expint.cpp ( File view )

  • By 2010-08-01
  • View(s):1071
  • Download(s):14
  • Price:$30 
			#include <cmath>
#include <limits>
#include "nr.h"
using namespace std;

DP NR::expint(const int n, const DP x)
{

	const int MAXIT=100;
	const DP EULER=0.577215664901533;
	const DP EPS=numeric_limits<DP>::epsilon();
	const DP BIG=numeric_limits<DP>::max()*EPS;
	int i,ii,nm1;
	DP a,b,c,d,del,fact,h,psi,ans;

	nm1=n-1;
	if (n < 0 || x < 0.0 || (x==0.0 && (n==0 || n==1)))
	nrerror("bad arguments in expint");
	else {

		if (n == 0) ans=exp(-x)/x;
		else {

			if (x == 0.0) ans=1.0/nm1;
			else {

				if (x > 1.0) {

					b=x+n;
					c=BIG;
					d=1.0/b;
					h=d;
					for (i=1;i<=MAXIT;i++) {

						a = -i*(nm1+i);
						b += 2.0;
						d=1.0/(a*d+b);
						c=b+a/c;
						del=c*d;
						h *= del;
						if (fabs(del-1.0) <= EPS) {

							ans=h*exp(-x);
							return ans;
						
}
					
}
					nrerror("continued fraction failed in expint");
				
} else {

					ans = (nm1!=0 ? 1.0/nm1 : -log(x)-EULER);
					fact=1.0;
					for (i=1;i<=MAXIT;i++) {

						fact *= -x/i;
						if (i != nm1) del = -fact/(i-nm1);
						else {

							psi = -EULER;
							for (ii=1;ii<=nm1;ii++) psi += 1.0/ii;
							del=fact*(-log(x)+psi);
						
}
						ans += del;
						if (fabs(del) < fabs(ans)*EPS) return ans;
					
}
					nrerror("series failed in expint");
				
}
			
}
		
}
	
}
	return ans;

}
			
...
Expand> <Close

Want complete source code? Download it here

