Professional Documents
Culture Documents
Essential Elements of Matlab
Essential Elements of Matlab
Essential Elements of Matlab
( EX_Matlab.m)
Lima, February 2010
Fernando Monar & Ken Nyholm
Outline
Getting Matlab up and running
Functionalities
Help
Graphing
Variables
Branching and Looping
Functions
Fmincon
To install:
In Excel go to: Tools, add-ins, browse
And find the folder: Matlab\toolbox\excel link
see next slide
10
11
12
Functionalities
There are different ways to obtain help in Matlab
a) Help on a particular function:
13
Functionalities
b) From the Matlab built-in help function:
14
Functionalities
Branching and Looping, i.e. conditional execution of
code, requires relation operators:
15
Functionalities
Branching:
16
Functionalities
The if and case statements:
17
Functionalities
Looping:
18
Functionalities
A function in Matlab typically has the following
components:
Header that specifies the name, input and output variables,
and the keyword function that tells Matlab that the
following should be interpreted as a function
An introduction section that tell the user how to use the
function
The text that performs the calculations of the function
19
Functionalities
An example of a function:
20
Functionalities
One of the most useful function for our purposes is
the Matlab built-in function fmincon
It can be use to find the arguments that minimise a
particular function
We will use this function to:
21
Functionalities
22
Functions in Matlab
User defined functions were presented in the
slide-set called An Introduction to Matlab
23
Functions in Matlab
Matlab uses a function handle when
functions are defined or used
If a function is defined in a file the follwing
structure has to be use:
function [output] = function_name(input)
24
Functions in Matlab
And it can be used as an input to a built-in
Matlab function, for example fmincon, usin the
handles @ or function_name, in the
following ways:
[Est,fval,flag,outp,lambd,grad,hess] = ...
fmincon(@var_p_lik, pStart,[],[],[],[],LB,UB,[],options_);
25
In-line functions
In-line functions refer to the concept of
defining the object of interest in just one line
within the program that condusts the
optimisation or function value calculation
This can be achieved by:
26