标签:mes ios turn distance poi ++ space efficient iostream
#include<iostream> #include<cmath> using namespace std; typedef double (*fpoint)(double x); //新定义的函数类型,里边有一个double变量 double fun1(double x){ const int u=0; const int b=1; const double Pi=3.14159; double coefficient=1/(sqrt(2*Pi)*b); double index = -((x-u)*(x-u)/(2*b*b)); return coefficient*exp(index); } double fun2(double x){ return 3*x*x+4*x; } double fun3(double x){ return exp(x); } double fintegration(fpoint f,const long long N=50000,const double minvalue=-1000,const double maxvalue=1000){ double distance=(maxvalue-minvalue)/N; long double sum=0; for(int i=0;i<N;i++){ double length; double x1,x2; x1=minvalue+i*distance; x2=minvalue+(i+1)*distance; length=(f(x1)+f(x2))/2; sum+=length*distance; } return sum; } int main(){ int m,n; double q; cout<<"请输入积分区间: "; cin>>m>>n; cout<<"请输入精度:"; cin>>q; double w = (n-m)/q; cout<<w<<endl; cout<<fintegration(fun3,w,m,n)<<endl; return 0; }
标签:mes ios turn distance poi ++ space efficient iostream
原文地址:https://www.cnblogs.com/ls-pankong/p/12564200.html