Recursion with Trigonometry

<< Previous Article

Trigonometric functions like sine, cosine, … can all be computed recursively as well. As exponential in our previous article, the need is just the recursive relation and the terminating condition.

Recursive relation for sine(x) could be sine(x) = 2 * sine(x / 2) * cosine(x / 2) = 2 * sine(x / 2) * sqrt(1 – sine2(x / 2)). And accordingly, the terminating condition has to be derived for the limiting case when x is approaching zero, but not necessarily zero. And from world of limits, we have sine(x) = x for small x’s in radians. Also, on careful observation, the recursive relation has just one lower order x / 2, so the computation could be simplified as:

v = sine(x / 2);
sine(x) = 2 * v * sqrt(1 - v2);

Putting in the complete logic (say in C) would be as follows:

#define DELTA 0.001 // Depends on the desired accuracy

double sine(double x)
	if (fabs(x) < DELTA) // Terminating Condition
		return x;
		double v = sine(x / 2);
		return 2 * v * sqrt(1 - v * v);

Similarly, cosine(x) could be recursively defined as 2 * cosine2(x / 2) – 1 with terminating condition of 1 – x2 / 2. And similarly all others.

Moreover, why only trigonometric functions, but all kind of mathematical functions having some recursive relation (with a terminating condition) can be computed using recursion.

And why only mathematical functions, but even procedural logic could be computed using recursion. Watch out for the same …

Next Article >>

Anil Kumar Pugalia (123 Posts)

The author is a hobbyist in open source hardware and software, with a passion for mathematics, and philosopher in thoughts. A gold medallist from the Indian Institute of Science, Linux, mathematics and knowledge sharing are few of his passions. He experiments with Linux and embedded systems to share his learnings through his weekend workshops. Learn more about him and his experiments at

   Send article as PDF   

2 thoughts on “Recursion with Trigonometry

  1. Pingback: Deriving the Functional Recursion | Playing with Systems

  2. Pingback: Introduction to Procedural Recursion | Playing with Systems

Leave a Reply

Your email address will not be published. Required fields are marked *