wolfram-mathematica

Parsing and generating JSON

谁说胖子不能爱 提交于 2019-12-02 23:37:36
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? 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 Mathematica 10.4.1: WARNING: This involves doing an eval (ToExpression) so don't use this to parse strings from

Complex Calculations in C#

房东的猫 提交于 2019-12-02 23:24:25
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# ? las3rjock 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 of dnAnalytics with Math.NET Iridium and includes the following features: real and complex, dense

Stable Sorting, ie, Minimally-Disruptive Sorting

百般思念 提交于 2019-12-02 23:04:03
Suppose I have a list of things (numbers, to keep things simple here) and I have a function I want to use to sort them by, using SortBy. For example, the following sorts a list of numbers by last digit: SortBy[{301, 201}, Mod[#,10]&] And notice how two of (ie, all of) those numbers have the same last digit. So it doesn't matter which order we return them in. In this case Mathematica returns them in the opposite order. How can I ensure that all ties are broken in favor of how the items were ordered in the original list? (I know it's kind of trivial but I feel like this comes up from time to

Custom ColorFunction/ColorData in ArrayPlot (and similar functions)

筅森魡賤 提交于 2019-12-02 22:26:55
This is related to Simon's question on changing default ColorData in Mathematica. While the solutions all addressed the issue of changing ColorData in line plots, I didn't quite find the discussion helpful in changing the ColorFunction / ColorData in ContourPlot / ArrayPlot / Plot3D , etc. TLDR: Is there a way to get mma to use custom colors in ArrayPlot/ContourPlot/etc. Consider the following example plot of the function sin(x^2+y^3) that I created in MATLAB: Now doing the same in mma as: xMax = 3; yMax = 3; img = Transpose@ Table[Sin[y ^3 + x^2], {x, -xMax, xMax, 0.01}, {y, -yMax, yMax, 0.01

How to find a function's rth derivative when r is symbolic in Mathematica?

回眸只為那壹抹淺笑 提交于 2019-12-02 22:00:50
I have a function f(t)=2/(2-t) . It is not so hard to get the rth derivative at t=0 (i.e. 2^(-r)*r! ) without using Mathematica. In the case of Mathematica calculation, I can get the r-th derivative when r=4 like this: D[2/(2-t), {t, 4}] . But how can I get the rth derivative at t=0 in Mathematica when r is ANY integer? I tried to use this expression, but it didn't work as expected: Simplify[D[2/(2 - t), {t, r}], Assumptions -> Element[r, Integers]] /. {t->0} Is it possible to do the above math symbolically in Mathematica just as we humans do? f = FindSequenceFunction[Table[D[2/(2 - t), {t, n}

Formatting usage messages

故事扮演 提交于 2019-12-02 21:16:53
If you take a look at the Combinatorica package in Mathematica8 in (mathematicapath)/AddOns/LegacyPackages/DiscreteMath/Combinatorica.m you will find the definitions of functions. What I'm interested to know is how Mathematica knows how to format the usage messages. Something tells me that I'm not looking at the right file. In any case, lets try the following: Cofactor::usage = "Cofactor[m, {i, j}] calculates the (i, j)th cofactor of matrix m." This line is the 682 line in the file mentioned above. Now if we run it in a mathematica notebook and we use ?Cofactor we will see the exact same

Syntax Coloring In Mathematica

让人想犯罪 __ 提交于 2019-12-02 20:57:31
How could user-defined function symbol such as f in f [x_] = 2 x or variable symbols such as lotto in lotto = Table[2, {10}]; be colored automatically ? In Syntax coloring on M8 no option is offered for this. Only Local Variables or Global symbols that have no values assigned. This is not exactly what you asked for, but it may be useful to you. You can highlight symbols by context, using this method: SetOptions[$FrontEndSession, AutoStyleOptions -> {"SymbolContextStyles" -> {"highlight`" -> Green}} ] AppendTo[$ContextPath, "highlight`"]; Now, when you create a symbol in the context highlight`

How would you do a PivotTable function in Mathematica?

纵饮孤独 提交于 2019-12-02 20:55:15
PivotTables in Excel (or, cross tabulations ) are quite useful. Has anyone already thought about how to implement a similar function in Mathematica? I am not familiar with the use of pivot tables, but taking the example on the page linked above, I propose this: Needs["Calendar`"] key = # -> #2[[1]] & ~MapIndexed~ {"Region", "Gender", "Style", "Ship Date", "Units", "Price", "Cost"}; choices = { {"North", "South", "East", "West"}, {"Boy", "Girl"}, {"Tee", "Golf", "Fancy"}, IntegerString[#, 10, 2] <> "/2011" & /@ Range@12, Range@15, Range[8.00, 15.00, 0.01], Range[6.00, 14.00, 0.01] }; data =

Is there HashTable structure in Wolfram Mathematica?

[亡魂溺海] 提交于 2019-12-02 17:38:52
I want to use a Structure like HashTable. Is there similar structure in Wolfram Mathematica ? Pillsy 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 need to change the entries in your table, you can use the DownValues of a symbol as a hash table. This

What does “upvalue” mean in Mathematica and when to use them?

巧了我就是萌 提交于 2019-12-02 17:10:20
To me, g /: f[g[x_]] := h[x] is just verbose equivalent of f[g[x_]] := h[x] . Can you raise an example that you have to use /: ? Actually, g /: f[g[x_]] := h[x] is not equivalent to f[g[x_]] := h[x] . The latter associates the definition with f , while TagSet ( /: ) and UpSet ( ^= and its delayed version , ^:= ) associate the definition with g . This is a crucial difference and can be illustrated by a simple example. Let's say you want to have a set of variables that obey modulo 5 addition, i.e. 6 + 7 mod 5 = 3. So, we want anything with Head mod to behave correctly. Initially, we'd think that