Вы находитесь на странице: 1из 6

MP 3

ES 204

Submitted by:
Timothy John S. Acosta
Submitted on:
May 26, 2015

Executive Summary:
A. Define the Problem
Solve the following equation:
=

50
50

(0) = 2

B. Problems Encountered
The trapezoidal method was used to solve this differential equation. Since the method solves for
the values implicitly and the differential equation is nonlinear, the Newton Rhapson Method
was used to solve for the roots.
C. References
Burden R., Faires J. (2011). Numerical Analysis 9th Edition. Brooks/Cole, 20 Channel Center
Street. Boston, MA 02210, USA.
D. Results

1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0

0.02

0.04

0.06

0.08

0.1

0.12

Figure 1. Solutions for different values of h


In the graph above, the blue plot shows the solution for a h value of 0.005. The purple
plot shows the solution for a h value of 0.02. And the orange plot shows the solution for a value
of 0.5. As you can see, all the choses values where within the region of absolute stability since no
overflow can be observed. Therefore any value between 0.5 and below can be used but the
problem would be the accuracy of the solution. For a low relative error, we can use a value of 0.05
for the h values. This would give us relative errors of around 0.001% to 0.820921% which may be
acceptable.

time
0
0.005
0.01
0.015
0.02
0.025
0.03
0.035
0.04
0.045
0.05

value
1.414214
1.266092
1.167563
1.103876
1.063665
1.038717
1.023425
1.014127
1.008503
1.005111
1.00307

time
0.055
0.06
0.065
0.07
0.075
0.08
0.085
0.09
0.095
0.1

The tables above show the values for each time step from 0 to 0.1.

value
1.001843
1.001106
1.000664
1.000398
1.000239
1.000143
1.000086
1.000052
1.000031
1.000019

Executive Summary:
A. Define the Problem
Solve the differential equation:
= 5 6

(0) = 1.0 0 < < 5

B. Problems Encountered
Like the first problem. The trapezoidal method was also used with the newton rhapson
method to solve for the stiff differential equation.
C. Reference
Burden R., Faires J. (2011). Numerical Analysis 9th Edition. Brooks/Cole, 20 Channel Center
Street. Boston, MA 02210, USA.
D. Results
2

0
0

-2
h=1e-8
-4

h=1e-7
h=1e-6
h=5e-6

-6

h=1e-4
-8

-10

-12

Figure 2. Solution to the differential equation with different values of h


As observed in the figure above, solutions with a time steps above 1e-6 do not converge to a single
value. It can be said the region of stability for this problem is for time steps 1e-6 and below. It can also be
observed the differences in the values are of 1e-3 for the later values of x. But for the earlier values of x,
there is almost 0% relative error.

time
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
2.2
2.4
2.6
2.8
3
3.2
3.4
3.6
3.8
4
4.2
4.4
4.6
4.8
5

H Values
1.00E-04 1.00E-06 1.00E-07 1.00E-08 5.00E-09
1
1
1
1
1
0.818731 0.818731 0.818731 0.818731 0.818731
0.67032 0.67032 0.67032 0.67032 0.67032
0.548812 0.548812 0.548812 0.548812 0.548812
0.449329 0.449329 0.449329 0.449329 0.449329
0.367879 0.367879 0.367879 0.367879 0.367879
0.301194 0.301194 0.301194 0.301194 0.301194
0.246597 0.246597 0.246597 0.246597 0.246597
0.201896 0.201897 0.201897 0.201897 0.201897
0.165298 0.165299 0.165299 0.165299 0.165299
0.135332 0.135335 0.135335 0.135335 0.135335
0.110795 0.110803 0.110803 0.110803 0.110803
0.090695 0.090718 0.090718 0.090718 0.090718
0.074212 0.074274 0.074274 0.074274 0.074274
0.060643 0.06081 0.06081 0.06081 0.06081
0.049333 0.049787 0.049787 0.049787 0.049787
0.039528 0.040762 0.040762 0.040762 0.040761
0.030018 0.033372 0.033372 0.033371 0.03337
0.018204 0.027319 0.027321 0.027319 0.027316
-0.00242 0.022358 0.022363 0.022358 0.02235
-0.04907 0.018281 0.018295 0.01828 0.018259
-0.16817 0.014901 0.014941 0.014898 0.014842
-0.48562 0.01202 0.012128 0.012011 0.011859
-1.34337 0.009354 0.009646 0.009329 0.008915
-3.67077 0.006332 0.007126 0.006265 0.00514
-9.99381 0.001579 0.003737 0.001396 -0.00166
Table 2. Computed values for different H sizes

Appendix: CC++ Code


#include<iostream>
#include<math.h>
#include "header.h"
#include<iomanip>
#include<fstream>
using namespace std;
double evalfunc(double t,double y){
return 5*y-6*exp(-t);
}
double dfunc(double t,double y){
return 5;
}
int main(){
double h=5e-9;
double t=0;
double w=1;
double n=(5)/h;
double k1,wo,FLAG,TOL=1e-8;
int j,i,writz=0.04*n;
ofstream writer;
writer.open("data.txt");
cout<<fixed;
writer<<fixed;
cout<<setprecision(8);
writer<<setprecision(8);
cout<<" time
value"<<endl;
writer<<" time
value"<<endl;
cout<<" "<<t<<"
"<<w<<endl;
writer<<" "<<t<<"
"<<w<<endl;
for(i=1;i<=n;i++){
k1=w+h/2*evalfunc(t,w);
wo=k1;
j=1;
FLAG=0;
while(FLAG==0){
w=wo-(wo-h/2*evalfunc(t+h,wo)-k1)/(1-h/2*dfunc(t+h,wo));
if((w-wo)<TOL)
FLAG=1;
else {
j++;
wo=w;
}
}
t=i*h;
if(i%(writz)==0){
cout<<" "<<t<<"
"<<w<<endl;
writer<<" "<<t<<"
"<<w<<endl;
}
}
return 0;
}

Вам также может понравиться