discretize a nonlinear model in YALMIP

192 views
Skip to first unread message

陈海亮

unread,
Apr 25, 2017, 8:58:06 AM4/25/17
to YALMIP
hi,Dr.Johan

 i want to ask how to discretize  a nonlinear continuous model  (dx/dt=Ax(t)+Bu(t)+w(t))   in yalmip ?

Thanks

Johan Löfberg

unread,
Apr 25, 2017, 9:00:49 AM4/25/17
to YALMIP
If you mean A and B are sdpvars, then you cannot apply c2d. The closest you can do is to use a simple Euler approximation x(t+Ts) = x(t) + Ts*(Ax(t) + Bu(t)) = (I+TsA)x(t) + (TsB)u(t)


陈海亮

unread,
Apr 25, 2017, 9:11:11 AM4/25/17
to YALMIP
yes, my A and B are sdpvars, and does 'w' (sdpvar)  keeps unchanged during discretization?

Johan Löfberg

unread,
Apr 25, 2017, 9:19:28 AM4/25/17
to YALMIP
same thing of course x(t+Ts) = x(t) + Ts*(Ax(t) + Bu(t)+w(t)).

However, didn't we discuss precisely this thing last week. If you want to create an optimizer object where your parameters influence the continuous-time data but your optimization model involves the discrete-time model, then you parameterize the model in terms of the discrete-time model, and compute the discrete-time model when you have the data, before calling the optimizer object. 

陈海亮

unread,
Apr 25, 2017, 11:00:00 AM4/25/17
to YALMIP
yes, i know. i will follow that structure and thanks for your support.

陈海亮

unread,
Apr 26, 2017, 4:19:47 AM4/26/17
to YALMIP
Hello,Dr.Johan
 x(t+Ts) = x(t) + Ts*(Ax(t) + Bu(t)+w(t)) , this discretization method seems didn't work.
here is part of my code

sdpvar  Ad,Bd,Edw

        Adr=Ts*Ac+eye(4);

        Bdr=Ts*Bc;

        Edwr=Ts*wr;  (Ac,Bc,wr are continuous model matrice and calculated in advance)

………………
 controller = optimizer(constraints,objective,ops,{Ad,Bd,Edw,x{1},r},u{1});
         uout = controller{{Adr,Bdr,Edwr,currentx,currentr}};

Johan Löfberg

unread,
Apr 26, 2017, 4:22:50 AM4/26/17
to YALMIP
didn't work is a pretty vague description...

note that optimizer no longer requires cells when calling, i.e, you can write  controller(Adr,Bdr,Edwr,currentx,currentr)

Johan Löfberg

unread,
Apr 26, 2017, 4:23:36 AM4/26/17
to YALMIP
and why are you using this simple discretization when you just as well can use c2d

陈海亮

unread,
Apr 26, 2017, 4:44:30 AM4/26/17
to YALMIP
ok, i know.

c2d seems didn't work too. 

But i doubt discretization model lead to the problem  for the reason that i  meet the same situation before which is as follows(a trajectory following control based on MPC,where bule line is the reference trajectory, red one is the real trajectory)




Johan Löfberg

unread,
Apr 26, 2017, 4:46:06 AM4/26/17
to YALMIP
obviously it's not about the discretization, but about the general tuning and setup of your controller

Saeed

unread,
Jun 5, 2017, 4:10:07 AM6/5/17
to YALMIP
Dear Johan,

When we use Euler backward method, x(k-1) will appear in difference equation as x(t)- x(t-1) =Ts*(Ax(t) + Bu(t)) =>x(t)= (I-TsA)^-1 x(t-1) + Ts(I-TsA)^-1 Bu(t)
So, for simulation, the will  state matrix be (I-TsA)^-1 ? and the input matrix Ts(I-TsA)^-1 B?

Is there any special difference between backward and Forward Euler methods, when we apply the discrete model in MPC simulation?

Johan Löfberg

