Question: Question 33: Write a C++ program to evaluate the integral of f x = x 2 +1 over 0, 2 with 10 subintervals using the

Question 33: Write a C++ program to evaluate the integral of fx=x2+1 over 0, 2 with 10 subintervals using the Composite Trapezoidal rule. Use a user-defined C++ function for evaluating fx at the different nodes (i.e., for finding the values of f at the different nodes).

#include

Question 33: Write a C++ program to evaluate the integral of fx=x2+1over 0, 2 with 10 subintervals using the Composite Trapezoidal rule. Usea user-defined C++ function for evaluating fx at the different nodes (i.e.,

I want these code to converted in PYTHON. it just a conversion don't make an excuse 1 question policy if u don't want to answer please leave my question will refunded. YES ONLY CONVERSION FROM C++ TO PYTHON.

-- // h = 0.2 #include for(j=1 ; j> XO; cout> xn; cout>n; 1 = f(x)d = [fo + 4(f1 + f2 + ... +fn-1) + 2(f2 +f4 + ... +fn-2) + fr] ---(1) // Processing Section -- // b-a where h = *-* . = f; = f() and xj = Xo+jh for j = 0,1,2,...n 11 n h = (xn - x0); // finding step size fx0 = fval(x0); Here a = Xo = 0, b = X10 = 2. n = 10 = 10 fxn = fval(xn); I = fxO + fxn; XC = x0 ; The relevant function values of f(x) = Vr* +1 are as follows: sum = 0.0 ; 1 2 3 4 6 8 9 2 cin>> xn; cout>n; 0 02 0.6 5 7 10 10 12 1.4 16 18 2.0 1.414 1.562 1.920 1.887 2.059 2.236 1 1,020 1.077 1.166 1.281 // Processing Section -- // Using these values in Eq. (1) gives, // finding step size 1 [3.236 + 4(1.0198 + 1.166 + 1.414 + 1.720 +2.059) + 2(1.077 + 1.281 + 1.562 +1.887)] 0.2 h = (xn - x0) ; fx0 = sqrt(x0*x0 + 1); fxn = sqrt(xn*xn + 1); I = fxO + fxn; XC = x0 ; sum1 = 0.0 ; sum2 = 0.0 ; = (3.236 + 4(7.3788) + 2(5.807)] = 2.598 Question 36: Write a C++ program to evaluate the integral of f(x) = x + 1 over [0, 2] with 12 subintervals using the Composite Simpson's 1/3 rule. #include > #include using namespace std; for(j=1 ; j> XO; cout #include using namespace std; else sum1 = sum1 + fxc; } I = (3.0*h / 8.0) * (I + 2 * sum2 + 3 * sumi); int main() { int n,j; double h , sum1 , sum2, 1, x0, xn, xc, fxo, fxn , fxc; Output Section cout> X0; cout> xn; cout>n; Processing Section // // finding step size Chapter 7 h = (xn - x0); fx0 = sqrt(x0*x0 + 1); fxn = sqrt(xnxn + 1); I = fxO + fxn; XC = 0; sum1 = 0.0 ; sum2 = 0.0 ; Iterative Linear Solvers I for(j=1 ; j for(j=1 ; j> XO; cout> xn; cout>n; 1 = f(x)d = [fo + 4(f1 + f2 + ... +fn-1) + 2(f2 +f4 + ... +fn-2) + fr] ---(1) // Processing Section -- // b-a where h = *-* . = f; = f() and xj = Xo+jh for j = 0,1,2,...n 11 n h = (xn - x0); // finding step size fx0 = fval(x0); Here a = Xo = 0, b = X10 = 2. n = 10 = 10 fxn = fval(xn); I = fxO + fxn; XC = x0 ; The relevant function values of f(x) = Vr* +1 are as follows: sum = 0.0 ; 1 2 3 4 6 8 9 2 cin>> xn; cout>n; 0 02 0.6 5 7 10 10 12 1.4 16 18 2.0 1.414 1.562 1.920 1.887 2.059 2.236 1 1,020 1.077 1.166 1.281 // Processing Section -- // Using these values in Eq. (1) gives, // finding step size 1 [3.236 + 4(1.0198 + 1.166 + 1.414 + 1.720 +2.059) + 2(1.077 + 1.281 + 1.562 +1.887)] 0.2 h = (xn - x0) ; fx0 = sqrt(x0*x0 + 1); fxn = sqrt(xn*xn + 1); I = fxO + fxn; XC = x0 ; sum1 = 0.0 ; sum2 = 0.0 ; = (3.236 + 4(7.3788) + 2(5.807)] = 2.598 Question 36: Write a C++ program to evaluate the integral of f(x) = x + 1 over [0, 2] with 12 subintervals using the Composite Simpson's 1/3 rule. #include > #include using namespace std; for(j=1 ; j> XO; cout #include using namespace std; else sum1 = sum1 + fxc; } I = (3.0*h / 8.0) * (I + 2 * sum2 + 3 * sumi); int main() { int n,j; double h , sum1 , sum2, 1, x0, xn, xc, fxo, fxn , fxc; Output Section cout> X0; cout> xn; cout>n; Processing Section // // finding step size Chapter 7 h = (xn - x0); fx0 = sqrt(x0*x0 + 1); fxn = sqrt(xnxn + 1); I = fxO + fxn; XC = 0; sum1 = 0.0 ; sum2 = 0.0 ; Iterative Linear Solvers I for(j=1 ; j

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets convert the given C code for the Composite Trapezoidal Rule to Python C Code Explanation The C ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!