Finding Extremum of Multivariate Functions

I tried to use the fmincon function to find the extremum of the multivariate function, but it didn't work.Here is my question:
There are 10 variables:x1,x2,x3,x4,x5,x6,x7,x8,x9,x10, and 5 constants with values taken from the interval [-1, 1]: R(1,2), R(1,3), R(2,2), R(2,3), R(3,3).
There are the following relationships among these 10 variables: R(1,2)^2+x1^2+x3^2+x4^2=1; R(1,3)^2+x2^2+x5^2+x6^2=1; R(1,2)^2*x1^2=x3^2*x4^2; R(1,3)^2*x2^2=x5^2*x6^2; x7^2+x8^2=1;x9^+x10^2=1; R(2,2)*x3*x5*x7+R(2,2)*x4*x6*x9-R(2,3)*R(2,2)^2+R(2,2)*x1*x2*(x7*x9-x8*x10)=0; x3*x5*x8+x4*x6*x10+x1*x2*(x8*x9+x7*x10)=0.
The objective function is:R(2,3)^2*x1^2/R(3,3)^2/R(2,2)^2-2*R(2,3)*x1*x2/R(2,2)/R(3,3)^2*(x7*x9-x8*x10)+x2^2/R(3,3)^2.
The objective is to find the maximum value of the objective function.
It is observed that by solving the first 8 equations, x3, x4, x5, x6, x7, x8, x9, and x10 can be expressed as functions of x1 and x2 (the expressions may be very complicated), thus transforming the problem into an unconstrained extremum problem of a function of two variables x1 and x2.
I have been stuck on this problem for a few days. Specifically, I have not made any progress on how to obtain a specific solution through MATLAB or other mathematical software when R(1,2)=0.7844, R(1,3)=0.7844, R(2,2)=0.6202, R(2,3)=-0.2021, and R(3,3)=0.5864. I would be very grateful if anyone could give me some guidance.
Supplement: to use the fmincon function, the following code is used to input the objective function: fun = @(x) (x(1) - 2)^2 + (x(2) - 3)^2; I encountered difficulties with this step because the expression for the objective function for my problem was very complex, and it was not possible for me to manually enter it one by one. However, the variables in this code must, in my understanding, be in the form of x(1), x(2), but x(1), x(2) cannot be defined as symbolic variables using the syms command. So I thought of using the subs command. I plan to do the following: first, use the [x7, x8, x9, x10] = solve('R(2,2)x(5)x(3)x7+R(2,2)x(4)x(6)x9-R(2,3)R(2,2)^2+R(2,2)x(1)x(2)(x7x9-x8x10)=0','x(3)x(5)x8+x(4)x(6)x10+x(1)x(2)(x8x9+x7x10)=0','x7^2+x8^2=1','x9^2+x10^2=1','x7,x8,x9,x10') command to express x7, x8, x9, x10 as functions of x(1), x(2), x(3), x(4), x(5), x(6), and know that: x(3)=(1/2 - R(1,2)^2/2 - x(1)^2/2 + (-(R(1,2) + x(1) - 1)(R(1,2) + x(1) + 1)(R(1,2) - x(1) + 1)(x(1) - R(1,2) + 1))^(1/2)/2)^(1/2)
x(4)=(1/2 - R(1,2)^2/2 - x(1)^2/2 - (-(R(1,2) + x(1) - 1)(R(1,2) + x(1) + 1)(R(1,2) - x(1) + 1)(x(1) - R(1,2) + 1))^(1/2)/2)^(1/2)
x(5)=(1/2 - R(1,3)^2/2 - x(2)^2/2 + (-(R(1,3) + x(2) - 1)(R(1,3) + x(2) + 1)(R(1,3) - x(2) + 1)(x(2) - R(1,3) + 1))^(1/2)/2)^(1/2)
x(6)=(1/2 - R(1,3)^2/2 - x(2)^2/2 - (-(R(1,3) + x(2) - 1)(R(1,3) + x(2) + 1)(R(1,3) - x(2) + 1)(x(2) - R(1,3) + 1))^(1/2)/2)^(1/2)
Then use the command R(2,2)=0.6202,R(2,3)=-0.2021,R(1,2)=0.7844,R(1,3)=0.7844 to determine the values of the constants R(2,2), etc.
Finally, input the code fun = @(x) -0.2021^2x(1)^2/0.5864^2/0.6202^2+2-0.2021x(1)x(2)/0.6202/0.5864^2(subs(x7(1),{x(3),x(4),x(5),x(6)},{expression for x3 as a function of x(1), x(2), x(4) , x(5) , x(6) })*subs(x9(1),{x(3),x(4),x(5),x(6)},{x(3) , x(5) , x(6) }) - subs(x8(1),{x(3),x(4),x(5),x(6)},{x(3), x(4) , x(5) , x(6)})*(subs(x10(1),{x(3),x(4),x(5),x(6)},{x(3) , x(4) , x(5) , x(6) })) -x(2)^2/0.5864^2(To seek the maximum value of the objective function but using fmincon to find its minimum value, a negative sign is added to the objective function, where x7, x8, x9, and x10 are all 2-dimensional column vectors)
>> A = [];
>> b = [];
>> Aeq = [];
>> beq = [];
>> lb = [0, 0];
>> ub = [1, 1];
>> x0 = [0.2156, 0.2156];
>> [x_min, fval] = fmincon(fun, x0, A, b, Aeq, beq, lb, ub)
Run-time error message:
Error in
@(x) expression... ...
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
So I think the error should be in the code line "fun = @(x) ...". Would anyone be willing to tell me how to correct it?

1 Comment

Please enclose the code where you tried to use "fmincon".

Sign in to comment.

 Accepted Answer

R(1,2)=0.7844;
R(1,3)=0.7844;
R(2,2)=0.6202;
R(2,3)=-0.2021;
R(3,3)=0.5864;
x0 = 0.5*ones(10,1);
lb = -1*ones(10,1);
ub = 1*ones(10,1);
fun = @(x)R(2,3)^2*x(1)^2/R(3,3)^2/R(2,2)^2-2*R(2,3)*x(1)*x(2)/R(2,2)/R(3,3)^2*(x(7)*x(9)-x(8)*x(10))+x(2)^2/R(3,3)^2
fun = function_handle with value:
@(x)R(2,3)^2*x(1)^2/R(3,3)^2/R(2,2)^2-2*R(2,3)*x(1)*x(2)/R(2,2)/R(3,3)^2*(x(7)*x(9)-x(8)*x(10))+x(2)^2/R(3,3)^2
nonlcon = @(x) deal([],...
[R(1,2)^2+x(1)^2+x(3)^2+x(4)^2-1; ...
R(1,3)^2+x(2)^2+x(5)^2+x(6)^2-1; ...
R(1,2)^2*x(1)^2-x(3)^2*x(4)^2; ...
R(1,3)^2*x(2)^2-x(5)^2*x(6)^2; ...
x(7)^2+x(8)^2-1; ...
x(9)^2+x(10)^2-1; ...
R(2,2)*x(3)*x(5)*x(7)+R(2,2)*x(4)*x(6)*x(9)-R(2,3)*R(2,2)^2+R(2,2)*x(1)*x(2)*(x(7)*x(9)-x(8)*x(10)); ...
x(3)*x(5)*x(8)+x(4)*x(6)*x(10)+x(1)*x(2)*(x(8)*x(9)+x(7)*x(10))]);
fun(x0)
ans = 0.8042
sol = fmincon(fun,x0,[],[],[],[],lb,ub,nonlcon)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.110223e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.365664e-17.
Local minimum possible. Constraints satisfied. fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
sol = 10×1
0.0022 0.1466 0.0027 0.6202 0.5676 -0.2025 0.1491 0.9888 0.9999 0.0147
fun(sol)
ans = 0.0626
[C,Ceq] = nonlcon(sol)
C = []
Ceq = 8×1
1.0e-15 * 0 0 0.0000 -0.0017 0 0.2220 0.0124 -0.0001

1 Comment

Thank you for the inspiration! I have also installed the latest version of MATLAB: MATLAB R2023a, so I can do some research.

Sign in to comment.

More Answers (0)

Asked:

on 22 Jul 2023

Commented:

on 24 Jul 2023

Community Treasure Hunt

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

Start Hunting!