# Quadratic Optimization for 4D in for Loop

1 view (last 30 days)
MarshallSc on 31 Dec 2021
Commented: yanqi liu on 1 Jan 2022
I need to find the roots (complex in nature) of an objective function in 4D by using quadratic optimization for the function below:
a = [0.0068 0.0036 0.000299 0.0151]; b = [0.0086 0.00453 0.0016 0.00872]
f = @(xj,xk) a(i) - (x(j)*x(k)) * b(l); %i,j,k,l = 1:4 - simple eqn: f = @(x1,x2) a(1) - (x(2)*x(3)) * b(4)
The problem that I have is that I don't know how to write it in a for loop or permutation manner that each loop takes a specific value of the (a,b) and (xj,xk) from 1:4. Basically it's a nonlinear coordinate transformation. Since my X(i) * X(j) makes the problem quadratic, I need to perform an approximation using the only equality constraint such (imposing the symmetry of the potential function - (i,j) and (k,l) pair become exchangeable):
(x(j)*x(k)) * b(l) + (x(i)*x(l)) * b(k) + (x(k)*x(j)) * b(j) + (x(l)*x(i)) * b(i) =< a(i) + a(j) + a(k) + a(l)
That's my only constraint for optimization that minimizes the objective function. I tried using fmincon but I don't know how to use it in a loop for the equation and the constraint.
I'd appreciate it if someone can help me! Thank you!
yanqi liu on 31 Dec 2021
yes，sir，may be write the equations，and we can use loop to generate cmd string，then use eval to get function handle

yanqi liu on 31 Dec 2021
clc; clear all; close all;
a = [0.0068 0.0036 0.000299 0.0151];
b = [0.0086 0.00453 0.0016 0.00872];
% f = @(xj,xk) a(i) - (x(j)*x(k)) * b(l); %i,j,k,l = 1:4 - simple eqn: f = @(x1,x2) a(1) - (x(2)*x(3)) * b(4)
for i = 1 : length(a)
eqi = sprintf('f=@(x1,x2) %f- (x(1)*x(2))*%f;', a(i), b(i));
disp(eqi)
end
f=@(x1,x2) 0.006800- (x(1)*x(2))*0.008600; f=@(x1,x2) 0.003600- (x(1)*x(2))*0.004530; f=@(x1,x2) 0.000299- (x(1)*x(2))*0.001600; f=@(x1,x2) 0.015100- (x(1)*x(2))*0.008720;
##### 2 CommentsShowHide 1 older comment
yanqi liu on 1 Jan 2022
yes，sir，may be it is non-linear optimization，use fmincon to get compute，may be write your equations in handwriting，we can make some debug