Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Sine Approximation
Author Message
Catalyst

Posted: Sun Jan 04, 2004 2:19 am   Post subject: Sine Approximation

 code: 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

Posted: Sun Jan 04, 2004 4:12 pm   Post subject: (No subject)

nice code...
+50
gigaman

Posted: Mon Oct 25, 2004 3:20 pm   Post subject: (No subject)

nice pretty cool program but what does it show?
Delos

Posted: Mon Oct 25, 2004 4:39 pm   Post subject: (No subject)

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:
 code: 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

Posted: Mon Oct 25, 2004 9:19 pm   Post subject: (No subject)

http://mathworld.wolfram.com/MaclaurinSeries.html
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: