6
$\begingroup$

Given the transfer function

gs = (5*s + 4)/(s^4 + 4*s^3 + 2*s^2 + 3*s);

and the input signal

ut = Sin[t + π/6;

I want to get the output signal by InverseLaplaceTransform , so I evaluated

gs = (5*s + 4)/(s^4 + 4*s^3 + 2*s^2 + 3*s);
us = LaplaceTransform[Sin[t + π/6], t, s]
xs = us*gs;
xt = InverseLaplaceTransform[xs, s, t]
Plot[xt, {t, 0, 50}]

and I also made what should be the same plot in the MATLAB environment

num=[5,4];
den=[1,4,2,3]
sys=tf(num, den);
t=0:0.1:50;
u=sin(t+pi/6);
y=lsim(sys, u,t);
plot(t,y,'k')

However, the two plots of the output signal are different. Why?

Mathematica result MATLAB result

$\endgroup$
2
  • $\begingroup$ Perhaps you could highlight the difference between the curves that you think is significant, or provide some numerical values. $\endgroup$
    – mikado
    Dec 23, 2019 at 6:20
  • $\begingroup$ i don't know if you can see the 2 pictures that i have uploaded,and the amplitude is different. $\endgroup$
    – dcydhb
    Dec 23, 2019 at 6:22

3 Answers 3

18
$\begingroup$

You missed one term in Matlab. den=[1,4,2,3,0]; and not den=[1,4,2,3]; The order is important in Matlab. Since you do not have constant term in denominator polynomial, you need to add an explicit 0 in the right most entry in the array. So s^4 + 4*s^3 + 2*s^2 + 3*s) becomes [1,4,2,3,0]

This is good example, why symbolic is simpler than using numerical array to indicate the expression. Most people make such mistakes counting positions all the time in Matlab.

ClearAll[s, t]
gs = (5*s + 4)/(s^4 + 4*s^3 + 2*s^2 + 3*s);
ut = Sin[t + Pi/6];
us = LaplaceTransform[ut, t, s];
xs = us*gs;
xt = InverseLaplaceTransform[xs, s, t];
Plot[xt, {t, 0, 50}, GridLines -> Automatic, 
 GridLinesStyle -> LightGray, PlotStyle -> Red]

Mathematica graphics

num=[5,4];
den=[1,4,2,3,0];
sys=tf(num, den);
t=0:0.1:50;
u=sin(t+pi/6);
y=lsim(sys, u,t);
plot(t,y,'k')

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ yes and thanks a lot! $\endgroup$
    – dcydhb
    Dec 23, 2019 at 6:40
9
$\begingroup$

With Mathematica you can also do the following

tf = TransferFunctionModel[(5 s + 4)/(s^4 + 4 s^3 + 2 s^2 + 3 s), s];
out = OutputResponse[tf, Sin[t + Pi/6], {t, 0, 50}];
Plot[out, {t, 0, 50}, GridLines -> Automatic]

enter image description here

$\endgroup$
6
$\begingroup$

With Mathematica, I get significantly different results than your Mathematica results. I do not have access to matlab nor know whether the matlab code shown is correct.

$Version

(* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *)

Clear["Global`*"]

ut = Sin[t + π/6];

us = LaplaceTransform[ut, t, s] // Simplify

(* (Sqrt[3] + s)/(2 + 2 s^2) *)

Verifying

InverseLaplaceTransform[us, s, t] == ut // Simplify

(* True *)

gs = (5*s + 4)/(s^4 + 4*s^3 + 2*s^2 + 3*s);

xs = us*gs;

xt = InverseLaplaceTransform[xs, s, t] // FullSimplify

enter image description here

Verifying,

LaplaceTransform[xt, t, s] == xs // FullSimplify

(* True *)

Plot[xt, {t, 0, 50}]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.