user3554567
user3554567

Reputation: 1

Octave to solve differential equations

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

Answers (2)

고민우
고민우

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

jpmuc
jpmuc

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

y versus t

Upvotes: 2

Related Questions