I do not know how to solve it if I do not use dsolve

5 Comments

John D'Errico
John D'Errico on 27 Dec 2017
Edited: John D'Errico on 27 Dec 2017
doc ode45
You might even see an example there that will explain how to solve a second order ODE.
thank you, let me try
Two Symbolic Math Toolbox functions you will find useful are odeToVectorField and matlabFunction.
why they're so different ?

Sign in to comment.

 Accepted Answer

Star Strider
Star Strider on 27 Dec 2017

0 votes

They are different because odeToVectorField gives you an array you can pass to matlabFunction that will give you an anonymous function you can use directly with ode45 (if you write the matlabFunction call correctly), to get a numeric solution.
The result of your dsolve call gives you the analytic solution to the differential equation.
They are two entirely different results.

4 Comments

If I want to find out the same result as the result of dsolve but I do not want to use dsolve but the other method. Could you show me that method, please?
I will get you started:
syms y(t) Y T
[YDE,Subs] = odeToVectorField(diff(y,2) - 2*diff(y) + y == sin(t) + exp(t));
ode_fcn = matlabFunction(YDE, 'Vars',{t,Y});
You can use ‘ode_fcn’ directly with ode45.
I also requested the ‘Subs’ output from odeToVectorField so you will know that the first row (and first column of the result returned by ode45) is ‘y’, and the second of both is ‘Dy’.
thank you so much
As always, my pleasure.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!