Question: Problem 6 . Gaussian Location Historical background ( not necessary to solve the problem, but interesting ) : Carl Friedrich Gauss was a German mathematician
Problem Gaussian Location
Historical background not necessary to solve the problem, but interesting:
Carl Friedrich Gauss was a German mathematician born in the th century, who is credited for several key ideas in mathematics that you're familiar with. For one, Gaussian elimination also known as row reduction in linear algebra is named after him. He's also credited for being the first person to my error he did so to build a model to predict the locations of planets in the night sky
Perhaps the most famous story involving Gauss is one from when he was just a child. His teacher, supposedly, asked him to add the integers from through expecting it to take him a while. However, within just a few seconds, he gave the answer style algorithmic problem efficiently.
The actual problem:
Here, we'll solve the "missing value problem." Suppose vals is a list of length containing the integers from to inclusive, with no duplicates and in unsorted order, but with exactly value missing. Your job is to write a function that finds the missing integer in vals. For example, if vals the missing integer is
Parts a and c of this problem will require you to write code in this supplementary Jupyter Notebook. The code that you write in that notebook is autograded, both using public test cases that you can see in the notebook and hidden test cases that will only be run after you submit on Gradescope.
To submit your homework, in addition to submitting your answers PDF to the Homework assignment on Gradescope, also submit hwcode.ipynb to the Homework Problems a and c autograder on Gradescope and wait until you see all public test cases pass!
a In the linked supplementary notebook, complete the implementation of the function missingvaluenaive There's nothing you need to include in your answers PDF for this part.
b Your implementation of missingvaluenaive didn't need to be particularly efficient. To make our solution to the missing value problem more efficient, we'll use the fact that the missing value is the difference between the sum we'd expect if none of the values were missing, and the sum of the values we actually have. For example, if vals then so the sum we'd expect is and so the missing value is To find the expected sum, instead of using a forloop or something like sum range n we can turn to Gauss to make things even faster. Let's look at how he quickly derived that dots Your job will then be to generalize what he did to dots and find a formula for the sum of the first positive integers.
Let dots Gauss wrote out in two different ways:
cdots
cdots
Then, he noticed that each vertical pair of terms and and and each summed to By adding the two lines above, he saw:
dots
Since there were terms in each of the original equations for there were terms equal to in the equation above for This let him solve for :
dots
Now, it's your turn. Let dots Find a closedform expression for for any integer and show your work. Your answer will be an arithmetic expression involving ; for example, an incorrect answer in the correct format could be
Hint: This problem may seem daunting at first, but most of the work has already been done for you. What you need to do is repeat Gauss' work, but with an arbitrary integer instead of When you expand twice, the way that Gauss expanded twice, what is the sum of each vertical pair of terms? How many such terms are there? Verify that your answer is correct by testing it out on etc.
c In the linked supplementary notebook, complete the implementation of the function missingvalue fast There's nothing you need to include in your answers PDF for this
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
