Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function "_ARCSEC()" is wrong?
#1
One example:
Code: (Select All)
PRINT _ARCSEC(-2.5)

results in "illegal function call".

But " .... the domain of sec inverse x is (-∞, -1] U [1, ∞) (being the range of secant function) and the range of arcsec is [0, π/2) U (π/2, π] (principal branch of sec x). ..."

From: https://www.cuemath.com/trigonometry/sec-inverse-x/

The result should be 1.982313172862385.

An alternative formula gives the correct result:

arcsec(x) = acos(1/x)

Code: (Select All)
PRINT _ACOS(1/-2.5)

This works fine and delivers: 1.982313172862385. 

The Help says:
Quote:  FUNCTION ARCSEC (x) ' Inverse Secant
    IF x < 1 THEN ARCSEC = ATN(x / SQR(1 - x * x)) + (SGN(x) - 1) * (2 * ATN(1)) ELSE BEEP
END FUNCTION
 I think this is not correct!   

 Correct for the domain is:  |x| > 1 

What do our mathematical specialists think?
Reply
#2
Quote:What do our mathematical specialists think?  Rolleyes
If x < 1, the result cannot be correct because there is an error message. If x > 1 the result is zero.
I should first go through the formula in peace .  . .

[Image: ARCSEC.jpg]
Reply
#3
When x < 1 do what you did @BSpinoza because even the help says you can't do it with a straight function call. Your solution looks simpler, so if it works, GO FOR IT! Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#4
Looks like a glitch to me.

ARCSEC should work in a range from: x ≤ -1 or x ≥ 1
Reply
#5
Why is there a forumla for ArcSec given below for Wiki on _ArcSec Keyword?

Something is wrong? a typo a wrong word? something...

Update: Oh that was from old QB stuff, who cares? water under the bridge
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#6
(10-28-2023, 02:42 PM)bplus Wrote: Why is there a forumla for ArcSec given below for Wiki on _ArcSec Keyword?

Something is wrong? a typo a wrong word? something...

Update: Oh that was from old QB stuff, who cares? water under the bridge

PRINT _ARCSEC(-2.5) OK it's broken!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#7
The formula in the wiki seems to be wrong. Is the result of the formula from the QBasic-Manual correct?

Code: (Select All)

Option _Explicit

Dim As Integer x

x = 0
Const PI = 1.141593

'Print _Arcsec(-2.5
Print
Print _Acos(1 / -2.5)
Print
Print ARCSECF(-2.5)

End

Function ARCSECF (x) ' Inverse Secant

  Dim As Double Arcsec

  If x <= 1 Or x >= 1 Then
    Arcsec = Atn(Sqr(x * x - 1)) + Sgn(Sgn(x) - 1) * PI
  Else Beep
  End If
  ARCSECF = Arcsec
End Function
Reply
#8
How does BSpinoza's solution look to you, seems like good idea to me.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#9
Something else comes out of it too. Wait for @Spinoza.

Code: (Select All)

Option _Explicit

Declare Function ARCSECF(x As Integer) As Double

Dim As Integer arcsecw, x

x = -2.5

Const PI = 1.141593

'Print _Arcsec(-2.5
Print
Print _Acos(1 / -2.5)
Print
Print ARCSECF(-2.5)

Print
arcsecw = _Acos(1 / x)
Print arcsecw

End

Function ARCSECF (x As Integer) 'Inverse Secant

  Dim As Double Arcsec

  If x <= 1 Or x >= 1 Then
    Arcsec = Atn(Sqr(x * x - 1)) + Sgn(Sgn(x) - 1) * PI
  Else Beep
  End If
  ARCSECF = Arcsec
End Function
Reply
#10
Correction: @BSpinoza's formula is correct.

Code: (Select All)

Option _Explicit

Declare Function ARCSECF(x As Double) As Double

Dim As Double arcsecw, x

x = -2.5

Const PI = 1.141593

'Print _Arcsec(-2.5
Print
Print _Acos(1 / -2.5)
Print
Print ARCSECF(-2.5)

Print 'Spinoza's Formel
arcsecw = _Acos(1 / x)
Print Using "#.#########"; arcsecw

End
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function Pointers? BlameTroi 5 244 02-20-2026, 05:55 PM
Last Post: BlameTroi
  TYPE and CONST within SUB/FUNCTION TerryRitchie 9 1,955 07-11-2023, 01:22 AM
Last Post: bplus
  Query to function _InputBox$ Petr 10 2,046 03-31-2023, 09:53 PM
Last Post: mnrvovrfc
  instr function in reverse ??? doppler 3 755 02-10-2023, 02:33 PM
Last Post: doppler
  Variable as a reference or value to a function Kernelpanic 22 4,264 08-08-2022, 07:41 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)