单复变单值、多值解析函数的程序计算;c++复数模板类(2012-12-06 20:25:36)


#include<iostream>
#include<complex>
#include<limits>
//using namespace std;
typedef double real;
typedef std::complex<real> complex;
#define M_PI 3.14159265358979323846
//加减乘除,阶乘
class CMath
{
public:
 static int Add(int nOp1,int nOp2);
 static int Subtract(int nOp1,int nOp2);
 static int Multiply(int nOp1,int nOp2);
 static int Divide(int nOp1,int nOp2);
 static int Factorial(int nOp);
};
int CMath::Add(int nOp1, int nOp2)
{
 return nOp1+nOp2;
}
int CMath::Subtract(int nOp1, int nOp2)
{
 return nOp1-nOp2;
}
int CMath::Multiply(int nOp1, int nOp2)
{
 return nOp1*nOp2;
}
int CMath::Divide(int nOp1, int nOp2)
{
 return nOp1/nOp2;
}
int CMath::Factorial(int nOp)
{
 if(nOp<=1)
  return 1;
 return nOp*Factorial(nOp-1);
}
//算术几何平均
namespace detail{
 complex agm(const complex& a0,const complex& b0,real prec,unsigned m);
}
//算术几何平均
namespace detail{
 complex agm(const complex& a0,const complex& b0,real prec,unsigned m)
 {
  complex a=a0;
  complex b=b0;
  complex t;
  for(unsigned n=0;std::abs(0.5*(a-b))>prec && n<m;++n)
  {
   t=0.5*(a+b);
   b=std::sqrt(a*b);
   a=t;
  }
  return a;
 }
}
//勒让德第一类完全椭圆积分
namespace detail{
 complex K(const complex& k,real e,unsigned m);
 complex K(const complex& z)
 {
  return K(z,std::abs(z)*1e-15,500);
 }
}
//勒让德第一类完全椭圆积分
namespace detail{
 complex K(const complex& k,real e,unsigned m)
 {
  complex a=detail::agm(1.0,std::sqrt(1.0-k*k),e,m);
  return M_PI/2.0/a;
 }
}
//雅可比theta函数
namespace detail{
 //computed to pretty high accuracy(a few epsilon)
 complex theta_q(const complex& z,const complex& q);//JT3
 complex theta_1(const complex& z,const complex& q);//JT1
}
//雅可比theta函数
namespace detail{
 complex theta_q(const complex& z,const complex& q)
 {
  if(std::abs(q)>=1)//XXX invalid q
   return 0;
  complex s=0.0;
  complex t=0.0;
  unsigned n=1;
  do
  {
   t=std::pow(q,n*n)*std::cos(static_cast<real>(2*n)*z);
   s+=t;
   ++n;
  }while(n<100 && std::abs(t)>5*std::numeric_limits<real>::epsilon());
  //compute to high precision because we implement other function using that
     return 1.0+2.0*s;
 }
 inline complex theta(const complex& z,const complex& tau)
 {
  return theta_q(z*M_PI,std::exp(M_PI*complex(0,1)*tau));
 }
 complex theta_1(const complex& z,const complex& q)
 {
  if(std::abs(q)>=1)//XXX invalid q
   return 0;
  complex s=0.0;
  complex t=0.0;
  unsigned n=0;
  int f=1;
  do
  {
   t=static_cast<real>(f)*std::pow(q,n*(n+1))*std::sin(static_cast<real>(2*n+1)*z);
   s+=t;
   ++n;
   f*=-1;
  }while(n<100 && std::abs(t)>5*std::numeric_limits<real>::epsilon());
  //compute to high precision because we implement other function using that
  return 2.0*std::pow(q,1.0/4)*s;
 }
 inline complex theta_2(const complex& z,const complex& q)
 {
  return theta_1(z+M_PI/2,q);
 }
 inline complex theta_3(const complex& z,const complex& q)
 {
  return theta_q(z,q);
 }
 inline complex theta_4(const complex& z,const complex& q)
 {
  return theta_3(z,-q);
 }
 //JT3
 inline complex theta_00(const complex& z,const complex& tau)
 {
  return theta(z,tau);
 }
 //JT4
 inline complex theta_01(const complex& z,const complex& tau)
 {
  return theta(z+0.5,tau);
 }
 //JT2
 inline complex theta_10(const complex& z,const complex& tau)
 {
  return std::exp(M_PI*complex(0,1)*(tau/4.0+z))*theta(z+tau/2.0,tau);
 }
 //JT1
 inline complex theta_11(const complex& z,const complex& tau)
 {
  return std::exp(M_PI*complex(0,1)*(tau/4.0+z+0.5))*theta(z+tau/2.0+0.5,tau);
 }
}
namespace detail{
 complex q_from_k(const complex& k);
 complex setup_period(const complex& k,const complex& g);
}
namespace detail{
 complex q_from_k(const complex& k)
 {
  complex kprimes=std::pow(1.0-k*k,1.0/4);
  complex l=0.5*(1.0-kprimes)/(1.0+kprimes);
        complex l4=l*l*l*l;
  complex q=l;
  l*=l4;q+=2.0*l;
  l*=l4;q+=15.0*l;
  l*=l4;q+=150.0*l;
  l*=l4;q+=1707.0*l;
  l*=l4;q+=20910.0*l;
  l*=l4;q+=268616.0*l;
  //XXX manually truncated series representation,error should be less than 10^(-4) for |k|<500
  //std::cout<<268616*std::pow(l,25)<<std::endl;
  return q;
 }
 complex setup_period(const complex& k,const complex& g)
 {
  complex K;//real quarter period
  complex iK_prime;
  complex P;
  K=detail::K(k,1e-25,5000);
  iK_prime=complex(0,1)*detail::K(std::sqrt(1.0-k*k),1e-25,5000);
  if((K/g).imag()>(iK_prime/g).imag())
   P=K;
  else
   P=iK_prime;
  P*=4.0/g;
  return P;
 }
}
namespace detail{
 complex sn(const complex& u,const complex& k);
 complex P(const complex& z, const complex& tau);//实周期为1个单位(w1=1)。计算结果同math::detail::weierstrass_e1
 complex P(const complex& z, const complex& tau, const complex& w1);//实周期为w1个单位(w1=w1)。计算结果同math::weierstrass_p2
 complex e1(const complex& tau);//计算结果同math::detail::weierstrass_e1
 complex e2(const complex& tau);//计算结果同math::detail::weierstrass_e2
 complex e3(const complex& tau);//计算结果约同(≈)math::detail::weierstrass_e3
 //平稳值e_1,e_2,e_3的计算
 inline complex e1(const complex& tau, const complex& w1)
 {
   return e1(tau)/(w1*w1);
 }
 inline complex e2(const complex& tau, const complex& w1)
 {
   return e2(tau)/(w1*w1);
 }
 inline complex e3(const complex& tau, const complex& w1)
 {
   return e3(tau)/(w1*w1);
 }
  //不变量g_2,g_3的计算
  inline complex g2(const complex& tau, const complex& w1)
  {
   complex e1=detail::e1(tau,w1);
   complex e2=detail::e2(tau,w1);
   complex e3=detail::e3(tau,w1);
   complex retg2=complex(2.0,0)*(e1*e1+e2*e2+e3*e3);
   return retg2;
  }
  inline complex g3(const complex& tau, const complex& w1)
  {
   complex e1=detail::e1(tau,w1);
   complex e2=detail::e2(tau,w1);
   complex e3=detail::e3(tau,w1);
   complex retg3=complex(4.0,0)*e1*e2*e3;
   return retg3;
  }
  void Test1()
  {
      std::cout<<"g_2(实周期w_1=8.626062,虚周期w_2=7.416195i)="<<g2(complex(0,7.416195/8.626062),complex(8.626062,0))<<std::endl;
   std::cout<<"g_3(实周期w_1=8.626062,虚周期w_2=7.416195i)="<<g3(complex(0,7.416195/8.626062),complex(8.626062,0))<<std::endl;
  }
  void Test2()
  {
      std::cout<<"sn(u=1.26604138177897;k=0.985171431009416)="<<sn(complex(1.26604138177897,0),complex(0.985171431009416,0))<<std::endl;
  }
}
namespace detail{
 complex sn(const complex& u,const complex& k)
 {
  if(k==0.0)
    return std::sin(u);
  static complex last_k=std::numeric_limits<real>::quiet_NaN();
  static complex f;
  static complex g;
  static complex q;
  static complex P;//period to use for reduction
  if(k!=last_k)
  {
   q=q_from_k(k);
   f=theta_3(0,q)/theta_2(0,q);
   g=theta_3(0,q);
   g*=g;
   P=setup_period(k,g);
   last_k=k;
  }
  complex z=u/g;
  //reduce imaginary part
  int a=static_cast<int>(z.imag()/P.imag());
  z-=static_cast<real>(a)*P;
  return f*theta_1(z,q)/theta_4(z,q);
 }
 complex P(const complex& z, const complex& tau)
 {
    complex z1=complex(M_PI*M_PI,0);
    complex z2=z1*std::pow(theta_00(complex(0,0),tau),2);
    z2=z2*std::pow(theta_10(complex(0,0),tau),2);
    z2=z2*std::pow(theta_01(z,tau),2);
    z2=z2/std::pow(theta_11(z,tau),2);
    complex z3=(z1/complex(3.0,0))*(std::pow(theta_00(complex(0,0),tau),4)+std::pow(theta_10(complex(0,0),tau),4));
    return z2-z3;
 }
 complex P(const complex& z, const complex& tau, const complex& w1)
 {
    complex retP=P(z/w1,tau)/(w1*w1);
    return retP;
 }
 complex e1(const complex& tau)
 {
    complex z1=complex(M_PI*M_PI,0);
    complex e1=(z1/complex(3.0,0))*(std::pow(theta_00(complex(0,0),tau),4)+std::pow(theta_01(complex(0,0),tau),4));
    return e1;
 }
 complex e2(const complex& tau)
 {
    complex z1=complex(M_PI*M_PI,0);
    complex e2=-(z1/complex(3.0,0))*(std::pow(theta_00(complex(0,0),tau),4)+std::pow(theta_10(complex(0,0),tau),4));
    return e2;
 }
 complex e3(const complex& tau)
 {
    complex z1=complex(M_PI*M_PI,0);
    complex e3=(z1/complex(3.0,0))*(std::pow(theta_10(complex(0,0),tau),4)-std::pow(theta_01(complex(0,0),tau),4));
    return e3;
 }
}
void main (void)
 {
   complex x(1,2.1),y;
   std::cout<<"sin(1,2.1)="<<std::sin(x)<<std::endl;
   //复数求模abs(55.6,68.2)=87.992
   std::cout<<"abs(55.6,68.2)="<<std::abs(complex(55.6,68.2))<<std::endl;
   //求实幂指数(16+81i)^3=(-310832,-469233)
   complex cpxZ(16,81);
   complex cpxPow=std::pow(cpxZ,3);
   std::cout<<"(16+81i)^3="<<cpxPow<<std::endl;
   //复数相乘(9+11i)(56+3i)=(471,643)
   complex cpxZ1(9,11),cpxZ2(56,3);
   std::cout<<"(9+11i)(56+3i)="<<cpxZ1*cpxZ2<<std::endl;
   //复数相除(471+643i)/(9+11i)=(56,3)
   cpxZ1=complex(471,643);
   cpxZ2=complex(9,11);
   std::cout<<"(471+643i)/(9+11i)="<<cpxZ1/cpxZ2<<std::endl;
   detail::Test2();
   getchar();
 }
