Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Mar 2012
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 Comments
Joon Jeon
Joon Jeon on 31 Mar 2012
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 on 31 Mar 2012
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!