_id
stringlengths
1
5
title
stringlengths
15
150
text
stringlengths
43
28.9k
40297
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?
38566
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?
44878
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?
10918
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]]]];
51893
"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.)
34752
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!
41737
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.
45707
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.
50951
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.
56616
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)
28271
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.
44626
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.
39686
How to convert the expression '{a->a0, b->b0}' to the expression 'a=a0; b=b0'?
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!
48463
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)
37879
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
35435
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
19802
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_]= ?
34483
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?
59445
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.
57276
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?
47235
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?
55065
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[]]]]
6669
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)
34188
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 ?
31599
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!
25977
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.
25161
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?
56865
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.
3616
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
29310
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`.
38420
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.
46963
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"?
47420
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} >
42631
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?
16380
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.
26821
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. >>`
46579
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?
34191
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 ?
27211
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?
40961
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?
29817
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?
29439
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?
30425
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?
29814
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.
29813
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.
29812
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;
40969
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.
1176
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
18939
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.
41676
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 ?
1170
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.
21736
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?
23505
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.
23056
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?
47211
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?
23050
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.
23053
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.
47212
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
51826
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?
47813
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
59265
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?
27616
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?
27615
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?
27614
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!
27612
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?
56973
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_.
39597
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?
39596
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.
29436
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)
59588
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}]
59032
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?
59030
How to use DegreeGraphDistribution with directed graphs?
`DegreeGraphDistribution` supports directed graphs because it has a `DirectedEdges` option. How can I specify the in-degree sequence and the out-degree sequence separately when generating random _directed_ graphs? For example, RandomGraph@DegreeGraphDistribution[{2, 2, 1, 1}, DirectedEdges -> True] gives a graph where the vertices have the following {in, out} degree combinations: `{{2,2}, {2,2}, {1,1}, {1,1}}`. This syntax worked, but the in and out-degree sequences are identical for each vertex. How can I specify them separately? * * * I'd like to note that as a workaround it is possible to use igraph's `degree.sequence.game` function through the IGraphR package. However, now I am looking to do this in pure Mathematica though. If you do end up using igraph, be sure to read the documentation in detail, and be aware of the quirks of each method that is available (does it guarantee uniform sampling? does it produce simple graphs? does it support directed graphs? there are several options).
7188
Construct a simple mesh or tetrahedral mesh from 3D image surface
I have a 3D Y-Shape hollow tube, not so good surface. Import["http://dl.dropbox.com/u/68983831/tube02.vtk", "Graphics3D"] ![enter image description here](http://i.stack.imgur.com/A2k9g.png) I tried to use following vertex data plot and generate mesh. pts = Import["tube02.vtk", "VertexData"]; Graphics3D[Point@pts] ![enter image description here](http://i.stack.imgur.com/5LztT.png) Question: How to plot a smooth surface from vertex data and then generate tetrahedral or simple mesh? I was trying to use following thread to solve my problem: How to calculate volume of convex hull and volume of a 3D object and My donut has holes in it!.
29921
Combination of a Contourplot and a Graphics Object
I want to combine the following to graphs. cartPoints = Table[With[{x = RandomReal[]}, {1/(2*Pi), ArcCos[x]}], {10}]; Graphics[Arrow[{{0, 0}, #}] & /@ CoordinateTransform["Polar" -> "Cartesian", cartPoints], Frame -> True, FrameTicks -> None, AspectRatio -> 1, PlotRange -> {{0, 1/(2*Pi)}, {0, 1/(2*Pi)}}, FrameLabel -> {{"z", ""}, {"y", ""}}, LabelStyle -> { FontFamily -> "Arial", FontSize -> 14}, BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}] ContourPlot[Cos[x^2 + y^2], {x, -Sqrt[Pi]/2, Sqrt[Pi]/2}, {y, -Sqrt[Pi]/2, Sqrt[Pi]/2}, FrameLabel -> {{"x", ""}, {"y", ""}}, LabelStyle -> { FontFamily -> "Arial", FontSize -> 14}, BaseStyle -> {FontFamily -> "Arial", FontSize -> 14}] How can I arrange both graphs in 3D? The Countourplot should be the bottom of the resultung graph and the arrows should point in z direction
31235
Keeping vertexcoordinates after adding a new vertex
I want to add a new vertex to a graph, with fixed VertexCoordinates but when I use VertexAdd, the new graph does not have the VertexCoordinates of the previous one. g = Graph[{1 -> 2}, VertexCoordinates -> {{0, 0.5}, {0.5, 0}}, PlotRange -> 1] This is the initial graph g = VertexAdd[g, 3] Adding a new vertex makes a new graph with automatic coordinates. I tried to see if there is a way to define the coordinates when adding a new vertex but I could not find anything. Also I was looking if there is something like: SetProperty[g, VectorCoordinates -> {list of coordinates}] To set coordinates for all vertices in a graph, but I could not find anything.
31238
How to combine elements of two matrices?
Given two matrices m1 and m2, e.g.: m1 = {{a1, b1}, {c1, d1}} m2 = {{a2, b2}, {c2, d2}} How can one obtain the following? {{f[a1, a2], f[b1, b2]}, {f[c1, c2], f[d1 ,d2]}} I found this solution MapThread[f, {m1, m2}, 2] Is there a simpler way?
29102
Question with ParametricNDSolveValue
When solving the following system: g[a_,b_] := c /. FindRoot[a + b == c, {c, 0}] pf = ParametricNDSolveValue[{y''[x] == g[a,b] y[x] Cos[x + y[x]], y[0] == a, y'[0] == 1}, Integrate[y[s]^2, {s, 0., b}], {x, 0, b}, {a, b}]; _Mathematica_ gives me two error messages, which say: > FindRoot::nlnum: The function value {0. +a+b}is not a list of numbers with > dimensions {1} at {c} = {0.}. >> > > ReplaceAll::reps: {FindRoot[a+b==c,{c,0}]} is neither a list of replacement > rules nor a valid dispatch table, and so cannot be used for replacing. >> How can I fix this issue?
3432
Using the same frame ticks for two different histograms
Consider the following: SetOptions[Histogram, BarOrigin -> Left, Frame -> {{True, None}, {True, None}}, FrameTicks -> Automatic]; data1 = {Table[1, {i, 5}], Table[5, {i, 50}], Table[3, {i, 25}], Table[4, {i, 20}]}; data2 = {Table[1, {i, 3}], Table[5, {i, 20}], Table[3, {i, 25}]}; data3 = {Table[1, {i, 3}], Table[5, {i, 20}], Table[4, {i, 15}]}; histo1 = Histogram[data1] histo2a = Show[Histogram[data1, ChartElements -> None],Histogram[data2]] histo3a = Show[Histogram[data1, ChartElements -> None],Histogram[data3]] histo2b = Show[Histogram[data1], Histogram[data2, ChartStyle -> Red]] histo3b = Show[Histogram[data1], Histogram[data3, ChartStyle -> Red]] I would like to use the same frame/coordinate system for `histo2a` and `histo3a` as in `histo1`. `histo3b` shows how it should be (only without the grey part) and `histo2a` how it should not be. `histo2b`in addition shows the disadvantage of the `Show[]`-approach (one bar exceeds the frame). Due to the latter, I was trying to extract the FrameTicks-values from `histo1` and to use them for `Histogram[data2]` and `Histogram[data3] but neither`Options[histo1,FrameTicks]`,`AbsoluteOptions[histo1,FrameTicks]`nor`HistogramList[data1]` return help. Now I would like to use exactly the same frame ticks, which were calculated based on `data1` for `histo2`. Neither `Options[histo1,FrameTicks]`, `AbsoluteOptions[histo1,FrameTicks]` or `HistogramList[data1]` help. Has anyone an idea?
7186
Generating a non-convex polyhedron from a list of vertex coordinates
I want to include a figure in a paper I am writing on Combinatorial Geometry which features a non-convex polyhedron given by the following vertices, EDIT: I was unaware that Mathematica could convert coordinates from spherical to Cartesian, so I will post the correct spherical coordinates as follows: {{0, 0, 0}, {1, 0, 0}, {1, Pi/3, 0}, {1, Pi/3, ArcCos[1/3]}, {1, Pi/3, 2 ArcCos[1/3]}, {1, Pi/3, 3 ArcCos[1/3]}, {1, Pi/3, 4 ArcCos[1/3]}, {1, (2 Pi)/3, (ArcCos[1/3])/2}, {1, (2 Pi)/3, (3 ArcCos[1/3])/2}, {1, (2 Pi)/3, (5 ArcCos[1/3])/2}, {1, (2 Pi)/3, (7 ArcCos[1/3])/2}, {1, (2 Pi)/3, (9 ArcCos[1/3])/2}, {1, Pi, 0}} Does anyone know how I can generate such a figure using Mathematica? I assume I will need to also somehow define which vertices are connected by an edge with a list, but I am unsure how I would do that as well. I have tried using the "Computational Geometry Package", and have been reading through the tutorial for about an hour, but I have no idea what a "vertex adjacency list" is or how I could make this work in 3-dimensions; the package tutorial seems to only comment on triangulations in the plane, etc. Any help is greatly appreciated! EDIT: I will attempt to describe this non-convex polyhedron and include pictures and a figure. ![Real image](http://i.stack.imgur.com/8d9hA.jpg) ![figure](http://i.stack.imgur.com/m4L7M.png) I will quote from my paper: > The inspiration for constructing a simplicial 3-complex $\mathcal{K}$ for > which 12 tetrahedra touch at a vertex comes from the configuration of 4 > tetrahedra sharing an edge; see Figure 3. Let $v_{0}=(0,0,0)$ be the origin > and connect the two vertices $v_{1}=(1,0,0)$ and $v_{12} = (-1,0,0)$ to > $v_{0}$ by an edge. Label these edges as $e(v_{0}v_{1})$ and > $e(v_{0}v_{12})$ and notice that their union forms a straight line of length > 2 in $\mathbb{E}^3$. Around each of these edges we arrange four tetrahedra > as in Figure 3, and we rotate the cluster of four tetrahedra sharing edge > $e(v_{0}v_{12})$ by $\pi/6$ in order to ensure that an extra four tetrahedra > will fit in between the two clusters of 4 tetrahedra (explained in more > detail later). Considering the vertices of these tetrahedra, we obtain a > point set $P$ (with $|P|=12$) where the minimum distance which can occur any > of the points is of unit length. Figure 3: in the context of my paper, this figure shows that at most 4 tetrahedra can share an edge with conditions I impose. If you imagine one of the tetrahedra removed so that there is a bigger space, these are the "clusters of 4 tetrahedra" I described above. ![figure 3](http://i.stack.imgur.com/GKAcn.png) * * * (The bonus question was solved, thank you Mr. Wizard.) BONUS: If anyone knows how to check with Mathematica if all of the points are at least a distance of 1 away from each other that would be very helpful.
22950
Crash with subsetting TemporalData
The first line gets a single sample path for an M/M/1 queue for time between 0 and 100. No problem, I can plot it, etc. td = RandomFunction[QueueingProcess[9, 10], {0, 100}, 1]; Next, I want to look at the sample path of the process between time 10 and 50, so I do subset = td["Part", 1, {10, 50}]; and MMA crashes on me. Ver 9.0.1.0 on windows 7 64 bit. Any suggestions?
16881
How to create animated snowfall?
Well, the title is self-explanatory. What sorts of snowfall can we generate using _Mathematica_? There are two options I suggest to consider: 1) Continuous GIF animations with smallest possible number of frames. 2) `Dynamic`-based animations.
54421
Transparency rendering problems in Mathematica 10 (Mac)
For some weird reason, they apparently changed the styling of contours in ContourPlot for 10.0. Here is a comparison of the results for V9 and V10 (first 9, then 10): ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ContourShading -> None, ContourStyle -> {{Red, Thickness[0.008]}}] ![Mathematica 9 output](http://i.stack.imgur.com/UUxhg.png) Version 9 ![Mathematica 10 output](http://i.stack.imgur.com/QxZ3N.png) Version 10 Firstly, can I override the coloring? I would like to keep the solid colors that were in V9. And secondly, where do those dark spots come from? Is this a bug? Edit: yes, this does look like a bug. The dark spots are only visible in the Mac version. Interestingly enough, for about half a second after the output appears, what I see on the screen is similar to what `Export` produces (shown below). The only difference is that the lines are thinner in the exported .png (another bug?). After those 0.5 seconds, another level of transparency kicks in and I see what is shown in the top picture below. ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Contours -> {.9}, ContourShading -> None, ContourStyle -> {{Red, Thickness[0.17]}}] ![enter image description here](http://i.stack.imgur.com/3pz2e.png) <\- What I see. ![enter image description here](http://i.stack.imgur.com/9HQzI.png) <\- What `Export` produces.
59263
How to incorporate a matrix in a For loop?
I would like the equivalent of: For[x = 0, x less than Infinity, x++] For[y = 0, y less than Infinity, y++] m = Table[(x, x-2 y, x-2 y, 0, 0, 0), (x-2 y, x, x-2 y, 0, 0, 0), (x-2 y, x-2 y, x, 0, 0, 0), (0, 0, 0, 2 y, 0, 0),(0, 0, 0, 0, 2 y, 0), (0, 0, 0, 0, 0, 2 y)] I then would like to include an "if-else" statement where I print only the largest possible matrix. (i.e. If `m` is less than `m`, continue running through loop until it finds the largest `m`, then print it). I have another matrix, `l`, where I need to minimize the distance between `l` and `m`, hence requiring the largest possible matrix for `m`. Could you help me with this?
8549
Using different random values at each recursion step
I have the following code: ϕ[0] := π/4 ϕ[n_] := Exp[-n] ϕ[n - 1] + Sqrt[1 - Exp[-2 n]] M M = RandomVariate[NormalDistribution[0, 1]] For this recursion relation, is the normal deviate taking a random variable during each recursion or is it just taking one for the whole recursion process? Thanks,
57630
Numerically integrating a list-valued function
I want to `NIntegrate` a `List` valued function `foo[x]` which is only defined for numerical arguments `x`. Here is a simple toy example: foo[x_?NumericQ] := {x^2, x^3}; NIntegrate[foo[x], {x, 0, 1}] It gives the following error > > NIntegrate::inum: Integrand foo[x] is not numerical at {x} = > {0.00795732}. >> > NIntegrate::inum: Integrand foo[x] is not numerical at {x} = > {0.00795732}. >>. > Note that the symbolic definition `fooS` works fine: fooS[x_] := {x^2, x^3}; NIntegrate[fooS[x], {x, 0, 1}] (*{0.333333, 0.25}*) What causes the error? It seems to be crucial that the function `foo` is `List` valued. When I `NIntegrate` each component separatly, the error does not occur: foo1[x_?NumericQ] := foo[x][[1]]; foo2[x_?NumericQ] := foo[x][[2]]; {NIntegrate[foo1[x], {x, 0, 1}], NIntegrate[foo2[x], {x, 0, 1}]} (*{0.333333, 0.25}*) and even NIntegrate[{#1, #2} & @@ {foo1[x], foo2[x]}, {x, 0, 1}] (*{0.333333, 0.25}*)
8016
How to find the domain and range of a function with Mathematica?
I'm studying calculus and in some exercises I am asked to find the domain and range of a function. Does _Mathematica_ have already a built-in function for this? I can imagine some ways of doing so, but at the moment I want to know if there's a built-in function or some easy way of doing it.
34556
How to compute MIN$(A(x), B(x))$
I have two polynomials: $\;A(x) = \sum a_i\;x^i$, $\quad B(x) = \sum b_i\;x^i$. Given $A(x)$, $B(x)$, I want to compute $\;C(x) = $MIN$(A(x), B(x)) = c_i\;x^i$ where $c_i = $MIN$(a_i, b_i)$. How can I do it automatically in _Mathematica_?
8014
Creating custom functions with multiple arguments
I am hoping that this isn't a stupid question so feel free to vote it for closure. Google failed somehow. I want to define a custom function (more complicated than the usual `f[x_] := someExpression`) that performs several tasks (taking elements of a set, performing computations, etc.) before giving an output. I don't want to run the whole bunch of codes repeatedly. Is there a way of defining such a function? What I have in mind is, say a program in R, which goes like function_name <- function(arg1, arg2, ..., argn){ routine 1 routine 2 routine 3 ... Output to be returned } EDIT: In view of the comment that this question is somewhat vague, I am posting part of the code below: Final = {{1}}; For[hn = 0, hn < 7, hn++; rp = {0}; fn = hn; For[fk = 0, fk < fn, fk++; Clear[r, v, w, p, q, z, x, n, k, t, res, pt]; v[z_] := Sum[q^d, {d, 0, z - 1}]; n = fn; k = fk; t = {}; For[i = 0, i < (n - k), i++; For[j = -1, j < k, j++; t = Join[t, {j}];]]; t = KSubsets[t, (n - k)]; For[i = 0, i < Length[t], i++; t[[i]] = Sort[t[[i]]]]; t = Union[t]; The code is quite long (sloppy programming). I just want the whole thing to be given a name so that I can just type that name of that function and vary the arguments.
8013
About minimizing calculations when using ComposeList
I have a lot of functions to use in a iterative way, and I need some of the calculation results. For example: func = Function[{s}, s Sin[#] &] /@ Range[100]; ComposeList[func, x][[1 ;; ;; 10]] Apparently, this code calculates much more than necessary. Especially, a lot of time is needed for the calculation when the length of `func` list is very long and when the `Function` is very complicated (e.g. `Length@func = 1024` and the function is `Fourier`); **Is there any elegant way to reduce the calculation?** _**Edit_** Perhaps I should say more about the fact that this code calculates than necessary. For example, func = Function[{s}, s Sin[#] &] /@ Range[10]; result=ComposeList[func, x][[1 ;; ;; 5]] (* {x, 5 Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]], 10 Sin[9 Sin[ 8 Sin[7 Sin[6 Sin[5 Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]]]]]]]} *) Now we can see that result[[2]] (i.e., 5Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]]) is also appeared inside result[[3]] (i.e., 10Sin[...5Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]]], so the evaluation for 5Sin[4 Sin[3 Sin[2 Sin[Sin[x]]]]] is repeated twice here. The repetition will be very large with an increase of Length[func], which will be much more time-consuming than it is required. This is my point here (Up to now, Rojo has gotten the point and solved it ).
8011
Assumptions with D
I want to give assumptions for the `D` function. Say I want to calculate $\frac{d|x|}{dx}$ for $x>0$, which is 1. I write `D[Abs[x], x, Assumptions -> x > 0]` which gives `D::optx: Unknown option Assumptions in D[Abs[x],x,Assumptions->x>0]. >>` Why doesn't D take assumptions?
28389
Clickable Bounded Diagram
Suppose I make a `BoundedDiagram` via the following code Needs["ComputationalGeometry`"]; data2D = RandomReal[{0, 10}, {10, 2}]; b1 = {{0, 0}, {11, 0}, {11, 11}, {0, 11}}; convexhull = ConvexHull[data2D]; delval = DelaunayTriangulation[data2D]; {vorvert, vorval} = VoronoiDiagram[data2D]; {dvert1, dval1} = BoundedDiagram[b1, data2D, delval, convexhull]; DiagramPlot[data2D, dvert1, dval1] How would I go about making each region clickable, i.e. open some link that I associated with the data? \-- Edit: I should note, all I really want is a to be able to click on regions of a Voronoi-Like diagram, it doesn't have to be done via BoundedDiagram, this is just my first attempt at doing that ... (and is basically straight from the documentation.)
44937
Calculating the volume under a surface with Riemann sum
I have a set of xyz data points. X and Y are coordinates of a regular grid of 10x10 units, Z is the independent variable. I am trying to calculate the volume under the set of points, using Riemann sum. I have used two approaches that I expected to produce the same result, and on the contrary, produce very different results. In the first approach I make a sum of the volumes of the prism formed by every point. In the second approach I make an interpolation function with an interpolation order of 0, and then integrate it. Here is a MWE of the code I'm using: Data = {{{230, 310}, 0.4434}, {{230, 320}, 0.5078}, {{230, 330}, 0.6000}, {{230, 340}, 0.6430}, {{230, 350}, 0.6724}, {{230, 360}, 0.7204}, {{230, 370}, 0.7593}, {{230, 380}, 0.7987}, {{230, 390}, 0.8908}, {{230, 400}, 1.0175}, {{230, 410}, 1.1136}, {{230, 420}, 1.2342}, {{230, 430}, 1.3375}, {{230, 440}, 1.4055}, {{230, 450}, 1.3979}, {{240, 310}, 0.4593}, {{240, 320}, 0.3963}, {{240, 330}, 0.3985}, {{240, 340}, 0.3877}, {{240, 350}, 0.4262}, {{240, 360}, 0.4763}, {{240, 370}, 0.5465}, {{240, 380}, 0.6163}, {{240, 390}, 0.7376}, {{240, 400}, 0.8567}, {{240, 410}, 0.9769}, {{240, 420}, 1.1350}, {{240, 430}, 1.2960}, {{240, 440}, 1.4032}, {{240, 450}, 1.4310}, {{250, 310}, 0.5866}, {{250, 320}, 0.4513}, {{250, 330}, 0.3789}, {{250, 340}, 0.3360}, {{250, 350}, 0.3273}, {{250, 360}, 0.3526}, {{250, 370}, 0.4068}, {{250, 380}, 0.4520}, {{250, 390}, 0.5269}, {{250, 400}, 0.6071}, {{250, 410}, 0.6807}, {{250, 420}, 0.7808}, {{250, 430}, 0.8794}, {{250, 440}, 0.9572}, {{250, 450}, 0.9682}}; Total[Data[[All, 2]]*100] Integrate[Interpolation[Data, InterpolationOrder -> 0][x, y], {x, 230, 250}, {y, 310, 450}] The first approach yields a volume of 3377.73, and the second one of 1918.94. Can someone explain the reason for this difference? Or which one is more appropriate for the purpose of estimating a volume? Any help will be very much appreciated.
7455
How can I dynamically get a file whenever it is saved in Workbench?
I want to get a file once and only once at the start of a coding session. Then, whenever I save the file in the Wolfram Workbench, have it be gotten automatically. How can I construct such a utility?
44931
Why doesn't Abs simplify further?
Why does this: Simplify[Abs[x + I], Element[x, Reals]] give me Abs[x + i] Is there a way to force Mathematica to give me the following answer? $\sqrt{x^2+1}$
7453
X label in GraphicsColumn is cut off
I'm trying to use GraphicsColumn to plot two curves with very different ranges. for example, GraphicsColumn[{Plot[Sin[x], {x, 0, 10}, PlotRange -> All, AspectRatio -> 0.3, Frame -> True, Axes -> False, ImageMargins -> 20], Plot[Cos[x], {x, 0, 10}, PlotRange -> All, AspectRatio -> 0.3, Frame -> True, Axes -> False, ImageMargins -> 20]}, Epilog -> {Text["Frequency", {Center, Bottom}], Rotate[Text["Power", {0.5, Center}], 90 Degree]}] But the x label is not displayed properly, i.e., it is cut by the edge of the graph. ![enter image description here](http://i.stack.imgur.com/yAVbL.jpg) How to improve it?
26623
Integration strategies for oscillatory multidimensional function
I am seeking to integrate a highly oscillatory, multidimensional function. I am currently using NIntegrate's QuasiMonteCarlo approach. However, this is time-consuming and, given my current resources, not very accurate. How can I obtain more reliable estimates of the beasty integral given below? As the function itself will be integrated at a later stage, I am also interested in speeding up the function evaluation. The integral to be solved: fun[r_?NumericQ, d_?NumericQ, c_, opts:OptionsPattern[]]:= NIntegrate[ Cos[(c (d^2+r^2-2 d r Cos[ta] - 3 ((-r+d Cos[ta]) Cos[tb]+d Cos[a] Sin[ta] Sin[tb])^2)) / Abs[d^2+r^2-2 d r Cos[ta]]^(5/2)] Cos[(c (d^2+r^2+2 d r Cos[ta] - 3 ((r+d Cos[ta]) Cos[tb]+d Cos[a] Sin[ta] Sin[tb])^2)) / Abs[d^2+r^2+2 d r Cos[ta]]^(5/2)] * Sin[ta]*Sin[tb]/(2*Pi), {ta,0,Pi}, {tb,0,Pi/2}, {a,0,Pi}, Evaluate@FilterRules[{opts},Options[NIntegrate]] ] Typically, $d$ = 2, $r$ is in the range from 0 to Infinity (with the small values and $r$=$d$ posing problems), and $c$ is in the range from 100 to 3000. A typical function call is: AbsoluteTiming[fun[3, 2, 400, Method -> "QuasiMonteCarlo", PrecisionGoal -> 6, MaxPoints -> 40000000]] (* -> {102.3215798,-0.00442278} *) This issues a NIntegrate::maxp warning and indicates an error estimate of 0.00011. Using the default strategy I obtain: AbsoluteTiming[ fun[3, 2, 400, MaxRecursion -> 20, Method -> {GlobalAdaptive, MaxErrorIncreases -> 10000}]] (* -> {9.3912165,-0.00439357} *) and a NIntegrate::eincr warning. Estimated error: 0.0369. How to proceed from here? Thank you for your help.
4593
Figuring out how AbsoluteOptions works with Graphs
I am puzzled by how `AbsoluteOptions` works with `Graph` objects. I would have expected that one could use it to obtain all the options used to draw a graph. There are several ways in which it behaves contrary to my expectations. First, let' s make a simple graph, g, and set some custom options: g = RandomGraph[{6, 11}, VertexStyle -> {1 -> Red, 2 -> Green}, VertexSize -> {1 -> Large, 2 -> Large}, VertexLabels -> "Name", ImagePadding -> 15, EdgeLabels -> "Name", Axes -> True] ![g](http://i.stack.imgur.com/cfx2X.png) **1 - Why won' t all the options work again?** One expects that the options used for `g` could be obtained through `AbsoluteOptions[g]` and redeployed. However, this does not work. Either the code below locks up completely or the Out cell has a tooltip: "$Failed is not a Graphics primitive or directive". allOptions = AbsoluteOptions[g]; g2 = Graph[EdgeList[g], allOptions] **2 - Some options work as expected, others do not. Why?** Let's take a subset of the options of `g`; namely, `{VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize, AlignmentPoint, ImagePadding}`. Now let's compare g and the partial replication, g3, side by side: someOptions = Sort@AbsoluteOptions[ g, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize, AlignmentPoint, ImagePadding}] g; g3 = Graph[EdgeList[g], someOptions] someOptions3 = Sort@AbsoluteOptions[ g3, {VertexCoordinates, EdgeLabels, Axes, VertexLabels, VertexSize, AlignmentPoint, ImagePadding}] (* Out someOptions3*) {AlignmentPoint -> Center, Axes -> {True, True}, EdgeLabels -> {"Name"}, ImagePadding -> 15., VertexCoordinates -> {{0.518253, 0.817802}, {1.61587, 0.866512}, {2.05896, 0.336143}, {1.03973, 1.21024}, {1.04431, 0.}, {0., 0.377097}}, VertexLabels -> {"Name"}, VertexSize -> {1 -> Large, 2 -> Large}} ![g and g3](http://i.stack.imgur.com/xfqQd.png) The vertex sizes are the same in each case, as expected. Also, the `VertexStyle` is different. That's fine: g3 has the default vertex style. But why are the vertices in different locations? After all, we passed the `VertexCoordinates` option to g3. And the vertex coordinates returned by `AbsoluteOptions[g3...` do not correspond to the coordinates used for the vertices. **3 - What are failed options?** If we inspect the options used by g, we will notice that two of them failed, even though `g` was drawn with no apparent issues. AbsoluteOptions[g, {VertexShapeFunction, EdgeShapeFunction}] (* Out *) {VertexShapeFunction -> $Failed, EdgeShapeFunction -> $Failed} If you look at the graph, g, you see that the default vertex shapes and edge shapes were correctly rendered? So, whence the fail? **4 - Why is it insufficient to remove failed options?** If we remove the failed options and try to implement all the other options, MMA does one of two things: (1) It returns the unparsed `Graph` command or (2) it produces only a small portion of the graph, g. Any help would be appreciated. I'm not trying to correct a particular program but rather understand the strengths and limitations of `AbsoluteOptions.`
48979
Sharpening extrema using DensityPlot
I have a data set where I really care mainly about visualizing the highest and lowest areas. DensityPlot suits my needs well, but ideally the maxima and minima would pop more from the rest of the data. I know that DensityPlot scales the data from your function to between zero and one before coloring it accordingly. I'd like to use a scaling that has more meat in the middle than theirs. So I was thinking I could take their scaling, and use it as an input to for example (x-0.5)^3/8, which has the properties `f[0]=0` and `f[1]=1`, but is better distributed for my purpose. Then I'd pass these values to the colorizer. Can't really figure out how to do this though. Any thoughts?
26629
Tips on giving a lecture course using Mathematica
I've had a look at this question on giving presentations with Mathematica which is very useful on the technical side of setting up slideshows. However, my question is more about the integration of Mathematica with good teaching style. I shall shortly be giving an undergraduate lecture course on Mathematical Methods to engineers and others from non pure maths disciplines (it'll be from integration onwards) and am planning on using Mathematica as a teaching tool. One has to be careful with not letting technology take the place of good teaching but I would like to be able to use Mathematica effectively for showing the structure of a problem and the parametric dependencies of functions etc. - the perfect place for plenty of `Manipulate` usage. I hope to give at least 90% of my lectures in Mathematica and the rest on a blackboard - this is a wild estimate but it's what I'm aiming for. I would be grateful if anyone has undertaken such an exercise to give me possible pitfalls and pointers as to the best methods they've found to make Mathematica bring the maths to life, rather than confuse the students with a mass of fast-paced buttons, dynamic displays and notation. P.S I saw also this question on lecture courses with Mathematica, however again, these are examples and not descriptions of what went well and what didn't.
46562
How to Show the "TemperatureMap" using Manipulate?
How to show the "TemperatureMap" in Manipulate?. ONLY the image, without text "ColorData..." Manipulate[ Column[{Style["This is a Test... " -> DateString[] -> " - " -> i^2,18, Bold], Style["How to show ONLY the image of TemperatureMap in the last row?", 18,Darker@Red, Bold], ColorData["TemperatureMap"]}], {i, 1, 5}] ![Temperature in Manipulate](http://i.stack.imgur.com/YBEfj.jpg)