Using Racket to Plot Points

送分小仙女□ 提交于 2020-01-05 05:50:11

问题


After spending some time looking at the documentation, searching the web, and experimenting at the prompt, I haven't succeeded at plotting points using Racket. Could someone post an example of how I'd go about plotting (0 1 2 3 4 5) for my x coordinates and (0 1 4 9 16 25) for the y coordinates. I think 1 good example will clear the problem up.


回答1:


Based on the first example of the doc, and given that the function you want to plot already exists in Racket, it's as simple as:

(require plot)
(plot (function sqr 0 5 #:label "y = x ^ 2"))

If you just want to see the individual points, this is also taken from the docs:

(require plot)
(define xs '(0 1 2 3 4 5))
(define ys '(0 1 4 9 16 25))
(plot (points (map vector xs ys) #:color 'red))

which is equivalent to

(require plot)
(plot (points '(#(0 0) #(1 1) #(2 4) #(3 9) #(4 16) #(5 25)) #:color 'red))



来源:https://stackoverflow.com/questions/26351792/using-racket-to-plot-points

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!