#Instructions: use this function to compute approximate numerical values of #solutions to initial value problems using the euler method # #if you want to solve dy/dt=f(t,y) for y(t0)=y0 with step size h, #try eulerapprox(f,t0,y0,h,n) where n is the number of values you want to see # #for example, if y'=3+t-y and y(0)=1, and step size h=0.1, try #eulerapprox(3+t-y,0,1,0.1,4); # eulerapprox:=proc(f,t0,y0,h,n) local yprev, ycurr, tprev, tcurr, i: ycurr:=y0: tcurr:=t0: for i from 1 to n do yprev:=ycurr: tprev:=tcurr: #If y_n=yprev and t_n=tprev, then... #y_(n+1) = y_n + f(t_n,y_n)*h (equation 8 on page 103) ycurr:=evalf(yprev+subs({y=yprev,t=tprev},f)*h): #t_(n+1)=t_n+h tcurr:=tprev+h: print("when t=", tcurr, ", y is approximately =", ycurr): od: end: