Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a c++ program to solve the integral of a function using Simpsons rule. Th

ID: 3832552 • Letter: C

Question

create a c++ program to solve the integral of a function using Simpsons rule. The upper and lower limits are positive and the value of n must be even. Need to be able to pass between all functions using pointers. The user will be requested to select which function to solve from, either 1/(1+x^2) or e^x^2. The "main" function requests the user to select one of the mathematical functions that they would like to solve. The main function will also request the upper and lower limits along with the value of n. Make a separate function that will calculate (delta x)/3 . Make another function that calculates the series in Simpsons rule. (f0 + 4f1 .... 4fn-1+ fn). There must also be a function that completes the overall calculation and prints out the solution. It should also print which function was solved and the upper and lower limits along with the value of n. Accurate to three decimal places.

Explanation / Answer


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>
using namespace std;
float y(float x)
{
return 1/(1+x*x);
}
int main()
{
int i,in;
float lw, up,x,sub;
cout<<" Enter Lower Limit:"<<endl;
cin>>lw;
cout<<" Enter Upper Limit:"<<endl;
cin>>up;
cout<<" Enter Sub Interval:"<<endl;
cin>>in;
x = (up - lw)/in;
sub = y(lw)+y(up)+4*y(lw+x);
for(i=3;i<=in-1;i+=2)
{
//sub+=(funct(lw)+4*funct(lw+in)+funct(lw+2*in));
sub += 4*y(lw+i*x) + 2*y(lw+(i-1)*x);
}
cout<<" Integral value is:";
std::cout << std::setprecision(3);
cout<<(x/3)*sub;
return 0;
}

OUTPUT

Enter Lower Limit: 0
Enter Upper Limit: 1
Enter Sub Interval: 5
Integral value is:0.667