Message Boards Message Boards

0
|
2630 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why outputresponse in discrete takes so long with this system?

Dear Members of the community,

I want to experiment with the new functionalities of Mathematica regarding model predictive control. In the process, I found troubles using outputresponse[] for discrete systems. Even for a few sample points, the response takes considerable time. My workflow is in the attached notebook.
I have doubts using ToDiscreteTimeModel[]. It seems to me that, in this case, Mathematica is using Euler's formula to approximate the derivative. I could not find much information about this. Is there documentation about this?
Also, I would like to know if it is possible to name the discrete variable and not use the automatic name given by Mathematica in this step.
It might be the case that the discrete systems be unstable because of the sampling time I am using, but I guess this will not be the cause of outputresponse[] taking so long.
I will appreciate your comments since I usually work in continuous time.

Jesus

2 Replies
Posted 1 year ago

Jesus,

The reason your simulations take so long to run is that you have some terms with infinite precision (Pi). If you numericise the transfer function it runs a thousand times faster.

    ToDiscreteTimeModel[N[AffineSS], dt, z]

putting the third argument, z, means that you want the discrete variable to be "z"

The default conversion to digital is not stable unless you lower your time step. I got reasonable short duration results with

    dt = 1/50/100000;

Your u2 definition does not agree with the continuous definition. It should be:

    u2 = Table[0., {z, 0, np}];

The simulation takes a long time because we are using such a tiny time step to maintain stability. np =200,000 works and exactly matches the continuous data:

    Show[ListPlot[SimuDT[[1, All]], DataRange -> {0, np*dt}, 
      PlotStyle -> Red], Plot[SimuAffine[[1]], {t, 0, np*dt}]]

You should use more stable conversion options for ToDiscreteTimeModel[]. The options are put in like this: Method->"ForwardRectangularRule"

For example:

DTAffineSS = 
 ToDiscreteTimeModel[N[AffineSS], dt, z, 
  Method -> "ForwardRectangularRule"]

The options are {"ForwardRectangularRule", "BackwardRectangularRule", "BilinearTransform", "ZeroOrderHold", "FirstOrderHold"}

Unfortunately, there seems to be a bug for all options except ForwardRectangularRule. I would report this to Wolfram. The other options should work (and be more stable allowing for a larger timestep)

I hope this helps.

Regards

Neil

POSTED BY: Updating Name

Neil,

Thank you very much. Your comments are constructive. The conversion is not easy, as you could verify, but this slow result is a start!! If I may, I suggest to Wolfram to increase the examples on ToDiscreteTimeModel[] and nonlinear models in general.

Thank you again!

Jesus

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract