2, MATLAB Slides Week2 PPT
2, MATLAB Slides Week2 PPT
2, MATLAB Slides Week2 PPT
Introduction to MATLAB
Summer of Core - 2023
IIT Bombay
min(x), max(x)
exp(x)
Logarithms Function
log: Natural logarithm
log2: Base-2 logarithm
Trigonometric Functions
sin(x)
asin(x)
cos(x)
acos(x)
tan(x)
atan(x)
cot(x)
acot(x)
sec(x)
asec(x)
csc(x)
acsc(x)
Hyperbolic Functions
sinh(x)
cosh(x)
tanh(x)
coth(x)
sech(x)
csch(x)
Matlab as a Programming Language
MATLAB Scripts are saved as so-called .m files (file extension is .m).
When using the Script Editor, you may create several lines of code and execute all
in one batch. You can easily do changes in your code, create comments, etc.
Scripting and user-
defined functions in
MATLAB
Syntax
Valid function names begin with an alphabetic character and can contain letters,
numbers, or underscores.
The name of the file must match the name of the first function in the file.
Function with One Output
end
z = 1:99;
ave = calculateAverage(z)
Function with Multiple Outputs
n = length(x);
m = sum(x)/n;
s = sqrt(sum((x-m).^2/n));
end
[ave,stdev] = stat(values)
• Multiple Functions in a Function File
• n = length(x);
• m = avg(x,n);
• s = sqrt(sum((x-m).^2/n));
• end
• function m = avg(x,n)
• m = sum(x)/n;
end
• [ave,stdev] = stat2(values)