wolfram-mathematica

Init.m considerations and good practices

早过忘川 提交于 2019-12-03 06:18:53
问题 As I never found (or perhaps I never search for it enough) a good article about how to manage the init.m files, I ended up developing my own "standard", but I wonder how bad I did it. For example, my usual init.m is stored in C:\Documents and Settings\All Users\Application Data\Mathematica\Kernel\init.m (Windows) and I edit it using a text editor. As I don't want the definitions to go into the Global context, the content is something like: (** User Mathematica initialization file **) Begin[

Why do Replace and ReplaceAll give different results even when only one rule and one expression is used?

北城余情 提交于 2019-12-03 06:02:40
Maybe someone can explain to me why Replace gives a different answer than ReplaceAll , even though I am using one rule, and, I think, I have one expression. According to the documentation: ReplaceAll looks at each part of expr, tries all the rules on it, and then goes on to the next part of expr. The first rule that applies to a particular part is used; no further rules are tried on that part, or on any of its subparts and for Replace A list of rules can be given. The rules are tried in order. The result of the first one that applies is returned. If none of the rules apply, the original expr

Possible to block OwnValues when DownValues already exist?

家住魔仙堡 提交于 2019-12-03 06:01:40
问题 For cases where one has already assigned DownValues associated with the name 'a', is there an accepted way to block the assignment of OwnValues to the same name? (I originally came across this issue while playing with someone's attempt at implementing a data dictionary.) Here's what I mean to avoid: Remove[a]; a[1] := somethingDelayed a[2] = somethingImmediate; DownValues[a] a[1] a[2] Returns... {HoldPattern[a[1]] :> somethingDelayed, HoldPattern[a[2]] :> somethingImmediate} somethingDelayed

Remap Caps lock key to Esc in Mma 7

微笑、不失礼 提交于 2019-12-03 05:56:05
TLDR : How do I get CapsLock to translate to "ShortNameDelimiter" in Mma 7? I like pretty text in my mma notebooks, and often define functions as f[\[Alpha]_] =... so as to match the exact equation that I'm working with. As such, it involves a lot of Esc - letter - Esc sequences, and reaching for Esc every other stroke breaks my flow of typing. Now, the CapsLock key is seldom used (I can't remember the last time I needed it), but conveniently placed (your pinky is right there!). Remapping it to Esc on vim worked wonders for me and I was wondering if there was a way to do the same in mma ,

Design approach: Overloading vs Switch?

北城余情 提交于 2019-12-03 05:32:10
In regard to performance and scalability in package design, is it best to: … ‘overload’ function names (letting Mathematica sort out which version to use based on patterns/conditions/tests and the way the system orders definitions)? … or to construct a single function with a Switch[] (or similar command) to direct evaluation? Mathematica’s expressiveness frequently confuses me with silly (?) issues like this. This is a broad question, but I will take this opportunity to give a broad answer... I advocate that one should embrace the principal paradigm of a programming language, rather than

NIntegrate - why is it much slower in Mathematica 8 in this given case?

蹲街弑〆低调 提交于 2019-12-03 05:17:35
问题 I have a Mathematica code where I have to evaluate numerically thousands of integrals similar to this one NIntegrate[ (Pi*Cos[(Pi*(-2*x + y))/(1 + y)] + (1 + y)*(-Sin[(2*Pi*x)/(1 + y)] + Sin[(Pi*(-2*x + y))/(1 + y)]))/(E^x*(1 + y)), {x, 0, 100}, {y, 0, 100} ] //AbsoluteTiming The integrand is a nice absolutely integrable function without singularities, which decays exponentially in one direction and as 1/y^3 in the other direction. The NIntegrate command was working fine in Mathematica 7, but

Self-restarting MathKernel - is it possible in Mathematica?

纵然是瞬间 提交于 2019-12-03 05:16:05
问题 This question comes from the recent question "Correct way to cap Mathematica memory use?" I wonder, is it possible to programmatically restart MathKernel keeping the current FrontEnd process connected to new MathKernel process and evaluating some code in new MathKernel session? I mean a "transparent" restart which allows a user to continue working with the FrontEnd while having new fresh MathKernel process with some code from the previous kernel evaluated/evaluating in it? The motivation for

Is right-to-left operator associativity in R possible?

筅森魡賤 提交于 2019-12-03 04:41:59
I'm new to R, and I just discovered I suffer from Bracket Phobia (see comment in the link). I like the way magrittr notation %>% works, because it avoids nested parenthesis in some situations, and makes code more readable. I came from Mathematica , where there is a very similar native // notation to do what %>% does. Here are some R and Mathematica comparisons: #R Notation c(1.5,-2.3,3.4) %>% round %>% abs %>% sum #Mathematica Notation {1.5,-2.3,3.4}//Round//Abs//Total So far so good, but, my question is: Is there some way to mimic Mathematica @ notation , with right-to-left associativity in R

Is there HashTable structure in Wolfram Mathematica?

梦想与她 提交于 2019-12-03 04:23:20
问题 I want to use a Structure like HashTable. Is there similar structure in Wolfram Mathematica ? 回答1: Update: Mathematica version 10 introduced the Association data structure (tutorial). There are a number of possibilities. The easiest possibility, which works well if you don't need to add or delete keys from your table, or change their associated values, is to construct a list of rules with the key on the left-hand side and the value on the right-hand side, and use Dispatch on it. If you do

Mathematica: why 3D plot remember last viewpoint/rotation made to it, even after evaluating again?

不问归期 提交于 2019-12-03 03:59:11
I find this a bit annoying. I make a 3D plot, initially it come up in the default orientation. Then, using the mouse, I rotate it some way. Now I run the command again, expecting to obtain the original shape (i.e the original orientation before I rotated it by mouse), but instead, it just gives me the same plot I have on the screen, i.e. it seems to have kept/remembered the last viewpoint in that output cell. I wanted it to go back to the original viewpoint. So, I delete the output cell to make it happen. Do you think this is how it is supposed to work? Having to keep deleting the cell output