How to resolve this error "Array indices must be positive integers or logical values."

4 次查看(过去 30 天)
syms p Dp D2p q Dq D2q x
r=0.09;
s=0.1;
m=0.03;
f=0.075;
vmax=100;
xf=90;
mum=0.5;
c=0.5;
t1=xf*vmax;
t2=((f*vmax+xf*Dq(-mum+3*m+12*(s^2))+4.5*(s^2)*(xf^2)*D2q)/(r-(3*m+3*(s^2))));
Array indices must be positive integers or logical values.

Error in indexing (line 936)
R_tilde = builtin('subsref',L_tilde,Idx);
m1=(Dp/p)*x*(3*m+3*(s^2)-mum)+(9/2)*(x^2)*(s^2)*D2p/p;
ode = p-((x/((c^3)*sqrt(2)))*(1+m1+mum-r-f)^2);
D2ynum = solve(ode==0,D2p);
D2ynum = D2ynum(2);
f1 = matlabFunction(D2ynum,"Vars",{x, [p Dp]});
ode1=q-((p*f/x-mum*x*Dq+(3*m+3*(s^2))*Dq*x+(9/2)*(s^2)*(2*x*Dq+(x^2)*D2q))/(r-(3*m+3*(s^2))));
D2ynum1 = solve(ode1==0,D2q);
D2ynum1 = D2ynum1(1);
f2 = matlabFunction(D2ynum1,"Vars",{x, [p Dp q Dq]});
odefcn = @(x,y)[y(2);f1(x, [y(1) , y(2)]);y(4);f2(x, [y(1), y(2), y(3) ,y(4)])];
bcfcn = @(ya,yb)[ya(1);yb(1)-t1;ya(3);yb(3)-t2];
xmesh = linspace(0.001,xf,10);
solinit = bvpinit(xmesh, [0.001 0.001 0.001 0.001]);
sol = bvp4c(odefcn,bcfcn,solinit);

回答(1 个)

Torsten
Torsten 2023-7-4
You forgot a multiplikation sign:
t2=((f*vmax+xf*Dq*(-mum+3*m+12*(s^2))+4.5*(s^2)*(xf^2)*D2q)/(r-(3*m+3*(s^2))));
instead of
t2=((f*vmax+xf*Dq(-mum+3*m+12*(s^2))+4.5*(s^2)*(xf^2)*D2q)/(r-(3*m+3*(s^2))));
  2 个评论
Della
Della 2023-7-4
Thanks @Torsten. But now I'm getting this error "The following error occurred converting from sym to double:
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function
first to substitute values for variables."

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by