Question 7.2: LOCAL AND GLOBAL TRUNCATION ERRORS In Example 7.1, calculate...

LOCAL AND GLOBAL TRUNCATION ERRORS

In Example 7.1, calculate the local and global truncation errors at each point and tabulate the results.

The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

Starting with the initial condition y_0=\frac{1}{2} , the Euler’s computed value at x_1 = 0.1 is y^{c}_{1} = 0.5250 while the actual value is y^{a}_{1} = 0.522007 . At this stage, the global and local truncation errors are the same because Euler’s method used the initial condition, which is exact, to find the estimate. At x_2 = 0.2 , the computed value is y^{c}_{2}= 0.543992, which was calculated by Euler’s method using the estimated value y^{c}_{2} = 0.5250 from the previous step. If instead of y^{c}_{1} we use the actual value y^{a}_{1} = 0.522007, the computed value at x_2 is

\overset{\sim }{y_{2} }=y^{a}_{1}+hf(x_1,y^{a}_{1} )=0.522007+0.1f(0.1,0.522007)=0.541148

Therefore, local truncation error at x_2  is

y^{a}_{2}-\overset{\sim }{y_2}=0.538525-0.541148=-0.002623

The global truncation error at x_2 is simply calculated as

y^{a}_{2}-y^{c}_{2}=0.538525-0.543992=-0.005467

It is common to express these errors in the form of percent relative errors, hence at each point, we evaluate

\frac{(local   or   global)   truncation   error}{actual   value}\times 100

With this, the (local) percentage relative error at x_2  is

\frac{y^{a}_{2}-\overset{\sim }{y_2} }{y^{a}_{2} }\times 100= \frac{-0.002623}{0.538525}\times 100\cong -0.49%

The (global) percentage relative error at x_2 is

\frac{y^{a}_{2}-y^{c}_{2} }{y^{a}_{2} }\times 100= \frac{-0.005467}{0.538525}\times 100\cong -1.02%

The following MATLAB script uses this approach to find the percentage relative errors at all xi, and completes the table presented earlier in Example 7.1.

disp(' x yEuler yExact e_local e_global')
h = 0.1; x = 0:h:1; y0 = 1/2;
f = @(x,y)((exp(-x)-y)/2);
yEuler = EulerODE(f,x,y0);
y _ exact = matlabFunction(dsolve('2*Dy + y = exp(-x)','y(0)=1/2','x'));
ytilda = 0*x; ytilda(1) = y0;
for n = 1:length(x)−1,
ytilda(n+1) = y_exact(x(n)) + h*f(x(n),y_exact(x(n)));
end
for k = 1:length(x),
x_coord = x(k);
yE = yEuler(k);
yEx = y_exact(x(k));
e_local = (yEx-ytilda(k))/yEx*100;
e_global = (yEx-yE)/yEx*100;
fprintf('%6.2f %11.6f %11.6f %6.2f %6.2f\n',x _ coord,yE,yEx,e _ local,e _ global)
end
x yEuler yExact e_local e_global
0.00 0.500000 0.500000 0.00 0.00
0.10 0.525000 0.522007 −0.57 −0.57
0.20 0.543992 0.538525 −0.49 −1.02 Hand calculations (see above)
0.30 0.557729 0.550244 −0.42 −1.36
0.40 0.566883 0.557776 −0.36 −1.63
0.50 0.572055 0.561671 −0.31 −1.85
0.60 0.573779 0.562416 −0.27 −2.02
0.70 0.572531 0.560447 −0.23 −2.16
0.80 0.568733 0.556151 −0.20 −2.26
0.90 0.562763 0.549873 −0.17 −2.34
1.00 0.554953 0.541917 −0.15 −2.41 Max. % rel. err. reported earlier

Related Answered Questions