RacketMathPlottingData-ScienceVisualization

Scientific Computing and Plotting | Schema Programming Part 31

2.71 min read
Md Nasim SheikhMd Nasim Sheikh
Share:

Racket comes with a batteries-included math library and a powerful visualization library plot.

Advertisement

The Math Library

#lang racket
(require math)

; Big Floats (Arbitrary precision)
(bf-precision 128)
(bf "3.141592653589793238462643383279502884")

; Statistics
(mean '(1 2 3 4 5))
(stddev '(1 2 3 4 5))

; Linear Algebra
(matrix [[1 2] [3 4]])

Plotting Data

The plot library is incredibly versatile.

(require plot)

(plot (function sin -5 5))

This opens a window with an interactive sine wave graph!

3D Plotting

(plot3d (surface3d (lambda (x y) (* (sin x) (cos y)))
                   -3 3 -3 3))

Integrating with the Web

You can render plots directly to SVG or PNG to embed in web pages (like this blog!).

(plot-file (function sin -5 5)
           "sine-wave.svg"
           #:kind 'svg)

Advertisement

Summary

Whether you are doing homework statistics or complex simulations, Racket's math and plot collections rival Python's NumPy and Matplotlib for ease of use and visual quality.

Quick Quiz

Which function creates a 2D graph of a mathematical function?

Md Nasim Sheikh
Written by

Md Nasim Sheikh

Software Developer at softexForge

Verified Author150+ Projects
Published:

You May Also Like