# Problem with step response of state space model

I have a continuous state space model for dc motor. I get a wrong step response when I use continuous model and I get the right response when I discretize the model using a different method. Can anyone solve this problem?

(* Defination of state space matrix  *)
A = {{-833.3 ,-25.18} , {5193 ,-7.145}}   ;
B = { {303.03},{0}}  ;
c={{ 0 , 60/(2*\[Pi])  }};
d= {{0}} ;
(* Response to 12 volt supply ( Analog ) *)
ssmC= StateSpaceModel[{A, B, c, d } ]
Res=OutputResponse[ssmC , 12 , t ]   ;
PlotA=Plot[ {Res}, {t,0, 15 },PlotLabel-> {" step Response "}, PlotRange-> 1500]

(* Response to 12 volt supply (ZOh) *)

DssmZoH= ToDiscreteTimeModel [ssmC , 0.020 ,Method -> "ZeroOrderHold"]

Res  = OutputResponse[DssmZoH ,12*UnitStep[n], n ]

PlotB= DiscretePlot[{ Res },{n,0,80} , PlotLegends -> {"ZoH " }, PlotRange-> 1500]

(* Response to 12 volt supply (FD) *)
add= {{1,0} , {0,1}} + 0.0020*A
ddd= 0.0020*B
ssmC=StateSpaceModel[{add, ddd , c, d },SamplingPeriod->0.0020 ]
Res6=OutputResponse[ssmC ,12*UnitStep[n], n ] ;
PlotC= DiscretePlot[{ Res6 },{n,0,40} , PlotLegends -> {"Forword diff" }, PlotRange-> 1500]


I agree with @Lotus. I think he has a good general solution to this issue. I answer here only to suggest what went wrong.

On version 12, I get a different, but also wrong, result in the plot of the continuous model.

(*Defination of state space matrix*)
A = {{-833.3, -25.18}, {5193, -7.145}};
B = {{303.03}, {0}};
c = {{0, 60/(2*\[Pi])}};
d = {{0}};

(*Response to 12 volt supply (Analog)*)
ssmC = StateSpaceModel[{A, B, c, d}];

Res = OutputResponse[ssmC, 12, t] I paste an image above so we can see the form of the output response.

(* Plot returns a wrong result *)

PlotA = Plot[{Res}, {t, 0, 15}, PlotLabel -> {" step Response "},
PlotRange -> 1500] But we see that for values of t greater than about 1, we encounter underflow:

(* due to underflow *)

Res /. t -> 1 (* simplifying Res brings the problem within the available precision *)

Res2 = Res // Simplify Res2 /. t -> 1

(* {1318.999525814868} *)

PlotA2 = Plot[{Res2}, {t, 0, 15}, PlotLabel -> {" step Response "},
PlotRange -> 1500] So I suggest that underflow was the root problem, and that the answer by Lotus provides a good general solution.

• thinks for you explanation , i think its clear now – Mechatronics World Jul 8 '19 at 14:44

I am not convinced that the above behaviour is expected, but here is what works. Rationalize the State-Space matrices and then use WorkingPrecision option inside Plot.

A = Rationalize[{{-833.3, -25.18}, {5193, -7.145}}, 0];
B = Rationalize[{{303.03}, {0}}, 0];
c = {{0, 60/(2*\[Pi])}};
d = {{0}};

ssmC = StateSpaceModel[{A, B, c, d}]
Res = OutputResponse[ssmC, 12, t]

PlotA = Plot[{Res}, {t, 0, 15}, PlotLabel -> {" step Response "},
PlotRange -> 1500, WorkingPrecision -> 20]
` 