Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Arcsin(x) for x > 1 in fortran

Zhiyong_b_
Beginner
2,032 Views

In fortran there exists a intrinsic function ASIN for calculating arcsine(x).

But there is one problem, x should be real and less than 1 or complex.

But my problem is I have to calculate arcsin(x) for real number x lager than 1.

How can I solve this?

0 Kudos
6 Replies
skinner__karl
New Contributor I
2,032 Views

Isn't arcsin(x) only defined for -1<=x<=1 ?

0 Kudos
Simon_Geard
New Contributor I
2,032 Views

In F2008 the following should work:

program main
   complex :: x, y
   x = cmplx(2,0)
   y = asin(x)
   print *,y
end program main

but you'll probably need a v15 compiler for that. The above doesn't build with Version 14.0.3.202.

0 Kudos
mecej4
Honored Contributor III
2,032 Views

Zhiyong B. wrote:
But my problem is I have to calculate arcsin(x) for real number x larger than 1. How can I solve this?

No real number y exists for which x = sin(y) > 1. In geometrical terms, no point on a circle falls outside the square that just circumscribes the circle.

You can solve 'this' by reviewing your mathematics books.

0 Kudos
JVanB
Valued Contributor II
2,032 Views

If you want to keep it real, recall that

sin(a+b*i) = sin(a)*cos(b*i)+cos(a)*sin(b*i)

= sin(a)*cosh(b)+i*cos(a)*sinh(b)

so let a = sign(pi/2,x), b = acosh(abs(x)), then sin(a+b*i) = sign(real(1,kind(x)),x)*abs(x)+i*(0)*(don't care) = x

Thus you can test whether abs(x) > 1 and if so you know asin(x) = cmplx(sign(pi/2,x),acosh(abs(x)),kind(x))

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,032 Views

This depends on how x is bunged-up. If it is a rounding error

if(x<-1.0) x=-1.0
if(x>1.0) x=1.0
y=asin(x)

Or if x is accumulation of cyclical use mod

y = asin(mod(x+1.0-TINY(x), 2.0) - 1.0)

The issue with the above is when x is exactly 1.0, you would end up with 1.0-TINY(x)

Jim Dempsey

0 Kudos
Zhiyong_b_
Beginner
2,032 Views

mecej4 wrote:

Quote:

Zhiyong B. wrote:
But my problem is I have to calculate arcsin(x) for real number x larger than 1. How can I solve this?

 

No real number y exists for which x = sin(y) > 1. In geometrical terms, no point on a circle falls outside the square that just circumscribes the circle.

You can solve 'this' by reviewing your mathematics books.

Thanks anyway. I have solved this problem. In fact, there exists x=sin(y) >1 with y a complex number.

Here is my code for solution:

complex function arcsin(x)
	real x
        complex I = (0.0, 1.0)
	if (abs(x) >= 1) then
		arcsin = -I*log(I*x + I*sqrt(x**2 -1)) 
	else
		arcsin = ASIN(x)
	end if
end function

 

0 Kudos
Reply