I have a set of second order differential nonlinear equation and I want to solve them together with ode45, how could I write codes for them?or better to say I want to define state transition function for such equations.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
roya afshar
el 15 de Dic. de 2018
Comentada: madhan ravi
el 17 de Dic. de 2018
first three equations all variable and constants are not in vector or matrix form but 4th equation is a 3by1 vector like this:
x''=y'+y+x-(x)/(x^2+y^2+z^2)^1.5+1
y''=x'-x+y-y/(x^2+y^2+z^2)^1.5
z''=-z/(x^2+y^2+z^2)^1.5
m''=[x'' y'' z'']'+[1 2 3]
and I want to write function for this system like this function that i have found in one of matlab example:
function dxdt = vdpStateFcnContinuous(x)
%vdpStateFcnContinuous Evaluate the van der Pol ODEs for mu = 1
dxdt = [x(2); (1-x(1)^2)*x(2)-x(1)];
end
2 comentarios
Respuesta aceptada
madhan ravi
el 17 de Dic. de 2018
I believe :
[t,x]=ode45(@eqns,[0 10],[1;0;0;0;0;0;0;0;0;0;0;0]); % function call
plot(t,x(:,1)) % to plot the solution
function dxdt = eqns(t,x) % function definition
dxdt = [x(2);
x(4)+x(5)+x(1)-(x(1)/((x(1)^2+x(3)^2+x(5)^2)^1.5))+1;
x(4);
x(2)-x(1)+x(3)-(x(3)/((x(1)^2+x(3)^2+x(5)^2)^1.5));
x(6);
-x(5)/((x(1)^2+x(3)^2+x(5)^2)^1.5);
x(2:2:6);
[x(4)+x(5)+x(1)-(x(1)/((x(1)^2+x(3)^2+x(5)^2)^1.5))+1;x(2)-x(1)+x(3)-(x(3)/((x(1)^2+x(3)^2+x(5)^2)^1.5));-x(5)/((x(1)^2+x(3)^2+x(5)^2)^1.5)]+[1;2;3]];
end
2 comentarios
Más respuestas (1)
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!