0% found this document useful (0 votes)
45 views8 pages

ECE120L - Activity 6

This document discusses using MATLAB to perform higher mathematical operations like derivatives, integrals, and Laplace transforms. It provides examples of using functions like polyder(), diff(), polyint(), int(), laplace(), and ilaplace() to: 1) Take the derivative of polynomials, polynomial products/quotients, and symbolic functions. 2) Find indefinite and definite integrals of polynomials and symbolic functions. 3) Calculate the Laplace transform and inverse Laplace transform of functions.

Uploaded by

Duper Fuber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views8 pages

ECE120L - Activity 6

This document discusses using MATLAB to perform higher mathematical operations like derivatives, integrals, and Laplace transforms. It provides examples of using functions like polyder(), diff(), polyint(), int(), laplace(), and ilaplace() to: 1) Take the derivative of polynomials, polynomial products/quotients, and symbolic functions. 2) Find indefinite and definite integrals of polynomials and symbolic functions. 3) Calculate the Laplace transform and inverse Laplace transform of functions.

Uploaded by

Duper Fuber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ECE120L – INTRODUCTION TO MATLAB

LABORATORY ACTIVITY #6
Higher Mathematical Operations

I. Learning Outcomes:
At the end of the laboratory activity, the students should be able to:
1. Use MATLAB to solve the derivative and integral of a given mathematical function
2. Use MATLAB to obtain linear transforms of higher equations such as Laplace Transforms and Fourier
Transform

II. Introduction:
A. Derivative of a Function
𝑑𝑓(𝑥)
The derivative of a function 𝑦 = 𝑓(𝑥) is written 𝑑𝑥
and is defined as the rate of change of the
dependent variable y with respect to x. The derivative is the slope of the line tangent to the function at a given
point.
MATLAB is capable to solve the derivative of a given function.
a) polyder
Polynomial derivative
Syntax
k = polyder(p)
k = polyder(a,b)
[q,d] = polyder(b,a)
Description
The polyder function calculates the derivative of polynomials, polynomial products, and polynomial quotients.
The operands a, b, and p are vectors whose elements are the coefficients of a polynomial in descending
powers.
k = polyder(p) returns the derivative of the polynomial p.
k = polyder(a,b) returns the derivative of the product of the polynomials a and b.
[q,d] = polyder(b,a) returns the numerator q and denominator d of the derivative of the
polynomial quotient b/a.
Examples:
1. The derivative of the polynomial 𝑦 = 3𝑥 5 + 6𝑥 4 − 4𝑥 3 + 9𝑥 2 + 2𝑥 + 10 is obtained with
%Derivative of a Polynomial
clear
y = [3 6 -4 9 2 10];
k = polyder(y)
k =
15 24 -12 18 2
This result represents the polynomial 15𝑥 4 + 24𝑥 3 − 12𝑥 2 + 18𝑥 + 2

PREPARED BY: RONEL V. VIDAL, PECE 1


2. The derivative of the product (3𝑥 2 + 6𝑥 + 9)(𝑥 2 + 2𝑥) is obtained with
% Derivative of the Product of Two Polynomials
clear
a = [3 6 9];
b = [1 2 0];
k = polyder(a,b)
k =
12 36 42 18
This result represents the polynomial 12𝑥 3 + 36𝑥 2 + 42𝑥 + 18
3. The derivative of the quotient of the two polynomials (3𝑥 2 + 6𝑥 + 9) and (𝑥 2 + 2𝑥) is obtained with
% Derivative of the Product of Two Polynomials
clear
a = [3 6 9];
b = [1 2 0];
[q,d] = polyder(a,b)
q =
-18 -18
d =
1 4 4 0 0
−18𝑥−18
This result represents the polynomial fraction𝑥 4 +4𝑥 3 +4𝑥2.

b) Derivative Using Symbolic Variables


The derivative of a given function can be solved in MATLAB using symbolic variables and the
command ‘diff’.
diff Differentiate.
Syntax:
diff(s) differentiates a symbolic expression s with respect to its free variable
as determined by SYMVAR.
diff(s,'v') or diff(s,sym('v')) differentiates s with respect to v
diff(s,n) for a positive integer n, differentiates s n times
diff(s,'v',n) and diff(s,n,'v') are also acceptable

