I have a problem with exponentials and the use of the commands N
and Collect
. I am trying to write a code that generates a very large list of polynomials on a variable x which are needed as input for an external program. In order to create the proper input for this program, I have to write the polynomials in a numerical format and not a symbolic one. A simple nesting of the commands
Collect[N[f[x],precision],x]
does (almost every time) what I want. The problem with my polynomials is that they come after the cancellation of some exponentials, of which the two commands above took care of so far. As a simple example,
In[]:= Collect[
N[-4*E^(2*Pi*(4 + x))*(E^(-(Pi*x) - Pi*(8 + x))/2 -
8*E^(-(Pi*x) - Pi*(8 + x))*Pi) +
8*E^(-(Pi*x) + 2*Pi*(4 + x) - Pi*(8 + x))*Pi*x], x]
Out[]= 98.531 + 25.1327 x
However, the only instance when this happens to fail is when one of the polynomials is of degree 0, in which case the cancellation of the exponentials doesn't happen anymore:
In[]:= Collect[N[-4*E^(-(Pi*x) + 2*Pi*(4 + x) - Pi*(8 + x))], x]
Out[]= -4. 2.71828^(-3.14159 x + 6.28319 (4. + x) -
3.14159 (8. + x))
A trivial swap of N
and Collect
doesn't solve the issue. After changing the arguments of the exponentials, the problem seems to appear if I have some parenthesis ()
and some noninteger number in front of my variable x. I would like to make use of Simplify
to solve the problem, but since the program is already demanding and the process has to be iterated tons of times, I need to find a faster way to fix this issue instead of using Simplify
each time. The only other solution which seemed to work is nesting the commands N[ExpToTrig[N[Collect[... ,x]]]]
(it's not enough to apply N[ ]
once), but I am not sure of how much it is reliable on the long run and (if and) how much it is faster than Simplify
. Is there some quick fix to the problem that I don't know of? Thanks in advance.