CS1302: 2026-01-13
ABOUT SOLVING EQUATIONS ITERATIVELY

Unrelated Quiz Time!

  1. solutions to quadratic equations

Show Me Some Work You've Done:

  1. Was the book at the right level?
  2. Navigate to rustpad.io/#CS1302 and paste in any code you'd like to show me.
  3. Did you write some for-loops?
  4. How might you estimate the value of a definite integral with a for-loop?

A Helpful Hint about Naming Functions

  1. A void function does work but does not calculate a single value to send back to the caller. For the name of a void function, use a verb phrase that describes its work (e.g. draw_star).
  2. A non-void function may do some work, but its primary purpose is to computer a single value that can be sent back to the caller. For the name of a non-void function, use a noun phrase that describes the value that it returns to the caller (e.g., cube_root).

I'll Show You Some Work I've Done: stars.cpp

Then we'll look at functions that calculate simple things and provide iterative solutions to certain equations: solvers.cpp

  1. c_temperature_from_f
  2. distance
  3. linear_equation_solution (an iterative solution)
  4. cube_root (iterative solution)
  5. kepler_solution (iterative solution)
  6. e_approximation
  7. pi_approximation (with associated graphics)

Tasks

  1. Chapter 1 is mostly history. How far did you get? We'll come back later.
  2. The most relevant sections right now are Sectins 3.2 to 3.6. See if you can finish those by Thursday. If you like, you may turn back to Chapter 2 or forward to chapters 4 and 5 to read topics that seem interesting.
  3. Today we looked at the implementation some of the functions in solvers.cpp. I'll send you the code that we looked at. Continue discussing those among yourselves. Also complete any of the functions that we did finish, especially the solution to Kepler's equation (see below).
  4. Write the kepler_solution function to solve for x in:
    x = m + e*sin(x)
    Test the function in a small standalong (no graphics) progam where the user is prompted to enter m and e. Use 1.0 as the initial guess, use a value of EPSILON = 0.0001 to stop the iteration, and limit the total number of iterations to 100,000. Run some tests based on the graph in the Wikipedia article on the equation. Did the iteration always converge for your test input? What happens if you change the initial guess? Does it still seem to always converge? Whenever it does converge, substitute the found value of x back into the equation to verify correctness.
  5. That equation is called Kepler's equation for for orbital motion. What does Wikipedia or elsewhere say about this equation? What does it suggest as a possible graphics programming assignment?