Examples:
1. Solve the derivative of 𝑓(𝑥) = 𝑥 4 .
% Derivative a function with respect to a variable
clear
symvar x;
f = x^4;
k = diff(f)
k =
4*x^3
The derivative is 4𝑥 3 .

PREPARED BY: RONEL V. VIDAL, PECE 2


2. Solve the derivative of 𝑓 = 2𝑦𝑥 4 − 5𝑦 2 𝑥 3 + 10𝑦𝑥 with respect to x.
% Derivative of f with respect to x
clear
syms f x y
f = (2*y*x^4)-(5*y^2*x^3)+(10*y*x);
k = diff(f,'x')
k =
8*x^3*y - 15*x^2*y^2 + 10*y
The derivative is 8𝑦𝑥 3 − 15𝑥 2 𝑦 2 + 10𝑦
3. Solve the 3rd derivative of the function 𝑓(𝑥) = 4𝑥 6 + 6 sin 5𝑥.
% 3rd derivative a function
clear
syms f x;
f = 4*x^6+6*sin(5*x);
k = diff(f,3)
k =
480*x^3 - 750*cos(5*x)
The 3rd derivative is 480𝑥 3 − 750 cos 5𝑥

B. Integral of a function
Finding the integral of a function with respect to x means finding the area to the x axis from the curve.
The integral is usually called the anti-derivative, because integrating is the reverse process of differentiating.
The fundamental theorem of calculus shows that antidifferentiation is the same as integration.
𝑏
The integral of a function 𝑓(𝑥) between the limits given by 𝑥 = 𝑎 and 𝑥 = 𝑏 is written as ∫𝑎 𝑓(𝑥)𝑑𝑥
and is defined as the area under the curve 𝑓(𝑥) from 𝑎 to 𝑏, as long as the function is above the 𝑥 − 𝑎𝑥𝑖𝑠.
Numerical integration techniques involve approximating this.
a) polyint
Integrate polynomial analytically
Syntax
polyint(p,k)
polyint(p)
Description
polyint(p,k) returns a polynomial representing the integral of polynomial p, using a scalar
constant of integration k.
polyint(p) assumes a constant of integration k=0.
Examples:
1. The indefinite integral of the polynomial 𝑦 = 3𝑥 5 + 6𝑥 4 − 4𝑥 3 + 9𝑥 2 + 2𝑥 + 10 is obtained with
% Indefinite integral of a polynomial function
clear
a = [3 6 -4 9 2 10];
k = polyint(a)
k =
0.5000 1.2000 -1.0000 3.0000 1.0000 10.0000 0
6 5 4 3 2
The integral is 0.5𝑥 + 1.2𝑥 − 𝑥 + 3𝑥 + 𝑥 + 10𝑥

PREPARED BY: RONEL V. VIDAL, PECE 3


b) Integral Using Symbolic Variables
The integral of a given function can be solved in MATLAB using symbolic variables and the
command ‘int’.
int Integrate
Syntax
int(s) indefinite integral of s with respect to its symbolic variable as defined by symvar. If s is
a constant, the integral is with respect to 'x'.
int(s,v) indefinite integral of s with respect to v. v is a scalar SYM.
int(s,a,b) definite integral of s with respect to its symbolic variable from a to b. a and b are each
double or symbolic scalars.
int(s,v,a,b) definite integral of s with respect to v from a to b.

Examples:
1
1. The indefinite integral of the function 𝑓(𝑥) = 1+𝑥2 is obtained with
% Indefinite integral of a function
clear
syms f x;
f = 1/(1+x^2);
k = int(f)
k =
atan(x)
The integral is tan−1 𝑥
2. The indefinite integral of the function 𝑓(𝑥) = sin 2𝜋𝑛𝑥 with respect to 𝑥 is obtained with
% Indefinite integral of a function with respect to x
clear
syms f pi n x;
f = sin(2*pi*n*x);
k = int(f,x)
k =
-cos(2*pi*n*x)/(2*pi*n)
1
The integral is − cos 2𝜋𝑛𝑥
2𝜋𝑛
3. The definite integral of the function 𝑓(𝑥) = 4𝑥 3 + 2𝑥 2 + 5𝑥 + 9 from 1 to 2 is obtained with
% Definite integral of a function
clear
syms f x;
f = 4*x^3 + 2*x^2 +5*x + 9;
k = int(f,1,2)
k =
217/6
The integral is 217⁄6 or 36.1667.

