Ode45 for first order differential equation (basic)

15 次查看(过去 30 天)
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

回答(1 个)

James Tursa
James Tursa 2017-11-22
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?

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by