From time to time, I would like to use Mathematica purely numerically, e.g., plotting a function which is defined as an integral which cannot be solve analytically or a solution of a differential equation, or ... . It turns out that Mathematica is rather efficient (I would say comparable to Matlab) if you know what you are doing. However, Mathematica even though it has incredible numerical possibilities makes numerical life quite hard. Problems which occur:
it tries to evaluate a function analytically, because you type something like
f[x]
wherex
does not have (yet) a numerical value.it tries to symbolically preprocess expressions (check out the
"SymbolicProcessing"
option ofNIntegrate
) even if I know that no symbolic solution existslists are not properly packed, because somewhere
Pi
appears which does not get converted to a numerical value...
I would like very much if there would be a switch, which changes Mathematica into purely numerical mode which would include:
a) all numbers are converted in machine numbers (lists are packed)
b) there is no attempted of any symbolic operation, any function
f[x]
withx
not a number remains unevaluated (of course, I know the trick to definef[x_?NumericQ]
but the numerical mode would save me lots of typing)c) turn off symbolical (pre-)processing
Is there a way which I can get the required behavior a) to c)?
Do other people suffer from the same problems?
It turns out that for me it is not a problem any more because I know how to deal with it; however, inexperienced user typically suffer from very bad performance if they would like to use Mathematica for numerical means. In fact Mathematica is a marvelous numerical tool with good plotting capabilities.
I hope that some of you might even now better than me what I am hunting for. I guess not all problems can be avoided. A problematic expression is, e.g., the following
Plot[{Re[#], Im[#]}&[f[x]], {x,0,1}]
. Plot
does not know that it has a list as an argument, but running evaluate on it decreases the performance because f[x]
is evaluated twice. What I am looking for is to put Mathematica in a mode which a typical user with a typical problem does not suffer the low speed as it does now. So typing Pi + 1
should result in 4.1416
, {Pi,1}
should give a packed array, and Mathematica should forget about commutativity and associativity of addition since it does not hold for numerical problems.
1.*10^16 + 1. - 1.*10^16
returns0
, and will return always return0
unless1.
is the last term. Additionally, in mma, that isn't even completely true as it will do some pruning prior to evaluation. For example,f[a_,b_,c_]:=1/(a^2 - 2 a b + b^2 - c^2)
will overflow forf[10.^10, 10.^10, 10.]
despite the first three terms cancelling. $\endgroup$1.*10^16
away from the last place by commutativity alone because if you have no associativity, the expressiona+b+c
has to be evaluated as(a+b)+c
. Since Mathematica does assume associativity for addition, whatever Mathematica does is no indication about what can or cannot be done without associativity. $\endgroup$