how to solve this coupled ODE problem using ode solvers ?
1 view (last 30 days)
Show older comments
Sravan Kumar Putta
on 19 Jan 2021
Edited: Sravan Kumar Putta
on 20 Jan 2021
I have two ODEs within time interval [0 1] with initial conditions values for F_x and F_y are calculated from function
0 Comments
Accepted Answer
Bjorn Gustavsson
on 20 Jan 2021
Edited: Bjorn Gustavsson
on 20 Jan 2021
If you want to use the odeNN functions you need to rewrite your 2 2nd-order ODEs into 4 1st-order ODEs, something like this:
function dxdydvxdvydt = your_eqs_of_motion(t,xyvxvy,other,parameters)
x = xyvxvy(1); % If my ode-equations are complicated
y = xyvxvy(2); % I prefer to explicitly extract the
vx = xyvxvy(3); % variables into something that's
vy = xyvxvy(4); % easily human-readable
m = other;
Fx = force_functionx(t,x,y,vx,vy,other,parameters); % Adjust inputs as necessary
Fy = force_functiony(t,x,y,vx,vy,other,parameters);
% or possibly preferable:
% [Fx,Fy] = force_function_xny(t,x,y,vx,vy,other,parameters);
dxdydvxdvydt = [vx;vy;Fx/m;Fy/m];
end
Then you can integrate the equations of motion something like this:
m = 12; % you know what to set for this one
x0y0vx0vy0 = [1e-10,5.08e-5,0,0]; % Your initial conditions
t_span = [0,2*pi]; % a time-span of interest
[t_out,xyvxvy] = ode45(@(t,xyvxvy) your_eqs_of_motion(t,xyvxvy,m,[]),t_span,x0y0vx0vy0);
When integrating equations of motion you typically also have to carefully check that the constants of motion we know should be conserved (total energy, angular momentum, etc.) are reasonably conserved - the general ODE-integrating functions are not guaranteed to do this.
HTH
0 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!