|
-
Nov 12th, 2004, 04:33 PM
#1
Thread Starter
Frenzied Member
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. 
-
Nov 15th, 2004, 10:37 AM
#2
Thread Starter
Frenzied Member
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. 
-
Nov 18th, 2004, 12:13 PM
#3
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|