...∫e*x dx 积分限(0,1) x·e*x-1=0,求x 头一个用梯形法···后一...

发布网友 发布时间:2024-10-24 00:14

我来回答

1个回答

热心网友 时间:2024-10-31 02:49

求积分
#include <cmath>
#include <cstdio>
#define oo 1000000
double e;
double f(double x)
{
return pow(e,x);
}
double get_e()
{
double FM=1;
double sum=1;
for(int i=1;i<=oo;i++){
FM*=i;
sum+=1.0/FM;
}
return sum;
}

double integral(double a,double b)
{

double k=(b-a)/oo,sum=0;
for(int i=1;i<=oo;i++)
sum+=(f(a+k*(i-1))+f(a+k*i))*k/2;
return sum;
}
int main()
{
e=get_e();
printf("%.9f\n",integral(0,1));
}
解方程
#include <cmath>
#include <cstdio>
#define oo 1000000
#define eps 1e-6
double e;
double f(double x)
{
return x*pow(e,x);
}
double get_e()
{
double FM=1;
double sum=1;
for(int i=1;i<=oo;i++){
FM*=i;
sum+=1.0/FM;
}
return sum;
}
double solve()
{
double l=0,h=1,mid;
while(fabs(l-h)>eps){
mid=(l+h)/2;
if(f(mid)<1) l=mid;
else h=mid;
}
return mid;
}
int main()
{
e=get_e();
printf("%.9f\n",solve());
}

热心网友 时间:2024-10-31 02:52

求积分
#include <cmath>
#include <cstdio>
#define oo 1000000
double e;
double f(double x)
{
return pow(e,x);
}
double get_e()
{
double FM=1;
double sum=1;
for(int i=1;i<=oo;i++){
FM*=i;
sum+=1.0/FM;
}
return sum;
}

double integral(double a,double b)
{

double k=(b-a)/oo,sum=0;
for(int i=1;i<=oo;i++)
sum+=(f(a+k*(i-1))+f(a+k*i))*k/2;
return sum;
}
int main()
{
e=get_e();
printf("%.9f\n",integral(0,1));
}
解方程
#include <cmath>
#include <cstdio>
#define oo 1000000
#define eps 1e-6
double e;
double f(double x)
{
return x*pow(e,x);
}
double get_e()
{
double FM=1;
double sum=1;
for(int i=1;i<=oo;i++){
FM*=i;
sum+=1.0/FM;
}
return sum;
}
double solve()
{
double l=0,h=1,mid;
while(fabs(l-h)>eps){
mid=(l+h)/2;
if(f(mid)<1) l=mid;
else h=mid;
}
return mid;
}
int main()
{
e=get_e();
printf("%.9f\n",solve());
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com