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 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
madhan ravi
on 17 Dec 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
More Answers (1)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!