chapter5.page05 - tMesh(a b N to compute the ending of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2. EULER’S METHOD 5 2.2. Mathcad implementation of Euler’s Method. First, we have the following simple algorithm for the Euler’s method, Input f , a , b , x 0 n. Output: the approximate solution to x 0 = f ( t,x ) with initial guess x 0 over interval [a, b]. Step One: Initialization Set h = b - a n Set x 0 = x 0 Set t 0 = a Step Two: For i=1 to n do Step Three Step Three: Set x i = x i - 1 - f ( t i - 1 ,x i - 1 ) * h Set t i = t i - 1 + h Step Four return x. Notice, algorithm return an array of values, the ith element of the return array is an approximations of x ( t ) at t = a + ih. The following screen shot shows Mathcad code for implementing the algorithm. Notice, we also create a function
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tMesh(a, b, N) to compute the ending of subinterval for graphing purpose. Figure 3. Mathcad code for Euler’s Method Notice the line to line corresponding between the Mathcad and the algorithm. Since Mathcad programming language is a scripting lan-guage, the translation between algorithm and code is straight forward, and you don’t need to worry about the variable type, io, etc. Also, without explicit return statement, the result of last is, by default, will be returned....
View Full Document

This note was uploaded on 10/04/2011 for the course MAP 4231 taught by Professor Dr.han during the Spring '11 term at UNF.

Ask a homework question - tutors are online