Rank: 270 based on 419 downloads (last 30 days) and 31 files submitted
photo

David Terr

E-mail
Company/University
Raytheon

Personal Profile:

I received a Ph.D. in number theory from UC Berkeley in 1997. I also enjoy other areas of math, as well as physics and computer programming. I live in Goleta, CA, near Santa Barbara and work at Raytheon in Goleta.


 

Watch this Author's files

 

Files Posted by David Terr View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
27 Dec 2004 numerical.zip Archive containing numerical function files. Author: David Terr numerical, function, mathematics, archive 8 0
27 Dec 2004 Lucas.m Given a nonnegative integer n, return the nth Lucas number. Author: David Terr symbolic math, lucas number, fibonacci number, mathematics 9 0
  • 5.0
5.0 | 1 rating
27 Dec 2004 rqf.m Reduce a binary quadratic form, given as a row vector of length 3. Author: David Terr quadratic form, positive definite, reduced 5 0
29 Nov 2004 qftimes.m This function composes two quadratic forms. Author: David Terr quadratic form, positive definite, reduced, composition 6 0
10 Nov 2004 Screenshot Physics.zip Archive containing various files pertaining to physics. Author: David Terr chemistry, physics, files, information, archive 24 5
  • 3.66667
3.7 | 6 ratings
Comments and Ratings on David Terr's Files View all
Updated File Comment by Comments Rating
02 Sep 2014 ChebyshevPoly.m This program returns the coefficients of the Chebyshev polynomial T_n, given n. Author: David Terr Zhexuan Zhang

The code fails at high degree. Please do not use this.

20 Jun 2014 Wigner3j.m Wigner3j(j1,j2,j,m1,m2,m) returns the Wigner 3j-symbol. Author: David Terr Hobson

08 Apr 2014 binomial.m This program computes the binomial coefficient C(n,m). Author: David Terr John D'Errico

Sorry. I think Herbert completely misunderstands the issue. In fact, he seems to be wrong on all counts.

It DOES have an overflow issue, just as as nchoosek has an issue. For example,

>> nchoosek(1500,265)
Warning: Result may not be exact. Coefficient is greater than 9.007199e+15 and is only accurate to 15 digits
> In nchoosek at 92
ans =
1.58269376513703e+302

nchoosek does return a valid answer, WITH a warning that it is not exact. But since the result has 303 decimal digits and is returned as a double what do you expect???

binomial also returns the same thing, however it generates no warning message. That does not say it has no issue, only that it fails to be friendly and warn you of that fact!

Both codes will return inf when the arguments cause a double to be exceeded.

binomial(1500,275)
ans =
Inf

However, note that nchoosek is both more flexible and more powerful than is binomial. And nchoosek has been around since the dark ages. So the fact that David could not find it is merely a reflection that he did not look that hard. Jos points out the simple use of lookfor that would have given him the answer.

nchoosek also has the ability to give exact results for a slightly larger set of inputs than binomial. So if the input is uint64, so will be the output.

>> b1 = nchoosek(uint64(65),30)
b1 =
3009106305270645216

>> b2 = binomial(65,30)
b2 =
3.00910630527064e+18

>> b1 - b2
ans =
480

Here nchoosek was exact, whereas binomial was wrong. In fact, nchoosek CAN do symbolic computation, whereas binomial fails to return anything of value.

>> b1 = nchoosek(sym(1500),750)
b1 =
722462892448930217028116073228485295944376343040546523665632913653613596406381727723198055046187955623124069093412562720869577867557610868874271130828359513282184417776042792372322074253393127328396528996120053749558122610911178218582669317535346728464707661495135518682519172221470420360910320792434869988224466647627642393919250205687942318888922893189087379790541907686956429837978631252775258630376332505697937034877619012586751274240109457111424

>> binomial(sym(1500),30)
ans =
exp(gammaln(1501) - gammaln(1471) - 5253606334386405/70368744177664)

Of course, nchoosek even works perfectly for vpi input, whereas binomial fails there completely.

There is only one point made by Herbert that MIGHT be correct in some circumstances, i.e., that binomial is faster. Since binomial does no error checking and it has lesser capability than does nchoosek, of course it might be faster. On top of that, the gamma log computation for large input might be be pretty fast. But is it good? Even for double inputs...

>> binomial(101,10)
ans =
19212541264839.3

>> nchoosek(101,10)
ans =
19212541264840

Oops. I'm pretty sure that most binomial coefficients are integers, at least they were when I went to school. You never know with the new math though. But I would think it disappointing to see a floating point result that is not a pure integer, at least for a reasonably small set of inputs.

So how about speed. Is it faster? I'll use timeit to do the comparison.

>> timeit(@() nchoosek(100,10))
ans =
8.32913416666667e-05

>> timeit(@() binomial(100,10))
ans =
0.0002867962125

So here nchoosek was actually 4 times FASTER than binomial. Not slower. binomial is the slow one.

08 Apr 2014 binomial.m This program computes the binomial coefficient C(n,m). Author: David Terr Herbert

perfect, it's faster than nchoosek and doesn't seem to have an overflow issue.

28 Mar 2014 HermitePoly.m This program returns the coefficients of the Hermite polynomial H_n, given n. Author: David Terr Kermin Guo

Contact us