atan2

89 views
Skip to first unread message

Kevin Korner

unread,
Aug 30, 2018, 6:07:34 PM8/30/18
to YALMIP
When trying to compute the arctangent of two variables, I get the error:

"Undefined function 'atan2' for input arguments of type 'sdpvar'."

Then, when I define atan2 using inequalities, I get the error:

"The following error occurred converting from constraint to logical:
Conversion to logical from constraint is not possible."

Does anyone have any suggestions as to how to implement a signed arctangent function using these solvers?

Thank you,
Kevin

Johan Löfberg

unread,
Aug 31, 2018, 2:25:00 AM8/31/18
to YALMIP
atan2 is not supported in YALMIP, and I see no sound way to go around that. atan is supported

Johan Löfberg

unread,
Aug 31, 2018, 5:01:46 AM8/31/18
to YALMIP
Add the file atan2 to yalmip/@sdpvar and atan2_internal to yalmip/operators

sdpvar x y;optimize([pi/10 <= [x y] <= pi],(pi/4-atan2(x,y))^2);

>> value([x y])

ans =

    1.3042    1.3042

atan2 is a pretty nasty operator though, and the current implementation does not supply derivatives

atan2.m
atan2_internal.m

Johan Löfberg

unread,
Aug 31, 2018, 7:27:45 AM8/31/18
to YALMIP
and this I don't understand what you are saying/doing

Kevin Korner

unread,
Aug 31, 2018, 3:31:16 PM8/31/18
to YALMIP
I tried to define my own function atan2(y,x) by using conditional statements (see image). Thank you for the help.
atan2.JPG

Johan Löfberg

unread,
Aug 31, 2018, 3:33:45 PM8/31/18
to YALMIP
if you tried to use if it would fail.https://yalmip.github.io/modellingif

User123

unread,
Apr 27, 2021, 4:31:31 PM4/27/21
to YALMIP
Hi Johan!

I am getting a similar issue when using atan2 in my dynamics equation with sdpvariables using the 'ipopt' (interior point optimization) solver. A screenshot of the error is attached. Could you please let me know if there is any way to get around this? I cannot use atan as the sign of the two arguments (numerator and denominator) are critical and I haven't (yet) thought of a way to ignore the signs. 

Thanks in advance for any help you can provide!

johanipopterror.PNG

Johan Löfberg

unread,
Apr 28, 2021, 2:52:28 AM4/28/21
to YALMIP

I've added support for gradient in atan2 now, pushed to develop branch.

User123

unread,
May 3, 2021, 2:21:31 PM5/3/21
to YALMIP
Hi again Johan!

Thank you for adding the support for atan2! My code seems to be working (does go inside atan2 switch case), however I am still getting this error in the command line. Can you please let me know if/what the issue is? If you need more information/ code, I can provide it. Thank you again for your help!

error2.PNG

Johan Löfberg

unread,
May 3, 2021, 2:33:41 PM5/3/21
to YALMIP
you would have to supply a reproducible example

Johan Löfberg

unread,
May 3, 2021, 4:18:25 PM5/3/21
to YALMIP
I found a small mistake which wasn't caught in my initial test, checked in to develop
Reply all
Reply to author
Forward
0 new messages