Because cos(x) can be writen as an infinite series. See picture included. You could do something like this :

using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (double d = 0; d < 3.0; d += 0.4)
{
Console.WriteLine("The cosine of {0} = {1}", d, Math.Cos(d));
Console.WriteLine("Calculated cosine of {0} = {1}", d, cos(d));
Console.WriteLine();
}
Console.ReadKey(); //keep console on screen until key press
}
static double cos(double x) //calculate cosine
{
double p = x * x; //reduce amount of multiplications
double q = p * p;
return 1.0 - p / 2 + q / 24 - p * q / 720 + q * q / 40320 - p * q * q / 3628800;
// add more terms for more accuracy
// 2, 24,720 etc. are the factorials of 2,4,6 etc.
}
}
}

A Taylor series isn't really a good way to compute this function unless you're looking for asymptotic accuracy around a particular point, rather than general accuracy along the whole thing. Also, it's a good idea to start by folding the number down to the interval [0,pi]. But suppose we did want to go with a Taylor series because that's all we knew of.

static double cos(double x) //calculate cosine
{
// move x to value in [0, pi] with equal answer
x = Math.Abs((x + Math.PI) % (2 * Math.PI) - Math.PI);
const double tf = 1.0 / 24.0, vtz = -1.0 / 720.0, fzhtz = 1.0 / 40320.0, fukit = -1.0 / 3628800.0;
double p = x * x;
// use Horner's method instead, just because.
return 1 + p * (-0.5 + p * (tf + p * (vtz + p * (fzhtz + p * fukit))));
}
}
}

See pages 115 and 116 here for a comparison of a Taylor approximation with one that strives for a different metric of accuracy.

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...