Plot now supports the option Axes.

This commit is contained in:
Jens Axel Søgaard 2012-07-02 17:49:11 +02:00
parent cd67ae6633
commit eb39b34a3b
2 changed files with 25 additions and 12 deletions

View File

@ -830,7 +830,10 @@
List->Set List->Set
Define Define
Range Range
Plot) Plot
; Plot options:
Axes
)
;;; ;;;
;;; INVARIANT ;;; INVARIANT
@ -1182,6 +1185,8 @@
; TODO: Improve this ; TODO: Improve this
(eval u ns)) (eval u ns))
; Plot options:
(define Axes 'Axes)
(define (Plot f range [options '(List)]) (define (Plot f range [options '(List)])
; TODO: Implement options ; TODO: Implement options
;(displayln (list f range)) ;(displayln (list f range))
@ -1195,13 +1200,14 @@
[f (list f)] [f (list f)]
[else (error 'Plot "TODO")])) [else (error 'Plot "TODO")]))
(define fs (list f)) (define fs (list f))
(define axes? (Member? Axes options))
(match range (match range
[(List: var x-min x-max) [(List: var x-min x-max)
; TODO: Declare var as a local variable ? ; TODO: Declare var as a local variable ?
(plot2d (if (procedure? f) (plot2d (if (procedure? f)
(λ (x) (f x)) (λ (x) (f x))
(λ (x) (N (Substitute f (Equal var x))))) (λ (x) (N (Substitute f (Equal var x)))))
x-min x-max y-min y-max excluded?)] x-min x-max y-min y-max excluded? axes?)]
[else (error)])) [else (error)]))
#;(and (real? x-min) (real? x-max) (real? y-min) (real? y-max) #;(and (real? x-min) (real? x-max) (real? y-min) (real? y-max)

View File

@ -144,7 +144,10 @@
(loop more (list x2) (cons (reverse (cons x1 ys)) xss)) (loop more (list x2) (cons (reverse (cons x1 ys)) xss))
(loop (cons x2 more) (cons x1 ys) xss))]))) (loop (cons x2 more) (cons x1 ys) xss))])))
(define (plot2d unwrapped-f [x-min -5] [x-max 5] [y-min -5] [y-max 5] [excluded? #f]) (define (cons-if bool x xs)
(if bool (cons x xs) xs))
(define (plot2d unwrapped-f [x-min -5] [x-max 5] [y-min -5] [y-max 5] [excluded? #f] [axes? #t])
; wrap the function to be drawn, s.t. it ; wrap the function to be drawn, s.t. it
; returns #f in error situations ; returns #f in error situations
(define (excluded-from-domain? x) (define (excluded-from-domain? x)
@ -195,9 +198,11 @@
(displayln (displayln
(list (list
(begin0 (begin0
(plot (list (map lines (plot (list
(cons-if axes? (axes)
(map lines
(map remove-non-numbers (map remove-non-numbers
connected-points))) connected-points))))
#:x-min x-min #:x-max x-max #:x-min x-min #:x-max x-max
#:y-min y-min #:y-max y-max) #:y-min y-min #:y-max y-max)
(displayln (format "adaptive number of evaluations: ~a" count)) (displayln (format "adaptive number of evaluations: ~a" count))
@ -209,9 +214,11 @@
(reset-count)) (reset-count))
(plot (list (map lines (plot (list
(cons-if axes? (axes)
(map lines
(map remove-non-numbers (map remove-non-numbers
connected-points))) connected-points))))
#:x-min x-min #:x-max x-max #:x-min x-min #:x-max x-max
#:y-min y-min #:y-max y-max))) #:y-min y-min #:y-max y-max)))