Index exceeds the number of array elements. Index must not exceed 1.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jack Verderber
el 26 de Nov. de 2021
Respondida: Walter Roberson
el 26 de Nov. de 2021
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 comentarios
Bjorn Gustavsson
el 26 de Nov. de 2021
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?
Respuesta aceptada
Walter Roberson
el 26 de Nov. de 2021
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!