Solved

Tan and tanh function?

Posted on 2008-10-27
14
776 Views
Last Modified: 2008-11-05
Hello,

I would like to use tanh function in a query. Like
SELECT column1, tanh(column2) from table1

However tanh is not know to sql server. Does somebody has a solution?

Regards,
Dennis
0
Comment
Question by:Schuttend
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22811074
what IS the tanh function doing?

sql server has ATAN:
http://msdn.microsoft.com/en-us/library/ms181746.aspx
and ATN2:
http://msdn.microsoft.com/en-us/library/ms173854.aspx

...
0
 

Author Comment

by:Schuttend
ID: 22811111
tanh squashes a signal so that the value is always between -1 and 1. Both tanh and atn2 are doing something else...
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22811200
well, COS and SIN function also return values between -1 and +1 ...
but sure that's not what you are looking for.
I am not a advanced math guy, so I don't know what/how the tanh function is working. I can only work with a proper formula, and translate that into either some sql code using the existing functions, or suggest to get it into a sql 2005 clr function (using c# code)...


0
 
LVL 4

Expert Comment

by:GO-87
ID: 22811615
TanH is hyperbolic tangent,
and can be approximated by
tanh(a) = [exp(a) - exp(-a)]/[exp(a) + exp(-a)],
where a is an angle in radians (i.e. between 0 and 1)
For more info, look here:
http://en.wikipedia.org/wiki/Hyperbolic_tangent 
0
 
LVL 4

Expert Comment

by:GO-87
ID: 22811630
Oops - a radian doesn't have to be between 0 and 1
0
 
LVL 13

Expert Comment

by:AielloJ
ID: 22811673
Schuttend:

The hyperbolic tangent (TANH) function is the hyperbolic sin / the hyperbolic cosine.  You can work up functions for SINH, and COSH, and then one for TANH.  The formula's are:

SINH = (e^x - e^-x) / 2

COSH =  (e^x + e^-x) / 2

Where x is the angle in radians.  Your hyperbolic tangent function is then:

TANH = SinH / CosH
0
 

Author Comment

by:Schuttend
ID: 22811737
you are indeed correct,its the hyperbolic tangent, but how can I insert this in a query? What would be the correct format?

regards,
Dennis
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 13

Expert Comment

by:AielloJ
ID: 22811754
I believe you can write functions in SQL Server.  These functions can then be used in your query.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22811846
that gives me the input I need:
declare @x float

declare @sinh float

declare @cosh float

set @x = 0.14

select @sinh = (power( exp(1), @x ) - power ( exp(1), -@x) / 2)

     , @cosh = (power( exp(1), @x ) + power ( exp(1), -@x) / 2)

select @x x , @sinh sinh, @cosh cosh, @sinH/@cosh tanh

Open in new window

0
 
LVL 4

Accepted Solution

by:
GO-87 earned 125 total points
ID: 22811856
You needn't create separate SINH and COSH functions if you only need TANH in one query, simply

select (exp(myAngle) - exp(-myAngle)) / (exp(myAngle) + exp(-myAngle) As TANH
from ...
assuming you are able to select the angle from a table in radians (not degrees).
0
 
LVL 13

Expert Comment

by:AielloJ
ID: 22812079
GO-87:

I realize the SinH and CosH functions weren't absolutely necessary and it could have been done "in line".  Since the Hyperbolic Tangent is actually the Hyperbolic Sin divided by the Hyperbolic Cos, having those two functions may be useful in the future, and makes the coding of the TanH function clearer and in the format that would be recognized easiest as SinH / CosH.

To convert degrees to radians you must multiply:

  Radians = Degrees * (pi / 180)
0
 
LVL 4

Expert Comment

by:GO-87
ID: 22814488
AielloJ:
No worries, I wasn't implying any criticism, actually I agree with you.
In fact, had I seen angelIII's post (which came in while I was typing), I wouldn't have commented at all.
It's been many years since I've had to think about tanh ... and series and such things.
Cheers
G
0
 
LVL 13

Expert Comment

by:AielloJ
ID: 22814892
GO-87:

No offense taken.  I'm a big fan of structure and reusability.  If Schuttend needs sTanH, he or she will probably need SinH and CosH one day as well, as well as conversions from degrees to radians.  Just thought I'd structure my answer that way up front.

Likewise on the math... It's been awhile, and an interesting challenge recalling it.  Glad we came up with the same algorithm.  LOL
0
 
LVL 4

Expert Comment

by:GO-87
ID: 22815299
:-)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Select - column value lookup. 3 40
SSRS ReportViewer report timeout 7 100
the whoisactive update 12 38
MS SQL - Conversion failed when converting the varchar value 3 22
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now