Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lab 4
Advantages
Repeatable operations can be written as a functions
The actual code becomes much cleaner
You do not need to return the output variables – just ensure that the
variable names are same
The name of the m-file should be the same as the function name you have
given
if (a<0 || b<0)
error (‘The inputs are not positive’);
end
c = a + b;
c = add(5,4);
if (a<0 || b<0)
error (‘The inputs are not positive’);
end
c = a + b;
d = a – b;
[c, d] = add_diff(5,4);
if (x2<x1)
error (‘The end is less than the start’);
end
N = length(xx);
xx_temp = linspace(x1,x2,N);
yy = xx.*xx_temp;