title: Renaming and indexing list of rules

text: I have a list of rules that represents a list of parameters to be applied to a circuit model (Wolfram SystemModeler model):               sk = {     {R1 -> 10080., R2 -> 10080., C1 -> 1.*10^-7, C2 -> 9.8419*10^-8},     {R1 -> 10820., R2 -> 4984.51, R3 -> 10000., R4 -> 10000., C1 -> 1.*10^-7,     C2 -> 1.85417*10^-7},     {R1 -> 12600., R2 -> 12600., C1 -> 1.*10^-7, C2 -> 6.29882*10^-8},     {R1 -> 16420., R2 -> 16420., C1 -> 1.*10^-7, C2 -> 3.70897*10^-8},     {R1 -> 26120., R2 -> 26120., C1 -> 1.*10^-7, C2 -> 1.46573*10^-8},     {R1 -> 76600., R2 -> 1283.61, R3 -> 10000., R4 -> 10000., C1 -> 1.*10^-7,      C2 -> 1.01704*10^-7}};      Before I can apply these values to the model parameters I have to rename them. The list above consists of six lists - four lists of four rules and two lists of six rules. Those that have 4 rules should be named "sallenKeyUnityGain" and those that have 6 rules should be named "sallenKey". This is what I have so far:               Table[If[Length[sk[[i]]] > 4, cirname = "sallenKey", cirname = "sallenKeyUnityGain"];     (cirname <> ToString[i] <> "." <> ToString[sk[[i]][[All, 1]][[j]]]) -> sk[[i]][[All, 2]][[j]]     , {i, Length[sk]}, {j, Length[sk[[i]]]}]      And this is the output:               {{"sallenKeyUnityGain1.R1" -> 10080., "sallenKeyUnityGain1.R2" -> 10080.,      "sallenKeyUnityGain1.C1" -> 1.*10^-7, "sallenKeyUnityGain1.C2" -> 9.8419*10^-8},     {"sallenKey2.R1" -> 10820., "sallenKey2.R2" -> 4984.51, "sallenKey2.R3" -> 10000.,      "sallenKey2.R4" -> 10000., "sallenKey2.C1" -> 1.*10^-7,     "sallenKey2.C2" -> 1.85417*10^-7},     {"sallenKeyUnityGain3.R1" -> 12600., "sallenKeyUnityGain3.R2" -> 12600.,      "sallenKeyUnityGain3.C1" -> 1.*10^-7, "sallenKeyUnityGain3.C2" -> 6.29882*10^-8},     {"sallenKeyUnityGain4.R1" -> 16420., "sallenKeyUnityGain4.R2" -> 16420.,      "sallenKeyUnityGain4.C1" -> 1.*10^-7, "sallenKeyUnityGain4.C2" -> 3.70897*10^-8},      {"sallenKeyUnityGain5.R1" -> 26120., "sallenKeyUnityGain5.R2" -> 26120.,      "sallenKeyUnityGain5.C1" -> 1.*10^-7, "sallenKeyUnityGain5.C2" -> 1.46573*10^-8},      {"sallenKey6.R1" -> 76600., "sallenKey6.R2" -> 1283.61, "sallenKey6.R3" -> 10000.,      "sallenKey6.R4" -> 10000., "sallenKey6.C1" -> 1.*10^-7,     "sallenKey6.C2" -> 1.01704*10^-7}}      This would work fine if all were sallenKey or if all were sallenKeyUnityGain. However, I would like the output to look like this:                {{"sallenKeyUnityGain1.R1" -> 10080., "sallenKeyUnityGain1.R2" -> 10080.,      "sallenKeyUnityGain1.C1" -> 1.*10^-7, "sallenKeyUnityGain1.C2" -> 9.8419*10^-8},     {"sallenKey1.R1" -> 10820., "sallenKey1.R2" -> 4984.51, "sallenKey1.R3" -> 10000.,      "sallenKey1.R4" -> 10000., "sallenKey1.C1" -> 1.*10^-7,      "sallenKey1.C2" -> 1.85417*10^-7},     {"sallenKeyUnityGain2.R1" -> 12600., "sallenKeyUnityGain2.R2" -> 12600.,      "sallenKeyUnityGain2.C1" -> 1.*10^-7, "sallenKeyUnityGain2.C2" -> 6.29882*10^-8},     {"sallenKeyUnityGain3.R1" -> 16420., "sallenKeyUnityGain3.R2" -> 16420.,      "sallenKeyUnityGain3.C1" -> 1.*10^-7, "sallenKeyUnityGain3.C2" -> 3.70897*10^-8},      {"sallenKeyUnityGain4.R1" -> 26120., "sallenKeyUnityGain4.R2" -> 26120.,      "sallenKeyUnityGain4.C1" -> 1.*10^-7, "sallenKeyUnityGain4.C2" -> 1.46573*10^-8},      {"sallenKey2.R1" -> 76600., "sallenKey2.R2" -> 1283.61, "sallenKey2.R3" -> 10000.,      "sallenKey2.R4" -> 10000., "sallenKey2.C1" -> 1.*10^-7,     "sallenKey2.C2" -> 1.01704*10^-7}}      In other words, if I have 4 apples and 2 oranges, instead of having:   apple1, orange2, apple3, apple4, apple5, orange6, I would like:   apple1, orange1, apple2, apple3, apple4, orange2. How would I do this?   Thank you   Tatjana


title: Discrete inequality plotting

text: I have an equation like this: $${20 \choose k}\cdot \sum_{i=0}^k {k \choose i}\cdot i \leq 1+f$$. I want to plot this inequality as the dependency between `k` and `f`. I found a commend `RegionPlot` but I don't know how to correctly use it in such equation.


title: Plot legend inside a Show

text: > **Possible Duplicate:**   >  Using PlotLegends with Show messes up the graphics I have created a composite plot function: ![enter image description here](http://i.stack.imgur.com/0uCZd.png) I want to add a legend to it, but `<< PlotLegends`` seems not to work, when inside a Show (Mathematica 8). Plots will probably be printed, so `Tooltip` won't work. How can I create a legend for a plot?


title: Solve the system of equalities and inequalities

text: I have a system of expressions, in which each expression is an equality or inequality expression of the following form:   * Var = Var1 + Var2   * Var $\odot$ number   * Var $\odot$ Var1   * $\odot$ = $\leq | \geq | == | > | <$ I want to find the range of values for each variable, is this possible to do that by Mathematica? **Update example** I tried with `Reduce` but it didn't work as I expected. For example, I tried `Reduce[a == b + c && a >= 2 && b <= 10 && c == 5, {a, b, c}]`, it returned `2 <= a <= 15 && b == -5 + a && c == a - b`. What I expect to get is `2 <= a <= 15 && -3 <= b <= 10 && c == 5` Thanks,


title: Plotting equations of motion of a baseball

text: So I went through the physics of a baseball and I got the exact same equations as shown here on page 8. I input all of the same parameters into my code, and I don't get the same thing. Any idea where I am going wrong?               ClearAll[t, x, y, z];     parms = {Cd -> .3, Cm -> 1, ωx -> -1500, ωy -> 0, ωz -> 0, m -> .142, ρ -> 1.225, A -> .608, R -> .22};     term = Sqrt[x'[t]^2 + y'[t]^2 + z'[t]^2];     eq1 = m x''[t] == -(1/2 ρ*A*Cd*x'[t]*term) + (4 π*ρ*R^3*(ωy*z'[t] - ωz*y'[t]));     eq2 = m y''[t] == -(1/2 ρ*A*Cd*y'[t]*term) + (4 π*ρ*R^3*(ωz*x'[t] - ωx*z'[t]))-9.81*m;     eq3 = m z''[t] == -(1/2 ρ*A*Cd*z'[t]*term) + (4 π*ρ*R^3*(ωx*y'[t] - ωy*x'[t]));     ic1 = {x'[0] == 0, x[0] == 0};     ic2 = {y'[0] == 0, y[0] == 1.6};     ic3 = {z'[0] == 90, z[0] == 0};     sol = NDSolve[{eq1, eq2, eq3, ic1, ic2, ic3} /. parms, {x[t], y[t], z[t]}, {t, 0, 1}];     ParametricPlot[Evaluate[{z[t], y[t]} /. sol], {t, 0, .01}, PlotRange -> 1.8]      This should be the same as the bottom image on page 13.


title: How to plot a parametric region representing a coordinate transformation

