PasteRack.org
Paste # 80952
2022-01-14 21:13:22

Forked from paste # 28373.

Fork as a new paste.

Paste viewed 117 times.


Embed:

  1. #lang racket
  2. (require plot)
  3.  
  4. (define xg0 1)
  5.  
  6. (define (g x)
  7.   (/ 3 (- x xg0)))
  8.  
  9. (define Xs
  10.   '(0.0
  11.     2.302785323219288
  12.     3.501885860538783
  13.     4.387531553378729
  14.     5.116359864244201
  15.     5.748205229427828))
  16.  
  17. (define aspect-ratio 2.)
  18. (define xmax 7)
  19. (define ymax (/ xmax aspect-ratio))
  20.  
  21. (parameterize ([plot-x-ticks no-ticks]
  22.                [plot-y-ticks no-ticks])
  23.   (displayln
  24.    (plot
  25.    #:aspect-ratio aspect-ratio
  26.    #:y-min 0 #:y-max ymax
  27.    #:x-max xmax
  28.    #:width 700
  29.    #:x-label #f
  30.    #:legend-anchor 'top-right
  31.    (list (function g #:color 1 #:label "g(x)")
  32.          (x-ticks (list (tick 0 #t "X₀=0")))
  33.          (lines-interval (list (list 0 0) (list 0 ymax))
  34.                          (list (list xg0 0) (list xg0 ymax))
  35.                          #:line1-style 'transparent
  36.                          #:line2-color 1 #:line2-style 'long-dash
  37.                          #:color 1 #:style 'fdiagonal-hatch #:alpha 1)
  38.          (for/list ([X Xs]
  39.                     [X2 (rest Xs)]
  40.                     [t (in-naturals 1)]
  41.                     [t-1_idx '(      )]
  42.                     [t_idx '(      )])
  43.            (define gX2 (g X2))
  44.            (define X2+δ (+ X2 (/ (+ t 1.)) #;(* .4 (- X2 X))))
  45.            (list
  46.             (function (λ (x) (- x X))
  47.                       #:color "black"
  48.                       X X2+δ)
  49.             (vrule X2 0 gX2 #:style 'long-dash #:color "black")
  50.             (point-label (list X2 gX2) (format "iso~a" t_idx) #:anchor 'left)
  51.             (x-ticks (list (tick X2 #t (format "X~a" t_idx))))
  52.             (point-label (list X2+δ (- X2+δ X)) (format "y = x - X~a" t-1_idx)
  53.                          #:anchor 'left #:point-size 0)))
  54.          ))))

=>