Ode solver varying parameters
Mostrar comentarios más antiguos
Hello,
I have a three differnetial equations with 8 parameters in total of which 1 parameter p7 actually changes with time (p7=a*b^y*c^z - given for representative purpose, but i have a similar equation for that). How do i solve this with ode45? When i tried i got the following error: Unable to perform assignment because the left and right sides have a different number of elements. This is because the p7 has several values wheras other parametrs have only 1. Can someone help me how to solve ode with changing parameters.
CODE:
dx = zeros(3,1);
p7=a*b^y*c^z;
dx(1)=((p1.*((x(2)/(x(2)+p2)).*(x(3)/(x(3)+p3)))).*x(1));
dx(2)=((-((1/p4).*(p1.*((x(2)/(x(2)+p2)).*(x(3)/(x(3)+p3)))))+p5).*x(1));
dx(3)=(((-((1/p6).*(p1.*((x(2)/(x(2)+p2)).*(x(3)/(x(3)+p3)))))+p5).*x(1))+(p7.*(p8-x(3))));
Respuesta aceptada
Más respuestas (1)
J Chen
el 31 de Jul. de 2019
You put the derivative calculation in a file such as fcn.m,
function dx = fcn(t,x)
dx = zeros(3,1);
p7 = t; %p7=a*b^y*c^z;
p1 = 1; p2 = 2; p3 = 3; p4 = 4; p5 = 5; p6 = 6; p8 = 8;
dx(1) = ((p1.*((x(2)/(x(2)+p2)).*(x(3)/(x(3)+p3)))).*x(1));
dx(2) = ((-((1/p4).*(p1.*((x(2)/(x(2)+p2)).*(x(3)/(x(3)+p3)))))+p5).*x(1));
dx(3) = (((-((1/p6).*(p1.*((x(2)/(x(2)+p2)).*(x(3)/(x(3)+p3)))))+p5).*x(1))+(p7.*(p8-x(3))));
and call the solver in the command line
[t,x] = ode45('fcn',[0 1],[0 0 0]');
You can set p1 to p8 in the fcn.m file.
1 comentario
Nivedhitha S
el 1 de Ag. de 2019
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
