eul-f10

# eul-f10 - something like the following at a Matlab prompt...

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

Numerical Methods and .m Files In order to use Matlab routines for the Euler, Improved Euler or Runge-Kutta Meth- ods, you will need the ﬁles eul.m , rk2.m or rk4.m , respectively. These ﬁles are already present on all ITaP machines as standard software. (If using your own copy of Mat- lab you may need to download these ﬁles from http://math.rice.edu/ dfield ). You may also access these ﬁles from Matlab via the Software Remote : http://goremote.ics.purdue.edu 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 ( x,y ) = 6 x 3 - e 2 y + x/y , type: function W=fcn1(x,y) W=6*x^3-exp(2*y)+sqrt(x)/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 been saved by typing
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: something like the following at a Matlab prompt: fcn1(0,3) You should get the value of f (0 , 3). • Your initial value problem should have the form: ( y = f ( x,y ) y ( x ) = y . Assuming f ( x,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’,[x0,xf],y0,h) where x0 and xf denote the initial and ﬁnal values of x , respectively, y0 is the initial value of y , and h is the 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 xf , with given h , using eul , just type the following at a Matlab prompt: [x,y]=eul(’fcn1’,[x0,xf],y0,h); The approximations y , y 1 , y 2 , . . . , y n are stored in the matrix y • To print them out, type: [x,y] • To plot them, type: plot(x,y)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online