How to plot points from odefun

5 visualizaciones (últimos 30 días)
Fátima Cecilia Chapa Viejo
Fátima Cecilia Chapa Viejo el 29 de Nov. de 2020
Comentada: KSSV el 29 de Nov. de 2020
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)

Respuesta aceptada

KSSV
KSSV el 29 de Nov. de 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 comentarios
Fátima Cecilia Chapa Viejo
Fátima Cecilia Chapa Viejo el 29 de Nov. de 2020
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 el 29 de Nov. de 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]

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by