A square_pos question

Dear everyone

Can I ask a silly question about the square_pos(x) function in cvx? Today I reconfigured the cvx and run my previous code. However, the error always occurred, I checked for some time and found that there is an issue on the function square_pos() in cvx. What I understand is that this function is equivalent to x^2 mathematically. However, please look at the picture, when I input square_pos(5) and the output is -1, I do not know why the result is like this. Could you please help me solve it? Thank you!

Kind Regards
截屏2022-03-15 下午3.18.56

sorry, I uploaded the wrong picture. The picture that I want to upload is thisb

What is the output of
which -all square_pos

Either there is some square_pos being called other than that supplied with CVX, or something is screwed up in your CVX installation (or corrupted MATLAB session).

Dear Mark

Thank you for your kind reply. The output of which -all square_pos is

The first path of your output might be of the highest priority, but CVX’s square is clearly on the second one. So you need to adjust path priority in MATLAB, the easiest way is click “set path”, then select all paths related to CVX, move them to the top of the path list so they have the highest priority.

That output explains square That doesn’t explain square_pos/

Dear Jack

Thank you for your kind reply. I have deleted that useless path. But I have another question. Please look at the picture, I input the command square_pos(2) and the output is an error. But I previously used this function and I remember it is okay to calculate the square of a real number using square_pos() function. Could you please offer me some help? Thank you !

Kind Regards

From your post, it seems square_pos() need to use square(), so you haven’t fixed square()? Can you do which -all square again and show it to us?

Dear Jack

I think my problem has been temporally solved. Thank you for your kind help.

Kind Regards


In response to:

But I want to use square_pos.m which includes square.m inside. I wanted to change its codes but I was not sure if it affects some other functions which I am using in some other parts of my main optimisation program. Then I thought the best way is to replace square function of MATLAB with square function of cvx.

notice in particular this post by the CVX developer, mcg.

So I think the moral of the story is that is you have the Signal Processing Toolbox installed, don’t use square_pos on MATLAB double precision variables. But it should still be o.k. to use square_pos if its argument is a CVX expression or variable.

Dear Mark

Thank you for your kind help. I will read them very carefully.

Kind Regards