Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sine Approximator Java

Name: Anonymous 2009-10-08 17:16

if you guys really think you are geniuses then write a java program that can approximate the sin function for any angle between 0 and 360 using taylor expansions

Name: Anonymous 2009-10-08 17:39

According to http://upload.wikimedia.org/math/e/7/2/e72a9c97103eed0fe72a1975a8fd748a.png and I have no idea if it's correct or not

(defun factorial (x)                               
  (reduce #'* (loop for i from 1 upto x collect i)))

(defun help (x)
  (let (result
        (n 0))
    (lambda ()   
      (setq result          
            (* (/ (expt -1 n)             
                  (factorial (1+ (* 2 n))))
               (expt x (1+ (* 2 n)))))
      (incf n)
      result)))
                            
(defun doit (x approximation)
  (do* ((i 0 (1+ i))
        (f (help x))
        (y (funcall f)
           (if (oddp i)
               (- y (funcall f))  
               (+ y (funcall f)))))
       ((= i approximation) y)))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List