PasteRack.org
Paste # 69408
2022-11-08 22:43:17

Forked from paste # 28373.

Fork as a new paste.

Paste viewed 878 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.   (plot
  24.    #:aspect-ratio aspect-ratio
  25.    #:y-min 0 #:y-max ymax
  26.    #:x-max xmax
  27.    #:width 700
  28.    #:x-label #f
  29.    #:legend-anchor 'top-right
  30.    (list (function g #:color 1 #:label "g(x)")
  31.          (x-ticks (list (tick 0 #t "X₀=0")))
  32.          (lines-interval (list (list 0 0) (list 0 ymax))
  33.                          (list (list xg0 0) (list xg0 ymax))
  34.                          #:line1-style 'transparent
  35.                          #:line2-color 1 #:line2-style 'long-dash
  36.                          #:color 1 #:style 'fdiagonal-hatch #:alpha 1)
  37.          (for/list ([X Xs]
  38.                     [X2 (rest Xs)]
  39.                     [t (in-naturals 1)]
  40.                     [t-1_idx '(      )]
  41.                     [t_idx '(      )])
  42.            (define gX2 (g X2))
  43.            (define X2+δ (+ X2 (/ (+ t 1.)) #;(* .4 (- X2 X))))
  44.            (list
  45.             (function (λ (x) (- x X))
  46.                       #:color "black"
  47.                       X X2+δ)
  48.             (vrule X2 0 gX2 #:style 'long-dash #:color "black")
  49.             (point-label (list X2 gX2) (format "iso~a" t_idx) #:anchor 'left)
  50.             (x-ticks (list (tick X2 #t (format "X~a" t_idx))))
  51.             (point-label (list X2+δ (- X2+δ X)) (format "y = x - X~a" t-1_idx)
  52.                          #:anchor 'left #:point-size 0)))
  53.          )))

=>