0% found this document useful (0 votes)
26 views16 pages

MATLAB Module 3

notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views16 pages

MATLAB Module 3

notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

A

Module 3

D
AD
U
VT
Working with anonymous function
• An anonymous function is a function of one or more variables that
you create on the command line for subsequent evaluation.

A
• Such a function is especially useful if you need to evaluate the

D
AD
function several times (with different input) during a single MATLAB
session and you do not care to code it in a function file and save for

U
later use.

VT
• Such a function is especially useful if you need to evaluate the
function several times (with different input) during a single MATLAB

A
session and you do not care to code it in a function file and save for

D
later use.

AD
• For example, let us say that you have f(x) = x3 - 32x2 + (x - 22)x + 100,

U
and you need to evaluate this function at different values of x, plot it

VT
over certain range of x, or find the zeros of f (x) . For such
computations, you can define f (x) as an anonymous function and
evaluate it at any value(s) of x or use
• The key to anonymous functions is the syntax of its creation:
• fn_name = @(list of input variables) function_expression

A
• Here, the key clement is the symbol © that assigns a function handle

D
AD
to the defined function.
• A function handle is a name given to a function by which you can call

U
it wherever you need it.

VT
• In the anonymous function definition line, fn_name is the name of
the function or the handle of the function. The syntax ©(list of input
variables) is what tells MATLAB that you are defining an anonymous
function here.
• Anonymous functions are defined on the command line. They live in
the MATLAB workspace and are alive as long as the MATLAB session

A
lasts.

D
AD
• You can define an anonymous function with any number of input
variable.

U
• You must use a vectorized expression (using array operators) for the

VT
function if you intend to use an array as an input variable.
• You can use anonymous functions as input to other functions where
appropriate.
VT
U
AD
D
A
VT
U
AD
D
A
VT
U
AD
D
A
Symbolic Computations
• The most important step in carrying out symbolic computation is to
declare the independent variables to be symbolic before you do

A
anything with them.

D
AD
• Suppose you want to use x and y as symbolic variables. Then, you can
declare them to be symbolic using any of the commands that follow:

U
• X= sym(‘x’);
• Y= sym(‘y’);
• Syms x y
VT
VT
U
AD
D
A
VT
U
AD
D
A
Importing and Exporting Data

A
D
AD
U
VT
VT
U
AD
D
A
Working with files and Directories
• MATLAB includes several menu-driven features that make file
navigation much easier (compared with the earlier versions) .

A
• In the lesson, you will learn commands that pretty much do the same

D
AD
thing from the command line. The commands that you will use are
pwd . dir , l s , cd , what , makedir, etc.

U
• You can create new directories from within the MATLAB command

VT
winrlow. You can also copy or move files from one directory to
another with MATLAB commands ( copyf ile , movef ile) . See on-liml
hAlp on pwd , cd , mkdir , rmdir, c opyf ile , movef ile , what , and
which
VT
U
AD
D
A
VT
U
AD
D
A

You might also like