Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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);

Risposte (1)

Torsten
Torsten il 4 Lug 2023
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 Commenti
Della
Della il 4 Lug 2023
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."
Torsten
Torsten il 4 Lug 2023
t2 is still a symbolic expression - you can't use it in the definition of "bcfcn".

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by