PREPARED BY: RONEL V. VIDAL, PECE 4


C. Laplace Transform and Inverse Laplace Transform with MATLAB
Laplace Transform is a method used to find solutions of linear differential equations and
corresponding initial and boundary value problems. Application of the Laplace transform is to convert a linear
differential equation problem into an algebraic problem. This method is used in the frequency domain analysis
of control systems.
Let f (t ) – given function in the time domain that is defined for all t  0 (causal function).

L{𝑓(𝑡)} = 𝐹(𝑠) = ∫0 𝑓(𝑡)𝑒 −𝑠𝑡 𝑑𝑡
For the inverse transform or inverse Laplace:
L –1 F ( s) = f (t )
Laplace transform and inverse Laplace transform can be solved with MATLAB. Laplace transform can
be obtained in MATLAB with the symbolic Math toolbox by typing 𝑙𝑎𝑝𝑙𝑎𝑐𝑒(𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛), where function is an
expression representing the function 𝑦(𝑡). The default independent variable is 𝑡, and the default result is 𝑠.
The inverse Laplace transform L–1[𝑌(𝑠)] is the time function 𝑦(𝑡) whose transform is 𝑌(𝑠); i.e., 𝑦(𝑡) =
ℒ −1 [𝑌(𝑠)]. Inverse transform can be found using the 𝑖𝑙𝑎𝑝𝑙𝑎𝑐𝑒(𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛).
Examples:
1. Consider 𝑦(𝑡) = 2𝑡 3 + 𝑒−3𝑡 , to solve its Laplace transform;
%To solve the Laplace Transform
clear
syms t
f = 2*t^3 + exp(-3*t);
k = laplace(f)
k =
1/(s + 3) + 12/s^4
1 12
The answer is 𝑌(𝑠) = (𝑠+3) + 4
𝑠
10 4
2. For the inverse Laplace, consider 𝑌(𝑠) = 𝑠3
+ (𝑠+3)3;
%To solve the inverse Laplace Transform
clear
syms s
F = (10/s^3)+(4/(s+3)^3);
k = ilaplace(F)
k =
(2*t^2)/exp(3*t) + 5*t^2
The answer is 𝑦(𝑡) = 2𝑡 2 𝑒 −3𝑡 + 5𝑡 2

PREPARED BY: RONEL V. VIDAL, PECE 5


D. Fourier Transform
fourier
Fourier integral transform
Syntax
F = fourier(f)
F = fourier(f,v) makes 𝐹 a function of the symbol 𝑣 instead of the default 𝜔.
F = fourier(f,u,v) makes 𝑓 a function of 𝑢 and 𝐹 a function of 𝑣 instead of the default variables
𝑥 and 𝜔, respectively.
Description
𝐹 = 𝑓𝑜𝑢𝑟𝑖𝑒𝑟(𝑓) is the Fourier transform of the symbolic scalar 𝑓 with default independent variable 𝑥.
The default return is a function of 𝜔. The Fourier transform is applied to a function of 𝑥 and returns a function
of 𝜔.
𝑓 = 𝑓(𝑥) ⇒ 𝐹 = 𝐹(𝜔)
If 𝑓 = 𝑓(𝜔), Fourier returns a function of 𝑥.
Examples:
2
1. Consider the function 𝑓(𝑥) = 𝑒−𝑥 , its Fourier transform
%To solve the Fourier Transform
clear
syms x
f = exp(-x^2);
k = fourier(f)
k =
pi^(1/2)/exp(w^2/4)
𝜔2⁄
The Fourier Transform is 𝐹(𝜔) = √𝜋𝑒− 4.
2. The Fourier transform of 𝑓(𝑥) = sin 1000𝑥
%To solve the Fourier Transform
clear
syms x
f = sin(1000*x);
k = fourier(f)
k =
pi*i*(dirac(- w - 1000) - dirac(1000 - w))
𝜋
The Fourier transform is 𝐹(𝜔) = 𝑖 [𝛿(𝜔 − 1000) − 𝛿(𝜔 + 1000)].

