



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




This is my sample writeup for our first class project. Your writeup obviously doesn’t need to be exactly like this, but it should contain more or less the same information.
For the first part of our project I wrote an implementation of Euler’s method in Maple (using code provided for you in the handout) and then used this implementation to estimate the values of the “famous” numbers e, π, and ln (2) by recognizing them as values of the solutions to certain differential equations at given points. Each time the total x distance from the initial x value to the estimated x value was 1, and I began by taking 50 steps, and then doubling the step size for each iteration until the estimate settled down. For the Euler’s method esimates settling down meant no change in the first three decimal places.
The code used to implement Euler’s method (given in the handout) is:
EulersMethod := proc(x0,y0,h,n) local xk, yk, k; xk := x0; yk := y0; k := 0; while k < n do k := k+1; yk := yk + h*f(xk,yk); xk := xk + h;
end do; [xk,yk]; end;
I first used this code to esimate the value of e as being the solution to the initial value problem:
dy dx
= y
y(0) = 1
at the point x = 1.
I first set the function f to be f (x, y) = y by entering in the command:
f := (x,y) -> y;
then using these initial conditions I recorded the values:
Command h n Value EulersMethod(0, 1 ,. 02 , 50) .02 50 2. 692 EulersMethod(0, 1 ,. 01 , 100) .01 100 2. 705 EulersMethod(0, 1 ,. 005 , 200) .005 200 2. 712 EulersMethod(0, 1 ,. 0025 , 400) .0025 400 2. 715 EulersMethod(0, 1 ,. 00125 , 800) .00125 800 2. 717 EulersMethod(0, 1 ,. 000625 , 1 , 600) .000625 1,600 2. 717
So, my esimate using Euler’s method for the value of e out to three decimal places is 2. 717. The actual value out to three decimal places is
The next famous value I estimated was ln (2), which is the solution to the initial value problem:
dy dx
x y(1) = 0
Command h n Value EulersMethod(0, 1 ,. 02 , 50) .02 50 3. 162 EulersMethod(0, 1 ,. 01 , 100) .01 100 3. 152 EulersMethod(0, 1 ,. 005 , 200) .005 200 3. 147 EulersMethod(0, 1 ,. 0025 , 400) .0025 400 3. 144 EulersMethod(0, 1 ,. 00125 , 800) .00125 800 3. 143 EulersMethod(0, 1 ,. 000625 , 1 , 600) .000625 1,600 3. 142 EulersMethod(0, 1 ,. 0003125 , 3 , 200) .0003125 3,2000 3. 142
So, my estimate using Euler’s method for the value of π out to three decimal places is 3. 142. The actual value out to three decimal places is
2 Improved Euler’s Method
For the next part of the project I did the same thing, only instead of us- ing Euler’s method I used an implementation of the improved Euler’s method, and instead of calculating out the estimate to three decimal places, I calculated the estimate out to five decimal places.
The code for implementing the improved Euler’s method I used was:
ImprovedEulersMethod := proc(x0,y0,h,n) local xk, yk, k, k1, uk, k2; xk := x0; yk := y0; k := 0; while k < n do k := k+1; k1 := f(xk,yk); uk := uk + hk1; k2 := f(xk+h,uk); yk := yk + h(1/2)*(k1+k2); xk := xk + h; end do; [xk,yk]; end;
Using this improved implementation, and the same methodology as I used with Euler’s method, I found the following esimates for the value of e:
Command h n Value ImprovedEulersMethod(0, 1 ,. 02 , 50) .02 50 2. 71810 ImprovedEulersMethod(0, 1 ,. 01 , 100) .01 100 2. 71824 ImprovedEulersMethod(0, 1 ,. 005 , 200) .005 200 2. 71827 ImprovedEulersMethod(0, 1 ,. 0025 , 400) .0025 400 2. 71828 ImprovedEulersMethod(0, 1 ,. 00125 , 800) .00125 800 2. 71828
So, our estimate for e to five decimal places is 2. 71828. The actual value to five decimal places is 2. 71828. Nice!
Estimating ln (2) using the improved Euler’s method I obtained the fol- lowing:
Command h n Value ImprovedEulersMethod(0, 1 ,. 02 , 50) .02 50 0. 69317 ImprovedEulersMethod(0, 1 ,. 01 , 100) .01 100 0. 69315 ImprovedEulersMethod(0, 1 ,. 005 , 200) .005 200 0. 69315
Here the method converged rather quickly to the estimate of 0. 69315 for the value of ln (2). The actual value to five decimal places is 0. 69315. Sweet!
Estimating π using the improved Euler’s method I obtained the follow- ing:
Command h n Value ImprovedEulersMethod(0, 1 ,. 02 , 50) .02 50 3. 14152 ImprovedEulersMethod(0, 1 ,. 01 , 100) .01 100 3. 14158 ImprovedEulersMethod(0, 1 ,. 005 , 200) .005 200 3. 14159 ImprovedEulersMethod(0, 1 ,. 0025 , 400) .0025 400 3. 14159
So, my estimate for π out to five decimal places is 3. 14159. The actual value to five decimal places is 3. 14159. Excellent!
go away with more steps. It looks like, with the rounding limitations of Maple, the best estimate for the value of e I can get with this approach is out to 8 decimal places. This estimate is 2. 71828182 , which is correct. The value of e to nine decimal places is 2. 718281728.
For my esimate of the value of ln (2) to nine decimal places I obtained the following:
Command h n Value RungeKuttaMethod(0, 1 ,. 02 , 50) .02 50 0. 693147181 RungeKuttaMethod(0, 1 ,. 01 , 100) .01 100 0. 693147180 RungeKuttaMethod(0, 1 ,. 005 , 200) .005 200 0. 693147181 RungeKuttaMethod(0, 1 ,. 0025 , 400) .0025 400 0. 693147181
So, this time the values settled down, and my estimate for ln(2) out to nine decimal places is 0. 693147181 , which is correct. Hooray!
Finally, for my estimate of the value of π out to nine decimal places using the Runge-Kutta method I obtained the following:
Command h n Value RungeKuttaMethod(0, 1 ,. 02 , 50) .02 50 3. 141592656 RungeKuttaMethod(0, 1 ,. 01 , 100) .01 100 3. 141592650 RungeKuttaMethod(0, 1 ,. 005 , 200) .005 200 3. 141592658 RungeKuttaMethod(0, 1 ,. 0025 , 400) .0025 400 3. 141592657 RungeKuttaMethod(0, 1 ,. 00125 , 800) .00125 800 3. 141592654 RungeKuttaMethod(0, 1 ,. 000625 , 1600) .000625 1,600 3. 141592646
Again, we’re running into round problems, and so it looks like the best estimate we can come up with using this approach is out to eight decimals,
So, I implemented Euler’s method, the improved Euler’s method, and the Runge-Kutta method in Maple and used these methods to calculate estimates of famous numbers out to three, five, and nine decimal places respectively. The nine decimal place estimates ran into problems with rounding error, but other than that the methods worked well, especially the improved Euler’s method and the Runge-Kutta method.