//基于标准复数库的扩展
#include<iostream>
#include<complex>
using namespace std;
const int PI = 3.14159265358979;
//模板函数,复数乘法
template<typename T>
complex<T>& CMul(const complex<T>& cpxZ1,const complex<T>& cpxZ2)
{
 return cpxZ1*cpxZ2;
}
//模板函数,复数的N次幂
template<typename T>
complex<T>& CPowN(const complex<T>& cpxZ1,int N)
{
 return pow(cpxZ1,N);
}
//模板函数,复数除法
template<typename T>
complex<T>& CDiv(const complex<T>& cpxZ1,const complex<T>& cpxZ2)
{
 return cpxZ1/cpxZ2;
}
//模板函数,复数求模
template<typename T>
T& CAbs(const complex<T>& cpxZ)
{
 return abs(cpxZ);
}
//模板函数,复自然对数(多值函数)
template<typename T>
complex<T>& CLn(const complex<T>& cpxZ)
{
 return log(cpxZ);
}
//模板函数,复平方根(多值函数)
template<typename T>
complex<T>& CSqrt(const complex<T>& cpxZ)
{
 return sqrt(cpxZ);
}
//以下三个圆积分在C++标准库中是没有对应的函数的
//模板函数,复反双曲正切(多值函数)
template<typename T>
complex<T>& atanh(const complex<T>& cpxZ)
{
 return CLn(CDiv(1+cpxZ,1-cpxZ))/2;
}
//模板函数,复反双曲正弦(多值函数)
template<typename T>
complex<T>& asinh(const complex<T>& cpxZ)
{
 return CLn(cpxZ+CSqrt(cpxZ*cpxZ+1));
}
//模板函数,复反双曲余弦(多值函数)
template<typename T>
complex<T>& acosh(const complex<T>& cpxZ)
{
 return CLn(cpxZ+CSqrt(cpxZ*cpxZ-1));
}
int main()
{
   complex<double>  xx,yy(1,2.718);
   xx = log(yy/complex<double>(3,0));
   cout << complex<double>(1,0)+xx<< endl;//(0.96476,1.21825)
   cout << "log(3,2)= " << log(complex<double>(3,2))<< endl;//log(3,2)= (1.28247,0.588003)
   complex<double> x(1,2.1), y;
   cout << "sin(1,2.1)= " << sin(x) << endl;
   cout << "cos(1,2.1)= " << cos(x) << endl;
   cout << "exp(1,2.1)= " << exp(x).real() << "+" << exp(x).imag() << "i" << endl;
   cout << "norm(1,2.1)= " << norm(x) << endl;
   cout << "arg(1,2.1)= " << arg(x) << endl;
   cout << "conj(1,2.1)= " << conj(x) << endl;
   cout << "abs(1,2.1)= " << abs(x) << endl;
   y=sin(x)/cos(x);
   cout << "tan(1,2.1)= " << y.real() << "+" << y.imag() << "i" << endl;
   cout << "tan(1,2.1)= " << tan(x) << endl;
   y=x+1.0;
   cout << "\ny = " << y << endl;
   // if (x < y) not allowed - no standard definition
   //   cout << "x less than y" << endl;
   system("pause");
   return 0;
}
#include<complex>//复数类
#include<iostream>
using namespace std;
//自定义复数类,可参看tc3定义的复数类COMPLEX.H
template<typename T>
class Tcomplex
{
private:
 T real;//,image;
 T image;
public:
 Tcomplex(); //缺省构造函数
 Tcomplex(T r, T i); //顺便初始化值的构造函数
 Tcomplex operator +(Tcomplex x); //计算A+B
 Tcomplex operator ++( ); //计算++A
 Tcomplex operator --(); //计算A-
 Tcomplex operator =(T x); //把一个double赋给一个complex时
 void print(); //输出复数
 //friend ostream& operator<<(ostream& os,const Tcomplex& c);//put-to操作符<<,error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Tcomplex<double> const &)" ( ??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Tcomplex@N@@@Z),该符号在函数 _main 中被引用
};
//template<typename T>
//ostream& operator<<(ostream& os,const Tcomplex<T>& c)
//{
// os<<"("<<c.real<<","<<c.image<<")";
// return os;
//}
template<typename T>
Tcomplex<T>::Tcomplex<T>()
{
    real=0.0f;
    image=0.0f;
}
template<typename T>
Tcomplex<T>::Tcomplex<T>(T r, T i)
{
    real=r;
    image=i;
}
template<typename T>
Tcomplex<T> Tcomplex<T>::operator +(Tcomplex<T> x)
{
    Tcomplex<T> c;
    c.real=real+x.real;
    c.image=image+x.image;
    return c;
}
template<typename T>
Tcomplex<T> Tcomplex<T>::operator ++( )
{
 Tcomplex c;
 ++real;
 c.real=real;
 c.image=image;
 return c;
}
template<typename T>
Tcomplex<T> Tcomplex<T>::operator --()
{
 Tcomplex c;
 c.real=real;
 c.image=image;
 real--;
 return c;
}
template<typename T>
Tcomplex<T> Tcomplex<T>::operator =(T x)
{
  real=x;
  return *this; //按照C++的惯例,返回*this,以便实现链式表达式
}
template<typename T>
void Tcomplex<T>::print()
{
    cout<<real<<"+"<<image<<"i"<<endl;
}
/* Define complex double data type */
typedef Tcomplex<double> dcomp;
typedef Tcomplex<double> dcomplex;
static const int g=7;
static const double pi =3.1415926535897932384626433832795028841972 ;
static const double p[g+2] = {0.99999999999980993, 676.5203681218851,-1259.1392167224028, 771.32342877765313, -176.61502916214059,
12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6,1.5056327351493116e-7};
complex<double> gamma( complex<double> z)
{
 if ( real(z)<0.5 ) {
  return pi / (sin(pi*z)*gamma(1.0-z));
 }
 z -= 1.0;
 complex<double> x=p[0];
 for (int i=1; i<g+2; i++) {
  x += p[i]/(z+complex<double>(i,0));
 }
 complex<double>t = z + (g + 0.5);
 return sqrt(2*pi) * pow(t,z+0.5) * exp(-t) * x;
}
//(24,0)
//0.234+2i
//5+7i
//0.234+2i
//(24,0)
//5+5i
//0.234+2i
//6+7i
//0.234+2i
//(24,0)
//5+5i
//4+5i
//5+5i
//0.234+2i
//6+7i
//0.234+2i
int main()
{
 cout << gamma(complex<double>(5,0)) << endl; // should be 4!
 Tcomplex<double> x(1,2.1), y;
 //cout << "x = " << x << endl;
 //y = x + 1.0;
 //cout << "\ny = " << y << endl;
    dcomplex a(1,2);
    dcomplex b(4,5);
    dcomplex e=++b;//先加1后赋值
    e.print();
    dcomplex g=e--;//先赋值后减1
    e.print( );
    g.print( );
    dcomplex c=a+b;
    //dcomplex d=++a;
    //dcomplex e=b--;
    //dcomplex f1=0.234; //这样写现在还不行,因为上面没写相应的拷贝构造函数
    dcomplex f;
    f=a=0.234; //链式表达式
    a.print( );
    c.print( );
    //d.print( );
    //e.print( );
    f.print( );
 system("pause");
 return 0;
}

