**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# How to formalize an optimization problem in Matlab?

3 views (last 30 days)

Show older comments

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 Comments

Torsten
on 3 May 2022

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 ?

reincornator
on 4 May 2022

It is necessary to find a vector x such that:

abs ((a1.')*x) -> max - goal

abs((a2.')*x) < tol, wheh tol->0 - limitations

Matt J
on 4 May 2022

Edited: Matt J
on 4 May 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.

reincornator
on 4 May 2022

Torsten, thanks. The "fmincon" function only works with real numbers. I use complex numbers.

reincornator
on 4 May 2022

Edited: reincornator
on 5 May 2022

Matt J, thanks. You are right, there is another constraint: abs(a1_i)>0, abs(a2_i)>0, i=1..p.

Torsten
on 4 May 2022

Matt J
on 4 May 2022

Edited: Matt J
on 4 May 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
on 5 May 2022

Matt J
on 5 May 2022

reincornator
on 5 May 2022

Matt J
on 5 May 2022

Edited: Matt J
on 5 May 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

reincornator
on 5 May 2022

### Answers (1)

Matt J
on 4 May 2022

Edited: Matt J
on 4 May 2022

N=null(a2.');

a3=a1.'*N;

[~,idx]=max(abs(a3));

x=N(:,idx);

##### 6 Comments

Matt J
on 4 May 2022

Edited: Matt J
on 4 May 2022

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

reincornator
on 5 May 2022

Edited: reincornator
on 5 May 2022

@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))

Matt J
on 5 May 2022

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.

reincornator
on 5 May 2022

### See Also

### Categories

### Tags

### Community Treasure Hunt

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

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

### Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)