Calculus 4.20
1. Solve the following problem using the forward Euler’s method with stepsizes of h = 0.2 and 0.1 using Matlab programs. Compute the error and relative error using the true solution $Y\left(x\right)$. For selected values of $x$, observe the ratio by which the error decreases when $h$ is halved. Plot the numerical solution and true solution on the same figure for each step size.

$Y'(x)=xe^{-x}-Y(x),\;0\leq x\leq10,\;Y(0)=1;$

The true solution is

$Y(x)=(1+\frac{x^2}2)e^{-x}$

Solution:

2. Use the backward Euler’s method to solve the following problem: Consider the linear equation

$Y'(x)=\lambda Y(x)+(1-\lambda)\cos(x)-(1+x)\sin(x),\;Y(0)=1;$

The true solution is $Y(x)=\sin(x)+cos(x)$. Solve this problem with several values of $\lambda$ and $h$, for $0\;\leq\;x\;\leq\;10$. Plot the numerical solution and true solution on the same figure for each stepsize and comment on the results.
(a) $\lambda\;=\;-1;\;h\;=\;0.25\;and\;0.125.$

Solution:

(b) $\lambda\;=\;1;\;h\;=\;0.25\;and\;0.125.$

Solution:

Author: Little Twain