A119 === Subject: Re: PolarPlot Sorry, I missed the (r^2 = ) in your original post. How about: a= 3; PolarPlot[r /. Solve[r^2 == 4 a^2 Cos[theta], r], {theta, 0, 2 Pi}] > Craig > a = 2; PolarPlot[4 a^2 Cos@theta, {theta, 0, 2 Pi}] only produces half the plot, since only theta values in [0,pi/2] and > [3pi/2,2pi] can satisfy the function. The actual polar curve has two parts, > each corresponding to a positive and negative value of r. I don't see how to easily apply ParametricPlot (what would the > parametric forms be for x and y?), although I may well be missing the > obvious. It seems that a PolarContourPlot command is what's needed, but no such > thing exists in Mathematica (I think). Bruce Cc: mathgroup@smc.vnet.net === > Subject: Re: PolarPlot It doesn't appear that you are plotting what you say you wish to. > If I understand correctly, you are asking for > a = 2; > PlotPlot[4 a^2 Cos@theta, {theta, 0, 2 Pi}] In your example, you are plotting two radial functions. Perhaps you were > thinking of ParametricPlot? Re 6.0.2 under WinXP. I'm using the command below to plot the polar equation r^2 = 4a^2 Bruce PolarPlot[{2 a Sqrt[Cos@t], -2 a Sqrt[Cos@t]}, {t, 0, 2 [Pi]}, > PlotRange -> 7] > -- > W. Craig Carter -- W. Craig Carter === Subject: Re: exporting to multiple sheets in XLS format In version 6.0.2 (I don't know about earlier), you can fake the appending of new sheets onto an old workbook. Unfortunately this method destroys any formatting or formulas you may have in your original file, but hopefully it will give you a starting point. Please post if you find/create a better solution. ------- Begin Example ------- XLAppend[oldfile_, newfile_, newdata_] := Module[{sheets, olddata, completedata}, sheets = Import[oldfile, Sheets]; olddata = {#, Import[oldfile, {Sheets, #}]} & /@ sheets; completedata = Join[olddata, newdata]; Export[newfile, Rule @@@ completedata] ] tmp = RandomReal[{1,10}, {5,10}]; XLAppend[Old File.xls, New File.xls, {{Random Numbers, tmp}}] ------- End Example -------- Hope that helps, Januk On Apr 10, 2:14 am, Russo, Peter (10170) object ) or the ability to append worksheets to already created XLS > document. === Subject: Re: PolarPlot Craig a = 2; PolarPlot[4 a^2 Cos@theta, {theta, 0, 2 Pi}] only produces half the plot, since only theta values in [0,pi/2] and [3pi/2= ,2pi] can satisfy the function. The actual polar curve has two parts, each= corresponding to a positive and negative value of r. I don't see how to easily apply ParametricPlot (what would the parametric= forms be for x and y?), although I may well be missing the obvious. It seems that a PolarContourPlot command is what's needed, but no such th= ing exists in Mathematica (I think). Bruce Cc: mathgroup@smc.vnet.net === Subject: Re: PolarPlot It doesn't appear that you are plotting what you say you wish to. If I understand correctly, you are asking for a = 2; PlotPlot[4 a^2 Cos@theta, {theta, 0, 2 Pi}] In your example, you are plotting two radial functions. Perhaps you were th= inking of ParametricPlot? e: Re 6.0.2 under WinXP. I'm using the command below to plot the polar equation r^2 = 4a^2 Cos@the= Bruce PolarPlot[{2 a Sqrt[Cos@t], -2 a Sqrt[Cos@t]}, {t, 0, 2 [Pi]}, =C2 PlotRange -> 7] -- W. Craig Carter === Subject: FinancialData problems One of the examples in the Doc Center for FinancialData[] is FinancialData[^DJI, Name] which should return the English language name for the DJI (Dow Jones Industrials). In the example in the Doc Center it returns DOW JONES INDUSTRIAL AVERAGE I. which makes perfect sense. This example is under (for the FinancialData function): Scope | Names and Identifiers | Specifying Exchanges | | Getting Names and Identifiers | Groups and Sectors | Other Financial Instruments But when I evaluate it I get Missing[NotAvailable] instead of DOW JONES INDUSTRIAL AVERAGE I. This has been happening since Sept. 2007 when I first alerted Wolfram which they acknowledged was a bug. There are plenty of other examples that don't work as well with FinancialData such as FinancialData[FMAGX,Name] However, it still doesn.89¥út work properly. Have others noticed this problem? Are there any clever work arounds? Also, if I evaluate the Example in the Doc Center Length[FinancialData[Exchanges]] this should give the total number of exchanges supported [according to the Doc Center]. I get 66 instead of what the documentation says which is 85. Is this an indication that Wolfram is pulling back from supporting FinancialData[] as originally conceived since the number of Exchanges that are now available has gone from 85 to 66? Don === Subject: Re: FinancialData problems > One of the examples in the Doc Center > > for FinancialData[] is > > FinancialData[^DJI, Name] > > which should return the > English language name for the DJI (Dow Jones Industrials). > > In the example in the Doc Center it returns > > DOW JONES INDUSTRIAL AVERAGE I. > > which makes perfect sense. > > This example is under (for the FinancialData function): > > Scope | Names and Identifiers | Specifying Exchanges | > | Getting Names and Identifiers | Groups and Sectors | Other Financial Instruments > > But when I evaluate it I get > > Missing[NotAvailable] > > instead of > > DOW JONES INDUSTRIAL AVERAGE I. > > This has been happening since Sept. 2007 when I first > alerted Wolfram which they acknowledged was a bug. > > > There are plenty of other examples that don't work > as well with FinancialData such as > > > FinancialData[FMAGX,Name] > > However, it still doesn.89¥út work properly. > Have others noticed this problem? > Are there any clever work arounds? > > > Also, if I evaluate the Example in the Doc Center > > > Length[FinancialData[Exchanges]] > > this should give the total number of exchanges > supported [according to the Doc Center]. > > I get 66 instead of what the documentation says > which is 85. Is this an indication that > Wolfram is pulling back from supporting FinancialData[] as originally conceived since the number of Exchanges that > are now available has gone from 85 to 66? Don, I am afraid this might be not of great help, but I got similar results when testing the expression on my system. In[1]:= FinancialData[^DJI, Name] Out[1]= Missing[NotAvailable] In[2]:= FinancialData[FMAGX, Name] Out[2]= Missing[NotAvailable] In[3]:= Length[FinancialData[Exchanges]] Out[3]= 66 In[4]:= $Version Out[4]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) -- === Subject: Re: Just primitive ColorFunction > 1. Is there a more appropriate way to force Plot to calculate the > function value at certain points? How about (not very clean, but does the work if you really need to use ColorFunction for this to make it work with Filling): ep = 0.0001; Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False, Mesh -> {{Pi, Pi + ep, 2 Pi, 2 Pi + ep, 3 Pi, 3 Pi + ep}}, MeshStyle -> None] and if you still need to add mesh points in the x direction, use: ep = 0.0001; Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False, Mesh -> {{Pi, Pi + ep, 2 Pi, 2 Pi + ep, 3 Pi, 3 Pi + ep}, 10}, MeshStyle -> {None, Black}, MeshFunctions -> {#1 &, #1 &}] 2. Is there a way to avoid having to find the zeros of the function > manually? (More generally: avoid having to calculate the points where > the colouring changes abruptly.) Look at these two cases: 1) Plot[x, {x, 0, 4 Pi}, PlotStyle -> Thick, ColorFunction -> (If[Mod[IntegerPart[30 #], 2] == 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &)] 2) Plot[x, {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> 20, MeshShading -> {Red, Blue}] Subdividing 1) by color will succeed only if the initial sampling gets the colored regions right. Then a color based find root will need to be computed for every single color jump. We will also need to define what a jump or color based Exclusion is. 2) is the way of dealing with subdividing curves and surfaces via the Mesh/MeshFunctions/MeshShading options. An Automatic intersection method can be attained in many cases (only if the mesh functions evaluate to +/- values, so no min/max tangential intersections) with something like: Plot[Sin[x], {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> {{0.}}, MeshShading -> {Red, Blue}, MeshFunctions -> {(Sin[#]) &}] Plot[{x, Sin[x] + x}, {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> {{0.}}, MeshShading -> {Red, Blue}, MeshFunctions -> {(Sin[#]) &}] Plot[{Cos[x] + x, Sin[x] + x}, {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> {{0.}}, MeshShading -> {Red, Blue}, MeshFunctions -> {(Sin[#] - Cos[#]) &}] Finally, using all ColorFunction/Mesh/MeshFunctions/Filling options together: Plot[{x, Sin[x] + x}, {x, 0, 4 Pi}, PlotStyle -> Thick, Mesh -> {{0.}}, MeshFunctions -> {(Sin[#]) &}, ColorFunction -> (If[Sin[#] >= 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &), ColorFunctionScaling -> False, Filling -> {1 -> {2}}] -Ulises Cervantes WRI === Subject: Re: Appearance of DendrogramPlot > I am finding that the leaves of my DendrogramPlot are too short: Example: > Needs[HierarchicalClustering`] DendrogramPlot[{1, 2, 10, 4, 8, -100, -101, -102}, > LeafLabels -> (# &), Orientation -> Left] I am getting the lowest level clusters are not being resolved graphically. > As a follow up to the reply I just sent, an alternative method for visualizing the two main subclusters is to set TruncateDendrogram -> {2, Infinity} in DendrogramPlot. Darren Glosemeyer Wolfram Research === Subject: Re: Appearance of DendrogramPlot > I am finding that the leaves of my DendrogramPlot are too short: Example: > Needs[HierarchicalClustering`] DendrogramPlot[{1, 2, 10, 4, 8, -100, -101, -102}, > LeafLabels -> (# &), Orientation -> Left] I am getting the lowest level clusters are not being resolved graphically. > The issue is that the lengths of the leaves represent the distances between points or clusters, and the distance between the two main clusters is much larger than the distances between the points within each of those clusters. One possible way to visualize this would be to obtain the clustering via Agglomerate: cls = Agglomerate[{1, 2, 10, 4, 8, -100, -101, -102}]; visualize the full dendrogram DendrogramPlot[cls, LeafLabels -> (# &), Orientation -> Left] and then split the clustering into the two main clusters and visualize them separately to zoom in on the two main clusters. clsplt = ClusterSplit[cls, 2]; DendrogramPlot[clsplt[[1]], LeafLabels -> (# &), Orientation -> Left] DendrogramPlot[clsplt[[2]], LeafLabels -> (# &), Orientation -> Left] Darren Glosemeyer Wolfram Research === Subject: Tooltip with ListPointPlot3D I'm having trouble using Tooltip with ListPointPlot3D. The documentation shows a couple of usages but not the one I'm looking for. Say I have a dataset that's something like this: d2 = {{label-1, 0.0802289, 0.58389}, {label-2, 0.0911174, 0.338125}, {label-3, 0.749692, 0.450291}, {label-4, 0.0473889, 0.102987}, {label-5, 0.163107, 0.404119}, {label-6, 0.0618558, 0.769436}, {label-7, 0.899026, 0.799652}, {label-8, 0.801986, 0.453665}, {label-9, 0.653963, 0.196583}, {label-10, 0.467749, 0.91355}} I can plot the data with the labels as tool tips like this: d2t = Tooltip[Rest[#], First[#]] & /@ d2 ListPlot[d2t] and the tooltips show the label when you hover the cursor over the corresponding point. Fantastic! I love it. Now what about 3D data? d3 = Table[ Prepend[Table[Random[], {3}], label- <> ToString[i]], {i, 10}] d3t = Tooltip[Rest[#], First[#]] & /@ d3 ListPointPlot3D[d3t] >> ListPointPlot3D::arrayerr: {{0.84741,0.224122,0.626086},{<<1>>},<<6>>,<<1>>,{<<1>>}} must be a valid array or a list of valid arrays. >> I've tried this various ways but haven't been able to make it work. I also tried it with graphics primitives and got similar results. Any ideas would be most welcome! Tom === Subject: Re: Tooltip with ListPointPlot3D > I'm having trouble using Tooltip with ListPointPlot3D. The > documentation > shows a couple of usages but not the one I'm looking for. > ... > Now what about 3D data? d3 = Table[ > Prepend[Table[Random[], {3}], label- <> ToString[i]], {i, 10}] > d3t = Tooltip[Rest[#], First[#]] & /@ d3 > ListPointPlot3D[d3t] ListPointPlot3D::arrayerr: > {{0.84741,0.224122,0.626086},{<<1>>},<<6>>,<<1>>,{<<1>>}} must be a > valid array or a list of valid arrays. I've tried this various ways but haven't been able to make it work. I > also tried it with graphics primitives and got similar results. Any ideas would be most welcome! Look for a c.s-s.m.m thread last January Locator 3D. Maxim Rytin posted a nifty 3D picking example that used Mouseover. Hth, Fred Klingener === Subject: Re: Tooltip with ListPointPlot3D d3 = Table[ Prepend[Table[Random[], {3}], label- <> ToString[i]], {i, 10}] d3t = Tooltip[Point[Rest[#]], First[#]] & /@ d3; Graphics3D[ {d3t}, Axes -> True] ?? Jens > I'm having trouble using Tooltip with ListPointPlot3D. The > documentation > shows a couple of usages but not the one I'm looking for. > > Say I have a dataset that's something like this: > > d2 = {{label-1, 0.0802289, 0.58389}, {label-2, 0.0911174, > 0.338125}, > {label-3, 0.749692, 0.450291}, {label-4, 0.0473889, 0.102987}, > {label-5, 0.163107, 0.404119}, {label-6, 0.0618558, 0.769436}, > {label-7, 0.899026, 0.799652}, {label-8, 0.801986, 0.453665}, > {label-9, 0.653963, 0.196583}, {label-10, 0.467749, 0.91355}} > > I can plot the data with the labels as tool tips like this: > > d2t = Tooltip[Rest[#], First[#]] & /@ d2 > ListPlot[d2t] > > and the tooltips show the label when you hover the cursor over the > corresponding point. Fantastic! I love it. > > Now what about 3D data? > > d3 = Table[ > Prepend[Table[Random[], {3}], label- <> ToString[i]], {i, 10}] > d3t = Tooltip[Rest[#], First[#]] & /@ d3 > ListPointPlot3D[d3t] > > ListPointPlot3D::arrayerr: {{0.84741,0.224122,0.626086},{<<1>>},<<6>>,<<1>>,{<<1>>}} must be a valid array or a list of valid arrays. > > I've tried this various ways but haven't been able to make it work. I > also tried it with graphics primitives and got similar results. > > Any ideas would be most welcome! > > Tom > === Subject: Re: Tooltip with ListPointPlot3D On Apr 13, 3:33 am, Jens-Peer Kuska Prepend[Table[Random[], {3}], label- <> ToString[i]], {i, 10}] > d3t = Tooltip[Point[Rest[#]], First[#]] & /@ d3; > Graphics3D[ > {d3t}, Axes -> True] for anyone that cares, the dataset i'm looking at is from this page: http://www.rmimaging.com/projects/inks/inks.html mathematica lets me look at these fountain pen inks in a whole new way. === Subject: Re: Intersection of lists of lists based on the first term > (isCommon[#] = True) & /@ timeStampsInCommon supposed to achieve other than > a list of True equal to the length of timeStampsInCommon in every case? > Perhaps I should have written it as Scan[(isCommon[#] = True) &, timeStampsInCommon] to emphasize that the function (isCommon[#] = True) & is only invoked for its side effects, i.e. defining new DownValues for the symbol isCommon. This will set the value of isCommon[ ... ] to True for each of the elements in timeStampsInCommon. Thus, isCommon[elem] is equivalent to MemberQ[timeStampsInCommon, elem], but it is much faster if timeStampsInCommon has many elements (because Mathematica will use a hash table for looking up elements instead of simply iterating through timeStampsInCommon). Note that isCommon[] needs to be Clear[]ed after each use (a better solution is encapsulating the whole thing into a Module where isCommon is a local symbol). === Subject: Deleting Integrate[] transformation rule I feel sure this should be easy and have searched for the answer in the online docs & NG but without success. I wish to remove (as opposed to modify) a rule such as the following; When integrating Mathematica knows the result of D[EllipticF[phi,m, phi]] = 1/Sqrt[1-m*Sin[phi]^2]] and will produce expressions containing EllipticF[] in its result when it encounters such a pattern. I want to prevent this -- that is Unprotect Integrate[] and make it forget this rule so that EllipticF[] will not appear in the result. Any ideas? Tom. -- Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill, Egham, Surrey, TW20 0EX, England. Email: T.Crane at rhul dot ac dot uk Fax: +44 (0) 1784 472794 === Subject: Re: Deleting Integrate[] transformation rule > When integrating Mathematica knows the result of D[EllipticF[phi,m, phi]] = Syntax error: a square bracket is missing. > 1/Sqrt[1-m*Sin[phi]^2]] and will produce expressions containing > EllipticF[] in its result when it encounters such a pattern. I want > to prevent this -- that is Unprotect Integrate[] and make it forget > this rule so that EllipticF[] will not appear in the result. No need to do that: just use the correct syntax as in, In[1]:= D[EllipticF[phi, m], phi] Out[1]= 1 --------------------- 2 Sqrt[1 - m Sin[phi] ] -- === Subject: Re: transformation rule It seems that not everything that must be possible is always possible. In fact, in this case, it is definitely not possible. You cannot in remove any transformations used by Integrate. The best you can do is to try to post-process answers returned by Integrate using FunctionExpand or FullSimplify with chosen complexity functions, but doing this will not transform EllipticF[phi,m] into anything else. You can of course wrap Hold or HoldForm over EllipticF[phi,m] but that will simply prevent any integration from being carried out. Of course if that is what you wanted then, indeed, it is definitely possible. Andrzej Kozlowski : > When integrating Mathematica knows the result of > D[EllipticF[phi,m, phi]] = > : > : Syntax error: a square bracket is missing. : > 1/Sqrt[1-m*Sin[phi]^2]] and will produce expressions containing > : > EllipticF[] in its result when it encounters such a pattern. I > want > : > to prevent this -- that is Unprotect Integrate[] and make it > forget > : > this rule so that EllipticF[] will not appear in the result. : No need to do that: just use the correct syntax as in, : In[1]:= D[EllipticF[phi, m], phi] : Out[1]= : 1 > : --------------------- > : 2 > : Sqrt[1 - m Sin[phi] ] My apologies. I typed the above in a rush, hence the syntax errors -- > including I notice an extraneous ']' in the derivative expression. > However you did not address the question. It must be possible to > Unprotect Integrate[] and modify it to remove the transformation > rule that > it uses to pattern match and convert integrand expressions of the form > 1/Sqrt[1-m*Sin[phi]^2] to resultant integral expressions of the form > EllipticF[phi,m] -- thus preventing EllipticF[] appearing in any > result > produced by Integrate[]. It is unclear to me from the Mathematica > 4.0 docs > I have how to do this. The Hold* family of functions, HoldComplete in > particular look relevant?? Can anybody confirm/refute and supply a > worked > example of this procedure? Tom. : -- > -- > Tom Crane, Dept. Physics, Royal Holloway, University of London, > Egham Hill, > Egham, Surrey, TW20 0EX, England. > Email: T.Crane at rhul dot ac dot uk > Fax: +44 (0) 1784 472794 > === Subject: Re: Deleting Integrate[] transformation rule My apologies. I typed the above in a rush, hence the syntax errors -- > including I notice an extraneous ']' in the derivative expression. > However you did not address the question. It must be possible to > Unprotect Integrate[] and modify it to remove the transformation rule that > it uses to pattern match and convert integrand expressions of the form > 1/Sqrt[1-m*Sin[phi]^2] to resultant integral expressions of the form > EllipticF[phi,m] -- thus preventing EllipticF[] appearing in any result > produced by Integrate[]. It is unclear to me from the Mathematica 4.0 docs > I have how to do this. The Hold* family of functions, HoldComplete in > particular look relevant?? Can anybody confirm/refute and supply a worked > example of this procedure? > Hi Tom, It is not possible to access the source code of Integrate (some parts of it are not even written in the Mathematica language, but implemented at a lower level). Even if we had access to the source code, I imagine that modifying it would not be a trivial task. (Unlike derivation, symbolic integration cannot generally be done by simply applying a set of transformation rules recursively.) You will find some notes about the implementation of Integrate here: http://reference.wolfram.com/mathematica/note/SomeNotesOnInternalImplementat ion.html === Subject: Re: Deleting Integrate[] transformation rule : > When integrating Mathematica knows the result of D[EllipticF[phi,m, phi]] = : Syntax error: a square bracket is missing. : > 1/Sqrt[1-m*Sin[phi]^2]] and will produce expressions containing : > EllipticF[] in its result when it encounters such a pattern. I want : > to prevent this -- that is Unprotect Integrate[] and make it forget : > this rule so that EllipticF[] will not appear in the result. : No need to do that: just use the correct syntax as in, : In[1]:= D[EllipticF[phi, m], phi] : Out[1]= : 1 : --------------------- : 2 : Sqrt[1 - m Sin[phi] ] My apologies. I typed the above in a rush, hence the syntax errors -- including I notice an extraneous ']' in the derivative expression. However you did not address the question. It must be possible to Unprotect Integrate[] and modify it to remove the transformation rule that it uses to pattern match and convert integrand expressions of the form 1/Sqrt[1-m*Sin[phi]^2] to resultant integral expressions of the form EllipticF[phi,m] -- thus preventing EllipticF[] appearing in any result produced by Integrate[]. It is unclear to me from the Mathematica 4.0 docs I have how to do this. The Hold* family of functions, HoldComplete in particular look relevant?? Can anybody confirm/refute and supply a worked example of this procedure? Tom. : -- -- Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill, Egham, Surrey, TW20 0EX, England. Email: T.Crane at rhul dot ac dot uk Fax: +44 (0) 1784 472794 === Subject: Re: transformation rule (some > Some progress on my original query. I tried the following where > the formulae below are expressions which integrate to elliptic > integrals of the first kind and are from mathematical handbooks. > > Unprotect[Integrate]; > > Integrate[1/Sqrt[1 - m_*Sin[phi_]^2], phi_] := > HoldForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] > > Integrate[1/Sqrt[(1 - v_^2)*(1 - k_^2*v_^2)], v_] := > HoldForm[Integrate[1/Sqrt[(1 - v^2)*(1 - k^2*v^2)], v]] > > Protect[Integrate]; > > > Subsequent attempts to integrate (eg. [Integrate[1/Sqrt[1 - a*Sin[b]^2], > b]) do indeed leave the integral undone as required. However more > involved expressions such as; > > In[52]:= > Integrate[Sqrt[Rvt^2 + (4*R^4)/Rx^4], R] // InputForm > > Out[52]//InputForm= > (R*Sqrt[Rvt^2 + (4*R^4)/Rx^4])/3 - > (I/3*Sqrt[2]*Rvt^2*Sqrt[Rvt^2 + (4*R^4)/Rx^4]* > Sqrt[1 - (2*I*R^2)/(Rvt*Rx^2)]* > Sqrt[1 + (2*I*R^2)/(Rvt*Rx^2)]*Rx^4* > EllipticF[I*ArcSinh[Sqrt[2]*R*Sqrt[I/(Rvt*Rx^2)]], > -1])/(Sqrt[I/(Rvt*Rx^2)]*(4*R^4 + Rvt^2*Rx^4)) > > still produce the unwanted EllipticF[]. My question is, is this; (a) > because my above HoldForm[] argument expressions are failing to > pattern-match the intermediate expressions produced by Integrate[], which > it then uses to produce results containing calls to EllipticF[], (b) > because Mathematica knows more expressions than I entered above > from my handbook which it can integrate up to EllipticF[], or > (c) something else? > > Any ideas? > > Tom. > If you are not averse to using a global flag variable, you can do it as follows. Unprotect[Integrate]; globalIntegrateFlag = True; Integrate[args__] := Block[ {globalIntegrateFlag=False, res}, res = Integrate[args]; If [FreeQ[res,EllipticF], res, HoldForm[Integrate[args]]] Examples: In[7]:= InputForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] Out[7]//InputForm= HoldForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] In[8]:= Integrate[1/Sqrt[1 - phi^2], phi] Out[8]= ArcSin[phi] (Even if you are averse to using a global variable, you can still do it that way; you'll just be less comfortable with it.) Daniel Lichtblau Wolfram Research === Subject: Re: Deleting Integrate[] transformation rule (some progress) Some progress on my original query. I tried the following where the formulae below are expressions which integrate to elliptic integrals of the first kind and are from mathematical handbooks. Unprotect[Integrate]; Integrate[1/Sqrt[1 - m_*Sin[phi_]^2], phi_] := HoldForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] Integrate[1/Sqrt[(1 - v_^2)*(1 - k_^2*v_^2)], v_] := HoldForm[Integrate[1/Sqrt[(1 - v^2)*(1 - k^2*v^2)], v]] Protect[Integrate]; Subsequent attempts to integrate (eg. [Integrate[1/Sqrt[1 - a*Sin[b]^2], b]) do indeed leave the integral undone as required. However more involved expressions such as; In[52]:= Integrate[Sqrt[Rvt^2 + (4*R^4)/Rx^4], R] // InputForm Out[52]//InputForm= (R*Sqrt[Rvt^2 + (4*R^4)/Rx^4])/3 - (I/3*Sqrt[2]*Rvt^2*Sqrt[Rvt^2 + (4*R^4)/Rx^4]* Sqrt[1 - (2*I*R^2)/(Rvt*Rx^2)]* Sqrt[1 + (2*I*R^2)/(Rvt*Rx^2)]*Rx^4* EllipticF[I*ArcSinh[Sqrt[2]*R*Sqrt[I/(Rvt*Rx^2)]], -1])/(Sqrt[I/(Rvt*Rx^2)]*(4*R^4 + Rvt^2*Rx^4)) still produce the unwanted EllipticF[]. My question is, is this; (a) because my above HoldForm[] argument expressions are failing to pattern-match the intermediate expressions produced by Integrate[], which it then uses to produce results containing calls to EllipticF[], (b) because Mathematica knows more expressions than I entered above from my handbook which it can integrate up to EllipticF[], or (c) something else? Any ideas? Tom. -- Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill, Egham, Surrey, TW20 0EX, England. Email: T.Crane at rhul dot ac dot uk Fax: +44 (0) 1784 472794 === Subject: Re: What is @@@? >Look, after using Mathematica extensively since, literally, version >1.0, I know full well that 3 is not an operator! >But, it sure seems to me that the quote given above unambiguously >implies that it is -- otherwise the sentence would have (and could >have, and should have) said something like Taken by itself, I can see how you would interpret this way. But no part of the documentation should ever be considered in isolation from other parts of the documentation. >Characters that are not letters, NUMBERS, letter-like forms, or >structural elements are treated by Mathematica as operators. Certainly, it could have been written that way. But if you know full well numbers are not operators where is the problem? >This branch of this thread started with my query about where in the >documentation I could learn about all the non-alphameric operators >that are so ubiquitous, and confusing, in Mathematica. >I use and understand some of these; I know that I don't know all of >them; I would like to have a brief overview (3 or 4 pages max) >giving a quick list of all of them (or least the most important of >them) and a brief (few sentence), so that I might learn what the >rest of them are, and perhaps improve my skills. >I was pointed to Section A 2.7. It doesn't really do what I want -- >and seems to be inaccurate (or at least imprecise) to boot. If the point of your post was Section A 2.7 is confusing to you, it would have been far more effective to say so rather than pose a question about whether 3 could be seen as an operator. >Finally, you mention precedence for Mathematica's documentation. >Precedence implies _precedence rules_ (otherwise it's meaningless). >So, if you'll pardon a little sarcasm: Where in the Mathematica >documentation are these precedence rules for the Mathematica >documentation itself given? Perhaps this was poor wording on my part. My point is none of the documentation should be expected to stand in isolation from other parts of the documentation. It is reasonable to expect later parts of the documentation assume an understanding of earlier parts of the documentation. This is particularly true of an appendix. Earlier parts of the documentation make it clear 3 is a number. It should not be necessary to repeat this. And the documentation should be consistent. Hence the lack of an explicit exclusion of numbers from the set of operators in an appendix should not be necessary. You say above you have been using Mathematica since version 1.0. If so, how can you take this portion of the documentation as implying numbers can be operators? >1) Writing totally precise, complete, detailed, absolutely accurate >_reference_ documentation, of the sort needed by experts, for any >system as massive and complex as Mathematica, is very hard -- a very >difficult task. This is certainly true. >Wolfram works hard, I believe, at providing this kind of reference >documentation -- as they more or less have to -- but don't do a >perfect job, as the opening sentence of A 2.7 illustrates in an >admittedly pretty minor way. >2) Writing less precise, less complete, much shorter, simpler, less >detailed, and very differently organized and structured _user_ >documentation, for the benefit of beginners and/or ordinary >non-expert users of a system like Mathematica is at least equally >hard -- in fact, perhaps an even more difficult task. This is also true. >Wofram has thus far, at least in my view, _totally_ failed at >performing this task and providing this kind of _user-oriented_ >documentation for version 6.0; and deserves severe criticism for >this failure. This is a rather extreme overstatement and is clearly not true. You are using version 6 successfully aren't you? If so, the documentation cannot be considered a total failure. This type of criticism is neither productive nor warranted. Can the documentation be improved? Certainly, it can be. And I am equally certain Wolfram is open to suggestion as to how that might be done. But labeling the documentation as a failure offers no ideas for improvement and serves no useful purpose. === Subject: Re: Import .xlsx files >I agree that Excel stinks as a data exchange format, but it is a >(sometimes unpleasant) fact of life. The Open->Save As->CSV cycle >works (if you can find those commands at all in Excel 2007) for one >or two files, but I might get an entire folder of files to >analyze. I already use Import[..., XLS] this way a lot. >I am also aware of Mathematica Link for Excel, which I believe is >compatible with the new formats, but I bounce between Windows and >MacOS X. Link for Excel, or even the .NET technology behind Link >for Excel, does not exist on the Mac platform. I don't understand what it is you are trying to achieve here. Like you, I also bounce from Macs (my perferred machine) to Windows based machines. But I don't see what this has to do with getting data in or out of Excel. You indicate an awareness Excel isn't a good data exchange format. So, why use Excel at all? Mathematica is a far superior tool for any kind scientific or technical analysis I can think of than Excel. >Although of course I welcome all comments and help from the general >participants in this users group, my posting is really directed at >the Wolfram developers who monitor this group, hoping to encourage >them to add .XLSX as an Import format. Given the ubiquity of Excel, I suspect Wolfram will at some point support that format. === Subject: Re: Import .xlsx files > I don't understand what it is you are trying to achieve here. > Like you, I also bounce from Macs (my perferred machine) to > Windows based machines. But I don't see what this has to do with > getting data in or out of Excel. > I mention the Mac only because it keeps me from using MathLink for Excel (a third party product for Windows only) as my solution. The point that I am getting to is that I am aware of (and am already using) the workarounds, but would prefer to work directly with Import. > You indicate an awareness Excel isn't a good data exchange > format. So, why use Excel at all? Mathematica is a far superior > tool for any kind scientific or technical analysis I can think > of than Excel. I agree. This is why I want to get the data out of Excel and into Mathematica for analysis. I am working in an office environment and often receive files in a format not of my choosing. === Subject: Player Pro and Packages How many people have tried out Player Pro yet? I copied my private Applications folder over to the Player Pro folder and tried to run a notebook that used a private package. Player Pro found the style sheet that came with the package but did not find the package. Does anyone know how to incorporate a private package into Player Pro? Without that it seems to be rather limited. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: Player Pro and Packages Will Player Pro allow use of environment variables MATHEMATICA_BASE and MATHEMATICA_USERBASE for finding packages -- as Mathematica itself does? >> How many people have tried out Player Pro yet? >> I copied my private Applications folder over to the Player Pro folder and >> tried to run a notebook that used a private package. Player Pro found the >> style sheet that came with the package but did not find the package. >> Does anyone know how to incorporate a private package into Player Pro? >> Without that it seems to be rather limited. > I put a package in the 'old' package location beneath the installation > directory. This appeared to work, and did not even require that the > package be encoded (as mentioned on the Wolfram website). > > David Bailey > http://www.dbaileyconsultancy.co.uk > -- 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: Player Pro and Packages Hi David, I have built some sophisticated applications for PlayerPro so far for some customers of mine. The trick with Packages (though perhaps you know this and your problem is different)--and reading in any files that have Mathematoca code in them--is that they cannot be in human readable form. For Player Pro to permit them to be read in they must first be processed using Encode. This of course makes sense given the intended purpose of Player Pro. If one could just read in normal .m files then one could have a text editor open and Player Pro open at the same time and thereby one could, in effect, have a crude but fully functional Mathematica available. One could also create a Front End to Mathematica in that way using something more sophisticated--like Java. So the restriction to Encoded files is essential to making Player Pro a deployment platform and leaving Mathematica as the development platform. Mathematica parameters to disk for future use using Get, then it needs to write them also with Encode. Also one can create files using DumpSave, and these too can be read in using Player PRo. Hope this helps, --David A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... Trial Version at: http://scientificarts.com/worklife/ > How many people have tried out Player Pro yet? I copied my private Applications folder over to the Player Pro folder and > tried to run a notebook that used a private package. Player Pro found the > style sheet that came with the package but did not find the package. Does anyone know how to incorporate a private package into Player Pro? > Without that it seems to be rather limited. -- > David Park > djmp...@comcast.nethttp://home.comcast.net/~djmpark/ === Subject: Re: Player Pro and Packages > How many people have tried out Player Pro yet? > > I copied my private Applications folder over to the Player Pro folder and > tried to run a notebook that used a private package. Player Pro found the > style sheet that came with the package but did not find the package. > > Does anyone know how to incorporate a private package into Player Pro? > Without that it seems to be rather limited. > I put a package in the 'old' package location beneath the installation directory. This appeared to work, and did not even require that the package be encoded (as mentioned on the Wolfram website). David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Player Pro and Packages On Apr 13, 3:32 am, David Bailey How many people have tried out Player Pro yet? > I copied my private Applications folder over to the Player Pro folder an= d > tried to run a notebook that used a private package. Player Pro found th= e > style sheet that came with the package but did not find the package. > Does anyone know how to incorporate a private package into Player Pro? > Without that it seems to be rather limited. I put a package in the 'old' package location beneath the installation > directory. This appeared to work, and did not even require that the > package be encoded (as mentioned on the Wolfram website). > If that's so it would be a Whoops! for WRI... > David Baileyhttp://www.dbaileyconsultancy.co.uk === Subject: Re: Player Pro and Packages > On Apr 13, 3:32 am, David Bailey I copied my private Applications folder over to the Player Pro folder an= > d > tried to run a notebook that used a private package. Player Pro found th= > e > style sheet that came with the package but did not find the package. > Does anyone know how to incorporate a private package into Player Pro? > Without that it seems to be rather limited. >> I put a package in the 'old' package location beneath the installation >> directory. This appeared to work, and did not even require that the >> package be encoded (as mentioned on the Wolfram website). > > If that's so it would be a Whoops! for WRI... > > >> David Baileyhttp://www.dbaileyconsultancy.co.uk > > My feeling is that there are so many ways of inputting a string and converting the result with ToExpression, that it might be better to handle abuses of PlayerPro by means of suitable wording in the license conditions. Plugging all the loopholes to prevent the execution of an arbitrary expression would seem to be almost impossible, and would greatly restrict the usefulness of PlayerPro. For example, if J/Link is disabled (it seems to work with the current version)to prevent the input of expressions via a Java interface, that will make a whole range of totally innocent applications unable to use PlayerPro. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Tilted decimals on the x-axis to avoid overlapping You might find the following thread useful: ead/8402afa67d8ea11c/7895e434fd285f66?hl=en&lnk=gst&q=Vertical+tick+la= bels+in+BarChart#7895e434fd285f66 John Jowett How can I see all the decimals on the x-axis **and** avoid overlapping ? Trivial example: Plot[x, {x, 123.45678, 123.45679}] I would like to rotate clockwise by an angle alpha (e.g.,Pi/6, or > Pi/2+Pi/6) > the values on the x-axis and translate them in order to see the starting > point, > i.e., the 1 of 123.45678 should be near to the relevant tick. Note: I cannot use the usual Options to reduce the **size** of the > figures or > increase the size of the image. Any hint ? PS The nice suggestion by Ruskeepaa (pag. 271) seems not applicable = in > this case. Gianfranco Zosi > Dip. Fisica Generale > Universita di Torino === Subject: Re: Tilted decimals on the x-axis to avoid overlapping Here is one solution using the CustomTicks function from the Presentations package. We also need to use NumberForm to extend the display precision, otherwise all the numbers will be the same. Needs[Presentations`Master`] With[ {xticks = CustomTicks[Identity, {123.45678, 123.45679, .000002, 5}, CTNumberFunction -> (Graphics[ Text[Style[NumberForm[#, {9, 6}], 12], {0, 0}, {-1, 0}, {0, 1}], AspectRatio -> 6, ImageSize -> {10, 60}] &)], yticks = CustomTicks[Identity, {123.45678, 123.45679, .000002, 5}, CTNumberFunction -> (NumberForm[#, {9, 6}] &)]}, Draw2D[ {Draw[x, {x, 123.45678, 123.45679}]}, AspectRatio -> 1/GoldenRatio, Frame -> True, FrameTicks -> {{yticks, Automatic}, {xticks, xticks // NoTickLabels}}, FrameLabel -> {x, y}, BaseStyle -> {FontSize -> 12}] ] However, that rather violates the principle: Maximize the information, minimize the ink. 123.45678 is repeated 12 times! In technical publication the tick labels themselves are usually simplified and the functional relation between the tick values and the quantity is put in the frame labels. Here the tick labels go from 0 to 1 on the x and y axes. With[ {ticks = CustomTicks[#/10^5 + 123.45678 &, {0, 1, .2, 5}]}, Draw2D[ {Draw[x, {x, 123.45678, 123.45679}]}, AspectRatio -> 1/GoldenRatio, Frame -> True, FrameTicks -> {{ticks, ticks // NoTickLabels}, {ticks, ticks // NoTickLabels}}, FrameLabel -> {(x-123.45678)!(*SuperscriptBox[10, 5]), (y-123.45678)!(*SuperscriptBox[10, 5])}, BaseStyle -> {FontSize -> 12}] ] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ How can I see all the decimals on the x-axis **and** avoid overlapping ? Trivial example: Plot[x, {x, 123.45678, 123.45679}] I would like to rotate clockwise by an angle alpha (e.g.,Pi/6, or > Pi/2+Pi/6) > the values on the x-axis and translate them in order to see the starting > point, > i.e., the 1 of 123.45678 should be near to the relevant tick. Note: I cannot use the usual Options to reduce the **size** of the > figures or > increase the size of the image. Any hint ? PS The nice suggestion by Ruskeepaa (pag. 271) seems not applicable in > this case. Gianfranco Zosi > Dip. Fisica Generale > Universita di Torino > === Subject: Re: Ranks for an array of triplets >I can create an array with x,y,z triplets. x,y are on a regularly spaced >raster, z is a RandomReal. >For sorting the array according to the z values, I found two options, >the second of which is significantly faster. >However, my goal is not to sort, but to calculate the rank of the z >value within the triplet. >For example: >original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} >convert to: {0,0,2},{0,1,1},{1,1,3} > > Ar[[All,3]] = Ordering@Ordering[Ar[[All,3]]] will do this, as long as all the z-values are distinct. Carl Woll Wolfram Research >.89ºâ 2.3 is the smallest z-value, hence it gets assigned rank 1 In my case I can reach this converted array only with extra steps: >- separating the z-values from Ar, >- calculating the (standardized) RanksOfAr, >- gluing the triplets back together. Is there a way to to this in one step? Claus Here is the mathematica code: >----------------------------- Make up an array with (x, y) being coordinates and z being a value at >that (x, y) location Ar = Partition[Flatten[Table[{i, j, k}, > {i, 1, 10} > , {j, 1, 10} > , {k, {RandomReal[]}} > ]], 3]; >Time two versions of Sorting the array Ar according to z Timing[SortBottomAATriples = Sort[Ar, #1[[3]] < #2[[3]] &]]; sll[ll_, elem_] := ll[[Ordering[ll[[All, elem]]]]] >Timing[OrdBotAATrip = sll[Ar, 3]]; Create the Ranks of z at the original position from Ar those ranks are scaled between [0, 1] RanksOfAr = Ordering[SortBottomAATriples]/Length[SortBottomAATriples]; Procedure to put it all back together x = Ar[[All, 1]]; >y = Ar[[All, 2]]; >FinalAr = Transpose[{x, y, RanksOfAr}] // N; > > === Subject: Re: Ranks for an array of triplets I can create an array with x,y,z triplets. x,y are on a regularly spaced raster, z is a RandomReal. For sorting the array according to the z values, I found two options, the second of which is significantly faster. However, my goal is not to sort, but to calculate the rank of the z value within the triplet. For example: original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} convert to: {0,0,2},{0,1,1},{1,1,3} $B*(B 2.3 is the smallest z-value, hence it gets assigned rank 1 > In my case I can reach this converted array only with extra steps: - separating the z-values from Ar, - calculating the (standardized) RanksOfAr, - gluing the triplets back together. > Is there a way to to this in one step? Claus > Here is the mathematica code: ----------------------------- > Make up an array with (x, y) being coordinates and z being a value at that (x, y) location > Ar = Partition[Flatten[Table[{i, j, k}, {i, 1, 10} , {j, 1, 10} , {k, {RandomReal[]}} ]], 3]; > Time two versions of Sorting the array Ar according to z > Timing[SortBottomAATriples = Sort[Ar, #1[[3]] < #2[[3]] &]]; > sll[ll_, elem_] := ll[[Ordering[ll[[All, elem]]]]] Timing[OrdBotAATrip = sll[Ar, 3]]; > Create the Ranks of z at the original position from Ar > those ranks are scaled between [0, 1] > RanksOfAr = Ordering[SortBottomAATriples]/Length[SortBottomAATriples]; > Procedure to put it all back together > x = Ar[[All, 1]]; y = Ar[[All, 2]]; FinalAr = Transpose[{x, y, RanksOfAr}] // N; Èåòå§ó smaller example of a method that should be faster: ÉîÛ±[CapitalYAcute]ºAr = Flatten[Array[{##,Random[]}&,{nrows = 5, ncols = 4}],1] ÏõôÛ±[CapitalYAcut e]{{1,1,0.418682},{1,2,0.692552},{1,3,0.263399},{1,4,0.860788}, û.b2¬±¬°®.b3[Cente rDot].b9±.b9.b3[YAcute]¬û.b2¬.b2¬[Degr ee]®.b3.b3.b9.b2.b9´£¿[ UHat].b2¬.b3¬°®.b2.b9.b3´¸ 262[YAcute]¬û.b2¬´¬°® 270´.b2·[Micro]±£¿ û.b3¬±¬°®[Micro]26 2.b2¶.b9.b9[YAcute]¬û.b3¬.b2¬° ®¶¸´¶¸[Micro]£ ¿û.b3¬.b3¬°®.b3 ¸.b2.b3·.b2[YAcute]¬û.b3¬´¬[Degre e]®°.b9°¶¶¸[C enterDot][YAcute] {4,1,0.192081},{4,2,0.176807},{4,3,0.464003},{4,4,0.0851869}, û[Micro]¬±¬°®¸[P aragraph].b9[Micro].b9.b9[YAcute]¬û[Micro]¬.b2¬[ Degree]®[Micro]¶·[Micro][Micro] ´£¿û[Micro]¬.b3¬°[Regis teredTrademark].b9·°.b3[Micro]´[YAcute]¬[UHat ][Micro]¬´¬°®°· ´¸·.b9±[YAcute] ÉîÛ.b2[CapitalYAcute]ºN@MapThread[Rep lacePart[#1,#2,3]&, ûÁò¬Ïò[ADoubleD ot]åòéîçÀ[CapitalIDoub leDot]òäåòéîç[Cap italAGrave]ÁòÛÛ[CapitalAAcu te]ìì¬.b3[CapitalYAcute][CapitalYAcute]¯¨[IHat ]òï÷óªîãï[I Grave]ó©[YAcute] ÏõôÛ.b2[CapitalYAcute]{{1.,1 .,0.55},{1.,2.,0.8},{1.,3.,0.3},{1.,4.,0.9}, û.b2®¬±®[No t]°®´[Micro][YAcute]¬û.b2[Regi steredTrademark]¬.b2®¬°[RegisteredTr ademark]´[YAcute]¬û.b2®¬.b3[Regis teredTrademark]¬°®.b3[Micro]£[ DownQuestion]û.b2®¬´[RegisteredTrademark ]¬°®¸[Micro][YAcute] {3.,1.,0.65},{3.,2.,0.75},{3.,3.,0.5},{3.,4.,0.15}, û´®¬±®[No t]°®.b2[Micro][YAcute]¬û´[Regi steredTrademark]¬.b2®¬°[RegisteredTr ademark].b2[YAcute]¬û´®¬.b3[Regis teredTrademark]¬°®¶[YAcute][No t]û´®¬´®¬[De gree]®±[YAcute] {5.,1.,0.95},{5.,2.,0.7},{5.,3.,1.},{5.,4.,0.05}} === Subject: Re: Ranks for an array of triplets Èåììï¬ Äï ùïcare whether the final data is in the same order as the ïòéçéîáì Éæ îïô¬ ôèéó éó æáéòìù åææéãéåîô[Register edTrademark] áìéó= RandomReal[{0, 100}, {10, 3}] áìéóôÛÛ[Cap italIDoubleDot]òäåòéî[CCedi lla]ÛÔòáîó[Eth][IDo ubleDot]óåÛáìéó[ OHat][CapitalYAcute]ÛÛ.b3[CapitalYAcute][Capita lYAcute][CapitalYAcute][CapitalYAcute][CapitalYAcute] Ôèrank is implied by the position in the result. I can create an array with x,y,z triplets. x,y are on a regularly spaced raster, z is a RandomReal. For sorting the array according to the z values, I found two options, the second of which is significantly faster. However, my goal is not to sort, but to calculate the rank of the z value within the triplet. For example: original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} convert to: {0,0,2},{0,1,1},{1,1,3} $B*(B 2.3 is the smallest z-value, hence it gets assigned rank 1 > In my case I can reach this converted array only with extra steps: - separating the z-values from Ar, - calculating the (standardized) RanksOfAr, - gluing the triplets back together. > Is there a way to to this in one step? Claus > Here is the mathematica code: ----------------------------- > Make up an array with (x, y) being coordinates and z being a value at that (x, y) location > Ar = Partition[Flatten[Table[{i, j, k}, {i, 1, 10} , {j, 1, 10} , {k, {RandomReal[]}} ]], 3]; Time two versions of Sorting the array Ar according to z > Timing[SortBottomAATriples = Sort[Ar, #1[[3]] < #2[[3]] &]]; > sll[ll_, elem_] := ll[[Ordering[ll[[All, elem]]]]] Timing[OrdBotAATrip = sll[Ar, 3]]; > Create the Ranks of z at the original position from Ar > those ranks are scaled between [0, 1] > RanksOfAr = Ordering[SortBottomAATriples]/Length[SortBottomAATriples]; > Procedure to put it all back together > x = Ar[[All, 1]]; y = Ar[[All, 2]]; FinalAr = Transpose[{x, y, RanksOfAr}] // N; > [Hyphen][Hyphen] [Times]® ÃòáéCarter === Subject: Re: Ranks for an array of triplets > I can create an array with x,y,z triplets. x,y are on a regularly spaced > raster, z is a RandomReal. > For sorting the array according to the z values, I found two options, > the second of which is significantly faster. > However, my goal is not to sort, but to calculate the rank of the z > value within the triplet. > For example: > original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} > convert to: {0,0,2},{0,1,1},{1,1,3} > .89ºâ 2.3 is the smallest z-value, hence it gets assigned rank 1 > > In my case I can reach this converted array only with extra steps: > - separating the z-values from Ar, > - calculating the (standardized) RanksOfAr, > - gluing the triplets back together. > > Is there a way to to this in one step? The following should do it. myRank[lst_List] := Module[ {ar = lst}, ar[[All, 3]] = Ordering[ar, All, #1[[3]] < #2[[3]] &]; ar] triples = {{0, 0, 9.8}, {0, 1, 2.3}, {1, 1, 12.6}}; myRank[triples] => {{0, 0, 2}, {0, 1, 1}, {1, 1, 3}} > Claus > > Here is the mathematica code: > ----------------------------- > > Make up an array with (x, y) being coordinates and z being a value at > that (x, y) location > > Ar = Partition[Flatten[Table[{i, j, k}, > {i, 1, 10} > , {j, 1, 10} > , {k, {RandomReal[]}} > ]], 3]; A more efficient (at least two times faster) version of the above is Ar = Sequence @@@ Table[{i, j, RandomReal[]}, {i, 1, 100}, {j, 1, 100}]; > Time two versions of Sorting the array Ar according to z > > Timing[SortBottomAATriples = Sort[Ar, #1[[3]] < #2[[3]] &]]; > > sll[ll_, elem_] := ll[[Ordering[ll[[All, elem]]]]] > Timing[OrdBotAATrip = sll[Ar, 3]]; > > Create the Ranks of z at the original position from Ar > > those ranks are scaled between [0, 1] > > RanksOfAr = Ordering[SortBottomAATriples]/Length[SortBottomAATriples]; > > Procedure to put it all back together > > x = Ar[[All, 1]]; > y = Ar[[All, 2]]; > FinalAr = Transpose[{x, y, RanksOfAr}] // N; -- === Subject: Re: Ranks for an array of triplets > I can create an array with x,y,z triplets. x,y are on a regularly spaced > raster, z is a RandomReal. > For sorting the array according to the z values, I found two options, > the second of which is significantly faster. > However, my goal is not to sort, but to calculate the rank of the z > value within the triplet. > For example: > original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} > convert to: {0,0,2},{0,1,1},{1,1,3} > .89ºâ 2.3 is the smallest z-value, hence it gets assigned rank 1 In my case I can reach this converted array only with extra steps: > - separating the z-values from Ar, > - calculating the (standardized) RanksOfAr, > - gluing the triplets back together. Is there a way to to this in one step? Claus Here is the mathematica code: > ----------------------------- Make up an array with (x, y) being coordinates and z being a value at > that (x, y) location Ar = Partition[Flatten[Table[{i, j, k}, > {i, 1, 10} > , {j, 1, 10} > , {k, {RandomReal[]}} > ]], 3]; > Time two versions of Sorting the array Ar according to z Timing[SortBottomAATriples = Sort[Ar, #1[[3]] < #2[[3]] &]]; sll[ll_, elem_] := ll[[Ordering[ll[[All, elem]]]]] > Timing[OrdBotAATrip = sll[Ar, 3]]; Create the Ranks of z at the original position from Ar those ranks are scaled between [0, 1] RanksOfAr = Ordering[SortBottomAATriples]/Length[SortBottomAATriples]; Procedure to put it all back together x = Ar[[All, 1]]; > y = Ar[[All, 2]]; > FinalAr = Transpose[{x, y, RanksOfAr}] // N; > One possibility is to make a copy of Ar FinalAr2 = Ar; and then replace the last column of that copy with the scaled ranks. FinalAr2[[All, -1]] = Ordering[Ordering[Ar, All, #[[-1]] < #2[[-1]] &]]/Length[Ar]; Then FinalAr2 will be the desired matrix. That's technically two steps, but the first one is pretty easy. Darren Glosemeyer Wolfram Research === Subject: Re: Ranks for an array of triplets > I can create an array with x,y,z triplets. x,y are on a regularly > spaced > raster, z is a RandomReal. > For sorting the array according to the z values, I found two options, > the second of which is significantly faster. > However, my goal is not to sort, but to calculate the rank of the z > value within the triplet. > For example: > original array Ar: {0,0,9.8},{0,1,2.3},{1,1,12.6} > convert to: {0,0,2},{0,1,1},{1,1,3} > =E2=86=92 2.3 is the smallest z-value, hence it gets assigned rank 1 In my case I can reach this converted array only with extra steps: > - separating the z-values from Ar, > - calculating the (standardized) RanksOfAr, > - gluing the triplets back together. Is there a way to to this in one step? You can combine all the steps into one expression but the individual operations still need to be done. You don't need to to pull the array completely apart and put it back together, just join the first two columns of the first array and the rank list then flatten the subelements. FinalAr=Flatten /@ Transpose[{Ar[[All, {1, 2}]], With[{len = Length[Ar]}, N[Ordering[Ar, len, #1[[3]] < #2[[3]] &]/= len]]}] Alternatively if you don't need the original matrix you can destructively assign the ranks back into it. Ar[[All,3]=With[{len = Length[Ar]}, N[Ordering[Ar, len, #1[[3]] < #2= [[3]] &]/len]] Ssezi === Subject: Re: Problem for using Epilog to plot legend I didn't quite see what the legend had to do with the plot. But in any case, with Presentations it is convenient to simply draw the legend lines on the plot as additional elements. Needs[Presentations`Master`] Draw2D[ {ListDraw[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, PlotMarkers -> Automatic, PlotStyle -> {Black, Darker@Red}], (* Draw legend *) Black, Line[Scaled /@ {{.1, .8}, {.3, .8}}], Text[a, Scaled[{.35, .8}]], Darker@Red, Line[Scaled /@ {{.1, .7}, {.3, .7}}], Text[b, Scaled[{.35, .7}]]}, AspectRatio -> 1/GoldenRatio, Axes -> True, PlotRange -> {{0, 5.1}, {0, 10}}, BaseStyle -> {FontSize -> 12}] Or, in this case, it might be more direct to simply label the two curves. Version 6.0.2 has a graphics tool for picking off coordinates (but it gives you an extra set of brackets that must be edited out) and Presentations has a LocatorDraw feature that gives you a temporary Locator and display for picking off coordinates. Draw2D[ {ListDraw[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, PlotMarkers -> Automatic, PlotStyle -> {Black, Darker@Red}], (* Label Curves *) Text[Style[a, 16], {4.26069, 6.55068}], Text[Style[b, 16], {3.14569, 7.37447}]}, AspectRatio -> 1/GoldenRatio, Axes -> True, PlotRange -> {{0, 5.1}, {0, 10}}, BaseStyle -> {FontSize -> 12}, ImageSize -> 350] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ i want to use Epilog to plot a legend,but i have a problem for the > Line command. ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, > PlotMarkers -> Automatic, > Epilog - Inset[Framed@ > Column[{Graphics[{DotDashed, Line[{{1, 0}, {2, 0}}]}] Style[a], > Graphics[{Dotted, Line[{{1, 0}, {2, 0}}]}] Style[b]}, > Spacings -> 0, ItemSize -> {15, 0.5}], {1.25, 7}]] the space between different rows in legend area are really large, but if i change the Line condition,such like below ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, > PlotMarkers -> Automatic, > Epilog - Inset[Framed@ > Column[{Graphics[{DotDashed, Line[{{100, 0}, {2, 0}}]}] > Style[a], > Graphics[{Dotted, Line[{{100, 0}, {2, 0}}]}] Style[b]}, > Spacings -> 0, ItemSize -> {15, 0.5}], {1.25, 7}]] the rows became close to each other, but the length of the lines became > too long how can i solve this? thank you > === Subject: Re: Problem for using Epilog to plot legend >i want to use Epilog to plot a legend,but i have a problem for the >Line command. >ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, >PlotMarkers -> Automatic, Epilog -> Inset[Framed@ >Column[{Graphics[{DotDashed, Line[{{1, 0}, {2, 0}}]}] Style[a], >Graphics[{Dotted, Line[{{1, 0}, {2, 0}}]}] Style[b]}, Spacings -0, ItemSize -> {15, 0.5}], {1.25, 7}]] >the space between different rows in legend area are really large, >but if i change the Line condition,such like below >ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, >PlotMarkers -> Automatic, Epilog -> Inset[Framed@ >Column[{Graphics[{DotDashed, Line[{{100, 0}, {2, 0}}]}] Style[a], >Graphics[{Dotted, Line[{{100, 0}, {2, 0}}]}] Style[b]}, Spacings >-> 0, ItemSize -> {15, 0.5}], {1.25, 7}]] >the rows became close to each other, but the length of the lines >became too long >how can i solve this? My approach would be to use Text instead of Style and specify placement of all of the elements rather than use Column to line things up. For example, ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True, PlotMarkers -> Automatic, Epilog -> Inset[Framed@ Graphics[{DotDashed, Line[{{5, 0}, {2, 0}}], Text[a, {5.1, 0}, {1, 0}], Dotted, Line[{{5, -.5}, {2, -.5}}], Text[b, {5.1, -.5}, {1, 0}]}], {1.5, 7}, {0, 0}, 1.5]] === Subject: Re: Pattern problem: How to count from a long list of numbers Reply-to: drmajorbob@longhorns.com For those of you, like me, who need a little help understanding Carl's always brilliant code, here's a cheat-sheet of sorts. First, the original: pairCount[data_, p1_, p2_] := Total@BitAnd[ Clip[Clip[Most@data, {p1, p1}, {p1 - 2, p1 - 2}], {p1 - 1, p1 - 1}, {0, 1}], Clip[Clip[Rest@data, {p2, p2}, {p2 - 2, p2 - 2}], {p2 - 1, p2 - 1}, {0, 1}]] Next, a parsing of that. straddle[data,p] changes everything that's NOT p to p-2, binaryMark changes that to 0s and 1s, and pairCount2 uses Total and BitAnd to compare binaryMark for Most@data to binaryMark for Rest@data. straddle[data_, p_] := Clip[data, {p, p}, {p - 2, p - 2}] binaryMark2[data_, p_] := Clip[straddle[data, p], {p - 1, p - 1}, {0, 1}] pairCount2[data_, p1_, p2_] := Total@BitAnd[binaryMark2[Most@data, p1], binaryMark2[Rest@data, p2]] That's exactly the same as Carl's solution, except for the compartmentalization of code. Third, here's my initial solution to the same problem, with a simpler binaryMark: binaryMark3[data_, p_] := 1 - Unitize@Sign[data - p] pairCount3[data_, p1_, p2_] := Total@BitAnd[binaryMark3[Most@data, p1], binaryMark3[Rest@data, p2]] A one-liner version of that: pairCount4[data_, p1_, p2_] := Total@BitAnd[1 - Unitize@Sign[Most@data - p1], 1 - Unitize@Sign[Rest@data - p2]] And a faster one-liner: pairCount5[data_, p1_, p2_] := Length@data - 1 - Total@BitOr[Unitize@Sign[Most@data - p1], Unitize@Sign[Rest@data - p2]] Finally, some timings: sample[n_] := RandomInteger[{1, 5}, n] times[n_, p1_, p2_] := With[{data = sample@n}, {Timing@pairCount[data, p1, p2], Timing@pairCount2[data, p1, p2], Timing@pairCount3[data, p1, p2], Timing@pairCount4[data, p1, p2], Timing@pairCount5[data, p1, p2]}] times[10^7, 2, 3] {{0.680051, 399704}, {0.683036, 399704}, {1.2015, 399704}, {1.19743, 399704}, {0.684635, 399704}} times[10^7, 2, 1] {{0.652513, 398875}, {0.65154, 398875}, {1.19801, 398875}, {1.20221, 398875}, {0.687839, 398875}} My final version is almost as fast as Carl's original, and for me, that's a VERY good day. Bobby > Hello; >> I think using Pattern is my weakest point in Mathematica. >> I have this list, say this: (it is all a list of integers, no real >> numbers). >> x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3} >> And I want to count how many say a 3 followed immediately by 3. So in >> the >> above list, there will be 4 such occurrences. And if I want to count how >> many 1 followed by a 3, there will be 2 such cases, etc... >> I tried Count[] but I do not know how to set the pattern for 3 >> followed by >> a comma followed by 3 or just 3 followed immediately by 3. >> I tried few things, such as the following >> In[68]:= Count[x, {3, 3}_] >> Out[68]= 0 >> Also tried Cases, but again, I am not to good with Patterns, so not >> sure how >> to set this up at this moment. >> Any ideas will be appreciated. >> Nasser >> I really need to sit down and study Patterns in Mathematica really well >> one >> day :) > If you have long lists and would like this to be very quick, I would do > this by basically finding out the locations of the first and second > elements, and seeing where the two line up. Here is a function that will > do this: pairCount[data_, p1_, p2_] := Total @ BitAnd[ > Clip[Clip[Most[data], {p1, p1}, {p1 - 2, p1 - 2}], {p1 - 1, p1 - 1}, > {0, 1}], > Clip[Clip[Rest[data], {p2, p2}, {p2 - 2, p2 - 2}], {p2 - 1, p2 - 1}, > {0, 1}] > ] A couple examples: In[146]:= pairCount[{1, 3, 3, 3, 2, 3, 3, 1, 3, 3}, 3, 3] Out[146]= 4 In[147]:= pairCount[{1, 3, 3, 3, 2, 3, 3, 1, 3, 3}, 1, 3] Out[147]= 2 Carl Woll > Wolfram Research -- = DrMajorBob@longhorns.com === Subject: Re: color scale for plot I don't think there is an option to do this, but you could construct it yourself with something like this (this is what I've used): ArrayPlot[Table[i/256, {j, 1, 24}, {i, 1, 256}], BaseStyle -> Small, ColorFunction -> TheParticularColorFunctionYouUsed, PlotLabel -> My Scale] And then insert the graphic into your plot. Drawing Tools may be useful. > Hi everyone, I was wondering if there is any simple way to add a color scale > associated to a 3D plot (something like a bar with a color and a > labelled axis corresponding to the z coordinate). I am interested > especially in ListPlot3D, ListPointPlot3D, and ListContourPlot. Adrian > -- W. Craig Carter === Subject: color scale for plot Hi everyone, I was wondering if there is any simple way to add a color scale associated to a 3D plot (something like a bar with a color and a labelled axis corresponding to the z coordinate). I am interested especially in ListPlot3D, ListPointPlot3D, and ListContourPlot. Adrian === Subject: Re: color scale for plot On 2008-04-12 20:41:29 +0930, Adrian Lupascu = said: > I was wondering if there is any simple way to add a color scale > associated to a 3D plot (something like a bar with a color and a > labelled axis corresponding to the z coordinate). I am interested > especially in ListPlot3D, ListPointPlot3D, and ListContourPlot. Hi Adrian, I'm just finishing up a beta version of my colorbarplot that currently adds colorbars to contourplots/densityplots and 3d plots: The new version already supports ListPlot3D and ListContourPlot. I'd be interested in adding ListPointPlot3D to the package, as well. When I squash a couple of bugs I'll send you a copy. Take care, Will === Subject: Re: EdgeRenderingFunction to produce edge labels in GraphPlot >I'm having trouble fathoming from the documentation how >EdgeRenderingFunction works. In a display produced by GraphPlot, >applied to a graph that's a Graph object created with Combinatorica, I >want to be able to put distinct labels on the edges. For example, take something very simple: g = Cycle[3]; I'd like to put labels a, b, c on the three {1,2}, {2,3}, {3,1}, >respectively. Here's what I tried finally: labels = Characters[abc]; > edgeLabelFunction[{u_, v_}] := > labels[[First@Flatten@Position[Edges[Cycle[3]], {u, v}]]] offset={0.05,0.05}; (* to move labels away from edges *) GraphPlot[g, Method -> None, > EdgeRenderingFunction -> ({ > Line[#1], > Inset[edgeLabelFunction[#2], Mean[#1] + offset] > ]} &) > ] This does not work. How, exactly, do I index into the list of edges... Edges[g] > {{1,2},{2,3},{1,3}} EdgeRenderingFunction, it seems to me that argument #2 is supposed to be >the length 2 list {u,v} of vertices with which the edge is incident. > It seems that GraphPlot conversions of Combinatorica graphs with edge labels isn't working. Otherwise you could use the Combinatorica function SetEdgeLabels on the graph and then display using EdgeLabeling->True. One possibility is to manipulate the Graph object produced by Combinatorica into a form suitable for GraphPlot. Here is an example: g = SetEdgeLabels[Cycle[3], {a, b, c}]; g = Replace[First@g, {{a_, b_}, opts___} :> (If[MatchQ[#, EdgeLabel], a -> b, {a -> b, #}] &[EdgeLabel /. {opts}]), {1}]; GraphPlot[g, EdgeLabeling -> True] The alternative as you tried to do, is to add the edge labels using EdgeRenderingFunction First, here's a close facsimile to the default EdgeRenderingFunction: EdgeRenderingFunction -> ({ RGBColor[0.5, 0, 0], Arrowheads[{{0.5, 0.5, Graphics[{Black, Inset[Style[#3], {0, 0}, ImageScaled[{0.5, 0.5}], Automatic, None, Background -> White]}]}, {0.03, 0.8}}], Arrow[#1] }&) Now, it's best if the Combinatorica graph is directed (otherwise GraphPlot will try to label it in both directions). So, g = Cycle[3, Type -> Directed]; labels = Characters[abc]; edgeLabelFunction[{u_, v_}] := labels[[First@Flatten@Position[Edges[Cycle[3, Type -> Directed]], {u, v}]]] GraphPlot[g, EdgeRenderingFunction -> ({RGBColor[0.5, 0, 0], Arrowheads[{{0.5, 0.5, Graphics[{Black, Inset[Style[edgeLabelFunction[#2]], {0, 0}, ImageScaled[{0.5, 0.5}], Automatic, None, Background -> White]}]}, {0.03, 0.8}}], Arrow[#1]} &)] Carl Woll Wolfram Research === Subject: EdgeRenderingFunction to produce edge labels in GraphPlot I'm having trouble fathoming from the documentation how EdgeRenderingFunction works. In a display produced by GraphPlot, applied to a graph that's a Graph object created with Combinatorica, I want to be able to put distinct labels on the edges. For example, take something very simple: g = Cycle[3]; I'd like to put labels a, b, c on the three {1,2}, {2,3}, {3,1}, respectively. Here's what I tried finally: labels = Characters[abc]; edgeLabelFunction[{u_, v_}] := labels[[First@Flatten@Position[Edges[Cycle[3]], {u, v}]]] offset={0.05,0.05}; (* to move labels away from edges *) GraphPlot[g, Method -> None, EdgeRenderingFunction -> ({ Line[#1], Inset[edgeLabelFunction[#2], Mean[#1] + offset] ]} &) ] This does not work. How, exactly, do I index into the list of edges... Edges[g] {{1,2},{2,3},{1,3}} EdgeRenderingFunction, it seems to me that argument #2 is supposed to be the length 2 list {u,v} of vertices with which the edge is incident. -- 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: what does Method->HighDimensionalEmbedding actually similar, private, response from another MathGroup subscriber.) Unresolved, though, is a more fundamental functionality issue: how to get Mathematica directly to display a planar graph by means of a planar embedding (i.e., no edges intersect except at their common vertices) -- without manual intervention by the user. There are well-known methods for determining whether a given graph is planar (including Kuratowski's Theorem), and I presume Combinatorica`PlanarQ already implements such a method. But actually constructing a plane embedding of such a graph is another matter. I had hoped that Mathematica could do this at least for relatively simple graphs. It seems no. > The default display of the graph causes some of its edges to lie on top of > each other. If you click down to node 3 (3 clicks on the graphic of node 3) > you can then click-drag it sideways to reveal all of the edges. > > Stephen Luttrell > West Malvern, UK > >> What, exactly, is the HighDimensionalEmbeedding value for the >> GraphPlot option Method? >> And why does the following produce a display that seems to be wrong: the >> displayed graph has only 5 edges instead of the expected 6 for the >> complete graph on 4 vertices? >> GraphPlot[CompleteGraph[4], Method -> HighDimensionalEmbedding, >> VertexLabeling -> True] >> -- >> 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 > > -- 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: what does Method->HighDimensionalEmbedding actually do for Hi Murray, http://www.research.att.com/areas/visualization/papers_videos/pdf/DBLP-journ als-jgaa-HarelK04.pdf may help. Jens > What, exactly, is the HighDimensionalEmbeedding value for the > GraphPlot option Method? > > And why does the following produce a display that seems to be wrong: the > displayed graph has only 5 edges instead of the expected 6 for the > complete graph on 4 vertices? > > GraphPlot[CompleteGraph[4], Method -> HighDimensionalEmbedding, > VertexLabeling -> True] === Subject: Re: what does Method->HighDimensionalEmbedding actually do for GraphPlot? The default display of the graph causes some of its edges to lie on top of each other. If you click down to node 3 (3 clicks on the graphic of node 3) you can then click-drag it sideways to reveal all of the edges. Stephen Luttrell West Malvern, UK > What, exactly, is the HighDimensionalEmbeedding value for the > GraphPlot option Method? And why does the following produce a display that seems to be wrong: the > displayed graph has only 5 edges instead of the expected 6 for the > complete graph on 4 vertices? GraphPlot[CompleteGraph[4], Method -> HighDimensionalEmbedding, > VertexLabeling -> True] > -- > 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: Cannot Factor an expression If Factor is effectively the reverse of expand, then how come factor cannot find back the expression below? Expand[Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}]] Factor[-3*[Mu]^2 + 2*[Mu]*Subscript[x, 1] - Subscript[x, 1]^2 + 2*[Mu]*Subscript[x, 2] - Subscript[x, 2]^2 + 2*[Mu]*Subscript[x, 3] - Subscript[x, 3]^2 + [Mu]^2*Subscript[z, 1] - 2*[Mu]*Subscript[x, 1]*Subscript[z, 1] + Subscript[x, 1]^2* Subscript[z, 1] + [Mu]^2*Subscript[z, 2] - 2*[Mu]*Subscript[x, 2]*Subscript[z, 2] + Subscript[x, 2]^2* Subscript[z, 2] + [Mu]^2*Subscript[z, 3] - 2*[Mu]*Subscript[x, 3]*Subscript[z, 3] + Subscript[x, 3]^2* Subscript[z, 3]] Is there some additional arguments to the function factor so that it can find back the original: Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] === Subject: Re: Cannot Factor an expression Syd, Formally you are right but, if you evaluate my input (without {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]}) you will see that it actually works. The official syntax for PolynomialReduce was changed in version 6, and now you are supposed to list the variables. In version 5 this was optional. In any case, if you do not list the variables, in other words, if you use the syntax PolynomialReduce[f[x,y,..],g[x,y,...]] instead of PolynomialReduce[f[x,y,..],g[x,y,...],{x,y,...}] Mathematica will itself deduce the variables and evaluate the output correctly. This is, in principle, less reliable, which is the reason for the change in version 6, but the old way still works. Partly through laziness and partly thorugh getting used to the older syntax I often forget to list the variables. get me into trouble although so far it never has ;-) Andrzej > Andrzej, There was a syntax problem with your PolynomialReduce function > below ... (complete inputs) should have been:- q = Sum[(Subscript[z, i] - 1)*(=CE=BC - Subscript[x, i])^2, {i, 1, 3}] p = Expand[q] Factor[First[ > PolynomialReduce[ > p, {Subscript[z, 1] - 1, Subscript[z, 2] - 1, > Subscript[z, 3] - 1}, {Subscript[x, 1], Subscript[x, 2], > Subscript[x, > 3]}]]].{Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] > - 1} > There is a missing , {Subscript[x, 1], Subscript[x, 2], > Subscript[x, 3]}] It seems your postings are sometimes missing lines because I am sure > you would have tested your function yet it clearly fails 6.0.2's > syntax checking. HTH Syd > Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.1 for Mac OS X x86 (64 - bit) (June 19, 2007) > MacOS X V 10.5 .20 > I got my p's and q's mixed up in addition to having some garbled >> input. So here we go again: >> q = Sum[(Subscript[z, i] - 1)* >> ([Mu] - Subscript[x, i])^2, {i, 1, 3}] >> (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + >> ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + >> ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) >> In[2]:= >> p = Expand[q]; >> Factor[First[PolynomialReduce[p, >> {Subscript[z, 1] - 1, Subscript[z, 2] - 1, >> Subscript[z, 3] - 1}]]] . >> {Subscript[z, 1] - 1, Subscript[z, 2] - 1, >> Subscript[z, 3] - 1} >> (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + >> ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + >> ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) >> All free and no need to load any Add On packages ;-) >> Andrzej Kozlowski > Factor is not effectively the reverse of Expand, except in the > case > of when you expand an expression that has been factored in *the > usual > sense*, in other words, into multiplicative factors (don't forget > that > a factor is the same thing as a divisor). Other kinds of > pseudo- > factorizations, like the one you want, are not unique, and > Mathematica can't read your mind to find out which one you like > best. > For example: q = Sum[(Subscript[z, i] - 1)*(=CE=BC - Subscript[x, i])^2, {i, 1, > 3}] (Subscript[z, 1] - 1)*(=CE=BC - Subscript[x, 1])^2 + > (=CE=BC - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + > (=CE=BC - Subscript[x, 3])^2*(Subscript[z, 3] - 1) p = Expand[q]; FullSimplify[p] (Subscript[z, 1] + Subscript[z, 2] + Subscript[z, 3] - 3)*[Mu]^2 - > 2*Subscript[x, 1]*(Subscript[z, 1] - 1)*[Mu] - > 2*Subscript[x, 2]*(Subscript[z, 2] - 1)*[Mu] - > 2*Subscript[x, 3]*(Subscript[z, 3] - 1)*[Mu] + > Subscript[x, 1]^2*(Subscript[z, 1] - 1) + > Subscript[x, 2]^2*(Subscript[z, 2] - 1) + > Subscript[x, 3]^2*(Subscript[z, 3] - 1) in by many criteria not worse then the one you want. However, there is, in fact, a way to get the form q by starting > from > p, as long as you know that that is what you want: > Factor[First[PolynomialReduce[q, {Subscript[z, 1] - 1, > Subscript[z, 2] - 1, Subscript[z, 3] - 1}]]] . > {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1} (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + > ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + > ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) Andrzej Kozlowski >> If Factor is effectively the reverse of expand, then how come >> factor >> cannot find back the expression below? >> Expand[Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, >> 1, >> 3}]] >> Factor[-3*[Mu]^2 + 2*[Mu]*Subscript[x, 1] - Subscript[x, 1]^2 + >> 2*[Mu]*Subscript[x, 2] - Subscript[x, 2]^2 + 2*[Mu]*Subscript[x, >> 3] - >> Subscript[x, 3]^2 + [Mu]^2*Subscript[z, 1] - >> 2*[Mu]*Subscript[x, 1]*Subscript[z, 1] + Subscript[x, 1]^2* >> Subscript[z, 1] + [Mu]^2*Subscript[z, 2] - >> 2*[Mu]*Subscript[x, 2]*Subscript[z, 2] + Subscript[x, 2]^2* >> Subscript[z, 2] + [Mu]^2*Subscript[z, 3] - >> 2*[Mu]*Subscript[x, 3]*Subscript[z, 3] + Subscript[x, 3]^2* >> Subscript[z, 3]] >> Is there some additional arguments to the function factor so that >> it >> can find back the original: >> Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] > === Subject: Re: Cannot Factor an expression Andrzej, There was a syntax problem with your PolynomialReduce function below ... (complete inputs) should have been:- q = Sum[(Subscript[z, i] - 1)*(=CE=BC - Subscript[x, i])^2, {i, 1, 3}] p = Expand[q] Factor[First[ PolynomialReduce[ p, {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]}]]].{Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1} There is a missing , {Subscript[x, 1], Subscript[x, 2], Subscript[x, = 3]}] It seems your postings are sometimes missing lines because I am sure you would have tested your function yet it clearly fails 6.0.2's syntax checking. HTH Syd Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.1 for Mac OS X x86 (64 - bit) (June 19, 2007) MacOS X V 10.5 .20 > I got my p's and q's mixed up in addition to having some garbled > input. So here we go again: > q = Sum[(Subscript[z, i] - 1)* > ([Mu] - Subscript[x, i])^2, {i, 1, 3}] (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + > ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + > ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) > In[2]:= > p = Expand[q]; > Factor[First[PolynomialReduce[p, > {Subscript[z, 1] - 1, Subscript[z, 2] - 1, > Subscript[z, 3] - 1}]]] . > {Subscript[z, 1] - 1, Subscript[z, 2] - 1, > Subscript[z, 3] - 1} (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + > ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + > ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) > All free and no need to load any Add On packages ;-) Andrzej Kozlowski >> Factor is not effectively the reverse of Expand, except in the case >> of when you expand an expression that has been factored in *the usual >> sense*, in other words, into multiplicative factors (don't forget >> that >> a factor is the same thing as a divisor). Other kinds of pseudo- >> factorizations, like the one you want, are not unique, and >> Mathematica can't read your mind to find out which one you like best. >> For example: >> q = Sum[(Subscript[z, i] - 1)*(=CE=BC - Subscript[x, i])^2, {i, = 1, >> 3}] >> (Subscript[z, 1] - 1)*(=CE=BC - Subscript[x, 1])^2 + >> (=CE=BC - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + >> (=CE=BC - Subscript[x, 3])^2*(Subscript[z, 3] - 1) >> p = Expand[q]; >> FullSimplify[p] >> (Subscript[z, 1] + Subscript[z, 2] + Subscript[z, 3] - 3)*[Mu]^2 - >> 2*Subscript[x, 1]*(Subscript[z, 1] - 1)*[Mu] - >> 2*Subscript[x, 2]*(Subscript[z, 2] - 1)*[Mu] - >> 2*Subscript[x, 3]*(Subscript[z, 3] - 1)*[Mu] + >> Subscript[x, 1]^2*(Subscript[z, 1] - 1) + >> Subscript[x, 2]^2*(Subscript[z, 2] - 1) + >> Subscript[x, 3]^2*(Subscript[z, 3] - 1) >> in by many criteria not worse then the one you want. >> However, there is, in fact, a way to get the form q by starting from >> p, as long as you know that that is what you want: >> Factor[First[PolynomialReduce[q, {Subscript[z, 1] - 1, >> Subscript[z, 2] - 1, Subscript[z, 3] - 1}]]] . >> {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1} >> (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + >> ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + >> ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) >> Andrzej Kozlowski > If Factor is effectively the reverse of expand, then how come factor > cannot find back the expression below? Expand[Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, > 3}]] Factor[-3*[Mu]^2 + 2*[Mu]*Subscript[x, 1] - Subscript[x, 1]^2 + > 2*[Mu]*Subscript[x, 2] - Subscript[x, 2]^2 + 2*[Mu]*Subscript[x, > 3] - > Subscript[x, 3]^2 + [Mu]^2*Subscript[z, 1] - > 2*[Mu]*Subscript[x, 1]*Subscript[z, 1] + Subscript[x, 1]^2* > Subscript[z, 1] + [Mu]^2*Subscript[z, 2] - > 2*[Mu]*Subscript[x, 2]*Subscript[z, 2] + Subscript[x, 2]^2* > Subscript[z, 2] + [Mu]^2*Subscript[z, 3] - > 2*[Mu]*Subscript[x, 3]*Subscript[z, 3] + Subscript[x, 3]^2* > Subscript[z, 3]] Is there some additional arguments to the function factor so that it > can find back the original: > Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] === Subject: Re: Cannot Factor an expression I got my p's and q's mixed up in addition to having some garbled input. So here we go again: q = Sum[(Subscript[z, i] - 1)* ([Mu] - Subscript[x, i])^2, {i, 1, 3}] (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) In[2]:= p = Expand[q]; Factor[First[PolynomialReduce[p, {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1}]]] . {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1} (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) All free and no need to load any Add On packages ;-) Andrzej Kozlowski > Factor is not effectively the reverse of Expand, except in the case > of when you expand an expression that has been factored in *the usual > sense*, in other words, into multiplicative factors (don't forget that > a factor is the same thing as a divisor). Other kinds of pseudo- > factorizations, like the one you want, are not unique, and > Mathematica can't read your mind to find out which one you like best. > For example: q = Sum[(Subscript[z, i] - 1)*(=CE=BC - Subscript[x, i])^2, {i, 1, 3}] (Subscript[z, 1] - 1)*(=CE=BC - Subscript[x, 1])^2 + > (=CE=BC - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + > (=CE=BC - Subscript[x, 3])^2*(Subscript[z, 3] - 1) p = Expand[q]; FullSimplify[p] (Subscript[z, 1] + Subscript[z, 2] + Subscript[z, 3] - 3)*[Mu]^2 - > 2*Subscript[x, 1]*(Subscript[z, 1] - 1)*[Mu] - > 2*Subscript[x, 2]*(Subscript[z, 2] - 1)*[Mu] - > 2*Subscript[x, 3]*(Subscript[z, 3] - 1)*[Mu] + > Subscript[x, 1]^2*(Subscript[z, 1] - 1) + > Subscript[x, 2]^2*(Subscript[z, 2] - 1) + > Subscript[x, 3]^2*(Subscript[z, 3] - 1) in by many criteria not worse then the one you want. However, there is, in fact, a way to get the form q by starting from > p, as long as you know that that is what you want: > Factor[First[PolynomialReduce[q, {Subscript[z, 1] - 1, > Subscript[z, 2] - 1, Subscript[z, 3] - 1}]]] . > {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1} (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + > ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + > ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) Andrzej Kozlowski >> If Factor is effectively the reverse of expand, then how come factor >> cannot find back the expression below? >> Expand[Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, >> 3}]] >> Factor[-3*[Mu]^2 + 2*[Mu]*Subscript[x, 1] - Subscript[x, 1]^2 + >> 2*[Mu]*Subscript[x, 2] - Subscript[x, 2]^2 + 2*[Mu]*Subscript[x, >> 3] - >> Subscript[x, 3]^2 + [Mu]^2*Subscript[z, 1] - >> 2*[Mu]*Subscript[x, 1]*Subscript[z, 1] + Subscript[x, 1]^2* >> Subscript[z, 1] + [Mu]^2*Subscript[z, 2] - >> 2*[Mu]*Subscript[x, 2]*Subscript[z, 2] + Subscript[x, 2]^2* >> Subscript[z, 2] + [Mu]^2*Subscript[z, 3] - >> 2*[Mu]*Subscript[x, 3]*Subscript[z, 3] + Subscript[x, 3]^2* >> Subscript[z, 3]] >> Is there some additional arguments to the function factor so that it >> can find back the original: >> Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] === Subject: Re: Cannot Factor an expression Factor is not effectively the reverse of Expand, except in the case of when you expand an expression that has been factored in *the usual sense*, in other words, into multiplicative factors (don't forget that a factor is the same thing as a divisor). Other kinds of pseudo- factorizations, like the one you want, are not unique, and Mathematica can't read your mind to find out which one you like best. For example: q = Sum[(Subscript[z, i] - 1)*(=CE=BC - Subscript[x, i])^2, {i, 1, 3}] (Subscript[z, 1] - 1)*(=CE=BC - Subscript[x, 1])^2 + (=CE=BC - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + (=CE=BC - Subscript[x, 3])^2*(Subscript[z, 3] - 1) p = Expand[q]; FullSimplify[p] (Subscript[z, 1] + Subscript[z, 2] + Subscript[z, 3] - 3)*[Mu]^2 - 2*Subscript[x, 1]*(Subscript[z, 1] - 1)*[Mu] - 2*Subscript[x, 2]*(Subscript[z, 2] - 1)*[Mu] - 2*Subscript[x, 3]*(Subscript[z, 3] - 1)*[Mu] + Subscript[x, 1]^2*(Subscript[z, 1] - 1) + Subscript[x, 2]^2*(Subscript[z, 2] - 1) + Subscript[x, 3]^2*(Subscript[z, 3] - 1) in by many criteria not worse then the one you want. However, there is, in fact, a way to get the form q by starting from p, as long as you know that that is what you want: Factor[First[PolynomialReduce[q, {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1}]]] . {Subscript[z, 1] - 1, Subscript[z, 2] - 1, Subscript[z, 3] - 1} (Subscript[z, 1] - 1)*([Mu] - Subscript[x, 1])^2 + ([Mu] - Subscript[x, 2])^2*(Subscript[z, 2] - 1) + ([Mu] - Subscript[x, 3])^2*(Subscript[z, 3] - 1) Andrzej Kozlowski > If Factor is effectively the reverse of expand, then how come factor > cannot find back the expression below? Expand[Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, > 3}]] Factor[-3*[Mu]^2 + 2*[Mu]*Subscript[x, 1] - Subscript[x, 1]^2 + > 2*[Mu]*Subscript[x, 2] - Subscript[x, 2]^2 + 2*[Mu]*Subscript[x, > 3] - > Subscript[x, 3]^2 + [Mu]^2*Subscript[z, 1] - > 2*[Mu]*Subscript[x, 1]*Subscript[z, 1] + Subscript[x, 1]^2* > Subscript[z, 1] + [Mu]^2*Subscript[z, 2] - > 2*[Mu]*Subscript[x, 2]*Subscript[z, 2] + Subscript[x, 2]^2* > Subscript[z, 2] + [Mu]^2*Subscript[z, 3] - > 2*[Mu]*Subscript[x, 3]*Subscript[z, 3] + Subscript[x, 3]^2* > Subscript[z, 3]] Is there some additional arguments to the function factor so that it > can find back the original: > Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] === Subject: Re: Cannot Factor an expression step1 = Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] step2 = Expand[step1] The problem is how to return step2 to the form of step1. The difficulty with the step2 expression is that the -mu^2 terms from each expansion have been added together into a single term and Mathematica doesn't know how to split it apart again. What we need to do is pick out the three sets of terms that contain the subscripts 1, 2 and 3, partition the -3 mu^2 term between them and factor. One method is to write a rule that matches the 5 terms without the -mu^2 term and then adds it back in to factor. Since by this rule mu^2 is being subtracted out three times we add 3 mu^2 to the original expression to compensate. factorrule = term : (Expand[(Subscript[z, i_] - 1)*([Mu] - Subscript[x, i_])^2] + [Mu]^2) :> Factor[term - [Mu]^2] step2 + 3 [Mu]^2 //. factorrule giving... ([Mu] - Subscript[x, 1])^2 (-1 + Subscript[z, 1]) + ([Mu] - Subscript[x, 2])^2 (-1 + Subscript[z, 2]) + ([Mu] - Subscript[x, 3])^2 (-1 + Subscript[z, 3]) The present developmental version of Presentations, which will be released in a few weeks and purchasers will receive updates, has a new section called Manipulations. It contains a set of routines that are extremely convenient for manipulating algebraic expressions. Two of these routines are MapLevelParts and MapLevelPatterns. These provide a method for applying a function to a level subset of items. This is most commonly a subset of terms in a sum. It might also be a subset of factors in a product or a subset of items in a list. The function is applied to the entire subset and not to the individual items. Then we could use MapLevelPatterns to affect the same transformation. Here we pick out subsets that are not free of specific subscript expressions. Needs[Presentations`Master`] Fold[Function[{e, i}, e // MapLevelPatterns[Factor[# - [Mu]^2] &, {{_?([Not] FreeQ[#, Subscript[z, i] | Subscript[x, i]] &)}}]], step2 + 3 [Mu]^2, {1, 2, 3}] giving... ([Mu] - Subscript[x, 1])^2 (-1 + Subscript[z, 1]) + ([Mu] - Subscript[x, 2])^2 (-1 + Subscript[z, 2]) + ([Mu] - Subscript[x, 3])^2 (-1 + Subscript[z, 3]) -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > If Factor is effectively the reverse of expand, then how come factor > cannot find back the expression below? Expand[Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, > 3}]] Factor[-3*[Mu]^2 + 2*[Mu]*Subscript[x, 1] - Subscript[x, 1]^2 + > 2*[Mu]*Subscript[x, 2] - Subscript[x, 2]^2 + 2*[Mu]*Subscript[x, > 3] - > Subscript[x, 3]^2 + [Mu]^2*Subscript[z, 1] - > 2*[Mu]*Subscript[x, 1]*Subscript[z, 1] + Subscript[x, 1]^2* > Subscript[z, 1] + [Mu]^2*Subscript[z, 2] - > 2*[Mu]*Subscript[x, 2]*Subscript[z, 2] + Subscript[x, 2]^2* > Subscript[z, 2] + [Mu]^2*Subscript[z, 3] - > 2*[Mu]*Subscript[x, 3]*Subscript[z, 3] + Subscript[x, 3]^2* > Subscript[z, 3]] Is there some additional arguments to the function factor so that it > can find back the original: > Sum[(Subscript[z, i] - 1)*([Mu] - Subscript[x, i])^2, {i, 1, 3}] === Subject: waiting for pressed key and reading key Hi everyone, I am interested to include in a program a part in which the program waits until either of two specific keys are pressed, and once this happens waiting is over and the one key (ut of the two) which was pressed determines the value of a variable. I basically want to use as a mean to read user confirmation. I figured out how to do something in this line by using a DynamicModule, with an EventHandler that wait for a mouse click. The problem I have with that is that I would prefer to use keys and also that MouseClicked event requires the cursor to be positioned over a certain expression. Any help is appreciated. Adrian -- Adrian Lupascu Centre National de la Recherche Scientifique Laboratoire Kastler Brossel Ecole Normale Sup.8erieure 24 rue Lhomond 75231 Paris CEDEX 05 Tel: +33 144323304 Fax: +33 144323434 E-mail: Adrian.Lupascu@lkb.ens.fr === Subject: Re: waiting for pressed key and reading key Hi Adrian, you may use a KeyDown event, e.g. like: EventHandler[Cursor here,{{KeyDown,a}:>(var=1;),{KeyDown,b}:>(var=2;)}] hope this helps, Daniel > Hi everyone, > > I am interested to include in a program a part in which the program > waits until either of two specific keys are pressed, and once this > happens waiting is over and the one key (ut of the two) which was > pressed determines the value of a variable. I basically want to use as a > mean to read user confirmation. > I figured out how to do something in this line by using a DynamicModule, > with an EventHandler that wait for a mouse click. The problem I have > with that is that I would prefer to use keys and also that > MouseClicked event requires the cursor to be positioned over a certain > expression. > Any help is appreciated. > > Adrian > > > === Subject: Re: waiting for pressed key and reading key > Hi everyone, I am interested to include in a program a part in which the program > waits until either of two specific keys are pressed, and once this > happens waiting is over and the one key (ut of the two) which was > pressed determines the value of a variable. I basically want to use as a > mean to read user confirmation. Hello Adrian, Perhaps this is not what you are exactly looking for but using CurrentValue might be the way to go, for example here pressing Command and Shift causes the Disk to change to Circle. DynamicModule[{x}, Column[{Dynamic@ If[CurrentValue[ShiftKey] && CurrentValue[CommandKey], Style[x = True, White], Style[x = False, White]], PaneSelector[{True -> Graphics[Circle[]], False -> Graphics[Disk[]]}, Dynamic[x]]}]] > I figured out how to do something in this line by using a DynamicModule, > with an EventHandler that wait for a mouse click. The problem I have > with that is that I would prefer to use keys and also that > MouseClicked event requires the cursor to be positioned over a certain > expression. Seems like CurrentValue[MouseOver] might also be useful Dynamic[Graphics[f[], PlotLabel -> If[CurrentValue[MouseOver], f = Circle, f = Disk]]] Pratik Desai Wolfram Research > Any help is appreciated. Adrian -- === Subject: Re: waiting for pressed key and reading key Have you tried to use the KeyDown event with EventHandler? Also you can do things at the full Notebook level using NotebookEventActions. And if you want to get even more Draconian (i.e., creative) you can use FrontEndEventActions. I haven't had time to experiment with these for you, but give them a try... Hope this helps, --David > Hi everyone, I am interested to include in a program a part in which the program > waits until either of two specific keys are pressed, and once this > happens waiting is over and the one key (ut of the two) which was > pressed determines the value of a variable. I basically want to use as a > mean to read user confirmation. > I figured out how to do something in this line by using a DynamicModule, > with an EventHandler that wait for a mouse click. The problem I have > with that is that I would prefer to use keys and also that > MouseClicked event requires the cursor to be positioned over a certain > expression. > Any help is appreciated. Adrian -- > Adrian Lupascu > Centre National de la Recherche Scientifique > Laboratoire Kastler Brossel > Ecole Normale Sup=E9rieure > 24 rue Lhomond > 75231 Paris CEDEX 05 > Tel: +33 144323304 > Fax: +33 144323434 > E-mail: Adrian.Lupa...@lkb.ens.fr === Subject: Possible bug in WAV export Something is wrong with WAV export. I tried the following: snd = Play[ Sin[440 2 [Pi] t] + Sin[2 440 2 [Pi] t] + Sin[3 440 2 [Pi] t] + Sin[4 440 2 [Pi] t], {t, 0, 1}, SampleRate -> 44100, SampleDepth -> 16] Export[test.wav, snd, WAV] The produced WAV file has a terrible buzzing sound, which is nothing like the sound played in Mathematica. Re-importing it and plotting the data shows that some of the samples are missing (they have the most negative value): data = Import[test.wav][[1, 1, 1]]; ListPlot[Take[data, {200, 500}], Joined -> True] (AIFF and FLAC export appear to be working correctly in this case.) === Subject: Re: Possible bug in WAV export The sound in Mathematica and the sound from the exported WAV file (using some unknown player) seem the same to me. I'm using V6.02 on a XP box. === Subject: Re: Possible bug in WAV export > The sound in Mathematica and the sound from the exported WAV file > (using some unknown player) seem the same to me. I'm using > V6.02 on a XP box. I experimented some more and it turns out that the problem is not limited to WAV (it is present with FLAC and AIFF too). However, the problem only appears randomly, and not in each evaluation. The following command does not always give the same result: ImportString[ ExportString[ Play[Sum[Sin[2 Pi 440 k t], {k, 1, 4}], {t, 0, 1}, SampleRate -> 44100, SampleDepth -> 16], WAV], WAV] In about 20 or so evaluations I always get a few incorrect results. It is not even necessary to play the sound---it is possible to see the difference by looking at the spectra: Table[ImportString[ ExportString[ Play[Sum[Sin[2 Pi 440 k t], {k, 1, 4}], {t, 0, 1}, SampleRate -> 44100, SampleDepth -> 16], WAV], WAV], {20}] Can anyone else reproduce this problem? It is very strange that the result is not deterministic. Any ideas why this might happen? To demonstrate that this unbelievable thing really happens, here's an another example, together with the result. Note that the very same command returns different results in subsequent evaluations: In[1]:= Table[ Total[#[[1, 1, 1]]] &@ ImportString[ ExportString[ Play[Sum[Sin[2 Pi 440 k t], {k, 1, 4}], {t, 0, 1}, SampleRate -> 44100, SampleDepth -> 16], WAV], WAV], {20}] Out[1]= {0., 268.745, -0.752563, -0.756226, -0.756226, -2.99866, 0., 0., -2.98279, 0., 0.756226, 341.993, 0., -0.752563, 0., 268.017, -0.752563, 0., -2.2522, 0.} The small fluctuations could be explained by dithering, but any reasonably precise result cannot have a sum of 342! The sound function was constructed in such a way that the sum should be 0. === Subject: List concatenation speed I am building mesh plots that require concatenation of thousands of Graphics objects into one list for Show[]. This is done by appending objects as they are created, and there are several ways to do that. Tested 3 of them for speed using a simple object: p=Table[x,{50}]; n=10000; ClearAll[poly]; poly={}; Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; ClearAll[poly]; poly={}; Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; ClearAll[poly]; poly={}; Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; {5.8395 Second,Null} {5.7206 Second,Null} {6.29728 Second,Null} Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to win, but it didnt. Is there a faster way? === Subject: Re: List concatenation speed > > >>I am building mesh plots that require concatenation of thousands of >>Graphics objects into one list for Show[]. This is done by appending >>objects as they are created, and there are several ways to do that. >>Tested 3 of them for speed using a simple object: >> p=Table[x,{50}]; n=10000; >> ClearAll[poly]; poly={}; >> Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; >> ClearAll[poly]; poly={}; >> Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; >> ClearAll[poly]; poly={}; >> Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; >>{5.8395 Second,Null} >>{5.7206 Second,Null} >>{6.29728 Second,Null} >>Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to >>win, >>but it didnt. Is there a faster way? > > > Carlos, > > use LISP style. > > to append to a list it is always quite fast to build a nested list like > poly = {poly,p} in a loop and then post process it. In your case (graphic > primitives) you to not even need to post process since Graphics can handle > nested lists. > > p = Line[ Table[{ Random[], Random[]}, {nr}] ]; > poly4 = List[]; > Print[Timing[ > Do[poly4 = {poly4, p}, {i, 1, n}]; > ]]; > > {0.012001 Second, Null} > > Show[Graphics[poly4]] > > The point is the the post processing is done outside of the loop. In case > you need to post process remember that Flatten only flattens to up until a > specific head. Like: > > p = g[ Table[{ Random[], Random[]}, {nr}] ]; > poly5 = List[]; > Print[Timing[ > Do[poly5 = {poly5, p}, {i, 1, n}]; > poly5 = Flatten[ poly5 ]; > ]]; > > > {0.020002 Second, Null} > > poly5[[1]] > > Now, the question I have is why does this performance depend on the symbol > name of the head? > > like in > > p = h[ Table[{ Random[], Random[]}, {nr}] ]; > poly5 = List[]; > Print[Timing[ > Do[poly5 = {poly5, p}, {i, 1, n}]; > poly5 = Flatten[ poly5 ]; > ]]; > > {4.96831 Second, Null} > > The problem with this is that Polygon seems to be a slow head and Line a > fast one. But perhaps I am missing something obvious here ;-) > > hth, > > Oliver > > Oliver Ruebenkoenig, No, not particularly obvious. It is an issue that has surfaced in this group and in sci.math.symbolic a few times. Here are a few URLs to past notes on this topic (apologies if the long ones get split into multiple lines). http://forums.wolfram.com/mathgroup/archive/2002/Sep/msg00324.html What happens is that the Mathematica implementation of infinite evaluation (or, more correctly, evaluation until stabilization) requires some way to assess that there is no need to reevalute expressions. In some cases collisions in hashing manage to thwart the first level of short-circuiting reevaluation, and instead the expression under scrutiny must be, at least in part, traversed (to determine whether further evaluation is needed). When that expression is growing linearly in a loop, we thus can get quadratic complexity due to this traversal, even though reevaluation might not be necessary. Daniel Lichtblau Wolfram Research === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? Here is a newbie approach: > In[14]:= > Timing[Reap[i = 1; > While[i <= n, Sow[p]; > i++; ]]; ] > Out[14]= > {0.11680799999999891*Second, > Null} For comparison: In[6]:=Timing[Do[AppendTo[poly, p], {i, 1, n}]] Out[6]={6.827495*Second, Null} J=E1nos > In[24]:= > $Version > Out[24]= > 5.2 for Mac OS X (64 bit) > (June 20, 2005) === Subject: Re: List concatenation speed yes, forget Do[], erase it from your mind total! And if you for some reason can't do that, try ClearAll[poly]; poly = {}; Print[Timing[Do[poly = {poly, p}, {i, 1, n}]; Flatten[poly];]]; Jens > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: > > p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; > > {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} > > Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? > === Subject: Re: List concatenation speed Hi Carlos, with Append & Co. every time you add a new element, the whole list is copied. To prevent this, you may build a nested list like e.g.: poly={poly,p} instead of using Append. Finally you may Flatten the list: Flatten[poly]. hope this helps, Daniel > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: > > p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; > > {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} > > Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? > === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: > > p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; > > {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} > > Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? > This is much faster, but requires an extra flatten at the end. If constructing graphics, this might not even be necessary, on the other hand it could change the appearance of your graphics if you need to keep some brackets. There are cures for all cases, but for that one would need more detailed information about your objects... ClearAll[poly]; poly = {}; Print[Timing[ Do[poly = {poly, p}, {i, 1, n}]; poly = Flatten[poly]; ]]; hth, albert === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? This may be cheating, but it's really fast: p = Table[x, {50}]; n = 10000; ClearAll[poly]; poly = {}; Print[Timing[poly = NestList[p &, p, n - 1];]]; {0.007093,Null} And for comparison: ClearAll[poly]; poly = {}; Print[Timing[Do[AppendTo[poly, p], {i, 1, n}]]]; ClearAll[poly]; poly = {}; Print[Timing[Do[poly = Append[poly, p], {i, 1, n}]]]; ClearAll[poly]; poly = {}; Print[Timing[Do[poly = Join[poly, {p}], {i, 1, n}]]]; {5.45663,Null} {5.4591,Null} {5.68613,Null} Jason === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: > > p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; > > {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} > > Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? > The best way is to create a structure like {c,{b,{a,{}}} by operations of the form: poly={p,poly}; When you are done, calculate Reverse[Flatten[poly]] (skip the Reverse if the order does not matter or if you can just as easily create the list in backward order). The problem with any form of Append is that it re-builds the whole list - which can be very long - each time it is used. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: List concatenation speed >I am building mesh plots that require concatenation of thousands of >Graphics objects into one list for Show[]. This is done by appending >objects as they are created, and there are several ways to do that. >Tested 3 of them for speed using a simple object: p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; {5.8395 Second,Null} >{5.7206 Second,Null} >{6.29728 Second,Null} Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to >win, >but it didnt. Is there a faster way? > > Each of your examples is basically doing an Append operation 10000 times, and unfortunately, Append is one of the slowest Mathematica operations. For your toy example, simply: poly = Table[p, {n}]; is practically instantaneous and produces the same answer: In[901]:= p = Table[x, {50}]; n = 10000; ClearAll[poly]; poly = {}; Timing[Do[AppendTo[poly, p], {i, 1, n}]] Timing[poly2 = Table[p, {n}];] Out[903]= {4.281,Null} Out[904]= {0.,Null} Out[905]= True For your real application, the best way to do things depends critically on what object you are trying to create. If at all possible, you should use multipoint, multiline or multipolygon objects to take advantage of packed arrays. Carl Woll Wolfram Research === Subject: Re: List concatenation speed The problem with your solution is that the p's are not > available synchronously. They are Graphics objects, some quite > complicated, computed sequientally and catenated to form the Show[] > list. If I knew their number in advance I could use a Table > pre-reservation, say Table[0,{numberofobjects}], > to speed collocation. (I guess I could try that with > an overestimate and then do a Take) > Another thought: Generally, you do not need to worry if your data structure is not a flat list while it is being built. It is always possible to flatten at the end. Just try to avoid appending elements to lists if possible. For example, here's a recursive function that builds a list of consecutive numbers: In[1]:= fun1[{elems___}, n_] := fun1[{elems, n}, n - 1] fun1[{elems___}, 0] := {elems} In[3]:= Block[ {$IterationLimit = Infinity}, fun1[{}, 10000]; // Timing ] Out[3]= {3.406, Null} This is very slow, because it uses something that is equivalent to append. It can only count to 10000 in 3.5 seconds. This algorithm is effectively O(n^2) because it copies the list with every iteration. Here's a much faster version, using a singly linked list data structure: In[4]:= fun2[list_, n_] := fun2[{list, n}, n - 1] fun2[list_, 0] := list In[6]:= Block[ {$IterationLimit = Infinity}, Flatten[fun2[{}, 1200000]]; // Timing ] Out[6]= {3.485, Null} This is O(n), and it could count to 1200000 in 3.5 seconds. The flattening was very fast at the end. Here's a Sow/Reap approach, also O(n), and about as fast as fun2: In[7]:= Reap[Do[Sow[i], {i, 2300000}]][[2, 1]]; // Timing Out[7]= {3.594, Null} I hope this helps, Szabolcs === Subject: Re: List concatenation speed The problem with your solution is that the p's are not > available synchronously. They are Graphics objects, some quite > complicated, computed sequientally and catenated to form the Show[] > list. If I knew their number in advance I could use a Table > pre-reservation, say Table[0,{numberofobjects}], > to speed collocation. (I guess I could try that with > an overestimate and then do a Take) > Table[] generates the elements sequentially, so it might still be applicable to the problem. There are some other functions too, which collect partial results (NestList, FoldList, FixedPointList are a few examples). If it is not possible to express the algorithm with any of these functions, there is still a fast way to collect results: Sow[] and Reap[]. They are much faster than Append/AppendTo. Szabolcs === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? Carlos, use LISP style. to append to a list it is always quite fast to build a nested list like poly = {poly,p} in a loop and then post process it. In your case (graphic primitives) you to not even need to post process since Graphics can handle nested lists. p = Line[ Table[{ Random[], Random[]}, {nr}] ]; poly4 = List[]; Print[Timing[ Do[poly4 = {poly4, p}, {i, 1, n}]; ]]; {0.012001 Second, Null} Show[Graphics[poly4]] The point is the the post processing is done outside of the loop. In case you need to post process remember that Flatten only flattens to up until a specific head. Like: p = g[ Table[{ Random[], Random[]}, {nr}] ]; poly5 = List[]; Print[Timing[ Do[poly5 = {poly5, p}, {i, 1, n}]; poly5 = Flatten[ poly5 ]; ]]; {0.020002 Second, Null} poly5[[1]] Now, the question I have is why does this performance depend on the symbol name of the head? like in p = h[ Table[{ Random[], Random[]}, {nr}] ]; poly5 = List[]; Print[Timing[ Do[poly5 = {poly5, p}, {i, 1, n}]; poly5 = Flatten[ poly5 ]; ]]; {4.96831 Second, Null} The problem with this is that Polygon seems to be a slow head and Line a fast one. But perhaps I am missing something obvious here ;-) hth, Oliver Oliver Ruebenkoenig, === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: > > p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; > > {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} > > Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? Hi Carlos, On my system (v6.0.2 Intel 64-bit Mac OS X 1.5.2), using *Sow* and *Reap* as in Reap[Do[Sow[p], {i, 1, n}]][[2, 1]] is more than 80 times faster than your fastest solution. This will not work on version below 5.xx. Using *Table* is about 35 faster and works on any version. Table[p, {i, 1, n}] Here are the timings for the five approaches: p = Table[x, {50}]; n = 10000; ClearAll[poly1]; poly = {}; Print[Timing[poly = Reap[Do[Sow[p], {i, 1, n}]][[2, 1]];]]; ClearAll[poly]; poly = {}; Print[Timing[poly = Table[p, {i, 1, n}];]]; ClearAll[poly]; poly = {}; Print[Timing[Do[poly = Append[poly, p], {i, 1, n}]]]; ClearAll[poly]; poly = {}; Print[Timing[Do[AppendTo[poly, p], {i, 1, n}]]]; ClearAll[poly]; poly = {}; Print[Timing[Do[poly = Join[poly, {p}], {i, 1, n}]]]; {0.00965,Null} {0.025739,Null} {0.828765,Null} {0.848818,Null} {1.10683,Null} -- === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, but it didnt. Is there a faster way? Try Reap/Sow. Also, see http://forums.wolfram.com/mathgroup/archive/2006/May/msg00175.html === Subject: Re: List concatenation speed > I am building mesh plots that require concatenation of thousands of > Graphics objects into one list for Show[]. This is done by appending > objects as they are created, and there are several ways to do that. > Tested 3 of them for speed using a simple object: > > p=Table[x,{50}]; n=10000; > ClearAll[poly]; poly={}; If you set poly = {}, then ClearAll is not necessary here. > Print[Timing[Do[AppendTo[poly,p],{i,1,n}]]]; Print[] is not necessary here. Do not use the semicolon at the end. > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p],{i,1,n}]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p}],{i,1,n}]]]; > > {5.8395 Second,Null} > {5.7206 Second,Null} > {6.29728 Second,Null} > > Tests were run on version 5.2 on a G5 desktop Mac. I expected Join to > win, > but it didnt. Is there a faster way? > Yes, there is, but it involves using a slightly different algorithm. The problem is that you are thinking in a procedural way here: you assign a value to a variable, and change its value in a loop. Assignment and appending to lists are slow in Mathematica because they involve copying the whole data structure. Try to avoid this. I'd use In[1]:= p = Table[x, {50}]; n = 10000; Table[p, {n}]; // Timing Out[2]= {0., Null} which is much-much faster. It is not even necessary to use Join or Append. If you need the sublists joined together, then use Join @@ Table[p, {n}] This will produce a flat list of 'x' symbols. Generally, you can build up a list of lists first, and Join[] or Flatten[] them in the end. I hope this helps, Szabolcs === Subject: Manipulate on the web Hi everyone, I have a simple manipulate with a slider. For instance: Manipulate[Plot[Sin[ax], {x, 0, 6}], {a, 0, 2}] Is it possible to somehow put this online so that the users using the site can drag the sliders and see how the graph changes? __________________________________________________ Do You Yahoo!? http://mail.yahoo.com === Subject: Re: Manipulate on the web You can upload the notebook to: http://www.wolfram.com/solutions/interactivedeployment/publish/ which will convert it for use in the (completely free) Player: http://www.wolfram.com/products/player/ After you upload, you will receive an email with a link to the converted notebook that will run interactively in the (free) Player. > Hi everyone, > I have a simple manipulate with a slider. For > instance: > > Manipulate[Plot[Sin[ax], {x, 0, 6}], {a, 0, 2}] > > Is it possible to somehow put this online so that the > users using the site can drag the sliders and see how > the graph changes? > > > __________________________________________________ > Do You Yahoo!? > http://mail.yahoo.com > === Subject: Re: Manipulate on the web with webMathematica ? The WRI site has Flash animations for that, as to see from http://demonstrations.wolfram.com Jens > Hi everyone, > I have a simple manipulate with a slider. For > instance: > > Manipulate[Plot[Sin[ax], {x, 0, 6}], {a, 0, 2}] > > Is it possible to somehow put this online so that the > users using the site can drag the sliders and see how > the graph changes? > > > __________________________________________________ > Do You Yahoo!? > http://mail.yahoo.com > > === Subject: Dynamically generating Manipulate I'm looking to make something like below, except that I want the Manipulate section to construct it's controls from mystocks list dynamically. What is the easiest way to achieve this? mystocks = {CHYIX, OREAX, IGNBX,ZEUS}; doit[stocks_] := ( poses = Position[stocks, True] // Flatten; FinancialData[mystocks[[#]], Jan. 1,2000] & /@ poses] ); Manipulate[doit[{s1, s2, s3}], {{s1, True}, {True, False}, ControlPlacement -> Bottom}, {{s2, False}, {True, False}, ControlPlacement -> Bottom}, {{s3, False}, {True, False}, ControlPlacement -> Bottom}] === Subject: Re: Dynamically generating Manipulate Hi Yaroslav, there are some problems with HoldAll and Evaluate, but it can be done. Here is a function that uses doit[] and draws whatever is in myStocks: fu[myStocks_]:=Module[{n=Length[myStocks],vars,ctrls}, vars=Table[Unique[v],{n}]; ctrls={{#,True},{True,False},ControlPlacement->Bottom}&/@ vars; With[{vars0=vars,ctrls0=Sequence@@ctrls}, vars=Thread[Interpretation[myStocks,vars]]; Manipulate[doit[vars0],ctrls0]] ] hope this helps, Daniel > I'm looking to make something like below, except that I want the > Manipulate section to construct it's controls from mystocks list > dynamically. What is the easiest way to achieve this? > > mystocks = {CHYIX, OREAX, IGNBX,ZEUS}; > doit[stocks_] := ( > poses = Position[stocks, True] // Flatten; > FinancialData[mystocks[[#]], Jan. 1,2000] & /@ poses] > ); > Manipulate[doit[{s1, s2, s3}], > {{s1, True}, {True, False}, > ControlPlacement -> Bottom}, {{s2, False}, {True, False}, > ControlPlacement -> Bottom}, {{s3, False}, {True, False}, > ControlPlacement -> Bottom}] > === Subject: Re: Pattern problem: How to count from a long list of numbers all occurrences of 2 numbers next to each others? > x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3} > And I want to count how many say a 3 followed immediately by 3. > ...1 followed by a 3, there will be 2 Just to be different for this particular problem... x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3}; Count[ListConvolve[{3, -3}, x], 0] 4 Count[ListConvolve[{1, -3}, x], 0] 2 -- HTH :>) Dana DeLouis > Hello; > > I think using Pattern is my weakest point in Mathematica. > > I have this list, say this: (it is all a list of integers, no real numbers). > > x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3} > > And I want to count how many say a 3 followed immediately by 3. So in the > above list, there will be 4 such occurrences. And if I want to count how > many 1 followed by a 3, there will be 2 such cases, etc... > > I tried Count[] but I do not know how to set the pattern for 3 followed by > a comma followed by 3 or just 3 followed immediately by 3. > > I tried few things, such as the following > > In[68]:= Count[x, {3, 3}_] > Out[68]= 0 > > Also tried Cases, but again, I am not to good with Patterns, so not sure how > to set this up at this moment. > > Any ideas will be appreciated. > > Nasser > I really need to sit down and study Patterns in Mathematica really well one > day :) > > === Subject: Re: Pattern problem: How to count from a long list of numbers all > x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3} > And I want to count how many say a 3 followed immediately by 3. > ...1 followed by a 3, there will be 2 Just to be different for this particular problem... x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3}; Count[ListConvolve[{3, -3}, x], 0] > 4 Count[ListConvolve[{1, -3}, x], 0] > 2 -- > HTH :>) > Dana DeLouis > Hello; > I think using Pattern is my weakest point in Mathematica. > I have this list, say this: (it is all a list of integers, no real > numbers). > x = {1, 3, 3, 3, 2, 3, 3, 1, 3, 3} > And I want to count how many say a 3 followed immediately by 3. So in th= e > above list, there will be 4 such occurrences. And if I want to count how= > many 1 followed by a 3, there will be 2 such cases, etc... > I tried Count[] but I do not know how to set the pattern for 3 followed= > by > a comma followed by 3 or just 3 followed immediately by 3. > I tried few things, such as the following > In[68]:= Count[x, {3, 3}_] > Out[68]= 0 > Also tried Cases, but again, I am not to good with Patterns, so not sure= > how > to set this up at this moment. > Any ideas will be appreciated. > Nasser > I really need to sit down and study Patterns in Mathematica really well > one > day :) Here's two other ways, one is slightly faster and one slower: In[20]:= xx = RandomInteger[{1, 5}, 1000000]; In[21]:= Count[Differences[xx], 0] // Timing In[22]:= Count[ListConvolve[{-3, 3}, xx], 0] // Timing In[23]:= Timing[Length[xx] - Length[Split[xx]]] Sam === Subject: Re: what does Method->HighDimensionalEmbedding I already tried all these methods, but choosing a method is not the issue. There were two issues: first, how to make Mathematica create a planar-embedded display of CompleteGraph (and more generally, any planar graph); and second, what happened to one of the vertices and one of the edges when I used Method -> HighDimensionalEmbedding. I now know an easy solution to the second issue -- see a separate post as a follow-up to ; the first one remains unresolved. > Murray, > > There is an example (below) from ref/GraphPlot in the Documentation > under Options->Method, > > Apply a number of methods on the Petersen graph: > > << Combinatorica` > > Grid@Partition[ > Table[GraphPlot[{1 -> 3, 1 -> 4, 2 -> 4, 2 -> 5, 3 -> 5, 6 -> 7, 7 - > > 8, > 8 -> 9, 9 -> 10, 6 -> 10, 1 -> 6, 2 -> 7, 3 -> 8, 4 -> 9, 5 -> > 10}, > Method -> m, PlotLabel -> Style[m, Small], BaselinePosition -> Top, > ImageSize -> 150], {m, {SpringElectricalEmbedding, > SpringEmbedding, > HighDimensionalEmbedding, CircularEmbedding, > RandomEmbedding, > LinearEmbedding}}], 3] > > The output diagrams the Method options for the Petersen graph. > > HTH > > Syd > > > Syd Geraghty B.Sc, M.Sc. > > sydgeraghty@mac.com > > My System > > Mathematica 6.0.1 for Mac OS X x86 (64 - bit) (June 19, 2007) > MacOS X V 10.5 .20 > > > > > What, exactly, is the HighDimensionalEmbeedding value for the > GraphPlot option Method? > > And why does the following produce a display that seems to be wrong: the > displayed graph has only 5 edges instead of the expected 6 for the > complete graph on 4 vertices? > > GraphPlot[CompleteGraph[4], Method -> HighDimensionalEmbedding, > VertexLabeling -> True] > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Grad