Introductory Programming Fall 2006 Leftovers --------- 1) notes11 contains examples code; I recommend keeping a collection. 2) anonymous functions; what's that all about? >> f = @(x, y) x+y >> f(1,2) >> g = @(angle) sin(angle)-0.5 >> x = fzero(g, 0.5) >> sin(x) 3) write quiet functions so you can use them with fzero (and other MATLAB tools) New topic: numerical approximation of differential equations. Today's instructions -------------------- 1) create a file named f.m in the usual place you put scripts 2) type in the following code function dydt = f(t, y) dydt = t + y; end 3) evaluate this function from the command line and make sure it does what you expect. 4) type 'help ode45' and read the documentation, or at least as much of it as you can stand 5) run 'ode45(@f, [0, 1], 0)' What does this command do? 6) Alternatively, you can run '[T, Y] = ode45(@f,[0, 1], 0);' and then 'plot(T, Y)' 7) Use ode45 to find a numerical solution to the differential equation dx/dt = g (T - x) + d(T^4 - x^4) + el u^2 with T = 293.15, g = 50, d = 2e-7, el = 800 and u=21. The initial condition is x(0) = 25. (See problem 8.10 on the next page.)