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
b = b + ...
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
b = b + ...
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!
b = b + ...
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.
b = b + ...
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




Users browsing this thread: 6 Guest(s)