Borrar filtros
Borrar filtros

"Error using / Matrix dimensions must agree." When creating a system of functions

2 visualizaciones (últimos 30 días)
This is the function that I aim to generate:
This is what I plugged in:
%input all the varaible
alpha= 0.33;
beta= 0.96;
frac= 0.01;
step= 0.001; %set proper step size
x0= (alpha*beta)^(1/(1-alpha))*frac; %starting point
Kss= (alpha*beta)^(1/(1-alpha)); %steady state
x= x0+step:step:Kss-step; %generated values to move the equation through the system
This is the function that I aim to use to generate the system of equations:
function [f]=sysoe(x)
k= length(x); %length of sequence without the two
%knwon value (the starter and the end game); this is not a number because
%you do not actually know. Instead, it's for machine to run through the
%sequence till it gets there.
global alpha beta frac %the factors
T= k+2; %total length of time for capital. one generation..... n generation
%until steady state
Kss= (alpha*beta)^(1/(1-alpha)); %the end game steady state value
k0= frac*Kss; %the starting level capital as a fraction of the steady
%state capital
K= [k0 x Kss]; %starting state, everything in the middle, steady-state. In
%column form; which need to be transposed later. x is not a singular number
%becuase x is as many values as the system needs it to be to solve the
%question. In this case, to go from one equation to another.
%K(1:T-2) first element in the vector & stops at the third to last element
%K(2:T-1) second element in the vector & stops at the second to last element
%K(3:T) third element in the vector & stops at the last element
f= 1./(K(1:T-2).^alpha-K(2:T-1))- ((beta.*alpha.*K(2:T-1).^(alpha-1))./(K(2:T-1).^alpha-K(3:T)));
f=f'; %turn it into a row system
end
This is what I called in the command window:
>> [f]=sysoe(x)
This is what I got in return:
Error using /
Matrix dimensions must agree.
Error in sysoe (line 15)
Kss= (alpha*beta)^(1/(1-alpha)); %the end game steady state value

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Oct. de 2020
%input all the varaible
alpha= 0.33;
beta= 0.96;
frac= 0.01;
step= 0.001; %set proper step size
You did not declare those as global in that code.
global alpha beta frac %the factors
You declare them as global in that code. MATLAB is going to look in the global workspace for them. If this is the first time in the session that they have been declared as global, then MATLAB is going to assign [] (the empty double array) to them. And that empty double array causes size problems later.

Más respuestas (0)

Categorías

Más información sobre Strategy & Logic en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by