필터 지우기
필터 지우기

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