Value At Risk IEF 217a: Lecture Section 5 Fall 2002 Jorion Chapter 5.
Matlab Basics IEF 217a: Lecture 2 Fall 2002 Sigmon and Davis, chapters 1-7.
-
date post
22-Dec-2015 -
Category
Documents
-
view
220 -
download
0
Transcript of Matlab Basics IEF 217a: Lecture 2 Fall 2002 Sigmon and Davis, chapters 1-7.
Loading Software
MatlabFollow matlab instructions for your own machine
DownloadsWe will eventually be downloading various
matlab programs and data from the website
Functions
Scalar functions: f(x)
log(x), exp(x), sqrt(x)
sin(x), cos(x), tan(x)
Vector functionssum(x), mean(x), median(x)
If’s With Vectors
if (a==b)
disp(‘a equals b’)
end
What if a and b are vectors?
True if every element of a equals every element of b
Any and All
if any(a==b)
disp(‘at least one equal’)
end
if all(a==b)
disp(‘all are equal’)
end
For matrices this gets more complicated
Fancy Subscripts (find function)
x = [5 2 –3 –4 1];
y = x(find(x<0);
all x values greater than zero put in y
k = find(x<0);
k = subscripts
k = [ 3 4];
Important: Comment Lines
Lines starting with % are comments
x = 1;
y = 2;
z = x*y;
% this really is not doing very much
Function file (positives.m)
function count = positives(x)
% usage: count = positives(x)
% x = vector
% count = number greater than zero
count = sum(x>0);
Fancy function stuff
Multiple returns
function [ count, count2] = positives(x)
count = sum(x>0);
count2 = sum(x>2);
Save
save
(saves everything to file matlab.mat)
load
(restores all settings)
useful for taking a break, and starting where you left off
Save
save filename x y z
(save to filename.mat variables x, y, z)
save filename x y z –ascii
(save in ascii format)