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

Solutions to the following problems should consist of program codes, computed re

ID: 3682907 • Letter: S

Question

Solutions to the following problems should consist of program codes, computed results, and short write-ups. In the write-up, discuss the results you have obtained and explain them from the numerical point of view. Use SINGLE PRECISION ONLY. Insert COMMENTS in your programs. Implement composite Trapezoid and Simpson's algorithms, both for equally spaced points. Test both algorithms for two integrals for which you know their exact values. For n = 100, 500, 1000, 2000, 3000, 10000 compute the true errors and next, in the discussion part, compare them to the theoretical errors. (If you use too long interval, you may need to use larger values of n.)

Explanation / Answer

Answer for Question 1:

1. This below C++ code will calculate the Simpson Rule for decimal points.
2. This will ask the upper and lower limits of internal.

#include <iostream>
#include <cmath>
using namespace std;

main(){
int a,b,n;
cout << "Enter upper limit, b:"; cin >> b;
cout << "Enter lower limit, a:"; cin >> a;
cout << " Enter number of Simpson's interval, n (even number only):"; cin >> n;
long double dx, t=0;
dx = (long double)(b-a)/n;
long double fx[n+1];
for(int i=0;i<=n;i++){
if (i == 0){
t = a;
}
else if (i == n){
t = b;
}
else{
t = a+(i*dx);
}
//cout << "t = " << t << endl; // im just curious to know
fx[i] = (1.36*pow(10,-10))*t*t*t*t - (1.23*pow(10,-7))*t*t*t + (4.12*pow(10,-6))*t*t + (3.95*pow(10,-4))*t - (8.58*pow(10,-2));
//fx[i] = (double)1 / (t + 1 );
//cout << "fx[" << i << "] = " << fx[i] << endl; // im just curious to know
}
long double sum = 0, area = 0;
for (int i=0;i<=n;i++){
if (i == 0 || i == n){
sum = sum + fx[i];
}
else if( i%2 == 0){
sum = sum + 2*fx[i];
}
else {
sum = sum + 4*fx[i];
}
}
area = (dx/3)*sum;
cout << "sum = " << sum << endl;
cout << "dx = " << dx << endl;
cout << " The Area is = " << area << endl;
return 0;
}

Trapizodal Rule:

#include<iostream>
#include<cmath>
using namespace std;

float f(float);
int main()
{
   float a,b,h,sum,x,trap;
   int n,i,m;
   cout<<"Enter the limits a & b & number of subintervals n ";
   cin>>a>>b>>n;
   h=(b-a)/n;
   sum=0.0;
   m=n-1;
   for(i=1;i<=m;i++)
   {
       x=a+i*h;
       sum=sum+f(x);
   }
   trap=h*(f(a)+2.0*sum+f(b))/2.0;
   cout<<"Value of integral with "<<n<<endl;
   cout<<"Subintervals="<<trap;
   return 1;
}
float f(float x)
{
   float fun;
   fun=1.0/(1+x);
   return fun;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote