Operation | |
---|---|
Natural Logarithm | log(10) |
Logarithm Base 10 | log10(10) |
Remainder (modulus) | mod(8,3) |
sin(arg in rads) | sin(2) |
sin(arg in degs) | sind(90) |
cos(radians) | cos(2) |
cos(degrees) | cosd(45) |
tan(rads) | tan(2) |
exponential $e^n$ | exp(n) |
square root | sqrt(4) |
factorial $n!$ | factorial(n) |
nth root $\sqrt[n]{x}$ | nthroot(x,n) |
% factorial - 5! is not used
factorial(5)
ans = 120
% square root
sqrt(9)
ans = 3
sqrt(5)
ans = 2.2361
9^(1/2)
ans = 3
% Nth Root: nthroot(X, n)
% returns the nth root of X
nthroot(27, 3)
ans = 3
sym(sqrt(89333))
ans = 89333^(1/2)
NOTE: MATLAB interprets arguments to trig functions as radians - must convert to degrees if thats what you want!
% some trig examples
deg = sym('deg');
rad = sym('rad');
deg = rad*180/pi; % convert rad2deg
rad = deg*pi/180; % convert deg2rad
sin(45)
ans = 0.8509
sin(45*180/pi)
ans = 0.8061
log10(11.5)
ans = 1.0607
% MATLAB uses log base e (natural log) by default
% e = 2.7183, so...
log(2.7183)
ans = 1.0000
% to change to base:
log10(100)
ans = 2
% for exponential, we use the exp() function
exp(1)
ans = 2.7183
% MATLAB recognizes both i and j as complex numbers
i
ans = 0.0000 + 1.0000i
j
ans = 0.0000 + 1.0000i
i * i
ans = -1
sqrt(-1)
ans = 0.0000 + 1.0000i
(1-4i)+(5-4i)
ans = 6.0000 - 8.0000i
2*j
ans = 0.0000 + 2.0000i
% variables can be assigned as complex
a = 3 - i;
b = 5 + 4i;
a*b
ans = 19.0000 + 7.0000i
a^b
ans = -1.1333e+03 + 1.6569e+02i
% the magnitude of complex can also be found with abs()
a = 4 - 3i;
abs(a)
ans = 5
% the angle is also found (in radians)
angle(a)
ans = -0.7854
% real()/imag() are used to get the respective part of a complex #
a = 57 - 872i;
real(a)
imag(a)
ans = 57 ans = -872
% complex conjugates are found 2 ways:
conj(a)
ans = 5.7000e+01 + 8.7200e+02i
a'
ans = 5.7000e+01 + 8.7200e+02i
% lastly, a complex number can be constructed using a function
complex(3,9)
ans = 3.0000 + 9.0000i