Symbolic Math Toolbox Symbolic Math Toolbox
In order to enter a transfer function into MATLAB, In order to enter a transfer function into MATLAB, the variables used to contain numerical values must the variables used to contain numerical values must
be ‘converted’ to store
be ‘converted’ to store symbolic variables symbolic variables . This can . This can be done with MATLAB symbolic toolbox.
be done with MATLAB symbolic toolbox.
Command Command
syms syms : Short-cut for constructing symbolic objects : Short-cut for constructing symbolic objects
All variables appearing on the right-hand-side must be All variables appearing on the right-hand-side must be symbolized.
symbolized.
Syntax Syntax
syms arg1 arg2 syms arg1 arg2 ... ...
Type ‘ Type ‘ syms syms ’ to see what variables are symbolized. Use ’ to see what variables are symbolized. Use
‘ ‘ clear arg1 clear arg1 ’ to remove ’ to remove arg1 arg1 from this list. from this list.
1. Using Laplace 1. Using Laplace
Transform in MATLAB
Transform in MATLAB
Laplace Transform Laplace Transform
LAPLACE Laplace transform.
L = LAPLACE(F) is the Laplace transform of the scalar sym F with default default
independent variable t
independent variable t. The default The default return is a function of s
return is a function of s. If F = F(t), then LAPLACE returns a function of s: L = L(s).
By definition L(s) = int(F(t)*exp(-s*t),0,inf), where integration occurs with respect to t.
(Try typing ‘help laplace’ in MATLAB…)
L = LAPLACE(F,t) makes L a function of t instead of the default s:
LAPLACE(F,t) <=> L(t) = int(F(x)*exp(- t*x),0,inf).
L = LAPLACE(F,w,z) makes L a function of z instead of the
default s (integration with respect to w):
LAPLACE(F,w,z) <=> LAPLACE(F,w,z) <=>
L(z) = int(F(w)*exp(-z*w),0,inf).
L(z) = int(F(w)*exp(-z*w),0,inf).
We We ’ ’ d prefer to use d prefer to use laplace(f, t, s) laplace(f, t, s) , or simply , or simply laplace(f).
laplace(f).
Examples:
syms a s t w
laplace(t^5)
laplace(exp(a*t)) laplace(sin(w*t),s) laplace(cos(w*t),t,s)
laplace(heaviside(t),t,s) laplace(heaviside(t-2),t,s)
heaviside(ta) : Unit step function u(ta)
Declare those as symbols instead of numeric values.
All 2
ndand 3
rdarguments for laplace() are not really needed at all.
>> laplace(x^sym(3/2),t)
??? Undefined function or variable 'x'.
>> syms 'ans'
>> syms x
>> laplace(x^sym(3/2),t)
??? Undefined function or variable 't'.
>> syms 'ans' 'x'
>> syms t
>> laplace(x^sym(3/2),t) ans =
3/4*pi^(1/2)/t^(5/2)
f(t)= F(s)=
f(x)=x3/2
F(t) = (3/2+1) / t
(3/2+1)where is the Gamma function defined as the following:
More examples:
Examples:
syms s t w
ilaplace(1/(s-1)) ilaplace(1/(s^2+1))
ilaplace(s/(s^2 + w^2),s,t) ilaplace(1/s,s,t)
ilaplace(exp(-2*s)/s,s,t)
Inverse Laplace Transform Inverse Laplace Transform
All 2
ndand 3
rdarguments for ilaplace() are not really needed at all.
Examples shown in the textbook Examples shown in the textbook
Find the transforms of cosh Find the transforms of cosh at at and and sinh
sinh at at . .
Find the Laplace transform of Find the Laplace transform of
f f ( ( t t ) = ) = e e
tt(3cos20 (3cos20 t t 7sin20 7sin20 t t ). ).
Example 1 Example 1
Consider the initial value problem Consider the initial value problem y y ” + 3 ” + 3 y y ’ + 2 ’ + 2 y y = = e e
tt, , y y (0) = 4 and (0) = 4 and y y ’(0) = 5. ’(0) = 5.
Solution steps: Solution steps:
Let f Let f ( ( t t ) be defined to the right-hand-side function. ) be defined to the right-hand-side function.
Use Laplace transform to convert Use Laplace transform to convert f f ( ( t t ) to ) to F F ( ( s s ). ).
Perform Laplace transform on Perform Laplace transform on y y ”, ”, y y ’ and ’ and y y , , incorporating the initial conditions. Note that
incorporating the initial conditions. Note that y y ( ( t t ) ) becomes
becomes Y Y( (s s). ).
From the resulting algebraic equation, solve for From the resulting algebraic equation, solve for Y Y ( ( s s ). ).
Use inverse Laplace transform to get Use inverse Laplace transform to get y y ( ( t t ) from ) from Y Y ( ( s s ). ).
Example 1 – cont’d Example 1 – cont’d
Consider the initial value problem Consider the initial value problem y y ” + 3 ” + 3 y y ’ + 2 ’ + 2 y y = = e e
tt, , y y (0) = 4 and (0) = 4 and y y ’(0) = 5. ’(0) = 5.
>> syms s t Y
>>
f=exp(-t);
f =
exp(-t)
>>
F=laplace(f ,t,s)
Declaring that these variables are symbolic.
Perform the transform on the non-homogeneous term first.
Part 1: 先求等號右邊的 laplace 轉換
11
Example 1 – cont’d Example 1 – cont’d
Consider the initial value problem Consider the initial value problem y y ” + 3 ” + 3 y y ’ + 2 ’ + 2 y y = = e e
tt, , y y (0) = 4 and (0) = 4 and y y ’(0) = 5. ’(0) = 5.
>> Y1=s*Y-4;
>> Y2=s*s*Y-s*4-5;
>> Sol=solve(Y2+3*Y1+2* Sol=solve(Y2+3*Y1+2* Y- Y - F F , , Y Y ) )
Sol =
(21*s+4*s^2+18)/(1+s)/
(3*s+2+s^2)
>> sol=ilaplace(Sol,s,t) sol =
-8*exp(-2*t)+(12+t)*exp(-t)
>> ezplot(f,[0,10])
>> ezplot(sol,[0,10])
Part 2: y’ sYy(0)
y” s
2Ysy(0)y’(0) = s[sYy(0)] y’(0) (s
2+3s+2)Y=
(4s
2+21s+18)/(s+1) y(t) = 8e
2t+ 12e
t+ te
tThese automatically make Y1 and Y2 symbolic, since Y and s are symbolic.