i'm new to programming, and i was just wondering how one would calculate sin squared of an angle? any help would be hugely appreciated!
Printable View
i'm new to programming, and i was just wondering how one would calculate sin squared of an angle? any help would be hugely appreciated!
Google -> define sine squared
edit: went looking for the right headers/functions, but everyone beat me to it...:(
Like you want to get the sine of an angle? Try this:
If that's not what you want let me know.Code:#include <iostream>
#include <stdlib.h>
#include <cmath.h>
int main()
{
int angle;
cout<<"Enter an angle:";
cin>>angle;
cout<<"The sine squared of that angle is "<<sin(angle)<<endl;
system("PAUSE");
return 0;
}
Quote:
SYNOPSIS
#include <math.h>
double sin(double x);
DESCRIPTION
The sin() function returns the sine of x, where x is given
in radians.
Of course since you are using c++ you should use <cmath> instead of <math.h>Quote:
SYNOPSIS
#include <math.h>
double pow(double x, double y);
DESCRIPTION
The pow() function returns the value of x raised to the
power of y.
im already using cmath, tried to use the pow function but i got an error...
would it be pow(sin(angle), 2) ? not sure how to set that up... if you just put pow (sin,2), where do you put the angle?
thanks all for your help, and your patience :)
Yes.
Sin^2(theta) is written that way so the power does not get confused for what you are evaluating sin at.
Sin^2(theta) is the same thing as (sin(theta)) all of that squared.
So you can either use the power function, or just multiply it by it’s self.
pow(sin(angle), 2);
that would be the correct call yes.
thanks, your help is greatly appreciated
I hate pow.
or if that's too verbose to use all the time,Code:tmp = sin(angle);
sq = tmp * tmp;
pow does too much nasty stuff like logarithms.Code:double sin_sq(double ang) {
tmp = sin(ang);
return tmp * tmp;
}
You can't hate pow(). pow() does nothing wrong. gets() you can hate, even vilify. Using a function like you showed really limits what you can do. What if they wanted the 4th power? The 8th power? The nth power?
Quote:
Originally Posted by Salem
Premature optimisation may be the root of all evil, but premature molassification is evil itself.
Pow isn't evil (and it's only to be hated in certain threads and at certain times of the day), but multiplying a number by itself to square it is not optimisation if it's the first thing you think of. And it's a good thing to think of first, instead of pow, when you need to square a number.
> tried to use the pow function but i got an error...
Sure, the incredible invisible error message strikes again.
Why don't people just post the information they know rather than making others guess what it is.