Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dynare
Commits
e3e6f4c9
Commit
e3e6f4c9
authored
1 year ago
by
Johannes Pfeifer
Browse files
Options
Downloads
Patches
Plain Diff
get_mean.m: fix internal logic
parent
7a5684bf
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2250
get_mean.m: remove globals and fix internal logic
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/accessors/get_mean.m
+36
-17
36 additions, 17 deletions
matlab/accessors/get_mean.m
with
36 additions
and
17 deletions
matlab/accessors/get_mean.m
+
36
−
17
View file @
e3e6f4c9
function
y0
=
get_mean
(
varargin
)
% function
x
= get_mean(v
name1, vname2, <order>
)
% returns the
steady-state
of a variable identified by its name
% function
y0
= get_mean(v
arargin
)
% returns the
mean
of a variable identified by its name
%
% INPUTS:
% vname1, vname2, ... : list of variable names
% order: if integer 1 or 2, optionally last input can trigger the order
% at which steady state is computed
% vargargin inputs containing
% - vname1, vname2, ... : list of variable names
% - order: if integer 1 or 2, optionally last input can trigger the order
% at which steady state is computed
%
% OUTPUTS
%
x
:
steady state
values
%
y0
:
mean
values
%
% SPECIAL REQUIREMENTS
% none
...
...
@@ -30,27 +31,45 @@ function y0 = get_mean(varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global
M_
oo_
options_
global
M_
options_
oo_
if
~
isempty
(
regexp
(
varargin
{
end
},
'\d'
,
'ONCE'
))
&&
isempty
(
regexp
(
varargin
{
end
},
'\D'
,
'ONCE'
))
order
=
eval
(
varargin
{
end
});
nvars
=
length
(
varargin
)
-
1
;
else
order
=
1
;
nvars
=
length
(
varargin
);
end
if
order
==
1
ys_
=
oo_
.
steady_state
;
ys_
=
evaluate_steady_state
(
ys_
,[
oo_
.
exo_steady_state
;
oo_
.
exo_det_steady_state
],
M_
,
options_
,
true
);
if
isfield
(
oo_
,
'dr'
)
&&
isfield
(
oo_
.
dr
,
'ys'
)
ys_
=
oo_
.
dr
.
ys
;
else
ys_
=
oo_
.
steady_state
;
ys_
=
evaluate_steady_state
(
ys_
,[
oo_
.
exo_steady_state
;
oo_
.
exo_det_steady_state
],
M_
,
options_
,
true
);
end
elseif
order
==
2
ys_
=
oo_
.
dr
.
ys
;
ys_
(
oo_
.
dr
.
order_var
)
=
ys_
(
oo_
.
dr
.
order_var
)
+
oo_
.
dr
.
ghs2
.
/
2
;
if
isfield
(
oo_
,
'dr'
)
&&
isfield
(
oo_
.
dr
,
'ys'
)
ys_
=
oo_
.
dr
.
ys
;
if
~
isfield
(
oo_
.
dr
,
'ghs2'
)
error
(
'get_mean: ghs2 needs to be present in oo_ to compute mean at order=2'
)
else
ys_
(
oo_
.
dr
.
order_var
)
=
ys_
(
oo_
.
dr
.
order_var
)
+
oo_
.
dr
.
ghs2
.
/
2
;
end
else
error
(
'get_mean: decision rules need to be present in oo_ to compute mean'
)
end
else
return
error
(
'get_mean: order>2 not implemented'
)
end
lgy_
=
M_
.
endo_names
;
mfys
=
nan
(
length
(
varargin
),
1
);
for
j
=
1
:
length
(
varargin
)
mfys
(
j
)
=
find
(
strcmp
(
varargin
{
j
},
lgy_
));
mfys
=
NaN
(
nvars
,
1
);
for
j
=
1
:
nvars
endo_index
=
find
(
strcmp
(
varargin
{
j
},
M_
.
endo_names
));
if
isempty
(
endo_index
)
error
(
'get_mean: unknown variables %s requested'
,
varargin
{
j
})
else
mfys
(
j
)
=
find
(
strcmp
(
varargin
{
j
},
M_
.
endo_names
));
end
end
y0
=
ys_
(
mfys
);
y0
=
ys_
(
mfys
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment