Solving differential equation using ode45 in a single file

3 views (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 18 Jul 2018
[x, y] = ode45(@(x,y) (y./x)-(y./x).^2, [1, 2], 1);
  1 Comment
Andy
Andy on 25 Jul 2018
Thank you Walter. Much appreciated. I'll try it out when my new MATLAB license gets in

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!