필터 지우기
필터 지우기

using explcit parameters in fsolve gives error, how to solve this?

조회 수: 1 (최근 30일)
I have numerical values assigned to several parameter.
Using these parameters, I want solve fsolve such as below.
But it keeps giving error messages saying that the parameters are
not defined. Should I write every numbers instead of characters in
the function? Help me, please!
g=0.03; %gamma
b=0.45; %beta
a=0.3; %alpha
aa=2.5222; %1+alphabeta/beta
rho=0.5; %rho
r=1+rho*b/(1+a*b); %1+rho/1+alphabeta
th1=0.000045; %theta1
th2=0.000037; %theta2
R=900; %Resource
S=210; %S_-1
B=1/(1-a-g); %1/1-alpha-gamma
A12=1.5;
A11=1.2;
A02=1.9;
A01=1.8;
F = @(E)[2.52*( g/E(2) - r*(th1+W*th2) ) - g/E(1) + (th1+W*th2);
2.52*( g/E(4) - r*(W*th1+th2) ) - g/E(3) + (W*th1+th2);
R - ( E(1)+E(2)+E(3)+E(4) );
((exp( -th2*( rho*S +E(2) + E(4) ) ))/(exp( -th1*( rho*S +E(2) + E(4) ) ))*A02/A01)^(B)-E(4)/E(2);
((exp( -th2*( rho*( rho*S +E(2) + E(4) ) +E(1) + E(3) ) ))/(exp( -th1*( rho*( rho*( rho*S +E(2) + E(4) ) +E(1) + E(3) ) )))*A12/A11)^(B)-E(1)/E(3);
W-E(4)/E(2);
E(4)/E(2)-E(3)/E(1)];
E0=[300];
options=optimset('Display','iter');
E=fsolve(@planerenergy, E0, options)
ps. I also tried to make the function as seperate function such as
xx.m file. But it still gives the same error message such as
??? Undefined function or variable 'g'.
Error in ==> planerenergy at 2 F = [2.52*( g/E(2) - r*(th1+W*th2) ) - g/E(1) + (th1+W*th2);
Error in ==> fsolve at 248 fuser = feval(funfcn{3},x,varargin{:});
Error in ==> calibration0329 at 27 E=fsolve(@planerenergy, E0, options) Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

채택된 답변

Alan Weiss
Alan Weiss 2012년 3월 30일
Your code shows many lines devoted to creating the function handle F. Then you don't seem to use F in your fsolve function call.
It is possible that you are not passing parameters correctly. Take a look at http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-7.html
Alan

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 3월 30일
Whatever planerenergy is at line two, it doesn't have g defined.

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by