You are on page 1of 6

Numerical Methods

CHE 384
“Applied Numerical Methods with MATLAB for Engineers and Scientist, Fourth Edition, Chapra”
Chapter 3

M-Files
M-file stands for Matlab and is called that due to
Script files vs Function Files

Script Function

 Saves many commands in 1 file  Variables created do not affect


command window
 Must be saved underneath MATLAB  Must be saved underneath MATLAB
folder folder
 Can open a new script by typing  Command window will return values
“edit” from function
In the command window

Script File Example:


Function File Example:

To edit the file as a new function, save the current function, click on new script, and open up
function file that needs to be edited.
Help in MATLAB
If you need to understand what a function does, the help function will tell you

Anonymous & Inline Functions

Anonymous:
 one-line function created without the need for an M-file
 defined by an @ symbol
 Is not saved
 Good for
simple
functions,
doesn’t need
a full function
file
In class example : (anonymous function):

f (x) =x 3 - x 2 + 6
f (6) =?

It is possible to have two anonymous functions in a single line:


Inline Function:

You might also like