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!