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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by