integral competition HP50g vs. DM42
|
08-23-2020, 07:38 PM
(This post was last modified: 08-25-2020 03:34 PM by Albert Chan.)
Post: #17
|
|||
|
|||
RE: integral competition HP50g vs. DM42
(08-23-2020 08:56 AM)peacecalc Wrote: @Albert Chan, do you know how this is implemented in XCAS? So, I don't have to invent the wheel a second time and maybe it is possible for me to translate it in code for the HP50g. I just downloaded giac source, usual.cc, function erf0(): Quote:if (absx<=3){ Code: def hyp1f1(a,b,x): >>> k = 2/pi**0.5 >>> erf = lambda x: k*x * hyp1f1(1/2, 3/2, -x*x) >>> CiS = lambda x, erf=erf: (1+1j)/2 * erf((1-1j)/k * x) >>> CiS(3.9) (0.42233270272270274 + 0.47520241152278453j) CiS(3.9) called erf(z = (1-1j) * 3.4562850092657564), |z| ≈ 5 > 3 As expected, we lose many digits precision due to massive cancellation. For big |z|, XCas use continued fraction form: Quote:// 2*exp(z^2)*int(exp(-t^2),t=z..inf) = 1/(z+1/2/(z+1/(z+3/2/(z+...)))) int(exp(-t^2),t=z..inf) = sqrt(pi)/2 * erfc(z), we got this: Code: def erfc(x, n=20, res=0): # continued fraction, bottom up >>> CiS(3.9, erf = lambda x: 1 - erfc(x)) (0.42233271026093344 + 0.47520240235068834j) Or, we could calculate generalized continued fraction top down, without hard-coded maximum n. Code: def erfc2(x, eps=1/16): # continued fraction, top down >>> CiS(3.9, erf = lambda x: 1 - erfc2(x)) (0.42233271026093344 + 0.47520240235068834j) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)