xmd79

MathComplexTrignometry

Oct 9th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.91 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © RicardoSantos
  3.  
  4. //@version=5
  5.  
  6. // @description Methods for complex number trignometry operations.
  7. library(title='MathComplexTrignometry')
  8.  
  9. // reference:
  10. // https://github.com/mathnet/mathnet-numerics/blob/a50d68d52def605a53d129cc60ea3371a2e97548/src/Numerics/Trigonometry.cs
  11. // test values : https://www.mathsisfun.com/numbers/complex-number-calculator.html
  12.  
  13. // imports:
  14. import RicardoSantos/DebugConsole/2 as console
  15. [__T, __C] = console.init(30)
  16. //
  17. import RicardoSantos/MathTrigonometry/1 as trig
  18. //
  19. import RicardoSantos/MathConstants/1 as constants
  20. //
  21. import RicardoSantos/MathComplexCore/1 as complex
  22. import RicardoSantos/MathComplexOperator/1 as complex_op
  23. import RicardoSantos/MathComplexExtension/1 as complex_ex
  24. //
  25.  
  26. // preview of functions parameters:
  27. bool show_1 = input.bool(title='Show Trig functions:', defval=true)
  28. bool show_2 = input.bool(title='Show hyper Trig functions:', defval=true)
  29. bool show_3 = input.bool(title='Show arc Trig functions:', defval=true)
  30. bool show_4 = input.bool(title='Show hyper arc Trig functions:', defval=true)
  31. input_a = complex.new(3.1416, 1.618)
  32.  
  33. // @function Hyperbolic Sine of complex number.
  34. // @param complex float array, complex number.
  35. // @returns float array.
  36. export sinh (float[] complex) => //{
  37. if not complex.is_complex(complex)
  38. runtime.error('MathComplexTrignometry -> sinh(): "complex" is the wrong size.')
  39. complex.nan()
  40. else
  41. if complex.is_real(complex)
  42. complex.new(trig.sinh(complex.get_real(complex)), 0.0)
  43. else
  44. float _re = complex.get_real(complex)
  45. float _im = complex.get_imaginary(complex)
  46. float _absre = math.abs(_re)
  47. if _absre >= 22.0
  48. float _h = math.exp(_absre) * 0.5
  49. complex.new(math.sign(_re) * _h * math.cos(_im), _h * math.sin(_im))
  50. else
  51. complex.new(trig.sinh(_re) * math.cos(_im), trig.cosh(_re) * math.sin(_im))
  52. //{ usage:
  53. if show_2
  54. console.queue_one(__C, str.format('sinh({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(sinh(input_a), '#.##')))
  55. //{ remarks:
  56. //}}}
  57.  
  58. // @function Hyperbolic cosine of complex number.
  59. // @param complex float array, complex number.
  60. // @returns float array.
  61. export cosh (float[] complex) => //{
  62. if not complex.is_complex(complex)
  63. runtime.error('MathComplexTrignometry -> cosh(): "complex" is the wrong size.')
  64. complex.nan()
  65. else
  66. if complex.is_real(complex)
  67. complex.new(trig.cosh(complex.get_real(complex)), 0.0)
  68. else
  69. float _re = complex.get_real(complex)
  70. float _im = complex.get_imaginary(complex)
  71. float _absre = math.abs(_re)
  72. if _absre >= 22.0
  73. float _h = math.exp(_absre) * 0.5
  74. complex.new(_h * math.cos(_im), math.sign(_re) * _h * math.sin(_im))
  75. else
  76. complex.new(trig.cosh(_re) * math.cos(_im), trig.sinh(_re) * math.sin(_im))
  77. //{ usage:
  78. if show_2
  79. console.queue_one(__C, str.format('cosh({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(cosh(input_a), '#.##')))
  80. //{ remarks:
  81. //}}}
  82.  
  83. // @function Hyperbolic tangent of complex number.
  84. // @param complex float array, complex number.
  85. // @returns float array.
  86. export tanh (float[] complex) => //{
  87. if not complex.is_complex(complex)
  88. runtime.error('MathComplexTrignometry -> tanh(): "complex" is the wrong size.')
  89. complex.nan()
  90. else
  91. if complex.is_real(complex)
  92. complex.new(trig.tanh(complex.get_real(complex)), 0.0)
  93. else
  94. float _re = complex.get_real(complex)
  95. float _im = complex.get_imaginary(complex)
  96. float _absre = math.abs(_re)
  97. if _absre >= 22.0
  98. float _e = math.exp(-_absre)
  99. if _e == 0.0
  100. complex.new(math.sign(_re), 0.0)
  101. else
  102. complex.new(math.sign(_re), 4.0 * math.cos(_im) * math.sin(_im) * math.pow(_e, 2.0))
  103. else
  104. float POSINF = 1.7976931348623157e+308 // positive float infinity, credit to Xel_Arjona.
  105. float _tani = math.tan(_im)
  106. float _sinhr = trig.sinh(_re)
  107. float _coshr = trig.cosh(_re)
  108. if math.abs(_tani) >= POSINF
  109. complex.new(_coshr / _sinhr, 0.0)
  110. else
  111. float _beta = 1.0 + math.pow(_tani, 2.0)
  112. float _denom = 1.0 + _beta * math.pow(_sinhr, 2.0)
  113. complex.new(_beta * _coshr * _sinhr / _denom, _tani / _denom)
  114. //{ usage:
  115. if show_2
  116. console.queue_one(__C, str.format('tanh({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(tanh(input_a), '#.##')))
  117. //{ remarks:
  118. //}}}
  119.  
  120. // @function Hyperbolic cotangent of complex number.
  121. // @param complex float array, complex number.
  122. // @returns float array.
  123. export coth (float[] complex) => //{
  124. if not complex.is_complex(complex)
  125. runtime.error('MathComplexTrignometry -> coth(): "complex" is the wrong size.')
  126. complex.nan()
  127. else
  128. if complex.is_real(complex)
  129. complex.new(trig.coth(complex.get_real(complex)), 0.0)
  130. else
  131. complex_op.divide(complex.one(), tanh(complex))
  132. //{ usage:
  133. if show_2
  134. console.queue_one(__C, str.format('coth({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(coth(input_a), '#.##')))
  135. //{ remarks:
  136. //}}}
  137.  
  138. // @function Hyperbolic Secant of complex number.
  139. // @param complex float array, complex number.
  140. // @returns float array.
  141. export sech (float[] complex) => //{
  142. if not complex.is_complex(complex)
  143. runtime.error('MathComplexTrignometry -> sech(): "complex" is the wrong size.')
  144. complex.nan()
  145. else
  146. if complex.is_real(complex)
  147. complex.new(trig.sech(complex.get_real(complex)), 0.0)
  148. else
  149. float _re = complex.get_real(complex)
  150. float _im = complex.get_imaginary(complex)
  151. float _absre = math.abs(_re)
  152. float _tani = math.tan(_im)
  153. float _cosi = math.cos(_im)
  154. float _sinhr = trig.sinh(_re)
  155. float _coshr = trig.cosh(_re)
  156. if _absre >= 22.0
  157. float _e = math.exp(-_absre)
  158. if _e == 0.0
  159. complex.zero()
  160. else
  161. float _e2 = math.pow(_e, 2.0)
  162. complex.new(4.0 * _coshr * _cosi * _e2, -4.0 * _sinhr * _tani * _cosi * _e2)
  163. else
  164. float POSINF = 1.7976931348623157e+308 // positive float infinity, credit to Xel_Arjona.
  165. if math.abs(_tani) >= POSINF
  166. complex.new(0.0, -math.sign(_tani) / _sinhr)
  167. else
  168. float _beta = 1.0 + math.pow(_tani, 2.0)
  169. float _denom = 1.0 +_beta * math.pow(_sinhr, 2.0)
  170. complex.new(_coshr / _cosi / _denom, -_sinhr * _tani / _cosi / _denom)
  171. //{ usage:
  172. if show_2
  173. console.queue_one(__C, str.format('sech({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(sech(input_a), '#.##')))
  174. //{ remarks:
  175. //}}}
  176.  
  177. // @function Hyperbolic Cosecant of complex number.
  178. // @param complex float array, complex number.
  179. // @returns float array.
  180. export csch (float[] complex) => //{
  181. if not complex.is_complex(complex)
  182. runtime.error('MathComplexTrignometry -> csch(): "complex" is the wrong size.')
  183. complex.nan()
  184. else
  185. if complex.is_real(complex)
  186. complex.new(trig.csch(complex.get_real(complex)), 0.0)
  187. else
  188. float _re = complex.get_real(complex)
  189. float _im = complex.get_imaginary(complex)
  190. float _absre = math.abs(_re)
  191. float _coti = trig.cot(_im)
  192. float _sini = math.sin(_im)
  193. float _sinhr = trig.sinh(_re)
  194. float _coshr = trig.cosh(_re)
  195. if _absre >= 22.0
  196. float _e = math.exp(-_absre)
  197. if _e == 0.0
  198. complex.zero()
  199. else
  200. float _e2 = math.pow(_e, 2.0)
  201. complex.new(4.0 * _sinhr * _coti * _sini * _e2, -4.0 * _coshr * _sini * _e2)
  202. else
  203. float POSINF = 1.7976931348623157e+308 // positive float infinity, credit to Xel_Arjona.
  204. if math.abs(_coti) >= POSINF
  205. complex.new(math.sign(_coti) / _sinhr, 0.0)
  206. else
  207. float _beta = 1.0 + math.pow(_coti, 2.0)
  208. float _denom = 1.0 +_beta * math.pow(_sinhr, 2.0)
  209. complex.new(_sinhr * _coti / _sini / _denom, -_coshr / _sini / _denom)
  210. //{ usage:
  211. if show_2
  212. console.queue_one(__C, str.format('csch({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(csch(input_a), '#.##')))
  213. //{ remarks:
  214. //}}}
  215.  
  216. // @function Trigonometric Sine of complex number.
  217. // @param complex float array, complex number.
  218. // @returns float array.
  219. export sin (float[] complex) => //{
  220. if not complex.is_complex(complex)
  221. runtime.error('MathComplexTrignometry -> sin(): "complex" is the wrong size.')
  222. complex.nan()
  223. else
  224. if complex.is_real(complex)
  225. complex.new(math.sin(complex.get_real(complex)), 0.0)
  226. else
  227. float _re = complex.get_real(complex)
  228. float _im = complex.get_imaginary(complex)
  229. complex.new(math.sin(_re) * trig.cosh(_im), math.cos(_re) * trig.sinh(_im))
  230. //{ usage:
  231. if show_1
  232. console.queue_one(__C, str.format('sin({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(sin(input_a), '#.##')))
  233. //{ remarks:
  234. //}}}
  235.  
  236. // @function Trigonometric cosine of complex number.
  237. // @param complex float array, complex number.
  238. // @returns float array.
  239. export cos (float[] complex) => //{
  240. if not complex.is_complex(complex)
  241. runtime.error('MathComplexTrignometry -> cos(): "complex" is the wrong size.')
  242. complex.nan()
  243. else
  244. if complex.is_real(complex)
  245. complex.new(math.cos(complex.get_real(complex)), 0.0)
  246. else
  247. float _re = complex.get_real(complex)
  248. float _im = complex.get_imaginary(complex)
  249. complex.new(math.cos(_re) * trig.cosh(_im), -math.sin(_re) * trig.sinh(_im))
  250. //{ usage:
  251. if show_1
  252. console.queue_one(__C, str.format('cos({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(cos(input_a), '#.##')))
  253. //{ remarks:
  254. //}}}
  255.  
  256. // @function Trigonometric tangent of complex number.
  257. // @param complex float array, complex number.
  258. // @returns float array.
  259. export tan (float[] complex) => //{
  260. if not complex.is_complex(complex)
  261. runtime.error('MathComplexTrignometry -> tan(): "complex" is the wrong size.')
  262. complex.nan()
  263. else
  264. if complex.is_real(complex)
  265. complex.new(math.tan(complex.get_real(complex)), 0.0)
  266. else
  267. float _re = complex.get_real(complex)
  268. float _im = complex.get_imaginary(complex)
  269. float[] _z = tanh(complex.new(-_im, _re))
  270. complex.new(complex.get_imaginary(_z), -complex.get_real(_z))
  271. //{ usage:
  272. if show_1
  273. console.queue_one(__C, str.format('tan({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(tan(input_a), '#.##')))
  274. //{ remarks:
  275. //}}}
  276.  
  277. // @function Trigonometric cotangent of complex number.
  278. // @param complex float array, complex number.
  279. // @returns float array.
  280. export cot (float[] complex) => //{
  281. if not complex.is_complex(complex)
  282. runtime.error('MathComplexTrignometry -> cot(): "complex" is the wrong size.')
  283. complex.nan()
  284. else
  285. if complex.is_real(complex)
  286. complex.new(trig.cot(complex.get_real(complex)), 0.0)
  287. else
  288. float _re = complex.get_real(complex)
  289. float _im = complex.get_imaginary(complex)
  290. float[] _z = coth(complex.new(_im, -_re))
  291. complex.new(complex.get_imaginary(_z), -complex.get_real(_z))
  292. //{ usage:
  293. if show_1
  294. console.queue_one(__C, str.format('cot({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(cot(input_a), '#.##')))
  295. //{ remarks:
  296. //}}}
  297.  
  298. // @function Trigonometric Secant of complex number.
  299. // @param complex float array, complex number.
  300. // @returns float array.
  301. export sec (float[] complex) => //{
  302. if not complex.is_complex(complex)
  303. runtime.error('MathComplexTrignometry -> sec(): "complex" is the wrong size.')
  304. complex.nan()
  305. else
  306. if complex.is_real(complex)
  307. complex.new(trig.sec(complex.get_real(complex)), 0.0)
  308. else
  309. float _re = complex.get_real(complex)
  310. float _im = complex.get_imaginary(complex)
  311. float _cosr = math.cos(_re)
  312. float _sinhi = trig.sinh(_im)
  313. float _denom = math.pow(_cosr, 2) + math.pow(_sinhi, 2)
  314. complex.new(_cosr * trig.cosh(_im) / _denom, math.sin(_re) * _sinhi / _denom)
  315. //{ usage:
  316. if show_1
  317. console.queue_one(__C, str.format('sec({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(sec(input_a), '#.##')))
  318. //{ remarks:
  319. //}}}
  320.  
  321. // @function Trigonometric Cosecant of complex number.
  322. // @param complex float array, complex number.
  323. // @returns float array.
  324. export csc (float[] complex) => //{
  325. if not complex.is_complex(complex)
  326. runtime.error('MathComplexTrignometry -> csc(): "complex" is the wrong size.')
  327. complex.nan()
  328. else
  329. if complex.is_real(complex)
  330. complex.new(trig.csc(complex.get_real(complex)), 0.0)
  331. else
  332. float _re = complex.get_real(complex)
  333. float _im = complex.get_imaginary(complex)
  334. float _sinr = math.sin(_re)
  335. float _sinhi = trig.sinh(_im)
  336. float _denom = math.pow(_sinr, 2) + math.pow(_sinhi, 2)
  337. complex.new(_sinr * trig.cosh(_im) / _denom, -math.cos(_re) * _sinhi / _denom)
  338. //{ usage:
  339. if show_1
  340. console.queue_one(__C, str.format('csc({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(csc(input_a), '#.##')))
  341. //{ remarks:
  342. //}}}
  343.  
  344. // @function Trigonometric Arc Sine of complex number.
  345. // @param complex float array, complex number.
  346. // @returns float array.
  347. export asin (float[] complex) => //{
  348. if not complex.is_complex(complex)
  349. runtime.error('MathComplexTrignometry -> asin(): "complex" is the wrong size.')
  350. complex.nan()
  351. else
  352. float _re = complex.get_real(complex)
  353. float _im = complex.get_imaginary(complex)
  354. float[] _imo = complex.imaginary_one()
  355. float[] _nimo = complex_op.negative(_imo)
  356. float[] _one = complex.one()
  357. if _im > 0.0 or (_im == 0.0 and _re < 0.0)
  358. float[] _ncomplex = complex_op.negative(complex)
  359. float[] _sq = complex_ex.square_root(complex_op.subtract(_one, complex_ex.square(_ncomplex)))
  360. float[] _ln = complex_ex.natural_logarithm(complex_op.add(_sq, complex_op.multiply(_imo, _ncomplex)))
  361. complex_op.negative(complex_op.multiply(_nimo, _ln))
  362. else
  363. float[] _sq = complex_ex.square_root(complex_op.subtract(_one, complex_ex.square(complex)))
  364. float[] _ln = complex_ex.natural_logarithm(complex_op.add(_sq, complex_op.multiply(_imo, complex)))
  365. complex_op.multiply(_nimo, _ln)
  366. //{ usage:
  367. if show_3
  368. console.queue_one(__C, str.format('asin({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(asin(input_a), '#.##')))
  369. //{ remarks:
  370. //}}}
  371.  
  372. // @function Trigonometric Arc Cosine of complex number.
  373. // @param complex float array, complex number.
  374. // @returns float array.
  375. export acos (float[] complex) => //{
  376. if not complex.is_complex(complex)
  377. runtime.error('MathComplexTrignometry -> acos(): "complex" is the wrong size.')
  378. complex.nan()
  379. else
  380. float _re = complex.get_real(complex)
  381. float _im = complex.get_imaginary(complex)
  382. float[] _imo = complex.imaginary_one()
  383. float[] _nimo = complex_op.negative(complex.imaginary_one())
  384. float[] _one = complex.one()
  385. if _im < 0.0 or (_im == 0.0 and _re > 0.0)
  386. float[] _ncomplex = complex_op.negative(complex)
  387. float[] _1_sqrt = complex_ex.square_root(complex_op.subtract(_one, complex_ex.square(_ncomplex)))
  388. complex_op.subtract(complex.new(math.pi, 0.0), complex_op.multiply(_nimo, complex_ex.natural_logarithm(complex_op.add(_ncomplex, complex_op.multiply(_imo, _1_sqrt)))))
  389. else
  390. float[] _1_sqrt = complex_ex.square_root(complex_op.subtract(_one, complex_ex.square(complex)))
  391. complex_op.multiply(_nimo, complex_ex.natural_logarithm(complex_op.add(complex, complex_op.multiply(_imo, _1_sqrt))))
  392. //{ usage:
  393. if show_3
  394. console.queue_one(__C, str.format('acos({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(acos(input_a), '#.##')))
  395. //{ remarks:
  396. //}}}
  397.  
  398. // @function Trigonometric Arc Tangent of complex number.
  399. // @param complex float array, complex number.
  400. // @returns float array.
  401. export atan (float[] complex) => //{
  402. if not complex.is_complex(complex)
  403. runtime.error('MathComplexTrignometry -> atan(): "complex" is the wrong size.')
  404. complex.nan()
  405. else
  406. float _re = complex.get_real(complex)
  407. float _im = complex.get_imaginary(complex)
  408. float[] _iz = complex.new(-_im, _re)
  409. float[] _one = complex.one()
  410. complex_op.multiply(complex.new(0.0, 0.5), complex_op.subtract(complex_ex.natural_logarithm(complex_op.subtract(_one, _iz)), complex_ex.natural_logarithm(complex_op.add(_one, _iz))))
  411. //{ usage:
  412. if show_3
  413. console.queue_one(__C, str.format('atan({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(atan(input_a), '#.##')))
  414. //{ remarks:
  415. //}}}
  416.  
  417. // @function Trigonometric Arc Cotangent of complex number.
  418. // @param complex float array, complex number.
  419. // @returns float array.
  420. export acot (float[] complex) => //{
  421. if not complex.is_complex(complex)
  422. runtime.error('MathComplexTrignometry -> acot(): "complex" is the wrong size.')
  423. complex.nan()
  424. else
  425. if complex.is_zero(complex)
  426. complex.new(constants.PiOver2(), 0.0)
  427. else
  428. float _re = complex.get_real(complex)
  429. float _im = complex.get_imaginary(complex)
  430. float[] _one = complex.one()
  431. float[] _half = complex.new(0.5, 0.0)
  432. float[] _imo = complex.imaginary_one()
  433. float[] _inv = complex_op.divide(_imo, complex)
  434. complex_op.multiply(complex_op.multiply(_imo, _half), complex_op.subtract(complex_ex.natural_logarithm(complex_op.subtract(_one, _inv)), complex_ex.natural_logarithm(complex_op.add(_one, _inv))))
  435. //{ usage:
  436. if show_3
  437. console.queue_one(__C, str.format('acot({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(acot(input_a), '#.##')))
  438. //{ remarks:
  439. //}}}
  440.  
  441. // @function Trigonometric Arc Secant of complex number.
  442. // @param complex float array, complex number.
  443. // @returns float array.
  444. export asec (float[] complex) => //{
  445. if not complex.is_complex(complex)
  446. runtime.error('MathComplexTrignometry -> asec(): "complex" is the wrong size.')
  447. complex.nan()
  448. else
  449. float _re = complex.get_real(complex)
  450. float _im = complex.get_imaginary(complex)
  451. float[] _one = complex.one()
  452. float[] _imo = complex.imaginary_one()
  453. float[] _inv = complex_op.divide(_one, complex)
  454. float[] _nimo = complex_op.negative(_imo)
  455. float[] _imosqrt = complex_op.multiply(_imo, complex_ex.square_root(complex_op.subtract(_one, complex_ex.square(_inv))))
  456. complex_op.multiply(_nimo, complex_ex.natural_logarithm(complex_op.add(_inv, _imosqrt)))
  457. //{ usage:
  458. if show_3
  459. console.queue_one(__C, str.format('asec({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(asec(input_a), '#.##')))
  460. //{ remarks:
  461. //}}}
  462.  
  463. // @function Trigonometric Arc Cosecant of complex number.
  464. // @param complex float array, complex number.
  465. // @returns float array.
  466. export acsc (float[] complex) => //{
  467. if not complex.is_complex(complex)
  468. runtime.error('MathComplexTrignometry -> acsc(): "complex" is the wrong size.')
  469. complex.nan()
  470. else
  471. float _re = complex.get_real(complex)
  472. float _im = complex.get_imaginary(complex)
  473. float[] _one = complex.one()
  474. float[] _imo = complex.imaginary_one()
  475. float[] _inv = complex_op.divide(_one, complex)
  476. float[] _nimo = complex_op.negative(_imo)
  477. float[] _sqrt = complex_ex.square_root(complex_op.subtract(_one, complex_ex.square(_inv)))
  478. complex_op.multiply(_nimo, complex_ex.natural_logarithm(complex_op.add(complex_op.multiply(_imo, _inv), _sqrt)))
  479. //{ usage:
  480. if show_3
  481. console.queue_one(__C, str.format('acsc({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(acsc(input_a), '#.##')))
  482. //{ remarks:
  483. //}}}
  484.  
  485. // @function Hyperbolic Arc Sine of complex number.
  486. // @param complex float array, complex number.
  487. // @returns float array.
  488. export asinh (float[] complex) => //{
  489. if not complex.is_complex(complex)
  490. runtime.error('MathComplexTrignometry -> asinh(): "complex" is the wrong size.')
  491. complex.nan()
  492. else
  493. float[] _one = complex.one()
  494. float[] _sq = complex_ex.square_root(complex_op.add(complex_ex.square(complex), _one))
  495. complex_ex.natural_logarithm(complex_op.add(complex, _sq))
  496. //{ usage:
  497. if show_4
  498. console.queue_one(__C, str.format('asinh({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(asinh(input_a), '#.##')))
  499. //{ remarks:
  500. //}}}
  501.  
  502. // @function Hyperbolic Arc Cosine of complex number.
  503. // @param complex float array, complex number.
  504. // @returns float array.
  505. export acosh (float[] complex) => //{
  506. if not complex.is_complex(complex)
  507. runtime.error('MathComplexTrignometry -> acosh(): "complex" is the wrong size.')
  508. complex.nan()
  509. else
  510. float[] _one = complex.one()
  511. float[] _sqn = complex_ex.square_root(complex_op.subtract(complex, _one))
  512. float[] _sqp = complex_ex.square_root(complex_op.add(complex, _one))
  513. float[] _sq = complex_op.multiply(_sqn, _sqp)
  514. complex_ex.natural_logarithm(complex_op.add(complex, _sq))
  515. //{ usage:
  516. if show_4
  517. console.queue_one(__C, str.format('acosh({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(acosh(input_a), '#.##')))
  518. //{ remarks:
  519. //}}}
  520.  
  521. // @function Hyperbolic Arc Tangent of complex number.
  522. // @param complex float array, complex number.
  523. // @returns float array.
  524. export atanh (float[] complex) => //{
  525. if not complex.is_complex(complex)
  526. runtime.error('MathComplexTrignometry -> atanh(): "complex" is the wrong size.')
  527. complex.nan()
  528. else
  529. float[] _one = complex.one()
  530. float[] _half = complex.new(0.5, 0.0)
  531. float[] _lnn = complex_ex.natural_logarithm(complex_op.subtract(_one, complex))
  532. float[] _lnp = complex_ex.natural_logarithm(complex_op.add(_one, complex))
  533. float[] _ln = complex_op.subtract(_lnp, _lnn)
  534. complex_op.multiply(_half, _ln)
  535. //{ usage:
  536. if show_4
  537. console.queue_one(__C, str.format('atanh({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(atanh(input_a), '#.##')))
  538. //{ remarks:
  539. //}}}
  540.  
  541. // @function Hyperbolic Arc Cotangent of complex number.
  542. // @param complex float array, complex number.
  543. // @returns float array.
  544. export acoth (float[] complex) => //{
  545. if not complex.is_complex(complex)
  546. runtime.error('MathComplexTrignometry -> acoth(): "complex" is the wrong size.')
  547. complex.nan()
  548. else
  549. float[] _one = complex.one()
  550. float[] _half = complex.new(0.5, 0.0)
  551. float[] _inv = complex_op.divide(_one, complex)
  552. float[] _lnn = complex_ex.natural_logarithm(complex_op.subtract(_one, _inv))
  553. float[] _lnp = complex_ex.natural_logarithm(complex_op.add(_one, _inv))
  554. float[] _ln = complex_op.subtract(_lnp, _lnn)
  555. complex_op.multiply(_half, _ln)
  556. //{ usage:
  557. if show_4
  558. console.queue_one(__C, str.format('acoth({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(acoth(input_a), '#.##')))
  559. //{ remarks:
  560. //}}}
  561.  
  562. // @function Hyperbolic Arc Secant of complex number.
  563. // @param complex float array, complex number.
  564. // @returns float array.
  565. export asech (float[] complex) => //{
  566. if not complex.is_complex(complex)
  567. runtime.error('MathComplexTrignometry -> asech(): "complex" is the wrong size.')
  568. complex.nan()
  569. else
  570. float[] _one = complex.one()
  571. float[] _inv = complex_op.divide(_one, complex)
  572. float[] _sqn = complex_ex.square_root(complex_op.subtract(_inv, _one))
  573. float[] _sqp = complex_ex.square_root(complex_op.add(_inv, _one))
  574. float[] _sq = complex_op.multiply(_sqn, _sqp)
  575. complex_ex.natural_logarithm(complex_op.add(_inv, _sq))
  576. //{ usage:
  577. if show_4
  578. console.queue_one(__C, str.format('asech({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(asech(input_a), '#.##')))
  579. //{ remarks:
  580. //}}}
  581.  
  582. // @function Hyperbolic Arc Cosecant of complex number.
  583. // @param complex float array, complex number.
  584. // @returns float array.
  585. export acsch (float[] complex) => //{
  586. if not complex.is_complex(complex)
  587. runtime.error('MathComplexTrignometry -> acsch(): "complex" is the wrong size.')
  588. complex.nan()
  589. else
  590. float[] _one = complex.one()
  591. float[] _inv = complex_op.divide(_one, complex)
  592. float[] _sq = complex_ex.square_root(complex_op.add(complex_ex.square(_inv), _one))
  593. complex_ex.natural_logarithm(complex_op.add(_inv, _sq))
  594. //{ usage:
  595. if show_4
  596. console.queue_one(__C, str.format('acsch({0}): {1}', complex.to_string(input_a, '#.##'), complex.to_string(acsch(input_a), '#.##')))
  597. //{ remarks:
  598. //}}}
  599.  
  600. //###########################################
  601. console.update(__T, __C)
Advertisement
Add Comment
Please, Sign In to add comment