How do I assign a formula to a variab

I want to compute equations and assign them to variable. This is a wxMaxima program that calculated symbolic PID gains for an integrating first order system               remvalue(all)$                      /* Undefine                         */     Gp: K*%alpha/(s*(s+%alpha));        /* System transfer function         */     Gc: Ki/s+Kp+Kd*s;                   /* Simple PID controller            */     CLTF: ratsimp(Gc*Gp/(1+Gc*Gp));     /* Closed loop transfer function    */     CE: expand(denom(ratsimp(CLTF)));   /* Characteristic equation          */     DIFCE: expand(CE-(s+%lambda)^3);     Ki: solve(coeff(DIFCE,s,0),Ki);     Kp: solve(coeff(DIFCE,s,1),Kp);     Kd: solve(coeff(DIFCE,s,2),Kd);     grind(Ki,Kp,Kd);      The grind outputs text that I can paste here               [Ki = %lambda^3/(%alpha*K)]$         [Kp = 3*%lambda^2/(%alpha*K)]$     [Kd = (3*%lambda-%alpha)/(%alpha*K)]$      Notice that Ki, Kp and Kd represent equations. This is what I want because I can change the values and compute new gains. This is my Mathematica equivelent               ClearAll["Global`*"];     Subscript[G, p][s] = (K*\[Alpha])/(s*(s + \[Alpha]))     Subscript[G, c][s] = Ki/s + Kp + Kd*s     T[s] = Subscript[G, c][s]*        Subscript[G, p][s]/(1 + Subscript[G, c][s]*Subscript[G, p][s]) //        Simplify     Solve[{CoefficientList[Denominator[T[s]], s] ==         CoefficientList[(s + \[Lambda])^3, s]}, {Ki, Kp, Kd}]      This looks ugly because I haven't found the Mathematica version of grind() yet. Notice that the results are in the form Ki->Lamba^3/(K*Alpha). The -> is not an assignment so I can't treat Ki as a formula.                            3                    2         \[Lambda]          3 \[Lambda]         -\[Alpha] + 3 \[Lambda]     {{Ki -> ---, Kp -> ----, Kd -> --------}}         K \[Alpha]        K \[Alpha]           K \[Alpha]      How do I assign Lambda^3/(K*Alpha) using equations instead of by hand? I give up. formatting what get much better. Edit Solve[{CoefficientList[Denominator[T[s]], s] == CoefficientList[(s + [Lambda])^3, s]}, {Ki, Kp, Kd}] /. Rule-> Equal Does not work. When I type Ki for I get Ki in return and not the equal for Ki. This looks like it works s = Solve[{CoefficientList[Denominator[T[s]], s] == CoefficientList[(s + [Lambda])^3, s]}, {Ki, Kp, Kd}] {{Ki, Kp, Kd}} = { Ki, Kp, Kd } /. s


Storing solution to x and y

If I do               sol=Solve[{2x+2==y,3x+9==y},{x,y}]      then Mathematica will tell me               {{x -> -7, y -> -12}}      But I would like to store values to x and y even if I don't write the following thing explicitly.               x = -7     y = -12      At least I know this is possible, because I found how to do it by myself. But now I forgot. But I am sure it is possible.


How to modify function argument?

Usually in programming languages, function arguments are normal local variables, which can be modified. Is this not true in Mathematica?               In[94]:= TTT[x_] := Block[{},        x += 2        ];          In[95]:= TTT[3]      > During evaluation of In[95]:= AddTo::rvalue: 3 is not a variable with a > value, so its value cannot be changed. >>               Out[95]= 3 += 2      Is it possible to simulate normal argument behavior somehow?


How to get a number from Solve

It's often useful to get just one number from `Solve`. I use the following construction for acquiring one solution from the expression returned by `Solve`.               q = t /. Solve[p == 2 t + 1, t][[1]]      Mostly I don't like to use the different variable name within `Solve`. And the rule-applying seems very unnatural. I think a solution that is more elegant must exist. Can anyone show me this?


Assign the result of Solve in a list

> **Possible Duplicate:**   >  Assign the results from a Solve to variable(s) I want to assign the results of a Solve command in a list. For example Solve[-((287 s^3)/50) == 0, s] returns {{s -> 0}, {s -> 0}, {s -> 0}} I want it to return {0,0,0}. Can this be done automatically and not manually? Thank you very much


Error in extracting a column

I imported excel data to Mathematica using this command.               kuruzD = Import[     "C:\\Users\\TMH\\Documents\\Problem Set 4\\kuruzData.xlsx"][[1]] //TableForm       I want to extract the 5th column. So, I used the command,               kuruzD[[All, 5]]      but, it results the data in 5th row? Could anyone please tell me what is my mistake?


Table of values for functions with random variables

I'm trying to get a table of values for functions with random variables. First of all, i have a function like that:               t = 100.0;     LimMatrix3x3[a11_, a12_, a13_, a21_, a22_, a23_] :=        SetPrecision[         TableForm[{           MatrixForm[             MatrixPower[{                 {a11, a12, a13},                  {a21, a22, a23},                  {1 - a11 - 21, 1 - a12 - a22, 1 - a13 - a23}               },               t],              TableAlignments -> Left]},           TableHeadings -> {{"m", "Value"}, Null},            TableSpacing -> {4, 2}],          3]      And two matrices:               MatrixIn :=        SetPrecision[         MatrixForm[{             {p11, p12, p13},              {p21, p22, p23},              {1 - p11 - p21, 1 - p12 - p22, 1 - p13 - p23}           },            TableAlignments -> Left], 3];          MatrixOut := LimMatrix3x3[p11, p12, p13, p21, p22, p23];      where variables pij are:               p11 = RandomReal[];     p12 = RandomReal[];     p13 = RandomReal[];     p21 = RandomReal[{0, 1 - 11}];      p22 = RandomReal[{0, 1 - p12}];     p23 = RandomReal[{0, 1 - p13}];      Now i want to get the table with values for matrices above and use this function:               k = 5;      TableForm[       Table[{MatrixIn , MatrixOut} , {, 0, k}],        TableHeadings -> {Table[a, {a, 0, k}], {"Basic Matrix", "Matrix infinity"}},        TableSpacing -> {3, 2},         TableAlignments -> Center]      As a result i get the table with 5 lines, which are identical. It happens because pij are evaluated only once. But i need to get random values for each pair of matrices. Is there a way to create from `MatrixIn`, `MatrixOut` functions? Or, i heard, it's possible to use `&` in some cases. Any other idea?


How to manipulate lists to get only part of the value

