fsolve - solving for a steady state

12 次查看(过去 30 天)
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:
*A function <file:*>
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.

采纳的回答

Star Strider
Star Strider 2014-12-3
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by