Giter Site home page Giter Site logo

fp2's Introduction

Programmer: Tony Ventura

My Library: Plot

For FP2, I explored the Plot library. Using this library, I was able to plot multiple graphs. The great thing about this library is the examples it gives covers just about any sort of graph you could want to make

By default, all functions plot inside the output box in the Racket GUI. By declaring (plot-new-window? #t), I was able to create new windows for each of my plots

I began by running a simple test case given as one of the first examples in the documentation. This function plots the sine function from -pi to pi, and gives it a label of "y = sin(x)".

(plot (function sin (- pi) pi #:label "y = sin(x)"))

The following graph was the result: alt-text

From there the possibilities are endless with what you can plot. I kept it somewhat simple and tried to plot multiple 2D functions. Using the parameterize function, one is able to add parameters to a plot window. The following code is the parameters I defined before writing the body. plot-title defines a new plot title, plot-x-label defines a new x-axis label, and plot-y-label defines a new y-axis label.

(parameterize ([plot-title "My graph"]
               [plot-x-label "Time Spent looking at it (s)"]
               [plot-y-label "Enjoyment level"])...

After it was time to write the body. I decided to plot eulers exponential function from 0 to 5, (plot (function exp 0 5)), because this was the best choice based on my label names.

The final result produced this as a graph: alt-text

Next I decided to produce a graph with two functions being plotted. The way to achieve this was to create a list with the (axes) proceedure (which returns the renderers for the axes, in order to handle multiple renders), and my two functions that are actually going to be plotted. This list is passed to the plot function, and was successful in creating a graph with both functions. I used the natural log function (with an out of bounds parameter to see how the graph would handle it) and the square function which returns x^2.

(plot (list (axes)
            (function log -1 5 #:color "green" #:label "y = ln(x)")
            (function sqr -5 5 #:color "blue"  #:label "y = x^2")))

This produces the graph below: alt-text

I lastly wanted to change things up and plot a 3d graph. I chose to plot a 3d surface of cosh(x)*sinh(y) (the hyperbolic sine and cosine functions) this becomes bound by -pi and pi on both axes. While complex this sounds, the plot function can easily handle situations like this. The actual graph becomes:

(surface3d (λ (x y) (* (cosh x) (sinh y)))
                     (- pi) pi (- pi) pi #:color "orange" #:style 'bdiagonal-hatch)

As you can see the suface3d proceedure is taking in the function with respect to x and y (cosh(x)*sinh(y)) and gives it the bounds -pi to pi on both the x and y axis. Lastly the color is set to orange and the style is changed to give the graph a little pizazz. This is all passed to (plot3d) to generate a 3d graph. The resulting graph is below: alt-text

fp2's People

Contributors

marksherman avatar tventura1337 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.