'Identifying weight matrix for MPC problem
I'm absolutely stuck in my programming exercise. I need to find a weight Matrix Q_weight which makes the objective feasible and has a low cost. I know that the Q has only elements on the diagonal.
I have a function which takes Q and gives me as an output a boolean if the objective is feasible, and cost function. Right now I can only think about a brute force method with several for loops. Since the values can range over several magnitudes [1e-2,1e-3](could be more), this would be very inefficient.
The lqr_tuning
takes as input the initial state x0
, Q matrix which is [q_1 ,q_2, ... q_n]
, with each q_i I create the weight matrix Q_weight = diag(q_i), and some parameters. The output is a struct (nx5) which includes the cost, and the boolean if the objective is feasible + more. i_opt
is the index which corresponds to the lowest cost, if it's not feasible it will be nan
. So I can find the optimal q_i with Q(:,i_opt)
.
for i=0.1:1000
for a=0.1:1000
for b=0.1:1000
for c=0.1:1000
for d=0.1:1000
for e=0.1:1000
Q = [e d c b a i];
[tuning_struct, i_opt] = lqr_tuning(x0,Q,params);
if (tuning_struct(i_opt).InputCost < max_cost) && (tuning_struct(i_opt).TrajFeasible)
max_cost = tuning_struct(i_opt).InputCost;
elseif (tuning_struct(i_opt).InputCost-max_cost<=thresh)
break
end
end
end
end
end
end
end
I also thought about a random approach, but I don't think that would be the right approach. Does someone could give me a hint how to tackle that problem.
Maybe you notice that I'm not a pro in matlab programming, so any help is very much appreciated.
Thanks in Advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|