Ode45 for first order differential equation (basic)

14 vues (au cours des 30 derniers jours)
Byom Adhikari
Byom Adhikari le 22 Nov 2017
Hello, I just started using matlab for my course and am stuck in the ode45 problem. I tried youtube and searched for answers but couldn't get through. I am trying to get some knowledge regarding this subject matter. My eqn is dy/dt=(y-1)^2. I need to graph the solutions for this equation for y(0) = 0.01,...1 at increments of 0.05. As of now i am converting the equation to first order ode and this is where i got.
function dx=ms(t,x)
dx(1) = x(2);
dx(2)=-x(1);
end

Réponses (1)

James Tursa
James Tursa le 22 Nov 2017
This is a 1st order ODE, so your variable will be only one element, not two elements. The derivative function will be (using your y nomenclature):
function dydt = ms(t,y)
dydt = (y-1)^2;
end
Look at the 1st order example in the ode45 doc and use your specific derivative function and initial conditions to obtain your solutions. Looks like maybe you will want to run this several times using different initial conditions?

Community Treasure Hunt

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

Start Hunting!

Translated by