The four numerical integration methods are the Mid-point rule, the Trapezoidal rule, the Simpson rule and the Monte Carlo method. The number of operations used should be reduced as much as possible to...

1 answer below »
Code a C or C++ program to implement sqrt(x) using the power series expansion method.
I have also attached the ppt for reference


The four numerical integration methods are the Mid-point rule, the Trapezoidal rule, the Simpson rule and the Monte Carlo method. The number of operations used should be reduced as much as possible to produce accuracy. Sample Output: ( the output should be similar to this) Enter a number (0 to exit): 3 x=0.750000, n=12 mysqrt(3.000000): 1.7320508086 Lib. sqrt(3.000000): 1.7320508076 Enter a number (0 to exit): 0.1 x=0.400000, n=23 mysqrt(0.100000): 0.3162277896 Lib. sqrt(0.100000): 0.3162277660 pi The value of pi using Trapezoidal method is: 3.14157200, The number of intervals used is 89. The value of pi using Simson's method is: 3.14159226, The value of pi using Midpoint method is: 3.14160228, The value of pi using Monte Carlo method with 100000 random points is: 3.14076000, Programming project (Part of your final) • Use the power series expansion method to implement sqrt(x). • Use the four numerical integration method to compute 1+x2π =∫ 0 1 4 dx Programmi ng project (Part of your final) •Use the power series expansion method to im plement sqrt(x). •Use the four numerical integration method to compute 1+x 2 π = ∫ 0 1 4 dx Programming project conti. Notes: 1. You can only use float variables to compute pi. 2. Use the Trapezoidal method to find the maximum number of intervals and then apply that number of intervals on the mid-point and Simpson’s methods. 3. Your sqrt function should work for any input number. 4. Demo your sqrt function with some very good and some not very good input numbers. 5. Your programs should produce outputs similar to the instructor’s sample programs. 6. The accuracies of your programs should be close to the instructor’s sample programs. 7. Email the instructor softcopies of your programs. 8. Turn in hardcopies of your source code and sample outputs. Programmi ng projectconti. Notes: 1.You can only use floatvariables to compute pi. 2.Use the Trapezoidal method to find the maximum number of intervals and then apply that number of intervals on the mid-point and Simpson’s methods. 3.Your sqrtfunction should work for any input number. 4.Demo your sqrtfunction with some very good and some not very good input numbers. 5.Your programs should produce outputs similar to the instructor’s sample programs. 6.The accuracies of your programs should be close to the instructor’s sample programs. 7.Email the instructor softcopies of your programs. 8.Turn in hardcopies of your source code and sample outputs. Numerical algorithms Numerical algorithms Algorithms for solving numerical  problems in  mathematics,  engineering,  and science, e.g. 1. Roots of equations. 2. Evaluation of polynomials. 3. Evaluation of mathematical functions. 4. Numerical integrations. etc. Major issues 1. Speed 2. Accuracy: absolute & relative errors. 3. Source of errors: rounding and truncation. How to make a numerical program faster and more accurate? Reduce the number of operations. Not all real numbers can be represented exactly on a digital computer. for (x=0.0; x!=1.0; x+=0.1) { … } Roots of equations Newton's method. Interpolation. Other iterative procedures, e.g. interval halving. Newton's method The first-order Taylor expansion of the equation f(x)=0 is f(x0)+(x-x0)f’(x0) = 0  An estimate of the root, x1, can be found from values of the function and its derivative: x1= x0 – f(x0)/f’(x0) The formula can then be used iteratively to obtain improving estimates of the root: xn+1 = xn– f(xn)/f’(xn) Newton's method conti xn+1 = xn– f(xn)/f’(xn) Xn+2 Evaluation of polynomials To evaluate p(x) = 3x7+10x6+32x5+21x4+8x3+12x2+6x+5 Brute force method p(x) = 3*x*x*x*x*x*x*x + 10*x*x*x*x*x*x + 32*x*x*x*x*x + 21*x*x*x*x + 8*x*x*x + 12*x*x + 6*x + 5 Horner’s method p(x) = ((((((3*x+10)*x+32)*x+21)*x+8)*x+12)*x+6)*x+5 Evaluation of mathematical functions Use power series expansion (slow) sin x = x - x3/3! + x5/5! - x7/7! + ... 2. Polynomial approximation Numerical integrations Mid-point rule Trapezoidal rule Simpson rule Monte Carlo method Etc. Mid-point rule The simplest numerical integration method. Approximates the area under the curve by the sum areas of rectangles centered at the midpoint of intervals. Trapezoidal rule Approximates the area under the curve by the sum of areas of trapezoids. Simpson rule Approximates the area under the curve by the sum of areas under quadratic interpolations of intervals. Simpson rule is popular because of high accuracy compared to the trapezoidal rule. Monte Carlo Method In order to compute the area of a complicated domain D, Monte Carlo method picks random points over some simple domain D’ which is a superset of D, checks whether each point is within D, and estimates the area of D as the area of D’ multiplied by the fraction of points falling within D. Programming project (Part of your final) Use the power series expansion method to implement sqrt(x). Use the four numerical integration method to compute 1+x2 π = ∫ 0 1 4 dx 14 Programming project conti. Notes: You can only use float variables to compute pi. Use the Trapezoidal method to find the maximum number of intervals and then apply that number of intervals on the mid-point and Simpson’s methods. Your sqrt function should work for any input number. Demo your sqrt function with some very good and some not very good input numbers. Your programs should produce outputs similar to the instructor’s sample programs. The accuracies of your programs should be close to the instructor’s sample programs. Email the instructor softcopies of your programs. Turn in hardcopies of your source code and sample outputs.
Answered Same DayNov 05, 2021

Answer To: The four numerical integration methods are the Mid-point rule, the Trapezoidal rule, the Simpson...

Arun Shankar answered on Nov 15 2021
137 Votes
Numerical methods/program_01.c
#include
using namespace std;
float f(float x)
{
re
turn 4.0/(1.0+(x*x));
}
int main()
{
// Trapezoidal rule
int n = 10000; // number of divisions
float h = (1.0-0.0)/(float)n;

float sum = 0;
for(int i=1;i {
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here