Beruflich Dokumente
Kultur Dokumente
Topics
Mathematics: Euler and simple RungeKutta methods; errors and step sizes. MATLAB: using functions as input arguments for other functions; built-in ODE solvers ode23 and ode45.
Preparation
Read your lecture notes. See also Chapra and Canale, Section 25.1 (pages 681689) and Section 25.2 (pages 693699). In the rst part of this lab you will work through some of the exercises from this chapter (Exercises 25.1 to 25.3). You will need an extra function M-le for this lab session: myeuler.m solves the initial value problem y = f (x, y ), by using Eulers method. This M-le is available from the Sample M-les on the course web page. Read the help for this M-le to see how to use it. You do not need to change this le, but you do need to know what input variables it needs, and what output variable it produces, so read the help carefully! y (x0 ) = x0
B. Eulers method
In this part of the lab, you will use Eulers method to solve the following initial value problem y = yx2 1.1y, and look at how reducing the step size aects the errors. 1. Solve the problem analytically over the interval from x = 0 to x = 2. (Hint: the dierential equation is rst order and separable.) 1 y (0) = 1
2. Use Eulers method with h = 0.20, h = 0.10 and h = 0.05 to solve the above initial value problem numerically over the interval from x = 0 to x = 2. Hints: Remember to pass your function as a function handle (@myfn), so your call to myeuler will begin with myeuler(@myfn,...). myeuler.m needs to know the number of steps to take (N ), so think about how many steps you will need for these each value of h. 3. Plot the exact solution and your approximate solutions on the same graph. Checkpoint: Tabulate the error verses h at x = 1.60 when h is successively halved; i.e. h = 0.20, 0.10, 0.05. What happens to the error in the numerical approximation as you reduce the step size? Use your tabulation of the error to estimate the order of your Euler method.
Hints: The new program myrk2.m will need a new rst line function [x, y] = myrk2(dydx, xspan, y0, N)
Notice that myeuler.m already calculates the rst slope estimate. Insert a line of MATLAB code for the second slope estimate. Finally, modify the line which calculates the new y-value. 1. Use Heuns method with h = 0.20, h = 0.10 and h = 0.05 to solve the above initial value problem numerically over the interval from x = 0 to x = 2. 2. Plot the exact solution you found in part B and your approximate solutions from using Heuns method on the same graph. Checkpoint: What happens to the error in the numerical approximation as you reduce the step size? How does Heuns method compare to Eulers method? Tabulate the error verses h at x = 1.60 when h is successively halved; i.e. h = 0.20, 0.10, 0.05. What happens to the error in the numerical approximation as you reduce the step size? Use your tabulation of the error to estimate the order of your RK method.
E is the activation energy (the minimum energy needed for the reaction to occur), R is the gas constant, u is the temperature (measured in Kelvin), k is a Newtonian cooling constant, and ua is the ambient temperature, the temperature of the surroundings (also in Kelvin). The rst term on the right-hand side is called the Arrhenius term (after the rst person to make an in-depth study of the eect of temperature on the rate of reactions). This term comes from looking at the probability of atoms in the system colliding with one another. The second term on the right-hand side represents Newtonian cooling, where an object cools at a rate proportional to its temperature dierence with its surroundings. In this part of the lab, you will solve this dierential equation with the following parameter values: A = 100 Ks1 , E = 24900 J, R = 8.3 JK1 , k = 1 s1 , ua = 300 K,
and an initial condition u(0) = 900 K. 1. Write a function le (like myfn.m) for the slope. Even though this function does not involve t you will still need to list it as a variable in the rst line of the function le, since your ODE solvers all expect the slope to depend on both variables. 2. Use Heuns method, with a step size of h = 0.5, to nd estimates for u(t) for 0 t 10. 3. MATLAB has several built-in ODE solvers. Read the help for the commands ode23 and ode45, and then use one of them to solve for u(t) for 0 t 10. Checkpoint: Plot your two estimates for u(t) on the same diagram. Describe how the physical system behaves over the rst 10 seconds.