Plot an ODE solution with different constant values.

9 visualizaciones (últimos 30 días)
BHZ
BHZ el 21 de Feb. de 2022
Comentada: BHZ el 21 de Feb. de 2022
Hi everyone.
I have an ODE which describes a fluid.
I want to solve this ODE and graph it for different constant values.
To solve it, I use this code
syms y(x)
ode = diff(y,x) == (1.5 - 0.8*y) / (0.5 + 0.8*x);
sol = dsolve(ode);
The problem I have is with plotting the solutions. I want to plot this solution for differnt valus of C (General Answer), but using the
ezplot(sol)
gives a (x,C) plot.
How can I plot the general answer to get this plot?
Thank you so much.

Respuesta aceptada

HWIK
HWIK el 21 de Feb. de 2022
Is this what you are looking for?
clear
syms y(x)
ode = diff(y,x) == (1.5 - 0.8*y) / (0.5 + 0.8*x);
sol = dsolve(ode);
y1 = matlabFunction(sol);
C1 = -5:5; %set your own values of C1
y1 = y1(C1,x);
hold on
for i=1:length(y1)
ezplot(y1(i))
end
  1 comentario
BHZ
BHZ el 21 de Feb. de 2022
Thank you so much.
I didn't know about the matlabFunction and it seems useful.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by