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

Solve the computer problem given in your text (Problem 5.C2). Solve only parts (

ID: 3863292 • Letter: S

Question

Solve the computer problem given in your text (Problem 5.C2). Solve only parts (a) and (c). Repeat the same with 40 straight line segments. Comment on the differences between the two results. Approximate the curve shown using 10 straight-line segments, and y then write a computer program that can be used to determine the location of the centroid of the curve. Use this program to determine the location of the centroid when (a) a = 1 in., L. = 11 in., h = 2 in; (b) a = 2 in., L = 17 in., h = 4 in., (c) a = 5 in., L = 12 in., h = 1 in

Explanation / Answer

#include<iostream>
#include<cmath>
using namespace std;
double f(double x) //The function whose definite integral is to be calcuated here
{
double a=1/(1+x*x);
return a;
}
int main()
{
int n,i; //n is for subintervals and i is for loop
double a,b,h,sum=0,integral;
cout<<"Enter the limits of integration ,Initial limit,a="; //get the limits of integration
cin>>a;
cout<<"Final limit, b=";
cin>>b;
cout<<"Enter the no. of subintervals, n="; //get the no. of subintervals
cin>>n;
double x[n+1],y[n+1];
h=(b-a)/n; //get the width of the subintervals
for (i=0;i<=n;i++)
{ //loop to evaluate x0,...xn and y0,...yn
x[i]=a+i*h; //and store them in arrays
y[i]=f(x[i]);
}
for (i=1;i<n;i++) //loop to evaluate h*(y1+...+yn-1)
{
sum=sum+h*y[i];
}
integral=h/2.0*(y[0]+y[n])+sum; //h/2*[y0+yn+2(y1+y2+y3+...yn-1)]
cout<<"The definite integral is "<<integral<<endl;
return 0;
}

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