ODE45 in 3 dimensions with 6 initial conditions
10 次查看(过去 30 天)
显示 更早的评论
How can you get a solution for an ODE45 problem that involves x,y,z position and velocity initial condtions and has second order equations of motion. I can't find any help with anything that is 3-dimensional and has 6 componenets for the initial conditions.
0 个评论
采纳的回答
James Tursa
2021-3-15
编辑:James Tursa
2021-3-15
I find it easier to keep the position elements together, and the velocity elements together, in the state vector. So I would define the state vector y this way:
y(1) = x position
y(2) = y position
y(3) = z position
y(4) = x velocity
y(5) = y velocity
y(6) = z velocity
Then you write a derivative function based on that state vector. It would look something like this:
function ydot = myderivative(t,y,param1,param2) % you fill in the actual parameters you need
pos = y(1:3);
vel = y(4:6);
acc = _____; % you fill this in for acceleration. An expression involving pos, vel, param1, param2
ydot = [vel;acc];
end
The acc expression in the above code would be based on your 2nd order derivative expression for the actual problem you are working. I just used generic names param1 and param2 above. But you might have actual parameters named mu, g, Cd, k, etc. Then your main code would look something like this:
param1 = whatever; % or whatever the actual parameters are for your particular problem
param2 = whatever;
pos0 = whatever; % a 3x1 vector
vel0 = whatever; % a 3x1 vector
t0 = whatever;
tend = whatever;
[t,y] = ode45(@(t,y)myderivative(t,y,param1,param2),[t0 tend],[pos0;vel0]);
% code here to examine y or plot y etc.
Give this a shot and if you still have problems don't hesitate to follow up here with more questions.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!