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

Write a computer code to implement the Composite Trapezoidal Rule quadrature T_h

ID: 3405249 • Letter: W

Question

Write a computer code to implement the Composite Trapezoidal Rule quadrature T_h[f] = h(1/2 f(x_0) + f(x_1) + ... + f(x_N-1) + 1/2 f(x_n)), to approximate the definite integral I|f| = integral^b_a f(x) dx, using the equally spaced points x_0 = a, x_1 = x_0 + h, x_2 = x_0 + 2h, ..., x_N= b, where h = (b-a)/N. Make sure that all your codes have a preamble which describes the purpose of the code, all the input variables, the expected output, your name, and the date of the last time you modified the code.

Explanation / Answer

Below is the Code for Trapezoidal rule in C Programming.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10],sum=0,h,temp;
int i,n,j,k=0;
float fact(int);
clrscr();
printf(" how many record you will be enter: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf(" enter the value of x%d: ",i);
scanf("%f",&x[i]);
printf(" enter the value of f(x%d): ",i);
scanf("%f",&y[i]);
}
h=x[1]-x[0];
n=n-1;
for(i=0;i<n;i++)
{
if(k==0)
{
sum = sum + y[i];
k=1;
}
else
sum = sum + 2 * y[i];
}
sum = sum + y[i];
sum = sum * (h/2);
printf(" I = %f ",sum);
getch();
}

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