I've got to compute some integrals using the trapezoidal rule. the two functions are exp(-x^2) and exp(-x). It seems simple enough, but I am getting the following errors:
*'rdiv_expr' not supported by pp_c_expression# 'trapeze.c: In function 'trapeze':
-called object is not a function
-called object 'h' is not a function
Code:
#include <stdio.h>
#include <math.h>
#define a 0
#define b 1
double sum(double h, int i){
/*calculates the steps taken by each iteration*/
return (a+i*h);
}
double trapeze(int n, double ans[]){
/*the step length for the integral, a constant*/
double h=(b-a)/n;
ans[0]=(h/2)(exp((-a)*a)+exp((-b)*b))+h(sum(h,n-1));
ans[1]=(h/2)(exp((-a))+exp((-b)))+h(sum(h,n-1));
}
main (void){
double ans[2];
int n;
printf("Enter the number of intervals: \n");
scanf("%d", &n);
trapeze(n, ans);
.........
Thank you!