
Originally Posted by
oxxiissiixxo
Hi I want to write a program to solve these 2 ODEs, but I do know how to do it. Please help!
y'_1 = -y_1 + y_2
y'_2 = -100(y_2 - sin t) + cos t
t is from 0 to 1 and with inital value y_1= 1, y_2 = 2.
time step = 0.01
Crude but should work:
Code:
function rv=IODE
y=[1,2];
rv=[0,y];
dt=0.1;
for t=0:dt:1-dt
dydt=[y(1)+y(2),-100*(y(2)-sin(t))+cos(t)];
y=y+dt*dydt;
rv=[rv;[t+dt,y]];
end returns an array each row consists of the time and the y's
.