I am posting this on our web

advertisement
I am posting this on our web
site as an example of a very
good solution set for Quiz 4.
Note that all the information
is present (solutions, details
of the methods used, tables to
compare results from various
methods, graphs to compare
solutions) without showing
maple code or messy
calculations. Also note that
the maple code they want to
show is added at the end of
the paper.
Problem 1
Euler's method is a geometrically motivated numerical approximation method for
describing a curve when only an initial condition and a differential equation are known.
This is done by representing the curve as small line segments, each with slope equal to
the slope of the function at the left endpoint of the line segment. Below is a graphical
representation of Euler's method being used to approximate a curve. The first line
segment (from x=0 to x=0.2) is tangent to the curve at x=0 because it's slope is defined
by the slope of the curve at x=0 (the left endpoint of the line segment). At x=0.2, a new
line segment begins with slope equal to the slope of the function at x=0.2. This process is
repeated as shown below. The horizontal lines in the diagram represent the error between
the actual and the approximation.
It should be noted that the second derivative of the function can be used to give
some indication of the accuracy of the Euler approximation. In general, the larger the
value of the second derivative at the point which is being approximated, the less accurate
the Euler’s method approximation will be. This is simply because the slope of the
function will change a greater amount in a smaller step size. The second derivative can
also indicate if the Euler approximations will, in general, be lower or higher than the
actual function. If the second derivative is negative (the graph is concave down) the
approximation will be too high, and if the second derivative is negative (the graph is
concave down) the approximation will be too low.
Of course, there are other more advanced methods of error approximation, one of
which is discussed in the appendix, and many of which are used throughout this report.
In order to derive a general algorithm, let the following be true:

dy
= f(x,y). Thus, f(x,y) defines a direction field.
dx
The known initial condition from which we will approximate a solution to the
differential equation f(x,y) is ( x0 , y0 ).

The step size will be defined as h where h>0.

