$TITLE ARCTRIG inverse sine and cosine example * * The GAMS built-in functions include the arctan function, * but arcsin, arccos, and tan are not included. * One can obtain the inverse sine and cosine functions * by using only the arctan function, using the formulas * * arcsin(y) = arctan(y/sqrt(1-y*y)), y in (-1,1) * arccos(y) = pi/2 - arctan(y/sqrt(1-y*y)), y in (-1,1) * * while tan(x) = sin(x) / cos(x). * * * To derive the above formula for arcsin(x), we have * y = sin x * arcsin y = x, * cos x = sqrt(1 - (sin x)**2) when x is in [-pi/2, pi/2], * * Now use the formula for tan x and substitute from above. * * tan x = sin x / cos x * = y / sqrt(1-y**2), and * * x = arctan( y / sqrt(1-y**2) ) = arcsin(y) * * * To get the formula for arccos(y), we note that sine and cosine * are horizontal translations of each other, so we use the identity * * cos x = sin(pi/2 - x) * * and the formula for arcsin(y) above. sets J / 1 * 10 /; scalar N; N = card(J) + 1; scalar pi; pi = arctan(INF) * 2; * the arctan function can accept an infinite argument * arctan(1) * 4 also works * The range of the arcsin function is usually taken as [-pi/2, pi/2] parameters x(J), y(J), arcsiny(J), sin_diff(J); x(J) = (-pi/2) + pi * ord(J)/N; y(J) = sin(x(J)); arcsiny(J) = arctan( y(J) / sqrt(1-sqr(y(J))) ); sin_diff(J) = arcsiny(J) - x(J); display sin_diff; * The range of the arccos function is usually taken as [0, pi] parameters arccosy(J), cos_diff(J); x(J) = pi * ord(J)/N; y(J) = cos(x(J)); arccosy(J) = (pi/2) - arctan( y(J) / sqrt(1-sqr(y(J))) ); cos_diff(J) = arccosy(J) - x(J); display cos_diff;