主题:求积分,大家帮忙看看
谁能帮忙编下f(x)exp(-xt)dx在0到无穷大的积分啊,f(x)是复数
其中Ww1c=100*beta,wc=0.1*beta
我编的如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dir.h>
#include <io.h>
#include <math.h>
#include <iostream.h>
#include <bcd.h>
#include <complex.h>
complex i;
#define i complex(0.,1.) //给i赋值
#define h 0.001
#define pi 3.1415926
double beta=1.0;
double wc,w1c;
double t=0.0000001;
complex lags(double t1);
complex lagsf(double x,double t2);
complex lags(double t1)
{
double xx;
static double b[5]={0.26355990, 1.41340290, 3.59642600, 7.08580990, 12.64080000};
static double c[5]={0.6790941054, 1.638487956, 2.769426772, 4.315944000, 7.104896230};
complex g=0.0;
for(int k=0;k<=4;k++)
{
xx=b[k];
g=g+c[k]*lagsf(xx,t1);
}
return g;
}
//-----------------------------------------------------------------------------
complex lagsf(double x,double t2)
{
complex y;
y=pow(i*x*beta*beta*beta,0.5)*(wc-i*x)*exp(-x*t2)/(pow((i*w1c-x)*(wc-i*x)-i*pow(beta*beta*beta*wc,0.5),2.0)+i*beta*beta*beta*x);
return y;
}
// -----------------------------------------------
void main()
{
//参数设置--------------
wc=100.0*beta;
w1c=0.1*beta;
//----------------------
FILE *fp1;//建立个文件夹
if((fp1=fopen("entropy.dat","wt"))==NULL)
{
printf("can not open file\n");
exit(0);
}
for(t=0.0000001;t<=50.0;)
{
complex At; //////////////////
At=exp(i*w1c*t)/pi*lags(t);//调用积分函数
double Pu; // the upper-level population
Pu=norm(At);//对AT求绝对值平方
//entropy------------------------------------------------------------
//-------------------------------------------------------------------
fprintf(fp1,"%e\t%e\n",t,Pu);
t=t+h;
}
}
大家帮忙看看啊,主要是求积分的函数,总得不到想要的结果,谢谢
其中Ww1c=100*beta,wc=0.1*beta
我编的如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dir.h>
#include <io.h>
#include <math.h>
#include <iostream.h>
#include <bcd.h>
#include <complex.h>
complex i;
#define i complex(0.,1.) //给i赋值
#define h 0.001
#define pi 3.1415926
double beta=1.0;
double wc,w1c;
double t=0.0000001;
complex lags(double t1);
complex lagsf(double x,double t2);
complex lags(double t1)
{
double xx;
static double b[5]={0.26355990, 1.41340290, 3.59642600, 7.08580990, 12.64080000};
static double c[5]={0.6790941054, 1.638487956, 2.769426772, 4.315944000, 7.104896230};
complex g=0.0;
for(int k=0;k<=4;k++)
{
xx=b[k];
g=g+c[k]*lagsf(xx,t1);
}
return g;
}
//-----------------------------------------------------------------------------
complex lagsf(double x,double t2)
{
complex y;
y=pow(i*x*beta*beta*beta,0.5)*(wc-i*x)*exp(-x*t2)/(pow((i*w1c-x)*(wc-i*x)-i*pow(beta*beta*beta*wc,0.5),2.0)+i*beta*beta*beta*x);
return y;
}
// -----------------------------------------------
void main()
{
//参数设置--------------
wc=100.0*beta;
w1c=0.1*beta;
//----------------------
FILE *fp1;//建立个文件夹
if((fp1=fopen("entropy.dat","wt"))==NULL)
{
printf("can not open file\n");
exit(0);
}
for(t=0.0000001;t<=50.0;)
{
complex At; //////////////////
At=exp(i*w1c*t)/pi*lags(t);//调用积分函数
double Pu; // the upper-level population
Pu=norm(At);//对AT求绝对值平方
//entropy------------------------------------------------------------
//-------------------------------------------------------------------
fprintf(fp1,"%e\t%e\n",t,Pu);
t=t+h;
}
}
大家帮忙看看啊,主要是求积分的函数,总得不到想要的结果,谢谢