how derive a solution of ode45
1 view (last 30 days)
Show older comments
Hi i have a ode45 solution with this script
syms y(t)
[V] = odeToVectorField(diff(y, 2) + 2*diff(y) - sin(y) == 0)
M = matlabFunction(V,'vars', {'t','Y'})
sol = ode45(M,[0 20],[1 0])
fplot(@(x)deval(sol,x,1),[0, 20])
dsol = diff(sol)
Now i want to derive the solution to obtain the velocity.
How i can do ?
0 Comments
Accepted Answer
Torsten
on 7 Nov 2022
The red curve is the derivative of the blue curve.
syms y(t)
[V] = odeToVectorField(diff(y, 2) + 2*diff(y) - sin(y) == 0)
M = matlabFunction(V,'vars', {'t','Y'})
sol = ode45(M,[0 20],[1 0])
hold on
fplot(@(x)deval(sol,x,1),[0, 20])
fplot(@(x)deval(sol,x,2),[0, 20])
hold off
3 Comments
Torsten
on 8 Nov 2022
Edited: Torsten
on 8 Nov 2022
If you look at the function handle M, your second-order equation is solved as a system of two first-order equations:
y1' = y2
y2' = sin(y1) -2*y2
Here, y1 is your y und y2 is dy/dt.
So if y1 is position, y2 is velocity, and these are the two components of the sol structure.
This is the disadvantage of OdeToVectorField: the beginner quickly looses control over the solution process.
More Answers (0)
See Also
Categories
Find more on Numerical Integration and 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!