How to plot points from odefun

7 views (last 30 days)
Hi, so I'm using odefun and ode45 to graph 3 different functions, but additionally I would like to graph specifically some points at several x values (50, 100,150, 200), but since I´m using odefun I don't know how to incorporate it. This is my code:
odefun function:
function yp = odefun(~,y)
yp = zeros(3,1);
yp(1)= (0.48947553*y(1))+(-0.2217926*y(1)*y(2))+(-0.8924614*y(3)*y(1));
yp(2)= (-0.0528409*y(2))+(0.00087705*y(1)*y(2));
yp(3)= (-0.0990983*y(3))+(0.00461634*y(1)*y(3));
ode code:
t0 = 0;
tfinal = 200;
y0 = [60.275818; 2.043051; 0.033794];
[T,Y] = ode45(@odefun,[t0 tfinal],y0);
figure;
plot(T,Y)

Accepted Answer

KSSV
KSSV on 29 Nov 2020
Note that Y is a m*3 matrix, you need to plot each column seperately.
figure(1);
plot(T,Y(:,1))
figure(2);
plot(T,Y(:,2))
figure(3);
plot(T,Y(:,3))
  2 Comments
Fátima Cecilia Chapa Viejo
Thanks! And if I want to let the program calculate the y value when x=50 and indicate this point (50,y) on the plot, how do I achieve this?
KSSV
KSSV on 29 Nov 2020
Use interp1. If x, y are your inputs.
xi = 50 ; % value of x at which you seek output
yi = interp1(x,y,xi) ; % get value yi corresponding to given xi
[xi yi]

Sign in to comment.

More Answers (0)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!