unread,
Jun 5, 2017, 4:14:42 AM6/5/17
to YALMIP
there is a whole plethora of methods for discretizing linear dynamics, with Euler being the trivial but non-exact one. read, e.g., the reference pages on c2d and go from there to learn the theory

Saeed

unread,
Jun 5, 2017, 4:53:58 AM6/5/17
to YALMIP
Thanks a lot,
But what about the state matrix in backward euler method?
Ad = (I-TsA)^-1 ??
Should we use x(t)= (I-TsA)^-1 x(t-1) + Ts(I-TsA)^-1 Bu(t)  for prediction model in nominal MPC in YALMIP?

Johan Löfberg

unread,
Jun 5, 2017, 7:01:19 AM6/5/17
to YALMIP
In a real situation where you don't need a simple parameterization, you would use an exact zero-hold based on integration of the dynamics, i.e, what you get from c2d. Euler approximation is just a hack to get something easily parameterized in continuous A matrix

陈海亮

unread,
Jun 15, 2017, 3:52:54 AM6/15/17
to YALMIP
hi,Dr Johan

sorry to interrupt you again.
 
i want to ask something about discretize a LTI model, dx/dt=Ax(t)+Bu(t)+W, Y=Cx(t)+Du(t),    where A,B,C,D,W are constant.

here i have some methods,will they all be ok?(The main problem is that i don't know how to deal with W)

1.x(k+1)-x(k)=Ts*Ax(k)+Ts*Bx(k)+Ts*W =>x(k+1)=(Ts*A+I)x(k)+Ts*Bx(k)+Ts*W 

2.x(k+1)-x(k)=(Ts*A+I)x(k)+Ts*Bx(k)+W ??

3.dmodel=c2d(A,B,C,D),Ad=dmodel.A,Bd=dmodel.B =>x(k+1)=Adx(k)+Bdx*u(k)+W

4.dx/dt=Ax(t)+Bu(t)+W=>dx/dt=Ax(t)+Bu(t)+I*W=>dx/dt=Ax(t)+[B I]*[u(t) W]'=>c2d(A,[B I],C,D) (where I is the unit matrix)=>split  discretized matrice [B I] to get the discretize matrice of B,W


Thanks

Johan Löfberg

unread,
Jun 15, 2017, 6:04:36 AM6/15/17
to YALMIP
You appear to have a weak understand of what a discretization actually is, otherwise it would be obvious that 2 is clearly wrong and you are treating W strangely

dxdt = f(x,q) is can be approximated by x(t+Ts) = x(t) + Ts*f(x(t),q(t)). Whether q involves control or disturbances is not interesting, its just a simple Euler approximation of the differential equation

When f is linear dxdt = Ax + Bq, you can create an exact zoh prediction x(t+Ts) = Fx(t) + Gq(t). Once again, the fact that q = [u;W] is not interesting. As long as q is an external zoh signal, that is an exact prediction

陈海亮

unread,
Jun 15, 2017, 9:26:19 AM6/15/17
to YALMIP
that seems 1 and 4 are right.
Additional question, i know zoh but i don't know why q msut be  an external zoh signal?  i don't understand well.

Johan Löfberg

unread,
Jun 15, 2017, 9:35:17 AM6/15/17
to YALMIP
They must be constant during the sample, otherwise it is impossible to solve the differential equation over one sample analytically, which is done when you apply c2d. c2d analytically solves the differential equation dxdt = Ax + Bq for Ts seconds, under assumption that q is constant during this time. Being external is just another way of saying that is doesn't vary as a function of x or something like that. Constant is the only important property

陈海亮

unread,
Jun 15, 2017, 9:49:36 AM6/15/17
to YALMIP
But q  involves control in the most situations and control is to be solved , how do i know it is an external zoh signal?

Johan Löfberg

unread,
Jun 15, 2017, 10:58:00 AM6/15/17
to YALMIP
Whether God chose the value, you did based on an algorithm, or whatever, does not matter, as long as it is fixed over the sample.

Start reading on the section Derivation.
Reply all
Reply to author
Forward
0 new messages