How do I find the derivative of sin(x) using recursion?

How do I find the derivative of sin(x) where x could be any value e.g. 1,2,3 using recursion?


Firstly, the derivative of sin(x) is cos(x) or, to put it more formally:

f(x) = sin(x)
f'(x) = cos(x)

I guess you could solve sin(x) using the Taylor series for cos(x):

cos(x) = 1 - x^2/2| + x^2/4! + ...

with recursion. In Java:

public double cos(double x) {
  return 1 + next(-x*x/2, x, 3);

public double next(double term, double x, int i) {
  double next = -term * x * x / (i * (i + 1));
  return term + next(term, x, i + 2);

Of course you'll need to put some limiter in to exit the recursion otherwise you'll get a stack overflow error eventually, which is left as an exercise for the reader.

Oh and I see the question is tagged as C not Java, but it is homework. :-)

I think you need to look up the terms you are trying to use (derivative and recursion). If I read this question it sounds like you are asking how to calculate:

derivative of sin(3)


derivative of sin(2)


derivative of sin(1)

The answer is zero for all values of x, so that can't be what you are asking. Recursion from that as a starting point terminates immediately.

One can only assume that you want to evaluate the derivative of sin(x) [period]. What recursion would have to do with such a calculation is not clear. A possible interpretation is that you are looking for a numerical approximation of the sine derivative, and want to recursively narrow the interval over which you are calculating the slope.

Nobody is going to be able to read your mind well enough to answer your question as is, so it is time to rephrase it more precisely. Perhaps examples or a pseudocode fragement would be helpful to demonstrate your intentions or problem more clearly.

Need Your Help

How to find object tag with param, and embed tag inside HTML using simple html DOM php

php html

I found it really hard for me to understand the simple html dom of php. Even if I read the instruction on how to do it. As for me, I'm just new in programming industry. As I've been searching on ho...

Can mongo upsert array data?

node.js mongodb

I have a mongo document like this.