newbie question - sin squared

This is a discussion on newbie question - sin squared within the C++ Programming forums, part of the General Programming Boards category; i'm new to programming, and i was just wondering how one would calculate sin squared of an angle? any help ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    3

    Question newbie 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!

  2. #2
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    Google -> define sine squared

    edit: went looking for the right headers/functions, but everyone beat me to it...
    Last edited by Decrypt; 09-28-2005 at 06:18 PM.
    There is a difference between tedious and difficult.

  3. #3
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    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;
    }
    If that's not what you want let me know.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    SYNOPSIS
    #include <math.h>
    double sin(double x);
    DESCRIPTION
    The sin() function returns the sine of x, where x is given
    in radians.
    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.
    Of course since you are using c++ you should use <cmath> instead of <math.h>

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    3
    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

  6. #6
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    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.

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    pow(sin(angle), 2);
    that would be the correct call yes.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    3
    thanks, your help is greatly appreciated

  9. #9
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    I hate pow.

    Code:
    tmp = sin(angle);
    sq = tmp * tmp;
    or if that's too verbose to use all the time,

    Code:
    double sin_sq(double ang) {
        tmp = sin(ang);
        return tmp * tmp;
    }
    pow does too much nasty stuff like logarithms.

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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 is a terrible disease - get it working first, then ask how it might be improved.

  11. #11
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    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.

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 05:45 PM
  4. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 03:38 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21