Function Graphs

Introduction

With the dia-functions Haskell package one can display SVG diagrams defined in an EDSL.

I added basic support for displaying function graphs; it was surprisingly easy!
The definitions will appear in the hackage page of the Graphics.Diagrams.FunctionGraphs module and you can reach the source code from there.

Here I give some usage examples.

Displaying Real Functions

The main function is displayFun:

displayFun :: (Real b, RealFrac a) => Point -> Point -> (a -> b) -> Diagram

The first two parameters are the left-bottom and right-up corners of the display area.

In the following example you can change the string after Test> and hit enter; the result should change.

Test>

displayFun is applied automagically by the interpreter:

Test>

Function Composition

Examples:

Test>
Test>
Test>

Exercises:

Test>
Test>
Test>
Test>

Functions with Singularities

Test>
Test>
Test>
Test>
Test>

Exercise:

Test>
Test>
Test>

Partial Functions

Test>
Test>

Integer Functions

The displaying function is displayDiscreteFun:

displayDiscreteFun :: (Integral a, Real b) => Point -> Point -> (a -> b) -> Diagram

It is applied by the interpreter automagically!

Test>

Exerciese:

Test>
Test>

Arcs

The displaying function is displayArc:

displayArc ::
(Fractional a, Real b, Real c) =>
Point -> Point -> (Double, Double) -> (a -> (b, c)) -> Diagram

The first two parameters are the left-bottom and right-up corners of the display area.
The third argument is the parameter interval.

Let’s specialize this function:

display :: (Double, Double) -> (Double -> (Double, Double)) -> Diagram
display = displayArc (-16,-10) (16,10)

Example:

Test>

Exercises:

Test>
Test>
Test>
Test>

Other Interesting Examples

Test>

This is done automagically by the interpreter:

Test>
Test>

Back to the main page

Main page