#include <stdioh>
#include <stdlibh>
#include <mathh>
float fx(float x){
return (exp(30x)+pow(x,7));
}
float tixing(float(fun)(float x),float a,float b,int n)
{
float s,h,y;
int i;
s=(fun(a)+fun(b))/2;
h=(b-a)/n;
for(i=1;i<n;i++)
s=s+fun(a+ih);
y=sh;
return y;
}
float juxing(float(fun)(float x),float a,float b,int n){
double h;
double fx;
double x;
int i;
double sum=0;
h=fabs(a-b)/100;
x=a;
for(i=0;i<100;i++)
{
fx=fun(x+ih+h/2);
sum=sum+fx;
}
return sumh;
}
float fsimp(float(fun)(float x),float a,float b,int eps)
{
int n,k;
double h,t1,t2,s1,s2,ep,p,x;
n=1; h=b-a;
t1=h(fun(a)+fun(b))/20;
s1=t1;
ep=eps+10;
while (ep>=eps)
{
p=00;
for (k=0;k<=n-1;k++)
{
x=a+(k+05)h;
p=p+fun(x);
}
t2=(t1+hp)/20;
s2=(40t2-t1)/30;
ep=fabs(s2-s1);
t1=t2; s1=s2; n=n+n; h=h/20;
}
return(s2);
}
void menu(){
system("cls");
printf("1梯形法\n2矩形法\n3辛普森法\n4退出\n");
}
int main()
{
int c=0;
menu();
while(1){
scanf("%d",&c);
switch(c){
case 1:printf("梯形法:%f\n",tixing(fx,1,3,1000));
break;
case 2:printf("矩形法:%f\n",juxing(fx,1,3,1000));
break;
case 3:printf("辛普森法:%f\n",fsimp(fx,1,3,1000));
break;
case 4:return 0;
}
}
}
dx=01;x=0:dx:4;y=xsin(x);s=cumtrapz(y)dx; %梯形法求累计积分
plot(x,y,x,s)
计算xsin(x)在[0,4]的定积分
以上就是关于分别采用梯形法、矩形法和辛普森法计算函数f(x)=e^x在区[-1,1]上的定积分全部的内容,包括:分别采用梯形法、矩形法和辛普森法计算函数f(x)=e^x在区[-1,1]上的定积分、用matlab编写程序求f(x)在[a,b]的定积分,用梯形法写出程序!、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)