I am trying to plot this function:
#lang racket
(define (smoothsquare x)
((smooth square) x))
(define (square x)
(* x x))
(require plot)
(plot (function smoothsquare (- 1) 1))
(define dx 0.00001)
(define (smooth f)
(lambda (x) (/ (+ (f (- x dx))
(f x)
(f (+ x dx)))
3)))
but I get the following error: ". plot: could not determine sensible plot bounds; got x ∈ [-1,1], y ∈ [#f,#f]"
Why is that? Is there a way around this? I can think of a sensible plot bound for the y-axis, namely [-1,1], but I'm not sure how to tell it that.
I have read the intro here https://docs.racket-lang.org/plot/intro.html but it isn't helping me
The problem here is that you define smooth too late. That is, when you call plot, the plot library attempts to call your smoothsquare, which in turn tries to call smooth, but smooth is not defined yet because it's only defined after the plot call is finished.
Following code should work:
#lang racket
(require plot)
(define dx 0.00001)
(define (smooth f)
(lambda (x)
(/ (+ (f (- x dx))
(f x)
(f (+ x dx)))
3)))
(define (smoothsquare x)
((smooth square) x))
(define (square x)
(* x x))
(plot (function smoothsquare -1 1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With