How to formalize an optimization problem in Matlab?

Hello.
How to issue a task in Matlab?
Given:
Vectors a1 and a2.
Find a vector of coefficients x such that:
abs((a2.')*x) -> min
abs ((a1.')*x) >= condition
under the conditions:
- Dimensions of vectors a1, a2 and x from 1 to p
- elements a1, a2 and x are complex numbers
- abs(a1_i)>0, abs(a2_i)>0, abs(x_i) = 1, where i =1..p

15 commentaires

So you want to maximize abs(a1.'*x). And you want to minimize abs(a2.'*x).
How do you want to combine these two objectives in one ?
It is necessary to find a vector x such that:
abs ((a1.')*x) -> max - goal
abs((a2.')*x) < tol, wheh tol->0 - limitations
Seems you get a quadratic objective with quadratic constraint. Try fmincon.
Matt J
Matt J le 4 Mai 2022
Modifié(e) : Matt J le 4 Mai 2022
abs(x_i) = 1, where i =1..p
Are you sure it's not abs(x_i) <= 1 or sum(abs(xi).^2)=1? It would be hard to satisfy the constraint as posted.
For example, if a2=[1;0;0;0] it would be impossible to satisfy abs(a2.'*x)-->0, because abs(a2.'*x)=abs(x1) and abs(x1) is constrained to 1.
Torsten, thanks. The "fmincon" function only works with real numbers. I use complex numbers.
reincornator
reincornator le 4 Mai 2022
Modifié(e) : reincornator le 5 Mai 2022
Matt J, thanks. You are right, there is another constraint: abs(a1_i)>0, abs(a2_i)>0, i=1..p.
With each optimization software you use, you will have to split in real and imaginary part and thus handle two real-valued numbers simultaneously.
Matt J
Matt J le 4 Mai 2022
Modifié(e) : Matt J le 4 Mai 2022
You are right, there is another constraint: abs(a1_i)>0, abs(a1_i)>0, i=1..p.
I assume you meant abs(a1_i)>0, abs(a2_i)>0.
That's still not enough. Consider a2=[2,1].'. Then if abs(x1)=abs(x2)=1,
abs(a2.'*x)=abs(2*x1+x2)
>=abs( 2*abs(x1) -abs(x2))
=1
So, the constraint abs(a2.'*x)=0 can never be satisfied.
@Matt J, thank you. Corrected the condition.
abs((a2^T)*x) < tol, tol-> 0
My counter-example still applies. There is little guarantee that a solution will exist under those constraints.
If you had abs(a2_i)=1 for all i=1...p. You might be able to guarantee existence of a solution for p>1.
@Torsten, in real numbers, the condition abs(x_i)=1, can be written as Re(x_i)=sqrt(1-Im(x_i)^2). How to write such a condition for vector x in constraints?
Matt J
Matt J le 5 Mai 2022
Modifié(e) : Matt J le 5 Mai 2022
How to write such a condition for vector x in constraints?
Your problem wouldn't be written in terms of x_i in what Torsten is recommending. Your objective and constraints would be written in terms of independent variables (u_i, v_i) where u_i stands in for the real component of x_i and v_i stands in for the imaginary component. The constraint, written differentiably, would be,
u_i^2 + v_i^2 = 1
How to set 2 restrictions in the "fmincon" function?
c and ceq can be vectors.

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 4 Mai 2022
Modifié(e) : Matt J le 4 Mai 2022
N=null(a2.');
a3=a1.'*N;
[~,idx]=max(abs(a3));
x=N(:,idx);

6 commentaires

No, it doesn't work. In addition, no restrictions are set: abs(x) == 1.
randcomplex = @(x,y) rand(x,y).*exp(2i*pi*rand(x,y));
a1 = randcomplex(1,10);
a2 = randcomplex(1,10);
N=null(a2.')
N = 1×0 empty double row vector
a3=a1.'*N
a3 = 10×0 empty double matrix
[~,idx]=max(abs(a3))
idx = 1×0 empty double row vector
x=N(:,idx)
x = 1×0 empty double row vector
randcomplex = @(x,y) rand(x,y).*exp(2i*pi*rand(x,y));
a1 = randcomplex(10,1);
a2 = randcomplex(10,1);
N=null(a2.');
a3=a1.'*N;
[maxval,idx]=max(abs(a3));
x=N(:,idx)*conj(a3(idx))/abs(a3(idx))
x =
0.1546 - 0.3938i 0.0998 + 0.0391i 0.0617 - 0.0385i 0.0246 + 0.1474i 0.1035 + 0.0910i 0.0625 + 0.0216i -0.5747 - 0.6314i 0.0177 + 0.0661i 0.0371 - 0.0283i 0.0319 + 0.1476i
a2.'*x
ans = -8.3267e-17 + 5.5511e-17i
maxval,
maxval = 0.7671
abs(a1.'*x)
ans = 0.7671
@Matt J, thank you. The graph shows that such a solution does not satisfy the condition abs(x_i)=1
randcomplex = @(x,y) rand(x,y).*exp(2i*pi*rand(x,y));
a1 = randcomplex(40,1);
a2 = randcomplex(40,1);
N=null(a2.');
a3=a1.'*N;
[maxval,idx]=max(abs(a3));
x=N(:,idx)*conj(a3(idx))/abs(a3(idx));
a2.'*x;
[a1.';a2.']*x
ans =
0.9866 + 0.0000i 0.0000 - 0.0000i
plot(abs(x))
The graph shows that such a solution does not satisfy the condition abs(x_i)=1
Yes, because as I've said above, I don't think you will be able to find such a solution.
@Matt J, I found one solution. It is implemented using a special algorithm and shows a good result. But I'm looking for a better way.
I thought a2'*x should be 0...

Connectez-vous pour commenter.

Commenté :

le 5 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by