To write a function using cvx

suppose f(x)=|l*X*h|^2/(y+ sigde/sig) is a function where y both are scalar values. l is a 1\times 3 ,h is a 3\times 1 is a random matrix. And X is a 3\times 3 matrix. How this function is written using cvx.

Sir ,I hd made a code, but it is not giving the result as when I calculate v by running the program it give some result and when I calculate the right hand side f v on command window it gives some other result.


close all;

clear all;



sig=10^(20/10) ; %varisnce of signal

s_r=10^(0/10) ; %variance of received signal

sigde=10^(0/10); %variance of signal at destination


for i=1:M




cvx_begin quiet

variable X(N,N)

variable Y(M,1)

for i=1:M




for i=1:M




minimize g



I also show the result on matlab window.


v =

1.0e-011 *

0.7079    0.7079    0.7079


ans =

3.8858e-024 +3.8243e-024i


ans =

7.0467e-025 +2.5340e-026i

U can see that result is different. plz help in this coding.

Assuming y is positive, this is just quad_over_lin(l*X*h,y). It is convex, and decreasing in y. If you cannot assume y is positive (or negative), then the function is not convex.

Please see the function reference for a complete list of functions CVX supports.

I believe you meant quad_pos_over_lin , not the non-existent quad_abs_over_lin .

Ah, just quad_over_lin, actually.

Those results are actually identical as far as the numerical solver is concerned: they are both zero to within reasonable numerical precision. It seems to me like you have a significant scaling issue in your models. You should make sure that all scalar values are between, say, 10^-4 to 10^4.

Sorry, but unable to understand… I want to ask that the output give v as given i.e real values and all values are same… but when calculate quad_over_lin in matlab window it shows the result as shown which is complex and all are different…

The point is that computer arithmetic is not exact. The numbers you are getting are effectively zero for v and ans. You simply cannot expect exact results here or in any numerical algorithm. And it also means that the large value of sig is likely to cause the solver to fail.