Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (fraction_approx x n Ni Di)
- (define (abs var)
- (if (< var 0) (- var) var)
- )
- (define (abs_difference a b)
- (abs (- a b) )
- )
- (define (Ni_pattern x N)
- (Ni x N)
- )
- (define (Di_pattern x N)
- (Di x N)
- )
- (define (next_element a2 a1 N)
- (+ (* (Di_pattern x N) a2) (* (Ni_pattern x N) a1))
- )
- (define (next_fraction a1 a2 b1 b2 N)
- (/ (next_element a2 a1 N) (next_element b2 b1 N))
- )
- (define (fraction a1 a2 b1 b2 N)
- (if (< (abs_difference (/ a2 b2) (next_fraction a1 a2 b1 b2 N) ) 0.000001 )
- (/ a2 b2)
- (fraction a2 (next_element a2 a1 N) b2 (next_element b2 b1 N) (+ N 1))
- )
- )
- (fraction 1.0 0.0 0.0 1.0 n)
- )
- ;; x - wartosc argumentu (na przyklad dla arctan) | n - l. naturalna
- ;; jako zmienna do wyznaczenia wzorow cigaow N i D | Ni, Di- wzory na kolejne
- ;; elementy ciogow N i D
- ;;Testy
- (define (pi)
- (define (Dpi x n) 6 )
- (define (Npi x n)
- (* (- (* 2 n) 1) (- (* 2 n) 1))
- )
- (+ 3 (fraction_approx 1 1 Npi Dpi) )
- )
- (pi)
- (define (fib)
- (define (Dfib x n) 1 )
- (define (Nfib x n) 1 )
- (fraction_approx 1 1 Nfib Dfib)
- )
- (fib)
- (define (arctan x)
- (define (Dtan x n)
- (* (+ (* 2 n) 1) (+ (* 2 n) 1))
- )
- (define (Ntan x n)
- (if (= n 0)
- x
- (* (* n x) (* n x))
- )
- )
- (fraction_approx x 0 Ntan Dtan)
- )
- (arctan 90)
- (- (arctan 90) (atan 90))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement