You are on page 1of 6

NATIONAL UNIVERSITY

551 M.F. JHOCSON ST., SAMPALOC, MANILA

COLLEGE OF ENGINEERING

ACTIVITY NO. 1
THE SYMBOLIC MATH TOOLBOX

OBJECTIVES:
This activity aims to:
1. present MATLAB’s Symbolic Math Toolbox as a tool for performing operations on expressions and
equations; and
2. demonstrate the use of the tool in performing common control systems engineering tasks such as simplifying
expressions, solving roots of the polynomials, solving differential equations and Laplace and inverse Laplace
transformations.

LEARNING OUTCOMES (LOs) COURSE LEARNING OUTCOMES (CLOs)


At the end of the activity, the students should be
able to: 1 2 3 4 5 6
1. use the functions provided by the Symbolic
Math Toolbox to perform operations on ●
expressions and equations.

COURSE LEARNING OUTCOMES (CLOs)


At the end of the course, the students should be able to:
1. Construct mathematical models for open- and closed-loop dynamic systems using Laplace transforms.
2. Analyze the performance of dynamic systems in terms of transient response, steady-state error and stability.
3. Use root-locus techniques to analyze systems and design active and passive compensators for the
improvement of system characteristics.
4. Use frequency response techniques to analyze systems and design active and passive compensators for
the improvement of system characteristics.
5. Use MATLAB as a tool in the analysis and design of dynamic systems.
6. Design a feedback control system.

MATERIALS/EQUIPMENT NEEDED:
A workstation installed with MATLAB and Control Systems Toolbox and Symbolic Math Toolbox.
ACTIVITY PROPER:

The Symbolic Math Toolbox of MATLAB provides functions for solving, plotting and manipulating symbolic math
equations. The toolbox provides libraries of functions in common mathematical areas such as calculus, linear
algebra, algebraic and ordinary differential equations, equation simplification and equation manipulation.

This activity will demonstrate the use of different functions available under the Symbolic Math toolbox in order to
manipulate and solve expressions and equations.

Procedure: Rewriting expressions


1. Use combine function for combining subexpressions of an original expression.
Command window:
>> clear all, close all
>> syms x y
>> combine(2*sin(x)*cos(x),'sincos')
>> combine(sqrt(2)*sqrt(x))
>> combine(sqrt(x)*sqrt(y))
>> combine(sqrt(x)*sqrt(y),'IgnoreAnalyticConstraints',true)
>> assume([x,y],'positive'), combine(sqrt(x)*sqrt(y))

1
Procedure: Rewriting expressions
2. For elementary expressions, use the expand function to transform the original expression by multiplying sums
of products.
Command window:
>> clear all, close all
>> syms x y
>> expand((x - 1)*(x - 2)*(x - 3))
>> expand(x*(x*(x - 6) + 11) - 6)
>> expand(exp(x + y)*(x + exp(x - y)))
>> syms a b c positive; expand(log(a*b*c))
>> expand(cos(x + y))
>> expand(sin(5*x))
>> expand(cos(3*acos(x)))
>> expand((sin(3*x) + 1)*(cos(2*x) - 1))
>> syms x y clear
3. Factor expressions.
Command window:
>> clear all, close all
>> syms x
>> factor(x^3 - 6*x^2 + 11*x - 6)
>> factor(x^6 + 1)
>> factor(x^6 + 1,'FactorMode','complex')
>> factor((log(x)^2 - 1)/(cos(x)^2 - sin(x)^2))
4. Rewrite expressions in terms of other functions.
Command window:
>> clear all, close all
>> syms x
>> rewrite(sin(x),'tan')
>> rewrite(cos(x),'tan')
>> rewrite(sin(2*x) + cos(3*x)^2,'tan')
>> rewrite(sin(x),'exp')
>> rewrite(cos(x),'exp')
>> rewrite(sinh(x),'exp')
>> rewrite(cosh(x),'exp')
5. Simplify expressions.
Command window:
>> clear all, close all
>> syms x y
>> simplify((1 - x^2)/(1 - x))
>> simplify((x - 1)*(x + 1)*(x^2 + x + 1)*(x^2 + 1)*(x^2 - x + 1)*(x^4 - x^2 + 1))
>> simplify(cos(x)^2 - sin(x)^2)
>> simplify(log(x) + log(sym(3)) - log(3*x)+(exp(x) - 1)/(exp(x/2) + 1))
>> simplify(log(x^2) + log(x),'IgnoreAnalyticConstraints',true)
>> simplifyFraction((x^3 - 1)/(x - 1))
>> simplifyFraction((x^3 - x^2*y - x*y^2 + y^3)/(x^3 + y^3))
>> simplifyFraction((1 - exp(x)^4)/(1 + exp(x))^4)
6. Compute partial fraction decompositions of expressions.
Command window:
>> clear all, close all
>> syms x
>> n = x^6 + 15*x^5 + 94*x^4 + 316*x^3 + 599*x^2 + 602*x + 247;
>> d = x^6 + 14*x^5 + 80*x^4 + 238*x^3 + 387*x^2 + 324*x + 108;
>> partfrac(n/d, x)

