Approximation of COSINE equation

I was given the approximation of COS formula where you get a value close to COS

Here it is:

cos = (1 - (1/2)*radians^2) + ((1/24)*radians^4) - ((1/720)*radians^6)) + ((1/40320)*radians^8)

I always get 1.0 as my answer:(

anyone know the formula to see if I have it correct?
Who is Participating?
ozoConnect With a Mentor Commented:
cos = (1 - (1.0/2)*Math.pow(radians,2)) + ((1.0/24)*Math.pow(radians, 4)) - ((1.0/720)*Math.pow(radians, 6)) + ((1.0/40320)*Math.pow(radians,8));
Except for an extra ) it is correct assuming that ^ means exponentiation in the language that you are implementing it in
and that ^ has a higher precedence than *
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

ClaudeWalkerAuthor Commented:

sin = (radians - (1/6)*Math.pow(radians,3)) + ((1/120)*Math.pow(radians, 5)) - ((1/5040)*Math.pow(radians, 7) + ((1/362880)*Math.pow(radians,9);
cos = (1 - (1/2)*Math.pow(radians,2)) + ((1/24)*Math.pow(radians, 4)) - ((1/720)*Math.pow(radians, 6)) + ((1/40320)*Math.pow(radians,8);
ClaudeWalkerAuthor Commented:
There is a missing paranthese in the cos formula which has been corrected however I think the formula is wrong because the sin one works.
>> There is a missing paranthese in the cos formula which has been corrected

In your previous post there is still a ) missing at the end ... But I assume that's the one you fixed ?

        cos = (1 - (1/2)*Math.pow(radians,2)) + ((1/24)*Math.pow(radians, 4)) - ((1/720)*Math.pow(radians, 6)) + ((1/40320)*Math.pow(radians,8));

Looks fine to me, assuming that the fractions are accurate real values, and not rounded integer values. Try calculating one term at a time, and see what results you get for each.
All Courses

From novice to tech pro — start learning today.