Results 1 to 3 of 3

Thread: alternative calculation for sin(x) [resolved]

  1. #1

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090

    Resolved alternative calculation for sin(x) [resolved]

    I have been given an excercise when I have to work out the sin value for x without using the inbuilt one. I was given this function:

    sin(x) ~= x- x3/3! + x5/5!
    The further on you keep going the more accurate the thing becomes. I was also told that x should be in radians.

    Now, I couldn't get this thing working. I have 360 degrees, where I know sin(36) = 0. 360 degrees is roughly 6.28 radians. This gives:
    6.28 - 248/24 + 9768/120
    =6.28 - 10.32 + 81.4
    =77.36

    Now that's just WAY off.
    Am I somehow using the formula badly or was I given an incorrect one? If it was the wrong one, does anyone know what we were most likely meant to be given?
    Last edited by Acidic; Nov 15th, 2004 at 01:32 PM.
    Have I helped you? Please Rate my posts.

  2. #2

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    never mind solved it. Here's the code:
    Code:
    double mysin(double x)
    {
    	bool flag = true;
    	double sinx = 0.0;
    
    	for (int i=1; i<=15; i=i+2)
    		{
    		if (flag == true)
    			{
    			sinx = sinx + pow(x,i)/myFactorial(i);
    			flag = false;
    			}
    		else
    			{
    			sinx = sinx - pow(x,i)/myFactorial(i);
    			flag = true;
    			}
    		}
    	return sinx;
    }
    Have I helped you? Please Rate my posts.

  3. #3
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Dunno how much you know about this, but as you said

    the further on you keep going the more accurate the thing becomes.

    In fact it becomes exact if you take the sum of an infinite number of terms (as one might guess).

    The series representation of sin is an example of Taylor series - you can write lots of functions in series form using Taylor.
    an ending

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width