Tip: For expressions containing even rational powers or logarithms, always make the assumption that your symbolic
variables are positive. Remember to clear the assumptions whenever you are to use the symbolic variables again in
another computation and you do not want the assumption to apply.

2
Question 1 : Perform the following operations using the functions used in the above procedure. Write the
commands you have used and write the results.
𝑦
a. Combine 2 ln 2𝑥 − 3 ln 5 + 2 ln 𝑧 2 in a single logarithmic expression.
b. Expand the expression sin 3𝑥 cos 2𝑥.
c. Factor the expression 40𝑥 6 − 348𝑥 5 𝑦 + 1218𝑥 4 𝑦 2 − 2165𝑥 3 𝑦 3 + 2007𝑥 2 𝑦 4 − 864𝑥𝑦 5 + 108𝑦 6
d. Rewrite the expression sin5 2𝑥 cos3 2𝑥 as an expression in terms of sines only.
12𝑥 7 +48𝑥6 −189𝑥 5 −129𝑥 4 +426𝑥3 +189𝑥 2 −267𝑥−126
e. Simplify the expression 18𝑥 7+135𝑥6−171𝑥 5−1710𝑥4+2457𝑥 3+3735𝑥2−8244𝑥+3780.
14𝑥 5 +208𝑥 4 +1206𝑥 3 +3593𝑥2 +5400𝑥+2755
f. Express the rational expression 𝑥 6+19𝑥 5+143𝑥 4+554𝑥 3+1187𝑥2+1315𝑥+525 as partial fractions.

Procedure: Equation solving


1. Solve the symbolic equation 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0 in terms of the variables 𝑥 and 𝑏.
Command window:
>> clear all
>> syms a b c x
>> eqn = a*x^2 + b*x + c == 0;
>> solx = solve(eqn,x)
>> solb = solve(eqn,b)
2. Solve non-linear equations and visualize its solutions.
Command window:
>> clear all, syms x
>> solx = solve(cos(x) == -sin(x),x)
>> [solx,param,cond] = solve(cos(x) == ...
-sin(x),x,'ReturnConditions',true)
>> assume(cond)
>> solk = solve(-2*pi < solx, solx < 2*pi,param)
>> xvalues = subs(solx, solk)
>> xvalues = vpa(xvalues)
>> fplot(cos(x))
>> hold on; grid on;
>> fplot(-sin(x))
>> title('Both sides of equation cos(x) = -sin(x)')
>> legend('cos(x)','-sin(x)','Location',...
'best','AutoUpdate','off')
>> yvalues = cos(xvalues)
>> scatter(xvalues,yvalues)
3. Solve systems of equations:

Command window:
>> clear all, syms x y a
>> [solx, soly] = solve((x^2)*(y^2) == 0, ...
x - y/2 == a)
4. Solve systems of equations:

Command window:
>> clear all, syms u v a
>> S = solve(u^2 - v^2 == a^2, u + v == 1,...
a^2 - 2*a == 3)
>> S.a, S.u, S.v
>> soln = [S.a S.u S.v]
5. Solve systems of equations:

