12-267/Numerical Methods: Difference between revisions
mNo edit summary |
m (Numerical Methods moved to 12-267/Numerical Methods) |
||
(One intermediate revision by one other user not shown) | |||
Line 30: | Line 30: | ||
<math>y_{n+1} = y_n + \frac{f_n + f(t_n + h, y_n + hf_n)}{2} h</math> |
<math>y_{n+1} = y_n + \frac{f_n + f(t_n + h, y_n + hf_n)}{2} h</math> |
||
To determine local error we took the taylor expansions of <math>y</math> and <math>\Phi</math> and compared them. |
|||
<math>\Phi(x_1) = \Phi(x_0 + h) = \Phi(x_0) + h \Phi'(x_0) + \frac{h^2}{2} \Phi''(x_0) + O(h^3)</math> |
|||
<math>\Phi'(x) = f(x, \Phi(x)) \quad \Phi''(x) = \Phi'(x) = f_x(x, \Phi(x)) + f_y(x, \Phi(x))\Phi'(x)</math> |
|||
<math>\Phi(x_0 + h) = y_0 + h f(x_0, y_0) + \frac{h^2}{2}(f_x + f_y f) + O(h^3)</math> |
|||
We compare this to the computed value <math>y_1</math> |
|||
<math>y_1 = y_0 +\frac{h}{2}(f(x_0, y_0) + f(x_0 + h, y_0 + hf(x_0, y_0)))</math> |
|||
Taking the taylor expansion we get |
|||
<math>y_1 = y_0 + h f(x_0, y_0) + \frac{h^2}{2}(f_x + f_y f) + O(h^3)</math> |
|||
So we have shown that the Improved Euler Formula is accurate up to an error term proportional to <math>h^3</math> |
|||
Local truncation error is proportional to <math>h^3</math> |
Local truncation error is proportional to <math>h^3</math> |
Latest revision as of 16:59, 26 October 2012
Summary of Numerical Methods
Based largely off of a note available here posted by Simon1 --Twine 20:55, 25 October 2012 (EDT)
Numerical methods: and , is a solution.
1. Using the proof of Picard's Theorem:
2. The Euler Method:
if h is constant
Backward Euler formula:
Local truncation error: where
Local error is proportional to .
Global error is proportional to h.
3. Improved Euler Formula (or Heun Formula):
To determine local error we took the taylor expansions of and and compared them.
We compare this to the computed value
Taking the taylor expansion we get
So we have shown that the Improved Euler Formula is accurate up to an error term proportional to
Local truncation error is proportional to
Global truncation error is proportional to
4. The Runge-Kutta Method:
where
Local truncation error is proportional to .
Global truncation error is proportional to .
Python Example of Euler's Method
In class on October 15th we discussed Euler's Method to numerically compute a solution to a differential equation. and are given as well as an increment amount , , and we use the guess where f computes the derivative as a function of x and y.
Here is an example of code (written in Python) which carries out Euler's Method for the example we discussed in class, :
def f(x, y): return -y def euler(x, y, f, h, x_max): """Take in coordinates x and y, a function f(x, y) which calculates dy/dx at (x, y), an increment h, and a maximum value of x. Return a list containing coordinates in the Euler's Method computation of the solution to Phi' = f(x, Phi(x)), Phi(x) = y, with the x values of those coordinates separated by h, and not exceeding x_max. """ if x > x_max: # we have already calculated all our values return [] x_next, y_next = (x + h, y + f(x, y)*h) # calculate the next x, y values # return the current coordinates, and every coordinates following it, in a list return [(x_next, y_next)] + euler(x_next, y_next, f, h, x_max) if __name__ == '__main__': print euler(0, 1, f, 0.01, 1)[-1]