How to plot points from odefun

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

采纳的回答

KSSV
KSSV 2020-11-29
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 个评论
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 2020-11-29
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]

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by