Need atan(x/y); x = 1e3 ohms. y = 338.63 ohms. Theta should equal 18.71 degrees. coming up with decimal. I even tried this as well....ratio = x/y; atan(ratio); theta = (x/y)/tan. Help please...no debug errors.
Quote from: buckbuilt03 on July 29, 2011, 03:16:12 AM
Need atan(x/y); x = 1e3 ohms. y = 338.63 ohms. Theta should equal 18.71 degrees. coming up with decimal. I even tried this as well....ratio = x/y; atan(ratio); theta = (x/y)/tan. Help please...no debug errors.
[/quote
The only way that theta can equal 18.71 degrees is if you arrange things like this (shown in BASIC)
r2d = 57.2958 ' convert radians to degrees
PRINT atn (338.63 / 1e3) * r2d
So what you're saying is that C can't perform a binary trig function without prior conversion?? I know how to convert on paper from repetition of the formula but,..........hmmmmmnnnnn, maybe I've been staring at the monitor too long.
Thanks man...I'll further research your example,
much obliged,
buck
#include <math.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("% .15G\n",(double)atan(338.63/1e3)*57.2958);
return 0;
}
In most languages trigonometry is performed in radians, so you need to convert back and forth into degrees.
Quote from: Stefan Pendl on July 29, 2011, 06:18:02 PM
In most languages trigonometry is performed in radians, so you need to convert back and forth into degrees.
And the doc/online help clearly state that this is the case for Pelle's C as well:
Quoteatan, atanf, atanl functions
Purpose:
Computes the arc tangent.
Syntax:
float atanf(float x);
double atan(double x);
long double atanl(long double x);
Declared in:
<math.h>
Description:
The function computes the angle whose tangent is x, in the interval [-pi/2, +pi/2] radians.
Returns:
The arc tangent of x.
Ralf