1.2.18 Variance for accumulator. Validate that the following code, which adds the methods var () and stddev () to Accumulator, computes both the mean and variance of the numbers presented as arguments to addDataValue(): public class Accumulator { private double m; private double s; private int N; public void addDataValue (double x) { N++; 1.0 (N-1) / N * (x m) * (x
1.2.18 Variance for accumulator. Validate that the following code, which adds the methods var () and stddev () to Accumulator, computes both the mean and variance of the numbers presented as arguments to addDataValue(): public class Accumulator { private double m; private double s; private int N; public void addDataValue (double x) { N++; 1.0 (N-1) / N * (x m) * (x
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
Related questions
Question
![1.2.18 Variance for accumulator. Validate that the following code, which adds the
methods var () and stddev () to Accumulator, computes both the mean and variance
of the numbers presented as arguments to addDataValue():
public class Accumulator
{
}
private double m;
private double s;
private int N;
public void addDataValue (double x)
{
}
N++;
S = s + 1.0 * (N-1) / N * (x - m) * (x - m);
m = m + (x - m) / N;
public double mean()
{ return m; }
public double var()
{ return s/(N - 1); }
public double stddev()
{ return Math.sqrt(this.var()); }
This implementation is less susceptible to roundoff error than the straightforward im-
plementation based on saving the sum of the squares of the numbers.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3b4adfb4-f96e-4443-b968-5a2d68a1d277%2F1069b948-67c9-443d-bd82-db0a97b7f954%2Feu6e6dn_processed.png&w=3840&q=75)
Transcribed Image Text:1.2.18 Variance for accumulator. Validate that the following code, which adds the
methods var () and stddev () to Accumulator, computes both the mean and variance
of the numbers presented as arguments to addDataValue():
public class Accumulator
{
}
private double m;
private double s;
private int N;
public void addDataValue (double x)
{
}
N++;
S = s + 1.0 * (N-1) / N * (x - m) * (x - m);
m = m + (x - m) / N;
public double mean()
{ return m; }
public double var()
{ return s/(N - 1); }
public double stddev()
{ return Math.sqrt(this.var()); }
This implementation is less susceptible to roundoff error than the straightforward im-
plementation based on saving the sum of the squares of the numbers.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning