Quadratic Plotter

Quadratic Plotter preview image

1 collaborator

Default-person Mighty Chen (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.0 • Viewed 161 times • Downloaded 31 times • Run 0 times
Download the 'Quadratic Plotter' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own [off-grid?]

to setup
  clear-all
  ask patches [
    set pcolor white
  ]
  draw-grid
end 

to go
  create-turtles 1 [
    ;; init turtle at leftmost point of the equation
    setxy min-pxcor plot-fn-safe min-pxcor
    set color red
    set pen-size 1.25
    set size 0.5
    set shape "circle"
    pen-down

    while [xcor < max-pxcor] [
      let next-point plot-fn-safe xcor + 0.1
      ifelse off-grid? [
        pen-up
        set xcor xcor + 0.1
        pen-down
      ] [
        setxy xcor + 0.1 next-point
      ]
    ]
    die
  ]
end 

to draw-grid
  create-turtles 1 [
    set size 0.75

    ;; draw grid lines
    setxy min-pxcor min-pycor
    facexy xcor max-pycor
    set color gray
    pen-down

    repeat max-pxcor * 2 + 1 [
      fd max-pycor * 2
      bk max-pycor * 2
      rt 90
      fd 1
      lt 90
    ]

    repeat max-pycor * 2 + 1 [
      fd 1
      lt 90
      fd max-pxcor * 2
      bk max-pxcor * 2
      rt 90
    ]

    pen-up
    set color black
    set pen-size 2

    setxy max-pxcor 0
    pen-down
    setxy min-pxcor 0
    pen-up
    setxy 0 max-pycor
    pen-down
    setxy 0 min-pycor
    die
  ]
end 

to-report solve-fn [x]
  report a * x * x + b * x + c
end 

to-report y-is-in-patches? [y]
  if y >= max-pycor or y <= min-pycor [report false]
  report true
end 

to-report plot-fn-safe [x]
  let y solve-fn x
  if y > max-pycor [setxy x max-pycor set off-grid? true report max-pycor]
  if y < min-pycor [setxy x min-pycor set off-grid? true report min-pycor]

  set off-grid? false
  report y
end 

to-report show-quadratic
  report (word pretty-a a pretty-b b pretty-c c)
end 

to-report pretty-a [n]
  if n = 0 [report ""]
  if n = 1 [report (word "" "x^2")]
  if n = -1 [report (word "-" "x^2")]
  if n < 0 [report (word "-" abs n "x^2")]
  if n > 0 [report (word abs n "x^2")]
end 

to-report pretty-b [n]
  if n = 0 [report ""]
  if n = 1 [report (word " + " "x")]
  if n = -1 [report (word " - " "x")]
  if n < 0 [report (word " - " abs n "x")]
  if n > 0 [report (word " + " abs n "x")]
end 

to-report pretty-c [n]
  if n = 0 [report ""]
  if n = 1 [report (word " + 1")]
  if n = -1 [report (word " - 1")]
  if n < 0 [report (word " - " abs n )]
  if n > 0 [report (word " + " abs n )]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Mighty Chen over 5 years ago removed animation Download this version
Mighty Chen over 5 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Quadratic Plotter.png preview Preview for 'Quadratic Plotter' over 5 years ago, by Mighty Chen Download

This model does not have any ancestors.

This model does not have any descendants.