Ode45 for first order differential equation (basic)

15 ビュー (過去 30 日間)
Byom Adhikari
Byom Adhikari 2017 年 11 月 22 日
回答済み: James Tursa 2017 年 11 月 22 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by