Index exceeds the number of array elements. Index must not exceed 1.
3 次查看(过去 30 天)
显示 更早的评论
function res = digestive_model()
syms x(y)
c = 7; tau = 1; K = 1; c0 = 1; c1 = 1; a = 1; b = 1; v0 = 0.001;
Wt = linspace(0,100); Vt = linspace(0,100);
dx = diff(x);
at = tau*(1-(1/c)*diff(x,y,1));
ode = diff(x,y,2) + (K./Wt).*diff(x,y,1) - at.*((c0+c1.*Vt)./(a+b*x)) == 0;
cond1 = x(0) == 0;
cond2 = dx(0) == v0;
[V] = odeToVectorField(ode);
M = matlabFunction(V,'var',{'Y','X'});
res = ode45(M,[0 20],[cond1 cond2]);
figure
fplot(res,[0 20])
end
Any help would be greatly appreciated, thank you.
2 个评论
Bjorn Gustavsson
2021-11-26
Dont attach the code as an image. Insert it as code in the message, using the editor facility for that. If someone is to help you they will for now write off what can be seen in the image - why making it harder for us to help you?
采纳的回答
Walter Roberson
2021-11-26
digestive_model()
function res = digestive_model()
syms x(y)
c = 7; tau = 1; K = 1; c0 = 1; c1 = 1; a = 1; b = 1; v0 = 0.001;
Wt = linspace(0,100); Vt = linspace(0,100);
dx = diff(x);
at = tau*(1-(1/c)*diff(x,y,1));
ode = diff(x,y,2) + (K./Wt).*diff(x,y,1) - at.*((c0+c1.*Vt)./(a+b*x)) == 0;
cond1 = x(0) == 0;
cond2 = dx(0) == v0;
ode
[V] = odeToVectorField(ode);
M = matlabFunction(V,'var',{'Y','X'});
res = ode45(M,[0 20],[cond1 cond2]);
figure
fplot(res,[0 20])
end
Notice your ode is a vector -- a vector the same length as Wt and Vt since those are both vectors. If it was going to work at all, you would need a vector of initial conditions at least as long as that vector.
Also, the first entry in Wt is 0, so K./Wt includes a division by 0, so the first entry in ode involves an infinity.
If Wt and Vt are parameters of the ode, then use them as symbolic, and use odeFunction() instead of matlabFunction and specify Wt and Vt as parameters of the system. You may need to iterate over all the Wt / Vt combinations to solve all of the cases.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!