1#的积分用Forcal求解:
高斯算法(通常耗时较长):
- mvar:
- f(x1,x2,x3,x4,x5)=sin{x1*exp[x2*sqrt(x3)]}+x4^x5;
- yx(j,x1,x2,x3,x4,x5,y0,y1)=
- {
- which{
- j==0:[y0=0, y1=1],
- j==1:[y0=exp(x1)/2, y1=exp(x1)],
- j==2:[y0=[x1+sin(x2)]/2, y1=x1+sin(x2)],
- j==3:[y0=(x1+x3)/2, y1=x1+x3],
- j==4:[y0=x4, y1=2*x4]
- }
- };
- t0=sys::clock();
- XSLSF::igaus[HFor("f"),HFor("yx"),10,10,10,10,10]; //一般,区间分隔数10,10,10,10,10越大越精确,但耗时越长
- [sys::clock()-t0]/1000;
[color=rgb(51, 102, 153) !important]复制代码
结果:
5.798135338576838
耗时113.875秒
用连分式法混合了IMSL算法(精度取1e-6):
- mvar:
- Fx4x5(x4,x5)=sin{x1*exp[x2*sqrt(x3)]}+x4^x5;
- x4x5(x4,y0,y1)=
- {
- y0=x4,
- y1=2*x4
- };
- Fx2x3(_x2,_x3)= x2=_x2, x3=_x3, XSLSF::pqg2[HFor("Fx4x5"),(x1+x3)/2,(x1+x3),HFor("x4x5"),1e-6];
- Gx2(x2)=[x1+sin(x2)]/2;
- Hx2(x2)=x1+sin(x2);
- Fx1(_x1)= x1=_x1, IMSL::TWODQ[HFor("Fx2x3"),exp(x1)/2,exp(x1),HFor("Gx2"),HFor("Hx2"),0,1e-6,2,0];
- t0=sys::clock();
- IMSL::QDAGS[HFor("Fx1"),0,1,0,1e-6,0];
- [sys::clock()-t0]/1000;
[color=rgb(51, 102, 153) !important]复制代码
结果:
5.798135342841069 |