Introductory Programming Fall 2006 Cleanup ------- I used some sloppy notation last time that may have created confusion. Let me try again. The problem we are working on is numerical approximation of a solution to an ordinary (as opposed to partial) differential equation. A first-order ODE has the form dy/dt = f(t, y) In other words, the derivative of y is a known function of time, t, and the current value of y. Also, we have an initial condition y(t0) = y0 In other words, we know that at some particular time t0, the value of the function we are looking for is y0. In some cases we can solve the differential equation analytically and come up with a function, y(t), that solves the problem. But most differential equations don't have analytic solutions, so we have to use numerical methods to approximate them. Euler's method is one numerical method; ode45 is another. The output from ode45 is sometimes called "the t's" and "the y's", to indicate that it contains a set of t values (running from t0 to t_end) and the corresponding y values. They are contained in vectors named T and Y. Using ode45 ----------- To use ode45, you have to write a function that evaluates f(t, y) Since your function will be invoked by ode45, it has to take just the right input variables, and produce just the right output value. Here is a solution to the oven problem from last time: function dxdt = oven(t, x) T = 293.15; g = 50; d = 2e-7; el = 800; u=21; dxdt = g * (T - x) + d * (T^4 - x^4) + el * u^2; end Sources of confusion: 1) The rate of change of the temperature is not a function of time, so t does not appear in the equation. But we have to take t as an input variable to keep ode45 happy. 2) we are using x to represent the temperature of the oven, so it is playing the role that y plays in our notation. 3) T represents the ambient temperature. It is a scalar, so it violates a style rule. To use ode45, you could call >> ode45(@oven, [0, 0.01], 25) which plots the values of x versus the values of t. Or >> [T, Y] = ode45(@oven, [0, 0.01], 25); Which stores the results in vectors named T and Y. There is no conflict between T in the interpreter and T inside the function. And in this case, the variable of interest is called x inside the function and Y when we get the result. Possibly confusing, but this kind of translation happens all the time, and will stop bothering you some day :)