Trigonometric functions in AMPL

102 views
Skip to first unread message

Vivi

unread,
Oct 20, 2022, 3:28:53 PM10/20/22
to AMPL Modeling Language
Hello,

I would like to know how to write trigonometric functions like cos and sin in AMPL program and how to manage their units.

Best regards,

AMPL Google Group

unread,
Oct 21, 2022, 9:19:50 AM10/21/22
to AMPL Modeling Language
The trigonometric functions available in AMPL are listed in Table A-2 of the AMPL book. You can write cos(. . .) and sin(. . .) for the cosine and sine functions, where . . . is replaced by any AMPL numerical expression. The units of AMPL trigonometric functions are radians, as you can see in this example:

ampl: param pi = 3.141592653589793;
ampl: display sin(pi), cos(pi);
sin(pi) = 1.22465e-16
cos(pi) = -1

(The value of sin(pi) comes out slightly nonzero because pi cannot be represented exactly in computer arithmetic.) You can easily convert from degrees; here is an example of showing the sine and cosine of 90 degrees:

ampl: param c = 180/pi;
ampl: display sin(90/c), cos(90/c);
sin(90/c) = 1
cos(90/c) = 6.12323e-17


--
Robert Fourer
am...@googlegroups.com
{#HS:2044147981-112454#}

Vivi

unread,
Oct 24, 2022, 12:14:42 AM10/24/22
to AMPL Modeling Language

Dear Mr Robert,

Many thanks for your assistance.

Best regards,
Reply all
Reply to author
Forward
0 new messages