Ok, I am still struggling fsolve with 'index exceeds matrix deminsion' error issue. Need your advice!

1 次查看(过去 30 天)
I am trying such as following code. But it keeps giving "index exceeds matrix dimension error"
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
A02=1.5;
A01=1.2;
A12=1.9;
A11=1.8;
W=1;
psi0=A02/A01;
psi1=A12/A11;
%%%%%%%%%
E0=[225 225,225 225];
options=optimset('Display','iter');
E=fsolve(@pl, E0, options)
%%pl.m function is
function F = pl(E)
global W th1 th2 R rho a b g psi0 psi1
F =
[g/E(2,1)-(th1+W*th2)-(1+a*b)/b*(g/E(1,1)-(1+rho*b/(1+a*b))*(th1+W*th2));
g/(psi1*E(2,1))-(1/W*th1+th2)-(1+a*b)/b*(g/(psi0*E(1,1))-((1+rho*b/(1+a*b))*(1/W*th1+th2)));
R-(E(1,1)+E(1,2)+E(1,1)+E(2,2));
E02-phi0*E(1,1);
E12-phi1*E(2,1);
psi0-psi1];
%%error message is
??? Index exceeds matrix dimensions.
Error in ==> pl at 4
F =[g/E(2,1)-(th1+W*th2)-(1+a*b)/b*(g/E(1,1)-(1+rho*b/(1+a*b))*(t1+W*th2));
Error in ==> fsolve at 254
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

采纳的回答

Walter Roberson
Walter Roberson 2012-3-30
E0=[225 225,225 225]; does not create a 2 x 2 array. To create a 1 x 4 array use
E0=[225 225;225 225];
  2 个评论
Joon Jeon
Joon Jeon 2012-3-31
Ok, thanks for your answer.
But now it gives a new error saying
??? Error using ==> mldivide
Matrix dimensions must agree.
what is wrong with my coding??
Walter Roberson
Walter Roberson 2012-3-31
Are any of your global variables arrays?
What is E02 and E12? You use them near the end of F but do not appear to define them.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by