wolfram-mathematica

Parsing and generating JSON

守給你的承諾、 提交于 2019-12-03 10:19:40
问题 Mathematica's list of built-in formats is pretty extensive; however, JSON is not on that list. Is there an existing solution for generating and parsing JSON in Mathematica, or are we going to have to roll our own solution? 回答1: UPDATE: As noted in Pillsy's answer, JSON is a built-in format for Import and Export as of Mathematica 8: http://reference.wolfram.com/mathematica/ref/format/JSON.html. But, as discussed in the comments, the following seems to be a more robust solution as of

Histogram with breaking axis and interlaced colorbar

荒凉一梦 提交于 2019-12-03 10:16:41
问题 I have data as those ones a b c d e alpha 5.51 0.60 -0.12 26.90 76284.53 beta 3.39 0.94 -0.17 -0.20 -0.20 gamma 7.98 3.34 -1.41 7.74 28394.93 delta 2.29 1.24 0.40 0.29 0.28 I want to do a nice publishable histogram as this one but with a break in the y axis so we can figure out the variation of a , b , c , d and e so that data will not be squashed by extreme values in e column as this one but using interlaced colorbar histogram: I would like to do that in python (matplotlib, pandas, numpy

Complex Calculations in C#

半腔热情 提交于 2019-12-03 10:03:51
问题 What are the best tools (most efficient) available in .NET (C#) for calculating: integrals partial derivatives other non-trivial math Can people please comment on Mathematica and Matlab and their integration into C# ? 回答1: Math.NET is a mathematical open source toolkit written in C# for the Microsoft .NET platform that aims to provide a self-contained clean framework for both numerical scientific and symbolic algebraic computations. In particular, Math.NET Numerics is the result of the merger

Why would Mathematica break normal scoping rules in Module?

百般思念 提交于 2019-12-03 09:57:03
问题 As was pointed out in a recent post scoping does not work as expected inside of Module. An example from that thread is: Module[{expr}, expr = 2 z; f[z_] = expr; f[7]] (*2 z*) But the following works almost as expected. Module[{expr}, expr = 2 z; Set@@{f[z_], expr}; f[7]] (*14*) What language design consideration made wolfram choose this functionality? Edit: See Jefromi's first comment I changed z from being a local variable to not and forgot to change the output. It does not effect the

Lexical and dynamic scoping in Mathematica: Local variables with Module, With, and Block

人走茶凉 提交于 2019-12-03 09:55:39
问题 The following code returns 14 as you'd expect: Block[{expr}, expr = 2 z; f[z_] = expr; f[7]] But if you change that Block to a Module then it returns 2*z . It seems to not matter what other variables besides expr you localize. I thought I understood Module, Block, and With in Mathematica but I can't explain the difference in behavior between Module and Block in this example. Related resources: Tutorial on Modularity and the Naming of Things from the Mathematica documentation Excerpt from a

Is there a fast product operation for PackedArrays?

那年仲夏 提交于 2019-12-03 09:51:11
问题 In Mathematica a vector (or rectangular array) containing all machine size integers or floats may be stored in a packed array. These objects take less memory, and some operations are much faster on them. RandomReal produces a packed array when possible. A packed array can be unpacked with the Developer function FromPackedArray Consider these timings lst = RandomReal[1, 5000000]; Total[lst] // Timing Plus @@ lst // Timing lst = Developer`FromPackedArray[lst]; Total[lst] // Timing Plus @@ lst /

Extracting an expression matching a pattern from a large expression

人盡茶涼 提交于 2019-12-03 09:40:46
问题 I have a Mathematica expression that contains a single square root, schematically expr = a / (b + Sqrt[c]); where a , b , c are large expressions. I would like to extract the expression under the sqrt, for instance by matching to a pattern, something like Match[expr,Sqrt[x_]] // should return c Is there an easy way to do this? 回答1: Theoretically, this should work correctly: extractSqrt = Cases[ToBoxes@#, SqrtBox@x_ :> ToExpression@x, Infinity] &; extractSqrt[expr] 回答2: If you are willing to

custom postfix notation, Apply / Function

ε祈祈猫儿з 提交于 2019-12-03 09:35:01
问题 I would like to set up the following custom notation in Mathematica 7. This notation is not particularly useful in itself, so please do not suggest existing alternatives, or point out that this only saves a few keystrokes. I want to know if and how it may be done. At present, one may enter f = #2 + #^2 / #3 & @@ # & ; f[ {a, b, c} ] Out[]= b + a^2 / c Where the inner function #^2 / #3 + #2 & is Apply 'd to the first argument. I would like to implement the syntax f = #2 + #^2 / #3 @@& ; and

How do I store the results of a long symbolic calculation for later use?

▼魔方 西西 提交于 2019-12-03 09:14:00
My calculations are something like this: f[x_]:= (*runs fast*) g[x_]:=(*runs fast*) h[x_]=depends on f[x],g[x] (*runs slow ~5mins*) Now I need only the results of h[x] and every time I restart mma, I essentially redo the same calculations to get h[x] , when it could have been stored. Is there some way I can save the symbolic results, and just import it anytime I need it? Try Save Use like: Save["h-defs.m", h] And load with Get : << "h-defs.m" 来源: https://stackoverflow.com/questions/5938880/how-do-i-store-the-results-of-a-long-symbolic-calculation-for-later-use

Algorithm for picking pattern free downvalues from a sparse definition list

醉酒当歌 提交于 2019-12-03 08:33:59
I have the following problem. I am developing a stochastic simulator which samples configurations of the system at random and stores the statistics of how many times each configuration has been visited at certain time instances. Roughly the code works like this f[_Integer][{_Integer..}] :=0 ... someplace later in the code, e.g., index = get index; c = get random configuration (i.e. a tuple of integers, say a pair {n1, n2}); f[index][c] = f[index][c] + 1; which tags that configuration c has occurred once more in the simulation at time instance index. Once the code has finished there is a list