C語言程式問題 有點看不懂題目在問什麼..

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等分去算它 因為題目看不太懂要分成幾分
還有可以麻煩高手看一下
我上面有哪些問題嗎?
嗯....切的越細...累加出來的值越接近積分出來的值嗎??
積分面積








這裡輸入你要的文字
這裡輸入你要的文字
s211322 wrote:
積分面積我是用公式A...(恕刪)

題目有說"b = (xn- x0) / n", 再利用這一句: "for three differen values of b: 0.0000001, 0.00000001, 0.000000001." 就可以推算出n要幾分幾格. 那是簡單代數, 推不出來要打屁股.
公喵不帥, 母喵不愛. 公喵愈壞, 母喵愈愛. 不帥的公喵想要母喵愛, 就只好學壞.
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!