Programming language C NOT C++ you will create an integral calculator polynomial
ID: 3766352 • Letter: P
Question
Programming language C NOT C++
you will create an integral calculator polynomials of degree zero, one, two three and four.
Degree 0 Function y = z where z is a constant where a,b,c,d,z E R, real numbers You will ask the user for the degree of the polynomial and then the coefficients and the constant values of the polynomial. Then you will ask the user for the beginning and the end of the interval along with the number of steps between the interval to integrate over. To do the actual integration, use the trapezoid rule for numerical integration to compute the integral which is noted below: (f(x1) + 2 * f(xa) + 2 * f(z21+ 2f(2... 2* f(zN-1)+f(xN)) + 2 * f(zN-11+ flex))Explanation / Answer
/* C program to calculate integral polynomial using Trapezoid rule*/
Example program
#include<stdio.h>
#include<math.h>
//Taking a function f(x)
float f(float(x))
{
return (pow(x,3)+pow(x,2)-(4*x)-5);
}
//Taking diffrentiation of f(x) i.e. g(x)
float g(float(x))
{
return (3*pow(x,2)+2*x-4);
}
//Taking double diffrentiation of f(x) i.e. h(x)
float h(float(x))
{
return (6*x+4);
}
void main() //Main Program
{
long double a,b,d,i,n,I=0,J=0,A,K=0,E=0;
printf("Given f(x)= x^3 + 2x^2 - 4x - 5 ");
printf("Enter lower limit ");
scanf("%f",&a);
printf("Enter Upper Limit ");
scanf("%f",&b);
printf("Enter the number of intervals : ");
scanf("%f",&n);
d=(b-a)/n;
//Steps of solving by Trapezoidal Rule
for(i=0;i<=n;i++)
{
I=I+f(a+(i*d));
}
for(i=1;i<n;i++)
{
J=J+f(a+(i*d));
}
A=(d/2)*(I+J);
//Printing the value of Integral
printf("The Value of integral under the enterd limits is : ");
printf("%f",A);
//Finding the mean of intervals
for(i=0;i<=n;i++)
{
K=K+a+(i*d);
}
//Calculating the Total Error
E=-((b-a)*d*d*(h(K/n)/12));
//Printing the Totoal Error
printf("The Total Error is : ");
printf("%f",E);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.