num - been saved by typing something like the following at...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
In order to use Matlab routines for the Euler, Improved Euler and Runge-Kutta Methods, you will need the files eul.m, rk2.m and rk4.m , respectively. These files are already present on all PUCC machines as standard software. If you are using your own copy of Matlab you may need to download these files. Here is a link : http://math.rice.edu/ dfield/ You must first create a function file in the same directory (or folder) as your Matlab . Here is one way. After Matlab has been opened, pull down the File menu and select “ New M-File ”. A window will pop up for you to create your function file. For example, to create a function file for the function f ( t,y )=6 t 3 - e 2 y + t y ,type: function W=fcn1(t,y) W=6*t 3-exp(2*y)+sqrt(t)/y; (Don’t forget the “ ; ” at the end.) Save this file as a .m file with the SAME name as your function. The above example would be saved as “ fcn1.m ”. You can check if your function has
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: been saved by typing something like the following at a Matlab prompt: >> fcn1(1,3) You should get the value of f (1 , 3). Your initial value problem will have the form : y = f ( t,y ) y ( t ) = y . Assuming f ( t,y ) was saved as the le fcn1.m , the syntax for eul (as well as rk2 and rk4 , just replace eul ) will be : eul(fcn1,[t ,t f ],y ,h) where t and t f are the initial and nal values of t and h = step size . (Your version of Matlab may not utilize brackets. Type help eul to nd out.) To approximate the actual solution to the IVP at t f , with given h , using eul , just type the following at a Matlab prompt: >> [t,y]=eul(fcn1,[t ,t f ],y ,h); The approximations y ,y 1 ,y 2 ,...,y n are stored in the matrix y . To print them out type : [t,y] To plot them, type : plot(t,y)...
View Full Document

Ask a homework question - tutors are online