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

- 09-28-2005midimannewbie question - sin squared
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!

- 09-28-2005Decrypt
Google -> define sine squared

edit: went looking for the right headers/functions, but everyone beat me to it...:( - 09-28-2005jmd15
Like you want to get the sine of an angle? Try this:

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;

}

- 09-28-2005ThantosQuote:

SYNOPSIS

#include <math.h>

double sin(double x);

DESCRIPTION

The sin() function returns the sine of x, where x is given

in radians.

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.

- 09-28-2005midiman
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 :) - 09-28-2005Enahs
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. - 09-28-2005Thantos
pow(sin(angle), 2);

that would be the correct call yes. - 09-28-2005midiman
thanks, your help is greatly appreciated

- 09-28-2005Rashakil Fol
I hate pow.

Code:`tmp = sin(angle);`

sq = tmp * tmp;

Code:`double sin_sq(double ang) {`

tmp = sin(ang);

return tmp * tmp;

}

- 09-28-2005Thantos
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**

- 09-29-2005Rashakil Fol
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. - 09-29-2005Salem
> 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.