Time-based integration of ODEs
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ali Almakhmari
el 13 de En. de 2023
Comentada: Ali Almakhmari
el 13 de En. de 2023
Hello everyone. I have a problem that I hope I can get some help on. So I have the following set of differential equations:
I need to solve for θ, ϕ, and ψ from those three differential equations. To be specific I need to solve for a value (not a function) of θ, ϕ, and ψ at a given moment. I have a for loop that runs, and at each iteration the value of p, q, and r change, so at each iteration I will need to do this integration and solve for a value of θ, ϕ, and ψ. What information do I have avaliable for me? The value of p, q, and r at each iteration, and I also know the initial values (iteration = 1) of θ, ϕ, and ψ, and finally, I know the time at each iteration as well. Is this possible in MATLAB? I tried implementing this with ODE45 and struggled very much. Any help is super appreciated.
6 comentarios
Jan
el 13 de En. de 2023
Editada: Jan
el 13 de En. de 2023
It is still not clear, what you call "iteration". ODE45 solves the ODE in steps, so this is an iterative process. But steps can be rejected or re-calculated, such that "changes in each iteration" are not meaningful. If p,q,r are functions of time, there is no problem.
Please post the existing code, even if it fails. Then it might get clear immediately, how p,q,r are defined.
Respuesta aceptada
Steven Lord
el 13 de En. de 2023
The problem you've written out looks quite similar to the "Pass Extra Parameters to ODE Function" example on the ode45 documentation page. You have a system of three first-order ODEs rather than the system of two first-order ODEs given in the example and you have three extra parameters (p, q, and r) rather than the two (A and B) from the example, but those will require only a small modification to the odefun and to the ode45 call.
The fact that p, q, and r are functions of time rather than fixed values is a little bit more challenging, but the "ODE with Time-Dependent Terms" example on that same documentation page shows how you can handle them if you have a vector of data. If you have function handles for p, q, and r that's even easier.
f = @(t) t.^2;
[t, y] = ode45(@(t, y) myode(t, y, f), [0 1], 1);
plot(t, y)
Let's check the symbolic solution.
syms ts ys(ts) % Using ts and ys instead of t and y so I can use t and y for plotting below
solution = dsolve(diff(ys, ts) == ts^2*ys(ts), ys(0)==1)
And now plot the numeric solution and the value of the symbolic solution at the same times.
figure
plot(t, y, '+', t, subs(solution, ts, t), 'o')
Those look to be in pretty good agreement.
function dydt = myode(t, y, f)
fvalue = f(t);
dydt = fvalue*y; % dydt = t^2*y
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations 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!