text: The Wikipedia page on Rindler coordinates shows a nice example of how a coordinate transformation can be represented in a plot. They start with two coordinates $T,X$ with $0 < X < \infty,\; -X < T < X$. Then, they introduce two new coordinates $t, x$ by $\begin{align*}t &= \mathrm{artanh}\left(\frac{T}{X}\right) \\\ x &= \sqrt{X^2-T^2}\end{align*}$ From the plot below, it is clear how curves of constant $x$ and constant $t$ run in the old coordinate system: ![Coordinate transformation from \(T,X\) to \(t,x\)](http://i.stack.imgur.com/Pj00M.png) How could you make a clear plot like this with _Mathematica_? I would like to include the labels as well. I guess you need the inverse transformations to express T and X in terms of t and x. I entered them below               T = x Sinh[t]     X = x Cosh[t]


title: Labeling a plot frame

text: I am trying to label the frame of an overlay plot I have made. However, it is not working at all. Here is my code:               A2 = A[[15 ;; 31, 2]];     PlotA = ListLinePlot[A2, PlotStyle -> Red, ImagePadding -> 25,         Frame -> {True, False, True, True},         FrameTicksStyle -> Directive[15],         FrameTicks -> {{{2, 1995}, {7, 2000}, {12, 2005}, {17, 2010}},           None, {{2, 1995}, {7, 2000}, {12, 2005}, {17, 2010}}, All},         FrameStyle -> {Automatic, Automatic, Automatic, Red},         FrameLabel -> {{False, "Consumption"}, {"Year", "Year"}}];     C2 = Consumption[[1 ;; 17, 2]];     PlotC = ListLinePlot[C2, PlotStyle -> Blue, ImagePadding -> 25,         Frame -> {False, True, False, False},         FrameTicksStyle -> Directive[15],         FrameStyle -> {Automatic, Blue, Automatic, Automatic},         FrameLabel -> {{False, "Affordability"}, {False, False}} ];     Overlay[{PlotA, PlotC}]      ![enter image description here](http://i.stack.imgur.com/HhcBW.jpg) Am I going about it the right way? When the plot is displayed, no labels are visible.


title: How do I create inline TraditionalForm expressions, and control their formatting?

text: > **Possible Duplicate:**   >  How to replace the style of the inline cell in a StyleSheet I'm trying to figure out the best practice for creating short, inline expressions that display as `TraditionalForm` within paragraphs of text, and to understand how to control the style used for expressions. For example, what I'd like to be able to is   * select some text and press a key or choose a style and have that selection display as `TraditionalForm`, and   * while typing, within a paragraph, be able to toggle `TraditionalForm` on and off. Ideally I'd also like to have the formatting or style of such expressions controlled by a (character, as opposed to paragraph) style. One approach that would seem to do this is just to apply the default "InlineFormula" style, but that has no apparent effect, and clearly is intended for some other purpose. Another might be to select text and choose "Cell > TraditionalForm Display", but that changes the whole cell. Selecting text and choosing an item from the "Typesetting Forms" palette works (or using the corresponding command keys), but all of the items in that palette add additional elements structure (e.g. superscripts) in addition to converting the selected text to `TraditionalForm`. Is there some straightforward way to just toggle inline `TraditionalForm` on and off? Can I control the (character) style of such selections.


title: How to set Math text size & line spacing

text: I have chosen different font for text. Unfortunately this font is larger than the standard Times font. So all math symbols (e.g. greek) are now a little too small. If I could just set the FontSize for the math font to 13 it would probably look good. How do I accomplish that? If it is not that simple: In defining a custom Style via Stylesheet (or private Style Definitions), what is the correct way to define a custom size for the math font. There are Style definitions for "Display Formula" and "Inline Formula", but if I type just an inline cell, the latter does not apply.


title: What's wrong with my palindrome finding function?

text: I'm trying to find the palindromes in the dictionary, but my output isn't giving me all of them. I have this so far               Palindrome[] := DictionaryLookup[y_ /; (y == StringReverse[y])]     Palindrome[]      And my the output just it gives me `{a,I}`. What's wrong with my input? I don't see it. * * * Thanks.


title: Switching parameter lines on/off in a 3D parametric plot

text: In a classroom demonstration for               ParametricPlot3D [{f[u, v], g[u, v], h[u, v]}, {u, ... }, {v, ... }]      I want to show   * u lines only without v,   * v lines only without u,   * no lines, only surface,   * no surface, only u, v lines.  How can it be done?


title: How do I assign specific data points in an array to a new array?

text: I am trying to learn how to script/program in mathematica and I am retyping some simple C and FORTRAN programs into Mathematica as a way to learn. I am writing a Monte Carlo code to calculate the value of pi. In the method attached a 10000x2 dimensional array is created using table with values ranging from 0 to 1. The magnitude of each row of the array is determined inside a For loop and if it is greater than 0 it is rejected and if it is less it is used in the running tally that is divided by the total number of points and then multiplied by 4 to give an estimate of pi. On top of calculating pi, I would like to create two more arrays to use in a list plot. In a second array I would like to store values of the first array that met the rejection criteria and in third array I would like to store values that were rejected, so I can plot the rejected points as red and the accepted points as blue. However, no matter what I try Mathematica will not seem to let me transfer points from the first array titled "vector". I am attaching the current code to this question that effectively calculates the estimate of pi. If anyone can show me how to transfer the rejected points to another array as determined inside the For loop I would be very grateful. `[counter, samples, a, vector, tally, pi, tally2] counter = 1; samples = 10000; tally = 1; a := Random[Real, {0, 1}]; Timing[vector = Table[a, {i, samples}, {j, 2}]; For[i = 1, i <= samples, i++, {If[Norm[vector[[i]]] < 1, tally++, ""]}]; pi = (tally/samples)*4 // N]` `


title: How can I implement the method of Lagrange multipliers to find constrained extrema?

text: I want to form the function $h=f-\lambda_{1}g_{1}-\lambda_{2}g_{2}$ where $f$ is the function to optimize subject to the constraints $g_{1}=0$ and $g_{2}=0$ so that I can solve the first partial derivatives with respect to $\lambda_{1}$ and $\lambda_{2}$. Can someone get me started using $f(x,y,z)=xy+yz$ subject to the constraints $x^2+y^2-2=0$ and $x^2+z^2-2=0$?


title: Adding Elements to a List of Lists

text: I'm trying to do the following: Given a function `f[x,y]`, I want to turn the list `{{x1,y1},{x2,y2},...,{xn,yn}}` into `{{x1,y1,f[x1,y1]},{x2,y2,f[x2,y2]},...,{xn,yn,f[xn,yn]}}`. In other words, I want to replace each 2-tuple in the original list of lists with a 3-tuple, where the 3rd element is a function evaluated using the 2-tuple. For example, if `f[x,y]` is `x+y`, then I'd want `{{1,2},{5,6}}` to be turned into `{{1,2,3},{5,6,11}}`. I've seen syntax for many similar tasks, but not one quite like this. I would tremendously appreciate any help -- I've been stumped on this one for a while!


title: NDSolve - 2nd order ODE - how to solve for y and y'

text: i am trying to workout how to solve a simple 2nd order ODE for y and y'. I can solve for y[t] as follows but how can i solve for y[t] and y'[t] ?               m = 1; g = 9.82;     sol = Flatten @         NDSolve[{y''[t] == -m g - 0.3 y'[t], y'[0] == 10, y[0] == 0,           WhenEvent[y[t] < 0, tmax = t; "StopIntegration"]},          y[t], {t, 0, 3}];     Plot[y[t] /. sol, {t, 0, tmax}]      Also the output from NDSolve is an interpolating function but how do i turn this into a function ? i.e i thought it would be something like this but that doesn't seem to work ?               g[t_]:= y[t]/. sol       Thanks David.


title: using a Mathematica function to define a new function

text: I'd like to define a function of three variables which produces a new, named function of a single variable, where this final variable is not a member of the first three. So I'd like something where I have `f0[x_ , y_ , z_] := << complicated function >>` which gives `f1[p_]` Furthermore, I'd like to have the functions be defined in such a way that when I write `IN:= f0[x0,y0,z0]` I get `OUT:= fx0y0z0[p_]` so that I can easily identify which inputs produced the function. So, basically, I'd like to wind up with a function produced via Interpolation and I'd like that function to have a specific name defined by my inputs. For instance, let's say I'm creating a numerical function by writing down a table in two variables (say, p and q) that requires x, y, and z as inputs. Then I'd like to integrate over q and interpolate over p so that my final function is just a function over q only. So, let's say that my first function is `g[x_,y_,z_,p_,q_] := (x + y + z) p / q` Now I'd like to tabulate this over p and q for given values of x, y, and z. Then I'd like to integrate over p and have a function of q only. I can for instance do the following `f1[x_,y_,z_] := NIntegrate[ Interpolation[ Flatten[Table[{q, p, g[x,y,z,p,q]}, {p,p0,p1}, {q,q0,q1}],1]][#, p], {p, p0, p1}] &` and then this is a well-behaved function of q which I can make tables of, which I can then plot, integrate, etc. just by writing f1[x0,y0,x0][q]. But this is not very convenient for me since it requires me to write out a new function name every time I want to examine the behavior as a function of different values of x, y, and z, and I will ultimately need many values of x, y, and z. Is there any way to write a meta-function that is capable of producing a brand new interpolating function of q only, with the name including the input values of x, y, and z? Thanks for your help, Sam


title: Chart with its ticks in geometric progression

text: I have to render a chart with an axis that has ticks with the following values:               250, 500, 1000, 2000, 4000, 8000      I first thought it was a logarithmic scale. But then I realized the pattern here is simpler (a tick has the value of the previous tick * 2). ![custom scale](http://i.stack.imgur.com/7IUct.png) Does this type of scale have its own name, or is it simply a logarithmic scale with a "special" base?


title: How do I stack a RectangleChart?

text: What I would like to do is represent the state of a machine over a period of time using a RectangleChart (or anything else that can do it) . The chart will need to be made up of equally sized blocks that change colour based on the state of the machine (there are 7 states 1-7) at that time. I've created this chart which is similar to what I want;               data = Table[{RandomInteger[{1, 7}], 5}, {i, 1, 20}];     RectangleChart[data, ChartLayout -> "Stacked", BarOrigin -> Left]      ![Almost what I'm after](http://i.stack.imgur.com/7YwOj.jpg) The problem with this chart is my state data is being represented by the height of the bar, not the colour. What is the best way to get the results I'm after?


title: How to do conditional matrix division when elements are a combination of zero and real numbers?

text: I tried to divide two large matrices DLand PL of size 100,000 x 5 each and they look like this, DL=![enter image description here](http://i.stack.imgur.com/WpATf.png) and PL=![enter image description here](http://i.stack.imgur.com/vwcHi.png) By using conditional function:               Spread1[DL_, PL_] := SparseArray[ {i_, j_} /; PL[[i, j]] != 0 :> 100000 DL[[i, j]]/PL[[i, j]], {1000, 5}]          test = Spread1[DL, PL];     MatrixForm[test]      and then I get result as shown, but why do I get those messages and some of the resulting test matrix elements say ComplexInfinity? Not sure if I should ignore those messages as all zero elements are aligned? ![enter image description here](http://i.stack.imgur.com/wol1z.png)


title: Finding linearly independent combination of vectors with a certain symmetry property

text: I have two linearly independent vectors $v_1$ and $v_2$. Is there a way for me using Mathematica to find two linear combinations $w_1$ and $w_2$ such that:   1. $w_1$ and $w_2$ are linearly independent.   2. If I cut $w_2$ in half and re-order the halves to get $w_2'$, i.e. $w_2=\\{1,2,3,4,5,6\\}\rightarrow w_2'=\\{4,5,6,1,2,3\\}$, then $w_2'=w_1$? $v_1$ and $v_2$ are chosen such that I am guaranteed $w_1$, $w_2$ exist.


title: Specifying shortcut without modifying KeyEventTranslations.tr

text: Until recently, I followed the suggestions(e.g., http://stackoverflow.com/questions/7327411/is-there-a-way-around-using-and- for-part-in-mathematica) to introduce some new shortcuts. However, I moved to another place recently, and here I am not allowed to modify `KeyEventTranslations.tr` personally. (I am now a user of linux system) To find an alternative solution, I encountered this post. Best way to add KeyEvents and faster Quit In the selected answer, the author introduced a seemingly alternative way but honestly I don't quite understand what it does and how I revise it to meet my needs. Can you show me some simple examples in this direction? Or, it would be great if you suggest another solution.


title: How can I use several data fields drawn from curated data at once?

text: How can I use `"MinTemperature"`, `"MaxTemperature"`, and `"Temperature"` properties of `WeatherData` for one or more cities in one line of code?


title: How can I improve the speed of eigenvalue decompositions for large matrices?

text: I often need to compute the eigenvalues of large matrices, and I invariably resort to MATLAB for these, simply because it is much faster. I'd like to change that, so that I can work entirely inside my notebook. Here's a plot comparing the timings between the two for eigenvalue decompositions for matrices of varying sizes (left). The y-axis shows the time in seconds. As you can see, there's about a factor 3 difference between the two (right). ![enter image description here](http://i.stack.imgur.com/w8cAnm.jpg) ![enter image description here](http://i.stack.imgur.com/3i8V5m.jpg) Here's a sample code in Mathematica to generate timings:               timings = With[{x = RandomReal[NormalDistribution[], {#, #}]},        Eigenvalues[x]; // Timing // First] & /@ Range[500,5000,500]      and its equivalent in MATLAB:               s = 500:500:5000;     t = zeros(numel(s),1);     for i = 1:numel(s)         x=randn(s(i));         t1=tic;eig(x);t(i)=toc(t1);     end      I do not think that Mathematica's algorithms are inefficient, as the fastest algorithms for eigenvalue decompositions (in the general case, not exploiting symmetry and such) are $\mathcal{O}(N^{2.376})$ and the timings both MATLAB's and Mathematica's implementations have the same correct slope on a log-log plot. I suspected unpacking in the background during the call to `Eigenvalues` and turning `On["Packing"]` confirms this. However, I don't think this alone could be the cause for a 3 fold speed reduction. I'm not expecting the timings to be exact either, as I understand that arrays and matrices are baked into the core of one and not the other, which can lead to performance differences. However, I'm interested in knowing if   1. there are reasons other than the simplified one I gave above for the difference in timings and    2. there ways in which I can improve the speeds or at least, reduce the difference by _some_ amount. Or is this something that one has to accept as a fact of life?


title: Cleaning up InverseLaplaceTransforms in Mathematica

text: I am attempting to use _Mathematica_ to model an electrical circuit in the s domain. The circuit contains capacitances and and inductances. I've written a series of equations using Kirchoff's laws to solve for various currents in the circuit; however, this output is in the s domain. I would like to transform the output back into the time domain. The outputs that I obtain using `ExpToTrig[InverseLaplaceTransform[expr,s,t]]` are large and complicated. They contain several complex sin and hyperbolic sin terms. I know, from my knowledge of the circuit that the time domain solution should consist of three or four exponentially decaying terms and a single steady state sinusoid. How can I convert this complicated output into one that consists of a few decaying exponentials and a single, phase shifted sinusoid? The s domain expression for ig that I want to transform into the time domain is:               ig=(3.25269*10^7 s)/((424000. + 923. s) (142122. + s^2))      Below, I have copied some of the code that I've tried.               In[168]:= ig = (      3.2526911934581187`*^7 s)/((424000.` +          923.` s) (142122.30337568675` + s^2))          Out[168]= (3.25269*10^7 s)/((424000. + 923. s) (142122. + s^2))          In[169]:= ExpToTrig[InverseLaplaceTransform[ig, s, t]]          Out[169]=      3.25269*10^7 (-1.40932*10^-6 Cosh[          459.372 t] + (Cos[(376.991 + 0. I) t] -            I Sin[(376.991 + 0. I) t]) ((7.0466*10^-7 +              5.78292*10^-7 I) + (7.0466*10^-7 -               5.78292*10^-7 I) Cos[(753.982 + 0. I) t] + (5.78292*10^-7 +               7.0466*10^-7 I) Sin[(753.982 + 0. I) t]) +         1.40932*10^-6 Sinh[459.372 t])          In[170]:= Simplify[%]          Out[170]=      3.25269*10^7 (-1.40932*10^-6 Cosh[          459.372 t] + (Cos[(376.991 + 0. I) t] -            I Sin[(376.991 + 0. I) t]) ((7.0466*10^-7 +              5.78292*10^-7 I) + (7.0466*10^-7 -               5.78292*10^-7 I) Cos[(753.982 + 0. I) t] + (5.78292*10^-7 +               7.0466*10^-7 I) Sin[(753.982 + 0. I) t]) +         1.40932*10^-6 Sinh[459.372 t])          In[171]:= FullSimplify[%]          Out[171]= 0. -       45.8409 E^(-459.372 t) + (22.9204 + 18.81 I) E^((0. - 376.991 I) t) +       (22.9204 - 18.81 I) E^((0. + 376.991 I) t)          In[172]:= ExpToTrig[%]          Out[172]= 0. + (45.8409 + 0. I) Cos[(376.991 + 0. I) t] -       45.8409 Cosh[459.372 t] + (37.6201 + 0. I) Sin[(376.991 + 0. I) t] +       45.8409 Sinh[459.372 t]


title: InputField Insertion Point Movement

text: I am trying to make the Return Key move the insertion point to the end of the input field's text. Please see the example below for the problem I am facing. Namely, when the return key is pressed, the input field's text is updated but the insertion point is not moved.               DynamicModule[{thing = "foo"}, nb = EvaluationNotebook[];EventHandler[InputField[Dynamic@thing,String], {"ReturnKeyDown" :> (thing = thing <> "bar";SelectionMove[nb, Next, Word])}]]


title: Why cannot import 3ds file into 3dsmax

text: ![enter image description here](http://i.stack.imgur.com/jdjBI.jpg) ![enter image description here](http://i.stack.imgur.com/FB7Od.jpg) The obj file can be imported into max rightly, but when I import the .3ds file into max I get some camera objects. Some 3ds files can be imported into max. What's wrong with the file? Is it possible to change something in Mathematica and make the .3ds file could be imported into 3dsMax? my file is here:


title: Ordering the Boundary points of a Polygon

text: I feel like this should be simple, but I keep running into walls. Say someone gives you the coordinates of the vertices of a pentagon and the center point of the hexagon. Is there any way to get an "ordered" list of the boundary points? Let me try to put this in a picture. For instance, if someone gave me a list `{+,m,\pi,[],2}` plus the center point C, and I plot it and find                                  2                      m              +                        C                         []     \pi      Is there anyway I can extract the list: `{2,+,\pi,[],m}` up to cyclic permutation? Ideally I would like to be able to differentiate orientations, clockwise vs counterclockwise, but I don't really care about cyclic permutation. Thanks for any help in advance! Big CRUCIAL edit: Thanks everyone for your help, I have been trying lots of suggestions, but I let out a crucial element in all of this. **My points are in 3D!** It seems to me that all of these routines, ConvexHullMesh, FindCurvePath, etc. all work with **2D** coordinates. I was thinking about trying to project onto a plane perpendicular to the central point, since I know the center, but that might be too lengthy. * * * Here are the points: Center:               {0.951057,-0.309017,0.}      Neighbors:               {{0.723607, -0.525731, -0.447214}, {0.850651, 0., -0.525731}, {0.894427, 0., 0.447214},       {0.951057, 0.309017, 0.}, {0.587785, -0.809017, 0.}, {0.688191, -0.5, 0.525731}}


title: Interpolation of 4D data

text: To create a table and an interpolation function of 3D data T=f(X,Y) I have the answer here: interpolation of 3D data How to create a table/interpolation function of 4D data T=f(X,Y,R)? If I do               dada = Flatten[Table[{x, r, t, func[x, r, t]}, {x, 0, 1}, {r, 0, 0.12}, {t, 0,       1}], 1];     intfunc=Interpolation[data];      doesn't work. func[x,r,t] is a valid function for this domain. I think it has to do with Flatten.


title: Recursive function with array of variables

text: I am trying to create a recursive function which works with an increasing array of variables. Since the formula is quite complex, i will try to simplify my example to the core of my problem. The initial value of the array should be $f[\\{1\\}]=2$ and all other arrays with a single element should have the value $0$. When an array of size $n$ is given to the function, it will reduce the size of the array to $n-1$ by dropping the first element. So if an array with the values $\\{0,0,1,0,2\\}$ is given, it will reduce it to $\\{0,1,0,2\\}$, or more generally the array $\\{r_5 ,r_4 ,r_3 ,r_2 ,r_1\\}$ will be reduced to $\\{r_4 ,r_3 ,r_2 ,r_1\\}$. The computation in this case should be: $$f[\\{r_5 ,r_4 ,r_3 ,r_2 ,r_1\\}]=(r_4 -1)*f[\\{r_4 -1,r_3 ,r_2 ,r_1\\}]+(r_3 -1)*f[\\{r_4 ,r_3 -1,r_2 ,r_1\\}]+(r_2 -1)*f[\\{r_4 ,r_3 ,r_2 -1,r_1\\}]+(r_1 -1)*f[\\{r_4 ,r_3 ,r_2 ,r_1-1\\}]$$ To speed up the computation, the function should memorize results and arrays containing a negative element ($-1$) should not be computed and instead given the value 0. My attempt so far starts with:               f[r_] := f[r] = With[{n = Length[r], k = Rest[r]}      ... To change the values of the $r_i$, I generated a For-Loop (from $1$ to $n$) containing:               f[ReplacePart[k, -i -> Part[k, -i] - 1]]      Any help is highly appreciated.


title: How can I ensure graphics exported in WMF format don't have text-spacing problems?

text: A lot of my work involves manipulating data, drawing a pretty plot of it and then inserting that graphic into a report written in Microsoft Word, under Windows.1 The fun comes with the exporting part. If the audience don't have the Mathematica fonts installed, negative signs, parentheses etc will come up as missing-characters in the WMF graphic and in Word. You can fix this using the `PrivateFontOptions` option, either in the notebook or in the Options Inspector.               SetOptions[$FrontEnd, PrivateFontOptions -> {"OperatorSubstitution" -> False}]      But I still find the output a bit disappointing, in that the spacing around parentheses and other characters in the WMF file looks wrong (sorry, I can't show the whole graphic because the data are confidential). ![enter image description here](http://i.stack.imgur.com/DKmZb.png) The code to produce the graph above rests partly on a package, so here is a minimal example:                test = Grid[{{DisplayForm[            AdjustmentBox[       Style["Source: REDACTED (confidential)", 13,         FontFamily -> "Arial", Black],              BoxMargins -> {{3, 0}, {0, 0}}]]}}]      ![enter image description here](http://i.stack.imgur.com/cF2wT.png) This is how it looks in Win7 and Office 2010: the first two are with operator substitution ON, the second pair are with operator substitution OFF. There is still a bit too much space but it is better than in Word 2007. ![enter image description here](http://i.stack.imgur.com/A6Heo.png) As highlighted, there is just too much space between the text and the closing parenthesis. This is not apparent in the Mathematica notebook, where it looks just fine. It must be something to do with Mathematica's WMF export routine: other applications with WMF export don't do this. Is there any way of automatically ensuring that the spacing around letters in the resulting WMF file is a bit more acceptable? Some kind of auto-kerning option? Ideally it should be something I can set in a package so my colleagues don't have to know the internals of how to do it. 1Actually I have people to do that now, but you get the idea.


title: UnFlatten an array into a ragged matrix

text: Trying to unflatten an array that was part of ragged array of sub matrices. As input we have flattened array:                 myflatarray={7.7056, 4.20225, 3.02775, 7.60807, 9.77169, 6.18476, 4.80993,        6.32965, 2.69882, 0.268505, 1.78048, 9.67702, 0.875699, 7.18504,         1.62811, 0.0313174, 5.66048, 1.61613, 5.71987, 0.971484, 3.87503,         2.8537, 2.68776, 3.47433, 2.81483, 4.0387, 1.74939, 3.12037, 4.18016,         2.35264, 0.853583, 1.22412, 0.382633, 3.67874, 8.68059, 8.02419,         6.9547, 7.11112};      and the original dimensions of the submatrices in the ragged array.                 mydimensions={{4, 5}, {3, 4}, {2, 3}};      In other words the original object looked like                original={       {{7.7056, 4.20225, 3.02775, 7.60807, 9.77169},         {6.18476, 4.80993, 6.32965, 2.69882, 0.268505},         {1.78048, 9.67702, 0.875699, 7.18504, 1.62811},         {0.0313174, 5.66048, 1.61613, 5.71987,  0.971484}},        {{3.87503, 2.8537, 2.68776, 3.47433},         {2.81483, 4.0387,1.74939, 3.12037},         {4.18016, 2.35264, 0.853583, 1.22412}},        {{0.382633, 3.67874, 8.68059},         {8.02419, 6.9547, 7.11112}}      };      I tried using the undocumented function Internal`Deflatten, and it didn't work, but I was happy that it didn't crash my kernel! I'm able to do it rather inefficiently this way:                 arraytoweights[myflatarray_,mydimensions_]:=       MapIndexed[Partition[#1, mydimensions[[Last@#2, 1]]] &,        Take[myflatarray, #] & /@ ((# - {0, 1}) & /@ (Partition[       FoldList[Plus, 1, (Times @@@ mydimensions)], 2, 1]))];      My main problem is that this is part of an optimization function, that needs to be called many times during the optimization, and this is atm the slowest part. It also can't seem to be compiled. I suppose with Compile I have to make sure there are no ragged arrays generated in-between neither. Any suggestions are appreciated! **Edit** : So it turns out mine is not as bad as I thought. Though I like the extensions to more structure as @Leonid did. I have no need for it now, but I see how I can use it in the future. Here is the current tally of the answers and their timing, using a random larger result, the typical size I need. (only with submatrices atm)                   mydimensions = {{30, 4}, {10, 5}, {3, 4}, {2, 1}};         SeedRandom[1345]         original = ((RandomReal[{0, 10}, ##] & /@ mydimensions));         myflatarray = Flatten[original];      For the timing I ran the result from each with $10^3$ runs. For example, here the set for my results.                   lalmeiresults =               Table[First@                Timing[lalmei = arraytoweights[myflatarray, mydimensions];],    {i,Range@1000]}]          lalmei === original      > > True Here is the BoxWhiskerChart, with only the 95% quantile, no outliers. (Not sure if this the best way to do timing, but here it goes ) ![enter image description here](http://i.stack.imgur.com/5aUql.jpg) Couple of notes about the image: the distribution of mine and Leonid's, and seismatica's is about the same. Picket's is only a bit larger 25% only. Mr.Wizard's, kguler's and WReach's results only shoot up as the size of the sub-matrices gets larger. With a small examples, Mr. Wizard's is the fastest.                     mydimensions = {{3, 4}, {2, 5}, {3, 4}, {2, 1}};           SeedRandom[1345]           original = ((RandomReal[{0, 10}, ##] & /@ mydimensions));      Here the distributions in that case: ![enter image description here](http://i.stack.imgur.com/NElRx.jpg)


title: Tooltip in Listplot - Export to PDF

text: I would like to export a listplot as a PDF document without loosing the tooltip information on the single points. It kind of works with hyperlinks. Nevertheless this workaround is pretty limited and does e.g. not offer graphics as tooltips. Looking forward any ideas! Thanks and best regards Patrick               data = {{1, 2}, {2, 3}, {3, 5}, {4, 7}};     hlinks = Text[     StringForm["``",       Hyperlink[" ", "http://" <> ToString[#[[2]]]]], #] & /@ data;     chart = Show[ListPlot[data, AxesOrigin -> {0, 0}], Graphics[hlinks]];     Export["C:\\Users\\myname\\Desktop\\scatterplot.pdf", chart]


title: What causes Manipulate to stop evaluating expressions?

text: I'm working on a N-body simulation within Mathematica, and currently I have something along these lines:               Manipulate[      {r, v, a} = Step[G, m, r, v, a, ts dt];      Show[Visualize[names, colors, radius1, r1],        PlotRange -> {{-d, +d}, {-d, +d}}, ImageSize -> 1200],       Dynamic[MatrixForm[r]],      {{dt, 0.02}, 0.0001, 1, 0.0001}]      `Step[...]` simply steps the simulation forward in time. This works fine and I can confirm it works perfectly fine independent of anything else. However, occasionally the `Dynamic[MatrixForm[r]]` expression stops evaluating. I can't really figure out why it does this. Furthermore, sometime after the `Dynamic` stops evaluating, the `Show[Visualize[...], ..]` expression stops evaluating. At some point earlier when I had something much simpler along the lines of               Manipulate[f = Step[f]; Show[SimpleVisualize[f]], {...}]      The code within `Manipulate` would run indefinitely. Now it seems to randomly stop. It never stops at the same time, but it always does. Any ideas why? **An example of where this occurs is available here:http://dl.dropbox.com/u/9450720/minimal.nb** **Environment Information: Mathematica 8.0.4.0 on Windows 7 64-bit** * * * Here is a basic example of what I'm doing:               Step[r_, v_, a_, dt_] := Block[{nr, nv, na},        nv = v + dt/2 a;       nr = r + dt nv;       na = -nr;       nv = nv + dt/2 a;       {nr, nv, na}]          r = {1, 0};     v = {0, 1};     a = {-1, 0};          Manipulate[{r, v, a} = Step[r, v, a, dt];      Dynamic[Show[{Graphics@Circle[{0, 0}, 1],          Graphics[{PointSize[Large], Red, Point[r]}]}]],      Dynamic[{r, Norm@r}],      {{dt, 0.005}, 0.00001, 1, 0.00001}]      This evaluates fine and runs indefinitely.


title: what is the difference between these definitions?

text: I define 2 functions:               g[s_][x_,y_] := the gaussian  (1)          g1[s_,x_,y_] := the gaussian  (2)      I get the same answer using `g[s][ x, y]` and `g1[ s, x, y]`.   So, what is the difference?   Is there some advantage to be gained in definition `1` over `2`?


title: Define parameterized function

text: I would like to be able to define the gain function of a system from its parameters. Specifically, I'd like to define a function that accepts two inputs, call them $b$ and $w$, and returns a function that accepts a single parameter, $v$ and returns $1/\sqrt{(w^2 - v^2)^2 + b^2 v^2}$ . What's the right way to do this? Presumably I'd like to be able to write               gain[b,w][v]      to evaluate the function, with parameters b and w, at v. But I'd also like to be able to write               f[v_] = gain[b,w]      and have `f[v]` be the same as `gain[b,w][v]`.


title: Key Mapping in Command Line Mode

text: I would like to map Ctrl-U to "kill line" when using Mathematica 9.0 in command line mode (i.e. not within the front end, but when called from a Unix command line by "math"). I am aware that (on a Mac) the directory /Applications/Mathematica.app/SystemFiles/FrontEnd/TextResources/Macintosh contains the file "KeyEventTranslations.tr", however this file seems to only affect the front end, not the behavior of the kernel when called from the command line. I also know that Ctrl-C and Ctrl-G are already mapped to "Kill line" (although they don't seem to have corresponding entries in "KeyEventTranslations.tr"). But I would prefer to use Ctrl-U since this is what I am using in all other applications. (Note: Ctrl-U used to work in Math 8.0).


title: How to set the boundary fixed and apply the Young's modulus in Mathematica's FEM?

text: Provided the drawing .stl is given, and the Young's modulus is know, how to start a FEM vibration mode test in Mathematica? The boundary is required to be fixed and the interested focus is on the different responses over various Young's modulus. ![enter image description here](http://i.stack.imgur.com/yGR80.jpg)


title: Manipulating Frame labels when legends are also there

text: I am plotting a few curves inside a frame with labels on three of its sides; left, right and bottom. I want legends to be places at the top. The problem which I am facing is that the top label occupies white space and I want it not to do so. In the code it is labeled as "I want this removed". Please guide me how can I remove the top label completely leaving no gap between frame and legends.               Plot[{Sin[h],Cos[h],Tan[h]},{h,5,10},     PlotStyle->{{GrayLevel[0],Dashing[None],Thickness[0.005]},        {GrayLevel[0],Dashing[Tiny],Thickness[0.005]},        {GrayLevel[0],Dashing[Small],Thickness[0.005]},        {GrayLevel[0], Dashing[Medium],Thickness[0.005]}},      Axes -> False,      Frame -> True,       FrameLabel->{{"Left", Rotate["Right",180 Degree]},{"Bottom","I want this removed"}},      PlotLegends -> Placed[LineLegend[Automatic, {"sin", "cos", "tan"},      LegendMarkerSize->{{45, 15}}],Top]]


title: Segment parts of a picture

text: I remember that there was some thread of this sort, but I could not find it, so I hope it's ok to open a new thread. I want to segment pictures of the brain, i.e. I only want the area within the skull without the bones (all the grey matter/pixels. White parts are bones of the skull). I have the following two pictures. In the first picture I also want all the grey parts, but you see that there are some white parts intermingled between. So basically the algorithm should segment four different images. In the second pictures it seems to be easier. Can you guys give me a hint to a function or some examples or threads? ![enter image description here](http://i.stack.imgur.com/U6adl.jpg) ![enter image description here](http://i.stack.imgur.com/zCxeQ.jpg)


title: How can I save the current evaluation state of a notebook and start from it later?

text: I currently have a nested `Table` command running (in Mathematica 9), with two progress bars to track the variables. I have to shut down or hibernate the computer in a couple of minutes, and the calculation is only halfway done. What can I do in such a situation. I'm pretty sure simply hibernating won't work, as I recall it not working in Mathematica 8. Will entering a subsession and _then_ hibernating work? Or entering a subsession and dumping the kernel? While I don't have any preference towards shutting down or hibernating in my current situation, a solution that allows me to close Mathematica and resume evaluation at some later time (after shutting down, etc) would be ideal. Note: This question is about a cell which is already running (so I can't modify it), however if it's not possible to do this here, an answer that shows how to run `Table` in an interrupt-and-saveable manner would be OK1 1\. I have a pretty good idea of how to do this (dynamically append data to a list with `For` instead f using `Table`), but there may be better ways of doing this.


title: Optimising 2D binning code

text: I have a set of (x,y,z) data, 45,000 to be precise and I want to bin the z values in 256 equidistant bins based on their (x,y) values. The final array should be a set of 256x256 array with each slot containing an average of binned z values. Being new to mathematica, I came up with the following code:                data = RandomReal[{12000, 35000}, {45000, 3}];     data1 = data[[All, {1, 2}]];(*strip the zvalues from the set*)     xValues = data[[All, 1]];     yValues = data[[All, 2]];     zValues = data[[All, 3]];     (*Compute maximum/minimum of x values*)     maxXvalue = Max[xValues];     minXvalue = Min[xValues];          (*Compute maximum/minimum of y values*)     maxYvalue = Max[yValues];     minYvalue = Min [yValues];          (*Compute maximum/minimum of z values*)     maxZvalue = Max[zValues];     minZValue = Min[zValues];          bbx = {Floor[minXvalue], Floor[maxXvalue],         Floor[((maxXvalue - minXvalue)/256)]}; (* equidistant x bins*)     bby = {Floor[minYvalue], Floor[maxYvalue],         Floor[((maxYvalue - minYvalue)/256)]};(* equidistant y bins*)     bList = BinLists[data1, {bbx}, {bby}];     bCount = BinCounts[data1, {bbx}, {bby}];(*Gives a count of the number of items in \     each bins*)          (*Defining array to contain final z average values*)     meanZValues = Table[0, {Length[bList]}, {Length[bList]}];           i = 0; (*initialising loop variables*)     j = 0;     k = 0;          f[x_] := zValues[[x]];(*Defining function to get z values back*)          For[i = 1, i <= Length[bList], i++,      For [j = 1, j <= Length[bList], j++, m1 = {};    (*Re-empty m1 list*)             For [k = 1, k <= Length[bList[[i, j]]], k++,        AppendTo[m1, Position[data1, bList[[i, j]][[k]]] (*accessing only the x-         coordinate index of the position on original matrix*)         ];        (*Getting the indices of the binned values*)        indices = Flatten[DeleteDuplicates[Take[m1, All]]]; (*Position command above gives multiple indices if  these values occur more than once, hence deleting the duplicate ones*)             meanZValues[[i, j]] =  Mean[Map[f,indices]];  (*Compute average values of Z by accessing the original array, getting the z values  *)        ]       ]      ]     meanZValues      It gives an output in a reasonable amount of time for up to couple of thousand values, however, it lags and maybe crashes without any output for 45,000 set of data. How do I make this code more efficient? Thank you


title: Partitioning a data set of two-dimensional coordinates into subsets of coordinates underlying non-overlapping tiles of a bounding box

text: Image I have a list of coordinates of the form:               CoordinateList = {{{107.187, 130.25}, {160.742, 131.872}, {22.1312, 86.4814}}, {{251.357, 47.4634}, {177.773, 223.6}, {251.487, 126.181}}, {{51.1981, 15.1508}, {10.17, 44.4388}, {75.039, 4.44131}}, {{21.6951, 47.7368}, {73.1692, 130.974}, {93.9724, 139.979}}, {{107.914, 237.77}, {139.735, 199.392}, {20.8538, 88.0626}}, {{3.47162, 71.022}, {150.473, 45.0054}, {83.2402, 228.76}}, {{244.43, 156.011}, {126.716, 77.7305}, {247.013, 87.2547}}, {{85.3221, 108.568}, {16.3881, 167.449}, {147.638, 107.363}}, {{135.401, 97.1536}, {210.616, 104.893}, {195.791, 210.578}}, {{95.4441, 115.686}, {236.267, 69.9433}, {160.552, 30.2893}}, {{92.4965, 199.097}, {201.669, 56.4691}, {186.667, 113.938}}, {{98.7167, 45.6133}, {151.794, 88.8944}, {245.539, 177.681}}, {{103.834, 250.27}, {56.5259, 176.679}, {90.3859, 164.626}}, {{64.3762, 197.027}, {78.5971, 216.795}, {52.4567, 200.263}}, {{31.2684, 73.8046}, {12.6404, 246.689}, {3.62497, 177.448}}, {{210.712, 104.823}, {151.347, 13.8795}, {63.3472, 197.042}}, {{92.1903, 12.4941}, {141.632, 112.287}, {221.041, 189.748}}, {{237.627, 76.7537}, {20.2009, 117.81}, {150.973, 110.379}}, {{24.1639, 218.049}, {251.751, 185.44}, {161.526, 231.584}}, {{125.477, 237.408}, {38.6014, 73.5206}, {4.64447, 49.3799}}, {{80.0287, 123.736}, {153.407, 131.396}, {11.0003, 202.104}}, {{250.583, 51.9734}, {69.2102, 89.4853}, {10.0789, 163.632}}, {{96.328, 67.6535}, {210.743, 104.839}, {175.073, 114.937}}, {{136.214, 115.21}, {58.048, 144.602}, {244.051, 57.6266}}, {{60.0216, 18.7106}, {173.178, 177.361}, {87.0396, 112.919}}, {{4.67427, 49.3867}, {60.0381, 18.7024}, {77.1039, 162.763}}, {{134.911, 10.2993}, {79.7796, 61.8847}, {168.708, 104.301}}, {{200.808, 221.631}, {84.5544, 137.876}, {136.434, 150.225}}, {{110.313, 30.4609}, {37.538, 199.435}, {10.6894, 230.592}}, {{132.621, 98.0955}, {213.781, 124.4}, {21.3729, 31.0911}}};      Note that this is a list (length = 30) of subsets of coordinates. These points fit within a bounding box of dimensions:               BoundingBox = {Min[CoordinateList[[All,1]]], Max[CoordinateList[[All,1]]], Min[CoordinateList[[All,2]]], Max[CoordinateList[[All,2]]]};      I would like to partition this box into the largest possible set of $A \times B$ rectangular tiles - the bounding box for the points can be trimmed as necessary. Call this number of tiles $k$. Then, without disturbing the ordering of the coordinate subsets, I would like to generate a list of $k$ subsets of the CoordinateList consisting of the points that fall in each rectangular region. Here's a brief illustration (by mouse, so it's inexact!) of how I'd like to partition the points: ![enter image description here](http://i.stack.imgur.com/CajWf.png) Here, we do the best we can to tile a bounding box for the list of points with tiles of some chosen dimension (here - roughly $A=B=50$), and then if a point falls underneath a certain tile, it is assigned to a subset for that tile. The subset must respect the primordial subsets in the original CoordinateList s.t. in each subset we can see while element of CoordinateList a point corresponds to. Is there a nicer way to proceed than defining a coordinate list for each box, and checking for membership by a few inequality checks, or more compactly, computing a winding number using:               Graphics`Mesh`InPolygonQ[poly, pt]      Perhaps this could be done via the use of Pick[]? The issue I have is that my CoordinateList is actually quite a bit larger than the example provided, and I need to do this partitioning quickly.


title: Coarse-graining and/or sorting of a list of arbitrary triades {x,y,z} in the (x,y) plane

text: In general my question is related to an approach to make an interpolation of a data which is not on a regular mesh. Another aspect of this question has already been discussed after my question "Numerical integration of a numeric data available as a nested list". I have data in the form of a list of triads `{x, y, z}` that came from an external simulation. It may be and may be not ordered. Further, x and y lie within a rectangle R, and are not regularly spaced. I would like to coarse- grain and simultaneously sort this data. The coarse-graining consists in partitioning the rectangle R into multiple small rectangles and constructing a list `{xij, yij, zij}` where xij and yij are the coordinates of the centers of the rectangles, while zij is the average of all z values for which x and y belong to the rectangle specified by i and j. To be specific, let us build a list mimicking the real one, but small enough:               a = RandomReal[{0, 10}, {10000, 2}];     b = RandomReal[{-1, 1}, {10000}];     lst =        MapThread[Insert[#1, #2, 3] &, {a, b}] /.         {x_, y_, z_} -> {x, y, 10 Exp[-((x - 5)^2 + (y - 5)^2)/4] + z};      The list lst has 10000 elements with x and y located between 0 and 10. The coarse-grained list may be obtained by the averaging over squares with the sizes 0.5*0.5 like this:               lstCoarseGrained = Flatten[Table[         (s = Select[            lst, ((i <= #[[1]] <= i + 0.5) && (j <= #[[2]] <= j + 0.5) &)];           {{i + 0.25, j + 0.25}, Mean[Transpose[s][[3]]]}),         {i, 0, 9.75, 0.5}, {j, 0, 9.75, 0.5}], 1];      It has               Length[lstCoarseGrained]      > 400 elements and can be straightforwardly interpolated:               f = Interpolation[lstCoarseGrained, InterpolationOrder -> 3, Method -> "Spline"]      plotted:               Row[{       ListPlot3D[lst, PlotRange -> All, ImageSize -> 250],        Plot3D[f[x, y], {x, 0, 10}, {y, 0, 10}, PlotRange -> All, ImageSize -> 250]     }]      ![enter image description here](http://i.stack.imgur.com/0bgtC.jpg) and then further post-processed. On the figure above the left image shows the data before, and the right - after the coarse-graining and interpolation. However, the coarse-graining by this approach requires               Timing[       Flatten[         Table[           (             s = Select[lst, ((i <= #[[1]] <= i + 0.5) && (j <= #[[2]] <= j + 0.5) &)];             {{i + 0.25, j + 0.25}, Mean[Transpose[s][[3]]]}           ),           {i, 0, 9.75, 0.5}, {j, 0, 9.75, 0.5}],         1];]      > {13.468750, Null} 13 seconds. My realistic lists have about 10^6 triads and will require about 21 min. My question is, if you can see a faster way to do this? In principle, if I could, say, use something like Partition instead of a Table, it would go faster. However, to do this, the list should be first sorted in 2D, and I do not see, how. So the second question is if you see the way to sort the list with elements {x,y,z} with arbitrary order in the (x,y) plane such that it is organized as like, say, the list given by the table:               Table[{i, j}, {i, 1, 5}, {j, 1, 5}]


title: Calculating Second-Order Tikhonov Regularization Parameter in Mathematica

text: I am trying to map slowness of underwater sound velocity in a river using some tomographic device. The location of each acoustic receiver/transmitter is shown in the picture below ![enter image description here](http://i.stack.imgur.com/dM7wr.png) To find the slowness m={S11,S12,S13, ...S112,...,S71,S72,S73, ... , S712} from the observations d={t_R1L1,t_R1L2,...,t_R4L4} I need to solve the regularized least-square equation min||Gm-d||^2+a^2||Lm||. I, therefore, established matrices                 G={{0, 12.1524, 2.7609, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.6297, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 15.6297, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        5.65726, 9.97241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.6297, 0, 0, 0, 0,       0, 0, 0, 0, 0, 0, 0, 15.6297, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        14.3434, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 14.912, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 15.6283, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        15.6283, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.50649, 11.1218, 0, 0, 0,       0, 0, 0, 0, 0, 0, 0, 0, 15.6283, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        15.6283, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.0604, 2.88671, 0, 0, 0,       0, 0, 0, 0}, {0, 0, 19.1877, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        2.16882, 17.9406, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.58072, 15.5287,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.99261, 13.1168, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 9.40451, 10.7049, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       11.8164, 8.293, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14.2283, 0.877225,       0, 0, 0}, {0, 0, 17.3355, 7.70369, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       10.5772, 15.6647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.61622,        18.2809, 5.34477, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12.9361, 13.3058,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.97514, 18.2809, 2.98585, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 15.295, 10.9468, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 7.33406, 14.2199}, {0, 0, 0, 0, 14.4946, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 9.24233, 9.34103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.41548,        16.1679, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18.5834, 0, 0, 0, 0, 0, 0, 0,       0, 0, 0, 14.172, 4.41137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7.34514,        11.2382, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17.054, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0}, {0, 0, 0, 0, 11.8019, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        15.1311, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.1311, 0, 0, 0, 0, 0, 0,       0, 0, 0, 0, 0, 15.1311, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.1311,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.1311, 0, 0, 0, 0, 0, 0, 0, 0, 0,       0, 0, 13.5034, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 2.1671, 10.7843,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.6048, 0, 0, 0, 0, 0, 0, 0, 0, 0,       0, 0, 7.58393, 9.02091, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.6048,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.34735, 7.25749, 0, 0, 0, 0, 0, 0,       0, 0, 0, 0, 0, 16.6048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.1108,        1.36223, 0, 0, 0}, {0, 0, 0, 0, 1.29176, 15.5556, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 5.29103, 16.3088, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        4.53791, 17.0619, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.78479, 17.815,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.03167, 18.5681, 0, 0, 0, 0, 0, 0,       0, 0, 0, 0, 0, 2.27856, 19.3212, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        1.52544, 16.2157}, {0, 0, 0, 0, 0, 0, 18.5392, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 19.4035, 2.06375, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19.9029,        1.56439, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20.4023, 1.06503, 0, 0, 0, 0, 0,       0, 0, 0, 0, 20.9016, 0.565678, 0, 0, 0, 0, 0, 0, 0, 0, 0.433035,        20.9679, 0.0663213, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19.7006, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 14.1187, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 16.3486, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.75723,        6.5914, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.3486, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 4.73928, 11.6094, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.3486, 0,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14.59, 0, 0, 0, 0, 0, 0, 0}, {0, 0,        0, 0, 0, 0, 1.65553, 11.4627, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        15.1901, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.1901, 0, 0, 0, 0, 0, 0,       0, 0, 0, 0, 0, 15.1901, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.1901,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.1901, 0, 0, 0, 0, 0, 0, 0, 0, 0,       0, 0, 7.70533, 3.70495, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0.447913,        15.4943, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10.2405, 8.21959, 0, 0, 0,       0, 0, 0, 0, 0, 0, 0, 0, 17.5151, 0.944913, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 18.4601, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.32976, 12.1303,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13.6044, 4.85561, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 15.1623}, {0, 0, 0, 0, 0, 0, 0, 0, 6.77971,        17.4671, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14.9997, 11.4365, 0, 0, 0, 0, 0,       0, 0, 0, 5.00342, 18.2163, 3.21656, 0, 0, 0, 0, 0, 0, 0, 0,        13.2234, 13.2128, 0, 0, 0, 0, 0, 0, 0, 0, 3.22712, 18.2163, 4.99286,       0, 0, 0, 0, 0, 0, 0, 0, 11.4471, 14.9891, 0, 0, 0, 0, 0, 0, 0, 0,        0, 17.4914, 6.76916, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,        0, 0, 0, 0, 18.2098, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16.1093, 3.74475,       0, 0, 0, 0, 0, 0, 0, 0, 0, 13.0672, 6.78682, 0, 0, 0, 0, 0, 0, 0,        0, 0, 10.0251, 9.8289, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.98307, 12.871,        0, 0, 0, 0, 0, 0, 0, 0, 0, 3.941, 15.913, 0, 0, 0, 0, 0, 0, 0, 0, 0,       0, 17.7183, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,        14.3166, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.6093, 0, 0, 0, 0, 0, 0,       0, 0, 0, 0, 0, 15.6093, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.15931,        6.45003, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.6093, 0, 0, 0, 0, 0, 0, 0,       0, 0, 0, 0, 15.6093, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.7252, 0,        0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 2.36708, 11.8831, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 15.5369, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.5369,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14.6006, 0.936286, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 15.5369, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15.5369,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12.7613}}      and               L=Flatten[       　　　Table[             M = ConstantArray[0, {7, 12}];,             M[[i, j]] = -4;             M[[i, j + 1]] = 1;             M[[i, j - 1]] = 1;             M[[i + 1, j]] = 1;             M[[i - 1, j]] = 1;             Flatten[M],             {j, 2, 11},             {i, 2, 6}],             1];      Given that `{{U, V}, {Lamb,M}, X} = SingularValueDecomposition[{G, L}]` , where `G=U.Lamb.Conjugate[Transpose[X]]` and `L=V.M.Conjugate[Transpose[X]]`, **Why the generalized singular values of G and L, gama, become indeterminate or zero? And, how can I fix this issue?**               gama=lambda/mu      where               lambda=Sqrt[Diagonal[Transpose[Lamb].Lamb]]           ={0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,          0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,          0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,          0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,          0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}      and               mu=Sqrt[Diagonal[Transpose[M].M]]       ={0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,      0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,      1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,      1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,     1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.}


title: Why cant I open CDF's in the Chrome browser on Linux?

text: I have google chrome on ubuntu 13.04. Every time I try to run a CDF on wolframs website, I'm required to download the CDF first, and then open it in my computer, but when I was using windows it was ready to use on the browser itself, any ideas on how to fix it? Is it a better topic for the ubuntu stackexchange?


title: Launching external program in background process with ParallelSubmit

text: I work on the implementation of an image processing pipeline in _Mathematica_ in which I also would like to use external programs to do certain processing steps. As an example I have macros for the program FIJI that are written, parameterized and then executed with the `Run` command in _Mathematica_. Some of these processing steps just need to be executed and I do not necessarily need the results in the pipeline later on. For those computations I thought it would be nice to let the computation be run in a background process and continue with other steps while the background process is still running. I've read about pushing computations to background kernels (Computing Many Slow I/O Operations, Concurrency: Managing Parallel Processes) and it works fine. What I've tried is the following: I launch a bunch of kernels, generate some processes and queue those processes using `ParallelSubmit`. I then use `QueueRun` to start the processes in the background and collect the results with `WaitAll` after a while.               CloseKernels[];     Needs["Parallel`Developer`"];     ResetQueues[];     LaunchKernels[5];          ids = Function[i,         ParallelSubmit[(Pause[i^2]; {i^2, DateString[]}),          Scheduling -> i]] /@ {1, 2, 3, 4, 5}      ![enter image description here](http://i.stack.imgur.com/oHcB1.png)               {QueueRun[], $QueueLength}      > {True, 0} ![enter image description here](http://i.stack.imgur.com/wHpGB.png)               WaitAll[ids]      > {{1, "Mon 10 Mar 2014 09:37:53"}, {4, "Mon 10 Mar 2014 09:37:56"}, {9, "Mon > 10 Mar 2014 09:38:01"}, {16, "Mon 10 Mar 2014 09:38:08"}, {25,   >  "Mon 10 Mar 2014 09:38:17"}} ![enter image description here](http://i.stack.imgur.com/RudKp.png)               DateString[]      > Mon 10 Mar 2014 09:41:23 I included `DateString` to see, when the tasks have been processed in the background kernels. As can be seen from the timings it worked as expected and I also was able to do computations in the front end while the tasks were running. Now I'd like to do the same thing with calling external programs like FIJI but for some reasons the tasks are processed not before `WaitAll` is evaluated. The kernels receive the jobs but they do not start until I evaluate `WaitAll`.               CloseKernels[];     Needs["Parallel`Developer`"];     ResetQueues[];     LaunchKernels[3];          ids = {       ParallelSubmit[runFijiMacro["command line code"]],       ParallelSubmit[runFijiMacro["command line code"]],       ParallelSubmit[runFijiMacro["command line code"]]       }      ![enter image description here](http://i.stack.imgur.com/9Kepv.png)               {QueueRun[], $QueueLength}      > {True, 0} ![enter image description here](http://i.stack.imgur.com/dzNo2.png) ( _The returned EvaluationObjects seem to be running but in fact they don't_ )               WaitAll[ids]      ( _now FIJI is started and the tasks are processed. But, also the main kernel is blocked._ ) **Questions**   1. Why does this construct not work with `Run`?   2. Is there a possibility to force the evaluation on the background kernels?   3. Is there a workaround to do this? Thanks for any help or comments!


title: Windows Insert File Path

text: Suppose I want to Save["filename", foo] under Windows. Ordinarily, the way to deal with file names under windows is to open the Insert dialogue and find a file path, but in this use case, the file is new, so it does not exist (yet). Unlike every other windows program I am familiar with, Mathematica is unwilling to create a new file (that is, once you locate the relevant folder, you type in "mynewfile.m", Mma balks. This seems like a bug (sorry, Dan Lichtblau, a misfeature :)), but is there any reasonable workaround? Am I missing something obvious?


title: Excel-like UI in Mathematica

text: This is NOT about importing/exporting Excel data to/from Mathematica. This is purely a UI question. The Mathematica notebook interface is very "linear" — I type in an input cell and _Mathematica_ produces an output cell. Is it possible to implement something like an Excel interface for _Mathematica_? For example, if I have:   * cell `a1 = "x+y"`   * cell `b1 = "x-y"`   * cell `c1 = "= a1^2 + b1^2"` Then, _Mathematica_ puts "2(x^2+y^2)" into `c1`. If I modify `a1` to say `"3"`, _Mathematica_ puts `"(x-y)^2 + 9"` into `c1`.


title: How to make the docked cell and the navigation toolbar in the Slide Show?

text: I have a notebook with a docked cell displaying a banner with some graphics. When I convert this notebook to the Slide Show the banner is nicely displayed on each slide. But the Navigation Toolbar is not visible, apparently covered by my docked cell. How to display both, the Navigation Toolbar and my graphical banner in the Slide Show?


title: How to model Macroeconomic dynamics?

text: I am rather new to _Mathematica_ and I wanted to see if I could get some help with the following. I am trying to generate a model of macroeconomic indicators defined by the following functions, but I do not know how to input these in _Mathematica_ or be able to manipulate them a bit more.               Y(T+2)    =  C(T+2) + I(T+2) + Govlev(T+2) + X(T+2) ;         YD(T+2)   = (1 - TX(T+2)) * Y(T+2) ;         C(T+2)    = a + b * YD(T+2) ;         I(T+2)    =  e - d * R(T+2) ;         Mlev(T+2) / plev(T+2) = k * Y(T+2) - h * R(T+2);         Pie(T+2)  = alpha * Pi(T+1) + beta * Pi(T) ;         Pi(T+2)   = Pie(T+2)+ f * (Y(T+1) - YNlev(T+2))  /  YNlev(T+2) ;         plev(T+2) = plev(T+1) * (1 + Pi(T+2)) ;         Ex(T+2) * plev(T+2) / plevw(T+2) = E = q +  v * R(T+2) ;         X(T+2)    = gamma - mu * Y(T+2) - n * ( Ex(T+2) * plev(T+2) / plevw(T+2)) ;         GD(T+2)   = Govlev(T+2) - TX(T+2) * Y(T+2) ;         U(T+2)    = UN(T+2) - s * (Y(T+2) - YNlev(T+2)) / YNlev(T+2) ;


title: How can I account for assumed X and Y errors when using findfit?

text: I'm using very noisy biological data, and I need to assume, when doing linear regression, that there are errors in both `X` and `Y`. To my understanding normal regression only assumes errors in `Y`. Is there a way to specify error values for `X` and `Y` in _Mathematica_ , and take that into account when finding a linear relationship between the two?


title: Data Fitting with xerrors and yerrors using findfit

text: I'm trying to fit data with xerror and yerror using "Findfit", so i'm trying the same form than in tuto : http://reference.wolfram.com/applications/eda/FittingDataToLinearModelsByLeast- SquaresTechniques.html which is {{x,errx},{y,erry}} So my code is :               data2201vol = ReadList["data.dat", {{Number, Number}, {Number, Number}, {Number, Number},{Number,Number}}][[All, {1, 3}]]          data1 = data2201vol     res1 = FindFit[data1, model, t, eta];      But when i evaluate i get that :               FindFit::fitd: First argument {{{7.98187,2.92332},{65326,255.59}},{{13.0174,2.91387},{61510,248.012}},{{23.0829,2.98836},{55135,234.808}},{{43.1855,3.0372},{45142,212.466}},{{53.2883,3.11867},{41257,203.118}},{{63.3186,3.16282},{38048,195.059}},{{83.3984,3.23615},{32628,180.632}},{{103.479,3.26169},{28339,168.342}},{{123.585,3.36999},{24976,158.038}},{{203.785,3.47143},{16381,127.988}},{{243.893,3.62374},{13685,116.983}},{{303.901,3.54541},{10845,104.139}},{{363.98,3.57129},{8753,93.5575}}} in FindFit is not a list or a rectangular array. >>      Of course "model" is well defined, it works when i use a more classical input without yerror. I didn't find so much on that, if someone have an idea !


title: Scheduling Mathematica scripts to run from a command line

text: I want to run _Mathematica_ "jobs" on a daily/weekly basis to do system maintenance and as part of daily processing operations. What is the best way to do this?


title: Determining the partitioning of Do loop iterations between kernels?

text: Say I have some `Do` loop that I'd like to evaluate in parallel: `Do[Something, {i, 1, M}]`. I'd like to split this list up into chunks which individual kernels evaluate. However, I would like to explicitly specify these chunks, which is something `ParallelDo` does not seem to allow for. How does `ParallelDo` actually partition values of $i$ to be evaluated during a `Do` loop? If I have a list $L$ where I need to access $L[i]$ at the $i$th iteration of the `Do` loop, how might I avoid slowdowns associated with using some large global list?


title: Specifying initial conditions for a PDE

text: I have simple diffusion equation with point source at `c(0, t) = 1` and initial condition `c(elsewhere, 0) = 0`. How should I apply `DSolve` or `NDSolve` to solve the equation ? I have tried specifying my initial conditions like this:               ic = {c[x > 0, 0] == 0, c[x < 0, 0] == 0, c[0, t] == 1, Derivative[1, 0][c][1, t] == 0}      but it fails. Any suggestions?               Diff = D[c[x, t], t] - D[c[x, t], {x, 2}] == 0;     ic = {c[x > 0, 0] == 0, c[x < 0, 0] == 0, c[0, t] == 1, Derivative[1, 0][c][1,t] == 0};     s1 = NDSolve[{Diff, ic}, {c[x, t]}, {x, 0, 1}, {t, 0, 1}];     Plot3D[c[x, t] /. s1, {x, 0, 1}, {t, 0, 1}]


title: How do I incorporate metadata using Export?

text: I have               Export["file.png",codeThatMakesAGraphicsObject[],"PNG"];      and want to embed some specific metadata information. Is there a simple way to do that? * * * Note that this code already (automatically, apparently) includes metadata information for "Horizontal resolution", "Vertical resolution", "Software used", and "Date and time of digitizing", and I don't want to disturb that with any fields I add.


title: Where can I find examples of good Mathematica programming practice?

text: I consider myself a pretty good _Mathematica_ programmer, but I'm always looking out for ways to either improve my way of doing things in _Mathematica_ , or to see if there's something nifty that I haven't encountered yet. Where (books, websites, etc.) do I look for examples of good (best?) practices of _Mathematica_ programming?


title: Where to begin?

text: I was looking at the Mathematica website today and just decided to buy the software. I've spent too much time juggling annoying symbolic expressions by hand that actually learning to do things with a computer should be a worthwhile investment. Similarly for making conjectures about formulas etc. a computer would seem like a useful tool. My question: Where should I begin? I have a Ph.D. in math and would consider myself an expert level programmer in C, C++, x86 assembler, OCaml and Perl. I understand the functional programming paradigm well, so I don't need any introductions. To begin with, I would like to be able to work efficiently with linear algebra, number theory and random sampling. Oh, and plotting would be nice too and how to embed formulas written in LaTeX into those plots. Any advice?


title: mathematica for learning?

text: _Mathematica_ looks like an extremely powerful tool. I would love to have it in my toolbox. Unfortunately, I can hardly add two numbers together. I think the application of math through programming is the best way to learn. Is there any book that takes you from _no math skills_ to advanced levels through the lens of _Mathematica_?


title: What Mathematica book to buy?

text: I have used Mathematica for several years but at a pretty low level - piecing together built-in function inefficiently and fearing the sight of # and &'s when I see others use them (I never do). I would like to improve my skills. Which book would be best to read for someone familiar with Mathematica basics but would like to learn more sophisticated uses of Mathematica?


title: Good Introduction / Tutorial to Mathematica **Books**

text: > **Possible Duplicate:**   >  Where can I find examples of good Mathematica programming practice? I'm a high school senior and am using Mathematica for a research project. However, I find it a bit slow to learn Mathematica by watching videos. I know that there are many helpful videos of Mathematica topics online, but I was wondering if there are any books or reference manuals I can read offline. I've looked at the question at What is the best Mathematica tutorial for young people? But again, it only lists online resources. So are there are any books out there detailing an introduction to Mathematica?


title: Manipulate Tutorials?

text: I am wanting to combine equations with sets of static data points in a manipulate and do the curve fitting by moving the slider bars on my independent variables. The best examples of this art may be found at: http://demonstrations.wolfram.com/search.html?query=Normand Could someone please point me to one or more detailed tutorials that would make me as good a Mathematica programmer as Mark D. Normand?


title: Plotting a function that uses the solutions to a system of differential equations

text: I am trying to draw a plot by using the solution of differential equations               z = 0;     Ω = 2.2758;     τ = 13.8;     T2 = 200;     ω0 = 1;     r = 0.7071;     Δ = 1.7758;     ΩR = 2.2758;     ω == 0.5;     system = {u'[t] ==  Ω*v[t],     v'[t] ==  Ω*u[t] - 2*ΩR*w[t] - v[t]/T2,     w'[t] ==  2*ΩR*v[t]};     initialvalues = {u[0] ==  0, v[0] ==  0, w[0] ==  -1};     sol = DSolve[Join[system, initialvalues], {u[t], v[t], w[t]}, t]     FT = (-2*2.2758*r*u[t])/ω0^2 E^(-(r^2/ω0^2) - (t^2/τ^2))* Cos[kz - ωt];     p1 =        Plot[FT, {t, -20, 20},          FrameLabel -> {"t", "FT"},          Frame -> True,          RotateLabel -> True,          PlotRange -> {-0.1, 0},         PlotStyle -> {Thickness[0.002]}]      ![my code](http://i.stack.imgur.com/9kWLE.jpg) right now I went to plot "FT" by using the result of "u" , How I can do that ?


title: how to print stack trace when TimeConstrained times out

text: According to the documentation, `TimeConstrained` generates an interrupt which interrupts the computation. This interrupt is treated just like an abort, at least in the sense that it respects `AbortProtect`. I want to see the contents of the stack at the time the abort is generated, before the aborted evaluation is removed from the stack. I tried this:               changeAbort[] :=      (       Unprotect[Abort];       testAbort = True;       Abort[args___] :=        (          Print[Stack[_]]; (* in real life, to a log file *)          Block[{testAbort = False}, Abort[args]]        ) /; testAbort       Protect[Abort];      )      This works for aborts that I generate myself. For example,               While[True, Abort[]]      aborts and prints the following stack trace:               (*      {While[True,Abort[]],Print[Stack[_]];Block[{testAbort=False},Abort[]],Print[Stack[_]]}     *)      Along (spiritually) similar lines, I can print the the stack at the time a message is displayed with this code:               Internal`AddHandler["Message", Print[Stack[_]]&];      Getting back to `TimeConstrained`, neither of the following give me a stack trace:               changeAbort[];TimeConstrained[While[True, Null], 1]     TimeConstrained[changeAbort[]; While[True, Null], 1]      The last line was written in case `TimeConstrained` was implemented by temporarily redefining `Abort`. Unfortunately, it doesn't work. Is there some way to intercept the interrupt generated by `TimeConstrained` so that I can get a stack trace of the aborted computation, before it is removed from the stack?


title: Judging the quality of fitting an EventData object to a distribution using LogRankTest

text: I have $389$ data points defined in an `EventData` object and want to judge the quality of fit of this data to a fitted $3$-parameter Weibull distribution. This particular data set contains no censoring but in general there will be censoring in my future data sets. My approach is to find the three parameters using `EstimatedDistribution` and then to represent the found distribution by generating a number of random variates from it so that they can be compared to the original `EventData` object. I’m using LogRankTest to produce the $p$-value to judge the fit. My fundamental question is, is there a more elegant way of doing this in _Mathematica_? My data and code are below. Here are the raw data:               data1=Table[40.8,{10}];     data2=Table[42.075,{23}];     data3=Table[43.35,{48}];     data4=Table[44.625,{80}];     data5=Table[45.9,{63}];     data6=Table[47.175,{65}];     data7=Table[48.45,{47}];     data8=Table[49.725,{33}];     data9=Table[51,{14}];     data10=Table[53.55,{6}];     data=Flatten[{data1,data2,data3,data4,data5,data6,data7,data8,data9,data10}];      Here is where I define the `EventData` object and determine the fitted distribution, distribution.               censoring=Table[0,{Length[data]}];     eventdata=EventData[data,censoring]     dist=EstimatedDistribution[eventdata,WeibullDistribution[a,b,c]]          EventData[ ]          WeibullDistribution[2.62045,7.14193,39.7656]      And here is where I non-parametrically determine the $p$-values via `LogRankTest`.               n=200000;     i=0;     Do[      {i=i+1,      If[i>4,Break[]],      samplevalues=RandomVariate[dist,{n}],      logrankpvalue=LogRankTest[{eventdata,samplevalues}] ,      Print["i=",i,"    Log Rank p Value=",logrankpvalue]},      {5}]          i=1    Log Rank p Value=0.999826          i=2    Log Rank p Value=0.973828          i=3    Log Rank p Value=0.948566          i=4    Log Rank p Value=0.976803      Note that with $n$ set at a relatively large value ($200\,000$), $p$-values of around $0.97$ are produced indicating that the hazard rates of the two data sets are in pretty good agreement. I think this tells me that `EstimatedDistribution` did a good job in the fitting. Conversely, in general, small values of $n$ (e.g., $10$) produce a much poorer agreement as expected and as evidenced by smaller $p$-values. I generate four $p$-values because I’ve observed that depending upon the particular random values chosen that it is possible to produce a large $p$-value with small values of $n$. My questions are   1. Is there a more elegant way of determining the degree of similarity between the `EventData` object and the found distribution? Perhaps comparing to the theoretical distribution, dist directly instead of sampling from dist?   2. If this approach (or any improved suggested approach) is robust for the _no-censoring_ case is it also robust if the `EventData` object contains _censored values_?


title: Sinusoid modelling

text: There are lots of great demonstrations that show how to get periodic functions in the unit circle. I'm wondering how hard it would be to simulate a "moving grid" similar to this video on youtube (at about 1 minute) The circle and moving points are easy , but I don't know how to simulate that grid and sinusoid moving under the moving points. Any help would be appreciated. Here is my start, lots of possibilities to make this look better cosmetically, but the moving "paper" is something that would really help to illustrate the idea.               Manipulate[Graphics[{        Circle[],        PointSize[0.012],        Point[{Cos[t], Sin[t]}],        Point[{0, Sin[t]}]        }, PlotRange -> {{-1.1, 11}, {-1.1, 1.1}},        ImageSize -> {500, 100}], {t, 0, 10}]


title: How can I deal with an NDSolve::ivone message regarding boundary values?

text: I have a question regarding the error message: > >     NDSolve::ivone: Boundary values may only be specified for one > independent variable. >     Initial values may only be specified at one value of the other > independent variable. >> >   I'm curious as to when this error shows up. If I run the heat equation example from the `NDSolve` documentation, I get a valid solution. However, consider an edit to the p.d.e to               NDSolve[{D[u[t, x], {t, 2}] == D[u[t, x], {x, 2}], u[0, x] == 0,        u[t, 0] == 0, u[t, 5] == 0}, u, {t, 0, 10}, {x, 0, 5}]      That is, I changed $u_t = u_{xx}$ to $u_{tt} = u_{xx}$ and also changed an initial condition. (A solution of course is $u(x, t) = 0$.) Now, if I run this, I will get the error quoted above. I believe `NDSolve` doesn't even try to run. How do I need to edit the boundary conditions in order to get a run attempt? Does `NDSolve` only accept certain types of boundary conditions dependent on the order of the p.d.e? How do I find out what boundary conditions are acceptable? I'm asking about this because I'm trying to solve a very complicated third- order, nonlinear, p.d.e resulting from an optic equation and every set of initial conditions that I have given `NDSolve` for this 3rd-order equation has resulted in the above error.


title: Curve Fitting Errors

text: I am trying to fit a part of a dataset to the function $$ae^{-b\sqrt{x-c}}$$. My friend was using GNUPlot to this and got reasonably good results. However when I try to this with _Mathematica_ :               NonlinearModelFit[Tmean, a*Exp[-b*Sqrt[x - c]], {{a, 45}, {b, 2}, {c, 1.8}}, x]).      > >     -188.006 E^{1.17551\sqrt{-<<18>> + x}} >   > > Data= {{2.76134, 6.134}, {2.7552, 6.081}, {2.7491, 6.224}, {2.74301, 6.288}, > {2.73696, 6.629}, {2.73093, 6.486}, {2.72493, 6.719}, {2.71895, 6.989}, > {2.713, 7.076}, {2.70708, 7.293}, {2.70118, 7.152}, {2.69531, 7.37}, > {2.68946, 7.626}, {2.68364, 7.59}, {2.67784, 7.74}, {2.67207, 7.723}, > {2.66633, 7.606}, {2.66061, 7.855}, {2.65491, 7.668}, {2.64923, 8.03}, > {2.64359, 8.16}, {2.63796, 7.932}, {2.63236, 8.174}, {2.62678, 8.335}, > {2.62123, 8.171}, {2.6157, 8.292}, {2.61019, 8.247}, {2.60471, 8.363}, > {2.59925, 8.541}, {2.59381, 8.357}, {2.5884, 8.347}, {2.583, 8.404}, > {2.57763, 8.414}, {2.57229, 8.363}, {2.56696, 8.509}, {2.56166, 8.556}, > {2.55638, 8.297}, {2.55112, 8.562}, {2.54588, 8.335}, {2.54066, 8.359}, > {2.53546, 8.581}, {2.53029, 8.311}, {2.52514, 8.308}, {2.52, 8.276}, > {2.51489, 8.337}, {2.5098, 8.075}, {2.50473, 8.098}, {2.49968, 8.119}, > {2.49465, 7.891}, {2.48964, 7.682}, {2.48465, 7.519}, {2.47968, 7.593}, > {2.47473, 7.482}, {2.4698, 7.567}, {2.46489, 7.053}, {2.46, 7.213}, > {2.45513, 7.077}, {2.45028, 6.784}, {2.44545, 6.81}, {2.44063, 6.796}, > {2.43584, 6.643}, {2.43106, 6.633}, {2.42631, 6.323}, {2.42157, 5.994}, > {2.41685, 6.198}, {2.41214, 6.063}, {2.40746, 5.797}, {2.40279, 5.808}, > {2.39815, 5.684}, {2.39352, 5.506}, {2.38891, 5.307}, {2.38431, 5.531}, > {2.37974, 5.207}, {2.37518, 5.193}, {2.37063, 5.247}, {2.36611, 4.985}, > {2.3616, 4.882}, {2.35711, 4.696}, {2.35264, 4.501}, {2.34819, 3.966}, > {2.34375, 4.399}, {2.33932, 4.297}, {2.33492, 4.154}, {2.33053, 4.011}, > {2.32616, 3.853}, {2.3218, 3.654}, {2.31746, 3.521}, {2.31314, 3.505}, > {2.30883, 3.519}, {2.30454, 3.627}, {2.30026, 3.49}, {2.296, 3.412}, > {2.29176, 3.624}, {2.28753, 3.43}, {2.28332, 3.345}, {2.27912, 3.503}, > {2.27494, 3.2}, {2.27077, 3.169}, {2.26662, 3.015}, {2.26249, 2.968}, > {2.25836, 2.76}, {2.25426, 2.523}, {2.25017, 2.624}, {2.24609, 2.567}, > {2.24203, 2.654}, {2.23798, 2.525}, {2.23395, 2.413}, {2.22993, 2.279}, > {2.22593, 2.262}, {2.22194, 2.47}, {2.21796, 2.288}, {2.214, 2.324}, > {2.21006, 2.204}, {2.20612, 2.224}, {2.20221, 2.316}, {2.1983, 2.183}, > {2.19441, 2.323}, {2.19053, 2.085}, {2.18667, 1.981}, {2.18282, 2.047}, > {2.17898, 2.096}, {2.17516, 2.062}, {2.17135, 2.091}, {2.16756, 2.057}, > {2.16377, 2.06}, {2.16, 2.048}, {2.15625, 2.231}, {2.1525, 1.956}, {2.14877, > 2.066}, {2.14506, 2.082}, {2.14135, 2.019}, {2.13766, 2.184}, {2.13398, > 2.043}, {2.13031, 1.94}, {2.12666, 1.985}, {2.12302, 2.172}, {2.11939, > 2.175}, {2.11577, 2.161}, {2.11217, 2.184}, {2.10857, 2.082}, {2.10499, > 1.994}, {2.10143, 2.081}, {2.09787, 2.066}, {2.09433, 2.239}, {2.0908, > 2.167}, {2.08728, 2.192}, {2.08377, 2.207}, {2.08027, 2.3}, {2.07679, > 2.342}, {2.07331, 2.346}, {2.06985, 2.37}, {2.0664, 2.391}, {2.06297, > 2.436}, {2.05954, 2.321}, {2.05612, 2.433}, {2.05272, 2.528}, {2.04933, > 2.714}, {2.04594, 2.569}, {2.04257, 2.682}, {2.03921, 2.621}, {2.03587, > 2.899}, {2.03253, 3.089}, {2.0292, 3.136}, {2.02589, 3.259}, {2.02258, > 3.158}, {2.01929, 3.147}, {2.016, 3.295}, {2.01273, 3.279}, {2.00947, > 3.294}, {2.00622, 3.47}, {2.00298, 3.481}, {1.99975, 3.544}, {1.99652, > 3.882}, {1.99332, 4.078}, {1.99012, 3.939}, {1.98693, 4.153}, {1.98375, > 4.395}, {1.98058, 4.377}, {1.97742, 4.471}, {1.97427, 5.051}, {1.97113, > 5.072}, {1.968, 5.454}, {1.96488, 5.711}, {1.96178, 6.012}, {1.95868, > 6.169}, {1.95559, 6.691}, {1.95251, 7.021}, {1.94944, 7.428}, {1.94638, > 7.902}, {1.94333, 8.348}, {1.94028, 9.005}, {1.93725, 9.836}, {1.93423, > 10.504}, {1.93122, 11.491}, {1.92821, 12.563}, {1.92522, 13.621}, {1.92224, > 14.784}, {1.91926, 16.286}, {1.91629, 17.614}, {1.91334, 19.183}, {1.91039, > 20.854}} when `a` should be around $50$, `b` around $5$-$7$ and `c` around $1.88$. We both have the same initial guesses. What does the `<< >>` mean and why am I getting such bad results? Data: _Mathematica_ : EDIT: Added Data


title: For-loop not working as I expect

text: I want to do this:   * When `10 <= t < 130`, give `t -> 1`;   * When `130 <= t<300`, give `t->3`;   * When `300 <= t< 1000`, give `t -> 4`;   * When `1000 <= t < 2000`, give `t -> 5`; My code is this:               data = {10, 130, 300, 1000, 2000};     fun[t_] := Part[data, t];     comf[s_] := For[t = 1, t <= 4, t++, If[fun[t] <= s < fun[t+1], Print[t]]];      I could get this:               comf[110]      > >     1 >                 comf[1300]      > >     4 >   But when I evaluate this               comf[110] + 100      I didn’t get the right result, rather I got this: > >     100 + Null >   I would like to know how I could fix this problem.


title: Integration and plot of an interpolating function

text: FrenetFucntion = {         t'[s] == s* n[s],          n'[s] == -s* t[s] + 0.3* b[s],         b'[s] == -0.3* n[s],          t[0] == {{1, 0, 0}}, n[0] == {{0, 1, 0}},         b[0] == {{0, 0, 1}}     };     sol = NDSolve[FrenetFucntion, {t, n, b}, {s, 0, 50}];      How to integrate the solution of `NDSolve`. Also is there any way of plotting the integration function of interpolating polynomial? I used `NIntegrateInterpolatingPolynomial` but then it will give me definite integral only because I have to specify the limits of s. Is there any way of defining s limits like from 0 to s so that I may plot the result of integration as well.


title: Plotting derivatives of B-splines

text: I am trying to solve an electrodynamics problem numerically by using B-splines a basis function. Please don't ask me why, but if you really wanna know, here is the assignment. Using the following code, I have successfully plotted the B-spline basis functions in two dimensions, given the specific knot sequence and the respective x and y intervals.               knots = {0, 0, 0, 0, 0.2, 1, 1, 1, 1}     Plot3D[Evaluate[Table[BSplineBasis[{4, knots}, i, x], {i, 0, 3}]] Evaluate[     Table[BSplineBasis[{4, knots}, i, y], {i, 0, 3}]], {x, 0, 1}, {y, 0, 1}]      The corresponding plot looks like this: ![enter image description here](http://i.stack.imgur.com/Kwtb5.png) Now I am trying to do the same for the second derivatives of the B-splines, using the following code:               knots = {0, 0, 0, 0, 0.2, 1, 1, 1, 1}     Plot3D[Evaluate[Table[D[BSplineBasis[{4, knots}, i, x], {x, 2}], {i, 0, 3}]]      Evaluate[Table[D[BSplineBasis[{4, knots}, i, y], {y, 2}], {i, 0, 3}]],     {x, 0, 1}, {y, 0, 1}]      However, it does not work and produces an empty graph and lots of red error messages. I have tried several combinations of the D, Table and Evaluate operators, but nothing seems to work. What am I doing wrong?


title: Extracting angles from a simple picture

text: I'm not sure if this is even possible with _Mathematica_ , but I want to extract the angles between all lines in this picture: ![enter image description here](http://i.stack.imgur.com/OiTnw.png) It consists of $12$ lines, so I want a matrix with $144$ entries. I really have no idea even how to begin. Any ideas?


title: Problem with inequality using refine

text: I am using inequalities to follow some line of reasoning in Mathematica and I came across a problem I can not explain to myself. Does from a>=0 and b>=0 not follow a+b >= 0? How does Mathematica evaluate these statements? Thanks!               In[225]:= Refine[(A0 c0 (c - c1) >= 0),        A0 >= 0 && A >= A0 && A1 >= A && c1 >= 0 && c > c1 && c0 >= c]          Out[225]= True          In[226]:= Refine[(A (c0 - c1) c1 >= 0),        A0 >= 0 && A >= A0 && A1 >= A && c1 >= 0 && c > c1 && c0 >= c]          Out[226]= True          In[227]:= Refine[(A0 c0 (c - c1) + A (c0 - c1) c1 >= 0),        A0 >= 0 && A >= A0 && A1 >= A && c1 >= 0 && c > c1 && c0 >= c]          Out[227]= A0 c0 (c - c1) + A (c0 - c1) c1 >= 0


title: I am having a Plot and i need inside a Do loop to export 100 frames (changing the bounds of the plot)

text: for some reason i was thinking of doing this               Do[     Plot[F[x],{x,-i,i}];     Export["name_0" + i + ".jpg", %, "JPEG", ImageSize->{250,250}],     {i,5}]      but i get an error Any ideas or help is welcome ps. i am a terribly new at this :-) Regards, J.


title: Exporting a Table of Graphics into Individual Files

text: The command `Table[Polt[Sin[k x],{x,1,10}],{k,1,30}]` generates a list of graphics. I want to export each list item as an individual jpg file, named according to the order of appearance in the list. How can I do this? Thanks in advance.


title: how to export multiple graphics from Do loop?

text: I would like to export graphics generated from do-loop as jpg. There will be like more than 100 graphs. I want to combine it later in latex beamer as animation. When I put Export command inside the loop, I could not manage to change the name of the files since the name is inside "". Is there any way to solve this problem? Thank you very much.


title: Simple Animate[] question

text: I am trying to make a visualization of random process: coin flip. What I want to visualize is the result of i-th try: 1 or 0 value (the dot) and the mean (line) at i-th step. My code is as follows:               m = {}; c = {}; k = {};      Animate[      AppendTo[c, RandomInteger[]];      AppendTo[m, Mean[c]];      AppendTo[k, i];      Show[       ListPlot[Transpose[{k, c}]],        ListPlot[Transpose[{k, m}], Joined -> True,                PlotRange -> {{1, 100}, {0, 1}}, AxesOrigin -> {1, 0}]       ]      , {i, 1, 100, 1}, AnimationRepetitions -> 1,AnimationRunning -> False     ]      What I can't figure out is: Why at the very beginnig I get such a plot: ![I get such a plot:](http://i.stack.imgur.com/MJzVD.png) The line is not a mean value as should be expected. The second thing: Why there are two points at the moment, despite the fact that I have AnimationRunning->False? And the third: why k list is filled with ones only? Shouldn't it contain 1 to 100 values?


title: Dynamically splitting Disks with Mouseover

text: I've recently stumbled across this site: Koalas to the Max, and the first thought that came to my mind was "I want to recreate this with Mathematica". As a first step I tried to create a `Disk` that splits itself up into four disks, when the mouse cursor touches it. Those four disks should in turn split themselves up. Here's what I have so far:               makeDisks[pos_] := makeDisks[1, pos]     makeDisks[level_, pos_] :=      Module[{        disk = Disk[pos, 1/level]},       Mouseover[Dynamic@disk, Dynamic[disk = makeDisks[level + 1, #] & /@         (pos + # & /@ (1/(2 level)) Tuples[{-1, 1}, 2])]]       ]          (* test with the following *)           Graphics[{makeDisks[1]},        PlotRange -> {{-1, 1}, {-1, 1}}]      For the first disk this seems to work just as I want it. For later steps, however, I got the positioning wrong and some of the disks go back to larger ones, when another one is touched. How can these issues be fixed? As a next step I want to add colors to the disks. Maybe this can be done by using `MapIndexed` with `makeDisks` on the `ImageData` of some image. The colors in each step should probably be the mean values of appropriate subsets of the image data. Any help to move this little program forward is highly appreciated!


title: Can I change Legend text in a stylesheet?

text: I prefer a sans serif font in graphics, which I do by creating a style for "Graphics" in a stylesheet. However, this does not affect the style used by legend labels:               Plot[{x, 2x}, {x, 0, 1}, PlotLegends -> {"Times", "New Roman"}]      ![enter image description here](http://i.stack.imgur.com/JT9NB.png) Is there any way to change the legend text style in the stylesheet, or can it only be done through the `LabelStyle` option?


title: How to use Mathematica functions in Python programs?

text: I'd like to know how can I call Mathematica functions from Python. I appreciate a example, for example, using the Mathematica function **Prime**. I had search about MathLink but how to use it in Python is a little obscure to me. I tried to use a Mathematica-Python library called _pyml_ but I hadn't no sucess, maybe because this lib looks very old (in tutorial says Mathematica 2 or 3). So, someone knows a good way to write python programs who uses Mathematica functions and can give me an example? **Old Edit:** _Maybe this edit can help someone who wants to use mathlinks directly._ _To another solution, please see the answer accepted._ Using the _Wolfram/Mathematica/8.0/SystemFiles/Links/Python_ I could had sucess in compiling the module changing some things in setup.py. _My architechture is`x86-64`._ 1-Change the `mathematicaversion` to `8.0`. 2-Changing the lib name `ML32i3` to `ML64i3`. 3-Copying the file `Wolfram/Mathematica/8.0/SystemFiles/Libraries/Linux-x86-64/libML64i3.so` to the path pointed in setup.py `library_dirs = ["/usr/local/Wolfram/Mathematica/" + mathematicaversion + "/SystemFiles/Links/MathLink/DeveloperKit/Linux/CompilerAdditions"]`. 5-Compiling the source with `sudo python setup.py build`. 6-Installing the lib with `sudo python setup.py install` 4-Editing the file `/etc/ld.so.conf` and putting the line ` include /usr/local/lib`. 5-Creating a directory in `/usr/local/lib/python2.6/dist-packages/mathlink` with the lib `libML64i3.so`. 6-Running `sudo ldconfig` I had tested the scripts `guifrontend.py` with `python guifrontend.py -linkname "math -mathlink" -linkmode launch` and `textfrontend.py` with `python textfrontend.py -linkname "math -mathlink" -linkmode launch` and worked fine. Looks like I almost. But the script               >>> from mathlink import *     >>> import exceptions,sys, re, os     >>> from types import ListType     >>> mathematicaversion = "8.0"     >>> os.environ["PATH"] = "/usr/local/Wolfram/Mathematica/" + mathematicaversion + ":/usr/local/bin:/usr/bin:/bin"     >>> e = env()     >>> sys.argv=['textfrontend.py', '-linkname', 'math -mathlink', '-linkmode', 'launch']     >>> kernel = e.openargv(sys.argv)     >>> kernel.connect()     >>> kernel.ready()     0     >>> kernel.putfunction("Prime",1)     >>> kernel.putinteger(10)     >>> kernel.flush()     >>> kernel.ready()     0     >>> kernel.nextpacket()     8     >>> packetdescriptiondictionary[3]     'ReturnPacket'     >>> kernel.getinteger()     Traceback (most recent call last):       File "<stdin>", line 1, in <module>     mathlink.error: MLGet out of sequence.      breaks in the last command and I don't know why. How can I fix this?


title: calling mathematica code in Python

text: I am wondering if there is any working example of calling mathematica 9 outputs in python? or plotting mathematica output in python?


title: How to change the density range in DensityPlot?

text: This is an example from Mathematic Help,               DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},         ColorFunction -> "SunsetColors", PlotLegends -> Automatic]      We can notice that the density values are from -1.0 to 1.0. However, I want to change this automatic density range to other values, for example, 0 to 0.5. Of course, the density plot should be different. This should be simple, however, I have no idea about it. Can you tell me how to change it? Thanks!


title: Is it possible to select outliers on a graph and determine the index of the outliers?

text: I have a large data set of experimental data for which I have determined a theoretical fit. However, for some of the experimental data I took, there was systematic error, leading to the data deviating from the expected fit as shown below (experimental values are plotted on x-axis and theoretical values are plotted on y-axis). ![graph of data and outliers](http://i.stack.imgur.com/4K3Wo.jpg) Is it possible to write some code to allow one to simply click on the outliers and determine their index, or is there any way to do so natively in Mathematica? It would also be possible for me to divide the values plotted on the y-axis by those plotted on the x-axis, but I'm wondering whether there's a general method allowing you to click on to identify outliers on any graph. My code for the graph is as follows (I'm only plotting the first 500 values):               Show[ListPlot[Prepend[Transpose[{experimentalCR[[1 ;; 500]],       theoreticalCR[[1 ;; 500]]}], {0, 0}]], ImageSize -> {500, 500}, AspectRatio -> Full]      A sample of the data can be found here: http://pastebin.com/mA6VxPfw


title: Trouble carrying out symbolic operations on matrixes

text: I have some problems. First of all, I declare matrices like below               $Assumptions = {       Element[X, Matrices[{m, n}]],        Element[T, Matrices[{n, k}]],        Element[Y, Matrices[{m, k}]]};      and I want to apply               transpose(X T - Y).(X T - Y) =        transpose[T].transpose[X].X.T - transpose[T].transpose[X].Y -        transpose[Y].X.T + transpose[Y].Y      so I tried   1. `Inner[Times, {X \[Transpose]}, {T \[Transpose]}, Plus] - \[Transpose][Y]`   2. `Inner[NonCommutativeMultiply, {X}, {T}] - {Y} = {-Y + X ** T} ...` But I can not multiply the two above expressions.               Inner[NonCommutativeMultiply,        Inner[Times, {X\[Transpose]}, {T\[Transpose]}, Plus] - Transpose[Y],        Inner[NonCommutativeMultiply, {X}, {T}] - {Y}]      because I get errors. Could you help me?


title: Implementing new algebra for list-like objects

text: I would like to implement an algebra (addition, multiplication, etc.) for what is called "truncated power series" (TPSA) (Differential Algebraic description of beam dynamics). . These 'objects' (sets of complex numbers) have special rules for addition and multiplication. Of course the easy way to go is just to use plain lists and redefine functions like myAdd[], myMult[], etc. acting on these lists. However in most implementations in other languages these objects are represented as real objects (OO) of a 'TPSA' class, and operator overloading is used to manipulate them. My question is: I know the last solution is not the way to go with Mathematica, but the first easy way doesn't seem the best one either. How would you advice to implement that with Mathematica ? **Edit:** The root of my question was apparently "what is an up-value", the answer below about dual number also points in that direction.


title: How to change the output format of a built-in function

text: Is it possible to change the output of build-in functions? I would like to change the output for IdentityMatrix[n] to "I", so I tried               Format[IdentityMatrix[n]] := "I"      For comparison I also tried               Format[Sin[x_]] := "Sine(" <> ToString[x] <> ")"      Both result into an error: "Tag IdentityMatrix in IdentityMatrix[n] is Protected." I guess these functions are protected because they are build-in functions. Is there a way to change the output format of a build-in function?