Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
MATH 157 final project
Math 157: Intro to Mathematical Software
UC San Diego, winter 2018
Numerical Solutions to ODE
Preview of Ordinary Differential Equations
An ordinary differential equation (frequently called an "ODE") is an equality involving a function and its derivatives. An ODE of order n is an equation of the form where y is a function of x, is the derivative of x.
Sovling Differential Equations with Sage
Example: Solve
Example: Solve
Example: Solve for y in terms of t in
Note we did not get an expression of y directly; let's try a different input.
Solve the same equation by adding an initial condition: y(1) = 3
Visualizing Solutions to ODE
The idea of direction field (or slope field) related to the first order ODE is similar to vector calculus.
At each point , we plot a small vector that has slope . A collection of all points where the vectors have slope m generate direction field.
Example: Newton's Equation (MATLAB assignment exercise 2.5)
Newton's law of cooling models the temperature change of an object at a certain temperature when placed in a surrounding environment of a different temperature. The law can be stated as follows: where k is a positive proportionality constant and A represents temperature of the environment.
Plot a direction field with A = 1, k = 2, and where the minimum value of t is zero.(We start range of t from 0 because we do not need to worry about negative times)
We can see that all solutions approach to 1 which is environmental temperature under our setting.
Euler's Method
What if the differential equation cannot be solved with a nice formula? We introduce Euler's Method here. Euler's Method is an algorithmic way of plotting an approximate solution to an initial value problem through the direction field.
A more detailed explanation to Euler's method could be found here.
Recall from Calculus that , solving for we get: where h is the step size.
Note: the first order DE must be in the form of for this method to work.
Example: Use Euler’s method with to approximate , where
Further references
In order to improve acccuracy in Euler's method, we usually choose small step sizes. However, it is hard to avoid roundoff errors. If the step size is too small, we will build up so many roundoff errors into approximation. To solve the problem, we introduce an improved Euler's method, which is also called Heun's Method. The "improved" tangent line approximation at is:
Solving improved Euler's method using sage.
Fourth-Order Runge-Kutta Method
With Euler's method, we are able to solve most cases. However, sometimes we encounter difficult cases that require more sophiscated methods. Thus, we introduce fourth-order Runge-Kutta method. This method involves computing four slopes and taking an average of them. A more detailed explanation could be found here.
Example:
Exercises
1.Use Euler’s method to approximate , where
Solution: Let , we trasform given equations to standard form: .
Take
2.Using the following function definition to complete Runge-Kutta method and Euler method(Note these two methods use different ways to calculate increment)
Solution