Question

Paragraph Styles Voce Sraut Simpsons 1/3rd rule is an extension of Trapezoidal rule where the integrand is approximated by a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

#include <stdio.h>
#include<math.h>
float func(float x)
{
return x*x*cos(x)+x*x*x*sin(x);
}
  
// Function for approximate integral
float simpsons_(float ll, float ul, int n)
{
// Calculating the value of h
float h = (ul - ll) / n;
  
// Array for storing value of x and f(x)
float x[1000], fx[1000];
int i;
// Calculating values of x and f(x)
for (i = 0; i <= n; i++) {
x[i] = ll + i * h;
fx[i] = func(x[i]);
}
// Calculating result
float res = 0;
for (i = 0; i <= n; i++) {
if (i == 0 || i == n)
res += fx[i];
else if (i % 2 != 0)
res += 4 * fx[i];
else
res += 2 * fx[i];
}
res = res * (h / 3);
return res;
}
  
// Driver program
int main()
{
float lower_limit = 0; // Lower limit
float upper_limit = 7.5; // Upper limit
int n = 100; // Number of interval
printf("Integration is %f\n",simpsons_(lower_limit,upper_limit,n));
return 0;
}

main.c 3 float func(float x) 4-{ 5 return x x*co (x) ** x*si (x); 63 7 8 // Function for approximate integral 9 float simpson

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Paragraph Styles Voce Sraut Simpson's 1/3rd rule is an extension of Trapezoidal rule where the integrand...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT