Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.33 KB | None | 0 0
  1. #lang racket
  2.  
  3. (define (fraction_approx x n Ni Di)
  4.     (define (abs var)
  5.         (if (< var 0) (- var) var)
  6.     )
  7.     (define (abs_difference a b)
  8.         (abs (- a b) )
  9.     )
  10.     (define (Ni_pattern x N)
  11.         (Ni x N)
  12.     )
  13.     (define (Di_pattern x N)
  14.         (Di x N)
  15.     )
  16.     (define (next_element a2 a1 N)
  17.         (+ (* (Di_pattern x N) a2) (* (Ni_pattern x N) a1))
  18.     )
  19.     (define (next_fraction a1 a2 b1 b2 N)
  20.         (/ (next_element a2 a1 N) (next_element b2 b1 N))
  21.     )
  22.     (define (fraction a1 a2 b1 b2 N)
  23.         (if (<  (abs_difference (/ a2 b2) (next_fraction a1 a2 b1 b2 N) ) 0.000001 )
  24.             (/ a2 b2)
  25.             (fraction a2 (next_element a2 a1 N) b2 (next_element b2 b1 N) (+ N 1))
  26.         )
  27.     )
  28.     (fraction 1.0 0.0 0.0 1.0 n)
  29. )
  30. ;; x - wartosc argumentu (na przyklad dla arctan) | n - l. naturalna
  31. ;; jako zmienna do wyznaczenia wzorow cigaow N i D | Ni, Di- wzory na kolejne
  32. ;; elementy ciogow N i D
  33.  
  34. ;;Testy
  35. (define (pi)
  36.     (define (Dpi x n) 6 )
  37.     (define (Npi x n)
  38.         (* (- (* 2 n) 1) (- (* 2 n) 1))
  39.     )
  40.     (+ 3 (fraction_approx 1 1 Npi Dpi) )
  41. )
  42. (pi)
  43. (define (fib)
  44.     (define (Dfib x n) 1 )
  45.     (define (Nfib x n) 1 )
  46.     (fraction_approx 1 1 Nfib Dfib)
  47. )
  48. (fib)
  49. (define (arctan x)
  50.     (define (Dtan x n)
  51.         (* (+ (* 2 n) 1) (+ (* 2 n) 1))
  52.     )
  53.     (define (Ntan x n)
  54.         (if (= n 0)
  55.             x
  56.             (* (* n x) (* n x))
  57.         )
  58.     )
  59.     (fraction_approx x 0 Ntan Dtan)
  60. )
  61. (arctan 90)
  62. (- (arctan 90) (atan 90))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement