How do I plot the solutions?
12 views (last 30 days)
Show older comments
This is the code I have so far, but I can't figure out how to plot the 3 solutions given the 3 initial conditions. Can anyone help?????
%Define the variables using syms - syms creates symbolic variables
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
%Conditions are the y values (y values are 1, 1.5, and 3 at varying t
%values. See the t values below.
conds = [1 1.5 3];
subs(ysol,y0,conds);
plot(ode,'color',rand(1,3),'linewidth',2)
title('Symbolic Solutions')
xlabel('t')
ylabel('y')
grid on
1 Comment
Walter Roberson
on 31 Jul 2019
See https://www.mathworks.com/matlabcentral/answers/474184-can-someone-explain-how-to-evaluate-a-function-with-multiple-initial-conditions-and-then-plot-it
Answers (0)
See Also
Categories
Find more on Equation Solving 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!