编译没有错误,要错就是逻辑的错误,希望懂的人指点一下-求不规则图形面积
#include#include
#define maxsize 100
#define eps 0.000001
int main(void)
{
double a,b,t,x[maxsize],step,s0,s1;
double f(double m);
int i,n;
printf("please input a= and b=\n");
scanf("%lf %lf",&a,&b);
n=1;
s0=(f(a)+f(b))*(b-a)/2;
do
{
n++;
step=(b-a)/n;
for(i=0;i<=n;i++)
{
x[i]=a+i*step;
s1=0;
for(i=1;i<=n;i++)
s1+=(f(x[i+1])+f(x[i]))*step/2;
t=s0;
s0=s1;
}
}
while (fabs(s0-t)>eps);
{
printf("s0=%lf\n",s0);
printf("此时步长为:%d",n);
printf("\n");
}
return 0;
}
double f(double m)
{
double y;
y=sqrt(1+pow(m,2));
return y;
}
这是数值分析或者计算方法里面:数值积分与数值微分里面的题目,求积分的近似值 。把不规则的图形换成梯形,然后将梯形分割成若干个小梯形,使小梯形相加,最后近似的求出不规则图形的面积