Solving differential equation using ode45 in a single file

6 ビュー (過去 30 日間)
Andy
Andy 2018 年 7 月 17 日
コメント済み: Andy 2018 年 7 月 25 日
Hello
I need to solve the following ODE using ode45 function:
dy/dx=(y/x)-(y/x)^2, in interval 1<=x<=2, and initial condition of y(1)=1
I am struggling with creating a script in a single file without using a separate function file. I thought this would work but it gives an error:
[x,y]=ode45(@deriv, [1,2],1);
function dydx=deriv(x,y)
dydx=(y/x)-(y/x)^2
Any help would be appreciated.
Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 7 月 18 日
[x, y] = ode45(@(x,y) (y./x)-(y./x).^2, [1, 2], 1);
  1 件のコメント
Andy
Andy 2018 年 7 月 25 日
Thank you Walter. Much appreciated. I'll try it out when my new MATLAB license gets in

サインインしてコメントする。

カテゴリ

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