CS1302: 2026-01-13
ABOUT SOLVING EQUATIONS ITERATIVELY
Unrelated Quiz Time!
- solutions to quadratic equations
Show Me Some Work You've Done:
- Was the book at the right level?
-
Navigate to rustpad.io/#CS1302
and paste in any code you'd like to show me.
- Did you write some for-loops?
- How might you estimate the value of a definite integral with a for-loop?
A Helpful Hint about Naming Functions
-
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).
-
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
c_temperature_from_f
distance
linear_equation_solution (an iterative solution)
cube_root (iterative solution)
kepler_solution (iterative solution)
e_approximation
pi_approximation (with associated graphics)
Tasks
- Chapter 1 is mostly history. How far did you get? We'll come back later.
-
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.
-
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).
-
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.
-
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?