Attempted to access x(2,1); index out of bounds because size(x)=[1,4].
2 ビュー (過去 30 日間)
古いコメントを表示
I keep encountering the error from my code below. I need help
Attempted to access x(2,1); index out of bounds because size(x)=[1,4].
Error in manish2 (line 2)
ca=x(1,1);cb=x(2,1);cc=x(3,1);cd=x(4,1);
Error in fsolve (line 219)
fuser = feval(funfcn{3},x,varargin{:});
Error in manish (line 13)
[x,fval]=fsolve(@manish2,x0,options,parameters);
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
keq=10;kor=((49.3e-6)/keq)*exp(139.4e6/8314/333);
%Set VR and TR
vr=100;tr=350;
kf=4.239e6*exp(-69.7e6/tr/8314);
kr=kor*exp(-139.4e6/8314/tr);
fa0=0.004377;ca0=8.01;fb0=0.004377;cb0=8.01;
flow=fa0+fb0;
parameters=[vr,kf,kr,fa0,ca0+fb0,cb0];
%Initial guesses of ca, ab, cc and cd
x0=[2 2 2 2 ];
options=optimset('MaxFunEvals',1000,'TolFun',1e-8);
% Use fsolve to solve four nonlinear algerbraic equaitons
[x,fval]=fsolve(@manish2,x0,options,parameters);
ca=x(1,1);cb=x(2,1);cc=x(3,1);cd=x(4,1);
conversion=(fa0*ca0-flow*ca)/(fa0*ca0);
ca,cb,cc,cd
function f=manish2(x,parameters)
ca=x(1,1);cb=x(2,1);cc=x(3,1);cd=x(4,1);
vr=parameters(1);kf=parameters(2);kr=parameters(3);
fao=parameters(4);cao=parameters(5);fbo=parameters(6);cbo=parameters(7);
flow=fao+fbo;
ratef=kf*ca*cb;
rater=kr*cc*cd;
f(1,1)=fao*cao-flow*ca-vr*(ratef-rater);
f(2,1)=fbo*cbo-flow*cb-vr*(ratef-rater);
f(3,1)=-flow*cc-vr(rater-ratef);
f(4,1)=-flow*cd-vr*(rater-ratef);
0 件のコメント
回答 (1 件)
Rik
2019 年 4 月 29 日
The fsolve function requires a working function as input. Your function contains a few typos, and it assumes the input is a column vector, while you enter the initial guess as a row vector. The edits below should allow you to run the code.
The best test in such a case is to run the function with the initial guess and see if it runs as expected.
keq=10;kor=((49.3e-6)/keq)*exp(139.4e6/8314/333);
%Set VR and TR
vr=100;tr=350;
kf=4.239e6*exp(-69.7e6/tr/8314);
kr=kor*exp(-139.4e6/8314/tr);
fa0=0.004377;ca0=8.01;fb0=0.004377;cb0=8.01;
flow=fa0+fb0;
parameters=[vr,kf,kr,fa0,ca0,fb0,cb0];
%Initial guesses of ca, ab, cc and cd
x0=[2 2 2 2 ];
options=optimset('MaxFunEvals',1000,'TolFun',1e-8);
% Use fsolve to solve four nonlinear algerbraic equaitons
[x,fval]=fsolve(@manish2,x0,options,parameters);
ca=x(1);cb=x(2);cc=x(3);cd=x(4);
conversion=(fa0*ca0-flow*ca)/(fa0*ca0);
ca,cb,cc,cd
function f=manish2(x,parameters)
f=x;%pre-allocate f in the shape of x
ca=x(1);cb=x(2);cc=x(3);cd=x(4);
vr=parameters(1);kf=parameters(2);kr=parameters(3);
fao=parameters(4);cao=parameters(5);fbo=parameters(6);cbo=parameters(7);
flow=fao+fbo;
ratef=kf*ca*cb;
rater=kr*cc*cd;
f(1)=fao*cao-flow*ca-vr*(ratef-rater);
f(2)=fbo*cbo-flow*cb-vr*(ratef-rater);
f(3)=-flow*cc-vr*(rater-ratef);
f(4)=-flow*cd-vr*(rater-ratef);
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Passivity and Sector Bounds についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!