March 3rd, 2006, 04:36 AM

How to use sin,cos,tan inverse in c or c++
Hello ...
.I have this program to calculate some math equations but i want it to be better using some inverses !
so any idea how to use Tan1(x) , Sin1(x) ??
March 3rd, 2006, 05:26 AM

You can use atan(), asin(), and acos(). Those are the respective inverses of tan, sin, and cos.
March 3rd, 2006, 05:28 AM

March 20th, 2006, 10:05 AM

how is it done in radians
Originally Posted by Lux Perpetua
You can use atan(), asin(), and acos(). Those are the respective inverses of tan, sin, and cos.
thnanks alot for your advice but still have problem with the radians and degree convertions
this is what we have at hand
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
int main()
{
printf("%f", atan (30));
return 0;
}
// the 30 is in degrees. how do i solve this issue. awiating you support and advice
March 20th, 2006, 10:37 AM

Multiply the degrees by pi and divide by 180.
Comments on this post
Any advertisement triggered by IntelliTxt in this post is not endorsed by the author of this post.
March 20th, 2006, 10:49 AM

Review a basic trigonometry text, because your conception of arctan is wrong as well.
In a circle, you have 360 degrees or 2*PI radians. Hence:
360 degrees == 2*PI radians
180 degrees == PI radians
1 degree == PI/180 radians
1 radian == 180/PI degrees
There are your conversion factors for degrees to radians and back again. You also see the basic procedure for deriving conversion factors.
Now, for your confused concept of trig and inverse trig functions. The trig functions take an angle argument and they return the ratio of two of the sides of a right triangle that contains that angle. Which two of the three sides of that triangle are used is determined by which trig function you use. Refer to a text to see what they are.
An inverse trig function (eg, atan) takes a ratio as an argument and returns the angle that that ratio represents; ie, it takes the associated trig function in the opposite direction  that is what makes it an inverse function. An important caveat to keep in mind is that the angle returned by an inverse trig function only ranges over 180 degrees, so you have to look at the two numbers in the ratio to figure out which quadrant of that circle that angle lies in and hence exactly what that angle was  again, read up on this in a trig textbook; the pictures should explain it better than my words could (no, I am not being facetious; a graphical representation communicates a lot in this area of math).
So, your sample code is wrong, because you would not pass an angle to atan().
Now, to get the value of PI, consider this: atan(1.0) == 45 degrees == PI/4.
So if you take the atan() of 1.0 and multiply it by 4, you will get PI. Hence, in your initialization code you should declare a global variable dPi and assign it thus:
Code:
#include <math.h>
double dPi;
int main(void)
{
dPi = 4.0 * atan(1.0);
return 0;
}
Oh, and in the future please use code tags to post code. Just stick your code between [code] and [/code].
PS
Don't be afraid to study up on trig. It's really quite simple. I taught myself one summer and I'm no genius, not by a long shot.
The reason for radians is that the method for calculating the trig functions (Maclaurin series, a special form of Taylor series  you'll cover these in 3rd semester calculus) depends on the angle being in radians. Also, throughout calculus you will be dealing with angles being measured in radians, so now's as good a time as any to start getting used to it.
Last edited by dwise1_aol; March 20th, 2006 at 11:03 AM.
March 20th, 2006, 11:26 AM

Originally Posted by Dave Sinkula
Multiply the degrees by pi and divide by 180.
Since you presumably are doing this in a number of places, and probably need to convert freely between them in both directions, you would be wise to write conversion functions:
C Code:
#include <math.h> // or <cmath> for C++
// Sombunall versions of math.h already define M_PI
#ifndef M_PI
// You can extend this approximation as far as you need to;
// this version was copied from the MINGW GCC headers
#define M_PI 3.14159265358979323846
#endif
#define DEG_CIRCLE 360
#define DEG_TO_RAD (M_PI / (DEG_CIRCLE / 2))
#define RAD_TO_DEG ((DEG_CIRCLE / 2) / M_PI)
// this assumes that your compiler supports C99 or C++
// otherwise, you can use macros to get the same result
inline double deg2rad(double degrees)
{
return degrees * DEG_TO_RAD;
}
inline double rad2deg(double radians)
{
return radians * RAD_TO_DEG;
}
This is one of those cases (like the isodd()/iseven() pair, or the previously mentioned constant M_PI) where what would seem an obviously common function is mysteriously absent from the standard library... while loose cannons like gets() get perpetuated indefinitely. Go figure. HTH.
Last edited by ScholRLEA; March 20th, 2006 at 11:46 AM.
March 21st, 2006, 04:26 AM

Thanks
thanks pals. i tried tried another approach and it work
1 rad = 57.692 degree.
thaank alot for your .
i really enjoy your lectures.