mathematica

Import and Export for CSV are both broken in Mathematica

Consider the following 2 by 2 array: x = {{"a b c", "1,2,3"}, {"i \"comma-heart\" you", "i \",heart\" u, too"}} If we Export that to CSV and then Import it again we don't get the same thing back: Import[Export["tmp.csv", d]] Looking at tmp.csv it's clear that the Export didn't work, since the quotes are not escaped properly. Accor...

Convert a Dynamic[] construct to a numerical list

I have been trying to put together something that allows me to extract points from a ListPlot in order to use them in further computations. My current approach is to select points with a Locator[]. This works fine for displaying points, but I cannot figure out how to extract numerical values from a construct with head Dynamic[]. Below...

Doxygen equivalent for Mathematica?

How do you put additional information into a Mathematica package file, like parameter specification doctests/example usage? Up to now, I only found the ::usage string and some information on how to write documentation notebooks. I am looking for an option to generate these documentation notebooks from introspecting package files. ...

Empty graphics when using Hue in a Raster?

Why does the following code Graphics[Raster[{{Hue[1], Hue[1/3]}, {Hue[2/3], Hue[1/6]}}]] not produce any output? In Mathematica < 6 RasterArray was able to handle this and produced the same output as Graphics[Raster[{{{1, 0, 0}, {0, 1, 0}}, {{0, 0, 1}, {1, 1, 0}}}]] ...

Version control of Mathematica notebooks

Mathematica notebooks are, of course, plaintext files -- it seems reasonable to expect that they should play nice with a version-control system (git in my case, although I doubt the specific system matters). But the fact is that any .nb file is full of cache information, timestamps, and other assorted metadata. Scads of it. Which mean...

Using Mathematica to generate crystal lattices

How do you generate a 3x3x3 lattice in Mathematica? Is it possible to color some of the lattice points? It seems that it is possible but I cannot get it to work so far http://reference.wolfram.com/mathematica/ref/LatticeData.html What I mean by 3x3x3 is something like figure (c) on the right:http://physics.ucsd.edu/was-sdphul/labs/2dl/...

Complicated programming and math tasks online. Any?

Possible Duplicate: What are some good websites for programming puzzles? Maybe it is not very thematic question in here, but I guess it will be interesting not only to me. I hope. So, I just want to get some cool tasks to do using programming languages or just pen and sheet of paper. I guess it can lead to improving my abilit...

Combining graphs in Mathematica

Any idea how I can overlay the following two functions to compare them? ln[1]:= p1 = Plot[(E^((Pi/6)^(1/3)/x) (Pi/6)^(2/3))/((-1 + E^((Pi/6)^(1/3)/x))^2 x^2), {x, -2.2, 2.2}] ln[2]:= p2 = Plot[(E^((Pi/6)^(1/3)/t) (Pi/6)^(2/3))/((-1 + E^((Pi/6)^(1/3)/t))^2 t^2), {t, 0, 2.0}] When I try Show[p1,p2] it doesn't work ...

6^x = 5 equation, how to solve it?

If it would be 6^x = 1 or 6^x = 6 or 6^x = 36 it would be extremely easy, but how to solve this equation: 6^x = 5 I don't need an answer, I want to find out how to solve equations like this one, I need solution. Thanks. ...

Plotting horizontal and vertical lines in Mathematica

In Mathematica, how do you plot a horizontal line at a given number? How do you plot a vertical line at a given number? ...

Two quick Mathematica questions

How do I remove the numbers on the x-axis only not the y-axis? Is it possible to shift the y-axis without shifting the functions? What I mean is, instead of having the y-axis at x = 0, could I have it at x = -5? ...

How to generate named patterns in Mathematica?

In principle, what I want to use the following to generate a named pattern for later use: In[1]:= Replace[var["x"],var[name_]:>Pattern[Apply[Symbol,name],_]] I expected to see this result. A named pattern which I can use in subsequent rules: Out[1]= x_ But instead, I got: Out[1]= Pattern[Symbol @@ x,_] The documentation says tha...

Take positive square root in Mathematica

Hi all, I'm currently doing some normalization along the lines of: J = Integrate[Psi[x, 0]^2, {x, 0, a}] sol = Solve[J == 1, A] A /. sol For this type of normalization, the negative square root is extraneous. My results are: In[49]:= J = Integrate[Psi[x, 0]^2, {x, 0, a}] Out[49]= 2 A^2 In[68]:= sol = Solve[J == 1, A] Out[68]= {{A -...

ShowGraph[ { {e1,e2}, {e1, e3} }, {e1,e2,e3} ]; // what is the problem here?

doesn't show specified graph in Mathematica Graph Theory package 'Combinatorica'. ...

scaling axes in Mathematica

I'm sure this is an incredibly simple question but I've recently started using Mathematica so it's all new to me. How do you scale the y axis? I try the following but it won't compile. Plot[y = {Exp[-(x^2+3x+2)]}, {x, 0, 5}, {y, 0, 1}] ...

Bug in Mathematica's Integrate with PrincipalValue->True

It seems that Mathematica's handling of principal value integrals fails on some corner cases. Consider these two expressions (which should give the same result): Integrate[UnitBox[x]/(x0 - x), {x, -Infinity, Infinity}, PrincipalValue -> True, Assumptions -> {x0 > 0}] /. x0 -> 1 // Simplify Integrate[UnitBox[x]/(x0 - x) /. x0 -> 1, {x,...

Mathematica equivalent of Ruby's inject

Is there a Mathematica function like inject in Ruby? For example, if I want the product of the elements in a list, in Ruby I can write: list.inject(1) { |prod,el| prod * el } I found I can just use Product in Mathematica: Apply[Product, list] However, this isn't general enough for me (like, if I don't just want the product or sum o...

How to construct a list of Set's

I have a large set of parameters P which take several distinct sets of values V_i and want to use ActionMenu[] to make assigning P=V_i easy, like so: ActionMenu["Label", {"name_1" :> (P = V_1;),..}] Now the problem is that the set of V_i's is large and not static, so instead of coding a long list {"opt_1" :> (P = V_1;),..} over and ov...

Sample uniformly at random from an n-dimensional unit simplex.

Sampling uniformly at random from an n-dimensional unit simplex is the fancy way to say that you want n random numbers such that they are all non-negative, they sum to one, and every possible vector of n non-negative numbers that sum to one are equally likely. In the n=2 case you want to sample uniformly from the segment of the line ...

AbsoluteTime with numeric argument behaves strangely.

This is strange: DateList@AbsoluteTime[596523] returns {2078, 7, 2, 2, 42, 9.7849} But DateList@AbsoluteTime[596524] returns {1942, 5, 26, 20, 28, 39.5596} The question: What's going on? Note that AbsoluteTime with a numeric argument is undocumented. (I think I now know what it's doing but figured this is useful to have as a...