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

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

In order to use Matlab routines for the Euler, Improved Euler and Runge-Kutta Methods, you will need the ﬁles eul.m, rk2.m and rk4.m , respectively. These ﬁles 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 ﬁles. Here is a link : http://math.rice.edu/ dﬁeld/ You must ﬁrst create a function ﬁle 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 ﬁle. For example, to create a function ﬁle 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 ﬁle as a .m ﬁle with the SAME name as your function. The above example would be saved as “ fcn1.m ”. You can check if your function has
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

{[ snackBarMessage ]}

Ask a homework question - tutors are online