mm-995 === Subject: points extraction from eigen vector direction Using Mathematica , i am trying to extract values in the direction of my eigenvector. I have an image that I consider as a distribution .For this i computed the eigenvectors. I am trying to pick points from this distribution but only those that are in the direction of my eigen vectors. I am having problem , with this extraction., How can i do that. vicky Al aisa === Subject: expressions list -> equations list 1st of all THX to all who answered my last question. Just one other before I lend a Mathematica manual from the public lib and pester you no more :-) So. Now that I have a tensor it must vanish identically. I Flatten[] it first and then I have a list of equations...oh, stop, I haven't. REDUCE (if I may mention the name of a competition :-) could take a Solve[] now because it automatically assumes a =0 as default but Mathematica is anally-retentive (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0}. Convert to string, global change , -> =0, and } -> =0}, reconvert to list? Is that possible? Or is there a less LISP-hack-style solution? -- Hauke Reddmann <:-EX8 fc3a501@uni-hamburg.de Er-a svo gott sem gott kve[CapitalYAcute]a .9al alda sonum, ßv.92 a[CapitalYAcute] f.berra veit er fleira drekkur s.92ns til ge[CapitalYAcute]s gumi. === Subject: Re: Re: expressions list -> equations list No, Equal is NOT Listable: {a, b, c} == 0 evaluates to {a, b, c} == 0 Bobby > THX again. I could have guessed myself that == (I didn't > mean =, of course) is Listable. Subtract 10 points > from my Supergenius account :-) Of course, I still must solve the equation system by hand - > with some human intelligence I fork on every a*b==0 where > Mathematica probably groebners for days :-) -- > Hauke Reddmann <:-EX8 fc3a501@uni-hamburg.de > Er-a svo gott sem gott kve[CapitalYAcute]a > .9al alda sonum, ßv.92 a[CapitalYAcute] f.berra veit > er fleira drekkur s.92ns til ge[CapitalYAcute]s gumi. -- DrMajorBob@bigfoot.com === Subject: Re: expressions list -> equations list THX again. I could have guessed myself that == (I didn't mean =, of course) is Listable. Subtract 10 points from my Supergenius account :-) Of course, I still must solve the equation system by hand - with some human intelligence I fork on every a*b==0 where Mathematica probably groebners for days :-) -- Hauke Reddmann <:-EX8 fc3a501@uni-hamburg.de Er-a svo gott sem gott kve[CapitalYAcute]a .9al alda sonum, ßv.92 a[CapitalYAcute] f.berra veit er fleira drekkur s.92ns til ge[CapitalYAcute]s gumi. === Subject: Re: expressions list -> equations list and #==0 & /@ {a,b,c} does not help ?? Jens > 1st of all THX to all who answered my last question. Just one other before > I lend a Mathematica manual from the public lib and pester you no more :-) So. Now that I have a tensor it must vanish identically. I Flatten[] it first > and then I have a list of equations...oh, stop, I haven't. REDUCE (if I may > mention the name of a competition :-) could take a Solve[] now because it > automatically assumes a =0 as default but Mathematica is anally-retentive > (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0}. > Convert to string, global change , -> =0, and } -> =0}, reconvert > to list? Is that possible? Or is there a less LISP-hack-style solution? > === Subject: Re: expressions list -> equations list > 1st of all THX to all who answered my last question. Just one other before > I lend a Mathematica manual from the public lib and pester you no more :-) So. Now that I have a tensor it must vanish identically. I Flatten[] it first > and then I have a list of equations...oh, stop, I haven't. REDUCE (if I may > mention the name of a competition :-) could take a Solve[] now because it > automatically assumes a =0 as default but Mathematica is anally-retentive > (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0}. > Convert to string, global change , -> =0, and } -> =0}, reconvert > to list? Is that possible? Or is there a less LISP-hack-style solution? The following examples, all using pure functions --- equivalent to anonymous functions in LISP, should fulfill your needs. lst = {a, b, c}; Thread[# == Table[0, {Length@#}]] &@lst Thread[# == Array[(0 &), Length@#]] &@lst Thread[# == ConstantArray[0, Length@#]] &@lst Cases[lst, x_ -> Equal[x, 0]] (* Each expressions yield {a == 0, b == 0, c == 0} *) lst = {x^2, Sin[x]^2 + Cos[x]^2, (x + 1)/x}; Thread[# == Table[0, {Length@#}]] &@lst Thread[# == Array[(0 &), Length@#]] &@lst Thread[# == ConstantArray[0, Length@#]] &@lst Cases[#, x_ -> Equal[x, 0]] &@lst (* Each of the above expression returns 2 2 2 1 + x {x == 0, Cos[x] + Sin[x] == 0, ----- == 0} x *) -- Jean-Marc === Subject: Re: expressions list -> equations list For example, vars = Array[a, 5] {a[1], a[2], a[3], a[4], a[5]} and then Thread[vars == 0] {a[1] == 0, a[2] == 0, a[3] == 0, a[4] == 0, a[5] == 0} Bobby. > 1st of all THX to all who answered my last question. Just one other > before > I lend a Mathematica manual from the public lib and pester you no more > :-) So. Now that I have a tensor it must vanish identically. I Flatten[] it > first > and then I have a list of equations...oh, stop, I haven't. REDUCE (if I > may > mention the name of a competition :-) could take a Solve[] now because it > automatically assumes a =0 as default but Mathematica is > anally-retentive > (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0}. > Convert to string, global change , -> =0, and } -> =0}, reconvert > to list? Is that possible? Or is there a less LISP-hack-style solution? -- > Hauke Reddmann <:-EX8 fc3a501@uni-hamburg.de > Er-a svo gott sem gott kve[CapitalYAcute]a > .9al alda sonum, ßv.92 a[CapitalYAcute] f.berra veit > er fleira drekkur s.92ns til ge[CapitalYAcute]s gumi. -- DrMajorBob@bigfoot.com === Subject: Re: expressions list -> equations list > 1st of all THX to all who answered my last question. Just one other before > I lend a Mathematica manual from the public lib and pester you no more :-) So. Now that I have a tensor it must vanish identically. I Flatten[] it first > and then I have a list of equations...oh, stop, I haven't. REDUCE (if I may > mention the name of a competition :-) could take a Solve[] now because it > automatically assumes a =0 as default but Mathematica is anally-retentive > (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0}. > Convert to string, global change , -> =0, and } -> =0}, reconvert > to list? Is that possible? Or is there a less LISP-hack-style solution? > Note that in Mathematica a = 0 is an assignment. If you need to assign values to several undefined symbols, then {a, b, c} = {0, 0, 0} will work. If you need to build a list of equations then try # == 0 & /@ {a, b, c} or Thread[{a,b,c} == 0] both of which yield {a==0, b==0, c==0} But Solve[] seems to accept vector-equations too: In[1]:= Solve[{a, b, c} == 0, {a, b, c}] Out[1]= {{a -> 0, b -> 0, c -> 0}} In[2]:= Solve[{a, b, c} == {1, 2, 3}, {a, b, c}] Out[2]= {{a -> 1, b -> 2, c -> 3}} If it doesn't work for some reason, then use Thread[]: In[3]:= Thread[{a, b, c} == {1, 2, 3}] Out[3]= {a == 1, b == 2, c == 3} -- Szabolcs === Subject: Re: expressions list -> equations list Hi Hauke, if I understand it right, you want to get {a==,b==0,c==0} from {a,b,c}. For this there is Thread and MapThread. For your case: Thread[{a,b,c}==0] hope this helps, Daniel > 1st of all THX to all who answered my last question. Just one other before > I lend a Mathematica manual from the public lib and pester you no more :-) So. Now that I have a tensor it must vanish identically. I Flatten[] it first > and then I have a list of equations...oh, stop, I haven't. REDUCE (if I may > mention the name of a competition :-) could take a Solve[] now because it > automatically assumes a =0 as default but Mathematica is anally-retentive > (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0}. > Convert to string, global change , -> =0, and } -> =0}, reconvert > to list? Is that possible? Or is there a less LISP-hack-style solution? > === Subject: Vers. 6: restore natural cell tags order instead of alphabetical in Mathematica Vers. 6 the list of cell tags in Cell -> Cell Tags -> Find Cell Tags is in alphabetical order. Is there a way to restore the natural order of cell tags in this list as in previous Mathematica versions, i.e. in the order as they occur in the notebook and not alphabetically? Thomas. === Subject: How right Export data without rewite it at Mathematica v.6 Hi. I need a advice about: How right export data to file without rewriting it at Mathematica v.6? I need add data: {string1,val1,val2,val3,val4,string2,string3} to MyFile.XLS file a lot of times without rewriting it. I found a topic: http://mathforum.org/kb/thread.jspa?forumID=79&threadID=1579796&messageID=576 3454#5763454 May be anybody know more comfortable method. Romb. === Subject: solution to undetermined linear equation hi my basic problem is i have a matrix 13*3 of values -0.2028 0.12778 -0.09129 0.1278 -0.09129 0.07089 -0.09129 0.07089 -0.05731 0.07089 -0.05731 0.04902 -0.05731 0.04902 -0.04188 0.04902 0.04188 0.03747 ............. ............ i want to find wieght factors which when applied to above values would result in a value close to 0 such as -0.2028 g1 + 0.1278 g2 + -0.09129 g3 +0.07089 g4+........................g13=min 0.12778 g1+-0.09129g2 + 0.07089 g3 + -0.05731g4+.........................g13=min -0.09129g1+0.07089g2+ -0.05731g3 + 0.04902 g4+........................g13=min howeverthe values of g's should be subjected to the constraint g1+g2+g3+.........................g13=13 and all the wieghts must be nonzero Is it possible thankyou for your patience === Subject: Re: solution to undetermined linear equation The constraint that all the weights must be nonzero makes the problem difficult; I'll ignore it for now. Here's a setup for the problem (with randomly chosen coefficients): gvec = Array[g, 13] {g[1], g[2], g[3], g[4], g[5], g[6], g[7], g[8], g[9], g[10], g[11], g[12], g[13]} m = RandomReal[{-1, 1}, {13, 3}]; obj1 = gvec.m; obj2 = #.# &[obj1]; Minimize[{obj2, Total@gvec == 13}, gvec] {1.1895*10^-31, {g[1] -> 5.77492, g[2] -> 0.588401, g[3] -> 0.860516, g[4] -> 0.750811, g[5] -> 0.108545, g[6] -> 1.22947, g[7] -> 0.876558, g[8] -> 0.590213, g[9] -> 0.53078, g[10] -> 1.03768, g[11] -> -0.418626, g[12] -> 0.471749, g[13] -> 0.598983}} Here's a solution using Minimize: Minimize[{obj2, Total@gvec == 13}, gvec] {1.1895*10^-31, {g[1] -> 5.77492, g[2] -> 0.588401, g[3] -> 0.860516, g[4] -> 0.750811, g[5] -> 0.108545, g[6] -> 1.22947, g[7] -> 0.876558, g[8] -> 0.590213, g[9] -> 0.53078, g[10] -> 1.03768, g[11] -> -0.418626, g[12] -> 0.471749, g[13] -> 0.598983}} And here's a linear algebra solution, with a check on the constraints: soln1 = First@ Quiet@Solve[Flatten@{Thread[obj1 == 0], Total@gvec == 13}, gvec] {obj1, Total@gvec} /. soln1 // Simplify // Chop {g[1] -> 4.34554- 1.86478 g[5] + 1.11788 g[6] + 1.39554 g[7] + 0.609062 g[8] + 0.85836 g[9] - 1.18596 g[10] - 0.235194 g[11] + 0.617057 g[12] - 1.56911 g[13], g[2] -> 3.24756- 0.782057 g[5] - 0.723537 g[6] - 0.71926 g[7] + 0.558484 g[8] + 0.231554 g[9] - 1.3287 g[10] - 0.799617 g[11] + 0.0856483 g[12] - 0.839982 g[13], g[3] -> 0.388265- 0.28712 g[5] + 0.694379 g[6] + 0.591973 g[7] - 0.0669889 g[8] - 0.322397 g[9] + 0.222869 g[10] - 0.492421 g[11] - 1.03194 g[12] - 1.01694 g[13], g[4] -> 5.01864+ 1.93395 g[5] - 2.08873 g[6] - 2.26825 g[7] - 2.10056 g[8] - 1.76752 g[9] + 1.2918 g[10] + 0.527233 g[11] - 0.670769 g[12] + 2.42603 g[13]} {{0, 0, 0}, 13.} Notice that's a 9-dimensional SPACE of solutions, not just one. The constraint that all the weights must be nonzero makes linear algebra unusable if used directly, but one might try instead all the weights must be POSITIVE, in which case Solve fails: First@Solve[ Flatten@{Thread[obj1 == 0], Total@gvec == 13, Thread[gvec > 0]}, gvec]; Solve::eqf: g[13]>0 is not a well-formed equation. >> But Minimize has no problem with it: Minimize[Flatten@{obj2, Total@gvec == 13, Thread[gvec > 0]}, gvec] {1.23455*10^-31, {g[1] -> 4.38325, g[2] -> 0.481395, g[3] -> 0.314046, g[4] -> 1.99654, g[5] -> 0.759683, g[6] -> 0.713266, g[7] -> 0.887778, g[8] -> 1.19497, g[9] -> 0.403486, g[10] -> 0.821527, g[11] -> 0.409302, g[12] -> 0.187768, g[13] -> 0.446988}} I think technically this could have returned variables that ARE zero, since > must be treated like >= -- but that didn't happen. Anyway, the 9-dimensional solution found earlier can easily be tweaked to find non-zero solutions. You can try FindInstance directly, in fact: FindInstance[ Flatten@{Thread[obj1 == 0], Total@gvec == 13, Thread[gvec > 0]}, gvec] {{g[1] -> 5.11765, g[2] -> 2.29094, g[3] -> 0.795716, g[4] -> 2.37257, g[5] -> 0.488027, g[6] -> 0.461637, g[7] -> 0.574777, g[8] -> 0.527069, g[9] -> 0.217686, g[10] -> 0.109726, g[11] -> 0.0246191, g[12] -> 0.0104144, g[13] -> 0.00916999}} Bobby > hi > my basic problem is i have a matrix 13*3 of values > -0.2028 0.12778 -0.09129 > 0.1278 -0.09129 0.07089 > -0.09129 0.07089 -0.05731 > 0.07089 -0.05731 0.04902 > -0.05731 0.04902 -0.04188 > 0.04902 0.04188 0.03747 > ............. > ............ > i want to find wieght factors which when applied to above values would > result in a value close to 0 > such as > -0.2028 g1 + 0.1278 g2 + -0.09129 g3 +0.07089 > g4+........................g13=min > 0.12778 g1+-0.09129g2 + 0.07089 g3 + > -0.05731g4+.........................g13=min > -0.09129g1+0.07089g2+ -0.05731g3 + 0.04902 > g4+........................g13=min > howeverthe values of g's should be subjected to the constraint > g1+g2+g3+.........................g13=13 and all the wieghts must be > nonzero > Is it possible > thankyou for your patience -- DrMajorBob@bigfoot.com === Subject: Re: solution to undetermined linear equation Hi Shame, your condition g1+g2+g3+..g13=13 is simply an additional equation.Therefore, you have 4 instead of 3 equations. Your 3x13 matrix M becomes a 4 x 13 matrix with and additional row of {1,1,1...} and your equations read: M.g == rhs, where g is the searched solution and rhs the vector {0,0,..,0,13}. You have now 4 equations and 13 variables. Therefore, there maybe many solutions. You can now either use LinearSolve, this returns one of the many possible solution. The rest you may get from the NullSpace. Or you can use Solve that gives you 4 g's as a function of the remaining g's hope this helps, Daniel > hi > > my basic problem is i have a matrix 13*3 of values > > -0.2028 0.12778 -0.09129 > 0.1278 -0.09129 0.07089 > -0.09129 0.07089 -0.05731 > 0.07089 -0.05731 0.04902 > -0.05731 0.04902 -0.04188 > 0.04902 0.04188 0.03747 > > ............. > ............ > > > i want to find wieght factors which when applied to above values would result in a value close to 0 > > such as > > -0.2028 g1 + 0.1278 g2 + -0.09129 g3 +0.07089 g4+........................g13=min > 0.12778 g1+-0.09129g2 + 0.07089 g3 + -0.05731g4+.........................g13=min > -0.09129g1+0.07089g2+ -0.05731g3 + 0.04902 g4+........................g13=min > > > howeverthe values of g's should be subjected to the constraint > > g1+g2+g3+.........................g13=13 and all the wieghts must be nonzero > > Is it possible > > thankyou for your patience === Subject: Re: Notebook programming: SlideShow: emulating bullet at-a-time Here is another approach that I have used for other things in http://scientificarts.com/worklife This is to have a notebook that contains in its TaggingRules the data (in your case various sets of cells in temporal sequence contained in a list) the material that you want to access. A click of your IR Remote would then execute a function that takes this data, grabs the notebook, and then deletes that set from the list. (TaggingRules doesn't need to conatain rules: it can contain any data one wishes.) Note that one can use Tagging Rules at the notebook level or at the cell level. So, for example you might have a Section cell that has TaggingRules that contain the bullets that are to be displayed below it. Of course this is just a proto idea and needs some actual work to see if it's viable. David > To those of you who have some experience with Notebook > programming: I've been trying to write commands for keystrokes that > emulates the standard add-a-bullet-to-current-display that > are common in other presentation applications. (I am giving > a talk about using mathematica to teach math to engineers.) I have a IR remote device that I can use to send > programmable key-strokes to mathematica (like -> to go to > next page). To add a bullet to the display, > I've been trying two strategies without success. 1. Recursive grouping of text cells, editing > ../../KeyEventTranslations.tr with something such as: KeyEvent[key,Modifiers->{..,..}], > FrontEndExecute[{ > FrontEnd`SelectionMove[FrontEnd`InputNotebook[],Next,CellGroup], > FrontEnd`FrontEndToken[FrontEnd`InputNotebook[],OpenClosedGroup], > ---and then SelectionMove to After and then Previous---} (* I can't get this to work, because I can't find a way to > move the selection to the next closed group *) 2. Set the Option->0 for all bullets to be revealed, > then (pseudocode) Select Next Text cell, > SetOption[??CurrentSelection??, Opacity->Automatic} > Here I fail, because I can only get the global options set, > and not that for the particular cell. Can anyone think of a method to make these strategies work; > or, suggest one that has a better chance of succeeding? As always with talks, this is a last-minute job. I have a > fall-back strategy which is to make separate pages with > increasing numbers of bullets. But, I'd rather not use this > because (well, I've sunk too much time into this method and > I know its lost time and should stop now, but, well you > know..), and I like to be able to back-up during > presentations and not remove bullets one at a time > === Subject: Re: File reading and writing within for loop On Nov 28, 4:02 pm, Jens-Peer Kuska filename[i_Integer] := > in_ <> StringTake[ > ToString[PaddedForm[i, 2, NumberPadding -> {0, 0}]], -2] < .dat iolst={#, StringReplace[#, in -> out]} & /@ > Table[filename[i], {i, 0, 50}] doSomething[{in_String,out_String}]:=Module[{dta} > dta=Import[in]; > Export[out,dta] > ] and no loop with doSomething /@ iolst Jens Suppose I have 50 files like following names, in_00.dat, > in_01.dat, in_02.dat, ........ > I want to read all the files, manipulate and save output like > out_00.dat, out_01.dat, out_02.dat..... within a for loop. Could you > please suggest how to do these ? If you have answer without for loop > is also OK. nilaakash nilaakash === Subject: Re: Re: different eigenvectors Isn't the issue far more complicated when the eigenvalues are repeated? > To take an extreme example, any n linearly independent vectors are an > eigenset for the Identity Matrix. Maybe I missed the point of all > this :-) Quoting Jean-Marc Gulliet : >> I am using Eigenvectors function to calculate eigenvectors in >> mathematica 5.2. >> while comparing the results with the eigenvectors (of same matrix) >> computed in another system, i found that both the results are bit different >> with some values having opposite sign and coloumns rearranged. Note sure what the question, but something tells me that you are unclear > about eigenvectors non-uniqueness. Second, for a given eigenvalue you can find infinitely many > eigenvectors. Indeed, any non-zero scalar multiple of an eigenvector is > also an eigenvector (for the corresponding eigenvalue of course). Second, for a given matrix, different CAS may produce the eigenvalues in > different order, so the corresponding eigenvectors may be in different > order from one system to another. Third, for a given matrix, different CAS may compute the eigenvectors in > different ways. One may look for orthonormal (perpendicular and unitary) > eigenvectors, while another system may satisfy with just orthogonal > (perpendicular) eigenvectors. So, if you want to check the results from one CAS against the results > from another CAS, first, you must check that the eigenvalues returned by > both systems are the same (whatever their order) and that the > corresponding eigenvectors returned by both system are scalar multiple. Here is an example with a 2 by 2 reflection matrix that illustrates the > usage of the *Eigensystem* function, which returns the eigenvalues > followed by the eigenvectors. In[1]:= m = {{0, 1}, {1, 0}} Out[1]= {{0, 1}, {1, 0}} In[2]:= Eigensystem@m Out[2]= {{-1, 1}, {{-1, 1}, {1, 1}}} In[3]:= Thread@% Out[3]= {{-1, {-1, 1}}, {1, {1, 1}}} In[4]:= (m.Last@# == First@#*Last@#) & /@ % Out[4]= {True, True} In[5]:= m.{1, -1} == (-1)*{1, -1} Out[5]= True In[6]:= m.(c*{1, -1}) == (-1)*(c*{1, -1}) Out[6]= True In[7]:= {-1, 1}.{1, 1} Out[7]= 0 In[8]:= Normalize /@ {{-1, 1}, {1, 1}} Out[8]= {{-(1/Sqrt[2]), 1/Sqrt[2]}, {1/Sqrt[2], 1/Sqrt[2]}} Oh, sure; I agree that many other things could have been told (though I am not sure about what issues you are talking about since from Mathematica's point of view there is no issue); but since the OP did neither ask --- explicitly --- any question nor give any example, it is somehow hard to find where to stop ideally! Speaking about Mathematica and repeated eigenvalues, the documentation center tells us that, All the non-zero eigenvectors given are independent. If the number of eigenvectors is equal to the number of non-zero eigenvalues, then corresponding eigenvalues and eigenvectors are given in corresponding positions in their respective lists. Moreover, If there are more eigenvalues than independent eigenvectors, then each extra eigenvalue is paired with a vector of zeros. Therefore, as one can see below, the method I indicated in my previous reply, works well in such cases. The following matrix has two repeated eigenvalues but independent eigenvectors, while the next one has only two independent eigenvectors. m = {{2, 0, 0}, {0, 2, 0}, {0, 0, 1}}; {vals, vecs} = Eigensystem[m] m.Transpose@vecs == Transpose@vecs.DiagonalMatrix@vals Out[2]= {{2, 2, 1}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}} Out[3]= True m = {{2, 1, 0}, {0, 2, 0}, {0, 0, 1}}; {vals, vecs} = Eigensystem[m] m.Transpose@vecs == Transpose@vecs.DiagonalMatrix@vals Out[5]= {{2, 2, 1}, {{1, 0, 0}, {0, 0, 0}, {0, 0, 1}}} Out[6]= True Note that other systems may return the eigenvectors in a different fashion. For instance, on another system, although the eigenvalues are given in the same order than Mathematica, the eigenvectors are in a different order for the first matrix, and for the second matrix two non-zero linearly-dependent eigenvectors are returned for the repeated eigenvalues. >> m = [2 0 0; 0 2 0; 0 0 1] m = 2 0 0 0 2 0 0 0 1 >> [V, D] = eigs(m) V = 1 0 0 0 1 0 0 0 1 D = 2 0 0 0 2 0 0 0 1 >> m = [2 1 0; 0 2 0; 0 0 1] m = 2 1 0 0 2 0 0 0 1 >> [V, D] = eigs(m) V = -1.0000 1.0000 0 0.0000 0 0 0 0 1.0000 D = 2 0 0 0 2 0 0 0 1 -- Jean-Marc === Subject: Re: Re: Hiding number cell Unlike you, perhaps, I do not READ code or output in an e-mail -- I immediately (if it looks vaguely interesting) paste it into Mathematica and run it. Frequently I find the code doesn't do what the post says it does, and even more often, I want to modify it and see what happens THEN, so this seems a useful strategy. That frequently means, of course, that I've pasted output cells as well as input, so I spend a few seconds deleting them. But even if I don't delete them, it usually makes no difference. I usually don't paste interspersed textual comments, but sometimes I do, and I have to delete those too. Generally they're not in-line with the code (they certainly shouldn't be!), so it's not hard to tell what's what. (* I'm not talking about Mathematica comments, although I never use those, either. Until now. *) Deleting In[..] and Out[..] crap (as I call it) is slightly more tedious... it's usually in-line, and deleting it is mandatory, since the code won't run while they are present. It's true that posts without In and Out may (at times) leave a reader wondering which lines are input and which are output (which to delete under my strategy described above)... but evaluating them one at a time (or all at once) will generally make it clear in seconds. Anyway, I think an experienced reader can tell input from output most of the time just by looking. As for knowing in what order you've evaluated things... I evaluate from the top down. Strange, I know, but that's just me! If I change anything I reevaluate from there down, and if in doubt, I evaluate everything (top-down) to that point. One line that, in fact, I often evaluate out of order is: Quit but then I delete that cell. Over time I've developed second-nature habits to support the overall strategy. As you have done for your own strategy, of course. Any number of things can cause me to delete an e-mail precipitously... and a dozen In/Out instances is frequently one of them. Nobody out there really needs my help, of course, so... to each his own! Bobby >> I never allow In/Out labels (they're hideous in a notebook, more so when >> posting to the group, and VERY inconvenient for a reader pasting back >> into >> a notebook)... Well, it is just a matter of taste :-D It is possible to copy without > In/Out labels, but I like to include them in MathGroup postings to > make the posts more readable, and make the distinction between input > and output cells clear. I also copy the cells from messages > one-by-one to see which output was generated from which input. > And I have noticed no surprises whatsoever, unpleasant or otherwise. I included that warning only because in the past there were a few > posts from new users who got confused by the lack of direct > correspondence between cell contents and kernel state. If you're more > organized than me and can keep track of which cells were evaluated in > what order, than of course there won't be any unpleasant surprises! > :-) The same goes for TraditionalForm vs StandardForm output. Szabolcs -- DrMajorBob@bigfoot.com === Subject: Printing Subscripted Variable on Screen? I want a subscripted variable, which has been entered in a notebook text cell, to print on the screen, when the notebook is executed. The subscripted variable is in the notebook, but it is not printed on the screen. John === Subject: Re: Printing Subscripted Variable on Screen? Hi John, here is a simpler solution that formats better: CreateDocument[TextCell@Row[{The symbol, ,Subscript[x,s],denotes the probability that the outcome of the roll is is i,i=1,2,3,...,6.}]] Further, CreateDocument creates a whole document. If you want to write a single cell into a document, use: NotebookWrite[notebook,data] Daniel > I want a subscripted variable, which has been entered in a notebook > text cell, to print on the screen, when the notebook is executed. The subscripted variable is in the notebook, but it is not printed on > the screen. John > === Subject: Re: Printing Subscripted Variable on Screen? Hi John, here is a pretty ugly solution. I do not know if an easier one is available. E.g.: CreateDocument[ RowBox[{aaa , SubscriptBox[x, s], , ssss}] //DisplayForm ] hope this helps, Daniel > I want a subscripted variable, which has been entered in a notebook > text cell, to print on the screen, when the notebook is executed. The subscripted variable is in the notebook, but it is not printed on > the screen. John === Subject: Adding coloured Polygon to a BarChart The below chart successfully uses Epilog to include some text on the BarChart: Needs[BarCharts`] barShape1 = BarChart[{1, 2, 3}, Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold]}] However, I want to add a small Polygon to the graph. Again this works well as long as the Polygon is black: barShape2 = BarChart[{1, 2, 3}, Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}] But I would like to make the Polygon a red colour. But the below does not work : barShape3 = BarChart[{1, 2, 3}, Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], Graphics[{Red, Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}]}] Does anyone have a suggestion for adding a coloured Polygon to a BarChart ? Tom === Subject: Re: Adding coloured Polygon to a BarChart Your only problem was that you put an extra level of Graphics in the Epilog list. The following works: BarChart[{1, 2, 3}, Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], {Red, Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}}] But Epilog is a little inconvenient. If you want to add many things Epilog becomes the tail that wags the dog. And suppose you wanted to add a curve to the plot? With the Presentations package all elements are combined in one drawing statement. Here is a bar chart with a curve and your extra label and polygon. Needs[Presentations`Master`] Draw2D[ {BarChart[{1, 4, 9}] // DrawGraphics, Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], Red, Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}], Draw[x^2, {x, 0, 3.2}]}, AspectRatio -> 1, Axes -> True, AxesOrigin -> {0, 0}, Ticks -> {CustomTicks[Identity, {1, 3, 1, 1}], Automatic}] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ The below chart successfully uses Epilog to include some text on the > BarChart: Needs[BarCharts`] > barShape1 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold]}] However, I want to add a small Polygon to the graph. Again this works > well as long as the Polygon is black: barShape2 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}] But I would like to make the Polygon a red colour. But the below does > not work : barShape3 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Graphics[{Red, > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}]}] Does anyone have a suggestion for adding a coloured Polygon to a > BarChart ? Tom > === Subject: Re: Adding coloured Polygon to a BarChart > Your only problem was that you put an extra level of Graphics in the Epilog > list. The following works: BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, > Bold], {Red, > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}}] But Epilog is a little inconvenient. If you want to add many things Epilog > becomes the tail that wags the dog. And suppose you wanted to add a curve to > the plot? With the Presentations package all elements are combined in one > drawing statement. Here is a bar chart with a curve and your extra label and > polygon. Needs[Presentations`Master`] Draw2D[ > {BarChart[{1, 4, 9}] // DrawGraphics, > Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Red, > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}], > Draw[x^2, {x, 0, 3.2}]}, > AspectRatio -> 1, > Axes -> True, AxesOrigin -> {0, 0}, > Ticks -> {CustomTicks[Identity, {1, 3, 1, 1}], Automatic}] -- > David Park > djmp...@comcast.nethttp://home.comcast.net/~djmpark/ > The below chart successfully uses Epilog to include some text on the > BarChart: Needs[BarCharts`] > barShape1 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold]}] However, I want to add a small Polygon to the graph. Again this works > well as long as the Polygon is black: barShape2 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}] But I would like to make the Polygon a red colour. But the below does > not work : barShape3 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Graphics[{Red, > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}]}] Does anyone have a suggestion for adding a coloured Polygon to a > BarChart ? Tom- Hide quoted text - - Show quoted text - === Subject: Re: Adding coloured Polygon to a BarChart and barShape3 = BarChart[{1, 2, 3}, Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], {Red, Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}}] ?? Jens The below chart successfully uses Epilog to include some text on the > BarChart: Needs[BarCharts`] > barShape1 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold]}] However, I want to add a small Polygon to the graph. Again this works > well as long as the Polygon is black: barShape2 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}] But I would like to make the Polygon a red colour. But the below does > not work : barShape3 = > BarChart[{1, 2, 3}, > Epilog -> {Style[Text[First, {1, 2}, {0, -1}], 12, Red, Bold], > Graphics[{Red, > Polygon[{{1.25, 2}, {1.5, 2}, {1.5, 2.25}, {1.25, 2.25}}]}]}] Does anyone have a suggestion for adding a coloured Polygon to a > BarChart ? Tom > === Subject: Convert Binary Image to Column Vector Can a 30x30 binary image be converted directly into a column vector of 900 components in Mathematica? Or must the image first be put into matrix form? I am using the command: Flatten@Transpose@t1, where t1 is my binary image, and it seems to give me a vector but I'm not sure if it's the one that I desire. If I first convert my image into matrix form and define my matrix as m and then use this command, Flatten@Transpose@m, then I get an output of Transpose[...] and my 30 x 30 matrix is explicitly written within the Transpose brackets. This does not provide me a column vector with 900 components, which is what I am looking for. Any thoughts? === Subject: Re: Convert Binary Image to Column Vector What is a binary image for you ? something like img=Graphics[Raster[{{0, 1}, {1, 0}}, {{0, 0}, {2, 2}}, {0, 1}, ColorFunction -> GrayLevel], AspectRatio -> Automatic] ?? or something like bm={{0, 1}, {1, 0}} .. Since Flatten[bm] will make a vector out of a matrix as well as Flatten[img[[1,1]]] it is not clear what ordering you perfer, i.e. should in bm[[j,i]] the index i run first or the index j. This is what you change with Transpose[]. Jens > Can a 30x30 binary image be converted directly into a column vector of > 900 components in Mathematica? Or must the image first be put into > matrix form? I am using the command: > Flatten@Transpose@t1, where t1 is my binary image, and it seems to > give me a vector but I'm not sure if it's the one that I desire. If I first convert my image into matrix form and define my matrix as > m and then use this command, > Flatten@Transpose@m, then I get an output of Transpose[...] and my > 30 x 30 matrix is explicitly written within the Transpose brackets. > This does not provide me a column vector with 900 components, which is > what I am looking for. Any thoughts? === Subject: Re: Convert Binary Image to Column Vector > Can a 30x30 binary image be converted directly into a column vector of > 900 components in Mathematica? It depends on what you mean by image, > Or must the image first be put into > matrix form? and what you mean by matrix. > I am using the command: > Flatten@Transpose@t1, This command works if t1 is a two-dimensional array, i.e. a nested list that looks like this when output is set to StandardForm: {{1,2},{3,4}} > where t1 is my binary image, and it seems to > give me a vector but I'm not sure if it's the one that I desire. If I first convert my image into matrix form How did you do this conversion? If the image is inside Graphics[Raster[...]], then you need to extract the contents of Raster[...]. > and define my matrix as > m and then use this command, > Flatten@Transpose@m, then I get an output of Transpose[...] and my > 30 x 30 matrix is explicitly written within the Transpose brackets. > This does not provide me a column vector with 900 components, which is > what I am looking for. In Mathematica there are no column or row vectors, only vectors and matrices (one might call n*1 matrices column vectors and 1*n matrices row vectors). Have you read the post I suggested in my answer to you last question? Here's the link again: If you use TraditionalForm output, try switching to StandardForm for a while to better understand how matrices/vectors are represented. Szabolcs === Subject: Re: Convert Binary Image to Column Vector > Can a 30x30 binary image be converted directly into a column vector of > 900 components in Mathematica? Yes. Either Flatten@t1 or Flatten@Transpose@t1 will do the job, though the elements will be put in different order (see an example below). > Or must the image first be put into matrix form? No. And if by matrix form you mean MatrixForm, never do that for MatrixForm must be reserved just for display purpose. > I am using the command: > Flatten@Transpose@t1, where t1 is my binary image, and it seems to > give me a vector but I'm not sure if it's the one that I desire. The following examples illustrate the differences between the outputs produced by Flatten@t1 and Flatten@Transpose@t1, respectively. Mathematica 6.0 for Microsoft Windows (32-bit) Copyright 1988-2007 Wolfram Research, Inc. In[1]:= t1 = {{a, b}, {c, d}}; In[2]:= t1 // MatrixForm Out[2]//MatrixForm= a b c d In[3]:= Flatten@t1 Out[3]= {a, b, c, d} In[4]:= Flatten@Transpose@t1 Out[4]= {a, c, b, d} -- Jean-Marc === Subject: Re: The integrand has evaluated to non-numerical values for all > Being given the function: >> f[x_,y_]:= Sin[x*y]*Exp[-(y-1)^2]/(x*y) , >> I want to integrate it with respect to y, from 0 to Infinity, and to >> obtain a function of x only, F[x]. >> I typed the command: >> F[x_]:= Assuming[x>0, Integrate[f[x,y],{y,0,Infinity}]] >> but the integral remained unevaluated by Mathematica 6. >> After this, I typed the command: >> F[x_]:= Assuming[x>0, NIntegrate[f[x,y],{y,0,Infinity}]] >> but I received the error message: The integrand f[x,y] has evaluated to >> non-numerical values for all sampling points in the region with >> boundaries {{Infinity,0.}}. >> I looked at the explanations of the error message and there it was >> suggested to give a particular value to x and to compute the integral for >> that particular value. I gived one particular value and I obtained the >> expected result. Anyway I need to obtain an analytical expression for all >> x>0. >> My question is, how can be performed the integral and to obtain the >> analytical function F[x]? You could change the form of the original expression to be written as > exponentials only, then do the integration. For instance, In[1]:= expr = Sin[x*y]*Exp[-(y - 1)^2]/(x*y) Out[1]= > Sin[x y] > ---------------- > 2 > (-1 + y) > E (x y) In[2]:= f = TrigToExp@expr Out[2]= > 2 2 > -(-1 + y) - I x y -(-1 + y) + I x y > I E I E > --------------------- - --------------------- > 2 x y 2 x y In[3]:= F[x_] = Assuming[x > 0, Integrate[f, {y, 0, Infinity}]] Out[3]= > 1 3 > --------------- ((-2 - I x) (2 I + x) > 2 > 24 E x (4 + x ) 5 1 2 > HypergeometricPFQ[{1, 1}, {2, -}, -(-) (-2 I + x) ] + > 2 4 2 > x /2 3 > (E (-2 + I x) (-2 I + x) 5 1 2 > HypergeometricPFQ[{1, 1}, {2, -}, -(-) (2 I + x) ] - > 2 4 2 > 1 - I x + x /4 I x > 6 (2 E Sqrt[Pi] (-2 I + x) Erf[1 - ---] + > 2 2 > 2 + 1/4 (2 I + x) I x > 2 E Sqrt[Pi] (2 I + x) Erf[1 + ---] + > 2 2 > x /2 2 I x I x > I E (4 + x ) (Pi Erfi[1 - ---] - Pi Erfi[1 + ---] - > 2 2 2 > 2 Log[-2 - I x] + 2 Log[-2 + I x] + Log[-(-2 I + x) ] - 2 > 2 x /2 > Log[-(2 I + x) ]))) / E ) In[4]:= F[2] Out[4]= > 1 5 > ----- (64 HypergeometricPFQ[{1, 1}, {2, -}, 2 I] + > 384 E 2 1 2 5 > -- (64 E HypergeometricPFQ[{1, 1}, {2, -}, -2 I] - > 2 2 > E 2 - 2 I > 6 ((4 - 4 I) E Sqrt[Pi] Erf[1 - I] + 2 + 2 I > (4 + 4 I) E Sqrt[Pi] Erf[1 + I] + 2 > 8 I E (I Pi + Pi Erfi[1 - I] - Pi Erfi[1 + I] - 2 Log[-2 - 2 I] + 2 Log[-2 + 2 I])))) In[5]:= % // N // Chop Out[5]= 0.453078 -- > Jean-Marc > I tried comparing my series solution (see my parallel posting to yours) with your closed-form solution. When I use my most accurate series approximation Last[fapprox] (1/(3628800 x))[ExponentialE]^(-(x^2/4)) (x (-20 [ExponentialE]^(x^2/4) (-37512+2252 x^2-54 x^4+x^6)+Sqrt[[Pi]] (1149120-110880 x^2+4032 x^4-72 x^6+x^8))+665280 [ExponentialE]^(x^2/4) [Pi] Erf[x/2]+10 Sqrt[[Pi]] (196224-41664 x^2+2352 x^4-56 x^6+x^8) Erfi[x/2]) from my posting I get F[2]=0.636495, which disagrees with your 0.453078 (which I can reproduce). Curious! I then tried evaluating the integral numerically using With[{x = 2.}, NIntegrate[([ExponentialE]^-(-1 + y)^2 Sin[x y])/(x y), {y, 0, [Infinity]}]] which gives 0.63577 in close agreement with my series approximation, but in disagreement with your result. I wonder what is going on here? Steve Luttrell West Malvern, UK === Subject: Re: Controlling evaluation Using dummy symbol, then replacing it, like you did, is one of the techniques that Robby Villegas' suggested for dealing with the overarching evaluator. http://library.wolfram.com/conferences/devconf99/villegas/UnevaluatedExpress ions/index.html He gives a few other approaches, I think the most general one is to use Replace* to manipulate expressions into the form you want. For instance, the function below uses Extract/Position/ReplacePart to extract expressions matching pattern, evaluate them, then stuff the results back in (*evaluates subexpressions of expr matching pattern,expr's head should have HoldAll attribute*) pointEvaluate[expr_, patt_] := Module[{poses, parts}, poses = Position[expr, patt]; (*ReplacePart doesn't work for empty position lists*) If[Length[poses] > 0,(*extract the parts (it also evaluates them), put them back in*)parts = Extract[expr, poses]; ReplacePart[expr, parts, poses, MapIndexed[#2 &, parts]], (*no pattern fits,return expr unchanged*) expr ] ] arg1 = {a, b, c}; arg2 = {d, e, f}; pointEvaluate[Condition[ex, samelistQ[arg1, arg2]], HoldPattern[arg1 | arg2]] pointEvaluate[Hold[{1 + 2, 3*4, 5 + 6}], HoldPattern[_ + _]] My own question for the group -- what is the recommended way to define a function only for arguments with HoldAll head (like Hold, Condition, etc)? Yaroslav Evaluate will evaluate its arguments if it appears as argument in a function with one of the Hold.. attributes. Consider: Condition[expr, samelistQ[arg1 // Evaluate, arg2 // Evaluate]] Condition has the attribute HoldAll. If samelistQ has the asme attribute, we therefore need to write Evaluate twice: Condition[expr, Evaluate[samelist[Evaluate[arg1],Evaluate[arg1]]] hope this helps, Daniel I am building a package and I need to programmatically construct > expressions . > At a certain point I have arg1 = {a, b, c}; (* some list *) > arg2 = {d, e, f}; (* some other list *) > samelistQ[list1_List, list2_List] := Now I want to construct an expression like Condition[expr, samelistQ[arg1, arg2]] with arg1 and arg2 evaluated, but with samelist[...] not evaluated. > In other words, I want to obtain exactly this Condition[expr, samelistQ[{a, b, c}, {d, e, f}]] where the 2 args have been evaluated, but samelistQ[...] appears > always unevaluated > What is expr is not important, just leave it unassigned. > The problem is that Condition blocks the evaluation of arg1 and arg2 > and of samelistQ. Now, doing Condition[expr, samelistQ[arg1 // Evaluate, arg2 // Evaluate]] does not work, because Evaluate does not disappear. > So what to do? I tried Hold, ReleaseHold, ect, but it didn't work. This is how I solved it Condition @@ List[expr, pp[arg1, arg2]] /. pp -> samelistQ where pp is an unassigned symbol. > My question: isn't there a better way, using the functions which are > supposed to control evaluation (Hold, Evaluate, ect) to achieve this > result? Perhaps a related more general question: > how do we block > f[x,y] > while allowing evaluation of x, and y ? === Subject: Re: Controlling evaluation My own question for the group -- what is the recommended way to define > a function only for arguments with HoldAll head (like Hold, Condition, > etc)? > The obvious solution is fun[completeArg : (head_[___])] /; MemberQ[Attributes[head], HoldAll] := something (* do something with completeArg *) But most probably you already know about this solution. I do not know if there are better or more compact ways to do it. -- Szabolcs === Subject: Re: slot argument weirdness >I have to produce some bulky matrices which are described by two >parameters and it seems the easiest way to produce them is as >follows (I took out all the complexity and just left in the slots to >illustrate my problem). v is the parameter array. >v = {2, 5}; >myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] >giving {{2, 5}, {5, 2}} and all is well. >But since the actual form in the first argument in Apply is really a >large messy thing, I thought I'd produce it just once in the >notebook and represent it with: >m = {{#1, #2}, {#2, #1}}; >But geez, this doesn't work at all: >MyMatrix2= Apply[m &, v] >gives {{#1, #2}, {#2, #1}} Are you using version 6 of Mathematica? If yes, did you notice the color of the slots was not the color Mathematica assigns by default to function arguements but instead was the color Mathematica uses to indicate a syntax error with your definition for m? Changing things to match the syntax Mathematca expects works, i.e., m = {{#1, #2}, {#2, #1}}&; makes m a function and In[4]:= Apply[m, v] Out[4]= {{2, 5}, {5, 2}} yields the desired result -- To reply via email subtract one hundred and four === Subject: Re: Insert a Math Symbol in Text in Notebook? >Using Mathematica 6. >Symbol is Subscript[p,i]. >Tried ctrl 9 symbol cntrl 0. Didn't work. The keystrokes to enter this would be p ctrl - i At least this works fine for me with version 6 or earlier on a Mac. -- To reply via email subtract one hundred and four === Subject: Re: ToolTips in SlideShow: Doesn't work in FullScreen? Can you be more specific in what you did and what Tooltip (note the lower case t) you used? I just created a new Slideshow, inserted one of the Documentation Center examples in the Input cell of the template Mathematica 6 gave me: Plot[Tooltip[{Sin[x], Cos[x]}], {x, 0, 10}] When I change Format>Screen Environment to Slideshow, I have no difficulty seeing the tooltips on the two curves, even when the notebook is left at its default size, which is far from full-screen. > In the SlideShow environment, I am able to get ToolTips to > work, unless I am in FullScreen mode, where it doesn't work. Am I missing something obvious to get it to work? > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Insert a Math Symbol in Text in Notebook? Hi John, short cut for subscript is ctrl_ Look up help: guide/MathematicalTypesetting hope this helps, Daniel > Using Mathematica 6. Symbol is Subscript[p,i]. Tried ctrl 9 symbol cntrl 0. Didn't work. John > === Subject: Re: Insert a Math Symbol in Text in Notebook? > Using Mathematica 6. Symbol is Subscript[p,i]. Tried ctrl 9 symbol cntrl 0. Didn't work. John > Subscripts are entered using CTRL-- (CTRL-minus or CTRL-_) on a US English keyboard. -- Szabolcs === Subject: Re: Partition a list into sublists of unequal size I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? This isn't really simpler ... but here's another way: In[1]:= l1 = RandomInteger[{0, 1}, {20}] Out[1]= {1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1} In[2]:= l2 = Accumulate[l1] - l1 Out[2]= {0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10, 10, 11, 11} In[3]:= l3 = Range[20] (* the list to be partitioned *) Out[3]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} In[4]:= Split[Transpose[{l2, l3}], First[#1] == First[#2] &][[All, All, 2]] Out[4]= {{1}, {2, 3, 4, 5, 6}, {7}, {8}, {9}, {10}, {11}, {12, 13}, {14}, {15, 16}, {17, 18}, {19, 20}} -- Szabolcs === Subject: Re: Partition a list into sublists of unequal size How's this? list = {1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0}; subSeqs = Split[list, #1 == 0 &] {{1}, {0, 0, 1}, {0, 0, 1}, {1}, {0, 1}, {0, 0, 0, 0, 1}, {0}} subSeqs /. {0 ..} :> Sequence[] {{1}, {0, 0, 1}, {0, 0, 1}, {1}, {0, 1}, {0, 0, 0, 0, 1}} For a list of just zeroes, that goes like list = {0, 0, 0}; subSeqs = Split[list, #1 == 0 &] {{0, 0, 0}} subSeqs /. {0 ..} :> Sequence[] {} And if it's all ones: list = {1, 1, 1}; subSeqs = Split[list, #1 == 0 &] {{1}, {1}, {1}} subSeqs /. {0 ..} :> Sequence[] {{1}, {1}, {1}} Bobby I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? Anthony -- DrMajorBob@bigfoot.com === Subject: Re: Partition a list into sublists of unequal size I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? Anthony Good day, A solution with Split: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0}; list2={5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35}; #[[All,2]]& /@ Split[Transpose[{list,list2}], #1[[1]]==0 && (#2[[1]]==0 || #2[[1]]==1)&] {{5},{7,9,11},{13,15,17},{19},{21,23},{25,27,29,31,33},{35}} V.Astanoff === Subject: Re: Partition a list into sublists of unequal size This is a little simpler and maybe a little faster: Take[targetlist,#]& /@ Transpose@{Prepend[Most@#+1,1],#}& @ Flatten@Position[list,1] === Subject: Re: Partition a list into sublists of unequal size > I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? The following might not be the simpler way you were expected; still, it might be a source of inspiration :) lst = {1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0}; myPart[target_List, source_List] /; Length@target == Length@source := Take[target, #] & /@ Thread[{PadLeft[Most@# + 1, Length@#, 1], #} &[ Flatten@Position[source, 1]]] myPart[lst, lst] returns {{1}, {0, 0, 1}, {0, 0, 1}, {1}, {0, 1}, {0, 0, 0, 0, 1}} (Note that in the case where the source and target lists are the same Split[lst, (#1 != 1) &] would be enough to get the desired result.) Also, in the example you provided, the last sequence of running zeros is not taken into account. Is this desired? -- Jean-Marc === Subject: Re: Partition a list into sublists of unequal size list = {1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0}; test = Array[a, {16}]; First /@ Rest[ FoldList[{Take[test, {Min[#1[[2]] + 1, #2], #2}], #2} &, {1, 1}, Flatten@Position[list, 1]]] may do that. Jens I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? Anthony > === Subject: Re: Partition a list into sublists of unequal size I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? I'm not sure about simple, but here's my approach list[[Range[#[[1]]+1,#[[2]]]]]]&/@Partition[Prepend[positions,0],2,1] Ssezi === Subject: Re: Partition a list into sublists of unequal size Hi Anthony, here is an example: pos={1,4,7,8,10,15}; dat=Range[pos[[-1]]]; FoldList[(Print[ind=,{#1,#2}];Take[dat,{#1[[-1]]+1,#2}])&,{0},pos] hope this helps, Daniel I have a list that looks like the following: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} I then find the positions of the 1s in the list: positions = Flatten@Position[list,1] {1,4,7,8,10,15} I then want to partition a third list into sublists so that the first > sublist is from index 1;;1, the second sublist is from index 2;;4, the > third sublist is from index 5;;7, the fourth sublist is just element > 8, etc. Currently, I use Partition on the positions sublist with overlap as > in: Partition[Join[{1},positions],2,1] {{1,1},{1,4},{4,7},{7,8},{8,10},{10,15}} I then use this list to partition the target list by Mapping Take to > each element of this list and adjusting the first index appropriately. I am sure there must be a simpler way to do this. Can anyone tell me > how to do this operation? Anthony > === Subject: Re: Partition a list into sublists of unequal size Proposed recipe: 1. Tighten your description a bit to partition a list into sublists that start with an instance of a particular value. 2. Note that Partition is not well suited to this task. Browse See Also near the bottom of help on Partition. 3. Split looks good. Try it: list={1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0} Split[list, #1 != 1 &] 4. Fiddle with the ends, depending upon your particular needs (not yet clear to me). Tom When responding, please replace news with my first initial and full last name, as one word. Tom Burton === Subject: Re: Fold and Cross Just one more thing: When working with scalar functions, you can directly assign to Derviative, e.g. In[1]:= Derivative[1][f] = g Out[1]= g In[2]:= f'[x] Out[2]= g[x] See the doc page tutorial/DefiningDerivatives === Subject: Memory consumption problem Hallo, I use mathematica mainly to perform one dimmensional numerical integration, and singular value decomposition of small matrices up to 64x64. I used 5.1, 5.2 and now I use 6.0 for the same purpose with the code that did not changed much. I observed that the memory consumption increases with the Mathematica version and the most painfull is the fact that the code does not finish evaluation becouse the run out of memory. I tried to slow down my program by deleting f[x_]:=f[x]=... and puting $HistoryLength=0 as well as appending f[x_NumericQ]. I mention that I run the code using command line on Linux workstation. Does anyone have any idea how to overcome this problem? Piotr === Subject: Re: expressions list -> equations list Thread[{a, b, c} == 0] {a == 0, b == 0, c == 0} Solve[{a + 2, b - 3, c} == 0, {a, b, c}] {{a -> -2, b -> 3, c -> 0}} Reduce[{a + 2, b - 3, c} == 0, {a, b, c}] c == 0 && b == 3 && a == -2 Bob Hanlon > 1st of all THX to all who answered my last question. Just one other befor= e > I lend a Mathematica manual from the public lib and pester you no more :-= ) So. Now that I have a tensor it must vanish identically. I Flatten[] it f= irst > and then I have a list of equations...oh, stop, I haven't. REDUCE (if I m= ay > mention the name of a competition :-) could take a Solve[] now because it= > automatically assumes a =0 as default but Mathematica is anally-reten= tive > (a good thing :-) and I somehow must turn {a,b,c} into {a=0,b=0,c=0= }. > Convert to string, global change , -> =0, and } -> =0}, recon= vert > to list? Is that possible? Or is there a less LISP-hack-style solution? -- > Hauke Reddmann <:-EX8 fc3a501@uni-hamburg.de > Er-a svo gott sem gott kve=C3=B0a > =C3=B6l alda sonum, =C3=BEv=C3=AD a=C3=B0 f=C3=A6rra veit > er fleira drekkur s=C3=ADns til ge=C3=B0s gumi. > === Subject: RE: Re: Presentations Package Announcement Yes Ditto - David is a master in dynamic graphics manipulation and animation. If you appreciate the mathematics of poetry, on David's homepage are some quite exquisite translations of Rainer Maria Rilke's and Charles Baudelaire's Cat Poems by Alice Parker. http://home.comcast.net/~djmpark/ There's even a wee bit of a Rule 30 Cellular Automaton in his views on Nation States? Sylvia Hobbs > -----Original Message----- On Behalf > Of DrMajorBob === > Subject: Re: Presentations Package Announcement Wolfram has plenty of experts on algebra, calculus, math, and programming, > but... I doubt they have many (or any) who can craft a meaningful diagram, chart, > or presentation like David Park can. He's a genious at that stuff, and he > has spent years fine-tuning tools to help. The examples alone are worth the price, but beyond that, David has > implemented a MUCH simpler paradigm for combining diverse graphical > elements. The results are native graphics objects in the end, but David's > code makes building them far easier. Bobby > After 10+ years of Mathematica being in existence, why Wolfram can't > seem to > include these capabilities directly in the program I do not understand. > I have now released the Presentations package for Mathematica Version 6. >> Presentations is a follow-on package for DrawGraphics. It can be >> obtained at >> the Mathematica page of my web site below and costs $50. Previous >> purchasers >> of DrawGraphics have been sent email notices and may freely upgrade to >> Presentations. If you are a purchaser who has changed your email >> address and >> have not received a notice please contact me with your current address. >> Presentations is a package designed to facilitate the use of >> Mathematica in >> studying standard textbook material, in writing tutorials for students, >> in >> research, and in using Mathematica in technical communications. >> Although it >> started as basically a graphics package it is now being enlarged to >> accommodate the many new features of Version 6 and to contain generally >> useful features that might not specifically be graphics. >> A 'presentation' is my term for any display of data or information >> about a >> scientific or mathematical concept that goes beyond simple text and >> equations. >> Some of the features of Presentations are: >> 1) Rather than treating graphics as a collection of major plot types >> that >> are difficult to combine, Presentations treats all graphics including >> curves >> and surfaces as graphics primitives that may be easily combined in one >> drawing statement. >> 2) Since graphical elements are all treated as primitives they can be >> easily >> manipulated and transformed. Routines are provided for that and the new >> geometric transformation routines of Version 6 have been cast in a form >> convenient for this use. >> 3) There is a suite of routines for generating custom ticks and grids, >> free >> standing scales, symbolic tick scales, and polar grids to replace the >> usual >> Cartesian axes. >> 4) There are 3D arrows with arrowcones that can be drawn in a number of >> styles. There are routines for marking angle arcs and right angle >> indicators >> on 2D geometrical diagrams. >> 5) For 2D graphics there are the LocatorDraw and LocatorLine routines >> that >> allow the user to temporarily add locators to a graphic, position them, >> and >> then copy the positions into a drawing statement. >> 6) There is provision for Text3D that allows true 3D text that rotates >> with >> the image and hides behind surfaces. >> 7) There is a complete set of routines for complex function graphics. >> These >> include primitives such as ComplexPoint, ComplexLine, ComplexText, >> ComplexCurve etc., that use complex arguments instead of coordinate >> pairs. >> In addition there are complex forms of maps, surface plots, contour >> plots, >> density plots and domain coloring plots that use a single complex >> iterator. >> There is a BranchArg routine that allows the user to set the branch >> line in >> the complex plane at any angle. There is a general multifunction with >> memory >> capability that calculates all function values and orders them to be >> continuous with a previous, close-by, evaluation. There is a Riemann >> sphere >> routine and a StereographicMap routine. There are information panel >> primitives for providing numerical information along with dynamic >> graphics. >> 8) There is an IndefiniteSequences subpackage that allows the >> formatting of >> expressions that contain ellipses to indicate skipped terms or factors >> in >> sums, products, tables, free standing sequences and infix expressions. >> There >> is the ability to do some operations on the expressions and to convert >> them >> to normal Mathematica expressions. >> 9) The Presentations package is a natural extension of standard >> Mathematica; >> it uses the regular Mathematica interface and in no way cuts the user >> off >> from any regular Mathematica functions, including the regular graphics >> functions. >> 10) Presentations is extensively documented with individual Help pages >> for >> each function. In addition there are many extended examples showing >> practical cases of graphics and extended presentations. There are three >> essays on 'Writing Notebooks', 'Writing Presentations' and 'Writing >> Packages' in which I try to give tips on avoiding traps and getting the >> most >> productive use from Mathematica. One example, EllipseArea, illustrates a >> style of writing notebooks that does everything actively and generates >> embedded knowledge. There is a sample toy package that can be used as a >> model for users who have never before written packages. There is an >> included >> optional style sheet that, to my taste, corrects many of the >> deficiencies of >> the WRI style sheets. Currently, the entire package contains 193 files >> and >> occupies some 3.5 MB (without the graphics being evaluated) - a true >> bargain >> for $50. >> David Park >> djmpark@comcast.net >> http://home.comcast.net/~djmpark > > -- > DrMajorBob@bigfoot.com === Subject: Re: Re: Presentations Package Announcement Three points: 1) Everybody -- and I do mean !!!EVERYBODY!!! -- needs to see the presentation linked below. 2) Definitely, David Park's package should be licensed and integrated into the base product. 3) Microsoft never made reliability and security a major focus... unless you mean their own security. Bobby > point is, graphics and presentation construction capability had been > considered a core strength of Mathematica for as long as I can remember, > and yet functions that many of us would consider fundamental are only > found as > add-ons with varying levels of support and extra cost. I believe > Wolfram should look more globally at what people are doing with > mathematical graphics and do a much better job of reducing the > requirements for folks to either a: reinvent the wheel or b: purchase > extra packages. If that means that they license Mr. Park's code and > integrate the functionality directly, perhaps that is a good solution. for an example of extraordinary graphics, take a look at the following > presentation: http://www.ted.com/index.php/talks/view/id/92 I think we all know that capability and usability are two different > things. I often wonder how many hours people have to spend to get the > results they do when using Mathematica - what percentage coding, > debugging, etc. > before getting meaningful results, especially in larger projects that > include text and graphics, along with developing the calculation > strategies. > I wish that the measure wolfram used to include new functions was more > usability based - designed to reduce time to construct common tasks, > reduce keystrokes, etc. As a interesting measure, I wish that when > people posted to the demomstrations project that they also included an > honest indication of the time spent to develop / release their code. > for a system as diverse and complex as Mathematica, usability would > seem to be > as big a shift in focus as was reliability and security was for > Microsoft a few years ago. > on another note, I am also deeply appreciative of the level on online > support wolfram gives to this newsgroup. The Mathematica organization > is full > of very wise and gifted people. -- DrMajorBob@bigfoot.com === Subject: Re: Presentations Package Announcement point is, graphics and presentation construction capability had been considered a core strength of Mathematica for as long as I can remember, and yet functions that many of us would consider fundamental are only found as add-ons with varying levels of support and extra cost. I believe Wolfram should look more globally at what people are doing with mathematical graphics and do a much better job of reducing the requirements for folks to either a: reinvent the wheel or b: purchase extra packages. If that means that they license Mr. Park's code and integrate the functionality directly, perhaps that is a good solution. for an example of extraordinary graphics, take a look at the following presentation: http://www.ted.com/index.php/talks/view/id/92 I think we all know that capability and usability are two different things. I often wonder how many hours people have to spend to get the results they do when using Mathematica - what percentage coding, debugging, etc. before getting meaningful results, especially in larger projects that include text and graphics, along with developing the calculation strategies. I wish that the measure wolfram used to include new functions was more usability based - designed to reduce time to construct common tasks, reduce keystrokes, etc. As a interesting measure, I wish that when people posted to the demomstrations project that they also included an honest indication of the time spent to develop / release their code. for a system as diverse and complex as Mathematica, usability would seem to be as big a shift in focus as was reliability and security was for Microsoft a few years ago. on another note, I am also deeply appreciative of the level on online support wolfram gives to this newsgroup. The Mathematica organization is full of very wise and gifted people. === Subject: Re: Re: Presentations Package Announcement Wolfram's lack of these facilities (or simple links to programs that do it well is limiting their market) If that is not deliberate, perhaps the decision needs to be reexamined. The demonstrations capability will go a long way to dealing with that -- assuming WRI does not price themselves out of the market when they sell the capability independently. My major concern today is that some of the features DO NOT WORK. These include the web Mathematica packages and the data base package. Both of these are important in that they provide systematic interfaces to widely used input and output interfaces. > After 10+ years of Mathematica being in existence, why Wolfram can't > seem to > include these capabilities directly in the program I do not understand. Actually It's 20 years. > Mathematica is essentially a programming language with thousands of > functions, so there is practically no limit to what can be done with > it. > WRI can't possibly put everything into it. You should see Mathematica > as a very sophisticated toolbox, which can be used to develop more > specialized applications. This is the job of independent developers or > yourself. > In this past 20 years several professionally made packages have been > developed by 3rd parties, mostly costing hundreds (or thousands) of > dollars.Mr. Park's packages are a notable and very welcome exception. > We are lucky to have independent developers, like Mr. Park, providing > high quality packages and great customer service at a very reasonable > cost. > -- Richard Palmer Home 508 877-3862 Cell 508 982-7266 === Subject: Re: Re: Presentations Package Announcement Wolfram has plenty of experts on algebra, calculus, math, and programming, but... I doubt they have many (or any) who can craft a meaningful diagram, chart, or presentation like David Park can. He's a genious at that stuff, and he has spent years fine-tuning tools to help. The examples alone are worth the price, but beyond that, David has implemented a MUCH simpler paradigm for combining diverse graphical elements. The results are native graphics objects in the end, but David's code makes building them far easier. Bobby > After 10+ years of Mathematica being in existence, why Wolfram can't > seem to > include these capabilities directly in the program I do not understand. > I have now released the Presentations package for Mathematica Version 6. >> Presentations is a follow-on package for DrawGraphics. It can be >> obtained at >> the Mathematica page of my web site below and costs $50. Previous >> purchasers >> of DrawGraphics have been sent email notices and may freely upgrade to >> Presentations. If you are a purchaser who has changed your email >> address and >> have not received a notice please contact me with your current address. >> Presentations is a package designed to facilitate the use of >> Mathematica in >> studying standard textbook material, in writing tutorials for students, >> in >> research, and in using Mathematica in technical communications. >> Although it >> started as basically a graphics package it is now being enlarged to >> accommodate the many new features of Version 6 and to contain generally >> useful features that might not specifically be graphics. >> A 'presentation' is my term for any display of data or information >> about a >> scientific or mathematical concept that goes beyond simple text and >> equations. >> Some of the features of Presentations are: >> 1) Rather than treating graphics as a collection of major plot types >> that >> are difficult to combine, Presentations treats all graphics including >> curves >> and surfaces as graphics primitives that may be easily combined in one >> drawing statement. >> 2) Since graphical elements are all treated as primitives they can be >> easily >> manipulated and transformed. Routines are provided for that and the new >> geometric transformation routines of Version 6 have been cast in a form >> convenient for this use. >> 3) There is a suite of routines for generating custom ticks and grids, >> free >> standing scales, symbolic tick scales, and polar grids to replace the >> usual >> Cartesian axes. >> 4) There are 3D arrows with arrowcones that can be drawn in a number of >> styles. There are routines for marking angle arcs and right angle >> indicators >> on 2D geometrical diagrams. >> 5) For 2D graphics there are the LocatorDraw and LocatorLine routines >> that >> allow the user to temporarily add locators to a graphic, position them, >> and >> then copy the positions into a drawing statement. >> 6) There is provision for Text3D that allows true 3D text that rotates >> with >> the image and hides behind surfaces. >> 7) There is a complete set of routines for complex function graphics. >> These >> include primitives such as ComplexPoint, ComplexLine, ComplexText, >> ComplexCurve etc., that use complex arguments instead of coordinate >> pairs. >> In addition there are complex forms of maps, surface plots, contour >> plots, >> density plots and domain coloring plots that use a single complex >> iterator. >> There is a BranchArg routine that allows the user to set the branch >> line in >> the complex plane at any angle. There is a general multifunction with >> memory >> capability that calculates all function values and orders them to be >> continuous with a previous, close-by, evaluation. There is a Riemann >> sphere >> routine and a StereographicMap routine. There are information panel >> primitives for providing numerical information along with dynamic >> graphics. >> 8) There is an IndefiniteSequences subpackage that allows the >> formatting of >> expressions that contain ellipses to indicate skipped terms or factors >> in >> sums, products, tables, free standing sequences and infix expressions. >> There >> is the ability to do some operations on the expressions and to convert >> them >> to normal Mathematica expressions. >> 9) The Presentations package is a natural extension of standard >> Mathematica; >> it uses the regular Mathematica interface and in no way cuts the user >> off >> from any regular Mathematica functions, including the regular graphics >> functions. >> 10) Presentations is extensively documented with individual Help pages >> for >> each function. In addition there are many extended examples showing >> practical cases of graphics and extended presentations. There are three >> essays on 'Writing Notebooks', 'Writing Presentations' and 'Writing >> Packages' in which I try to give tips on avoiding traps and getting the >> most >> productive use from Mathematica. One example, EllipseArea, illustrates a >> style of writing notebooks that does everything actively and generates >> embedded knowledge. There is a sample toy package that can be used as a >> model for users who have never before written packages. There is an >> included >> optional style sheet that, to my taste, corrects many of the >> deficiencies of >> the WRI style sheets. Currently, the entire package contains 193 files >> and >> occupies some 3.5 MB (without the graphics being evaluated) - a true >> bargain >> for $50. >> David Park >> djmpark@comcast.net >> http://home.comcast.net/~djmpark -- DrMajorBob@bigfoot.com === Subject: Re: Presentations Package Announcement > After 10+ years of Mathematica being in existence, why Wolfram can't seem to > include these capabilities directly in the program I do not understand. Actually It's 20 years. Mathematica is essentially a programming language with thousands of functions, so there is practically no limit to what can be done with it. WRI can't possibly put everything into it. You should see Mathematica as a very sophisticated toolbox, which can be used to develop more specialized applications. This is the job of independent developers or yourself. In this past 20 years several professionally made packages have been developed by 3rd parties, mostly costing hundreds (or thousands) of dollars.Mr. Park's packages are a notable and very welcome exception. We are lucky to have independent developers, like Mr. Park, providing high quality packages and great customer service at a very reasonable cost. === Subject: Re: Slider[] and Dynamic[] implementation details Hi Otto, see below, Daniel > Hey all, I'm curious about the workings of Mathematica 6's dynamic functionality. > Specifically the interaction between Slider[] and Dynamic[] in this simple > example: Slider[Dynamic[x, (x = 1 - #) &]] > Dynamic[x] Okay so my first question involves removing the first embedded dynamic and > leaving just the x, like so: Slider[x] > Dynamic[x] > from the manual: Slider[Dynamic[x]] will reset the value of x when the slider is moved; Slider[x] will not. > Intuitively, to me, the slider function should still be able to update the > value of x and the dynamic should still be able to display those updated > values. Like if slider were just like a normal function that updates the > value of x in the kernel just like a new assignment statement would. BUT, > this doesn't happen--X doesn't change. This makes me think there's some > special mechanism here. Could someone explain it? My second question has to do with the second argument to Dynamic. Again, > intuitively, to me, it seems like when dynamic looks for an updated value of > x, it uses that function to assign it it's new value. But this couldn't be > completely true because it doesn't work like this: > Slider[Dynamic[x]] > Dynamic[Dynamic[x, (x = 1 - #) &]] The dynamic display of x doesn't seem to use the function--it only works > when it's in slider[]. Why is that? First, I do not see any reason for a double Dynamic. Second, how do you decide that: The dynamic display of x doesn't seem to use the function. E.g. you can not simply say: Dynamic[x, (x = 1 - #) &], this would make a definition for Dynamic not x. To assign to x, you simply need to write x=... I looked through the documentation and didn't see anything addressing these > kinda picky questions, but I'm just darn curious. Although Mathematica isn't > open source, I'm assuming there are plenty of people out there who are > familiar with implementation details like these. > === Subject: Re: ContourLabel placement Mark, The following statement, in the Presentations package, labels the contours near the center of each line. DrawLineLabels gives some control over where on the contour lines the labels will be placed and it also allows a selected subset of the lines to be labeled. (Sometimes labeling all of the lines gets cluttered.) Needs[Presentations`Master`] With[ {f = Function[{p, q}, Log[((-1 + p)*q)/(p*(-1 + q))]/Log[2]]}, Draw2D[ {g = ContourDraw[f[p, q], {p, 0, 1}, {q, 0, 1}, Contours -> Range[-7, 7], PlotPoints -> Automatic, ContourShading -> False], g // DrawLineLabels[f, 0.5 &, 0.05, Range[-7, 7], DrawLLTextOptions -> {Background -> HTML@Linen}]}, Frame -> True, ImageSize -> 400] ] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hi all, The documentation for ContourLabels says The positions of contour > labels are determined automatically to optimize readability. But that > doesn't seem to be the case with this plot: ContourPlot[Log[((-1 + p)*q)/(p*(-1 + q))]/Log[2], > {p, 0, 1}, {q, 0, 1}, Contours -> Range[-7, 7], > PlotPoints -> Automatic, ContourShading -> False, > ContourLabels -> Automatic] Does this count as a bug? Of course, I can place labels by hand. --Mark. PS, I'm using 6.0 for Microsoft Windows (32-bit) (June 19, 2007). > === Subject: Real to String What is the way to convert real to a string in Mathematica? For example, I have a variable, which takes a real value (for example x=1.2345). And I would like to have a variable whose value is 1.2345. I cannot find the answer in the Mathematica help. Could you pleas help me? === Subject: Re: Real to String > What is the way to convert real to a string in Mathematica? For > example, I have a variable, which takes a real value (for example > x=1.2345). And I would like to have a variable whose value is > 1.2345. In[1]:= x = 1.2345 y = ToString@x Out[1]= 1.2345 Out[2]= 1.2345 -- Jean-Marc === Subject: Re: Real to String ToString[expr] gives a string corresponding to the printed form of expr in OutputForm. Jens What is the way to convert real to a string in Mathematica? For > example, I have a variable, which takes a real value (for example > x=1.2345). And I would like to have a variable whose value is > 1.2345. I cannot find the answer in the Mathematica help. Could you pleas help me? === Subject: ListPLot for 2 List I'm trying to plot 2 lists with ListPlot, something like that (following a mathematica 5.2 help) ListPlot[{z,s}] where z={{100,1},{425,2},{156,3}} s={{235,1},{256,2},{265,3}} But, I have an error !(ListPlot::lpn ((:)( )) !({{{200.`, 5.053110000000001`*^-6}, {201.`, (-5.08005`*^-6)}, {202.`, 2.58061`*^-6}, {203.`, (-3.68235`*^-6)}, [LeftSkeleton]3[RightSkeleton], {207.`, 1.54361`*^-6}, {208.`, 1.76702`*^-6}, {209.`, 3.7100000000000003`*^-7}, [LeftSkeleton]3091[RightSkeleton]}, { [LeftSkeleton]1[RightSkeleton]}}) is not a list of numbers or pairs of numbers) Ary -- For more information please visit http://linux.bitdefender.com/ === Subject: Re: ListPLot for 2 List with mathematica 5.2 you must load the Graphics`MultipleListPlot` package. Or you combine the individual graphics objects by your self. Jens I'm trying to plot 2 lists with ListPlot, something like that (following a > mathematica 5.2 help) ListPlot[{z,s}] where z={{100,1},{425,2},{156,3}} > s={{235,1},{256,2},{265,3}} But, I have an error > !(ListPlot::lpn ((:)( )) !({{{200.`, > 5.053110000000001`*^-6}, {201.`, (-5.08005`*^-6)}, {202.`, > 2.58061`*^-6}, {203.`, (-3.68235`*^-6)}, > [LeftSkeleton]3[RightSkeleton], > {207.`, 1.54361`*^-6}, {208.`, 1.76702`*^-6}, {209.`, > 3.7100000000000003`*^-7}, [LeftSkeleton]3091[RightSkeleton]}, { > [LeftSkeleton]1[RightSkeleton]}}) is not a list of numbers or pairs of > numbers) > Ary > === Subject: Re: How do I let them know about a bug ? Although many WRI employees read MathGroup, it's best to report bugs to support@wolfram.com, just to be sure they don't get overlooked. Bhuvanesh, Wolfram Research === Subject: Finding position of an element in a list: Hello Friends, (This is an easy problem, but I was unable to get it work in Mathematica, probably because of the precision - I tried setting precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to find one nearest value I am interested in that list. In the below example, I wanted to find the position of a number belonging to list and close to 6 (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; dropOuterBraces[lst_List] := StringTake[#1, {2, StringLength[#1] - 1}] &[ ToString[lst]]; (* took from previous help posted by Peter Pein *) n1 = Nearest[xlis, 6] eval = dropOuterBraces[n1] Position[xlis, eval] Position[xlis, 5] As you see, the last but one command returns nothing, and we have to explicitly say the number to return the position. Or should some other command be used to extract the position of an arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False for some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; dropOuterBraces[lst_List] := StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; xlis elem = dropOuterBraces[eval] MemberQ[xlis, 0.545392] MemberQ[xlis, 0.33] Position[xlis, 0.33] Position[xlis, elem] Please hint where I am wrong. Gopinath Venkatesan Graduate Student University of Oklahoma === Subject: Re: Finding position of an element in a list: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; dropOuterBraces[{lst_}] := lst works fine *and* it is total unclear why *your* dropOuterBraces[] function is so uncredible clumsy .. Jens > Hello Friends, (This is an easy problem, but I was unable to get it work in Mathematica, probably because of the precision - I tried setting precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to find one nearest value I am interested in that list. In the below example, I wanted to find the position of a number belonging to list and close to 6 (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] > Position[xlis, eval] > Position[xlis, 5] As you see, the last but one command returns nothing, and we have to explicitly say the number to return the position. Or should some other command be used to extract the position of an arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False for some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; > xlis > elem = dropOuterBraces[eval] > MemberQ[xlis, 0.545392] > MemberQ[xlis, 0.33] > Position[xlis, 0.33] > Position[xlis, elem] Please hint where I am wrong. > Gopinath Venkatesan > Graduate Student > University of Oklahoma > === Subject: Re: Finding position of an element in a list: > (This is an easy problem, but I was unable to get it work in Mathematica, > probably because of the precision - I tried setting precision too, still got stuck) this has presumably absolutely nothing to do with precision... > Suppose we have a list, xlis, having some elements, and I have to find one > nearest value I am interested in that list. In the below example, I > wanted to find the position of a number belonging to list and close to 6 > (which is 5.5 located at 7th). > I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) I don't think that this function is a good choice for the problem at hand: conversion of expressions to string to manipulate them is rarely a good idea and I think Peter's function served a very different purpose... > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] If you use InputForm[eval] or FullForm[eval] you will find that dropOuterBraces returns a string, not a number, so it is the expected behavior that no occurance of the string 5.5 is found within the list containing the number 5.5. One solution could be to revert eval to a number with ToExpression[eval], but why not just use: n1=First[Nearest[xlis,6]] Position[xlis,n1] which extracts the first element of the list which Nearest returns and works perfectly for me. Note that Nearest returns always a list, presumably since 1. it is possible to have more than one nearest member, like in: Nearest[{1,3},2] 2. it is possible to ask Nearest for the n nearest, like in: Nearest[{1,2,3,4,5,6,7,8,9},5,4] In your case, only the first of these cases could make Nearest return a list longer than one. In this case additional information is needed to decide which one you want n1 to be set to. Also note that dropOuterBraces would return a string 1,3 for case 1, which doesn't make sense even if converted back with ToExpression. Conclusion: don't use ToString when not necessary... hth, albert === Subject: Re: Finding position of an element in a list: Hi Gopinath, with version 6 we have the function Nearest: Nearest[xlis -> Automatic, 6] hope this helps, Daniel > Hello Friends, (This is an easy problem, but I was unable to get it work in Mathematica, probably because of the precision - I tried setting precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to find one nearest value I am interested in that list. In the below example, I wanted to find the position of a number belonging to list and close to 6 (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] > Position[xlis, eval] > Position[xlis, 5] As you see, the last but one command returns nothing, and we have to explicitly say the number to return the position. Or should some other command be used to extract the position of an arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False for some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; > xlis > elem = dropOuterBraces[eval] > MemberQ[xlis, 0.545392] > MemberQ[xlis, 0.33] > Position[xlis, 0.33] > Position[xlis, elem] Please hint where I am wrong. > Gopinath Venkatesan > Graduate Student > University of Oklahoma > === Subject: question with FindRoot I have a problem using FindRoot under Mathematica 5.2. I wants to find a root for an equation, but this equation depends of anothers equations. I would like to kown how to put the equation that I want to solve, and the others equations, in the same line. Ary -- For more information please visit http://linux.bitdefender.com/ === Subject: Re: question with FindRoot {x^2+y^2==1, x==-y} ?? and FindRoot[{x^2 + y^2 == 1, x == -y}, {{x, 1}, {y, -1}}] or Solve[{x^2 + y^2 == 1, x == -y}, {x, y}] ?? Jens I have a problem using FindRoot under Mathematica 5.2. I wants to find a root for an equation, but this equation depends of > anothers equations. I would like to kown how to put the equation that I want to solve, and the > others equations, in the same line. > Ary > === Subject: Re: question with FindRoot Hi Ary, it's hard to tell without an example. Well, assume your equation for x1 depends on a further variable x2 given by a second equation. E.g.: eq={ x1^3+3 x2==5, x2^4-x2^2+x2==2 }; FindRoot[eq,{{x1,1},{x2,1}}] hope this helps, Daniel I have a problem using FindRoot under Mathematica 5.2. I wants to find a root for an equation, but this equation depends of > anothers equations. I would like to kown how to put the equation that I want to solve, and the > others equations, in the same line. > Ary > === Subject: Mathematica 6 installation problem on Vista. Hello all, Mathematica 6 has no installation options apart from directory selection, which I leave to default. So I hit Install and the installation begins. When installation reaches a certain point (Wolfram Notebook Indexers), the installation window disappears, although I can see it at my taskbar... I wait for 5 minutes lets say with no activity. When I kill the installation I get a 1628 Installation Failed message box. I tried to find a solution to this but had no luck. Here is the installation log (I run installation in verbose mode) http://rapidshare.com/files/74558803/MathematicaInstallation.txt.rar.html === Subject: Re: Mathematica 6 installation problem on Vista. > Hello all, Mathematica 6 has no installation options apart from directory > selection, which I leave to default. So I hit Install and the > installation begins. When installation reaches a certain point (Wolfram Notebook Indexers), > the installation window disappears, although I can see it at my > taskbar... I wait for 5 minutes lets say with no activity. When I kill the > installation I get a 1628 Installation Failed message box. I tried to find a solution to this but had no luck. Here is the > installation log (I run installation in verbose mode)http://rapidshare.com/files/74558803/MathematicaInstallation.txt.rar.... If you examined the log file, it seems to be a documented issue: http://community.installshield.com/showthread.php?t=132326 http://community.installshield.com/showthread.php?t=116318 === Subject: joint histogram of an three channels of an image hello everyone. I wanted to know how can I draw the joint histogram between three different channels of an image in mathematica. I have an image , and i want to plot the joint histogram between red, green and blue channels of the image. I know the underlying method of making the joint histogram between two differnt channels ...say red and green, but how can it be poltted for all three channels together....is it something like density plot?? vicky Al Aisa === Subject: Re: joint histogram of an three channels of an image A joint histogram for 3 quantities would be 4-dimensional, would it not? We're not likely to see plots like THAT in the near future! Taking the DensityPlot approach you'd shade different points within a 3D cube -- but how could one see interior points properly? Bobby > hello everyone. I wanted to know how can I draw the joint histogram between three > different channels of an image in mathematica. I have an image , and i want to plot the joint histogram between red, > green and blue channels of the image. > I know the underlying method of making the joint histogram between two > differnt channels ...say red and green, but how can it be poltted for > all three channels together....is it something like density plot?? > vicky Al Aisa > -- DrMajorBob@bigfoot.com === Subject: Re: joint histogram of an three channels of an image there is no function for that -- you can plot the 3d points corresponding to the colors, i.e. img = Import[http://blog.wolfram.com/images/people/sw.jpg] Graphics3D[ Map[{RGBColor @@ (#/255), Point[#]} &, img[[1, 1]], {2}] ] Jens > hello everyone. I wanted to know how can I draw the joint histogram between three > different channels of an image in mathematica. I have an image , and i want to plot the joint histogram between red, > green and blue channels of the image. > I know the underlying method of making the joint histogram between two > differnt channels ...say red and green, but how can it be poltted for > all three channels together....is it something like density plot?? > vicky Al Aisa === Subject: MathLink and VC++ 2008 Does anybody have experience with getting MathLink running under VC++ 2008? I got major troubles with it. I started with the MathLink package that came with Mathematica 6.0 (mprep rev 12). I've put all the files in the right place, and added an entry for the linker to link with the library. Since i could not get it working, i switched to the mathlink version that came with 5.2 (MPrep rev 11). The errors i am currently running into are these: template.cpp(70) : error C2664: 'GetModuleHandleW' : cannot convert parameter 1 from 'const char [7]' to 'LPCWSTR'. Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast template.cpp(73) : error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [260]' to 'LPWCH' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast template.cpp(83) : error C2664: 'LoadIconW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast template.cpp(88) : error C2440: '=' : cannot convert from 'LPSTR' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast and so on.... Anybody any sugestions? Gao Han ----------------------------------------------------------- .... http://www.sb-software.com/android ----------------------------------------------------------- . === Subject: Re: MathLink and VC++ 2008 a) no b) that is a Microsoft defect. You must switch of the UNICODE macros with the $(NOINHERIT) preprocessor directive. Jens > Does anybody have experience with getting MathLink running under VC++ 2008? I > got major troubles with it. I started with the MathLink package that came > with Mathematica 6.0 (mprep rev 12). I've put all the files in the right > place, and added an entry for the linker to link with the library. Since i > could not get it working, i switched to the mathlink version that came with > 5.2 (MPrep rev 11). The errors i am currently running into are these: template.cpp(70) : error C2664: 'GetModuleHandleW' : cannot convert parameter > 1 from 'const char [7]' to 'LPCWSTR'. Types pointed to are unrelated; > conversion requires reinterpret_cast, C-style cast or function-style cast > template.cpp(73) : error C2664: 'GetModuleFileNameW' : cannot convert > parameter 2 from 'char [260]' to 'LPWCH' Types pointed to are unrelated; > conversion requires reinterpret_cast, C-style cast or function-style cast > template.cpp(83) : error C2664: 'LoadIconW' : cannot convert parameter 2 from > 'const char [7]' to 'LPCWSTR' Types pointed to are unrelated; conversion > requires reinterpret_cast, C-style cast or function-style cast > template.cpp(88) : error C2440: '=' : cannot convert from 'LPSTR' to > 'LPCWSTR' Types pointed to are unrelated; conversion requires > reinterpret_cast, C-style cast or function-style cast and so on.... > Anybody any sugestions? Gao Han ----------------------------------------------------------- > .... http://www.sb-software.com/android > ----------------------------------------------------------- > . > === Subject: Re: slot argument weirdness Even though I've made lots of attempts to understand what pure functions are and how to use them, I'm still not there. Some examples seem so clear but virtually every time I try to do it myself, I find I haven't caught the idea. And I've read thru all the HELP and tutorials! I'll keep trying. > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. > === Subject: Re: slot argument weirdness Hi Jerry, you are nearly there. If you set: m = {{#1, #2}, {#2, #1}}&; all is well. The reason for this is, that ...& is a function. Functiosn has the attribute HoldAll what prevents from the replacement of m by its value. You get a function that always returns m. This leaves m that is subsequently evaluated. Another solution that forces the evaluation, is: Apply[Evaluate[m] &, v] hope this helps, Daniel > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. > === Subject: Re: slot argument weirdness > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. > Since Function holds its arguments, that should be myMatrix2 = Apply[Evaluate[m] &, v] but why not use fun = {{#1, #2}, {#2, #1}} & myMatrix3 = Apply[fun, v] instead? -- Szabolcs === Subject: Re: slot argument weirdness What's wrong with: m = {{#1, #2}, {#2, #1}} &; myMatrix2 = Apply[m, v] {{2, 5}, {5, 2}} Bobby > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. -- = DrMajorBob@bigfoot.com === Subject: Re: slot argument weirdness > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. The problem is that Function is HoldAll, so that the body of the function (m) doesn't get substituted until after Apply is evaluated and Function head is stripped. So you should tell it explicitly to evaluate the Function body -- MyMatrix2 = Apply[(m // Evaluate) &, v] You can use Chris Chiasson's trace routine to see what goes wrong in things like recordSteps[MyMatrix2 = Apply[m &, v]] then look in C:msgStream.m SetAttributes[recordSteps, HoldAll]; recordSteps[expr_] := Block[{$Output = List@OpenWrite[C:msgStream.m]}, TracePrint[Unevaluated[expr], _?(FreeQ[#, Off] &), TraceInternal -> True]; Close /@ $Output; Thread[Union@ Cases[ReadList[C:msgStream.m, HoldComplete[Expression]], symb_Symbol /; AtomQ@Unevaluated@symb && HoldComplete@symb, {0, Infinity}, Heads -> True], HoldComplete] ] === Subject: Re: slot argument weirdness > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. The Slots (#) are usually part of the Function (&) so the natural way to do this would be... v = {2, 5}; m = {{#1, #2}, {#2, #1}} &; Apply[m, v] But if you want to pass the slot expression around separately from the Function then you need to take notice of the HoldAll attribute of Function and do the following... m = {{#1, #2}, {#2, #1}}; Apply[Evaluate[m] &, v] Jon McLoone http://members.wolfram.com/jonm === Subject: Re: slot argument weirdness m = {{#1, #2}, {#2, #1}}; v = {2, 5}; and MyMatrix2 = Apply[Function @@ {m}, v] will do it. Jens > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. > === Subject: Re: slot argument weirdness > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. The slots don't make much sense without the enclosing function. This means you should define m with the & to make it a function and then use it like: m = {{#1,#2},{#2,#1}}&; Apply[m,v] note that the definition of m is just a shortcut for : m = Function[{{#1,#2},{#2,#1}}] which can be elaborated even more to: m = Function[{x,y},{{x,y},{y,x}}] I find it often much more readable to work with named arguments for functions than just the slots, but that depends on the use case and is a matter of taste. hth, albert === Subject: Re: slot argument weirdness > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. Apply[Release[m] &, v] === Subject: Re: slot argument weirdness > I have to produce some bulky matrices which are described by > two parameters and it seems the easiest way to produce them > is as follows (I took out all the complexity and just left > in the slots to illustrate my problem). v is the parameter > array. v = {2, 5}; > myMatrix=Apply[{{#1, #2}, {#2, #1}} &, v] giving {{2, 5}, {5, 2}} and all is well. But since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just > once in the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all: This is normal since you have defined is an incomplete pure function. In other words, Slot must always be accompanied by & to form a syntacticly correct expression. > MyMatrix2= Apply[m &, v] gives {{#1, #2}, {#2, #1}} I've tried a lot of things to make this work but have failed > completely. If someone can tell me that there is absolutely > no representation of the slot configuration that will do > any info. v = {2, 5}; m = {{#1, #2}, {#2, #1}} &; Apply[m, v] m @@ v -- Jean-Marc === Subject: Re: slot argument weirdness Considering that all the examples of slots in online help (Slot) show slots inside of pure functions, where is the weirdness: in the slots, or in your attempt to use them outside their native habitat? You're so close :-) How about? m={{#1,#2},{#2,#1}}&; Apply[m, v] Simple pure functions are fine, but complex ones can be hard to read. How about instead a regular function, m=Function[{u,v},{{u,v},{v,u}}] or a rule? r={u_,v_}:>{{u,v},{v,u}}; v/.r Tom When responding, please replace news with my first initial and full last name, as one word. Tom Burton > I have to produce some bulky matrices which are described by two > parameters and it seems the easiest way to produce them is as > follows (I took out all the complexity and just left in the slots > to illustrate my problem). v is the parameter array. v = {2, 5}; ... but since the actual form in the first argument in Apply is > really a large messy thing, I thought I'd produce it just once in > the notebook and represent it with: m = {{#1, #2}, {#2, #1}}; But geez, this doesn't work at all ... === Subject: Re: Exporting Sound > SoundNote] to .mid. Unfortunately, though, this doesn't compltely > help. The sounds I'm working with are a combination of sounds > generated from SoundNote and sounds imported from .wav files. > EmitSound doesn't have any trouble with these combined sounds, but it > seems impossible to export them. What I finally ended up doing was to play my sounds with EmitSound in > Mathematica, and record them on a handheld digital audio recorder (which > I have anyway, for purposes of recording the various music groups that I > play in), then upload from my audio recorder to my computer, and save it > as one big happy .wav or .mp3. OK, I just found a somewhat better way to do this. The audio editing software that I use in conjunction with my audio recorder, Acoustica, doesn't support midi, at least not directly. However, it can record directly off the computer's sound card. So, I started it recording, played my sounds (combining SoundNote / midi with WAV) with EmitSound from within Mathematica, and voila, I have a sound I can save from Acoustica as a .wav or .mp3 or .au. Still: > I'd be happier if I had a direct way to convert from SoundNote / midi > into .wav (or other non-midi format) from within Mathematica. -- Helen Read University of Vermont === Subject: Re: Exporting Sound > Helen: > Try > ding = SoundNote[F, 1, Tinklebell]; > Export[C:ding.mid, Sound[ding], Sound] though, this doesn't compltely help. The sounds I'm working with are a combination of sounds generated from SoundNote and sounds imported from .wav files. EmitSound doesn't have any trouble with these combined sounds, but it seems impossible to export them. So unless I can convert the SoundNote (midi) sound into some other format, I'm kind of stuck, since it's not possible to go the other way and convert the .wav into midi. > What tipped me off to the format was what is in the General Help File for > SoundNote. Style ... represents General MIDI instrument Now how to get MIDI sound to a Wave format? data = SystemDialogInput[RecordSound] This opens a dialog box to record a sound. The Input is a Sound Driver but > then how do you record the ding which you would play in Mathematica? Yeah, that's my question. I don't see how to get this to work. I could not get the example in the documentation to work, let alone anything else. > There must be an easier way? What I finally ended up doing was to play my sounds with EmitSound in Mathematica, and record them on a handheld digital audio recorder (which I have anyway, for purposes of recording the various music groups that I play in), then upload from my audio recorder to my computer, and save it as one big happy .wav or .mp3. This did work, but was kind of a clunky way to do it. I'd be happier if I had a direct way to convert from SoundNote / midi into .wav (or other non-midi format) from within Mathematica. -- Helen Read University of Vermont === Subject: Eigensystem consistency why these two calculations give different rezults? In[1]:= N[ Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. {[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] Out[1]= {{9.96423, 0.0357679}, {{0.32797, 1.}, {-3.04906, 1.}}} and In[2]:= Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, { [Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] Out[2]= {{9.96423, 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} -- Arturas Acus === Subject: Re: Eigensystem consistency Sorry, my earlier post was somewhat incorrect. The difference isn't that N supervises the computations of Eigensystem in your first example; it does change the exact Eigensystem result to Real, as in Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. {[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}] N@% {{1/50 (250 + Sqrt[61609]), 1/50 (250 - Sqrt[61609])}, {{-(150/49) + 1/147 (250 + Sqrt[61609]), 1}, {-(150/49) + 1/147 (250 - Sqrt[61609]), 1}}} {{9.96423, 0.0357679}, {{0.32797, 1.}, {-3.04906, 1.}}} Notice that Eigensystem gives an EXACT result, based on symbolic computations, as in Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}}] {{1/2 ([Sigma]1^2 + [Sigma]2^2 - Sqrt[[Sigma]1^4 - 2 [Sigma]1^2 [Sigma]2^2 + 4 [Rho]^2 [Sigma]1^2 [Sigma]2^2 + [Sigma]2^4]), 1/2 ([Sigma]1^2 + [Sigma]2^2 + Sqrt[[Sigma]1^4 - 2 [Sigma]1^2 [Sigma]2^2 + 4 [Rho]^2 [Sigma]1^2 [Sigma]2^2 + [Sigma]2^4])}, {{-((- [Sigma]1^2 + [Sigma]2^2 + Sqrt[[Sigma]1^4 - 2 [Sigma]1^2 [Sigma]2^2 + 4 [Rho]^2 [Sigma]1^2 [Sigma]2^2 + [Sigma]2^4])/( 2 [Rho] [Sigma]1 [Sigma]2)), 1}, {-((-[Sigma]1^2 + [Sigma]2^2 - Sqrt[[Sigma]1^4 - 2 [Sigma]1^2 [Sigma]2^2 + 4 [Rho]^2 [Sigma]1^2 [Sigma]2^2 + [Sigma]2^4])/( 2 [Rho] [Sigma]1 [Sigma]2)), 1}}} These are also correct eigenvectors: 2 [Rho] [Sigma]1 [Sigma]2 vectors {{[Sigma]1^2 - [Sigma]2^2 - Sqrt[[Sigma]1^4 - 2 [Sigma]1^2 [Sigma]2^2 + 4 [Rho]^2 [Sigma]1^2 [Sigma]2^2 + [Sigma]2^4], 2 [Rho] [Sigma]1 [Sigma]2}, {[Sigma]1^2 - [Sigma]2^2 + Sqrt[[Sigma]1^4 - 2 [Sigma]1^2 [Sigma]2^2 + 4 [Rho]^2 [Sigma]1^2 [Sigma]2^2 + [Sigma]2^4], 2 [Rho] [Sigma]1 [Sigma]2}} In your second example, the inputs are Real and computation is numeric, as in {{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}] Eigensystem[%] {{1., 2.94}, {2.94, 9.}} {{9.96423, 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} As I said before, the two results ARE the same, except for scaling. If there were repeated eigenvalues, they need not be the same even to that degree, so long as the eigenvectors for a specified eigenvalue span the same space in both results. Bobby > Both results ARE the same, to the extent that equivalent eigensystems > SHOULD be the same. That is, one set of eigenvectors is just a rescaled > version of the other. The reason this can occur is that N doesn't merely > evaluate its argument, then change it to a Real. It controls evaluation > of its argument in order to get a specific precision in the result. So > Eigensystem within N computes differently. Hence these are the same, Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] > [Sigma]1 [Sigma]2, [Sigma]2^2}} /. > N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] > N@% {{9.96423, 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} {{9.96423, 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} but your first expression is different. Bobby >> why these two calculations give different rezults? >> In[1]:= N[ >> Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] >> [Sigma]1 [Sigma]2, [Sigma]2^2}} /. {[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] >> Out[1]= {{9.96423, 0.0357679}, {{0.32797, 1.}, {-3.04906, 1.}}} >> and >> In[2]:= Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, { >> [Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. >> N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] >> Out[2]= {{9.96423, >> 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} > -- DrMajorBob@bigfoot.com === Subject: Re: Eigensystem consistency Both results ARE the same, to the extent that equivalent eigensystems SHOULD be the same. That is, one set of eigenvectors is just a rescaled version of the other. The reason this can occur is that N doesn't merely evaluate its argument, then change it to a Real. It controls evaluation of its argument in order to get a specific precision in the result. So Eigensystem within N computes differently. Hence these are the same, Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] N@% {{9.96423, 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} {{9.96423, 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} but your first expression is different. Bobby why these two calculations give different rezults? In[1]:= N[ > Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] > [Sigma]1 [Sigma]2, [Sigma]2^2}} /. {[Sigma]1 -> 1, [Sigma]2 - 3, [Rho] -> 98/100}]] Out[1]= {{9.96423, 0.0357679}, {{0.32797, 1.}, {-3.04906, 1.}}} and In[2]:= Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, { > [Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. > N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] Out[2]= {{9.96423, > 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} -- DrMajorBob@bigfoot.com === Subject: Re: Eigensystem consistency Hi Arturus, I think Eigensystem gives unnormalized vectors if calculating with exact numbers or symbols, but normalizes the vectors if we feed it machine numbers. The reason may be that in the former case we may get ungainly expressions that do not contain any additional information. hope this helps, Daniel why these two calculations give different rezults? In[1]:= N[ > Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] > [Sigma]1 [Sigma]2, [Sigma]2^2}} /. {[Sigma]1 -> 1, [Sigma]2 - 3, [Rho] -> 98/100}]] Out[1]= {{9.96423, 0.0357679}, {{0.32797, 1.}, {-3.04906, 1.}}} and In[2]:= Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, { > [Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. > N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] Out[2]= {{9.96423, > 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} === Subject: Re: Eigensystem consistency because a symbolic eigenvalue/eigensystem solver is different from a numeric one. Jens why these two calculations give different rezults? In[1]:= N[ > Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, {[Rho] > [Sigma]1 [Sigma]2, [Sigma]2^2}} /. {[Sigma]1 -> 1, [Sigma]2 - 3, [Rho] -> 98/100}]] Out[1]= {{9.96423, 0.0357679}, {{0.32797, 1.}, {-3.04906, 1.}}} and In[2]:= Eigensystem[{{[Sigma]1^2, [Rho] [Sigma]1 [Sigma]2}, { > [Rho] [Sigma]1 [Sigma]2, [Sigma]2^2}} /. > N[{[Sigma]1 -> 1, [Sigma]2 -> 3, [Rho] -> 98/100}]] Out[2]= {{9.96423, > 0.0357679}, {{0.311638, 0.950201}, {0.950201, -0.311638}}} === Subject: Re: Finding position of an element in a list: nearestPosition[xlis_List, val_?NumericQ] := Flatten[Position[xlis, #]] & /@ Nearest[xlis, val]; xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; nearestPosition[xlis, 6] {{7}} xlis = {0, 1, 6.5, 10, 4, 5, 5.5, 10.25}; nearestPosition[xlis, 6] {{3}, {7}} Bob Hanlon > Hello Friends, (This is an easy problem, but I was unable to get it work in Mathematica, probably because of the precision - I tried setting precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to find one nearest value I am interested in that list. In the below example, I wanted to find the position of a number belonging to list and close to 6 (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] > Position[xlis, eval] > Position[xlis, 5] As you see, the last but one command returns nothing, and we have to explicitly say the number to return the position. Or should some other command be used to extract the position of an arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False for some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; > xlis > elem = dropOuterBraces[eval] > MemberQ[xlis, 0.545392] > MemberQ[xlis, 0.33] > Position[xlis, 0.33] > Position[xlis, elem] Please hint where I am wrong. > Gopinath Venkatesan > Graduate Student > University of Oklahoma > === Subject: Re: Finding position of an element in a list: Nice one, Bob. Yet another new function (Nearest) that I didn't know about. I found the output of your function to be a bit cumbersome. Also, if there are repeated nearest values, then you get the positions twice. I modified your function by adding a Union and a final Flatten to produce a single list: nearestPosition2[lst_List,val_?NumericQ]:= Flatten[Union[Flatten[Position[lst,#]]&/@Nearest[lst,val]]]; So that the output of xlis = {0, 1, 5.5, 10, 4, 5, 5.5, 10.25}; is {3,7} instead of {{{3},{7}},{{3},{7}}}. Kevin > nearestPosition[xlis_List, val_?NumericQ] := > Flatten[Position[xlis, #]] & /@ > Nearest[xlis, val]; xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; nearestPosition[xlis, 6] {{7}} xlis = {0, 1, 6.5, 10, 4, 5, 5.5, 10.25}; nearestPosition[xlis, 6] {{3}, {7}} > Bob Hanlon > >> Hello Friends, >> (This is an easy problem, but I was unable to get it work in Mathematica, probably because of the precision - I tried setting precision too, still got stuck) >> Suppose we have a list, xlis, having some elements, and I have to find one nearest value I am interested in that list. In the below example, I wanted to find the position of a number belonging to list and close to 6 (which is 5.5 located at 7th). >> I can do this: >> xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; >> dropOuterBraces[lst_List] := >> StringTake[#1, {2, StringLength[#1] - 1}] &[ >> ToString[lst]]; (* took from previous help posted by Peter Pein *) >> n1 = Nearest[xlis, 6] >> eval = dropOuterBraces[n1] >> Position[xlis, eval] >> Position[xlis, 5] >> As you see, the last but one command returns nothing, and we have to explicitly say the number to return the position. >> Or should some other command be used to extract the position of an arbitrary number in a list? >> Same with the case of MemberQ command, it gives True for some and False for some. For example, consider this list, >> xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; >> dropOuterBraces[lst_List] := >> StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] >> eval = Nearest[xlis, 0.32]; >> xlis >> elem = dropOuterBraces[eval] >> MemberQ[xlis, 0.545392] >> MemberQ[xlis, 0.33] >> Position[xlis, 0.33] >> Position[xlis, elem] >> Please hint where I am wrong. >> Gopinath Venkatesan >> Graduate Student >> University of Oklahoma -- Kevin J. McCann Research Associate Professor JCET/Physics Physics Building University of Maryland, Baltimore County 1000 Hilltop Circle Baltimore, MD 21250 === Subject: Re: Finding position of an element in a list: > Nice one, Bob. Yet another new function (Nearest) that I didn't know about. I found the output of your function to be a bit cumbersome. Also, if > there are repeated nearest values, then you get the positions twice. I > modified your function by adding a Union and a final Flatten to produce > a single list: nearestPosition2[lst_List,val_?NumericQ]:= > Flatten[Union[Flatten[Position[lst,#]]&/@Nearest[lst,val]]]; > So that the output of xlis = {0, 1, 5.5, 10, 4, 5, 5.5, 10.25}; is {3,7} instead of {{{3},{7}},{{3},{7}}}. > Kevin We can even slightly improve this improved function by removing the inner Flatten as in, nearestPosition3[lst_List, val_?NumericQ] := Flatten[Union[Position[lst, #] & /@ Nearest[lst, val]]]; xlis = {0, 1, 5.5, 10, 4, 5, 5.5, 10.25}; nearestPosition3[xlis, 6] returns {3, 7} Just my $0.02 :-) Jean-Marc >> nearestPosition[xlis_List, val_?NumericQ] := >> Flatten[Position[xlis, #]] & /@ >> Nearest[xlis, val]; >> xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; >> nearestPosition[xlis, 6] >> {{7}} >> xlis = {0, 1, 6.5, 10, 4, 5, 5.5, 10.25}; >> nearestPosition[xlis, 6] >> {{3}, {7}} >> Bob Hanlon > Hello Friends, (This is an easy problem, but I was unable to get it work in Mathematica, probably because of the precision - I tried setting precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to find one nearest value I am interested in that list. In the below example, I wanted to find the position of a number belonging to list and close to 6 (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] > Position[xlis, eval] > Position[xlis, 5] As you see, the last but one command returns nothing, and we have to explicitly say the number to return the position. Or should some other command be used to extract the position of an arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False for some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; > xlis > elem = dropOuterBraces[eval] > MemberQ[xlis, 0.545392] > MemberQ[xlis, 0.33] > Position[xlis, 0.33] > Position[xlis, elem] Please hint where I am wrong. > Gopinath Venkatesan > Graduate Student > University of Oklahoma === Subject: Re: ListPLot for 2 List z={{100, 1}, {425, 2}, {156, 3}}; s={{235, 1}, {256, 2}, {265, 3}}; In version 5.2 Needs[Graphics`]; MultipleListPlot[z, s, PlotJoined -> True]; In version 6 ListPlot[{z, s}, Joined -> True] Bob Hanlon I'm trying to plot 2 lists with ListPlot, something like that (following a > mathematica 5.2 help) ListPlot[{z,s}] where z={{100,1},{425,2},{156,3}} > s={{235,1},{256,2},{265,3}} But, I have an error > !(ListPlot::lpn ((:)( )) !({{{200.`, > 5.053110000000001`*^-6}, {201.`, (-5.08005`*^-6)}, {202.`, > 2.58061`*^-6}, {203.`, (-3.68235`*^-6)}, > [LeftSkeleton]3[RightSkeleton], > {207.`, 1.54361`*^-6}, {208.`, 1.76702`*^-6}, {209.`, > 3.7100000000000003`*^-7}, [LeftSkeleton]3091[RightSkeleton]}, { > [LeftSkeleton]1[RightSkeleton]}}) is not a list of numbers or pairs of > numbers) > Ary -- > For more information please visit http://linux.bitdefender.com/ === Subject: Re: Real to String x = 1.2345; xs = ToString[x]; xs // InputForm 1.2345 Bob Hanlon What is the way to convert real to a string in Mathematica? For > example, I have a variable, which takes a real value (for example > x=1.2345). And I would like to have a variable whose value is > 1.2345. I cannot find the answer in the Mathematica help. Could you pleas help me? === Subject: Vertical tick labels in BarChart I would have thought this is a FAQ but it doesn't seem to be ... Consider the following construction of simple Bar Charts where the bar labels are strings. The first one looks OK. In the second one, where there are more bars, it's a mess because all the labels overlap (unless the graphics is increased a lot in size): Needs[BarCharts`] labels = {MQM.A7L2B1, MQMC.9R2.B1, MQTLI.11R2.B1}; vals = {5, 6, 7}; BarChart[vals, BarLabels -> labels] vals = Flatten[Table[vals, {5}]]; labels = Flatten[Table[labels, {5}]]; BarChart[vals, BarLabels -> labels] This could be neatly solved if the labels were oriented vertically instead of horizontally (it's easy to do this, e.g., in certain spreadsheet applications). However I can't find any option that allows it. I suspect it might be possible using some special Ticks construction but haven't taken the time to see. But this should be easy ... does anyone know how ? John Jowett === Subject: Re: Vertical tick labels in BarChart Hi John, is the following acceptable? BarChart[vals,BarLabels->labels,BarOrientation->Horizontal] Daniel > I would have thought this is a FAQ but it doesn't seem to be ... Consider the following construction of simple Bar Charts where the bar > labels are strings. The first one looks OK. In the second one, where > there are more bars, it's a mess because all the labels overlap > (unless the graphics is increased a lot in size): Needs[BarCharts`] labels = {MQM.A7L2B1, MQMC.9R2.B1, MQTLI.11R2.B1}; > vals = {5, 6, 7}; BarChart[vals, BarLabels -> labels] vals = Flatten[Table[vals, {5}]]; > labels = Flatten[Table[labels, {5}]]; BarChart[vals, BarLabels -> labels] This could be neatly solved if the labels were oriented vertically > instead of horizontally (it's easy to do this, e.g., in certain > spreadsheet applications). However I can't find any option that > allows it. > I suspect it might be possible using some special Ticks construction > but haven't taken the time to see. But this should be easy ... does > anyone know how ? John Jowett > === Subject: Re: Vertical tick labels in BarChart ok - here you go.... (* create the bar chart with labels in the wrong orientation, then convert the whole thing to primitives with FullGraphics to circumvent all of the graphics ticks bugs*) b = BarChart[vals, BarLabels -> labels] // FullGraphics ; (* apply a transformation to all text primitives, being careful to only modify the non-numeric ones since the numeric ones are the vertical axis text marks. The transformation replaces the offending label with a rotated and translated version of the label. *) b /. Text[ v_String, al_List, bl_List] -> Translate[Rotate[Text[v, {0, 0}, {-1, 0}], -[Pi]/2, {0, 0}], al] --- > I would have thought this is a FAQ but it doesn't seem to be ... Consider the following construction of simple Bar Charts where the bar > labels are strings. The first one looks OK. In the second one, where > there are more bars, it's a mess because all the labels overlap > (unless the graphics is increased a lot in size): Needs[BarCharts`] labels = {MQM.A7L2B1, MQMC.9R2.B1, MQTLI.11R2.B1}; > vals = {5, 6, 7}; BarChart[vals, BarLabels -> labels] vals = Flatten[Table[vals, {5}]]; > labels = Flatten[Table[labels, {5}]]; BarChart[vals, BarLabels -> labels] This could be neatly solved if the labels were oriented vertically > instead of horizontally (it's easy to do this, e.g., in certain > spreadsheet applications). However I can't find any option that > allows it. > I suspect it might be possible using some special Ticks construction > but haven't taken the time to see. But this should be easy ... does > anyone know how ? John Jowett === Subject: Re: Vertical tick labels in BarChart When the labels are wide, the sensible solution is BarChart[vals, BarLabels -> labels, BarOrientation -> Horizontal] Bobby > I would have thought this is a FAQ but it doesn't seem to be ... Consider the following construction of simple Bar Charts where the bar > labels are strings. The first one looks OK. In the second one, where > there are more bars, it's a mess because all the labels overlap > (unless the graphics is increased a lot in size): Needs[BarCharts`] labels = {MQM.A7L2B1, MQMC.9R2.B1, MQTLI.11R2.B1}; > vals = {5, 6, 7}; BarChart[vals, BarLabels -> labels] vals = Flatten[Table[vals, {5}]]; > labels = Flatten[Table[labels, {5}]]; BarChart[vals, BarLabels -> labels] This could be neatly solved if the labels were oriented vertically > instead of horizontally (it's easy to do this, e.g., in certain > spreadsheet applications). However I can't find any option that > allows it. > I suspect it might be possible using some special Ticks construction > but haven't taken the time to see. But this should be easy ... does > anyone know how ? John Jowett -- = DrMajorBob@bigfoot.com === Subject: Re: Vertical tick labels in BarChart bar chart uses Ticks to draw the labels. Ticks seems to have bugs ( Ticks are bugs, as you know. ) for example, Needs[BarCharts`] labels = {MQM.A7L2B1, MQMC.9R2.B1, MQTLI.11R2.B1}; vals = {5, 6, 7}; vals = Flatten[Table[vals, {5}]]; labels = Flatten[Table[labels, {5}]]; (* create the kind of labels you want... *) grlabels = Map[ Graphics[Rotate[Text[#, {0, 0}, {-1, 0}], -[Pi]/2, {0, 0}], Frame -> False] &, labels]; lrng = Range[Length[labels]]; ListPlot[vals, Ticks -> {Transpose[{lrng, grlabels}], Automatic}] which proves that if Ticks are graphics objects, things break. further, you cannot specify Tics as a simple sequence of graphics objects since the form of Ticks assumes that a list has position information. further, there is no concept of a Rotation style, so you cannot specify a text direction without creating a graphics object so forget that too. Just export it to Excel and save yourself for higher ROI activities. > I would have thought this is a FAQ but it doesn't seem to be ... Consider the following construction of simple Bar Charts where the bar > labels are strings. The first one looks OK. In the second one, where > there are more bars, it's a mess because all the labels overlap > (unless the graphics is increased a lot in size): Needs[BarCharts`] labels = {MQM.A7L2B1, MQMC.9R2.B1, MQTLI.11R2.B1}; > vals = {5, 6, 7}; BarChart[vals, BarLabels -> labels] vals = Flatten[Table[vals, {5}]]; > labels = Flatten[Table[labels, {5}]]; BarChart[vals, BarLabels -> labels] This could be neatly solved if the labels were oriented vertically > instead of horizontally (it's easy to do this, e.g., in certain > spreadsheet applications). However I can't find any option that > allows it. > I suspect it might be possible using some special Ticks construction > but haven't taken the time to see. But this should be easy ... does > anyone know how ? John Jowett === Subject: Re: Real to String Did you try typing string convert into version 6 help? The second entry is your answer, ToString. Tom When responding, please replace news with my first initial and full last name, as one word. Tom Burton > What is the way to convert real to a string in Mathematica? For > example, I have a variable, which takes a real value (for example > x=1.2345). And I would like to have a variable whose value is > 1.2345. === Subject: Ndsolve I'm confused about the interpolation thing. Why if I have some diff eq with boundary conditions NdSolve doesn't give me a numerical solution? And suppose I have y'[x]== f[x] with y[a]== b as a condition (a,b any numbers) How can I find f[0], for example? (Generalizing, how can I find f[c], where c is a number?) === Subject: Re: Ndsolve InterpolationFunction _is_ a numerical answer. For instance, execute: Clear[y] y = y /. First@ NDSolve[{y'[x] == Cos@Sin[x^2], y[0] == 0}, y, {x, 0, Pi}] y[0] y[1] y[Pi] Plot[y[x], {x, 0, Pi}] and the output is InterpolatingFunction[{{0.,3.14159}},<>] 0. 0.919768 2.52142 (and a plot) Bobby > I'm confused about the interpolation thing. Why if I have some diff eq > with boundary conditions NdSolve doesn't give me a numerical solution? > And suppose I have y'[x]== f[x] > with y[a]== b as a condition (a,b any numbers) How can I find f[0], for example? (Generalizing, how can I find f[c], > where c is a number?) > -- DrMajorBob@bigfoot.com === Subject: Re: Ndsolve NDSolve actually does generate an internal (x,y) table of numerical values; however, it then continues on and calculates an InterpolationFunction. The advantage of the latter is that you can take derivatives, etc. You might check the documentation on NDSolve. Clear[y, Y] Y = y /. First[NDSolve[{y'[x] == y[x], y[0] == 1}, y, {x, 0, 1}]] You can check the BC: Y[0] 1 Also Plot[Y[x]-Y'[x],{x,0,1}] Kevin > I'm confused about the interpolation thing. Why if I have some diff eq with boundary conditions NdSolve doesn't give me a numerical solution? And suppose I have y'[x]== f[x] > with y[a]== b as a condition (a,b any numbers) How can I find f[0], for example? (Generalizing, how can I find f[c], where c is a number?) === Subject: Solving a set of 9 nonlinear equations with 11 parameters? I have a set of 9 nonlinear equations that contains 11 parametes. To solve it I have used the REDUCE function in Mathematica but after running the program for some hours the message No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry was created. I know that my equations are horribly complicated but does anyone know a better way to solve it? Or is there a stronger software or another command? I would appreciate it very much if anyone can help me:) === Subject: Re: Re: Derivative of function with indexed variables D[expr, y[i]] is zero here for several reasons: 1) y[i] is no specific symbol, since i is undefined. 2) expr is no specific Sum, since n, y, and p are undefined. (Especially n.) 3) The i in y[i] doesn't have the same scope (isn't the same variable) as the i in expr. The last is especially important. 0 This is fairly general, but not too general to work: Clear[num, den, expr] n = 5; num[i_] = Exp[-(y[i] - y[j])^2]; den[y_] = Sum[Exp[-(y[k] - y[h])^2], {h, k + 1, n}, {k, 1, n}]; expr[y_, p_] = Sum[p[i, j] Log[p[i, j] den[y]/num[i]], {j, 1, n}]; dExpr[i_] := D[expr[y, p], y[i]] dExpr[3] 2 p[3, 1] (-y[1] + y[3]) + 2 p[3, 2] (-y[2] + y[3]) + 2 p[3, 4] (y[3] - y[4]) + 2 p[3, 5] (y[3] - y[5]) Bobby > Here is the same in proper Mathematica-style: num = Exp[- (y[i] - y[j])^2] > den = Sum[Sum[Exp[-(y[k] - y[h])^2], {h, k + 1, n}], {k, 1, n}] > expr = Sum[p[i, j]Log[p[i, j]/(num / den)], {j, 1, n}] > D[expr, y[i]] The resulting derivative is incorrect, because Mathematica does not seem > to notice that y[k] and y[h] are sometimes equal to y[i] (over which we > compute the derivative). Any ideas? -- DrMajorBob@bigfoot.com === Subject: Re: Derivative of function with indexed variables Here is the same in proper Mathematica-style: num = Exp[- (y[i] - y[j])^2] den = Sum[Sum[Exp[-(y[k] - y[h])^2], {h, k + 1, n}], {k, 1, n}] expr = Sum[p[i, j]Log[p[i, j]/(num / den)], {j, 1, n}] D[expr, y[i]] The resulting derivative is incorrect, because Mathematica does not seem to notice that y[k] and y[h] are sometimes equal to y[i] (over which we compute the derivative). Any ideas? === Subject: Re: Finding position of an element in a list: The problem is that dropOuterBraces is turning the list of values returned by Nearest into strings. Then Position isn't able to determine where these strings appear in the original list -- because they don't! My recommendation is something like the following: * Use Nearest to grab the element(s) closest to what you want; * Use Position directly on those elements (not their string representations; * Flatten the result (if your original list is one-dimensional). It's basically exactly what you did, except for the step of turning things into strings. Here's a one-liner to do this: In[27]:= Flatten@(Position[xlis, #] & /@ Nearest[xlis, 6]) Out[27]= {7} Hope that helps! C.O. > Hello Friends, (This is an easy problem, but I was unable to get it work in Mathematica, > probably because of the precision - I tried setting precision too, still > got stuck) Suppose we have a list, xlis, having some elements, and I have to find one > nearest value I am interested in that list. In the below example, I wanted > to find the position of a number belonging to list and close to 6 (which is > 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] > Position[xlis, eval] > Position[xlis, 5] As you see, the last but one command returns nothing, and we have to > explicitly say the number to return the position. Or should some other command be used to extract the position of an > arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False for > some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; > xlis > elem = dropOuterBraces[eval] > MemberQ[xlis, 0.545392] > MemberQ[xlis, 0.33] > Position[xlis, 0.33] > Position[xlis, elem] Please hint where I am wrong. > Gopinath Venkatesan > Graduate Student > University of Oklahoma -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Finding position of an element in a list: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; Position[xlis, First@Nearest[xlis, 6], 1] {{7}} or: Nearest[xlis -> Range@Length@xlis, 6] {7} Or better yet: Nearest[xlis -> Automatic, 6] {7} Bobby > Hello Friends, (This is an easy problem, but I was unable to get it work in > Mathematica, probably because of the precision - I tried setting > precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to find > one nearest value I am interested in that list. In the below example, I > wanted to find the position of a number belonging to list and close to 6 > (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1] > Position[xlis, eval] > Position[xlis, 5] As you see, the last but one command returns nothing, and we have to > explicitly say the number to return the position. Or should some other command be used to extract the position of an > arbitrary number in a list? Same with the case of MemberQ command, it gives True for some and False > for some. For example, consider this list, xlis = Table[N[((1 - Cos[(j - 1)/9 [Pi]])/2) 1.32], {j, 1, 10}]; > dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ToString[lst]] eval = Nearest[xlis, 0.32]; > xlis > elem = dropOuterBraces[eval] > MemberQ[xlis, 0.545392] > MemberQ[xlis, 0.33] > Position[xlis, 0.33] > Position[xlis, elem] Please hint where I am wrong. > Gopinath Venkatesan > Graduate Student > University of Oklahoma -- = DrMajorBob@bigfoot.com === Subject: Re: Finding position of an element in a list: It should be clear to you that dropOuterBraces returns a string. There are no strings in your list, so of course Position returns the empty set. By default, Mathematica does not quote outputed strings, allowing your confusion. To avoid future confusion, you can in the Options Inspector set the global parameter ShowStringCharacters -> True You could modify dropOuterBraces to yield a number (see ToExpression), however, it's far easier to do this: eval = First[n1] Tom When responding, please replace news with my first initial and full last name, as one word. Tom Burton > ... Suppose we have a list, xlis, having some elements, and I have > to find one nearest value I am interested in that list. In the > below example, I wanted to find the position of a number belonging > to list and close to 6 (which is 5.5 located at 7th). I can do this: xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; dropOuterBraces[lst_List] := > StringTake[#1, {2, StringLength[#1] - 1}] &[ > ToString[lst]]; (* took from previous help posted by Peter Pein *) > n1 = Nearest[xlis, 6] > eval = dropOuterBraces[n1]... === Subject: Re: FindInstance what inspite ? The summary of Root calling patterns (first thing in Help for Root) should include Root[f,k,0] and Root[f,k,1]. Bobby >> Help for Root (version 6.0.1) says: >> Root[poly,x,k] >> gives the k[Null]^th root of the polynomial poly in x. >> and later it says: >> The setting of ExactRootIsolation is reflected in third argument of a >> Root object: >> a = Root[#^40 - 15 #^17 - 21 #^3 + 11 &, 20, ExactRootIsolation -> >> False]; >> b = Root[#^40 - 15 #^17 - 21 #^3 + 11 &, 20, ExactRootIsolation -> >> True]; >> {a, b} // InputForm >> {Root[11 - 21*#1^3 - 15*#1^17 + #1^40 & , 20, 0], >> Root[11 - 21*#1^3 - 15*#1^17 + #1^40 & , 20, 1]} >> The two descriptions seem, at first glance, incompatible, but the >> problem is only that the second usage isn't included in the >> top-section summary of calling patterns. >> Here are EIGHT ways of specifying the same number (unless exact root >> isolation is actually necessary, as I gather it should never be): >> Root[1 + 2 #1 + #1^5 &, 1] == >> Root[1 + 2 #1 + #1^5 &, 1, ExactRootIsolation -> False] == >> Root[1 + 2 #1 + #1^5 &, 1, ExactRootIsolation -> True] == >> Root[1 + 2 #1 + #1^5 &, 1, 0] == Root[1 + 2 #1 + #1^5 &, 1, 1] == = >> Root[1 + 2 x + x^5, x, 1] == >> Root[1 + 2 x + x^5, x, 1, ExactRootIsolation -> False] == >> Root[1 + 2 x + x^5, x, 1, ExactRootIsolation -> True] >> True >> Bobby I note this is in response to my response. But I'm not seeing a > question. If there is one, and if it is something I should address, > you'll need to spell it out. In particular if you think the > documentation needs work, let me know and I can raise the issue in house. Daniel > -- DrMajorBob@bigfoot.com === Subject: Re: FindInstance what inspite ? Help for Root (version 6.0.1) says: Root[poly,x,k] gives the k[Null]^th root of the polynomial poly in x. and later it says: The setting of ExactRootIsolation is reflected in third argument of a Root object: a = Root[#^40 - 15 #^17 - 21 #^3 + 11 &, 20, ExactRootIsolation -> False]; b = Root[#^40 - 15 #^17 - 21 #^3 + 11 &, 20, ExactRootIsolation -> True]; {a, b} // InputForm {Root[11 - 21*#1^3 - 15*#1^17 + #1^40 & , 20, 0], Root[11 - 21*#1^3 - 15*#1^17 + #1^40 & , 20, 1]} The two descriptions seem, at first glance, incompatible, but the problem is only that the second usage isn't included in the top-section summary of calling patterns. Here are EIGHT ways of specifying the same number (unless exact root isolation is actually necessary, as I gather it should never be): Root[1 + 2 #1 + #1^5 &, 1] == Root[1 + 2 #1 + #1^5 &, 1, ExactRootIsolation -> False] == Root[1 + 2 #1 + #1^5 &, 1, ExactRootIsolation -> True] == Root[1 + 2 #1 + #1^5 &, 1, 0] == Root[1 + 2 #1 + #1^5 &, 1, 1] == Root[1 + 2 x + x^5, x, 1] == Root[1 + 2 x + x^5, x, 1, ExactRootIsolation -> False] == Root[1 + 2 x + x^5, x, 1, ExactRootIsolation -> True] True Bobby >> Who have idea what function uses inspite FindInstance in procedure? >> !(FindInstance[Chop[N[Root[(-1) - 2 #1 - 2 #1^2 - #1^3 + #1^ 5 >> &, 2] >> + Root[(-1) - 2 #1 - 2 #1^2 - #1^3 + #1^5 &, 3], 500]] == a + b >> Root[(-1) - 2 #1 - 2 #1^2 - #1^3 + #1^5 &, >> 1] + c Root[(-1) - 2 #1 - 2 #1^2 - #1^3 + >> #1^5 >> &, 1]^2 + d >> Root[(-1) - 2 #1 - 2 #1^2 - #1^3 + #1^5 &, 1]^3 + e >> Root[(-1) - 2 #1 - 2 #1^2 - #1^3 + #1^5 &, >> 1]^4 && a != 0, {a, b, c, d, e}, Integers]) >> And anser is empty set {} >> Good answer is {a,b,c,d,e}={-2,-3,-2,-1,2} >> Who know how I can realize that procedure in Mathematica ? >> Best wishes >> Artur One can attempt such problems directly using lattice reduction. The idea > is to form a vector consisting of your target value and basis values > (the zeroeth through fourth powers of a certain algebraic number, in > your example). Multiply by a power of 10 raised to the precision you > have in mind, and round off to get integers. Augment on the right with > an identity matrix. Reduce this lattice, look for a small vector with > element in the column corresponding to the input value equal to +-1 (so > we know we obtained the value itself, and not a nontrivial multiple > thereof). This last can be relaxed if you are willing to allow rationals > (with small denominators, say) as coefficients. So here is code to do all this. minimalPolynomialInRoot[val_Real, alg_Root, deg_Integer] := Module[ > {vec, prec=Floor[Precision[val]], lat, redlat, mults}, > vec = Round[10^prec*Append[alg^Range[0,deg],-val]]; > lat = Transpose[Prepend[IdentityMatrix[deg+2],vec]]; > redlat = LatticeReduce[lat]; > mults = First[redlat]; > If [Abs[Last[mults]]==1, > Take[mults,{2,-2}] / Last[mults], > $Failed] > ] Your example: val = Re[N[Root[-1 - 2*#1 - 2*#1^2 - #1^3 + #1^5 & , 2, 0] + > Root[-1 - 2*#1 - 2*#1^2 - #1^3 + #1^5 & , 3, 0], 500]]; > alg = Root[-1 - 2*#1 - 2*#1^2 - #1^3 + #1^5 & , 1]; In[65]:= multipliers = minimalPolynomialInRoot[val, alg, 4] > Out[65]= {2, 2, 2, 1, -2} Check: In[66]:= multipliers.alg^Range[0,deg] - val > -500 > Out[66]= 0. 10 > Daniel Lichtblau > WOlfram Research -- DrMajorBob@bigfoot.com === Subject: Re: Finding position of an element in a list: >(This is an easy problem, but I was unable to get it work in >Mathematica, probably because of the precision - I tried setting >precision too, still got stuck) Suppose we have a list, xlis, having some elements, and I have to >find one nearest value I am interested in that list. In the below >example, I wanted to find the position of a number belonging to list >and close to 6 (which is 5.5 located at 7th). >I can do this: >xlis = {0, 1, 3, 10, 4, 5, 5.5, 10.25}; >dropOuterBraces[lst_List] := StringTake[#1, {2, >StringLength[#1] - 1}] &[ >ToString[lst]]; (* took from previous help posted by Peter Pein *) >n1 = Nearest[xlis, 6] >eval = dropOuterBraces[n1] >Position[xlis, eval] >Position[xlis, 5] A one line solution to returning the desired position number is Ordering[Abs[xlis-6],1][[1]] -- To reply via email subtract one hundred and four === Subject: forming filename string Do[infile=StringForm[U:datafile``.nb,i]; outfile=StringForm[U:dataofile``.tex,i]; x=Import[infile];Export[outfile,x];,{i,0,10,1}] I am getting errors like: Import::chtype: First argument U:datafile0.nb is not a valid file, directory, or URL specification. Export::chtype: First argument U:dataofile0.tex is not a valid file specification. BUT IF I DO: Import[U:datafile0.nb] it works! so is not an invalid file address. I guess there is some requirement for filename string?? Please help. === Subject: Re: forming filename string you should increase the number of backslashes -- only will be a single valid backslash ;-) or may Do[infile=U:/data/file<>ToString[i]<>.nb; outfile=U:/datao/file<>ToString[i]<>.tex; x=Import[infile];Export[outfile,x];,{i,0,10,1}] Jens help ?? Do[infile=StringForm[U:datafile``.nb,i]; outfile=StringForm[U:dataofile``.tex,i]; x=Import[infile];Export[outfile,x];,{i,0,10,1}] I am getting errors like: Import::chtype: First argument U:datafile0.nb > is not a valid file, directory, or URL specification. Export::chtype: First argument U:dataofile0.tex is not a valid file specification. BUT IF I DO: > Import[U:datafile0.nb] it works! so is not an invalid file address. I guess there is some requirement for filename string?? Please help. > === Subject: Re: Finding position of an element in a list: Albert, Yes, you are right and I might run into 2nd situation you mentioned. Gopinath === Subject: Contour Lines colored by temperature scale I am using the following code to get colored contour lines. ListContourPlot[doseArray,Contours->{200,400,600,800,900},ContourShading->No ne, ContourStyle->{Blue,Green,Yellow,Orange,Red},ContourLabels->(Text[Framed[#3] ,{#1,#2}, Background->White]&),AspectRatio->Automatic,InterpolationOrder->1]; I would like to use a Temperature scale to color my contour lines; the higher values at the red end of the visible light spectrum, and the lower values at the blue end. And instead of specifically naming the colors (as in the code above), I would like it to be generic so that I could just have a list of values for the contours, and the function automatically map the requisite colors. John C. Erb === Subject: Re: Contour Lines colored by temperature scale for the following to work you have to install IMS: http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/ Needs[Imtek`UnstructuredPlot`]; nx = 6; ny = 6; coordinates = Flatten[Table[{1. i, 1. j}, {i, 0, nx - 1}, {j, 0, ny - 1}], 1]; incidence = Flatten[Table[{{j*nx + i + 1, j*nx + i + 2, (j + 1)*nx + i + 1}, {j*nx + i + 2, (j + 1)*nx + i + 2, (j + 1)*nx + i + 1}}, {i, 0, nx - 2}, {j, 0, ny - 2}],2]; values = .3*((#[[1]] - 3)*(#[[2]] - 3)) & /@ coordinates; ucp = imsUnstructuredMeshPlot[coordinates, incidence]; {ma, mi} = Through[{Max, Min}[values]]; myContours = Range[ ma, mi, -0.2 ]; hueVals = (ma + mi)/Length[myContours]; allConts = {Thickness[0.01], Hue[ 1 - hueVals*# ], Line /@ imsFindContour[ coordinates, incidence, values, myContours[[#]] ][[All, -1]]} & /@ Range[Length[myContours]]; Show[ { ucp, Graphics[ allConts ] }, AspectRatio -> 1 ] Hope this helps, Oliver > I am using the following code to get colored contour lines. ListContourPlot[doseArray,Contours->{200,400,600,800,900},ContourShading->Non e, > ContourStyle->{Blue,Green,Yellow,Orange,Red},ContourLabels->(Text[Framed[#3], {#1,#2}, > Background->White]&),AspectRatio->Automatic,InterpolationOrder->1]; I would like to use a Temperature scale to color my contour lines; > the higher values at the red end of the visible light spectrum, and the lower > values at the blue end. And instead of specifically naming the colors (as in > the code above), I would like it to be generic so that I could just have a list > of values for the contours, and the function automatically map the requisite colors. > John C. Erb Oliver Ruebenkoenig, === Subject: GLToolbox Ver. 1.1 - OpenGL 3D Graphics Programming Package for Mathematica GLToolbox is an OpenGL programming interface for Mathematica version 6 or greater. GLToolbox uses Mathematica's J/Link interface with JOGL(Java/OpenGL). GLToolbox has support to draw Mathematica generated graphics with a single function call as OpenGL primitives, in addition to having access the entire OpenGL API. Version 1.1 adds support to simplify selecting objects with OpenGL. For documentation and package download, please visit: http://www.gltoolbox.com/ Feedback & thoughts are welcome! Per === Subject: Need features to make kernel and user functions bullet proof Need features to make kernel and user functions bullet proofWe can overload functions that are part of the Mathematica language, and this is good. However, we often hear in the MathGroup that you can easily break the kernel by changing kernel functions. This wouldn't be so risky if users could not indirectly change the way functions such as Solve, Simplify, NDSolve, etc. perform. I mean a user should be able to change what Simplify does by making a new definition for Simplify, but changing functions such as Thread, Map, or Apply should not change Solve, Simplify, or NDSolve. Besides that users who are writing their own functions should be able to ensure their functions cannot be broken inadvertently. ------------------------------------------------------------------------- Also notice you can change the default options of a protected symbol without first calling Unprotect. As a result a user can seriously break a lot of functions with lines such as SetOptions[ReplaceRepeated,MaxIterations -> 1]; SetOptions[Map,Heads->True]; Mathematica needs a new attribute called OptionsProtected. OptionsProtected::usage=OptionsProtected is an attribute that prevents the default options of a symbol from being modified. ------------------------------------------------------------------------- Now about preventing inadvertent changes to a functions definitions. One way WRI could provide this capability would be to have all symbols in the System` context also in a context called DefaultDefinitions`. All Symbols in context DefaultDefinitions` would have attributes {OptionsProtected, Protected, Locked}. That would make it impossible for a user to modify features in the DefaultDefinitions` context. Things that happen automatically behind the scenes should use symbols from the DefaultDefinitions` context to ensure everything always works correctly. So for example when definitions are automatically added to DownValues[f], UpValues[f], etc. they should be created using DefaultDefinitions`HoldPattern, and DefaultDefinitions`RuleDelayed. Imagine what could happen if you changed the meaning of RuleDelayed in the current Mathematica. -------------------------------------------------------------------------= - WRI could also give us a new function called SystemDefaults that would do the following. Attributes[SystemDefaults]={HoldRest}; SystemDefaults[All, expr] replaces all symbols in expr that are in the System` context with the same symbol from the DefaultDefinitions` context. Once the replacements are made the new form of expr evaluates. SystemDefaullts[{symb1, symb2, ...},expr] selects from {symb1, symb2, ...} Symbols in the System` context and replaces each instance of these symbols in expr with the same symbol from the DefaultDefinitions` context. Once the replacements are made the new form of expr evaluates . ----------------------------------------------- Then I could write the following and ensure all system symbols below are from the DefaultDefinitions` context and it would not be possible to make Inadvertent changes to my function integrate. SystemDefaults[All, integrate[c_?NumericQ, f_, x_Symbol]:=c*integrate[f,x]; integrate[f_+g_,x_Symbol]:=integrate[f,x]+integrate[g,x]; integrate[x_Symbol,x_Symbol]:=1/2 x^2; integrate[_Symbol^n_?(NumericQ[#]&&TrueQ[# != -1]&), x_Symbol]:=1/(n+1) x^(n+1) ] ------------------------------------------------ Instead I might want to use the following to ensure symbols DefaultDefinitions`NumericQ, DefaultDefinitions`Power, DefaultDefinitions`SetDelayed are used in my definitions of integrate. No other symbol form the DefaultDefinitions` context would be used. SystemDefaults[{NumericQ,Power,SetDelayed}, integrate[c_?NumericQ f_,x_Symbol]:=c*integrate[f,x]; integrate[f_+g_,x_Symbol]:=integrate[f,x]+integrate[g,x]; integrate[x_Symbol,x_Symbol]:=1/2 x^2; integrate[_Symbol^n_?(NumericQ[#]&&TrueQ[#!=-1]&),x_Symbol]:=1/(n+1)x ^(n+1) ] In the above examples above use of SystemDefaults[_._] would not force the use of symbols from the DefaultDefinitions` context when f[t], or (t) in integrate[f[t], t] evaluates. -------------- Ted Ersek === Subject: Re: Need features to make kernel and user functions bullet proof Here are my thoughts on this: > Need features to make kernel and user functions bullet proofWe can > overload functions that are part of the Mathematica language, and this > is good. However, we often hear in the MathGroup that you can easily > break the kernel by changing kernel functions. This wouldn't be so risky > if users could not indirectly change the way functions such as Solve, > Simplify, NDSolve, etc. perform. I mean a user should be able to change > what Simplify does by making a new definition for Simplify, but changing > functions such as Thread, Map, or Apply should not change Solve, Simplify, > or NDSolve. Besides that users who are writing their own functions should > be able to ensure their functions cannot be broken inadvertently. But is this really necessary? I mean, is there any legitimate reason to change symbols like Thread, Map, or Apply? If one needs a Map that behaves a bit differently, shouldn't one just define a new myMap function? (I know that some people are changing these symbols ... see e.g. But I always found these things extremely scary (and I think that it is a bad practice to do this). As you mentioned, it is possible that some built-in (or package) function uses the form Map[{a,b,c},d] (see the referenced post), so it would be broken by this change to Map. However, in this situation the user could have just defined his own listableMap[] function, which would be safe. Actually after I read that message I searched all the standard packages and the UpValues, OwnValues and DownValues of symbols returned by Names[] for Map[_List, __], but found nothing (though I'm not sure I searched the *built-in* definitions correctly, and I could completely prevent evaluation of the symbols only if I ran Mathematica without the Front End ...) ) ------------------------------------------------------------------------- > Also notice you can change the default options of a protected symbol > without first calling Unprotect. As a result a user can seriously break > a lot of functions with lines such as SetOptions[ReplaceRepeated,MaxIterations -> 1]; > SetOptions[Map,Heads->True]; Mathematica needs a new attribute called OptionsProtected. > OptionsProtected::usage=OptionsProtected is an attribute that prevents > the default options of a symbol from being modified. OptionsProtected could be useful. > ------------------------------------------------------------------------- Now about preventing inadvertent changes to a functions definitions. One > way WRI could provide this capability would be to have all symbols in the > System` context also in a context called DefaultDefinitions`. All Symbols > in context DefaultDefinitions` would have attributes {OptionsProtected, > Protected, Locked}. That would make it impossible for a user to modify > features in the DefaultDefinitions` context. Things that happen automatically behind the scenes should use symbols > from the DefaultDefinitions` context to ensure everything always > works correctly. So for example when definitions are automatically > added to DownValues[f], UpValues[f], etc. they should be created using > DefaultDefinitions`HoldPattern, and DefaultDefinitions`RuleDelayed. Imagine what could happen if you changed the meaning of RuleDelayed in > the current Mathematica. -------------------------------------------------------------------------= > - > WRI could also give us a new function called SystemDefaults that would > do the following. Attributes[SystemDefaults]={HoldRest}; SystemDefaults[All, expr] replaces all symbols in expr that are in > the System` context with the same symbol from the DefaultDefinitions` > context. Once the replacements are made the new form of expr evaluates. SystemDefaullts[{symb1, symb2, ...},expr] selects from {symb1, symb2, > ....} Symbols in the System` context and replaces each instance of > these symbols in expr with the same symbol from the DefaultDefinitions` > context. Once the replacements are made the new form of expr evaluates > .. ----------------------------------------------- Then I could write the following and ensure all system symbols below > are from the DefaultDefinitions` context and it would not be possible > to make Inadvertent changes to my function integrate. SystemDefaults[All, > integrate[c_?NumericQ, f_, x_Symbol]:=c*integrate[f,x]; > integrate[f_+g_,x_Symbol]:=integrate[f,x]+integrate[g,x]; > integrate[x_Symbol,x_Symbol]:=1/2 x^2; > integrate[_Symbol^n_?(NumericQ[#]&&TrueQ[# != -1]&), > x_Symbol]:=1/(n+1) x^(n+1) > ] ------------------------------------------------ > Instead I might want to use the following to ensure > symbols DefaultDefinitions`NumericQ, DefaultDefinitions`Power, > DefaultDefinitions`SetDelayed are used in my definitions of integrate. No > other symbol form the DefaultDefinitions` context would be used. SystemDefaults[{NumericQ,Power,SetDelayed}, > integrate[c_?NumericQ f_,x_Symbol]:=c*integrate[f,x]; > integrate[f_+g_,x_Symbol]:=integrate[f,x]+integrate[g,x]; > integrate[x_Symbol,x_Symbol]:=1/2 x^2; > integrate[_Symbol^n_?(NumericQ[#]&&TrueQ[#!=-1]&),x_Symbol]:=1/(n+1)x > ^(n+1) > ] In the above examples above use of SystemDefaults[_._] would not force > the use of symbols from the DefaultDefinitions` context when f[t], or > (t) in integrate[f[t], t] evaluates. > Now about changing symbols like Simplify, NIntegrate, etc.: There might be reasons for changing these, but one could argue that a legitimate change should extend these symbols in a mathematically sensible way, so that other function which use them would not break (i.e. Simplify would still simplify expression, but would be a bit smarter, NIntegrate would still compute integrals numerically, possibly with another method etc.) If the behaviour of these functions is changed completely, then probably it would have been better to define completely new functions instead. So I think that one should never change built-in symbols, except in the case when it is really expected that the new definitions would be applied even when the re-defined symbols are used inside some package (or built-in) function. I see that the proposed SystemDefaults allows for excluding certain symbols (more precisely: it allows for only including certain symbols when rewriting them to the alternatives in DefaultDefinitions), but this couldn't work correctly because of the nature of Mathematica: Suppose that we're writing a new function that uses Simplify, and we want to allow for the re-definition of Simplify, therefore we use System`Simplify instead of DefaultDefinitions`Simplify. But if our function calls a built-in function that also uses Simplify (I don't know if there are actually any of these), the built-in function will use DefaultDefinitions`Simplify and not the intended System`Simplify. So we would end up with two different versions of Simplify being inconsistently called in different situations. This sounds even more dangerous and confusing than the current situation. In my (subjective) opinion, for those functions where re-definition seems legitimate (like Simplify), WRI should provide a documented and safe API that only allows sensible changes. And indeed they do for some functions: Simplify has the TransformationFunctions option, NIntegrate can be extended with new integration methods, NumericQ and Derivative are directly assignable (NumericQ[n] = True and Derivative[1][f] = g work without Unprotect[]ing these symbols), etc. To summarize: I think that one should never modify any Protected built-in functions, except through documented APIs. But I like the idea of OptionsProtected. What do other MathGroup users think about this? Are there situations when it is legitimate to modify built-ins? I can give one example and show that it was a bad idea because it really breaks things: when I was trying to get the DownValues of all symbols returned by Names[], I changed its HoldAll attribute to HoldAllComplete so that it would work on really strange symbols like 'x' if 'x' has the definitions x[1]=1 and _[x] ^= x. (Question: Are there other ways of doing this than changing the attributes of DownValues?) But with this change, DownValues[Evaluate[sym]] ceases to work, and indeed I got lots of error messages when I tried to open the Help Browser ... Szabolcs P.S. I hope that my broken English didn't make this long post completely unintelligible. P.P.S. Your Mathematica Tricks website is really nice! === Subject: Exact roots of transcedental functions Exact roots of transcedental functionsThe notebook at http://library.wolfram.com/infocenter/Conferences/7010/ Talks about how the first argument of Root[_,_] can be a pure transcendental function, not just a polynomial. It sounds like this is a new feature in Mathematica 6, but I can't find any mention of such a feature in the documentation. Is this capability in Mathematica 6, or in some version to come out in the future? I can't see for myself because I don't have Mathematica 6. Ted Ersek === Subject: Re: Exact roots of transcedental functions > Exact roots of transcedental functionsThe notebook athttp://library.wolfram.com/infocenter/Conferences/7010/ > Talks about how the first argument of Root[_,_] can be a pure > transcendental function, not just a polynomial. > It sounds like this is a new feature in Mathematica 6, but I can't find > any mention of such a feature in the documentation. > Is this capability in Mathematica 6, or in some version to come out in > the future? I can't see for myself because I don't have Mathematica 6. > Ted Ersek That feature doesn't seem to be in Mathematica 6.0.1, I get Reduce::nsmet: This system cannot be solved with the methods available to Reduce message === Subject: Re: Unable to access v6 internal data sources (paclets) I am having the same problem on my office pc. Mathematica is not able to connect to the internet (Edit..Preferences..Internet Connectivity..Test Internet Connectivity). Everything works fine at home. Dario === Subject: Re: Re: Images chopped during Export Dario's solution (ImagePadding) works for my system. To recap, by setting ImagePadding high enough, I can export high resolution bitmaps without the axes labels being chopped off. (It's strange that ImageMargins does not work on my system, however. Maybe WRI will fix this stuff, or write a tutorial on the internals of Graphics[] rendering, since I think that many of us choose Mathematica for its superior graphics output abilities.) Also, it is true as Szabolcs said that the pdf format supports transparencies... I had not realized this because of a problem in one of the pdf renderers I use. So that format is also an option for some of my applications. Kenta > I believe that is just one of the many bugs of the Export function. > At least on my system (6.0.1, Vista32) I can compensate for that bug > by using ImagePadding: graph = Plot[Exp[x], {x, 0, 2 Pi}, ImageSize -> 5*72, ImagePadding - 15] > Export[test.tif, graph, ImageResolution -> 600] Please let me know if this solution works on your system. > Dario === Subject: Re: Images chopped during Export I believe that is just one of the many bugs of the Export function. At least on my system (6.0.1, Vista32) I can compensate for that bug by using ImagePadding: graph = Plot[Exp[x], {x, 0, 2 Pi}, ImageSize -> 5*72, ImagePadding -> 15] Export[test.tif, graph, ImageResolution -> 600] Please let me know if this solution works on your system. Dario === Subject: Re: Re: Images chopped during Export Hello Szabolcs, PlotRegion -> {{0.1, 0.9}, {0.1, 0.9}} Does not seem to help. Is the Mathematica Export[] command not capable of exporting bitmaps at high resolution, or am I just making some mistake? I need to export high resolution bitmaps for publication, to take advantage of the new support for transparencies. Kenta > I have a problem where tick labels are chopped off when I try to > Export high resolution Graphics to high-resolution tiff. graph=Plot[Exp[x], {x, 0, 2 Pi}, ImageSize -> 5*72] > Export[test.tif, graph, ImageResolution -> 600] This only happens when the ImageResolution is high. I've tried around > with ImageMargins in the Plot command, but the exported bitmap just > shows the same chopped graph with image margins on the outside. I guess it is due to some internal quirks in handling of Graphics[] > options or something. Does anybody know why this happens, and how to > fix it? > I know that this is an ugly solution, but if no one suggests anything > better, you could try using the PlotRegion option: Plot[Sin[x], {x, 0, 2 Pi}, PlotRegion -> {{0.1, 0.9}, {0.1, 0.9}}] -- > Szabolcs === Subject: Re: Images chopped during Export > Hello Szabolcs, PlotRegion -> {{0.1, 0.9}, {0.1, 0.9}} > Does not seem to help. Unfortunately I don't have any better ideas than PlotRegion ... > Is the Mathematica Export[] command not capable > of exporting bitmaps at high resolution, or am I just making some > mistake? I need to export high resolution bitmaps for publication, to > take advantage of the new support for transparencies. It is usually better to export to a vector format (except in the case of 3D graphics), because it gives a higher quality. Transparency is preserved when the graphics are exported to PDF, and PDF can be directly included into LaTeX documents (when compiled with pdfTeX). -- Szabolcs === Subject: line in 3d in direction of eigen vector Hello everyone This is actually follow on. I was able to a 3d plot of an image using this (suggested by someone of u) pic=Graphics3D[ Map[{RGBColor @@ (#/255), Point[#]} &, img[[1, 1]], {2}] ] Show[pic] Now I was able to get a line in the direction of eigen vctor by doing the following ------------------------------------------------------- ColorDot=Table[0,{ImgSize},{3}]; For[i=1,i<=ImgSize,i++, ColorDot[[i]]=MeanVector+EigenVectorsColoumn[[1]]*stept[[i]] ] Graphics3D[Line[ColorDot]] --------------------------------------------------------- I was able to get a line with this , but that was black, I wanted a colored line...color depending on the coordinate( taken as RGB) So I did the following --------------------------------------------- pic=Graphics3D[ Map[{RGBColor @@ (#/255), Point[#]} &, ColorDot] ] Show[pic] ------------------------------------------------ But problem with this is that, to compute ColorDot vector .,,I started from mean, and took a positive and negative step( taken as stept above) to go forward and backward from mean,,,,,,,so ColorDot table has coordinates but some of those are negative..and So the above gives me half line and tat too just blue colored.... i get error Graphics::realu: Argument in expr is not a real number between 0 and 1. vicky Al Aisa === Subject: BarChart[{1,2},Frame->True] Here is some extremely simple code that doesn't work in version 6.0.1: BarChart[{1,2},Frame->True] That's it! Note: BarChart[{1,2}] and BarChart[{1,2,3},Frame->True] work fine. Surely, this is some kind of bug! j === Subject: Re: BarChart[{1,2},Frame->True] > Here is some extremely simple code that doesn't work in version 6.0.1: > BarChart[{1,2},Frame->True] > That's it! Note: > BarChart[{1,2}] > and > BarChart[{1,2,3},Frame->True] > work fine. Surely, this is some kind of bug! > j Hello It looks like a bug and the culprit seems to be FrameTicks. If you use one of the following ... Needs[BarCharts`] BarChart[{1, 2}, Frame -> True, FrameTicks -> True] BarChart[{1, 2}, Frame -> True, FrameTicks -> Automatic] BarChart[{1, 2}, Frame -> True, FrameTicks -> All] ... it works nicely. Norbert Marxer === Subject: Re: Exact roots of transcedental functions Must be a future version. The Reduce examples did not work in Version 6.0.1 on a Mac Bob Hanlon Exact roots of transcedental functionsThe notebook at > http://library.wolfram.com/infocenter/Conferences/7010/ > Talks about how the first argument of Root[_,_] can be a pure > transcendental function, not just a polynomial. > It sounds like this is a new feature in Mathematica 6, but I can't find > any mention of such a feature in the documentation. > Is this capability in Mathematica 6, or in some version to come out in > the future? I can't see for myself because I don't have Mathematica 6. > Ted Ersek === Subject: Adding description to plots hi, i?m in trouble with a plot. The following functions generates a plot with several curves Plot[Evaluate[Table[Steuerkeil[0.1, s, t], {s, 0.2, 0.5, 0.05}]], {t, 0, 30}, AxesLabel -> {Laufzeit T, Steuerkeil}, PlotLabel -> s, BaseStyle -> {FontFamily -> Garamond, FontSize -> 12}] Now i have the followung problem: i dont know which curve refers to which parameter of s. I only see 6 differently coloured curves. Does Mathematica 6.0 provide such a function to add labels to each curve in the plot? Frank === Subject: Re: Adding description to plots You could try the Tooltip function: Steuerkeil[a_, s_, t_] := Exp[-s t] Sin[2 [Pi] a t]; Plot[Evaluate[ Table[Tooltip[Steuerkeil[0.1, s, t], s], {s, 0.2, 0.5, 0.05}]], {t, 0, 30}, AxesLabel -> {Laufzeit T, Steuerkeil}, PlotLabel -> s, PlotRange -> All, BaseStyle -> {FontFamily -> Garamond, FontSize -> 12}] In this case, when the cursor passes over a curve the value of s is placed in a tooltip. Dan > hi, i?m in trouble with a plot. The following functions generates a plot > with several curves Plot[Evaluate[Table[Steuerkeil[0.1, s, t], {s, 0.2, 0.5, 0.05}]], {t, > 0, 30}, AxesLabel -> {Laufzeit T, Steuerkeil}, PlotLabel -> s, > BaseStyle -> {FontFamily -> Garamond, FontSize -> 12}] Now i have the followung problem: i dont know which curve refers to > which parameter of s. I only see 6 differently coloured curves. Does > Mathematica 6.0 provide such a function to add labels to each curve in > the plot? > Frank === Subject: Re: Adding description to plots > hi, i?m in trouble with a plot. The following functions generates a plot > with several curves Plot[Evaluate[Table[Steuerkeil[0.1, s, t], {s, 0.2, 0.5, 0.05}]], {t, > 0, 30}, AxesLabel -> {Laufzeit T, Steuerkeil}, PlotLabel -> s, > BaseStyle -> {FontFamily -> Garamond, FontSize -> 12}] Now i have the followung problem: i dont know which curve refers to > which parameter of s. I only see 6 differently coloured curves. Does > Mathematica 6.0 provide such a function to add labels to each curve in > the plot? > Frank Hello What about Tooltip's? Steuerkeil[0.1, s_, t_] := s*t; Plot[Evaluate[(Tooltip[#1[[1]], #1[[2]]] & ) /@ Table[{Steuerkeil[0.1, s, t], s}, {s, 0.2, 0.5, 0.05}]], {t, 0, 30}, AxesLabel -> {Laufzeit T, Steuerkeil}, PlotLabel -> s, BaseStyle -> {FontFamily -> Garamond, FontSize -> 12}] Norbert Marxer === Subject: Memory leak bug in plotting functions? (Sudden kernel shutdown without error message) Hello mathgroup, I have an iterative data analysis routine that prints complex plots into the notebook, so that I can come back and audit the intermediate data analysis steps post-hoc. I have recently encountered a problem in v6.0 (Win32) where the kernel suddenly quits on me, without any error message. This happens after a relatively predictable number of iterations of my analysis routine. I have isolated the putative memory leak into the following proof-of-principle code. Do[ Print[{MemoryInUse[], MaxMemoryUsed[]}]; Print[ Plot[Sin[x]*Random[Real, {0.9, 1.1}] + Random[Real, {0, Pi/5}], {x, 0, 2 Pi},ImageSize -> 72*1] ], {50}] As this iteration runs, the MaxMemoryUsed[] value creeps up gradually. In my real code, the MaxMemoryUsed[] reaches a certain threshold, and the kernel predictably fails (silently) at that point. I have tried various methods such as ClearSystemCache[], Share[] and NotebookSave[] to no avail. It is always the kernel that quits, not the front end or java. I don't think it is the output using up too much memory in the front end, since if I restart the kernel and resume the calculation from where it quit, I can go for another while, even though the previous output is all still in the notebook frontend. It is interesting that I don't seem to get this problem when I plot a simple function, like Sin[x]. The problem segment of my actual code is a large LogListPlot of a large amount of complex data, so I guess it's not directly related to the Plot[] interpolation, etc. (In my real code, I Rasterize[] to low resolution, to save memory on the front end.) Kenta === Subject: Re: Get list of function variables? > I am aware that the solutions I posted do not hold in general. My > basic desire for the getVariables function was to help generate a new > function with those variables (and another set of the same size). I > wanted a notebook that could give the the error function for ANY > function the user inputed without having to do any work. Maybe there's > a better way than how I did it (but I have a working notebook so I'm > better off than I was). In other words give some function, say, the price to carpet an x by > y by z room at w per square unit area: > f(w,x,y,z)=w(x*y*z) > I want the sigma error on f given sigma errors on the variables. So a > new function ef > ef(x,y,z,ex,ey,ez) > where ef is defined by the usual error propagation equation a sum over > partial derivatives squared. The e prefix denotes the sigma error on > the corresponding variable. Note the new function recognizes w as a > parameter. If I went about this in some ass-backwards fashion by grabbing the > variables from f directly, I'm a little bit embarrassed but would be > interested in knowing a better way. Jason, You do need to know the number of arguments your function takes and the meaning of each argument (e.g. that the first argument in your example, w, needs to be excluded), otherwise you couldn't use the function. So with this knowledge, just plug in any symbol names into the function and use D[], e.g. f[w_, x_, y_, z_] = w x y z Sqrt[D[f[w,a,b,c], {{a,b,c}}]^2 . {ea, eb, ec}^2] This works with any kind of function in Mathematica, a pure function, or one defined using patterns. I wouldn't even use functions for this purpose, but expression: I would define the function that computes the error so that it takes an expression (f[w,x,y,z] or simply w x y z), and not the name of a function (f): error[expr_, vars_List, errs_List] := Sqrt[D[expr, {vars}]^2 . errs^2] Use it in the following way: error[w x y z, {x, y, z}, {ex, ey, ez}] or error[f[w, x, y, z], {x, y, z}, {ex, ey, ez}] Here it is made very clear which symbols represent the function variables (x, y, and z), which are simply parameters (w), and which are the errors (ex, ey, and ez). And the user of the function has the freedom to choose these names. As I understand, you tried to avoid the user having to explicitly name the variables (one can generate random names instead, e.g. with Unique[], or try to extract some names from the function definition) and having to explicitly input the number of arguments the function takes (again, if the functions were defined in a certain way, one could try to extract this information from the function definition). While it is possible to do this (provided that there are strict rules and conventions about how the function may be defined), it is error-prone, unreliable, and difficult to implement. I would consider it an ugly hack. Of course, this is a subjective opinion, but there are really many things that can go wrong: Just imagine that the function was defined using a pattern named 'x', f[x_] := x^2, but later the global symbol 'x' was given a value. Now if we want to extract 'x' from the definition of 'f' and use it to construct a new function (Function[{x}, ...]), we would have to go through a *lot* of trouble to avoid 'x' being evaluated during the calculations ... Szabolcs === Subject: Re: BarChart[{1, 2}, Frame->True] Two observations: First, I was apparently able to suppress the error message and get a decent plot by wrapping the offending expression in FullGraphics. Second, note that the data is a list of length 2. Many plot options, in particular, Ticks, take a list of length 2. Perhaps someone made a mistake I so often make, casting a pattern replacement too widely and catching an unintended part of an expression. Tom When responding, please replace news with my first initial and full last name, as one word. Tom Burton === Subject: Precedence of Infix Operator I would like to use some less common infix operator, such as Colon or VerticalBar, but give it a precedence on input greater than Times. Is there a way to do this? -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: The offending code _almost_ works: the error message is that one of the ticks. Of course this boundary exception needs to be fixed. However, it's unclear to me why one would want to create a bar chart with only two bins. > Here is some extremely simple code that doesn't work in version 6.0.1: > BarChart[{1,2},Frame->True] > That's it! Note: > BarChart[{1,2}] > and > BarChart[{1,2,3},Frame->True] > work fine. Surely, this is some kind of bug! > j -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Did we get an answer on whether this is a bug in Tally? Bobby > There is, apparently, something wrong with Tally, but your test wasn't > the right one, since cgraph's 5th and 10th elements were not returned in = > the Tally results. Here's a modification of your code and some tests: Needs[Combinatorica`]; > diagrams::usage = Calculate diagrams; > basicedges::usage; wick[a_, b_] := pair[a, b]; > wick[a_, b__] := > Sum[Expand[pair[a, {b}[[i]]] Delete[Unevaluated[wick[b]], i]], {i, > Length[{b}]}]; > ham[n_Integer] := (ns = 4*n - 3; {c[ns], c[ns + 1], d[ns + 2], > d[ns + 3]}); > basicedges[n_] := > Flatten[Table[{{{i, i + 1}, EdgeColor -> Red}}, {i, 1, 2*n, 2}], > 1]; > hamserie[n_Integer] := Flatten[Table[ham[i], {i, n}]]; > cvertices[n_Integer] := {{n, 1}, {n, 0}}; > cvertexserie[n_Integer] := Flatten[Table[cvertices[i], {i, n}], 1]; > pair[c[_], c[_]] := 0; > pair[d[_], d[_]] := 0; > pair[a_Integer, b_Integer] /; (a > b) := pair[b, a]; diagrams[n_] := > Module[{wickli, rep, i, cgraph, cvertices, congraph, le, un, ta}, > wickli = wick[Sequence @@ hamserie[n]] /. Plus -> List; > le = Length[wickli[[1]]]; > wickli = > wickli /. {pair[c[i_], d[j_]] -> pair[i, j], > pair[d[i_], c[j_]] -> pair[i, j]}; > graph = {}; > While[wickli =!= {}, > wickli = rempar[First[wickli], wickli, n, le]]; > (*edge reduction and edgelist construction for use by > Combinatorica*) > rep = Dispatch[ > Flatten[Table[{Rule[2*i - 1, i], Rule[2*i, i]}, {i, 2*n}]]]; > graph = (Take[#, -le] /. rep /. pair[a__]^_ -> pair[a]) & /@ > graph; > be = basicedges[n]; > cgraph = Map[List, (graph /. {pair -> List, Times -> List}), {2}= ]; > cvertices = List /@ cvertexserie[n]; > cgraph = Join[be, #] & /@ cgraph; > cgraph = Graph[#, cvertices] & /@ cgraph; > (*Now I compare Union and Tally*) > saved = cgraph; > un = Union[cgraph, SameTest -> IsomorphicQ]; > Print[Union: number of elements: , Length[un]]; > Print[GraphicsGrid[ > Partition[ShowGraph[#] & /@ un, 3, 3, {1, 1}, {}]]]; > ta = Sort@Tally[cgraph, IsomorphicQ][[All, 1]]; > Print[Tally: Number of Elements: , Length[ta]]; > Print[GraphicsGrid[Partition[ShowGraph /@ ta, 3, 3, {1, 1}, {}]]];= > Print[GraphicsGrid[ > Partition[ShowGraph /@ ta[[{2, 4}]], 3, 3, {1, 1}, {}]]]; > Print[Are 2 and 4 isomorphic? , IsomorphicQ[ta[[2]], ta[[4]]]]; > Print[Are 4 and 2 isomorphic? , IsomorphicQ[ta[[4]], ta[[2]]]]; > ]; rempar[li_, wickli_List, n_Integer, le_] := > Module[{lis, mult, gem, pre, i}, lis = {Take[li, -le]}; > pre = Drop[li, -le]; > Do[lis = Join[lis, lis /. {i -> i + 1, i + 1 -> i}], {i, 1, > 4*n - 1, 2}]; > lis = Union[lis]; > mult = Length[lis]; > graph = Join[graph, {li*mult}]; > Complement[wickli, pre*lis]]; diagrams[3] > Union: number of elements: 8 > Tally: Number of Elements: 11 > Are 2 and 4 isomorphic? True > Are 4 and 2 isomorphic? True saved // Length > index = Thread[saved -> Range@Length@saved]; > (u = Union[saved, SameTest -> IsomorphicQ]) // Length > (t = Sort@Tally[saved, IsomorphicQ][[All, 1]]) // Length 21 8 11 These are the cgraph indices returned by Union and Tally: u /. index > t /. index {1, 11, 4, 21, 8, 18, 15, 6} {1, 11, 4, 2, 8, 14, 3, 18, 15, 7, 6} Comparing cgraph[[5]] and cgraph[[10]] is irrelevant, as you can see. (boo = Boole@Outer[IsomorphicQ, t, t, 1]) // MatrixForm; > boo == Transpose@boo > Cases[Position[boo, 1], {a_, b_} /; a < b, 1] True {{2, 4}, {5, 7}, {8, 10}} boo is NOT an identity matrix, so Tally did something very odd. Bobby >> in the Mathematica 6.0 documentation it says in the entry for Tally:= = >> Properties and Relations: >> A sorted Tally is equivalent to a list of counts for the Union: >> This is what I indeed expect of Tally and Union, in particular then i= t = >> holds for any list: >> Length[Tally[list]] is equal to Length[Union[list]]. >> Now, I have an example, where Mathematica 6.0 produces a result where= >> Tally[list] and Union[list] are different in length, which surprises = me. >> And in fact, the result of Tally[ ] seems wrong to me. >> You can reproduce this result using the small Mathematica package = >> enclosed, which >> uses Combinatorica. (Sorry for the somewhat complicated example, but= I = >> did not find >> a simpler case showing the effect.) >> If you load this package into a notebook and then execute >> diagrams[2] >> Tally and Union produce the expected result: both lists have equal = >> length. >> (The list elements are diagrams.) >> However, if you execute >> diagrams[3] >> Tally and Union produce lists of different length. >> To my opinion, it really should never happen that Tally and Union >> produce lists of different length. I just expect of Tally to tell me = = >> the multpilicities in the equivalence classes, in addition to >> the information produced by Union. (The two list to be compared are = = >> called ta and un in the package enclosed.) >> Strangely enough, the program compares list elements 5 and 10 = >> explicitly, and comes to the >> conclusion that element 5 and 10 belong to the same equivalence class= , = >> nevertheless they are >> both listed seperately in the Tally, but - correctly - lumped up in = = >> the Union. >> Do I misinterpret something here or is there a bug in Tally? (Tally = is = >> new in Mathematica 6, and I >> would find it extremely useful, if it would do what I expect it to do= .) >> Michael >> Here comes my little package in order to reproduce the effect.... >> BeginPackage[wick`] >> Needs[Combinatorica`]; >> diagrams::usage=Calculate diagrams; >> basicedges::usage; >> Begin[`Private`] >> wick[a_, b_] := pair[a, b]; >> wick[a_, b__]:= Sum[Expand[pair[a, {b}[[i]]] = >> Delete[Unevaluated[wick[b]], i]], {i, Length[{b}]}]; >> ham[n_Integer]:=(ns=4*n-3;{c[ns],c[ns+1],d[ns+2],d[ns+3]}); >> basicedges[n_]:=Flatten[Table[{{{i,i+1}, EdgeColor->Red}}, = >> {i,1,2*n,2}],1]; >> hamserie[n_Integer]:=Flatten[Table[ham[i],{i,n}]]; >> cvertices[n_Integer]:={{n,1},{n,0}}; >> cvertexserie[n_Integer]:=Flatten[Table[cvertices[i],{i,n}],1]; >> pair[c[_],c[_]]:=0; >> pair[d[_],d[_]]:=0; >> pair[a_Integer,b_Integer]/;(a>b):=pair[b,a]; >> diagrams[n_]:=Module[{wickli, rep, i, cgraph, cvertices, congraph, = le, = >> un, ta}, >> wickli=wick[Sequence@@hamserie[n]]/.Plus->List; >> le=Length[wickli[[1]]]; >> wickli=wickli/.{pair[c[i_],d[j_]]->pair[i,j], >> pair[d[i_],c[j_]]->pair[i,j]}; >> graph={}; >> While[wickli=!={}, >> wickli=rempar[First[wickli],wickli,n, le]]; >> (*edge reduction and edgelist construction for use by Combinatorica= *) >> rep=Dispatch[Flatten[Table[{Rule[2*i-1,i],Rule[2*i,i]},{i,2*n}]]]= ; >> graph=(Take[#,-le]/.rep/.pair[a__]^_->pair[a])&/@graph; >> be=basicedges[n]; >> cgraph=Map[List,(graph/.{pair->List, Times->List}),{2}]; >> cvertices=List/@cvertexserie[n]; >> cgraph=Join[be,#]&/@cgraph; >> cgraph=Graph[#,cvertices]&/@cgraph; >> (* Now I compare Union and Tally *) >> un=Union[cgraph,SameTest->IsomorphicQ]; >> Print[Union: number of elements: , Length[un]]; >> Print[GraphicsGrid[Partition[ShowGraph[#]&/@un, 3,3,{1,1},{}]]]; >> ta=Tally[cgraph,IsomorphicQ]; >> ta=Sort[ta]; >> Print[Tally: Number of Elements: , Length[ta]]; >> Print[GraphicsGrid[Partition[ShowGraph[#]&/@(First/@ta), = >> 3,3,{1,1},{}]]]; >> Print[Are 5 and 10 isomorphic? , IsomorphicQ[cgraph[[5]], = >> cgraph[[10]]]]; >> ]; >> rempar[li_,wickli_List,n_Integer,le_]:=Module[{lis, mult, gem, pre= , i}, >> lis={Take[li,-le]}; pre=Drop[li,-le]; >> Do[lis=Join[lis,lis /. {i->i+1, i+1->i}], {i,1,4*n-1,2}]; >> lis =Union[lis]; >> mult=Length[lis]; >> graph=Join[graph,{li*mult}]; >> Complement[wickli,pre*lis] >> ]; >> End[]; >> EndPackage[]; > -- = DrMajorBob@bigfoot.com === Subject: Re: Using ReadList to read a string Don, here is a way to import that data correctly in one pass with a single ReadList call: ReadList[EWZ2.TXT, {Number, Word, Word, Number, Number, Number, Number, Number}, WordSeparators -> { , , }] This solution assumes that the EWZ2.TXT file is exactly as stated in your post (the data is space delimited and not tab delimited). Please let me know if this solution works on your system. Dario === Subject: Re: Adding description to plots which parameter of s. I only see 6 differently coloured curves. >Does Mathematica 6.0 provide such a function to add labels to each >curve in the plot? There are a number of ways to add labeling to plots in version 6. Here are three: Plot[Tooltip@{x, x^2, x^3}, {x, -1, 1}] This displays the label when your mouse is positioned over a curve << PlotLegends`; Plot[{x, x^2, x^3}, {x, -1, 1}, PlotLegend -> {x, !(*SuperscriptBox[x, 2]), !(*SuperscriptBox[x, 3])}] This gives you a shadow box with the plot labels GraphicsRow[{Plot[{x, x^2, x^3}, {x, -1, 1}], Plot[{1, 2, 3}, {x, 0, 1}, PlotRange -> {{-1, 10}, {-3, 4}}, Axes -> None, Epilog -> MapThread[ Text[#1, {1.2, #2}, {-1, 0}] &, {{x, !(*SuperscriptBox[x, 2]), !(*SuperscriptBox[x, 3])}, Range@3}]]}] This creates labels to the side of the main plot -- To reply via email subtract one hundred and four === Subject: Re: Mathematica: Long divison for polynomials As yet another semi-frequent contributor to this group I'd like to point out the following option that I often exercise. When I answer a question by a Mathematica user who appears to need the answer quickly I simply CC the answer to him or her as well. Then, independent of the Moderation, the (hopefully) useful content of what I have to say gets to the questioner promptly and is shared more universally when it appears in the group... --David > I agree with Daniel completely and, in addition, I'll just point out that > quite a few individuals like myself donate many hours & much energy > answering questions on Mathgroup, for absolutely no compensation but the > chance to learn something in the process and the fun of doing so. It wouldn't be fun to see half the messages revolve around debating > (arguing incessantly, really) which CAS is best. I've seen and been a > participant in similar time-waster threads off-line, and I'm quite certain > things constantly polluting, even dominating, the mailings. I do sometimes wonder what other CASs do differently, but really, I don't > have time to worry about it, here or anywhere else. Bobby > As the reply in the newsgroup is quite slow I did try a different >> newsgroup >> and receive an answer right after 21 minutes (rather than to have to >> wait >> a whole day in this newsgroup): > bd8e9a5475af5fe9?hl=it > There is also an interesting discussion about how meaningful it is >> to have a moderation in this particular newsgroup. > Frankly, I agree with what they are saying. >> I'm curious though whether my post is going to be displayed or not. > [I am offering a totally free service to those who want to use it. >> You should probably go elsewhere if it does not meet your needs. >> -- Moderator] There has been substantial commentary in sci.math.symbolic, going back > several years, over the various ups and downs of having a moderated > forum comp.soft-sys.math.mathematica. Here is a URL to a reply I made in > one such thread, a few months ago. > I've had some involvement with this since the beginning so I think I can > clarify and address a few issues. Bear in mind that I am replying as one > to the group, are part of my official job responsibilities. First, the group began life, and remains, as a moderated mailing list > forum known as MathGroup. It was extended to a Usenet group around 12-13 > years ago. I think this was partly in response to a need to remove the > many Mathematica-centric posts from sci.math.symbolic. And also there > was a desire to extend the mailing list reach to more people for whom it > was an appropriate venue, but who might not otherwise find it. So what are the gripes about this moderated group? They fall into a few > categories. (1) Turnaround time. It takes a day or so for a post to appear. So what > are the disadvantages to the relatively slow turnaround? One is that > feedback to the person posing questions is slow. This, I concede, is a > very real drawback. But short of cloning the moderator, I don't see a > good way around it. Suffice it to say, the advantages to having a > moderator (or at least to having the one we have), in my opinion, far > outweigh this. More below. (2) Another perceived drawback to the turnaround time is replication of > effort in responses. I've seen this issue raised but frankly I think it > is mostly baloney. The vast majority of responders know good and well > that others are also likely to respond, and they do so anyway. The fact > is, Mathematica is a complex program, and often there are multiple ways > to achieve a stated goal. Responders know this and oftentimes best > practice, or several reasonable forms thereof, emerge in the > multiplicity of responses. About the only actual drawback is that some > responders might delay an extra day to see if others answer first, and > this can prolong the process per (1) above. (3) There has been persistent griping about the moderation amounting to > censorship. Depending on how you define the terms, I suppose perhaps > this can be a valid sort of remark. But the upshot is that whether you > call it moderating or censorship, the moderator keeps a huge amount of > garbage out of the group. If you have not seen similar groups > to say that these problems have arisen and persisted for long stretches > of time. But never, absolutely never, has such a fate befallen > comp.soft-sys.math.mathematica. The group has remained consistently > useable, with outages only in rare times (like two or three over a > period of a dozen years) when the moderator's systems or ISP have > suffered grievous damage. (4) One particular censorship gripe concerns the rule against mention of > competing programs. I myself am a bit sympathetic to this one; if there > were a single restriction I could change, this would be it. That said, I > think that unrestricted allowance of such could pose a problem. That is, > we might see the sort of degeneration into rants (Why can't Mathematica > do X? Program MZZZ does it? followed, a day later, by Why can't > Mathematica do Y?...). In past I've seen at least some tendency toward > such posts, and it is generally thwarted by this restriction, which > means the restriction has some merit. Also it helps to keep the focus on > Mathematica per se, which is what the group is all about. As to what are the best places to take Mathematica related questions, > answers will vary and to some extent it can depend on what you need. > MathGroup aka comp.soft-sys.math.mathematica remains a compelling venue > when the one day turnaround is acceptable, and high quality of response > is needed. It is the forum with the most expertise. I think this is in > large part because the moderator keeps out garbage, thus making the > signal-to-noise ration quite high. Were it to degenerate to some of the > things I have seen, I doubt most of us would maintain interest for long. > So yeah, the turnaround time is an issue, but there are advantages to > the moderating that, for myself at least, far outweigh this drawback. Daniel Lichtblau > Wolfram Research -- DrMajor...@bigfoot.com === Subject: Re: Re: Mathematica: Long divison for polynomials I agree with Daniel completely and, in addition, I'll just point out that quite a few individuals like myself donate many hours & much energy answering questions on Mathgroup, for absolutely no compensation but the chance to learn something in the process and the fun of doing so. It wouldn't be fun to see half the messages revolve around debating (arguing incessantly, really) which CAS is best. I've seen and been a participant in similar time-waster threads off-line, and I'm quite certain things constantly polluting, even dominating, the mailings. I do sometimes wonder what other CASs do differently, but really, I don't have time to worry about it, here or anywhere else. Bobby >> As the reply in the newsgroup is quite slow I did try a different >> newsgroup >> and receive an answer right after 21 minutes (rather than to have to >> wait >> a whole day in this newsgroup): >> bd8e9a5475af5fe9?hl=it >> There is also an interesting discussion about how meaningful it is >> to have a moderation in this particular newsgroup. >> Frankly, I agree with what they are saying. >> I'm curious though whether my post is going to be displayed or not. >> [I am offering a totally free service to those who want to use it. >> You should probably go elsewhere if it does not meet your needs. >> -- Moderator] There has been substantial commentary in sci.math.symbolic, going back > several years, over the various ups and downs of having a moderated > forum comp.soft-sys.math.mathematica. Here is a URL to a reply I made in > one such thread, a few months ago. > I've had some involvement with this since the beginning so I think I can > clarify and address a few issues. Bear in mind that I am replying as one > to the group, are part of my official job responsibilities. First, the group began life, and remains, as a moderated mailing list > forum known as MathGroup. It was extended to a Usenet group around 12-13 > years ago. I think this was partly in response to a need to remove the > many Mathematica-centric posts from sci.math.symbolic. And also there > was a desire to extend the mailing list reach to more people for whom it > was an appropriate venue, but who might not otherwise find it. So what are the gripes about this moderated group? They fall into a few > categories. (1) Turnaround time. It takes a day or so for a post to appear. So what > are the disadvantages to the relatively slow turnaround? One is that > feedback to the person posing questions is slow. This, I concede, is a > very real drawback. But short of cloning the moderator, I don't see a > good way around it. Suffice it to say, the advantages to having a > moderator (or at least to having the one we have), in my opinion, far > outweigh this. More below. (2) Another perceived drawback to the turnaround time is replication of > effort in responses. I've seen this issue raised but frankly I think it > is mostly baloney. The vast majority of responders know good and well > that others are also likely to respond, and they do so anyway. The fact > is, Mathematica is a complex program, and often there are multiple ways > to achieve a stated goal. Responders know this and oftentimes best > practice, or several reasonable forms thereof, emerge in the > multiplicity of responses. About the only actual drawback is that some > responders might delay an extra day to see if others answer first, and > this can prolong the process per (1) above. (3) There has been persistent griping about the moderation amounting to > censorship. Depending on how you define the terms, I suppose perhaps > this can be a valid sort of remark. But the upshot is that whether you > call it moderating or censorship, the moderator keeps a huge amount of > garbage out of the group. If you have not seen similar groups > to say that these problems have arisen and persisted for long stretches > of time. But never, absolutely never, has such a fate befallen > comp.soft-sys.math.mathematica. The group has remained consistently > useable, with outages only in rare times (like two or three over a > period of a dozen years) when the moderator's systems or ISP have > suffered grievous damage. (4) One particular censorship gripe concerns the rule against mention of > competing programs. I myself am a bit sympathetic to this one; if there > were a single restriction I could change, this would be it. That said, I > think that unrestricted allowance of such could pose a problem. That is, > we might see the sort of degeneration into rants (Why can't Mathematica > do X? Program MZZZ does it? followed, a day later, by Why can't > Mathematica do Y?...). In past I've seen at least some tendency toward > such posts, and it is generally thwarted by this restriction, which > means the restriction has some merit. Also it helps to keep the focus on > Mathematica per se, which is what the group is all about. As to what are the best places to take Mathematica related questions, > answers will vary and to some extent it can depend on what you need. > MathGroup aka comp.soft-sys.math.mathematica remains a compelling venue > when the one day turnaround is acceptable, and high quality of response > is needed. It is the forum with the most expertise. I think this is in > large part because the moderator keeps out garbage, thus making the > signal-to-noise ration quite high. Were it to degenerate to some of the > things I have seen, I doubt most of us would maintain interest for long. > So yeah, the turnaround time is an issue, but there are advantages to > the moderating that, for myself at least, far outweigh this drawback. Daniel Lichtblau > Wolfram Research -- DrMajorBob@bigfoot.com === Subject: Re: Re: Mathematica: Long divison for polynomials As the reply in the newsgroup is quite slow I did try a different newsgroup > and receive an answer right after 21 minutes (rather than to have to wait > a whole day in this newsgroup): > There is also an interesting discussion about how meaningful it is > to have a moderation in this particular newsgroup. Frankly, I agree with what they are saying. > I'm curious though whether my post is going to be displayed or not. [I am offering a totally free service to those who want to use it. > You should probably go elsewhere if it does not meet your needs. > -- Moderator] There has been substantial commentary in sci.math.symbolic, going back several years, over the various ups and downs of having a moderated forum comp.soft-sys.math.mathematica. Here is a URL to a reply I made in one such thread, a few months ago. I've had some involvement with this since the beginning so I think I can clarify and address a few issues. Bear in mind that I am replying as one to the group, are part of my official job responsibilities. First, the group began life, and remains, as a moderated mailing list forum known as MathGroup. It was extended to a Usenet group around 12-13 years ago. I think this was partly in response to a need to remove the many Mathematica-centric posts from sci.math.symbolic. And also there was a desire to extend the mailing list reach to more people for whom it was an appropriate venue, but who might not otherwise find it. So what are the gripes about this moderated group? They fall into a few categories. (1) Turnaround time. It takes a day or so for a post to appear. So what are the disadvantages to the relatively slow turnaround? One is that feedback to the person posing questions is slow. This, I concede, is a very real drawback. But short of cloning the moderator, I don't see a good way around it. Suffice it to say, the advantages to having a moderator (or at least to having the one we have), in my opinion, far outweigh this. More below. (2) Another perceived drawback to the turnaround time is replication of effort in responses. I've seen this issue raised but frankly I think it is mostly baloney. The vast majority of responders know good and well that others are also likely to respond, and they do so anyway. The fact is, Mathematica is a complex program, and often there are multiple ways to achieve a stated goal. Responders know this and oftentimes best practice, or several reasonable forms thereof, emerge in the multiplicity of responses. About the only actual drawback is that some responders might delay an extra day to see if others answer first, and this can prolong the process per (1) above. (3) There has been persistent griping about the moderation amounting to censorship. Depending on how you define the terms, I suppose perhaps this can be a valid sort of remark. But the upshot is that whether you call it moderating or censorship, the moderator keeps a huge amount of garbage out of the group. If you have not seen similar groups to say that these problems have arisen and persisted for long stretches of time. But never, absolutely never, has such a fate befallen comp.soft-sys.math.mathematica. The group has remained consistently useable, with outages only in rare times (like two or three over a period of a dozen years) when the moderator's systems or ISP have suffered grievous damage. (4) One particular censorship gripe concerns the rule against mention of competing programs. I myself am a bit sympathetic to this one; if there were a single restriction I could change, this would be it. That said, I think that unrestricted allowance of such could pose a problem. That is, we might see the sort of degeneration into rants (Why can't Mathematica do X? Program MZZZ does it? followed, a day later, by Why can't Mathematica do Y?...). In past I've seen at least some tendency toward such posts, and it is generally thwarted by this restriction, which means the restriction has some merit. Also it helps to keep the focus on Mathematica per se, which is what the group is all about. As to what are the best places to take Mathematica related questions, answers will vary and to some extent it can depend on what you need. MathGroup aka comp.soft-sys.math.mathematica remains a compelling venue when the one day turnaround is acceptable, and high quality of response is needed. It is the forum with the most expertise. I think this is in large part because the moderator keeps out garbage, thus making the signal-to-noise ration quite high. Were it to degenerate to some of the things I have seen, I doubt most of us would maintain interest for long. So yeah, the turnaround time is an issue, but there are advantages to the moderating that, for myself at least, far outweigh this drawback. Daniel Lichtblau Wolfram Research === Subject: Re: Re: Mathematica: Long divison for polynomials Ditto. Some of my posts shouldn't go through either! Bobby >> As the reply in the newsgroup is quite slow I did try a different >> newsgroup >> and receive an answer right after 21 minutes (rather than to have to >> wait >> a whole day in this newsgroup): >> There is also an interesting discussion about how meaningful it is >> to have a moderation in this particular newsgroup. >> Frankly, I agree with what they are saying. >> I'm curious though whether my post is going to be displayed or not. Clearly it was. I think there is a place both for moderated and > unmoderated groups of this kind. I, for one, on principle avoid > participating in the second kind. In order to be able to tell how > meaningful it is to have moderation in this particular newsgroup you > would have to know some of the posts that got stopped by the > moderator. I personally find the moderator very useful even though, or > rather because, a few of them were mine. -- DrMajorBob@bigfoot.com === Subject: Re: Re: Mathematica: Long divison for polynomials As the reply in the newsgroup is quite slow I did try a different > newsgroup > and receive an answer right after 21 minutes (rather than to have to > wait > a whole day in this newsgroup): > There is also an interesting discussion about how meaningful it is > to have a moderation in this particular newsgroup. Frankly, I agree with what they are saying. > I'm curious though whether my post is going to be displayed or not. > Clearly it was. I think there is a place both for moderated and unmoderated groups of this kind. I, for one, on principle avoid participating in the second kind. In order to be able to tell how meaningful it is to have moderation in this particular newsgroup you would have to know some of the posts that got stopped by the moderator. I personally find the moderator very useful even though, or rather because, a few of them were mine. === Subject: Re: Mathematica: Long divison for polynomials As the reply in the newsgroup is quite slow I did try a different newsgroup and receive an answer right after 21 minutes (rather than to have to wait a whole day in this newsgroup): There is also an interesting discussion about how meaningful it is to have a moderation in this particular newsgroup. Frankly, I agree with what they are saying. I'm curious though whether my post is going to be displayed or not. [I am offering a totally free service to those who want to use it. You should probably go elsewhere if it does not meet your needs. -- Moderator] === Subject: MultivariateStatistics Package How do I make the MultivariateStatistics package accessible to any cell in a notebook? John === Subject: Re: trying to Import[] USGS-resident DEM data > I am still trying to wrap my head around the need for the > hh[] construct, since it is apparently not used in the final > RepliefPlot invocation. The hh and the dd are arbitrary symbols that I chose as heads to indicate the location of certain types of file information. The symbol hh stands for header and one parameter in the header indicates the length of the next row. The symbol dd stands for data, since this is where the actual list of elevations for the row occurs. Note that the function, row, operates on {hh,dd} pairs. Certainly, nested lists could have been used. I like to use specific heads to indicate specific types of data, since I think it it makes the code more understandable and can be easier with respect to certain operations, like Flatten. > Also, I am hopeful that some future point release of V6 will > resolve the issue using the built-in Import[] function. While not certain, I *believe* that further developement is planned for geospatial file formats. I would particlarly like to see shape file import. I'm glad the code helped, Mark === Subject: Re: ListAnimate and GIF format saving > I am sending a small code (in Mathematica 6.0). Here data plots > as animation and I want to save as a .gif file. Export[anim.gif, graphicsList] will automatically export to an animated GIF, assuming that graphicsList is a List of Graphics objects. You should remove the ListAnimate command from your example, if you want to generate an animated GIF. Mark === Subject: Re: Scalars Instead of Lists with One Element I've found the problem. Say you want to sum a list whose elements are > 13 and 9. Mathematica will return a list with one element, {22}, > rather than 22 if the original list is specified as a 2x1 column vector. x = {{13}, {9}}; y = Total@x > returns {22} This also happens if you write x as I have above, or you use > Mathematica's Insert menu to create a more visually appealing column > vector, Tip: Use CTRL+Enter and CTRL+, instead of the insert menu. > but it does not happen if you define x as a 2x1 array using > the Array command. Yes, it does: In[1]:= Array[# &, {2, 1}] Out[1]= {{1}, {2}} In[2]:= Total[%] Out[2]= {3} I think it will happen with any matrix calculation whose result should > otherwise be a scalar. If we now let y be the row vector {1, 1} then y.x > returns {22} > This is because Mathematica works with tensors of arbitrary dimensions, not just matrices or vectors. So in Mathematica it does not make sense to speak about column or row vectors---all vectors (1D arrays) are treated in the same way. {{1},{2}} is a 2 by 1 matrix and {{1, 2}} is a 1 by 2 matrix, not vectors. (Of course all this is just a question of naming conventions. I am just trying to explain why Mathematica works this way.) > The upshot of this is that any table that is created from calculations > that make use of column vectors or matrix math will likely have a > depth greater than 3, and you won't be able to cut and paste directly > into a word processor or spreadsheet. When you multiply a vector with a matrix, you get a vector. If you multiply a vector with a vector, you get a scalar: In[4]:= {x, y}.{{a, b}, {c, d}} Out[4]= {a x + c y, b x + d y} In[5]:= {{a, b}, {c, d}}.{x, y} Out[5]= {a x + b y, c x + d y} In[6]:= {x, y}.{a, b} Out[6]= a x + b y If the distinction between column and row vectors is important, just work with matrices, and you'll always get matrices as the result (no scalars): In[7]:= {{x, y}}.{{a}, {b}} Out[7]= {{a x + b y}} In[8]:= {{a}, {b}}.{{x, y}} Out[8]= {{a x, a y}, {b x, b y}} If it is not important to differentiate between row and column vectors, then use 1D arrays to represent vectors. The Outer product can be calculated like this: In[9]:= Outer[Times, {a, b}, {x, y}] Out[9]= {{a x, a y}, {b x, b y}} I'm going to have a look at some of the work-arounds that have been > suggested in this thread and my related thread Copy and Pasting > Tables into Spreadsheet. > Gregory > -- Szabolcs === Subject: Export figures with tooltips I have a list of points {{x,y, label}, ...} that I can render trivially as points with tooltips ListPlot[ Map[ Tooltip[ {#[[1]], #[[2]]}, #[[3]]] &, dat] ] I would like to export this figure, including these tooltips, so it can be shared broadly. How can I do so? === Subject: Re: negative FileByteCount > Very interesting replies, thank you very much. I don't want to load > the whole file into memory, the main, virtual or whatever, but I do > want to have an access to it. The C runtime fopen() gives me a handle > to my big file (and to the biggest files on my harddisk, which are now > a couple of HD films). Then I can read from it with a trivial C code. > Why can't I do the same from Mathematica? In[3]:= snum = OpenRead[scandata.xyz] > Out[3]= InputStream[scandata.xyz, 29] > In[4]:= FileByteCount[scandata.xyz] > Out[4]= -936210076 > In[5]:= ReadList[snum, Number, 3] > Out[5]= {} This is a known limitation in Mathematica. Expect it to be fixed in future releases. Oleksandr Pavlyk Wolfram Research === Subject: Button[label, action] Change Font? I want to change the font of the button label, but apparently can't do this. Using the basic example as input Button[Click Here Print[10!]] obtaining the button with Click Here with type face plain, font Ariel. I can change the type face from the format menu to obtain type face bold. But I can not change the front, even though the corresponding expression (below) reveals that the font should be Ariel Black, this face is not displayed. I can also change the type color, but apparently not the size. Might there be some place where some things are set globally that overrides this setting? Cell[BoxData[ ButtonBox[, Appearance->DialogBox, ButtonData->paclet:ref/Click Here, ButtonFrame->DialogBox, ButtonFunction:>Print[ Factorial[10]], Evaluator->Automatic, Method->Preemptive]], Output, ImageSize->{61, 25}, ImageMargins->{{0, 0}, {0, 0}}, ImageRegion->{{0, 1}, {0, 1}}, FontFamily->Arial Black, FontWeight->Bold, CellLabel->Out[1]=, CellID->23005] Any help much appreciated.... Joe -- Joe Sneed Division of Liberal Arts and International Studies Colorado School of Mines Golden CO USA mailto:jsneed@mines.edu http://www.mines.edu/fs_home/jsneed/ === Subject: Database like left join or SAS like Merge function Is there a builtin function that can join (merge) two two- dimensional data lists based on a single or multiple key column? This seems like such a basic requirement that I feel like I must be missing something obvious. === Subject: Re: Discrepancy between Integrate and NIntegrate > I first use Integrate and then evaluate the results with n=3 and > the limits t=pi and t=0. I then numerically evaluate the same > integrand and the results are very different. Can anyone help > me with this problem? Sure. (BTW, I'm surprised that nobody has responded to your request yet.) Your results don't _quite_ prove a bug. But I will show a bug (present in version 5.2, and probably also in version 6) which is very closely related to your discrepancy. I'll try to explain everything clearly. > Clear[n] > val1 = n*Pi*I*Integrate[(Cos[n*Pi*Exp[I*t]]/ > Cosh[n*Pi*Exp[I*t]])*Exp[I*t], t] > N[(val1 /. {n -> 3, t -> Pi}) - (val1 /. {n -> 3, t -> 0})] n = 3; > i1 = NIntegrate[n*Pi*I*(Cos[n*Pi*Exp[I*t]]/Cosh[n*Pi*Exp[I*t]])* > Exp[I*t], {t, 0, Pi}] -1.2522017302861566 + 0.*I > 7757.4213022137155 + 0.*I As you might have supposed, the result of NIntegrate is correct. But let's get in mind what it represents: the integral of Cos[z]/Cosh[z] counterclockwise along the portion of the circle, centered at the origin and having radius 3 Pi, in the upper half of the complex plane. If we were to consider a closed curve C formed by the semicircle mentioned above and its diameter along the real axis, then we can get the value of the integral around C using the residue theorem. Within that contour, we have only simple poles at I Pi/2, 3 I Pi/2, and 5 I Pi/2. Mathematica can easily evaluate the residues. For example, In[4]:= Residue[Cos[z]/Cosh[z], {z, 5 I Pi/2}] Out[4]= (-I)*Cosh[(5*Pi)/2] So then the value of the integral around C is 2 Pi I (-I Cosh[Pi/2] - (-I) Cosh[3*Pi/2] + (-I) Cosh[5*Pi/2]) which simplifies In[7]:= Simplify[2 Pi I (-I Cosh[Pi/2] - (-I) Cosh[3*Pi/2] + (-I)Cosh[5*Pi/2])] Out[7]= 2*Pi*Cosh[Pi/2]*(1 - 2*Cosh[Pi])^2 In[8]:= N[%] Out[8]= 7758.67 An important clue to your discrepancy is that the numerical value above is the sum of the absolute values of your two numerical results, -1.25 and 7757.42 . Now consider something which is closely related to your val1: In[9]:= N[Integrate[(Cos[3*Pi*E^(I*t)]/Cosh[3*Pi*E^(I*t)])*3*Pi*E^(I*t)*I, {t, 0, Pi}]] Out[9]= -1.2522 + 0.*I This shows a bug, of a sort which is not uncommon in Mathematica. Now you're probably wondering why I call that a bug, but had said earlier, when you got that same numerical answer, that you hadn't quite proven a bug! Well, it's because, although your val1 had discontinuites, you nonetheless proceeded to evaluate the definite integral by using just F(b) - F(a), and so it could be argued that you made the mistake, rather than Mathematica, by not taking the discontinuites into account. But my Out[9] indicates that Mathematica _itself_ makes the very same mistake, and so that is indeed a bug. We can, if careful, get a correct symbolic answer for the integral along just your semicircle: In[10]:= 2 Re[Integrate[(Cos[3*Pi*E^(I*t)]/Cosh[3*Pi*E^(I*t)])*3*Pi*E^(I*t)*I, {t, Pi/2, Pi}]] Out[10]= 2*Re[((-(1/4))*((2 + 2*I)*Hypergeometric2F1[1/2 - I/2, 1, 3/2 - I/2, -E^(-6*Pi)] + (2 - 2*I)*Hypergeometric2F1[1/2 + I/2, 1, 3/2 + I/2, -E^(-6*Pi)] + PolyGamma[0, 1/4 + I/4] + E^(6*Pi)*(PolyGamma[0, 1/4 - I/4] - PolyGamma[0, 3/4 - I/4]) - PolyGamma[0, 3/4 + I/4]))/E^(3*Pi)] In[11]:= N[%] Out[11]= 7757.42 But I should explain what I did: I looked at graphs of real and imaginary parts of Mathematica's indefinite integral. Although the real part had discontinuities, it didn't have any between t = Pi/2 and Pi. Thus, by symmetry, I knew that doubling the real part of the definite integral from Pi/2 to Pi should correctly give the real part of the desired result. Furthermore, by symmetry, the imaginary part of the integral from 0 to Pi/2 is our complete symbolic answer. Finally, note that Mathematica correctly calculates the integral along the real axis from -3 Pi to 3 Pi: In[15]:= Integrate[Cos[x]/Cosh[x], {x, -3 Pi, 3 Pi}] Out[15]= ((1/2)*I*(Beta[-E^(-6*Pi), 1/2 - I/2, 0] - Beta[-E^(6*Pi), 1/2 - I/2, 0] + E^Pi*(Beta[-E^(-6*Pi), 1/2 + I/2, 0] - Beta[-E^(6*Pi), 1/2 + I/2, 0])))/E^(Pi/2) In[16]:= N[%] Out[16]= 1.2522 + 0.*I Then adding Out[10] and Out[15], we get a result in numerical agreement with Out[7], our integral around C which we had calculated using the residue theorem. David W. Cantrell === Subject: Re: Dynamic Timeout I just posted a response to another user with a similar, and fortunately, more soluble problem than what you're dealing with. In the case of Button[], the same problem does arise, but it would be trivially resolvable by setting the Method->Queued option. Clearly, ActionMenu ought to have a similar Method option. In version 6, it does not, but it's certainly on our radar for future releases. You can work around it by wrapping an EventHandler[] around your ActionMenu[] which resets the DynamicEvaluationTimeout. The below example is not elegant and does not restore the DynamicEvaluationTimeout, but it gives you an idea of how to proceed. EventHandler[ ActionMenu[ menu, {file :> Print[SystemDialogInput[FileOpen]]}], {MouseDown :> SetOptions[$FrontEnd, DynamicEvaluationTimeout -> 1000]}, PassEventsDown -> True] John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Hello Mathgroup, I have created my own custom Toolbar (DockedCell) with some shortcuts > and buttons that I frequently use. One of the items in the toolbar is > an ActionMenu which contains calls to some of my own functions. In one > of these functions, SystemDialogInput[] is called, with which I can > select a subdirectory on my hard drive. ActionMenu is implemented as a Dynamic[] object in Mathematica; > therefore, whatever action is triggered by choosing one of the > entries, is subject to the Timeout feature of Dynamic[] evaluations. > That means that if I am not fast enough when picking my directory, > nothing will happen, since the call has timed out. Setting the option > SynchronousUpdating->False does not help. What does help is to increase the Timeout-time by setting > SetOptions[$FrontEnd,DynamicEvaluationTimeout->10000] or some other > high number. My problem is: I do not usually want the timeout to be that large, the > normal setting of 5 or 6 seconds is quite reasonable. What I can do, > then, is to automatically re-set DynamicEvaluationTimeout to 6 at the > end of the function - that works. What does NOT work, however, is to > set it to 10000 at the beginning of the function. (Actually, it does > work, but it does not take effect yet for the currently evaluating > Dynamic[] within which it was set to 10000.) So, the question is: how do I avoid the timeout in this case, without > generally increasing the timeout time? thomas p.s. A very easy work-around is to call my function with the help of a > button, instead of using an action menu. This avoids Dynamic and the > problem doesn't even show up. Nevertheless, I think it should be > possible to do such things from within an action menu (or from within > other dynamic constructs) === Subject: Re: Dynamic Timeout A better solution (i.e. one that never touches the global value of DynamicEvaluationTimeout) than EventHandler[] would be to set DynamicEvaluationTimeout using Style. E.g., Style[ActionMenu[...], DynamicEvaluationTimeout->1000] Mea culpa. I plead temporary insanity while trying to get home for John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > I just posted a response to another user with a similar, and fortunately, > more soluble problem than what you're dealing with. In the case of Button[], > the > same problem does arise, but it would be trivially resolvable by setting > the > Method->Queued option. Clearly, ActionMenu ought to have a similar > Method > option. In version 6, it does not, but it's certainly on our radar for > future > releases. You can work around it by wrapping an EventHandler[] around your > ActionMenu[] > which resets the DynamicEvaluationTimeout. The below example is not > elegant and > does not restore the DynamicEvaluationTimeout, but it gives you an idea > of how > to proceed. EventHandler[ > ActionMenu[ > menu, {file : Print[SystemDialogInput[FileOpen]]}], {MouseDown : SetOptions[$FrontEnd, DynamicEvaluationTimeout -> 1000]}, > PassEventsDown -> True] > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. >> Hello Mathgroup, >> I have created my own custom Toolbar (DockedCell) with some shortcuts >> and buttons that I frequently use. One of the items in the toolbar is >> an ActionMenu which contains calls to some of my own functions. In one >> of these functions, SystemDialogInput[] is called, with which I can >> select a subdirectory on my hard drive. >> ActionMenu is implemented as a Dynamic[] object in Mathematica; >> therefore, whatever action is triggered by choosing one of the >> entries, is subject to the Timeout feature of Dynamic[] evaluations. >> That means that if I am not fast enough when picking my directory, >> nothing will happen, since the call has timed out. Setting the option >> SynchronousUpdating->False does not help. >> What does help is to increase the Timeout-time by setting >> SetOptions[$FrontEnd,DynamicEvaluationTimeout->10000] or some other >> high number. >> My problem is: I do not usually want the timeout to be that large, the >> normal setting of 5 or 6 seconds is quite reasonable. What I can do, >> then, is to automatically re-set DynamicEvaluationTimeout to 6 at the >> end of the function - that works. What does NOT work, however, is to >> set it to 10000 at the beginning of the function. (Actually, it does >> work, but it does not take effect yet for the currently evaluating >> Dynamic[] within which it was set to 10000.) >> So, the question is: how do I avoid the timeout in this case, without >> generally increasing the timeout time? >> thomas >> p.s. A very easy work-around is to call my function with the help of a >> button, instead of using an action menu. This avoids Dynamic and the >> problem doesn't even show up. Nevertheless, I think it should be >> possible to do such things from within an action menu (or from within >> other dynamic constructs) === Subject: Re: Neural networks with mathematica necessary was to clarify the point, because the reader could read words like illegal that sounds very bad. (dont you think?) Anyway i have the same kind of errors and i guess that the examples i just a manuscript i found. Now i start to study on simulating neural networks with mathematica and of course the examples are working. Dino === Subject: Coloring cells Hi All, I'm presenting data in a square arrangement and am trying to highlight specific cells in it which have something in common, e.g. all are prime, or all are odd numbers. I don't mind if the data is in an array/matrix/table, as long as it is n x n. myData = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; How do I either color the text or the background of a particular cell, based on a rule (e.g. how could I color just 2, 3, 5, and 7 in the data given)? Jamie === Subject: Re: Get list of function variables? Hi Jason > I am aware that the solutions I posted do not hold in general. My > basic desire for the getVariables function was to help generate a new > function with those variables (and another set of the same size). I > wanted a notebook that could give the the error function for ANY > function the user inputed without having to do any work. Maybe there's > a better way than how I did it (but I have a working notebook so I'm > better off than I was). In other words give some function, say, the price to carpet an x by > y by z room at w per square unit area: > f(w,x,y,z)=w(x*y*z) > I want the sigma error on f given sigma errors on the variables. So a > new function ef > ef(x,y,z,ex,ey,ez) > where ef is defined by the usual error propagation equation a sum over > partial derivatives squared. The e prefix denotes the sigma error on > the corresponding variable. Note the new function recognizes w as a > parameter. If I went about this in some ass-backwards fashion by grabbing the > variables from f directly, I'm a little bit embarrassed but would be > interested in knowing a better way. I think for what you want to achieve you should really look into pure functions and define your functions as those, e.g.: f=Function[{w,x,y,z},w[x*y*z]] those are easier to pass around as objects (since you don't need to care about wasting your namespace with symbols that hold the downvalues), the function getVariables is much simpler, since you just need to extract the first argument: getVariables[f_]:=First[f] or maybe if you want your code to be more robust: getVariables[f]:=Extract[f,{1},Hold] of course then you need to handle the extra Hold... Finally when you need to calculate derivatives, this is also very convenient and can be done with using either named or positional arguments, where the later directly returns a function again, so you don't need to mess around with reconstructing functions from expressions in a save way: D[f[w,x,y,z],x] or with positional arguments: Derivative[0, 1, 0, 0][f] hth, albert === Subject: Re: Fast way of checking for perfect squares? This can be sped up slightly by using listability: In[1]:= data = RandomInteger[{10^50, 10^60}, 10^5]; data = Join[data^2, data^2 + 1]; In[3]:= Timing[Pick[data, Unitize@ FractionalPart@ Sqrt@ N[data, 1 + Ceiling@ Log[10, Max@ data]], 0] == Take[data, 10^5]] Out[3]= {1.453, True} Maxim Rytin m.r@inbox.ru > And that's the new speed champion for this problem! It fails for squares of 15-digit and bigger integers, however... and my > earlier fasterSquareQ fails for squares of 32-digit and bigger integers. Of the three reliable methods, Daniel Lichtblau's is slightly faster than > my intSqrt method, and the OP's slowSquareQ is fastest for perfect > squares, but slowest for non-squares (which are far more common). Bobby Since your integers are not too large, the following works fine and fast: Select[data, Round[Sqrt[N[#]]]^2 == # &] Fred Simons > Eindhoven University of Technology > Hi > Lets say I have a lot of large integers and I want to check to see >> which ones are perfect squares - eg > data = Table[RandomInteger[10000000000], {100000}]; > I create a function that takes the square root of each one and checks >> to see if the result is an integer > slowSquareQ := IntegerQ[Sqrt[#1]] & > This works fine: > Select[data, slowSquareQ] // Timing > {11.39, {6292614276, 2077627561}} > but I am wondering if I can make it faster as my actual application >> has a LOT more numbers to test than this. This was a question posed a >> few years ago in this very newsgroup and the suggestion was to use a >> test of the form MoebiusMu[#]==0. > Well the MoeboisMu function is new to me so I experimented a little >> and sure enough when you apply the MoebiusMu function to a perfect >> square number the result is zero. > MoebiusMu[4] = 0 > The problem is that lots of other numbers have this property as well - >> eg > MoebiusMu[8] =0 > despite this minor problem I determined that applying the test >> MoebiusMu[#]==0 on a list of integers is fater than my slowSquareQ: > mobSquareQ := If[MoebiusMu[#1] == 0, True, False] & >> Select[data, mobSquareQ]; // Timing > gives a result of 8.156 seconds compared to 11.39 for slowSquareQ. On >> my test data I had around 39,000 integers that passed this test which >> is a shame but at least I have eliminated the other 61,000 or so. So >> I thought that maybe I can use the faster MoebiusMu test as a filter: > SquareQ := If[MoebiusMu[#1] == 0, slowSquareQ[#1], False] & >> Select[data, SquareQ] // Timing >> {11.312, {6292614276, 2077627561}} > So after all that I have saved just a few tenths of a second. Not >> very impressive. Can anyone out there do any better? >> Please forgive me if I have made any stupid mistakes but I have a cold >> at the moment. > Mike -- DrMajor...@bigfoot.com === Subject: Re: Joining InterpolatingFunctions into Piecewise - doman? Hi Janos, note that Piecewise has the attribute HoldAll. However, you want to evaluate the body of Pieceweise before feeding it to Piecewise. I do this with tt: f[ini_,tlast_]:=Module[{from=tlast,to=tlast+1,X},{X=(x/.NDSolve[{x'[t]==-0.5 x[t],ini},x,{t,from,to}])[[1]],to,X[to]}] nl=NestList[f[x[#[[2]]]==#[[3]],#[[2]]]&,{zzz,0,2.0},3]; tt=Transpose[{Table[nl[[k,1]][t],{k,2,4}],Table[k<=t I would like to solve a diff eq on a very large interval, therefore I > solve it on successive intervals. > When putting the results together I get a _relatively_ good figure and > an error message. > Note that there is a hole on the graph of the function. Any other > solution to join InterpolatingFunction objects would be appreciated. > f[ini_, tlast_] := > Module[{from = tlast, to = tlast + 1, > X}, {X = (x /. > NDSolve[{x'[t] == -0.5 x[t], ini}, x, {t, from, to }])[[1]], > to, X[to]}] > nl = NestList[f[x[#[[2]]] == #[[3]], #[[2]]] &, {zzz, 0, 2.0}, 3]; > full[t_] := > Piecewise[ > Transpose[{Table[nl[[k, 1]][t], {k, 2, 4}], > Table[k <= t < k + 1, {k, 0, 2}]}]] > Plot[full[t], {t, 0, 3}] > === Subject: Re: Interpolating arrays Hi Fred, i seems that for vector valued functions you have to enclose the independent variable in braces: Interpolation[{{{1},{1,1}},{{2},{2,2}},{{3},{3,3}}}] The documentation is a bit thin here. hope this helps, Daniel > Interpolation (according to the doc center) offers to construct an > interpolating function given x values and f[x] values in the following > format: Interpolation[{{x1, f1},{x2, f2},...{xi, fi}...] Down a few lines, doc center says: > The fi can be lists or arrays of any dimension I'm interested in interpolating between 2D geometric points {a, b}, and a > naive form would be p = Interpolation[{{x1, {a1, b1}},{x2, {a2, b2}},...,{xi, {ai, bi}}...}], > expecting to get a form where p[x] would return a 2D point. Too naive it seems, because it doesn't work. As far as I can determine, it > returns only an Interpolation on a. How come? It's straightforward enough to construct separate 1D interpolations on a and > b, then reassemble them later, but that's just clumsy and seems just not the > Mathematica Way. Any help? TIA, Fred Klingener === Subject: Re: Interpolating arrays By trial and error, I found that I could get a list-valued interpolation function by enclosing the abscissa values in braces--in your example, Interpolation[{{{x1}, {a1, b1}},{{x2}, {a2, b2}},...,{{xi}, {ai, bi}}...}] Here is how I think Interpolation interprets the arguments a1 and b1 in four variations: 1. {x1, a1, b1} (* a1 is the ordinate, b1 is its first derivative *) 2. (x1, {a1,b1}} (* ditto *) 3. {{x1}, a1, b1} (* {a1, b1} is a list-valued ordinate *) 4. {{x1}, {a1,b1}} (* ditto*) 5. {{x1}, {{a1,b1}, {c1, d1}}} (* {a1,b1,c1,d1} is a list-valued ordinate *) Behaviors 2, 3, & 5 differ from what the explanation of Interpolation lead me to believe. Tom > ... Interpolation (according to the doc center) offers to construct > an interpolating function given x values and f[x] values in the > following format: Interpolation[{{x1, f1},{x2, f2},...{xi, fi}...] Down a few lines, doc center says: The fi can be lists or arrays of > any dimension I'm interested in interpolating between 2D geometric points {a, b}, > and a naive form would be p = Interpolation[{{x1, {a1, b1}},{x2, {a2, b2}},...,{xi, {ai, > bi}}...}], expecting to get a form where p[x] would return a 2D point. Too naive it seems, because it doesn't work. As far as I can > determine, it returns only an Interpolation on a. How come? ... === Subject: Re: Problems with Mathematica text in email Szabolcs, Jean-Marc, Kevin > I have noticed recently that a number of posts show text with powers >> and other symbols. For example, x^2+y^2==z^3 shows up with the nice >> exponentials in the text rather than what I just showed. I am not >> sure how this was copied, but I can't get it. Anyway, when I copy >> such things into a notebook it comes out as x2+y2==z3, which makes it >> difficult to use. >> Is there a way to copy this stuff into a notebook so it does it >> correctly? If not, then it would be nice if posters would Copy As >> Plain Text. Does anyone else have this problem? I am using >> Thunderbird under WXP. The issue is related to how Thunderbird handles emoticons (or smilies). To fix it, in Thunderbird 2.0, go to menu Tools -> Options -> Display > -> Formatting -> Plain Test Messages -> uncheck the box Display > emoticons as graphics. > === Subject: Re: Problems with Mathematica text in email > I have noticed recently that a number of posts show text with powers and > other symbols. For example, x^2+y^2==z^3 shows up with the nice > exponentials in the text rather than what I just showed. I am not sure > how this was copied, but I can't get it. Anyway, when I copy such things > into a notebook it comes out as x2+y2==z3, which makes it difficult to use. Is there a way to copy this stuff into a notebook so it does it > correctly? If not, then it would be nice if posters would Copy As Plain > Text. Does anyone else have this problem? I am using Thunderbird under WXP. Kevin There may be better ways to do this, but (at least using Thunderbird) you can select an option to view message source. This is a bit messy, but the above appears in the same form as Mathematica InputForm - with circumflex characters - so this will copy and paste as required. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Bug with LaplaceTransform? yes, I think so. Expanding Exp[-x s] in a Taylor Series around 0 it is clear that the integral divergeces there. hope this helps, Daniel > The Laplace Transform integral seems not to converge for any s for the function f(x)=1/x but LaplaceTransform returns -EulerGamma-Log(s) for this function: > LaplaceTransform[1/x, x, s] > Integrate[1/(x*Exp[s*x]), {x, 0, Infinity}] Is this a bug? > === Subject: Contour Lines How do you extract the coordinates of points making up a Contour Line as a List? This has been dealt with before in the archive (see e.g., ) but the code there seems no longer to work. For example, the following is suggested f[x_, y_] := x^2 + 2y^2 plot1 = ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, Contours -> {1}, ContourShading -> False, PlotPoints -> {30, 30}]; f[x_, y_] := x^2 + 2y^2 plot1 = ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, Contours -> {1}, ContourShading -> False, PlotPoints -> {30, 30}]; Convert the ContourGraphics to Graphics and then extract the first part and you will see how Mathematica represents the contours. contour = First@Graphics@plot1 (output omitted) I can see that the data I want (the actual coordinates) is there, but I can't figure how to extract it as a matrix or list. === Subject: Re: Mathematica v5 versus v6 As yet I have not managed to solve this problem concerned with computing the rank of an 8 by 8 matrix. Some people have asked for a specific example. The matrix which I am having a problem with is not a simple matrix, each element of the matrix is an analytic function and not a simple numerical element. As a result I cannot simply post the matrix here. If you are interested then you can simply reply to my post and I shall email a notebook file containing the matrix to you. The problem I find is that, a matrix which takes a few minutes to have it's rank computed in v5.1 or 5.2 causes v6 to run for 10 times as long without giving an answer. Any help, particularly from people running v6 on 64 bit machines would be very welcome. jon === Subject: Re: How can I find roots in Mathematica 6? soln = Reduce[{Cosh[z] == I, Abs[Im[z]] < 10}, z] z == -2*I*Pi - ArcCosh[I] || z == 2*I*Pi - ArcCosh[I] || z == -ArcCosh[I] || z == ArcCosh[I] || z == -2*I*Pi + ArcCosh[I] || z == 2*I*Pi + ArcCosh[I] soln // N z == -0.8813735870195429 - 7.853981633974483*I || z == -0.8813735870195429 + 4.71238898038469*I || z == -0.8813735870195429 - 1.5707963267948966*I || z == 0.8813735870195429 + 1.5707963267948966*I || z == 0.8813735870195429 - 4.71238898038469*I || z == 0.8813735870195429 + 7.853981633974483*I Cosh[Last /@ List @@ soln] {I, I, I, I, I, I} Bob Hanlon > Does anyone know what should I type in in order to find the roots of cosh(z)=i with Abs[Im[z]]<10 ? === Subject: Mathematica fonts Is there a way to improve the appearance of text on screen in Mathematica? In particular, default fonts seem somewhat jaggy. For instance, here's an example of snippet (125% zoom) in Mathematica and comparable resolution rendered with Latex http://yaroslavvb.com/share/mathematica-latex.PNG === Subject: Re: express a quadratic, in the form (x+a)^2 + b f[quad_, var_: x] := Module[{a, b}, (var + a)^2 + b /. Solve[CoefficientList[#, var] & /@ (quad == (var + a)^2 + b), {a, b}][[1]]] f[x^2 + 4 x + 7] (x + 2)^2 + 3 f[y^2 + 6 y + 7, y] (y + 3)^2 - 2 Bob Hanlon > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: FindRoot / Jacobian code and get rid of the complex values (which was expected since I used complex starting points in FindRoot before). Do you know how I can increase the precision in FindRoot, without increasing the computing time dramatically? If you plot p/.solutions and q/.solutions, respectively, using e.g. the ListSurfacePlot3D command, you see some peaks. Ideally those peaks should not be there. Do you have any clever suggestion on how to get rid of those peaks? Sigmund Vestergaard Kongens Lyngby, Denmark On Dec 18, 11:37 am, Steve Luttrell > Here is how you can solve your problem: solU=(E^((-I)*p-(2*ArcTan[Tan[q/2]/Sqrt[3]])/Sqrt[3])*(1+E^((2*I)*p)))/2 > solV=Sin[p]/E^((2*ArcTan[Tan[q/2]/Sqrt[3]])/Sqrt[3]) solutions=Table[FindRoot[solU==N[u]&&solV==N[v],{{p,0},{q,0}}],{u,-[Pi],[ Pi],(2[Pi])/70},{v,-[Pi],[Pi],(2[Pi])/70}]; You can do a quick visualisation of the solutions with the following > graphics: Graphics[{Map[Point,#,{2}],Map[Line,#],Map[Line,Transpose[#]]}&[{p,q}/.soluti ons//Chop]] Stephen Luttrell > West Malvern, UK > Consider the following expressions: solU = (E^((-I)*p - (2*ArcTan[Tan[q/2]/Sqrt[3]])/Sqrt[3])*(1 + > E^((2*I)*p)))/2 solV = Sin[p]/E^((2*ArcTan[Tan[q/2]/Sqrt[3]])/Sqrt[3]) I then want to solve the system of equations (u = solU, v = solV) > numerically on a grid (u,v) in (-pi,pi). For that purpose I use > FindRoot, and execute the following: u1 = Pi; du = 2*Pi/70; uvPts1 = Flatten[Table[{u, v}, {u, u1 + du, u2 - du, du}, {v, v1 + > du, > v2 - du, dv}], 1]; uvNew = {p, q} /. Table[FindRoot[{solU == uvPts1[[i, 1]], solV == > uvPts1[[i, 2]]}, {p, > -2}, {q, 1+I}], {i, Length[uvPts1]}]; This gives me a p-value and a q-value for each point on the grid, no > problem. However, I get the wrong solution at some of the grid points. > Since I get several of the following type of messages, this would be > expected: FindRoot::jsing:Encountered a singular Jacobian at the point {p,q} = > {-10.4516+0.784848 [ImaginaryI],108.092+104.013 [ImaginaryI]}. Try > perturbing the initial point(s). Then I would like to know if there is any 'nice' way to handle these > 'singular Jacobian' errors? Does there exist any kind of 'event > handler', as in NDSolve? Sigmund Vestergaard === Subject: Re: Problem with labeling contour Lines I am having problem with labeling of the contour lines using the following code: ClearAll[Global`*] Needs[ExtendGraphics`LabelContour`] DelTau=3 10^(-3) mAngle=50; SigmaG=0.262 g[K_]:=2*Sum[ I^(-n)*(Re[Exp[-(n^2) (SigmaG^2)]*Exp[I*n*(-mAngle)]])* BesselJ[n,2 Pi K],{n,1,250}] h[K_]:=BesselJ[0,2 Pi K] hOmega[deltaOmega_]:=1/(1+4 Pi^2 deltaOmega^2 DelTau^2) c=ContourPlot[(Abs[h[K]+g[K]]^2)*hOmega[deltaOmega],{K,0,8},{deltaOmega,0,17 5}, Contours->8,ContourShading->None,PlotRange->All] LabelContourLines[c] When i execute LabelContourLines[c], i receive the following list of messages (*the description is excluded*) and the contour plot is returned without labels: First::normal , Part::pspec , Last::normal , NumberForm::sigz, Part::partw, Append::normal, Graphics::gprim In the same notebook, when i run the following example, the command LabelContourLines[c1] works absolutely fine: c1=ContourPlot[x y,{x,-4,4},{y,-4,4},ContourShading->False, Contours->8] LabelContourLines[c1] Can somebody please help me resolve this problem? Rauf Iqbal PhD Student Australian National Universitry, Canberra, Australia === Subject: Re: Plot without a graph Suppose I want the table of values that Mathematica uses to plot the > graph but I don't want the graph plotted. I knew how to do it once, a > long time ago, but I have forgotten the scheme. Something like > Display->Identity? Sorry to trouble you guys with this trivia but I could not find the > method by searching the options for plot. By the way, I do know how to > get the table! > if $VersionNumber < 6: Block[{$DisplayFunction=Identity}, ] else: ; (that is: just append a semicolon to suppress output for version 6) hth, albert === Subject: Re: Plot without a graph here is an example. Make a plot: g=Plot[Sin[x],{x,0,1}] Now g[[1]] contains the data points in the form as you can see by: You may extract the data points e.g. by: Cases[g,Line[x__]:>x,4][[1]] hope this helps, Daniel Suppose I want the table of values that Mathematica uses to plot the > graph but I don't want the graph plotted. I knew how to do it once, a > long time ago, but I have forgotten the scheme. Something like > Display->Identity? Sorry to trouble you guys with this trivia but I could not find the > method by searching the options for plot. By the way, I do know how to > get the table! > === Subject: Re: Button Question > The cell, pasted below, is in my notebook. When the cell is evaluated, > It prints a button, labeled simulate, but clicking on the button does > not print the six simulated integers that RandomInteger computed. The error message says that the list of probabilities, entered as > shown below, is not a probability distribution recognized by the > system, but {1/6,1/6,1/6,1/6,1/6,1/6} is a valid multinomial > distribution. ButtonEvaluator, not mispelled, is printed in red. The color red must > be an indication of an error of some kind, but I have no idea what it > is. Cell[ButtonBox[Simulate, Active -> True, > ButtonFunction - Print[RandomInteger[ > MultinomialDistribution[ > 100, {1, /, 6, 1, /, 6, 1, /, 6, 1, /, > 6, 1, /, 6, 1, /, 6}], 1]], > ButtonEvaluator -> Automatic] // DisplayForm, Output], since you use RandomInteger I guess you are using version 6. Then there is no need to struggle with ButtonBox for this. This works for me: Needs[MultivariateStatistics`] Button[Simulate, Print[RandomInteger[MultinomialDistribution[100,{1/6,1/6,1/6,1/6,1/6,1/6}],1 ]] ] hth, albert === Subject: RE: Button Question John, It works perfectly well if you paste the following in Mathematica 6.0 (choose to interpret the text!) Cell[ButtonBox[Simulate, Active -> True, ButtonFunction -> (Needs[MultivariateStatistics`]; Print[RandomInteger[ MultivariateStatistics`MultinomialDistribution[ 100, {1/6,1/6,1/6,1/6,1/6,1/6}], 1]]), ButtonEvaluator -> Automatic] // DisplayForm, Output] Thus avoid the quotes around 1/6. The arrow with colon (RuleDelayed) is generated by :> . I do not think it is needed here. You could also try to execute the following code Button[Simulate, Needs[MultivariateStatistics`]; Print[RandomInteger[ MultivariateStatistics`MultinomialDistribution[ 100, {1/6,1/6,1/6,1/6,1/6,1/6}], 1]]] (The printed line is then overwritten each time the button is pressed) Ingolf Dahl -----Original Message----- === Subject: Button Question The cell, pasted below, is in my notebook. When the cell is evaluated, It prints a button, labeled simulate, but clicking on the button does not print the six simulated integers that RandomInteger computed. The error message says that the list of probabilities, entered as shown below, is not a probability distribution recognized by the system, but {1/6,1/6,1/6,1/6,1/6,1/6} is a valid multinomial distribution. ButtonEvaluator, not mispelled, is printed in red. The color red must be an indication of an error of some kind, but I have no idea what it is. Cell[ButtonBox[Simulate, Active -> True, ButtonFunction -> Print[RandomInteger[ MultinomialDistribution[ 100, {1, /, 6, 1, /, 6, 1, /, 6, 1, /, 6, 1, /, 6, 1, /, 6}], 1]], ButtonEvaluator -> Automatic] // DisplayForm, Output], In one example, I saw, the arrow between ButtonFunction and Print is short and preceded by a colon. If if that notation is necessary, I don't know how to do it. Helpful advice will be appreciated . John === Subject: Re: Button Question Hi John, you entered the probabilities as strings not as numbers. hope this helps, Daniel > The cell, pasted below, is in my notebook. When the cell is evaluated, > It prints a button, labeled simulate, but clicking on the button does > not print the six simulated integers that RandomInteger computed. The error message says that the list of probabilities, entered as > shown below, is not a probability distribution recognized by the > system, but {1/6,1/6,1/6,1/6,1/6,1/6} is a valid multinomial > distribution. ButtonEvaluator, not mispelled, is printed in red. The color red must > be an indication of an error of some kind, but I have no idea what it > is. Cell[ButtonBox[Simulate, Active -> True, > ButtonFunction - Print[RandomInteger[ > MultinomialDistribution[ > 100, {1, /, 6, 1, /, 6, 1, /, 6, 1, /, > 6, 1, /, 6, 1, /, 6}], 1]], > ButtonEvaluator -> Automatic] // DisplayForm, Output], In one example, I saw, the arrow between ButtonFunction and Print is > short and preceded by a colon. If if that notation is necessary, I > don't know how to do it. Helpful advice will be appreciated . John === Subject: Re: Updating NumberPadding? > Carl, If you raise Pi to zero or a negative power of ten, your last form below > does not work correctly, i.e. N[Pi]10^-1 produces 0.31x10. I agree with David that it would be REALLY nice if WRI made it easier > for us to produce nice columnar data. I know it is not easy, as the > examples below show. I know from my FORTRAN days that a lot of CPU > cycles were used on formatted input and output. Still, it would be nice. Isn't this better addressed with using Grid and an explicit setting for Alignment? The following gives me something that looks good enough for me: Style[ Grid[{ {NumberForm[1000*N@Pi, {5, 2}]}, {NumberForm[N@Pi, {5, 2}]}, {NumberForm[N[Pi] 10^-1, {5, 2}]} }, Alignment -> {.} ], FontFamily -> Helvetica ] albert === Subject: Re: Problem with Out keeping the camera view direction try {vp, vc, vv} = OptionValue[Plot3D, #] & /@ {ViewPoint, ViewCenter, ViewVertical}; Plot3D[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, MeshShading -> {{Yellow, Orange}, {Pink, Red}}, Mesh -> 10, Evaluate[ Sequence @@ Thread[{ViewPoint, ViewCenter, ViewVertical} -> {Dynamic[vp], Dynamic[vc], Dynamic[vv]}] ], MaxRecursion -> 2, WorkingPrecision -> 20, PlotPoints -> {100, 100}, Boxed -> False, Background -> Black] to save the camera position and orientation in vp,vc,vv and use the values when you save the graphics. Jens > Ok let' say we run this command Plot3D[Sqrt[1 - x^2 - y^2], {x, -1, 1}, {y, -1, 1}, > MeshShading -> {{Yellow, Orange}, {Pink, Red}}, Mesh -> 10, > MaxRecursion -> 2, WorkingPrecision -> 20, PlotPoints -> {100, 100}, > Boxed -> False, Background -> Black] that produces a nice semi sphere now use the Mouse cursor to rotate the semisphere to a different > position. or Alt to zoom in or out etc > and then use Rasterize[Out[3]] > assuming the Out[3] is the output from the above Plot3D command shouldn't Rasterize of the Out[3] keep the same camera view port > coordinates? How can I get the view port coordinates from the Out[3] so that I can > place that directly on my Plot3D then? > === Subject: RE: It's certainly true that they are not the same, though IN PRINCIPLE the results are the same. Try, for example, s1 = LinearSolve[Array[a, {3, 3}], Array[b, 3]] s2 = LinearSolve[Array[a, {3, 3}]][Array[b, 3]] s1 - s2 // Simplify Your matrix m is badly conditioned, which may be where the problem arises. Incidentally, why did Wolfram think it was a good idea to remove MatrixConditionNumber from the standard add-on packages? I'm happy with the idea that things from the add-ons get 'promoted' to the standard system, but I've always regarded the standard add-ons as something I could rely on being there. Seeing some of their content whisked away to a web address seems to be a step backwards. And the only way I found this out was to fire up 5.2 with its vastly superior help file to remind me of the precise name of the function, then go back to 6.1 to find out where it had gone. Tony Harker Dr A.H. Harker Department of Physics and Astronomy University College London Gower Street London WC1E 6BT Tel: (44)(0) 2076793404 E: a.harker@ucl.ac.uk ]-> -----Original Message----- === ]-> Subject: is not equivalent to ]-> LinearSolve[m][b] ]-> ]-> At the bottom of this message I define a machine-precision ]-> matrix m and a machine precision vector b. (I apologise for ]-> their large size.) ]-> ]-> ]-> 1. LinearSolve[m, b] is not equivalent to LinearSolve[m][b]. ]-> ]-> The documentation for LinearSolve states that ]-> LinearSolve[m,b] is equivalent to LinearSolve[m][b]. For ]-> m and b, however: ]-> ]-> sol1 = LinearSolve[m, b] ]->> ]-> {-1.68129*10^9,-7.29642*10^11,-6.31285*10^20,4.99506*10^22,3 ]-> .84561*10^24,-1. ]-> 3535*10^26,-7.82045*10^25,1.69903*10^27,2.25713*10^25,-2.492 ]-> 72*10^26,-1.0616 ]-> *10^26,9.03507*10^26,-4.77786*10^24,2.87158*10^25,4.55334*10 ]-> ^25,-2.43647*10^ ]-> 26,-2.82578*10^26,1.27101*10^27,-1.38448*10^28,5.52681*10^30} ]-> ]-> sol2 = LinearSolve[m][b] ]->> ]-> {-1.8893*10^-6,0.00627488,-0.000025753,-0.00767333,0.0000624 ]-> 517,-0.000027213 ]-> 7,-0.0000464774,0.00188393,7.51337*10^-6,-0.0000585884,6.018 ]-> 09*10^-6,-0.0004 ]-> 30135,-6.4536*10^-7,-0.0000946245,-1.29985*10^-6,0.000070139 ]-> 2,-4.03265*10^-7 ]-> ,0.0000499027,4.97681*10^-7,9.8366*10^-6} ]-> ]-> Needless to say, sol2 is the one that approximately solves ]-> m.x==b. Type ]-> (m.sol1 - b) and (m.sol2 - b) to see this. sol1 is wild. ]-> ]-> ]-> 2. When using arbitrary precision arithmetic instead of ]-> machine precision arithmetic, the wild behaviour does not occur. ]-> ]-> Here are m and b at precision $MachinePrecision (i.e., 15.9546): ]-> mm = SetPrecision[m, $MachinePrecision]; bb = ]-> SetPrecision[b, $MachinePrecision]; ]-> ]-> For these definitions, LinearSolve[mm,bb] and ]-> LinearSolve[mm][bb] *are* approximately equal, and they are ]-> approximately equal to sol2 (the tame solution). ]-> ]-> ]-> Can anyone shed some light on this topic? My working ]-> hypothesis is that 1. ]-> sol1 is the result of a bug (or inconsistent/bad handling ]-> of poorly conditioned matrices); and 2. that bug isn't ]-> present in the arbitrary precision version of LinearSolve. ]-> Then the workaround would be: don't use LinearSolve[m, b]; ]-> instead use LinearSolve[m][b]. ]-> ]-> ]-> Andrew Moylan ]-> ]-> ]-> Here are the definitions of m and b: ]-> ]-> m={{0.,120.,4.,-120.,-16.,120.,36.,-120.,-64.,120.,100.,-120 ]-> .,-144.,120.,196 ]-> .,-120.,-256.,120.,324.,-120.},{-120.,0.,120.,4.,-120.,-16., ]-> 120.,36.,-120.,- ]-> 64.,120.,100.,-120.,-144.,120.,196.,-120.,-256.,120.,324.},{ ]-> 0.,137.667770123 ]-> 3155,4.,-126.52361302070159,-14.704805681953697,94.895372832 ]-> 69993,28.5433706 ]-> 01,45.5838278268 ]-> 89575,60.48297480676686,-39.728436874545594,-104.33013932096 ]-> 895,21.378320417 ]-> 681632,131.28632837898377,8.062099516267708,-136.98735411779 ]-> 6,-44.1577316683 ]-> 6576,120.51022451941246},{-137.6677701233155,0.,126.52361302 ]-> 070159,4.,-94.89 ]-> 537283269993,-14.704805681953697,47.90363918197348,28.543370 ]-> 962903201,-40.5445084603741,-60.48297480676686,45.5838278268 ]-> 89575,104.330139 ]-> 32096895,-39.728436874545594,-131.28632837898377,21.37832041 ]-> 7681632,136.9873 ]-> 54117796,8.062099516267708,-120.51022451941246,-44.157731668 ]-> 36576},{0.,190.5 ]-> 9730297009568,4.,-140.79278017868444,-11.819078485136764,17. ]-> 407811913964213, ]-> 14.191990544591762,115.0747432704792,-4.317884714201286,-187 ]-> .4174897103089,- ]-> 15.679345960738772,161.81300927620237,34.27414014713948,-51. ]-> 64259235864097,- ]-> 37.12435871470173,-85.51702774336465,16.98339066468509,177.9 ]-> 8415019794658,19 ]-> .503939521116326,-177.43405229412292},{-190.59730297009568,0 ]-> .,140.7927801786 ]-> 8444,4.,-17.407811913964213,-11.819078485136764,-115.0747432 ]-> 704792,14.191990 ]-> 544591762,187.4174897103089,-4.317884714201286,-161.81300927 ]-> 620237,-15.67934 ]-> 5960738772,51.64259235864097,34.27414014713948,85.5170277433 ]-> 6465,-37.1243587 ]-> 1470173,-177.98415019794658,16.98339066468509,177.4340522941 ]-> 2292,19.50393952 ]-> 1116326},{0.,322.872632447701,4.,-154.48510511279565,-7.6555 ]-> 31727995272,-175 ]-> .03942948598953,-1.0111563678108242,321.98759337281865,16.60 ]-> 122006528058,-13 ]-> 3.08385014981712,-18.17273422029246,-194.634138709607,-4.033 ]-> 538586739716,319 ]-> .3373281801208,29.944998291495985,-110.95299226741214,-27.37 ]-> 121776748681,-21 ]-> 3.1618091027223,-9.033977175382377,314.93636636525736},{-322 ]-> .872632447701,0. ]-> ,154.48510511279565,4.,175.03942948598953,-7.655531727995272 ]-> ,-321.9875933728 ]-> 1865,-1.0111563678108242,133.08385014981712,16.6012200652805 ]-> 8,194.6341387096 ]-> 07,-18.17273422029246,-319.3373281801208,-4.033538586739716, ]-> 110.952992267412 ]-> 14,29.944998291495985,213.1618091027223,-27.37121776748681,- ]-> 314.936366365257 ]-> 36,-9.033977175382377},{0.,688.6670919150857,4.,-114.7211902 ]-> 4973249,-2.66535 ]-> 03057498296,-650.4455719765721,-10.667982702682368,331.42935 ]-> 32674049,10.0696 ]-> 8577122105,540.0236559683539,13.586339913460915,-511.3483803 ]-> 35829,-20.536381 ]-> 943186196,-369.6583357342561,-11.038447478035566,634.5070001 ]-> 073631,31.584889 ]-> 64242715,158.26040739218521,2.3538027804037114,-687.23442826 ]-> 12197},{-688.667 ]-> 0919150857,0.,114.72119024973249,4.,650.4455719765721,-2.665 ]-> 3503057498296,-3 ]-> 31.4293532674049,-10.667982702682368,-540.0236559683539,10.0 ]-> 6968577122105,51 ]-> 1.348380335829,13.586339913460915,369.6583357342561,-20.5363 ]-> 81943186196,-634 ]-> .5070001073631,-11.038447478035566,-158.26040739218521,31.58 ]-> 488964242715,687 ]-> .2344282612197,2.3538027804037114},{0.,1955.742698127284,4., ]-> 319.116359538738 ]-> 95,2.610702193856547,-1851.6029756343717,-10.722043885311114 ]-> ,-923.3643533687 ]-> 346,-9.886748303381077,1550.2743077507857,13.837048847537616 ]-> ,1429.2774204092 ]-> 866,20.248784522486616,-1083.847095614267,-11.66260123591745 ]-> 1,-1782.97766919 ]-> 99382,-31.348033453698886,501.9941315420778,3.48596962079657 ]-> 45,1946.79731676 ]-> 494},{-1955.742698127284,0.,-319.11635953873895,4.,1851.6029 ]-> 756343717,2.6107 ]-> 02193856547,923.3643533687346,-10.722043885311114,-1550.2743 ]-> 077507857,-9.886 ]-> 748303381077,-1429.2774204092866,13.837048847537616,1083.847 ]-> 095614267,20.248 ]-> 784522486616,1782.9776691999382,-11.662601235917451,-501.994 ]-> 1315420778,-31.3 ]-> 48033453698886,-1946.79731676494,3.4859696207965745},{0.,826 ]-> 7.868082849189,4 ]-> .,3927.69394068881,7.6008836161019895,-4536.125017493609,-1. ]-> 1674815477135652 ]-> ,-8237.513731446,-16.680749126890216,-3290.4228773517743,-17 ]-> .86489003655355, ]-> 5111.248564132217,4.652781192989794,8146.673560968948,30.168 ]-> 278100627578,262 ]-> 8.9911352802987,26.554230419975788,-5648.841605090274,-10.40 ]-> 4652778807701,-7 ]-> 996.014586041039},{-8267.868082849189,0.,-3927.69394068881,4 ]-> .,4536.125017493 ]-> 609,7.6008836161019895,8237.513731446,-1.1674815477135652,32 ]-> 90.4228773517743 ]-> ,-16.680749126890216,-5111.248564132217,-17.86489003655355,- ]-> 8146.67356096894 ]-> 8,4.652781192989794,-2628.9911352802987,30.168278100627578,5 ]-> 648.841605090274 ]-> ,26.554230419975788,7996.014586041039,-10.404652778807701},{ ]-> 0.,66714.5128785 ]-> 9093,4.,49053.640102814905,11.764430373243481,5421.503814372 ]-> 8425,13.95034162 ]-> 6292579,-41081.027085007,3.8241097110929165,-65833.364164734 ]-> 65,-16.221120559 ]-> 06104,-55730.47653404341,-34.361001075598665,-16121.29969181 ]-> 952,-36.24174857 ]-> 068484,32023.238065218116,-15.09440727983296,63213.194009826 ]-> 875,21.624753701 ]-> 270276,60935.1643846494},{-66714.51287859093,0.,-49053.64010 ]-> 2814905,4.,-5421 ]-> .5038143728425,11.764430373243481,41081.027085007,13.9503416 ]-> 26292579,65833.3 ]-> 6416473465,3.8241097110929165,55730.47653404341,-16.22112055 ]-> 906104,16121.299 ]-> 69181952,-34.361001075598665,-32023.238065218116,-36.2417485 ]-> 7068484,-63213.1 ]-> 94009826875,-15.09440727983296,-60935.1643846494,21.62475370 ]-> 1270276},{0.,2.1 ]-> 09193656453301*^6,4.,1.931251213300796*^6,14.650157570060415 ]-> ,1.4274481663250 ]-> 76*^6,28.242584405174718,682791.3566687256,39.65940348013593 ]-> 6,-177073.045991 ]-> 05718,43.712855697405764,-1.0070598598161684*^6,36.570928350 ]-> 44224,-1.6671251 ]-> 576076704*^6,16.935107017831488,-2.0458959211793535*^6,-13.3 ]-> 18096903865762,- ]-> 2.0794620445450086*^6,-49.21136470378096,-1.7621599055136922 ]-> *^6},{-2.1091936 ]-> 56453301*^6,0.,-1.931251213300796*^6,4.,-1.427448166325076*^ ]-> 6,14.65015757006 ]-> 0415,-682791.3566687256,28.242584405174718,177073.0459910571 ]-> 8,39.65940348013 ]-> 5936,1.0070598598161684*^6,43.712855697405764,1.667125157607 ]-> 6704*^6,36.57092 ]-> 835044224,2.0458959211793535*^6,16.935107017831488,2.0794620 ]-> 445450086*^6,-13 ]-> .318096903865762,1.7621599055136922*^6,-49.21136470378096},{ ]-> 0.,3.21113804748 ]-> 0835*^10,4.,3.2001703830231155*^10,15.945351888106718,3.1673 ]-> 423099192696*^10 ]-> ,35.67267128166534,3.1128780771958237*^10,62.91151228627201, ]-> 3.03714973078828 ]-> 5*^10,97.28714180413428,2.94067457209015*^10,138.32438810885 ]-> 077,2.8241116242 ]-> 59851*^10,185.4525285933514,2.6882571304243427*^10,238.01117 ]-> 208726953,2.5340 ]-> .211138047480835 ]-> *^10,0.,-3.2001703830231155*^10,4.,-3.1673423099192696*^10,1 ]-> 5.94535188810671 ]-> 8,-3.1128780771958237*^10,35.67267128166534,-3.0371497307882 ]-> 85*^10,62.911512 ]-> 28627201,-2.94067457209015*^10,97.28714180413428,-2.82411162 ]-> 4259851*^10,138. ]-> 32438810885077,-2.6882571304243427*^10,185.4525285933514,-2. ]-> 534039114531167* ]-> ]-> b={1.4715177646857693,0.,1.7272858774111686,0.,2.43844948323 ]-> 59858,0.,3.86819 ]-> 71196755,0.,6.1130185623361015,0.,7.4508820294899945,0.,3.39 ]-> 3321220405215,0. ]-> ,0.03385691675272283,0.,3.3743307736651725*^-14,0.,1.2388511 ]-> 2322841128107475 ]-> 3`10.061735978331926*^-496,0.}; ]-> ]-> ]-> === Subject: RE: Show changes in a function dynamically within a Manipulate Take a look at the code of my Molecular Dynamics demonstration in the Wolfram Demonstrations Project, here is the link: ingTheVelocityVerl/ It might be give you some ideas for your animation (specially the central idea that I took from Jon McLoone ...Gas Pressure... Demonstration: Make a Manipulate[] of a Dynamic[]) Saludos del D.F.! Jose -----Mensaje original----- De: Sergio Miguel Terrazas Porras [mailto:sterraza@uacj.mx] Enviado el: Mi=E9rcoles, 19 de Diciembre de 2007 03:10 a.m. Para: mathgroup@smc.vnet.net Asunto: Show changes in a function dynamically within a Manipulate Hi guys! I have made an animation showing a block sliding up and then down an inclined plane, with Manipulate. The animation works fine, but I would like to show the changing values of the speed in the animation, and I do not know how. Your help will be very much appreciated. === Subject: RE: Timing and Pi On Windows Vista 64-bit (6.0 for Microsoft Windows (64-bit) (June 19, 2007)) I get : 2.14 s. Robert -----Original Message----- === Subject: Timing and Pi i wish to see other people results in running the code: Timing[N[Pi,1000000]] i am using mathematica 6 ,windowsXp i have tried the code on two machines: 1- celeron 2.6GHZ-256kb cash, memory DDR-512MB-400Mhz the timing result is 4.281 seconds 2- pentium D-925 dual processor 3GHZ-4MB cash , memory DDR2-2GB-667Mhz the timing is 3.218 seconds i am astonished that there is not much difference between the two = values, even the second machine are speedier in cpu frequency and have more cash = and the memory frequency. peter === Subject: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2] ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2] Evaluating this line in Mathematica 5.2 or Mathematica 6 returns 16. This makes sense, because the second definition replaces the first, as we can see when ?f returns: Global`f f[y_]:=y^4 But in _A_Physicist's_Guide_to_Mathematica_ on p.314, Patrick Tam shows an example like this returning the other answer, 4, defined in the first definition. He then demonstrates that ?f returns: Global`f f[x_] := x^2 f[y_]:= y^4 He says his book was developed with Mathematica 2.2 and a prerelease of Mathematica 3 and is compatible with both. He goes on to explain: Contrary to expectation, Mathematica used the first definition. The ? operator reveals that Mathematica stores both definitions in the global rule base, giving higher priority to the first definition. (This problem cannot, perhaps, be called a bug because developers of Mathematica are well aware of this design flaw, which is quite difficult to mend....) What is he talking about? Did Mathematica 2.2 and 3 treat this differently? If earlier versions worked in this surprising way, there must have been a reason - what was it? Was it changed to prevent surprises like this example? Did changing it create other unfortunate consequences? Was Tam just wrong? Or do I misunderstand? === Subject: Re: Re: Speeding Up Realtime Visualization Since I haven't mentioned this before, I'm trying to make a two species reaction diffusion simulator by approximating the associated PDE using finite difference integration. These 'rough' simulators, e.g. http://texturegarden.com/java/rd/index.html, are typically very fast. I'm going for something with this speed. In my code, I've compiled a function which performs the 'next-time-interval' finite difference calculation. Using the Timing function, I found this calculation takes essentially no time. Mathematica usually says 0. sec. However, when I perform this calculation across the entire 100x100 grid, i.e. ~99^2 calcuations, it takes 0.45 sec. I originally computed the entire grid using For loops, which required ~0.5-0.6 sec. Figuring that Mathematica doesn't like procedural programming, I tried implementing a Threading technique to apply the finite difference calculation across the grid, which takes 0.45. Of course, this is way to slow for a 'fast' simulator. Again, I can speed things up by lowering my grid size, or keeping the grid size and increasing the spatial interval in the integrator, but I'll be losing significant quality. I still think the sluggishness has something to do with the way I'm setting up my matrices, which are used to read/write during the finite difference calculation. I figure I'm forgetting something huge Ok, here's my code: Clear[Global`*]; N[ L=100; ds=1; length=L/ds; dt=0.5; a=0.082;(*u diffusion*) b=0.041;(*v diffusion*) f=0.035;(*u feed/rxn rate*) k=0.0625;(*v death rate*) dtf=dt f; dtfk=dt(f+k); e=a dt/(ds)^2; g=b dt/(ds)^2; uP=Table[1,{i,1,length},{j,1,length}];(*previous u state*) uC=Table[0,{i,1,length},{j,1,length}];(*current u state*) vP=Table[0,{i,1,length},{j,1,length}];(*previous v state*) vC=Table[0,{i,1,length},{j,1,length}];(*current v state*) c=2;p=1;(*for double buffer*) u={uP,uC};(*u[[1]] is previous, u[[2]] is current*) v={vP,vC};(*v[[1]] is previous, v[[2]] is current*) (*initial conditions, small square of altered conc values*) Do[u[[1,i,j]]=0.35,{i,0.4length,0.6length},{j,0.40length,0.6length}]; Do[v[[1,i,j]]= Sin[0.1i-0.5length]Cos[0.1j-0.5length]^2,{i,1,length},{j,1,length}]; ]; (*finite difference/rxn diffusion calculation*) Rxn=Compile[{{c,_Integer},{p,_Integer},{i,_Integer},{j,_Integer}}, u[[c,i,j]]=u[[p,i,j]](1-4*e-dt*(v[[p,i,j]])^2-dtf)+dtf+e*(u[[p,i+1,j]]+u[[p, i-1,j]]+u[[p,i,j+1]]+u[[p,i,j-1]])//N; v[[c,i,j]]=v[[p,i,j]](1-4*g+dt*u[[p,i,j]]*v[[p,i,j]])-dtfk+ g*(v[[p,i+1,j]]+v[[p,i-1,j]]+v[[p,i,j+1]]+v[[p,i,j-1]])//N; ]; (*Rxn Diffusion*) While[True, Outer[ Thread[Rxn[c,p,#1,#2]]&,Range[2,length-1],Range[2,length-1] ]; If[p==1,c=1;p=2,c=2;p=1] ; (*c/p inverter*) ugrid=u[[2]]; vgrid=v[[2]]; ] Then I Dynamically visualize either ugrid or vgrid using ArrayPlot or Graphics[Raster[]] , which seem take take the same time. Any ideas? === Subject: Collapsing animation output Is it possible to suppress the extra images or lock the cell so it won't expand? Having to scroll back up the screen every time is annoying. === Subject: Re: is it possible to solve Matrix Equations? > Hi Gilbert, LinearSolve can solve matrix equiations, but you have to fill the matrices and vectors: n=2; mat=Array[m,{n,n}] bvec=Array[b,{n}]; LinearSolve[mat,bvec] hope this helps, Daniel > I have two Matrix form equations, is it possible to solve them in > Mathematica? The equations seem like this: A1.x+B1.y=C1 > A2.x+B2.y=C2 I know LinearSolve can solve equation like m.x=b, but does not work > for equations. I have used FindRoot, since it surpport matrix in 6.0, > but answser seems to be not precise for it is hard to select an > initial values for x and y. > Gibert- Hide quoted text - - Show quoted text - === Subject: Re: pattern >I want to define a function that accepts only one argument - a 2x2 >matrix and not any more. >Is it possible? Yes. For example f[x_]:=Total[x]/;Dimensions[x]=={2,2} will return a list of two elements if x is a 2 x 2 matrix and will return f[x] unevaluated if x is not a 2 x 2 matrix. -- To reply via email subtract one hundred and four === Subject: Re: Plot without a graph >Suppose I want the table of values that Mathematica uses to plot the >graph but I don't want the graph plotted. I knew how to do it once, >a long time ago, but I have forgotten the scheme. Something like >Display->Identity? >Sorry to trouble you guys with this trivia but I could not find the >method by searching the options for plot. By the way, I do know how >to get the table! For Mathematica versions earlier than 6, you need to add the directive DisplayFunction->Identity or do something like Block[{$DisplayFunction=Identity},a=Plot[x,{x,0,1}]] For version 6 and later simply terminate your plot statement with a semicolon. -- To reply via email subtract one hundred and four === Subject: Re: alignment in TabView (v6) labels Hi Matt: Interestingly enough I just came upon just this need in a project that you thought of any other approaches? Maxim Rytin approach is certainly quite helpful. I find that the display of the TabView buttons on the LHS or RHS of the display is very crude. There is a much too very prominent drop shadow, and the curve of the upper and lower boundaries of the tab column is quite jagged. Also the text in the tabs will sometimes go beyond the boundary of the tab and be written into the drop shadow. Some of these problems are controllable using Maxim's approach. Another helpful Option to use is the ImageMargins Option to Pane. This helps to keep the text away from the edges of the tab boundary. David Reiss (in Arlington MA) Hi all, I am trying to use TabView, with my tabs on the left rather than on > top because my tab labels are long-ish strings. However, it looks like > TabView automatically centers the tab label on the tab, which does not > look as good when the tabs are on a side. I'd like to align my tab > labels on the left, but I don't see an easy way to do that. There may > not be one. Any ideas? > Matt Enlow > Newton, MA If you don't mind specifying explicit label sizes, you can use Pane: TabView[ > Pane[#[[1]], {45, Automatic}, Alignment -> {Left, Center}] - #[[2]]& /@ > {1 -> 1, xxxxxxx -> xxxxxxx, 3 -> 3}, > ControlPlacement -> Left] Maxim Rytin > m...@inbox.ru === Subject: Problem with labeling Contour Lines I am trying to label the lines in the following contour plot: The following messages appear when i execute LabelContourLines[c] command: At the end of the messages, the same contour plot returns without any labeling of contour lines. Importantly, in the same notebbook, i am able to label the contour lines using the same LabelContourLines[c] command in the follwoing example: Can somebody help me resolve this problem, please Rauf Iqbal === Subject: Re: FileNameSetter button return state Yes, I can see how to do it the way that you suggest. In my original posting I was wondering whether it was possible to do it with FileNameSetter[Dynamic[filename, {fstart,f,fend}], Save, Appearance -> Save File...] but it didn't work. I had hoped that I could use the function fend to catch the exit from the File Save dialog and then take appropriate action. It would be quite neat if you could do everything (i.e. pick a file name, then take whatever immediate action is needed based on the mode of exit from the file dialog) within a single function call. Stephen Luttrell West Malvern, UK >> Suppose that the file selection dialog starts up with a valid filename >> (e.g. >> the filename that you had used on a previous use of this dialog), but >> then >> you decide to press the Cancel button, how would you tell that it was >> Cancel rather than OK that you had just pressed? I don't know how to do this with FileNameSelector, but it can be > achieved with a combination of Button and SystemDialog[FileSave] or > SystemDialog[FileOpen]. I have done this and found it pretty straight forward, so if you need > more information I could try to find the code snippet, but probably you > are faster rewriting it your way. The only pitfall I can remember is > that you need to use Method -> Queued for the Button, otherwise the > preemptive link is likely to time out... hth, albert > === Subject: Re: FileNameSetter button return state How fiendishly cunning! I'll add that to my list of tricks. Stephen Luttrell West Malvern, UK > Hi Steve, here is a dirty trick: Append a space to your file name. If on return the space is still there, Cancel was chosen. Otherwise the space is gone. hope this helps, Daniel >> I want to use FileNameSetter to create a button which behaves in the > expected way for implementing a Save As... functionality. >> So I did this >> FileNameSetter[Dynamic[filename], Save, Appearance -> Save File...] >> This is fine, except that I can't find any way to determine whether the >> OK > or Cancel button is used to exit the file dialog box. It is not >> sufficient > to determine if the value of filename changes, because if you leave >> filename > unchanged and use the OK button to exit the dialog then this appears to >> be > indistinguishable from using the Cancel button. >> I can't find anything in the documentation about how to do this. I tried >> to > use the {fstart,f,fend} functionality of Dynamic, but this caused > FileNameSetter to break. >> Stephen Luttrell > West Malvern, UK > === Subject: Re: FileNameSetter button return state On Dec 17, 12:44 am, Steve Luttrell > I want to use FileNameSetter to create a button which behaves in the > expected way for implementing a Save As... functionality. So I did this FileNameSetter[Dynamic[filename], Save, Appearance -> Save File...] This is fine, except that I can't find any way to determine whether the OK > or Cancel button is used to exit the file dialog box. It is not sufficient > to determine if the value of filename changes, because if you leave filename > unchanged and use the OK button to exit the dialog then this appears to be > indistinguishable from using the Cancel button. Try this instead: Button[Save File[Ellipsis], filename := SystemDialogInput[FileSave], Method -> Queued] -Rob === Subject: Re: pattern This is an example: f[x : {{_?NumericQ, _?NumericQ}, {_?NumericQ, _?NumericQ}}] := x The pattern object {{_?NumericQ, _?NumericQ}, {_?NumericQ, _?NumericQ}} matches a numerical 2x2 matrix, and the x: preceding it is the name that I have assigned to this pattern object for use inside the function definition. If you want to match other types of matrix element then change the tests as necessary. Stephen Luttrell West Malvern, UK >I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang === Subject: Re: pattern consider: f[x_/;Dimensions[x]=={2,2}]:= ... hope this helps, Daniel > I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang === Subject: Re: pattern > I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang Adriano Pascoletti === Subject: Re: pattern IWantToDefineAFunctionThatAcceptsOnlyOneArgument[matrix:{{_,_},{_,_}}]:= ... Jens > I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang === Subject: Re: pattern Here is an example using a general pattern specification that also includes a default value for the matrix: matfunc[mat : {{_, _}, {_, _}} : {{1, 2}, {3, 4}}] := mat + mat.mat mat is the name of the pattern. {{_, _}, {_, _}} is the pattern {{1, 2}, {3, 4}} is the default value and these are all separated by colons. If you don't want a default value leave off the last colon and matrix. It now accepts a 2x2 matrix. matfunc[{{.5, -1}, {.33, 4.5}}] {{0.42, -6.}, {1.98, 24.42}} It does not accept any nonmatching argument. matfunc[3] matfunc[3] And with no argument it uses the default value. matfunc[] {{8, 12}, {18, 26}} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang === Subject: Re: pattern > I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang f[m:{{_,_},{_,_}}]:=(your code goes here) for other cases more general patterns can be constructed with MatrixQ and Dimensions. Probably you want to also check for the entries to be numbers with NumericQ. hth, albert === Subject: Re: Re: pattern f[x_?MatrixQ] := Det[x] /; Dimensions[x] == {2, 2}; Bob Hanlon > I want to define a function that accepts only one argument - a 2x2 > matrix and not any more. Is it possible? orelang === Subject: Re: express a quadratic, in the form (x+a)^2 + b Hi Joseph, I am assuming you want the values of a anb b and not the procedure how to do it manually in Mathematica. You may e.g. say: Reduce[{ForAll[x, x^2+4x+7==(x+a)^2+b]},{a,b}] hope this helps, Daniel > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: express a quadratic, in the form (x+a)^2 + b > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe Another solution for quadratic polys poly = x^2 + 4 x + 7; tempPoly = PolynomialRemainder[poly, (x + a)^2, x]; temp = Flatten[Solve[D[tempPoly, x] == 0]]; ind = PolynomialRemainder[poly, (x + a)^2, x] /. temp; (x + a)^2 + ind /. temp === Subject: Re: express a quadratic, in the form (x+a)^2 + b ClearAll[quad] quad[{c_, b_, a_}] := a (x + b/(2 a))^2 + c - b^2/(4 a) quad[poly_, x_Symbol] /; PolynomialQ[poly, x] := quad@CoefficientList[poly, x] quad[x^2 + 4 x + 7, x] 3 + (2 + x)^2 Bobby > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe -- DrMajorBob@bigfoot.com === Subject: Re: express a quadratic, in the form (x+a)^2 + b > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe Take the Taylor expansion near the coefficient of x divided by 2: (Normal[Series[#1, {x, -Coefficient[#1, x, 1]/2, 2}]] & )[x^2 + 4*x + 7] gives 3 + (2 + x)^2. Adriano Pascoletti === Subject: Re: express a quadratic, in the form (x+a)^2 + b Joe, The following is a step by step derivation of the 'complete the square' process. Copy the entire statement from the posting and paste into a notebook and then evaluate. I think you will find the steps straightforward, but as a beginner you will probably find the Mathematica implementation of the steps somewhat difficult. Nevertheless this does show how you can carry out derivations with Mathematica and let it do all of the calculation. You don't have to do anything 'by hand' on the side. I used a pure function, # - Part[%%, 2] &, with Map, /@, to move the right hand side of the equation to the left. Pure functions (Function in Help) are extremely useful in manipulating expressions. I didn't actually have to do the step where the terms were collected but I included it because it clarifies the derivation. You should look up the various commands (Part, Function, Map, MapAt, Collect, CoefficientList and Thread) if you are unfamiliar with them. This is all done in a single cell using % and %% to refer back to previous outputs in the cell. In making such a derivation one would usually develop it step by step, making additions and modifications and continually reevaluating until you are satisfied. The Print statements aren't really necessary but I often find them useful for keeping track of what I'm doing. Print[General polynomial represented as a square plus a constant] step1 = a x^2 + b x + c == d (x + e)^2 + f Print[Moving right hand side to the left] # - Part[%%, 2] & /@ %% Print[Collecting terms] MapAt[Collect[#, x] &, %%, 1] Print[Setting the coefficients of each power of x to zero and threading] MapAt[CoefficientList[#, x] &, %%, 1] Thread[%] Print[Solve the equations for d, e and f] defsols = First@Solve[%%, {d, e, f}] Print[Substitute into the right hand side of step1] step2 = Last[step1] /. defsols Now that we have a general solution, we can write a general routine CompleteTheSquare. CompleteTheSquare::usage = CompleteTheSquare[x][expr] will complete the square of subexpressions a !(*SuperscriptBox[x, 2]) + b x + c in expr.; CompleteTheSquare[var_: Global`x][expr_] := expr //. a_. var^2 + b_. var + c_. -> (-b^2 + 4 a c)/(4 a) + a (b/(2 a) + var)^2 If you write a nice routine you should always consider writing a good usage message for it. All the funny stuff in the usage message is because I used a superscript expression in a String expression and the internal representation came out when I copied and pasted to this posting. In the routine itself we just use a Rule to replace quadratic expressions with their 'complete the square' forms. We allow the variable to be specified and give it a default value of x. Global`x is used just in case you later decided to copy this function into a package and the routine would have to know that x is the global symbol and not some internal package symbol. You can check the usage message with: ?CompleteTheSquare We check the routine on your initial example: x^2+4x+7//CompleteTheSquare[] and a more complicated example with x and y polynomials. (3 x^2 - 11 x + 7)/(x^2 + 5 x - 11) == 5 y^2 + 24 y - 3 % // CompleteTheSquare[] % // CompleteTheSquare[y] You can use Mathematica to derive results. Then you can use the result of the derivation to write a useful routine. Then you could keep that routine, say in a Routines Section at the top of your notebook, or later in a package, and use it whenever you need it. You will have actually generated something useful and permanent - for yourself and perhaps for others. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: express a quadratic, in the form (x+a)^2 + b > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe Another solution is the answer is only for quadratics then Expand[(x + a)^2 + b] gives a^2+b+2ax+x^2 then making equal degrees coefficients equal we get the system Solve[{a^2 + b == 7, 2 a == 4}, {a, b}] and that gets you {{b -> 3, a -> 2}} applying that to (x + a)^2 + b /. {b -> 3, a -> 2} gets you 3 + (2 + x)^2 building the system of equations can be done programaticaly too I just do not have the time to do it. === Subject: Re: express a quadratic, in the form (x+a)^2 + b There are several easy ways. One of them is: (x + a)^2 + b /. First[SolveAlways[ x^2 + 4*x + 7 == (x + a)^2 + b, x]] (x + 2)^2 + 3 > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: express a quadratic, in the form (x+a)^2 + b > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe You can do Series[x^2 + 4 x + 7, {x, -2, 2}] the answer will be 3+(x+2)^2 +O[x+2]^3 === Subject: Re: express a quadratic, in the form (x+a)^2 + b > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: express a quadratic, in the form (x+a)^2 + b No responses - is that because it's too easy, too hard, too dull or too dumb? > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: express a quadratic, in the form (x+a)^2 + b x^2 + 4 x + 7 /. x^2 + b_*x + c_ :> Factor[x^2 + b*x + b^2/4] - b^2/4 + c Jens > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe > === Subject: Re: express a quadratic, in the form (x+a)^2 + b Something like transform[equation_] := Module[{coeffs = CoefficientList[equation, x]}, {c, b, a} = coeffs; (x + b/(2*a))^2 + (c/a - (b/(2*a))^2)] In[28]:= transform[x^2 + 4*x + 7] Out[28]= 3 + (2 + x)^2 ? Note that this does not exactly return what you want, as the result is not sorted in descending polynomial order. Hope that helps a bit! C.O. > I'm a Mathematica beginner. > I wish to express a quadratic, in the form (x+a)^2 + b > eg to express x^2 + 4x + 7 as (x+2)^2 + 3 > Is there an easy way? > Joe === Subject: Re: Trouble with double factorial and an infinite product Confirmed here on $Version 6.0 for Microsoft Windows (32-bit) (April 20, 2007) Visual Studio quickly offers to do a stack trace, with a message of Unhandled exception at 0x648c3ebb in MathKernel.exe: 0xC0000005: Access violation reading location 0x01d2e512. Whatever THAT means. The same product with just 1/n!! returns zero (correct), and Product[1 + 1/n!, {n, Infinity}] returns unevaluated. > A collegue of mine says that evaluating this Product[1+1/n!!,{n,Infinity}] quickly kills the kernel in Mathematica 6. > (but the same with {n,2,Infinity} does not) (The symbol n!! denotes the double factorial not > the repeated application of factorial, n!!=n(n-2)(n-4)... (1 or 2).) In previous versions it seems to me that it simply > returns it unevaluated. I'm just curious to know if it is a problem in his installation > or a little bug. > giovanni === Subject: Re: Trouble with double factorial and an infinite product Hi Giovanni, I can confirm this. 6.0 for Microsoft Windows (32-bit) (June 19, 2007) Daniel > A collegue of mine says that evaluating this Product[1+1/n!!,{n,Infinity}] quickly kills the kernel in Mathematica 6. > (but the same with {n,2,Infinity} does not) (The symbol n!! denotes the double factorial not > the repeated application of factorial, n!!=n(n-2)(n-4)... (1 or 2).) In previous versions it seems to me that it simply > returns it unevaluated. I'm just curious to know if it is a problem in his installation > or a little bug. > giovanni > === Subject: Re: is not equivalent to LinearSolve > On Dec 17, 7:18 pm, Andrew Moylan >1. LinearSolve[m, b] is not equivalent to LinearSolve[m][b]. > Well, I was definitely hoping someone might have clarified > this interesting issue. I haven't totally figured it out > myself, but I've got a few observations. My basic guess is > that LinearSolve[m][b] introduces the possibility of > compounded error via intermediate matrix factorizations that > a direct LinearSolve[m,b] avoids. Here's a simple example > illustrating this. > [...] Strangely enough, the issue is that LinearSolve[m][b] gives a good result, whereas LinearSolve[m, b] gives garbage. I'm fairly certain this is simply a bug. It was filed as such, and will be investigated. Daniel Lichtblau Wolfram Research === Subject: Re: LinearSolve[m, b] is not equivalent to LinearSolve[m][b] On Dec 17, 7:18 pm, Andrew Moylan Direct]; ans2 = LinearSolve[m3, Method -> Direct][b3]; Max[Abs[ans1 - ans2]] 0.1700000000000000000 This example might seem contrived, in that we've used a low precision approximation to an ill-conditioned matrix. It does illustrate the basic point that LinearSolve[m][b] and LinearSolve[m,b] are different. Also, it's interesting to note that ans2 is relatively close to the following: {lu, p, c} = LUDecomposition[m3]; l = lu SparseArray[{i_, j_} /; j < i -> 1, {3, 3}] + IdentityMatrix[3]; u = lu SparseArray[{i_, j_} /; j >= i -> 1, {3, 3}]; y = LinearSolve[l, b3[[p]], Method -> Direct]; ans3 = LinearSolve[u, y, Method -> Direct]; Max[Abs[ans3 - ans2]] 0.01000000000000000000 If I we're going to implement something like a Direct LinearSolveFunction from scratch, I suppose I'd use an LUDecompostion. Perhaps the error can arise here? In fact, the LUDecomposition is part of the LinearSolveFunction returned by LinearSolve, when the Method is Direct: lu1 = LinearSolve[m3, Method -> Direct][[2, 3]]; lu2 = LUDecomposition[m3]; Now, in your example, it appears that the method is IterativeRefinement. I figured this out simply by playing with the possible methods and looking at the answers. Here's an easy way to generate a list of possible Methods: LinearSolve[m, b, Method -> bogus]; Strangely, the IterativeRefinement method is not documented in the LinearSolve documentation or the MatrixComputations documentation; rather, it is a LeastSquares method. Of course, this is all conjecture; I have no direct knowledge of the LinearSolve algorithms. Mark