Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
#lang racket
(define (integrate f a b steps meth)
(define h (/ (- b a) steps))
(* h (for/sum ([i steps])
(meth f (+ a (* h i)) h))))
(define (left-rect f x h) (f x))
(define (mid-rect f x h) (f (+ x (/ h 2))))
(define (right-rect f x h)(f (+ x h)))
(define (trapezium f x h) (/ (+ (f x) (f (+ x h))) 2))
(define (simpson f x h) (/ (+ (f x) (* 4 (f (+ x (/ h 2)))) (f (+ x h))) 6))
(define (test f a b s n)
(displayln n)
(for ([meth (list left-rect mid-rect right-rect trapezium simpson)]
[name '( left-rect mid-rect right-rect trapezium simpson)])
(displayln (~a name ":\t" (integrate f a b s meth))))
(newline))
(test (λ(x) (* x x x)) 0. 1. 100 "CUBED")
(test (λ(x) (/ x)) 1. 100. 1000 "RECIPROCAL")
(test (λ(x) x) 0. 5000. 5000000 "IDENTITY")
(test (λ(x) x) 0. 6000. 6000000 "IDENTITY")

View file

@ -0,0 +1,27 @@
CUBED
left-rect: 0.24502500000000005
mid-rect: 0.24998750000000006
right-rect: 0.25502500000000006
trapezium: 0.250025
simpson: 0.25
RECIPROCAL
left-rect: 4.65499105751468
mid-rect: 4.604762548678376
right-rect: 4.55698105751468
trapezium: 4.605986057514676
simpson: 4.605170384957133
IDENTITY
left-rect: 12499997.5
mid-rect: 12500000.0
right-rect: 12500002.5
trapezium: 12500000.0
simpson: 12500000.0
IDENTITY
left-rect: 17999997.000000004
mid-rect: 17999999.999999993
right-rect: 18000003.000000004
trapezium: 17999999.999999993
simpson: 17999999.999999993