Reputation: 1
How do I solve the differential equation y'+y=t with y(0)=24?
Do I need to defined the differential equation with a file in the form .m?
Upvotes: 0
Views: 2978
Reputation: 1
dy/dt + y = t
Multiply integrating factor e^t
on both sides. Then,
d/dt [(e^t)y] = te^t
y = t-1+ce^(-t)
Because, y(0)=24
then c=25
y = t-1+25e^(-t)
Upvotes: -1
Reputation: 1154
To solve ordinary differential equations you've got the function lsode (run lsode for help).
f = @(y,t) t-y;
t = linspace(0,5,50)';
y=lsode(f, 24, t);
plot(t,y);
print -djpg figure-lsnode.jpg
Upvotes: 2