Can someone explain how to evaluate a function with multiple initial conditions? And then plot it?

조회 수: 1 (최근 30일)
This is what I have so far. I don't need the exact answer, but any help would be greatly appreciated!!! I need to plot the 3 different symbolic solutions to the IVP on the figure.
%Define the variables using syms
syms y(t) y0 y t
%define the ordinary differential equation
ode = diff(y,t) == cos(t^2);
%solve the differential equation using dsolve
ysol = dsolve(ode)
%Create a figure called Task 1
figure ('Name','Task 1')
%Pick 3 different initial conditions for which the solution exists
conds = [1 1.5 3];

답변 (1개)

Walter Roberson
Walter Roberson 2019년 7월 30일
편집: Walter Roberson 2019년 7월 30일
ysol = dsolve(ode, y(0)==y0)
After which subs(ysol, y0, conds) to get the three different equations.
  댓글 수: 2
Vincenzo  Dragone
Vincenzo Dragone 2019년 7월 30일
Thanks you for the help! Do you know what to do to plot those three equations?
What variable would I plot? ysol?
Walter Roberson
Walter Roberson 2019년 7월 31일
%Define the variables using syms
syms y(t) y0
%define the ordinary differential equation
ode = diff(y,t) == cos(t^2);
%solve the differential equation using dsolve
ysol = dsolve(ode, y(0)==y0);
%Create a figure called Task 1
figure ('Name','Task 1')
%Pick 3 different initial conditions for which the solution exists
conds = [1 1.5 3];
eqns = subs(ysol, y0, conds);
t_end = 10;
fplot(eqns, [0 t_end])
legend(string(conds))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by