3 ms·
Random interesting (to me) tangent - couldn't you find a recursive function that, at its limit, was a sine? Could any function be generated this way? And throw
by Scene_Cast2 7y ago
Random interesting (to me) tangent - couldn't you find a recursive function that, at its limit, was a sine? Could any function be generated this way? And throw some variant of Kolmogorov complexity metric on this class of function-generating fractals and this becomes a neat mathematical area.
- excessive 7y agoHere is one in Python. Uncomment the if statement if you want it to terminate. def sin(x): def recur(x, n, s, p, f): #if n > 9: return s; return recur(x, n + 2, s + p/f, -p*x*x, f*(n + 1)*(n + 2)) return recur(x, 1, 0, x, 1) Of course maybe it's cheating from your intent because it's really just implementing the Taylor series, and it has too many arguments. I believe any analytic function could be defined this way if you can figure out the pattern for its derivatives.
- perl4ever 7y agoFunction sine(x As Double, Optional term, Optional p = 1#) As Double If IsMissing(term) Then term = x End If If term <> 0 Then sine = term + sine(x, -term * x / (p + 1) * x / (p + 2), p + 2) End If End Function Edit: This is my interpretation of the Taylor series approximation, but it's probably a bad idea to use this for anything that matters. One reason is that it doesn't reduce large angles, and another is that people who know what they're doing prefer to use some other formula, from a cursory Googling...though I'm not sure why.