xxxxxxxxxx
28
/*
As part of a modeling problem, I asked a student to
determine t such that 20 * 10^t = 1000. Since this student
does not yet know about logarithms, we're using the bisection
method to automate the trial and error process.
I haven't taught loops or functions yet, so this program
contains only the basic logic. However, it can be used
to get an answer through manual iterations (typing in
new bounds based on the output, running again, and repeating
until the size of the search interval is as small as desired).
*/
let a = 1; //lower bound of search interval
let b = 2; //upper bound of search interval
let m = (a + b) / 2; //midpoint of search interval
let y = 20 * (10 ** m); //y-value at midpoint
if (y < 1000) { //midpoint is too small
a = m; //set lower bound to m
}
else { //midpoint is too big (or it's correct)
b = m; //set upper bound to t
}
console.log(a); //log new lower bound
console.log(b); //log new upper bound
console.log(b - a); // log size of search interval