# Minimization of cost function on MPC

조회 수: 13 (최근 30일)
답변: Sam Chak 2022년 11월 7일
Hello,
I want to optimize a cost function of MPC which is output reference tracking as shown below:
min J(∆u) = ||xref(k + i) − x(k + i)||2 Q+ ||∆u(k + i)||2 R + ||xref(k + N) − x(k + N)||2 S, where Q,R and S are weight matrices.
Can anyone tell me how can I optimize this with constraint -1<∆u<1. Is it better use solver or can I optimize it without using solver?
If using solver, how can I convert into standard solver form?
If without using solver, which function to be used to minimize this cost function?
Any help is appreciated. Thanks in advance
##### 댓글 수: 7이전 댓글 5개 표시이전 댓글 5개 숨기기
Sam Chak 2022년 11월 6일
I think it depend on the problem and how you want to call quadprog() to perform the minimization and update the desired parameter in each iteration. If it is a MPC problem, then I prefer to use mpc() command:
mpcobj = mpc(plant, ts, P, M, W, MV, OV, DV)
I have not used mpc command or toolbox in my optimization proble. I created matrices which predicts future states and optimize the control variable. I just wanted to know how can I give initial state as 0 and update the state for each iteration as my control variable and state changes every iteration and without using mpc commands.
Thank you

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Sam Chak 2022년 11월 7일
You have a system model sys and I presume that you have written your own code for the ODE_solver to run the sys.
Under normal circumstances, you should be able to specify the initial states y0 in the ODE_solver.
The solver should produce the numerical solution array y that corresponds to a value returned in time vector t.
With the data, you can run your own optim_solver to produce some control action u.
Then, update the initial states y0 with final value of the states y(end) from the last iteration.
Finally, repeat the loop/steps by running the ODE_solver > the optim_solver until the specified number of iteration is completed.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Refinement에 대해 자세히 알아보기

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by