Block Matrix Algebra with Mathematica

I have come up with some BlockMatrix Algebra for Mathematica to make notations easier. I have the following:               Needs["Notation`"];     Notation[ParsedBoxWrapper[     RowBox[{"A_", "\[CenterDot]", "B_"}]] \[DoubleLongLeftRightArrow]         ParsedBoxWrapper[     RowBox[{"BlockMultiply", "[",      RowBox[{"A_", ",", "B_"}], "]"}]]];     Notation[ParsedBoxWrapper[     SuperscriptBox["A_", "Inv"]] \[DoubleLongLeftRightArrow]         ParsedBoxWrapper[     RowBox[{"BlockInv", "[", "A_", "]"}]]];     Notation[ParsedBoxWrapper[     SuperscriptBox[     RowBox[{"(", "A_", ")"}], "T"]] \[DoubleLongLeftRightArrow]         ParsedBoxWrapper[     RowBox[{"BlockTransp", "[", "A_", "]"}]]];      And the actual matrix algebra functions:               ClearAll[BlockTransp]     (*SetAttributes[BlockTransp,OneIdentity]*)          BlockTransp[M_List] := Map[BlockTransp[#] &, Transpose[M], {2}]      BlockTransp[M__ + B__ ] := BlockTransp[M] + BlockTransp[B]     BlockTransp[a_ /; NumberQ[a]] := a;     BlockTransp[a_Scalar ] := a;     BlockTransp[a_   M__ /; NumberQ[a]] := a BlockTransp[M];     BlockTransp[a_Scalar   M__] := a BlockTransp[M];          BlockTransp[BlockMultiply[x_, y_] ] :=       BlockMultiply[BlockTransp[y], BlockTransp[x]]     BlockTransp[BlockTransp[x_]] := x          ClearAll[BlockMultiply]     BlockMultiply[mats1 : {{_ ..} ..}, mats2 : {{_ ..} ..}] :=       Inner[BlockMultiply, mats1, mats2]     (*For numbers*)          BlockMultiply[a_ A_ /; NumberQ[a], B_] := a BlockMultiply[A, B]     BlockMultiply[A_ , a_ B_ /; NumberQ[a]] := a BlockMultiply[A, B]     BlockMultiply[A__, a_ /; NumberQ[a]] := a A     BlockMultiply[a_ /; NumberQ[a], A__ ] := a A     (*For scalar symbols*)          BlockMultiply[a_Scalar A_, B_] := a BlockMultiply[A, B]     BlockMultiply[A_ , a_Scalar B_ ] := a BlockMultiply[A, B]     BlockMultiply[A__, a_Scalar ] := a A     BlockMultiply[a_Scalar, A__ ] := a A                    ClearAll[BlockInv]     BlockInv[mats1 : {{_ ..} ..}] := Map[BlockInv[#] &, mats1, {2}];     BlockInv[ a_ /; NumberQ[a]] := a          (*Make some formatting expression*)     Scalar /: MakeBoxes[Scalar[a_], StandardForm] :=        MakeBoxes[a, StandardForm];      I can do now some funny cool thing like:   **1\. Example:**   ![First Example](http://i.stack.imgur.com/LEmOc.png)   **2\. Example:**   ![Second Example](http://i.stack.imgur.com/s2Btb.png)   **3\. Example:**   ![Third Example](http://i.stack.imgur.com/o5P5z.png)   **4\. Example:**   ![Fourth Example](http://i.stack.imgur.com/42Yfj.png) **Remark:** Of course the `BlockInverse` Function is sensless in the sense that it does not really invert correctly. The input to `BlockInverse` should only be a **diagonal block matrix**! There is a general formula for block matrices Block Inversion, but it is not implemented here for the sake of simplicity. I have two questions which I could not come up so far:   1. How can I make the 3. example such that the `scalar` variable is treated like a scalar? Can I overload `NumberQ[scalar]:= ...` ? Or is there a better way? **[SOLVED]** See the above definitions with added `_Scalar` that matches any pattern with head `Scalar`. See example 4!   2. How can I pretty print these things such that superfluous brackets are neglected? Is there some elegant way for the function definitions such that, associativity and non-commutativity is handled well?


A good choice to find solutions of ODE

In order to rephrase the question. I would ask you to take a look at the following problem:   1. I have this system of ODE: $$ \begin{cases} \dot{x}(t)= x(t)[r_1(t) -b_1(t)x(t- \tau(t)) - c_1(t)y^m(t)] & t\neq t_k\\\ \dot{y}(t)= y(t)[- r_2(t)- b_2(t) y(t- \sigma(t)) +c_2(t) x(t) y^{m-1}(t)] & \\\ \Delta x(t_k)= x(t_k^+)- x(t_k)=d_k x(t_k) & t=t_k\\\ \Delta y(t_k)= y(t_k^+)- y(t_k) = f_k y(t_k) & \end{cases}. $$   2. $x(t)$ and $y(t)$ are discontinuous function at points $t_k$.   3. All these functions: $r_1(t), \, r_2(t), \, b_1(t), \, b_2(t), \, c_1(t),\mbox{ and } c_2(t)$ are positive and periodic with the same period $\omega$.   4. $\tau(t)$ and $\sigma(t)$ are continuously differentiable positive periodic functions with the same period $\omega$ such that $\tau'(t) <1 \mbox{ and } \sigma'(t)<1$.   5. $m\in (0,1)$   6. $-1 < d_k \leq 0, \, -1 < f_k \leq 0$ are constants for $k=1,2, \cdots,$ such that there exists a positive integer $q$ $t_{k+q}=t_k + \omega$. I am trying to make the right choice for these parameters to solve this with _Mathematica_.


Problems with manipulating plot in a dialog

G'day, guys. Here is a silly problem I am struggling with.               (*file name: 1.nb*)Button["Load the program", NotebookEvaluate[SystemDialogInput["FileOpen"]], Method->"Queued"]          (*file name: 2.nb*)eff = 1 - y Abs[1 + x]/(2 + Abs[1 + x]);CreateWindow[DialogNotebook[{TabView[{"eff"->Panel[With[{expr = eff}, Manipulate[Plot[expr, {x, -5, 5}], {y, 0, 0.1, 0.001}]]]}]       The 2 lines of codes are saved in separate file. The idea is that I want to use the first file to open the 2nd file and show the manipulate output in a dialog. The 2nd file runs fine with itself from notebook (i.e. output shows fine in notbook and a dialog window). However, if I choose the 2nd file by running the 1st file, the graph doesn't update dynamically. Anyone got an idea for that? Thanks in advance!!


Percentage axis ticks

To create a percentage axe in some plot I use this `Ticks` configuration:               ListPlot[          Range[0,1,0.1]         ,Ticks->{Automatic, {#,If[IntegerPart@Mod[100#,10]==0,Row[{100#,"%"}],""]}&/@Range[0,1,0.05]}     ]      ![enter image description here](http://i.stack.imgur.com/HieCK.png) That has 3 disadvantage:   1. Non automatic range scale   2. No subticks with different sizes   3. It's nor elegant nor simple I miss a Mathematica `TicksFunction` or equivalent, so I could have better control over it. I also tried something like: `ListPlot[Quantity[Range[0, 1, 0.1], "Percent"]]` without succes. Some clue into a better approach?


What is the real default CellEvaluationFunction?

The default `CellEvaluationFunction` is `Identity` but one can quickly see that this is handled specially as an equivalent function, `(# &)`, does not work at all the same. The sole example in the documentation uses `ToExpression` but this also does not work the same, returning only the output of the last line in the Input Cell:               SetOptions[EvaluationNotebook[], CellEvaluationFunction -> ToExpression]      Now in one cell:               2 + 2     5 + 7      > >     12 >   My question is then: What is the _real_ default function that correctly handles multi-line input/output including the `Out[xx]=` cell labels?


Any code to add elements of a list to make a new list?

Is there any code built in to add the numbers in a list sequentially? For example, lets say I have a list B. B has 6 numbers like below.               B={0,6,5,4,3,2}      I want to produce a new list C. C will add the first two numbers in the list, so 0+6 = 6. That will be put into the new list C. Then the next term in the list C will be 0+6+5 = 11. And then 0+6+5+4 = 15, and so on. The result of the new list C will be as below.               C={6,11,15,18,20}      Any help is appreciated. Thanks.


I'm getting this error in Wolfram Workbench, and I don't know where it comes from: "Syntax error: newline character interpreted as multiplication" This error happens around an If[] function, in a custom function, defined as               myFunction[x_,y_] :=          Module[{variable},          (* some code *)     variable = 1     If[x==2,x=3,x=4]          (* some code *)          ]      No matter where I try to put my If[] function inside myFunction[], I get this error, but I don't get it if I put it outside myFunction[]. Maybe the problem comes from the Module[] function, as when I take it out the error disappears. Any idea what's going on?


Constructing a list that includes a leading zero (01,02,03 ... 55, 56, etc.)

I am constructing a list for use in file operations. Say I want to create `list` which contains values from 01 to 87. The kicker is that the first nine integers need to keep a value of `01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11.. etc.` So if I create `list=Range[87]` I generate a list of integers. Whenever I'm trying to then replace values with '01', etc. they become strings. If they are integers, they revert back to the single value. Ideally, I need a list that I can feed through `Do[]`. Is there a quick way to create a list that uses the two digit form the whole time? FWIW, the specific application of this that I have a list of files i.e. `{1997-01-page100.jpeg, 1997-01-page101,jpeg, <<33 379>>, 1997-87-page9.jpeg, 1997-87-page10,jpeg}`. I'm using the following command to generate specific lists of the sub-file using `importlist=FileNames["1997-"<>ToString[x]<>"-*.jpeg"]` but am being thrown off by the zero in front of the single-digit file number.


What changes in Dynamic have occurred from Mathematica 7 to Mathematica 8 that might induce incompatibilities?

I have a function that outputs a Manipulate (say                FAnimated[params_]:= Manipulate[F[params,t], {Time, Animator[t]}]      where `F` is some function that takes `params` and `t` and makes a plot. Suppose I make some sliders that control various of the params:               Slider[Dynamic[p1], {3, 7}]      and call               Dynamic[FAnimated[{p1,p2,etc}]].      The hope is that the sliders should let me vary parameters in my plots while they run their animation. In Mathematica 7, this works great, and runs very smoothly. In Mathematica 8, the exact same code no longer lets me drag the sliders while the animation is running, and also doesn't let me drag the sliders smoothly even when the animation is paused! So the question is, "What changes (either in `Dynamic` functionality or in some options that might possibly be set different by default) might cause this code to break?"


Efficient conditional division

I was curious about the following little problem. Suppose $n \in \mathbb{N}$ is some large number and $p$ is a (possibly large) prime, and I want to update $n$ according to $$n := \begin{cases} n/p, & (n,p) = p; \\\ n, & (n,p) = 1.\end{cases}$$ In other words, I want to divide by $p$ if $p$ divides $n$, and not divide by $p$ if $p$ does not divide $n$. Also, I would like to know if a division took place. Of course I could implement this with something like               If[Divisible[n,p],        n = Quotient[n,p];        Print["A division took place!"];     ];      However, this feels inefficient, since to check divisibility the machine may have already computed $n/p$. Would there be a more efficient way to do this in Mathematica? i.e. A way that uses only $1$ division if $p$ divides $n$ and at most $1$ division if $p$ does not divide $n$? Also, I'm curious which Mathematica functions would be most suited for these purposes in general. Is there any difference in performance between e.g. `Divisible[n,p]`, `Mod[n,p] == 0`, `IntegerQ[n/p]`, `FractionalPart[n/p] == 0`, `CoprimeQ[n,p]`, `GCD[n,p] == p`? Thanks in advance.


Can graph interpolating function, but not use it. Any thoughts?

When solving a system of differential equations numerically, I get two interpolating functions. I can graph both of these, but when I try to evaluate either of the functions at a point, it just spits out:               {x1[5]}      `x1[t]` is the interpolating function, and 5 is the number I chose to try to evaluate it at. I set `prsol=NDSolve[blah blah]` To evaluate it, I've tried:               Evaluate[x1[5]/.prsol]      and               one[t_]:=x1[t]/.prsol     one[5]      Both of these spit out `{x1[5]}` which is contrary to what the F1 Help says it should do.               P0h = 1.856*10^7;     V0h = .826063;     T0 = 299.817     g = 9.81;     Aac=.16;     Abe=.025;     Vr=1.067;     Vst=.006306;     Vh[x_] := Vr - x*Aac;     Vl[x_] := Vst + x*Abe;     m1 = 290000;     m4 = 9021;     k3 = 8*10^6;     R = 8.3144621;     Tc = 126.1;     Pc = 3.394*10^6;     ω = .040;     b = .07779607*(R*Tc)/Pc;     Trr[T_] := T/Tc;     κ = .37464 + 1.54226 ω - .26993 ω^2     α[T_] := (1 + κ (1 - Sqrt[Trr[T]]))^2     ac = .45723553*(R^2*Tc^2)/Pc;     a[T_] := ac*α[T]     nh = (P0h*V0h)/(R*T0);     nl = (P0l*V0l)/(R*T0);     Vmolh[x_] := Vh[x]/nh     Vmoll[x_] := Vl[x]/nl          Ppr[x_] := (R*T0)/(Vmolh[x] - b) -        a[T0]/(Vmolh[x]^2 + 2*b*Vmolh[x] - b^2)          Fpr[x_] :=       Aac ((R*T0)/(Vmolh[x] - b) -           a[T0]/(Vmolh[x]^2 + 2*b*Vmolh[x] - b^2)) -        Abe ((R*T0)/(Vmoll[x] - b) -           a[T0]/(Vmoll[x]^2 + 2*b*Vmoll[x] - b^2))          A1 = .1;     ω2 = π/4;     c = 10000;     d = 300000;          ctipmot[t_] := A1 Cos[ω2 t]          prsol = NDSolve[{-c x4'[t] -           k3 ((m4 g + Fpr[54/39.3701])/k3 + ctipmot[t] + x4[t]) +           Fpr[x1[t] - x4[t] + 54/39.3701] + m4 g ==          m4 x4''[t], -c x1'[t] - d x1'[t]*Abs[x1'[t]] -           Fpr[x1[t] - x4[t] + 54/39.3701] + m1 g == m1 x1''[t], x1[0] == 1,         x4[0] == 0, x1'[0] == 0, x4'[0] == 0}, {x1[t], x4[t]}, {t, 0,         100}]      > {{x1[t] -> InterpolatingFunction[{{0.,100.}},<>][t],x4[t] -> > InterpolatingFunction[{{0.,100.}},<>][t]}}               Plot[Evaluate[x1[t] /. prsol], {t, 0, 32}]      ^That gives me a graph               Evaluate[x1[5] /. prsol]      ^That gives me:               {x1[5]}      instead of a value.


How to batch run Mathematica code from Python?

I have this notebook:               arg1 = "input.txt";     arg2 = "output.txt";     u1 = Import[arg1, "Table"];     u2 = u1(*extremely complicated and long chain of operations*);     Export[arg2, u2]      and I would like to run it in a Python program like this:               def run(arg1,arg2):         my_mathematica_code(arg1,arg2)          for i in range(100):         run("input{}".format(i), "output{}".format(i))      How can I do this? Preferably without GUI and several threads in parallel (I can use 4 cores in Mathematica).


How can I draw an asymptotic bode plot?

When I use _Mathematica_ to draw a bode plot, it always gives the precise version, like this:               BodePlot[(10 (s + 3))/(s (s + 2) (s^2 + s + 2))]      ![enter image description here](http://i.stack.imgur.com/ZjVkf.png) How can I draw the asymptotic version, the kind where `1/(1 + jw)` is represented as a -20dB straight line but not a curve?


Matrix and string variable

There are $100$ `.dat` data files which contain numerical parameters.               m={1,2,.....,34};     n={8,10,12,.....19};     l={67,68,69,...96}       and so on. I constructed a $100*100$ matrix with the code below:               xmatrixx = Table[0, {100}, {100}];     mflatten=Flatten[m];          Do[xmatrixx[[i, j]] = mflatten[[j]], {i, 1, 1}, {j, 1, 34}]];      But I want to put `n` and `l` and the other files in the other rows of the same matrix `xmatrixx`. How can I change the `mflatten` for obtaining `n` and `l`? All the Best


How can I get the solution of complicated implicit function?

The question is what is the method to solve the implicit function has real and imaginary number. For example, The function is $$F(x,y)=(-I*x + 2*y^2)^2 + x^2 - 4*y^4*Sqrt[1 - I*x/(y^2)]$$ Although I used a `NSolve` and `Solve` I can't get the solution. (It is too complicated to solve by those command i think.) What is the value y? (y may be a complex number when x is given) And is it possible to draw a graph of `Real[y] - x` and `Imaginary[y] - x`?


ParametricNDSolve and Constraint satisfaction problem

I am trying to find the values of two parameters that allow for a specific result of my differential equations, under different initial conditions. Given a system of equations:               TestSystem = {H'[t] == p - H[t] (k1 sh[t]), H[0] == H0,        sh'[t] == -k1 H[t] sh[t] + k2 ss[t], sh[0] == sh0,             st == sh[t] + ss[t]};      I use `ParametricNDSolve` to compute the values of the dependent variables, while leaving `k1` and `k2` unspecified:               TestSolver[H0e_, st0_] :=      ParametricNDSolve[       TestSystem /. p -> 0 /. {H0 -> H0e}           /. sh0 -> st0 /. st -> st0         /. k2 -> k2estim /. k1 -> k1estim, {h, sh, st}, {t, 0,         300}, {k1estim, k2estim}];      The conditions that I want to evaluate are then specified by `m,d,hh`, at `t=300`:               m = 100 sh[k1estim, k2estim][300]/st;     d = 100 ss[k1estim, k2estim][300]/st;     hh = h[k1estim, k2estim][300];          cond1a[k1estim_, k2estim_] :=       Evaluate[m /. st -> 5.*^-6 /. TestSolver[1.*^-5, 5.*^-6]]     cond1b[k1estim_, k2estim_] :=       Evaluate[d /. st -> 5.*^-6 /. TestSolver[1.*^-5, 5.*^-6]]     cond1c[k1estim_, k2estim_] :=       Evaluate[hh /. TestSolver[1.*^-5, 5.*^-6]]          cond2a[k1estim_, k2estim_] :=       Evaluate[m /. st -> 5.*^-6 /. TestSolver[5.*^-5, 5.*^-6]]     cond2b[k1estim_, k2estim_] :=       Evaluate[d /. st -> 5.*^-6 /. TestSolver[5.*^-5, 5.*^-6]]     cond2c[k1estim_, k2estim_] :=       Evaluate[hh /. TestSolver[5.*^-5, 5.*^-6]]      Now, say that I wanted to find the following               1 < cond1a < 100,     0 < cond1b < 1,     1.*^-8 < cond1c < 1*^-5,     1 < cond2a < 50,     50 < cond2b < 100,     1.*^-8 < cond2c < 1*^-5,      How could I find the values of `k1` and `k2` that would satisfy such a thing? I was considering using `NMinimize` like this:               NMinimize[{1/cond1a+cond1b+cond1c+cond2a+1/cond2b+cond2c,cons},{k1,k2}]      (where `cons` would be the required constrains). Yet, this does not seem like an efficient and plausible way to solve this problem. Does anyone have any ideas on how I could approach this problem? Given that this is a multi-objective optimization problem, how would you suggest that I could specify the objective function? Thank you so much!


How to substitute $x$ in a expression $f(x)$ but not calculate the value of the $f(x)$ at the point $x$?

I want to subtitute $x = 1$ into the expression $$f(x)=x^2 + 3 (x^2 - m^2) + \sqrt{x^2 + 1}$$ but I don't calculate the value $f(1)$, that is mean, I want $$1^2 + 3(1^2-m^2)+\sqrt{1^2 + 1}.$$ If I tried               f[x_] := x^2 + 3 (x^2 - m^2) + Sqrt[x^2 + 1];     f[1]      I receive `1 + Sqrt[2] + 3 (1 - m^2)` How do I tell _Mathematica_ to do that?


Comparing Positions of Elements in a List

How can I check if `Position[i] > Position[j]` for two arbitrary elements in a given list? The problem is that `Position[i]` returns `{{k}}` instead of just `k`, and I don't know how to compare `{{k}}` and `{{l}}`.


Finding the maximum order derivative of an expression

I have an expression that is the the sum and product of undefined derivatives and their derivatives. e.g. `fg+ Dt[f,t]g +Dt[g,{t,2}]f+` What I would like to find is the maximum order of the derivatives, and so 2 would be returned for the above example. My first attempts use `Cases` to make lists of the order of derivatives. This would send `Dt[x_,t]->1` and `Dt[x_,{t,n_}]->n`. However for some reason `Dt[f,t]` and `Dt[f,{t,2}]` fail to match with their respective patterns and don't trigger the rule. If, in the rules, the `x_` is replaced with `f` the rules will trigger but only for `f` and no other function. Is there a way to do this search without a strict list of the available functions.


Programming a numerical method in the functional style

I am new to _Mathematica_ and I would like to learn a bit more about functional programming. At the moment I have assignments like programming different numerical methods (for integration: trapezoidal rule, simpson's rule ,.. , for differential equations: euler's method, midpoint Runge-Kutta, ..). I've been implementing all of the methods with procedural programing, with `While` loops and `For` loops, but now with Eluer's method I've started using functional programming and have used `Table` and `FoldList` instead of a `For` loop. It comes together quite nicely. Here is an example:               euler[f_Symbol, y0_, {tz_, tk_}, h0_: 0.1] :=       Module[{t0 = tz, h = h0, n = Abs[tz - tk]/h0, Y, T, y},         y = FoldList[#1 + h*f[#1, #2] &, y0, Table[t0 + i*h, {i, 0, n - 1}]];         T = Table[t0 + i*h, {i, 0, n + 1}];         Y = Table[N[{T[[j]], y[[j]]}], {j, 1, n + 1}];         ListPlot[Y, Joined -> True, PlotRange -> All]       ]      I would like to do something similar with the midpoint Runge-Kutta method, but I don't know how. Here is the procedural code:               midpointRK[f_, y0_, ta_, tb_, h0_: 0.1] :=       Module[{tA = ta, tB = tb, h = h0, n, Y, g, y},         n = Abs[tB - tA]/h;         y[0] = y0;         For[i = 0, i <= n, i++,           y[i + 0.5] = y[i] + (h/2)*f[y[i], tA + i*h];           g = f[y[i + 0.5], tA + i*h*0.5];           y[i + 1] = y[i] + h*g;           Y = Table[{N[tA + j*h], y[j]}, {j, 0, n}]         ];         ListPlot[Y, Joined -> True, PlotRange -> All]          ]      Can someone please help me in this regard and explain to me a little, what each command does?


How can I detect and modify one area of an image while preserving the rest

I have an image with a big black disk bounded by a white boundary in its center. The image contains some other stuff outside of the spot and its boundary. This stuff has colors which include both black and white. I wonder whether _Mathematica_ can do either of the following:   1. Find the position of all the points in the central disk   2. Change the color of the central disk to red while preserving all the other parts of the image.  ![enter image description here](http://i.stack.imgur.com/kJVmP.png)


How to convert rgb to YCbCr?

I looked at `ColorConvert`, but haven't found a relevant option. Is there a built-in function do this?


Improving a function that filters each table from a list of tables

I have written the following function which can take in a list of tables as an arguement, and then filters each one. The function I wrote is below, and the commands I combined are listed below the function in case it is not clear what the steps are (sometimes I get confused if things are all strung together). Can this be cleaned up to be more concise, and readable?               Function[myTable, {tunableORRData =      Replace[myTable , a_ /; Abs[a] >= 10 -> 0, {2}] - ORR /.         targets; d = Sign@Diagonal@tunableORRData;         returnValue[row_, col_, myTable] := myTable[[row, col]] ;         tunablePairs =          Position[(tunableORRData\[Transpose] d)\[Transpose], _?          Negative]  /. Reverse /@ elementList;         pairEnergy =          returnValue[#1, #2] & @@ {#1, #2} & @@@           Position[(tunableORRData\[Transpose] d)\[Transpose], _?            Negative] ;         tempVar = Partition[Riffle[tunablePairs, pairEnergy], 2];          filterImposs = Replace[tempVar, a_ /; Abs[a] >= 5 -> 0 , {2}] ;          filterImposs = Replace[filterImposs, a_ /; a > 1 -> 0 , {2}] ;          Cases[           filterImposs, {x_, y_} /; y != 0]}][#] & /@ {smallBindingTable,            bigBindingTable}      Targets is used to set any value to the table equal to zero that is exactly the target. element list is used to map elements onto rows and columns of the tables.               targets = {ORR -> -1.51}     elementList = {"Sc" -> 1, "Ti" -> 2, "V" -> 3, "Cr" -> 4, "Mn" -> 5,       "Fe" -> 6, "Co" -> 7, "Ni" -> 8, "Cu" -> 9, "Zn" -> 10, "Y" -> 11,       "Zr" -> 12, "Nb" -> 13, "Mo" -> 14, "Tc" -> 15, "Ru" -> 16,       "Rh" -> 17, "Pd" -> 18, "Ag" -> 19, "Hf" -> 20, "Ta" -> 21,       "W" -> 22, "Re" -> 23, "Os" -> 24, "Ir" -> 25, "Pt" -> 26,       "Au" -> 27};      Leave only those elements that are within 0.05 of the target non zero               idealORRSmall =      Replace[smallBindingTable - (ORR) /. targets,       a_ /; Abs[a] >= 0.05 -> 0, {2}] ;      Get those elements and their positions. Then map a rule replacement to put the element names in, and the table name (to make the output human readable) Then filter the same table broadly for a different search.               tunableORRData =        Replace[smallBindingTable , a_ /; Abs[a] >= 10 -> 0, {2}] - ORR /.         targets; (*set any spurious values to zero *)      Here we filter to see if the diagonal element is on opposite sides of the target. IE (opposite in sign from any member of the column)               d = Sign@Diagonal@tunableORRData;     returnValue[row_, col_] :=       smallBindingTable[[row,         col]] ; (* lets us take row, col data from theidealORR data and \     get the energy from the small binding table*)          tunablePairs =       Position[(tunableORRData\[Transpose] d)\[Transpose], _?Negative]  /.        Reverse /@         elementList; (* get tunable pairs, map on element names *)          pairEnergy =       returnValue[#1, #2] & @@ {#1, #2} & @@@        Position[(tunableORRData\[Transpose] d)\[Transpose], _?Negative] ;     tempVar = Partition[Riffle[tunablePairs, pairEnergy], 2];          filterImposs = Replace[tempVar, a_ /; Abs[a] >= 5 -> 0 , {2}] ;     filterImposs = Replace[filterImposs, a_ /; a > 0 -> 0 , {2}] ;          Cases[filterImposs, {x_, y_} /; y != 0]      I have included a sample data table needed to make this work in a txt file. Here is the link:smallBindingTable Below is the output from filtering the smallBindingTable. I would like to do the same thing with a list of such tables.               {{{"Sc", "Pd"}, -1.47187}, {{"Sc", "Ag"}, -1.69071}, {{"Ti", "Mn"},       0.860106}, {{"Ti", "Au"}, -1.19295}, {{"V",       "Au"}, -1.10513}, {{"Cr", "Au"}, -0.131714}, {{"Mn",       "Ag"}, -2.51796}, {{"Mn", "Pt"}, -1.29537}, {{"Mn",       "Au"}, -1.21843}, {{"Fe", "Ag"}, -1.81939}, {{"Fe",       "Au"}, -1.44088}, {{"Co", "Au"}, -1.30395}, {{"Ni",       "Au"}, -0.671956}, {{"Zn", "Ag"}, -2.13397}, {{"Y",       "W"}, -0.189288}, {{"Nb", "Au"}, -1.087}, {{"Mo",       "Au"}, -1.1764}, {{"Tc", "Au"}, -0.922638}, {{"Ru",       "Au"}, -0.787955}, {{"Rh", "Au"}, -0.482705}, {{"Pd",       "Au"}, -0.379127}, {{"Ta", "Ag"}, -2.3501}, {{"Ta",       "Au"}, -1.12029}, {{"W", "Au"}, -1.16135}, {{"Re",       "Pt"}, -1.22974}, {{"Re", "Au"}, -1.04512}, {{"Os",       "Au"}, -0.76104}, {{"Ir", "Au"}, -0.578992}, {{"Pt",       "Au"}, -0.593863}}


Multi-table SQLSelects

I'm trying to figure out how these statements really work, and am having some trouble with the documentation (and the software!). Using the example publishers database (Mathematica 8), the following works fine (as documented):               SQLSelect[conn,{"TITLES","ROYSCHED"},{{"TITLES","TITLE"},         {"TITLES","TITLE_ID"},{"ROYSCHED","TITLE_ID"},{"ROYSCHED","ROYALTY"}},       "MaxRows"->5]      Now, there is no column `ROYALTY` in the `TITLES` table, so perhaps I should be able to write               SQLSelect[conn,{"TITLES","ROYSCHED"},{{"TITLES","TITLE"},         {"TITLES","TITLE_ID"},{"ROYSCHED","TITLE_ID"},"ROYALTY"},       "MaxRows"->5]      But this results in the error               DatabaseLink`SQL`Private`SQLValue::illegalvalue:          The value {{TITLES,TITLE},{TITLES,TITLE_ID},{ROYSCHED,TITLE_ID},ROYALTY}          cannot be converted to a value in an SQL statement.      So apparently either none or all of the entries in the columns list must themselves be lists. Is this right, or a bug, or what? So assuming that this is correct, and all the columns must be lists in any multi-table inner join, how can I then apply a function such as `COALESCE` to the results to cast NULLs to zero? I tried `{"TITLES","COALESCE(TITLE_ID,0) AS TITLE_ID"}`, which failed because the string passed to the JDBC driver was `TITLES.COALESCE(TITLE_ID,0) AS TITLE_ID`, which is of course incorrect. At the risk of asking too many questions in one question, let me add: I'm perfectly OK with simply returning the rows I want, with whatever NULLs may be in them. But can someone tell me the right way to turn all those NULLs to zeros once the result set is a Mathematica list?


PlotLegends from a List

I want to generate plots showing dependence of a function on another parameter, and automatically add correct PlotLegend that says which graph is which parameter.               f[x_, a_] := x + a ; Params = {1, 2};     Plot[Evaluate[f[x,#] & /@ Params], {x, 0, 1},           PlotLegends -> {StringForm["a = ``", #] & /@ Params }]      But this doesnt work, Mathematica complains that functions and legend are not the same shape.


Web deployment of document containing URLSave function

Is it possible to deploy a _Mathematica_ notebook which contains a dynamic `URLSave` function? My code has the following structure:               web = URLSave["http://www.wolfram.com/mathematica/", Close[OpenTemporary[]]]     web = Import[web, {"GZIP", "Text"}]     Dynamic[web, UpdateInterval -> 20, TrackedSymbols -> {}, SynchronousUpdating -> False]      The problem is when I start to deploy it, in the last step after I indicate in which folder to save the CDF file, then this error appears: > Select::normal: Nonatomic expression expected at position 1 in > Select[C:\Users\Morry\Dropbox\MEPS\ALISalehi\HTML\146\Untitled.cdf,StringMatchQ[#1,*.png]&].


$\LaTeX$ and Mathematica

I quite often would like to draw graphics in my $\LaTeX$ documents using Mathematica. I have encountered three problems. I would like to know if there are any workarounds to these problems I would like to make my graphics homogeneous with my document. That means that I would like to use the same font in the graphics (labels for axis etc) as the main text. Mathematica does not support Computer Modern. I found a workaround using PSFrag, saving graphics as EPS. It is possible using PSfrag to rename the text in the graphic into $\LaTeX$ code. A big downside is that this method does not allow me to use pdflatex. Many other packages (hyperlink) therefore do not work. `Graphics3D` objects are extremely big. If I save it using a bitmap, the picture usually becomes horrible. I often would like to use transparency. If I use `Opacity` to make some part of the graphic transparent, the exported file in Mathematica is horrible.


After executing MessageDialog[] how can I wait for it to close before continuing? I want to popup up a message and wait for the user to hit OK before continuing. Is there a mechanism for this?


Choosing a position in an array with uniform random probability conditioned on it having a specific element

I have an array `exArray` with two types of integer elements: `1` and `2`. I'd like to choose a position $k$ in the array with uniform random probability conditioned on it having an element with the value `1`. Is there a one-liner to do this? Right now I'm using `RandomInteger[{1,arrayLength}]`, which is a ridiculous way to proceed.


Solve function doesn't work

I have the following system of equations that I need to solve:               ArrayOfEquations={-(u/10) + 0.4 v[1] - 0.16 v[2] + 0.064 v[3] - 0.0256 v[4] +      0.01024 v[5] - 0.004096 v[6] + 0.0016384 v[7] - 0.00065536 v[8] +      0.000262144 v[9] == g[1],      -0.4 v[1] + 0.32 v[2] - 0.192 v[3] + 0.1024 v[4] -      0.0512 v[5] + 0.024576 v[6] - 0.0114688 v[7] + 0.00524288 v[8] -      0.0023593 v[9] == g[2],      -0.16 v[2] + 0.192 v[3] - 0.1536 v[4] + 0.1024 v[5] -      0.06144 v[6] + 0.0344064 v[7] - 0.0183501 v[8] + 0.00943718 v[9] ==g[3],      -0.064 v[3] + 0.1024 v[4] - 0.1024 v[5] + 0.08192 v[6] -      0.057344 v[7] + 0.0367002 v[8] - 0.0220201 v[9] == g[4],      -0.0256 v[4] + 0.0512 v[5] - 0.06144 v[6] + 0.057344 v[7] -      0.0458752 v[8] + 0.0330301 v[9] == g[5],      -0.01024 v[5] + 0.024576 v[6] - 0.0344064 v[7] +      0.0367002 v[8] - 0.0330301 v[9] == g[6],      -0.004096 v[6] + 0.0114688 v[7] - 0.0183501 v[8] +      0.0220201 v[9] == g[7],      -0.0016384 v[7] + 0.00524288 v[8] - 0.00943718 v[9] == g[8],      -0.00065536 v[8] + 0.0023593 v[9] == g[9],      -0.000262144 v[9] == g[10]}      I want to solve it for variables $u$ and $v[i]$, $i=1,..9$. When I call               Solve[ArrayOfEquations, Join[{u}, Array[v, 9]]]      I get {} as an output. Why doesn't it work? I understand that {} in general means no solution. However, I tried it with some numbers substituted for $g[i]$ and got a numerical output. Can't understand what goes wrong if I keep the $g[i]$ symbolically Thanks for any help!


Band Intensity Quantification

I would like to measure the density of my western blot band by measuring the area under the peak from this plot. More specifically, my image will have several lanes with a pattern of bands in each lane (see link below). I would like to select an area and then measure the intensity of the bands as scanned from top to bottom. I would do this for each lane by selecting same area (essentially move my rectangle over to the new lane) and then plot the density vs length of gel (down direction). I would then like to integrate the area under each curve to get a value which can then be compared to the pattern and density (increased or decreased) of the neighboring lane. Is this possible to do in _Mathematica_ and, if so, how can I do it. I'm very new to _Mathematica_ and any help would greatly be appreciated. ![http://i2.wp.com/homemadeprojects.org/wp- content/uploads/2014/02/gel.png](http://i.stack.imgur.com/HnRBX.png) * * * _Keywords_ : line, lines, spectrum, spectral


How can I format a table to look nice?

I have this code, but i would like to see the results well formated, How can I obtain a well formatted data with aligment?, similar to this one ![http://img854.imageshack.us/img854/9938/snap2002.png](http://i.stack.imgur.com/W62Pm.png) insted what i obatin, you can see here ![http://img856.imageshack.us/img856/2972/codeandtalbamalformatte.png](http://i.stack.imgur.com/GBQ7W.png) * * * Here is the code, where i want to obtain a well formated results:               itmax = 10;     tolerancia = 0.2;     alfa = (-1 + Sqrt[5])/2;     ttheta[Lambda_] = Lambda^2 + 2*Lambda;     a = -3;     b = 5;     La = a + (1 - alfa)*(b - a) // N;     Mu = a + alfa*(b - a) // N;     tthetaLa = ttheta[La];     tLacalc = "*";     tthetaMu = ttheta[Mu];     tMucalc = "*";     Print["iteración_k   |   a_k    b_k   |   Lambda_k     Mu_k   |   \     theta(Lambda_k)  theta(Mu_k)"];     Do[       L = b - a;       Print[i, "   |   ", a, "     ", b, "   |  ", La, "     ", Mu,         "   |  ", tthetaLa, tLacalc "      ", tthetaMu, tMucalc ];       If[tthetaLa > tthetaMu,        If[b - a < tolerancia, Break[]];             a = La;        La = Mu;        Mu = a + alfa (b - a);        tthetaLa = tthetaMu;        tLacalc = " ";        tthetaMu = ttheta[Mu];        tMucalc = " ";,             b = Mu;        Mu = La;        La = a + (1 - alfa) (b - a);        tthetaMu = tthetaLa;        tMucalc = " ";        tthetaLa = ttheta[La];        tLacalc = "*";        ]       , {i, 1, itmax}       ];     solucionestimada = (Mu + La)/2;     valorestimado = ttheta[solucionestimada];     Print["The stimated solution is ", solucionestimada,        " where functions value is ", valorestimado];


Plot3D Not Showing plot

I have a function that I'm trying to visualize and for some reason the plot only shows a small snippet of the graph of the function. The function, `d`, and relevant values are as follows:                   G = 6.67*10^(-11)         c = 3*10^8         M = 10^(30)         J = 10^(20)         \[Gamma] = 0.018         rmin = M  + Sqrt[M^2 - J^2/M^2]              d[r_, \[Theta]_] = 1 - (2 G M r)/(c^2 r^2 + J^2/M^2 Cos[\[Theta]]^2)                             - (Sin[\[Theta]]^2 \[Gamma]^2)/c^2 (r^2 + J^2/(M^2 c^2) + ( 2 G J^2 r Sin[\[Theta]]^2)/(c^4 M (r^2 + J^2/(M^2 c^2) Cos[\[Theta]]^2)))                             + (8 \[Gamma] G r J Sin[\[Theta]]^2)/(c^4 (r^2 + J^2/(M^2 c^2) Cos[\[Theta]]^2))      The exact values of `\[Gamma], M` and `J` aren't particularly significant, although `M` and `J` are meant to be large. I'm trying to plot the graph of this function using Plot3D                    Plot3D[                 d[Sqrt[x^2 + y^2], ArcCos[x/Sqrt[x^2 + y^2]]],                  {x, 0, 3 M},                  {y,0, 6 M},                  RegionFunction -> Function[{x, y, z}, rmin < Sqrt[x^2 + y^2] ]                ]      I'm really new when it comes to working with mathematica, but I've seen online that sometimes varying `PlotPoints` and `MaxRecursion` can help to fix a plot. I tried setting `PlotPoints -> {50, 100, 1000}`, as well as `MaxRecursion -> 10` (I don't if these values are high or low w.r.t Mathematica's default settings), changing these tended to make Mathematica really sluggish, moreover they didn't produce any more of the plot. I've also tried setting `ClippingStyle -> None` and `PlotRange -> All` and none of these had any effect. I'm thinking that maybe It could be the large values that might be throwing Mathematica off, but I was under the impression that Mathematica could deal with 'astronomical numbers' (literally). Anyway if anybody has any insight into what's going wrong or just helpful advice it would be very much appreciated. **EDIT** : In the comments it was mentioned that (0,0) is a potential problem, but I have an analogous function                   M = 10         J = 1         \[Gamma] = 0.018              g[r_, \[Theta]_] = 1 - 2 M r/(r^2 + J^2/M^2 Cos[\[Theta]]^2)                             - \[Gamma]^2 Sin[\[Theta]]^2 (r^2  + J^2/M^2 + 2 r J^2 Sin[\[Theta]]^2/(M (r^2 + J^2/M^2 Cos[\[Theta]]^2)))                             + \[Gamma] 8 r J Sin[\[Theta]]^2/(r^2 + J^2/M^2 Cos[\[Theta]]^2)      Which in principle is the same, and should encounter the same issue at (0,0), but Plot3D manages just fine.


How can you combine lines in LATEX, and lines Mathematica?

supose that You want to make a report about the golden section algorithm, and you want to explain the proccess with text in LATEX, and in every iteration you want to show in that report the values ande the correct option, and then, you want to continue explaining in LATEX. How can you do this? ## For exemplae in this code, How can you do it?               itmax = 10;     tolerancia = 0.2;     alfa = (-1 + Sqrt[5])/2;     ttheta[Lambda_] = Lambda^2 + 2*Lambda;     a = -3;     b = 5;     La = a + (1 - alfa)*(b - a) // N;     Mu = a + alfa*(b - a) // N;     tthetaLa = ttheta[La];     tLacalc = "*";     tthetaMu = ttheta[Mu];     tMucalc = "*";     Printf["With * we show you that this is an evaluate of theta(t)"]     Printf["With NO* we show you that this is an evaluate of theta(t)"]     Print["iteración_k   |   a_k    b_k   |   Lambda_k     Mu_k   |   \     theta(Lambda_k)  theta(Mu_k)"];     Do[       L = b - a;       Print[" In the iteration "i, " you have the values:",           "\n a= ",a,           "\n b= ",b,           "\n Lamda= ",La,           "\n Mu= ",Mu,           "\n ",           "\n Where the values of theeta are:",           "\n theta (Lambda)= ",tthetaLa,           "\n theta (Mu)=     ",tthetaMu,        "os a =  |   ", a, "     ", b, "   |  ", La, "     ", Mu,         "   |  ", tthetaLa, tLacalc "      ", tthetaMu, tMucalc ];       If[tthetaLa > tthetaMu,        If[b - a < tolerancia, Break[]];             a = La;        La = Mu;        Mu = a + alfa (b - a);        tthetaLa = tthetaMu;        tLacalc = " ";        tthetaMu = ttheta[Mu];        tMucalc = " ";,             b = Mu;        Mu = La;        La = a + (1 - alfa) (b - a);        tthetaMu = tthetaLa;        tMucalc = " ";        tthetaLa = ttheta[La];        tLacalc = "*";        ]       , {i, 1, itmax}       ];     solucionestimada = (Mu + La)/2;     valorestimado = ttheta[solucionestimada];     Print["La solución estimada es ", solucionestimada,        " donde la función toma valor ", valorestimado];


How could I find the singular solutions of an ODE?

Starting with the equation $$y^{\prime\prime}x^2={y^\prime}^2$$ I could only get the general solution using `DSolve`:               DSolve[{y''[x] x^2 == y'[x]^2}, y[x], x]     (* {{y[x] -> -(x/C[1]) + C[2] - Log[1 - x C[1]]/C[1]^2}} *)      However, I failed to get the singular solutions `y[x] -> x^2/2 + C[1]` and `y[x] -> C[1]`. So, how can I get them?


Problems with CircleTimes and infix notation

I am trying to create a function called `TensorBasis` that takes as input a list (thought of as a list of names of basis vectors of a vector space) and an integer `d` and output the lexicographically ordered basis of the `d`-fold tensor product of the vector space with itself. For instance, the output of `TensorBasis[{v1,v2},2]` should be               { v1 [\CircleTimes] v1, v1 [\CircleTimes] v2, v2 [\CircleTimes] v1, v2 [\CircleTimes] v2 },      and so on. I have written the following code:               TensorBasis[labels_, d_] := Module[        {dim = Length[labels], basis, j, k, indexlist, tmp},             basis = ConstantArray[0, dim^d];        tmp = ConstantArray[0, d];             For[j = 1, j <= dim^d, j++,        (* Indexlist stores the indices of the jth element of the basis for the d-fold tensor product  *)             indexlist = InverseLex[dim, d, j];             (* tmp holds the list of individual factors that will make up the jth element of the basis *)         For[k = 1, k <= d, k++,           tmp[[k]] = labels[[indexlist[[k]] ]]         ];             (* jth element of the basis is created by tensoring together all elements of tmp *)         basis[[j]] = Infix[tmp, "\[CircleTimes]"]       ];     Return[basis]     ];      The function InverseLex just gives me the appropriate list of indices for the basis element I am trying to construct. I am sure that that function is working properly. But the output is all weird. The problem is that in the output, the [CircleTimes] (i.e. tensor product) symbol is replaced by some junk: in Plain Text form it is               {Subscript[v, 1]â Subscript[v, 1],Subscript[v, 1]â Subscript[v, 2],Subscript[v, 2]â Subscript[v, 1],Subscript[v, 2]â Subscript[v, 2]}      When I use the Infix notation with "[CircleTimes]" otherwise it works fine. Why won't it work inside this function?


Find time since last 0 in list

When I have a list of data (measured per day), is it possible to define a function that gives the nr of days since the data has been 0? I tried working with`Position`to find the 0's but that did not really help me to create a function. **Simplified example:**               data = {{1, 0}, {2, 1}, {3, 3}, {4, 0}, {5, 1}, {6, 0}};     ListPlot[data, InterpolationOrder -> 0, AxesLabel -> {"time(day)", "data(mm)"}, Joined -> True]      ![enter image description here](http://i.stack.imgur.com/LtkUV.jpg) **Result I want:** ( I now entered it myself, but I want to do this for large amounts of data, which makes typing it very time consuming ;))               result = {{1, 0}, {2, 0}, {3, 1}, {4, 2}, {4,0}, {5, 0}, {6, 1}};     ListPlot[result, AxesLabel -> {"time(day)", "days since last 0"},         Joined -> True]      ![enter image description here](http://i.stack.imgur.com/fbuTb.jpg)


Extracting polygon color parameter from another variable

I'm a beginner with Mathematica, so this may seem like a simple question, though it's got me totally stumped. I'm trying to display several polygons and have the color of each polygon depend on the value in some other variable (`stscds`). My thinking is that I should do something like this: `Show[Graphics[Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}]]]` `poly` contains all of the polygons. Or possibly this: `megapol = Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}] Graphics[megapol]` It doesn't like that I'm trying to pull the color parameter out of `stscds` (this variable is full of values between 1 and zero). It says 'Ignoring invalid graphics directive RGBColor[0,01 1,0,0]. Any idea how I might approach this problem? Edit: Output of `stscds`: `{("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, \ ("1")/100, ("1")/100, ("1")/100, ("2")/100, ("2")/100, ("2")/100, \ ("2")/100, ("2")/100, ("2")/100, ("3")/100, ("4")/100, ("4")/100, \ ("4")/100, ("4")/100, ("4")/100, ("4")/100,....`


Custom highlighting in definitions

Suppose we defined a pattern with custom pattern name provided by user, like               Quiet[myCustomPattern@terms_ := f[terms : (_[_, _])..]]      for use in further definitions:               myTransform@myCustomPattern@localNameForTerms := Reverse /@ {localNameForTerms}      However, in definitions like this one, `localNameForTerms` is not by default highlighted the way it would be in case of appearing in explicit Pattern expression. Is it possible to Style it as a properly localized symbol, by putting               myCustomPattern -> Composition[myCustomPattern, Style[#, Darker@Darker@Green, Italic] &]      somewhere in the low-level notebook representation rules, for example?


What is an efficient way of selecting multiple colors via Manipulate?

Background: The following snippet is what I (intend to) use in a `Manipulate` form where up to 12 different colors can be selected:                Manipulate[{sliderCol1},       Row[{"Kleur 1: ", ColorSlider[          Dynamic[sliderCol1] ,          AppearanceElements -> {"SwatchSpectrum"},          ImageSize -> {200, 40},          BaselinePosition -> Scaled[.25]]}        ]      ]      To make this work with fields `sliderCol1` to `sliderColn` (where $n$ = 2, …, 12), I see no other option than copying the code in `Row` so many times. **Question: Is there a less verbose way of implenting a multiple (here 12) color selector using color sliders?**


Simple derivative not working

I'm a complete newbie to Mathematica. I've been using Wolfram Alpha Pro as well as MS Mathematics for a few months but wanted to dive into using a more powerful tool. I'm having a problem with calculating a simple derivative and I can't figure out what I'm doing wrong. I tried using free-form input after unsuccessfully trying to use Mathematica syntax but I get the same results. The same query works fine in Wolfram Alpha Pro. I'm getting pages of repetitive output. Here are a couple of screenshots. The second one is a continuation from further down showing "MaxFormatDepthExceeded" errors. Any help is greatly appreciated. I apologize for such a basic question. P.S. I've added a 3rd screenshot to illustrate the successful results for the same query in Wolfram Alpha Pro. As an aside, can anyone suggest any resources to quickly jump-start my usage of Mathematica? I started to go through the documentation but some of it was quite dense and assumed a level of knowledge that I don't yet have as a first semester calculus student who hasn't done math in some time. ![screenshot 1](http://i.stack.imgur.com/8Gpuu.png) ![screenshot 2](http://i.stack.imgur.com/r4p1z.png) ![same query in Wolfram Alpha Pro](http://i.stack.imgur.com/3SC25.png)


DSolve expression doesn't evaluate

Can _Mathematica_ solve $\; d^2/dx^2{}+ (1/x) d/dx\;$ form of equations?   For example, I am trying to solve the system of equations given below:               eqn1 = D[w[x], {x, 2}] + (1/x) (D[w[x], x]) - w[x];     eqn2 = D[v[x], {x, 2}] + (1/x) (D[v[x], x]) - (v[x] - u[x]);     eqn3 = D[u[x], {x, 2}] + (1/x) (D[u[x], x]) + v[x] - u[x] - w[x];     eqnSet = {eqn1 == 0, eqn2 == 0, eqn3 == 0, w[1] == 0, v[1] == 0,            u[1] == 0, w'[0] == 0, v'[0] == 0, u'[0] == 0};     DSolve[eqnSet, {w[x], v[x], u[x]}, x]      I am getting `DSolve` returning the input statement unevaluated.


How to create a 2D array (matrix)

I am pretty new to _Mathematica_. I need to create 2d array dynamicly. I got some code in C++(Qt) and it looks like this:               void Wave::getMatrix(int M, int N)     {         int k = -N;         while(k < N+1){             QVector<tsk_type> temp_vec;                  for(int i = -N; i < N+1; i++){                 temp_vec.push_back(getY(i));                 tsk_type temp_sum0;                      for(int ii = -M; ii < M+1; ii++ ){                     temp_sum0 += (getI(i-ii, b)/getY(ii)) * getJ(ii-k,b1,b2);                             }                 temp_vec[temp_vec.size()-1] = temp_sum0;                      if (k == i)                     temp_vec[temp_vec.size()-1] -= l;                          }                  temp_vec.push_back(getD(S)*getI(S-k, b));             main_array.push_back(temp_vec);             k++;         }          }      In _Mathematica_ , I have already written all the functions that I need to make some linear equation system matrix which I can solve. I even got a formula for this and I also implemented the functions I need.               getI[k_ , a_, b_];     getJ[k_ , a1_, b1_, a2_, b2_];      getGamma[n_]     getD[s_]      So `C_k` and `C_n` are unknown parameters which I need to find. Here is the formula ![enter image description here](http://i.stack.imgur.com/D9PEo.png) And the question is: How should I properly prepare and create matrix for which I could apply some lineral equation solving method like Gaussian or Gaussian- Jordan? P.S. I know that there are some C++ stuff like `librarylink`, but I need to use _Mathematica_ ;s built-in functions. **UPD:** Here's my attempt to create matrix. I run it but it's not working. Also there are no error messages. Whats wrong?               (*all globlas definiton is somewhere here*)                  k = -N;                  mainmatrix = List[[]];             While[k < N + 1,                         rowvalues = List[];                         For[i = -N, i < N + 1, i++,                             tempsum;                                 AppendTo[rowvalues, getGamma[i]];                             For[j = -M, j < M + 1, j++,                                                tempsum = tempsum +  (getI[i - j, a, b]/getGamma[j]) *                                            getJ[j - k, a1, b1, a2, b]                                 ]                                AppendTo[rowvalues, tempsum];                                    If[k == i, AppendTo[rowvalues, -l], 0]];                                AppendTo[rowvalues, getD[S]*getI[S - k, a, b]];                                AppendTo[mainmatrix, rowvalues];                   k++]


Returning a bounding disk or box centered on a coordinate in a 2D image

Provided a coordinate $c_k$ in a two-dimensional image, how can I return all of the pixels in a bounding disk or rectangle centered on $c_k$ of some specified dimension $d$? **Update:** Hat tip to Kuba for recommending `PixelValue` and Sjoerd C. de Vries for recommending `ImageData`. However, considering the case of the bounding box, is it possible to return the pixels using:               PixelValue[image,                {Subscript[x, min];;Subscript[x, max],Subscript[y, min];;Subscript[y, max]}]       In the form of a matrix rather than a 1-dimensional array?


Defining a pure function involving a function argument

I've got an expression involving `x` and `y` that I want to use as a `MeshFunction`:               mymesh = x + y     Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, MeshFunctions -> {Function[{x, y, z}, mymesh]}]      This works just fine. But now I want to create a plotting function that takes the mesh function as an argument, like so:               myplot[mesh_] := Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1},                             MeshFunctions -> {Function[{x, y, z}, mesh]}]     myplot[mymesh]      This produces the following error:               MeshFunctions::invmeshf:       "MeshFunctions->Function[{x$,y$,z$},x+y] must be a pure function or a list of pure functions"      It seems like it's making local variables `x$, y$, z$` and then keeping them distinct from the `x,y` in `mymesh`. Any suggestions how to make this work? I'd like to keep `mymesh` in the symbolic form, because the plot I'm actually interested in doing is much more complicated, and uses the `mymesh` function a second time as part of the function to plot. I'm going to add some more to this question, because I have a few answers, all of which suggested not passing `mymesh` in it's current form to the function. But I explicitly want to pass `mymesh` as it is. Here's the actual code I'm using it for. It plots the solutions to `c==0` on the unit sphere, where `c` is a homogeneous polynomial in `x,y,z`.               elliptic = z y^2 - x^3 + z^2 x     curveSpherePlot[c_] := ContourPlot3D[       {x^2 + y^2 + z^2 == 1, c == 0},       {x, -1, 1}, {y, -1, 1}, {z, -1, 1},       MeshFunctions -> {Function[{x, y, z}, x^2 + y^2 + z^2 - 1 - c]},       MeshStyle -> {{Thick, Black}},       Mesh -> {{0}},       ContourStyle -> {Opacity[0.9], None},       BoundaryStyle -> None     ]     curveSpherePlot[elliptic]      Notice that the argument `c` appears in the equation as well as in the mesh function. Not only that, but I manipulate the curve symbolically with other functions in the package, so I really don't want to switch it to a different type of object if I can help it.


NIntegrate Issue: Changing integration limits makes calculation time extremely long

After a long time developing some code in mathematica and finally getting it to work, I have unfortunately encountered an odd problem: When I change the limits of integration (and shift the function that I am integrating) NIntegrate takes extremely long (on the order of hours) to complete. Now, this would be understandable if I increased the limits of integration but in my case, its the opposite I am decreasing the limits of integration. Given the following constants and functions:               sL[phi_] := (r*phi^3)/24     lambdaB[z_] := 1/(sigmaSbeg*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSbeg^2))]     lambdaE[z_] := 1/(sigmaSend*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSend^2))]     lambdaC[z_, phi_] :=       1/(((sigmaSend - sigmaSbeg)/theta *phi + sigmaSbeg)*Sqrt[2 Pi])Exp[-(z^2/(         2*((sigmaSend - sigmaSbeg)/theta *phi + sigmaSbeg)^2))]         deEntrance[s_, phi_?NumericQ] :=       With[{sL = sL[phi]},         ((lambdaC[s - sL, phi] - lambdaB[s - 4 sL])/sL^(1/3) +           NIntegrate[(1/(s - sprime)^(1/3)*             D[lambdaC[sprime, phi], sprime]), {sprime, s - sL,             s}])]     deEntranceRMS[phi_?NumericQ] :=       Sqrt[NIntegrate[         lambdaE[s]*(deEntrance[s, phi])^2, {s, -5 sigmaSend,           5 sigmaSend}] - (NIntegrate[          lambdaE[s]*(deEntrance[s, phi]), {s, -5 sigmaSend,            5 sigmaSend}])^2]          NIntegrate[(eta1[r*phi])*deEntranceRMS[phi], {phi, 0.0,theta}]     NIntegrate[(eta2[r*phi])*deEntranceRMS[phi], {phi, 0.0, theta}]      The following works well and outputs an answer within a reasonable amount of time:               sigmaSbeg = 2.759153*10^-004;     sigmaSend = 2.774392*10^-004;     theta=0.06;     r=9.15445;     eta1[s_]:=-0.05461846 s^2     eta2[s_]:=-0.10923649 s      But, for the following, Mathematica takes extraordinarily long.               sigmaSbeg = 8.280940*10^-006;     sigmaSend = 8.308940*10^-006;     theta=0.014;     r=17.857143;     eta1[s_]:=0.00059452375 + 0.028 (-0.25 + s)^2     eta2[s_]:=-0.014 + 0.056 s      I cannot figure out why. I assume my eta1 and eta2 functions are a little more complex, but they're only shifted quadratics and linear functions. Any help would be great


How to calculate solution for each variable automatically

Here I have one problem how to calculate x for each y. In this form code doesn't work                    y = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6,0.7};             NSolve[-y*16 x^3 - y^2*25 x^2 + 5 == 0, x]


Why doesn't FindClusters find any clusters in this case?

I am trying to use FindClusters to segment data points into similar numbers but so far I couldn't get it work for this example:               l = {110, 111, 115, 117, 251, 254, 254, 259, 399, 400, 401,           402, 542, 546, 549, 554, 660, 660, 660, 660};     FindClusters[l]     (*     -> {{110, 111, 115, 117, 251, 254, 254, 259, 399, 400, 401, 402, 542,         546, 549, 554, 660, 660, 660, 660}}     *)      If I set the N parameter (to specify: Exactly N clusters), it works:               FindClusters[l, 5]     (*     -> {{110, 111, 115, 117}, {251, 254, 254, 259},          {399, 400, 401, 402}, {542, 546, 549, 554}, {660, 660, 660, 660}}     *)      However, my intent was to use FindClusters to figure out N.


Module and Local variable

Hello,               GetIntersectionPoint[p1_, p2_] :=                   Module[{pts, vecs, n, vars, distance, sol, x, y, z, t}, (                         pts = p2;                    vecs = p1 - pts;                    n = Length[pts];                    vars = Array[t, n];                    {distance, sol} =                      Minimize[                      Total[({x, y, z} - Transpose[pts + vecs vars])^2, 2], {x, y, z}~                       Join~vars]                              )]      I call this function with p1 and p2 where                   p1={{100, 100, 100},{100, 0, 100},{0, 100, 100}};         p2={{500/3, 500/3, 0},{500/3, 0, 0},{0, 500/3, 0}};      I obtain like this:               {0, {x$17013 -> 0, y$17013 -> 0, z$17013 -> 250, t$17013[1] -> 5/2,        t$17013[2] -> 5/2, t$17013[3] -> 5/2}}      How Can I fix the rename of the local variables ?


Plot "OilReserves" using CountryData from 1985 until 2014

I am newer using Mathematica to plot with the Function: CountryData, I am trying to plot "OilReserves" in "UnitedKingdom" from 1985 until 2014. I don't know how to do it, please help me!


Filling the empty space in RevolutionPlot3D

I'm wanting plot the solid of revolution from the area between two functions such as: $1\leq x \leq e$ and $1 \leq y \leq 2 + ln(x)$, doing something like:               f[x_]:=2+Log[x]     g[x_]:=1     RevolutionPlot3D[{{f[x]}, {g[x]}}, {x, 1, E},      RevolutionAxis -> x, AxesOrigin -> {0, 0, 0},      Boxed -> False, Mesh -> {5, 0}, PlotRange -> {{0, 3}, All},      PlotStyle -> Opacity[0.5]]      ![plot](http://i.stack.imgur.com/mVCDJ.png) There is a way to fill this empty space between $f(x)$ and $g(x)$?   Thanks in advance.


How to create symbol whose name has subscript?

I can do               Symbol["foobar"]      to create a symbol `foobar`. How to create a symbol $\theta_1$?               Symbol[Subscript[\[Theta], 1]]      doesn't work.


How to minimize a certain function

What can be wrong with this?               Clear[a, b, c, x, AX, BX];     a > 0;     b > 0;     c > 0;     AX[x_] := Sqrt[a^2 + x^2];     BX[x_] := Sqrt[b^2 + (c - x)^2];     roadCost[x_] := 10000 AX[x] + 20000 BX[x];     Minimize[{roadCost[x], c - (b c)/(a + b) <= x <= c}, x]


Combining lists in a matrix

So I have a list of data `A={1.1,1.2,1.3,1.4,6.1}` etc and `B={2.5,2.6,2.7,2.8,2.9}` I need to combine the lists into a matrix C               {{1.1,2.5},{1.2,2.6},{1.3,2.7},{1.4,2.8},{6.1,2.9}}      How would I go about doing that?


Why does a translation in the horizontal direction affect PointSize?

I'm running _Mathematica_ 9.0.1 under Mac OSX. Not sure if this is a bug or whether I'm not supposed to apply a `GeometricTransformation` to a list containing graphic primitives and directives:               verts = {{0, 0}, {1, 0}, {Cos[60 Degree], Sin[60 Degree]}};     tri = {{PointSize[0.2], Point[verts]}, {Line[verts~Append~First@verts]}};      Translating purely in the vertical direction works how I expect it to:               Graphics[GeometricTransformation[tri, TranslationTransform[{0, #}] & /@ Range[0, 2]]]      ![vertical translation](http://i.stack.imgur.com/og8cq.png)               Graphics[GeometricTransformation[tri, TranslationTransform[{#, 0}] & /@ Range[0, 2]]]      However, if the translation has a horizontal component, then the point size gets messed up, in the sense that it's not compensating the size of the points with respect to the size of the graphic in the notebook: ![horizontal translation](http://i.stack.imgur.com/zWoAw.png) Is this a bug?


A problem about option "Plotlegends"

**_Today,I use the Mathematica to deal with data.My code as below:_**                Needs["PlotLegends`"]      **_Function Definition:_**                TargetList[dData_List, massData_List] := Block[      {TargetListResult, dAverageData, miData},      dAverageData = Mean /@ Partition[dData, 2, 1];      miData = Table[Total@massData[[1 ;; i]], {i, 1, Length@dAverageData}];           TargetListResult =       MapThread[List,                  N@Log[10, #] & /@ {dAverageData/Max@dAverageData, miData/         Total@massData}]      ]      **_Data Input:_**               DryData={{8.28, 17.57, 10.15, 4.85, 2.41, 11.74}, {7.82, 12.19, 6.65, 3.57, 1.8, 20.97},             {23.58, 19.44, 18.08, 11.1, 8.72, 19.08}, {25.18,16.51, 17.5, 8.01, 4.54, 28.26},            {10.67, 28, 14.49, 17.86, 8.97, 20.01},{14.29, 19.28, 16.14, 15.54, 10.36,24.39},               {25.94, 21.1,20.02, 11.37, 6.11, 15.46},{24.51, 23.99, 13.75, 11.95, 4.32,21.48},             {33.51, 22.69, 19.26, 8.23, 4.88, 11.43},{22.15, 25.54, 23.5, 8.34, 4.69,15.78},              {20, 19.06, 18.65, 12.19, 11.68,18.42}, {18.84, 20.09, 9.75, 15.3, 12.48,23.54}};           DryNameData={"Space0-20,Dry", "Space20-40,Dry", "Tao0-20,Dry", "Tao20-40,Dry",                    "Yang0-20,Dry", "Yang20-40,Dry", "Pu0-20,Dry", "Pu20-40,Dry",                   "Yangshu0-20,Dry", "Yangshu20-40,Dry",                   "MoxigeBai0-20,Dry", "MoxigeBai20-40,Dry"};           dData = {0, 0.25, 0.5, 1, 2, 5, 10};           solvingDryData = Reverse /@ DryData;           fitLineDryFunction =       Fit[#, {1, x}, x] & /@ (TargetList[dData, List[##]] & @@@solvingDryData);      **_Without PlotLegends:_**                Show[Plot[fitLineDryFunction, {x, -2, 0}, AxesOrigin -> {-2, -1},ImageSize -> 600],          ListPlot[TargetList[dData, List[##]] & @@@ solvingDryData,          AxesOrigin -> {-2, -1}, PlotMarkers -> Automatic, ImageSize -> 600]]      **_It give the normal graphics_** ![enter image description here](http://i.stack.imgur.com/XWtAN.jpg) **_However,when I use the`PlotLegends`option,it gives the wrong result:_**                Show[ListPlot[TargetList[dData, List[##]] & @@@ solvingDryData,            AxesOrigin -> {-2, -1}, PlotLegend -> DryNameData,            PlotMarkers -> Automatic, LegendPosition -> {1.1, -0.5},            LegendSize -> 1.25, LegendShadow -> None,            LegendTextOffset -> {-.6, 0}, LegendTextDirection -> {3, 1},            ImageSize -> 800], Plot[fitLineDryFunction, {x, -2, 0}]]      ![enter image description here](http://i.stack.imgur.com/prrh1.jpg) **_So my question is how to revise it?_**


Setting non-standard ImageResolution for EMF export as default

Mathematica has a bug in that `BarChart`s and `ListPlot`s with `Filling` will export as a pixelated bitmap, not a vector graphic when exporting as EMF format. There is a workaround, which is to set `ImageResolution` to be 1300 or higher in the `Export` command, like this:               testdata = RandomReal[{5, 10}, 20];     bg1 = BarChart[{testdata}]     Export["bg1400.emf", bg1, ImageResolution -> 1400]      (No, you don't get a huge file if you set `ImageResolution` this high. It somehow tricks it into using vector graphics. However the workaround is a bit unreliable, depending on the graph in question.) How can I make this option the default? `SetOptions[Export]={ImageResolution -> 1400}` produces an error message that it's not a recognised option to `Export`. I also tried:               SetOptions[$FrontEndSession, ConversionOptions -> {"ExportOptions" -> {"EMF" ->        {"IncludeSpecialFonts" -> True, ImageResolution -> 1400}}}]      But that doesn't seem to do anything. How do I set these export options as the default, e.g. in a package? Alternatively, how do I force this hidden vector capability?


Simple rule appears not to work

I have the following simple code               Clear["Global`*"];          V = v0^2/2*Log[x^2 + (y/q)^2 + rc^2];     sub = {(v0^2/(x^2 + (y/q)^2 + rc^2)) -> (arg)};          Vx = D[V, x];     Vy = D[V, y];          Vxx = Simplify[D[V, {x, 2}]];     Vxy = Simplify[D[Vx, y]];     Vyy = Simplify[D[V, {y, 2}]];     Vyx = Simplify[D[Vy, x]];          Print["******************************"]     Print["Vx = ", Vx //. sub]     Print["Vy = ", Vy //. sub]     Print["Vxx = ", Vxx //. sub]     Print["Vxy = ", Vxy //. sub]     Print["Vyx = ", Vyx //. sub]     Print["Vyy = ", Vyy //. sub]     Print["*****************************"]      which calculates the first and second derivatives the function $V$. The printed results I added a rule `sub` in order to make the output much simpler. However, for a strange reason, the rule applies correctly to the first derivatives $Vx$ and $Vy$ but it has no effect to the second ones $(Vxx, Vxy, Vyx, Vyy)$. Any ideas why?


How to create a wind rose with Mathematica?

I am trying to plot **wind rose** in _Mathematica_ , but have no idea how to do this. ![Plot](http://i.stack.imgur.com/wlLbu.jpg) Any suggestions ?


How to make Joined skip missing data points

I have a set of data taken on sequential days, but some points are missing. I'd like to make a joined date list plot, where the points are not joined across the missing point.The following example illustrates the desired result.               data1 = {     {{2013, 7, 1}, 1},     {{2013, 7, 2}, 5},     {{2013, 7, 3}, 2},     {{2013, 7, 4}, 4},     {{2013, 7, 6}, 2},     {{2013, 7, 7}, 6}     };     data2 = {     {{2013, 7, 1}, 6},     {{2013, 7, 2}, 2},     {{2013, 7, 3}, 4},     {{2013, 7, 4}, 1},     {{2013, 7, 5}, 7},     {{2013, 7, 6}, 1},     {{2013, 7, 7}, 4}     };     DateListPlot[{     data1[[1 ;; 4]],     data1[[5 ;; 6]],     data2[[ ;; ]]     }, PlotStyle -> {Blue, Blue, Red}, Joined -> True]      Note that `data1` is missing a point on July 5. In practice I'm doing this with multiple data sets, with hundreds of points, so breaking it apart and manually assiging plotstyle like I have here is not viable. How can I make `Joined` skip missing points?


Pure function with attributes of arbitrary number of arguments: Is it possible?

_Mathematica_ allows to define pure function, like               Function[{a, b},Length[Unevaluated@a]{b}][1+2,2+3]     (*     ==> {0}     *)      Pure functions in _Mathematica_ can take an arbitrary number of arguments, but only if not naming them, for example:               Function[Length[Unevaluated@#1]{##2}][1+2,2+3,3+1]     (*     ==> {0,0}     *)      Also, pure functions can optionally have attributes, for example:               Function[{a,b},Length[Unevaluated@a]{b},{HoldFirst}][1+2,2+3]     (*     ==> {10}     *)      However what I haven't found is a way to have both arbitrary many arguments and attributes:               Function[(* what, if anything, to put here? *)][1+2,2+3,3+1]     (*     ==> {10, 8}     *)      Therefore my question: **Is it possible to define pure functions which take an arbitrary number of arguments and at the same time have attributes? And if so, how would one define them?** The obvious solution doesn't work:               Function[Length[Unevaluated@#1]{##2},{HoldFirst}][1+2,2+3,3+1]     (*     Function::flpar: Parameter specification Length[Unevaluated[#1]] {##2} in      Function[Length[Unevaluated[#1]] {##2},{HoldFirst}] should be a symbol or      a list of symbols. >>     *)      Adding an empty parameter list disables parameter substitution for `##`;               Function[{},Length[Unevaluated@#1]{##2},{HoldFirst}][1+2,2+3,3+1]     (*     ==> {##2}     *)      Of course, a workaround is easy; for example, have the pure function take a list (which in the example above would actually have been the better alternative anyway), or simply using a named function. So it's more of a curiosity. It just seems odd to have two completely orthogonal features of pure functions, and yet not being able to combine them.


How to make a scatter plot from 2 images

How can two images be used to create a scatter plot, image 1 being the x axis, image 2 being the y axis, and the color of each plot point being the bin count?


Is there a better way to create my rotational-symmetric (180 degrees) rectangles?

I have created a simple way to create rotational-symmetric (180 degrees) rectangles, but my `stuffit` function bothers me. No matter what I tried, I couldn't get it to work within the recursive function. Can someone show me the way?               stuffit[n_List, k_] :=      Block[{j = n}, For[m = k, m <= Length[j], m += k, j[[m]] = k];      Return[j]]            f[1] := 1     f[k_] := stuffit[Flatten[Table[f[k - 1], {n, (Cyclotomic[k, 1])}]], k]     f[k_, p_] := Partition[f[k], p]          f[6, 6] // MatrixForm        **Edit** Replaced `stuffit` with `MapAt` from kguler's answer below. I used it within the recursive routine. Also, added parameter to the partitioning function to subtract the 3rd parameter from p to take the smaller rectangle: f[6,6,1] skips the rightmost column.               f[1] := 1       f[k_] := MapAt[k &, Flatten[Table[f[k - 1],       {n, (Cyclotomic[k, 1])}]], {k ;;  ;; k}]     f[k_, p_, x_] := Partition[f[k], p][[All, 1 ;; p - x]]          f[6, 6, 0] // MatrixForm (*below*)      $$\left( \begin{array}{cccccc} 1 & 2 & 3 & 4 & 5 & 6 \\\ 1 & 4 & 3 & 5 & 1 & 6 \\\ 1 & 2 & 5 & 4 & 1 & 6 \\\ 1 & 5 & 3 & 2 & 1 & 6 \\\ 5 & 2 & 3 & 4 & 1 & 6 \\\ 1 & 4 & 3 & 2 & 5 & 6 \\\ 1 & 2 & 3 & 5 & 1 & 6 \\\ 1 & 4 & 5 & 2 & 1 & 6 \\\ 1 & 5 & 3 & 4 & 1 & 6 \\\ 5 & 4 & 3 & 2 & 1 & 6 \\\ \end{array} \right)$$ The rotational symmetry is 180 degrees using the $k-1$ rectangle (omitting the rightmost column, including the ends of the rows.) I think this is the coolest thing I have ever created because it partitions down and keeps the symmetry. _Try 6,4,0 and 6,5,0 and 6,4,1 and 6,5,1_


puzzled with ColorData

At first let me thank, from this point as well, those that they replied to my previous queries. From a reply I got, I obtained finally the desired graph.               lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};     dam = Sqrt[(1296*Cos[u]^4*            Sin[v]^4)/(900*Cos[v]^2 + 36*Cos[u]^2*Sin[v]^2 +              400*Sin[u]^2*Sin[v]^2)^2 + (3600*Cos[u]^2*            Sin[v]^2*(9*Cos[v]^2 + 4*Sin[u]^2*Sin[v]^2))/(900*Cos[v]^2 +              4*(9*Cos[u]^2 + 100*Sin[u]^2)*Sin[v]^2)^2];     colFun = Function[{u, v}, Evaluate@Hue[Rescale[dam, {0, 1}]]];     {min, max} = {0, 1};     ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False,       ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,       PlotRange -> All, ImageSize -> 800,       PlotLegends ->        BarLegend[{Hue, {min, max}}, ColorFunctionScaling -> True]]      Now, what I want is to check the outputs of other available color schemes. I did the following:               coldata = ColorData["Gradients"];     col = Table[{i, coldata[[i]], ColorData[coldata[[i]]]}, {i, 51}];      So, for instance (for ColorData["BrightBands"])               {min, max} = {0, 1};     lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};     colFun = Function[{u, v}, Evaluate@col[[10, 3]][Rescale[dam, {0, 1}]]];     h = ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False,        ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,        ImageSize -> 800,        PlotLegends ->         BarLegend[{colFun, {min, max}}, ColorFunctionScaling -> True]]      The coloring of the ellipsoid is as desired, but this does not hold true for the color bar. Obviously, something I made wrong. I really appreciate any help! Dimitris


How to calculate a double indefinite integral

I need to calculate double integral as shown below. I used the Classroom Assistant palette to write the integral. How can I enter it as ordinary text, i.e., `Integrate[....],` so _Mathematica_ would treat it exactly the same as the form entered by means of the palette? How would I formulate it for submission to Wolfram Alpha? ![enter image description here](http://i.stack.imgur.com/rFOf8.png)


A timed switch with Dynamic

I'm trying to make a binary switch that switches after a fixed given interval. Why doesn't the following work:               step = .1;     t = Dynamic[Clock[{0, 5, step}, 5, 1] ];      Dynamic[t >=  2]


plot totally fragmented, WorkingPrecision,matlab comparison

I am trying to plot               F2q0overLambdaSimpler3[m_] :=      1/(Sqrt[2] (4*Pi)^2)*1/(2 (m^4) )*(1/Sqrt[1 - 4 m^2]*(2 - 10 m^2 + 8 m^4)*      ArcTanh[Sqrt[1 - 4 m^2]/(1 - 2 m^2)] +      2*(2 m^2 - 3 m^4 + (2 - 6 m^2) Log[m]))$      Just using               Plot[F2q0overLambdaSimpler3[m], {m, 1/(200*10^3), 1/(100*10^3)}]      But the result looks like this: ![enter image description here](http://i.stack.imgur.com/anmaP.jpg) Then I plotted this function using matlab: ![enter image description here](http://i.stack.imgur.com/blCyz.jpg) How do I get mathematica plotting it equally nice? I already tried things like               WorkingPrecision -> 100      or even 1000 what yields a very weird behaviour.... Any suggestions?


Prove (or check) an expression is positive given constraints on variables?

I'm trying to figure out whether an expression is always positive given positive parameters. When the expression is complicated, I can't do this by eye. Is there any way to make _Mathematica_ prove (that is, check) if `j` is positive for positive `c, d, k, ton, toff, V`?               j=-2 c d k toff ton - d^2 k toff ton - 2 c k toff^2 ton -       2 d k toff^2 ton - k toff^3 ton - 2 c d k ton^2 - d^2 k ton^2 -       4 c k toff ton^2 - 4 d k toff ton^2 - 3 k toff^2 ton^2 -       2 c k ton^3 - 2 d k ton^3 - 3 k toff ton^3 -       k ton^4 + (Sqrt[k] Sqrt[ton] (toff + ton) Sqrt[         d + toff +           ton] (2 c + d + toff +            ton) \[Sqrt]((c + d) k ton (c + toff + ton) (d + toff + ton) +             4 c d ((d + toff + ton) (k toff + (toff + ton)^2) +                c (k toff +                   d (toff + ton) + (toff + ton)^2)) V))/(2 Sqrt[(c +             d) (c + toff + ton)]) + (Sqrt[k] Sqrt[         ton] (toff + ton) Sqrt[(c + d) (c + toff + ton)] Sqrt[         d + toff +           ton] (k ton (d + toff + ton) (2 c + d + toff + ton) +            4 d ((d + toff + ton) (k toff + (toff + ton)^2) +               2 c (k toff +                  d (toff + ton) + (toff + ton)^2)) V))/(2 \[Sqrt]((c +                d) k ton (c + toff + ton) (d + toff + ton) +             4 c d ((d + toff + ton) (k toff + (toff + ton)^2) +                c (k toff + d (toff + ton) + (toff + ton)^2)) V))      I have many more expressions like this. I have tried putting in random values of the parameters and I do (so far) always get positive values. But I'd prefer something more convincing than a Monte Carlo argument for this (and other) complicated expressions being positive for any positive inputs. Thoughts?


Parallel computation of NDSolve and a problem

I used this code to solve a system of differential equations:                   ro[t_] :=          Table[Subscript[ρ, i, j][t], {i, 1, sysdim}, {j, 1, sysdim}];              RHS = A matrix;         RHS2 = RHS              ParallelTable[Flatten[NDSolve[{ro'[t] == RHS, ro[0] == initial}, Flatten[ro[t]],                                {t, 0, 10}]], {γ, 1, 2}]      Whenever I use `RHS`inside the `NDSolve`, I get this error: > >        NDSolve::ndnum: Encountered non-numerical value for a derivative at t > == 0.`. >   But, when I use `RHS2` which is basically `RHS`, I don't get any error message. Does anybody know the problem? * * * ### Edit. Here I put the whole code:                   δ[i_, j_] := KroneckerDelta[i, j]         sysdim = 7;              Hsystem[dimension_] := Module[{sysdim = dimension},         V[ii_, jj_] := Module[{i = ii, j = jj},              If[i > j, Return[Subscript[V, j, i]], Return[Subscript[V, i, j]]]];              hsys[i_, j_] := δ[i, j]*Subscript[ϵ, i] + V[i, j] (1 - δ[i, j]);              MHsys = Table[hsys[i, j], {i, 1, sysdim}, {j, 1, sysdim}]         ]              Hsys = Hsystem[sysdim];              A[m_] := Table[δ[i, m]*δ[j, m], {i, 1, sysdim}, {j, 1,          sysdim}]         ro[t_] :=          Table[Subscript[ρ, i, j][t], {i, 1, sysdim}, {j, 1, sysdim}];         (*LL=Table[(-1+δ[i,j])*ro[t][[i,j]],{i,1,sysdim},{j,1,sysdim}]*)                   L = γ*         Sum[A[m].ro[t].A[m]\[ConjugateTranspose] -           1/2 (A[m].A[m]\[ConjugateTranspose].ro[t] +              ro[t].A[m].A[m]\[ConjugateTranspose]), {m, 1, sysdim}];              Hrecom = Table[-I*ℏ*Γ*δ[i, j], {i, 1,          sysdim}, {j, 1, sysdim}];              Htrap = Table[-I*ℏ*κ*δ[i, 3]*δ[j, 3], {i,          1, sysdim}, {j, 1, sysdim}];              Hdiss = Hrecom + Htrap;              RHS = -I/ℏ (Hsys.ro[t] - ro[t].Hsys) + -I/ℏ (Hdiss.ro[t] +            ro[t].Hdiss) + L ;              hcp = 6.62606957*10^-34*3*10^10*10^-12; Subscript[ϵ, 1] =          280*hcp; Subscript[ϵ, 2] =          420*hcp; Subscript[ϵ, 3] = 0; Subscript[ϵ, 4] =          175*hcp; Subscript[ϵ, 5] =          320*hcp; Subscript[ϵ, 6] =          360*hcp; Subscript[ϵ, 7] = 260*hcp;              Subscript[V, 1, 2] = -106*hcp; Subscript[V, 1, 3] =           8*hcp; Subscript[V, 1, 4] = -5*hcp; Subscript[V, 1, 5] =           6*hcp; Subscript[V, 1, 6] = -8*hcp; Subscript[V, 1, 7] = -4*          hcp;  Subscript[V, 2, 3] = 28*hcp; Subscript[V, 2, 4] =           6*hcp; Subscript[V, 2, 5] = 2*hcp; Subscript[V, 2, 6] =           13*hcp; Subscript[V, 2, 7] =           1*hcp; Subscript[V, 3, 4] = -62*hcp; Subscript[V, 3, 5] = -1*          hcp; Subscript[V, 3, 6] = -9*hcp; Subscript[V, 3, 7] =           17*hcp; Subscript[V, 4, 5] = -70*hcp; Subscript[V, 4, 6] = -19*          hcp; Subscript[V, 4, 7] = -57*hcp; Subscript[V, 5, 6] =          40*hcp; Subscript[V, 5, 7] = -2*hcp; Subscript[V, 6, 7] = 32*hcp;                   κ = 1;         Γ = 10^-3;         ℏ = (6.62606957*10^-34)/(2*Pi);         initial = Table[δ[i, 6]*δ[j, 6] + δ[i, 1]*δ[j,            1], {i, 1, sysdim}, {j, 1, sysdim}];              RHS2 = RHS;              num = 20;         upper\[TripleDot]limit = 10;         sol = ParallelTable[NDSolve[{ro'[t] == RHS, ro[0] == initial}, Flatten[ro[t]],          {t, 0,upper\[TripleDot]limit}, MaxSteps -> 10^5], {γ, 1, num, 1}];//AbsoluteTiming              dens = Flatten[Table[ro[t] /. sol[[i, All, All]], {i, 1, num}],1];


Bar legend does not display values

My `BarLegend` shows only zeros instead of right values and I cannot find the reason. I set following minimum and maximum:               MinC=-1.66423*10^-13;      MaxC=9.39154*10^-13;     legend = BarLegend[{"TemperatureMap", {MinC, MaxC}}, LegendLayout -> "Column"]


How to pad Background size in Style calls

When highlighting text using `Style` and `Background`, as in `Style["Test ", White, Background -> Lighter@Blue]` is there a way to pad (ie, enlarge) the bounding box? The bottom of the background seems coincident with the base of the text: ![here](http://i.stack.imgur.com/SLimA.jpg)


How Can I superpose an image and a graphics?

I want to superpose an image with a graphics in order to evaluate their alignment. I am writting this exemple of code.               s1 = Graphics[{RGBColor[{1,0,0}],Circle[{0, 1}]}];     model = ContourPlot[x^2 + y^2 - 1 == 0, {x, -2, 2}, {y, -2, 2}]     imref = Rasterize[s1, ImageSize -> {200, 150}](*suppose that is given by camera*)     Show[imref,model];      (*second method*)     immodel=Rasterize[model, ImageSize -> {200, 150}];     ImageCompose[imref,immodel]      I have an other idea, I can binarize the two images and Multiply them or do ImageDifference to get the result alignement but I need also to show graphically the results! Is there any idea to add the opacity or transparency parameters in order to see both images superposed images? thanks


Changing default ImageSize in the frontend?

I would like graphs to appear somewhat larger in my notebooks (running v8.0.4 on OSX 10.8.2). Naturally I can specify `ImageSize` in each individual plot, or drag each plot to the size I want. But how can I just make it happen all the time? This legacy documentation indicates `ImageSize` typically defaults to 288px but shows no way to change that default. Checking the frontend preferences also comes up empty. How can I get bigger plots by default?


Refreshing the Palettes menu

How can the contents of the Palettes menu be refreshed (preferably programmatically) without restarting the Front End? When droppping a new palette notebook into `$UserBaseDirectory/SystemFiles/FrontEnd/Palettes`, it will appear in the Palettes menu after restarting the Front End. How can I make it appear there without restarting the front end? When using the `Palettes -> Install Palette...` feature, this refresh happens automatically, so I assume it must be possible. The source of the installation dialog notebook is available in `$InstallationDirectory/SystemFiles/FrontEnd/SystemResources`, but I did not manage to figure out how it works yet.


How do I plot the derivative of a set of experimental points?

I have a set of points like this: P = {{$x_1$,$y_1$},{$x_2$,$y_2$},...,{$x_n$,$y_n$}}. I want to plot them and also plot the derivative of that graph. How can I do this with Mathematica? Is there a simple way in Mathematica?


Writing data to a common file during parallel processing

I am executing a loop, and in each loop I have to store a parameter in a file. It is like               file = FileNameJoin[{NotebookDirectory[], "info.txt"}];     OpenWrite[file];     Do[out = Prime[i]; WriteString[file, i, "\t", out, "\n"], {i, 1, 10}]     Close[file]      It stores the values perfectly. But when I use Parallelize[], it produce only partial output.               file = FileNameJoin[{NotebookDirectory[], "infop.txt"}];     OpenWrite[file];     Do[out = Prime[i]; WriteString[file, i, "\t", out, "\n"], {i, 1, 10}]     Close[file]      It produces only 4-5 sets out of 10 (They are in random ordering, but that is not a problem). Although when I use Print[], it shows all the sets.               Parallelize[Do[out = Prime[i]; Print[i , "\t", out], {i, 1, 10}]]      The loop I am using for work is pretty big and I may have to check the info.txt file several times to know the status while the code is running. Is there any way to write the data (as the code is running) in a common file while using parallel processing.


Looking for ideas for handling a complicated fitting problem

I have the following data:               test={{{15.8257, -0.0769379}, {16.1561, -0.0974535}, {16.4865,      -0.0896821}, {16.5195, -0.065402}, {16.6847, -0.0581635}, {16.8499,      -0.0702727}, {17.0151, -0.0836196}, {17.1803, -0.0888208}, {17.3455,      -0.0929545}, {17.5107, -0.105148}, {17.6759, -0.103528}, {17.8411,      -0.0836455}, {18.0063, -0.0715808}, {18.1715, -0.0650529}, {18.3366,      -0.0582498}, {18.5018, -0.0588228}, {18.667, -0.0599082}, {18.8322,      -0.0605835}, {18.9974, -0.0664554}, {19.1626, -0.0695087}, {19.3278,      -0.0696179}, {19.493, -0.0734236}, {19.6582, -0.0709082}, {19.8234,      -0.0622981}, {19.9886, -0.0673829}, {20.1538, -0.0802961}, {20.319,      -0.0798284}, {20.4842, -0.0687257}, {20.6494, -0.0717655}, {20.8146,      -0.0806611}, {20.9798, -0.085287}, {21.145, -0.0922109}, {21.3102,      -0.0944269}, {21.4754, -0.0878644}, {21.6405, -0.0880898}, {21.8057,      -0.0899869}, {21.9709, -0.078788}, {22.1361, -0.0591576}, {22.3013,      -0.044466}, {22.4665, -0.0600192}, {22.6317, -0.0748474}, {22.7969,      -0.0704493}, {22.9621, -0.0572922}, {23.1273, -0.0562575}, {23.2925,      -0.0623347}, {23.4577, -0.0634224}, {23.6229, -0.068166}, {23.7881,      -0.0829702}, {23.9533, -0.0888241}, {24.1185, -0.0735696}, {24.2837,      -0.0593534}, {24.4489, -0.0637424}, {24.6141, -0.0650974}, {24.7793,      -0.0519863}, {24.9444, -0.0404489}, {25.1096, -0.0633278}, {25.2748,      -0.0747063}, {25.44, -0.0698835}, {25.6052, -0.0770221}, {25.7704,      -0.0828237}, {25.9356, -0.0727494}, {26.1008, -0.0432394}, {26.266,      -0.0423326}, {26.4312, -0.06231}, {26.5964, -0.0736631}, {26.7616,     -0.0655702}, {26.9268, -0.0632276}, {27.092, -0.0749202}, {27.2572,      -0.0780181}, {27.4224, -0.0727166}, {27.5876, -0.0615335}, {27.7528,      -0.056091}, {27.918, -0.063779}, {28.0832, -0.0615237}, {28.2483,      -0.0506654}, {28.4135, -0.0563894}, {28.5787, -0.0836379}, {28.7439,      -0.0994342}, {28.9091, -0.0896401}, {29.0743, -0.0615194}, {29.2395,      -0.0517822}, {29.4047, -0.062227}, {29.5699, -0.0769844}, {29.7351,      -0.0813083}, {29.9003, -0.0899082}, {30.0655, -0.0893884}, {30.2307,      -0.0725808}, {30.3959, -0.050268}, {30.5611, -0.0426449}, {30.7263,      -0.0480701}, {30.8915, -0.0559944}, {31.0567, -0.0608699}, {31.2219,      -0.06694}, {31.3871, -0.0797316}, {31.5522, -0.0904721}, {31.7174,      -0.0867335}, {31.8826, -0.0808754}, {32.0478, -0.0764141}, {32.213,      -0.0672197}, {32.3782, -0.0500709}, {32.5434, -0.0431931}, {32.7086,      -0.0477298}, {32.8738, -0.0606955}, {33.039, -0.072429}, {33.2042,      -0.0820698}, {33.3694, -0.100112}, {33.5346, -0.0911248}, {33.6998,      -0.0722954}, {33.865, -0.0553945}, {34.0302, -0.0577424}, {34.1954,         0.267945}, {34.3606, 0.580552}, {34.5258, 0.665223}, {34.6579,         0.755472}, {34.8231, 0.759053}, {34.9883, 0.76307}, {35.1535,         0.776505}, {35.3187,         0.779363}, {35.4839, -1.12199}, {35.6491, -2.55552}, {35.8143,      -2.94135}, {35.9795, -3.09798}, {36.1447, -3.19286}, {36.3099,      -3.20814}, {36.4751, -3.20919}, {36.6403, -3.21143}, {36.8054,      -3.22794}, {36.9706, -3.23869}, {37.1358, -3.22691}, {37.301,      -3.22079}, {37.4662, -3.23454}, {37.6314, -3.23401}, {37.7966,      -3.21475}, {37.9618, -3.20351}, {38.127, -3.19776}, {38.2922,      -3.20082}, {38.4574, -3.20999}, {38.6226, -3.20835}, {38.7878,      -3.22132}, {38.953, -3.24514}, {39.1182, -3.23904}, {39.2834,      -3.22584}, {39.4486, -3.22737}, {39.6138, -3.21398}, {39.779,      -3.19581}, {39.9442, -3.18892}, {40.1093, -3.18855}, {40.2745,      -3.20021}, {40.4397, -3.21298}, {40.6049, -3.21224}, {40.7701,      -3.20945}, {40.9353, -3.21391}, {41.1005, -3.20505}, {41.2657,      -3.195}, {41.4309, -3.19082}, {41.5961, -3.19234}, {41.7613,      -3.19255}, {41.9265, -3.18381}, {42.0917, -3.20026}, {42.2569,      -3.2267}, {42.4221, -3.24796}, {42.5873, -3.24242}, {42.7525,      -3.23463}, {42.9177, -3.229}, {43.0829, -3.21687}, {43.2481,      -3.19914}, {43.4132, -3.17638}, {43.5784, -3.17475}, {43.7436,      -3.1944}, {43.9088, -3.22259}, {44.074, -3.23448}, {44.2392,      -3.23701}, {44.4044, -3.25577}, {44.5696, -3.25209}, {44.7348,      -3.2347}, {44.9, -3.20355}, {45.0652, -3.18403}, {45.2304, -3.1984},      {45.3956, -3.2077}, {45.5608, -3.20139}, {45.726, -3.18804},      {45.8912, -3.19259}, {46.0564, -3.22305}, {46.2216, -3.23381},      {46.3868, -3.21896}, {46.552, -3.19782}, {46.7171, -3.19925},      {46.8823, -3.21254}, {47.0475, -3.20822}, {47.2127, -3.20076},      {47.3779, -3.21503}, {47.5431, -3.23415}, {47.7083, -3.23585},      {47.8735, -3.21257}, {48.0387, -3.19277}, {48.2039, -3.21066},      {48.3691, -3.23566}, {48.5343, -3.23804}, {48.6995, -3.22519},      {48.8647, -3.22}, {49.0299, -3.22857}, {49.1951, -3.22214}, {49.3603,      -3.18748}, {49.5255, -3.17048}, {49.6907, -3.18617}, {49.8559,      -3.20105}, {50.021, -3.19556}, {50.1862, -3.19728}, {50.3514,      -3.22789}, {50.5166, -3.25828}, {50.6818, -3.252}, {50.847,      -3.22992}, {51.0122, -3.23513}, {51.1774, -3.23703}, {51.3426,      -3.19712}, {51.5078, -3.1469}, {51.673, -3.15768}, {51.8382,      -3.19598}, {52.0034, -3.22341}, {52.1686, -3.22205}, {52.3338,      -3.21716}, {52.499, -3.24412}, {52.6642, -3.25222}, {52.8294,      -3.22671}, {52.9946, -3.2061}, {53.1598, -3.21205}, {53.3249,      -3.20663}, {53.4901, -3.1892}, {53.6553, -3.18521}, {53.8205,      -3.21223}, {53.9857, -3.22453}, {54.1509, -3.21086}, {54.3161,      -3.20821}, {54.4813, -1.83753}, {54.6465, -0.497467}, {54.8117,      -0.172629}, {54.9769, -0.118185}, {55.1421, -0.0401817}, {55.3073,      -0.0390328}, {55.4725, -0.0519028}, {55.6377, -0.0341139}, {55.8029,      -0.0159919}, {55.9681, -0.0322755}, {56.1333, -0.0560436}, {56.2985,      -0.055005}, {56.4637, -0.0382538}, {56.6288, -0.0461829}, {56.794,      -0.0519669}, {56.9592, -0.0478512}, {57.1244, -0.0485063}, {57.2896,      -0.0450605}, {57.4548, -0.0328684}, {57.62, -0.0012728}, {57.7852,         0.000699344}, {57.9504, -0.0282098}, {58.1156, -0.0528248},      {58.2808, -0.0660222}, {58.446, -0.0670143}, {58.6112, -0.0803909},      {58.7764, -0.0722626}, {58.9416, -0.056143}, {59.1068, -0.052108},      {59.272, -0.041373}, {59.4372, -0.0346966}, {59.6024, -0.0253502},      {59.7676, -0.0264026}, {59.9327, -0.0481955}, {60.0979, -0.0662766},      {60.2631, -0.068389}, {60.4283, -0.0613654}, {60.5935, -0.0516283},      {60.7587, -0.0460859}, {60.9239, -0.026215}, {61.0891, -0.0075962},      {61.2543, -0.0158598}, {61.4195, -0.0383789}, {61.5847, -0.052961},      {61.7499, -0.0406836}, {61.9151, -0.0423972}, {62.0803, -0.0769325},      {62.2455, -0.0948179}, {62.4107, -0.0665865}, {62.5759, -0.0433503},      {62.7411, -0.0465402}, {62.9063, -0.064464}, {63.0715, -0.0543498},      {63.2366, -0.0287138}, {63.4018, -0.0410531}, {63.567, -0.0596464},      {63.7322, -0.0323676}, {63.8974, -0.00447797}, {64.0626, -0.0176177},      {64.2278, -0.0278519}, {64.393, -0.0175132}, {64.5582, -0.0343388},      {64.7234, -0.0728937}, {64.8886, -0.0859438}, {65.0538, -0.0851371},      {65.219, -0.0734951}, {65.3842, -0.0496842}, {65.5494, -0.00584685},      {65.7146,         0.0095625}, {65.8798, -0.00930119}, {66.045, -0.0250789},      {66.2102, -0.0359847}, {66.3754, -0.0667467}, {66.5405, -0.09646},      {66.7057, -0.0840331}, {66.8709, -0.0524984}, {67.0361, -0.0383522},      {67.2013, -0.0540666}, {67.3665, -0.0645649}, {67.5317, -0.0412653},      {67.6969, -0.0161336}, {67.8621, -0.037667}, {68.0273, -0.0628333},      {68.1925, -0.0356986}, {68.3577, -0.0229571}, {68.5229, -0.0403972},      {68.6881, -0.0403037}, {68.8533, -0.0353493}, {69.0185, -0.0300052},      {69.1837, -0.0497527}, {69.3489, -0.0725242}, {69.5141, -0.0655332},      {69.6793, -0.0600311}, {69.8444, -0.0536261}, {70.0096, -0.051527},      {70.1748, -0.045936}, {70.34, -0.0338074}, {70.5052, -0.0315814},      {70.6704, -0.0265081}, {70.8356, -0.0228345}, {71.0008, -0.0348291},      {71.166, -0.0534865}, {71.3312, -0.0559775}, {71.4964, -0.0523304},      {71.6616, -0.0514005}, {71.8268, -0.0403854}, {71.992, -0.0236734},      {72.1572, -0.0114473}, {72.3224, -0.0182658}, {72.4876, -0.0314441},      {72.6528, -0.0284464}, {72.818, -0.0324639}, {72.9832, -0.0492846},      {73.1483, -0.0854126}, {73.3135, -0.0898038}, {73.4787, -0.0559581},      {73.6439, -0.0413622}, {73.8091, -0.051359}, {73.9743, -0.058296},      {74.1395, -0.0417273}, {74.3047, -0.0255182}, {74.4699, -0.0485516},      {74.6351, -0.0663423}, {74.8003, -0.0699121}, {74.9655, -0.0530811},      {75.1307, -0.0473759}, {75.2959, -0.0496924}, {75.4611, -0.0424499},      {75.6263, -0.0241374}, {75.7915, -0.0436916}, {75.9567, -0.089127},      {76.1219, -0.0761635}, {76.2871, -0.0538311}, {76.4522, -0.0522625},      {76.6174, -0.0747319}, {76.7826, -0.0739987}, {76.9478, -0.0333077},      {77.113, -0.00486031}, {77.2782, -0.0153005}, {77.4434, -0.0266643},      {77.6086, -0.0274922}, {77.7738, -0.0620418}, {77.939, -0.0877488},      {78.1042, -0.0803497}, {78.2694, -0.0537084}, {78.4346, -0.0425878},      {78.5998, -0.0402573}, {78.765, -0.0197596}, {78.9302, -0.0105323},      {79.0954, -0.0277539}, {79.2606, -0.0459642}, {79.4258, -0.0416842},      {79.591, -0.0456379}, {79.7561, -0.0775024}, {79.9213, -0.0816734},      {80.0865, -0.0372224}, {80.2517, -0.0110671}, {80.4169, -0.0447514},      {80.5821, -0.073486}, {80.7473, -0.0684747}, {80.9125, -0.0510865},      {81.0777, -0.0564664}, {81.2429, -0.05117}, {81.4081, -0.0249809},      {81.5733, -0.00204501}, {81.7385, -0.0035259}, {81.9037,      -0.00623434}, {82.0689, -0.0128054}}}      When I plot these data with _Mathematica_ , I get the following figure: > ![Overview](http://i.stack.imgur.com/9voBl.jpg) By the way, this is a physical, non-local, spin valve signal at a given temperature. What I need is a method to find the two switching fields (actually 4 if negative values are also considered). At present, I doing the following: By hand, I make two linear fits, one for the area where the signal is constant at about $-3$ mOhm, one for the area where the signal is decreasing from $0$ mOhm to $-3$ mOhm. For all temperatures, the first area is nearly the same. In the second area, where is this strong decrease of the signal, I have to fit the line by hand. For this example it would be: > >     {{35.3187, 0.779363}, {35.4839, -1.12199}, {35.6491, -2.55552}, >      {35.8143, -2.94135}, {35.9795, -3.09798}} >   From these two lines, I get the intersection point which is what I am interessted in. This method takes me about 10 min for each intersection point because I have to do it by hand, which is OK for one data set. For the 240 data sets that I have this would take a relativly long time, so I'm looking for a way to automate it. The final result looks like this : > ![final result](http://i.stack.imgur.com/fJ9rw.jpg) What I find especially difficult is getting _Mathematica_ to find the correct values for the second line, because I usually have just 3 or 4 measured points for such lines. I hope someone will respond with some nice ideas how this can be done automatically.


Transition between graphs

I want to visually demonstrate the manipulations made to a graph. For instance, I have a graph `g` where using the command `LayeredGraphPlot[g, Bottom, VertexLabeling -> True]` I get this figure as the output: ![g1](http://i.stack.imgur.com/TDjyd.png) After adding an edge and using the same command I get this one: ![g2](http://i.stack.imgur.com/hmqdH.png) I want to show a smooth transition between the two figures so that the user can track the addition of the edge. Is there any easy/general way to do such an effect in Mathematica.


Remote access to notebook is very slow

I am using _Mathematica_ at work remotely from a computer in my building and I can edit notebooks by opening them from terminal via ssh without problem (a little slow if there is a figure with many points, but that's all). Now I need to work from home, but editing a notebook that I open from terminal is just impossible because it is too slow and freezes each time I click on it. I am still using ssh on Ubuntu 12.04. Any idea how I can make it faster?


Custom TransformationFunction in Graphics? GeometricTransformation::nonaffine error

There are many functions in Mathematica, which return expressions with `TransformationFunction` head, for example RotationTransform. Unfortunately, there is no PerspectiveTransform amongst them. How to create custom transformation functions in general? There is no explanation in docs. It is only said that "TransformationFunction works like Function." what does it mean? That writing `TransformationFunction` is just writing a `Function`? Also it is said that when possible "matrix forms for transformations can be obtained from TransformationFunction objects using TransformationMatrix." Can I have some samples of custom TransformationFunction with and without matrix? **UPDATE** If I provide my transformation (homogenous) matrix it produces "nonaffine" error: ![enter image description here](http://i.stack.imgur.com/TJho5.jpg) ![enter image description here](http://i.stack.imgur.com/ffbB0.jpg) ![enter image description here](http://i.stack.imgur.com/w0X0h.jpg) **UPDATE 2** Now trying to form transformation via `LinearFractionalTransform` and effect ios the same ![enter image description here](http://i.stack.imgur.com/R94mK.jpg)


Function[] argument nesting for operations like Select[]

The following code selects a special element from a list               thelist = {"this", "notthis"};          Select[thelist, (# == "this") &]      What I want is a function which does just that and which takes lists (like _thelist_ ) and a string (like _"this"_ ) as argument. However I have a problem, because _Select_ already uses an abstract function and so the naive idea               sel:=Select[#1, (# == #2) &]          sel[thelist,"this"]      doesn't work. This is really about the Function command and the problem might not just appear with _Select_ but any abstract function nesting. How to construct the object I need?


ListDensityPlot: How to only retain regions with data without using interpolation?

I'm working with `ListDensityPlot` on a set of triples, $\\{\\{x_1, y_1, z_1\\}, \dots\\}$. The data is on a semi-regular grid and looks just as it should through most of the plot. However, at the boundary of the dataset, the function continues on with the bordering hue. ![Mathematica graphics](http://i.stack.imgur.com/1sMXt.png) Is there a simple way to fix this? I think it should work to append 'above' the data set a 'dummy' region with zero's or the like, but I feel that there must be something more elegant. Anyone have any thoughts? The top of the function is not neatly described by an analytic function, or this would be rather simple.


Decomposing a diagonal positive real matrix

I would like to 'decompose' a _diagonal positive real_ matrix $E$ of rank $D$ onto $\sum_{i=1}^{D}c(i)N^i$: $$E = \left( \begin{array}{ccc} 0 & & & \\\ & a & & \\\ & & b & \\\ & & & \ldots \\\ \end{array} \right) \Rightarrow \sum_{i=1}^{D}c(i)N^i$$ where $$ N = \left( \begin{array}{ccc} 0 & & & \\\ & 1 & & \\\ & & 2 & \\\ & & & \ldots \\\ \end{array} \right) $$ and $\bigl\\{c(0), c(1), c(2), \ldots \bigr\\}$ is the coeffients we want to find given $E$. Just a note about $E$: it is well behaved and $0<a<b<\ldots$. We can also assume $E$ is such that $c(i) < c(i+1)$. First I just re-express the problem as a set of linear equations, where $E[i]$ is the $i$th eigenvalue of the rank $D$ matrix and $D_{max}$ is the truncation of the expansion (I assume I have truncate because of numerical difficulty in solving the equations). $D$ should be of $\mathcal{O}(10^3)$: $$ E[p] = \sum_{i=1}^{D_\max}c(i)p^i : p\in(1,\ldots,D)$$ This sounds more complicated than the rather simple problem I think it should be. Now in terms of _Mathematica_ my toy attempt is as follows:                d = 10;       Dmax = 5;       (* Generate matrix E *)      evals = Table[1.25* x - 1.21*10^-5 x^2 + 10^-6 x^3 + 0*10^-8 x^7, {x, 1, d}]      (* Decompose *)      eqns = Table[ evals[[p]] == Sum[c[i] p^i, {i, 1, Dmax}], {p, 1, d}];      solns = NSolve[eqns, Table[c[i], {i, 0, Dmax}], Reals]  ;      Chop@solns       So as long as this is soluble, this works and gives:                (* {{c[1] -> 1.25, c[2] -> -0.0000121, c[3] -> 1.*10^-6, c[4] -> 0, c[5] -> 0}} *)      That is as long as 0 multiples $10^{-8} x^7$. Otherwise this is not a problem to solve but to minimize (which is the case of interest). (The `NSolve` here is just to demonstrate the idea). Using `NMinimize` with the constrains: $c[1] > c[2] > c[3] > c[4] > c[5]$:                eqns = Table[Abs[evals[[p]] - Sum[c[i] p^i, {i, 1, Dmax}] ],          {p, 1, d}];      solns = NMinimize[{Total[eqns],  Greater @@ Table[c[i], {i, 1, Dmax}]}, Table[c[i], {i, 1, Dmax}]]        Which gives the bad result:                (* {995.29, {c[1] -> 0.91, c[2] -> 0.468, c[3] -> 0.247, c[4] -> 0.245, c[5] -> -0.030}} *)      This is quite far from the result above, and it is much worse if the $10^{-8}x^7$ term is included. Does anyone have any ideas on how to do this more correctly or efficiently?