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

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

View Full Document Right Arrow Icon
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 files eul.m , rk2.m or rk4.m , respectively. These files are already present on all ITaP machines as standard software. (If using your own copy of Mat- lab you may need to download these files from dfield ). You may also access these files from Matlab via the Software Remote : 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 ( 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 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 been saved by typing
Background image of page 1
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

Ask a homework question - tutors are online