This is really a question about manipulating the output of `Maximize`. I have a function of 2 variables, defined thus:                Pqpcum[r_, b_] = Integrate[2 Pi*x*Pqp[x, b], {x, 0, r}, Assumptions -> {b > 0}]      I want to find the point where the maximum of a certain function, defined below, occurs:               Abs[Pqpcum[x1, b] - Pqpcum[x1, 0]], x1]      The function `Maximize` returns an array, like this:               In[24]:= Maximize[Abs[Pqpcum[x1, 0.1] - Pqpcum[x1, 0]], x1]          Out[24]= {0.0204023, {x1 -> 1.77787}}      Now I want to plot the location of the maximum, which is 1.77787 in this case, as a function of b. Attempting to get the second element of the array returns an element like this:               {x1 -> 1.777869648006448`}      The above cannot be plotted. I need to do something like this:               Plot[Maximize[Abs[Pqpcum[x1, b] - Pqpcum[x1, 0]], x1][[2]],{b,0,0.2}]      except that the above doesn't return anything, since I have plotted the list. How can I go about doing it? I could discretize the data and manually copy- paste the location of maximum values to do a `ListLinePlot`, but it would be a pain to do it. **EDIT:** I found my answer- I can use ArgMax instead. It directly returns the location of the maximum, so the above can be done. But the question still remains- how in general can one manipulate a list that reads like `{x1 -> 1.777869648006448}` to get only the numeric value `1.777869648006448`?


Do loop - variable does not change

I got the follwing code which should add a '1' 100 times to an empty list.               plotVals = {}     Do[Append[plotVals, 1], {l, 1, Nmax}];      The output is again an empty list, why is this the case?


Plot not displaying

I'm trying to perform a basic plot to show that two equations align, but I'm not getting any results. Plot[{[Pi]*Cos (3 x - [Pi]), [Pi] * Sin (3*[Pi] - 3 x)}, {x, -3 [Pi], 3 [Pi]}] To me this seems fairly straightforward, but I'm getting a graph without the functions.


Mathematica, nested optmization

I want to use the solution of `Maximize`, defined as a function, in another function. Here's an example:               f1[y_] := x /. Last[Maximize[{Sin[x y], Abs[x] <= y}, x]]  (* or any other function *)      This definition is fine, for example if I give `f1[4]`, I get the answer `-((3 \[Pi])/8)`. The problem is that when I want to use it in another function I get an error. For example:               FindRoot[f1[y] == Pi/4, {y, 1}]      Gives me the following error: > ReplaceAll::reps: {x} is neither a list of replacement rules nor a valid > dispatch table, and so cannot be used for replacing. >> > > FindRoot::nlnum: The function value {-0.785398+(x/.x)} is not a list of > numbers with dimensions {1} at {y} = {1.}. >> I've been struggling with this for several days now! Any comment, idea, help, ... is deeply appreciated!


On reimplementing the Select function

I am working through the course _Programming Paradigms via Mathematica_. One of the exercises asks that you construct a function that mimics `Select`,even with three arguments. It also includes the following direction: > Do not use the `Select[]` function in your definition. Here is an example of how `Select` works:               Select[{1, 2, 3, 4, 6, 8, 10}, EvenQ, 4]     (* {2, 4, 6, 8} *)      First I tested the following code and got the same result as `Select`:               l1 = {1, 2, 3, 4, 6, 8, 10};     l2 = {};     crit = EvenQ;     n = 4;     While[Length[l1] > 0 && Length[l2] < n,      If[crit[First[l1]], l2 = Append[l2, First[l1]]];         l1 = Rest[l1];      ]     l2          (* {2, 4, 6, 8} *)      I then tried to write a function that would do the same thing (caution causes infinite loop):               Clear[whileSelect]     whileSelect[l1_List, crit_, n_] := Module[{l2},       While[Length[l1] > 0 && Length[l2] < n,         If[crit[First[l1]], l2 = Append[l2, First[l1]]];             l1 = Rest[l1];         ]        l2       ]      However I got a series of `Set::shape: Lists {1,2,3,4,6,8,10} and {2,3,4,6,8,10} are not the same shape. >>` error messages and the code put the computer into an infinite loop. I have looked at documentation on `Module`,`Rest`,`Set` and `If` but have not been able to figure out what I am doing wrong. I would greatly appreciate a point in the right direction.


Combined numerical minimization and maximization

I want to numerically calculate the maximum of a function defined by the minimization of another function, like the following:               NMaximize[b/.NMinimize[(a^2+b)^2,{b}][[2]],{a}]      Obviously the intended result (for this simple test function) would be:               {0., {a->0.}}      because the inner minimization would give b=-a^2 for any value of a, and maximizing that gives 0 for a=0. However I get the error message `NMinimize::nnum: "The function value (-0.829053+a^2)^2 is not a number at {b} = {-0.829053}."` and the result `NMaximize[b/.{b},{a}]`. I figured that this is due to premature evaluation of the argument (i.e. before `a` got anumerical value), therefore I tried to wrap either the whole first argument of just the `NMinimize` call in `Unevaluated`, but neither helped. So my question is: How can I do this combined numerical optimization?


Circumventing the default scoping: Assign a variable inside a function

I'm currently trying very hard to assign a variable inside a function.   Therefore I'm using a function like this, which should reassign a predefined variable.               assign[a_] := (HoldForm@a = 2)     a=1;     assign[a]      The problem is that Mathematica uses the value of "a" instead of its name.   Any suggestions?


Store results of inequality

I eveluated some values using `Reduce` commend and I store them in a `Table`               t = Table[       N[Reduce[ 1/(1 + f) <= p[[i]] <= 1 + f , f], 100], {i, 1, n}]      Elements of a table looks like: `{f>= 99.000000000000000000000000000000000, f>=49.00000000000000000000000000000000...}` Now I want to plot this values for an integer domain. So I wanted to use ListPlot, but to use it I have to have a table which looks like: `{99.00000000000000000000000000000, 49.000000000000000000 ...}` How can I transform the first table to the second, which includes only values?


How to find the x-axis intersections/zeroes of a parametrized integral?

Consider the situation with this functions,                F[mm_, q_] :=  NIntegrate[(q/2) * (x Tanh[π x]) *( ( (Coth[π q Sqrt[x^2 + mm] ]                                 )/Sqrt[ x^2 + mm] - Coth[π x])/x,                     {x, 0, ∞}] + (1/2) Tan[Sqrt[mm] π ]   ;          Plot[ F[mm, 2], {mm, 0, 1}]      ![Mathematica graphics](http://i.stack.imgur.com/mGvpo.png) Looking at the graph it is clear that the function has roots in the range of $mm \in [0,1]$. But I am unable to use any of the root finding commands to get those numbers! Why are they not working here? * * * Also what are those vertical lines that the Mathematica is plotting here?


FindMinimum, NMinimize, etc. with external process

I was hoping to be able to use MMA's minimization power to work with an external process. I want to minimize the function 'TryThisNumber[x_]' which sends the value of x to something external and gets back a result from that external object. I want to find the number which minimizes the returned result. But ... I can only talk to the external process using strings. So, assume I have a function SendNumberToProcess[m_String] which does the actual communication with the process, I try:               TryThisNumber[x_]:= ToExpression[SendNumberToProcess[ToString[x]]];      and then,               FindMinimum[{TryThisNumber[a],0<a<10},{a}];      The problem is that ToString[x] in the above is just evaluating to the symbol, a, not a numerical value, and thus I'm not actually able to send a number to the external process. Any ideas? Update. Presumably the problem is that FindMinimum has the HoldAll attribute, but this attempt doesn't work either:               TryThisNumber[x_]:= ToExpression[SendNumberToProcess[ToString[Evaluate[x]]]];


"not a list of numbers" and "cannot be used for replacing "

I am trying to plot a function which is based on the solution of some equation; I could get the correct figure but only after lots of warnings are printed out. The following is a minimum version of my problem:               solx[z_] := FindRoot[x z == 40, {x, 1.}]     r[z_, f_] := f x /. solx[z];     Plot[Evaluate[Table[r[z, f], {f, 1., 5., 1.}]], {z, 1., 5.}]      Then I got the following warning messages: > FindRoot::nlnum: The function value {-40.+1. z} is not a list of numbers > with dimensions {1} at {x} = {1.}. > > ReplaceAll::reps: {FindRoot[x z==40,{x,1.}]} is neither a list of > replacement rules nor a valid dispatch table, and so cannot be used for > replacing. > > FindRoot::nlnum: The function value {-40.+1. z} is not a list of numbers > with dimensions {1} at {x} = {1.}. > > ... What can be done to avoid the warning messages? (I have tested that if I remove the $f$-dependence and plot $r[z]$, there is no warning messages, i.e.,               solx[z_] := FindRoot[x z == 40, {x, 1.}]     r[z_] := x /. solx[z];     Plot[r[z], {z, 1., 5.}]      works without any problem.)


Stop function evaluating input at time of definition

I would like to create a function that acts on whether the input is even or odd, e.g.:               In[644]:= f[a_] = If[EvenQ[a], 2 a, 3 a];               f[2]          Out[645]= 6      I've determined (I think) that this is because `a` is an expression and `QEven` returns false for expressions. How do I hold off evalution of this until input is given? I thought something like `Defer` would work but then it is never evaluated (see below)!               In[641]:= g[a_] = If[Defer[EvenQ[a]], 2 a, 3 a]          Out[641]= If[EvenQ[a], 2 a, 3 a]          In[643]:= g[3]          Out[643]= If[EvenQ[3], 2 * 3, 3 * 3]      Apologies if this gets asked a lot - I assume this is a common issue, but I was unable to come up with appropriate search terms to describe it (I'm not very familiar with Mathematica terminology yet). Thanks!


Error when solving equations constructed with Table

I have a couple of questions about the problem I am trying to solve               n = 7;     alpha = 0.01; c = 10;          atable = Table[a[i], {i, 0, n}];      Solu = y^Range[0, n].atable;          Leftequ = Solu;      Rightequ =  A y^2 +  B y + DD + 1/2/alpha Integrate[Solu^2, y];          Lec = CoefficientList[Leftequ, y];     Rec = CoefficientList[Rightequ, y];          Lec = PadRight[Lec, Min[Length[Lec], Length[Rec]]];     Rec = PadRight[Rec, Min[Length[Lec], Length[Rec]]];          eqs = Lec == Rec;          Sol = Solve[eqs, atable]      If I check `a[0]` it will show that `a[0]=a[0]`, but I want to set it to `a[0] = DD`. This is probably a mistake I overlooked, but nevertheless could not find it. Thanks in advance.


Mathematica "Insert" not working

Why doesn't this work:               mergeList[a_, b_] := (       list = a;       Insert[list, 98, 3];       Do[        Do[         (          If[           b[[f]] < list[[s]],           (Insert[list, b[[f]], s]; Break[])           ]          ),         {s, Length[list]}         ],        {f, Length[b]}        ];       list       )      It doesn't give an error, it just outputs the original value of list = a For example:               mergeList[{1, 2, 3, 4}, {2, 3, 4, 5}]      outputs `{1, 2, 3, 4}`, and I don't know why.


NMinimize not starting

I am new to Mathematica so I might be asking a trivial question, although I wasn't able to resolve it for several days. I am trying to optimize a 7x7 matrix with 12 variables with a certain evaluation function. The evaluation function is defined as:               SumCenter[v1_, v2_, v3_, v4_, v5_, v6_, v7_, v8_, v9_, v10_, v11_, v12_] :=        Re[Sum[N[Func[v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, t]], {t, 0, 3, 0.01}]]      `Func` is a time dependent outcome of the matrix which is a little long if I tried to write it down here. Some functions that are used are: `MatrixExp[]`,`Tr[]`. I can guarantee that it gives a near accurate number, although it generates a very small amount of imaginary number which is not supposed to be there. That is why there is the `Re[]` function. `N[]` might not be necessary. Then I used `NMinimize` to find the optimal value and the variables:               NMinimize[{SumCenter[z1, z2, z3, z4, z5, z6, z7, z8, z9, z10, z11, z12],        -1 <= z1 <= 1 && -1 <= z2 <= 1 && -1 <= z3 <= 1 && -1 <= z4 <= 1 &&       -1 <= z5 <= 1 && -1 <= z6 <= 1 && -1 <= z7 <= 1 && -1 <= z8 <= 1 &&        -1 <= z9 <= 1 && -1 <= z10 <= 1 && -1 <= z11 <= 1 && -1 <= z12 <= 1},        {z1, z2, z3, z4, z5, z6, z7, z8, z9, z10, z11, z12},        StepMonitor :> Print["Step to z1 = ", z1]]      The calculation did not begin. Even though I put StepMonitor, it did not show the first step. I made a rather simple version with 3x3 matrix and 3 variables, which worked perfectly. I would like to figure out what might be causing the problem.


Why would this function work only when I make a copy of the variable?

Why would this function work with a copy of the function variable:               Clear[zero]     zero[list_] := Module[{listCopy = list}, listCopy[[2]] = 0; listCopy]     zero[{1, 2, 3, 4, 5}]     (* {1, 0, 3, 4, 5} *)      but not when using the variable directly?               Clear[zero]     zero[list_] := Module[{}, list[[2]] = 0; list]     zero[{1, 2, 3, 4, 5}]      ![Mathematica graphics](http://i.stack.imgur.com/DSZFZ.png)


Check if an inequality holds among the solutions returned by Solve

Let's say I solve a system:               Solve[{a == 3* c, b == 2 *a}, {a, b}]      and then want to see if the values found for `a` and `b` satisfy an inequality:               Reduce[a < 7 b]      What I would usually do is copy and paste by hand the result of the `Solve[]` to make it available to `Reduce`:               Solve[{a == 3* c, b == 2 *a}, {a, b}]     (output) {{a -> 3 c, b -> 6 c}}          a = 3 c;     b = 6 c;     Reduce[a < 7 b]      but there must be a better way to do this? I would also like all those variables (`a`,`b` and `c`) to stay local because I will have to solve a lot of similar equations with the same variable names on the same notebook and I wouldn't want the values to mix.


Mathematica can't minimize a function

Mathematica seems not to be able to minimize this univariate function over integer arguments, $r>2, r \in \mathbb{Z}$.               k=6;     SB[n_, r_] :=       Sum[Binomial[r Binomial[2 k, 2]/2, i] Binomial[         Binomial[n, 2] - r Binomial[2 k, 2]/2,          r Binomial[k, 2] + r - i], {i, r Binomial[k, 2] + r/2,         r Binomial[k, 2] + r}]               NMinimize[{SB[k r, r], Element[r, Integers] && r > 2}  , r]      This takes forever, even if, evaluated with `Table` the function in the interval $r=(2,100]$ for example, has perfectly valid values. The other command `FindInstance` seems unable to tell me a valid value when checking if $S_B(k r,r) > 0$ even if this is true for every value of $r$. Some help to make this computation faster or let it converge to a feasible solution? I know the solution is at $r=2$ but I just want to know how to properly specify this problem that is part of a more general framework.


How to convert the expression '{a->a0, b->b0}' to the expression 'a=a0; b=b0'? I think this is a common question and do not know if someone has asked it before. Any help or suggestion will be appreiated!


Evaluation of m.v is blocked by applying MatrixForm. Why?

I'm trying to understand what is happening in the notebook session below. I have a 2x2 matrix `m = {{-1,-1}, {-1,-1}}`. And a vector `v ={1,1}`. `m.v` (not shown) gives `{-2,-2}` as expected, and applying `MatrixForm` to `m`, to `v`, and to `m.v` gives presents the 3 values in the form I would expect. However, if `MatrixForm` is applied to `m` and `v` prior to evaluating `m.v` (as shown) then both `mm.vv` and `mm.vv` give the same unexpected result -- what appears to be then "unevaluated" product. (And possibly the wrong "kind" of product: "m dot v", rather than "m times v".) I realize there are (probably related) issues around Mathematica not actually operating in terms of "column vectors", and instead doing some more general tensor based operation. I'm in the process of trying to understand all that as well. But my basic question here is what exactly `MatrixForm` is doing. I thought that is was simply a presentation-level operation, but it appears that is not the case? ![MatrixForm, applied after and before](http://i.stack.imgur.com/n2oS7.png)


Fitting a Function With a Numerical Integral

I am having trouble using FindFit with the following function.               f[x_] := NIntegrate[a x k, {k, 0, 1}];          data = {{0, 0}, {0.2, 0.1}, {0.4, 0.2}};          param = FindFit[data, {f[x],2>a>1},a, x]      I get the following error               NIntegrate::inumr: The integrand a k x has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. >>      Yet I can easily plot the function if I set "a" to any value between 1 and 2. So I assume FindFit is not assigning "a" a numerical value for some reason? This function is the simplest function in which I can reproduce the error (The data set is similarly a toy dataset). The actual function I need to use will be more complicated, so unfortunately getting rid of NIntegrate is not possible. Thanks


Replace doesn't replace the denominator

I have the following expression in Mathematica                   -((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/Sqrt[(x[1] -         x[2])^2])      I want to replace anything of the form `Sqrt[t^2]` to `t`. I tried               -((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/       Sqrt[(x[1] - x[2])^2]) /. Sqrt[(t_)^2] -> t      But it just does the changes in the numerator and not in the denominator. What is that I am doing wrong here? Thanks in advance! -dbm


Defining a Function, := versus =

Consider:               crossRatio[z_, q_, r_, s_] := (z - q) (r - s)/((z - s) (r - q));     points1 = {-1, 1, (-1 + Sqrt[2]) I};     points2 = {I, -I, 1};     ff[z_] :=       w /. Solve[          crossRatio[z, Sequence @@ points1] ==            crossRatio[w, Sequence @@ points2], w][[1]] // Simplify      Now               ff[(-1 + Sqrt[2]) I]      gives me a sequence of errors: > Power::infy: Infinite expression 1/0 encountered. >>   >  Solve::infc: The system ComplexInfinity==((1/2-I/2) (-I+w))/(-1+w) contains > an infinite object ComplexInfinity. >>   >  ReplaceAll::reps: {ComplexInfinity==((1/2-I/2) (-I+w))/(-1+w)} is neither a > list of replacement rules nor a valid dispatch table, and so cannot be used > for replacing. >> However, if I leave out the semicolon:               ff[z_] = w /.         Solve[crossRatio[z, Sequence @@ points1] ==            crossRatio[w, Sequence @@ points2], w][[1]] // Simplify      Then it works.               In[262]:= ff[(-1 + Sqrt[2]) I]          Out[262]= (I Sqrt[2] (Sqrt[2]-1)-I (Sqrt[2]-2))/(I Sqrt[2]+I (Sqrt[2]-2) (Sqrt[2]-1))          In[263]:= Simplify[%]          Out[263]= 1      How come? What's the difference between f[z_]:= and f[z_]= ?


How can I access numerical values of variables calculated with Solve?

I am trying to calculate some thermodynamical cycles so I often use lists with equations. Here's a simple example:               list1 = {          x + 2 y == z,          z - 2 x == 3z,          y - z == 5 x}          Solve[list1,{x,y,z}]      > >     {{x -> 0, y -> 0, z -> 0}} >   The problem appears when I want to use the calculated values of `x,y,z` later on to calculate some other parameters. _Mathematica_ every time keeps returning `x,y or z` instead of its numerical value. Is that because the result of `Solve` is a nested list? Anyway, what should I do to have an access to these values?


Getting message NIntegrate::inumr: in V10; did not happen in V9

I just tried making a `ParametricPlot` that worked error-free in _Mathematica_ 9, but now produces errors before successfully plotting in _Mathematica_ 10\. It appears to have something to do with which order _Mathematica_ evaluates the various expressions. A very simple example that generates this error is the command               ParametricPlot[{t, NIntegrate[a*t, {a, 0, 1}]}, {t, 0, 1}]      which produces > NIntegrate::inumr: "The integrand a t has evaluated to non-numerical values > for all sampling points in the region with boundaries {{0,1}}. " a couple times before suppressing the error and showing the plot. My actual functions are much more complicated, and, while I'd like to get rid of this annoyance, I'd also prefer to not have to rewrite many function definitions.


Use FindRoot solution as number in function

I would like to save a number that I gain with FindRoot so that I can use it in another function. I tried:               alph := FindRoot[BesselJ[0, x], {x, 0, 2}]     f[x_] := alph*x     Plot[f[x], {x, 0, 10}]      This does not work because `alph` is not a number but an expression `{x -> 2.40483}`. So how do I do this correctly?


What is wrong with setting one list to another within function?

I have built a function which carries out a set of operations given two parameters. The function looks as follows:               playingHand[Player_, Name_String] :=      Row[{Style[Name <> ":", FontSize -> 48, FontFamily -> "Calibri"],         Spacer[20]}~Join~        If[Player == {}, {Style["Not playing", 48, Gray,            FontFamily -> "Calibri"]},         {ButtonBar[Table[            With[{i = i},             Player[[i, 3]] :>              {AppendTo[discardPile, Player[[i]]],                Player = Delete[Player, i]}],            {i, Length@Player}]]}]]      The gist of this function is that as its first input it takes a list, which looks something like: ![enter image description here](http://i.stack.imgur.com/S6cOs.jpg) and displays the third elements of each list within that list: ![enter image description here](http://i.stack.imgur.com/ejcR3.jpg) It also makes these images clickable, so that when one of these cards is clicked, it should disappear from `player1` and get added to an initially empty list called `discardPile`. So far so good. When I run this function by itself without the defined function, namely like this:               ButtonBar[Table[        With[{i = i},         player1[[i, 3]] :>          {AppendTo[discardPile, player1[[i]]],            player1 = Delete[player1, i]}],        {i, Length@player1}]] // Dynamic      it works like a treat. The cards are clickable and they disappear from the `ButtonBar` as soon as they are clicked and added to `discardPile`. When I try to do the same from within the function though, namely `playingHand[player1, "Aron"] // Dynamic` it suddenly stops working. A `Set::shape` error message comes up warning that two lists are not the same length, and although it does add the card to `discardPile`, it does not remove it from `player1`. So:   1. What is wrong with this function and why won't it delete the card from the list when it is clicked, and   2. How come the same error does not occur when I run the function directly without calling it by its function name?


Adding a tree to a list of trees within a loop

I'm trying to write a function which for a list of trees checks if a given tree is isomorphic with any of the listed, and if not - adds it to the list. I tried to use both `Append` and `AppendTo`, but they don't work ( I checked for non-isomorphic trees, and whole loop is executed, but nothing is added to the list).   `Append` doesn't seem to work at all (I mean outside of the loop), and `AppendTo` works outside, but doesn't work in loop.   What can be a problem here?               checkIsomorph[outList_, seedling_] :=       For[i = 1, i <= Length[outList], i++,       If[IsomorphicGraphQ[outList[[i]], seedling], Break[],        If[i == Length[outList], AppendTo[outList, seedling],         Continue[]]]]


Assign the results from a Solve to variable(s)

I understand Mathematica can't assign the results of a Solve to the unknowns because there may be more than 1 solution. How can I assign the 4 values of following result to variables? ![enter image description here](http://i.stack.imgur.com/wu2c0.png)


How to fit ODE's coefficient, just like using NMinimize

I want to fit ODE's coefficients to a model. I tried using `NMinimize`, but it seems it does symbolic instead of numerical calculations.               ode[a_] := Block[{am=a},            sol=NDSolve[{x''[t]==a,x[0]==0,x'[0]==1},x,{t,0,2}];            Abs[x[1]/.sol]]     NMinimize[ode[a],a]      And then, I got the Error Message: > >     NDSolve::ndnum: Encountered non-numerical value for a derivative at t == > 0.`. >   I have also tried `Method->"RandomSearch"` ect. I got:               {Abs[x[1] /.         NDSolve[{(x^\[Prime]\[Prime])[t] == a, x[0] == 0,         Derivative[1][x][0] == 1}, x, {t, 0, 1}]], {a -> -0.829053}}      I receive the error message > >     ReplaceAll::reps: "\!\({NDSolve[{\*SuperscriptBox[\"x\", > \"\[Prime]\[Prime]\", >       MultilineFunction->None][t] == a, x[0] == 0, \*SuperscriptBox[\"x\", > \"\[Prime]\", >       MultilineFunction->None][0] == 1}, x, {t, 0, 1}]}\) is neither a list >       of replacement rules nor a valid dispatch table, and so cannot be used > for replacing." >   It seems to me that it performs symbolic calculations instead of numerical. Is there a way to solve this problem OR is there other ways to fit ODE's coefficients to a model ?


The /. syntax in numerical methods

I have an analytical approximation method for solving an ODE and want to compare this to an NDSolve solution, but the syntax is confusing me. To get the solution from NDSolve, I define the ODE as eqn and use the following command to solve for O2n;               s = NDSolve[{eqn == 0, O2n[rn] == 0, O2n[ro] == po/omega},        O2n, {r, rn, ro}]          Af = Plot[{(O2n[r]) /. s}, {r, rn, ro}, PlotStyle -> {Blue},        PlotLegends -> LineLegend[{"Numerical"}]]      This works fine, but the /. syntax confuses me a little - what exactly does it signify, and how can I manipulate this? Specifically, I want to subtract my analytical function p[r] from this solution over the same range (rn - ro) to see how much they differ. Ideally I'd like to be able to export this data and analyze it further - can anyone explain the syntax to me, and how I might go about comparing the twain? Thank you!


How to use output from previous line in Plot?

Suppose, I want to solve a equation and want to obtain it's first root. In this case I've used               In[1]=:Solve[b^2 + b*z + 1 == 0, b][[1]]      This gives               Out[2]={b -> 1/2 (-z - Sqrt[-4 + z^2])}      Now I want use this result directly in Plot command. My code for this is               In[3]:Plot[Out[2], {z, -1000, 1000}, PlotRange -> All]      But I'm not getting the plot. If I use               In[4]:Plot[1/2 (-z - Sqrt[-4 + z^2]), {z, -1000, 1000}, PlotRange -> All]      I'm getting the plot correctly. I guess in In[3], `Out[2]` contains `b->`, that's why it's unable to plot. How to handle this situation? p.s. This is a prototype of my actual problem. I want to solve this in this way because my output is too large to copy and paste in the `Plot` command.


NIntegrate/NSum with parameters

I'm trying to calculate a continuous integral within a discrete integral. Something similar to this (yet more complex):               NSum[NIntegrate[x^2 + y, {x, 0, 1}], {y, 2}]      I receive the following error code: > NIntegrate::inumr: "The integrand x^2+y has evaluated to non-numerical > values for all sampling points in the region with boundaries {{0,1}}. " What is the proper way to tell Mathematica to evaluate this expression?


How to define a variable updating function?

I tried to program a `Sudoku` solver when I suddenly ran into this problem: I need a function which effectivley does this:               Updater[a_,b_,c_,Sudoku_]:=Sudoku[[a]][[b]]=c      Quasi an updater. But the code above won't work because the only thing I get is: > SetDelayed::setps: > "{{Null,Null,8,1,7,6,Null,2,Null},{Null,4,Null,Null,Null,9,7,Null,Null},{Null,Null,Null,Null,Null,Null,Null,Null,Null},{Null,7,1,8,Null,Null,Null,Null,Null},{Null,Null,Null,Null,Null,Null,6,7,9},{Null,Null,Null,5,9,7,Null,8,1},{Null,Null,Null,Null,2,Null,Null,Null,Null},{Null,5,9,Null,Null,Null,Null,1,Null},{Null,1,4,6,5,Null,3,Null,Null}} > in the part assignment is not a symbol." The list in the error message is what I used as `Sudoku` in my `Updater` function.


Modifying a List in a function in place

An example will be most specific:               func[list_, column_] := list[[All, column]] = Map[#*2 &, list[[All, column]]];      This throws errors. I want to avoid doing something like this:               func2[list_] := Map[#*2 &; list];     list[[All, 2]] = func2[list[[All,2]]]      because nesting a couple of functions raises complexity unnecessarily, the output would have to be reassigned every time. Thanks in advance. As a followup, using HoldFirst works fine, but using the so defined function in a Map gives again errors. The setup is as follows: create a nested list               testList = Table[Table[{x y, x y 2}, {x, 1,3}], {y,1,3}]      define afunc with HoldFirst Attribute               afunc = Function[{list, col}, list[[All, col]] = Map[# * 2 &, list[[All, col]]], HoldFirst]      and another function using the first               bfunc[nestedList_, col_] := Map[afunc[#, col] &, nestedList]      now, a call to               bfunc[testList, 2]      should alter the 2'nd columns of the nested lists I'd expect, but it instead throws errors i've tried to set Attribute HoldFirst on this function as well but it didn't work out as expected


Simplifying expressions with square roots

I would like _Mathematica_ to simplify this expression: $4 \left(16 \sqrt{\left(-1+2 c^2\right)^2}-32 c^2 \sqrt{\left(-1+2 c^2\right)^2}+\sqrt{\left(1-8 c^2+8 c^4\right)^2}\right)^2$               expression = 4*( 16*Sqrt[(-1 + 2*c^2)^2] - 32*c^2*Sqrt[(-1 + 2*c^2)^2]                       + Sqrt[(1 - 8*c^2 + 8*c^4)^2])^2;      I have tried               PowerExpand[expression]          FullSimplify[expression]      but they did not simplify `expression`.


Assigning the answer of Solve to a variable

If I enter               Solve[(x-2)(x+2)==0,x]      then the answer comes up as               {{x -> 2}, {x -> -2}}      I want to make two variables sol1 and sol2, and sol1=2 and sol2=-2. I don't mean I want to make sol1 and sol2 from {{x -> 2}, {x -> -2}} I want to make them directly before anything such as {{x -> 2}, {x -> -2}} comes up. As long as I get sol1 and sol2, I don't need such answers like {{x -> 2}, {x -> -2}} I know it's possible because a year ago I could manage to do it after hours of trial-and-error. But I don't remember now.


Change input variable in a function

I'd like to write a function, that would take a matrix as an input parameter and would change it by multiplying one of its rows by a factor. I try to do it in the following way:               matrix=Table[i*j,{i,Range@2},{j,Range@2}]     MultiplyRowByFactor[m_,factor_,iRow_]:=Module[{},m[[All,iRow]]*=factor;m]     MultiplyRowByFactor[matrix,2,1]      and get an error message               Set::setps: "{{1,2},{2,4}} in the part assignment is not a symbol. "      Of course, if I change the matrix outside of the function:               matrix[[All,1]]*=2;     matrix      everything works as expected. What is the problem and how can I write a function to modify a matrix "in place"?


save all inputs as list

I received three results of calculations: > >     {k->0.190729} >   >     {k->0.197575} >   >     {k->0.249319} >   Could you help me write the results in the following form: > >     {0.190729,0.197575,0.249319} >


FindRoot gives strange results when used on an interpolating function with vector output

I am currently experiencing a problem when I try to use `FindRoot` with an interpolating function that outputs a vector. I have constructed a minimal example that illustrates the problem. Consider the following function, that parametrizes a circle in the plane.               circle[t_] := {Cos[t], Sin[t]};      Suppose you want to find the point at which the x coordinate of the circle equals one half.               FindRoot[ circle[t][[1]] - 0.5, {t, 0.1, 0, Pi/2}]      Of course, `FindRoot` finds the root: > >     {t -> 1.0472} >   However, sometimes you do not have an exact function, and you need to use an `InterpolatingFunction` instead. The function `circleInterpol` is an interpolation of $100$ points sampled from the circle. Although the interpolation of lists of the type `{ t, {x,y}}` is not considered in the reference, _Mathematica_ does not issue any warnings and plotting using `ParametricPlot` works fine.               circleInterpol = Interpolation[ Table[{t, circle[t]}, {t, 0, Pi/2, Pi/200}]]     ParametricPlot[{circle[t], circleInterpol[t]}, {t, 0, Pi/2}]      However, when I try to use `FindRoot` in the same way as before:               FindRoot[circleInterpol[t][[1]] - 0.5, {t, 0.1, 0, Pi/2}]      but with circle replaced by `circleInterpol`, I get a completely different (and obviously wrong) result: > >     {t -> 0.5} >   `FindRoot` does not issue any warnings at this point. Changing the syntax to (I realize that `{0.5, 0.1}` is not a point on the circle, but since you take the first part anyway, this should not matter.)               FindRoot[(circleInterpol[t] - {0.5, 0.1})[[1]], {t, 0.1, 0, Pi/2}]      issues the warning: > >     FindRoot::nveq: The number of equations does not match the number of > variables in >     FindRoot[(circleInterpol[t] - {0.5, 0.1})[[1]], { t, 0.1, 0, Pi/2}]. >> >   Replacing the interpolating function by the exact function still gives the correct result. So it seems to me that something is going wrong with the combination of `FindRoot` and `InterpolatingFunction`. An obvious solution to the problem is to construct two interpolating functions; one for each coordinate (`x` and `y`). Although this would solve the problem, I do not understand why this extra step is necessary. Could someone help me to understand what is going wrong here?


How to extract Solve results as variables

> **Possible Duplicate:**   >  Assign the results from a Solve to variable(s) In the following example:               Clear[g1, z1, a, g2, z2]     sa = Solve[ g1 == 1 + l z1/(z1^2 + a), a]     sb = Solve[ g2 == 1 - l z2/(z2^2 + b), b] /. z2 -> z1 + l      This gives me solutions for `a` and `b` that are in the form               {{ a -> astuff }}     {{ b -> bstuff }}      I want to use this result in a secondary computation, and did so by cut and pasting from the `Solve[]` results like so                Solve[ astuff == bstuff, z1 ]      How can I just extract those results without cut and pasting? I don't like the cut and paste dependency since I'd have to redo it all if I make any sort of correction to the first couple identities.


NMinimize and FindRoot Issues with System of Equations

I am trying to solve a constrained optimization problem with a system of transcendental equations and am running into issues with NMinimize. I have a system of equations (`twoPopsVac`) and a function (`popRootsVac`) to find the roots of these.               twoPopsVac[V1_, V2_, alpha_, S1_, S2_, R01_, R02_, N1_, N2_] := {(S1 - V1)*(1 -      Exp[-R01*(1 - alpha)*Zinf1/N1 - R02*alpha*Zinf2/N2]) - Zinf1,     (S2 - V2)*(1 - Exp[-R02*(1 - alpha)*Zinf2/N2 - R01*alpha*Zinf1/N1]) - Zinf2}          popRootsVac[V1_, V2_, alpha_, S1_, S2_, R01_, R02_, N1_, N2_ ] :=      FindRoot[twoPopsVac[V1, V2, alpha, S1, S2, R01, R02, N1, N2], {Zinf1,     S2 - V1}, {Zinf2, S2*V1}]      I then create an objective function (`finalSize`) that is a function of the roots and try to use it in NMinimize.               finalSize[vac1_, vac2_] := Total[{Zinf1, Zinf2} /. popRootsVac[vac1, vac2, 0, N1*s01,     N2*s02, R01, R02, N1, N2 ]]          NMinimize[{finalSize[x, y], x + y == Vtotal && 0 <= x <= N1 && 0 <= y <= N2}, {x, y}]      Unfortunately, when I try to minimize, it seems like the attempted values of the parameters (x and y) are not being passed all the way through the equations. Any idea what is going on? `FindRoot::srect: Value 9000. -x in search specification {Zinf1,9000. -x} is not a number or array of numbers. >>` `ReplaceAll::reps: {FindRoot[twoPopsVac[x,y,0,9000.,9000.,3,2,10000,10000],{Zinf1,9000. -x},{Zinf2,9000. x}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>`


Minimizing roots of a transcendental equations

I'm trying to use the solution of FindRoot with parameters for further calculations. Annoyingly enough it always gives me trouble with replacing the parameters. As an example I'm attaching a simple example I've cooked, since the solution is obvious. First I've defined the function "root", which is the solution for the equation, and is obviously (x-1)^2               root[x_] := y /. FindRoot[y - (x - 1)^2, {y, 1}]      Next I've tried to minimize this function, which should obviously return x=1, but I get a string of errors:               FindMinimum[root[x], {x, 2}]          FindRoot::nlnum: The function value {1. -1. (-1.+x)^2} is not a list of numbers with dimensions {1} at {y} = {1.}. >>          ReplaceAll::reps: {FindRoot[y-(x-1)^2,{y,1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>          FindRoot::nlnum: The function value {1. -1. (-1.+x)^2} is not a list of numbers with dimensions {1} at {y} = {1.}. >>          ReplaceAll::reps: {FindRoot[y-(x-1)^2,{y,1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>          FindRoot::nlnum: The function value {1. -1. (-1.+x)^2} is not a list of numbers with dimensions {1} at {y} = {1.}. >>          General::stop: Further output of FindRoot::nlnum will be suppressed during this calculation. >>          ReplaceAll::reps: {FindRoot[y-1. (-1.+x)^2,{y,1.}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>          General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation. >>          FindMinimum::lstol: The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. >>          Out[87]= {0., {x -> 1.}}      The result comes out right in the end, but obviously something isn't right. Any ideas?


Use Output as Input

I have this function which as a result returns a point               f[x, y] =        Max[((x - #[[1]])^2 + (y - #[[2]])^2) & /@ Subscript[Rp, A0]];     min = Minimize[{f[x, y], {20 <= x <= 80, 20 <= y <= 80}}, {x, y}]        > >     {576.25, {x -> 34.5, y -> 52.}} >   How can I use this point $(x,y)$ as an input ?


Nested For Loops that result in no output

I am sure that this is not the most elegant code you will have seen, but I am trying to loop through an expression to see if `FultonHarrisn]` produces any outputs that are equal to a prime squared. My function `FultonHarris` is defined as follows:               FultonHarris[n_] := Product[(Sum[a[k], {k, i, j - 1}] + j - i)/(j - i), {j, 1, n}, {i, 1,     j - 1}]      and my for loop runs as follows, looping through `n` from `3` to `9`, and `j` from `1` to `n`, and `i` from `1` to `j-1`:               numPoints = 10; For[n = 3, n < 10, n++,      For[j = 1, j <= n, j++,       For[i = 1, i < j, i++,          a[i] := x; a[j] := y;  a[k_] /; k != {i, j} := 0;          dd[x_, y_, p_] := FultonHarris[n] - p^2;         FindInstance[         dd[xx, yy, pp] == 0 && xx > 0 && yy > 0 && PrimeQ[pp], {xx, yy,           pp}, Integers, numPoints]        ]       ]      ]      However, when I run this, it doesn't return anything, not even empty braces. Do I need to put a `Print` statement in there?


How to find the Mean of results given as a list of Rules?

How can we find the mean of the following type of data?               {{β -> 0.516819}, {β -> 0.499907},       {β -> 0.494064}, {β -> 0.472742},       {β -> 0.537485}, {β -> 0.478291},       {β -> 0.523855}, {β -> 0.483624},       {β -> 0.50126},  {β -> 0.527267}}      Which command could be used to find the mean of this data?


How to strip all formatting from a string and convert it to plain text?

The documentation on `String` states: ![Strings preserve internal formatting](http://i.stack.imgur.com/f0DA7.png) But if I try to perform some manipulations on this string, for example, take 2 words from the left, I get some shards of internal representation instead (which is understandable):               (* In[2]:= *) StringTake[%1, 8]     (* Out[2]= "\!\(\*\nStyl" *)      _Question:_ Is it possible to write a function which strips all formatting (colors, fonts, style, size, etc) from a string and returns just a plain text?


Replace inverse function

I'm solving an expression like so:               Solve[u[x] == u[a] + u[b], x]      Mathematica returns               {{x->(u^(-1))[u[a]+u[b]]}}      If I now specify the function `u` more precisely, via               % /. {u[x_] -> x}      what I get is               {{x->(u^(-1))[a+b]}}      i.e. Mathematica replaces the function but not its inverse. Is there any way of replacing the inverse appropriately as well?


when is f@g not the same as f[g]?

I have always thought that `f@g` will give the same result as `f[g]` in all cases, and it is just a matter of style which one to use and that `g` will always evaluates first, and then `f` will evaluate using the result of `g` evaluation. I never thought that there can be any precedence issue here, since no one ever mentioned it in all the times I have been using Mathematica. So I was really surprised when I found one case where this was not so. So my question is: How does one know when `f@g` is not the same as `f[g]` ? The help says nothing about this (thanks to chat room for giving me the link to this, I searched and could not find it) http://reference.wolfram.com/mathematica/ref/Prefix.html Even though one can see the word `precedence` and `grouping` but no explanation of where these are talked about and no more links to follow `Prefix[expr, h, precedence, grouping] can be used to specify how the output form should be parenthesized.` clearly this is a precedence issue. But I have never seen this mentioned before any where.               Tr[Times @@@ {{2, 3}, {4, 5}}]      ![Mathematica graphics](http://i.stack.imgur.com/YaTTM.png)               Tr @ Times @@@ {{2, 3}, {4, 5}}      ![Mathematica graphics](http://i.stack.imgur.com/cfoD2.png)               Tr @ ( Times @@@ {{2, 3}, {4, 5}} )      ![Mathematica graphics](http://i.stack.imgur.com/uNYZs.png) What seems to have happened is that in `Tr@Times@@@....` the command `Tr` grabbed `Times` before `Times` was applied. You can replaced `Tr` by `Total` also and see the same effect. ps. This is another reason for me to not use `@` too much. I I really never liked to use `@` and always liked the good old fashioned `[]` as it seems clearer also, and now safer also. **question is** : What is the rule(s) of thumb to use? One should always look ahead and check before using `@` to make sure precedence is met? Any other cases than this one might have to watch out for? If there are very few cases, may be one can add them to their cheat sheet. Where are the `precedence` of all operators listed so one can check?


Conditioned Probability Task

I have this task with two questions I would like to compute in Mathematica. > Suppose a pair of random variables $(X, Y)$ has a equal distribution on the > following 7 points: > > $\begin{matrix} & x & y\\\ 1 & -1 & 0\\\ 2 & 0 & 0\\\ 3 & 1 & 0\\\ 4 & -2& > 1\\\ 5 & 2 & 1\\\ 6 & -1 & 3\\\ 7 & 1 & 3 \end{matrix}$ > > The simultaneously probability function $p(x, y)$ is then given by: $p (1,0) > = \ldots = P (1, 3) = 1/7 \text{ and } p(x, y) = 0$ for all other points > > **1)** Find the conditional mean $E (Y\; |\; X = x)$ and the conditional > variance $V (Y\; | \;X = x)$ for $x = -2, -1,0,1,2.$ > > **2)** Compute the variance on Y and the variance on the conditional mean of > Y given X This additional information might help you:               E(X)=0     E(Y)=8/7      I have tried over and over but without any luck. Ps. I use Mathematica 8.


Converting this recursive function definition into nested sums?

Here's the recursive function I'm using:               DH[n_, k_, s_] := Sum[Binomial[k, k - j] DH[n/m^j, k - j, m + 1], {m, s, n^(1/k)}, {j, 1, k}]       DH[n_, 0, s_] := 1      Now, on paper, if I expand out the recursion of DH by hand, I know that               DH[n,1,1] == n.        I also know, expanding by hand, that               DH[n,2,1] == 2 Sum[Floor[n/k], {k, 1, Floor[n^(1/2)]}] - Floor[n^(1/2)]^2      Can Mathematica do that for me, especially for larger values (like, say, `DH[n,8,1]` or `DH[n,10,2]`)? I would like to type in `DH[n,2,1]` or `DH[n,3,1]` and get those sums, but right now, I just get a recursion depth exceeded error and no answers. * * * * * * **The following is a note, not part of the original question** Computing `DH[n,2,1]` by hand, For Mr. Wizard: _Here's our starting formula_               DH[n,2,1] = Sum[Binomial[k, k - j] DH[n/m^j, k - j, m + 1], {m, s, n^(1/k)}, {j, 1, k}]      _apply`s=1, k=2` and remove the `{j,1,k} Sum` by manually looping `j` from `1 to k`, with `k=2`_               DH[n,2,1] = Sum[ Binomial[2,1] DH[ n/m, 2-1,m+1 ] + Binomial[2,2] DH[n/m^2, 2-2, m+1],         {m,1,n^(1/2)}]      _apply binomials, simplify trivial arithmetic_               DH[n,2,1] = Sum[ 2 DH[n/m, 1,m+1] + DH[n/m^2,0,m+1], {m,1,n^(1/2)}]      _Swap in`DH[n,0,s] = 1`_                DH[n,2,1] = Sum[ 2 DH[n/m, 1,m+1] + 1, {m,1,n^(1/2)}]      _Inspection should make clear that`DH[ n/m, 1, m+1 ] is Floor[n/m] - (m+1) + 1`_               DH[n,2,1] = Sum[ 2 (Floor[n/m]-m) + 1, {m,1,n^(1/2)}]      _Distribute the`x2`_               DH[n,2,1] = Sum[ 2 Floor[n/m] - 2 m + 1, {m,1,n^(1/2)}]      _Extract the`1` from the sum_               DH[n,2,1] = Floor[n^(1/2)] + Sum[ 2 Floor[n/m] - 2 m, {m,1,n^(1/2)}]      _Use the triangle number formula`(n)(n+1)/2` to pull `-2 m` out of the sum as `-2 ( Floor[n^(1/2)] (Floor[n^(1/2)] + 1))/2`_               DH[n,2,1] = Floor[n^(1/2)] -2 ( Floor[n^(1/2)] (Floor[n^(1/2)] + 1))/2 + Sum[ 2Floor[n/m],      {m,1,n^(1/2)}]      _Cancel the`2s` outside the sum, and move the `2` inside the sum out front_               DH[n,2,1] = Floor[n^(1/2)] - ( Floor[n^(1/2)] (Floor[n^(1/2)] + 1)) + 2 Sum[ Floor[n/m],      {m,1,n^(1/2)}]      _Multiply the terms in parenthesis outside the sum_               DH[n,2,1] = Floor[n^(1/2)] - Floor[n^(1/2)]^2 - Floor[n^(1/2)] + 2 Sum[ Floor[n/m],         {m,1,n^(1/2)}]      _get rid of cancelling terms, and we are left with_               DH[n,2,1] = -Floor[n^(1/2)]^2 + 2 Sum[ Floor[n/m], {m,1,n^(1/2)}]      ...which is what I wanted to show. Check http://en.wikipedia.org/wiki/Divisor_summatory_function and you should see that is indeed the equations for D(n) when using the hyperbola method. That page mentions a generalized Divisor function, D_k(n). The k in that function corresponds to the k here - this recursive expression applies the hyperbola method to D_k(n) for any k, a whole number. By way of comparison, I have simplified `DH[x,4,2]` to               1 - Floor[x^(1/4)]^4 +       Sum[           4 (Floor[x/(u^3)] + Floor[Floor[x/u]^(1/3)]^3)           - 6 Floor[ Floor[x/(u^2)]^(1/2)]^2 +           12 (Sum [Floor[x/(u^2 s)], {s, (u + 1),        Floor[Floor[x/(u^2)]^(1/2)]}] +           Sum[Floor[x/( u s^2)] - Floor[Floor[x/(u s)]^(1/2)]^2, {s, (u + 1),         Floor[Floor[x/u]^(1/3)]}]) +           24  Sum[ Floor[x/(u m s)], {s, u + 1, (x/u)^(1/3)}, {m, s + 1, (x/(u s))^(1/2)}],        {u, 2, x^(1/4)}]      I haven't gotten up the gumption to go higher, as it's a bit exhausting to work through - thus my question.


Interpolating Function inside of NDSolve

I have a problem and it seems to be connected to an Interpolating function inside of an `NDSolv`e command. The `resistivity[x`] function inside the `NDSolve` command is an interpolation of measurement data. The code works fine with an ordinary function instead of the interpolating function. When I run the code, it does not give an error, but no results are displayed either. Does anybody know what the problem is? The code is:               xydataplot = Reap[          For[i = 1, i <= n, i++,            J = i j;            s =             NDSolve[{y'[x] == (resistivity[y[x]]  J^2)/nC              - alpha/nC (-T + y[x]), y[0] == T}, y, {x, 0, t}];            Te = y[t] /. s;            resis2 = resistivity[Te];            efeld = J resis2;            Sow[efeld];            Sow[J];            ];          ][[2, 1]]~Partition~2;


Piecewise of different functions

You know, NDsolve coupled with Piecewise can be used to solve a series of discontinuous differential equations. But what if one of the function is different? For example: $$z''(t)=\begin{cases}x(t)-(1+y(t)), & \text{if } x>(1+y) \\\ \\\ \\\ x(t)+(1+y(t)), & \text{if } x<-(1+y) \end{cases} $$ $$\rm{and}$$ $$z'(t)=0, \rm{if } |x|<(1+y) $$ I tried something like below               xyz = First@NDSolve[{x''[t] == -2.25 Cos[1.5 t] - x[t] - x'[t],      x[0] == 0, x'[0] == 0,      y''[t] == -1.125 Cos[1.5 t] - 4 y[t] - y'[t],      y[0] == 0, y'[0] == 0,      z''[t] == Piecewise[{         {x[t] - (1 + y[t]), x[t] > 1 + y[t]},          {0, Abs[x[t]] <= 1 + y[t]},          {x[t] + (1 + y[t]), x[t] < -1 - y[t]}}],      z[0] == 0},      {x, y, z}, {t, 0, 30}];      but have no idea how to correctly incorporate $z'(t)$ condition.


How to use a matrix variable for a compiled function

I want to compile the following function which takes a matrix variable.               ClusterFind =      Compile[{{Inte, _Real}, {Matrix}},      Map[If[Last@# == Inte, Take[#, 4]] &, Matrix], CompilationTarget -> "C",     RuntimeAttributes -> {Listable}, Parallelization -> True];      Here `Matrix` is a $m\times n$ matrix of real,integer or complex numbers. I also would like to know if it is possible to compile without knowing the dimension of the variable matrix beforehand. Can the `Matrix` in the above example be of `PackedArray` data type? **UPDATE** Thanks for the suggestions. I found the following compiled version most efficient as far as speed is concerned.               ClusterFind =      Compile[{{Inte, _Real}, {Matrix, _Complex, 2}},      Take[Select[Matrix, (Last@# == Inte) &], All, 4],      CompilationTarget -> "C"];      BR


MATLAB-like convolution and derivation using Mathematica

> **Possible Duplicate:**   >  Discrete Convolution I would like to be able to convolve two functions of two variables in Mathematica, and then plot derivatives (or functions of derivatives) of the solution. However, the result of the convolution is itself a function of two variables and in many cases there is no exact formula or it takes a very long time to compute. In Mathematica, is it possible to convolve two functions numerically (by this I mean compute g(x,y)*f(x,y) where x and y correspond to sets of data), obtain and take derivatives of the solution (also both sets of data)? I know the first answer will be "use MATLAB." I would prefer not to do this. If anyone has some example code where this has been done and is willing to share, I would be very grateful.


refer to result of cell above current cell?

`%` allows to refer to the result of the preceding calculation (preceding in time) but this seems not necessarily to be the cell just **above** a given cell. How can one refer to the result of the cell just above ?


Expand modulus squared

Is it possible to make a function in Mathematica that expands expressions of the form $$|z + w|^2 = |z|^2 + 2\text{Re} \overline{z}w + |w|^2?$$ Preferably it should also be able to handle things like $$\left |\sum_{i = 1}^n z_i \right |^2.$$ The last thing can obviously be mathematically deduced from the first one by consecutively applying the first equality.


How to use custom Dynamic inside Manipulate

I was wondering if it is possible to use a custom `Dynamic[var, function]` inside a `Manipulate`. The reason for the need is this: Suppose you have a time consuming computation like               timeConsuming[x_] := (Pause[1]; x)      and you want to use it in a `Manipulate`. Writing               DynamicModule[{y},      Manipulate[       y = timeConsuming[x]; {x, y, other},       {x, 0, 1},       {other, 0, 1}]      ]      entails the following issue: you have to wait for `timeConsuming` to be computed even when you change `other` and leave `x` unmodified. A (simple) solution is to code the dynamic by hand:               DynamicModule[{x = 0, y = timeConsuming[0], other = 0},      Panel@Column[{         Grid[{           {"x", Slider[Dynamic[x, (x = #; y = timeConsuming[x]) &], {0, 1}]},           {"other", Slider[Dynamic[other], {0, 1}]}           }],         Dynamic@{x, y, other}         }]      ]      This is feasible, but as a drawback makes you renounce all other `Module`'s conveniences. I tried coding something like               Module[(* result *), {x, 0, 1, some-suitable-function}]      but had no success in the attempt. A (clean) use of `Manipulate` would be much appreciated. Just to summarize, the question is: How can I make some statements be executed only when some specified controls are touched?


Solving a system of equations with conditions related to the number of solutions

The equation below describes a conic with oblique axis: $$9 + 22 x + 9 x^2 + 46 y + 24 x y + 16 y^2=0$$ It is a parabola, as the coefficients in $x^2$, $y^2$, $xy$ form a perfect square. To find the coordinates of its vertex, it's either the hard way using algebra only on paper (I summarise that at the end of my entry) or possibly an easy way with _Mathematica_.   Let me describe my _Mathematica_ approach: Looking at the $x^2$ and $y^2$ coefficients I know that the slope of the tangent to the parabola at its vertex is $4/3$ so this tangent is of the form $y = 4x/3 + b$ and it intercepts the parabola at its vertex $(x,y)$ exactly one time. When I translate this in _Mathematica_ terms, I have the following system of equations to solve:                {x, y, b} /.       Solve[{9 + 22 x + 9 x^2 + 46 y + 24 x y + 16 y^2 == 0,              y - (4/3)x - b == 0}, {x, y, b}]      which is not enough of course to find unique values for $(x,y,b)$.   Is it possible to add conditions to the above `Solve` expressions such as only one solution for $(x,y,b)$ is to be returned (or more exactly as there are squares in the expression) two solutions but identical?. On paper, I transformed with factors the equation of the parabola. End result put into _Mathematica_ :               eq1 = (3 x + 4 y + 5)^2  - 2 (4 x - 3 y + 8)       eqc = 9 + 22 x + 9 x^2 + 46 y + 24 x y + 16 y^2     eqc == eq1 // FullSimplify     tangentvertex = Reduce[4 x - 3 y + 8 == 0, y]     vertex = {x, y}/.Solve[{eqc == 0, y - 8/3 - (4 x)/3 == 0}, {x, y}] // FullSimplify      Vertex coordinates at last: > `{-47/25, 4/25}` Thanks for any answer.


Calculating the rank of a huge sparse array

By virtue of the suggestion in my previous question, I constructed the sparse matrix whose size is $518400 \times 86400$, mostly filled with $0$ and $\pm 1$. Now I want to calculate its **rank**. Since `RowReduce` requires a huge amount of memory to fill in $0$s, my first approach was to divide the matrix into many parts, e.g., each containing 144 rows ($144\times 86400$).               Module[{i, part, rank},      For [i = 0, 144 (i + 1) <= 518400, i++,        part = RowReduce[input[[144*i + 1 ;; 144 (i + 1)]]];        rank = MatrixRank[part];        If[i == 0, result = part[[1 ;; rank]],          result = Join[result, part[[1 ;; rank]]]]        ];      ]      Unfortunately, this does not work because all rows in each part are linearly independent so that the number of rows does not decrease. Does anyone have such an experience? Should I export the matrix to the file and calculate its rank via other language / packages? If so, any suggestion?


Elegant solution to the Zebra [logic] Puzzle ("Einstein's Riddle")

The famous Zebra Puzzle (Wikipedia), often called "Einstein's Riddle," is a logic puzzle that can be solved deductively by applying a list of logical rules. One version of the riddle (from Wikipedia) begins: >   1. There are five houses. >   2. The Englishman lives in the red house. >   3. The Spaniard owns the dog. ... > The idea is that there are five houses, painted different colors, with occupants (one in each house) of different nationalities each of whom smokes a different brand, drinks a different beverage, and keeps a different pet. Given the "clues," the puzzle asks which resident owns the zebra. Given that Mathematica is a rule-based language, it seems that there should be a way of solving the puzzle without resorting to brute-force (i.e. while loops or searching). Can Mathematica be used to elegantly deduce the solution? How?


Can I put subscripted parameter values into a package?

When defining packages, can I put parameter values alone or along with functions into a package in subscripted form?               BeginPackage["Myfunction`"];      Subscript[q, 1] = 0;     Subscript[q, 2] = 0.5;     myfunction::usage ="...";     Begin["`Private`"];     myfunction[ak__List] := blablabla...;     End[];     EndPackage[];      Because these global subscripted parameters in the package are needed in many programs, I separated them from the main programs and put them into a single package. In the main programs, I only need to load the package rather than bothering to redefine these parameters again. For plain symbols, it works fine. But whem it comes to subscripted symbols, it fails. And I found that is because I used                 Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]];      in the main program. subscripted symbols like                 Subscript[q, 1]       are transformed into                 q_Subscript_1      I also tried to use Symbolize function in the package, but it fails. The clarity for using subscripted symbols made me reluctant to avoid them.


Triangle mapped on a sphere in $\mathbb R^3$?

How can I map a triangle on an sphere? I want to visualize (plot or animate) it for my student in my Non Euclidean geometry. I have no restrictions on the triangle's kind or on the sphere in $\mathbb R^3$. Thanks for any hint.


DSolve does not solve my system of PDEs

I am a long time Maple user who had just recently got hands on _Mathematica_. I have a "simple" system of PDEs, one can be solved easily. But I cant seem to get it work in _Mathematica_. I am nos sure whether I'm having a synatex problem or it's just not doable in _Mathematica_.               FF = f[a, b, c, d]          eq1 = D[FF, d] + (1 - a)*D[FF, a]/d == 0          eq2 = D[FF, c] + (b - (a - 1)*d)*D[FF, a]/(c*d) == 0          eq3 = D[FF, b] + D[FF, a]/d == 0          DSolve[{eq1, eq2, eq3}, {FF}, {a, b, c, d}]      ![Mathematica does not work](http://i.stack.imgur.com/SL7pI.png) Tried using different parameters to avoid the double subscript ![Tried using different parameters to avoid the double subscript](http://i.stack.imgur.com/CyHVM.png) Here is how it works in Maple: ![Maple works fine](http://i.stack.imgur.com/63Em1.png) Thanks The Mathematica Notebook is here Mathematica NB


Limit the output of financial indicators list

Imagine I have a list of Forex data as below:               data= {{"2014 06 30  07:49", {1.36535, 1.36525, 1.36543, 1.36542, 81}},             {"2014 06 30  07:50", {1.36543, 1.3654, 1.36545, 1.36544, 25}},             {"2014 06 30  07:51", {1.36544, 1.36544, 1.36562, 1.36552, 116}}      The list has different sizes in different case. Then using `FinancialIndicator["WildersMovingAverage", i][data]` you can get a list of `WildersMovingAverage` given period `i`. The output of this function is a list. My question is how one may limit the function in order to just compute the value of `WildersMovingAverage` for last data point and not to compute the whole list which is time consuming when the list is huge?


Multi-Camera streaming using Mathematica

I am attempting to capture dynamic streams from multiple usb webcams using only mathematica. Using `ImageCapture["Device" -> $ImagingDevices[[x]]`, I've tried to open multiple instances of _Mathematica_ using ImageCapture on different devices for the different instances. No Luck :( Is this too complex a task for _Mathematica_ alone?) Wolfram Community related question link


Replacing matrix values

I want to find the n largest values in a matrix and replace all others with zero. The solution I found uses `ReplaceAll` and becomes very slow as the size of matrices grows:               FindLargestValues[m_?MatrixQ, n_Integer] :=       With[{v = (Union @ Flatten @ m)[[-n]]},         m /. x_Real /; x < v :> 0]      Example:               (small = RandomReal[{1, 10}, {5, 5}]) // MatrixForm      ![enter image description here](http://i.stack.imgur.com/Sb5tz.jpg)               FindLargestValues[small, 10] // MatrixForm      ![enter image description here](http://i.stack.imgur.com/xGhvU.jpg) Timing example:               large = RandomReal[{1, 10}, {50, 50}];          Do[FindLargestValues[large, 50], {1000}]; // Timing // First      > 2.574016 Is there a faster way to do this?


What is the default ColorFunction for 3D plots?

This should be a really simple question, but it isn't in the documentation for some perverse reason. I like the default `ColorFunction` that _Mathematica_ uses for `Plot3D` and the like. I'd like to use the same color scheme for other _Mathematica_ plots that don't have it as the automatic default. However, after looking through all of the Color Gradients listed by `ColorData["Gradients"]` I can't find any that match the effect of just setting `ColorFunction->Automatic`. My question: What does _Mathematica_ call its default color palette, why isn't it listed in `ColorData`, and how can I access it to apply it to other plots?


ParametricPlot with DSolve does not show anything

I manage to plot strn[t] and sig[t] where sig[t] is the solution from my DSolve. However, when I want to ParametricPlot sig[t] vs strn[t], I failed to do it as the parametric plot does not show anything.               strn[t] = t*0.00025;     modulus = 20000;     sol1 = DSolve[{D[strn[t], t] == D[sig[t], t]/modulus, sig[0] == 0}, sig[t], t]     Plot[strn[t], {t, 0, 100}]     Plot[sig[t] /. sol1, {t, 0, 100}]     ParametricPlot[{sig[t] /. sol1, strn[t]}, {t, 0, 10}]      Can someone please tell me why?


Inconsistent results in fits from NArgMin

EDIT: Just realized I had misspelled "inconsistent." I'm using version 7.0. I'm trying to fit a (noisy) data set to a large-order polynomial. (Just for context: there isn't a model for the data, and I need to find the minimum of the derivative, which is much easier with a polynomial that bypasses some of the noise.) The derivative of the data should always be positive, but noise in the data can cause it to appear to have a local minimum. This consistently happens at low x-values of the data (not a problem) and at higher x-values (the part I'm interested in). It's actually pretty difficult to find the best fit with a constraint like that on the derivative; I was lucky enough to find this previous question and started from there. Since I've had trouble reproducing this with a simpler set of data, I'm including the data that's causing the problem as well as my attempt. Sorry about that :\               data={{-7.60206, -5.90028}, {-7.20412, -6.32711}, {-7.05799, -6.24573}, \     {-6.90309, -8.23214}, {-6.727, -6.25497}, {-6.67264, -6.0359}, \     {-6.62434, -7.09815}, {-6.60206, -6.74033}, {-6.58087, -6.9319}, \     {-6.50515, -6.00988}, {-6.47173, -5.89132}, {-6.42597, -6.61755}, \     {-6.41173, -6.8024}, {-6.39794, -7.15367}, {-6.38458, -6.50378}, \     {-6.35902, -6.08738}, {-6.33489, -6.03554}, {-6.30103, -6.94662}, \     {-6.27984, -7.61019}, {-6.26962, -6.91566}, {-6.24988, -6.00816}, \     {-6.23099, -6.14881}, {-6.20412, -7.65494}, {-6.18709, -6.84911}, \     {-6.17881, -7.91219}, {-6.16273, -6.09495}, {-6.14722, -6.48424}, \     {-6.12494, -6.66752}, {-6.11776, -6.91584}, {-6.10375, -6.39662}, \     {-6.07058, -7.19377}, {-6.05799, -6.65843}, {-6, -6.80801}, \     {-5.98928, -7.18128}, {-5.95861, -6.81322}, {-5.9393, -7.01644}, \     {-5.89449, -6.82349}, {-5.87778, -6.55417}, {-5.86967, -6.74259}, \     {-5.83863, -6.76216}, {-5.82391, -7.12595}, {-5.81673, -7.83024}, \     {-5.80272, -6.71336}, {-5.75696, -6.77054}, {-5.73283, -7.41132}, \     {-5.72125, -6.87451}, {-5.69897, -6.64371}, {-5.66756, -6.78701}, \     {-5.65758, -6.83261}, {-5.64782, -7.04809}, {-5.62893, -8.12271}, \     {-5.61083, -6.81729}, {-5.59346, -7.58534}, {-5.58503, -7.65891}, \     {-5.56864, -6.98094}, {-5.5157, -6.928}, {-5.50169, -6.98523}, \     {-5.4437, -6.9454}, {-5.4318, -7.17851}, {-5.38722, -7.31544}, \     {-5.27572, -7.36563}, {-5.25964, -7.53078}, {-5.22185, -7.11725}, \     {-5.18046, -7.66833}, {-5.16749, -7.64004}, {-5.14267, -7.4718}, \     {-5.11919, -7.46749}, {-5.07572, -9.05899}, {-5.0655, -7.38326}, \     {-5.04576, -7.79535}, {-5.02687, -7.01003}, {-5, -7.47527}, \     {-4.95078, -7.14359}, {-4.9431, -7.44334}, {-4.90658, -7.12264}, \     {-4.85387, -7.25088}, {-4.80688, -7.77359}, {-4.78516, -8.05067}, \     {-4.76447, -8.07252}, {-4.72584, -7.33981}, {-4.70774, -6.99741}, \     {-4.69037, -7.45587}, {-4.63451, -7.42141}, {-4.62709, -7.89697}, \     {-4.61979, -7.52025}, {-4.61261, -8.00335}, {-4.5784, -7.78812}, \     {-4.56543, -7.40386}, {-4.49485, -7.813}, {-4.47366, -7.16346}, \     {-4.46344, -7.41719}, {-4.45346, -7.40907}, {-4.40671, -7.47877}, \     {-4.38934, -8.33093}, {-4.38091, -7.22819}, {-4.35655, -7.74591}, \     {-4.32606, -7.95015}, {-4.31876, -7.74146}, {-4.27737, -7.78947}, \     {-4.22768, -8.35667}, {-4.2161, -7.79398}, {-4.19382, -8.42667}, \     {-4.17263, -7.2905}, {-4.16241, -8.96208}, {-4.15243, -7.80177}, \     {-4.14267, -7.95211}, {-4.11464, -7.71493}, {-4.07988, -7.54309}, \     {-4.0716, -7.63749}, {-4.06349, -7.86216}, {-4.04769, -7.92244}, \     {-4.02503, -7.52806}, {-4.01773, -7.8399}, {-3.99568, -7.93923}, \     {-3.97469, -8.35667}, {-3.96257, -8.13847}, {-3.9393, -8.43652}, \     {-3.90309, -8.75796}, {-3.89279, -8.1729}, {-3.88273, -7.92428}, \     {-3.8729, -8.31709}, {-3.86012, -8.59314}, {-3.85078, -7.85531}, \     {-3.83268, -7.93671}, {-3.81248, -7.82018}, {-3.8041, -8.00778}, \     {-3.79588, -8.06567}, {-3.78781, -8.06229}, {-3.76955, -8.69581}, \     {-3.76195, -7.8496}, {-3.75449, -7.86858}, {-3.74715, -8.20325}, \     {-3.73993, -7.70706}, {-3.73049, -7.62317}, {-3.72354, -7.72065}, \     {-3.7167, -8.27666}, {-3.69465, -7.76037}, {-3.68825, -7.76928}, \     {-3.67572, -7.67484}, {-3.66154, -8.02366}, {-3.64975, -8.23589}, \     {-3.63827, -7.93107}, {-3.62525, -7.50342}, {-3.61439, -7.75411}, \     {-3.60206, -7.77489}, {-3.59176, -7.76971}, {-3.5817, -7.81586}, \     {-3.57025, -7.46451}, {-3.56067, -8.15378}, {-3.54975, -7.59961}, \     {-3.54061, -7.53351}, {-3.53165, -7.61588}, {-3.52143, -8.01452}, \     {-3.51286, -7.76544}, {-3.50307, -7.50226}, {-3.49485, -7.92735}, \     {-3.48678, -7.53301}, {-3.47756, -7.6037}, {-3.4698, -7.59014}, \     {-3.46092, -7.61198}, {-3.45346, -7.50342}, {-3.44612, -7.35343}, \     {-3.43771, -7.75246}, {-3.43063, -7.72065}, {-3.42251, -7.95802}, \     {-3.41567, -7.56719}, {-3.40894, -7.47331}, {-3.40121, -7.57152}, \     {-3.39469, -7.48833}, {-3.38722, -7.46707}, {-3.37469, -7.4033}, \     {-3.36151, -7.65035}, {-3.34872, -7.43076}, {-3.3363, -7.48253}, \     {-3.32422, -7.35195}, {-3.31336, -7.36444}, {-3.3019, -7.41038}, \     {-3.29073, -7.36041}, {-3.27984, -7.41529}, {-3.26922, -7.29265}, \     {-3.25964, -7.24932}, {-3.24949, -7.35146}, {-3.23958, -7.35113}, \     {-3.22988, -7.16049}, {-3.2204, -7.3206}, {-3.21183, -7.23806}, \     {-3.20273, -7.20416}, {-3.19382, -7.24997}, {-3.18509, -7.24803}, \     {-3.17653, -7.14634}, {-3.16877, -7.10937}, {-3.16052, -7.17391}, \     {-3.15243, -7.13803}, {-3.14448, -7.11725}, {-3.13668, -7.19217}, \     {-3.1296, -7.13175}, {-3.12205, -7.12332}, {-3.11464, -7.07218}, \     {-3.10735, -7.09241}, {-3.10018, -7.04678}, {-3.09366, -7.07227}, \     {-3.08672, -7.07253}, {-3.07314, -7.07348}, {-3.06048, -7.00128}, \     {-3.04769, -7.01659}, {-3.03527, -6.96567}, {-3.02365, -6.935}, \     {-3.01189, -6.95611}, {-3.00087, -6.95308}, {-2.9897, -6.93702}, \     {-2.97881, -6.91176}, {-2.96859, -6.90015}, {-2.95821, -6.9111}, \     {-2.94846, -6.89271}, {-2.93855, -6.8787}, {-2.92885, -6.86577}, \     {-2.91973, -6.864}, {-2.91045, -6.83028}, {-2.9017, -6.80614}, \     {-2.89279, -6.8052}, {-2.88406, -6.8232}, {-2.87582, -6.79925}, \     {-2.86742, -6.76766}, {-2.85949, -6.77332}, {-2.8514, -6.75764}, \     {-2.84345, -6.74061}, {-2.83594, -6.7553}, {-2.82827, -6.73816}, \     {-2.82102, -6.7275}, {-2.81361, -6.75098}, {-2.80632, -6.73848}, \     {-2.79942, -6.7172}, {-2.79237, -6.70536}, {-2.78569, -6.71977}, \     {-2.77211, -6.69684}, {-2.7592, -6.69571}, {-2.74666, -6.68624}, \     {-2.73447, -6.66456}, {-2.72262, -6.67177}, {-2.71086, -6.65361}, \     {-2.69962, -6.64591}, {-2.68867, -6.65048}, {-2.67799, -6.64835}, \     {-2.66756, -6.64439}, {-2.65718, -6.64516}, {-2.64724, -6.63901}, \     {-2.63752, -6.64361}, {-2.62801, -6.64287}, {-2.6187, -6.63583}, \     {-2.60942, -6.63402}, {-2.6005, -6.62981}, {-2.59176, -6.64484}, \     {-2.58319, -6.64474}, {-2.57479, -6.65147}, {-2.56639, -6.65002}, \     {-2.5583, -6.64274}, {-2.55037, -6.64187}, {-2.54257, -6.64871}, \     {-2.53491, -6.63834}, {-2.52724, -6.65454}, {-2.51985, -6.66038}, \     {-2.51258, -6.65696}, {-2.50543, -6.65914}, {-2.49839, -6.64055}, \     {-2.49134, -6.65408}, {-2.48452, -6.65424}, {-2.47121, -6.6424}, \     {-2.45817, -6.63535}, {-2.44563, -6.63281}, {-2.43344, -6.62368}, \     {-2.42148, -6.61031}, {-2.40994, -6.59431}, {-2.39859, -6.57061}, \     {-2.38764, -6.55078}, {-2.37696, -6.538}, {-2.36643, -6.51422}, \     {-2.35625, -6.49867}, {-2.34621, -6.47369}, {-2.33649, -6.46208}, \     {-2.32698, -6.43439}, {-2.31758, -6.41997}, {-2.30848, -6.40473}, \     {-2.29947, -6.393}, {-2.29073, -6.37805}, {-2.28216, -6.37162}, \     {-2.27368, -6.36121}, {-2.26544, -6.34662}, {-2.25727, -6.34753}, \     {-2.24934, -6.34287}, {-2.24154, -6.34032}, {-2.23381, -6.33989}, \     {-2.22629, -6.34378}, {-2.21882, -6.34209}, {-2.21155, -6.34217}, \     {-2.2044, -6.34847}, {-2.19729, -6.35258}, {-2.19037, -6.35258}, \     {-2.18349, -6.35968}, {-2.17018, -6.36461}, {-2.1572, -6.36892}, \     {-2.1446, -6.36796}, {-2.13236, -6.36432}, {-2.12045, -6.35925}, \     {-2.10891, -6.34518}, {-2.09762, -6.33549}, {-2.08661, -6.31951}, \     {-2.07588, -6.3087}, {-2.0654, -6.29828}, {-2.05522, -6.29348}, \     {-2.04523, -6.29345}, {-2.03546, -6.30076}, {-2.0259, -6.31038}, \     {-2.01655, -6.32847}, {-2.00745, -6.34783}, {-1.99848, -6.37117}, \     {-1.9897, -6.39458}, {-1.98109, -6.41923}, {-1.97265, -6.43722}, \     {-1.96441, -6.44987}, {-1.95628, -6.45579}, {-1.94831, -6.45369}, \     {-1.94047, -6.44678}, {-1.93278, -6.43521}, {-1.92526, -6.42661}, \     {-1.91783, -6.41699}, {-1.91052, -6.41109}, {-1.90333, -6.40588}, \     {-1.89626, -6.41371}, {-1.88934, -6.42107}, {-1.8825, -6.43708}, \     {-1.86912, -6.47919}, {-1.85617, -6.52883}, {-1.84357, -6.55976}, \     {-1.83133, -6.5558}, {-1.81944, -6.51556}, {-1.80785, -6.4633}, \     {-1.79659, -6.42203}, {-1.78558, -6.39845}, {-1.77485, -6.39715}, \     {-1.7644, -6.4092}, {-1.75417, -6.41564}, {-1.7442, -6.40869}, \     {-1.73443, -6.3793}, {-1.72487, -6.33557}, {-1.71555, -6.29011}, \     {-1.70639, -6.25807}, {-1.69745, -6.24437}, {-1.68867, -6.2509}, \     {-1.68006, -6.26612}, {-1.67164, -6.27975}, {-1.66336, -6.28322}, \     {-1.65525, -6.26844}, {-1.64728, -6.24355}, {-1.63944, -6.22114}, \     {-1.63177, -6.20663}, {-1.62421, -6.2108}, {-1.6168, -6.23096}, \     {-1.60949, -6.26405}, {-1.6023, -6.29625}, {-1.59525, -6.31671}, \     {-1.5883, -6.31662}, {-1.58147, -6.3016}, {-1.56809, -6.27854}, \     {-1.55513, -6.30344}, {-1.54254, -6.33983}, {-1.53031, -6.32322}, \     {-1.51841, -6.26627}, {-1.50682, -6.24411}, {-1.49554, -6.25615}, \     {-1.48455, -6.23942}, {-1.47383, -6.17853}, {-1.46337, -6.13769}, \     {-1.45314, -6.14292}, {-1.44315, -6.15919}, {-1.4334, -6.14313}, \     {-1.42385, -6.11713}, {-1.41452, -6.12631}, {-1.40536, -6.16569}, \     {-1.39641, -6.18248}, {-1.38764, -6.16451}, {-1.37904, -6.15518}, \     {-1.37061, -6.17622}, {-1.36233, -6.18461}, {-1.35421, -6.14501}, \     {-1.34625, -6.10036}, {-1.33842, -6.08757}, {-1.33074, -6.08959}, \     {-1.32318, -6.06436}, {-1.31576, -6.02264}, {-1.30846, -6.00601}, \     {-1.30128, -6.0189}, {-1.29422, -6.02749}, {-1.28727, -6.01383}, \     {-1.28043, -6.00676}, {-1.26707, -6.05246}, {-1.2541, -6.04137}, \     {-1.24151, -6.04864}, {-1.22928, -6.00765}, {-1.21738, -5.96689}, \     {-1.2058, -5.93204}, {-1.19451, -5.90199}, {-1.18352, -5.90146}, \     {-1.1728, -5.89875}, {-1.16233, -5.92488}, {-1.15211, -5.91532}, \     {-1.14212, -5.9226}, {-1.13237, -5.88736}, {-1.12282, -5.86103}, \     {-1.11348, -5.82132}, {-1.10434, -5.80047}, {-1.09538, -5.79469}, \     {-1.08661, -5.79257}, {-1.07801, -5.80953}, {-1.06958, -5.80259}, \     {-1.06131, -5.80503}, {-1.05318, -5.77427}, {-1.04522, -5.7585}, \     {-1.03739, -5.72601}, {-1.0297, -5.71595}, {-1.02215, -5.70825}, \     {-1.01473, -5.70799}, {-1.00743, -5.71207}, {-1.00025, -5.70483}, \     {-0.993188, -5.70018}, {-0.98624, -5.67431}, {-0.979398, -5.66444}, \     {-0.966038, -5.63829}, {-0.953072, -5.63347}, {-0.940482, -5.62353}, \     {-0.928247, -5.59392}, {-0.916347, -5.56682}, {-0.904768, -5.56074}, \     {-0.893486, -5.55977}, {-0.88249, -5.5387}, {-0.871766, -5.50732}, \     {-0.8613, -5.49268}, {-0.851083, -5.49433}, {-0.841098, -5.48539}, \     {-0.831338, -5.45912}, {-0.821792, -5.43721}, {-0.812451, -5.43104}, \     {-0.80331, -5.42785}, {-0.794355, -5.41191}, {-0.78558, -5.39096}, \     {-0.776979, -5.37989}, {-0.768546, -5.37566}, {-0.760275, -5.36394}, \     {-0.752157, -5.34505}, {-0.744187, -5.33322}, {-0.736362, -5.32963}, \     {-0.728674, -5.32043}, {-0.721123, -5.30286}, {-0.713699, -5.28876}, \     {-0.706399, -5.28529}, {-0.69922, -5.28199}, {-0.692158, -5.26763}, \     {-0.68521, -5.24964}, {-0.678371, -5.24109}, {-0.665006, -5.2306}, \     {-0.652042, -5.20638}, {-0.639452, -5.19457}, {-0.627217, -5.17444}, \     {-0.615319, -5.1607}, {-0.603736, -5.14226}, {-0.592456, -5.13065}, \     {-0.58146, -5.11305}, {-0.570736, -5.10147}, {-0.560271, -5.08776}, \     {-0.550051, -5.07206}, {-0.540068, -5.06321}, {-0.530308, -5.04697}, \     {-0.520762, -5.03815}, {-0.511422, -5.02446}, {-0.502279, -5.01468}, \     {-0.493325, -5.00185}, {-0.48455, -4.99366}, {-0.475949, -4.98007}, \     {-0.467517, -4.97234}, {-0.459244, -4.96171}, {-0.451127, -4.95081}, \     {-0.443157, -4.94383}, {-0.435332, -4.93212}, {-0.427645, -4.92523}, \     {-0.420092, -4.91513}, {-0.412669, -4.90733}, {-0.405369, -4.89753}, \     {-0.39819, -4.89191}, {-0.391129, -4.88128}, {-0.384179, -4.87593}, \     {-0.377341, -4.86739}, {-0.363976, -4.85303}, {-0.351011, -4.83878}, \     {-0.338422, -4.82565}, {-0.326188, -4.81316}, {-0.314289, -4.80114}, \     {-0.302706, -4.78971}, {-0.291425, -4.77868}, {-0.28043, -4.76819}, \     {-0.269706, -4.75792}, {-0.259241, -4.74798}, {-0.249021, -4.7385}, \     {-0.239037, -4.72924}, {-0.229278, -4.7201}, {-0.219732, -4.71146}, \     {-0.210392, -4.7033}, {-0.201249, -4.69572}, {-0.192294, -4.68787}, \     {-0.18352, -4.68039}, {-0.17492, -4.67327}, {-0.166487, -4.66616}, \     {-0.158214, -4.65948}, {-0.150096, -4.65317}, {-0.142127, -4.64682}, \     {-0.134302, -4.64059}, {-0.126615, -4.63473}, {-0.119062, -4.6292}, \     {-0.111638, -4.62373}, {-0.104339, -4.61836}, {-0.0971603, -4.61337}, \     {-0.0900986, -4.60855}, {-0.0831493, -4.60343}, {-0.07631, -4.59873}, \     {-0.0629462, -4.58964}, {-0.049981, -4.58088}, {-0.037392, -4.57269}, \     {-0.0251578, -4.56487}, {-0.0132583, -4.55743}, {-0.00167657, \     -4.55083}, {0.0096047, -4.54454}, {0.0205999, -4.53893}, {0.0313236, \     -4.53337}, {0.0417893, -4.52825}, {0.0520083, -4.52332}, {0.0619927, \     -4.51822}, {0.0717524, -4.51344}, {0.0812976, -4.50889}, {0.0906379, \     -4.50455}, {0.0997811, -4.50059}, {0.108736, -4.49674}, {0.11751, \     -4.49265}, {0.12611, -4.48908}, {0.134543, -4.48549}, {0.142816, \     -4.48249}, {0.150934, -4.47944}, {0.158903, -4.47637}, {0.166728, \     -4.47342}, {0.174415, -4.4706}, {0.181968, -4.46742}, {0.189392, \     -4.46434}, {0.196691, -4.46137}, {0.20387, -4.45885}, {0.210932, \     -4.45637}, {0.21788, -4.45369}, {0.22472, -4.45128}, {0.238084, \     -4.4462}, {0.251049, -4.44101}, {0.263638, -4.43577}, {0.275872, \     -4.43012}, {0.287772, -4.42478}, {0.299353, -4.41977}, {0.310634, \     -4.41556}, {0.32163, -4.41204}, {0.332354, -4.40875}, {0.342819, \     -4.40574}, {0.353038, -4.40279}, {0.363023, -4.40021}, {0.372782, \     -4.39779}, {0.382328, -4.39527}, {0.391668, -4.39256}, {0.400811, \     -4.39048}, {0.409766, -4.38866}, {0.41854, -4.38663}, {0.42714, \     -4.38516}, {0.435573, -4.3833}, {0.443846, -4.38112}, {0.451964, \     -4.37841}, {0.459933, -4.37602}, {0.467758, -4.37398}, {0.475445, \     -4.37215}, {0.482998, -4.37002}, {0.490422, -4.36768}, {0.497721, \     -4.36579}, {0.5049, -4.3635}, {0.511962, -4.36165}, {0.518911, \     -4.36083}, {0.52575, -4.36591}, {0.539114, -4.37695}, {0.552079, \     -4.38624}, {0.564668, -4.39179}, {0.576902, -4.39043}, {0.588802, \     -4.39048}, {0.600384, -4.39417}, {0.611665, -4.39192}, {0.62266, \     -4.38866}, {0.633384, -4.37718}, {0.643849, -4.36093}, {0.654068, \     -4.33669}, {0.664053, -4.32032}, {0.673812, -4.31347}, {0.683358, \     -4.31332}, {0.692698, -4.31251}, {0.701841, -4.31158}, {0.710796, \     -4.31023}, {0.71957, -4.3079}, {0.72817, -4.31828}, {0.736603, \     -4.33206}, {0.744876, -4.34439}, {0.752994, -4.35617}, {0.760963, \     -4.35984}, {0.768788, -4.36454}, {0.776475, -4.3641}, {0.784028, \     -4.35747}, {0.791452, -4.35255}, {0.798751, -4.34871}, {0.80593, \     -4.3443}, {0.812992, -4.33782}, {0.81994, -4.33342}, {0.82678, \     -4.33645}, {0.840144, -4.3371}, {0.853109, -4.33312}, {0.865698, \     -4.33385}, {0.877932, -4.31409}, {0.889832, -4.28469}, {0.901414, \     -4.27696}, {0.912695, -4.27538}, {0.92369, -4.27261}, {0.934414, \     -4.27074}, {0.944879, -4.26815}, {0.955098, -4.27633}, {0.965083, \     -4.28695}, {0.974842, -4.3028}, {0.984388, -4.30428}, {0.993728, \     -4.28852}, {1.00287, -4.28339}, {1.01183, -4.26882}, {1.0206, \     -4.26852}, {1.0292, -4.28874}, {1.03763, -4.30999}, {1.04591, \     -4.34026}, {1.05402, -4.34564}, {1.06199, -4.33417}, {1.06982, \     -4.31732}, {1.0775, -4.3048}, {1.08506, -4.28295}, {1.09248, \     -4.26599}, {1.09978, -4.28068}, {1.10696, -4.31298}, {1.11402, \     -4.33177}, {1.12097, -4.32824}, {1.12781, -4.30647}, {1.14117, \     -4.25651}, {1.15414, -4.22247}, {1.16673, -4.22796}, {1.17896, \     -4.29991}, {1.19086, -4.30709}, {1.20244, -4.30735}, {1.21372, \     -4.31431}, {1.22472, -4.3091}, {1.23544, -4.27057}, {1.24591, \     -4.21295}, {1.25613, -4.1817}, {1.26611, -4.18344}, {1.27587, \     -4.18317}, {1.28542, -4.18257}, {1.29476, -4.1835}, {1.3039, \     -4.18194}, {1.31286, -4.18449}, {1.32163, -4.18843}, {1.33023, \     -4.19232}, {1.33866, -4.19326}, {1.34694, -4.19159}, {1.35505, \     -4.18504}, {1.36302, -4.18344}, {1.37085, -4.18041}, {1.37853, \     -4.17377}, {1.38609, -4.21639}, {1.39351, -4.26059}, {1.40081, \     -4.28928}, {1.40799, -4.27665}, {1.41505, -4.22666}, {1.422, \     -4.1761}, {1.42884, -4.17782}, {1.4422, -4.16613}, {1.45517, \     -4.17583}, {1.46776, -4.1726}, {1.47999, -4.21981}, {1.49189, \     -4.29252}, {1.50347, -4.30803}, {1.51475, -4.34688}, {1.52575, \     -4.29175}, {1.53647, -4.27055}, {1.54694, -4.21275}, {1.55716, \     -4.17283}, {1.56714, -4.21776}, {1.5769, -4.1952}, {1.58645, \     -4.16187}, {1.59579, -4.19783}, {1.60493, -4.16365}, {1.61389, \     -4.17921}, {1.62266, -4.27348}, {1.63126, -4.31112}, {1.63969, \     -4.2974}, {1.64797, -4.25625}, {1.65608, -4.20345}, {1.66405, \     -4.20957}, {1.67188, -4.19068}, {1.67956, -4.11956}, {1.68712, \     -4.13562}, {1.69454, -4.21543}, {1.70184, -4.18477}, {1.70902, \     -4.25779}, {1.71608, -4.28487}, {1.72303, -4.27459}, {1.72987, \     -4.28326}, {1.74323, -4.25068}, {1.7562, -4.27135}, {1.76879, \     -4.28912}, {1.78102, -4.32662}, {1.79292, -4.31143}, {1.8045, \     -4.35274}, {1.81578, -4.29717}, {1.82678, -4.29271}, {1.8375, \     -4.31687}, {1.84797, -4.32874}, {1.85819, -4.25051}, {1.86817, \     -4.21378}, {1.87793, -4.24568}, {1.88748, -4.17369}, {1.89682, \     -4.18327}, {1.90596, -4.29785}, {1.91492, -4.26084}, {1.92369, \     -4.22121}, {1.93229, -4.22309}, {1.94072, -4.2172}, {1.949, \     -4.22707}, {1.95711, -4.32227}, {1.96508, -4.40666}, {1.97291, \     -4.27942}, {1.98059, -4.25027}, {1.98815, -4.31823}, {1.99557, \     -4.25654}, {2.00287, -4.28529}, {2.01005, -4.28781}, {2.01711, \     -4.24779}, {2.02406, -4.23673}, {2.0309, -4.13488}, {2.04426, \     -4.08296}, {2.05723, -4.2324}, {2.06982, -4.17255}, {2.08205, \     -4.19828}, {2.09395, -4.13272}, {2.10553, -4.19443}, {2.11681, \     -4.14937}, {2.12781, -4.22916}, {2.13853, -4.10431}, {2.149, \     -4.14669}, {2.15922, -4.33392}, {2.1692, -4.22209}, {2.17896, \     -4.11348}, {2.18851, -4.23143}, {2.19785, -4.31207}, {2.20699, \     -4.18715}, {2.21595, -4.21967}, {2.22472, -4.2331}, {2.23332, \     -4.10382}, {2.24175, -4.03334}, {2.25003, -4.12132}, {2.25814, \     -4.10954}, {2.26611, -4.10093}, {2.27394, -3.98143}, {2.28162, \     -3.96581}, {2.28918, -3.93108}, {2.2966, -3.86353}, {2.3039, \     -3.90121}, {2.31108, -4.14699}, {2.31814, -4.16986}, {2.32509, \     -4.06914}, {2.33193, -4.09747}, {2.34529, -4.13102}, {2.35826, \     -4.10327}, {2.37085, -4.03584}, {2.38308, -4.11951}, {2.39498, \     -3.98065}, {2.40656, -3.86725}, {2.41784, -3.87111}, {2.42884, \     -3.90806}, {2.43956, -4.10791}, {2.45003, -4.17971}, {2.46025, \     -4.00339}, {2.47023, -4.02952}, {2.47999, -4.09248}, {2.48954, \     -4.05987}, {2.49888, -3.82593}, {2.50802, -3.76067}, {2.51698, \     -3.86685}, {2.52575, -3.84597}, {2.53435, -3.8714}, {2.54278, \     -3.91248}, {2.55106, -3.86843}, {2.55917, -3.74494}, {2.57497, \     -3.88662}, {2.58265, -3.84542}, {2.59021, -3.8864}, {2.59763, \     -3.77177}, {2.60493, -3.76896}, {2.61211, -3.69489}, {2.61917, \     -3.80791}, {2.63296, -3.76332}, {2.64632, -3.71202}, {2.65929, \     -4.13497}, {2.68411, -3.7482}, {2.69601, -3.87555}, {2.70759, \     -3.90333}, {2.74059, -4.06462}, {2.75106, -3.90174}};      Here is my attempt to fit it with an order-4 polynomial:               Clear[a,b,c,d,e]     {a,b,c,d,e}=NArgMin[{Norm[Function[{x,y},\[FormalA]+\[FormalB] x+\[FormalC] x^2+ \     \[FormalD] x^3+\[FormalE] x^4-y]@@@data],Function[{x,y},\[FormalB]+2 \[FormalC] x \     +3 \[FormalD] x^2+4 \[FormalE] x^3>0]@@@data},{\[FormalA],\[FormalB],\[FormalC], \     \[FormalD],\[FormalE]}]      The coefficients this gives are               {a,b,c,d,e}={-5.01894, 0.720639, -0.0207154, -0.0210971, -0.00153312}      and the polynomial both approximately fits the data and has an always-positive derivative. Here is an attempt with an order-5 polynomial:               Clear[a,b,c,d,e,f]     {a,b,c,d,e,f}=NArgMin[{Norm[Function[{x,y},\[FormalA]+\[FormalB] x+\[FormalC] \      x^2+\[FormalD] x^3+\[FormalE] x^4+\[FormalF] x^5-y]@@@data],Function[{x,y},\[FormalB]+ \     2 \[FormalC] x+3 \[FormalD] x^2+4 \[FormalE] x^3+5 \[FormalF] x^4>0]@@@data},{\[FormalA], \     \[FormalB],\[FormalC],\[FormalD],\[FormalE],\[FormalF]}]      It's exactly the same as before except that there is a term `f x^5`. It gives the error message `NArgMin::nsol : There are no points that satisfy the constraints` {a number of terms equal to Length[data], each of which is the derivative constraint evaluated at the x-value for a particular point}. However there obviously is a solution that satisfies the constraints, since in the worst case setting `f=0` would duplicate the order-4 fit which I've already established works. Based on some experimenting with the fit _without_ constraining the derivative to always be positive, I expect that in order to satisfactorily fit the data I will need to use a polynomial of order about 20. That might present problems of its own, but I'll almost surely run into this particular one again unless I figure out how to fix it. Also, because fitting the order-4 polynomial takes about a minute, any suggestions on how to speed this up would also be appreciated. Thanks in advance for any help!


Why doesn't Mathematica evaluate this limit?

I am trying to evaluate a few limits in _Mathematica_ , and I can only get it to evaluate them in certain cases. I don't fully understand the evaluation order and when it substitutes numerical values in for variables. If anyone could explain to me how to do these I would appreciate it. Mn, g, and extent have numerical values that are determined before this. x0 and order are parameters that I input manually when plotting and using for matching, etc.               DeltaAnalytic[k_?NumericQ, g_?NumericQ, extent_?NumericQ] :=        ArcTan[((Sin[k*extent])^2)/(k*extent*Mn/g - Sin[k*extent]*Cos[k*extent])];          EffRangeExp[k0_, x0_?NumericQ, order_?NumericQ, coupling_?NumericQ, extent_?NumericQ] :=       Limit[Normal[Series[DeltaAnalytic[k, coupling, extent], {k, x, order}]], x -> x0] /.          k -> k0;      Now when I try to plot the above, `EffRangeExp`, or just get it to spit out a numeric value at some k with various parameters, it is clearly evaluating something in the wrong order. I just don't know how to fix this problem. Would it help to make the variables local in the above function?


Moments Ratio Plot using "ProbabilityDistribution"

I am trying to plot moments ratio plot with the following code:               f1[al_, be_, ga_, lam_] =        Skewness[ProbabilityDistribution[         al be x^(-be - 1) (1 + ga x^-be )^(-(al/ga) - 1) (1 + lam - 2 lam ((1 + ga x^-be )^(-(al/ga)))), {x, 0, ∞}]];     f2[al_, be_, ga_, lam_] = Kurtosis[ProbabilityDistribution[al be x^(-be - 1) (1 + ga x^-be )^(-(al/ga) -  1) (1 + lam - 2 lam ((1 + ga x^-be )^(-(al/ga)))), {x,           0, ∞}]];          b = ParametricPlot[{f1[10, be, 1.5, -0.5], f2[10, be, 1.5, -0.5]}, {be, 0.1, 5}];     a = RegionPlot[b2 - (b1)^2 - 1 < 0, {b1, -2, 3}, {b2, 0, 9}];     Show[a, b]      where `{al,be,ga} > 0` and `lam` is between `-1` and `1`. But _Mathematica_ is unable to compute skewness and kurtosis of the specified distribution (under this code). How can I compute `Skewness` and `Kurtosis` and further plot moments ratio plot of the specified distribution. In above code if I replace `ProbabilityDistribution` by `WeibullDistribution` I got moments ratio plot of _Weibull distribution_.


How to generate a series of bisection points of a given line segment?

I want to get the coordinates of the bisection points for a given line segment to a specified resolution. For example, when the line is given by {0,0} and {1,0}, the output coordinates should be {0.5,0} for the first iteration, and then {0.25,0} and {0.75,0} for the second iteration, and so on, until the distances between those points are less than some resolution, say 1/16. Is there a convenient way?


How copy a large cell into clipboard using `input text`?

This is a strange problem and everything I tried did not work. I have a very large single Manipulate cell (it is a demonstration stylesheet notebook, hence this cell have to be one), and I simply wanted to copy the content of this cell and paste it into another text file. It seems that, for some reason, Mathematica has a limit somewhere, since I am sure the windows 7 clipboard can handle this size itself. When I select the cell, and then do CTRL-c, and paste into a plain text file in my editor, the output that shows up is only about 850 lines (this is much less than the original cell, which is I think few thousands lines long). I tried two different editors with the same result. It always gets cut off at the same place. The copy has to be done as `input text` and not as `plain text`. The copy as `plain text` is able to copy the whole cell, but the formatting is all messed up and not possible to read. I need to copy it as `input text`, which what happens when selecting the cell and doing CTRL-C, then CTRL-V (on windows) I can save the whole notebook as .txt file, but again, the formatting is all lost, and it seems to save it using the `plain text` mode. I can offocurse break the cell into many smaller cells, and then copy one by one with the mouse, but this is very tedious way to do it and I think there should be a way to handle this directly. Here is the notebook and I hope someone can find a way. I have many such notebooks with large cells to do. I am using version 9.01 on windows 7 64 bit.


Using WhenEvent for derivative of discontinuous function

I have a discontinuous function ($u(t)$, a square wave) and I would like `WhenEvent` to trigger when the signal goes high/low, i.e. when the value of $u(t)$ changes. I was hoping to use the derivative of $u(t)$ to determine this.               squareWave[t_, period_, duty_] := UnitBox[Mod[t/period, 1.]/(2. duty)]          system =  {x'[t] == u[t], WhenEvent[Mod[t, 0.5 τ],          u[t] -> squareWave[t, 2 τ, 0.2]], x[0] == 0, u[0] == 1,          WhenEvent[D[u[t]] > 0, Print[t]]};     params = {τ -> 1};     sol = NDSolve[system /. params, {x, u}, {t, 0, 10},         DiscreteVariables -> u];     Plot[Evaluate[{x[t], u[t], u'[t]} /. sol], {t, 0, 10},         PlotLegends -> {"x(t)", "u(t)", "u'[t]"}]      Unfortunately this does not seem to work? The output is: ![Output](http://i.stack.imgur.com/3Rjxl.png)


Axis Labels Disappear With Manipulate

I have a `ListPlot3D` with custom axis labels that I am scrolling with `Manipulate`. My issue is that the axis labels scroll away as the plot is scrolled. The commands below reproduce the problem that I am having. Thanks, Edmund               tickLabels = {{1, ""}, {2, ""}, {3, ""}, {4, ""}, {5, "lv1"}, {6,      ""}, {7, ""}, {8, ""}, {9, ""}, {10, "lv2"}, {11, ""}, {12,      ""}, {13, ""}, {14, ""}, {15, "lv3"}, {16, ""}, {17, ""}, {18,      ""}, {19, ""}, {20, "lv4"}, {21, ""}, {22, ""}, {23, ""}, {24,      ""}, {25, "lv5"}, {26, ""}, {27, ""}, {28, ""}, {29, ""}, {30,      "lv6"}, {31, ""}, {32, ""}, {33, ""}, {34, ""}, {35, "lv7"}, {36,      ""}, {37, ""}, {38, ""}, {39, ""}, {40, "lv8"}, {41, ""}, {42,      ""}, {43, ""}, {44, ""}, {45, "lv9"}, {46, ""}, {47, ""}, {48,      ""}, {49, ""}, {50, "lv10"}};          Manipulate[      ListPlot3D[       Table[i + j RandomReal[{1, 5}], {i, 50}, {j, 15}][[window - 9 ;; window]],       AxesLabel -> {"x", "y", "value"},        Ticks -> {Automatic, tickLabels[[window - 9 ;; window]], Automatic}],        {window, 10, 50, 1}]


How to build a list of functions

Having said that I'm no expert, I have some problems in generating a list of functions inside a loop. The functions in the list should depend on the elements of a _parameters_ list, that are read in sequence. The stripped down examples here below should show what I mean. First I tried this (rather naively)               parameters = {a, 3, 6, E, 2}; p = 1;     While[p <= 5, funclist[[p]][x_] := parameters[[p]] x^p; p++]      Naturally it doesn't work. After some other trials I arrived at this possible solution               parameters = {a, 3, 6, E, 2}; p = 1;     While[p <= 5, With[{p = p}, funclist[p, x_] := parameters[[p]] x^p]; p++]      But in this case the output is not actually a list but rather a sort of indexed function that cannot be manipulated as a list could be. What I'd like to get is a list of functions that, for example can be used in the following ways:               in: funclist     out: {a x, 3 x^2...}      and also               in: funclist[[2]][4]     out: 48      or also               Plot[funclist[[2]],{x,-1,5}]      Is it possible?