Result of sin function differs?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asd

    #1

    Result of sin function differs?

    Hello all.

    I was doing some kind of development and in the test file I have something
    like this:

    ///// Test File /////
    double x = sin(45);

    The output for that statement is:

    ///// Output Test File /////
    0.707107


    Unfortunately the output in my system differs from the one in the test
    file.

    I run the following example in my system:

    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
    cout << sin(45) << endl; // prints 0.850904

    return 0;
    }

    The example above prints 0.850904 in my system. In addition to that, my
    calculator says sin(45) is 0.707107, while calculator at google says that
    it is 0.850904.

    I am just curious if I am doing something wrong.
    Thanks a lot.


  • Stephen SM WONG

    #2
    Re: Result of sin function differs?

    sin(45 degree) is approximately 0.707107,
    sin(45 in radian) is approximately 0.850904.

    My 2 cents.

    Stephen Wong @ Hong Kong

    On Sat, 24 Mar 2007, asd wrote:
    Hello all.
    >
    I was doing some kind of development and in the test file I have something
    like this:
    >
    ///// Test File /////
    double x = sin(45);
    >
    The output for that statement is:
    >
    ///// Output Test File /////
    0.707107
    >
    >
    Unfortunately the output in my system differs from the one in the test
    file.
    >
    I run the following example in my system:
    >
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
    cout << sin(45) << endl; // prints 0.850904
    >
    return 0;
    }
    >
    The example above prints 0.850904 in my system. In addition to that, my
    calculator says sin(45) is 0.707107, while calculator at google says that
    it is 0.850904.
    >
    I am just curious if I am doing something wrong.
    Thanks a lot.
    >
    >
    >

    Comment

    • Kai-Uwe Bux

      #3
      Re: Result of sin function differs?

      asd wrote:
      Hello all.
      >
      I was doing some kind of development and in the test file I have something
      like this:
      >
      ///// Test File /////
      double x = sin(45);
      >
      The output for that statement is:
      >
      ///// Output Test File /////
      0.707107
      >
      >
      Unfortunately the output in my system differs from the one in the test
      file.
      >
      I run the following example in my system:
      >
      #include <iostream>
      #include <cmath>
      using namespace std;
      int main()
      {
      cout << sin(45) << endl; // prints 0.850904
      >
      return 0;
      }
      >
      The example above prints 0.850904 in my system. In addition to that, my
      calculator says sin(45) is 0.707107, while calculator at google says that
      it is 0.850904.
      You are confusing different ways of measuring angles. A half of a right
      angle can be specified as 45 deg or as Pi/8 rad. In the above computations,
      the number 45 sometimes is interpreted as deg and sometimes as rad.


      Best

      Kai-Uwe Bux

      Comment

      • Jim Langston

        #4
        Re: Result of sin function differs?


        "asd" <nospam@nospam. comwrote in message
        news:pan.2007.0 3.24.20.51.57.8 84232@nospam.co m...
        Hello all.
        >
        I was doing some kind of development and in the test file I have something
        like this:
        >
        ///// Test File /////
        double x = sin(45);
        >
        The output for that statement is:
        >
        ///// Output Test File /////
        0.707107
        >
        >
        Unfortunately the output in my system differs from the one in the test
        file.
        >
        I run the following example in my system:
        >
        #include <iostream>
        #include <cmath>
        using namespace std;
        int main()
        {
        cout << sin(45) << endl; // prints 0.850904
        >
        return 0;
        }
        >
        The example above prints 0.850904 in my system. In addition to that, my
        calculator says sin(45) is 0.707107, while calculator at google says that
        it is 0.850904.
        >
        I am just curious if I am doing something wrong.
        This program should explain.

        #include <cmath>
        #include <iostream>
        #include <string>

        const double pi = 3.1415926;

        int main()
        {
        double degrees = 45.0;
        // There are 2 pi radians in a circle.
        // There are 360 degrees in a circle.
        double radians = ( 2.0*pi) / 360.0 * degrees;

        // std::sin expects input as radians
        std::cout << std::sin( radians ) << "\n";

        std::string wait;
        std::getline( std::cin, wait );

        }


        Comment

        • asd

          #5
          Re: Result of sin function differs?

          Thank you so much for all of your answers.

          Now I am struggling with asin.

          the test file has:
          asin(.5);

          // test output
          30

          // My output with radian conversion
          0.00872676

          // without radian conversion
          0.523599

          I would be glad if you could also help this one.
          Thanks alot.


          Comment

          • Jim Langston

            #6
            Re: Result of sin function differs?

            "asd" <nospam@nospam. comwrote in message
            news:pan.2007.0 3.24.22.00.01.4 81064@nospam.co m...
            Thank you so much for all of your answers.
            >
            Now I am struggling with asin.
            >
            the test file has:
            asin(.5);
            >
            // test output
            30
            >
            // My output with radian conversion
            0.00872676
            >
            // without radian conversion
            0.523599
            >
            I would be glad if you could also help this one.
            Thanks alot.
            comments for asin in VC++ is:

            The units of the returned elements are in radians.
            The return value is a principal value between +pi/2 and -pi/2 that is
            consistent with the sine value input.

            No way you're going to get a value of 30 out of that unless you multiply it
            by some factor. I don't know where they get 30 from.



            Comment

            • asd

              #7
              Re: Result of sin function differs?

              On Sat, 24 Mar 2007 15:31:09 -0700, Jim Langston wrote:
              "asd" <nospam@nospam. comwrote in message
              news:pan.2007.0 3.24.22.00.01.4 81064@nospam.co m...
              >Thank you so much for all of your answers.
              >>
              >Now I am struggling with asin.
              >>
              >the test file has:
              >asin(.5);
              >>
              >// test output
              >30
              >>
              >// My output with radian conversion
              >0.00872676
              >>
              >// without radian conversion
              >0.523599
              >>
              >I would be glad if you could also help this one.
              >Thanks alot.
              >
              comments for asin in VC++ is:
              >
              The units of the returned elements are in radians.
              The return value is a principal value between +pi/2 and -pi/2 that is
              consistent with the sine value input.
              >
              No way you're going to get a value of 30 out of that unless you multiply it
              by some factor. I don't know where they get 30 from.

              Thank you so much Jim, it worked.

              Comment

              • Marcus Kwok

                #8
                Re: Result of sin function differs?

                Kai-Uwe Bux <jkherciueh@gmx .netwrote:
                You are confusing different ways of measuring angles. A half of a right
                angle can be specified as 45 deg or as Pi/8 rad.
                I think you mean Pi/4 rad.

                --
                Marcus Kwok
                Replace 'invalid' with 'net' to reply

                Comment

                • Kai-Uwe Bux

                  #9
                  Re: Result of sin function differs?

                  Marcus Kwok wrote:
                  Kai-Uwe Bux <jkherciueh@gmx .netwrote:
                  >You are confusing different ways of measuring angles. A half of a right
                  >angle can be specified as 45 deg or as Pi/8 rad.
                  >
                  I think you mean Pi/4 rad.
                  Sort of: I think, I meant 2*Pi/8 :-)


                  Thanks

                  Kai-Uwe Bux

                  Comment

                  Working...