----------------------------------- Catalyst Sun Jan 04, 2004 2:19 am Sine Approximation ----------------------------------- var factorialHold : int := 0 const maxPres := 100 var ZeroSineDx : array 0 .. maxPres of real for i : 0 .. maxPres - 4 by 4 ZeroSineDx (i) := 0 ZeroSineDx (i + 1) := 1 ZeroSineDx (i + 2) := 0 ZeroSineDx (i + 3) := -1 end for var SineHold, SineN : real := 0 var sinePres : int := 9 function sinE (n : real) : real result sin(n) end sinE function Factorial (n : int) : int if (n = 1) or (n = 0) then result 1 else factorialHold := 1 for i : 1 .. n factorialHold *= i end for result factorialHold end if end Factorial function Sine (n : real) : real SineHold := 0 if (n = 0) then result 0 end if for i : 0 .. sinePres SineHold += (ZeroSineDx (i) * (n ** i)) / (Factorial (i)) end for result SineHold end Sine View.Set ("nobuttonbar,graphics:512;512,position:300;300,offscreenonly") for k : 1 .. 12 by 2 drawfillbox (0, 0, maxx, maxy, 7) sinePres := k drawline (maxx div 2, 0, maxx div 2, maxy, 10) drawline (0, maxy div 2, maxx, maxy div 2, 10) for i : -maxx .. maxx drawdot (i + maxx div 2, round (sinE (i / maxx * 10) * 50) + maxx div 2, 103) drawdot (i + maxx div 2, round (Sine (i / maxx * 10) * 50) + maxx div 2, 42) end for View.Update delay (200) end for ----------------------------------- Homer_simpson Sun Jan 04, 2004 4:12 pm ----------------------------------- nice code... +50 ----------------------------------- gigaman Mon Oct 25, 2004 3:20 pm ----------------------------------- nice pretty cool program but what does it show? ----------------------------------- Delos Mon Oct 25, 2004 4:39 pm ----------------------------------- As the title infers...Catalyst has used some crazy maths there (factorials, possibly some level of calculus as well) so as to approximate the value of sine on a graph, starting with the function y = x. Of course I can't tell you exactly how this works, or the applications, but I can tell you that if you exchange the assignemnts at the start of the programme thusly: ZeroSineDx (i + 1) := -1 ZeroSineDx (i + 2) := 0 ZeroSineDx (i + 3) := 1 You get cosine. This is interesting as the graph you start off with is y = -x. ----------------------------------- Catalyst Mon Oct 25, 2004 9:19 pm ----------------------------------- http://mathworld.wolfram.com/MaclaurinSeries.html :D