Thus, the x value of the Euler approximation for the point one step away from ( x0 , y0 )
will be the initial x value plus h. The y value of the Euler approximation will be the
function f evaluated at ( x0 , y0 ) multiplied by the step size h plus the initial y value y0 .
Thus, the Euler approximation for one step size away from the point will be ( x0h ,
y0f( x0, y0 ) h ).
To find any value where n steps have been taken, the coordinates of the point will be
( x0h n , yn1f( xn1, yn1 ) h ).
Figure 1—Euler’s Method
Problem 2
dx
2 x3, x( 0 )3 that we have created. The equation
dt
is a non-trivial first-order, linear, non-homogeneous differential equation.
We have the equation
For comparison’s sake, we will compare the different methods of numerical
analysis to determine which is the most accurate. Using Euler’s method, the Improved
Euler’s method, the Runge-Kutta Method, and using the analytic method (actual), we can
determine the values of the function over the x interval [0,3].
XCoordinate
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3.0
Euler Method
3
3.9
4.98
6.276
7.8312
9.69744
11.936928
14.6243136
17.84917632
21.71901158
26.36281390
31.93537668
38.62245202
46.64694242
56.27633090
67.83159708
81.69791650
98.33749980
118.3049998
142.2659998
171.0191998
205.5230398
246.9276478
296.6131774
356.2358129
427.7829755
513.6395706
616.6674847
740.3009816
888.6611779
1066.693414
Step Size = 0.1
Improved
Runge-Kutta Method
Euler Method
3
3
3.99
3.99631227480901030
5.178
5.21321075275598123
6.6036
6.69953391357977688
8.31432
8.51493310566999462
10.367184
10.7322666080430764
12.83062080 13.4405237401043767
15.78674496 16.7483963076141436
19.33409395 20.7886407811573940
23.59091274 25.7234062751195546
28.69909529 31.7507421568438774
34.82891435 39.1125464586793399
42.18469722 48.1042740902530142
51.01163666 59.0867944753164878
61.60396399 72.5008745014731062
74.31475679 88.8848680340881288
89.56770815 108.896321936311140
107.8712498 133.338365720208856
129.8354998 163.191943937828711
156.1925998 199.655184910562154
187.8211198 244.191485801350780
225.7753438 298.588243851543154
271.3204126 365.028590871967480
325.9744951 446.179009943766972
391.5593942 545.296350693079376
470.2612730 666.358538036121444
564.7035276 814.224220192932648
678.0342331 994.827763201921016
814.0310797 1215.41741774582033
977.2272957 1484.84621675527888
1173.062755 1813.92727852646817
Analytic
Solution
3
3.996312411
5.213211141
6.699534600
8.514934180
10.73226823
13.44052615
16.74839985
20.78864591
25.72341359
31.75075245
39.11256075
48.10429371
59.08682118
72.50091046
88.88491614
108.8963859
133.3384502
163.1920550
199.6553302
244.1916751
298.5884897
365.0289090
446.1794204
545.2968788
666.3592160
814.2250886
994.8288729
1215.418833
1484.848020
1813.929571
XCoordinate
0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
Euler Method
3
4.8
7.32
10.848
15.7872
22.70208
32.382912
45.9360768
64.91050752
91.47471052
128.6645947
180.7304326
253.6226056
355.6716478
498.5403069
698.5564297
Step Size = 0.2
Improved
Runge-Kutta Method
Euler Method
3
3
5.16
5.21321075275598123
8.184
8.51493310566999462
12.4176
13.4405237401043767
18.34464
20.7886407811573940
26.642496
31.7507421568438774
38.2594944 48.1042740902530142
54.52329216 72.5008745014731062
77.29260902 108.896321936311140
109.1696526 163.191943937828711
153.7975136 244.191485801350780
216.2765190 365.028590871967480
303.7471266 545.296350693079376
426.2059773 814.224220192932648
597.6483683 1215.41741774582033
837.6677156 1813.92727852646817
Analytic
Solution
3
5.213211141
8.514934180
13.44052615
20.78864591
31.75075245
48.10429371
72.50091046
108.8963859
163.1920550
244.1916751
365.0289090
545.2968788
814.2250886
1215.418833
1813.929571
XCoordinate
0
0.3
0.6
0.9
1.2
1.5
1.8
2.1
2.4
2.7
3.0
Euler Method
3
5.7
10.02
16.932
27.9912
45.68592
73.997472
119.2959552
191.7735283
307.7376453
493.2802325
Step Size = 0.3
Improved
Runge-Kutta Method
Euler Method
3
3
6.51
6.69953391357977688
12.126
13.4405237401043767
21.1116
25.7234062751195546
35.48856
48.1042740902530142
58.491696
88.8848680340881288
95.2967136 163.191943937828711
154.1847418 298.588243851543154
248.4055868 545.296350693079376
399.1589388 994.827763201921016
640.3643022 1813.92727852646817
Analytic
Solution
3
6.699534600
13.44052615
25.72341359
48.10429371
88.88491614
163.1920550
298.5884897
545.2968788
994.8288729
1813.929571
For the Euler’s Method and Improved Euler’s Method columns, the Maple loops
used to generate the numbers can be seen in the appendix. The analytic solutions and
Runge-Kutta approximation are more trivial to do in Maple (i.e. we used preprogrammed packages/algorithms) and are not included.
In the previous pages, the tables and graphs display the differences between the
numerical methods used to approximate a differential equation. As the step size gets
bigger, the error between the actual value and the value that the approximation will
produce will become greater and greater, indicating greater error. This is seen through
the tables and graphs on the previous pages. As expected, the Runge-Kutta Method
produces the most accurate approximation, followed by the Improved Euler’s Method
and finally Euler’s Method. This holds true for all of the three step sizes used.
Problem 3
The problem gives a differential equation model as well as known initial values
for the constants. Below are printed the original equation and the differential equation
with the constant values plugged in:
d
C( t )k ( AC( t ) ) ( BC( t ) )
dt
d
C( t )0.01 ( 70t ) ( 50t )
dt
Next, maple can be used to find an exact, analytic solution for this differential
equation for the concentration C(t) in terms of time t. This equation is necessary because
once Euler’s method has been used to approximate this curve, the analytic solution will
provide a basis for which to measure the error in the Euler’s method approximation.
Maple’s output is below:
t
  

5