PREPARED BY: RONEL V. VIDAL, PECE 6


III. Laboratory Exercises

a) Derivative
• Using MATLAB, determine the derivative of the following functions
1. 𝑓(𝑥) = 𝑥 𝑛
2. 𝑓(𝑡) = sin(𝑎𝑡 + 𝑏)
3. 𝑓(𝑥) = 𝑥 2 + 3𝑥 + 1
4. 𝑓(𝑥) = ln 𝑥
• Determine the derivatives of the following functions with respect to 𝑥 and then with respect to 𝑦.
1. 𝑓 = 5 ln 𝑥𝑦
2. 𝑓 = 2𝑦 sin 𝑥 2
• Determine the second derivative of the following functions with respect to 𝑥 and then with respect to
𝑦.
1. 𝑓 = 2𝑥 5 𝑦 3 − 3𝑥 4 𝑦 2 + 9𝑥 2 𝑦
2. 𝑓 = 10 cos(𝑥𝑦 2 )
b) Integral
• Using MATLAB, determine the indefinite integral of the following functions
1. 𝑓(𝑥) = 𝑥 𝑛
2. 𝑓(𝑡) = sin(𝑎𝑡 + 𝑏)
3. 𝑓(𝑥) = 𝑥 2 + 3𝑥 + 1
4. 𝑓(𝑥) = ln 𝑥
• Determine the integral of the following functions with respect to 𝑥 and then with respect to 𝑦.
(1
3. 𝑓 = − 𝑥)⁄𝑥𝑦
4. 𝑓 = 2𝑦 sin 𝜋𝑥 2
• Determine the second integral of the following functions with respect to 𝑥 and then with respect to 𝑦.
1. 𝑓 = 2𝑥 5 𝑦 3 − 3𝑥 4 𝑦 2 + 9𝑥 2 𝑦
2. 𝑓 = 10 cos(2𝜋𝑥𝑦 2 )
• Determine the integral with limit from 0 to 3 of the following functions
1. 𝑓(𝑥) = −𝑥 3
2. 𝑓(𝑥) = 𝑥 2 sin(𝜋𝑥)
c) Laplace Transform
• Determine the Laplace transform of the following t – domain function.
1. 𝑓(𝑡) = 10 sin 2𝑡
2. 𝑓(𝑡) = 2 cosh 4𝑡
3. 𝑓(𝑡) = 5 cos 5𝑡
4. 𝑓(𝑡) = 2𝑡 3 𝑒2𝑡
5. 𝑓(𝑡) = 6𝑒−6𝑡

PREPARED BY: RONEL V. VIDAL, PECE 7


d) Inverse Laplace
• Determine the inverse Laplace of the following s – domain functions.
1. 𝐹(𝑠) = 1⁄ 4
𝑠
2. 𝐹(𝑠) = 5⁄(𝑠 2
+ 16)
3. 𝐹(𝑠) = 2⁄(𝑠
+ 3)3
(𝑠 + 2)
4. 𝐹(𝑠) = ⁄[(𝑠 + 2)2 + 1]
5. 𝐹(𝑠) = 2⁄(𝑠 + 2⁄(𝑠 + 1⁄(𝑠 − 2)
− 2)3 − 2)2
e) Fourier Transform
• Determine the Fourier transform of the following t – domain functions.
1. 𝑓(𝑡) = 10𝛿(𝑡)
2. 𝑓(𝑡) = cos(500𝜋𝑡)
3. 𝑓(𝑡) = 𝑒−2𝑡
4. 𝑓(𝑡) = 𝑡 2 𝑒−|𝑡|

PREPARED BY: RONEL V. VIDAL, PECE 8

You might also like