0
$\begingroup$

I'm trying to investigate nonlinear system numerical methods. So if we have a simple DE $x' = x$,

a) how to find the explicit solution $x(t)$ satisfying $x(0) = 1$?

b) how to use Euler's method to approx the value of $x(1) = e$ using $\Delta t = 0.1$. I.e., recursively determine $t_k$ and $x_k$ for $k = 1,...10$ with $\Delta t = 0$, starting with $t_0 = 0$ and $x_0 = 1$.

c) Repeat using $\Delta t = 0.05$

d) Again using Euler's method but reduce step size by a factor of 5, so that delta $t = 0.01$ to approx x(1)

e) Repeat parts b, c, and d with Improved euler's method using the same step sizes

f) Repeat using Runge-Kutta

g) Calculate the error in each case, since we now have 9 different approx for the value of $x(1) = e$, three for each method.

h) Calculate how the error changes as we change the step size from 0.01 to 0.05 and then from 0.05 to 0.01


My approach:

So for part $a$, $dx/dt = x$, and we get $\ln|x| = t + c $

for part $b$, eulers method is $ x_{k+1} = x_k + f(t_k,x_k)(\Delta t) $

$\endgroup$
5
  • $\begingroup$ @Amzoti, the differential equation is for x' = x $\endgroup$
    – mary
    Commented Apr 20, 2013 at 4:58
  • $\begingroup$ OK, this is just a simple differential equation. I guess its not nonlinear then. Thanks for clarifying $\endgroup$
    – mary
    Commented Apr 20, 2013 at 5:01
  • 1
    $\begingroup$ you are very welcome, this is very important problem to help you getting a bunch of things straight. I would recommend digesting it to the fullest extent! regards $\endgroup$
    – Amzoti
    Commented Apr 21, 2013 at 1:01
  • $\begingroup$ @Amzoti, thanks. $\endgroup$
    – mary
    Commented Apr 21, 2013 at 5:21
  • $\begingroup$ Did you get everything working and it is all clear? Regards $\endgroup$
    – Amzoti
    Commented Apr 21, 2013 at 5:26

2 Answers 2

4
$\begingroup$

I am going to do some and you can work the others from these as guides/examples.

Part a.

We are given the first-order linear ordinary differential equation: $x ' = x, x(0) = 1.$

Solving this yields the exact solution: $x(t) = e^{t}.$

Part b.

$x'(t) = f(t, x) = x, x(0) = 1$

$x_0 = 1, t_0 = 0, h = \frac{1}{10}, n = 0,..., 10$

$x_{n} = x_{n-1} + hf(t_n, x_n) = x_{n-1} + 0.1\left[x_{n-1}\right] = 1.1x_{n-1}$

This yields:

$t ~~~~~|~~ x_{n+1}$

$0.0 ~~|~~ 1.0$

$0.1 ~~|~~ 1.1$

$0.2 ~~|~~ 1.21$

$0.3 ~~|~~ 1.331$

$0.4 ~~|~~ 1.4641$

$0.5 ~~|~~ 1.61051$

$0.6 ~~|~~| 1.77156$

$0.7 ~~|~~ 1.94872$

$0.8 ~~|~~ 2.14359$

$0.9 ~~|~~ 2.35795$

$1.0 ~~|~~ 2.59374$

Part c

Just repeat Part a with a new step size.

Part d

Just repeat Part a with a new step size.

Part e

This is just the Improved Euler Method, which is given by:

$\displaystyle y_{n+1} = y_n + \frac{h}{2}\left(f(x_n, y_n) + f(x_n + h, y_n + hf(x_n, y_n))\right]$

From this, we have our iteration formula:

$\displaystyle x_{n+1} = x_n(1 + h + \frac{h^2}{2}) = x_n(1 + 0.1 + \frac{0.1^2}{2}) = 1.105x_n$

Now, just use the given starting points aain, and you have:

$t ~~~~~|~~ x$

$0.0 ~~|~~ 1.$

$0.1 ~~|~~ 1.105$

$0.2 ~~|~~ 1.22103$

$0.3 ~~|~~ 1.34923$

$0.4 ~~|~~ 1.4909$

$0.5 ~~|~~ 1.64745$

$0.6 ~~|~~ 1.82043$

$0.7 ~~|~~ 2.01157$

$0.8 ~~|~~ 2.22279$

$0.9 ~~|~~ 2.45618$

