Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECE 204 Numerical methods

Project 4

In this course, we have described how Euler’s method is O(h), Heun’s method is O(h2) and the 4th-order Runge-Kutta method is O(h4). This is by looking at the error when estimating the value ofthe solution at a point y(tf) and when there are n points approximating the solution between [t0, tf] (tk  = t0  + kh where h = (tf – t0)/n and k runs from 1 to n and tn = tf).

Another measure of error is the root-mean-squared error (RMSE). For a sequence of values from 0 to n, if ak is an approximation to yk, the root-mean-squared error is defined as:

 n k  0

Note the name: we are taking the square root of the average (mean) ofthe sum of errors squared, hence the name.

Suppose one real-valued function a approximates a real-valued function y on the interval [t0, tf]. In this case, the root-mean-squared error is given by:


You will recognize that           y t   a t dx  is the formula for the average (mean) value of the square

of the error on the given interval, so once again, the name is appropriate.

Your task is to determine if there is a relationship between h and the RMSE for Euler’s, Huen’s and the 4th- order Runge-Kutta method as h gets small (but not too small).


Required approach:

1.   Choose a value of n.

2.   Use Euler’s, Heun’s and 4th-order Runge-Kutta to approximate solutions at tk for k = 1, … , ntf

3.   You now have to approximate y t   a t dt  where a(t) is the approximating function, but we t0

only know that a(tk) = yk  and at best we can interpolate between these points. Instead, you can choose to use either the trapezoidal rule or Simpson’s rule, whichever you determine is more appropriate:

tft y t   a t dt  n1k  y tk   yk   y tk  yk

tft0   y t   a t dt  12k  y t2k   y2k 2   4  y t2k  y2k2    y t2k  y2k

Of course, ifyou use Simpson’s rule, you must ensure your initial n is even.

4.   Repeat this with 2n (so halving h). Recalculate the RMSE. Determine if there is a relationship between the h and the RMSE. (Is it O(h), O(h2), etc.?)

 

You will use ODEs that are tailored to your uWaterloo Student ID number. If your uWaterloo Student ID number is 20123456, then one ODE will be

y(1)(t) + 1.456y(t) = 0

and the other will be

y(1)(t) + 1.123y(t) = 1.2345 cos(t)

In all cases, your initial condition will be y(0) = 1. You can chose any tf you wish, but tf  = 10 is reasonable.

With Matlab (using format long), you are capable of finding a solution to these IVPs. You will then implement solutions to each of these, so in the above case, I would implement, respectively,

double y1( double t ) {

return std::exp(-1.456*t);

}

double y2( double t ) {

return 0.6131200387063277*std::cos(t)

+ 0.5459661965327940*std::sin(t)

+ 0.3868799612936723*std::exp(-1.123*t);

}

These are the exact solutions, and you will then proceed to test the approximations of Euler’s, Heun’s and the 4th-order Runge-Kutta methods in comparison with the exact solution by calculating the RMSE.

You may use Matlab or C++ or any other programming language you wish. You can, if you wish, start with the code at

https://replit.com/@dwharder/ECE-204-Project-4