title: How to set the initial condition? (to make IC and BC consistent)

text: I want to find the initial condition which fits mixed boundary condition of Phi[r, Theta, t]. The original initial condition in text is               Phi[r, Theta, 0] == 1      . I heard the information that the initial condition doesn't have to be strictly consistent (the value 1). It can be bigger or smaller than 1, or can vary. The mixed boundary condition which should be consistent with initial condition and shouldn't be changed is               Derivative[1, 0, 0][Phi][s, Theta, t] == k/rc Phi[s, Theta, t]      I tried five kinds of initial conditions. At first, as information in text               Phi[r, Theta, 0] == 1      At second, (using exponential function in small section)               Phi[r, Theta, 0] == If[r < (1 + a) s, Exp[k/rc (r - s)], If[r < (1 + 2 a) s,      Exp[-(k/rc) (r - (1 + 2 a) s)], 1]]      At third, (using linear function in small section)               Phi[r, Theta, 0] == If[r < (1 + b) s, k/rc (r - s) + 1, If[r < (1 + 2 b) s,      -(k/rc) (r - (1 + 2 b) s) + 1, 1]]      At fourth, (using exponential function again but some different from second)               Phi[r, Theta, 0] == If[r < (1 + c) s, 2 - Exp[-(k/rc) (r - s)], If[r < (1 + 2 c) s,      2 - Exp[k/rc (r - (1 + 2 c) s)], 1]]      At fifth, (same function with second, but using Piecewise than If statement)               Phi[r, Theta, 0] == Piecewise[{{Exp[k/rc (r - s)], r < (1 + a) s}, {Exp[-(k/       rc) (r - (1 + 2 a) s)], r < (1 + 2 a) s}, {1, r >= (1 + 2 a) s}}]      All five trial gave me 'ibcinc boundary and initial conditions are inconsistent' error message. How can I set ' **initial condition** ' to fit 'mixed boundary condition'? Thanks in advance! * * * * * * _From here, it is the before-shortened question. (How to get over NDSolve ibcinc error message? (Inconsistent initial condition and mixed boundary condition))_ I have a question about the error message which includes ibcinc. The problem is that I tried to adjust initial condition to satisfy the Mixed boundary condition, but I was still given ibcinc inconsistent message. The original initial condition is               Phi[r, Theta, 0] == 1      . I tried to make new initial condition (Fun1[r],Fun2[r],and Fun3[r] instead of 1) using this original initial condition. However, this gave same ibcinc inconsistent IC and BC error message. The hole code is following.               Clear["Global`*"]     Dif = 1.33 10^11;     s = 8 ;     rc = s/0.0713;     k = 10^4;     a = 10^-3;     Fun1[r_] =      If[r < (1 + a) s, Exp[k/rc (r - s)],      If[r < (1 + 2 a) s,      Exp[-(k/rc) (r - (1 + 2 a) s)], 1]]     b = 10^-3;     Fun2[r_] =      If[r < (1 + b) s, k/rc (r - s) + 1,      If[r < (1 + 2 b) s, -(k/        rc) (r - (1 + 2 b) s) + 1, 1]]     c = 10^-3;     Fun3[r_] =      If[r < (1 + c) s, 2 - Exp[-(k/rc) (r - s)],      If[r < (1 + 2 c) s,      2 - Exp[k/rc (r - (1 + 2 c) s)], 1]]     Fun11[r_] = Piecewise[{{Exp[k/rc (r - s)],      r < (1 + a) s}, {Exp[-(k/rc) (r - (1 + 2 a) s)], r < (1 + 2 a) s}, {1,      r >= (1 + 2 a) s}}]     Plot[Fun1[r],{r,s,(1+3 a)s}]     Plot[Fun2[r],{r,s,(1+3 b)s}]     Plot[Fun3[r],{r,s,(1+3 c)s}]     Plot[Fun11[r],{r,s,(1+3 a)s}]     t0 = 10^-3;     tmax = 10;     rmax = 1.5 s     e = 1.602 10^-19     Ef = 10^6     kB = 1.381 10^-23     T = 298     Const = (e Ef)/(kB T) /10^10 (* 1/(angstrom)*)     sol = NDSolve[{D[Phi[r, Theta, t], {t, 1}] ==      Dif (D[Phi[r, Theta, t], {r, 2}] +         1/r^2 D[Phi[r, Theta, t], {Theta, 2}] + (2/r -            rc/r^2 + Const Cos[Theta]) D[Phi[r, Theta,            t], {r, 1}] + (1/r^2 Cos[Theta]/Sin[Theta] -            Const/r Sin[Theta]) D[Phi[r, Theta,            t], {Theta, 1}]), Phi[r, Theta, 0] ==      Fun3[r], Phi[rmax, Theta, t] ==      1, ( Derivative[1, 0, 0][Phi][s, Theta,        t]) == k/rc (Phi[s, Theta, t]), (       D[Phi[r, Theta, t], {Theta, 1}] /. Theta ->         10^-3) ==      0, ( D[Phi[r, Theta, t], {Theta,          1}] /. Theta -> (\[Pi] - 10^-3)) ==      0}, Phi, {r, s, rmax}, {Theta,      10^-3, \[Pi] - 10^-3}, {t, 0, tmax}, PrecisionGoal -> 4,      StartingStepSize -> 0.0001,      Method -> {"MethodOfLines",      "SpatialDiscretization" -> {"TensorProductGrid",        "MinPoints" -> 100, "MaxPoints" -> 200}}]          (*BCtest1*)Plot3D[      First[(Phi[rmax, Theta, t] - 1) /. sol], {Theta,       10^-3, \[Pi] - 10^-3}, {t, 0, tmax}]     (*BCtest2-1*)Plot3D[      First[((( D[Phi[r, Theta, t], {r, 1}]) - k/         rc Phi[r, Theta, t]) /. sol) /.       r -> s], {Theta, 10^-3, \[Pi] - 10^-3}, {t, 0, tmax}]     (*BCtest2-1-1*)Plot3D[      First[((( D[Phi[r, Theta, t], {r, 1}])) /. sol) /.       r -> s], {Theta, 10^-3, \[Pi] - 10^-3}, {t, 0, tmax}]     (*BCtest2-1-1-1*)Plot3D[      First[((( D[Phi[r, Theta, t], {r, 1}])) /.       r -> s) /. sol], {Theta, 10^-3, \[Pi] - 10^-3}, {t, 0,       tmax}]     (*BCtest2-2*)Plot3D[      First[((( D[Phi[r, Theta, t], {r, 1}]) - k/          rc Phi[r, Theta, t]) /. sol) /.       r -> s] + k/rc, {Theta,       10^-3, \[Pi] - 10^-3}, {t, 0, tmax}]     (*BCtest2-3*)Plot3D[      First[((( D[Phi[r, Theta, t], {r, 1}]) - k/         rc (Phi[r, Theta, t] - 1)) /. sol) /.       r -> s], {Theta, 10^-3, \[Pi] - 10^-3}, {t, 0, tmax}]     (*BCtest3*)Plot3D[      First[( D[Phi[r, Theta, t], {Theta, 1}] /. Theta ->        10^-3) /. sol], {r, s, rmax}, {t, 0, tmax}]     (*BCtest4*)Plot3D[      First[( D[Phi[r, Theta, t], {Theta,         1}] /. Theta -> (\[Pi] - 10^-3)) /. sol], {r, s,       rmax}, {t, 0, tmax}]          Phin = First[Phi /. sol]     Plot3D[Phin[s, Theta, t], {Theta,      10^-3, \[Pi] - 10^-3}, {t, 0, tmax}]     Plot3D[Phin[r, 10^-3, t], {r, s, rmax}, {t, 0, tmax}]      If solution is well investigated, boundary conditions should have consistency so that the boudary condition test gives the value nearly zero ( _BCtest 1~4_ ) using Plot3D, but the second boundary condition               ( Derivative[1, 0, 0][Phi][s, Theta, t]) == k/rc (Phi[s, Theta, t])      is not satisfied (That is, in boundary condition test ( _BCtest2-1_ ) using Plot3D, (Derivative[1,0,0][Phi][s, Theta, t]- (k/rc) Phi[s, Theta, t]) should give nearly zero, but k/rc ), and is expected to have conflicts with initial condition               Phi[r, Theta, 0] == Fun1[r]      ,               Phi[r, Theta, 0] == Fun2[r]      , or               Phi[r, Theta, 0] == Fun3[r]      Could I get a suggestion for adjust the initial condition to new one which doesn't deviate much from the original initial condition               Phi[r, Theta, 0] == 1      ? Or can I receive new insights to get over inconsistent IC and BC error message? Thanks in advance!


title: Changing "Block[]" to a Manipulation

text: I have a graph here and I want to be able to manipulate the 4 parameters that are in the Block command. I want to watch the graph change as I change the parameters. I've done this before, but the Block command that Mathematica suggested throws me off a little bit. Here is the code:                test = Block[{ε = 3, ω0 = 1, ωf = 1.788,       A = 5}, Reap[      NDSolve[{x''[t] == ε (1 - x[t]^2) x'[t] - ω0^2*x[t] +           A*Sin[ωf*t], x[0] == 1, x'[0] == 0,         WhenEvent[Mod[t, 2 π/ωf] == 0,          Sow[{x[t], x'[t]}]]}, {}, {t, 0, 10000},        MaxSteps -> ∞]]][[-1, 1]];          ListPlot[test, ImageSize -> Medium, PlotRange -> All,       PlotStyle -> PointSize[0.0035]]


title: ListPlot under conditions Part II

