Week 6
Week 6
M = mean(A), M = median(A)
M = mean(A,dim), M = median(A,dim)
Example:
A = [ 0 2 5 7 20] B = [1 2 3
336
468
4 7 7];
mean(A) = 6.8
mean(B) = 3.0000 4.5000 6.0000 (column-wise mean)
mean(B,2) = 2.0000 4.0000 6.0000 6.0000 (row-wise mean)
Mean and Median
Examples:
A = [ 0 2 5 7 20] B = [1 2 3
336
468
4 7 7];
Mean:
mean(A) = 6.8
mean(B) = 3.0 4.5 6.0 (column-wise mean)
mean(B,2) = 2.0 4.0 6.0 6.0 (row-wise mean)
Median:
median(A)= 5
median(B) = 3.5 4.5 6.5 (column-wise median)
median(B,2) = 2.0
3.0
6.0
7.0 (row-wise median)
Polynomials
Introduction
Polynomials
x2+2x-7
x4+3x3-15x2-2x+9
>>s=[1 -3];
>> value=polyval(y, s)
value =
9 13
OR
>> value=polyval(y,[1 -3])
Roots of Polynomials
Roots of polynomials: roots(p)
>>p=[1 3 2]; % p=s2+3s+2
>>r=roots(p)
r = -2
-1
Current 10 15 20 25 30
voltage 100 150 200 250 300
Sol:
>>current=[10 15 20 25 30];
>>voltage=[100 150 200 250 300];
>>resistance=polyfit(current, voltage, 1)
resistance=
10.0000 -0.0000
Ex: Evaluate the matrix polynomial X2+X+2, given that the square matrix
X= 2 3
4 5
Sol:
>>A=[1 1 2]; %A= X2+X+2I
>>X=[2 3; 4 5];
>>Z=polyvalm(A,X) %poly+val(evaluate)+m(matix)
Z=
20 24
32 44
DIFFERENTIAL
• MATLAB provides the diff command for computing
symbolic derivatives. In its simplest form, you
• pass the function you want to differentiate to diff
command as an argument.
• For example, let us compute the derivative of the
function ft = 3t2 + 2t-2
• Example
• syms t
f = 3* t^2 + 2* t^(-2);
diff(f)
INTEGRATION
• MATLAB provides an int command for
calculating integral of an expression. To
derive an expression for the indefinite
integral of a function, we write − int(f);
• int(f)
• int(x, a, b)
Laplace Transform
• Laplace transform turns differential
equations into algebraic ones. To compute
a Laplace transform of a function ft, write −
• laplace(f(t))
• MATLAB allows us to compute the inverse
Laplace transform using the command
ilaplace.
• ilaplace(1/s^3)
Fourier Transforms
• Fourier transforms commonly transforms a
mathematical function of time, ft, into a
new function, sometimes denoted by or F,
whose argument is frequency with units of
cycles/s hertz or radians per second. The
new function is then known as the Fourier
transform and/or the frequency spectrum
of the function f.
Fourier Transforms
• syms x
f = exp(-2* x^2); %our function
ezplot(f,[-2,2]) % plot of our function
FT = fourier(f) % Fourier transform
Fourier Transforms
• MATLAB provides the ifourier command
for computing the inverse Fourier
transform of a function. For example,
• f = ifourier(-2* exp(-abs(w)))
Limits
• MATLAB provides the limit function for
calculating limits. In its most basic form, the limit
function takes expression as an argument and
finds the limit of the expression as the
independent variable goes to zero.
• For example, let us calculate the limit of a
function fx = (x3 + 5)/(x4 + 7), as x tends to zero.
• syms x
limit((x^3 + 5)/(x^4 + 7))
Limits
• For example, let us calculate limit of a function fx
= x − 3/x − 1, as x tends to 1.
• limit((x - 3)/(x-1),1)
Expanding and Collecting
Equations in MATLAB
• The expand and the collect function expands
and collects an equation respectively. The
following example demonstrates the concepts −
• When you work with many symbolic functions,
you should declare that your variables are
symbolic. Create a script file and type the
following code
Expanding and Collecting
Equations in MATLAB
• syms x %symbolic variable x
syms y %symbolic variable x
% expanding equations
expand((x-5)* (x+9))
expand((x+2)* (x-3)* (x-5)* (x+7))
expand(sin(2* x))
expand(cos(x+y))
% collecting equations
collect(x^3 * (x-7))
collect(x^4* (x-3)* (x-5))
Factorization and Simplification
of Algebraic Expressions
• The factor function factorizes an expression and
the simplify function simplifies an expression.
• The following example demonstrates the
concept
• syms x
syms y
factor(x^3 - y^3)
factor([x^2-y^2,x^3+y^3])
simplify((x^4-16)/(x^2-4))