Skip to content

Help with Riemann sum graph #392

Closed Answered by ThatOneCalculator
ThatOneCalculator asked this question in Q&A
Discussion options

You must be logged in to vote

Styled it a bit nicer

#align(center)[#canvas(length: 0.4in, {
  // Function
  let f = x => 16 - x * x

  // Plot
  plot.plot(size: (6, 6),
    x-grid: true,
    y-grid: true,
    axis-style: "school-book",
    x-tick-step: 1,
    y-tick-step: 4,
    padding: 10pt,
    {
      plot.add(
        domain: (0, 6),
        x => f(x))
    }
  )

  // Left-hand Riemann sum
  let barColor = color.green
  let fixedOffset = 10/3
  for i in (0, 1, 2, 3, 4, 5) {
    let height = f(i)
    if (f(i) < 0) {
      barColor = color.red
    }
    draw.fill(rgb(barColor.lighten(70%).darken(8%).to-hex() + "66"))
    draw.stroke(barColor.darken(30%))
    draw.rect(
      (i, fixedOffset),
      (i + 1, (height…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ThatOneCalculator
Comment options

Answer selected by johannes-wolf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant