wolfram-mathematica

Python Pylab pcolor options for publication quality plots

左心房为你撑大大i 提交于 2019-12-03 07:51:23
I am trying to make DFT (discrete fourier transforms) plots using pcolor in python. I have previously been using Mathematica 8.0 to do this but I find that the colorbar in mathematica 8.0 has bad one-to-one correlation with the data I try to represent. For instance, here is the data that I am plotting: [[0.,0.,0.10664,0.,0.,0.,0.0412719,0.,0.,0.], [0.,0.351894,0.,0.17873,0.,0.,0.,0.,0.,0.], [0.10663,0.,0.178183,0.,0.,0.,0.0405148,0.,0.,0.], [0.,0.177586,0.,0.,0.,0.0500377,0.,0.,0.,0.], [0.,0.,0.,0.,0.0588906,0.,0.,0.,0.,0.], [0.,0.,0.,0.0493811,0.,0.,0.,0.,0.,0.], [0.0397341,0.,0.0399249,0.,0.

Formatting usage messages

时光毁灭记忆、已成空白 提交于 2019-12-03 07:47:48
问题 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

Define control as variable in Mathematica

一世执手 提交于 2019-12-03 07:29:21
When I use Manipulate I can do: Manipulate[x, {u, 1, 10}] In reality my controls are many and complicated, so I would prefer to take their definition out of the Manipulate expression, like that: control = {u, 1, 10} Manipulate[x, control] But that does result in a an error: Manipulate argument control does not have the correct form for a \ variable specification. Why doesn't it work that way? Manipulate has the HoldAll attribute . You can force control to evaluate and everything works ok control = {u, 1, 10}; Manipulate[x[u], Evaluate[control]] The problem with this is that the variable u is

Parser for the Mathematica syntax?

假如想象 提交于 2019-12-03 07:28:32
问题 Is there a built parser that I can use from C# that can parse mathematica expressions? I know that I can use the Kernel itself to parse an expression, and use .NET/Link to retrieve the tree structure... But I'm looking for something that doesnt rely on the Kernel. 回答1: My matheclipse-parser module implements a parser in Java which can parse a big subset of mathematica expressions. See the readme.md page for usage. Maybe you can port the parser to C#? 回答2: I wrote a Mathematica parser in 300

How would you do a PivotTable function in Mathematica?

老子叫甜甜 提交于 2019-12-03 07:24:52
问题 PivotTables in Excel (or, cross tabulations) are quite useful. Has anyone already thought about how to implement a similar function in Mathematica? 回答1: 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[#,

Export custom formatted expressions from Mathematica

試著忘記壹切 提交于 2019-12-03 07:15:29
How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting, that is, 72 columns and a continuation marker on the sixth column? I am using Mathematica to generate large and complex analytic expressions, which I then need to insert into pre-existing Fortran77 code. I have everything working correctly in the front end of Mathematica with FortranForm[] and SetOptions[$Output, PageWidth -> 72] However, I can't figure out how to get Mathematica to output correctly to a text file. I want something like this: MM11 = mH1**2 + (g2**2*v1**2)/2. - - (g2**2*(v1**2/2. - - (

Count how many different values a list takes in Mathematica

坚强是说给别人听的谎言 提交于 2019-12-03 06:58:01
I would like to get the number of different values found in a List. For example: The output for the List a={1,2,3,4,5} would be 5 whereas it would be 2 for b={1,1,1,2,2} . Just for amusement, all the following commands also give the desired result: Length@Gather@l Length@Union@l Length@Tally@l Count[BinCounts@l, Except@0] Count[BinLists@l, Except@{}] Length@Split@Sort@l Length@GatherBy[l, # &] Length@Split@SortBy[l, # &] And many more, of course. Edit Here is a little timing experiment (not serious) l = RandomInteger[{1, 10^2}, 10^7]; t2[x_] := {Timing[x], ToString[HoldForm@x]}; SetAttributes

Efficient alternative to Outer on sparse arrays in Mathematica?

两盒软妹~` 提交于 2019-12-03 06:48:01
Suppose I have two very large lists {a1, a2, …} and {b1, b2, …} where all ai and bj are large sparse arrays. For the sake of memory efficiency I store each list as one comprehensive sparse array. Now I would like to compute some function f on all possible pairs of ai and bj where each result f[ai, bj] is a sparse array again. All these sparse arrays have the same dimensions, by the way. While Flatten[Outer[f, {a1, a2, ...}, {b1, b2, ...}, 1], 1] returns the desired result (in principle) it appears to consume excessive amounts of memory. Not the least because the return value is a list of

Secret Santa - Generating 'valid' permutations

眉间皱痕 提交于 2019-12-03 06:38:26
问题 My friends invited me home to play the game of Secret Santa, where we are supposed to draw a lot & play the role of 'Santa' for a friend in the group. So, we write all our names and pick a name randomly. If any of us ends up having their own name picked, then we reshuffle and pick names all over again (the rationale being that one can not be one's own Santa). There are seven of us while playing so I thought of the final 'Santa-allocation' as a permutation of (1:7) onto itself, with some

Plotting a number line in Mathematica

家住魔仙堡 提交于 2019-12-03 06:20:50
I would like to plot a simple interval on the number line in Mathematica. How do I do this? Here's another attempt that draws number lines with the more conventional white and black circles, although any graphics element that you want can be easily swapped out. It relies on LogicalExpand[Simplify@Reduce[expr, x]] and Sort to get the expression into something resembling a canonical form that the replacement rules can work on. This is not extensively tested and probably a little fragile. For example if the given expr reduces to True or False , my code does not die gracefully. numLine[expr_, x