Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168695
Image: ubuntu2004
%latex $$ \left\lbrace\begin{array}{rcl} y'(t) &=& 1 + \frac{y}{t} + \left( \frac{y}{t}\right)^2\\ y(1) &=& 0 \end{array}\right.$$ The exact solution of the above IVP is given by $y(t) = t \tan(\ln t) $ a)Obtain numerical solution for the IVP given above by using Euler’s method, Midpoint method (Runge-Kutta method order 2), Modified Euler’s method, and Runge-Kutta method order 4. Use h = 0.01 and calculate the error for each method at each point. Organize your results into a table or tables.
%latex Euler's Method Algorithm is as follows
def eulers_method(a,b,N,alpha): h = (b-a)/N t = a f = lambda x,y: 1.0 + (y/x) + (y/x)^2 omega = alpha #for storage of values, we create a list w = [] w.append((0,omega)) for i in range(1,N): omega = omega + h * f(t,omega) w.append((i,omega)) t = a + i * h return w
#since h = 0.01, N = (4-1)/.01 = 300 ans = eulers_method(1,4,300,0) # returns a table of points (i, w_i) mat_ans = matrix(ans)# creates a matrix of ans Latex_Table = latex(mat_ans)#makes the matrix into a table array in Latex
%latex The table is so large I cannot display it in the notebook. I will show you the problem in Wave. I will have to truncate the table. :-(