return all the possible solutions along with the parameters in the solution and the conditions on the solution.
Visualize the system of equations and the solutions.
Command window:
>> clear all, syms x y
>> eqn1 = sin(x)+cos(y) == 4/5;
3
Procedure: Equation solving
>> eqn2 = sin(x)*cos(y) == 1/10;
>> a = axes;
>> fimplicit(eqn1,[-2*pi 2*pi],'b');
>> hold on, grid on
>> fimplicit(eqn2,[-2*pi 2*pi],'m');
>> L = sym(-2*pi:pi/2:2*pi);
>> a.XTick = double(L); a.YTick = double(L);
>> M = arrayfun(@char, L, 'UniformOutput', false);
>> a.XTickLabel = M; a.YTickLabel = M;
>> title('Plot of System of Equations')
>> legend('sin(x)+cos(y) == 4/5',...
'sin(x)*cos(y) == 1/10', 'Location',...
'best','AutoUpdate','off')
>> Srange = solve(eqn1, eqn2, -2*pi<x, x<2*pi,...
-2*pi<y, y<2*pi,'ReturnConditions', true);
>> scatter(Srange.x, Srange.y,'k')
6. Solve the first order differential equation
𝑑𝑦
= 𝑡𝑦
𝑑𝑡
with and without initial conditions.
Command window:
>> clear all, syms y(t)
>> ode = diff(y,t) == t*y
>> ySol = dsolve(ode)
>> cond = y(0) == 2;
>> ySol2 = dsolve(ode,cond)
7. Solve the first order nonlinear differential equation
2
𝑑𝑦
( + 𝑦) = 1
𝑑𝑡
with the initial condition 𝑦(0) = 0.
Command window:
>> clear all, syms y(t)
>> ode = (diff(y,t)+y)^2 == 1;
>> cond = y(0) == 0;
>> ySol = dsolve(ode,cond))
8. Solve the third-order ODE
𝑑3 𝑢
=𝑢
𝑑𝑥 3
with initial conditions 𝑢(0) = 1, 𝑢 ′ (0)
= −1, 𝑢 ′′ (0)
= 𝑝𝑖.
Command window:
>> clear all, syms u(x)
>> Du = diff(u,x);
>> D2u = diff(u,x,2);
>> ode = diff(u,x,3) == u;
>> cond1 = u(0) == 1;
>> cond2 = Du(0) == -1;
>> cond3 = D2u(0) == pi;
>> conds = [cond1,cond2,cond3];
>> uSol = dsolve(ode,conds)
>> pretty(uSol)

