

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Programming Project for Math 2605
This project is aimed at developing a visual understanding of what it means to solve an initial value problem for a system of differential equations, and how to go about it in practical terms. So that we can graph the results, we will restrict ourselves to the 2 variable case. Let F be a function from R^2 to R^2 ; that is, a vector valued function on R^2. Given an initial point x 0 , and a time step h > 0, we define a sequence of points as follows:
x 1 = x 0 + hF(x 0 ) x 2 = x 1 + hF(x 1 ) x 3 = x 2 + hF(x 2 ) x 4 = x 3 + hF(x 3 ) x 5 = x 4 + hF(x 4 ) ..
. =
Connecting these points with straight line segments yields a path in the plane that is a polygonal approximation to the solution of the initial value problem
x′(t) = F(x(t)) , x(0) = x 0.
If you want to see the approximate solution for all t in some interval [0, T ], you continue with the sequence in (1) for n steps, where n is the smallest integer such that nh ≥ T. This approach goes back to Euler, and is called the Euler method. The accuracy of the approximation it produces depends on h: The smaller h is the better the approximation, but if T is held fixed and h is decreased, then n will increase, and more computation will have to be done. Part of the point of this project is to investigate how the accuracy depends on h, so we can get some feel for how small to make it. Make a program – an applet would be ideal – that does the following: It takes the following inputs:
(1) A function F from R^2 to R^2 , specified in the form
F(x, y) =
f (x, y) g(x, y)
so that f and g are what you would actually enter in text fields.
(2) A time step value h > 0
(3) A starting point x 0. This would be specified by entering the components x 0 and y 0.
(4) A a final time value T > 0, so that we draw the path x(t) for 0 ≤ t ≤ T.
The program should run the iteration in (1) until nh ≥ T , and then draw the path obtained by connecting the dots. Then, to see the h dependence, replace h by 10−^1 h, and
repeat. Draw this path in a different color. Again, replace h by 10−^1 h, (so now the time step is one hundred times smaller than it was initially), and repeat, drawing this path in a third color. Your program should output a graph showing all three paths. (As each path is com- puted, keep track of the smallest and largest x values encountered, and the smallest and largest y values encountered. Then you will know which box in the x, y plane you should graph). If you pick h small enough, all three graphs will come out on top of each other. If h is not so small, only the last two will be indistinguishable, and if h is larger still, all three will be distinguishable. A rule of thumb is that when the three graphs come out on top of each other, what you are seeing is, for all practical purposes, a graph of the exact solution. Test your program by having it draw a known curve. For instance, with
F(x, y) =
y −x
x 0 =
and T = 2π, the exact result is the unit circle. (As you can check, x(t) = cos(t)
and y(t) = sin(t) is the exact solution of this initial value problem. What is the largest value of h that you find that makes the three paths indistinguishable for this problem? (This will depend on the resolution in your graph: the more detailed the graph, the finer will be the distinctions that you can see, and the smaller h will have to be). Does the result in fact look like a circle? In particular, does your graph close? Next, take F(x, y) =
xy(y^2 − x) (x + 2y)(y^2 − x^2 )
x 0 =
and T = 10. How small do you have to take h this time? You will notice that
the path tends to the equilibrium point at
, and it does so for all initial data near
the given starting point. Finally, take F(x, y) =
xy(y^2 − x) (x + 2y)(y^2 + x^2 )
x 0 =
and T = 0.6. The difference in F is just one sign, but it makes a big difference
in the curve which now “runs away”. You will not be able to continue the curve much beyond T = 0.6. How small do you have to take h this time? Does this“runaway” curve require a larger or smaller value of h than the “stable curve”?