# What is wrong with the plot of this transfer function?


n = 13;
Show[Plot[

Evaluate[Chop @
OutputResponse[
TransferFunctionModel[Unevaluated[{{1/(s (s + 2) (s + 3))}}], s,
SamplingPeriod ->None, SystemsModelLabels -> None], Ramp[t],
t]], {t, 0, n}, PlotRange -> All],
Plot[Ramp[t], {t, 0, n}, PlotRange -> All, PlotStyle -> Red]]



for $n=10$ this works fine

I am not exactly sure if I am plotting transfer function the right way. Any help is appriciated.

Use Simplify rather than Chop which only works on numerical results

n = 13;
Show[Plot[
Evaluate[Simplify@
OutputResponse[
TransferFunctionModel[Unevaluated[{{1/(s (s + 2) (s + 3))}}], s,
SamplingPeriod -> None, SystemsModelLabels -> None], Ramp[t],
t]], {t, 0, n}, PlotRange -> All],
Plot[Ramp[t], {t, 0, n}, PlotRange -> All, PlotStyle -> Red]]


Just to show why this happens; take a look at this example:

Plot[Exp[5 t] (Exp[-5 t] - t/t + 1), {t, 0, 20}]


The plot above should have been a horizontal line across 1, but it's not. What happens here is that the HoldAll attribute of Plot prevents any symbolic transformation to be done, or the expression sometimes is too complicated and time consuming for Mathematica to automatically simplify (like your case), so small numerical errors that are multiplied by terms like Exp[t] become significant in the plot. Thus, Simplify would be helpful in this case.

Plot[Evaluate[Exp[5 t] (Exp[-5 t] - t/t + 1) // Simplify], {t, 0, 20}]


• That was a lifesaver Commented Apr 5, 2017 at 5:33

On a side note, Your system is marginally unstable (sometimes called marginally stable)

n = 13;
sys = TransferFunctionModel[{{1/(s (s + 2) (s + 3))}}, s,
SamplingPeriod -> None, SystemsModelLabels -> None]


poles = TransferFunctionPoles[sys]


Now to the main question. I have always used the numerical version of output response. I find it much faster as well. The method you used produces analytical solution. And I am not sure why the analytical solution becomes unstable for large t. However the numerical solution works:

out = First@OutputResponse[sys, Ramp[t], {t, 0, 20}];
Plot[out, {t, 0, 20}]


Verified with Matlab, it gives same result as above:

>> clear
>> s=tf('s');
>> sys = 1/(s*(2+s)*(3+s));
>> t=0:0.1:20;[y,t]=lsim(sys,t,t);
>> plot(t,y)


When in doubt with OutputResponse use the numerical version, which happens automatically when you change t to {t,0,20} and it is much faster also.

It is possible the analytical solution have some issues.

 out = First@OutputResponse[sys, Ramp[t], t]


 Plot[out, {t, 0, 20}]


On other hand, it is possible the analytical solution is actually correct and the numerical solution is not! Since this is marginally stable system. Hard for me to say now. May be someone who knows more can look into this.

update

I just verified this using Maple 2016.2, and it gives same plot as Matlab and Mathematica's numerical version. This leads me to think Mathematica analytical solution is the one that could have some issue in it:

 sys := DynamicSystems:-TransferFunction(1/(s*(2+s)*(3+s)));
p1:=DynamicSystems:-ResponsePlot(sys, t,duration=20);


One way to really make sure, is the following: Convert the transfer function to ODE, and solve the ODE with ramp input and see if you get same solution as one given by OutputResponse or not. No time to do this now, have to go. Will try to do this later.

• Actually it's caused by numerical error. You can get the same plot from analytical results by simplifying out. I believe, due to the complex form of the solution and the HoldAll property of Plot, large numerical errors are not uncommon in such cases. Commented Apr 4, 2017 at 10:44
• Thank you, I have upvoted you. I wish there is an "accept both answer" Commented Apr 5, 2017 at 5:33