Arithmetic, Functions, and Animations

Part A. Racket Math

For each math expression below, translate it to Racket.

Example:

Expression: \(3 + 2\cdot 5^{2}\)
With Parentheses: \((3 + (2\cdot (5^{2})))\)
In Racket: (+ 3 (* 2 (expt 5 2)))
Test Case: (check-expect (+ 3 (* 2 (expt 5 2))) 53)

You just need to write the Test Case line, but make sure it’s right!

  1. \(3\cdot 2^3-7\)
  2. \(5^2\cdot 3 - 5\cdot 10\)
  3. \(10\div 2\cdot 4 + 6\)
  4. \((4 + 5) - (3\cdot 7) + 2\)
  5. \((3 + 2) \cdot 7 - (15 \div 3) + 6^{1 + 1}\)
Part B. Functions

For each function defined below, create a T-chart for the domain values -2, -1, 0, 1, and 2. (You can put the function and chart in a comment between #| and |#.) Then write the function and five test cases to make sure you translated it correctly.

For example, if the problem were \(f(x) = 3x^2 - 1\), you would write:

#|
f(x) = 3x^2 - 1
 x  | f(x)
----+------
 -2 | 11
 -1 | 2
 0  | -1
 1  | 2
 2  | 11
|#

(define (f x)
  (- (* 3 (expt x 2)) 1))

(check-expect (f -2) 11)
(check-expect (f -1) 2)
(check-expect (f 0) -1)
(check-expect (f 1) 2)
(check-expect (f 2) 11)
  1. \(g(x) = 2x - 4\)
  2. \(d(x) = x^2\)
  3. \(s(k) = k^2 - k + 3\)
  4. \(h(z) = 2z^3 - z^2 + z - 4\)
  5. \(p(n) = \frac{n(n + 1)}{2}\)
Part C. Animations

Here’s the starter code for animating a circle.

(define (circle-pic t)
  (place-image (circle 20 "solid" "yellow")
               t 100
               (empty-scene 200 200)))

(animate circle-pic)

This makes a yellow circle move from left to right in the middle of a 200 pixel by 200 pixel scene. For each description below, change the function so that the animation changes as described.

You can just name each function with its number: circle-pic-1, circle-pic-2, etc. Don’t forget to add the right number in the animate function or nothing will change.

  1. Change the color of the circle.
  2. Make the circle have a radius of 50 instead of 20.
  3. Make the circle go across the middle of a 500x500 pixel scene.
  4. Make the circle go down the middle of the scene.
  5. Make the circle start at the top right and go down to the bottom left.
  6. Change the animation in some way that seems cool to you.