Write a C program to compute the area under a curve y = f( x ) :
The darkened area under a curve y = f( x ) can be approximated by breaking the interval (x0 , xn) into n equal intervals of size b = (xn- x0) / n and computing the sum of the n areas of the trapezoids with base b. The smaller the interval b the colser the approximation is to the exact area. The formula to compute the sum of the areas of the n trapezoids is A = b/2 ( y0+2y1+2y2+2y3+........2yn-1+yn ) where y0 , y1 , y2 , .... , yn are the values of the function at the points x0 , x1 , x2 , .... , xn.
2
Your program should approximate the area under the curve y = e-x /2 for between 2 and 5 for three differen values of b: 0.0000001, 0.00000001, 0.000000001.(This is equivalent to obtaining an approximation for
∫25 e-x2/2 dx = ?
我有寫出來一些不過有點不明白題目怎麼做?
內容:
#include <stdio.h>
#include <math.h>
#define f( x ) (exp((- x )*( x )/2)) /*被積分函數*/
int main(void)
{
int k;
double a,b,n,h,x,s,sum;
printf("積分區間a,b?");
sacnf("", &a,&b);
n=50; /*a~b間的分割數*/
h=(b-a)/n; /*區間幅度*/
x=a;
s=0;
for(k=1;k<=n-1;k++)
}
{
sum=h*((f( a )+f( b ))/2+s);
printf("/%f\n",b));
printf("1 exp(-x*x/2)=%f\n",sum);
printf("/%f\n",a);
}
-------------------------------------------------------------------------
以上我先用50等分去算它 因為題目看不太懂要分成幾分
還有可以麻煩高手看一下
我上面有哪些問題嗎?




























































































