factorial of negative one (-1)
clp2 at rebertia.com
Fri Oct 29 07:02:25 CEST 2010
On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz <whitequill.bj at gmail.com> wrote:
> I am working with differential equations of the higher roots of negative
> one. (dividing enormous numbers into other enormous numbers to come out with
> very reasonable numbers).
> I am mixing this in to a script for Maya (the final output is graph-able as
> a spiral.)
> I have heard that Sage, would be a good program to do this in, but I'd like
> to try and get this to work in native python if I can.
> The script I am trying to port to Python is; http://pastebin.com/sc1jW1n4.
Unless your code is really long, just include it in the message in the future.
So, for the archive:
indvar = 200;
q = 0;
lnanswer = 0;
for m = 1:150
lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m)) ;
q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer);
Also, it helps to point out *what language non-Python code is in*. I'm
guessing MATLAB in this case.
Naive translation attempt (Disclaimer: I don't know much MATLAB):
from math import log, factorial, exp
indvar = 200
q = 
lnanswer = 0
for m in range(1, 151):
lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m))
q.append(q[-1] + (1 if m % 2 == 0 else -1) * exp(lnanswer))
More information about the Python-list