How can i solve this cost function?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Volcano
el 29 de Jun. de 2022
Comentada: Sam Chak
el 29 de Jun. de 2022
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 comentarios
Respuesta aceptada
Matt J
el 29 de Jun. de 2022
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));
q=sol.q
Más respuestas (1)
Sam Chak
el 29 de Jun. de 2022
Hi @Volcano
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)
4 comentarios
Matt J
el 29 de Jun. de 2022
Editada: Matt J
el 29 de Jun. de 2022
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.
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!