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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperbolic Trig functions

Ken01

Programmer
Aug 8, 2014
54
0
6
GB
Owing to VB6 not having the standard Hyperbolic Trig functions (Sinh, Cosh etc) I have written routines to calculate them from scratch,
e.g Sinh(x) = (e^x - e^-x)/2 and Cosh(x) = (e^x + e^-x)/2
However when multiple calculations are required within a loop then the process grinds to a halt as it is a memory hog
(I am trying to calculate X, Y co-ordinates for a parametric graph).

Have any of your experts any ideas for a resolution ?
 
How are we supposed to pinpoint a solution for you when you do not show us what you are doing?
 
Hmm - I just wrote a loop that calculates HSin and and HCos 100000 times, and it was practically instantaneous.. Perhaps we need to see your code
 
Here is the sample code (calls to the relevant trig functions are highlighted :
It was adapted from code downloaded from a VB 6 "shareware" website

Variable declarations
Rem Main Loop
For Count = Xst - 2 * MyPi To Xst + 2 * MyPi Step 3
'Step++ = Faster; Step-- = Slower
'
If Option1 = True Or Option3 = True Then
y = -Sin((Count - Xst) / One) * One + Yst
y1 = -Atn((Count - Xst) / One) * One + Yst
Else
y = Atn(Sin(Count + Xst) / One) * One + Yst
y1 = (MSinh((Count + Xst)) / One) * One + Yst ********************************
End If
y2 = -((Count - Xst) / One) ^ 3 * One + Yst
If Option1 = True Or Option2 = True Then
If Count > Xst Then y3 = -Log(Atn(Count - Xst) / One) * One + Yst
Else
If Count > Xst Then y3 = -Log(Tan(Count - Xst) / One) * One + Yst
End If

If Option3 = False Then
y4 = -Cos((Count - Xst) / One) * One + Yst
Else
y4 = (MCosh((Count - Xst)) / One) * One + Yst *********************************
End If

'Draw ...
Picture1.PSet (Count, y), vbBlue ' &HFFFF&
Picture1.PSet (Count, y1), vbGreen ' &H8000&
Picture1.PSet (Count, y2), vbMagenta ' &HC0&
If Count > Xst Then Picture1.PSet (Count, y3), &HFF0000
Picture1.PSet (Count, y4), vbRed ' &HFF&
DoEvents 'Without this line drawing is not interesting!
Next Count

=============================================================================================================

Public Function MSinh(Ival)
Ival = Ival / 16
MSinh = ((2.718 ^ Ival) + (2.718 ^ (Ival * -1)) / 2)
Print #1, "MSinh : " & MSinh & " : " & Ival

End Function


Public Function MCosh(Ival)
Ival = Ival / 16
MCosh = (2.718 ^ Ival) - (2.718 ^ (Ival * -1))
Print #1, "Mcosh : " & MCosh & " : " & Ival

End Function

Public Function Mtanh(Ival)
On Error Resume Next
Dim jx1 As Double, kx1 As Double
jx1 = MCosh(Ival): kx1 = MSinh(Ival)
Mtanh = jx1 / kx1
Ival = Ival / 16

Print #1, "Mtanh : " & Mtanh & " : " & Ival

End Function
 
I'd suggest that

Print #1, "MSinh : " & MSinh & " : " & Iva
Print #1, "Mcosh : " & MCosh & " : " & Ival
Print #1, "Mtanh : " & Mtanh & " : " & Ival

are what are slowing things down
 

Part and Inventory Search

Sponsor

Back
Top