Using Sine Cosine and Tan in Excel.
Using Sine Cosine and Tan in Excel.
(OP)
Can any one give me guidance in using Sine/Cosine/Tan in excel.
Example.
1000*Cosq and so on.
How do you write it in excel format?
Example.
1000*Cosq and so on.
How do you write it in excel format?





RE: Using Sine Cosine and Tan in Excel.
- In cell B1 type "=1000 * sin(A1)". For cos, use cos(A1). For tan, use tan(A1).
RE: Using Sine Cosine and Tan in Excel.
To convert degrees to radians, multiply by Pi/180
For example to find the cos of cell G20 which contains an angle in degrees, use the following:
=+COS(PI()/180*G20)
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Using Sine Cosine and Tan in Excel.
TTFN
RE: Using Sine Cosine and Tan in Excel.
=RADIANS(C2) equals 4.71238898 radians when C2 = 270 degrees (3pi/2 radians)
=DEGREES(C6) equals 179.999848 degrees when C6 = 3.14159 radians
Norm
RE: Using Sine Cosine and Tan in Excel.
RE: Using Sine Cosine and Tan in Excel.
I can’t get the following VBA Macro to work – it generates a "#VALUE!" error:
Public Function sindeg(theta_degrees)
Pi=Excel.WorksheetFunction.Atan2(1,1)*4
sindeg=Excel.WorksheetFunction.Sin(theta_degrees/180*Pi)
End Function
However, the following macro (with just the addition of one character, to convert “sin” to “sinh”) runs fine. (It’s just a shame that it generates the wrong answer!)
Public Function sindeg(theta_degrees)
Pi=Excel.WorksheetFunction.Atan2(1,1)*4
sindeg=Excel.WorksheetFunction.Sinh(theta_degrees/180*Pi)
End Function
Does anyone know a way around this apparent fundamental limitation of VBA?
RE: Using Sine Cosine and Tan in Excel.
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Using Sine Cosine and Tan in Excel.
What version of Excel are you running?
I am beginning to suspect the omission of the basic trig functions (sin etc) in VBA is a new "enhancement" in the 2003 version. I have found plenty of references to using trig functions in VBA in older versions, but the examples won't run on my 2003 version.
For example, Microsoft on-line help defines "SIN" in the 1997 VBA reference here:
ht
However, the 2003 on-line reference provides a list of mathematical functions available in VBA - see here:
htt
The hyperbolic functions (SINH, COSH, etc) are listed, as are the inverse trig functions (ASIN, ACOS, etc), but the basic trig functions (sin, cos, tan) are conspicuous by their absence. Sure enough, I can run a VBA function which uses SINH, but when I try to use SIN, it generates an error message.
Surely I am missing something obvious?!?
RE: Using Sine Cosine and Tan in Excel.
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Using Sine Cosine and Tan in Excel.
In the worksheet, =sin(90) yields a correct answer
In VBA, Range("A1").Value = Sin(90) puts the correct value in cell A1
Perhaps you have to load the analysis pack in Excel?
RE: Using Sine Cosine and Tan in Excel.
It seems there is a group of core mathematical functions which are built into the core of VBA. These functions include Sin, Cos, Tan, etc, and the correct syntax is the normal method of calling such a mathematical function:
sindeg = Sin(theta_degrees / 180 * Pi)
(Note that the syntax for the VBA arc-tan function is Atn(x) NOT Atan(x), which is the Excel syntax.)
Then, you can access MOST (but not all) Excel mathematical functions using the following syntax:
answer = Excel.WorksheetFunction.Sinh(x)
A list of Excel functions which are available in this way can be found by opening Visual Basic help, and then search down through the contents for:
Microsoft Excel Visual Basic Reference
Programming Concepts
Events, Worksheet Functions & Shapes
Using Microsoft Excel Worksheet functions in Visual Basic
and then click on the link to “List of Worksheet Functions Available to Visual Basic”. These available functions include the hyperbolic functions (Sinh, Cosh, etc), Acos, Asin, Atan2 (but NOT Atan!), and so on.
Note that it seems that in general, if any function is built into the core of VBA, the Excel version is NOT available in this way. That is:
sindeg = Sin(theta_degrees / 180 * Pi)
will work, but
sindeg = Excel.WorksheetFunction.Sin(theta_degrees / 180 * Pi)
will generate an error.
Sorry if this is obvious to others, but it caused me a LOT of grief working out where I went wrong.
For the record, the following VBA code runs fine. (Note – this is just a demonstration – I KNOW it’s not the most efficient way to achieve my objectives! Note also, I have used the excel Function Pi() to create a local variable called Pi. This is probably very poor programming form, but is allowable here, because VBA does not seem to recognise Pi as a reserved keyword, unless it is in the Excel.WorksheetFunction.Pi() syntax.)
Public Function sindeg(theta_degrees)
Pi = Excel.WorksheetFunction.Pi()
sindeg = Sin(theta_degrees / 180 * Pi)
End Function
RE: Using Sine Cosine and Tan in Excel.
Bung
Life is non-linear...
RE: Using Sine Cosine and Tan in Excel.
The only post with a star in this thread is a post which was a passing comment by it's nature no constructive info intended or included
I had to pause to point out the irony before I deliver my star which will destroy the evidence.
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Using Sine Cosine and Tan in Excel.
CODE
SIN(number)
SIN(30) equals -0.98803, the sine of 30 radians
SIN(RADIANS(30)) equals 0.5, the sine of 30°
Example: =SIN(RADIANS(30))
COS(number)
COS(1.5) equals 0.07074, the cosine of 1.5 radians
COS(RADIANS(1.5)) equals 0.99966, the sine of 1.5°
Example: =COS(RADIANS(1.5))
TAN(number)
TAN(2) equals -2.18504, the tangent of 2 radians
TAN(RADIANS(2)) equals 0.03492, the tangent of 2°
Example: =TAN(RADIANS(2))
ASIN(number)
ASIN(0.5) equals 0.523599 radians
DEGREES(ASIN(0.5)) equals 30°, the arcsine of 0.5
Example: =DEGREES(ASIN(0.5))
ACOS(number)
ACOS(-0.5) equals 2.09440 radians
DEGREES(ACOS(-0.5)) equals 120°, the arccosine of -0.5
Example: =DEGREES(ACOS(-0.5))
ATAN(number)
ATAN(1) equals 0.785398 radians
DEGREES(ATAN(1)) equals 45°, the arctangent of 1
Example: =DEGREES(ATAN(1))
Flores