Question 2: Perform the following operations using the functions used in the above procedure. Write the
commands you have used and write the results.
𝑎+1 𝑎−1 𝑏+1
a. Solve the equation 𝑏 = 𝑏 + 𝑎 for the variables 𝑎 and 𝑏.
b. Solve the non-linear equation 4 sin 2𝑥 − 2 cos 𝑥 = 0 for 0 ≤ 𝑥 ≤ 2𝜋.
c. Solve the equation 𝑠 8 + 𝑠 7 + 12𝑠 6 + 22𝑠 5 + 39𝑠 4 + 59𝑠 3 + 48𝑠 2 + 38𝑠 + 20 = 0.
3𝑥 2 + 2𝑦 = 26
d. Find all the solutions of the system { 2 and visualize them. Print the plot on a separate sheet of
5𝑥 + 7𝑦 = 3
paper and attach it to this report.
𝑑𝑦
e. Solve the differential equation 𝑥 𝑑𝑥 + 𝑥𝑦 = 1 − 𝑦 if 𝑦(1) = 0.
f. Solve the differential equation 𝑦 ′′′ + 𝑦 ′ = cos 𝑡 given the conditions 𝑦(0) = 2, 𝑦 ′ (0) = 1 and 𝑦 ′′ (0) = −2.

4
Procedure: Laplace and inverse Laplace transform
1
1. Compute the Laplace transform of 𝑓(𝑡) = .
√𝑥
Command window:
>> clear all, syms x y
>> f = 1/sqrt(x);
>> F = laplace(f), pretty(F)
2. Compute the Laplace transform of 𝑓(𝑡) = 𝑒 −𝑎𝑡 , with 𝑎 being a constant.
Command window:
>> clear all, syms a t
>> f = exp(-a*t);
>> F = laplace(f), pretty(F)
3. Compute the Laplace transform of 𝑓(𝑡) = cos(𝑎𝑡 + 𝑏), 𝑎 and 𝑏 are parameters of the function.
Command window:
>> clear all, syms a b t
>> f = cos(a*t+b)
>> F = laplace(f), pretty(F)
4. Compute the Laplace transform of 𝑓1 (𝑡) = 𝛿(𝑡) the Dirac function and 𝑓2 (𝑡) = 𝑢(𝑡), the Heaviside, or step,
function.
Command window:
>> clear all, syms t s k
>> assume(k,'positive'),
>> F1 = laplace(dirac(t-k)), pretty(F1)
>> F2 = laplace(heaviside(t - k)), pretty(F2)
1
5. Compute the inverse Laplace transform of 𝐹(𝑠) = 2.
𝑠
Command window:
>> clear all, syms s
>> F = 1/s^2;
>> f = ilaplace(F)
1
6. Compute the inverse Laplace transform of 𝐹(𝑠) = (𝑠−𝑎)2.
Command window:
>> clear all, syms s a
>> F = 1/(s+a)^2;
>> f = ilaplace(F)
𝑒 −2𝑠
7. Compute the inverse Laplace transform of 𝐹(𝑠) = 2
𝑠 +1
Command window:
>> clear all, syms s t
>> F = exp(-2*s)/(s^2+1)
>> f = ilaplace(F,s,t)

Question 3: Perform the following operations using the functions used in the above procedure. Write the
commands you have used and write the results.
a. Find the Laplace transform of the function 𝑓(𝑡) = 5 cosh 2𝑡 − 3 sinh 𝑡. Express the answer as a single fraction.
1
b. Find the Laplace transform of 𝑓(𝑡) = 16𝑡 2 𝑢 (𝑡 − ). Express the answer as a single fraction.
4
c. Find the Laplace transform 𝑓(𝑡) = sin 𝜔𝑡 ⋅ cos 𝜔𝑡.
7.5
d. Find the inverse Laplace transform of 𝐹(𝑠) = 𝑠2−2𝑠−8.
2𝑠−10
e. Find the inverse Laplace transform of 𝐹(𝑠) = ⋅ 𝑒 −5𝑠 .
𝑠3
3𝑠+4
f. Find the inverse Laplace transform of 𝐹(𝑠) = 𝑠2+4𝑠+5.

Question 4: What are the roots of 𝑃(𝑥) = 𝑥 6 + 9𝑥 5 + 8𝑥 4 + 9𝑥 3 + 12𝑥 2 + 15𝑥 + 20?

Question 5: What polynomial has the roots −7, −8, −3, −5, −9, and −10? Show how to solve this problem using
MATLAB.

5𝑠+10
Question 6: Show how you can obtain a partial fraction expansion of 𝐹(𝑠) = using MATLAB.
𝑠 3 +8𝑠 2 +15𝑠

5
Question 7: Do the following.
a. Express
20(𝑠 + 2)(𝑠 + 3)(𝑠 + 6)(𝑠 + 8)
𝐺1 (𝑠) =
𝑠(𝑠 + 7)(𝑠 + 9)(𝑠 + 10)(𝑠 + 15)
as a ratio of two polynomials.
b. Express
𝑠 4 + 17𝑠 3 + 99𝑠 2 + 223𝑠 + 140
𝐺2 (𝑠) =
𝑠 5 + 32𝑠 4 + 363𝑠 3 + 2092𝑠 2 + 5052𝑠 + 4320
as a ratio of product of linear or quadratic factors.

Question 8: Solve the differential equation


𝑑2 𝑥 𝑑𝑥
+2 + 3𝑥 = 1
𝑑𝑡 2 𝑑𝑡
with 𝑥(0) = 1, 𝑥 ′ (0)
= −1. Plot 𝑥(𝑡) for 0 ≤ 𝑡 ≤ 5.

Question 9: Write a partial fraction expansion of

Question 10: Find the Laplace transform of the following.


a. 𝑓(𝑡) = 8𝑡 2 cos(3𝑡 + 45°)
b. 𝑓(𝑡) = 3𝑡𝑒 −2𝑡 sin(4𝑡 + 60°)

Question 11: Find the inverse Laplace transform of the following.


(𝑠 2 +3𝑠+10)(𝑠+5)
a. 𝐺(𝑠) = (𝑠+3)(𝑠+4)(𝑠2 +2𝑠+100)
𝑠 3 +4𝑠 2 +2𝑠+6
b. 𝐺(𝑠) = (𝑠+8)(𝑠2
+8𝑠+3)(𝑠 2 +5𝑠+7)

Conclusions and Recommendations: Write your thoughts, take-aways, and recommendations for this activity.

References
MATLAB. (n.d.). Retrieved June 27, 2017, from http://bit.ly/SymMathTB

Laboratory Manual for Feedback and Control Systems Lab (FCONSYL). Written 2019-06-01.

You might also like