There is a famous story about a primary school teacher who wanted to occupy his
ID: 3676461 • Letter: T
Question
There is a famous story about a primary school teacher who wanted to occupy his students' time by making the children compute the sum of 1 + 2 + 3 + ... + 100 by hand. As the story goes, the teacher was astounded when one of the children immediately produced the correct answer: 5050. The student, a child prodigy, was Carl Gauss, who grew up to be one of the most famous mathematicians of the eighteenth century. Repeat Gauss's remarkable calculation by writing a program with a loop that will compute and print the above sum. After you have the program working, rewrite it so you can compute 1 + 2 + ... + n where n is any positive integer. The Babylonian Algorithm for Square Root Approximation Perhaps the first algorithm used for approximating the square root of S is known as the "Babylonian method", named after the Babylonians, or "Heron's method", named after the first-century Greek mathematician Heron of Alexandria who gave the first explicit description of the method. It can be derived from (but predates by 16 centuries) Newton's method. The basic idea is that if x is an overestimate to the square root of a non-negative real number S then S/x will be an underestimate and so the average of these two numbers may reasonably be expected to provide a better approximation. More precisely, assuming S is a positive number: Make a guess at the answer (you can pick S/2 as your initial guess). Compute r = S / guess. Set new guess = (guess + r) / 2 Go back to step 2 until the last two guess values are within 1% of each other^1. Write a program that: Inputs the value of S from the user. Uses the Babylonian Algorithm to determine and output the square root of n.Explanation / Answer
14.1 Gaussians sum =n(n+1)/2
int n = 100;
int sum=0;
for(i=0;i<=100;i++)
{
sum=sum+i;
}
system.out.println(sum);
}
////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
int n=100;
sum=0;
sum=n*(n+1)/2;
system.out.println("sum is"+sum);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14.2)
The Baylonian Algorithm for square approximation
Babylonian Square Roots
Step 1: Make a guess.
Step 2: Divide your original number by your guess.
Step 3: Find the average of these numbers.
Step 4: Use this average as your next guess.
REPEAT THE PROCESS THREE TIMES.
For example, find sqrt 5
FIRST PROCESS
Step 1: Guess 2 (because 2*2=4, close to 5)
Step 2: Divide 5 by 2 = 2.5
Step 3: Find average of 2 and 2.5 = 2.25 (because (2+2.5)/2 = 2.25)
Step 4: Next guess is 2.25
SECOND PROCESS
Step 1: Guess 2.25
Step 2: Divide 5 by 2.25 = 2.22222222 (go 8 decimal places for accuracy)
Step 3: Find average of 2.25 and 2.22222222 = 2.23611111
Step 4: Next guess is 2.23611111
THIRD PROCESS
Step 1: Guess 2.236111111
Step 2: Divide 5 by 2.23611111 = 2.2360248
Step 3: Find average of 2.23611111 and 2.2360248 = 2.2360679
Step 4: FINAL guess is 2.236067
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.