text: I have a data file containing several columns and thousands lines of data. Below I present a small portion of it, in order to express my issue:               -6.00000000          -0.50000000   0.2012925952067529E+01   -.1354335628382003E+01   -.1226489717949115E+01   0.3971000000000000E+02   0.3563073636222663E-02    8     -6.00000000          -0.40000000   -.1667709017102080E+01   0.1996988297249126E+01   -.8819770483714856E+00   0.2608000000000000E+02   0.7532864609099250E-05    6     -6.00000000          -0.30000000   -.1790107106742991E+01   -.1663230917261907E+01   0.1128076001589623E+01   0.2088000000000000E+02   0.3177221419972102E-02    3     -6.00000000          -0.20000000   -.1705528943436493E+01   -.1416493048162809E+01   -.1473371717762452E+01   0.1974000000000000E+02   0.1287464426169665E-04    7     -6.00000000          -0.10000000   -.1438853964633666E+01   0.8237153975034051E+00   0.2328464291089728E+01   0.1852000000000000E+02   0.4189535638506170E-02    2     -6.00000000           0.00000000   -.7656851229280424E+00   -.1226763235452721E+01   -.2690993457287972E+01   0.4270000000000000E+02   0.1253249246603346E-11    7     -6.00000000           0.10000000   0.2359731627744364E+01   -.1081845089584134E+01   -.1195510444527736E+01   0.3603000000000000E+02   0.3777453269309895E-06    8      The first two columns correspond to the coordinates $x$ and $y$. I have a MMA code (is given below) for plotting the coordinates $(x,y)$ and assign to each point a color according to the value of the sixth column. The last column has an integer which takes values inside the interval [0,8].               input = ReadList["data18.out", Number, RecordLists -> True];     input2 = ReadList["data0.out", Number, RecordLists -> True];          data = Table[{input[[i, 1]], input[[i, 2]], Log10[input[[i, 6]]]}, {i,1, Length[input]}];     data2 = Table[{input2[[i, 1]], input2[[i, 3]]}, {i, 1, Length[input2]}];          Clear[colorbar]     colorbar[{min_, max_}, colorFunction_: Automatic, divs_: 150] :=      DensityPlot[y, {x, 0, 0.1}, {y, min, max}, AspectRatio -> 10,      PlotRangePadding -> 0, PlotPoints -> {2, divs}, MaxRecursion -> 0,      Frame -> True,      FrameLabel -> {{None,       Row[{Subscript["log", "10"], "(", Subscript["t", "esc"],         ")"}]}, {None, None}},      LabelStyle -> Directive[FontFamily -> "Helvetica", 17],      FrameTicks -> {{None, All}, {None, None}},      FrameTicksStyle -> Directive[FontFamily -> "Helvetica", 15, Plain],      ColorFunction -> colorFunction]          V = ω^2/2*(x^2 + y^2 + z^2) + ϵ*(x^2*y^2 + x^2*z^2 +        y^2*z^2 - x^2*y^2*z^2);     Vxy = V /. {z -> 0};     ω = ϵ = 1;     E0 = 8.5;     z0 = 0.1;     xmin = 4.5;          f[x_, px_] := 1/2*px^2 + V /. {y -> 0, z -> z0};          plrange = {{-xmin, xmin}, {-xmin, xmin}};     valrange = {0, 5};          C0 = ContourPlot[Evaluate[f[x, px]], {x, -5, 5}, {px, -5, 5},      Contours -> {E0}, ContourStyle -> {{Black, Thickness[0.003]}},      AspectRatio -> 1, ContourShading -> False, PlotPoints -> 200,      PerformanceGoal -> "Speed", PlotRange -> plrange];          L0 = ListPlot[data2, PlotStyle -> {Black, PointSize[0.011]}];          With[{opts = {ImageSize -> {Automatic, 550}}, cf = "Rainbow"},      Row[{Show[     ListPlot[List /@ data[[All, {1, 2}]],       PlotStyle -> ({PointSize[0.01], ColorData[cf][1 - #]} & /@          Rescale[data[[All, 3]], valrange]), PlotRange -> plrange,       AspectRatio -> 1, Frame -> True, RotateLabel -> False,       Axes -> None, FrameTicks -> True,       FrameLabel -> {Subscript["x", "0"],         OverDot[Subscript["x", "0"]]},       LabelStyle -> Directive[FontFamily -> "Helvetica", 17],       ImagePadding -> {{60, 20}, {60, 20}}, opts], C0, L0],      Show[colorbar[valrange, ColorData[cf][1 - #] &],      ImagePadding -> {{20, 60}, {60, 20}}, opts]}]]      The `data18.out` file contains all the data. However, if there is a zero at the last column I want the corresponding points to be plotted in black; only when 1-8 the rainbow colors should apply. So, in order plot with in black these points, I extracted them in a separate file `data0.out`. What I want is instead of using two files, to use only the original `data_all.out` file. I suppose that and `IF` condition is possible inside the `ListPlot` Here is the final output ![grid](http://i.stack.imgur.com/8518J.jpg) Many thanks in advance. **EDIT** The complete data file can be found here: data **EDIT 2** A revised working MMA notebook can be downloaded from here: code


title: Set Frame Margin for Exporting Video File (.avi)

text: I have a question regarding setting the frame margins of exporting .avi file. I want to make a short video of some pictures I import using Table:               table1 = Table[     [Show[Import[ToString[i] <> ".eps"], ImageSize -> Large], {i, 1, 100, 1}];      These pictures are all fine with 0 image padding, but when I try exporting them to video:               Export["1.avi", table1, ImageSize -> Large,      "FrameRate" -> 4],      And the video cuts them off, as if only showing a thin stripe of the whole pictures. I tried messing with ImagePadding, but that only puts the pictures in the video in the bottom left corner. Is there a way to show the pictures in the video at the center of the screen, when playing? Thank you very much.


title: Converting other C++ classes to MTensor in LibraryLink

text: Hopefully this will be a quick question + a quick answer: Say I have a C++ (or C) code using LibraryLink. I am using a library that defines a specific matrix class, as many numerical libraries commonly do. So during the computations I am using this class and, at the very end, I want to convert it to an MTensor to be used as output. What is the simplest way to do that? Hopefully, one that does not require reallocating the entire matrix? [Not sure it helps, but the matrix elements are assumed to be stored sequentially.] Thank you in advance for the support. Gabriel **Edit:** Two examples are the NVector class in SUNDIALS and the Matrix class in numerical recipes (3rd Edition in C++). Here is a quote from Numerical Recipes ($n$,$m$ are integers): let               MatDoub a(n,m);     Doub *b &a[0][0];      Then $a[i][j]$ and $b[m*i+j]$ are equivalent.


title: Complex Numbers: need to find $\left | H(\omega ) \right |$ and the arg $\left | H(\omega) \right |$ of the following equation

text: > Let $H(\omega)$ be a complex-valued function of the real variable $\omega$. > Find $\left | H(\omega ) \right |$ and arg $\left | H(\omega ) \right |$. > > $\quad \quad H(\omega) = \frac{-2-j\omega}{(3 + j\omega)^{2}}$ I'm pretty cobfused with what I'm supposed to be looking for. Am I looking for the principle argument of $H(\omega)$? and just calculate the absolute value of the function?


title: NSolve cannot solve system of equations in Mathematica

text: I have the following two equations:               Ieq1=-1 - (0.763546 I1 (1/(-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2) - (     18 (1 - 9/I1 + 10/I2))/(     I1 (-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2)^2)) X^1.3)/((1.36-      I1) (I1/(-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2))^2.3) + (     0.587343 X^1.3)/((1.36-      I1) (I1/(-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2))^1.3) + (     0.587343 I1 X^1.3)/((1.36-      I1)^2 (I1/(-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2))^1.3);          Ieq2=1 + (0.763546 I1^2 ((20 (-8 + 10/I2))/I2^2 - (20 (1 - 9/I1 + 10/I2))/     I2^2) (-8 + (1 - 9/I1 + 10/I2)^2) X^1.3)/((1.36-      I1) (I1/(-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/       I2)^2))^2.3 (-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2)^3) - (      0.587343 I1 ((20 (-8 + 10/I2))/I2^2 - (20 (1 - 9/I1 + 10/I2))/     I2^2) (-8 + (1 - 9/I1 + 10/I2)^2) X^1.3)/((1.36-      I1) (I1/(-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/       I2)^2))^1.3 (-(-8 + 10/I2)^2 + (1 - 9/I1 + 10/I2)^2)^2);      and then I use the NSolve function:                NSolve[{Ieq1 == 0, Ieq2 == 0}, {I1, I2}]      because I want to solve each one as a function of X. But unfortunately it just gets stuck while running. Do you have any suggestions to overcome this problem?


title: Packing squares into a circle

text: I am currently trying to solve and understand a problem about packing the maximum of squares into a circle. What I am trying to do, is to calculate the maximum number of variable sized squares (with fixed side) into a circle of variable diameter. For example the result you get at WolframAlpha typing 'pack squares of side 50mm into a circle of diameter 300mm': Densest known packing: ![enter image description here](http://i.stack.imgur.com/D26ua.gif) Furthermore, I would like to be able to add a variable for horizontal and vertical spacing between each square. I have found this to be exactly what I am trying to understand and build.


title: some confusion about ReplaceRepeated

text: This is Right.               NestWhile[Log, 100, # > 1 &]     {100} //. {x_} /; x > 1 :> {Log[x]}     100. //. x_ /; x > 1 :> Log[x]      This is wrong,why?               100 //. x_ /; x > 1 :> Log[x]      ![enter image description here](http://i.stack.imgur.com/0BFpO.jpg)


title: Simple Solve example fails: why?

text: `Solve` is an amazing tool, but sometimes it doesn't work in the way I expect it to. The particular instance that is confusing me right now is this:               Solve[a==b&&c==d,a]      I expect it to tell me that `a->b`, but instead it gives no solutions. I am using version 9, if this makes a difference. To be clear, my question is _not_ how do I fix this example (e.g. "Ian, just do `Solve[a==b&&c==d,{a,c}]`"), but rather, _why_ does it think there are no solutions. Bonus if you can provide a tool that does think `a->b` is a solution. **Update:** Thanks to @MichaelE2 in the comments for the illustrative example -- it made obvious what was not obvious to me before; `Solve` performs a task which is only an approximation to the everyday meaning of the word "solve". When I think of the expression `Solve[expr,vars]`, what I want it to do is treat every symbol not in the list `vars` as "known" and solve for the "unknown" symbols in `vars`. What it actually does is try to find a set of replacements for the symbols in `vars` such that `expr/.soln` is `True`. This slight difference in meaning is usually not an issue, but for examples like the one above, and also ones like               Solve[{a==b,b==c},c]      these two meanings give very different, but respectively correct, answers. I guess the updated question is just the bonus: is there a function which does a better job of approximating the "usual" definition of solve.


How can I make a stylesheet where inline cells have are styled like input cells? By "similar", I mean the same font and syntax highlighting. I have even tried copying all settings from `Input` cell of `Core.nb` to a private style definition for `InlineCell`, but had no luck.


title: How do I find the intersection of a closed 3D curve given by numerical data with a specified plane?

text: I have a list of 3D data points which form a closed curve. My own data can't be easily generated analytically, but the qualitative behaviour is well represented by a parametric curve families such as `{Sin[a1 t] Cos[a2 t], Sin[a3 t] Sin[a4 t], Sin[a5 t]}` where the `aN` are constants. Sample data is given by:               dt = Table[{Sin[3 t] Cos[1 t], Sin[t] Sin[5 t], Sin[2 t]}, {t, -10, 10, 0.005}];     p1 = ListPointPlot3D[dt]      ![points from a closed curve](http://i.stack.imgur.com/nqFrN.png) I want to solve for the points where this closed 3D curve cuts a plane I specify but I'm am unable to do it. For example a plane at `z = 0.5` as shown here:               p2 = Plot3D[-0.5, {x, -1, 1}, {y, -1, 1}]     Show[p1, p2]      ![cutting plane](http://i.stack.imgur.com/24FqM.png) No approach I've tried so far has worked e.g. `Interpolation`, `Nearest` to -0.5, use of `Select` and `Drop`. The data does wrap around itself multiple times and getting slightly different solution points on each pass due to differences in the stepsize or something like that is not a problem. Related I think to this question In brief: How can I find where a closed curve given by numerical data points cuts a specified plane? Any help you can give is much appreciated.


title: Plotting series solution to the heat equation

text: I am trying to plot a solution to the heat equation $u(x,t) = \sum_1^\infty \frac{8(-1)^(n+1)}{\pi^2 n^2} \sin(n \pi x) \exp(-n^2 \pi^2) $ I am using the following from another answer here on Mathematica. I am trying to plot it from x=[0,1]. I am trying the following, but it does not seem to produce a plot               f[x_, t_, nm_] := SUM[(8 (-1)^(n + 1)/(Pi^2*n^2))*Sin[n* Pi *x]*Exp[-n^2 Pi^2*t], {n, 1, nm}];          Plot[Table[f[x, t, 150], {t, {0, 0.01, 0.1, 0.5, 1, 10}}] // Release, {x, 0, 1, 0.05}]


title: Why do certain values in ArcSin not fully evaluate?

text: This is a continuation of: Why do certain fractional values in TriangleWave not evaluate?   The analysis by R.M and rasher revealed that problem to reduce to the behavior of:               ArcSin[Sin[π / 10]]      > >     ArcSin[1/4 (-1 + Sqrt[5])] >   Every other denominator besides ten, at least up to 500,000, automatically evaluates to a simpler form:                Position[ArcSin[Sin[π / Range[500000]]], _ArcSin]  (* slow *)      > >     {{10}} >   All other coefficient of π with a denominator of ten appear to exhibit the same problem:               ArcSin[Sin[{1, 3, 7, 9, 11} π/10]]      > >     {ArcSin[1/4 (-1 + Sqrt[5])], ArcSin[1/4 (1 + Sqrt[5])], ArcSin[1/4 (1 + > Sqrt[5])], >      ArcSin[1/4 (-1 + Sqrt[5])], ArcSin[1/4 (1 - Sqrt[5])]} >   `FullSimplify` reduces the expression:                ArcSin[Sin[{1, 3, 7, 9, 11} π/10]] // FullSimplify      > >     {π/10, (3 π)/10, (3 π)/10, π/10, -(π/10)} >   Is this a bug? Is there some explanation for it? * * * **Before someone points out the obvious** : I see that `Sin[π/10]` evaluates to `1/4 (-1 + Sqrt[5])`. But why isn't `ArcSin` "smart" enough to recognize this value, when it recognizes others? For example `Sin[π/12]` evaluates to `(-1 + Sqrt[3])/(2 Sqrt[2])` but `ArcSin` correctly recognizes this and outputs `π/12`.


title: Return struct from function (with DownValues)

text: In Mathematica there is a way to create struct-like data type:               struct[myField]=value      I want to return myStruct from a function:               getStruct[input_List] := Module[{struct},        (*populate struct[key]=value from input*)        Return[struct];        ];      But when I do:               st = getStruct[myInput];     DownValues[st]      it returns nothing, because it references symbol that was created inside function (like struct$1299885). I can still access this struct with st["field"], but it's not very usefully without field list. Basically, I want to pass structs between functions, easily get field list AND easily access values inside those fields. And no, I don't want to do this with global symbols - I want to keep everything in local scope. Is it possible with Mathematica? I tried this approach because you can easily nest structs within each other and easily access nested fields, like st["field1"]["field2"]. I can also do this with list of rules, but nested access requires a lot of code and looks ugly for something so simple. Edit: it seems I was missing something very simple. To get list of fields I just needed to run:               DownValues[Evaluate[st]]      Thanks, Leonid.


title: Showing result of derivative and other functions

text: I have a problem with my _Mathematica_ 7.0 When I write:               Derivative[x^2, x]      Mathematica returns as result :               Derivative[x^2, x]      not `2x` Why is that? Am I doing something wrong with `Derivative`?


title: Animated Vector plot

text: I'm trying to make an animation of a time-varying 2D vector field. However, I'm got a difficulty in that _Mathematica_ normalises the length of the vectors with each call to `VectorPlot`. A (very simple) example:               myField = {Cos[2 π t], 0};          Animate[             VectorPlot[myField /. t -> TT, {x, -1, 1}, {y, -1, 1}],             {TT, 0, 1}]      Expected result: The arrows grow and shrink in time The actual result: The arrows remain the same size, but flick direction Is there some way to fix the length of the arrows relative to the field value?


title: Conditional solution for system of linear equations

text: I have a linear equation system `Q.m = t`, with `m` unkown and where `Q` has dimensions `{(n-1)²,n²}`, `t` has dimensions `{(n-1)²}` and `m` dimensions `{n²}`. I'm trying to find a way to find a (possible) solution `m1` such that `Norm[Partition[m1,n]]` is less or equal to 1. My idea goes something like this: Somehow optimizing using the solution given by `LinearSolve[Q,t]` and `NullSpace[Q]`. I got some help with the code from a friend, he gave this suggestion:               ns = NullSpace[Q];     vars = Array[p, {Length@ns}];     sol = Partition[m + vars.ns, n];     NumericMatrixOnly[f_][args_?(MatrixQ[#, NumericQ] &)] := f[args]     AbsoluteTiming[     res = FindMinimum[Max[NumericMatrixOnly[Norm][sol], 1], vars];]     m1 = sol /. Last@res;      This solution isn't as fast or accurate as I would want, in what other ways could I optimize this? I could do it with alternating projections, but I wanted to see if Mathematica have any nice built-in methods.


title: Long run time for older code that ran fast in older versions

text: The following code block is in Trott's Guidebook for Programming. The associated notebook says that this and a few other routines ran in a matter of seconds. I killed it after half an hour.   I am curious to know what might be the issue. My guess is that `$MaxMachineNumber` is much bigger on my new laptop.               Module[{cp, cls, L = 0.02},       (* an initial contour plot *)       cp = ContourPlot[Im[Exp[1/(x + I y)]], {x, -L, L}, {y, -L, L},                         PlotPoints -> 400, DisplayFunction -> Identity] /.       (* replace large high-precision numbers by biiig machine numbers *)          z_?(Abs[#] > $MaxMachineNumber&) :> Sign[z] $MaxMachineNumber/2;       (* homogeneously distributed contour lines *)                        cls = #[[100]]& /@ Partition[Sort[Flatten[cp[[1]]]], 800];          (* the final contour plot *)            ListContourPlot[cp[[1]], MeshRange -> {{-L, L}, {-L, L}},                       Contours -> cls, ContourLines -> False,                       ColorFunction -> (Hue[Random[]]&),                        AspectRatio -> Automatic, FrameTicks -> None]]


title: Mathematica Manipulate with macros AND variable number of controls (persistence desired)

text: This post about avoiding code duplication in `Manipulate` helped a lot getting as far as I did. The method of "macros" outlined there works excellent, but when the number of controls is again controlled by yet another manipulate control, things get difficult. I got two closely related problems in that area: **Problem 1:** The following works like a charm:               With[{rows = 3, cols = 3, fieldSize = 5},       Manipulate[         Column[{           TableForm@mat,           Row[{"det = ", Det[mat]}]         }]         , {mat, None}, {initialized, None}         , Evaluate@With[{makeRow = Function[{rowIndex},             Map[Function[{colIndex}                 ,InputField[Dynamic[mat[[rowIndex, colIndex]]], Number, FieldSize -> fieldSize]]               , Range[cols]]             , HoldAll]}         , Grid[Map[makeRow, Range[rows]]]]         , Initialization :> (           If[Not[initialized === True], mat = Table[0, {rows}, {cols}]];           initialized = True         )         , SaveDefinitions -> True     ]]      ![Mathematica graphics](http://i.stack.imgur.com/rAd1T.png) I can enter a matrix, and Manipulate will calculate the determinant. If I start a new session, the values from the last session will still be there (important). But now suppose, I want to specify the matrix size with a setter bar. This can be done by wrapping a manipulate around it.               Manipulate[       With[{rows = size, cols = size, fieldSize = 5},         Manipulate[           Column[{TableForm@mat, Row[{"det = ", Det[mat]}]}]           , {mat, None}, {initialized, None}           , Evaluate@With[{makeRow = Function[{rowIndex},               Map[Function[{colIndex}, InputField[Dynamic[mat[[rowIndex, colIndex]]], Number, FieldSize -> fieldSize]], Range[cols]]               , HoldAll]}             , Grid[Map[makeRow, Range[rows]]]]           , Initialization :> (             If[Not[initialized === True], mat = Table[0, {rows}, {cols}]];             initialized = True           ), SaveDefinitions -> True]]         , {{size, 3}, Range[7], ControlType -> SetterBar}     ]      But this breaks the persistence over sessions. I tried to put the variable mat into the outer `Manipulate`, but that broke the whole thing. ![Mathematica graphics](http://i.stack.imgur.com/4K1IH.png) **Problem 2:** Kind of the same thing, with sliders instead of input fields.   I want to use a combination of setter bars and sliders to input a discrete probability istribution, and then do stuff with it within a manipulate.   IMPORTANT: The values should be persistent over sessions. ![Mathematica graphics](http://i.stack.imgur.com/8hP3N.png) Via the setter bar, I indicate that I want, for example, a prob dist for the integers from 2 through 5. That should then bring up 4 sliders that I can use to define the prob dist, one for each number. So the number of sliders should be variable. As you can see, I solved the problem of writing a macro for the slider generation, but I failed to make the number of sliders dependent on the inputs from the setter bars. It's clear from the code how I tried to solve the problem: The code, as it is, does everything I want, except that the number of sliders is always the same; and if you change one of the "lifeIsEasy" variables, it will seize to work.               With[{slidersPerRow = 3, lifeIsEasy1 = False, lifeIsEasy2 = False,        length = 8       , normalize = Function[{pd, from, to}         , With[{total = Total[pd[[Range[from, to]]]], len = to - from + 1}          , If[total == 0, Table[1/len, {len}],            pd[[Range[from, to]]]/total]]]},      Manipulate[       If[max < min, max = min];       Column[{         Row[{"min ", min, "   max ", max}]         , Row[{"=== slider values ==="}]         , TableForm[{sliderVals}, TableHeadings -> {None, Range[length]}]         , Row[{"=== prob dist ==="}]         , TableForm[{normalize[sliderVals, min, max]},           TableHeadings -> {None, Range[min, max]}]         , Row[{"expectation: ",            normalize[sliderVals, min, max] . Range[min, max]}]         }]       , {initialized, None}       , {sliderVals, None}       , Row[{         Control[{{min, 1}, Range[4], ControlType -> SetterBar}]         , Spacer[25]         , Control[{{max, min + 3}, Range[min, min + 4],            ControlType -> SetterBar}]         }]       , Row[{"I want ", Dynamic[max - min + 1], " sliders in ",          Dynamic@Ceiling[(max - min + 1)/slidersPerRow], " rows, "         , slidersPerRow, " per Row, and ",          Dynamic@Mod[max - min + 1, slidersPerRow, 1], " in the last" }]       , Evaluate@With[{makeSl = Function[{index}            , Dynamic@             Row[{ToString[index] <> " ",                Manipulator[Dynamic[sliderVals[[index]]]]}]            , HoldAll]}         , With[{           makeSliderRow = Function[{startIndex, endIndex}             , Row[Map[makeSl, Range[startIndex, endIndex]], Spacer[10]]]           }          , Sequence @@ Table[            makeSliderRow[             min + slidersPerRow*sliderRow(*=startIndex*)             , Min[Join[{min + slidersPerRow - 1 + slidersPerRow*sliderRow}, If[lifeIsEasy1, max, {}]]]](*=endIndex*)               , {sliderRow, 0, If[lifeIsEasy2, Ceiling[(max - min + 1)/slidersPerRow] - 1, 1]}             ](*seqtab*)          ](*with*)         ](*evalwith*)       , Initialization :> (         If[Not[initialized === True], sliderVals = Table[0, {length}]];         initialized = True         )       , SaveDefinitions -> True       ](*manip*)      ](*with*)      Another approach I had for the problem was to use an inner Manipulate, but that didn't work either; I didn't get that even to the point where everything except persistence works, as in problem 1. **UPDATE** Although it is possible to do all this with Manipulate (see my 3 answers below), jVincent has convinced me that it is better and easier to do with DynamicModule instead. I want to show how to make reusable components with this method. Here is a slightly improved version of jVincent's solution.               makeInputGrid = Function[{mat},         Grid@Table[With[{x = x, y = y},             InputField[Dynamic[mat[[x, y]]], ImageSize -> 50]],             {x, 1, Dimensions[mat][[1]]},             {y, 1, Dimensions[mat][[2]]}],         HoldAll];     DynamicModule[{mymat = Table[0, {2}, {2}]},         Column[{             Slider[Dynamic[Dimensions[mymat][[1]], (mymat = Table[0, {#}, {#}]) &], {2, 8, 1}],             Dynamic@makeInputGrid[mymat],              Dynamic@MatrixForm@mymat,             Dynamic@Det@mymat         }]     ]      Now, the function makeInputGrid can be used elsewhere. Note the HoldAll attribute, it won't work without that. Here is how to do the slider problem with this approach. (I tried to make it look a little towards the way Manipulate makes things look.)               sliderGrid = Function[         {sliderValues, slidersPerRow, minVal, maxVal, which},         Panel@Grid[Partition[             Table[With[{index = which[[i]]},                 Row[{index, Spacer[7], Manipulator[Dynamic[sliderValues[[index]]], {minVal, maxVal}]}]             ], {i, Length[which]}],             slidersPerRow, slidersPerRow, 1, {}]],        HoldFirst     ];     checkboxRow = Function[{flags},         Panel@Row[Table[With[{i = i},            Row[{i, Spacer[5], Checkbox[Dynamic[flags[[i]]]], Spacer[7]}]         ], {i, Length[flags]}]],        HoldAll     ];     With[{len = 10, min = -1, max = 1},         DynamicModule[{             flags = Table[True, {len}],             vals = RandomReal[{min, max}, len]         },         Panel[Column[{             Panel@Column[{                 checkboxRow[flags],                 Dynamic@sliderGrid[vals, 3, min, max, Select[Range[10], flags[[#]]&]]             }],             Dynamic@Grid[{Range[len], vals}]         }],         Background -> GrayLevel[0.9]         ]     ]]      ![variable number of sliders using dynamicmodule](http://i.stack.imgur.com/tO2Uc.jpg)


title: Attaching functions to movable locators

text: I'm trying to create a manipulate plot showing the electric field due to a collection of point charges. At the moment I've created such a plot which allows the x and y positions of each charge to be manipulated using sliders, however what I would particularly like to do is to be able to click and drag the points on the plot. I have created locators which can be manipulated like so, however I can't work out how to attach a function to them. Any help would be greatly appreciated.


title: Logarithmic scale in BarChart3D

text: I want to display my data in a logarithmic way in a 3d diagram. I found BarChart3D, which seems to be nearly what i need. I tried:               BarChart3D[data2, ChartLayout -> "Grid"]     BarChart3D[(Log[10, data2] - 2)/5.0568, ChartLayout -> "Grid"]      and got this figures: ![non-logarithmic data](http://i.stack.imgur.com/7sC8B.png) ![logarithmic data \(wrong scale\)](http://i.stack.imgur.com/2j3ir.png) What I need now is a way to fix the horizontal scale. Would be glad to get some hints! THANKS A LOT! Andreas EDIT: Just found the very simple answer               ScalingFunctions -> "Log"      sorry for waste of bits.


title: Change the height of a function being plotted

text: How do I alter the height of any function plot using the `Plot` function? Mathematica seems to limit the height of the plot up to the range of a function and distort the ratio of the Plot ![](http://i.stack.imgur.com/UWYIZ.png) Here in the above example the plot has a distorted axes ratio. How do I correct it?


title: Forcing unifom axis scaling on a list plot

text: I'm trying to draw a `ListPlot` where the x and y axis have the same scale. My data is               {{100, 500}, {461/5, 473}, {548/5, 452}, {1459/10, 437}, {974/5, 428}, {250, 425},       {1526/5, 428}, {3541/10, 437}, {1952/5, 452}, {2039/5, 473}, {400, 500}}      A simple `ListPlot` will result in: ![Listplot no scale](http://i.stack.imgur.com/wMjwD.png) where the x and y axis have a different scales. I want them to force them to have the same scale. So far I've been able to achieve this only by explicitly setting `PlotRange` to the same value for x and y, and using `AspectRation->1`. Example:               range := {Min[Flatten[x]], Max[Flatten[x]]}     ListPlot[x, PlotRange -> {range, range}, AspectRatio -> 1]      The result is: ![List plot scaled](http://i.stack.imgur.com/9zevu.png) Questions:   * Is there a `Plot` option to force the scale to be uniform? Do I always have to set the same range and `AspectRatio` to 1?   * From the second image there is satisfying y ∈ [400, 500] and x < 100 with an x value that is lying outside of the drawing range. I thought by using the `Min` of all x and y this could not happen. What am I doing wrong?


title: How to plot an ellipse?

text: I'm new to _Mathematica_ , and I'm finding it difficult to plot an ellipse. I tried using               Plot[(x/5)^2 + (y/3)^2 == 1, {x, -5, 5}, {y, -3, 3}]      but I'm getting some errors. Is there something wrong with the syntax? Or do I need to rewrite the equation and plot?


title: Coloring a shape according to a function

text: I would like to create a $2D$ shape, say an ellipse, where each point in the ellipse is colored according a `RGB` function, so at point `x` and `y` the color would be:               RGBColor[ u[x,y], v[x,y], w[x,y]]      I am sure there has to be an easy way to do this, but I have not had much luck.


title: Plotting 2D color function on the plane

text: Suppose `p` is a some point in the plane. The function `f[q]` defined as               f[q_]:= Block[{d = Norm[p-q]}, RGBColor[1 - d/(1 + d), 0, d/(1 + d)]]      Continuously colors points in the plane by thier distance from `p`. What is the easiest way to plot this in 2D? I tried DensityPlot but that's not exactly what I'm looking for. Basically I want to specify some color function for points in the plane and plot it. Contours would be a bonus. Apologies if this exact question has been asked before.


title: how to plot and animate an hyperbole?

text: I am an new user of _Mathematica_ and learning basics so please guide me I tried to use this code               Animate[Plot[x^2/a^2 - y^2/b^2 == 1, {x, 0, 2}, {y, 0, 2}],        {a, 1, 3},        {b, 1, 3}]      but I got this error message: > Plot::nonopt: Options expected (instead of {y,0,2}) beyond position 3 in > Plot[x^2/FE`a$$116^2-y^2/FE`b$$116^2==1,{x,0,2},{y,0,2}]. An option must be > a rule or a list of rules. >> All I want to do is to animate a hyperbole with its asymptotes.


title: ?AspectRatio? setting to obtain equal length pr pixel on all axes

text: Like these does:               Show[Graphics[Rectangle[{2, 1}, {15, 2}]]]     ParametricPlot[{t,t t},{t,0,2}]      how do I create a `Plot[]` with axes having equal variable length pr. pixel? My first idea was               Show[ParametricPlot[{}, {t, 0, 1}], Plot[t, {t, 0, 1}]]      But that messes with the `PlotRange` and possibly more...


title: Plotting rainbow circle

text: I am trying to plot a parametric circle in rainbow colors. It should go round once, but I'd like to be able to make it go round the rainbow an arbitrary amount of times. I currently have:               ParametricPlot3D[{Sin[u] Sin[Theta], Cos[u] Sin[Theta],        Cos[Theta]} /. Theta -> Pi/6, {u, -Pi, Pi},        PlotStyle -> Directive[Thickness[.01]],        ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][(Arg[x + I y] + Pi)/(2 Pi)]]]      Which I think should choose a color from the `ColorData` named `Rainbow` (which changes only between 0 and 1 (the result of `Arg` lies between `-Pi` and `Pi`, so adding `Pi` and dividing the resulting interval by `2 Pi` will give me a number between 0 and 1) depending on the angle of the circle. I get an almost decent result if I divide by `Pi/2` instead of `2 Pi`: ![Nearly rainbow circle](http://i.stack.imgur.com/88y7i.png) But I have no idea why there is yellow and green twice. I'm certainly missing something, does anyone know what?


title: Plot a perfect looking circle using two functions, always look like an ellipse

text: I want to use the the following two functions to plot a perfect looking circle, but the graph always ends up looking a bit squashed. I've been playing with some of the parameters of the function but can't seem to get it to look right still. Here is the function:               Plot[{Sqrt[1 - x^2], -Sqrt[1 - x^2]}, {x, -2, 2}, PlotRange -> {-2, 2}]      Thanks for the help!


title: Indicating the axes

text: I want to scale the $x$ axis of the plot by $x^0$ and the $y$ axis by $\tan x$. Is this possible ?                Plot[Tan[x], {x, 0, 10}, PlotRange -> Automatic]      EDIT: Actually wanted to know that how to include the axes name like in the below picture mentioned by (x and y) and the curve whiched is defiend in the picture by $f(x)=x^2$? ![enter image description here](http://i.stack.imgur.com/qYMvu.gif)


title: Are plotting markers with inscribed letters possible?

text: I have large data consisting of values obtained by sweeping across three parameters (e, w, and f). I want to plot all this data on one graph using different shapes for e (e.g., circle, triangle, square, and diamond), different colors for w, and a letter inside the shape for f. So far I have               Jw1e1 = {{16, 832}, {32, 3150}, {64, 12237}, {128, 48212}};     J1 = ListLogPlot[Jw1e1, PlotMarkers -> (Style[Framed[H], Red]),        Frame -> True]     Jw1e3 = {{16, 826}, {32, 3127}, {64, 12145}, {128, 47851}};     J3 = ListLogPlot[Jw1e1, PlotMarkers -> (Style[Framed[H], Blue]),        Frame -> True]     Show[J1, J3]      I cannot figure out how have a square, circle, etc. appear as the specified shape by changing `Framed[H]`. If I replace `Framed[H]` by `Circle[]`, Circle[{0, 0}] appears on my plots and replacing by `Circle[H]`, `Circle[H]` appears.


title: Running a script Mathematica 9

text: I am working in a Linux machine.The name of my mathematica file is deres.nb Code:               a={};     AppendTo[a,1];     a>>"file"      Now, if I run this code, by simply evaluating the cell, there is no problem, I get the file saved in the directory I am working. But I want to run a script. Then I prepare my file by: 1.Cell -> Cell Properties-> Initialization Cell 2.I save the file with a .m extension(deres.m) 3.Format -> Style -> Code Now I run the script by writing in the terminal:   1. screen   2. math -script deres.m & Then I exit by writing "exit". The problem is that I do not get my file saved. This works perfectly for me in Mathematica 8. Any solution please? Thanks a bunch.


title: Partial differential equation with initial conditions

text: And so I want to solve the following equation, subject to these initial conditions: $\ u_{tt} - u_{xx} = 6u^5+(8+4a)u^3-(2+4a)u$ $\ u(0,x)=\tanh(x), u_t(0,x)=0$ When I use NDSolve to solve within the intervals $\ [0,10] \times [-5,5]$, I tried this as a code:               NDSolve[{D[u[t, x], t, t] - D[u[t, x], x, x] == 6 u[t, x]^5 + (8+4a) u[t, x]^3 - (2+4a) u[t, x], u[0, x] == Tanh[x], D[u[0, x], t] == 0}, u[t, x], {t, 0, 10}, {x, -5, 5}]      But Mathematica then returns the following line:               NDSolve::deqn: Equation or list of equations expected instead of True in the first argument      where the `True` affirmation seemingly refers to the second initial condition. What is it that I did wrong? Is there anything wrong with the code? Is there anything wrong with the problem?


title: How to read non-standard-format data into Mathematica from a file

text: I would like to read non-standard-format data into Mathematica from a file. How can this be achieved? For example, how can I read the following text file of data into Mathematica:               (8.675e-11+3.881e-11j) (7.775e-11+3.815e-11j) (0.675e-11+3.385e-11j)     (2.675e-11+3.889e-11j) (7.075e-11+3.835e-11j) (3.675e-11+3.815e-11j)     (0.675e-11+3.886e-11j) (7.975e-11+3.875e-11j) (7.675e-11+3.885e-11j)     (1.675e-11+3.828e-11j) (7.275e-11+3.185e-11j) (1.675e-11+3.805e-11j)      To explain, the first entry should be entered as the complex number $8.675 \times 10^{-11} + i (3.881 \times 10^{-11})$.


title: Nested NDSolves with functions

text: I am trying to solve a system of nested differential equations, and have attached my code below. The first section is some variable declarations, then I solve my first diffeq and store the solution to s. Then I make another function evaluated with that solution, and try to use it in another diffeq, but I get the error > "Computed derivatives do not have dimensionally consistent with the initial > conditions".               ClearAll["Global`*"];     falltime = 5*^-12;     Rd[t_] := 200000000000*E^(-t/falltime) + 1300;          Vc = 5; Va = -200; Rl = 220; Rs = 1000000; Ccs = 2*^-12; Cas = 2*^-12; Cac = 2*^-12;          eq1 = (Vc-V1[t])/Rl == (V1[t]-V2[t])/Rd[t] + Ccs*(V1'[t] - V2'[t]);     eq2 = Cac*(V1'[t]-V2'[t]) + (V1[t]-V2[t])/Rd[t] == (V2[t]-Va)/Rs + V2'[t];     eq3 = V2[0] == (Va*(Rd[0] + Rl) + Rs*Vc)/(Rd[0] + Rl + Rs);     eq4 = V1[0] == (Va*Rl + Vc (Rd[0] + Rs))/(Rd[0] + Rl + Rs);          s = NDSolve[{eq1, eq2, eq3, eq4}, {V1[t], V2[t]}, {t, 0, 100*^-9}];               IdRd[t_] := Evaluate[{(V1[t] - V2[t])/Rd[t]} /. s];  (* Current through Rd *)          qt = 10*^-9; \[Tau]q = .2*^-9; Lifetime1 = 50;          IdQuenched[t_] := IdRd[t]*(UnitStep[t] - (UnitStep[t - qt]*(1 - E^-((t - qt)/\[Tau]q))));          s1 = NDSolve[{n'[t] == (IdQuenched[t]/(1.602*^-19)) - (n[t]/(Lifetime1*1*^-9)),                    n[0] == 0.0000000000001},n[t], {t, 0, 1*^-6}]      I'm really not sure where to go from here and would appreciate any help.


title: C compilation not working with Visual Studio 2013

text: I'm running Mathematica 9 on a 64 bit Windows 8.1 laptop. I'm having no luck getting C compilation to work.               Needs["CCompilerDriver`"]          CCompilers[Full]     CCompilers[]       returns > >     {}   >     {} >   The package did load successfully, as `$Packages` shows `CCompilerDriver` entries and               $ContextPath//First      returns > >     "CCompilerDriver`" >   I have the following compilers installed:   * Microsoft Visual Studio Professional 2013   * Intel C++ Composer XE


title: Copy/paste of Interpretation to Latex fails, but works for InputText

text: As part of another issue, the following has come up. Create an `Interpretaion`:               Interpretation[Subscript[a, b], a[b]]      Select and copy the $a_b$ output from the notebook. If you paste it into a text file, you get: `a[b]`, which is correct as the `Inputform`, and what we want. However, if you select it and choose Copy as Latex, you get: `\text{$\$$CellContext$\grave{ }$a}(\text{$\$$CellContext$\grave{ }$b})` in a text file. I would like to be able to copy this and get the latex as $a_b$, or $a[b]$ as a worst case. Are there any tricks that could help here? (I don't think this has anything to do with subscripts)


title: Finding a certain invariant polynomial using matrix coordinates

text: Here's a math problem that I would like to solve. This is also my first time posting on the Mathematica stackexchange website so please excuse me if this looks messy. Let               a = {{a11, a12, a13}, {0, a22, a23}, {0, 0, a33}};     b = {{b11, b12, b13}, {0, b22, b23}, {0, 0, b33}};     c = {{c11, c12, c13}, {0, c22, c23}, {0, 0, c33}};     d = {{d11, d12, d13}, {0, d22, d23}, {0, 0, d33}};     r = {{r11, r12, r13}, {0, r22, r23}, {0, 0, r33}};     s = {{s11, s12, s13}, {0, s22, s23}, {0, 0, s33}};     u = {{1, u12, u13}, {0, 1, u23}, {0, 0, 1}};       Consider               MatrixForm[Expand[u.a.Inverse[u]]]     MatrixForm[Expand[u.b.Inverse[u]]]     MatrixForm[Expand[u.c.Inverse[u]]]     MatrixForm[Expand[u.d.Inverse[u]]]     MatrixForm[Expand[u.r.Inverse[u]]]     MatrixForm[Expand[u.s.Inverse[u]]]      I would like to find an invariant polynomial in the entries of $a,b,c,d,r$, and/or $s$ such that at least one of its monomials is divisible by the $(1,3)$-entry of $a,b,c,d,r$ and/or $s$. For example, consider the polynomial $(a11-a22)c12-(c11-c22)a12$. Then under the u-action, this polynomial becomes $(a11-a22)(c12 + (c22 - c11) u12) - (c11-c22)(a12 + (a22 - a11) u12)$, which simplifies to $(a11-a22)c12-(c11-c22)a12. So (a11-a22)c12-(c11-c22)a12$ is a polynomial in the entries of $a$ and $c$ such that at least one of its monomials is divisible by the $(1,2)$-entry of $a$ or $c$. By the way, I tried:               Simplify[(c11 - c33) (a13) - (a11 - a33) (c13) + c12 a23 - a12 c23 ]       by guessing and checking (which is not an invariant polynomial) but is there a systematic way to use mathematica to help me find such polynomials?


title: With/Function(/etc) replacement behaviour

text: Can anyone explain to me this behaviour? I've been having more than a couple of similar doubts these last weeks. For example               f[_?NumericQ] := 8;      Now, if I do               With[{a = f[a]}, HoldForm@Block[{NumericQ = True &}, a]]      I get               Block[{NumericQ = True &}, f[a]]      And if I do               Block[{NumericQ = True &}, f[a]]      I get               8      So far so good... Another so-far-so-goodie is (notice the `:=`)               With[{a := f[a]}, Block[{NumericQ = True &}, a]]          8      Question: Can anyone help me understand why this output?               With[{a = f[a]}, Block[{NumericQ = True &}, a]]          f[a]      Could it be that `With` (`=` version) not only evaluates and replaces, but also guarantees that the replaced expression won't be reevaluated no matter what until the `With` is exited? If that's the case I wasn't expecting that. What's happening here? **EDIT** Question also applies to Function               Block[{NumericQ = True &}, #] &[f[a]]          f[a]      And not just those too. Everything I try behaves the same way... A couple of other examples               Block @@ (Hold[{NumericQ = True &}, exp] /. exp -> f[a])          With[{a := Evaluate@f[a]}, Block[{NumericQ = True &}, a]]      both give `f[a]` **EDIT**               With[{g = h}, h = 8; Print[g] ]      prints 8, not h, so clearly h is reevaluated inside the `With` in this case, so `g` is not so constant. **EDIT** Ok, another couple of examples               In[10]:= ClearAll[h, f];     h := 8 /; NumericQ["a"];     f[_?NumericQ] := 8;      Now, both `h` and `f[a]` remain unevaluated               In[21]:= {h, f[a]}          Out[21]= {h, f[a]}      Now, with the `OwnValues` everything works as expected               In[17]:= With[{g = h},      Block[{NumericQ = True &}, g]]          Out[17]= 8      But with the `DownValues`, it doesn't               In[19]:= With[{g = f[a]},      Block[{NumericQ = True &}, g]]          Out[19]= f[a]      Similarly               f[a_?NumericQ] := 8;     g[e_] := Block[{NumericQ = True &}, e]      `f[a]` evaluates to `f[a]`, but weirdly               In[17]:= g[Unevaluated@f[a]]          Out[17]= 8          In[18]:= g[f[a]]          Out[18]= f[a]


title: Epilog->Text placement on LogLogPlot

text: Hopefully this is a simple question. I'm trying to overlay some text on top of a `LogLogPlot` using `Epilog` and `Text`. However, I'm struggling with the coordinates that `Text` seems to be using for placement. For example:               LogLogPlot[x + Sin[2x], {x, 1, 1000},       Epilog -> Style[Text["x+sin(2x)", {5, 5}], 14]]      places the label "x+sin(x)" at roughly {x,y}={150,150} on the plot's coordinate system, and not {5,5} as in the input. However, if I change the LogLogPlot to just Plot, the label will get placed at {5,5} (or wherever I specify). What's going on? How it looks right now: ![graph](http://i.stack.imgur.com/7FP4e.png)


title: How to use MathPSfrag package in Mathematica 10?

text: I am interested to use LaTeX like labels in the plots that I prepare in Mathematica, and hence, I downloaded the MathPSfrag package from this website http://wwwth.mpp.mpg.de/members/jgrosse/mathpsfrag/ . Since I cannot attach any file here, I request anyone who is interested to help me, to download the package and run the MathPsfrag-Test.nb notebook. I apologize if the manner in which I am asking the question violates any code of conduct, but since I am new to this group, and because there are multiple files involved with long codes, I am not entirely sure about how else to ask. This package has been tested only up to version 6, and I am using Mathematica 10 on Windows 7 machine. Unfortunately the package does not work, and I tried finding the problem and any solution to it myself, but without much success. Here is a summary of what I have found. After unzipping the contents on the package, I followed the instructions and tried running the MathPSfrag-Test.nb notebook line by line. First and foremost I realized that the Windows 7 has a space in their folder names like Program Files, where all programs are installed, and hence, I gave the absolute path to the GhostScript executable, after which the `MathPSfragConfigurationTest[]` was successful. After that I started executing the notebook step-by-step, and got stuck at the command:               CreatePSfragRules[HandleAutomaticPSfrag[exampleplot]][[1]]      I tried investigating a bit into MathPSfrag.m file, and found the following:   1. The Utilities`FilterOptions` is replaced by `FilterRules` in version 10. Hence, I replaced all the commands with `FilterOptions` functions with the `FilterRules` function, but with the right syntax.    2. Despite the above step, I get an error saying that `FilterRules` function needs two arguments. So I checked the `HandleAutomaticPSfrag` function defined in the package file, which is defined as `HandleAutomaticPSfrag[gr_Graphics,opts___Rule]:= ...` and realized that there is a `opts___` argument that denotes a `BlankNullSequence`. The `FilterRules` as an example is used within this function as as               FilterRules[opts, Options @ HandleAutomaticPSfrag]      By using the `HandleAutomaticPSfrag[exampleplot]` command in the Test notebook, there seem to be no opts provided as a second argument, and this is where I think the `FilterRules` gets stuck. However, if my explanation of the `opts___` above is correct, then I do not understand how the old versions of _Mathematica_ were able to run the package. This makes me feel that I am missing something obvious. Could someone please help me changing the package so that I can also use it with version 10? Thanks!


title: Non-linear curve fitting with multiple parameters and conditional expression

text: ![Bloch-Gruneissen formula](http://i.stack.imgur.com/0xWbt.gif) The above integral(Bloch Gruneissen formula) is what i like to fit with my experimental data.I am new to Mathematica. To cross-check the fit results obtained in other software, I try to fit with my experimental data(Resistivity Vs Temperature) using this software. I make the integral analytical and then i get a conditional expression at the end..Following the steps as   1. mydata = ReadList["Sheet1.dat", Number, RecordLists -> True];               mydata={{50.3838, 0.241641}, {50.886, 0.242787}, {51.3245,      0.243584}, {51.8868, 0.244274}, {52.2609, 0.244107}, {52.6343,      0.245124}, {53.0692, 0.246065}, {53.5032, 0.246445}, {53.9364,      0.247621}, {54.3688, 0.248046}, {54.8004, 0.248783}, {55.2927,      0.250672}, {55.7226, 0.250763}, {56.2743, 0.252342}, {56.6414,      0.25238}, {57.069, 0.253314}, {57.5569, 0.25537}, {57.9831,      0.255082}, {58.4087, 0.256258}, {58.8943, 0.2577}, {59.3185,      0.25852}, {59.8026, 0.259537}, {60.2859, 0.26019}, {60.6479,      0.26129}, {61.0698, 0.261632}, {61.5512, 0.263006}, {61.972,      0.263711}, {62.5122, 0.264979}, {62.9319, 0.266193}, {63.411,      0.266641}, {63.8895, 0.267749}, {64.3675, 0.269039}, {64.8449,      0.269191}, {65.2623, 0.270026}, {65.7389, 0.271741}, {66.215,      0.272462}, {66.6311, 0.272994}, {67.0469, 0.274345}, {67.5216,      0.275073}, {68.0551, 0.276204}, {68.5287, 0.278656}, {69.0018,      0.278633}, {69.4153, 0.279194}, {69.9463, 0.280652}, {70.3589,      0.282094}, {70.8298, 0.283566}, {74.2852, 0.290996}, {74.8094,      0.292765}, {75.3909, 0.293334}, {75.9134, 0.294814}, {76.3192,      0.295664}, {76.7824, 0.297675}, {77.2449, 0.297858}, {77.7645,      0.2998}, {78.168, 0.30081}, {78.6285, 0.301432}, {79.0308,      0.302366}, {79.49, 0.304195}, {80.063, 0.304802}, {80.4062,      0.305925}, {80.9204, 0.307709}, {81.3196, 0.309075}, {81.8322,      0.310024}, {82.2302, 0.311481}, {82.798, 0.313166}, {83.1948,      0.314054}, {83.7042, 0.314616}, {84.1563, 0.316528}, {84.6077,      0.31709}, {85.0585, 0.318668}, {85.5649, 0.320665}, {86.0143,      0.321727}, {86.4631, 0.32307}, {86.9113, 0.32364}, {87.4148,      0.325545}, {87.9175, 0.327214}, {88.3637, 0.328072}, {88.865,      0.32918}, {89.2543, 0.330895}, {89.8098, 0.331563}, {90.1981,      0.332838}, {90.6413, 0.334113}, {91.084, 0.335449}, {91.6365,      0.336975}, {92.078, 0.338379}, {92.5188, 0.339601}, {92.9592,      0.340094}, {93.454, 0.34272}, {93.9481, 0.343244}, {94.3319,      0.344898}, {94.8796, 0.346136}, {95.4265, 0.347236}, {95.9181,      0.349156}, {96.3545, 0.34968}, {96.7904, 0.351076}, {97.2803,      0.352784}, {97.7695, 0.353778}, {98.1495, 0.355334}, {98.746,      0.356799}, {99.1793, 0.358082}, {99.612, 0.358826}, {100.098,      0.360404}, {100.53, 0.361558}}      2.Then making the integral analytical(B,C and Capital Theta are my desired parameters to be evaluated).... ![enter image description here](http://i.stack.imgur.com/PJ6st.png) 3.I will be happy if you can tell me where I go wrong and give me advice on this fitting![enter image description here](http://i.stack.imgur.com/pHP8G.png)


title: Making two lists which share part of its name, while its name is also an element of the list

text: I am stalled with the following problem: I want two lists, for example:               name={1,2,3}      and               namec={{1,2,3},{x,y,z},name}      The list "namec" is a list with extra information for internal use in a (non- comercial) package, while the List "name" is a vector shown to the user. The "name" inside the list has               Head[name]=String      I tried the following piece of code:                g = {1, 2, 3};      c = {x, y, z};      (ToExpression["Set[" <> # <> "c" <> ", {g,c," <> # <> "}]"];       ToExpression["Set[" <> # <> ", g]"]) &["name"];      the problem is that with the second assignment, the full list "name" replace the string "name" in the list "namec" (I know it could be a little confusing, this is counterintuitive to me). With the code above I get:                name={1,2,3}      and                namec={{1,2,3},{x,y,z},{1,2,3}}      Without the second assignment in the piece of code shown above, I get the list "namec" I want, however, the problem appears when I added the second assignment (name=g). Actually "name" is obtained interactively with an Input, but I simplified the code here. How can I solve this problem?, I suspect that I must use the Hold attribute but what I tried didn't work. Can somebody help me ? Just for reference the real piece of code is:               With[{symbol = Input["enter a new name"]},     nom = ToString[symbol];     ToExpression[     "Set[" <> ToString[symbol] <> "c" <> ", {g,c," <>      ToString[symbol] <> "}]"];     ToExpression["Set[" <> ToString[symbol] <> ", g]"];       (* finally I get the solution based on a suggestion of george2079 (I only modified the last line of his solution) :*)               In[68]:= name = InputString["enter symbol name"]     ToExpression[name <> "={1,2,3}"]     ToExpression[name <> "c" <> "={{1,2,3},{x,y,z},name}"]          Out[68]= "ju"          Out[69]= {1, 2, 3}          Out[70]= {{1, 2, 3}, {x, y, z}, "ju"}          In[71]:= ju          Out[71]= {1, 2, 3}          In[72]:= juc          Out[72]= {{1, 2, 3}, {x, y, z}, "ju"}


title: BarChart include multiple fields on x-axis

text: I want to chart data using a BarChart, the labels on the x-axis should consist of three values, however I can only use one of the values (the street name), where I would like to include the city and country name. The relevant piece of code:               rEntities = {{1261, "C/O C T Corporation System", "Boston",      "UNITED STATES"}, {1017, "C/O National Registered Agents, Inc.",      "New York", "UNITED STATES"}, {1004, "49, Avenue J.F. Kennedy",      "Luxembourg", "LUXEMBOURG"}, {799,      "C/O National Corporate Research, Ltd.", "Dover",      "UNITED STATES"}, {793, "C/O CT Corporation System", "Boston",      "UNITED STATES"}}          BarChart[#, ChartStyle -> "DarkRainbow",      PlotLabel -> Framed[Text[Grid[{         {Style["Entities with same address", Blue, FontSize -> 18]},         {Style["Address's with 200 to 6999 entities", Red,            FontSize -> 12]}}]]],      ChartLabels -> (Placed[       Rotate[Style[#, Black], Pi/3] & /@ #2, {{.7, 0}, {1, 1}}])] & @@     Transpose[rEntities]      ![only 1 field on x-axis](http://i.stack.imgur.com/omzTP.jpg) What I would like to see would be the city and country as well. For example: "C/O C T Corporation System, Boston, UNITED STATES" under the blue bar. "49, Avenue J.F. Kennedy, Luxembourg, LUXEMBOURG" under the olive bar, etc. Thank you in advance!


title: Most Efficient Way to Calculate the Product of All Items in a List?

text: Say that I have a list of returns on a financial asset over time and want to know the total compounded return. To get the answer, I need to add 1 to each return and then calculate the product of all of them. So, I'm looking for a function like `Total`, except that it computes the product. The `Product` function works, but seems clumsy and slower than my alternatives (at first, I was having trouble getting `Product` to work, so I wrote a few of my own functions). Here are the alternatives:               listProduct[x_List] := Exp[Total[Log[x]]];     listProduct2[x_List] := Last[FoldList[Times, 1, x]];     listProduct3[x_List] := Fold[Times, 1, x];     listProduct4[x_List] := Product[x[[i]], {i, 1, Length[x]}];      Those are in the order that I thought of them. A couple of surprising things: The first seems to be the fastest by quite a lot (though none are super slow). The slowest is the last one using `Product`, which I thought would be highly optimized and fast. Here are my tests:               s = RandomVariate[NormalDistribution[0.05, 0.1], 10^6];     listProduct[1 + s] - 1; // AbsoluteTiming     listProduct2[1 + s] - 1; // AbsoluteTiming     listProduct3[1 + s] - 1; // AbsoluteTiming     listProduct4[1 + s] - 1; // AbsoluteTiming      which produces these results:               {0.0312000, Null} {1.4820026, Null} {1.4040025, Null} {1.8252032, Null}      So, the question is: Is there a faster way, and am I missing some built-in function that would do this better? I won't be using lists this long, but I may be doing a lot of lists if I can get the rest of my idea implemented.


title: Showing the terms in a partial sum?

text: I am trying to get                  s[n_]:=Sum[1/2^k,{k,1,n}]      to show me the actual terms involved in the $n$th partial sum and not just the sum itself. I've tried `Expand`, `Apart`, etc. to no avail. Ideas? Edit based on early comments: Is it necessary to use `Table` to accomplish this rather than some algebraic command applied to `s[n]` or some option of `Sum`?


title: Derivative of the composition of two functions

text: Background, this seems to work (This is manually transcribed from the program, beware of errors):               J1[f_, i_] := DifferenceDelta[f[i], i]^2     D[J1[f + t v, i], t]      > >     2 (-v[i] + v[i+1]) (-(f + t v)[i] + (f + t v)[i+1]) >   What I would like to do is replace the `()^2` with a generic function `JJ`, and later specify               JJ[x_] := ...      Here's what happens with the generic `JJ`:               J2[f_, i_] := JJ[DifferenceDelta[f[i], i]]     D[J2[f + t v, i],t]      > >     0 >   Why can't it return a derivative expression in terms of a generic derivative `JJ'`, and how could I modify my code to make it work?


title: Make contour lines level with graph interval?

text: I am graphing the voltage traveling through some water with two electrodes. I have the graph with contour lines and all, but is there any way that I can get the contour lines to be at the tick marks along the Z axis? So, if every tick mark is 1volt, can I have contour lines at every integer voltage?![enter image description here](http://i.stack.imgur.com/EhhJ8.png)


title: Can I apply a ColorFunction to FaceGrids, or otherwise have FaceGrids with varying color?

text: I want to make a 3d plot with `FaceGrids` with a certain color scheme. Specifically, I'd like them to be one color below a diagonal line, and a different color above it. (So for example, on the `y=0` surface, I'd like the `FaceGrids` to be pink below `x=z`, and blue above `x=z`.) If I were coloring the plot itself, I'd define a `ColorFunction`, but it seems that `FaceGrids` doesn't take `ColorFunction` as an option. Here's an example of my best attempt:               Graphics3D[Cylinder[],       FaceGrids -> {{{0, -1,           0}, {{{-1/2, ColorFunction -> Function[{x, y, z}, Hue[z]]}, {0,             Green}, {1/2, Blue}}, {-1/3, {1/3,             Directive[Thick, Dashed]}}}}}]      Note that while the other gridlines have the properties assigned, the one with a `ColorFunction` is just gray. Is there any way to have varying colors on `FaceGrids`?


title: WholeCellGroupOpener and Hyperlinks

text: My problem is: I would like to activate WholeCellGroupOpener on a cell containing hyperlinks. But when I do that, the hyperlinks are no longer active. Is there a way to change the order of the two, so that 'Hyperlink' is activated before 'WholeCellGroupOpener'. More precisely: I want the cell group to collapse when I click anything but a hyperlink. Does anyone know a way to achieve that?


title: 3D Plot of .txt File of the Surface Plotting Variety

text: I'm having a bit of trouble. I've seen other questions answered on here about how to 3D plot data from .txt files of the format:               x y z          x y z          x y z      Which works well with the `ListPointPlot` function. However, using that methodology seems to confuse poor _Mathematica_ when trying to do surface plotting of data that is in the format               ` y y y y y y y y y y y y y y          z x x x x x x x x x x x x x x          z x x x x x x x x x x x x x x          z x x x x x x x x x x x x x x       Where the ` is a place holder (just an empty space in my case). I've tried the manipulations that I know of or could find around the web, but those attempts end with errors being kicked back at me. How would I get _Mathematica_ to plot this .txt data?


title: complicated color function and color bar legend (summary of the results from previous relevant posts)

text: At first let me apologize. I should have read the policies of this forum before attempting a post. I was more accustomed to a moderated forum like MathGroup than such an active one like the StackExchange. Let me also thank from this position the following people that answering in my previous questions. **Szabolcs kguler eldo Chenminqi** I really hope that I did not forget anyone! So in order to say a thank to these people and summarize for future reference the results I made the current post. The codes are based to replies I recieved. I wish that this will make up for any incovenience I caused:-)! Let me state the problem now. I have the following list of parametric equations (of an ellipsoid)               lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};      I also have the following functions of (u,v)               dam = 3*Sqrt[2]*Sqrt[(Cos[u]^2*(409 - 391*Cos[2*u] + 1800*Cot[v]^2))/(109 -              91*Cos[2*u] + 450*Cot[v]^2)^2];       I want a parametric plot of `lst` according to the values of `dam`. I found the maximum value that `dam` can take.               Cases[Flatten[Table[{u, v, N[dam]}, {u, 0, 2*Pi, Pi/10}, {v, 0, Pi,          Pi/10}], 1], {a_, b_, c_ /; c > 1}]          FindMaximum[dam, {{u, Pi/10}, {v, Pi/2}}, WorkingPrecision -> 30]     maxDam = %[[1]]      Next, I define the color function               colFun = Function[{u, v},         Evaluate@Hue[Rescale[FullSimplify@dam, {0, maxDam}]]];      And now the plots.               g1 = ParametricPlot3D[lst, {u, 0, 2 π}, {v, 0, π}, Mesh -> False,        ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,        PlotPoints -> 100, ImageSize -> 800, ViewPoint -> {2, 2, 1}];          g2 = Plot3D[dam, {u, 0, 2 Pi}, {v, 0, Pi}, Mesh -> False,        ColorFunction -> colFun, ColorFunctionScaling -> False,        PlotRange -> All, PlotPoints -> 100, ImageSize -> 400];          Row[{Show[g1, ImageSize -> Large], Show[g2, ImageSize -> Medium]}]      At this point I have one question. See the extremities of the ellipsoid. There, after the purple color, comes the red and again (it seems to me) purple. Can anyone figure out what is going on? Now, regarding the color bar.               {min, max} = {0, maxDam};     ParametricPlot3D[lst, {u, 0, 2 π}, {v, 0, π}, Mesh -> False,       ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,       PlotPoints -> 100, ImageSize -> 800,       PlotLegends ->        BarLegend[{Hue, {min, max}}, ColorFunctionScaling -> True]]      I want now to see a different color scheme. I tried               coldata = ColorData["Gradients"];          col = Table[{i, coldata[[i]], ColorData[coldata[[i]]]}, {i, 51}];          Table[{min, max} = {0, maxDam};      lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};      colFun =        Function[{u, v}, Evaluate@col[[i, 3]][Rescale[dam, {0, maxDam}]]];      ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False,        ColorFunction -> (colFun[#4, #5] &), ColorFunctionScaling -> False,        ImageSize -> 800,        PlotLegends -> BarLegend[{col[[i, 3]], {min, max}}]], {i, 51}]      Still, not satisfying with the coloring I tried the following function which I found here http://stackoverflow.com/questions/5753508/custom-colorfunction-colordata-in- arrayplot-and-similar-functions               jet[u_?NumericQ] :=       Blend[{{0, RGBColor[0, 0, 9/16]}, {1/9, Blue}, {23/63, Cyan}, {13/21,           Yellow}, {47/63, Orange}, {55/63, Red}, {1,           RGBColor[1/2, 0, 0]}}, u] /; 0 <= u <= maxDam          {min, max} = {0, maxDam};     lst = {10*Cos[u]*Sin[v], 3*Sin[u]*Sin[v], 2*Cos[v]};     colFun = Function[{u, v}, Evaluate@jet[Rescale[dam, {0, maxDam}]]];     h = ParametricPlot3D[lst, {u, 0, 2*Pi}, {v, 0, Pi}, Mesh -> False,        ColorFunction -> (colFun[#4, #5] &), PlotPoints -> 100,        ColorFunctionScaling -> False, ImageSize -> 800,        PlotLegends -> BarLegend[{jet[#] &, {min, max}}]]      Now, the coloring scheme is great. But again it appears to exist the above mentioned problem with the extremities color rendering. Last but not least, is it possible to make a function like `jet` above according to combination of colors {green, yellow, orange, blue, red}? Dimitris


title: direct assignment to the element in a Table

text: I have already asked a related question here why set values in this way doesn't work? But I think I have to write the question which I encountered explicitly?               tmp = {1, 2, 3, 4, 5}     label[i_, p_] := i + p     test[p_] := Table[tmp[[label[i, p]]], {i, 1, 2}]      Here I defined a function `test` and the thing I want to is that change the values of list `tmp` via setting values to function `test`. While simply write               test[1]={111,222}      and expecting `tmp` will change to {1,111,222,3,4,5} is not possible. So how to achive this? I have tried many `Hold` things, but failed. Inspired by **andre**. I know that `Set` has attribute `HoldFirst`. So I tried `Evaluate`                Evaluate[test[1]]={111,222}      this won't work! I guess the problem is that I must properly Hold `label[i,p]` and `tmp[[]]` in the table. But I can't work it out. Anyone help?


title: Benefits of using Intellij IDEA as Mathematica IDE?

text: I use Intellij IDEA for Java programming, but have not really considered it for Mathematica. I saw a video with a Wolfram programmer who was describing it as "essential" for him, but from what I could gather of what he said, most of the benefits for him were either workgroup related (sharing code with other Wolfram programmers) or were doing things involving "internal" Mathematica code, not notebook code/problem solving. So, for a person doing normal Mathematica calculations and models in the science world, what, if any, are the significant benefits to using Intellij IDEA?


title: How can I get Mathematica to simplify my square root expression?

text: $$\sqrt{r^2 e^{4 \gamma (r)-4 \psi (r)}}$$ If I set               var = r^2*E^(4 \[Gamma][r] - 4 \[Psi][r])          Simplify[Sqrt[var], var > 0]      I just get $$\left| r\right| \sqrt{e^{4 \gamma (r)-4 \psi (r)}}$$ How to tell Mathematica to perform the full square root calculation? $$r e^{2 \gamma (r)-2 \psi (r)}$$


title: How to output a bat file and execute it?

text: I tried to write a bat file which helped me rename files. Command to do this in that file is "ren file1 file2" which is equivalent to RenameFile[file1,file2].               renameFiles[directory_, files_, rename_] :=      Module[{list, i = 1, newfiles},       SetDirectory[directory];       newfiles = ("ren " <> #) & /@ FileNames[files];       list = Table[         " " <> rename <> ToString[i] <> ".png", {i, 1, Length[newfiles]}];       While[i <= Length[newfiles],         newfiles[[i]] = newfiles[[i]] <> list[[i]]; i++];       Return[newfiles]       ]     a = renameFiles["E:\\Download Pictures", ___, "save"]     Export["E:\\Download Pictures\rename.txt", a]      The renameFiles[] has three arguments which take the path, files in that path and name I want to change to respectively, and then convert them into a list "ren file1 file2". Afterwards, I output it as a txt file. I tried to output it as a bat file, however it displays error after I do: `Export["E:\\Download Pictures\rename.bat", a]` Therefore, I attempt to do that in a different way, which renames "rename.txt" afterwards by doing: `RenameFiles["E:\\Download Pictures\rename.txt","E:\\Download Pictures\rename.bat"]` So, now, I have my "rename.bat" file. I try to use `SystemOpen["E:\\Download Pictures\rename.bat"]` to execute it. However, it cannot work well, and I have to do it by clicking the file. My questions are: 1. Sometimes I get the syntax: `OpenWrite::noopen: "Cannot open \!\(\"E:\\\\Download Pictures\\\\nename.txt\"\). "` , how can I fix this? 2\. Is this the only way I can output a bat file. 3\. and, how can I execute via MMA. Thanks a lot!


title: Using FunctionExpand to evaluate symbolic derivatives

text: Some symbolic derivatives of certain special function are not expanded automatically, but `FunctionExpand` often helps to get a derivative-free closed form expression.               Derivative[1, 0][BesselJ][0, 1]     (* Derivative[1, 0][BesselJ][0, 1] *)          FunctionExpand[%]     (* 1/2 π BesselY[0, x] *)      But for some functions it takes too much time to evaluate. Possibly, there is even an infinite loop. For example, I left the following expression to evaluate overnight, and it was still running in the morning without any result or messages.               FunctionExpand[Derivative[1, 0][StruveL][0, 1]]      * * *   * Is there a workaround that could get an expanded form the expression `Derivative[1, 0][StruveL][0, 1]` in reasonable time?   * Is there an infinite-loop bug in the implementation of `FunctionExpand` or I just have to wait longer for the results (weeks, months, ...)?   * Are there any public information about what approaches are used by `FunctionExpand` to expand derivatives?


title: problem solving coupled second order differential equations using Dsolve

text: I have three coupled second order ODE's given as below      $x''[t] = -c_1*y'[t]-c_2*z[t]-c_3$   $y''[t] = -c_4*x'[t]$   $z''[t] = \frac{c_5}{c_6}*x[t]-c_6$   where $c_i$'s are know constants. The boundary conditions are      $x[-1]=x[1]=y[-1]=y[1]=z'[-1]=z'[1]=0$. I followed the example given here How do I solve coupled ordinary differential equations?               {x, y, z} = {x, y, z} /.              Dsolve[{x''[t] == -c1*y'[t] - c2*z[t] - c3, y''[t] == -c4*x'[t],                z''[t] == -c5 + c5*x[t]/c6, x[-1] == 0, x[1] == 0, y[-1] == 0,                y[1] == 0, z'[-1] == 0, z'[1] == 0}, {x, y, z}, t] //             FullySimplify // First      I get the following output      > >     ReplaceAll::reps: {Dsolve[{x''[t] == -c3 - c2 z[t] - c1 y'[t], <<8>>}, > {x, y, z}, t]} >      is neither a list of replacement rules nor a valid dispatch table, and >      so cannot be used for replacing. >   >     Set::shape: Lists {x, y, z} and {x, y, z} /. Dsolve[{x''[t] == >     -c3 - c2 z[t] - c1 y'[t], <<8>>}, {x, y, z}, t] are not the same shape. >   > > Could someone please tell me what is wrong with my approach and please > suggest me how to solve this system.   >  Thank you for your time


title: Why do identifiers of the form ${\tt c}k\$nnn$ appear in the rules returned by my function?

text: I want to define a function, `PolynomialInterpolation` to find the coefficients of a polynomial interpolation function. My trial is as shown below:               PolynomialInterpolation[tb_, tf_, θb_, θf_, θbDot1_, θfDot1_, θbDot2_, θfDot2_] :=        Module[         {InterpolationResult, u, θ, θDot1, θDot2, c0, c1, c2, c3, c4, c5, PolynomialParameter},         θ[t_] := c0 + c1 t + c2 t^2 + c3 t^3 + c4 t^4 + c5 t^5;         θDot1[t_] := D[θ[u], u] /. u -> t;         θDot2[t_] := D[θ[u], {u, 2}] /. u -> t;         PolynomialParameter =            Solve[{             θ[tb] == θb,              θ[tf] == θf,              θDot1[tb] == θbDot1,              θDot1[tf] == θfDot1,             θDot2[tb] == θbDot2,              θDot2[tf] == θfDot2             },             {c0, c1, c2, c3, c4, c5}]       ]      However, when I use my function `PolynomialInterpolatio`, it returns:               PolynomialInterpolation[0, 5, 30, 75, 0, 0, 5, - 5]      > >     {{c0$698 -> 30, c1$698 -> 0, c2$698 -> 5/2, c3$698 -> 8/5, >       c4$698 -> -(29/50), c5$698 -> 29/625}} >   So my question is why does the result contain variables with `$` in their names?


title: Making Mathematica graphics exported as PDF "usable" performance wise

text: > **Possible Duplicate:**   >  Exporting graphics to PDF - huge file   >  Saner alternative to ContourPlot fill   >  How can all those tiny polygons generated by RegionPlot be joined into a > single FilledCurve? When exporting a 3D plot to PDF my viewer takes quite long to render the PDF, which especially makes for a very bad scrolling experience. I've also tried exporting as EPS, but that seems to be much worse, especially when trying to load the generated files in Illustrator (a simple graph took a minute to load and Illustrator needed 5Gb of memory for it...). I don't really want to include the graphics as rasterized images in my thesis :(


title: How to reduce the memory necessary for the image?

text: > **Possible Duplicate:**   >  Exporting graphics to PDF - huge file I have a figure that is created to use in a paper. Here it is:               h = 5.8;     a = 0.6;          pl3 = Plot3D[       If[x >= 2,           0.5*(-Tanh[2*(Sqrt[x^2 + y^2] - 5*(1 + x/Sqrt[x^2 + y^2 + 0.01]))] + 1),              0.5*(Tanh[If[y >= 0, a*x + h - y, y + a*x + h]] + 1)], {x, -15,              12},      {y, -10, 10}, PlotRange -> All, Ticks -> None,      PlotPoints -> 30,      AxesLabel -> {Style["x-Vt", 18, Italic, "TimesNewRoman"],      Style["y", 18, Italic, "TimesNewRoman"],      Style["\[Eta]", 18, Italic]},      ColorFunction -> Function[{x, y, z}, Hue[.65 (1 - z)]],      BoxRatios -> {1.7, 0.7, 0.4}, ViewPoint -> {1.81`, -3.52`, 1.642`}];     plX = Graphics3D[{Red, Thick,              Line[{Scaled[{0.868, 0.256, 0.5}], Scaled[{0.956, 0, 0.5}]}]}];     plY = Graphics3D[{Red, Thick,              Line[{Scaled[{0.865`, 0.269`, 0.5}],                Scaled[{0.972`, 0.494`, 0.5}]}]}];     txtX = Graphics3D[            Text[Style["x'", 24, Italic, Red, Bold], Scaled[{0.989`, 0, 0.5}]]];     txtY = Graphics3D[            Text[Style["y'", 24, Italic, Red, Bold],              Scaled[{0.979`, 0.633`, 0.5}]]];          fig1A = Show[{pl3, plX, plY, txtX, txtY}, ImageSize -> 350]      However, if I directly save the notebook containing this picture into the pdf format it appears to occupy too much memory. On the other hand, if I export the picture itself into say, jpg ot tiff or gif formats, the file size is OK. However, if I then import the obtained jpg, tiff or gif files into the notebook it appears that the image has dramatically lost its quality becoming unacceptable for the publication. One problem of this image is that it contains both the "useful" surface part that is on the front view and the one behind. The latter is useless, but is contained in the image file. Is there a way to decrease the memory used by such an image?


title: Place graph vertex labels in circles

text: Consider the following code:               vsh[{xc_, yc_}, name_, {w_, h_}] := {LightYellow,         Rectangle[{xc - w, yc - h}, {xc + w, yc + h}],         Inset[Style[Text[name], 14, Black, Bold], {xc, yc}]};     options =        Sequence[VertexSize -> 0.1, VertexShapeFunction -> vsh,         GraphLayout -> "CircularEmbedding", ImageSize -> 350,         EdgeStyle -> Blue];          g1 = Graph[{1 -> 2, 1 -> 3, 2 -> 4, 3 -> 4}, options];     g1      The output will be a simple graph with vertex labels depicted in rectangles (as can be inferred from `vsh`): ![Mathematica output](http://i.stack.imgur.com/TqTkf.png) My question is: how can I encapsulate the vertex labels in circles instead? Nothing I've tried seems to be working.


title: Checking from a preemptive evaluation whether a main evaluation is ongoing

text: How can I programmatically check from a preemptive evaluation whether a main evaluation is currently ongoing? I need a function `mainEvaluationOngoingQ[]` so that               Button["Evaluating?", Print@mainEvaluationOngoingQ[], Method -> "Preemptive"]      will print `True` only if a main evaluation is ongoing.


title: What is the purpose of tags like :Name:, :Context:, etc. in packages?

text: I noticed that all of the packages that come with Mathematica start with a header that is in a standard format. (See e.g. the header of `NIntegrateUtilities`` at the end.) There are several commented sections, each starting with a word surrounded by colons. **Question:** What is the purpose of these colon-surrounded words? Do they have any meaning to Mathematica? They look like they were made for a machine to parse. Does Mathematica have any functions/tools that can read these? > >     (* :Name: NIntegrateUtilities` *) >   >     (* :Title: Utility functions for NIntegrate. *) >   >     (* :Author: Anton Antonov *) >   >     (* :Summary: >      This package provides a number of supporting functions for NIntegrate. >     *) >   >     (* :Context: DifferentialEquations`NIntegrateUtilities` *) >   >     (* :Package Version: 1.0 *) >   >     (* :Copyright: Copyright 2007, Wolfram Research, Inc. *) >   >     (* :History: >      Version 1.0 by Anton Atnonov, March 2007. >     *) >   >     (* :Keywords: >      NIntegrate, integration, evaluations, profiling. >     *) >   >     (* :Source: >     *) >   >     (* :Mathematica Version: 6.0 *) >   >     (* :Limitation: >     *) >   >     (* :Discussion: >     *) >


title: Unable to evaluate reasonable max expression

text: Consider the following statement:               Max[0, Sqrt[1 - Cos[4 \[Theta]]]]      You'll find that Mathematica won't evaluate this, because it doesn't know the range of $\theta$. Okay, that makes sense, so change it to:               Simplify[Max[0, Sqrt[1 - Cos[4 \[Theta]]]], {0 <= \[Theta] <= 2 \[Pi]}]      This evaluates happily. As it should. But then consider this not-impactful adjustment:               Simplify[Max[0, Sqrt[1 - Cos[4 \[Theta]]]/       Sqrt[2]], {0 <= \[Theta] <= 2 \[Pi]}]      This doesn't evaluate. I don't know why; because it seems quite obvious that it should be exactly the same as the previous case, right? (The constant factor of `1/Sqrt[2]` can't change the fact that it is still $\geq 0$). Any thoughts on how to fix this? Of course, in my case I want to actually keep the `Max` ..., but I don't know the exact form of the other side, so I can't just arbitrarily remove constants ...


title: Approximate the largest and the smallest values of the integral

text: How do I solve this:approximate the largest and the smallest values of the integral ![enter image description here](http://i.stack.imgur.com/AWPK8.png) for ![enter image description here](http://i.stack.imgur.com/r8FuV.png)


title: How can I threshold for a minimum value with MatrixPlot?

text: Looking at the `Options` for `MatrixPlot`, there doesn't seem to be a mechanism for lowerbound threshold - i.e. ignoring values that fall below a certain cutoff. If my data set is very large, and I need a fast method of accomplishing this, would anyone have a recommendation?


title: Generating a table of contents

text: This is my oldest question on SO. It still hasn't generated a useful answer there, so I thought I'd give it a try here. The question was: I don't seem to be able to find the method to generate the table of contents for a Mathematica notebook. AuthorTools, an old v5.1 utility package is still hidden in Mathematica, but it doesn't work for me. The TOC should contain correct section numbers (if present in the stylesheet) and list page numbers (this requires taking page size settings into account).


> **Possible Duplicate:**   >  Generating a table of contents How to create a dynamically self-updating table of content for a notebook? The TOC should contain the titles for the section, subsection, subsubsection etc. and should self-update as the new sections are added, and existing ones changed. A "dynamic self-updating" part may be loosen from the question if it's too hard, i.e. a function that can be ran to generate a TOC which i can then manually copy.


title: Cannot solve equation

text: I just started using mathematica and I'm facing a problem that I just can't solve. I want to solve the following equation: ![enter image description here](http://i.stack.imgur.com/71VXO.jpg) Code:               eqn = {(ao)/((c*Exp[a*(n - o)/n]) (-Log[(c*Exp[a*(n - o)/n])] + Log[c] + a)^2) == m,             ao*1/2 < n};          Solve[eqn, n, Reals]      Program says ' This system cannot be solved with the methods available to Solve.' Can anybody help me with this?


title: What are the possible ways of visualizing a 4D function in Mathematica?

text: I have a function $F$ that maps the xyz space to a set of reals, more clearly: $c = F[x,y,z]$ Where $c$,$x$,$y$ and $z$ are reals. What are the possible ways of visualizing this 3d function in Mathematica? (if possible, please post a how-to-do-it)


title: Monitor doesn't work with ParallelTable

text: I can't monitor ParallelTable:               Monitor[ParallelTable[Pause[3]; i, {i, 1, 10}], i]      just displays `i` until it is finished. Do you guys know of alternatives?


title: How can I generate and color annular sectors?

text: ![enter image description here](http://i.stack.imgur.com/9rU6Z.png) How can I generate such an image and fill every annular sector with a random colour?


title: Option Inspector -- option definitions

text: Relatively new to Mathematica, using v. 8.0.4.0 on OSX, and wanting to know where I can find something like a list of definitions for each of the many Global, Notebook, Cell, etc. options listed in the OptionsInspector. Some are fairly obvious, and I've come across the definitions of several others in my learning a little about the system. But I'd like to know how I can get the definition of any option in which I'm interested (at least a description of what that option does). If you know of such a source, I would appreciate you pointing it up to me. Thank you.


title: Exporting graphics to PDF results in destroyed fonts on Windows 8

text: Executing               plot = Plot[x^2, {x, 0, 100}, PlotLabel -> "Plot"];     SetDirectory[NotebookDirectory[]];     Export["plot.pdf", plot, "PDF"];      results in ![Distorted fonts](http://i.stack.imgur.com/Nvd7P.png) Is this a bug? OS is Windows 8, 64bit.


title: Some questions about Integral Equation

text: I am trying to solve the finite Hilbert transformation like the following form $ f(x)= \frac{1}{π} \int_{-1}^{1} \frac{g(y)}{(y-x)}dy $ the given function f(x)=1 and I want to solve the g(x) I know there is no direct way to solve the integral equation in Mathematica. Moreover, I found some boundary problems when solving it. Does anyone provide some useful tips?


title: Package autoloading not working in CDF and Player Pro

text: I have made a package                BeginPackage["top`"]      t[x_]:=MessageDialog["This is top"]      t1[x_]:=MessageDialog["This is top1"]      EndPackage[]      and used the code of this link and I am able to auto load packages in `Mathematica` and it is working fine. But when I have used it with `Player Pro`. It is not working. Automatically load packages at startup                initFileName = FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}];          (* Make a back-up *)      CopyFile[initFileName, initFileName <> "_" <>     StringReplace[ToString@Round[DateList[]], " " -> ""] <> ".bak"];     exprs = Import[initFileName, {"Package", "HeldExpressions"}];           Export[initFileName,        Append[exprs, HoldComplete[Needs["VectorAnalysis`"]]],          {"Package", "HeldExpressions"}       ]              Row[{Button["Click for function t", top`t[5]], Button["Click for f1", top`t[7]]}]      I have deployed the notebook in to `CDF Player`. But when I am opening the `CDF` by closing Mathematica and opening it with `CDF Player`, it is not working. I have also added that package in Autoload folder of Mathematica Player. What should I do so that my CDF or Player Pro also works fine as `Mathematica` notebook was working fine by autoloading packages at startup? I was getting this output in mathematica when I clicked at "click for function t".![enter image description here](http://i.stack.imgur.com/oiW7q.png) But I am not getting any output when I click on these two buttons in case of CDF or Player Pro.


title: How to find pixel position in a graph , given two points?

text: I have a graph where on my Y axis , I have price and on X axis I have period/time. My range on Y axis is from 10 (lower limit) to 200 (upper limit), so to draw the point on graph I need the Y position of the value for example if my price is 100.50 then how should I calculate Y position of this price . Example: If my upper limit point is (200,HeightOfGraph) that is P1, and the lower limit point is (0,0) is P2, so if height of graph is 100 so if the value is 100 it's y position will be 50 , but how should I calculate it , is there any formula to do this ?


title: How to create hedcut style images?

text: Yesterday the hedcut style was brought up in chat. How can we create a hedcut- like style automatically in Mathematica, using a photograph as a starting point? ![](http://i.stack.imgur.com/R3nUd.jpg) I am looking to create a similar artistic feel, not necessarily reproduce the hedcut style precisely. * * * Relevant resources:   * Hedcut-like effect in Photoshop   * A blog showing illustrations of this style   * Halftone, spiral cut/engraving, and 'pointillism' effects from the recent image vectorization question. All of these re-compose the image out of dots of varying size or lines of varying width. Sample portraits to work with: ![](http://i.stack.imgur.com/3LkNC.jpg) ![](http://i.stack.imgur.com/eQtVz.jpg) ![](http://i.stack.imgur.com/qaZpG.jpg) ![](http://i.stack.imgur.com/UZg4t.jpg) ![](http://i.stack.imgur.com/YajUp.jpg) @Silvia's idea from yesterday:               ImageDeconvolve[Import["http://www.alleba.com/blog/wp-content/photos/put001.jpg"],      GaussianMatrix[2.7], Method -> "TSVD"]      ![Mathematica graphics](http://i.stack.imgur.com/jPlBC.png) ![Mathematica graphics](http://i.stack.imgur.com/ITXL1.png) * * * My own failed first attempt (the part that detect line directions may be useful to people who work on answers): ![Mathematica graphics](http://i.stack.imgur.com/irocm.png) ![Mathematica graphics](http://i.stack.imgur.com/Iu8ig.png)               img = Import[       "http://www.stars-portraits.com/img/portraits/stars/j/jimi-hendrix/jimi-hendrix-by-BikerScout.jpg"]          (* "Real" images support negative numbers---for convenience *)          img = Image[ColorConvert[img, "GrayLevel"], "Real"];     img = ImageRotate[img, Right];          (* horizontal and vertical components of the gradient;        the direction can be computed using ArcTan *)     gv = ImageCorrelate[img, ( {          {0, -1, 0},          {0, 0, 0},          {0, 1, 0}         } )];     gh = ImageCorrelate[img, ( {          {0, 0, 0},          {1, 0, -1},          {0, 0, 0}         } )];          g = GradientFilter[img, 1];          (* verify the number of white pixels in Binarize[g] *)     Count[ImageData@Binarize[g], 1, Infinity]          (* create small strokes along the outlines *)     outline =       With[{point = RandomChoice[Position[ImageData@Binarize[g], 1], 1500]},       Graphics@MapThread[         Rotate[Disk[#1, {4, 1}], #2] &,         {point,          ArcTan @@@            Transpose[{Extract[ImageData[gh], point],              Extract[ImageData[gv], point]}]}         ]       ]               (* try to tone down plain grey/dark backgrounds *)     detail = ImageAdjust@       ImageAdd[img,         ImageMultiply[ColorNegate@ImageAdjust@EntropyFilter[img, 15], 2]]          coords = Outer[List, #2, #1] & @@ Range /@ ImageDimensions[img];          fill = With[{point =          RandomChoice[          Join @@ ImageData@ImageClip@ColorNegate[detail] ->            Join @@ coords, 5000]},       Graphics@MapThread[         Rotate[Disk[#1, {3, 0.8}], #2] &,         {point,          ArcTan @@@            Transpose[{Extract[ImageData[gh] + 10 $MachineEpsilon, point],              Extract[ImageData[gv], point]}]}         ]       ]          Show[fill, outline]      Note: I'm not fond of Putin, but his portrait I linked to seems to be easier to handle than some others. * * * **Update:** Second attempt, based on @Silvia's suggestion to try `ContourPlot` and wxffles's image vectorization approach. It's better, but still not achieving that feel. ![Mathematica graphics](http://i.stack.imgur.com/KsTuo.png)               img = Import["http://i.stack.imgur.com/YajUp.jpg"]          baseimg =        ColorConvert[ImageReflect@CurvatureFlowFilter[img], "GrayScale"];          (* Here we could simply use           ct=Table[p,{p,0,1,0.02}];           but the following approach gives a better balanced image *)          if = Interpolation[ImageLevels[baseimg]];          cif = Derivative[-1][if];          cifmax = cif[1];          f[x_] := cif[x]/cifmax          ct = Block[{x},       Table[        x /. First@FindRoot[f[x] == p, {x, 0.5, 0, 1}], {p, 0, 1, 0.02}]      ];          lcp = ListContourPlot[ImageData[baseimg], Frame -> False,        Contours -> ct,        ContourStyle -> (Dashing[{#, 1/50}] &) /@ ((1 - ct)/50),        PlotRange -> {0, 1}, AspectRatio -> Automatic,        ContourShading -> None]


title: eigenvector bug?

text: This bug was fixed in version 10.0.0 * * * I have a fairly simple $3\times3$ complex matrix, $$ M=\left( \begin{array}{ccc} \frac{7}{2}-\frac{i}{2} & -1+i & \frac{1}{2}+\frac{5 i}{2} \\\ -1+i & 5+i & -1+i \\\ \frac{1}{2}+\frac{5 i}{2} & -1+i & \frac{7}{2}-\frac{i}{2} \\\ \end{array} \right) $$ Solving for the eigenvalues and eigenvectors:               mat = {{7/2 - I/2, -1 + I, 1/2 + 5 I/2}, {-1 + I,          5 + I, -1 + I}, {1/2 + 5 I/2, -1 + I, 7/2 - I/2}};      {vals, vecs} = Eigensystem[mat]      gives (Mathematica 9.0.1) \begin{array}{ccc} 6 & 3+3 i & 3-3 i \\\ \\{1,-2,1\\} & \left\\{\frac{17}{13}+\frac{6 i}{13},0,1\right\\} & \\{-1,0,1\\} \\\ \end{array} But that 2nd eigenvector is not right; it should be $(1,1,1)$. Is there a bug, or am I being incredibly obtuse?


title: Timing Differences

text: In More efficient implementation for comparing coefficient lists in a Do-loop link, george2079 posts in his first answer a piece of code that takes 352 seconds to compute. When I run this same piece of code on my 2.3 GHz Intel Core i7 MacBook Pro laptop, it takes 853 seconds. What are the reasons for this, and how can I get the code running optimally on my machine? (Would it be appreciably faster if I used a desktop?) Perhaps this question is best posed to George2079, but the original thread is unfortunately dead and there doesn't seem to be a way to contact individual users.


title: A simple error with stochastic variables

text: f = Piecewise[{         {0.1, x == 1 && y == 1}, {0.1, x == 2 && y == 1}, {0.0,           x == 3 && y == 1}, {0.3, x == 1 && y == 2}, {0.1,           x == 2 && y == 2}, {0.2, x == 3 && y == 2}, {0.0,           x == 1 && y == 3}, {0.2, x == 2 && y == 3}, {0.1,           x == 3 && y == 3}, {0, True}}];     fi = ProbabilityDistribution[f, {x, 1, 3, 1}, {y, 1, 3, 1}];     Probability[      x <= 2 && y <= 2, {x \[Distributed] fi, y \[Distributed] fi}]      I am trying to compute this problem. The result I am looking for is 0.9


title: Make a huge vector in a wise way

text: I need to construct a vector similar to:               v[x_]:={0, 0, x, 0, 0, 2*x, 0, 0, 3*x, ....., 0, 0, n*x};      where `n=10^9`. How can I make such a vector wisely?


title: Plotting $\omega(k_x, k_z)$ in $(\omega, k)$ plane with assumption of $k^2 = k_x^2 + k_z^2$

text: I'm currently studying atmospheric-gravity waves and their dispersion relations. For analysis I need to plot the dispersion function: \begin{equation} \omega^4 - \omega^2\cdot C_s^2(k_x^2 + k_z^2 + \dfrac{1}{4H^2}) + (\gamma - 1)g^2\cdot k_x^2 = 0 \end{equation} where, $C_s^2$, $H$, $\gamma$ and $g$ are some constant values. I used `Solve` to get $\omega$ as a function of $k_x^2$ and $k_z^2$ - $\omega = \omega(k_x^2, k_z^2)$. Code for solving:                  Solve[\[Omega]^4 - \[Omega]^2*(Subscript[k, x]^2 +              Subscript[k, z]^2 + 1/(4*H^2)) + (\[Gamma] - 1)*g^2*Subscript[k, x]^2 == 0, \[Omega]]      What I want:               Plot[f, {k, 0, 20}]      where `f` is any solution of `Solve`. It plot nothing, because _Mathematica_ didn't know about $k^2 = k_x^2 + k_z^2$ relation.