10  77 e   
C( t )
t
7  5 
e 1
5
Euler’s Method was then applied, using the second equation listed to find the
slopes of the approximation lines. We did 200 steps of Euler’s method using Maple
loops. The appendix contains a sample of the Maple code used to accomplish this.
Below are a graph and table of values comparing Euler’s method to the actual
functional value. It is extremely difficult to see the difference in the graph because of the
large number of steps which were used to approximate the graph. The large number of
steps also meant that our table could only provide a sampling of the total points which
were actually used in the approximation.
Comparison of Euler’s Approximation to Functional Value at Various Times
A
B
C
D
Time ( t )
Euler Aproximation
Actual Value
Error
0
0
0.
0.
1
22.50222896
21.82955205
0.67267691
2
32.20721719
31.62701221
0.58020498
3
37.56038247
37.10481347
0.45556900
4
40.90383549
40.54711996
0.35671553
5
43.15379412
42.87138625
0.28240787
6
44.74409038
44.51778986
0.22630052
7
45.90727413
45.72401049
0.18326364
8
46.77942834
46.62973155
0.14969679
9
47.44556801
47.32244692
0.12312109
10
47.96155608
47.85974445
0.10181163
11
48.36559616
48.28105134
0.08454482
12
48.68466759
48.61423361
0.07043398
13
48.93832677
48.87950368
0.05882309
14
49.14105506
49.09183812
0.04921694
15
49.30376534
49.26253010
0.04123524
16
49.43480064
49.40021968
0.03458096
17
49.54061551
49.51159642
0.02901909
18
49.62625253
49.60189124
0.02436129
19
49.69568300
49.67522796
0.02045504
20
49.75205527
49.73487955
0.01717572
In summary, we approximated the given equation using Euler's Method with a
step size of .1 units (which on the given interval of t = 0 to 20 is 200 individual steps).
Our error analysis was done by finding the average error between the
approximation of the value of p(x) and the actual value at each of the 200 steps. Maple
does this calculation automatically by using the loop above and shows that the average
deviation of the Euler approximation from the analytic solution to the differential
equation was .1859789992 . This is fairly low average error considering that it is an
average approximation over a range of 20. This small error was made possible by the
large number of steps used in Euler's Method.
Problem 4
The above methods used, the Simpson's Method, Euler's Method, the RungeKutta Method, all are approximations of the actual integral that is being evaluated. Even
to a certain extent, the method that Maple uses is an approximation of the actual integral,
yet Maple would probably have the most accurate way of finding the integral because it
can use any technique it wants, even a combination of techniques. The other methods are
used in a repetitive manner to calculate the approximate integral. The most accurate
method in this case, is the Simpson's Rule, because we used 100 intervals over the
selected area to approximate our answer, hence making our approximation much more
accurate. The second most accurate method is the Runge-Kutta Method, using advanced
algorithms to determine an incredibly accurate answer much of the time. And finally the
Euler's method is the least accurate in this case, because of the step size of 0.1 used.
Perhaps, with a smaller step size, the Euler approximation could be the most accurate
answer. As with all these methods, the approximations can be much closer to the actual
answer by increasing the intervals you approximate at, and hence why in this case,
Simpson's Method is the most accurate method to 10 decimal places.
A
X
B
Simpsons Method
C
Maple Method
D
Euler
E
RungeKuttaMethod
0.5
0.6914624612
0.6914624612
0.6914858859
0.691462666101979706
1.
0.8413447460
0.8413447460
0.8415016367
0.841342872926164276
1.5
0.9331927988
0.9331927987
0.9335967898
0.933190615502182408
2.
0.9772498678
0.9772498677
0.9779396263
0.977249154024164234
2.5
0.9937903348
0.9937903346
0.9947437791
0.993792205982602428
3.
0.9986501020
0.9986501019
0.9998335938
0.998650935381134808
Appendix of Maple Code
Euler’s Method:
f:=x->2*x+3;
initial_point:=[0,3];
step:=0.1;
x_coord:=[seq(step*i,i=0..100)]:
Euler:=[seq([x_coord[i],y_coord[i]],i=1..101)]:
y_coord[1]:=initial_point[2]:
for i from 2 to 101 do
y_coord[i]:= y_coord[i-1]+step*f(y_coord[i-1]):
od:
Improved Euler’s Method:
(uses the same code as before except for the loop below)
for i from 2 to 101 do
y_coord2[i]:= y_coord2[i-1]+step*(f(y_coord[i1])+f(y_coord[i]))/2:
od:
Error Evaluation:
(there are numerous ways to evaluate error between various methods. In addition to using
tables and graphs, we also used a Maple loop to find the average error between two
methods)
sum('Euler_Aprox[i,2]subs(t=Euler_Aprox[i,1],Analytic_Solution)',
'i'=1..201)/200;
Download