mp 3 on es 204

Upload: tim-acosta

Post on 29-Feb-2016

4 views

Category:

Documents


0 download

DESCRIPTION

Numerical Methods

TRANSCRIPT

  • 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

    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.

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    1.6

    0 0.02 0.04 0.06 0.08 0.1 0.12

  • time value

    0 1.414214

    0.005 1.266092

    0.01 1.167563

    0.015 1.103876

    0.02 1.063665

    0.025 1.038717

    0.03 1.023425

    0.035 1.014127

    0.04 1.008503

    0.045 1.005111

    0.05 1.00307

    time value

    0.055 1.001843

    0.06 1.001106

    0.065 1.000664

    0.07 1.000398

    0.075 1.000239

    0.08 1.000143

    0.085 1.000086

    0.09 1.000052

    0.095 1.000031

    0.1 1.000019

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

  • 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

    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.

    -12

    -10

    -8

    -6

    -4

    -2

    0

    2

    0 1 2 3 4 5 6

    h=1e-8

    h=1e-7

    h=1e-6

    h=5e-6

    h=1e-4

  • H Values

    time 1.00E-04 1.00E-06 1.00E-07 1.00E-08 5.00E-09

    0 1 1 1 1 1

    0.2 0.818731 0.818731 0.818731 0.818731 0.818731

    0.4 0.67032 0.67032 0.67032 0.67032 0.67032

    0.6 0.548812 0.548812 0.548812 0.548812 0.548812

    0.8 0.449329 0.449329 0.449329 0.449329 0.449329

    1 0.367879 0.367879 0.367879 0.367879 0.367879

    1.2 0.301194 0.301194 0.301194 0.301194 0.301194

    1.4 0.246597 0.246597 0.246597 0.246597 0.246597

    1.6 0.201896 0.201897 0.201897 0.201897 0.201897

    1.8 0.165298 0.165299 0.165299 0.165299 0.165299

    2 0.135332 0.135335 0.135335 0.135335 0.135335

    2.2 0.110795 0.110803 0.110803 0.110803 0.110803

    2.4 0.090695 0.090718 0.090718 0.090718 0.090718

    2.6 0.074212 0.074274 0.074274 0.074274 0.074274

    2.8 0.060643 0.06081 0.06081 0.06081 0.06081

    3 0.049333 0.049787 0.049787 0.049787 0.049787

    3.2 0.039528 0.040762 0.040762 0.040762 0.040761

    3.4 0.030018 0.033372 0.033372 0.033371 0.03337

    3.6 0.018204 0.027319 0.027321 0.027319 0.027316

    3.8 -0.00242 0.022358 0.022363 0.022358 0.02235

    4 -0.04907 0.018281 0.018295 0.01828 0.018259

    4.2 -0.16817 0.014901 0.014941 0.014898 0.014842

    4.4 -0.48562 0.01202 0.012128 0.012011 0.011859

    4.6 -1.34337 0.009354 0.009646 0.009329 0.008915

    4.8 -3.67077 0.006332 0.007126 0.006265 0.00514

    5 -9.99381 0.001579 0.003737 0.001396 -0.00166

    Table 2. Computed values for different H sizes

  • Appendix: CC++ Code #include #include #include "header.h" #include #include 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