How can i solve this cost function?

Hi,
I have a cost function which includes vectors and matrices:
v = [(1 / (0.47 * 0.94 * 1500)^2) (1 / (0.47 * 0.94 * 1700)^2) (1 / (0.47 * 0.94 * 2000)^2) (1 / (0.47 * 0.94 * 2200)^2)];
delta = diag(v);
nu = transpose([120 340]);
K = [((1.95 / (2*0.47)) .* [-1 1 -1 1]);...
1 1 1 1 ];
zeta = [2 0; 0 1];
%J = transpose(q) * delta * q + (transpose(K*q - nu)) * zeta * (K*q - nu) %Cost function
%q = transpose([X Y Z T]) %Output of cost function
I am trying to find q vector without any constraint. What kind of methods can be used to solve related equation?
Thanks,

8 件のコメント

Abhijit Nayak
Abhijit Nayak 2022 年 6 月 29 日
Can you send the code for the function? The code you gave has no meaning for X,Y,Z,T variables which forms the q vector.
Volcano
Volcano 2022 年 6 月 29 日
編集済み: Volcano 2022 年 6 月 29 日
Hi Nayak,
J is the cost function which is utilized to obtain q vector. q includes 4 elements and i represent them as X Y Z T. This vector is unknown which should be solved (output of cost function).
Walter Roberson
Walter Roberson 2022 年 6 月 29 日
Is the task to minimize J? Is the task to find the q such that J becomes a all zero?
Sam Chak
Sam Chak 2022 年 6 月 29 日
@Volcano, because your zeta is a matrix?
v = [(1 / (0.47 * 0.94 * 1500)^2) (1 / (0.47 * 0.94 * 1700)^2) (1 / (0.47 * 0.94 * 2000)^2) (1 / (0.47 * 0.94 * 2200)^2)]
v = 1×4
1.0e-05 * 0.2277 0.1773 0.1281 0.1059
delta = diag(v)
delta = 4×4
1.0e-05 * 0.2277 0 0 0 0 0.1773 0 0 0 0 0.1281 0 0 0 0 0.1059
nu = transpose([120 340])
nu = 2×1
120 340
K = [((1.95 / (2*0.47)) .* [-1 1 -1 1]);...
1 1 1 1 ]
K = 2×4
-2.0745 2.0745 -2.0745 2.0745 1.0000 1.0000 1.0000 1.0000
zeta = [2 0; 0 1]
zeta = 2×2
2 0 0 1
Volcano
Volcano 2022 年 6 月 29 日
Yes, it is standard optimization problem. I am struggling to find optimal q vector which makes J minimum.
Sam Chak
Sam Chak 2022 年 6 月 29 日
Thanks @Volcano. Checked. J cost function no problem.
Guess, you want formulate this problem in LMI form?
q = rand(4, 1)
q = 4×1
0.2950 0.2162 0.1987 0.3864
v = [(1 / (0.47 * 0.94 * 1500)^2) (1 / (0.47 * 0.94 * 1700)^2) (1 / (0.47 * 0.94 * 2000)^2) (1 / (0.47 * 0.94 * 2200)^2)];
delta = diag(v);
nu = transpose([120 340]);
K = [((1.95 / (2*0.47)) .* [-1 1 -1 1]);...
1 1 1 1 ];
zeta = [2 0; 0 1];
J = transpose(q) * delta * q + (transpose(K*q - nu)) * zeta * (K*q - nu) %Cost function
J = 1.4355e+05
Volcano
Volcano 2022 年 6 月 29 日
@Sam Chak Yes, it is 2*2 matrix. Do you think there is a mistake in formulation?
Volcano
Volcano 2022 年 6 月 29 日
@Sam Chak sorry, but what is LMI?
There should be optimal q vector which minimize J.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2022 年 6 月 29 日

2 投票

v = [(1 / (0.47 * 0.94 * 1500)^2) (1 / (0.47 * 0.94 * 1700)^2) (1 / (0.47 * 0.94 * 2000)^2) (1 / (0.47 * 0.94 * 2200)^2)];
delta = diag(v);
nu = transpose([120 340]);
K = [((1.95 / (2*0.47)) .* [-1 1 -1 1]);...
1 1 1 1 ];
zeta = [2 0; 0 1];
q=optimvar('q',4,1);
J=transpose(q) * delta * q + (transpose(K*q - nu)) * zeta * (K*q - nu);
sol=solve(optimproblem('Objective',J));
Solving problem using quadprog. Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
q=sol.q
q = 4×1
50.7877 74.3710 90.2892 124.5521

その他の回答 (1 件)

Sam Chak
Sam Chak 2022 年 6 月 29 日

2 投票

I converted the matrix equation into a scalar equation. Since there is no constraint, fminunc() is used and the local minimum is found.
v = [(1 / (0.47 * 0.94 * 1500)^2) (1 / (0.47 * 0.94 * 1700)^2) (1 / (0.47 * 0.94 * 2000)^2) (1 / (0.47 * 0.94 * 2200)^2)];
delta = diag(v);
nu = transpose([120 340]);
K = [((1.95 / (2*0.47)) .* [-1 1 -1 1]); 1 1 1 1];
zeta = [2 0; 0 1];
% Cost function
J = @(q) v(1)*q(1).^2 + v(2)*q(2).^2 + v(3)*q(3).^2 + v(4)*q(4).^2 + zeta(1,1)*(K(1,1)*q(1) + K(1,2)*q(2) + K(1,3)*q(3) + K(1,4)*q(4) - nu(1)).^2 + zeta(2,2)*(K(2,1)*q(1) + K(2,2)*q(2) + K(2,3)*q(3) + K(2,4)*q(4) - nu(2)).^2;
% Initial guess of q solution
q0 = [1 1 1 1];
% Minimize unconstrained multivariable function
[q, fval] = fminunc(J, q0)
Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
q = 1×4
70.5372 99.4606 70.5396 99.4624
fval = 0.0457

4 件のコメント

Volcano
Volcano 2022 年 6 月 29 日
Thanks a lot @Sam Chak. I want to accept your ansvwer, but system only permits one answer. Both the posts are useful for me. Thanks a lot!
Sam Chak
Sam Chak 2022 年 6 月 29 日
Thanks for your vote, @Volcano. Mine is just a local minimum as clarified earlier. In fact, I also learned from him. The system appears to many local minima.
Matt J
Matt J 2022 年 6 月 29 日
編集済み: Matt J 2022 年 6 月 29 日
It doesn't seem possible that it is a local minimum, because it is a convex problem. Possibly, fminunc's finite difference approximations to the gradient, or maybe the optimoption defaults, led to incomplete convergence. quadprog doesn't rely on approximate gradients, so it wouldn't have that difficulty to overcome.
Sam Chak
Sam Chak 2022 年 6 月 29 日
Thanks @Matt J for the explanations. I learned something new today.

サインインしてコメントする。

カテゴリ

質問済み:

2022 年 6 月 29 日

コメント済み:

2022 年 6 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by