fsolve - solving for a steady state
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James
el 3 de Dic. de 2014
Comentada: Star Strider
el 3 de Dic. de 2014
I have a system of 4 unknowns and 4 equations of which I can cancel down to a system of 2 equations and 2 unknowns which leads to a trivial solution to the other 2 unknowns.
The two equations are:
(0.99)*(0.3*(k^0.3)*(n^0.7) + 0.975) = 1
and
((0.21)*(k^0.3)*(n^-0.3))/((k^0.3)*(n^0.7) - (0.025*k)) = 0.7/(1-n)
I am obviously looking to solve for k and h and I know that h is bounded by 0 and 1 (labour-leisure choice per period). I attempt to solve this via fsolve and this is my code:
function [ F ] = myfun(k,n)
% the system of 2 equations to solve for in vector F
F = [((((0.21)*(k.^0.3)*(n.^-0.3))/((k.^0.3)*(n.^0.7)- 0.025*k)) - ((0.7)/(1-n)));
(((0.99)*(0.3*(k.^-0.7)*(n.^0.7) + 0.975)) - 1)];
end
%%why was I told to use .^ for powers since I thought k and n were both scalar and I am looking to be returned a scalar?
and the script:
F0 = [5; 0.5]';
options = optimoptions('fsolve','Display','iter'); % Option to display output
X = fsolve(@myfun,F0,options); % Call solver
When I run this through Matlab I get this error:
Error using myfun (line 5)
Not enough input arguments.
Error in fsolve (line 219)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
And quite honestly, I'm not sure where it's going wrong and why it is saying there are not enough input arguments, any guidance is appreciated.
0 comentarios
Respuesta aceptada
Star Strider
el 3 de Dic. de 2014
The fsolve (and fminsearch and others) solve for a vector of parameters, so you have to express the arguments to them as such.
This works:
function [ F ] = myfun(p)
k = p(1);
n = p(2);
% the system of 2 equations to solve for in vector F
F = [((((0.21)*(k.^0.3)*(n.^-0.3))/((k.^0.3)*(n.^0.7)- 0.025*k)) - ((0.7)/(1-n)));
(((0.99)*(0.3*(k.^-0.7)*(n.^0.7) + 0.975)) - 1)];
end
F0 = [5; 0.5]';
options = optimoptions('fsolve','Display','iter'); % Option to display output
X = fsolve(@myfun,F0,options) % Call solver
and successfully completes with this result:
X =
5.9198e+000 276.1589e-003
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra 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!