Calculates the exponential integral Ei(x).
Ei(x)=-∫[-x,∞](e^(-t)/t)dt
Ei(x)=γ+ln(x)+∑[k=1->∞]x^k/(kk!)
E_n(z)=E(n,z)=∫[1,∞](e^(-zt)/t^n)dt;Re(z)>0
E_n(0)=1/(n-1)
lexpp(x)=Ei(-x)=-E_1(x),x>0----20121021确认
E_1(z)=-Ei(-z)+(1/2)(log(-z)-log(-1/z))-log(z)
E_1(z)-E_1(-z)=2Shi(z)+log(-z)-log(z)
Ei(0.00001)=-10.9357,E_1(0.00001)=10.9357,E_1(-0.00001)=10.93570-3.14159i
Ei(0.001)=-6.32954,E_1(0.001)=6.33154,E_1(-0.001)=6.32954-3.14159i
Ei(-0.5)=-0.559774,Ei(0.5)=0.4542199048631735799205=0.454220,E_1(0.5)=0.559774,E_1(-0.5)=-
0.45422-3.14159i
Ei(-1)=-0.219384,Ei(1)=1.895117816355936755467=1.89512,E_1(1)=0.219384,E_1(-1)=1.89512-
3.14159i
Ei(1.5)=3.301285449129797837957=3.30129,E_1(1.5)=0.100020,E_1(-1.5)=-3.30129-3.14159i
Ei(1.8)=4.24986755748793350415=4.24987,E_1(1.8)=0.0647131,E_1(-1.8)=-4.24987-3.14159i
Ei(-2)=-0.0489005,Ei(2)=4.95423,E_1(2)=0.0489005,E_1(-2)=-4.95423-3.14159i
Ei(-3)=-0.0130484,Ei(3)=9.93383,E_1(3)=0.0130484,E_1(-3)=-9.93383-3.14159i
Ei(-4)=-0.00377935,Ei(4)=19.6309,E_1(4)=0.00377935,E_1(-4)=-19.6309-3.1416i
Ei(-5)=-0.00114830,Ei(5)=
40.1853,E_1(5)=0.00114830,E_1(-5)=-40.1853-3.1416i
Ei(1000)=1.97205*10^431,E_1(-1000)=-1.97205*10^431+0.10^426i
x E_1(x)
1 0.219383934
1.02 0.212171083
1.04 0.205238352
1.06 0.198572347
1.08 0.192160479
1.1 0.185990905
1.12 0.180052467
1.14 0.174334651
1.16 0.1688275347
1.18 0.163521748
1.2 0.158408437
1.22 0.153479226
1.24 0.148726188
1.26 0.144141815
1.28 0.139718989
1.3 0.135450958
1.32 0.1313313142
1.34 0.127353972
1.36 0.123513146
1.38 0.119803337
1.4 0.116219313
1.42 0.11275609
1.44 0.1094089233
1.46 0.1061732915
1.48 0.103044882
1.5 0.100019582
1.52 0.097093466
1.54 0.094262786
1.56 0.0915239595
1.58 0.0888735661
1.6 0.086308334
1.62 0.083825133
1.64 0.08142097
1.66 0.0790929778
1.68 0.0768384124
1.7 0.0746546444
1.72 0.0725391544
1.74 0.0704895272
1.76 0.0685034467
1.78 0.0665786914
1.8 0.0647131294
1.82 0.0629047145
1.84 0.0611514822
1.86 0.0594515454
1.88 0.0578030914
1.9 0.0562043782
1.92 0.0546537311
1.94 0.0531495402
1.96 0.0516902569
1.98 0.0502743916
2 0.0489005107
2.02 0.0475672347
2.04 0.0462732354
2.06 0.0450172338
2.08 0.0437979981
2.1 0.0426143415
2.12 0.0414651206
2.14 0.0403492332
2.16 0.0392656169
2.18 0.0382132475
2.2 0.0371911371
2.22 0.0361983327
2.24 0.0352339152
2.26 0.0342969976
2.28 0.0333867237
2.3 0.0325022672
2.32 0.0316428303
2.34 0.03080764268
2.36 0.0299959603
2.38 0.02920706448
2.4 0.0284402609
2.42 0.0276948788
2.44 0.02697026969
2.46 0.026265807
2.48 0.025580885
2.5 0.0249149179
2.52 0.0242673394
2.54 0.02363760171
2.56 0.0230251751
2.58 0.0224295471
2.6 0.0218502218
2.62 0.0212867194
2.64 0.02073857545
2.66 0.0202053406
2.68 0.0196865798
2.7 0.0191818718
2.72 0.0186908088
2.74 0.0182129959
2.76 0.0177480506
2.78 0.01729560237
2.8 0.0168552924
2.82 0.0164267731
2.84 0.0160097076
2.86 0.0156037693
2.88 0.0152086421
2.9 0.01482401923
2.92 0.0144496036
2.94 0.01408510704
2.96 0.0137302503
2.98 0.01338476252
3 0.01304838109
Si(x)=∫[0,x](sint/t)dt
Ci(x)=∫[0,x]((cost-1)/t)dt+lnx+γ
Shi(x)=∫[0,x](sinht/t)dt
Chi(x)=∫[0,x]((cosht-1)/t)dt+lnx+γ
特殊值
Si(0)=0
Si(∞)=pi/2
Si(-∞)=-pi/2
Si(i∞)=i∞
Si(-i∞)=-i∞
Si(z)是定义整个复z-平面上的z的整函数
z->Si(z)::C->C
Si(z)是一个奇函数
Si(-z)=-Si(z)
Si(~z)=~Si(z)
无周期性
Si(x)=x-x^3/18+x^5/600-x^7/35280+x^9/3265920+O[x]^11
Shi(x)=x+x^3/18+x^5/600+x^7/35280+x^9/3265920+O[x]^11
Shi(0)=0
Shi(i∞)=ipi/2
Shi(-z)=-Shi(z)
Shi(iz)=iSi(z)
http://keisan.casio.com/has10/SpecExec.cgi?id=system/2006/1180573422
http://reference.wolfram.com/mathematica/ref/SinhIntegral.html
Calculates the hyperbolic sine integral Shi(x).
Shi(1)=1.05725099232145=1.057250875375728514572
Shi(2)=2.5015677431029=2.501567433354975641473
Shi(2.8)=4.34807680447594=4.34808
Shi(2.5+i)=2.84649+2.22177i
用如下的Integral.vbs计算实正弦积分Si(1)、Si(1000)的值得Si(1)=0.946082974628235=0.946083070367183014941、Si(1000)=1.57023329630831=1.570233121968771218148
http://keisan.casio.com/has10/SpecExec.cgi
http://reference.wolfram.com/mathematica/ref/SinIntegral.html
Si(1.5)=1.32468324780711=1.32468
Si(2)=1.60541283839347=1.6054129768026948485767201481985889408485834223285 
Si(2.5)=1.77851996670859=1.77852
Si(2.8)=1.83209635279175=1.8321
Si(3.5)=1.83312516606361=1.83313
Si(2.5+i)=1.99549+0.222995i
x Si(x) Ci(x)
1 0.94608307 0.33740392
1.1 1.028685219 0.384873377
1.2 1.108047199 0.42045918
1.3 1.183958009 0.44573857
1.4 1.256226733 0.46200659
1.5 1.324683531 0.47035632
1.6 1.389180486 0.471732517
1.7 1.44959229 0.466968364
1.8 1.50581678 0.456811129
1.9 1.557775314 0.44194035
2 1.605412977 0.422980829
2.1 1.648698636 0.400511988
2.2 1.687624827 0.375074599
2.3 1.722207482 0.3471756175
2.4 1.752485501 0.317291617
2.5 1.778520173 0.2858711964
2.6 1.800394451 0.2533366161
2.7 1.818212076 0.2200848786
2.8 1.832096589 0.18648839
2.9 1.842190195 0.152895324
3 1.848652528 0.119629786
3.1 1.851659308 0.086991831
3.2 1.851400897 0.055257412
3.3 1.848080783 0.0246782846
3.4 1.841913983 -0.004518078
3.5 1.833125399 -0.032128549
3.6 1.821948116 -0.057974352
3.7 1.808621681 -0.081901001
3.8 1.793390355 -0.1037781504
3.9 1.77650136 -0.123499349
4 1.758203139 -0.140981698
4.1 1.738743626 -0.1561653918
4.2 1.718368564 -0.169013157
4.3 1.697319851 -0.179509573
4.4 1.675833959 -0.1876602868
4.5 1.654140414 -0.1934911221
4.6 1.632460353 -0.1970470797
4.7 1.611005172 -0.1983912468
4.8 1.589975278 -0.1976036133
4.9 1.569558938 -0.194779806
5 1.549931245 -0.1900297497
5.1 1.531253205 -0.1834762632
5.2 1.513670947 -0.1752536023
5.3 1.497315064 -0.1655059586
5.4 1.482300083 -0.1543859262
5.5 1.468724073 -0.1420529476
5.6 1.456668385 -0.1286717494
5.7 1.446197529 -0.1144107808
5.8 1.437359182 -0.0994406647
5.9 1.430184334 -0.0839326741
6 1.424687551 -0.0680572439
6.1 1.420867373 -0.051982529
6.2 1.418706824 -0.0358730193
6.3 1.418174035 -0.0198882206
6.4 1.419222974 -0.004181411
6.5 1.421794274 0.01110151951
6.6 1.425816149 0.0258231381
6.7 1.431205385 0.03985544
6.8 1.437868416 0.0530807167
6.9 1.445702443 0.065392314
7 1.454596614 0.0766952785
7.1 1.464433244 0.0869068881
7.2 1.475089055 0.0959570643
7.3 1.486436445 0.1037886664
7.4 1.498344753 0.1103576658
7.5 1.510681531 0.1156332032
7.6 1.523313791 0.1195975293
7.7 1.536109238 0.1222458319
7.8 1.548937458 0.1235859542
7.9 1.56167107 0.1236380071
8 1.574186822 0.1224338825
8.1 1.586366622 0.1200166733
8.2 1.598098511 0.1164400055
8.3 1.609277542 0.1117672931
8.4 1.619806597 0.1060709196
8.5 1.6295971 0.0994313586
8.6 1.638569645 0.09193623959
8.7 1.646654531 0.0836793696
8.8 1.653792186 0.0747597196
8.9 1.659933505 0.065280385
9 1.665040076 0.05534753133
9.1 1.669084306 0.0450693325
9.2 1.672049448 0.03455491342
9.3 1.673929528 0.0239133045
9.4 1.674729173 0.01325241867
9.5 1.674463342 0.0026780588
9.6 1.67315698 -0.0077070361
9.7 1.67084457 -0.0178040977
9.8 1.667569617 -0.0275191811
9.9 1.663384057 -0.0367639563
10 1.658347594 -0.045456433
10.1 1.652526986 -0.05352161295
10.2 1.64599527 -0.060892065
10.3 1.638830948 -0.06750841928
10.4 1.631117137 -0.07331977742
10.5 1.622940693 -0.078284036
10.6 1.614391308 -0.08236812222
10.7 1.605560609 -0.0855481414
10.8 1.596541242 -0.087809435
10.9 1.587425976 -0.0891465523
11 1.578306807 -0.0895631355
'HSin(X)=(Exp(X)-Exp(-X))/2
Function func(x)
ret=1
if x<>0 then
ret=(Exp(x)-Exp(-x))/(2*x)
end if
func=ret
End Function
Function Si(x)
ret=1
if x<>0 then
ret=sin(x)/x
end if
func=ret
End Function
Function func(x)
'Calculates the sine integral Si(x).
ret=1
if x<>0 then
ret=sin(x)/x
end if
func=ret
End Function
Function nitrapzd(a, b, eps)
fa = func(a)
fb = func(b)
n = 1
h = b-a
t1 = h * (fa + fb) / 2
p = eps + 1
While (p >= eps)
s = 0
For k=0 To (n-1)
x = a + (k + 0.5) * h
s = s + func(x)
Next
t=(t1 + h * s) / 2
p = Abs(t1 - t)
t1 = t
n = n + n
h = h / 2
Wend
nitrapzd = t
End Function
Sub main()
a = 0
b = 1
eps = 0.000001
v = nitrapzd(a, b, eps)
MsgBox "积分值 =" & v
End Sub
main
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值