Index in position 2 exceeds array bounds
Afficher commentaires plus anciens
Could someone please tell me what should I put for D2q in odefcn?
syms p Dp D2p q Dq D2q x
r=0.06;
s=0.3;
m=0.01;
f=0.075;
vmax=5;
smax=3;
xf=90;
w=0.15;
l=0.01;
a0=0.001;
h=0.2;
alpha=1;
pi=0.5;
mk=5;
mum=0.6;
t=0.1;
tp=0.05;
k=0.3;
a=((q+x*Dq)*t+(2*Dq*x+(x^2)*D2q)*s*tp)/(k-(2*Dq*x+(x^2)*D2q)*(tp^2));
m1=(Dp/p)*x*(m+a*t-mum)+0.5*(x^2)*((s+a*tp)^2)*(D2p/p);
t11=((w+m-r-f+mum)*(sqrt(vmax*alpha*xf)))/((pi^2)*sqrt(mk));
ode = p-(((x*alpha)*(w+m1+mum-r-f)^2)/((pi^4)));
D2ynum = solve(ode==0,D2p);
D2ynum = D2ynum(2);
f1 = matlabFunction(D2ynum,"Vars",{x, [p Dp q Dq D2q]})
ode1=q-((((p*f/x)-mum*x*Dq+(m+a*t)*Dq*x+0.5*((s+a*tp)^2)*(2*x*Dq+(x^2)*D2q)-0.5*k*(a^2))/(r-(m+a*t))));
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(3), y(4)]);y(4);f2(x, [y(1), y(2), y(3) ,y(4)])];
bcfcn = @(ya,yb)[ya(1);yb(1)-t11;ya(4);yb(3)-((f*t11-0.5*k*(a^2)/((r-(m+t*a)))))];
xmesh = linspace(0.001,xf,10);
solinit = bvpinit(xmesh, [0.001 0.001 0.001 0.001]);
sol = bvp4c(odefcn,bcfcn,solinit);
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 10 Juil 2023
f1 = matlabFunction(D2ynum,"Vars",{x, [p Dp q Dq D2q]})
5 variables bunched together, so f1 is going to expect to be able to index up to 5 for the second parameter.
odefcn = @(x,y)[y(2);f1(x, [y(1) , y(2), y(3), y(4)]);y(4);f2(x, [y(1), y(2), y(3) ,y(4)])];
but there you are only passing 4 values to the second parameter of f1.
1 commentaire
Della
le 10 Juil 2023
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!