Skip to main content

Posts

front end - Why is SparseArray and InterpolationFunction always grayed out?

In the front end of Mathematica version 10, a new feature was implemented which dims output cells that no longer correspond to its input cells. So when you type 1 + 1 (* 2 *) and go into the input and add another +1 , the 2 is slightly gray to indicate that 1+1+1 is not 2 . SparseArray seem to be always grey, as if they are never up-to-date The same is true for InterpolatingFunction but not for CompiledFunction . Any clues why this is?

string manipulation - Why is StringMatchQ["IP1", "IP"] returning False?

Maybe there is a knot in my head, but I would expect that StringMatchQ["IP1", "IP"] should return True (which it does not) just as StringFreeQ["IP1", "IP"] returns False (which it does). What am I missing? Answer StringMatchQ tests the pattern, and "IP1" doesn't match the pattern "IP", it does match the pattern ___~~"IP"~~___ , but that's a different pattern! Similarly you could write your pattern as StringMatchQ["IP1", "IP*"] StringFreeQ however doesn't just test the entire string, it tests every substring, so in effect the ___~~pattern~~___ is added by the function itself to your pattern.

programming - How can I wrap a C++ object in WSTP?

I am trying to wrap a sophisticated C/C++ API in Mathematica using WSTP, but can't work out how to return a pointer to a C/C++ data structure. This object was created on the C/C++ side of the wrapper, and I want to be able to pass it back to the API as a parameter later on. I know how to wrap basic functions that return simple Mathematica objects like numbers and strings. In a perfect world, I would simply convert C++ objects into Mathematica expressions in my wrapper code. But this API's state cannot be represented as Mathematica expressions, so the objects need to remain on the C/C++ side. I need some way to wrap this state in a Mathematica expression. In other words, I would like to treat these structures as Abstract Data Types. To make my question concrete, consider a silly example. Suppose I have an API written in C for controlling battle robots, and that I want to use Mathematica to guide a robot army to victory over the bad guys. Let's also assume that the RobotLink ...

special functions - Binomial[-1,-1]

According to various sources e.g. http://www.proofwiki.org/wiki/Definition:Binomial_Coefficient and Wolfram themselves http://functions.wolfram.com/GammaBetaErf/Binomial/02/ , the binomial coefficient ${n\choose k}$ is is defined as 0 whenever $k$ and $n$ are negative integers and $k\le n$. But when I type Binomial[-1,-1] Mathematica returns 1 I looked up the documentation for the definition of Binomial and it says In general, ${n\choose m}$ is defined by $\Gamma(n+1)/\Gamma(m+1)\Gamma(n-m+1)$ or suitable limits of this. Apparently, when $n=-1$ or $m=-1$ since $\Gamma(0)$ is not defined the suitable limit case is applied. So, why does Mathematica return 1 for ${-1\choose -1}$? What precisely is the "suitable limits"?

plotting - DensityPlot, ScalingFunctions, and small values

Edit: I figured out I can use Rescale to retrieve the plot as well as get the correct plot legend. I still can't figure out how to rescale the axes from 10^-9 to 1 though... Original I'm trying to make a density plot of a 2D potential energy, but mathematica fails to produce the plots. The system is of relevance for nano-technology so everything is in nano scale, I believe this is the source of my problems. My code looks like cont = DensityPlot[(c1 + c2 q^2) (1 - Cos[2 Pi (x - c4 q)/a]) + (c5 + c6 q^2) (1 - Cos[c7 2 Pi (x)/a]) + c3 q^4, {x, 0, 3*^-9},{q, 0, 1.5*^-10}, PlotPoints -> 200, FrameLabel -> {"x[t]", "q[t]"}, ImageSize -> 400, PlotLegends -> Automatic, ScalingFunctions -> {{1*^-9 # &, 1*^9 # &}, {1*^-9 # &, 1*^9 # &}, # &}] it results in something that looks like this there are two issues with this image: It has been flatly colored blue, however, the the PlotLegend seems to have picked up the right values ...

options - Saving a notebook without output lines

Is it possible to change the way Mathematica saves so that Out[] lines are never included? I have a .nb file that processes a lot of data, and displays most of it as standard output. These graphs, tables, and intensity plots almost double the size of the file. I'd like to easily save these files in a smaller form and also prevent accidentally sending confidential results to users outside my company or not under an NDA. That is, of course, without using Cell -> Delete All Output before each save. I can't be expected to remember to do that all the time! :-P Answer In Options Inspector you can change the EvaluationOptions for Selected Notebook or for Global Preferences by adding {"WindowClose" :> FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]} to the NotebookEventActions line. Screenshots for changing the notebook evaluation options in Options Inspector : A notebook with Input and Output cells and the Evaluation Options page in Option...

plotting - Converting Mesh in DensityPlot to a Graph

Consider the following line of code: DensityPlot[4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1}, Mesh -> All, MeshStyle -> Thick] with the following output: How can I convert the shown mesh into a Graph object such that: All the vertices are aligned at the intersection of the lines, with correct VertexCoordinates . The edges (line segments in the plot) connect the corresponding vertices. Note: If g is the resulting Graph , then the following code should give the same figure as the one above: Show[DensityPlot[4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1}], g] Answer This will do densPlot = DensityPlot[ 4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1}, MeshStyle -> Thick, Mesh -> All]; vertexCoordinates = densPlot[[1, 1]]; length = Length[vertexCoordinates]; graphReadyConnections = DeleteDuplicates@ Flatten[ Cases[#, List[x_, y_, z_] :> {Sort[x \[Undirecte...