Question
Please Help I wrote a code fot the trapezoid rule but im not sure its right. PLEASE edit the code and help me with the
Please HelpI wrote a code fot the trapezoid rule but im not sure its right. PLEASE edit the code and help me with the simpsons rule.
/* Integration using Trapezoidal Rule */
#include
#include
#define PI 3.14159265
double f(double x);
double trapz(int n, double a, double b);
int main(){
double x0 = 10, xn = 20;
int n = 100;
printf("For n = %d, the integral is %f ", n, trapz(n, x0, xn));
return 0;}
double f(double x){
double y;y = 2*x+3;
return y;}
double trapz(int n, double a, double b){
int i;
double dx, x, sum;dx = (b -a) / n;
sum = f(a) + f(b);
for (i = 1; i
x = a + dx * i;
sum += 2 * f(x);}
sum *= dx/2;
return sum;}
Problem 8: Using Simpson's rule and trapezoidal rule, estimate J 2x +3 dx using 10, 20 and 30 intervals. 10Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started