$30

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
<recipes>0.00 B21-09-04 22:31
addint.cpp207.00 B30-11-02 11:52
airy.cpp879.00 B30-11-02 11:52
amebsa.cpp1.71 kB30-11-02 11:52
amoeba.cpp1.50 kB30-11-02 11:52
amotry.cpp479.00 B30-11-02 11:52
amotsa.cpp707.00 B30-11-02 11:52
anneal.cpp1.63 kB30-11-02 11:52
anorm2.cpp230.00 B30-11-02 11:52
arcmak.cpp696.00 B30-11-02 11:52
arcode.cpp1.92 kB30-11-02 11:52
arcsum.cpp409.00 B30-11-02 11:52
asolve.cpp233.00 B30-11-02 11:52
atimes.cpp207.00 B30-11-02 11:52
avevar.cpp290.00 B30-11-02 11:52
badluk.cpp1.22 kB30-11-02 11:52
balanc.cpp780.00 B30-11-02 11:52
banbks.cpp472.00 B30-11-02 11:52
bandec.cpp844.00 B30-11-02 11:52
banmul.cpp296.00 B30-11-02 11:52
bcucof.cpp1.32 kB30-11-02 11:52
bcuint.cpp679.00 B30-11-02 11:52
beschb.cpp635.00 B30-11-02 11:52
bessi.cpp724.00 B30-11-02 11:52
bessi0.cpp493.00 B30-11-02 11:52
bessi1.cpp537.00 B30-11-02 11:52
bessik.cpp2.52 kB30-11-02 11:52
bessj.cpp1.00 kB30-11-02 11:52
bessj0.cpp739.00 B30-11-02 11:52
bessj1.cpp762.00 B30-11-02 11:52
bessjy.cpp3.25 kB30-11-02 11:52
bessk.cpp278.00 B30-11-02 11:52
bessk0.cpp471.00 B30-11-02 11:52
bessk1.cpp479.00 B30-11-02 11:52
bessy.cpp278.00 B30-11-02 11:52
bessy0.cpp753.00 B30-11-02 11:52
bessy1.cpp811.00 B30-11-02 11:52
beta.cpp149.00 B30-11-02 11:52
betacf.cpp909.00 B30-11-02 11:52
betai.cpp400.00 B30-11-02 11:52
bico.cpp162.00 B30-11-02 11:52
bksub.cpp504.00 B30-11-02 11:52
bnldev.cpp1.02 kB30-11-02 11:52
brent.cpp1.54 kB30-11-02 11:52
broydn.cpp3.22 kB30-11-02 11:52
bsstep.cpp2.75 kB30-11-02 11:52
caldat.cpp682.00 B30-11-02 11:52
chder.cpp284.00 B30-11-02 11:52
chebev.cpp337.00 B30-11-02 11:52
chebft.cpp476.00 B30-11-02 11:52
chebpc.cpp405.00 B30-11-02 11:52
chint.cpp335.00 B30-11-02 11:52
chixy.cpp646.00 B30-11-02 11:52
choldc.cpp389.00 B30-11-02 11:52
cholsl.cpp334.00 B30-11-02 11:52
chsone.cpp385.00 B30-11-02 11:52
chstwo.cpp397.00 B30-11-02 11:52
cisi.cpp1.44 kB30-11-02 11:52
cntab1.cpp902.00 B30-11-02 11:52
cntab2.cpp943.00 B30-11-02 11:52
convlv.cpp1.16 kB30-11-02 11:52
copy.cpp174.00 B30-11-02 11:52
correl.cpp489.00 B30-11-02 11:52
cosft1.cpp696.00 B30-11-02 11:52
cosft2.cpp1.31 kB30-11-02 11:52
covsrt.cpp383.00 B30-11-02 11:52
crank.cpp395.00 B30-11-02 11:52
cyclic.cpp577.00 B30-11-02 11:52
daub4.cpp819.00 B30-11-02 11:52
dawson.cpp718.00 B30-11-02 11:52
dbrent.cpp2.02 kB30-11-02 11:52
ddpoly.cpp403.00 B30-11-02 11:52
decchk.cpp789.00 B30-11-02 11:52
df1dim.cpp406.00 B30-11-02 11:52
dfpmin.cpp1.91 kB30-11-02 11:52
dfridr.cpp842.00 B30-11-02 11:52
dftcor.cpp1.96 kB30-11-02 11:52
dftint.cpp1.26 kB30-11-02 11:52
difeq.cpp1.77 kB30-11-02 11:52
dlinmin.cpp720.00 B30-11-02 11:52
eclass.cpp387.00 B30-11-02 11:52
eclazz.cpp321.00 B30-11-02 11:52
ei.cpp866.00 B30-11-02 11:52
eigsrt.cpp335.00 B30-11-02 11:52
elle.cpp237.00 B30-11-02 11:52
ellf.cpp185.00 B30-11-02 11:52
ellpi.cpp273.00 B30-11-02 11:52
elmhes.cpp620.00 B30-11-02 11:52
erfcc.cpp352.00 B30-11-02 11:52
erff.cpp103.00 B30-11-02 11:52
erffc.cpp107.00 B30-11-02 11:52
eulsum.cpp606.00 B30-11-02 11:52
evlmem.cpp429.00 B30-11-02 11:52
expdev.cpp169.00 B30-11-02 11:52
expint.cpp1.30 kB30-11-02 11:52
f1dim.cpp281.00 B30-11-02 11:52
factln.cpp263.00 B30-11-02 11:52
factrl.cpp343.00 B30-11-02 11:52
fasper.cpp1.66 kB30-11-02 11:52
fdjac.cpp447.00 B30-11-02 11:52
fgauss.cpp373.00 B30-11-02 11:52
fit.cpp1.08 kB30-11-02 11:52
fitexy.cpp1.81 kB30-11-02 11:52
fixrts.cpp554.00 B30-11-02 11:52
fleg.cpp286.00 B30-11-02 11:52
flmoon.cpp703.00 B30-11-02 11:52
fmin.cpp277.00 B30-11-02 11:52
four1.cpp943.00 B30-11-02 11:52
fourew.cpp316.00 B30-11-02 11:52
fourfs.cpp4.31 kB30-11-02 11:52
fourn.cpp1.46 kB30-11-02 11:52
fpoly.cpp144.00 B30-11-02 11:52
fred2.cpp398.00 B30-11-02 11:52
fredex.cpp561.00 B30-11-02 11:52
fredin.cpp271.00 B30-11-02 11:52
frenel.cpp1.46 kB30-11-02 11:52
frprmn.cpp874.00 B30-11-02 11:52
ftest.cpp434.00 B30-11-02 11:52
gamdev.cpp569.00 B30-11-02 11:52
gammln.cpp433.00 B30-11-02 11:52
gammp.cpp289.00 B30-11-02 11:52
gammq.cpp289.00 B30-11-02 11:52
gasdev.cpp436.00 B30-11-02 11:52
gaucof.cpp400.00 B30-11-02 11:52
gauher.cpp924.00 B30-11-02 11:52
gaujac.cpp1.84 kB30-11-02 11:52
gaulag.cpp892.00 B30-11-02 11:52
gauleg.cpp637.00 B30-11-02 11:52
gaussj.cpp1.20 kB30-11-02 11:52
gcf.cpp680.00 B30-11-02 11:52
golden.cpp830.00 B30-11-02 11:52
gser.cpp642.00 B30-11-02 11:52
hpsel.cpp508.00 B30-11-02 11:52
hpsort.cpp508.00 B30-11-02 11:52
hqr.cpp2.75 kB30-11-02 11:52
hufapp.cpp360.00 B30-11-02 11:52
hufdec.cpp541.00 B30-11-02 11:52
hufenc.cpp817.00 B30-11-02 11:52
hufmak.cpp1.50 kB30-11-02 11:52
hunt.cpp855.00 B30-11-02 11:52
hypdrv.cpp462.00 B30-11-02 11:52
hypgeo.cpp871.00 B30-11-02 11:52
hypser.cpp568.00 B30-11-02 11:52
icrc.cpp1.09 kB30-11-02 11:52
icrc1.cpp270.00 B30-11-02 11:52
igray.cpp286.00 B30-11-02 11:52
indexx.cpp2.59 kB30-11-02 11:52
interp.cpp418.00 B30-11-02 11:52
irbit1.cpp240.00 B30-11-02 11:52
irbit2.cpp276.00 B30-11-02 11:52
jacobi.cpp1.82 kB30-11-02 11:52
jacobn.cpp630.00 B30-11-02 11:52
julday.cpp497.00 B30-11-02 11:52
kendl1.cpp607.00 B30-11-02 11:52
kendl2.cpp796.00 B30-11-02 11:52
kermom.cpp672.00 B30-11-02 11:52
ks2d1s.cpp613.00 B30-11-02 11:52
ks2d2s.cpp913.00 B30-11-02 11:52
ksone.cpp403.00 B30-11-02 11:52
kstwo.cpp524.00 B30-11-02 11:52
laguer.cpp1.01 kB30-11-02 11:52
lfit.cpp1.33 kB30-11-02 11:52
linbcg.cpp1.89 kB30-11-02 11:52
linmin.cpp616.00 B30-11-02 11:52
lnsrch.cpp1.60 kB30-11-02 11:52
locate.cpp345.00 B30-11-02 11:52
lop.cpp355.00 B30-11-02 11:52
lubksb.cpp424.00 B30-11-02 11:52
ludcmp.cpp1.01 kB30-11-02 11:52
machar.cpp2.28 kB30-11-02 11:52
matadd.cpp183.00 B30-11-02 11:52
matsub.cpp183.00 B30-11-02 11:52
medfit.cpp1.11 kB30-11-02 11:52
memcof.cpp838.00 B30-11-02 11:52
metrop.cpp180.00 B30-11-02 11:52
mgfas.cpp1.95 kB30-11-02 11:52
mglin.cpp1.21 kB30-11-02 11:52
midexp.cpp651.00 B30-11-02 11:52
midinf.cpp610.00 B30-11-02 11:52
midpnt.cpp473.00 B30-11-02 11:52
midsql.cpp679.00 B30-11-02 11:52
midsqu.cpp679.00 B30-11-02 11:52
miser.cpp2.22 kB30-11-02 11:52
mmid.cpp606.00 B30-11-02 11:52
mnbrak.cpp1.14 kB30-11-02 11:52
mnewt.cpp664.00 B30-11-02 11:52
moment.cpp676.00 B30-11-02 11:52
mp2dfr.cpp234.00 B30-11-02 11:52
mpdiv.cpp623.00 B30-11-02 11:52
mpinv.cpp605.00 B30-11-02 11:52
mpmul.cpp804.00 B30-11-02 11:52
mpops.cpp2.27 kB30-11-02 11:52
mppi.cpp1,008.00 B30-11-02 11:52
mprove.cpp361.00 B30-11-02 11:52
mpsqrt.cpp819.00 B30-11-02 11:52
mrqcof.cpp838.00 B30-11-02 11:52
mrqmin.cpp1.32 kB30-11-02 11:52
newt.cpp1.73 kB30-11-02 11:52
odeint.cpp1.47 kB30-11-02 11:52
orthog.cpp639.00 B30-11-02 11:52
pade.cpp785.00 B30-11-02 11:52
pccheb.cpp319.00 B30-11-02 11:52
pcshft.cpp304.00 B30-11-02 11:52
pearsn.cpp642.00 B30-11-02 11:52
period.cpp1.70 kB30-11-02 11:52
piksr2.cpp294.00 B30-11-02 11:52
piksrt.cpp229.00 B30-11-02 11:52
pinvs.cpp1.47 kB30-11-02 11:52
plgndr.cpp645.00 B30-11-02 11:52
poidev.cpp666.00 B30-11-02 11:52
polcoe.cpp477.00 B30-11-02 11:52
polcof.cpp643.00 B30-11-02 11:52
poldiv.cpp335.00 B30-11-02 11:52
polin2.cpp339.00 B30-11-02 11:52
polint.cpp653.00 B30-11-02 11:52
powell.cpp1.06 kB30-11-02 11:52
predic.cpp415.00 B30-11-02 11:52
probks.cpp400.00 B30-11-02 11:52
psdes.cpp595.00 B30-11-02 11:52
pwt.cpp913.00 B30-11-02 11:52
pwtset.cpp1,008.00 B30-11-02 11:52
pythag.cpp278.00 B30-11-02 11:52
pzextr.cpp741.00 B30-11-02 11:52
qgaus.cpp496.00 B30-11-02 11:52
qrdcmp.cpp781.00 B30-11-02 11:52
qromb.cpp568.00 B30-11-02 11:52
qromo.cpp640.00 B30-11-02 11:52
qroot.cpp802.00 B30-11-02 11:52
qrsolv.cpp294.00 B30-11-02 11:52
qrupdt.cpp582.00 B30-11-02 11:52
qsimp.cpp455.00 B30-11-02 11:52
qtrap.cpp419.00 B30-11-02 11:52
quad3d.cpp596.00 B30-11-02 11:52
quadct.cpp369.00 B30-11-02 11:52
quadmx.cpp359.00 B30-11-02 11:52
quadvl.cpp306.00 B30-11-02 11:52
ran0.cpp308.00 B30-11-02 11:52
ran1.cpp666.00 B30-11-02 11:52
ran2.cpp878.00 B30-11-02 11:52
ran3.cpp820.00 B30-11-02 11:52
ran4.cpp581.00 B30-11-02 11:52
rank.cpp145.00 B30-11-02 11:52
ranpt.cpp190.00 B30-11-02 11:52
ratint.cpp746.00 B30-11-02 11:52
ratlsq.cpp1.42 kB30-11-02 11:52
ratval.cpp261.00 B30-11-02 11:52
rc.cpp808.00 B30-11-02 11:52
rd.cpp1.05 kB30-11-02 11:52
realft.cpp1,009.00 B30-11-02 11:52
rebin.cpp389.00 B30-11-02 11:52
red.cpp521.00 B30-11-02 11:52
relax.cpp355.00 B30-11-02 11:52
relax2.cpp467.00 B30-11-02 11:52
resid.cpp369.00 B30-11-02 11:52
revcst.cpp642.00 B30-11-02 11:52
reverse.cpp308.00 B30-11-02 11:52
rf.cpp886.00 B30-11-02 11:52
rj.cpp1.63 kB30-11-02 11:52
rk4.cpp554.00 B30-11-02 11:52
rkck.cpp1.39 kB30-11-02 11:52
rkdumb.cpp674.00 B30-11-02 11:52
rkqs.cpp867.00 B30-11-02 11:52
rlft3.cpp1.89 kB30-11-02 11:52
rofunc.cpp708.00 B30-11-02 11:52
rotate.cpp638.00 B30-11-02 11:52
rsolv.cpp249.00 B30-11-02 11:52
rstrct.cpp511.00 B30-11-02 11:52
rtbis.cpp558.00 B30-11-02 11:52
rtflsp.cpp719.00 B30-11-02 11:52
rtnewt.cpp494.00 B30-11-02 11:52
rtsafe.cpp1.03 kB30-11-02 11:52
rtsec.cpp550.00 B30-11-02 11:52
rzextr.cpp784.00 B30-11-02 11:52
savgol.cpp883.00 B30-11-02 11:52
scrsho.cpp1.25 kB30-11-02 11:52
select.cpp743.00 B30-11-02 11:52
selip.cpp1.14 kB30-11-02 11:52
sfroid.cpp1.67 kB30-11-02 11:52
shell.cpp351.00 B30-11-02 11:52
shoot.cpp518.00 B30-11-02 11:52
shootf.cpp776.00 B30-11-02 11:52
simp1.cpp466.00 B30-11-02 11:52
simp2.cpp595.00 B30-11-02 11:52
simp3.cpp397.00 B30-11-02 11:52
simplx.cpp1.82 kB30-11-02 11:52
simpr.cpp929.00 B30-11-02 11:52
sinft.cpp582.00 B30-11-02 11:52
slvsm2.cpp290.00 B30-11-02 11:52
slvsml.cpp185.00 B30-11-02 11:52
sncndn.cpp928.00 B30-11-02 11:52
snrm.cpp384.00 B30-11-02 11:52
sobseq.cpp1.14 kB30-11-02 11:52
solvde.cpp1.80 kB30-11-02 11:52
sor.cpp975.00 B30-11-02 11:52
sort.cpp1.13 kB30-11-02 11:52
sort2.cpp1.38 kB30-11-02 11:52
sort3.cpp405.00 B30-11-02 11:52
spctrm.cpp1.28 kB30-11-02 11:52
spear.cpp877.00 B30-11-02 11:52
sphbes.cpp440.00 B30-11-02 11:52
sphfpt.cpp1.46 kB30-11-02 11:52
sphoot.cpp1.20 kB30-11-02 11:52
splie2.cpp324.00 B30-11-02 11:52
splin2.cpp443.00 B30-11-02 11:52
spline.cpp753.00 B30-11-02 11:52
splint.cpp460.00 B30-11-02 11:52
spread.cpp608.00 B30-11-02 11:52
sprsax.cpp317.00 B30-11-02 11:52
sprsin.cpp473.00 B30-11-02 11:52
sprspm.cpp992.00 B30-11-02 11:52
sprstm.cpp1.14 kB30-11-02 11:52
sprstp.cpp1.10 kB30-11-02 11:52
sprstx.cpp349.00 B30-11-02 11:52
stifbs.cpp2.90 kB30-11-02 11:52
stiff.cpp2.24 kB30-11-02 11:52
stoerm.cpp690.00 B30-11-02 11:52
svbksb.cpp412.00 B30-11-02 11:52
svdcmp.cpp3.63 kB30-11-02 11:52
svdfit.cpp790.00 B30-11-02 11:52
svdvar.cpp389.00 B30-11-02 11:52
toeplz.cpp1.18 kB30-11-02 11:52
tptest.cpp432.00 B30-11-02 11:52
tqli.cpp1.13 kB30-11-02 11:52
trapzd.cpp396.00 B30-11-02 11:52
tred2.cpp1.49 kB30-11-02 11:52
tridag.cpp443.00 B30-11-02 11:52
trncst.cpp745.00 B30-11-02 11:52
trnspt.cpp546.00 B30-11-02 11:52
ttest.cpp401.00 B30-11-02 11:52
tutest.cpp413.00 B30-11-02 11:52
twofft.cpp658.00 B30-11-02 11:52
vander.cpp512.00 B30-11-02 11:52
vegas.cpp4.63 kB30-11-02 11:52
voltra.cpp775.00 B30-11-02 11:52
wt1.cpp300.00 B30-11-02 11:52
wtn.cpp750.00 B30-11-02 11:52
wwghts.cpp1.37 kB30-11-02 11:52
zbrac.cpp452.00 B30-11-02 11:52
zbrak.cpp384.00 B30-11-02 11:52
zbrent.cpp1.38 kB30-11-02 11:52
zrhqr.cpp488.00 B30-11-02 11:52
zriddr.cpp1.10 kB30-11-02 11:52
zroots.cpp834.00 B30-11-02 11:52
...
Sponsored links

expint.cpp (158.06 kB)

Need $ 30
Your balance $

账户余额不足,支付宝快速购买。

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D