Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using inverse trigonometric functions of complex argument in fortran?

Status
Not open for further replies.

280286

Programmer
May 28, 2011
1
RU
Hello, guys. im writing my current program in fortran 90 and i've come across this problem: how to calculate arccos(z) if z is a complex number, z=x+i*y.is it possible in fortran to calculate it at all. And if it isnt then are there any alternatives?
thank you, i woould be very thankful for your help.
 
I don't know about library available for calculating it,
but IMHO to calculate Arccos(z) for complex z, |z| <= 1 we can use something like this:
complex_function.f95
Code:
[COLOR=#a020f0]program[/color] complex_function
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]

[COLOR=#2e8b57][b]  real[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: pi [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]acos[/color]([COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]1.0[/color])
[COLOR=#2e8b57][b]  real[/b][/color] :: re_Z, im_Z
  [COLOR=#2e8b57][b]complex[/b][/color] :: Z, ZRSLT, cacos
  [COLOR=#2e8b57][b]complex[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: J [COLOR=#804040][b]=[/b][/color] ([COLOR=#ff00ff]0.0[/color], [COLOR=#ff00ff]1.0[/color])

  [COLOR=#0000ff]! complex arccos(z)[/color]
  cacos (Z) [COLOR=#804040][b]=[/b][/color] [COLOR=#804040][b]-[/b][/color]J [COLOR=#804040][b]*[/b][/color] [COLOR=#008080]clog[/color](Z [COLOR=#804040][b]+[/b][/color] J[COLOR=#804040][b]*[/b][/color][COLOR=#008080]csqrt[/color]([COLOR=#ff00ff]1[/color] [COLOR=#804040][b]-[/b][/color] Z[COLOR=#804040][b]*[/b][/color]Z))

  [COLOR=#0000ff]! real argument[/color]
  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]1[/color],[COLOR=#ff00ff]0[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]0.5[/color],[COLOR=#ff00ff]0[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#ff00ff]0[/color],[COLOR=#ff00ff]0[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#ff00ff]0.5[/color],[COLOR=#ff00ff]0[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#ff00ff]1[/color],[COLOR=#ff00ff]0[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  [COLOR=#0000ff]! complex argument[/color]
  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#ff00ff]0[/color],[COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]1[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  re_Z [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]cos[/color](pi[COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]4.0[/color])
  im_Z [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]sin[/color](pi[COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]4.0[/color])
  Z [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]cmplx[/color](re_Z, im_Z)
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  re_Z [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]cos[/color](pi[COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]6.0[/color])
  im_Z [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]sin[/color](pi[COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]6.0[/color])
  Z [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]cmplx[/color](re_Z, im_Z)
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  Z [COLOR=#804040][b]=[/b][/color] ([COLOR=#ff00ff]0[/color],[COLOR=#ff00ff]1[/color])
  ZRSLT [COLOR=#804040][b]=[/b][/color] cacos(Z)
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]100[/color]), Z, ZRSLT

  [COLOR=#6a5acd]100[/color] [COLOR=#804040][b]format[/b][/color] ([COLOR=#ff00ff]'Arccos('[/color],[COLOR=#008080]f6.3[/color],[COLOR=#ff00ff]' + J*'[/color],[COLOR=#008080]f6.3[/color],[COLOR=#ff00ff]') = '[/color],[COLOR=#008080]f10.8[/color],[COLOR=#ff00ff]' + J*'[/color],[COLOR=#008080]f10.8[/color])
[COLOR=#a020f0]end program[/color] complex_function
Code:
$ gfortran complex_function.f95 -o complex_function

$ complex_function
Arccos(-1.000 + J* 0.000) = 3.14159274 + J*-.00000000
Arccos(-0.500 + J* 0.000) = 2.09439516 + J*-.00000000
Arccos( 0.000 + J* 0.000) = 1.57079637 + J*-.00000000
Arccos( 0.500 + J* 0.000) = 1.04719758 + J*-.00000000
Arccos( 1.000 + J* 0.000) = 0.00000000 + J*-.00000000
Arccos( 0.000 + J*-1.000) = 1.57079637 + J*0.88137364
Arccos( 0.707 + J* 0.707) = 0.99893749 + J*-.76428539
Arccos( 0.866 + J* 0.500) = 0.78539819 + J*-.65847898
Arccos( 0.000 + J* 1.000) = 1.57079637 + J*-.88137364
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top