$1.0 ~~|~~ 2.71408$

Repeat this for the other two step sizes using the same algorithm.

Part f

This is just doing the same thing (you already have a closed form solution to compare against) is using Runge-Kutta.

We have: $x' = f(t, x) = x, a \le t \le b, x(0) = \alpha = 1.$

$\displaystyle h = \frac{b-a}{N} = 0.1$ (for first case only of course).

$t = a = 0$

$w = \alpha = 1$

For $i = 1, 2, \ldots, N$, do steps 3 - 4:

Step 3 (of course, there is no $t$ term in our problem - which simplifies things):

$K_1 = hf(t, w) = 0.1 w$

$K_2 = hf(t + h/2, w + k_1/2) = 0.1(w + 0.1w/2) = 0.105 w$

$K_3 = hf(t+h/2, w + K_2/2) = 0.1(w + 0.105 w/2) = 0.10525 w$

$K_4 = hf(t+h, w + K_3) = 0.1(w + 0.10525 w) = 0.110525 w$

Step 4:

$w = w + (K_1 + 2K_2 + 2K_3 + K_4)/6$ (this is computing the $w_i's)$

$t ~~~~~|~~ x$

$0.0 ~~|~~ 1.$

$0.1 ~~|~~ 1.10517$

$0.2 ~~|~~ 1.2214$

$0.3 ~~|~~ 1.34986$

$0.4 ~~|~~ 1.49182$

$0.5 ~~|~~ 1.64872$

$0.6 ~~|~~ 1.82212$

$0.7 ~~|~~ 2.01375$

$0.8 ~~|~~ 2.22554$

$0.9 ~~|~~ 2.4596$

$1.0 ~~|~~ 2.71828$

Part g

For the error, you are just comparing the absolute value of the actual value versus the calculated value from the method.

Part h

You are just putting together tables from the above values for the different step sizes and comparing methods versus step size.

$\endgroup$
11
  • $\begingroup$ I'm confused on how part e, f, and g work out for this example. Could you provide a setup and some calculation? Thanks! $\endgroup$
    – mary
    Commented Apr 20, 2013 at 21:35
  • $\begingroup$ could you provide the setup of the RK-4 that this DE takes? I know how what the k1, k2, k3's are but cannot seem to format it for this problem. A starting point/calculation would be nice. THanks $\endgroup$
    – mary
    Commented Apr 20, 2013 at 23:25
  • $\begingroup$ Nice examples for teaching! +1 $\endgroup$
    – amWhy
    Commented Apr 21, 2013 at 0:09
  • $\begingroup$ @Mary: Added RK-4. $\endgroup$
    – Amzoti
    Commented Apr 21, 2013 at 0:38
  • $\begingroup$ @amWhy: Just finished adding the RK-4 solution. Not sure if the OP is working as hard as needed. $\endgroup$
    – Amzoti
    Commented Apr 21, 2013 at 0:39
1
$\begingroup$

You are correct for part a. You should be able to evaluate $c$ from the fact that $x(0)=1$ You can also remove the absolute value bars if you are going to only work in the area $x \gt 0$ (as you are).

The rest are basically writing a program to implement the various methods. What is your question? Note that the comparison you are given, $x(1)=3$ is incorrect. What should it be, based on your solution to a?

Added: there is a good discussion of what is going on in Chapter 16 of Numerical Recipes. Obsolete versions are free on line. One step of Euler's method is $y(x+h)=y(x)+hy'(x)$. Essentially you take one step up the tangent line. You are supposed to write a program that implements this over a range, with $h$ as an input parameter, then run the program for several sizes of $h$. It will take $\frac 1h$ steps to get to $x=1$. You should discover that as $h$ gets smaller, the answer gets more accurate. It is not exact because you are only fitting (locally) the first term in the Taylor series of the solution. You should observe how quickly the error falls with $h$. Then do the same for Runge-Kutta. You will have to look up the formulas. The Numerical Recipes chapter gives some advice on how to structure the problem so you can reuse some of what you did before. Because Runge-Kutta is a higher order method, the error should be smaller and decrease faster with $h$.

$\endgroup$
1
  • $\begingroup$ I pretty much need help through this example. If you could work it out, I can repeat it for other calculations. I want to see one done entirely to put me on the right track. Thanks $\endgroup$
    – mary
    Commented Apr 20, 2013 at 5:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .