0
votes

Consider the Initial value problem: t dy dt + y = 2t, y(1) = c

  1. Solve it using dsolve.
  2. Evaluate the solution with c= 0.7 at t= 0.01, 0.1, 1, 10. Repeat for c=1 and c=2.1.
  3. Plot the solutions with c= 0.7, 0.9, 1.1, 1.5, 2.1 on the same graph on the interval (0,2.5).

heres what ive tried

syms c y(t)

dsolve(diff(y)==(2*t-y)/t,y(.01)==.7)

dsolve(diff(y)==(2*t-y)/t,y(.1)==0.7);

dsolve(diff(y)==(2*t-y)/t,y(1)==0.7);

dsolve(diff(y)==(2*t-y)/t,y(10)==0.7);

everytime ive tried to plot it says MATLAB cant change double from sym. I am not really sure how to approach this problem, or if what I have tried is correct.

2

2 Answers

0
votes

Have you tried using ezplot?

f = dsolve(diff(y)==(2*t-y)/t,y(.01)==.7)
ezplot(f)

Note: if you have more than one solution, you might have to use ezplot(f{1}) to de-reference the cell array.

0
votes

The key is to turn your symbolic expression into a function using the symfun function.

For the first case, try the following

syms c y(t)

myfun = symfun(dsolve(diff(y)==(2*t-y)/t,y(.01)==.7), t);

N = 100;
x = linspace(0.001, 2.5, N);
plot(x, myfun(x));