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 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 GraphPlot? 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] === Subject: Any One have an idea? Does anyone have any idea how to do or come up with the knight's tour problem. Please give me some idea how to do it! The program is used a random number to select a starting position for the knight, and select the next position by selecting one of the available positions at random. When the knight reaches a position from which the number of the last possible available positions, the tour is finished. Anna SJ. === Subject: Re: Any One have an idea? There are some demonstrations on the Wolfram Demonstrations web site which may be helpful to you: http://demonstrations.wolfram.com/search.html?query=knight%27s+tour > > Does anyone have any idea how to do or come up with the knight's tour problem. Please give me some idea how to do it! > > The program is used a random number to select a starting position for the knight, and select the next position by selecting one of the available positions at random. When the knight reaches a position from which the number of the last possible available positions, the tour is finished. > > > Anna SJ. === Subject: Re: Any One have an idea? > Does anyone have any idea how to do or come up with the knight's > tour problem. Please give me some idea how to do it! The program is used a random number to select a starting position > for the knight, and select the next position by selecting one of the > available positions at random. When the knight reaches a position > from which the number of the last possible available positions, the > tour is finished. http://demonstrations.wolfram.com/TheKnightsTour/ === Subject: Re: Any One have an idea? Hello Anna, I found this: Needs[Combinatorica`] ?KnightsTourGraph But, could not find a direct documentation route to find it. I can't remember why I even knew it was there. Hope this is the method you were thinking of. Does anyone have any idea how to do or come up with the knight's tour problem. Please give me some idea how to do it! The program is used a random number to select a starting position for the knight, and select the next position by selecting one of the available positions at random. When the knight reaches a position from which the number of the last possible available positions, the tour is finished. > Anna SJ. -- W. Craig Carter === Subject: Re: Any One have an idea? Type knight's tour mathematica into Google.... you will find some good resoruces... --David Does anyone have any idea how to do or come up with the knight's tour pr= oblem. Please give me some idea how to do it! The program is used a random number to select a starting position for the = knight, and select the next position by selecting one of the available posit= ions at random. When the knight reaches a position from which the number = of the last possible available positions, the tour is finished. > Anna SJ. === Subject: Re: Any One have an idea? > Does anyone have any idea how to do or come up with the knight's tour problem. Please give me some idea how to do it! A good starting point may be Dr Colin Rose's website. See, The Distribution of the Knight at http://www.tri.org.au/knightframe.html -- === Subject: Re: Frametick Orientation (2 Questions) Hi ouadad, regarding your first question, you could take a look at this thread which describes an experimental feature you might find helpful. Regarding your second question, yes it is possible. It's even possible without manually specifying a list of ticks. Here's a function that will do it: frameTicksTransform[f_, graphic_, sides_: {1, 2, 3, 4}] := Show[graphic, FrameTicks -> With[{ticksPos = Position[AbsoluteOptions@graphic, FrameTicks -> _]}, With[{ticks = AbsoluteOptions[graphic][[ Sequence @@ Flatten@Join[ticksPos, {2}]]]}, MapAt[ f, ticks, Flatten[ Table[{side, i}, {side, sides}, {i, 1, Length[ticks[[side]]]}], 1] ]]]] This is kind of kludgy in the sense that you have to start with a graphic that already has frame ticks; a better solution would let you specify the way you want the ticks to look before it generates the graphic. This does seem to work fine, though. In a graphic with frame ticks, each individual tick is specified by a list that looks like {position, label, {positiveLength, negativeLength}, directives}. The frameTickTransform function takes as its first argument a function that transform a single tick specification like above into what you want it to look like. The second argument is the graphic you want to transform, and the third optional argument is the list of sides you want the transform to apply to, which are numbered clockwise starting from 1 at the bottom. In your case, to make the frame ticks appear outside the frame instead of inside, you just need to switch the positiveLength and negativeLength for each tick. For example, if g is the graphic you gave as an example on April 11, you could write frameTicksTransform[MapAt[Reverse, #, 3] &, g] to get all the ticks outside the frame. This is just saying that the Reverse function should be mapped on to the third part of every tick specification. If you only want to flip the ticks on the bottom, frameTicksTransform[MapAt[Reverse, #, 3] &, g, {1}] Hope that this helps! -Daniel === Subject: List concatenation - two more methods, one truly fast As follow up, the following tests are more realistic in that p is similar to the Graphics objects produced during a mesh plot. The last method (table entry substitution) is about 2 orders of magnitude faster. Unfortunately in actual plot generation I dont known n (number of objects) in advance, so that one is out. ClearAll[poly,p,n]; poly={}; n=5000; SetRandom[1234]; p[arg_]:= {Graphics[RGBColor[Random[],Random[],Random[]]], Graphics[Polygon[{{Random[],Random[]}, {Random[],Random[]},{Random[],Random[]}}]]}; Print[Timing[Do[AppendTo[poly,p[i]],{i,1,n}]][[1]]]; ClearAll[poly]; poly={}; Print[Timing[Do[poly=Append[poly,p[i]],{i,1,n}]][[1]]]; ClearAll[poly]; poly={}; Print[Timing[Do[poly=Join[poly,{p[i]}],{i,1,n}]][[1]]]; ClearAll[poly]; poly={}; Print[Timing[Do[poly={poly,p[i]},{i,1,n}];poly=Flatten[poly]][[1]]]; ClearAll[poly]; poly=Table[0,{n}]; Print[Timing[Do[poly[[i]]=p[i],{i,1,n}]][[1]]; 11.3361 Second 11.3306 Second 11.7123 Second 7.24559 Second 0.061505 Second Observation: timing of the first 4 methods is roughly O(n^2). That would suggest that Mathematica does not implement a true list processor in the kernel, since building a list should be O(n). === Subject: Coordinates of vertices I am sure I have done this before but I can't for the life of me remember how, and I can't find it in the manual. Some help would be much appreciated. I'd like to find the coordinates of the vertices of a truncated cube. Whilst Vertices[cube] correctly gives me the coordinates of a cube Vertices[Truncate[Polyhedron[Cube]]] doesn't do what I want because Truncate[Polyhedron[... is a graphics object not a polyhedron object. So can I convert the graphics object into a polyhedron and use vertices, or work out the vertices some other way (for a cube this is trivial to do but for more complicated shapes this is much more tedious) Peter === Subject: Re: Coordinates of vertices > I am sure I have done this before but I can't for the life of me > remember how, and I can't find it in the manual. Some help would be much > appreciated. I'd like to find the coordinates of the vertices of a > truncated cube. > > Whilst Vertices[cube] correctly gives me the coordinates of a cube > Vertices[Truncate[Polyhedron[Cube]]] doesn't do what I want because > Truncate[Polyhedron[... is a graphics object not a polyhedron object. So > can I convert the graphics object into a polyhedron and use vertices, or > work out the vertices some other way (for a cube this is trivial to do > but for more complicated shapes this is much more tedious) Hi Peter, Assuming I have correctly understood what you are looking for and that you are using version 6.x.x, you can get, among many many other things, function. For instance, In[1]:= PolyhedronData[TruncatedCube, VertexCoordinates] Out[1]= {{-(1/2), 1/2 + 1/Sqrt[2], 1/2 + 1/Sqrt[2]}, {-(1/2), 1/2 + 1/Sqrt[2], 1/(2 - 2 Sqrt[2])}, {-(1/2), 1/(2 - 2 Sqrt[2]), 1/2 + 1/Sqrt[2]}, {-(1/2), 1/(2 - 2 Sqrt[2]), 1/( 2 - 2 Sqrt[2])}, {1/2, 1/2 + 1/Sqrt[2], 1/2 + 1/Sqrt[2]}, {1/2, 1/2 + 1/Sqrt[2], 1/(2 - 2 Sqrt[2])}, {1/2, 1/(2 - 2 Sqrt[2]), 1/2 + 1/Sqrt[2]}, {1/2, 1/(2 - 2 Sqrt[2]), 1/( 2 - 2 Sqrt[2])}, {1/2 + 1/Sqrt[2], -(1/2), 1/2 + 1/Sqrt[2]}, {1/2 + 1/Sqrt[2], -(1/2), 1/( 2 - 2 Sqrt[2])}, {1/2 + 1/Sqrt[2], 1/2, 1/2 + 1/Sqrt[2]}, {1/2 + 1/Sqrt[2], 1/2, 1/( 2 - 2 Sqrt[2])}, {1/2 + 1/Sqrt[2], 1/2 + 1/Sqrt[2], -(1/2)}, {1/2 + 1/Sqrt[2], 1/2 + 1/Sqrt[2], 1/ 2}, {1/2 + 1/Sqrt[2], 1/(2 - 2 Sqrt[2]), -(1/2)}, {1/2 + 1/Sqrt[2], 1/(2 - 2 Sqrt[2]), 1/2}, {1/(2 - 2 Sqrt[2]), -(1/2), 1/2 + 1/Sqrt[2]}, {1/(2 - 2 Sqrt[2]), -(1/2), 1/( 2 - 2 Sqrt[2])}, {1/(2 - 2 Sqrt[2]), 1/2, 1/2 + 1/Sqrt[2]}, {1/( 2 - 2 Sqrt[2]), 1/2, 1/(2 - 2 Sqrt[2])}, {1/(2 - 2 Sqrt[2]), 1/2 + 1/Sqrt[2], -(1/2)}, {1/(2 - 2 Sqrt[2]), 1/2 + 1/Sqrt[2], 1/ 2}, {1/(2 - 2 Sqrt[2]), 1/(2 - 2 Sqrt[2]), -(1/2)}, {1/( 2 - 2 Sqrt[2]), 1/(2 - 2 Sqrt[2]), 1/2}} Hope this helps, -- === Subject: Re: List concatenation - two more methods, one truly fast > > Observation: timing of the first 4 methods is roughly O(n^2). > That would suggest that Mathematica does not implement a true > list processor in the kernel, since building a list should be O(n). Yes, unlike in most other languages that support a functional programming paradigm, expressions in Mathematica are represented as simple arrays in memory (and not linked lists). This means that indexing is very fast, but concatenation is slow. A linked list can be created by nesting expressions: {1, {2, {3, {4, {5, {}}}}}} === Subject: Re: List concatenation - two more methods, one truly fast Carlos, p[arg_] := Graphics[{RGBColor[Random[], Random[], Random[]], pp[{{Random[], Random[]}, {Random[], Random[]}, {Random[], Random[]}}]}] ClearAll[poly]; poly = {}; Print[Timing[Do[poly = {p[i], poly}, {i, 1, n}]; poly = poly /. pp -> Polygon; ][[1]]]; 0.068004 Second Show[poly] hth, Oliver > As follow up, the following tests are more realistic in that p > is similar to the Graphics objects produced during a mesh > plot. The last method (table entry substitution) is about 2 orders > of magnitude faster. Unfortunately in actual plot generation I > dont known n (number of objects) in advance, so that one is out. ClearAll[poly,p,n]; poly={}; n=5000; SetRandom[1234]; > p[arg_]:= {Graphics[RGBColor[Random[],Random[],Random[]]], > Graphics[Polygon[{{Random[],Random[]}, > {Random[],Random[]},{Random[],Random[]}}]]}; > Print[Timing[Do[AppendTo[poly,p[i]],{i,1,n}]][[1]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p[i]],{i,1,n}]][[1]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p[i]}],{i,1,n}]][[1]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly={poly,p[i]},{i,1,n}];poly=Flatten[poly]][[1]]]; > ClearAll[poly]; poly=Table[0,{n}]; > Print[Timing[Do[poly[[i]]=p[i],{i,1,n}]][[1]]; > 11.3361 Second > 11.3306 Second > 11.7123 Second > 7.24559 Second > 0.061505 Second Observation: timing of the first 4 methods is roughly O(n^2). > That would suggest that Mathematica does not implement a true > list processor in the kernel, since building a list should be O(n). > Oliver Ruebenkoenig, === Subject: Mathematica Player Pro! I don't know if this falls within the purview of MathGroup because it has to do with the Mathematica business model, but it also is vitally important to how Mathematica is used and its range and scope. Anybody who knows me knows that I am a tremendous enthusiast for Mathematica. I believe it is a truly revolutionary new medium and even in twenty years the technical community has not come fully to grips with it. Mathematica Player Pro is as great an advance as Version 6 is, perhaps even greater! You can write a notebook in the normal manner and ANYONE who has Player Pro can read it and get all the interactivity. And anyone who has commercial packages can distribute free Player Pro versions so that anyone can also read and interact with any notebooks written with the package. This requirement for making packages work in Player Pro. Encode them.) There is only one problem: 'ANYONE who has Player Pro' is still not very many people. WRI is allowing Premier subscribers to give away two free copies. But why not go all the way and provide free copies of Player Pro to everyone? (And junk Player and all its little restrictions and convolutions.) Why not go even further and try to convince Dell and Apple, and any other OEM, to sell the computers with Mathematica Player Pro preloaded, just as they now come preloaded with Acrobat Reader? Huge numbers of people buy the Adobe Acrobat software because they know for a certainty that absolutely everybody can read the documents. Everything from IRS tax forms, restaurant menus to scientific papers on quantum gravity are available as pdf files. I have long believed that all scientific papers and technical reports should be written as Mathematica notebooks. But, in practice, this is very little done. Rather I think that most users use Mathematica as a super calculator or programming language and then export some of the results, or copy out by hand, to the actual paper or report that is either written in Word or as a Postscript file using Latex, and then often converting to pdf. The main reason they do this is because they know very well that most people can't read Mathematica notebooks. A static printed scientific document, or a pdf document, is to a Mathematica notebook as an ox cart is to a Lear jet. And that vastly understates it. Active Mathematica notebooks, written in the style of a research paper or textbook have huge advantages. One, of many, of these advantages is that they are largely self-proofing. When active definitions are used to carry out derivations and make graphics and dynamic displays there is a tremendous amount of cross-checking that goes on. When I mentioned this to a scientist friend he perked up - but only for a moment. I think some time ago I read that Mathematica notebooks would be accepted as documents on the physics and mathematical arXives. But I have never seem one there and if any exist they are vanishingly few. Everything is Postscript or pdf. Mathematica notebooks would be far superior except for the available readership. Providing Mathematica Player Pro free to everyone would unleash a torrent of Mathematica use that would eclipse its present reach. More people would write and distribute Mathematica notebooks because they would know that everybody could read them. More people would read them (and how could they help but be impressed!) and decide they wanted to write notebooks also. It would be the second revolution. I believe it is by far the superior business model. I just cross my fingers and hope the folks at WRI will come to the same conclusion. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: Mathematica Player Pro! David, I haven't tried Player Pro yet but I have long wished for something like the vision you outline. For me, the greatest advantage of live Mathematica notebooks, as opposed to traditional formats for scientific and mathematical exposition, is the ease with which readers can assimilate new material to greater depth. This is true, not only of research work but also of pedagogical material. There could also be a (long overdue!) educational revolution here. I hope that Wolfram Research will make Player Pro free. John Jowett > I don't know if this falls within the purview of MathGroup because it has = to > do with the Mathematica business model, but it also is vitally important t= o > how Mathematica is used and its range and scope. Anybody who knows me knows that I am a tremendous enthusiast for > Mathematica. I believe it is a truly revolutionary new medium and even in > twenty years the technical community has not come fully to grips with it. Mathematica Player Pro is as great an advance as Version 6 is, perhaps eve= n > greater! You can write a notebook in the normal manner and ANYONE who has > Player Pro can read it and get all the interactivity. And anyone who ha= s > commercial packages can distribute free Player Pro versions so that anyone= > can also read and interact with any notebooks written with the package. Th= is > requirement for making packages work in Player Pro. Encode them.) There is only one problem: 'ANYONE who has Player Pro' is still not very > many people. WRI is allowing Premier subscribers to give away two free > copies. But why not go all the way and provide free copies of Player Pro t= o > everyone? (And junk Player and all its little restrictions and > convolutions.) Why not go even further and try to convince Dell and Apple,= > and any other OEM, to sell the computers with Mathematica Player Pro > preloaded, just as they now come preloaded with Acrobat Reader? Huge numbers of people buy the Adobe Acrobat software because they know fo= r > a certainty that absolutely everybody can read the documents. Everything > from IRS tax forms, restaurant menus to scientific papers on quantum gravi= ty > are available as pdf files. I have long believed that all scientific papers and technical reports shou= ld > be written as Mathematica notebooks. But, in practice, this is very little= > done. Rather I think that most users use Mathematica as a super calculator= > or programming language and then export some of the results, or copy out b= y > hand, to the actual paper or report that is either written in Word or as a= > Postscript file using Latex, and then often converting to pdf. The main > reason they do this is because they know very well that most people can't > read Mathematica notebooks. A static printed scientific document, or a pdf document, is to a Mathemati= ca > notebook as an ox cart is to a Lear jet. And that vastly understates it. > Active Mathematica notebooks, written in the style of a research paper or > textbook have huge advantages. One, of many, of these advantages is that > they are largely self-proofing. When active definitions are used to carry > out derivations and make graphics and dynamic displays there is a tremendo= us > amount of cross-checking that goes on. When I mentioned this to a scientis= t > friend he perked up - but only for a moment. I think some time ago I read that Mathematica notebooks would be accepted = as > documents on the physics and mathematical arXives. But I have never seem o= ne > there and if any exist they are vanishingly few. Everything is Postscript = or > pdf. Mathematica notebooks would be far superior except for the available > readership. Providing Mathematica Player Pro free to everyone would unleash a torrent = of > Mathematica use that would eclipse its present reach. More people would > write and distribute Mathematica notebooks because they would know that > everybody could read them. More people would read them (and how could they= > help but be impressed!) and decide they wanted to write notebooks also. It= > would be the second revolution. I believe it is by far the superior busine= ss > model. I just cross my fingers and hope the folks at WRI will come to the > same conclusion. -- > David Park > djmp...@comcast.nethttp://home.comcast.net/~djmpark/ === Subject: Re: Mathematica Player Pro! I can see yet another reason: Mathematica is a great programming language but no free runtime to run it. I currently only use it in the first stage of development as proof of concept. When I want to deploy my programs I have to rewrite them in C++. It would be great to have some Mathematica runtime freely available. Igor === Subject: Re: Mathematica Player Pro! documents on the physics and mathematical arXives. But I have never seem one > there and if any exist they are vanishingly few. Everything is Postscript or > pdf. Mathematica notebooks would be far superior except for the available > readership. David, Though the arXiv Palette and Style Sheet for Mathematica Users is still advertised on WRI's website [1], arXiv documentation clearly states that they will not accept Mathematica notebook as mean of publishing [2]: Mathematica Notebook Submissions Mathematica please submit PDF instead. If you wish to archive Mathematica source files with your submission you may include them in a sub-directory so that they are not picked up by our processing system. > Providing Mathematica Player Pro free to everyone would unleash a torrent of > Mathematica use that would eclipse its present reach. More people would > write and distribute Mathematica notebooks because they would know that > everybody could read them. More people would read them (and how could they > help but be impressed!) and decide they wanted to write notebooks also. It > would be the second revolution. I believe it is by far the superior business > model. I just cross my fingers and hope the folks at WRI will come to the > same conclusion. I totally second that and cross my fingers too :-) [1] http://wolfram.com/solutions/publishing/stylearxiv.html [2] http://aps.arxiv.org/help/submit_nb === Subject: Re: Mathematica Player Pro! > Though the arXiv Palette and Style Sheet for Mathematica Users is >> still advertised on WRI's website [1], arXiv documentation clearly >> states that they will not accept Mathematica notebook as mean of >> publishing [2]: >> Mathematica Notebook Submissions >> you use >> Mathematica please submit PDF instead. If you wish to archive >> Mathematica source files with your submission you may include them >> in a >> sub-directory so that they are not picked up by our processing >> system. It would be interesting to know the reasons for this decision. (This is not intended as a snide remark or jab at Mathematica. > Presumably arXiv had what they thought were reasonable and > significant reasons for this policy, and it would be educational > to know what they were.) > Not enough submissions? Andrzej Kozlowski === Subject: Re: Mathematica Player Pro! > Though the arXiv Palette and Style Sheet for Mathematica Users is > still advertised on WRI's website [1], arXiv documentation clearly > states that they will not accept Mathematica notebook as mean of > publishing [2]: > > Mathematica Notebook Submissions > > Mathematica please submit PDF instead. If you wish to archive > Mathematica source files with your submission you may include them in a > sub-directory so that they are not picked up by our processing system. It would be interesting to know the reasons for this decision. (This is not intended as a snide remark or jab at Mathematica. Presumably arXiv had what they thought were reasonable and significant reasons for this policy, and it would be educational to know what they were.) === Subject: Malformed Fractions in a PDF file Re 6.0.2 under WinXP. Although Wolfram developers are investigating this question, I wonder if someone here already has. Suppose a notebook only has the text cell that concludes this message. When the notebook is printed via File/SaveAs/pdf, the resulting pdf file has fractions whose dividing lines don't fully appear. Other fractions have a full dividing line. Bruce (the text cell follows) Since sin 8/5[Theta]=sin(8/5([Theta]+2[Pi] n))=sin(8/5[Theta]+(16[Pi] n)/5)... === Subject: Re: Malformed Fractions in a PDF file > Since sin 8/5[Theta]=sin(8/5([Theta]+2[Pi] n))=sin(8/5[Theta]+(16= [Pi] n)/5)... Can you include the actual cell expression? Select the cell bracket & choose Edit > Copy As > Cell Expression from the menu bar. I don't see any problems with the PDF created by Mathematica when simply copying the above text from my browser and pasting it into a text cell in Mathematica. -Rob === Subject: Parallel Computing Toolkit with ssh tunnels I would like to create a poor man's parallel cluster using PCT to work through ssh tunnels due circumvent firewall restrictions. I have 3 slave and 1 master linux machines with sshd running on port 22 and no other ports open. Assume each machine is additionally behind a physical firewall and has a local IP and the firewall port forwards 22 to this machine. Authentication is set up without a password so that the following works: me@master: ssh slave1 math Mathematica 6.0 for Linux x86 (64-bit) Copyright 1988-2008 Wolfram Research, Inc. In[1]:= I haven't been able to get LaunchSlave[] to work with this setup with various combinations of LinkName, LinkHost and for example, 'ssh -R port1:127.0.0.1:port1 -R port2:127.0.0.1:port2' as replacement for $RemoteCommand. It seems for each launch, the master listens on two new random ports for each slave and instructs the slave to connect to these ports on a specific IP. I think I have both an issue with the firewall and the fact that meaningless local IPs are passed to the slaves rather than the IP of the firewall. Even when I hand set the ports and open them on the firewalls, I have problems. I am guessing the mathlink connection protocol is the same as launching a remote kernel on a slave from the master, which I also haven't been able to get to work with these firewalls and port restrictions. I have been able to get it to work with all machines in one local network and with no firewall restrictions. I have also been able to use gdb to debug mathlink code using the similar two port communication. I was wondering if anyone has gotten either PCT or remote kernel launching through ssh tunnels to work. There are prior posts on this forum and help on a wiki page: http://tinyurl.com/5ano5t but I haven't been able to get them to work either. I am using 6.0.2 on 64-bit Ubuntu 7.10 with PCT 2.1. Art. === Subject: Re: ContourPlot, etc.: not every point a Real On 2008-04-11 19:31:03 +0930, dh said: > ContourPlot first calls Eval with symbolic arguments in order to check > if it can simplify the expression. This is done to improve speed. You > can suppress this, by specifying that the arguments must be numeric, Ah, excellent! All the best, Will === Subject: Documentation Center Tutorial ...as promised I have created a notebook with a set of notes on some aspects of how to prepare material for the Mathematica Documentation Center. You can find this notebook at (its the only one on this page at the moment): http://www.scientificarts.com/worklife/notebooks/ The material described there will allow you to create material for the mathematica Documentation Center by hand. And it will not have the full set of bells and whistles; but, it may provide just the starting point and a subset of the tricks needed to get folks going on this. When version 3.0 of A WorkLife FrameWork is released it will contain a variety of tools for doing all of this automatically. rather quickly... I hope that 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/ === Subject: Re: Documentation Center Tutorial > ...as promised I have created a notebook with a set of notes on some > aspects of how to prepare material for the Mathematica Documentation > Center. > > You can find this notebook at (its the only one on this page at the > moment): > > http://www.scientificarts.com/worklife/notebooks/ > > The material described there will allow you to create material for the > mathematica Documentation Center by hand. And it will not have the > full set of bells and whistles; but, it may provide just the starting > point and a subset of the tricks needed to get folks going on this. > > When version 3.0 of A WorkLife FrameWork is released it will contain a > variety of tools for doing all of this automatically. > > rather quickly... > > I hope that this helps... Just a suggestion. Why not remove all the stuff at the top about not reproducing it (except in full), not for commercial use, plus other restrictions. Instead, stick it on a wiki of some sort where others can edit it? My guess is that perhaps someone from Wolfram Research might make some changes. http://www.mathematica-users.org has not been a wonderful successful it must said, and there might be better places, but this documentation issue is the sort of item that could be put in an FAQ http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=FAQs === Subject: Re: PolarPlot Hi Bruce, the radius in polar coordinates has to be real and positive. Therefore, r=Sqrt[Cos[phi]] can not be the correct formula, we would get imaginary values. To prevent this, we may e.g. write: r=Sqrt[Abs[Cos[phi]] what gives the plot you are looking for. hope this helps, Daniel > Re 6.0.2 under WinXP. > > > Bruce > > PolarPlot[{2 a Sqrt[Cos@t], -2 a Sqrt[Cos@t]}, {t, 0, 2 [Pi]}, > PlotRange -> 7] > === Subject: Re: PolarPlot > Hi Bruce, > > the radius in polar coordinates has to be real and positive. Therefore, Actually, no. In polar coordinates r is a *directed* distance, which may be positive or negative. > r=Sqrt[Cos[phi]] can not be the correct formula, we would get imaginary > > values. To prevent this, we may e.g. write: r=Sqrt[Abs[Cos[phi]] what > > gives the plot you are looking for. > > hope this helps, Daniel -- Helen Read University of Vermont === 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 === Subject: Re: PolarPlot PolarPlot[Flatten[Table[ {2 a Sqrt[Cos@t], -2 a Sqrt[Cos@t]}, {a, 7}]], {t, 0, 2 [Pi]}, AspectRatio -> 1, Frame -> True, Axes -> False] Cos[ArcTan[y/x]] 1/Sqrt[y^2/x^2 + 1] ContourPlot[Evaluate[Table[ (x^2 + y^2) == 4 a^2 /Sqrt[y^2/x^2 + 1], {a, 7}]], {x, -15, 15}, {y, -10, 10}, AspectRatio -> 1, ContourLabels -> (Text[Sqrt[Numerator[#3[[2]]]/4], {#1, #2}] &)] Put the arrow over one of the lines in the ContourPlot. Bob Hanlon > Re 6.0.2 under WinXP. > > > Bruce > > PolarPlot[{2 a Sqrt[Cos@t], -2 a Sqrt[Cos@t]}, {t, 0, 2 [Pi]}, > PlotRange -> 7] > === Subject: Numerical integration and list of points Hello everyone, I have a function which I read as a list of points. I want then to estimate its integral. I do more or less this : data={{x1,y1},{x2,y2},...,{xN,yN}} f=Interpolation[data] NIntegrate[f[x],{x,x1,xN}] Is it the correct way ? Because Mathematica hangs without giving me an answer although it seems a pretty straightforward thing to do... === Subject: Re: Numerical integration and list of points Why don't you provide a specific case of evaluable code that causes the problem? This is far better than just giving a generic description. You can't expect that most potential responders are going to spend much time trying to guess what specific thing caused the problem and making up examples that are relevant to your case. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hello everyone, I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... === Subject: Re: Numerical integration and list of points After some tests, it's just that my list contains 20'000 elements and the integration takes forever to finish... I thought Mathematica crashed because I thought it was a rather simple thing to do but it turns out I would need to run this integration on a powerful cluster or something :) === Subject: Re: Numerical integration and list of points So... I must do something wrong because when I use Integrate instead of NIntegrate, it returns an unevaluated results. Let me explain quickly and I will also link to some snapshots of my code... I have some data points : data={{x1,y1},{x2,y2}...{xN,yN}} f=Interpolation[data] Integrate[f[r],{r,,x1,xN}] returns Integrate[InterpolationFunction[{{x1,xN}}<>][r],{r,,x1,xN}] NIntegrate[f[r],{r,,x1,xN}] returns the correct number... It is more involved than this so here are couple of pictures. Hope you'll be able to visualize them : Using Integrate : http://img59.imageshack.us/img59/3074/usingintegrateas6.jpg Using NIntegrate : http://img59.imageshack.us/img59/7663/usingnintegratepq0.jpg === Subject: Re: Numerical integration and list of points > After some tests, it's just that my list contains 20'000 elements and > the integration takes forever to finish... > I thought Mathematica crashed because I thought it was a rather simple > thing to do but it turns out I would need to run this integration on a > powerful cluster or something :) Before going to the extremes, like using a cluster, you should try *Integrate[]* rather than *NIntegrate[]*. The symbolic integration tool *Integrate[]* works very well over *InterpolatingFunction* object and it is way faster (anything between about 40 and 100 times faster on my system). For instance, it can integrate over 100,000 points in 3/4th of a second. In[1]:= data = RandomReal[{-1000, 1000}, {10, 2}]; f = Interpolation[data]; Timing@Integrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] Timing@NIntegrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] %[[1]]/%%[[1]] Out[3]= {0.000163, -867887.} Out[4]= {0.017414, -867887.} Out[5]= 106.834 In[6]:= data = RandomReal[{-1000, 1000}, {100000, 2}]; f = Interpolation[data]; Timing@Integrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] Out[8]= {0.79024, -3.53364*10^7} In[9]:= $Version Out[9]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) -- === Subject: Re: Numerical integration and list of points > After some tests, it's just that my list contains 20'000 elements and > the integration takes forever to finish... > I thought Mathematica crashed because I thought it was a rather simple > thing to do but it turns out I would need to run this integration on a > powerful cluster or something :) Try using Integrate instead of NIntegrate. Integrate[] supports InterpolatingFunction objects directly, so this will be much faster than using NIntegrate[]. (I found out that Integrate can do this only because your message Example: In[1]:= f = Interpolation@Table[{x, Sin[x^2]}, {x, 0., 20, 20/20000}]; In[2]:= Integrate[f[x], {x, 0, 20}] // Timing Out[2]= {0.25, 0.639816} Check result: In[3]:= NIntegrate[Sin[x^2], {x, 0, 20}] Out[3]= 0.639816 (Indeed, NIntegrating this takes a very long time. I haven't had the patience to wait for it to finish.) Szabolcs === Subject: Re: Numerical integration and list of points with Mathematica 6.0.2 both: data = Table[{x, Sin[x]}, {x, 0, Pi, Pi/32}] // N; f = Interpolation[data] Integrate[f[t], {t, 0, Pi}] and NIntegrate[f[t], {t, 0, Pi}] gives 2.0 Jens > Hello everyone, > > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > > === Subject: Re: Numerical integration and list of points It seems to work for me: In[1]:= data = ({#1, Sin[13.4*#1]} & ) /@ Range[0, 4, 0.01]; f = Interpolation[data]; NIntegrate[f[x], {x, 0, 4}] Integrate[f[x], {x, 0, 4}] Integrate[Sin[a*x], x] % /. a -> 13.4 (% /. {x -> 4}) - (% /. {x -> 0}) During evaluation of In[1]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {0.126211}. NIntegrate obtained 0.14786850709355207` and 1.9590212682839143`*^-7 for the integral and error estimates. >> Out[3]= 0.147869 Out[4]= 0.147869 Out[5]= -(Cos[a x]/a) Out[6]= -0.0746269 Cos[13.4 x] Out[7]= 0.147869 > Hello everyone, I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Numerical integration and list of points > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... Well, the method is correct, but its implementation must be faulty in some way since Mathematica hangs. Without an actual sample of the code and data you are using, it is indeed hard to tell where the error is located. For instance, the following works like a charm on my system (and should on your system too) data = RandomReal[{0, 10}, {10, 2}] f = Interpolation[data] f // FullForm f[[1, 1]] f[2.5] Plot[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] Show[%, ListPlot[data]] Integrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] NIntegrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] -- === Subject: Re: Numerical integration and list of points HI, what you describe sounds reasonable and should work. Did you check for syntax errors? How many pints are there? Try it with a few points and you may find the bug. hope this helps, Daniel > Hello everyone, > > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > > === Subject: Re: List concatenation speed p = Table[x, {50}]; n = 10000; poly1 = {}; Print[Timing[Do[AppendTo[poly1, p], {n}]]]; poly2 = {}; Print[Timing[Do[poly2 = Append[poly2, p], {n}]]]; poly3 = {}; Print[Timing[Do[poly3 = Join[poly3, {p}], {n}]]]; Clear[poly4]; Print[Timing[poly4 = Reap[Table[Sow[p], {n}]][[2, 1]];]]; Clear[poly5]; Print[Timing[poly5 = Table[p, {n}];]]; {3.51951,Null} {3.50509,Null} {3.76392,Null} {0.009156,Null} {0.001755,Null} poly1 == poly2 == poly3 == poly4 == poly5 True If possible structure your problem to use Table or Sow and Reap. Bob Hanlon > 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: Documentation - what is the big secret? > On 10 Apr, 07:16, Jens-Peer Kuska the secret is called Wolfram Workbench 1.2 .. >> Jens > > But Workbench 1.2 is no excuse for not documentating the method to > produce documentation (there is a certain irony here). It is about a > year ago that 6.0 was released and to leave it a year and still not > have the information publically available seems bizare to me. > > There are 1001 tools designed specifically for creating web pages, yet > many people, myself included, prefer to use a text editor and write > PHP and HTML. At least give us that choice. > > And of course, 1.2 is not out, there is not even a link to download a > beta of 1.2. > > > > I absolutely agree with that! The Workbench should sell itself because of its intrinsic utility, NOT because certain vital functions are arbitrarily delegated to run on it! I would be very interested to know how useful people have found the Workbench. I tried to use it, but didn't have the time or patience to learn a wholly different way of working. When I last looked at it, the WB did not even display Mathematica characters - such as [Breve] - in Unicode form. Maybe I am missing a whole new level of productivity - I would quite like to know! David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Documentation - what is the big secret? On Apr 13, 3:33 am, Dr. David Kirkby I basically agree with David here. I think that there is indeed a > style of working that corresponds to the workflow in Workbench. And I= > suspect that there are many who like to work with it. However My > approach to Mathematica programming (and I have done a **lot** of it > over the years) is to code in notebooks and save to packages. So it > does make sense to include documentation tools inside of Workbench as > WRI is in the process of doing. But this needs to be in addition to documenting the format of the > documentation. I certainly agree such tools in the next version ofhttp://www.scientificarts.com/worklife/= . The way that I have created these has been to reverse engineer the > examples that are included with Mathematica: But it should not be necessary to reverse engineer files, as others have > said. Yes, that's also something I agree with. But I've done it and have put together a write-up of some of what I've learned which I will post sometime later this week. Hopefully it will help people get started doing bare bones additions of their material to the Documentation Center. I assume there are internal documents in Wolfram Research detailing how > to write documentation. Perhaps WRI could clean them up a bit and > release them. One the whole, Mathematica's documentation is excellent, > but it really seems to be let down in this area. I can think of no other > area where the documentation is so poor, although there might be areas I > don't know about. This all brings to mind what I think is the history of the former Help Browser. I think (and people can correct me here) that tools for creating documentation for the Help Browser trailed the release of Mathematica 3 (where the Help Browser appeared, I think) by at least one full version number. IT was then that Author Tools was included with Mathematica... have devoted so far to this aspect ofhttp://www.scientificarts.com/workl= ife= > of tools for Documenting withinhttp://www.scientificarts.com/worklife/ > follow-on releases ofhttp://www.scientificarts.com/worklife/. So, Frankly, the more folks who try and buyhttp://www.scientificarts.com= /work= > life/, > Trial Version at: >http://scientificarts.com/worklife/ Does it really need 6 links tohttp://scientificarts.com/worklife/in > one message? I understand you want to sell it, but that amount of I agree that the number of direct links was more than was necessary and I should have simply referred at those points to my product. So, my apologies... But this does bring up an interesting thread having to do with marketing Mathematica products--something that is very difficult--and I will start that thread perhaps in a later post. === Subject: Re: Documentation - what is the big secret? Bravo!!! Indeed, that Wolfram DID do this with earlier versions is one reason they succeeded so well, I believe (but have no data beyond anecdote to confirm). > > ...Anyone with a decade or so of experience in buying and using software > knows that major vendors who are busy developing a new consumer software > product or a major new release of an existing product often bring in one > or more trusted outside authors of known skill at writing user manuals > or introductory books, to write exactly such books about their emerging > product. > > In general, they give these outside authors full advance access to the > emerging product (with suitable nondisclosure agreements), so that the > resulting books can emerge simultaneously or very soon after the product > itself. > > The results of doing this are almost always good for the vendor > (increased publicity and sales, and their staff can focus totally on the > product, not the user documentation); good for the authors (who have > skills that the vendor's employees may never have); and most of all, > good for the ultimate users of the product. > > So, I'd really like to know: why the h-ll did Wolfram (apparently) not > do this with 6.0?!? (At least, I have yet to see the results of any > such effort on amazon.) A disastrous, or at least highly damaging, > failure, at least in my opinion. > -- 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: Documentation - what is the big secret? > So, I'd really like to know: why the h-ll did Wolfram (apparently) not > do this with 6.0?!? (At least, I have yet to see the results of any > such effort on amazon.) A disastrous, or at least highly damaging, > failure, at least in my opinion. I am 90% confident that I was told that Wolfram did have outside beta-testers for 6.0 quite some time prior to release. (I wish I would have been one of them--it would have saved me quite a bit of effort). I believe that it is understandable and perhaps necessary that documentation would lag behind release of new functions and packages. I haven't looked at the new doc. for 6.02, but it would be useful to treat the documention like the integrated data resources (i.e., update as updates become available). This would be much less pressure on the authors of new functions/packages. Furthermore, there is nothing stopping a usergroup from developing their own wiki version of supplementary documentation--except perhaps time and effort. -- W. Craig Carter === Subject: Re: Documentation - what is the big secret? > > the secret is called Wolfram Workbench 1.2 .. > > Jens > >> Given Mathematica 6 has been out for several months, why is there still no >> information about how to write documentation for 6? I see plenty of >> references to this on the web, including some on this mailing list very >> recently. But there seems to be no official information. >> I'm puzzled where there is so little information. >> Lin > Yes, but some of us are happy developing without using the Workbench, and it does seem unreasonable to bundle part of the core Mathematica system into this product. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Documentation - what is the big secret? And don't forget, a) previous versions of Workbench have been practically unusable (crashes, inexplicable GUI, etc.), and b) old-style documentation was never documented much, either. Bobby > On 10 Apr, 07:16, Jens-Peer Kuska the secret is called Wolfram Workbench 1.2 .. >> Jens But Workbench 1.2 is no excuse for not documentating the method to > produce documentation (there is a certain irony here). It is about a > year ago that 6.0 was released and to leave it a year and still not > have the information publically available seems bizare to me. There are 1001 tools designed specifically for creating web pages, yet > many people, myself included, prefer to use a text editor and write > PHP and HTML. At least give us that choice. And of course, 1.2 is not out, there is not even a link to download a > beta of 1.2. > -- DrMajorBob@longhorns.com === Subject: Re: Documentation - what is the big secret? > > But Workbench 1.2 is no excuse for not documentating the method to > produce documentation (there is a certain irony here). It is about a > year ago that 6.0 was released and to leave it a year and still not > have the information publically available seems bizare to me. > As an addendum to this: Anyone with a decade or so of experience in buying and using software knows that major vendors who are busy developing a new consumer software product or a major new release of an existing product often bring in one or more trusted outside authors of known skill at writing user manuals or introductory books, to write exactly such books about their emerging product. In general, they give these outside authors full advance access to the emerging product (with suitable nondisclosure agreements), so that the resulting books can emerge simultaneously or very soon after the product itself. The results of doing this are almost always good for the vendor (increased publicity and sales, and their staff can focus totally on the product, not the user documentation); good for the authors (who have skills that the vendor's employees may never have); and most of all, good for the ultimate users of the product. So, I'd really like to know: why the h-ll did Wolfram (apparently) not do this with 6.0?!? (At least, I have yet to see the results of any such effort on amazon.) A disastrous, or at least highly damaging, failure, at least in my opinion. === Subject: Re: Documentation - what is the big secret? I basically agree with David here. I think that there is indeed a style of working that corresponds to the workflow in Workbench. And I suspect that there are many who like to work with it. However My approach to Mathematica programming (and I have done a **lot** of it over the years) is to code in notebooks and save to packages. So it does make sense to include documentation tools inside of Workbench as WRI is in the process of doing. But it is also important to have such tools available directly in Mathematica; hence, why I am including such tools in the next version of http://www.scientificarts.com/worklife/. The way that I have created these has been to reverse engineer the examples that are included with Mathematica: essentially the content of the Documentation Center itself. This wasn't trivial, but with experimentation it could be figured out. With this knowledge, while there are many things that one can do via the text editor approach to modifying, for example, Pacletinfo.m files, there is much that really needs to be done programatically to create the functionality that you see in the Documentation Center. So it really requires the creation of an application within Mathematica to do this. One thing that I my do over the next week, if I can find the time, is to write up a bit of what I have learned in the 100 hours or so that I have devoted so far to this aspect of http://www.scientificarts.com/worklife= /. Perhaps that will help some folks get launched on their own at least making simple additions to the Documentation Center. With a cores set of tools for Documenting within http://www.scientificarts.com/worklife/ I will then have a platform for creating a variety of other functionalities (personalized electronic books, for example) in follow-on releases of http://www.scientificarts.com/worklife/. So, plese send me your thoughts on what you'd like to have included in later versions. Frankly, the more folks who try and buy http://www.scientificarts.com/work= life/, the more time I can devote to this. give it a spin! 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/ On Apr 11, 1:48 am, David Bailey the secret is called Wolfram Workbench 1.2 .. > Jens >> Given Mathematica 6 has been out for several months, why is there still= no >> information about how to write documentation for 6? I see plenty of >> references to this on the web, including some on this mailing list very= >> recently. But there seems to be no official information. >> I'm puzzled where there is so little information. >> Lin Yes, but some of us are happy developing without using the Workbench, > and it does seem unreasonable to bundle part of the core Mathematica > system into this product. David Baileyhttp://www.dbaileyconsultancy.co.uk === Subject: Re: Documentation - what is the big secret? > I basically agree with David here. I think that there is indeed a > style of working that corresponds to the workflow in Workbench. And I > suspect that there are many who like to work with it. However My > approach to Mathematica programming (and I have done a **lot** of it > over the years) is to code in notebooks and save to packages. So it > does make sense to include documentation tools inside of Workbench as > WRI is in the process of doing. But this needs to be in addition to documenting the format of the documentation. examples that are included with Mathematica: But it should not be necessary to reverse engineer files, as others have said. I assume there are internal documents in Wolfram Research detailing how to write documentation. Perhaps WRI could clean them up a bit and release them. One the whole, Mathematica's documentation is excellent, but it really seems to be let down in this area. I can think of no other area where the documentation is so poor, although there might be areas I don't know about. life/, http://scientificarts.com/worklife/ Does it really need 6 links to http://scientificarts.com/worklife/ in one message? I understand you want to sell it, but that amount of === Subject: Re: Labelling contours on contour plots I would like to create a contour plot with traditional, map-style labels. Here are some examples of such plots: http://upload.wikimedia.org/wikipedia/en/f/fa/Cntr-map-1.jpg http://www.mathworks.com/products/demos/shipping/map/mapexmap_15.png http://www.mathworks.com/access/helpdesk/help/techdoc/ref/contour1.gif I attached what I have so far, but the approach I used has several problems: 1. It doesn't work well if ContourShading is turned on. (One problem is the background of the text, another problem is that Normal[], which is used to expand GraphicsComplex objects so that p1 and p2 will be real coordinate-pairs, makes the shading ugly.) 2. I do not know how to position the labels in a way so that they will be close enough to each other to be readable, but still not overlap. Note how on the gr1 example some labels are drawn at one end of the contour lines, some at the other end. 3. It would be nice to be able to drop labels from regions of high gradients (to avoid overlapping/crowding). How could the labels be created in a better way, to avoid these problems? (* example graphics *) gr1 = Normal@ ContourPlot[Sin[x] Sin[y], {x, 0, 5}, {y, 0, 5}, PlotPoints -> 30, ContourShading -> None] gr2 = Normal@ ContourPlot[ Evaluate[Sum[Sin[RandomReal[5, 2].{x, y}], {5}]], {x, 0, 3}, {y, 0, 3}, ContourShading -> None, Contours -> 10] (* create labels *) (* This function collects the labels from the Tooltip objects, and positions them between the 21st and 22nd points of the contour line. *) makeLabels[gr_] := gr /. Tooltip[line : Line[{Longest@Repeated[_, 20], p1_, p2_, ___}], label_] :> {line, {Opacity[1], Rotate[Text[label, (p1 + p2)/2, Background -> White], Mod[ArcTan @@ (p2 - p1) + Pi/2, Pi] - Pi/2]}} makeLabels[gr1] makeLabels[gr2] === Subject: Re: Labelling contours on contour plots The Presentations package gives some extra control for labeling contour lines, or any line in a graphic that is described by a constant function. Here is an example from your second function. I think it is better in these cases to use a specific set of regular contour values. The operative routine is: DrawLineLabels[ constant Function on line, positioning Function for labels, error allowed in matching contour values, list of values to be labeled]. The list of contours to be labeled does not have to be the full set of contours used in the contour plot. The positioning function might be 0.5& to label lines half way along their length, or RandomReal[{.3,.5}]& to label them randomly somewhere in the middle section. You don't have to use Normal on the contour graphics. If you wanted to double label the contours you could use two DrawLineLabels routines. The desirable contourlist used in this example would depend on the specific case generated by your function. Needs[Presentations`Master`] f[x_, y_] = Evaluate[Sum[Sin[RandomReal[5, 2].{x, y}], {5}]] Sin[3.17456 x + 0.214736 y] + Sin[3.49989 x + 0.518615 y] + Sin[1.91662 x + 2.45835 y] + Sin[1.53246 x + 4.12794 y] + Sin[2.95345 x + 4.58416 y] Module[ {g, contourlist}, contourlist = Range[-4, 4, .25]; g = ContourDraw[f[x, y], {x, 0, 3}, {y, 0, 3}, Contours -> contourlist, ContourShading -> Automatic, ColorFunction -> ColorData[Pastel], PlotRange -> {-5, 5}]; Draw2D[ {g, g // DrawLineLabels[f[#1, #2] &, .5 &, 0.01, Range[-4, 4, 1], DrawLLTextOptions -> {Background -> None, BaseStyle -> {FontSize -> 10, FontFamily -> Helvetica}}]}, Frame -> True, ImageSize -> 450] ] Only every 4th contour line is labeled. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >I would like to create a contour plot with traditional, map-style > labels. Here are some examples of such plots: http://upload.wikimedia.org/wikipedia/en/f/fa/Cntr-map-1.jpg > http://www.mathworks.com/products/demos/shipping/map/mapexmap_15.png > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/contour1.gif I attached what I have so far, but the approach I used has several > problems: 1. It doesn't work well if ContourShading is turned on. (One problem is > the background of the text, another problem is that Normal[], which is > used to expand GraphicsComplex objects so that p1 and p2 will be real > coordinate-pairs, makes the shading ugly.) 2. I do not know how to position the labels in a way so that they will > be close enough to each other to be readable, but still not overlap. > Note how on the gr1 example some labels are drawn at one end of the > contour lines, some at the other end. 3. It would be nice to be able to drop labels from regions of high > gradients (to avoid overlapping/crowding). > How could the labels be created in a better way, to avoid these problems? > (* example graphics *) gr1 = Normal@ > ContourPlot[Sin[x] Sin[y], {x, 0, 5}, {y, 0, 5}, PlotPoints -> 30, > ContourShading -> None] gr2 = Normal@ > ContourPlot[ > Evaluate[Sum[Sin[RandomReal[5, 2].{x, y}], {5}]], > {x, 0, 3}, {y, 0, 3}, ContourShading -> None, Contours -> 10] (* create labels *) (* This function collects the labels from the Tooltip objects, and > positions them between the 21st and 22nd points of the contour line. *) makeLabels[gr_] := > gr /. > Tooltip[line : Line[{Longest@Repeated[_, 20], p1_, p2_, ___}], > label_] :> {line, {Opacity[1], > Rotate[Text[label, (p1 + p2)/2, Background -> White], > Mod[ArcTan @@ (p2 - p1) + Pi/2, Pi] - Pi/2]}} makeLabels[gr1] > makeLabels[gr2] > === Subject: mx files what is the preferred method to create packages in .mx files analogous to the initialization cell method in notebooks to maintain packages in the .m format? Hannes Kessler === Subject: Re: mx files DumpSave[] will do it. Jens > > what is the preferred method to create packages in .mx files analogous > to the initialization cell method in notebooks to maintain packages in > the .m format? > > Hannes Kessler > === Subject: Re: mx files What about the following example? BeginPackage[SomePackage`, {OtherPackage`}] ... EndPackage[] DumpSave[ SomePackage.mx, SomePackage`] Quit[] Needs[SomePackage`] The context OtherPackage` is not in $ContextPath as it should be. Hannes Kessler On 15 Apr., 12:49, Jens-Peer Kuska DumpSave[] will do it. Jens > what is the preferred method to create packages in .mx files analogous > to the initialization cell method in notebooks to maintain packages in > the .m format? > Hannes Kessler === Subject: Re: mx files DumpSave[ SomePackage.mx, {SomePackage`,OtherPackage`}] ?? Jens > What about the following example? > > BeginPackage[SomePackage`, {OtherPackage`}] > ... > EndPackage[] > DumpSave[ SomePackage.mx, SomePackage`] > > Quit[] > Needs[SomePackage`] > > The context OtherPackage` is not in $ContextPath as it should be. > > Hannes Kessler > > > On 15 Apr., 12:49, Jens-Peer Kuska DumpSave[] will do it. >> Jens > what is the preferred method to create packages in .mx files analogous > to the initialization cell method in notebooks to maintain packages in > the .m format? > Hannes Kessler > > === Subject: Re: Circles and Text Offset in Graphics3D >I have some Points in Graphics3D with a numeric label on >each one. The labels obscure the points. I'd like to move the text off >to the side of the point, but I don't see any offset that applies to >the 2D projection of the text. I tried putting a few spaces before the >actual label, but the spaces are dropped and the label is recentered >around its location so it still obscures the point. The Text primitive takes a 3rd argument that specifies how the text should be positioned relative to the projected reference point. By default text is positioned with the reference point at its center. This moves the text clear of the point on the right side: Graphics3D[{Point[{0, 0, 0}], Text[My Point, {0, 0, 0}, {-2, 0}]}] A more complete description of this 3rd argument and its coordinate system is found in the More Information section of the Text reference page. Chris Hill Wolfram Research === Subject: Circles and Text Offset in Graphics3D Two questions: 1. Is there any way to define a circle in Graphics3D other than by using a Cylinder with a very short length? I'm doing that now but it seems inefficient, and especially calculating the direction of the cylinder's axis seems unnecessary. The circle could be defined by 3 points in 3D it goes through and the usual colors, thickness, etc. Or by its center, radius, and a vector parallel to the axis. 2. I have some Points in Graphics3D with a numeric label on each one. The labels obscure the points. I'd like to move the text off to the side of the point, but I don't see any offset that applies to the 2D projection of the text. I tried putting a few spaces before the actual label, but the spaces are dropped and the label is recentered around its location so it still obscures the point. info. Steve Gray === Subject: Re: Circles and Text Offset in Graphics3D Steve, The Presentations package has commands Circle3D and Disk3D that work like Circle and Disk in 2D except that they also use a normal vector to determine the orientation. Presentations also has Text3D expressions that provide true 3D text that rotates with the image and hides behind surfaces. The present version uses vector fonts but the new version will also allow any of the standard fonts you have on your computer and even block characters. But this might not be the complete solution for you because at certain viewing angles (using the mouse say) points and the characters might still line up and at other angles the text might be viewed edge on. Still, since the images can be rotated, the 3D text gives a much more natural presentation than the wierd behavior of ordinary Text. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Two questions: 1. Is there any way to define a circle in Graphics3D other > than by using a Cylinder with a very short length? I'm doing that now > but it seems inefficient, and especially calculating the direction of > the cylinder's axis seems unnecessary. The circle could be defined by > 3 points in 3D it goes through and the usual colors, thickness, etc. > Or by its center, radius, and a vector parallel to the axis. 2. I have some Points in Graphics3D with a numeric label on > each one. The labels obscure the points. I'd like to move the text off > to the side of the point, but I don't see any offset that applies to > the 2D projection of the text. I tried putting a few spaces before the > actual label, but the spaces are dropped and the label is recentered > around its location so it still obscures the point. info. Steve Gray > === Subject: Re: Circles and Text Offset in Graphics3D 1) Manipulate[ Graphics3D[ Rotate[Rotate[ Rotate[Line[ Table[{Cos[phi], Sin[phi], 0}, {phi, 0, 2 Pi, 2 Pi/64}]], psi, {1, 0, 0}], th, {0, 0, 1}], phi, {1, 0, 0}], PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}} ], {psi, 0, 2 Pi}, {th, 0, 2 Pi}, {phi, 0, 2 Pi}] is not a circle ? and you can't orient it as you like ?? OK it is a polygon approximation to a circle .. 2) with Graphics3D[ MapIndexed[{Point[#1], Text[Style[#2[[1]], 16], #1, {-1, -1}]} &, {{0, 0, 0}, {1, 0, 0}, {0.5, 0.5, 0.5}}] ] I can move the graphics but the points are never obscured .. Jens > Two questions: > > 1. Is there any way to define a circle in Graphics3D other > than by using a Cylinder with a very short length? I'm doing that now > but it seems inefficient, and especially calculating the direction of > the cylinder's axis seems unnecessary. The circle could be defined by > 3 points in 3D it goes through and the usual colors, thickness, etc. > Or by its center, radius, and a vector parallel to the axis. > > 2. I have some Points in Graphics3D with a numeric label on > each one. The labels obscure the points. I'd like to move the text off > to the side of the point, but I don't see any offset that applies to > the 2D projection of the text. I tried putting a few spaces before the > actual label, but the spaces are dropped and the label is recentered > around its location so it still obscures the point. > > info. > > Steve Gray > === 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. David, Sorry to keep you waiting...I meant to reply to this immediately, but then my whole weekend went haywire. Player Pro won't load plain text package files. It will load package files which have been created using Encode[] or DumpSave[]. This restriction is to help ensure that behind the content created for a Player Pro is a genuine Mathematica license. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. === 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 Yes, this works for now, but you should not presume that this will continue to work in future versions. We don't document or support the behavior and may break it at any point in a future version. In fact, as a general principle of dealing with modern operating systems, you shouldn't even presume that you have write permissions to that directory. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. === Subject: Re: Derivative of a Conjugate Hello Andrzej and Daniel, All the Best, David === Subject: bar charts, frame ticks, and error bars Hello all, I've found a number of posts that deal with either using frames with bar charts or error bars with bar charts, but I've been having difficulty implementing those previous suggestions when it comes to a bar chart showing multiple sets of data. Take for example the following: BarChart[{{10, 20, 30, 40}, {5, 15, 25, 35}}, Frame -> {True, True, None, None}, FrameTicks -> {{{1, A}, {2, B}, {3, C}, {4, D}}, Automatic, None, None}] The problem with the result is that the ticks show up under the first bar of each set, when I would hope that the ticks would be at the center of each set. I haven't even tried to use error bars yet. Does anyone have any suggestions on how to make this work? And maybe, how to implement a plot legend with these multiple set bar charts? Dan === Subject: Re: bar charts, frame ticks, and error bars went through a lot of gyrations on formatting of charts, hate to say it, but I simply went back to MS Excel. > Hello all, I've found a number of posts that deal with either using frames with > bar charts or error bars with bar charts, but I've been having > difficulty implementing those previous suggestions when it comes to a > bar chart showing multiple sets of data. Take for example the > following: BarChart[{{10, 20, 30, 40}, {5, 15, 25, 35}}, > Frame -> {True, True, None, None}, > FrameTicks -> {{{1, A}, {2, B}, {3, C}, {4, D}}, Automatic, > None, None}] The problem with the result is that the ticks show up under the first > bar of each set, when I would hope that the ticks would be at the > center of each set. I haven't even tried to use error bars yet. Does > anyone have any suggestions on how to make this work? And maybe, how > to implement a plot legend with these multiple set bar charts? Dan === Subject: Solving equations and inequalities with Reduce - how? I tried to solve equations with Reduce and somehow did not quite formulate it right, so Reduce complains with Reduce::ivar: 1 is not a valid variable. This is what I tried: Wanted: A six digit number satisfying the following conditions: The first digit is not zero. If you take the first two digits and move them to the end of the number, the resulting number must be twice the original number. In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, Modulus[Rule]9] I did solve the problem through exhaustive search: In[14]:=Timing[Select[Range[10^6], FractionalPart[#/10000] 1000000 + IntegerPart[#/10000][Equal] 2 #&]] Out[14]={34.2848 Second,{142857,285714,428571}} but would like to understand how to use Reduce (or another function) to solve such a set of equations. TIA Marc -- remove bye and from mercial to get valid e-mail === Subject: Re: Solving equations and inequalities with Reduce - how? > I tried to solve equations with Reduce and somehow did not quite > formulate it right, so Reduce complains with > Reduce::ivar: 1 is not a valid variable. > > This is what I tried: > > Wanted: A six digit number satisfying the following conditions: > The first digit is not zero. > If you take the first two digits and move them to the end of the number, > the resulting number must be twice the original number. > > In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f > [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, > Modulus[Rule]9] > > I did solve the problem through exhaustive search: > > In[14]:=Timing[Select[Range[10^6], FractionalPart[#/10000] 1000000 + > IntegerPart[#/10000][Equal] 2 #&]] > Out[14]={34.2848 Second,{142857,285714,428571}} > > but would like to understand how to use Reduce (or another function) to > solve such a set of equations. > > TIA > > Marc > I realize this has been answered by now, but you might want to have a look at problem 1 in the notebook at http://library.wolfram.com/infocenter/Conferences/6530/ Among other things, I'll note that you really need to enforce one digitedness by inequalities, not with a Modulus setting. Along the lines of that notebook, here is some code for your particular problem. In[26]:= Reduce[{2*n==100*m+k, n==m+10^4*k, Element[{n,m,k},Integers], 10^4>m>=10^3, 0<=k<=99, n>=10^5}, {n,m,k}] Out[26]= (n == 142857 && m == 2857 && k == 14) || (n == 285714 && m == 5714 && k == 28) || (n == 428571 && m == 8571 && k == 42) Daniel Lichtblau Wolfram Research === Subject: Re: Solving equations and inequalities with Reduce - how? > I tried to solve equations with Reduce and somehow did not quite > formulate it right, so Reduce complains with > Reduce::ivar: 1 is not a valid variable. > > This is what I tried: > > Wanted: A six digit number satisfying the following conditions: > The first digit is not zero. > If you take the first two digits and move them to the end of the number, > the resulting number must be twice the original number. > > In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f > [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, > Modulus[Rule]9] > > I did solve the problem through exhaustive search: > > In[14]:=Timing[Select[Range[10^6], FractionalPart[#/10000] 1000000 + > IntegerPart[#/10000][Equal] 2 #&]] > Out[14]={34.2848 Second,{142857,285714,428571}} > > but would like to understand how to use Reduce (or another function) to > solve such a set of equations. Marc, First, one of your variables had been set to the value one before you tried Reduce[]. Second, the option Modulus->9 is not doing what you may have in mind (the solution yield by Reduce[] does not fulfill your original criteria ). Third, using FindInstance[] may help to formulate and check your problem in an algebraic way. For instance, starting with a fresh kernel, In[1]:= eqn = 200000 a + 20000 b + 2000 c + 200 d + 20 e + 2 f == 100000 c + 10000 d + 1000 e + 100 f + 10 a + b; In[2]:= Reduce[eqn && a != 0, {a, b, c, d, e, f}, Modulus -> 9] Out[2]= a != 0 && a == C[1] && b == C[2] && c == C[3] && d == C[4] && e == C[5] && f == 8 C[1] + 8 C[2] + 8 C[3] + 8 C[4] + 8 C[5] In[3]:= FindInstance[eqn && a != 0, {a, b, c, d, e, f}, Modulus -> 10] eqn /. %[[1]] Out[3]= {{a -> 1, b -> 0, c -> 0, d -> 0, e -> 0, f -> 0}} Out[4]= False In[5]:= FindInstance[eqn && a != 0, {a, b, c, d, e, f}, Integers] eqn /. %[[1]] Out[5]= {{a -> 1, b -> 4, c -> 0, d -> 0, e -> 0, f -> 2857}} Out[6]= True -- === Subject: Re: Solving equations and inequalities with Reduce - how? Hello Marc, Your initial example worked fine for me: Reduce[200000 a + 20000 b + 2000 c + 200 d + 20 e + 2 f == 100000 c + 10000 d + 1000 e + 100 f + 10 a + b, {a, b, c, d, e, f}, Modulus -> 9] resulted in a == C[1] && b == C[2] && c == C[3] && d == C[4] && e == C[5] && f == 8 C[1] + 8 C[2] + 8 C[3] + 8 C[4] + 8 C[5] Perhaps you had a typo? In your original post you had 20000a and not 20000 a Craig > I tried to solve equations with Reduce and somehow did not quite > formulate it right, so Reduce complains with > Reduce::ivar: 1 is not a valid variable. This is what I tried: Wanted: A six digit number satisfying the following conditions: > The first digit is not zero. > If you take the first two digits and move them to the end of the number, > the resulting number must be twice the original number. In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f > [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, > Modulus[Rule]9] I did solve the problem through exhaustive search: In[14]:=Timing[Select[Range[10^6], FractionalPart[#/10000] 1000000 + > IntegerPart[#/10000][Equal] 2 #&]] > Out[14]={34.2848 Second,{142857,285714,428571}} but would like to understand how to use Reduce (or another function) to > solve such a set of equations. TIA Marc -- > remove bye and from mercial to get valid e-mail > -- W. Craig Carter === Subject: Re: Solving equations and inequalities with Reduce - how? > I tried to solve equations with Reduce and somehow did not quite > formulate it right, so Reduce complains with > Reduce::ivar: 1 is not a valid variable. This is what I tried: Wanted: A six digit number satisfying the following conditions: > The first digit is not zero. > If you take the first two digits and move them to the end of the > number, > the resulting number must be twice the original number. In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f > [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, > Modulus[Rule]9] I did solve the problem through exhaustive search: In[14]:=Timing[Select[Range[10^6], FractionalPart[#/10000] > 1000000 + > IntegerPart[#/10000][Equal] 2 #&]] > Out[14]={34.2848 Second,{142857,285714,428571}} but would like to understand how to use Reduce (or another function) > to > solve such a set of equations. TIA Marc -- > remove bye and from mercial to get valid e-mail > Reduce[200000*a + 20000*b + 2000*c + 200*d + 20*e + 2*f == 100000*c + 10000*d + 1000*e + 100*f + 10*a + b && Inequality[1, Less, a, LessEqual, 9] && 0 <= b <= 9 && 0 <= c <= 9 && 0 <= d <= 9 && 0 <= e <= 9 && 0 <= f <= 9, {a, b, c, d, e, f}, Integers] (a == 2 && b == 8 && c == 5 && d == 7 && e == 1 && f == 4) || (a == 4 && b == 2 && c == 8 && d == 5 && e == 7 && f == 1) Andrzej Kozlowski === Subject: Re: Solving equations and inequalities with Reduce - how? > I tried to solve equations with Reduce and somehow did not quite > formulate it right, so Reduce complains with > Reduce::ivar: 1 is not a valid variable. > One of the variables that you used in the equation already had a value. Try it again in a fresh kernel. > This is what I tried: > > Wanted: A six digit number satisfying the following conditions: > The first digit is not zero. > If you take the first two digits and move them to the end of the number, > the resulting number must be twice the original number. > > In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f > [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, > Modulus[Rule]9] Here Modulus does not do what you expect (restrict the digits to 0..9). But here's a way to solve the problem with Reduce: We need to tell reduce that all of a, b, ..., f are integer digits, i.e. 0 <= ... < 10, and also that a is not 0: In[1]:= Reduce[ a != 0 && 200000 a + 20000 b + 2000 c + 200 d + 20 e + 2 f == 100000 c + 10000 d + 1000 e + 100 f + 10 a + b && And @@ Thread[0 <= {a, b, c, d, e, f} < 10], {a, b, c, d, e, f}, Integers] Out[1]= (a == 1 && b == 4 && c == 2 && d == 8 && e == 5 && f == 7) || (a == 2 && b == 8 && c == 5 && d == 7 && e == 1 && f == 4) || (a == 4 && b == 2 && c == 8 && d == 5 && e == 7 && f == 1) In[2]:= {ToRules[%]} Out[2]= {{a -> 1, b -> 4, c -> 2, d -> 8, e -> 5, f -> 7}, {a -> 2, b -> 8, c -> 5, d -> 7, e -> 1, f -> 4}, {a -> 4, b -> 2, c -> 8, d -> 5, e -> 7, f -> 1}} Out[3]= {142857, 285714, 428571} === Subject: Re: Solving equations and inequalities with Reduce - how? Hi Marc, your syntax is correct. But you met a common pit fall. On of your variables already had a value (of 1) and therefore got replaced by this value before Reduce got it. You may clear a value by e.g. a=. or Clear[a]. hope this helps, Daniel > I tried to solve equations with Reduce and somehow did not quite > formulate it right, so Reduce complains with > Reduce::ivar: 1 is not a valid variable. > > This is what I tried: > > Wanted: A six digit number satisfying the following conditions: > The first digit is not zero. > If you take the first two digits and move them to the end of the number, > the resulting number must be twice the original number. > > In[23]:=Reduce[200000a +20000 b +2000 c+200 d+20 e + 2 f > [Equal]100000c +10000 d +1000 e+100 f+10 a + b , {a,b,c,d,e,f}, > Modulus[Rule]9] > > I did solve the problem through exhaustive search: > > In[14]:=Timing[Select[Range[10^6], FractionalPart[#/10000] 1000000 + > IntegerPart[#/10000][Equal] 2 #&]] > Out[14]={34.2848 Second,{142857,285714,428571}} > > but would like to understand how to use Reduce (or another function) to > solve such a set of equations. > > TIA > > Marc > === Subject: How to solve this simple equation? least find an optimal solution for the following equation: y = 0.00324184/(2 + 2.78456 (1/y)^0.4) Dino === Subject: Re: How to solve this simple equation? > least find an optimal solution for the following equation: > > y = 0.00324184/(2 + 2.78456 (1/y)^0.4) You may want to try Solve[] (or Reduce[]) as in (note the *double* equal sign to check logical equality) In[29]:= Solve[y == 0.00324184/(2 + 2.78456 (1/y)^0.4)] Out[29]= {{y -> 0.0000127162}} -- === Subject: Re: How to solve this simple equation? Solve[y == 0.00324184/(2 + 2.78456 (1/y)^(4/10)), y] ARTUR dinodeblasio@gmail.com pisze: > least find an optimal solution for the following equation: y = 0.00324184/(2 + 2.78456 (1/y)^0.4) Dino > __________ NOD32 Informacje 2701 (20071204) __________ Wiadomosc zostala sprawdzona przez System Antywirusowy NOD32 > http://www.nod32.com lub http://www.nod32.pl === Subject: Re: How to solve this simple equation? Hello Dino, It is a good strategy to look graphically before trying a numerical solution: Plot[{0.00324184/(2 + 2.78456 (1/y)^0.4), y}, {y, 0, .00005}, PlotRange -> {0, .00005}] FindRoot[0.00324184/(2 + 2.78456 (1/y)^0.4) == y, {y, .00001}] Of course, there may be other (and complex) solutions... Craig > least find an optimal solution for the following equation: y = 0.00324184/(2 + 2.78456 (1/y)^0.4) Dino -- W. Craig Carter === Subject: Re: How to solve this simple equation? Hi Dino, look up Solve or Reduce in the manual. Daniel > least find an optimal solution for the following equation: > > y = 0.00324184/(2 + 2.78456 (1/y)^0.4) > > Dino > === Subject: Re: Numerical integration and list of points data = Sort[RandomReal[{0, 1}, {10, 2}]]; f = Interpolation[data]; xMin = f[[1, 1, 1]]; xMax = f[[1, 1, 2]]; Plot[f[x], {x, xMin, xMax}] Integrate[f[x], {x, xMin, xMax}] -2.16322 NIntegrate[f[x], {x, xMin, xMax}] -2.16322 Bob Hanlon > Hello everyone, > > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > > === Subject: A kernel, multiple notebooks, and Global? Pardon any awkward wordings here, but I may not have all the jargon relevant to my query clearly understood. Suppose that on a single-user computer I have several notebooks open that address different parts of a common calculation, and thus share overlapping sets of globally used variable names. The broad question is then, how far can I go -- or what dangers may lurk -- in treating these multiple notebooks as essentially one unified notebook that just happens to be stored in multiple files and appear on screen in multiple windows? 1) For example, in terms of contexts or scopes, I'm guessing that Global is Global: the Global` context for all of these notebooks is set by or recorded by the kernel, and at any one instant is exactly the same for all these open notebooks -- right? 2) Suppose a certain Input cell is present in exactly identical form at some random (i.e., different) point in each of the notebooks; I've been executing cells from all of the notebooks in some irregular sequence; and then I execute this particular cell in whichever of the notebooks happens to be most convenient for me. I assume the kernel is likely to be able to recognize which notebook submitted these Input instructions. But beyond that, unless this cell contains some code which directly or indirectly identifies the notebook in which the cell resides, and uses this information to modify the Input instructions, executing the copy of this cell that resides in any of the notebooks will produce exactly the same result, except for where it displays its output -- right? === Subject: Re: A kernel, multiple notebooks, and Global? > The broad question is then, how far can I go -- or what dangers may lurk > -- in treating these multiple notebooks as essentially one unified > notebook that just happens to be stored in multiple files and appear on > screen in multiple windows? I usually jump between several notebooks in the same session. This hasn't caused any trouble yet. But you should know about a setting that (I think) is new in Mathematica 6: Check the menu item Evaluation -> Notebook's Default Context -> With this setting it is possible to set up different contexts for each notebook, or even each cell group. So just make sure that this is set to Global`. (I think that this setting is saved with the notebook so be careful when you receive notebooks from other people.) Another possible problem: In Mathematica 5 I used to scribble on the documentation pages, and everything I evaluated there was available globally. But it seems that in Mathematica 6 the default setting for doc pages is unique context to each cell group, so be careful: what you evaluate in doc pages will be put into a separate context. === Subject: Re: A kernel, multiple notebooks, and Global? both your assumptions are correct. Daniel > Pardon any awkward wordings here, but I may not have all the jargon > relevant to my query clearly understood. > > Suppose that on a single-user computer I have several notebooks open > that address different parts of a common calculation, and thus share > overlapping sets of globally used variable names. > > The broad question is then, how far can I go -- or what dangers may lurk > -- in treating these multiple notebooks as essentially one unified > notebook that just happens to be stored in multiple files and appear on > screen in multiple windows? > > 1) For example, in terms of contexts or scopes, I'm guessing that > Global is Global: the Global` context for all of these notebooks is > set by or recorded by the kernel, and at any one instant is exactly the > same for all these open notebooks -- right? > > 2) Suppose a certain Input cell is present in exactly identical form at > some random (i.e., different) point in each of the notebooks; I've been > executing cells from all of the notebooks in some irregular sequence; > and then I execute this particular cell in whichever of the notebooks > happens to be most convenient for me. > > I assume the kernel is likely to be able to recognize which notebook > submitted these Input instructions. But beyond that, unless this cell > contains some code which directly or indirectly identifies the notebook > in which the cell resides, and uses this information to modify the Input > instructions, executing the copy of this cell that resides in any of the > notebooks will produce exactly the same result, except for where it > displays its output -- right? > === Subject: Re: A kernel, multiple notebooks, and Global? > > both your assumptions are correct. > But be aware that this is only correct for the default settings, at least in version 6. When one of the Notebooks or one of the Cells has an explicit setting for CellContext the symbols created within this Notebook or Cell will appear in a different context than Global`. I just wanted to mention this for the case that the OP asked this question because he is trying to track down a problem related to this. In that case it might be a good idea to check the settings of CellContext on a per notebook and per cell level. Also I think it would not be a good idea to base a package functionality on this default behavior because as soon as people start to use this feature, a package relying on the default behavior might break... Oh, and of course the Notebooks Kernel could also be set to another one for each one of the notebooks, but that is probably more obvious... hth, albert === Subject: Package to 'graft' Lists onto Matrices I've been looking at Join[ ], Append[ ], Insert[ ], etc. and wonder if someone has written a package that allows an Mathematica user to add Lists as rows and columns to form a new matrix. It seems a little daft that that you need to use MapThread and Append to simply graft a row onto an existing matrix! Am I missing some new functionality? Robert Prince-Wright Houston TX, 77006 USA === Subject: Re: Package to 'graft' Lists onto Matrices Hi Robert, look at ArrayFlatten in version 6 and BlockMatrix up until version 5.2. Oliver > I've been looking at Join[ ], Append[ ], Insert[ ], etc. and wonder if > someone has written a package that allows an Mathematica user to add > Lists as rows and columns to form a new matrix. It seems a little daft that that you need to use MapThread and Append to simply graft a row onto an existing matrix! Am I missing some new functionality? > Robert Prince-Wright > Houston > TX, 77006 > USA Oliver Ruebenkoenig, === Subject: Re: Player Pro and Packages My concern is just the reverse of what your reply seems to address: I do NOT want packages within the locations to which MATHEMATICA_BASE and MATHEMATICA_USERBASE point to be sought first by Player Pro. I want to be able to have a separate location for, say, an encoded version of a package that I'm running with Player Pro, and a source-visible package I use for development within Mathematica itself. It sounds then like the only alternative would be to put the encoded version directly within the PlayerPro tree (is there an AddOns/Applications subdirectory?). So... Will that work -- will PlayerPro first search for a package within its own directory tree despite settings of MATHEMATICA_BASE and MATHEMATICA_USERBASE? If not, that's really bad! If so, that's only partly good: it still forces me to put such things as (encoded) packages within the PlayerPro tree that might get wiped out whenever I re-install or upgrade PlayerPro. > Yes. Although, in retrospect, we should have considered changing the names of > these environment variables for Player Pro. We might decide to do this in a > future version, but for now, MATHEMATICA_BASE and MATHEMATICA_USERBASE will > function just fine. > > For those who haven't noticed already (although most on this thread seem to have > realized it by now), the default values of $BaseDirectory and $UserBaseDirectory > are different from those in Mathematica, and so packages installed for > Mathematica will not, by default, show up for Player Pro (i.e., you'll have to > install Player Pro packages separately). > > > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. > > >> 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 Yes. Although, in retrospect, we should have considered changing the names of these environment variables for Player Pro. We might decide to do this in a future version, but for now, MATHEMATICA_BASE and MATHEMATICA_USERBASE will function just fine. For those who haven't noticed already (although most on this thread seem to have realized it by now), the default values of $BaseDirectory and $UserBaseDirectory are different from those in Mathematica, and so packages installed for Mathematica will not, by default, show up for Player Pro (i.e., you'll have to install Player Pro packages separately). John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > 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 === Subject: Re: Any One have an idea? >Does anyone have any idea how to do or come up with the knight's >tour problem. Please give me some idea how to do it! >The program is used a random number to select a starting position >for the knight, and select the next position by selecting one of the >available positions at random. When the knight reaches a position >from which the number of the last possible available positions, the >tour is finished. The usual statement of the problem is from a random starting point visit every square of the chessboard once. When that is done, the tour is finished. See === Subject: Re: Numerical integration and list of points >I have a function which I read as a list of points. I want then to >estimate its integral. I do more or less this : >data={{x1,y1},{x2,y2},...,{xN,yN}} f=Interpolation[data] >NIntegrate[f[x],{x,x1,xN}] >Is it the correct way ? Because Mathematica hangs without giving me >an answer although it seems a pretty straightforward thing to do... What you've outlined above should work. Since it doesn't work for you there must be something else impacting the computation you aren't showing us. For example, I just did the following with no problems: In[9]:= data = Sort[Transpose@{#, Sin[#]} &@RandomReal[{0, [Pi]}, {50}]]; f = Interpolation[data]; NIntegrate[f[x], {x, 0, [Pi]}] Out[11]= 2. === Subject: Re: Numerical integration and list of points >I have a function which I read as a list of points. I want then to >estimate its integral. I do more or less this : >data={{x1,y1},{x2,y2},...,{xN,yN}} >f=Interpolation[data] >NIntegrate[f[x],{x,x1,xN}] >Is it the correct way ? Because Mathematica hangs without giving me >an answer although it seems a pretty straightforward thing to do... Yes, it seems straightforward and it should work. If it isn't working for you, then there must be something else going on with your code you haven't shown. For example, In[1]:= data = Sort[Transpose@{#, Sin[#]} &[RandomReal[{0, Pi}, {50}]]]; f = Interpolation[data]; NIntegrate[f[x], {x, 0, Pi}] Out[3]= 2. Gives the expected result === Subject: Re: A Problem with Simplify >Try the following: >Integrate[Exp[(a - 1)*x], x] /. a -> 1 >Integrate[Cos[(a - 1)*x], x] /. a -> 1 >Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 >Integrate[Cos[a x]/Sin[x], x] /. a -> 1 >There is the ONE underlying BUG! There is no bug here. Each of the integrals you do above result in an expression divided by (a-1). The replacement rule simply substitutes 1 for a everywhere. Consequently, the denominator of each integral evaluates to 0 and Mathematica returns either Indeterminate or ComplexInfinity as it should. Where you expecting a to be replaced by 1 before the integration was done? If so, the syntax should be written Integrate[f/.a->1,x] Or perhaps you were expecting Mathematica to simplify the results of the integral before replacing a with 1. If so, you need either FullSimplify[Integrate[f,x]]/.a->1 or Simplify[Integrate[f,x]]/.a->1 However, neither of these are guaranteed to remove the singularity. So, these may result in exactly what you got. === Subject: Re: A Problem with Simplify >Try the following: >Integrate[Exp[(a - 1)*x], x] /. a -> 1 >Integrate[Cos[(a - 1)*x], x] /. a -> 1 >Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 >Integrate[Cos[a x]/Sin[x], x] /. a -> 1 >There is the ONE underlying BUG! There is no bug here. Each of the integrals you do above result > in an expression divided by (a-1). The replacement rule simply > substitutes 1 for a everywhere. Consequently, the denominator of > each integral evaluates to 0 and Mathematica returns either > Indeterminate or ComplexInfinity as it should. Where you expecting a to be replaced by 1 before the integration > was done? If so, the syntax should be written Integrate[f/.a->1,x] Or perhaps you were expecting Mathematica to simplify the > results of the integral before replacing a with 1. If so, you > need either FullSimplify[Integrate[f,x]]/.a->1 or Simplify[Integrate[f,x]]/.a->1 However, neither of these are guaranteed to remove the > singularity. So, these may result in exactly what you got. I am expecting to get all partial answers or at least an answer with conditions! >In the manual one finds: > For indefinite integrals, Integrate tries to find results that are > correct for almost all values of parameters. This note is located under MORE INFORMATION field in the reference for Integrate. And this seems to be false... :( And for definite integrals there is an option GenerateConditions that does not work in the most cases (try it with example above: int1 = Integrate[Sin[a*x/L]*Sin[x/L], {x, 0, L}, GenerateConditions -> True] int1 /. a -> 1 The answer is Indeterminate that is false! :( ). === Subject: Re: A Problem with Simplify > For indefinite integrals, Integrate tries to find results that are > correct for almost all values of parameters. This note is located under MORE INFORMATION field in the reference > for Integrate. And this seems to be false... :( And for definite > integrals there is an option GenerateConditions that does not work > in the most cases (try it with example above: > int1 = Integrate[Sin[a*x/L]*Sin[x/L], {x, 0, L}, GenerateConditions - True] > int1 /. a -> 1 > The answer is Indeterminate that is false! :( > ). Again, the given behavior is not a bug. It is similar to Mathematica returning x^(n+1)/(n+1) for the indefinite integral of x^n, or simplifying x/x to 1. You missed the part in the manual where it says that Integrate tries to find results that are correct for *almost all* (emphasis added) values of parameters. Bhuvanesh, Wolfram Research === I'm using Grid to show some parameters as follows (Fixed-width font): ptedgeL ptfaceL ptsphrL ttencl 10 10 5 3 ptvertS3= {{-75, -51, -45}, {27, 30, -9}} ptvertS4= {{-32, -69, -57}, {-31,-31,59},{-21,56,-46}} leftward near the ptsphrL so I could display more parameters on the first two lines above the lists, but it did not do that in any of the ways I tried. (Actually I have more Grid cells at the left of all the lines, but this email can't be that wide.) The Help isn't totally Steve Gray === Hi Steve, it is not clear to me where your problem is. If I try: tit={ptedgeL,ptfaceL,ptsphrL,ttencl}; d1={10,10,5,3}; Grid[{tit,d1}] I get: ptedgeL ptfaceL ptsphrL ttencl 10 10 5 3 what seems o.k. to me. I am using version 6. Daniel > I'm using Grid to show some parameters as follows (Fixed-width font): > > ptedgeL ptfaceL ptsphrL ttencl > 10 10 5 3 > ptvertS3= {{-75, -51, -45}, {27, 30, -9}} > ptvertS4= {{-32, -69, -57}, {-31,-31,59},{-21,56,-46}} > > leftward near the ptsphrL so I could display more parameters on the > first two lines above the lists, but it did not do that in any of the > ways I tried. (Actually I have more Grid cells at the left of all the > lines, but this email can't be that wide.) The Help isn't totally > > Steve Gray > === > I'm using Grid to show some parameters as follows (Fixed-width font): > > ptedgeL ptfaceL ptsphrL ttencl > 10 10 5 3 > ptvertS3= {{-75, -51, -45}, {27, 30, -9}} > ptvertS4= {{-32, -69, -57}, {-31,-31,59},{-21,56,-46}} > > leftward near the ptsphrL so I could display more parameters on the > first two lines above the lists, but it did not do that in any of the > ways I tried. (Actually I have more Grid cells at the left of all the > lines, but this email can't be that wide.) The Help isn't totally > > Steve Gray > Is this what you are looking for? Grid[{ {ptedgeL , ptfaceL, ptsphrL, ttencl}, {10, 10, 5, 3}, {ptvertS4=, {{-32, -69, -57}, {-31, -31, 59}, {-21, 56, -46}}, }, Dividers -> All, Alignment -> Left ] I find it very useful to include the Dividers->All option to better understand what Grid does, even if I might decide to remove it in the end for aesthetic reasons... hth, albert === Subject: Re: EdgeRenderingFunction to produce edge labels in GraphPlot For a Graph[...] object created within Combinatorica (e.g., Cycle[3], Wheel[4], etc., and graphs derived from them by adding or removing edges or vertices), if one want to retain their vertices' coordinates in the plane when displaying with GraphPlot, then Method->None is used. The complexity of the methods you proposed to work around the additional difficulties I raised will likely scare the daylights out of the undergraduates in my Discrete Structures course! And that complexity suggests the need for further development of Combinatorica and/or GraphPlot so as to allow the two to coexist more comfortably. Obviously one of the core difficulties now is the different structure for graphs that Combinatorica, and its ShowGraph function, expect, on the one hand, and the vertex-coordinate-free structure for graphs fed to GraphPlot, on the other hand. Vertex coordinates are part of a Combinatorica-type graph. I'd sure hate to see that additional structure disappear in any effort to bridge the gap. For many graphs, the way vertex coordinates are chosen automatically by Combinatorica functions often leads to much more attractive disposition of vertices and edges. Yet GraphPlot ofen provides more flexible control over over vertex and edge labeling than does Combinatorica`ShowGraph. One thing that neither method seems to do nicely is to give complete, easy flexibility over placement of vertex or edge labels so that these labels don't lie on top of the vertices or edges, respectively, and at the same time have positions individually controllable so as to keep the labels from being partly obscured by edges (or vertices). Overall, then, I would conclude that the language design issues of handling of graphs is not yet sufficiently understood, or at least if it is sufficiently understood, then the implementation is at a suboptimal intermediate stage right now. That's my two cents. > >> But... >> (1) The first method you suggest -- to use SetEdgeLabels to build the >> labels into the Graph object -- does not seem to allow the option >> Method->None in GraphPlot: >> g=Cycle[3]; >> g=SetEdgeLabels[g,{a,b,c}]; >> GraphPLot[g,Method->None] >> This produces a GraphPlot::mthd error saying that None is not a >> permissible method. Why not? I do NOT want GraphPlot to relocate the >> vertices in the plane drawing, but to maintain their location; that's >> the purpose of Method->None, after all. Method->Automatic moves >> vertices and creates an unpleasnt skewing of the eges away from their >> original positions. (This becomes more evident with more complicated >> graphs, e.g., those having horizontal or vertical egdes.) >> > I don't know anything about Method->None. > > If you want to use my first method and maintain the vertex locations, > then you need to include that information in the call to GraphPlot. > > Here is a function that creates the usual rule structure that GraphPlot > expects from a Combinatorica graph (with vertex and edge labels): > > torules[Graph[edges_, vertices_, ___]] := Module[ > {vrules}, > vrules = DeleteCases[ > Thread[Range[Length[vertices]] -> (VertexLabel /. vertices[[All,2 > ;;]])], > _ -> VertexLabel > ]; > Replace[ > Transpose[{Rule @@@ (edges[[All,1]] /. vrules), EdgeLabel /. > edges[[All,2 ;;]]}], > {a_, EdgeLabel} -> a, > {1} > ] > ] > > Here is a function that extracts coordinates from a Combinatorica graph: > > getcoords[Graph[edges_, vertices_, ___]] := > Thread[Rule[Range[Length[vertices]], vertices[[All, 1]]]] > > So, let's create a graph with edge and vertex labels: > > g = SetEdgeLabels[SetVertexLabels[Cycle[3], {a, b, c}], {x, y, z}]; > > Now, we'll use GraphPlot to view the graph: > > GraphPlot[torules[g], EdgeLabeling->True, VertexLabeling->True, > VertexCoordinateRules->getcoords[g]] > >> (2) My graphs are UNdirected. I don't readily see how to adapt the >> second method -- using an EdgeRenderingFunction building upon an >> edgeLabelFunction -- to undirected graphs. >> Am I missing something obvious here with method (2)? >> > If you don't want to use Directed graphs, you'll just need to have your > edgeLabelFunction create the same label for both directions, i.e., {1,2} > and {2,1}. This is because GraphPlot will try to give labels to both > 1->2 and 2->1 if the graph is undirected. Here is an example: > > g = Cycle[3]; > labels = Characters[abc]; > edgeLabelFunction[{u_, v_}] := > labels[[First@Flatten@Position[Edges[Cycle[3]], {u, v} | {v, u}]]] > > 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]}]}}], > Arrow[#1]} &)] > > Carl Woll > Wolfram Research > >> >> 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 >> > -- 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: EdgeRenderingFunction to produce edge labels in GraphPlot >But... (1) The first method you suggest -- to use SetEdgeLabels to build the >labels into the Graph object -- does not seem to allow the option >Method->None in GraphPlot: g=Cycle[3]; > g=SetEdgeLabels[g,{a,b,c}]; > GraphPLot[g,Method->None] This produces a GraphPlot::mthd error saying that None is not a >permissible method. Why not? I do NOT want GraphPlot to relocate the >vertices in the plane drawing, but to maintain their location; that's >the purpose of Method->None, after all. Method->Automatic moves >vertices and creates an unpleasnt skewing of the eges away from their >original positions. (This becomes more evident with more complicated >graphs, e.g., those having horizontal or vertical egdes.) > > I don't know anything about Method->None. If you want to use my first method and maintain the vertex locations, then you need to include that information in the call to GraphPlot. Here is a function that creates the usual rule structure that GraphPlot expects from a Combinatorica graph (with vertex and edge labels): torules[Graph[edges_, vertices_, ___]] := Module[ {vrules}, vrules = DeleteCases[ Thread[Range[Length[vertices]] -> (VertexLabel /. vertices[[All,2 ;;]])], _ -> VertexLabel ]; Replace[ Transpose[{Rule @@@ (edges[[All,1]] /. vrules), EdgeLabel /. edges[[All,2 ;;]]}], {a_, EdgeLabel} -> a, {1} ] ] Here is a function that extracts coordinates from a Combinatorica graph: getcoords[Graph[edges_, vertices_, ___]] := Thread[Rule[Range[Length[vertices]], vertices[[All, 1]]]] So, let's create a graph with edge and vertex labels: g = SetEdgeLabels[SetVertexLabels[Cycle[3], {a, b, c}], {x, y, z}]; Now, we'll use GraphPlot to view the graph: GraphPlot[torules[g], EdgeLabeling->True, VertexLabeling->True, VertexCoordinateRules->getcoords[g]] >(2) My graphs are UNdirected. I don't readily see how to adapt the >second method -- using an EdgeRenderingFunction building upon an >edgeLabelFunction -- to undirected graphs. Am I missing something obvious here with method (2)? > > If you don't want to use Directed graphs, you'll just need to have your edgeLabelFunction create the same label for both directions, i.e., {1,2} and {2,1}. This is because GraphPlot will try to give labels to both 1->2 and 2->1 if the graph is undirected. Here is an example: g = Cycle[3]; labels = Characters[abc]; edgeLabelFunction[{u_, v_}] := labels[[First@Flatten@Position[Edges[Cycle[3]], {u, v} | {v, u}]]] 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]}]}}], Arrow[#1]} &)] Carl Woll Wolfram Research > >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: Re: EdgeRenderingFunction to produce edge labels in GraphPlot But... (1) The first method you suggest -- to use SetEdgeLabels to build the labels into the Graph object -- does not seem to allow the option Method->None in GraphPlot: g=Cycle[3]; g=SetEdgeLabels[g,{a,b,c}]; GraphPLot[g,Method->None] This produces a GraphPlot::mthd error saying that None is not a permissible method. Why not? I do NOT want GraphPlot to relocate the vertices in the plane drawing, but to maintain their location; that's the purpose of Method->None, after all. Method->Automatic moves vertices and creates an unpleasnt skewing of the eges away from their original positions. (This becomes more evident with more complicated graphs, e.g., those having horizontal or vertical egdes.) (2) My graphs are UNdirected. I don't readily see how to adapt the second method -- using an EdgeRenderingFunction building upon an edgeLabelFunction -- to undirected graphs. Am I missing something obvious here with method (2)? > >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 > -- Murray Eisenberg Internet: murray@math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) Amherst, MA 01003 Fax: 413-545-1801 === Subject: Re: Product Well, maybe I conceded too much too quickly ;-) > dealing with general tensors. Unfortunately I did not devote to this many > any detailed thought but instinctively felt that, in the case of general > tensors, it would not be as easy to do the same things with Apply and Plus > as with Total. When I first read your reply I again reacted too quickly and > conceded the entire point. However, after cosnidering this issue a little > more carefully, I now think the truth is more subtle. It was certainly very > rash of me to write it would be quite hard or impossible, as it is > clearly possible and in fact not at all hard. But now, I think, in the case > of tensors there can be significant inconveniences in using the Apply, Plus > combination instead of Total. Let me illustrate this. Consider this tensor: A = Array[a, {2, 3, 4}]; Now, with Total we can add all elements in A with: Total[A, Infinity] a[1, 1, 1] + a[1, 1, 2] + a[1, 1, 3] + a[1, 1, 4] + a[1, 2, 1] + a[1, 2, > 2] + > a[1, 2, 3] + a[1, 2, 4] + > a[1, 3, 1] + a[1, 3, 2] + a[1, 3, 3] + a[1, 3, 4] + a[2, 1, 1] + > a[2, 1, 2] + a[2, 1, 3] + a[2, 1, 4] + > a[2, 2, 1] + a[2, 2, 2] + a[2, 2, 3] + a[2, 2, 4] + a[2, 3, 1] + > a[2, 3, 2] + a[2, 3, 3] + a[2, 3, 4] or we can do the same with Total[A,-1]. Note, however, that this will give a completely different answer: Apply[Plus, A, {0, Infinity}] > 144 Of course what happened is that all the indexes got added. If we want to > add all the tensor entries you > need to correctly specify the highest level: Apply[Plus, A, {0, 2}] > a[1, 1, 1] + a[1, 1, 2] + a[1, 1, 3] + a[1, 1, 4] + a[1, 2, 1] + a[1, 2, 2] > + > a[1, 2, 3] + a[1, 2, 4] + > a[1, 3, 1] + a[1, 3, 2] + a[1, 3, 3] + a[1, 3, 4] + a[2, 1, 1] + > a[2, 1, 2] + a[2, 1, 3] + a[2, 1, 4] + > a[2, 2, 1] + a[2, 2, 2] + a[2, 2, 3] + a[2, 2, 4] + a[2, 3, 1] + > a[2, 3, 2] + a[2, 3, 3] + a[2, 3, 4] Note also that now your rule: > Total[expression, {n}] is equivalent to Apply[Plus, expression, {n-1}] > > does not work for negative indexes. Total[A,{-1}] is Apply[Plus,A,{-3}] > and not Apply[Plus,A,-2}]. > The reason is again the same: Apply counts negative levels beginning with > the atoms, which are in this case just the indexes. OK, so now comes my main point. Suppose that now we define a[x_, y_, z_] := Times[x, y, z] With this definition the array A turns into an array of integers. Now, note > that Total[A, Infinity] > 180 > Total[A, -1] > 180 have the same meaning as before, they are both the sum of all the entries > of A. But the meaning of Apply[Plus, A, {0, Infinity}] > 180 has now changed. Recall that earlier the answer was 140, which was the sum > of the indexes, and now it has become 180, which is the sum of entries. The > same applies to some of the other cases of using the Apply, Plus > combination. This change of meaning can be a serious inconvenience in > certain situations. So while you can certainly do the same things with Apply and Plus and level > specifications as with Total and level specifications, they seem to be > intended for different purposes. Apply and Plus are more suitable for > handling general expressions while Total is much more convenient for dealing > with tensors. While you can always achieve the same purpose with Apply and > Plus as with Total, doing so is not completely automatic but has to be based > on individual cases. So I conclude that the reason for the existence of Total is not simply that > of syntax but more importantly that of purpose: the Apply, Plus combination > is more suitable for handling general expressions but Total is more suitable > for dealing with tensors. I think it is a fairly significant difference. Total[] have a more important essential difference than the Method option. To sum up the main difference: Apply treats expressions with different heads in the same way. But Total only touches those subexpressions whose head matches the head of the complete expression. For example, Total[ f[...], Inifnity ] will only sum the terms of expressions with head f, and Total[ {...}, Infinity ] will only sum lists (but it treats everything else as atoms). Szabolcs === Subject: Re: Product > But of course in principle there is nothing that would make it > impossible to introduce a special case for functions like Times and > Plus, and make them work with packed arrays. So this alone does not > make it necessary to introduce a new syntax/new function, like Total[]. > > Well, I never claimed that it did. I didn't mean that you did :-) > It seems to me that WRI wanted to add > new functionality to Mathematica and modifying Plus would break too many > things. For example, Total, in version 6 accepts level specifications, so: Total[{{a, b}, {c, d}}, {2}] > {a + b, c + d} while Apply[Plus, {{a, b}, {c, d}}, {2}] > {{a, b}, {c, d}} The key thing, in my opinion, is that Total[list] is just a spacial case of > Total (=Total[list,1]) and the general case of Total would be quite hard or > impossible to define using Apply and Plus. > Actually one just needs to shift the level specification by 1, so Total[{{a, b}, {c, d}}, {2}] is equivalent to Apply[Plus, {{a, b}, {c, d}}, {1}] Generally, Total[expression, {n}] is equivalent to Apply[Plus, expression, {n-1}] and Total[expression, n] is equivalent to Apply[Plus, expression, {0, n-1}] Szabolcs HorvÌÁt === Subject: Re: Product These horrible computer gremlins are always trying to ruin my posts! In this one packed got changed into backed and never see into never say. Ugh! Andrzej > You are right of course and actually I realized that lists like > {Log[2],....}, which are list sof symbols, can't be backed. But, in > fact, I believed that my mytestlist was a list of reals and was > quite surprised it was being unpacked. It's partly the fault of > always putting thse semicolons at the end so I never say the actual > result of the comutation! Andrzej The reason for the speed of Total unlike Plus is that it does not > need > to unpack packed arrays. Here is how you can see what happens. SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; > Note that mytestlist is a list of integers. > Developer`PackedArrayQ[mytestlist] > True So mytestlist is a packed array. Now let's see what happens if we > add > it up using Plus: In[4]:= Plus @@ mytestlist > Unpacking array. > Unpacking array to > Out[4]= 4998322 Now the same with Total: In[5]:= Total[mytestlist] > Out[5]= 4998322 It is the unpacking of packed arrays by Plus that makes adding up > this > list using Plus much slower. > As for multiplying: I can't think of any way to multiply the > elements > of a list without unpacking. However, if, as in your example, the > list > contains only positive numbers the following will still beat Times > (though not by much): Timing[b = Exp[Total[Log[mytestlist]]]; ] > Unpacking array. > Unpacking array in call to Log > {2.0021780000000007, Null} > Note that {Log[2], Log[8], ...} cannot be a packed array of >> integers or reals. If one were to use: >> mytestlist = Table[RandomReal[{1, 9}], {1000000}]; >> then the Exp[Total[Log[mytestlist]]] approach would be a couple >> orders of magnitude faster. >> In[824]:= Timing[b = Exp[Total[Log[mytestlist]]]] >> Timing[c = Times @@ mytestlist] >> Out[824]= {0.016,3.490395044*10^639025} >> Out[825]= {1.156,3.490395043914*10^639025} >> Also, if one wants to extend this to a list of both positive and >> negative numbers (without 0, of course) then there are two >> possibilities. The simplest and probably best is to just do the >> same using Abs and counting the number of negative numbers. The >> other possibility is to convert mytestlist into a packed array of >> complex numbers. For example: >> mytestlist = Table[RandomReal[{-1,1}], {1000000}]; >> In[836]:= Timing[b = >> Exp[Total[Log[Developer`ToPackedArray[mytestlist, Complex]]]]] >> Timing[c = Times @@ mytestlist] >> Out[836]= >> Out[837]= {1.125,-2.460527426692*10^-434382} >> Here one would take the real part at the end, of course. >> Carl Woll >> Wolfram Research > while In[4]:= Timing[a = Times @@ mytestlist; ] > Unpacking array. > Unpacking array to level 1 > {0.30934300000000015, Null} a == b > True If there is a method of multiplying without unpacking it should be a > lot faster but at least at this moment I can't think of one. Andrzej Kozlowski >> (* Steven *) >> (* I think it is an interesting question *) >> (* See what happens when we compare total with other ways to add >> many small >> integers *) >> (* First a test list:*) >> In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; >> (* add all the numbers in the list, and also report the computer >> time used >> to calculate:*) >> In[2]:= Timing[Plus @@ mytestlist] >> Out[2]= {0.266, 5003966} >> (* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL >> and also >> report the computer time used to calculate:*) >> In[3]:= Timing[Total[mytestlist]] >> Out[3]= {0.031, 5003966} >> (* As you can see, for small integers, Total has a special >> algorithm >> that >> that adds ten times faster than just add all the numbers in order*) >> (* Therefore your question is equivalent to ask if there is an >> improved >> algorithm to multiply numbers, and if that algorithm is implemented >> in a >> special command in Mathematica, equivalent to Total*) >> (* I do not know the answer, while someone else answers this, you >> can >> multiply the following way:*) >> In[4]:= Times @@ mytestlist >> (* large result deleted *) >> (* The following link might be interesting for you:*) >> (* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) >> (* http://homepage.cem.itesm.mx/lgomez/matecmatica/ >> funcionalprog.nb *) >> (* Hope that helps *) >> (* Jose *) >> (* Mexico *) >> -----Mensaje original----- >> De: Steven [mailto:steven_504@telenet.be] >> Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. >> Para: mathgroup@smc.vnet.net >> Asunto: Product >> Silly beginner's question: is there a function to multiply all >> elements of a >> list, like Total does for addition? >> 'fraid I can't find it. >> TIA === Subject: Re: Product You are right of course and actually I realized that lists like {Log[2],....}, which are list sof symbols, can't be backed. But, in fact, I believed that my mytestlist was a list of reals and was quite surprised it was being unpacked. It's partly the fault of always putting thse semicolons at the end so I never say the actual result of the comutation! Andrzej >> The reason for the speed of Total unlike Plus is that it does not >> need >> to unpack packed arrays. Here is how you can see what happens. >> SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; >> mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; > Note that mytestlist is a list of integers. >> Developer`PackedArrayQ[mytestlist] >> True >> So mytestlist is a packed array. Now let's see what happens if we add >> it up using Plus: >> In[4]:= Plus @@ mytestlist >> Unpacking array. >> Unpacking array to >> Out[4]= 4998322 >> Now the same with Total: >> In[5]:= Total[mytestlist] >> Out[5]= 4998322 >> It is the unpacking of packed arrays by Plus that makes adding up >> this >> list using Plus much slower. >> As for multiplying: I can't think of any way to multiply the elements >> of a list without unpacking. However, if, as in your example, the >> list >> contains only positive numbers the following will still beat Times >> (though not by much): >> Timing[b = Exp[Total[Log[mytestlist]]]; ] >> Unpacking array. >> Unpacking array in call to Log >> {2.0021780000000007, Null} > Note that {Log[2], Log[8], ...} cannot be a packed array of integers > or reals. If one were to use: mytestlist = Table[RandomReal[{1, 9}], {1000000}]; then the Exp[Total[Log[mytestlist]]] approach would be a couple > orders of magnitude faster. In[824]:= Timing[b = Exp[Total[Log[mytestlist]]]] > Timing[c = Times @@ mytestlist] Out[824]= {0.016,3.490395044*10^639025} Out[825]= {1.156,3.490395043914*10^639025} Also, if one wants to extend this to a list of both positive and > negative numbers (without 0, of course) then there are two > possibilities. The simplest and probably best is to just do the same > using Abs and counting the number of negative numbers. The other > possibility is to convert mytestlist into a packed array of complex > numbers. For example: mytestlist = Table[RandomReal[{-1,1}], {1000000}]; In[836]:= Timing[b = > Exp[Total[Log[Developer`ToPackedArray[mytestlist, Complex]]]]] > Timing[c = Times @@ mytestlist] Out[836]= Out[837]= {1.125,-2.460527426692*10^-434382} Here one would take the real part at the end, of course. Carl Woll > Wolfram Research > while >> In[4]:= Timing[a = Times @@ mytestlist; ] >> Unpacking array. >> Unpacking array to level 1 >> {0.30934300000000015, Null} >> a == b >> True >> If there is a method of multiplying without unpacking it should be a >> lot faster but at least at this moment I can't think of one. >> Andrzej Kozlowski > (* Steven *) > (* I think it is an interesting question *) > (* See what happens when we compare total with other ways to add > many small > integers *) (* First a test list:*) In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; (* add all the numbers in the list, and also report the computer > time used > to calculate:*) In[2]:= Timing[Plus @@ mytestlist] Out[2]= {0.266, 5003966} (* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL > and also > report the computer time used to calculate:*) In[3]:= Timing[Total[mytestlist]] Out[3]= {0.031, 5003966} (* As you can see, for small integers, Total has a special algorithm > that > that adds ten times faster than just add all the numbers in order*) > (* Therefore your question is equivalent to ask if there is an > improved > algorithm to multiply numbers, and if that algorithm is implemented > in a > special command in Mathematica, equivalent to Total*) (* I do not know the answer, while someone else answers this, you > can > multiply the following way:*) In[4]:= Times @@ mytestlist (* large result deleted *) (* The following link might be interesting for you:*) > (* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) > (* http://homepage.cem.itesm.mx/lgomez/matecmatica/ > funcionalprog.nb *) (* Hope that helps *) > (* Jose *) > (* Mexico *) -----Mensaje original----- > De: Steven [mailto:steven_504@telenet.be] > Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. > Para: mathgroup@smc.vnet.net > Asunto: Product Silly beginner's question: is there a function to multiply all > elements of a > list, like Total does for addition? > 'fraid I can't find it. > TIA > === Subject: Re: Product >The reason for the speed of Total unlike Plus is that it does not need >to unpack packed arrays. Here is how you can see what happens. SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; > > Note that mytestlist is a list of integers. >Developer`PackedArrayQ[mytestlist] >True So mytestlist is a packed array. Now let's see what happens if we add >it up using Plus: In[4]:= Plus @@ mytestlist >Unpacking array. >Unpacking array to >Out[4]= 4998322 Now the same with Total: In[5]:= Total[mytestlist] >Out[5]= 4998322 It is the unpacking of packed arrays by Plus that makes adding up this >list using Plus much slower. >As for multiplying: I can't think of any way to multiply the elements >of a list without unpacking. However, if, as in your example, the list >contains only positive numbers the following will still beat Times >(though not by much): Timing[b = Exp[Total[Log[mytestlist]]]; ] >Unpacking array. >Unpacking array in call to Log >{2.0021780000000007, Null} > > Note that {Log[2], Log[8], ...} cannot be a packed array of integers or reals. If one were to use: mytestlist = Table[RandomReal[{1, 9}], {1000000}]; then the Exp[Total[Log[mytestlist]]] approach would be a couple orders of magnitude faster. In[824]:= Timing[b = Exp[Total[Log[mytestlist]]]] Timing[c = Times @@ mytestlist] Out[824]= {0.016,3.490395044*10^639025} Out[825]= {1.156,3.490395043914*10^639025} Also, if one wants to extend this to a list of both positive and negative numbers (without 0, of course) then there are two possibilities. The simplest and probably best is to just do the same using Abs and counting the number of negative numbers. The other possibility is to convert mytestlist into a packed array of complex numbers. For example: mytestlist = Table[RandomReal[{-1,1}], {1000000}]; In[836]:= Timing[b = Exp[Total[Log[Developer`ToPackedArray[mytestlist, Complex]]]]] Timing[c = Times @@ mytestlist] Out[836]= Out[837]= {1.125,-2.460527426692*10^-434382} Here one would take the real part at the end, of course. Carl Woll Wolfram Research >while In[4]:= Timing[a = Times @@ mytestlist; ] >Unpacking array. >Unpacking array to level 1 >{0.30934300000000015, Null} a == b >True If there is a method of multiplying without unpacking it should be a >lot faster but at least at this moment I can't think of one. Andrzej Kozlowski >(* Steven *) >>(* I think it is an interesting question *) >>(* See what happens when we compare total with other ways to add >>many small >>integers *) >>(* First a test list:*) >>In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; >>(* add all the numbers in the list, and also report the computer >>time used >>to calculate:*) >>In[2]:= Timing[Plus @@ mytestlist] >>Out[2]= {0.266, 5003966} >>(* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL >>and also >>report the computer time used to calculate:*) >>In[3]:= Timing[Total[mytestlist]] >>Out[3]= {0.031, 5003966} >>(* As you can see, for small integers, Total has a special algorithm >>that >>that adds ten times faster than just add all the numbers in order*) >>(* Therefore your question is equivalent to ask if there is an >>improved >>algorithm to multiply numbers, and if that algorithm is implemented >>in a >>special command in Mathematica, equivalent to Total*) >>(* I do not know the answer, while someone else answers this, you can >>multiply the following way:*) >>In[4]:= Times @@ mytestlist >>(* large result deleted *) >>(* The following link might be interesting for you:*) >>(* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) >>(* http://homepage.cem.itesm.mx/lgomez/matecmatica/funcionalprog.nb *) >>(* Hope that helps *) >>(* Jose *) >>(* Mexico *) >>-----Mensaje original----- >>De: Steven [mailto:steven_504@telenet.be] >>Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. >>Para: mathgroup@smc.vnet.net >>Asunto: Product >>Silly beginner's question: is there a function to multiply all >>elements of a >>list, like Total does for addition? >>'fraid I can't find it. >>TIA >> > === Subject: Re: Product Sorry, I was completly blind when I did the timings. Looking at the results again it is a clear as can be that Times @@ mytestlist is almost an order of magnitude faster then Exp[Total[Log[mytestlist]]]. So at this time I cna see now way to multiply faster than with Times. Andrzej Kozlowski > The reason for the speed of Total unlike Plus is that it does not > need to unpack packed arrays. Here is how you can see what happens. SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; > Developer`PackedArrayQ[mytestlist] > True So mytestlist is a packed array. Now let's see what happens if we > add it up using Plus: In[4]:= Plus @@ mytestlist > Unpacking array. > Unpacking array to > Out[4]= 4998322 Now the same with Total: In[5]:= Total[mytestlist] > Out[5]= 4998322 It is the unpacking of packed arrays by Plus that makes adding up > this list using Plus much slower. > As for multiplying: I can't think of any way to multiply the > elements of a list without unpacking. However, if, as in your > example, the list contains only positive numbers the following will > still beat Times (though not by much): Timing[b = Exp[Total[Log[mytestlist]]]; ] > Unpacking array. > Unpacking array in call to Log > {2.0021780000000007, Null} while In[4]:= Timing[a = Times @@ mytestlist; ] > Unpacking array. > Unpacking array to level 1 > {0.30934300000000015, Null} a == b > True If there is a method of multiplying without unpacking it should be a > lot faster but at least at this moment I can't think of one. Andrzej Kozlowski > (* Steven *) >> (* I think it is an interesting question *) >> (* See what happens when we compare total with other ways to add >> many small >> integers *) >> (* First a test list:*) >> In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; >> (* add all the numbers in the list, and also report the computer >> time used >> to calculate:*) >> In[2]:= Timing[Plus @@ mytestlist] >> Out[2]= {0.266, 5003966} >> (* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL >> and also >> report the computer time used to calculate:*) >> In[3]:= Timing[Total[mytestlist]] >> Out[3]= {0.031, 5003966} >> (* As you can see, for small integers, Total has a special >> algorithm that >> that adds ten times faster than just add all the numbers in order*) >> (* Therefore your question is equivalent to ask if there is an >> improved >> algorithm to multiply numbers, and if that algorithm is implemented >> in a >> special command in Mathematica, equivalent to Total*) >> (* I do not know the answer, while someone else answers this, you can >> multiply the following way:*) >> In[4]:= Times @@ mytestlist >> (* large result deleted *) >> (* The following link might be interesting for you:*) >> (* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) >> (* http://homepage.cem.itesm.mx/lgomez/matecmatica/funcionalprog.nb >> *) >> (* Hope that helps *) >> (* Jose *) >> (* Mexico *) >> -----Mensaje original----- >> De: Steven [mailto:steven_504@telenet.be] >> Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. >> Para: mathgroup@smc.vnet.net >> Asunto: Product >> Silly beginner's question: is there a function to multiply all >> elements of a >> list, like Total does for addition? >> 'fraid I can't find it. >> TIA > === Subject: Re: Product The reason for the speed of Total unlike Plus is that it does not need to unpack packed arrays. Here is how you can see what happens. SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; Developer`PackedArrayQ[mytestlist] True So mytestlist is a packed array. Now let's see what happens if we add it up using Plus: In[4]:= Plus @@ mytestlist Unpacking array. Unpacking array to Out[4]= 4998322 Now the same with Total: In[5]:= Total[mytestlist] Out[5]= 4998322 It is the unpacking of packed arrays by Plus that makes adding up this list using Plus much slower. As for multiplying: I can't think of any way to multiply the elements of a list without unpacking. However, if, as in your example, the list contains only positive numbers the following will still beat Times (though not by much): Timing[b = Exp[Total[Log[mytestlist]]]; ] Unpacking array. Unpacking array in call to Log {2.0021780000000007, Null} while In[4]:= Timing[a = Times @@ mytestlist; ] Unpacking array. Unpacking array to level 1 {0.30934300000000015, Null} a == b True If there is a method of multiplying without unpacking it should be a lot faster but at least at this moment I can't think of one. Andrzej Kozlowski > (* Steven *) > (* I think it is an interesting question *) > (* See what happens when we compare total with other ways to add > many small > integers *) (* First a test list:*) In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; (* add all the numbers in the list, and also report the computer > time used > to calculate:*) In[2]:= Timing[Plus @@ mytestlist] Out[2]= {0.266, 5003966} (* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL > and also > report the computer time used to calculate:*) In[3]:= Timing[Total[mytestlist]] Out[3]= {0.031, 5003966} (* As you can see, for small integers, Total has a special algorithm > that > that adds ten times faster than just add all the numbers in order*) > (* Therefore your question is equivalent to ask if there is an > improved > algorithm to multiply numbers, and if that algorithm is implemented > in a > special command in Mathematica, equivalent to Total*) (* I do not know the answer, while someone else answers this, you can > multiply the following way:*) In[4]:= Times @@ mytestlist (* large result deleted *) (* The following link might be interesting for you:*) > (* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) > (* http://homepage.cem.itesm.mx/lgomez/matecmatica/funcionalprog.nb *) (* Hope that helps *) > (* Jose *) > (* Mexico *) -----Mensaje original----- > De: Steven [mailto:steven_504@telenet.be] > Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. > Para: mathgroup@smc.vnet.net > Asunto: Product Silly beginner's question: is there a function to multiply all > elements of a > list, like Total does for addition? > 'fraid I can't find it. > TIA > === Subject: Re: Product >> But of course in principle there is nothing that would make it >> impossible to introduce a special case for functions like Times and >> Plus, and make them work with packed arrays. So this alone does = >> not >> make it necessary to introduce a new syntax/new function, like >> Total[]. Well, I never claimed that it did. >> I didn't mean that you did :-) > It seems to me that WRI wanted to add > new functionality to Mathematica and modifying Plus would break > too many > things. For example, Total, in version 6 accepts level > specifications, so: Total[{{a, b}, {c, d}}, {2}] > {a + b, c + d} while Apply[Plus, {{a, b}, {c, d}}, {2}] > {{a, b}, {c, d}} The key thing, in my opinion, is that Total[list] is just a > spacial case of > Total (=Total[list,1]) and the general case of Total would be > quite hard or > impossible to define using Apply and Plus. > Actually one just needs to shift the level specification by 1, so >> Total[{{a, b}, {c, d}}, {2}] is equivalent to Apply[Plus, {{a, b}, = >> {c, d}}, {1}] >> Generally, >> Total[expression, {n}] is equivalent to Apply[Plus, expression, >> {n-1}] >> and >> Total[expression, n] is equivalent to Apply[Plus, expression, {0, = >> n-1}] >> Szabolcs Horv=E1t > Yes, you are right, of course. (I gues I should stop posting replies = > whose conents consist of the first thing that comes to my mind, but = > I usually do not have the time for much more). > Level specifications are certianly not the reason for having Total > (though I find them a bit more convenient to use - which is what > made me make that silly claim). I guess the reason was just the > feeling that the syntax of Apply and Plus was just a bit too > convoluted. Andrzej > Well, maybe I conceded too much too quickly ;-) mind dealing with general tensors. Unfortunately I did not devote to this many any detailed thought but instinctively felt that, in the case of general tensors, it would not be as easy to do the same things with Apply and Plus as with Total. When I first read your reply = I again reacted too quickly and conceded the entire point. However, after cosnidering this issue a little more carefully, I now think the = truth is more subtle. It was certainly very rash of me to write it would be quite hard or impossible, as it is clearly possible and in fact not at all hard. But now, I think, in the case of tensors there can be significant inconveniences in using the Apply, Plus combination = instead of Total. Let me illustrate this. Consider this tensor: A = Array[a, {2, 3, 4}]; Now, with Total we can add all elements in A with: Total[A, Infinity] a[1, 1, 1] + a[1, 1, 2] + a[1, 1, 3] + a[1, 1, 4] + a[1, 2, 1] + a[1, 2, 2] + a[1, 2, 3] + a[1, 2, 4] + a[1, 3, 1] + a[1, 3, 2] + a[1, 3, 3] + a[1, 3, 4] + a[2, 1, 1] + a[2, 1, 2] + a[2, 1, 3] + a[2, 1, 4] + a[2, 2, 1] + a[2, 2, 2] + a[2, 2, 3] + a[2, 2, 4] + a[2, 3, 1] + a[2, 3, 2] + a[2, 3, 3] + a[2, 3, 4] or we can do the same with Total[A,-1]. Note, however, that this will give a completely different answer: Apply[Plus, A, {0, Infinity}] 144 Of course what happened is that all the indexes got added. If we want = to add all the tensor entries you need to correctly specify the highest level: Apply[Plus, A, {0, 2}] a[1, 1, 1] + a[1, 1, 2] + a[1, 1, 3] + a[1, 1, 4] + a[1, 2, 1] + a[1, = 2, 2] + a[1, 2, 3] + a[1, 2, 4] + a[1, 3, 1] + a[1, 3, 2] + a[1, 3, 3] + a[1, 3, 4] + a[2, 1, 1] + a[2, 1, 2] + a[2, 1, 3] + a[2, 1, 4] + a[2, 2, 1] + a[2, 2, 2] + a[2, 2, 3] + a[2, 2, 4] + a[2, 3, 1] + a[2, 3, 2] + a[2, 3, 3] + a[2, 3, 4] Note also that now your rule: >> Total[expression, {n}] is equivalent to Apply[Plus, expression, >> {n-1}] does not work for negative indexes. Total[A,{-1}] is Apply[Plus,A, {-3}] and not Apply[Plus,A,-2}]. The reason is again the same: Apply counts negative levels beginning with the atoms, which are in this case just the indexes. OK, so now comes my main point. Suppose that now we define a[x_, y_, z_] := Times[x, y, z] With this definition the array A turns into an array of integers. Now, = note that Total[A, Infinity] 180 Total[A, -1] 180 have the same meaning as before, they are both the sum of all the entries of A. But the meaning of Apply[Plus, A, {0, Infinity}] 180 has now changed. Recall that earlier the answer was 140, which was the = sum of the indexes, and now it has become 180, which is the sum of entries. The same applies to some of the other cases of using the Apply, Plus combination. This change of meaning can be a serious inconvenience in certain situations. So while you can certainly do the same things with Apply and Plus and = level specifications as with Total and level specifications, they seem = to be intended for different purposes. Apply and Plus are more suitable for handling general expressions while Total is much more convenient for dealing with tensors. While you can always achieve the = same purpose with Apply and Plus as with Total, doing so is not completely automatic but has to be based on individual cases. So I conclude that the reason for the existence of Total is not simply = that of syntax but more importantly that of purpose: the Apply, Plus combination is more suitable for handling general expressions but Total is more suitable for dealing with tensors. I think it is a fairly significant difference. Andrzej Kozlowski === Subject: Re: Product > But of course in principle there is nothing that would make it > impossible to introduce a special case for functions like Times and > Plus, and make them work with packed arrays. So this alone does not > make it necessary to introduce a new syntax/new function, like > Total[]. > Well, I never claimed that it did. I didn't mean that you did :-) > It seems to me that WRI wanted to add >> new functionality to Mathematica and modifying Plus would break too >> many >> things. For example, Total, in version 6 accepts level >> specifications, so: >> Total[{{a, b}, {c, d}}, {2}] >> {a + b, c + d} >> while >> Apply[Plus, {{a, b}, {c, d}}, {2}] >> {{a, b}, {c, d}} >> The key thing, in my opinion, is that Total[list] is just a spacial >> case of >> Total (=Total[list,1]) and the general case of Total would be quite >> hard or >> impossible to define using Apply and Plus. Actually one just needs to shift the level specification by 1, so Total[{{a, b}, {c, d}}, {2}] is equivalent to Apply[Plus, {{a, b}, > {c, d}}, {1}] Generally, Total[expression, {n}] is equivalent to Apply[Plus, expression, > {n-1}] and Total[expression, n] is equivalent to Apply[Plus, expression, {0, > n-1}] Szabolcs Horv=E1t Yes, you are right, of course. (I gues I should stop posting replies whose conents consist of the first thing that comes to my mind, but I usually do not have the time for much more). Level specifications are certianly not the reason for having Total (though I find them a bit more convenient to use - which is what made me make that silly claim). I guess the reason was just the feeling that the syntax of Apply and Plus was just a bit too convoluted. Andrzej === Subject: Re: Product >> The reason for the speed of Total unlike Plus is that it does not >> need >> to unpack packed arrays. Here is how you can see what happens. >> SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; >> mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; >> Developer`PackedArrayQ[mytestlist] >> True >> So mytestlist is a packed array. Now let's see what happens if we add >> it up using Plus: >> In[4]:= Plus @@ mytestlist >> Unpacking array. : >> Unpacking array to >> Out[4]= 4998322 >> Now the same with Total: >> In[5]:= Total[mytestlist] >> Out[5]= 4998322 >> It is the unpacking of packed arrays by Plus that makes adding up >> this >> list using Plus much slower. But of course in principle there is nothing that would make it > impossible to introduce a special case for functions like Times and > Plus, and make them work with packed arrays. So this alone does not > make it necessary to introduce a new syntax/new function, like > Total[]. Well, I never claimed that it did. It seems to me that WRI wanted to add new functionality to Mathematica and modifying Plus would break too many things. For example, Total, in version 6 accepts level specifications, so: Total[{{a, b}, {c, d}}, {2}] {a + b, c + d} while Apply[Plus, {{a, b}, {c, d}}, {2}] {{a, b}, {c, d}} The key thing, in my opinion, is that Total[list] is just a spacial case of Total (=Total[list,1]) and the general case of Total would be = quite hard or impossible to define using Apply and Plus. Andrzej Kozlowski > For example, Unprotect[Apply] > Apply[Plus, arr_?Developer`PackedArrayQ] := Total[arr] > Protect[Apply] (Of course this is just an example to show that it is possible to do > this. It is not a complete implementation and certainly not something > that I would recommend for _users_ to do. But it would be nice if WRI > provided these special case algorithms unless there is some limitation > in Mathematica's internal design that makes it difficult/impossible to > do this in a proper way.) > === Subject: Re: Product > The reason for the speed of Total unlike Plus is that it does not need > to unpack packed arrays. Here is how you can see what happens. > > SetSystemOptions[PackedArrayOptions -> {UnpackMessage -> True}]; > > mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; > Developer`PackedArrayQ[mytestlist] > True > > So mytestlist is a packed array. Now let's see what happens if we add > it up using Plus: > > In[4]:= Plus @@ mytestlist > Unpacking array. > Unpacking array to > Out[4]= 4998322 > > Now the same with Total: > > In[5]:= Total[mytestlist] > Out[5]= 4998322 > > It is the unpacking of packed arrays by Plus that makes adding up this > list using Plus much slower. But of course in principle there is nothing that would make it impossible to introduce a special case for functions like Times and Plus, and make them work with packed arrays. So this alone does not make it necessary to introduce a new syntax/new function, like Total[]. For example, Unprotect[Apply] Apply[Plus, arr_?Developer`PackedArrayQ] := Total[arr] Protect[Apply] (Of course this is just an example to show that it is possible to do this. It is not a complete implementation and certainly not something that I would recommend for _users_ to do. But it would be nice if WRI provided these special case algorithms unless there is some limitation in Mathematica's internal design that makes it difficult/impossible to do this in a proper way.) === Subject: Re: Product But of course Total is also redundant! Plus @ {1,2,3,4} So the issue is one of language design: when does a particular case of a more general construction occur so frequently that a special function should be introduced for it. >> Silly beginner's question: is there a function to multiply all elements of a >> list, like Total does for addition? No, there isn't. But it would be redundant anyway because it is very > easy to build your own: In[1]:= Times @@ {1, 2, 3, 4, 5} > Out[1]= 120 Look up Apply in the documentation. > -- 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: Product Sorry about my typo @ instead of @@. Yes, of course that's what I was referring to: including a special, additional function that does what a special case of a more general construct. But simplicity and elegance of the language is only one design consideration. Another is usability. I can see someone coming to Mathematica who, among other things, just wants to get some computations = done that involve adding up a list of numbers, who would prefer to be able to use a single function Total rather than the combination of Plus and Apply. >> But of course Total is also redundant! Plus @ {1,2,3,4} >> So the issue is one of language design: when does a particular case of= a >> more general construction occur so frequently that a special function >> should be introduced for it. ...Personally I think that the *syntax* Total[list] provides nothing ov= er > Plus @@ list, so just because summation is a common operation, a new > syntax should not be introduced for it. In fact I would consider the > introduction of too many redundant constructs bad language design. -- 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: Product > But of course Total is also redundant! Plus @ {1,2,3,4} > > So the issue is one of language design: when does a particular case of a > more general construction occur so frequently that a special function > should be introduced for it. Total[] and Accumulate[] are not completely redundant. Total[] is faster than Plus @@ # &, and also less precise by default. When using Total[] or Accumulate[], one has the option to choose between a faster and a more precise (Method -> CompensatedSummation) summation method. Personally I think that the *syntax* Total[list] provides nothing over Plus @@ list, so just because summation is a common operation, a new syntax should not be introduced for it. In fact I would consider the introduction of too many redundant constructs bad language design. Note that faster algorithms for special cases *can* be implemented without a new syntax/new function. Mathematica does exactly this for many operations. But the syntax Plus @@ list or FoldList[Plus, 0, list] cannot (should not?) be extended to allow for selecting between two algorithms just for the special case of summation. Thus the introduction of Total[] and Accumulate[] was legitimate. These two functions do not only provide a new syntax, but also new functionality. > > Silly beginner's question: is there a function to multiply all elements of a > list, like Total does for addition? >> No, there isn't. But it would be redundant anyway because it is very >> easy to build your own: >> In[1]:= Times @@ {1, 2, 3, 4, 5} >> Out[1]= 120 >> Look up Apply in the documentation. >> === Subject: Re: Product > Silly beginner's question: is there a function to multiply all elements > of a list, like Total does for addition? > 'fraid I can't find it. > TIA Apply[Times,list] will do what you want. -- ---------------------------------------- Informatique technique et scientifique http://www.dxdydz.net Jean-Marie Thomas +33 (0)3 88 32 93 64 +33 (0)6 37 18 86 63 === Subject: Re: Product (* Steven *) (* I think it is an interesting question *) (* See what happens when we compare total with other ways to add many small integers *) (* First a test list:*) In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; (* add all the numbers in the list, and also report the computer time used to calculate:*) In[2]:= Timing[Plus @@ mytestlist] Out[2]= {0.266, 5003966} (* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL and also report the computer time used to calculate:*) In[3]:= Timing[Total[mytestlist]] Out[3]= {0.031, 5003966} (* As you can see, for small integers, Total has a special algorithm that that adds ten times faster than just add all the numbers in order*) (* Therefore your question is equivalent to ask if there is an improved algorithm to multiply numbers, and if that algorithm is implemented in a special command in Mathematica, equivalent to Total*) (* I do not know the answer, while someone else answers this, you can multiply the following way:*) In[4]:= Times @@ mytestlist (* large result deleted *) (* The following link might be interesting for you:*) (* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) (* http://homepage.cem.itesm.mx/lgomez/matecmatica/funcionalprog.nb *) (* Hope that helps *) (* Jose *) (* Mexico *) -----Mensaje original----- De: Steven [mailto:steven_504@telenet.be] Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. Para: mathgroup@smc.vnet.net Asunto: Product Silly beginner's question: is there a function to multiply all elements of a list, like Total does for addition? 'fraid I can't find it. TIA === Subject: Re: Product > Silly beginner's question: is there a function to multiply all elements of a > list, like Total does for addition? > 'fraid I can't find it. Hi Steven, This not a silly question since such a built-in function does not exist. Nevertheless, it is very easy to the product of a list by changing its head. What does that mean? Every Mathematica expression is made of a head, say h, and some elements, say e1, e2, etc., that is an expression if of the form h[e1, e2, ...] The difference among a list, a sum, and a product of variables, therefore, is just their heads. For instance, List[a, b, c, d] (* {a, b, c, d} *) Plus[a, b, c, d] (* a + b + c + d *) Times[a, b, c, d] (* a * b * c * d *) are the canonical --- or *FullForm* --- representation of the list, sum, and product of the four variables a, b, c, and d (assuming they are unassigned). To go from one representation to another, it suffice to The following should illustrate the process. {a, b, c, d} (* => {a, b, c, d} *) FullForm[{a, b, c, d}] (* => List[a, b, c, d] *) Total[{a, b, c, d}] (* => a + b + c + d *) FullForm[Total[{a, b, c, d}]] (* => Plus[a, b, c, d] *) Apply[Plus, {a, b, c, d}] (* => a + b + c + d *) Apply[Times, {a, b, c, d}] (* => a b c d *) Range[5] (* => {1, 2, 3, 4, 5} *) FullForm[Range[5]] (* => List[1, 2, 3, 4, 5] *) Apply[Plus, Range[5]] (* => 15 *) Apply[Times, Range[5]] (* => 120 *) -- === Subject: Generalised ImagePadding->All Mathematica's ImagePadding (v6.0.1) only accepts options either All None m {{l,r},{u,d}} Where m/l/r/u/d all must be dimensions in points. But I'd like to use All in any combination of the l/r/u/d; for example: ImagePadding->{{All,All},{50,50}} to, say, still allow enough space for horizontal tick labels but pad things out more vertically. Does v6.0.2 improve this situation? If not, is it possible to calculate these values manually? Will === Subject: smart change of variables? I have a arithmetic problem. I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) where p1 + p2 = k1 + k2 I wanna make the following change of variables, s = (p1 + p2)^2 t = (p1 - k1)^2 u = (p1 - k2)^2 Is it possible to tell Mathematica to express expr in terms of s, t, and u automatically? any ideas would be appreciated. === Subject: Re: smart change of variables? (eqns = {expr == (p1 + 2 p2) (k1 + 2 k2), p1 + p2 == k1 + k2, s == (p1 + p2)^2, t == (p1 - k1)^2, u == (p1 - k2)^2}) // Column Solve[eqns, expr, {k1, k2, p1, p2}] {{expr -> 1/4 (9 s - t - 6 Sqrt[s] Sqrt[u] + u)}, {expr -> 1/4 (9 s - t + 6 Sqrt[s] Sqrt[u] + u)}} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? any ideas would be appreciated. > === Subject: Re: smart change of variables? expr = (p1 + 2*p2)*(k1 + 2*k2) sol = Solve[ { p1 + p2 == k1 + k2, s == (p1 + p2)^2, t == (p1 - k1)^2, u == (p1 - k2)^2}, {k1, k2, p1, p2} ]; newform = expr/.sol; Length[newform] I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? any ideas would be appreciated. -- W. Craig Carter === Subject: Re: smart change of variables? > > I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 > > Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? > > any ideas would be appreciated. More or less. You can create a Groebner basis out of the defining polynomials, such that variables p1, p2, k1, and k2 are ordered higher than s, t, and u. Then generalized division (aka polynomial reduction) of expr will do what it can to make such a replacement. polys = {s-(p1+p2)^2,t-(p1-k1)^2,u-(p1-k2)^2,p1+p2-(k1+k2)}; vars = {p1,p2,k1,k2,s,t,u}; gb = GroebnerBasis[polys, vars]; In[19]:= InputForm[PolynomialReduce[(p1+2*p2)*(k1+2*k2), gb, vars][[2]]] Out[19]//InputForm= 3*k2*p2 + (3*s)/2 + t/2 - u/2 In general the replacement will be dependent on variable and monomial ordering. But I'm fairly certain that you will be stuck with some part not replaced no matter waht orders are used, since this particular variable/monomial ordering does not manage to reduce k2*p2. Daniel Lichtblau Wolfram Research === Subject: Re: smart change of variables? > > I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 > > Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? > > any ideas would be appreciated. > Barrow, You could use Eliminate[] and Reduce[] as in the following (note that you have two answers for the final expression since quadratics are involved) In[40]:= Eliminate[ f == (p1 + 2*p2)*(k1 + 2*k2) && p1 + p2 == k1 + k2 && s == (p1 + p2)^2 && t == (p1 - k1)^2 && u == (p1 - k2)^2, {p1, p2, k1, k2}] Out[40]= -81 s^2 + 18 s t - t^2 + 18 s u + 2 t u - u^2 == 16 f^2 + f (-72 s + 8 t - 8 u) In[41]:= Reduce[%, f] Out[41]= f == 1/4 (9 s - t - 6 Sqrt[s] Sqrt[u] + u) || f == 1/4 (9 s - t + 6 Sqrt[s] Sqrt[u] + u) -- === Subject: Re: smart change of variables? Sorry , just made a type. Here is the correct code: Solve[{expr==(k1+2 k2) (p1+2 p2),p1+p2==k1+k2,s==(p1+p2)^2,t==(-k1+p1)^2,u==(-k2+p1)^2},expr,{p1,p2,k1,k2 }] Daniel > > I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 > > Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? > > any ideas would be appreciated. > === Subject: Re: smart change of variables? Hi barrow, you may achieve this using e.g. Solve: Solve[{expr==(k1+2 k2) (p1+2 p2)p1+p2==k1+k2,s==(p1+p2)^2,t==(-k1+p1)^2,u==(-k2+p1)^2,},expr,{p1,p2,k1,k2 }] hope this helps, Daniel > > I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 > > Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? > > any ideas would be appreciated. > === Subject: Re: smart change of variables? > > I have a arithmetic problem. > I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) > where p1 + p2 = k1 + k2 > I wanna make the following change of variables, > s = (p1 + p2)^2 > t = (p1 - k1)^2 > u = (p1 - k2)^2 > > Is it possible to tell Mathematica to express expr > in terms of s, t, and u automatically? Use Eliminate to get rid of variables: In[1]:= Eliminate[{expr == (p1 + 2*p2)*(k1 + 2*k2), p1 + p2 == k1 + k2, s == (p1 + p2)^2, t == (p1 - k1)^2, u == (p1 - k2)^2}, {p1, k1, p2, k2}] Out[1]= -81 s^2 + 18 s t - t^2 + 18 s u + 2 t u - u^2 == 16 expr^2 + expr (-72 s + 8 t - 8 u) In[2]:= Reduce[%, expr] Out[2]= expr == 1/4 (9 s - t - 6 Sqrt[s] Sqrt[u] + u) || expr == 1/4 (9 s - t + 6 Sqrt[s] Sqrt[u] + u) === Subject: Dynamic (more) Hi! The following gives the (expected?) result 1: p = 0; q = 0; Dynamic[q = p + 1]; Dynamic[q] This one gives {1, 1}, also as I would expect: DynamicModule[{p, q}, p = 0; q = 0; {Dynamic[q = p + 1], Dynamic[q]}] Can anybody explain why the next gives 0? DynamicModule[{p, q}, p = 0; q = 0; Dynamic[q = p + 1]; Dynamic[q] ] Try the following pair too: DynamicModule[{p = 0, q}, {Dynamic[q = p + 1], Dynamic[q]}] DynamicModule[{p = 0, q}, Dynamic[q = p + 1]; Dynamic[q]] Luca === Subject: Re: pdf and accents - SOLUTION FROM MYSELF Now I had a lesson with my smart students and they told me that I have to choose ''PDF printer'' from the File|Print|Printers menu, and then my .nb will be printed into a nice PDF file. Janos You are right, it is not Mathematica who does it for me, but the > Saving notebooks inPDFform I get an unreadable result if the text > is, say, in Hungarian, probably the same problem arises with other > languages with diacritical signs. Any idea? > Just the same happens if the text is in Russian. There is no way for > exporting such text toPDFexcept printing notebook toPDF-printer. These are known limitations in Mathematica'sPDFexport capabilities. Rob > Wolfram Research === Subject: Re: pdf and accents > Saving notebooks in PDF form I get an unreadable result if the text > is, say, in Hungarian, probably the same problem arises with other > languages with diacritical signs. Any idea? Just the same happens if the text is in Russian. There is no way for > exporting such text to PDF except printing notebook to PDF-printer. These are known limitations in Mathematica's PDF export capabilities. Rob Wolfram Research === Subject: Re: Package to 'graft' Lists onto Matrices I still think Wolfram should have a simple, optimised, function that allows you to Insert and add matrices, vectors / lists into defined positions in an existing matrix. Something like: Graft[ list, mat, Column, 3] - which inserts list into matrix mat after column 3. Graft[ list, mat, Row, 2] - which inserts list into matrix mat after row 2. Or how about Graft[ mat1, mat2, Column, 3 - to insert a matrix. I find myself rethinking how to do this every now and then. (Your probably thinking I should just write a package - but what a waste of time for something so fundamental.) mat = RandomInteger[{0, 10}, {5, 7}]; mat // MatrixForm AddRow[mat_?MatrixQ, row_List] := Join[mat, {row}] AddRow[mat, {a, b, c, d, e, f, g}] // MatrixForm AddColumn[mat_?MatrixQ, column_List] := Transpose[Join[Transpose[mat], {column}]] AddColumn[mat, {a, b, c, d, e}] // MatrixForm No checking here or matching dimensions, but that could be built in easily. It seems a little daft that that you need to use MapThread and Append to simply graft a row onto an existing matrix! > -- W. Craig Carter Robert Prince-Wright Houston TX, 77006 USA === Subject: Re: EdgeRenderingFunction to produce edge labels in GraphPlot DeleteCases[ Thread[Range[Length[vertices]] -> (VertexLabel /. vertices[[All,2 ;;]])], _ -> VertexLabel ]; I am just curious. Why the DeleteCases? In this simple example DeleteCases does nothing. In what kind of graph would it have a function? with friendly greetings, P_ter === Subject: Re: Malformed Fractions in a PDF file Rob As requested, although the code below is even simplier. Everything appears correctly on the screen...the incomplete fractionline appears when printed to a pdf file, or when the notebook is simply printed. The problem disappears when a term (numerator or denominator) is 2-letter, e.g., xy / a. This didn't occur in 6.0.1 but the problem is now known to Wolfram Research. Bruce Cell[TextData[{ hello , Cell[BoxData[ FormBox[ FractionBox[x, y], TraditionalForm]], FormatType->TraditionalForm] }], Text, CellChangeTimes->{{3.417265252484375*^9, 3.417265254578125*^9}}] === Subject: Re: Malformed Fractions in a PDF file > Since sin 8/5[Theta]=sin(8/5([Theta]+2[Pi] n))=sin(8/5[Theta]+(16= [Pi] n)/5)... Can you include the actual cell expression? Select the cell bracket & choose Edit > Copy As > Cell Expression from the menu bar. I don't see any problems with the PDF created by Mathematica when simply copying the above text from my browser and pasting it into a text cell in Mathematica. -Rob === Subject: Re: Directory of Mathematica Add-Ons On Apr 13, 3:32 am, David Bailey > Contact the Wolfram Partnerships group... >>http://partnerships.wolfram.com/ > I don't think that would cover the many Mathematica packages - free and > otherwise - published independently of Wolfram. Correct. it includes only those that have negotiated a partnership agreement with Wolfram. --David David Baileyhttp://www.dbaileyconsultancy.co.uk === Subject: Re: Directory of Mathematica Add-Ons You are absolutely right. Of course one can distribute a package oneself as I do (in addition to doing it through WRI). The advantage of that is that one then does not have to share the revenue for those sales. And it is easy to set up payment methods using PayPal and Google Checkout (see http://scientificarts.com/worklife/purchase/ ). And there are other services that also are usable for sales of software and shareware such as kagi (http://www.kagi.com/index.php). The key problem really is marketing. One advantage of the Wolfram Partnerships group is that WRI then is an additional route to marketing presence. But in my offering of http://scientificarts.com/worklife the most difficult thing that I find is getting people to try it. And this has lead me to learn more of why, in the real world, active advertising is unfortunately essential. So the real question in my mind is how to get Mathematica users to try applications that are offered. There are very few routes to marketing Mathematica applications--very few places where Mathematica users congregate. And in those places (and remember that an application developer usually does not have a marketing budget--I don't-- significant revenue is needed to support such a budget) one has to find a way to convince the users to give the application a try. My experience is that very few do try. My experience with my application is that of those who do try, a significant percentage do buy the product. Of course those of us who develop products are often not marketers by personality type. I suppose that I could, for example, email the members of this group individually and ask them to try my application, but I generally think that that is wrong to do unless there is a good and open reason to do so. So that's the key issue in my mind: getting to the potential customer and getting them to take the time to try something out. In my case there is no financial barrier: mine is a very low cost product. In summary, offering the products on-line is easy, and one could indeed create an aggregation site. But if people don't try the products they won't purchase them. And the question is how to get the message broadcast that it's ok to try out these products? (There is the technical issue of how to create password protected products and with those, trial versions. I've solved this for myself, but there is no intrinsic method in Mathematica itself at this time.) So (shameless plug--one has to be a bit shameless in selling things): give http://scientificarts.com/worklife a try... what's holding *you* back... : - ) Best, David A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... Trial Version at: http://scientificarts.com/worklife/ > Contact the Wolfram Partnerships group... >http://partnerships.wolfram.com/ Interesting and useful. But, as with any major product or system or vendor, could be useful to > also have a totally _independent_, non-Wolfram-controlled users' group > or organization -- such as the web now makes so readily possible. === Subject: Re: Directory of Mathematica Add-Ons > > But in my offering of http://scientificarts.com/worklife the most > difficult thing that I find is getting people to try it. And this has > lead me to learn more of why, in the real world, active advertising is > unfortunately essential. > Genuine sympathy for your dilemma. And just a note that in the Silicon Valley startup / venture capital / entrepreneurship world (where I live physically, but which I'm not in any way engaged in), one of the most highly regarded ideas is the concept of viral marketing. === Subject: Re: Directory of Mathematica Add-Ons > Contact the Wolfram Partnerships group... > > http://partnerships.wolfram.com/ Interesting and useful. But, as with any major product or system or vendor, could be useful to also have a totally _independent_, non-Wolfram-controlled users' group or organization -- such as the web now makes so readily possible. === Subject: Re: Directory of Mathematica Add-Ons > Contact the Wolfram Partnerships group... > > http://partnerships.wolfram.com/ -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u === Subject: Re: Directory of Mathematica Add-Ons >> Contact the Wolfram Partnerships group... >> http://partnerships.wolfram.com/ > > I don't think that would cover the many Mathematica packages - free and otherwise - published independently of Wolfram. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Directory of Mathematica Add-Ons >> Is there a directory of available Mathematica Add-Ons (including >> commercial ones) anywhere? >> I'm looking for productive ways to advertise our own commercial >> Mathematica Add-On for time-frequency analysis: >> http://www.ffconsultancy.com/products/CWT/?mma >> If we can sell that product more effectively then I'd like to create more >> add-ons for Mathematica in the future... > > This product sounds very interesting, but does it work with V6.0 of > Mathematica. Yes, it works with Mathematica 6. This Add-On is designed to let users extract the frequency content of a signal over time as easily as possible. Time-frequency analysis has a wide range of applications and, IMHO, more should be done to teach this at university level. -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u === Subject: Re: A kernel, multiple notebooks, and Global? Actually, the kernel has absolutely no knowledge of which notebooks produce a particular evaluation. Even though there are functions which can query this information, such as EvaluationNotebook[] and ButtonNotebook[], these functions are resolved by having the kernel ask the front end for the information. And the kernel will never request the information unless you've explicitly asked it to. The only down sides I can think of for using Mathematica in the way you're describing are the potential confusion it would cause you with very complex usage, and the potential difficulty in recreating a sequence of evaluations in alater session. If you feel you can confidently avoid these pratfalls, then by all means, do it! I should point out here that, for those who *don't* wish to see interactions between notebooks, there's a new feature in version 6 to support this. In the Evaluation menu, there's a new submenu called Notebook's Evaluation Context. This allows you to set rules for what context to use in a given notebook. You can specify a specific context, request a context which is guaranteed unique to that notebook, or request that each cell group in a notebook get its own context. The feature also keeps track of $Line separately for each context (even here, this is all done by the FE...the kernel remains ignorant of anything except the FE's requests to switch $Context, $Line, $ContextPath, etc.). This is, essentially, the same mechanism which is used in the help viewer to ensure unique contexts in each example group of a function home page. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Pardon any awkward wordings here, but I may not have all the jargon > relevant to my query clearly understood. Suppose that on a single-user computer I have several notebooks open > that address different parts of a common calculation, and thus share > overlapping sets of globally used variable names. The broad question is then, how far can I go -- or what dangers may lurk > -- in treating these multiple notebooks as essentially one unified > notebook that just happens to be stored in multiple files and appear on > screen in multiple windows? 1) For example, in terms of contexts or scopes, I'm guessing that > Global is Global: the Global` context for all of these notebooks is > set by or recorded by the kernel, and at any one instant is exactly the > same for all these open notebooks -- right? 2) Suppose a certain Input cell is present in exactly identical form at > some random (i.e., different) point in each of the notebooks; I've been > executing cells from all of the notebooks in some irregular sequence; > and then I execute this particular cell in whichever of the notebooks > happens to be most convenient for me. I assume the kernel is likely to be able to recognize which notebook > submitted these Input instructions. But beyond that, unless this cell > contains some code which directly or indirectly identifies the notebook > in which the cell resides, and uses this information to modify the Input > instructions, executing the copy of this cell that resides in any of the > notebooks will produce exactly the same result, except for where it > displays its output -- right? === Subject: Re: How to solve this simple equation? eqn = (y == 0.00324184/(2 + 2.78456 (1/y)^0.4)); NSolve[eqn, y] {{y->0.0000127162}} FindRoot[eqn, {y, 1}] {y->0.0000127162} Reduce[Rationalize[eqn, 0], y] // N y == 0.0000127162 Bob Hanlon > least find an optimal solution for the following equation: > > y = 0.00324184/(2 + 2.78456 (1/y)^0.4) > > Dino > === Subject: List re-arrangement question I'm trying to do something like the following: Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, {b1, b2, b3}}}, {3, 1, 2}] expecting to get: {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, b3}}} However, it looks like Transpose doesn't work with ragged arrays...so what is the recommended Mathematica style to do the above transformation? === Subject: Re: List re-arrangement question > I'm trying to do something like the following: > Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, > {b1, b2, b3}}}, {3, 1, 2}] > > expecting to get: > {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, > b3}}} > > However, it looks like Transpose doesn't work with ragged > arrays...so what is the recommended Mathematica style to do the above > transformation? > Hi Yaroslav, Thread[] is very similar to Transpose[] (in fact completely equivalent for matrices), but it is more difficult to use with multidimensional arrays. On the up side, it works fine with ragged arrays :-) In[1]:= xx = {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, {b1, b2, b3}}} Out[1]= {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, {b1, b2, b3}}} In[2]:= Thread[xx] Out[2]= {{{a1, a2, a3}, {b1, b2, b3}}, {{a1}, {b1}}, {{a1, a2, a3}, {b1, b2, b3}}} In[3]:= Thread /@ % Out[3]= {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, b3}}} Szabolcs === Subject: ListPlot & lots 'o dots. Apparently ListPlot has a quirk on my systems (XP SP2/3, 6.0.2) With test data test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], [Pi]/50}]; ListPlot[test] produces a plot with lots 'o dots as expected. It's easy to see which dots correspond to which frequency by connecting points in each data set ListPlot[test, Joined->True] We can correct the ordinate scale using ListPlot[test, Joined->True, DataRange->{-[Pi], [Pi]}], and for lots 'o plots this looks messy. Using SetOptions, we can set ListPlot up so that we don't need to specify Joined & a data range every time we use ListPlot using SetOptions[ListPlot, DataRange -> {-[Pi], [Pi]}, Joined -> True ]; We can confirm ListPlot's new settings either by removing the ; or using Options@ListPlot. For me this is where the problem starts. After an appropriate SetOptions (like above), ListPlot[test] should give me a plots that is joined & has the correct ordinate scale. For me it doesn't, despite Joined->True and DataRange, ListPlot[test] gets ma a plot with lots 'o dots and the wrong scale. I know there's a point to SetOptions since I can set (eg) a PlotRange and FrameLabels. It's just that ListPlot (apparently) ignores DataRange & Joined so that I have to specify them each time I use ListPlot. I'd like to know if this problem restricted to my system. In the event that it can be reproduced, I'll report it as a bug. Tests. test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], [Pi]/ 50}]; (* generate test data *) ListPlot[test] (* plot w/ lots o dots *) ListPlot[test, Joined -> True, DataRange -> {-[Pi], [Pi]}] (* desired plot *) SetOptions[ListPlot, DataRange -> {-[Pi], [Pi]}, Joined -> True, FrameLabel -> {Hi, Lo}, PlotRange -> {0, [Pi]/2}]; (* set default options for ListPlot *) ListPlot[test] (* dotty plot, incorrect ordinate but correct abscissa & labels -- WTF? *) Dave. === Subject: Re: A Problem with Simplify >And code: >int1 = Integrate[Cos[a*x]/Sin[x], x]; int1 /. a -> 1 >MUST give us answer equal to >int2 = Integrate[Cos[x]/Sin[x], x] Mathematica simply doesn't work this way. If you do Integrate[Cos[a x]/Sin[x],x] you will see a fairly complex expression. I assume this expression is valid and can be simplified to Log[Sin[x]] when a is 1 with the right transformations. But it is far from obvious to me what transformations are required. And Mathematica does not attempt to simplify this expression. Once you get this result, the replacement rule simply substitutes 1 for a every where and evaluates. This simple process results in division by 0. There are two ways to avoid this problem. One would be to find the set of transformations that reduce the expression to Log[Sin[x]]. The other is to re-write the problem as: Integrate[Cos[a x]/Sin[x]/.a->1, x] Despite the fact, Mathematica does not get the result you desire, this is not a bug. Mathematica is working as intended. So, you have a choice. Either accept this and figure out how to use Mathematica as it is or find some other tool that works more like you want. === Subject: Re: A kernel, multiple notebooks, and Global? >Pardon any awkward wordings here, but I may not have all the jargon >relevant to my query clearly understood. >Suppose that on a single-user computer I have several notebooks open >that address different parts of a common calculation, and thus share >overlapping sets of globally used variable names. >The broad question is then, how far can I go -- or what dangers may >lurk -- in treating these multiple notebooks as essentially one >unified notebook that just happens to be stored in multiple files >and appear on screen in multiple windows? The only real issue here is your being able to keep track of what is going on. That is I am confident, long before you run out of resources (memory etc) you will have too many windows to be convenient for your use. >1) For example, in terms of contexts or scopes, I'm guessing that >Global is Global: the Global` context for all of these notebooks >is set by or recorded by the kernel, and at any one instant is >exactly the same for all these open notebooks -- right? Right. >2) Suppose a certain Input cell is present in exactly identical >form at some random (i.e., different) point in each of the >notebooks; I've been executing cells from all of the notebooks in >some irregular sequence; and then I execute this particular cell in >whichever of the notebooks happens to be most convenient for me. Right. But you will need to be careful about dependencies in each of the notebooks. >I assume the kernel is likely to be able to recognize which notebook >submitted these Input instructions. I think this implies more tracking done by the kernel than is the case. I believe the kernel simply sees every thing as a sequence of operations and simply sends results back to which ever notebook was the evaluation notebook at the time. That is, I don't believe once you have evaluated several expressions in several notebooks there is a means within Mathematica to find the notebook containing say the 10th expression that was evaluated. >But beyond that, unless this cell contains some code which directly or >indirectly identifies the notebook in which the cell resides, and uses >this information to modify the Input instructions, executing the copy >of this cell that resides in any of the notebooks will produce exactly >the same result, except for where it displays its output -- right? Right. But watch out for unexpected dependencies. It is really easy when working in this manner to miss a change in a variable in one notebook that impacts another notebook. === Subject: Re: Package to 'graft' Lists onto Matrices mat = RandomInteger[{0, 10}, {5, 7}]; mat // MatrixForm AddRow[mat_?MatrixQ, row_List] := Join[mat, {row}] AddRow[mat, {a, b, c, d, e, f, g}] // MatrixForm AddColumn[mat_?MatrixQ, column_List] := Transpose[Join[Transpose[mat], {column}]] AddColumn[mat, {a, b, c, d, e}] // MatrixForm No checking here or matching dimensions, but that could be built in easily. It seems a little daft that that you need to use MapThread and Append to simply graft a row onto an existing matrix! > -- W. Craig Carter === Subject: Re: Package to 'graft' Lists onto Matrices Strictly speaking, there is no such thing as a matrix in Mathematica, despite there being a function MatrixQ to test whether an object that can represent a matrix. Rather, one can represents a matrix as a list of lists, where the latter individual lists -- all having the same length for a genuine matrix -- represent the rows of the matrix. (Or one can create an Array.) Here's an example of such a list: m = { {1,2,3,4}, {5,6,7,8} }; MatrixQ[m] Dimensions[m] True {2,4} This should not be confused with a special formatted form that you get by acting upon m with MatrixForm: mat = MatrixForm[m]; MatrixQ[m] False So what's wrong about using Append to join new rows to the matrix? m = Append[m, {a,b,c,d}]; Dimensions[m] {3,4} What simpler thing could you possibly want to graft a new row to the bottom of the matrix? (Or to use Prepend to graft the new row at the top of the existing matrix.) And, to graft a new column to the left side of a matrix: m = Join[m, {{Sin},{Cos},{Tan}},2]; Dimensions[m] {3,5} So despite the example in ref/Append, no MapThread is required to adjoin a new column -- provided one is willing to first make that column a genuine matrix, as I did above with the double nesting in {{Sin},{Cos},{Tan}}. Certainly joining an additional column now in Mathematica 6 is not as direct as it was in earlier versions where, after loading the package LinearAlgebra`MatrixManipulation`, you could just use AppendRows: a = Partition[Range[8],4]; AppendRows[a, {{Exp}, {Log}}] Of course you can still load that legacy package and use AppendRows, but who knows how much longer that package will be around? Notice that, even with AppendRows, you still have to create an actual matrix in order to stick new columns on -- just as you have to do with Join[..., ..., 2]. (At least you can avoid worrying about level.) Should it be simpler. I'm not sure there's a good way without breaking something in the fundamental structure of Mathematica, or without introducing a new, special construct of a matrix. But that would complicate lots of other things, I think. > I've been looking at Join[ ], Append[ ], Insert[ ], etc. and wonder if someone has written a package that allows an Mathematica user to add Lists as rows and columns to form a new matrix. > > It seems a little daft that that you need to use MapThread and Append to simply graft a row onto an existing matrix! > > Am I missing some new functionality? > > > > > Robert Prince-Wright > Houston > TX, 77006 > USA > > -- 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: Package to 'graft' Lists onto Matrices >I've been looking at Join[ ], Append[ ], Insert[ ], etc. and wonder >if someone has written a package that allows an Mathematica user to >add Lists as rows and columns to form a new matrix. >It seems a little daft that that you need to use MapThread and >Append to simply graft a row onto an existing matrix! Join works just fine for adding a row. For example, In[19]:= m = Partition[Range[9], 3]; data = RandomInteger[{0, 4}, 3] Out[20]= {2,0,0} In[21]:= Join[m, {data}] Out[21]= {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {2, 0, 0}} or if I wanted to add a column I could do In[22]:= Transpose@Join[Transpose@m, {data}] Out[22]= {{1, 2, 3, 2}, {4, 5, 6, 0}, {7, 8, 9, 0}} === Subject: Re: Player Pro and Packages > Player Pro won't load plain text package files. It will load > package files which have been created using Encode[] or > DumpSave[]. This restriction is to help ensure that behind > the content created for a Player Pro is a genuine Mathematica license. > > > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. Maybe Wolfram should ask Adobe for an advice, how to ensure that behind the content created for Adobe Reader is a genuine Adobe Acrobat license. The problems involved seem to be quite equivalent. ;-) It it really possible to lock up a tiger (Mathematica) behind chicken wire? By the way, Publicon is in a way a complemetary product to Player Pro: just editing, no evaluation. Is there any compatibility? Ingolf Dahl Sweden === Subject: Re: Player Pro and Packages Your proposed solution wouldn't work, as $UserBaseDirectory is earlier on the path than $InstallationDirectory. I think you're going to have to reset those environment variables for Player Pro. If you're running under Windows, you could create a batch file which sets the environment variables and then launches Mathematica. This would also be pretty simple under Unix. It's more complicated under Mac, but it wouldn't be too difficult to at least create a script which resets the variables for the kernel's environment (perhaps you care less about the FE's environment). If you need help, let me know what environment you're running under and I'll help you craft something that works. The fact that it wasn't different was just a silly oversight, and unfortunately, yours truly was responsible. I'll fix it for future releases. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > My concern is just the reverse of what your reply seems to address: I do > NOT want packages within the locations to which MATHEMATICA_BASE and > MATHEMATICA_USERBASE point to be sought first by Player Pro. I want to be able to have a separate location for, say, an encoded > version of a package that I'm running with Player Pro, and a > source-visible package I use for development within Mathematica itself. It sounds then like the only alternative would be to put the encoded > version directly within the PlayerPro tree (is there an > AddOns/Applications subdirectory?). So... Will that work -- will PlayerPro first search for a package within its > own directory tree despite settings of MATHEMATICA_BASE and > MATHEMATICA_USERBASE? If not, that's really bad! If so, that's only partly good: it still forces me to put such things as > (encoded) packages within the PlayerPro tree that might get wiped out > whenever I re-install or upgrade PlayerPro. >> Yes. Although, in retrospect, we should have considered changing the >> names of these environment variables for Player Pro. We might decide to >> do this in a future version, but for now, MATHEMATICA_BASE and >> MATHEMATICA_USERBASE will function just fine. >> For those who haven't noticed already (although most on this thread seem >> to have realized it by now), the default values of $BaseDirectory and >> $UserBaseDirectory are different from those in Mathematica, and so >> packages installed for Mathematica will not, by default, show up for >> Player Pro (i.e., you'll have to install Player Pro packages >> separately). >> John Fultz >> jfultz@wolfram.com >> User Interface Group >> Wolfram Research, Inc. > 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 === Subject: Help with minimization of Eigenvalues I am trying to minimize a particular eigenvalue of a generalized eigenvalue problem that depends on a few parameters. I have the following problem: Suppose we have two matrices s and m like these (the real matrices are much more complicated) m = {{a, b}, {b, -a + 1}} s = {{1, 0}, {0, 3a}} If I define the function Eig Eig[a_, b_] := Eigenvalues[{m, s}]//First And use it with the FindMinimum function it does not work. Infact just calling Eig[1,2] gives the error Eigenvalues::gfargs: Generalized Eigenvalues arguments accept only matrices with machine real and complex elements. More... Even inserting Evaluate[] into the Eigenvalues function does not work. What am I doing wrong? Any help would be appreciated :-) === Subject: Re: Help with minimization of Eigenvalues Eig[a_?NumericQ, b_?NumericQ] := With[{m = {{a, b}, {b, -a + 1}}, s = {{1, 0}, {0, 3 a}}}, Eigenvalues[N[{m, s}]] // First ] may help. Jens > > I am trying to minimize a particular eigenvalue of a generalized > eigenvalue problem that depends on a few parameters. I have the > following problem: > > Suppose we have two matrices s and m like these (the real matrices are > much more complicated) > > m = {{a, b}, {b, -a + 1}} > > s = {{1, 0}, {0, 3a}} > > If I define the function Eig > > Eig[a_, b_] := Eigenvalues[{m, s}]//First > > And use it with the FindMinimum function it does not work. > Infact just calling > > Eig[1,2] gives the error > > Eigenvalues::gfargs: > Generalized Eigenvalues > arguments accept only matrices with machine real > and complex elements. More... > > Even inserting Evaluate[] into the Eigenvalues function does not work. > What am I doing wrong? > Any help would be appreciated :-) > > === Subject: Re: Select from list > I have a list like this: ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray > Flatten[Position[ptX, {___, 2, ___, 3, ___}]] {1, 2, 5} That's assuming that 3 comes always after 2 in your list. If not: Flatten[Position[ptX, {___, 2, ___, 3, ___} | {___, 3, ___, 2, ___}]] Andrzej Kozlowski === Subject: Select from list I have a list like this: ptX= {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both a 2 and a 3. In this example I would get {1,2,5}. The best solution I have, with more generality, is: va = 2; vb = 3; za = Map[Cases[#1, va]&, ptX] /. {} -> {0} zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} {{3}, {3}, {0}, {3}, {3}} {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray === Subject: Re: Select from list > I have a list like this: > > ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} > > and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: > > va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] > > which gives > > {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. > > (This doesn't work if va or vb is zero. That's ok.) Hi Steve, The following solution uses directly Position[] and works with zeros. Position[ptX, x_ /; MemberQ[x, 2] && MemberQ[x, 3]] // Flatten For instance, In[1]:= ptX = {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}}; Position[ptX, x_ /; MemberQ[x, 2] && MemberQ[x, 3]] // Flatten Out[2]= {1, 2, 5} In[3]:= ptX = {{1, 2, 3, 4, 0}, {1, 2, 3, 5}, {1, 2, 4, 5, 0}, {1, 3, 4, 5}, {0, 2, 3, 4, 5}}; Flatten[Position[ptX, x_ /; MemberQ[x, 0] && MemberQ[x, 3]]] Out[4]= {1, 5} -- === Subject: DifferenitalD vs CapitalDifferenitalD The documentation for DifferenitalD states: DifferenitalD[x] displays as dx , where instead of d appears the smybol entered as esc dd esc (without the spaces). Yet when I enter DifferentialD[x] and evaluate I get back DifferenitalD[x] (not esc dd esc x ). The documentation for CapitalDifferentialD seems identical to that for DifferentialD. Yet when I enter CapitalDifferentialD[x] I get Dx where D is the symbol entered as esc DD esc. Moreover, esc dd esc x evaluates to DifferenitalD[x] but esc DD esc x evaluates to esc DD esc x. It is all so confusing I feel like giving up on Mathematica typesetting altogether. Can anyone explain what is going on here? This is with $Version 6.0 for Mac OS X x86 (64-bit) (March 13, 2008) $ReleaseNumber 2 Andrzej Kozlowski === Subject: Re: DifferenitalD vs CapitalDifferenitalD this is a bug, add MakeBoxes[DifferentialD[x_], fmt_] := RowBox[{[DifferentialD], ToBoxes[x, fmt]}] Jens > The documentation for DifferenitalD states: > > DifferenitalD[x] displays as dx , where instead of d appears the > smybol entered as esc dd esc (without the spaces). Yet when I > enter DifferentialD[x] and evaluate I get back DifferenitalD[x] (not > esc dd esc x ). > > The documentation for CapitalDifferentialD seems identical to that for > DifferentialD. Yet when I enter CapitalDifferentialD[x] I get Dx > where D is the symbol entered as esc DD esc. > > Moreover, esc dd esc x evaluates to DifferenitalD[x] but esc DD esc > x evaluates to esc DD esc x. > > It is all so confusing I feel like giving up on Mathematica > typesetting altogether. Can anyone explain what is going on here? > > This is with > > $Version > 6.0 for Mac OS X x86 (64-bit) (March 13, 2008) > $ReleaseNumber > 2 > > Andrzej Kozlowski > === Subject: Re: Coordinates of vertices Peter, The vertices are in the graphics object. Just use [[ ]] to get them out. tc=Truncate[PolyhedronData[Cube]] vertices=ph[[1,1]]//N ListPointPlot3D[vertices ,BoxRatios->Automatic] Hope this helps, maarten King, Peter R ial.ac.uk> cc: === Subject: Coordinates of vertices 16/04/2008 11:02 I am sure I have done this before but I can't for the life of me remember how, and I can't find it in the manual. Some help would be much appreciated. I'd like to find the coordinates of the vertices of a truncated cube. Whilst Vertices[cube] correctly gives me the coordinates of a cube Vertices[Truncate[Polyhedron[Cube]]] doesn't do what I want because Truncate[Polyhedron[... is a graphics object not a polyhedron object. So can I convert the graphics object into a polyhedron and use vertices, or work out the vertices some other way (for a cube this is trivial to do but for more complicated shapes this is much more tedious) Peter === Subject: Extending Integrate[] According to the documentation it is possible to extend Integrate[] with new rules: http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCannotB eDone.html The specific example that is given is: Unprotect[Integrate] Integrate[Sin[Sin[a_. + b_. x_]], x_] := Jones[a, x]/b Now Integrate[Sin[Sin[3x]], x] will return Jones[0, x]/3 But if I try an integrand that is just slightly more complicated, Mathematica returns it unevaluated: In[21]:= Integrate[a + Sin[Sin[x]], x] Out[21]= Integrate[a + Sin[Sin[x]], x] My question is: Is it really possible to extend Integrate in an intelligent way? The above example seems to be just simple pattern matching. It would work with any function, not just Integrate[]. There is nothing new or surprising about it. But is it *really* possible to extend Integrate[] with new definitions in a way that Mathematica will use these rules when calculating more complicated Integrals? If (as I suspect) it is not possible to do this, then the documentation is a bit misleading ... === Subject: Re: Extending Integrate[] for a new integration rule, give always the most general pattern, i.e. in your case Unprotect[Integrate] Integrate[d_. + c_.*Sin[Sin[a_. + b_. x_]], x_] := c*Jones[a, x]/b + Integrate[d, x] /; FreeQ[c, x] and all works fine. Jens > According to the documentation it is possible to extend Integrate[] wit= h > new rules: http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCa= nnotBeDone.html The specific example that is given is: Unprotect[Integrate] Integrate[Sin[Sin[a_. + b_. x_]], x_] := Jones[a, x]/b Now Integrate[Sin[Sin[3x]], x] will return Jones[0, x]/3 But if I try an integrand that is just slightly more complicated, > Mathematica returns it unevaluated: In[21]:= Integrate[a + Sin[Sin[x]], x] > Out[21]= Integrate[a + Sin[Sin[x]], x] My question is: Is it really possible to extend Integrate in an > intelligent way? The above example seems to be just simple pattern > matching. It would work with any function, not just Integrate[]. Ther= e > is nothing new or surprising about it. But is it *really* possible to extend Integrate[] with new definitions > in a way that Mathematica will use these rules when calculating more > complicated Integrals? If (as I suspect) it is not possible to do this, then the documentation= > is a bit misleading ... > === Subject: Re: Select from list ptX = {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}}; If the sublists are always ordered Position[ptX, {___, 2, ___, 3, ___}] // Flatten {1,2,5} If not, sort first Position[Sort /@ ptX, {___, 2, ___, 3, ___}] // Flatten {1,2,5} Bob Hanlon > I have a list like this: > > ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} > > and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: > > va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] > > which gives > > {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. > > (This doesn't work if va or vb is zero. That's ok.) > > Steve Gray > === Subject: Re: List re-arrangement question There are probably better ways, but the following is one solution: orig = {{{a1, a2, a3}, {b1, b2, b3}}, {{a1}, {b1}}, {{a1, a2, a3}, {b1, b2, b3}}} Transpose[{Flatten[orig[[All, 1]]], Flatten[orig[[All, 2]]]}] Out[452]= {{a1, b1}, {a2, b2}, {a3, b3}, {a1, b1}, {a1, b1}, {a2, b2}, {a3, b3}} MapThread[List, {Flatten[orig[[All, 1]]], Flatten[orig[[All, 2]]]}] is a slight variant. And of course TableForm[orig] gives a nice table of what is needed Tom Dowling > I'm trying to do something like the following: > Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, > {b1, b2, b3}}}, {3, 1, 2}] expecting to get: > {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, > b3}}} However, it looks like Transpose doesn't work with ragged > arrays...so what is the recommended Mathematica style to do the above > transformation? === Subject: Re: List re-arrangement question mat = {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, {b1, b2, b3}}}; Inner[Transpose[{##}] &, Sequence @@ mat, List] {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, b3}}} Bob Hanlon > I'm trying to do something like the following: > Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, > {b1, b2, b3}}}, {3, 1, 2}] > > expecting to get: > {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, > b3}}} > > However, it looks like Transpose doesn't work with ragged > arrays...so what is the recommended Mathematica style to do the above > transformation? > === Subject: If Integrate returns no result, can we conclude that no closed-form The documentation says: In the most convenient cases, integrals can be done purely in terms of elementary functions such as exponentials, logarithms and trigonometric functions. In fact, if you give an integrand that involves only such elementary functions, then one of the important capabilities of Integrate is that if the corresponding integral can be expressed in terms of elementary functions, then Integrate will essentially always succeed in finding it. http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCannotB eDone.html How precise is this? Can one rely on this information? Is it really true that if Mathematica cannot integrate an expression made up of elementary functions, then no closed-form result exists? Szabolcs (P.S. I do not know how Integrate works. I heard that CASs use a so-called Risch-alogrithm, but there is relatively little information about this on the web (except in academic papers, most of which expect the reader to be familiar with the topic).) === Subject: Re: A Problem with Simplify >>I have the following rather simple integral of two sines, which should= >>evaluate to zero if m is not equal to n and to L/2 if they are the sam= e.= >Try the following: >Integrate[Exp[(a - 1)*x], x] /. a -> 1 >Integrate[Cos[(a - 1)*x], x] /. a -> 1 >Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 >Integrate[Cos[a x]/Sin[x], x] /. a -> 1 >There is the ONE underlying BUG! In some complicated cases this bug >may result in random partial answers. >http://forum.ru-board.com/topic.cgi?forum=5&topic=10291&start=80#= 9 >>Removing the replacements, here are the Integrate results. >>In[17]:= InputForm[Integrate[Exp[(a - 1)*x], x]] >>Out[17]//InputForm= E^((-1 + a)*x)/(-1 + a) >> [...] >>As far as I am aware thse are correct. What is the bug? >>Daniel Lichtblau >>Wolfram Research > The above answers are correct only if a is not equal to 1. Answers > with a=1 are lost! > And code: > int1 = Integrate[Cos[a*x]/Sin[x], x]; > int1 /. a -> 1 > MUST give us answer equal to > int2 = Integrate[Cos[x]/Sin[x], x] Capitalization notwithstanding, it need not do any such thing. Integrate > should give a generic result that behaves sensibly in the limit as a->1 > from whatever path is specified to Limit. This is similar to the > situation of In[18]:= InputForm[solns = x /. Solve[a*x^2 + x == 1, x]] > Out[18]//InputForm= {(-1 - Sqrt[1 + 4*a])/(2*a), > (-1 + Sqrt[1 + 4*a])/(2*a)} In[20]:= Limit[solns, a->0] > Out[20]= {-Infinity, 1} Note that a blind substitution of a->0 will not give nice results. In[21]:= solns /. a->0 1 > Power::infy: Infinite expression - encountered. > 0 1 > Power::infy: Infinite expression - encountered. > 0 Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. Out[21]= {ComplexInfinity, Indeterminate} > But the first answer is invalid in this simple case... :( > I should emphasize that in some complicated cases this BUG may result > in random partial answers! I'll emphasize that this is not a bug; it's the way Integrate is > intended to work in Mathematica. An antiderivative of a function that > depends on parameters can be invalid for some values of those > parameters. Provided we are talking about analytic functions (things > that can be said to have antiderivatives in the usual meaning of the > term), the bad set will have measure zero. Daniel Lichtblau > Wolfram Research >Capitalization notwithstanding, it need not do any such thing. Integrate >should give a generic result that behaves sensibly in the limit as a->1 >from whatever path is specified to Limit. This is similar to the >situation of >In[18]:= InputForm[solns = x /. Solve[a*x^2 + x == 1, x]] >Out[18]//InputForm= {(-1 - Sqrt[1 + 4*a])/(2*a), > (-1 + Sqrt[1 + 4*a])/(2*a)} In[20]:= Limit[solns, a->0] >Out[20]= {-Infinity, 1} Note that a blind substitution of a->0 will not give nice results. Well. But how I can get the partial answer for the case a=1 with Limit? I have tried the foolowing code: In[1]:= Limit[Integrate[Cos[a*z]/Sin[z],z],a->1] Out[1]= [Infinity] In[2]:= Limit[Integrate[Exp[a*z]*Sinh[z],z],a->1] Out[2]= -[Infinity] In[3]:= Limit[Integrate[Exp[z]*Sinh[a z],z],a->1] Out[3]= E^z DirectedInfinity[E^(-I*Im[z])] In[4]:= Limit[Integrate[Exp[(a-1)*x],x],a->1] Out[4]= [Infinity] All results are incorrect! As I understand, Integrate does not give a generic result that behaves sensibly in the limit as a->1! === Subject: Re: A Problem with Simplify > >>I have the following rather simple integral of two sines, which should >>evaluate to zero if m is not equal to n and to L/2 if they are the same.= > > >Try the following: >Integrate[Exp[(a - 1)*x], x] /. a -> 1 >Integrate[Cos[(a - 1)*x], x] /. a -> 1 >Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 >Integrate[Cos[a x]/Sin[x], x] /. a -> 1 >There is the ONE underlying BUG! In some complicated cases this bug >may result in random partial answers. >http://forum.ru-board.com/topic.cgi?forum=5&topic=10291&start=80#9 >>Removing the replacements, here are the Integrate results. >>In[17]:= InputForm[Integrate[Exp[(a - 1)*x], x]] >>Out[17]//InputForm= E^((-1 + a)*x)/(-1 + a) >> [...] >>As far as I am aware thse are correct. What is the bug? >>Daniel Lichtblau >>Wolfram Research > > > The above answers are correct only if a is not equal to 1. Answers > with a=1 are lost! > > And code: > > int1 = Integrate[Cos[a*x]/Sin[x], x]; > int1 /. a -> 1 > > MUST give us answer equal to > > int2 = Integrate[Cos[x]/Sin[x], x] Capitalization notwithstanding, it need not do any such thing. Integrate should give a generic result that behaves sensibly in the limit as a->1 from whatever path is specified to Limit. This is similar to the situation of In[18]:= InputForm[solns = x /. Solve[a*x^2 + x == 1, x]] Out[18]//InputForm= {(-1 - Sqrt[1 + 4*a])/(2*a), (-1 + Sqrt[1 + 4*a])/(2*a)} In[20]:= Limit[solns, a->0] Out[20]= {-Infinity, 1} Note that a blind substitution of a->0 will not give nice results. In[21]:= solns /. a->0 1 Power::infy: Infinite expression - encountered. 0 1 Power::infy: Infinite expression - encountered. 0 Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. Out[21]= {ComplexInfinity, Indeterminate} > But the first answer is invalid in this simple case... :( > > I should emphasize that in some complicated cases this BUG may result > in random partial answers! I'll emphasize that this is not a bug; it's the way Integrate is intended to work in Mathematica. An antiderivative of a function that depends on parameters can be invalid for some values of those parameters. Provided we are talking about analytic functions (things that can be said to have antiderivatives in the usual meaning of the term), the bad set will have measure zero. Daniel Lichtblau Wolfram Research === Subject: Re: A Problem with Simplify I can see no bugs here at all. Concerning indefinite integrals: I suggest you look at any book on algebraic integration and the Risch algorithm. One possibility is the famous and fundamental monograph: On the integration of algebraic functions by John Davenport (Springer 1981) (there is a Russian translation Mir 1985). You will find that in this book and in all others the so called Risch algorithm is used and this algorithm works in a certain function field. Both inputs and outputs are elements of a function field and values of functions at special points do not enter at any stage of the algorithm, therefore you cannot expect that Integrate[Exp[(a - 1)*x], x] /. a -> 1 will give the same answer as Unevaluated[Integrate[Exp[(a - 1)*x], x]] /. a -> 1 x If you want the latter answer use the latter input. By the way, the very same approach approach is implemented in every computer algebra system in existence. In the case of definite integration the situation may vary, because the answer provided by the Risch algorithm is then post-processed, so sometimes some account of special values can be made. But in any case, you cannot in general expect that Unevaluated[f[x,y]]/.y->a will return the same value as f[x,y]/.y->a, for many functions f which use algorithms valid in some function algebras. Whether they do so or not will depend on post-processing of the answers returned by algebraic algorithms and whether such post-processing can deal with special values of parameters will depend on considerations such as how costly it is in terms of processing time to try to check for singular values etc. There is absolutely no point claiming that you have found a bug when you do not understand the existing algorithms (which you obviously do not), and such things as the cost in computing time of implementing an approach that would not suffer from this bug, etc. And there is also no point at all arguing with with a developer who tells you that as far as he is concerned there is no bug. It is, so to speak, a take it or leave it situation. Andrzej Kozlowski > On Apr 10, 10:14 am, Kevin J. McCann >> I have the following rather simple integral of two sines, which >> should >> evaluate to zero if m is not equal to n and to L/2 if they are >> the same.= Try the following: > Integrate[Exp[(a - 1)*x], x] /. a -> 1 > Integrate[Cos[(a - 1)*x], x] /. a -> 1 > Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 > Integrate[Cos[a x]/Sin[x], x] /. a -> 1 > There is the ONE underlying BUG! In some complicated cases this bug > may result in random partial answers. > http://forum.ru-board.com/topic.cgi?forum=5&topic=10291&start=80#9 >> Removing the replacements, here are the Integrate results. >> In[17]:= InputForm[Integrate[Exp[(a - 1)*x], x]] >> Out[17]//InputForm= E^((-1 + a)*x)/(-1 + a) >> In[18]:= InputForm[Integrate[Cos[(a - 1)*x], x]] >> Out[18]//InputForm= Sin[(-1 + a)*x]/(-1 + a) >> In[19]:= InputForm[Integrate[(a - 1)^x, {x, -1, 0}]] >> Out[19]//InputForm= (-2 + a)/((-1 + a)*Log[-1 + a]) >> In[20]:= InputForm[Integrate[Cos[a*x]/Sin[x], x]] >> Out[20]//InputForm= >> ((1 + a)*Hypergeometric2F1[1/2 - a/2, 1, 3/2 - a/2, E^((2*I)*x)] - >> =9A =9A(-1 + a)*E^((2*I)*a*x)*Hypergeometric2F1[(1 + a)/2, 1, (3 + >> a)/2, >> =9A =9A =9AE^((2*I)*x)])/((-1 + a^2)*E^(I*(-1 + a)*x)) >> As far as I am aware thse are correct. What is the bug? >> Daniel Lichtblau >> Wolfram Research The above answers are correct only if a is not equal to 1. Answers > with a=1 are lost! And code: int1 = Integrate[Cos[a*x]/Sin[x], x]; > int1 /. a -> 1 MUST give us answer equal to int2 = Integrate[Cos[x]/Sin[x], x] But the first answer is invalid in this simple case... :( I should emphasize that in some complicated cases this BUG may result > in random partial answers! And the lost answer in the above-mentioned case (by Kevin J. McCann) > is already very dangerous in spite of the fact that this partial > answer is still not random (because in this relatively simple case > there are only 2 partial answers): int1 = Integrate[Sin[a*x/L]*Sin[x/L], {x, 0, L}] > int1 /. a -> 1 > int2 = Integrate[Sin[x/L]*Sin[x/L], {x, 0, L}] One can represent how it will be, when 3 or more partial answers will > exist! > In the manual one finds: >> For indefinite integrals, Integrate tries to find results that are >> correct for almost all values of parameters. > This note is located under MORE INFORMATION field in the reference > for Integrate. And this seems to be false... :( And for definite > integrals there is an option GenerateConditions that does not work > in the most cases (try it with example above: > int1 = Integrate[Sin[a*x/L]*Sin[x/L], {x, 0, L}, GenerateConditions - True] > int1 /. a -> 1 > The answer is Indeterminate that is false! :( > ). > === Subject: Re: A Problem with Simplify >>I have the following rather simple integral of two sines, which should >>evaluate to zero if m is not equal to n and to L/2 if they are the same.= > Try the following: > Integrate[Exp[(a - 1)*x], x] /. a -> 1 > Integrate[Cos[(a - 1)*x], x] /. a -> 1 > Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 > Integrate[Cos[a x]/Sin[x], x] /. a -> 1 > There is the ONE underlying BUG! In some complicated cases this bug > may result in random partial answers. >http://forum.ru-board.com/topic.cgi?forum=5&topic=10291&start=80#9 Removing the replacements, here are the Integrate results. In[17]:= InputForm[Integrate[Exp[(a - 1)*x], x]] > Out[17]//InputForm= E^((-1 + a)*x)/(-1 + a) In[18]:= InputForm[Integrate[Cos[(a - 1)*x], x]] > Out[18]//InputForm= Sin[(-1 + a)*x]/(-1 + a) In[19]:= InputForm[Integrate[(a - 1)^x, {x, -1, 0}]] > Out[19]//InputForm= (-2 + a)/((-1 + a)*Log[-1 + a]) In[20]:= InputForm[Integrate[Cos[a*x]/Sin[x], x]] > Out[20]//InputForm= > ((1 + a)*Hypergeometric2F1[1/2 - a/2, 1, 3/2 - a/2, E^((2*I)*x)] - > =9A =9A(-1 + a)*E^((2*I)*a*x)*Hypergeometric2F1[(1 + a)/2, 1, (3 + a)/2, > =9A =9A =9AE^((2*I)*x)])/((-1 + a^2)*E^(I*(-1 + a)*x)) As far as I am aware thse are correct. What is the bug? Daniel Lichtblau > Wolfram Research The above answers are correct only if a is not equal to 1. Answers with a=1 are lost! And code: int1 = Integrate[Cos[a*x]/Sin[x], x]; int1 /. a -> 1 MUST give us answer equal to int2 = Integrate[Cos[x]/Sin[x], x] But the first answer is invalid in this simple case... :( I should emphasize that in some complicated cases this BUG may result in random partial answers! And the lost answer in the above-mentioned case (by Kevin J. McCann) is already very dangerous in spite of the fact that this partial answer is still not random (because in this relatively simple case there are only 2 partial answers): int1 = Integrate[Sin[a*x/L]*Sin[x/L], {x, 0, L}] int1 /. a -> 1 int2 = Integrate[Sin[x/L]*Sin[x/L], {x, 0, L}] One can represent how it will be, when 3 or more partial answers will exist! >In the manual one finds: > For indefinite integrals, Integrate tries to find results that are > correct for almost all values of parameters. This note is located under MORE INFORMATION field in the reference for Integrate. And this seems to be false... :( And for definite integrals there is an option GenerateConditions that does not work in the most cases (try it with example above: int1 = Integrate[Sin[a*x/L]*Sin[x/L], {x, 0, L}, GenerateConditions -> True] int1 /. a -> 1 The answer is Indeterminate that is false! :( ). === Subject: Re: A Problem with Simplify > >>I have the following rather simple integral of two sines, which should >>evaluate to zero if m is not equal to n and to L/2 if they are the same. > > > Try the following: > Integrate[Exp[(a - 1)*x], x] /. a -> 1 > Integrate[Cos[(a - 1)*x], x] /. a -> 1 > Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 > Integrate[Cos[a x]/Sin[x], x] /. a -> 1 > > There is the ONE underlying BUG! In some complicated cases this bug > may result in random partial answers. > > http://forum.ru-board.com/topic.cgi?forum=5&topic=10291&start=80#9 Removing the replacements, here are the Integrate results. In[17]:= InputForm[Integrate[Exp[(a - 1)*x], x]] Out[17]//InputForm= E^((-1 + a)*x)/(-1 + a) In[18]:= InputForm[Integrate[Cos[(a - 1)*x], x]] Out[18]//InputForm= Sin[(-1 + a)*x]/(-1 + a) In[19]:= InputForm[Integrate[(a - 1)^x, {x, -1, 0}]] Out[19]//InputForm= (-2 + a)/((-1 + a)*Log[-1 + a]) In[20]:= InputForm[Integrate[Cos[a*x]/Sin[x], x]] Out[20]//InputForm= ((1 + a)*Hypergeometric2F1[1/2 - a/2, 1, 3/2 - a/2, E^((2*I)*x)] - (-1 + a)*E^((2*I)*a*x)*Hypergeometric2F1[(1 + a)/2, 1, (3 + a)/2, E^((2*I)*x)])/((-1 + a^2)*E^(I*(-1 + a)*x)) As far as I am aware thse are correct. What is the bug? Daniel Lichtblau Wolfram Research === Subject: Re: A Problem with Simplify > I have the following rather simple integral of two sines, which should > evaluate to zero if m is not equal to n and to L/2 if they are the same. Try the following: Integrate[Exp[(a - 1)*x], x] /. a -> 1 Integrate[Cos[(a - 1)*x], x] /. a -> 1 Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 Integrate[Cos[a x]/Sin[x], x] /. a -> 1 There is the ONE underlying BUG! In some complicated cases this bug may result in random partial answers. http://forum.ru-board.com/topic.cgi?forum=5&topic=10291&start=80#9 === Subject: Re: A Problem with Simplify Simplify does not return conditional answers (in the form If[..]) and I don't think it would be reasonable to expect it to do so. The reason is that unlike definite Integration (which does) Simplify is frequently used as part of code for other functions (including built in functions) and returning conditional answers could have a dramatic impact on complexity and what's worse, would only make sense if other functions also returned conditional answers (and accepted conditional input). It just does not seem practical now or in any foreseeable future. Andrzej Kozlowski > I have the following rather simple integral of two sines, which should > evaluate to zero if m is not equal to n and to L/2 if they are the > same. The following is just fine Imn = Simplify[Integrate[ > Sin[(m*Pi*x)/L]* > Sin[(n*Pi*x)/L], > {x, 0, L}]] > However, if I specify that m and n are integers, I only get the > general solution of zero, i.e. when m and n are not equal. Imn = Simplify[Integrate[ > Sin[(m*Pi*x)/L]* > Sin[(n*Pi*x)/L], > {x, 0, L}], > Element[m, Integers] && > Element[n, Integers]] The workaround is obvious in this case, but shouldn't Mathematica give > multiple > answers? Perhaps something similar to what it already does with > Integrate? Kevin > -- Kevin J. McCann > Research Associate Professor > JCET/Physics > Physics Building > University of Maryland, Baltimore County > 1000 Hilltop Circle > Baltimore, MD 21250 > === Subject: Re: A Problem with Simplify > Simplify does not return conditional answers (in the form If[..]) and > I don't think it would be reasonable to expect it to do so. The problem statement was initially wrong. The problem not in Simplify but in Integrate! Integrate may and MUST return conditions as it do it in other cases: In[1]:= Integrate[Exp[-a x^2], {x, 0, Infinity}] Out[1]= If[Re[a] > 0, Sqrt[Pi]/(2*Sqrt[a]), Integrate[E^(-(a*x^2)), {x, 0, Infinity}, Assumptions -> Re[a] <= 0]] But it does not do it in many other cases loosing some answers: Try the following: > Integrate[Exp[(a - 1)*x], x] /. a -> 1 > Integrate[Cos[(a - 1)*x], x] /. a -> 1 > Integrate[(a - 1)^x, {x, -1, 0}] /. a -> 1 > Integrate[Cos[a x]/Sin[x], x] /. a -> 1 There is the ONE underlying BUG! In some complicated cases this bug > may result in random partial answers. === Subject: Re: A Problem with Simplify Yes, you are right here and I admit that I spent no time at all on this issue. I manufactured the example essentilally by replacing Sin by Exp, and of course I should have remembered that as these functions are closely related one very likely probably manufacture a siutbale anti-derivative in terms of Sinc. But my purpose was to demonstrate how easily one can generate examples of this kind. In order for your proposed solution to be really useful what you would need to do is 1) construct a general algorithm for expressing at least a wide class of such anti-derivatives in tems of Sinc (and parhaps other related functions) 2) show how to combine this algorithm with the Risch algorithm used in all current CAS systems for evaluating indefinite integrals. Unless you or someone can deal with both of these problems (none of which seems very easy to me but then this is not my field and I have not given the issue more time than it takes ot write this sort of message), then even if you write many more posts to the MathGroup on the virues of Sinc and related topics (in addition to the large number that you have already written) they will all remain just curiosities without any practical impact. Andrzej Kozlowski >> Just to demonstrate my assertion that returning the answer in terms >> of Sinc does not solve the general problem >> here is a slightly different example: >> Simplify[Integrate[Exp[(2 m*I *Pi*x)/L]*Exp[(2 n*Pi*I*x)/L], >> {x, 0, L}], Assumptions -> Element[m | n, Integers]] >> 0 >> Simplify[Integrate[Exp[(m*I*Pi*x)/L]*Exp[(n*Pi*I*x)/L], {x, 0, L}], >> Assumptions -> Element[m | n, Integers] && m == -n] >> Indeterminate >> Simplify[Integrate[Exp[(0*I *Pi*x)/L]*Exp[(0*Pi*I*x)/L], {x, 0, L}]] >> L >> There are certainly lots of others of this kind. I don't see a >> panacea for all of them. I never claimed to have a panacea. Nonetheless, returning an answer in > terms of Sinc certainly _does_ work for your slightly different > example. (BTW, I'm quite puzzled that you claim to provide an example > showing that returning an answer in terms of Sinc does not help, but > yet you never actually show what an appropriate answer in terms of > Sinc would be!) Your example seems, at least to my eye, to be needlessly complicated. > The problem which lies at its heart is simply that In[6]:= Integrate[Exp[r x], x] > Out[6]= E^(r*x)/r is not valid when r happens to be 0, for then we should instead have In[7]:= Integrate[Exp[0 x], x] > Out[7]= x But, using Sinc, it's easy to give an antiderivative for Exp[r x] > which is valid even when r happens to be 0: x (Sinc[I r x] + r x/2 Sinc[I r x/2]^2) Of course, that antiderivative can then be used to get an answer for > your specific example, namely, your first definite integral Integrate[Exp[(2 m*I *Pi*x)/L]*Exp[(2 n*Pi*I*x)/L], {x, 0, L}] is L*(Sinc[2*(m + n)*Pi] + I*(m + n)*Pi*Sinc[(m + n)*Pi]^2) So again, Sinc was helpful. But of course, many examples > could be given in which Sinc would be of no help. David W. Cantrell > As often happens, I answered in too much of a hurry, so some of the > response. > [Message also posted to: comp.soft-sys.math.mathematica] > I am not convinced (by the way, this very question with the same >> example was discussed here quite recently). >> The usual argument is that Mathematica adopts a generic >> approach, >> whatever that means. I don't much like this way of thinking >> because >> such a concept of genericity is hard to formalize. Instead I >> have my >> own way of thinking about this, which at least satisfies me on >> this >> score. Essentially, I think of all Mathematica expressions as >> belonging to some formal algebraic system, a partial algebra >> (you >> can formally add and multiply most expressions although not >> quite all, >> and you can even multiply then by scalars). There are certain >> built >> in relations that hold between certain expressions in the >> algebra and >> other relations can be introduced by the user. Any two different >> symbols are always different, unless there is a built in >> relationship >> or a user defined relationship that says otherwise. Hence the >> answer >> returned by >> Assuming[Element[m | n, Integers], >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] >> 0 >> is completely correct in my interpretation and not just >> generically >> correct because in my interpretation m and n are not equal >> simply by >> virtue of being different Mathematica expressions. On the other >> hand: >> Assuming[Element[m | n, Integers] && m == n, >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] >> L/2 >> is also O.K. because we performed the simplification with the >> user >> introduced relation m==n. That's not the reason. Rather, it's because we performed the > _integration_ > with the assumption that m==n. (Note that if the integration had > been done > without that assumption and then that result had been simplified > with the > assumption, we would have gotten Indeterminate.) >> Yes, of course I realized that. In fact, note that >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}], >> Assumptions -> Element[m | n, Integers] && m == n] >> returns Indeterminate while >> Assuming[Element[m | n, Integers] && m == n, >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] >> returns L/2. >> I did not mention this because I did not think it was relevant to >> the point I was making, which applies equally well (or equally >> badly) to Integrate and to Simplify. The point was that general >> principle that all distinct symbols represent distinct entities >> unless stated otherwise no logical problems arise. (By the way, >> this can actually be given a formal mathematical proof). However, >> I have to admit that Mathematica does not actually follow this >> principle - in fact it is kind of erratic about it. I would like to add that this issue involves a certain basic > distinction between symbolic algebra (as performed by a computer) > and mathematics as practiced by humans. The meaning of every > statement (program) in computer algebra (unlike most statements > in mathematics) is operational, in the sense that it involves a > definite order in which a certian operations are performed, and > quite often different orders will lead to different resulst. In > mathematics this issue is usually ignored as there is usually a > natural or canonical order which is not made explicit. As an > example consider the problem of simplifying Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] under the assumption that m and n are equal integers. > Operationally this can have two distinct meaning. One is: we > assume first that m and n are integers and simplify then Integrate > the resulting expression. In other words: Simplify[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], > Assumptions -> Element[m | n, Integers] && m == n] > Sin[(n*Pi*x)/L]^2 Integrate[%, {x, 0, L}, Assumptions - Element[ n, Integers] ] > L/2 > The other: we integrate the given expression and then simplify the > answer with the given assumptions. In other words: Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] > (L*n*Cos[n*Pi]*Sin[m*Pi] - L*m*Cos[m*Pi]*Sin[n*Pi])/ > (m^2*Pi - n^2*Pi) Simplify[%, Assumptions -> Element[m | n, Integers] && m == n] > Indeterminate Ignoring for the time being the case m==n==0 (to which I will > return below) both of the above are quite correct from the > operational point of view, but only the first appraoch > corresponds to the usual meaning of assuming... in mathematics. > In most cases, however, the different operational orders will lead > to the same outcome and the issue which order to choose will be > decided by considerations of computational efficiency. I don't > this issue can be completely avoided in computer algebra but as > long as one is aware of it, it should not cause serious problems. So, with my interpretation (different symbols are always >> different >> quantities unless stated otherwise) all is well. Not in my opinion. If both m and n are 0, then obviously the > value of the > integral must be 0, rather than L/2. (BTW, I had not noted that > fact in my > previous response to Kevin.) >> distinct symbols never represent the same quantity (unless >> explicitely stated that they do) then both m and n can't be 0. >> Opinion has nothing to do with that. notice you were referring to the n==m case). You are quite right, > this time even my principle does not apply. So, to be strictly > logical and consistent here, there seem to be only three choices: > to return your answer (using Sinc), to return any answer at all (as > Kevin suggested) or to return a conditional answer (from > very attractive, will not solve the general problem. I am inlcined > to think that in this case Integrate ought to return a conditional > answer (If[m!=0,...]) since (unlike Simplify) it does some time > return conditional answers. As I already indicated, I don't think > that the generic parameters argument is logically fully > satisfactory, although its not a bad guide to the actual practice. Andrzej Kozlowski In my previous post, I gave a result which is valid for all real > values of > the parameters: L/2 (Sinc[(m - n) Pi] - Sinc[(m + n) Pi]) >> This is true but it deal with just the one single case of the >> function Sin. One can certainly come up with other cases where a >> similar problem appears not involving Sin so even if Mathematica >> returned this resut it would hardly deal with the wider problem. >> In any case, the problem is only one of formal interpretation - >> in practice it is easy to get around it if one is aware of how it >> comes about. >> Andrzej Kozlowski === Subject: Re: A Problem with Simplify > Just to demonstrate my assertion that returning the answer in terms > of Sinc does not solve the general problem > here is a slightly different example: Simplify[Integrate[Exp[(2 m*I *Pi*x)/L]*Exp[(2 n*Pi*I*x)/L], > {x, 0, L}], Assumptions -> Element[m | n, Integers]] > 0 Simplify[Integrate[Exp[(m*I*Pi*x)/L]*Exp[(n*Pi*I*x)/L], {x, 0, L}], > Assumptions -> Element[m | n, Integers] && m == -n] > Indeterminate Simplify[Integrate[Exp[(0*I *Pi*x)/L]*Exp[(0*Pi*I*x)/L], {x, 0, L}]] > L There are certainly lots of others of this kind. I don't see a > panacea for all of them. I never claimed to have a panacea. Nonetheless, returning an answer in terms of Sinc certainly _does_ work for your slightly different example. (BTW, I'm quite puzzled that you claim to provide an example showing that returning an answer in terms of Sinc does not help, but yet you never actually show what an appropriate answer in terms of Sinc would be!) Your example seems, at least to my eye, to be needlessly complicated. The problem which lies at its heart is simply that In[6]:= Integrate[Exp[r x], x] Out[6]= E^(r*x)/r is not valid when r happens to be 0, for then we should instead have In[7]:= Integrate[Exp[0 x], x] Out[7]= x But, using Sinc, it's easy to give an antiderivative for Exp[r x] which is valid even when r happens to be 0: x (Sinc[I r x] + r x/2 Sinc[I r x/2]^2) Of course, that antiderivative can then be used to get an answer for your specific example, namely, your first definite integral Integrate[Exp[(2 m*I *Pi*x)/L]*Exp[(2 n*Pi*I*x)/L], {x, 0, L}] is L*(Sinc[2*(m + n)*Pi] + I*(m + n)*Pi*Sinc[(m + n)*Pi]^2) So again, Sinc was helpful. But of course, many examples could be given in which Sinc would be of no help. David W. Cantrell >> As often happens, I answered in too much of a hurry, so some of the >> response. > [Message also posted to: comp.soft-sys.math.mathematica] > I am not convinced (by the way, this very question with the same > example was discussed here quite recently). The usual argument is that Mathematica adopts a generic > approach, > whatever that means. I don't much like this way of thinking > because > such a concept of genericity is hard to formalize. Instead I > have my > own way of thinking about this, which at least satisfies me on > this > score. Essentially, I think of all Mathematica expressions as > belonging to some formal algebraic system, a partial algebra > (you > can formally add and multiply most expressions although not > quite all, > and you can even multiply then by scalars). There are certain > built > in relations that hold between certain expressions in the > algebra and > other relations can be introduced by the user. Any two different > symbols are always different, unless there is a built in > relationship > or a user defined relationship that says otherwise. Hence the > answer > returned by Assuming[Element[m | n, Integers], > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] 0 is completely correct in my interpretation and not just > generically > correct because in my interpretation m and n are not equal > simply by > virtue of being different Mathematica expressions. On the other > hand: Assuming[Element[m | n, Integers] && m == n, > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] > L/2 is also O.K. because we performed the simplification with the > user > introduced relation m==n. >> That's not the reason. Rather, it's because we performed the >> _integration_ >> with the assumption that m==n. (Note that if the integration had >> been done >> without that assumption and then that result had been simplified >> with the >> assumption, we would have gotten Indeterminate.) Yes, of course I realized that. In fact, note that Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}], > Assumptions -> Element[m | n, Integers] && m == n] returns Indeterminate while Assuming[Element[m | n, Integers] && m == n, > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] returns L/2. I did not mention this because I did not think it was relevant to > the point I was making, which applies equally well (or equally > badly) to Integrate and to Simplify. The point was that general > principle that all distinct symbols represent distinct entities > unless stated otherwise no logical problems arise. (By the way, > this can actually be given a formal mathematical proof). However, > I have to admit that Mathematica does not actually follow this > principle - in fact it is kind of erratic about it. >> I would like to add that this issue involves a certain basic >> distinction between symbolic algebra (as performed by a computer) >> and mathematics as practiced by humans. The meaning of every >> statement (program) in computer algebra (unlike most statements >> in mathematics) is operational, in the sense that it involves a >> definite order in which a certian operations are performed, and >> quite often different orders will lead to different resulst. In >> mathematics this issue is usually ignored as there is usually a >> natural or canonical order which is not made explicit. As an >> example consider the problem of simplifying >> Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] >> under the assumption that m and n are equal integers. >> Operationally this can have two distinct meaning. One is: we >> assume first that m and n are integers and simplify then Integrate >> the resulting expression. In other words: >> Simplify[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], >> Assumptions -> Element[m | n, Integers] && m == n] >> Sin[(n*Pi*x)/L]^2 >> Integrate[%, {x, 0, L}, Assumptions -> Element[ n, Integers] ] >> L/2 >> The other: we integrate the given expression and then simplify the >> answer with the given assumptions. In other words: >> Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] >> (L*n*Cos[n*Pi]*Sin[m*Pi] - L*m*Cos[m*Pi]*Sin[n*Pi])/ >> (m^2*Pi - n^2*Pi) >> Simplify[%, Assumptions -> Element[m | n, Integers] && m == n] >> Indeterminate >> Ignoring for the time being the case m==n==0 (to which I will >> return below) both of the above are quite correct from the >> operational point of view, but only the first appraoch >> corresponds to the usual meaning of assuming... in mathematics. >> In most cases, however, the different operational orders will lead >> to the same outcome and the issue which order to choose will be >> decided by considerations of computational efficiency. I don't >> this issue can be completely avoided in computer algebra but as >> long as one is aware of it, it should not cause serious problems. So, with my interpretation (different symbols are always > different > quantities unless stated otherwise) all is well. >> Not in my opinion. If both m and n are 0, then obviously the >> value of the >> integral must be 0, rather than L/2. (BTW, I had not noted that >> fact in my >> previous response to Kevin.) distinct symbols never represent the same quantity (unless > explicitely stated that they do) then both m and n can't be 0. > Opinion has nothing to do with that. >> notice you were referring to the n==m case). You are quite right, >> this time even my principle does not apply. So, to be strictly >> logical and consistent here, there seem to be only three choices: >> to return your answer (using Sinc), to return any answer at all (as >> Kevin suggested) or to return a conditional answer (from >> very attractive, will not solve the general problem. I am inlcined >> to think that in this case Integrate ought to return a conditional >> answer (If[m!=0,...]) since (unlike Simplify) it does some time >> return conditional answers. As I already indicated, I don't think >> that the generic parameters argument is logically fully >> satisfactory, although its not a bad guide to the actual practice. >> Andrzej Kozlowski > >> In my previous post, I gave a result which is valid for all real >> values of >> the parameters: >> L/2 (Sinc[(m - n) Pi] - Sinc[(m + n) Pi]) > This is true but it deal with just the one single case of the > function Sin. One can certainly come up with other cases where a > similar problem appears not involving Sin so even if Mathematica > returned this resut it would hardly deal with the wider problem. In any case, the problem is only one of formal interpretation - > in practice it is easy to get around it if one is aware of how it > comes about. Andrzej Kozlowski >> === Subject: Re: A Problem with Simplify Just to demonstrate my assertion that returning the answer in terms of Sinc does not solve the general problem here is a slightly different example: Simplify[Integrate[Exp[(2 m*I *Pi*x)/L]*Exp[(2 n*Pi*I*x)/L], {x, 0, L}], Assumptions -> Element[m | n, Integers]] 0 Simplify[Integrate[Exp[(m*I*Pi*x)/L]* Exp[(n*Pi*I*x)/L], {x, 0, L}], Assumptions -> Element[m | n, Integers] && m == -n] Indeterminate Simplify[Integrate[Exp[(0*I *Pi*x)/L]*Exp[(0*Pi*I*x)/L], {x, 0, L}]] L There are certainly lots of others of this kind. I don't see a panacea for all of them. Andrzej Kozlowski > As often happens, I answered in too much of a hurry, so some of the > [Message also posted to: comp.soft-sys.math.mathematica] > I am not convinced (by the way, this very question with the same >> example was discussed here quite recently). >> The usual argument is that Mathematica adopts a generic approach, >> whatever that means. I don't much like this way of thinking because >> such a concept of genericity is hard to formalize. Instead I >> have my >> own way of thinking about this, which at least satisfies me on this >> score. Essentially, I think of all Mathematica expressions as >> belonging to some formal algebraic system, a partial algebra (you >> can formally add and multiply most expressions although not quite >> all, >> and you can even multiply then by scalars). There are certain >> built >> in relations that hold between certain expressions in the >> algebra and >> other relations can be introduced by the user. Any two different >> symbols are always different, unless there is a built in >> relationship >> or a user defined relationship that says otherwise. Hence the >> answer >> returned by >> Assuming[Element[m | n, Integers], >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] >> 0 >> is completely correct in my interpretation and not just >> generically >> correct because in my interpretation m and n are not equal >> simply by >> virtue of being different Mathematica expressions. On the other >> hand: >> Assuming[Element[m | n, Integers] && m == n, >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] >> L/2 >> is also O.K. because we performed the simplification with the user >> introduced relation m==n. That's not the reason. Rather, it's because we performed the > _integration_ > with the assumption that m==n. (Note that if the integration had > been done > without that assumption and then that result had been simplified > with the > assumption, we would have gotten Indeterminate.) >> Yes, of course I realized that. In fact, note that >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}], >> Assumptions -> Element[m | n, Integers] && m == n] >> returns Indeterminate while >> Assuming[Element[m | n, Integers] && m == n, >> Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] >> returns L/2. >> I did not mention this because I did not think it was relevant to >> the point I was making, which applies equally well (or equally >> badly) to Integrate and to Simplify. The point was that general >> principle that all distinct symbols represent distinct entities >> unless stated otherwise no logical problems arise. (By the way, >> this can actually be given a formal mathematical proof). However, I >> have to admit that Mathematica does not actually follow this >> principle - in fact it is kind of erratic about it. I would like to add that this issue involves a certain basic > distinction between symbolic algebra (as performed by a computer) > and mathematics as practiced by humans. The meaning of every > statement (program) in computer algebra (unlike most statements in > mathematics) is operational, in the sense that it involves a > definite order in which a certian operations are performed, and > quite often different orders will lead to different resulst. In > mathematics this issue is usually ignored as there is usually a > natural or canonical order which is not made explicit. As an > example consider the problem of simplifying Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] under the assumption that m and n are equal integers. > Operationally this can have two distinct meaning. One is: we > assume first that m and n are integers and simplify then Integrate > the resulting expression. In other words: Simplify[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], > Assumptions -> Element[m | n, Integers] && m == n] > Sin[(n*Pi*x)/L]^2 Integrate[%, {x, 0, L}, Assumptions - Element[ n, Integers] ] > L/2 > The other: we integrate the given expression and then simplify the > answer with the given assumptions. In other words: Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] > (L*n*Cos[n*Pi]*Sin[m*Pi] - L*m*Cos[m*Pi]*Sin[n*Pi])/ > (m^2*Pi - n^2*Pi) Simplify[%, Assumptions -> Element[m | n, Integers] && m == n] > Indeterminate Ignoring for the time being the case m==n==0 (to which I will return > below) both of the above are quite correct from the operational > point of view, but only the first appraoch corresponds to the usual > meaning of assuming... in mathematics. In most cases, however, the > different operational orders will lead to the same outcome and the > issue which order to choose will be decided by considerations of > computational efficiency. I don't this issue can be completely > avoided in computer algebra but as long as one is aware of it, it > should not cause serious problems. So, with my interpretation (different symbols are always different >> quantities unless stated otherwise) all is well. Not in my opinion. If both m and n are 0, then obviously the value > of the > integral must be 0, rather than L/2. (BTW, I had not noted that > fact in my > previous response to Kevin.) >> distinct symbols never represent the same quantity (unless >> explicitely stated that they do) then both m and n can't be 0. >> Opinion has nothing to do with that. notice you were referring to the n==m case). You are quite right, > this time even my principle does not apply. So, to be strictly > logical and consistent here, there seem to be only three choices: > to return your answer (using Sinc), to return any answer at all (as > Kevin suggested) or to return a conditional answer (from Integrate). > attractive, will not solve the general problem. I am inlcined to > think that in this case Integrate ought to return a conditional > answer (If[m!=0,...]) since (unlike Simplify) it does some time > return conditional answers. As I already indicated, I don't think > that the generic parameters argument is logically fully > satisfactory, although its not a bad guide to the actual practice. Andrzej Kozlowski In my previous post, I gave a result which is valid for all real > values of > the parameters: L/2 (Sinc[(m - n) Pi] - Sinc[(m + n) Pi]) >> This is true but it deal with just the one single case of the >> function Sin. One can certainly come up with other cases where a >> similar problem appears not involving Sin so even if Mathematica >> returned this resut it would hardly deal with the wider problem. >> In any case, the problem is only one of formal interpretation - in >> practice it is easy to get around it if one is aware of how it >> comes about. >> Andrzej Kozlowski > === Subject: Re: A Problem with Simplify As often happens, I answered in too much of a hurry, so some of the > [Message also posted to: comp.soft-sys.math.mathematica] > I am not convinced (by the way, this very question with the same > example was discussed here quite recently). The usual argument is that Mathematica adopts a generic approach, > whatever that means. I don't much like this way of thinking because > such a concept of genericity is hard to formalize. Instead I > have my > own way of thinking about this, which at least satisfies me on this > score. Essentially, I think of all Mathematica expressions as > belonging to some formal algebraic system, a partial algebra (you > can formally add and multiply most expressions although not quite > all, > and you can even multiply then by scalars). There are certain > built > in relations that hold between certain expressions in the algebra > and > other relations can be introduced by the user. Any two different > symbols are always different, unless there is a built in > relationship > or a user defined relationship that says otherwise. Hence the answer > returned by Assuming[Element[m | n, Integers], > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] 0 is completely correct in my interpretation and not just generically > correct because in my interpretation m and n are not equal simply > by > virtue of being different Mathematica expressions. On the other > hand: Assuming[Element[m | n, Integers] && m == n, > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] > L/2 is also O.K. because we performed the simplification with the user > introduced relation m==n. >> That's not the reason. Rather, it's because we performed the >> _integration_ >> with the assumption that m==n. (Note that if the integration had >> been done >> without that assumption and then that result had been simplified >> with the >> assumption, we would have gotten Indeterminate.) Yes, of course I realized that. In fact, note that Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}], > Assumptions -> Element[m | n, Integers] && m == n] returns Indeterminate while Assuming[Element[m | n, Integers] && m == n, > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] returns L/2. I did not mention this because I did not think it was relevant to > the point I was making, which applies equally well (or equally > badly) to Integrate and to Simplify. The point was that general > principle that all distinct symbols represent distinct entities > unless stated otherwise no logical problems arise. (By the way, this > can actually be given a formal mathematical proof). However, I have > to admit that Mathematica does not actually follow this principle - > in fact it is kind of erratic about it. I would like to add that this issue involves a certain basic distinction between symbolic algebra (as performed by a computer) and mathematics as practiced by humans. The meaning of every statement (program) in computer algebra (unlike most statements in mathematics) is operational, in the sense that it involves a definite order in which a certian operations are performed, and quite often different orders will lead to different resulst. In mathematics this issue is usually ignored as there is usually a natural or canonical order which is not made explicit. As an example consider the problem of simplifying Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] under the assumption that m and n are equal integers. Operationally this can have two distinct meaning. One is: we assume first that m and n are integers and simplify then Integrate the resulting expression. In other words: Simplify[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], Assumptions -> Element[m | n, Integers] && m == n] Sin[(n*Pi*x)/L]^2 Integrate[%, {x, 0, L}, Assumptions -> Element[ n, Integers] ] L/2 The other: we integrate the given expression and then simplify the answer with the given assumptions. In other words: Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}] (L*n*Cos[n*Pi]*Sin[m*Pi] - L*m*Cos[m*Pi]*Sin[n*Pi])/ (m^2*Pi - n^2*Pi) Simplify[%, Assumptions -> Element[m | n, Integers] && m == n] Indeterminate Ignoring for the time being the case m==n==0 (to which I will return below) both of the above are quite correct from the operational point of view, but only the first appraoch corresponds to the usual meaning of assuming... in mathematics. In most cases, however, the different operational orders will lead to the same outcome and the issue which order to choose will be decided by considerations of computational efficiency. I don't this issue can be completely avoided in computer algebra but as long as one is aware of it, it should not cause serious problems. So, with my interpretation (different symbols are always different > quantities unless stated otherwise) all is well. >> Not in my opinion. If both m and n are 0, then obviously the value >> of the >> integral must be 0, rather than L/2. (BTW, I had not noted that >> fact in my >> previous response to Kevin.) distinct symbols never represent the same quantity (unless > explicitely stated that they do) then both m and n can't be 0. > Opinion has nothing to do with that. notice you were referring to the n==m case). You are quite right, this time even my principle does not apply. So, to be strictly logical and consistent here, there seem to be only three choices: to return your answer (using Sinc), to return any answer at all (as Kevin suggested) or to return a conditional answer (from Integrate). As I will not solve the general problem. I am inlcined to think that in this case Integrate ought to return a conditional answer (If[m! =0,...]) since (unlike Simplify) it does some time return conditional answers. As I already indicated, I don't think that the generic parameters argument is logically fully satisfactory, although its not a bad guide to the actual practice. Andrzej Kozlowski > In my previous post, I gave a result which is valid for all real >> values of >> the parameters: >> L/2 (Sinc[(m - n) Pi] - Sinc[(m + n) Pi]) > This is true but it deal with just the one single case of the > function Sin. One can certainly come up with other cases where a > similar problem appears not involving Sin so even if Mathematica > returned this resut it would hardly deal with the wider problem. In any case, the problem is only one of formal interpretation - in > practice it is easy to get around it if one is aware of how it comes > about. Andrzej Kozlowski === Subject: Re: A Problem with Simplify > I am not convinced (by the way, this very question with the same > example was discussed here quite recently). The usual argument is that Mathematica adopts a generic approach, > whatever that means. I don't much like this way of thinking because > such a concept of genericity is hard to formalize. Instead I have my > own way of thinking about this, which at least satisfies me on this > score. Essentially, I think of all Mathematica expressions as > belonging to some formal algebraic system, a partial algebra (you > can formally add and multiply most expressions although not quite all, > and you can even multiply then by scalars). There are certain built > in relations that hold between certain expressions in the algebra and > other relations can be introduced by the user. Any two different > symbols are always different, unless there is a built in relationship > or a user defined relationship that says otherwise. Hence the answer > returned by Assuming[Element[m | n, Integers], > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] 0 is completely correct in my interpretation and not just generically > correct because in my interpretation m and n are not equal simply by > virtue of being different Mathematica expressions. On the other hand: Assuming[Element[m | n, Integers] && m == n, > Simplify[Integrate[Sin[(m*Pi*x)/L]*Sin[(n*Pi*x)/L], {x, 0, L}]]] > L/2 is also O.K. because we performed the simplification with the user > introduced relation m==n. That's not the reason. Rather, it's because we performed the _integration_ with the assumption that m==n. (Note that if the integration had been done without that assumption and then that result had been simplified with the assumption, we would have gotten Indeterminate.) > So, with my interpretation (different symbols are always different > quantities unless stated otherwise) all is well. Not in my opinion. If both m and n are 0, then obviously the value of the integral must be 0, rather than L/2. (BTW, I had not noted that fact in my previous response to Kevin.) In my previous post, I gave a result which is valid for all real values of the parameters: L/2 (Sinc[(m - n) Pi] - Sinc[(m + n) Pi]) David W. Cantrell === Subject: Re: A Problem with Simplify On 11 =C1=D0=D2, 13:59, Gulliet Recently I also have found another strange bug in Simplfy (not so > dangerous): > FullSimplify[Sin[x]*Cos[x]] > gives Sin[x]*Cos[x] instead Sin[2*x]/2. The workaround is > FullSimplify[2*Sin[x]*Cos[x]]/2. This is not a bug, indeed. As a rule of thumb, *FullSimplify* tries to > minimize the leaf count of the expression. For the case above, the original expression sin(x)cos(x) has a leaf > count of 5 whereas the trigonometric identity sin(2x)/2 has a leaf count > of 8. Therefore, *FullSimplify* returns the original form sin(x)cos(x) > since it is deemed as simpler than sin(2x)/2 w.r.t. the lead count of > each expression. Note that, in general, you can modify/tweak this default behavior to > suit your needs by witting your own *ComplexityFunction*. However, when > dealing with trigonometric expressions (especially when looking for some > trigonometric identities) it is usually better and less cumbersome to > use *TrigReduce* and the like (*TrigExpand*, *TrigFactor*, etc.). FullSimplify[Sin[x]*Cos[x]] (* returns Cos[x] Sin= [x] *) > % // LeafCount (* returns = 5 *) > TrigReduce[Sin[x]*Cos[x]] (* returns 1/2 Sin[= 2 x] *) > % // LeafCount (* returns = 8 *) > LeafCount[Cosh[x] - Sinh[x]] (* returns 7 = *) > FullSimplify[Cosh[x] - Sinh[x]] (* returns E^-x = *) > % // LeafCount (* returns = 5 *) -- this become clear. === Subject: Re: A Problem with Simplify > Recently I also have found another strange bug in Simplfy (not so > dangerous): > FullSimplify[Sin[x]*Cos[x]] > gives Sin[x]*Cos[x] instead Sin[2*x]/2. The workaround is > FullSimplify[2*Sin[x]*Cos[x]]/2 This is not a bug! In[7]:= LeafCount[Sin[x]*Cos[x]] > Out[7]= 5 In[8]:= LeafCount[Sin[2*x]/2] > Out[8]= 8 In other words, Sin[x] Cos[x] is considered simpler by Simplify than =9A > Sin[2*x]/2, that's all. Indeed: In[9]:= Simplify[Sin[2*x]/2] > Out[9]= Cos[x]*Sin[x] If you want Simplify to return Sin[2*x]/2 use a different complexity =9A > functions: =9A Simplify[Sin[x]*Cos[x], ComplexityFunction - =9A =9A =9A (LeafCount[#1] + 10*Count[#1, _Cos, > =9A =9A =9A =9A =9A =9A =9A =9AInfinity] & )] > =9A (1/2)*Sin[2*x] === Subject: Re: Applying the Integration Function to a List Of Simplified version regions = {{{x, 0, a}, {cx, 0, b}, {y, 0, c}, {cy, 0, d}}, {{x, 0, 2 a}, {cx, 0, b}, {y, 0, c}, {cy, 0, d}}, {{x, 0, a}, {cx, 0, 3 b}, {y, 0, c}, {cy, 0, d}}}; Integrate[1, Sequence @@ #] & /@ regions {a b c d,2 a b c d,3 a b c d} Bob Hanlon > Assume that I have already determined a list of 4 dimensional regions as > follows: > > regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; > > I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: > > {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} > > How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: > > Integrate @@ regions > > or > > Integrate @@@ regions > > But I can't figure out how to incorporate the 1 as the integrand when I try > to set this up automatically. > > There must be a way? > > > John > > === Subject: Re: Linking EventHandler to a Control Object Hi Todd, I'm not entirely sure that I understood your precise goal, but you might try something along the lines of the following. Use a helper function and the ability to trigger functions from Dynamic statements: updateColours := Module[{temp2}, (color = color /. {Black -> Red, Red -> Green, Green -> Black}; temp2 = Position[test2, trak2]; test2 = ReplacePart[test2, temp2 -> Style[trak2, color]];) ]; trak2 = SetterBar[ Evaluate@Dynamic[trak2, (trak2 = #; updateColours) &], {Phe -> Phe, Ser -> Ser, Leu -> Leu, Val -> Val}] test2 = {Phe, Ser, Leu, Ser, Val}; color = Black; EventHandler[{Dynamic[trak2], Dynamic[test2]}, {MouseClicked :> updateColours}] Hope that helps, Januk > Hi folks, Have any of you tried to use the new > (V6)EventHandler command to excute a series of actions > based on input to a control object such as SetterBar? I have had success getting Mathematica to update a > displayed list every time the displayed list is > clicked on, but not when I want a control object to be > clicked on to update the displayed list. Probably an example would help clarify: Example 1: WORKS on my computer test1 = {Phe, Ser, Leu, Ser, > Val}; color = Black; trak = Ser; > EventHandler[ > Dynamic[test1], {MouseClicked :> (color = > color /. {Black -> Red, Red -> Green, Green - Black}; > temp1 = Position[test1, trak]; > test1 = ReplacePart[test1, temp1 -> Style[trak, > color]];)}] Example 2: Does NOT work trak2 = SetterBar[ > Evaluate[Dynamic[trak2]], {Phe -> Phe, Ser - Ser, > Leu -> Leu, Val -> Val}] > test2 = {Phe, Ser, Leu, Ser, Val}; color = > Black; > EventHandler[{Dynamic[trak2], > Dynamic[test2]}, {MouseClicked :> (color = > color /. {Black -> Red, Red -> Green, Green - Black}; > temp2 = Position[test2, trak2]; > test2 = ReplacePart[test2, temp2 -> Style[trak2, > color]]; test2)}] Notice how the SetterBar in example 2 is updated, but > the corresponding list that should be updated is not. > Its as though the EventHandler command is actually not > seeing the mouse click. Would you have any thoughts on how to link the input > at the control object to the desired response of > updating a displayed list? Todd ______________________________________________________________= _____________=AD_________ > Be a better friend, newshound, and > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/= ;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ === Subject: Re: DSolve question DSolve always gives a list of possible solutions, even if there is only one. Therefore, your functions are lists and not scalars. E.g. look at Out[5]. You can fix this by taking the first elemenbt. E.g.: i1[t_] = (i1[t] /. it1)[[1]] or you can pick the first element when you define it1. With this fix, everything should work as expected. hope this helps, Daniel > Hi everyone. I'm looking for help using the result of DSolve. > In the code below the DSolve statements in In[3] and In[4] find i1[t] and i2[t] respectively in terms of variable t and a constant a1, a2 respectively. Then, numerical values for a1 and a2 will be found by simultaneous equations equating i1[t] and i2[t] in the FindRoot statement in In[7]. > However, I haven.89¥út been able to make Mathematica relate the i1[t], i2[t] in FindRoot to the i1[t], i2[t] resulting from DSolve. I.89¥úve tried several ways and finally the way below and always get errors. > On the other hand if I COPY and PASTE the DSolve output Out[3], Out[4] following the -> into the lhs of i1[t] = lhs, then the FindRoot gives me the a1, and similar for a2.. > If anyone can instruct me on how to get the FindRoot to recognize the i1[t], i2[t] found from DSolve I would appreciate it. I guess in other words, how do I get output of DSolve to be a usable function. > > In my own reply to this post I will paste the example of the code where COPY/PASTE has been used as described above to give numerical values for a1, a2. > > > > In[1]:= Duty = .6; SWfreq = 1*10^6; Vin = 3.2; Vout = 1.8; L = > 4.7*10^-7; R = 0.008; > > In[2]:= Dt1 = > Duty (1/SWfreq); Dt2 = (1 - Duty) (1/SWfreq); VL2 = - Vout; VL1 = > Vin - Vout; T = 1/SWfreq; > > In[3]:= it1 = > Simplify[DSolve[{L i1'[t] + R i1[t] - VL1 == 0, i1[0] == a1}, i1[t], > t]] > > Out[3]= {{i1[t] -> 175.+ (-175. + 1. a1) E^(-17021.3 t)}} > > In[4]:= it2 = > Simplify[DSolve[{L i2'[t] + R i2[t] - VL2 == 0, i2[0] == a2}, i2[t], > t]] > > Out[4]= {{i2[t] -> -225. + (225.+ 1. a2) E^(-17021.3 t)}} > > In[5]:= i1[t_] = i1[t] /. it1 > > Out[5]= {175.+ (-175. + 1. a1) E^(-17021.3 t)} > > In[6]:= i2[t_] = i2[t] /. it2 > > Out[6]= {-225. + (225.+ 1. a2) E^(-17021.3 t)} > > In[7]:= FindRoot[{i1[0] == i2[T], > i1[Dt1] == i2[Dt1]}, > {a1, 0}, {a2, 0}] > > During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {0,{-0.983123}}+{{1.,0}} cannot be combined. > > During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {{1.,0}}+{0,{-0.983123}} cannot be combined. > > During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {0,{-0.989839}}+{{0.989839,0}} cannot be combined. > > During evaluation of In[7]:= General::stop: Further output of > Thread::tdlen will be suppressed during this calculation. > > During evaluation of In[7]:= FindRoot::njnum: The Jacobian is not a > matrix of numbers at {a1,a2} = {0.,0.}. > > Out[7]= {a1 -> 0., a2 -> 0.} > === Subject: Re: DSolve question > Hi everyone. I'm looking for help using the result of DSolve. > In the code below the DSolve statements in In[3] and In[4] find i1[t] and i2[t] respectively in terms of variable t and a constant a1, a2 respectively. Then, numerical values for a1 and a2 will be found by simultaneous equations equating i1[t] and i2[t] in the FindRoot statement in In[7]. > However, I haven.89¥út been able to make Mathematica relate the i1[t], i2[t] in FindRoot to the i1[t], i2[t] resulting from DSolve. I.89¥úve tried several ways and finally the way below and always get errors. > On the other hand if I COPY and PASTE the DSolve output Out[3], Out[4] following the -> into the lhs of i1[t] = lhs, then the FindRoot gives me the a1, and similar for a2.. > If anyone can instruct me on how to get the FindRoot to recognize the i1[t], i2[t] found from DSolve I would appreciate it. I guess in other words, how do I get output of DSolve to be a usable function. > > In my own reply to this post I will paste the example of the code where COPY/PASTE has been used as described above to give numerical values for a1, a2. > > > > In[1]:= Duty = .6; SWfreq = 1*10^6; Vin = 3.2; Vout = 1.8; L = > 4.7*10^-7; R = 0.008; > > In[2]:= Dt1 = > Duty (1/SWfreq); Dt2 = (1 - Duty) (1/SWfreq); VL2 = - Vout; VL1 = > Vin - Vout; T = 1/SWfreq; > > In[3]:= it1 = > Simplify[DSolve[{L i1'[t] + R i1[t] - VL1 == 0, i1[0] == a1}, i1[t], > t]] This is unrelated to the question, but it's probably better to work with exact numbers when using DSolve. I don't know if inexact numbers can cause trouble with DSolve, but I know that they can be a problem for Solve when using certain settings and DSolve does use Solve internally (or at least it does emit Solve::* messages sometimes). So this is a bit better/safer: it1 = Simplify[ DSolve[Rationalize[{L i1'[t] + R i1[t] - VL1 == 0, i1[0] == a1}], i1[t], t]] > > Out[3]= {{i1[t] -> 175.+ (-175. + 1. a1) E^(-17021.3 t)}} > > In[4]:= it2 = > Simplify[DSolve[{L i2'[t] + R i2[t] - VL2 == 0, i2[0] == a2}, i2[t], > t]] > > Out[4]= {{i2[t] -> -225. + (225.+ 1. a2) E^(-17021.3 t)}} > > In[5]:= i1[t_] = i1[t] /. it1 Try using i1[t_] = i1[t] /. First[it1] here, > > Out[5]= {175.+ (-175. + 1. a1) E^(-17021.3 t)} > > In[6]:= i2[t_] = i2[t] /. it2 and i2[t_] = i2[t] /. First[it2] here, and everything will work fine. > > Out[6]= {-225. + (225.+ 1. a2) E^(-17021.3 t)} > > In[7]:= FindRoot[{i1[0] == i2[T], > i1[Dt1] == i2[Dt1]}, > {a1, 0}, {a2, 0}] > > During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {0,{-0.983123}}+{{1.,0}} cannot be combined. > > During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {{1.,0}}+{0,{-0.983123}} cannot be combined. > > During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {0,{-0.989839}}+{{0.989839,0}} cannot be combined. > > During evaluation of In[7]:= General::stop: Further output of > Thread::tdlen will be suppressed during this calculation. > > During evaluation of In[7]:= FindRoot::njnum: The Jacobian is not a > matrix of numbers at {a1,a2} = {0.,0.}. > > Out[7]= {a1 -> 0., a2 -> 0.} > === Subject: Traditional Ordering of Equations As a beginner in Mathematica I am using Mathematica 6.0 for integration and simplification of a number of functions which I subsequently use in a Fortran program. Now I have two questions which I cannot find the answer to in the documentation or forums: - Is there a way to prevent Mathematica from reordering a function to its standard order upon evaluation? - I want to list all resulting functions in one cell, as can be done using the Print and Fortranform commands. I want the list to look like this: FunctionName1 = Function1 FunctionName2 = Function2 FunctionName3 = Function3 etc. All these functions were defined earlier in the notebook using the following syntax: FunctionName1 = Function1 I tried writing a new Mathematica function to do this: FortranFormulas[ff_] := Print[HoldForm[ff] = FortranForm[ff]] FunctionNameList = {NO3inYt, NO3outYt} Scan[FortranFormulas, FunctionNameList] However, this generates an output like: = Function1inFortranForm Function1 = Function2inFortranForm Function2 The alternative: FortranFormulas[ff_] := Print[ff] = FortranForm[Release[ff]]] FunctionNameList = {HoldForm[NO3inYt], HoldForm[NO3outYt]} Scan[FortranFormulas, FunctionNameList] generates an output like: = FunctionName1 FunctionName1 = FunctionName2 FunctionName2 Both are incorrect and in the wrong order. === Subject: Re: Traditional Ordering of Equations $Version 6.0 for Microsoft Windows (32-bit) (February 7, 2008) Hallo Joost, I can not reproduce the reordering: 1) Print[HoldForm[b = a]] prints b = a as expected 2) Print[b =a] prints = a b as expected but you get output as 2) from input as 1) ???? Daniel > As a beginner in Mathematica I am using Mathematica 6.0 for integration and simplification of a number of functions which I subsequently use in a Fortran program. Now I have two questions which I cannot find the answer to in the documentation or forums: > > - Is there a way to prevent Mathematica from reordering a function to its standard order upon evaluation? > > - I want to list all resulting functions in one cell, as can be done using the Print and Fortranform commands. I want the list to look like this: > > > FunctionName1 = Function1 > FunctionName2 = Function2 > FunctionName3 = Function3 > etc. > > All these functions were defined earlier in the notebook using the following syntax: > > FunctionName1 = Function1 > > I tried writing a new Mathematica function to do this: > > FortranFormulas[ff_] := > Print[HoldForm[ff] = FortranForm[ff]] > FunctionNameList = {NO3inYt, NO3outYt} > Scan[FortranFormulas, FunctionNameList] > > However, this generates an output like: > = Function1inFortranForm Function1 > = Function2inFortranForm Function2 > > The alternative: > FortranFormulas[ff_] := > Print[ff] = FortranForm[Release[ff]]] > FunctionNameList = {HoldForm[NO3inYt], HoldForm[NO3outYt]} > Scan[FortranFormulas, FunctionNameList] > > generates an output like: > = FunctionName1 FunctionName1 > = FunctionName2 FunctionName2 > > Both are incorrect and in the wrong order. > > === Subject: Problem with cell brackets and Manipulate Here is some code: conGrade[bias_, sd_, sm_, tea_, maxBias_] := Module[{grade}, grade = 103. - 33.*(Sqrt[(bias/maxBias)^2 + (sm*sd)^2]/tea); If[grade > 100., grade = 100.]; If[grade < 0., grade = 0.]; grade]; Manipulate[ conGrade[bias, sd, sigMult, TEa, maxBias], {{bias, 0}, -10, 10, Appearance -> Labeled}, {{sd, 1.0}, 0, 10, Appearance -> Labeled}, {{sigMult, 2.5}, 1.65, 3.0, Appearance -> Labeled}, {{TEa, 8.0}, 5, 10, Appearance -> Labeled}, {{maxBias, 0.85}, 0.75, 1.0, Appearance -> Labeled}] The code works fine. However, when I select the bracket to the right of the manipulate to collapse the code, most of the sliders move to the end of their range. As long as the bracket is highlighted, the sliders will move to the pegged positions. As soon as the highlight is removed -- collapsing the code part does not matter -- the sliders work properly. Using Mathematica 6.0.2.1, OS X 10.5 2 Any help would be appreciated. george woodrow === Subject: Multiple threads using Mathlink I have a question regarding multithreaded access to Mathematica via MathLink. I'm developing a set of webservices for use with the Taverna Workbench (taverna.sourceforge.net), a computational biology tool. These webservices call Mathematica to perform some computations. Obviously, each webservice invocation creates a new thread. As I'd like the Mathematica environments belonging to different threads to be completely separated one from another, I've implemented a mechanism which creates a new MathLink object for every thread. Unfortunately, this leads to serious problems, including an application service crash, occuring from time to time. Apparently, this is some kind of a concurrent access problem - it doesn't happen when I run only one thread at a time, with subsequent invocations separated by a few seconds. Perhaps there is a problem with my understanding of the relation between MathLink and Mathematica kernels? Is it true that each Mathlink object creates a separate kernel process? If not, how to achieve such behavior? Do the MathLink native libraries support multithreading? Pawel Banasik === Subject: Re: cell convert to > > > > Some of my students have a strange problem, and I cannot find the > solution. > > In the menu Cell, Convert To, they don't have StandardForm and > TraditionalForm (ctrl+shift+n and ctrl+shift+t also don't work). > > > > Is there a way to install these settings? > > > > > > > Florian Jaccard > > I wonder if the file Menusetup.tr, that you will find in a subdirectory off the home directory of Mathematica, has been corrupted. This file contains a specification of the entire FrontEnd menu, and people sometimes edit it to augment the menu in various ways. If this was a problem, you could copy a clean version from nother machine with Mathematica loaded, provided it was the same version of Mathematica and the same operating system. Of course, the other, more general answer might be to remove Mathematica and re-install. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: remote Kernel i want to run the MathKernel (Mathematica 6) on another faster computer remotely in the frontend of my laptop (Mac Pro and MacBook Pro). I Configured the Kernel and the box 'Arguments to MLOpen' contains the following (by default): -LinkMode Listen -LinkProtocol TCPIP -LinkOptions MLDontInteract then the Launch command box shows (by default): `java` -jar `mathssh` jasch@crush /Applications/Mathematica-6.0.app/ Contents/MacOS/MathKernel -mathlink -LinkMode Connect -LinkProtocol TCPIP -LinkName `linkname` -LinkHost `ipaddress` now, if i now run a notebook with that kernel, a window asking for the password appears and after that i can see that a kernel on the remote machine (i specified 'launch on remote machine') is started. But then nothing happens and finally i get the error message: 'The kernel Crush failed to connect to the front end. (Error = MLECONNECT). You should try running the kernel connection outside the front end' Could someone provide some help on how to make this work, that is run the kernel of a remote machine within the frontend of my local machine? Jan === Subject: Re: Replace non-numeric values in a list list = {a, 1, 2, b, 3}; Replace[list, {x_?NumericQ -> x, x_ -> 0}, 1] {0, 1, 2, 0, 3} or Replace[list, x_ /; ! NumericQ[x] -> 0, 1] {0, 1, 2, 0, 3} Bobby I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? > -- DrMajorBob@longhorns.com === Subject: Re: Replace non-numeric values in a list I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? -- > Adel Elsabbaghhttp://www.svlab-asu.com/aelsabbagh.html list={a,1,2,b,3}; myfunc[x_] /; Not[NumberQ[x]] = 0; myfunc[x_] = x; newlist = Simplify[list,TransformationFunctions -> myfunc] Output is {0,1,2,0,3} === Subject: Re: Replace non-numeric values in a list I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? -- > Adel Elsabbaghhttp://www.svlab-asu.com/aelsabbagh.html Surprisingly the script below fails. Anyone want to comment? list = { a, 1, 2, b, 3}; newlist2 = list /. v_?(Not[NumericQ[#]] &) -> 0 === Subject: Re: Replace non-numeric values in a list > I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? > -- > Adel Elsabbaghhttp://www.svlab-asu.com/aelsabbagh.html Surprisingly the script below fails. Anyone want to comment? list = { a, 1, 2, b, 3}; newlist2 = list /. v_?(Not[NumericQ[#]] &) -> 0 This is because the pattern you used matches the whole list (which is not a numeric quantity). === Subject: Re: Replace non-numeric values in a list I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? -- > Adel Elsabbaghhttp://www.svlab-asu.com/aelsabbagh.html newlist = Map[( If[NumericQ[#],#,0] &),list] list = newlist === Subject: Re: Replace non-numeric values in a list If[IntegerQ[#], #, # = 0] & /@ list Kim === Subject: Re: Replace non-numeric values in a list > I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? This is the kind of thing the Mathematica does extremely well. At the core of Mathematica is a very sophisticated pattern matching engine around which everything else is built, so you want to take advantage of that system as often and directly as possible. Here is one solution: ZeroNonNumeric[ (n_)?NumericQ ] := n; ZeroNonNumeric[ _ ] := 0; Map[ ZeroNonNumeric, {a, 1, 2, b, 3} ] Out[1]= {0, 1, 2, 0, 3} The first version of the function says that any for pattern for which the predicate NumericQ[] returns False, throw back that pattern. The second version says to return 0 for anything else. Mathematica will always try the more specific patterns first, then try more general patterns. Finally, I Map that function over the list. Why do I use Map instead of ZeroNonNumeric[ {a, 1, 2, b, 3} ] ? Simple: the list itself is not a number. By Map'ping, I make sure that only the elements of the list get checked, not the list itself. There are more code-efficient ways of solving this, which all look like perl code having a bad hair day. This solution spells out exactly its intent, which is good practice in any language. === Subject: Re: Replace non-numeric values in a list list //. {any___, a_, other___} /; ! NumericQ[a] :> {any, 0, other} or If[! NumericQ[#], 0, #] & /@ list ?? Jens > > I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? > === Subject: Re: Replace non-numeric values in a list list = {a, 1, 2, b, 3}; If[NumericQ[#], #, 1] & /@ list {1, 1, 2, 1, 3} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? -- > Adel Elsabbagh > http://www.svlab-asu.com/aelsabbagh.html === Subject: Re: Replace non-numeric values in a list > > I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? > This is one possibility: Replace[{a, 1, 2, b, 4}, x_ /; ! NumericQ[x] -> 0, 1] === Subject: Re: DSolve question Duty = 6/10; SWfreq = 10^6; Vin = 32/10; Vout = 18/10; L = 47*10^-8; R = 8/1000; T = 1/SWfreq; Dt1 = Duty*T; Dt2 = (1 - Duty)*T; VL2 = -Vout; VL1 = Vin - Vout; Clear[i1, i2, i]; i1[t_] = i[t] /. DSolve[{L * i'[t] + R i[t] - VL1 == 0, i[0] == a1}, i[t], t][[1]] // FullSimplify (a1 - 175)/E^((800000*t)/47) + 175 i2[t_] = i[t] /. DSolve[{L * i'[t] + R i[t] - VL2 == 0, i[0] == a2}, i[t], t][[1]] // FullSimplify (a2 + 225)/E^((800000*t)/47) - 225 Solve[{i1[0] == i2[T], i1[Dt1] == i2[Dt1]}, {a1, a2}][[1]] // FullSimplify {a1 -> -((25*(7 - 16*E^(12/1175) + 9*E^(4/235)))/(-1 + E^(4/235))), a2 -> (25*(9 - 25*E^(4/235) + 16*E^(32/1175)))/(-1 + E^(4/235))} % // N {a1->14.1825,a2->18.2886} Bob Hanlon > Hi everyone. I'm looking for help using the result of DSolve. > In the code below the DSolve statements in In[3] and In[4] find i1[t] and i2[t] respectively in terms of variable t and a constant a1, a2 respective ly. Then, numerical values for a1 and a2 will be found by simultaneous equations equating i1[t] and i2[t] in the FindRoot statement in In[7]. > However, I haven=C3=A2=C2=80=C2=99t been able to make Mathematica relate the i1[t], i2[t] in FindRoot to the i1[t], i2[t] resulting from DSolve. I =C3=A2=C2=80=C2=99ve tried several ways and finally the way below and alway= s get errors. > On the other hand if I COPY and PASTE the DSolve output Out[3], Out[4] following the -> into the lhs of i1[t] = lhs, then the FindRoot gives me the a1, and similar for a2.. > If anyone can instruct me on how to get the FindRoot to recognize the i1[t], i2[t] found from DSolve I would appreciate it. I guess in other words, how do I get output of DSolve to be a usable function. In my own reply to this post I will paste the example of the code where COPY/PASTE has been used as described above to give numerical values for a1, a2. In[1]:= Duty = .6; SWfreq = 1*10^6; Vin = 3.2; Vout = 1.8; L = > 4.7*10^-7; R = 0.008; In[2]:= Dt1 = > Duty (1/SWfreq); Dt2 = (1 - Duty) (1/SWfreq); VL2 = - Vout; VL1 == > Vin - Vout; T = 1/SWfreq; In[3]:= it1 = > Simplify[DSolve[{L i1'[t] + R i1[t] - VL1 == 0, i1[0] == a1}, i1[t], > t]] Out[3]= {{i1[t] -> 175.+ (-175. + 1. a1) E^(-17021.3 t)}} In[4]:= it2 = > Simplify[DSolve[{L i2'[t] + R i2[t] - VL2 == 0, i2[0] == a2}, i2[t], > t]] Out[4]= {{i2[t] -> -225. + (225.+ 1. a2) E^(-17021.3 t)}} In[5]:= i1[t_] = i1[t] /. it1 Out[5]= {175.+ (-175. + 1. a1) E^(-17021.3 t)} In[6]:= i2[t_] = i2[t] /. it2 Out[6]= {-225. + (225.+ 1. a2) E^(-17021.3 t)} In[7]:= FindRoot[{i1[0] == i2[T], > i1[Dt1] == i2[Dt1]}, > {a1, 0}, {a2, 0}] During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {0,{-0.983123}}+{{1.,0}} cannot be combined. During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {{1.,0}}+{0,{-0.983123}} cannot be combined. During evaluation of In[7]:= Thread::tdlen: Objects of unequal length > in {0,{-0.989839}}+{{0.989839,0}} cannot be combined. During evaluation of In[7]:= General::stop: Further output of > Thread::tdlen will be suppressed during this calculation. During evaluation of In[7]:= FindRoot::njnum: The Jacobian is not a > matrix of numbers at {a1,a2} = {0.,0.}. Out[7]= {a1 -> 0., a2 -> 0.} > === Subject: Re: Labeling points data = { {0.5, 50, 50%}, {1.0, 50, 75%}, {1.5, 50, 88%}, {2.0, 50, 94%}, {1.0, 100, 25%}, {1.5, 100, 50%}, {2.0, 100, 69%}, {1.5, 150, 13%}, {2.0, 150, 31%}, {2.0, 200, 6%}}; Plot[50 x, {x, 0, 2}, Epilog -> {AbsolutePointSize[5], Point[Take[#, 2] & /@ data], Text[#[[3]], #[[{1, 2}]], {-1.5, -.5}] & /@ data}, PlotRange -> {{0, 2.15}, {0, 210}}, AxesLabel -> {Time, Damage}, AspectRatio -> 1] Bob Hanlon > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png > > I put the text next to the points in as a post-processing step by hand in > PhotoShop. > > Is there a way to get mathematica to display such information? > > > === Subject: Re: Replace non-numeric values in a list Hi Adel, a really straightforward method would be (assuming your list explicitly contains letters and numbers only as in your example) In[1]= list = {a, 1, 2, b, 3}; In[2]= isletter[a_] := If[LetterQ[ToString[a]], True, False] In[3]= newlist = Table[If[isletter[list[[i]]], 0, list[[i]]], {i, Length[list]}] Out[4]= {0, 1, 2, 0, 3} HTH, Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) MacOS X V 10.5.2 I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? -- > Adel Elsabbagh > http://www.svlab-asu.com/aelsabbagh.html === Subject: Re: Replace non-numeric values in a list list = {a, 1, 2, b, 3}; If[NumericQ[#], #, 0] & /@ list {0,1,2,0,3} list (Boole[NumericQ[#]] & /@ list) {0,1,2,0,3} Replace[list, _?(Not[NumericQ[#]] &) -> 0, 1] {0,1,2,0,3} Bob Hanlon > > I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? > > -- > Adel Elsabbagh > http://www.svlab-asu.com/aelsabbagh.html > > === Subject: Re: Expression manipulation David, As a very satisfied user of your Presentations package may I suggest a possible interface addition to a future release. It would be nice to have your additional manipulations (discussed below by you) in a new palette PresentationsAlgebraicManipulation. This would supplement the standard release palette AlgebraicManipulation and enable use of one very interactive style of expression manipulation. As I write this it strikes me that this might not be a very easy thing to do and I would appreciate your response. This thought was prompted by John Fulz's contribution to this thread. === Subject: Expression manipulation Best wishes, Syd Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) MacOS X V 10.5.2 > David, You should be able to do all the manipulations using Mathematica. > You should > learn how to use rule based programming, commands such as MapAt, > Apart, > Together, Cancel. HoldForm and of course Simplify. Still, Mathematica is often very theoretically oriented and lacks > some of > the practical operations often used. The Presentations package, at > my web > site below, has a 'Manipulations' section that contains some practical > additions. Sometimes these are useful in manipulating expressions and > sometimes useful to get expressions in particular standard forms for > display > in reports or to match a textbook expression. If you want to keep a particular subexpression together as a unit > you can > wrap it in a HoldForm. This prevents routines like Simplify from > splitting > it up. Presentations has a CreateSubexpression and a > ReleaseSubexpressions > routines that allow you to wrap a subexpression in a tagged Tooltip. > This > works just as well as a HoldForm and allows you to see what the > subexpressions are. FactorOut can be used to remove a factor from an expression - even > if the > factor is not initially in the expression. For example, you can > pull a > factor out of a matrix and wrap the matrix in a HoldForm all in one > operation. MultiplyByOne will multiply the numerator and denominator of an > expression > by the same factor and Simplify, or perform any other specified > operations MapLevelParts and MapLevelPatterns will map an operation onto a > subset of > level parts in an expression. The most common use is to apply some > function > to a selected subset of terms in a sum. LinearBreakout[f1,f2,...][v1,v2,..][expr] will break out the linear > terms of > any expressions within expr that have heads matching the patterns fi > over > variables matching the patterns vj. PushOnto is a much improved version of the Through command that will > push a > list of arguments onto specific functions. HoldOp[operation][expr] will prevent an explicit operation in expr > from > being evaluated but will evaluate the arguments of the operation. It > is > useful when operation has a number of definitions with it, but you > want to > see what the expression looks like before these definitions are > applied. EvaluateAtPattern will evaluate specific patterns in held expressions. Here is an example of using some of these routines to manipulate an > expression as you might do it 'by hand': a + b + c > % // MapLevelParts[CreateSubexpression, {{1, 3}}] > d % // Expand > % // FactorOut[sub] > % // ReleaseSubexpressions[] a + b + c b + (a + c) where (a+c) has a tag and Tooltip 'held'. b d+d (a + c) where d did not Distribute across the > subexpression. (d+(b d)/(a+c)) (a+c) factoring out the subexpression (a+c), even > though it > is not a true 'factor'. (a+c) (d+(b d)/(a+c)) releasing the subexpression keeps the overall > structure. Finally, I might mention the annoying tendency of Mathematica to get > more > minus signs into standard expressions than you might wish. One way to > correct this is just to Map Minus onto two factors in a product. For > example: 3 - a (c - b) > MapAt[Minus, %, {{2, 1}, {2, 3}}] > 3 - a (-b + c) > 3 + a (b - c) -- > David Park > djmpark@comcast.net > http://home.comcast.net/~djmpark/ >> When trying to simplify an expression by hand, one carries out >> various >> kinds of steps: >> 1. Replace a subexpression that occurs repeatedly by a single symbol. >> 2. Multiply numerator and denominator of some subexpression by the >> same factor. >> 3. Cancel particular factors in numerator and denominator of some >> subexpression. >> 4. Gather together two subexpressions that were added together, and >> rewrite with a common denominator. >> 5. Remove common factors. >> etc. etc. etc. >> Using Part, one can of course access any particular subexpression. >> But >> this is time-consuming and clumsy. I find that I need trial and error >> to access the correct subexpression. Once I've accessed it, I often >> have difficulty in persuading Mathematica to perform the desired >> operation. And then I have trouble putting the subexpression back >> into >> place. It's something like 20 times slower than working with pencil >> and paper. HOWEVER pencil and paper calculations are more prone to >> stupid arithmetic errors, particularly if the computation is a long >> one. >> I have been unable to find a convenient way of doing this in >> Mathematica. I use version 5.2, but because of my University's site >> license, I have access to more recent versions. Would it help to >> change? >> Can anyone point me to a tutorial where experts use Mathematica to do >> a typical pencil and paper computation? >> don't look at the newsgroup very often. >> David === Subject: Re: Expression manipulation > I'm no expert at this, but I've seen other experts within Wolfram using the > AlgebraicManipulation palette to do simplifications on pieces of a large > expression similar to the ones you describe. Basically, they select a piece by > hand, apply the appropriate button from the palette, possibly re-evaluate to > combine like terms and/or save the current state of the expression, and iterate > again with the palette until they're satisfied. > > To aid in this, you may find structured selection in the user interface useful. > The user interface is aware of the structure of expressions and responds to > multi-clicking by selecting successively larger structurally complete elements > (important since the buttons in the palette would fail on structurally > incomplete elements). For example, double-clicking on an open or close > parenthesis will select the entire parenthesized contents. Double-click-drag > from there will then allow you to drag-select neighboring terms in their > entirety. Triple-click, quadruple-click, quintuple-click, and so on from any > given point will select successively larger structural elements. It's difficult > to explain in words, but easy to understand once you've observed it in action, > so feel free to experiment. > > The AlgebraicManipulation palette is available in both 5.2 and 6.0. > > Back at version 4.0, I devised a package that did some algebraic manipulation using colour. The idea was that working on selections has two drawbacks - you can only select one piece of an expression at a time, and there is no audit trail of what happened in the notebook. Since, more often than not (at least with me) there is a need to backtrack, the lack of an audit trail can be very frustrating. Selected sub-expressions were coloured red with a palette item that wrapped Red[] (you could use a range of colours) around the expression and MakeBoxes/ MakeExpression rules converted this to a coloured expression (one of the problems that arose at 5.0 was that names like Red got used as names of colours - I should have read the cautions on using names reserved for WRI!). The package came with a lot of functions that picked out coloured expressions and did various things to them. It also came with a set of inert operations - such as an inert form of integration - that could be manipulated passively, but displayed normally. The idea was that perhaps you wanted to study making certain substitutions in integrals (say), and it really wasn't helpful if Mathematica just jumped in and returned a result regardless. Anyway, although I gave a talk about the package and it was downloaded by various people, there was not that much interest in the idea, and I never got round to updating the package. I also think in retrospect, there were probably better ways to do certain things. My main point is that I really feel that this is a big hole in Mathematica - that you can't easily use it to help out with developing derivations/proofs - except perhaps to check transformations that you have generated by hand. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Multiple clipboards Hi Paul, The method I use is to have another notebook open and use it as a clipboard. This window can be minimised to save screen space and persists as long as the current Mathematica session lasts. It can also be saved if you wish with a filename referencing the primary notebook in order to finish work later. There is an added benefit that the Clipboard can be used to evaluate expressions and test options without messing up the primary notebook. HTH Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) MacOS X V 10.5.2 > It can be very useful to save multiple items to a clipboard so that > any > one of them can be chosen and pasted in later. I am using an Intel Mac > with OS 10.5.2. The two utilities I have that ordinarily do this are: > iClipboard and CopyPaste. Neither of these works with my Mathematica > 6.0.1. I can only paste the most recent item I have copied in > Mathematica. Is there a utility or method that would permit multiple > clipboard items. Paul > === Subject: Re: Multiple clipboards > It can be very useful to save multiple items to a clipboard so that any > one of them can be chosen and pasted in later. I am using an Intel Mac > with OS 10.5.2. The two utilities I have that ordinarily do this are: > iClipboard and CopyPaste. Neither of these works with my Mathematica > 6.0.1. I can only paste the most recent item I have copied in > Mathematica. Is there a utility or method that would permit multiple > clipboard items. > > Paul > The Clipboard can be accessed in Mathematica as if it were a notebook. For example: NotebookGet[ClipboadNotebook[]] I guess it would be possible to use this to build a system that would juggle several clipboards, moving the 'right' one into the ClipboardNotebook. If you made the relevant operations work off the menu system, the result could be quite neat. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Multiple clipboards > It can be very useful to save multiple items to a clipboard so that any > one of them can be chosen and pasted in later. I am using an Intel Mac > with OS 10.5.2. The two utilities I have that ordinarily do this are: > iClipboard and CopyPaste. Neither of these works with my Mathematica > 6.0.1. I can only paste the most recent item I have copied in > Mathematica. Is there a utility or method that would permit multiple > clipboard items. I don't know how either of these utilities works, but if they change the data on the clipboard while Mathematica is in the foreground (something which is strongly discouraged by Apple), Mathematica will not notice the change until the next time it is activated. So you might be able to work around this problem by clicking on any other application to activate it then clicking back on Mathematica (or command-tab). -Rob === Subject: Re: Multiple clipboards Why not just open a scrap notebook, and copy to and from this? Then you have excellent control over the whole process. Even editing the clips is possible. I do not really see that it would be easier to use these special utilities you are mentioning. You could in principle build your own utility inside Mathematica by reading from and writing to ClipBoardNotebook[] from some kind of palette, but I do not see what you will gain, except possibly a more idiosyncratic interface. Windows XP. That seems to work together with Mathematica, if you can stand having the clips also pasted into a Word scrap document... Ingolf Dahl -----Original Message----- === Subject: Multiple clipboards It can be very useful to save multiple items to a clipboard so that any one of them can be chosen and pasted in later. I am using an Intel Mac with OS 10.5.2. The two utilities I have that ordinarily do this are: iClipboard and CopyPaste. Neither of these works with my Mathematica 6.0.1. I can only paste the most recent item I have copied in Mathematica. Is there a utility or method that would permit multiple clipboard items. Paul === Subject: Re: HoldForm, TraditionalForm Bug? If one is using the Mathematica for exclusively for typesetting, there is absolutely no need to evaluate anything. In which case what, on earth, is the relevance of this supposed perfect example? Perfect example of what? It may be argued that the desire to obtain fully traditional output when using Mathematica for computation (evaluation) is a rather ambitious one, perhaps excessively so. But, I am sure very few choose Output Form as the default output format. Nevertheless, if that is what you wish you can do so! What stops you? In fact you can even set up the FrontEnd to return all output in InputForm, if that is what you really like. What's wrong with other people being able to make other choices? Does it not strike you as rather arrogant to argue that to satisfy your own personal preferences (or perhaps ignorance) Wolfram should reduce the choices available to other users? For in Mathematica, unlike in most other programs, you do not need to use any of the Front End features you do not like, in fact, you do not need to use the Front End at all. That's something you seem to be completely unable to grasp. I cannot find almost any merit in all your posts on this subject except or one argument that curiously you never choose to make (I wonder why?). The argument is, of course, that people who do not need and do not like any of the new Front End features but do wish to have some of the new features of the Kernel, should not have to pay for the development of the former. This could be easily dealt by making the Mathematica Kernel available separately (at a lower price) and giving users a choice of front ends, including a very cheap (or better free) one, much like that in version 2. (An just by the way, by the way, the solution to the original problem, already posted by several persons: PolynomialForm[HoldForm[x y - x^3 - 1], TraditionalOrder -> False] does not seem dreadfully complicated to me.) I have not been able to Andrzej Kozlowski > Here is a polynomial. Mathematica rearranges the order of the terms. >> x y - x^3 - 1 >> -1 - x^3 + x y >> I would like to display the polynomial without rearranging the >> order. So I >> use a HoldForm. Sorry, but given previous posts by both of us, have to say that it > seems > to me you've just provided a perfect example of why even attempting to > devise a software system or syntax in which users are supposed to be > able to use the same input both for evaluating (computing, > calculating) > a mathematical expression, and also for displaying (typesetting) the > expression in a desired fashion, is an inherently bad idea. And the first several initial responses to your post have simply > reinforced the claim that it's an inherently bad idea. And the particular difficulty that's exemplified by this example is > only > one of multiple reasons why it's a bad idea. Bottom line, at least IMHO: Attempting to create a software app > that is > simultaneously a top of the line numerical and symbolic computational > app, and also a top of the line typesetting and publication app, is an > inherently impossible goal, and attempting it ultimately acts to the > detriment of both these functions. > === Subject: Re: HoldForm, TraditionalForm Bug? I'm probably jumping into this thread a bit late, but isn't this the sort of thing that Interpretation was designed to handle? The following generates an object which displays in the form you want but which is interpreted as the standard symbolic expression. Interpretation[ Style[HoldForm[x y - x^3 - 1], SingleLetterItalics -> True, FontFamily -> Times], x y - x^3 - 1] Jason > Here is a polynomial. Mathematica rearranges the order of the terms. >> x y - x^3 - 1 >> -1 - x^3 + x y >> I would like to display the polynomial without rearranging the >> order. So I >> use a HoldForm. Sorry, but given previous posts by both of us, have to say that it > seems > to me you've just provided a perfect example of why even attempting to > devise a software system or syntax in which users are supposed to be > able to use the same input both for evaluating (computing, > calculating) > a mathematical expression, and also for displaying (typesetting) the > expression in a desired fashion, is an inherently bad idea. And the first several initial responses to your post have simply > reinforced the claim that it's an inherently bad idea. And the particular difficulty that's exemplified by this example is > only > one of multiple reasons why it's a bad idea. Bottom line, at least IMHO: Attempting to create a software app > that is > simultaneously a top of the line numerical and symbolic computational > app, and also a top of the line typesetting and publication app, is an > inherently impossible goal, and attempting it ultimately acts to the > detriment of both these functions. > -- Dr J. McKenzie Alexander Department of Philosophy, Logic and Scientific Method London School of Economics and Political Science Houghton Street, London WC2A 2AE Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm === Subject: Re: Replace non-numeric values in a list >I have a list that contains numeric and non-numeric values list = { >a, 1, 2, b, 3}; How can I replace non-numeric values with zeros? Here is one way to do what you want In[12]:= list /. Thread[DeleteCases[list, _?NumericQ] -> 0] Out[12]= {0,1,2,0} === Subject: Re: RenderBadPicture error while running Mathematica 6 on Linux Hi dear group, I get hundreds of these messages since I upgraded to Fedora Linux 9 (for x86_64 - architecture). Additionally the fonts are only partally shown in the Frontend (FontPaths are set in xorg.conf and xset q confirms they are recognized). Mathematica 6 worked well with Fedora 8. The same messages and symptoms ('special' characters like brackets and '+' display but letters and digits do not) on Ubuntu 8.04 x86_64. Mathematica 5 works fine in both cases. openSuse 10.3 + Mathematica 6 works perfectly, but I did a fresh install on a small partition and do not want to migrate from Fedora to openSuse (but maybe I will do. Fedora 9 came without 3D-support (at least for my ATI-Radeon based card); unbelievable these days, isn't it?). I really can not figure out, why this happens and any idea is welcome. TIA, Peter > Hi all, > > I am getting an error while running Mathematica 6 on my Linux machine. > The details of the error is as follows. Please help me out if you know > the solution. > > X Error of failed request: RenderBadPicture (invalid Picture > parameter) > Major opcode of failed request: 154 (RENDER) > Minor opcode of failed request: 7 (RenderFreePicture) > Picture id in failed request: 0x2a09632 > Serial number of failed request: 382906 > Current serial number in output stream: 382909 > > X Error of failed request: BadMatch (invalid parameter attributes) > Major opcode of failed request: 154 (RENDER) > Minor opcode of failed request: 4 (RenderCreatePicture) > Serial number of failed request: 383763 > Current serial number in output stream: 383766 > > > > Kishan. > === Subject: Re: export mathematica table to .mat (MATLAB) format.Please help!!! What does $ExportFormats return? Is MAT contained in the list returned? I have no problems exporting a matrix to a MAT file. I'm running In[6]:= $Version Out[6]= 6.0 for Linux x86 (32-bit) (April 20, 2007) The following export formats are supported: In[1]:= $ExportFormats Out[1]= {3DS, ACO, AIFF, AU, AVI, Base64, Binary, Bit, BMP, Byte, BYU, BZIP2, CDF, Character16, Character8, Complex128, Complex256, Complex64, CSV, DICOM, DIF, DXF, EPS, ExpressionML, FASTA, FITS, FLAC, FLV, GIF, Graph6, GZIP, HarwellBoeing, HDF, HDF5, HTML, Integer128, Integer16, Integer24, Integer32, Integer64, Integer8, JPEG, JPEG2000, JVX, List, LWO, MAT, MathML, Maya, MGF, MIDI, MOL, MTX, MX, NB, NOFF, OBJ, OFF, Package, PBM, PCX, PDF, PGM, PLY, PNG, PNM, POV, PPM, PXR, RawBitmap, Real128, Real32, Real64, RIB, RTF, SCT, SND, Sparse6, STL, String, SVG, SWF, Table, TAR, TerminatedString, TeX, Text, TGA, TIFF, TSV, UnsignedInteger128, UnsignedInteger16, UnsignedInteger24, UnsignedInteger32, UnsignedInteger64, UnsignedInteger8, UUE, VRML, WAV, Wave64, WDX, X3D, XBM, XHTML, XHTMLMathML, XLS, XML, XYZ, ZIP, ZPR} I do not know if this list is machine dependent, though. Sigmund Vestergaard I am aware of this. I simply changed it to make the text more readable. Th= is is because I copy pasted the values directly from the table in this box. The first few entries is simply an example of the Table as I see it. I hav= e also used the command MatrixForm[%]. Now when I try to export this it fails. HELP PLEASE!!!!!!!! So a different sample of what I see follows: { > {{0.272409}}, > {{0.132711+ 0.231672 [ImaginaryI], > 0.221351, -0.130221 + 0.226132 [ImaginaryI]}}} I then use MatrixForm[%] > I then use Export[file.mat, Out[6]] and it fails.WHY??? > Alex === Subject: Re: export mathematica table to .mat (MATLAB) format.Please help!!! Hello Alex, I don't know anything about the file structure for MTLB, but your data is not a rectangular matrix. This works how I would expect it to work: mydata = {{{0.272409}}, {{0.132711 + 0.231672 [ImaginaryI], 0.221351, -0.130221 + 0.226132 [ImaginaryI]}}} Export[mydata1.dat, TableForm[ mydata]] Export[mydata2.dat, mydata,CSV] Export[mydata.mat, mydata] (*fails, mat is not a known format*) Export[mydata.mat, mydata, TABLE] (*works*) WCC { > {{0.272409}}, > {{0.132711+ 0.231672 [ImaginaryI], > 0.221351, -0.130221 + 0.226132 [ImaginaryI]}} > } > I then use MatrixForm[%] > I then use Export[file.mat, Out[6]] and it fails.WHY??? > Alex -- W. Craig Carter === Subject: Re: export mathematica table to .mat (MATLAB) format.Please help!!! > > I am aware of this. I simply changed it to make the text more readable. This is because I copy pasted the values directly from the table in this box. > > The first few entries is simply an example of the Table as I see it. I have also used the command MatrixForm[%]. > > Now when I try to export this it fails. HELP PLEASE!!!!!!!! > > So a different sample of what I see follows: > > { > {{0.272409}}, > {{0.132711+ 0.231672 [ImaginaryI], > 0.221351, -0.130221 + 0.226132 [ImaginaryI]}} > } > I then use MatrixForm[%] > I then use Export[file.mat, Out[6]] and it fails.WHY??? Unfortunatly the documentation of many export formats is, well rudimentary. This is from the documentation: Export[file.mat,expr] exports any numeric array to a MAT-file. I think this tries to tell you that only full arrays (of dimension 1 or 2?) can be exported this way. So you need to massage your data to export: You can pad the data (look at PadRight) and make it a matrix: Export[ ToFileName[{$HomeDirectory, Desktop}, tst.mat], {{ {0.272409, 0, 0}, {0.132711 + 0.231672 [ImaginaryI], 0.221351, -0.130221 + 0.226132 [ImaginaryI]} }} ] Another possibility is to export more than one matrix to one file, but then you need to use names for the variables: Export[ ToFileName[{$HomeDirectory, Desktop}, tst.mat], { var1 -> {{0.272409}}, var2 -> {{0.132711 + 0.231672 [ImaginaryI], 0.221351, -0.130221 + 0.226132 [ImaginaryI]}} }, Rules ] (I have not checked the result, just took care that Export will succeed...) hth, albert === Subject: Re: export mathematica table to .mat (MATLAB) format.Please help!!! > > I am aware of this. I simply changed it to make the text more readable. This is because I copy pasted the values directly from the table in this box. > > The first few entries is simply an example of the Table as I see it. I have also used the command MatrixForm[%]. > > Now when I try to export this it fails. HELP PLEASE!!!!!!!! You did not describe very precisely what you did ... so I had to guess. A precisely formulated question is more likely to receive an answer than one in which you type in all caps ... > > So a different sample of what I see follows: > > { > {{0.272409}}, > {{0.132711+ 0.231672 [ImaginaryI], > 0.221351, -0.130221 + 0.226132 [ImaginaryI]}} > } This is not a matrix at all. A matrix should be a two-level list, with every sublist having the same length. This is a three-level list, with sublists of different lengths. While I am not very familiar with the MAT format, I believe that the problem is that it can only store matrices, but not ragged arrays. > I then use MatrixForm[%] MatrixForm is only for pretty printing. Do not use it before export. > I then use Export[file.mat, Out[6]] and it fails.WHY??? If you refer to Out[6] then you should say exactly what Out[6] is. > > > Alex > === Subject: Re: export mathematica table to .mat (MATLAB) format.Please help!!! > I am integrating a function many times. Every time the integral is evaluated > I store its output value in a Table. I want to export all the table values > to .mat format. So my code looks like this: Table[NIntegrate[ > Function[[Theta], [Phi]] > SphericalHarmonicY[n, m, [Theta], [Phi]], {[Theta], > 0, [Pi]}, {[Phi], 0, 2 [Pi]}], {n, 0, 20}, {m, -n, n}] > MatrixForm[%] This command does not have a correct syntax and cannot be evaluated without errors, so I'm not sure what your data looks like exactly. But it seems that we are working with 2-level lists, so we just need to pad it. As you can understand from my code for each value of n,m I want to evaluate > this integral and store the output. A few months ago I was advised to use > the Table function in order to do this. However, now that I want to export > this table I get problems. Do you have any suggestions? You are right that my matrix is not quite a matrix as we know it. However, > perhaps there is a way to fill in the empty entries with zeros. I don't know > how to do it. > If we have a ragged array, such as data = Table[i + j, {i, 1, 5}, {j, 1, 2 i}] , we can pad it with zeros using PadRight: PadRight[data, {Length[data], Max[Length /@ data]}] This will give return a matrix that can be exported to .mat format. === Subject: Re: export mathematica table to .mat (MATLAB) format.Please help!!! What is Out[6]? Is this the MatrixForm expression? If so then you are trying to export a formatted expression rathe than the matrix. --David I am aware of this. I simply changed it to make the text more readable. Th= is is because I copy pasted the values directly from the table in this box. The first few entries is simply an example of the Table as I see it. I hav= e also used the command MatrixForm[%]. Now when I try to export this it fails. HELP PLEASE!!!!!!!! So a different sample of what I see follows: { > {{0.272409}}, > {{0.132711+ 0.231672 [ImaginaryI], > 0.221351, -0.130221 + 0.226132 [ImaginaryI]}}} I then use MatrixForm[%] > I then use Export[file.mat, Out[6]] and it fails.WHY??? > Alex === Subject: Re: Applying the Integration Function to a List Of Regions > Assume that I have already determined a list of 4 dimensional regions as > follows: > > regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; > > I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: > > {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} > > How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: > > Integrate @@ regions > > or > > Integrate @@@ regions > > But I can't figure out how to incorporate the 1 as the integrand when I try > to set this up automatically. > > There must be a way? Yes, this can be easily done with inline functions (look up Function): Integrate[1, ##] & @@@ regions ## stands for all the arguments that the function receives. You may want to consider giving Mathematica some information about the variables, e.g. if all of them are reals then use Assuming[(a|x|y|cx|cy) [Element] Reals, Integrate[1, ##] & @@@ regions] === Subject: Re: Applying the Integration Function to a List Of Regions > Assume that I have already determined a list of 4 dimensional regions as > follows: regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: Integrate @@ regions or Integrate @@@ regions But I can't figure out how to incorporate the 1 as the integrand when I try > to set this up automatically. There must be a way? > John Hello You could use Map integrate[1, Sequence @@ #1] & /@ regions Note that I used integrate instead of Integrate to see that the integration limits are set correctly. To perform the calculation you have to use Integrate of course. Norbert Marxer === Subject: Re: Applying the Integration Function to a List Of Regions Hi John, you may try: myIntegrate[1,Sequence@@#]&/@regions I used myIntegrate that you can see what is going on. If you replace thsi by Integrate, Mathematica tries to evaluate the integrals. hope this helps, Daniel > Assume that I have already determined a list of 4 dimensional regions as > follows: > > regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; > > I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: > > {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} > > How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: > > Integrate @@ regions > > or > > Integrate @@@ regions > > But I can't figure out how to incorporate the 1 as the integrand when I try > to set this up automatically. > > There must be a way? > > > John > > === Subject: Re: Applying the Integration Function to a List Of Regions Formally, this seems to be what you want: integrate[1,##]&@@@regions {integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}],integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx a},{cx,-a+x,2 a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx Using capital Integrate integrate works the same way, although it causes the machine to think a VERY long time. Integrate[1, ##] & @@@ regions {(13 a^4)/8, -(1/3) a ((a^2)^(3/2) (4 - 3 [Pi]) + a^3 (13 + 3 [Pi])), (13 a^4)/8, ( 13 a^4)/8, 1/3 a^3 (-4 Sqrt[a^2] + a (-13 + 6 [Pi])), (13 a^4)/8} Bobby > Assume that I have already determined a list of 4 dimensional regions as > follows: > regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; > I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: > {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 > a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} > How can I do that without having to set up each of the integrals > manually? > I am looking for some way to do something like: > Integrate @@ regions > or > Integrate @@@ regions > But I can't figure out how to incorporate the 1 as the integrand when I > try > to set this up automatically. > There must be a way? > John > -- DrMajorBob@longhorns.com === Subject: Re: Applying the Integration Function to a List Of Regions Hello John, Here is a way to do this, but I am going to guess that you will get more elegant responses: In steps, instead of in-lining: temp = Map[Apply[f, #] &, regions]; temp /. f[a__] :> Integrate[1, a] (*this takes a while on my machine*) (* returns {(13 a^4)/8, -(1/3) a ((a^2)^(3/2) (4 - 3 [Pi]) + a^3 (13 + 3 [Pi])), (13 a^4)/8, ( 13 a^4)/8, 1/3 a^3 (-4 Sqrt[a^2] + a (-13 + 6 [Pi])), (13 a^4)/8} *) Craig > Assume that I have already determined a list of 4 dimensional regions as > follows: regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx : : 2 a}}}; I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx : : How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: There must be a way? > John > -- W. Craig Carter === Subject: Re: Applying the Integration Function to a List Of Regions > Assume that I have already determined a list of 4 dimensional regions as > follows: > > regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > > I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: > > {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: > > Integrate @@ regions > > or > > Integrate @@@ regions or: Integrate[1, ##] & @@@ regions If you wonder about the ## and & look up Function in the documentation center. hth, albert === Subject: Re: Applying the Integration Function to a List Of Regions > Assume that I have already determined a list of 4 dimensional > regions as > follows: regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; I want to integrate over each of these regions using an integrand > of 1. I > want my output to be as follows: {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x- > x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a > +x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 a}, > {cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2 > +2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} How can I do that without having to set up each of the integrals > manually? > I am looking for some way to do something like: Integrate @@ regions or Integrate @@@ regions But I can't figure out how to incorporate the 1 as the integrand > when I try > to set this up automatically. There must be a way? > John > Me as a newbie, I would try a variant of this to start with: In[2]:= (Integrate[Sequence[1], #1] & ) /@ regions But to tell the truth if I see an Integrate I duck for cover. J=E1nos ------ ..because Annushka has already bought sunflower oil, and not only bought it, but spilled it too. Bulgakov: Master and Margarita === Subject: Re: Applying the Integration Function to a List Of Regions regions = {{{x, 0, a}, {cx, 0, a + x}, {y, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2]}, {cy, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, 0, a}, {cx, 0, a + x}, {y, Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a - Sqrt[ a^2 - cx^2 + 2 cx x - x^2]}, {cy, -Sqrt[ a^2 - cx^2 + 2 cx x - x^2] + y, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, 0, a}, {cx, 0, a + x}, {y, 2 a - Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a}, {cy, -Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y, 2 a}}, {{x, a, 2 a}, {cx, -a + x, 2 a}, {y, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2]}, {cy, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, a, 2 a}, {cx, -a + x, 2 a}, {y, Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a - Sqrt[ a^2 - cx^2 + 2 cx x - x^2]}, {cy, -Sqrt[ a^2 - cx^2 + 2 cx x - x^2] + y, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, a, 2 a}, {cx, -a + x, 2 a}, {y, 2 a - Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a}, {cy, -Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y, 2 a}}} Integrate[1, ##] & @@@ regions -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Assume that I have already determined a list of 4 dimensional regions as > follows: regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 > a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: Integrate @@ regions or Integrate @@@ regions But I can't figure out how to incorporate the 1 as the integrand when I > try > to set this up automatically. There must be a way? > John === Subject: Re: Applying the Integration Function to a List Of Regions regions = {{{x, 0, a}, {cx, 0, a + x}, {y, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2]}, {cy, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, 0, a}, {cx, 0, a + x}, {y, Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a - Sqrt[ a^2 - cx^2 + 2 cx x - x^2]}, {cy, -Sqrt[ a^2 - cx^2 + 2 cx x - x^2] + y, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, 0, a}, {cx, 0, a + x}, {y, 2 a - Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a}, {cy, -Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y, 2 a}}, {{x, a, 2 a}, {cx, -a + x, 2 a}, {y, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2]}, {cy, 0, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, a, 2 a}, {cx, -a + x, 2 a}, {y, Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a - Sqrt[ a^2 - cx^2 + 2 cx x - x^2]}, {cy, -Sqrt[ a^2 - cx^2 + 2 cx x - x^2] + y, Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y}}, {{x, a, 2 a}, {cx, -a + x, 2 a}, {y, 2 a - Sqrt[a^2 - cx^2 + 2 cx x - x^2], 2 a}, {cy, -Sqrt[a^2 - cx^2 + 2 cx x - x^2] + y, 2 a}}} Integrate[1, ##] & @@@ regions -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Assume that I have already determined a list of 4 dimensional regions as > follows: regions={{{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}},{{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}},{{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx x-x^2],2 > a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}}}; I want to integrate over each of these regions using an integrand of 1. I > want my output to be as follows: {Integrate[1,{x,0,a},{cx,0,a+x},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 > a-Sqrt[a^2-cx^2+2 cx x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx > x-x^2]+y,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,0,a},{cx,0,a+x},{y,2 > a-Sqrt[a^2-cx^2+2 cx x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 > a}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,0,Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,0,Sqrt[a^2-cx^2+2 cx x-x^2]+y}],Integrate[1,{x,a,2 > a},{cx,-a+x,2 > a},{y,Sqrt[a^2-cx^2+2 cx x-x^2],2 a-Sqrt[a^2-cx^2+2 cx > x-x^2]},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,Sqrt[a^2-cx^2+2 cx > x-x^2]+y}],Integrate[1,{x,a,2 a},{cx,-a+x,2 a},{y,2 a-Sqrt[a^2-cx^2+2 cx > x-x^2],2 a},{cy,-Sqrt[a^2-cx^2+2 cx x-x^2]+y,2 a}]} How can I do that without having to set up each of the integrals manually? > I am looking for some way to do something like: Integrate @@ regions or Integrate @@@ regions But I can't figure out how to incorporate the 1 as the integrand when I > try > to set this up automatically. There must be a way? > John === Subject: Re: DSolve question Below is the code that works. Clearly Mathematica recognizes output in curly braces { } differently than that without. In[1]:= Duty = .6; SWfreq = 1*10^6; Vin = 3.2; Vout = 1.8; L = 4.7*10^-7; R = 0.008; In[2]:= Dt1 = Duty (1/SWfreq); Dt2 = (1 - Duty) (1/SWfreq); VL2 = - Vout; VL1 = Vin - Vout; T = 1/SWfreq; In[3]:= it1 = Simplify[DSolve[{L i1'[t] + R i1[t] - VL1 == 0, i1[0] == a1}, i1[t], t]] Out[3]= {{i1[t] -> 175.+ (-175. + 1. a1) E^(-17021.3 t)}} In[4]:= it2 = Simplify[DSolve[{L i2'[t] + R i2[t] - VL2 == 0, i2[0] == a2}, i2[t], t]] Out[4]= {{i2[t] -> -225. + (225.+ 1. a2) E^(-17021.3 t)}} In[5]:= i1[t_] = 175.00000000000003`+ (-175.00000000000003` + 1.` a1) E^(-17021.276595744683` t) Out[5]= 175.+ (-175. + 1. a1) E^(-17021.3 t) In[6]:= i2[t_] = -225.` + (225.`+ 1.` a2) E^(-17021.276595744683` t) Out[6]= -225. + (225.+ 1. a2) E^(-17021.3 t) In[7]:= FindRoot[{i1[0] == i2[T], i1[Dt1] == i2[Dt1]}, {a1, 0}, {a2, 0}] Out[7]= {a1 -> 14.1825, a2 -> 18.2886} === Subject: Re: Labeling points Labeled list plot was available in Mathematica 5. For some reason, it's not available anymore in version 6, but you can use it by downloading the package from the previous version from http://library.wolfram.com/infocenter/MathSource/6808/ Then, after reading the package in by << or Get, try LabeledListPlot[ {{0.5, 50, 50%}, {1, 100, 25%}, {1.5, 100, 50%}}, PlotRange -> {{0, 1.7}, {20, 110}}] Antti > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png > > I put the text next to the points in as a post-processing step by hand in > PhotoShop. > > Is there a way to get mathematica to display such information? > > > === Subject: Re: Labeling points One way to annotate graphics like this is to use the Epilog option, which allows you to specify arbitrary graphic constructs for inclusion in the graphic. To keep the Epilog option from becoming unreadable (and to give you the change to tweak the appearance of the point/label pairs), here's a simple function that generates the annotations: f[lab_, pt_] := {Point[pt], Text[Style[lab, 14], pt, {-1.5, 0}]} Your plot is then constructed as follows: Plot[50 x, {x, 0, 2}, PlotRange -> {{0, 2.25}, {0, 200}}, PlotStyle -> Blue, AspectRatio -> 1, AxesLabel -> {Time, Damage}, PlotRangeClipping -> False, Epilog -> { AbsolutePointSize[6], Point[{0, 0}], Point[{0.5, 0}], Point[{1.5, 0}], Point[{2.0, 0}], f[50%, {0.5, 50}], f[75%, {1, 50}], f[88%, {1.5, 50}], f[94%, {2, 50}], f[25%, {1, 100}], f[50%, {1.5, 100}], f[69%, {2, 100}], f[13%, {1.5, 150}], f[31%, {2, 150}], f[6%, {2, 200}] } ] Jason > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png I put the text next to the points in as a post-processing step by > hand in > PhotoShop. Is there a way to get mathematica to display such information? > -- Dr J. McKenzie Alexander Department of Philosophy, Logic and Scientific Method London School of Economics and Political Science Houghton Street, London WC2A 2AE Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm === Subject: Re: Labeling points > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png I put the text next to the points in as a post-processing step by > hand in > PhotoShop. Is there a way to get mathematica to display such information? You can post-process plot output to add the information you want. For example, here is a ListPlot: plot = ListPlot[Table[{x, y}, {x, 1, 4}, {y, 1, x}], AxesOrigin -> {0, 0}] Christopher Carlson User Interface Group Wolfram Research, Inc === Subject: Re: Labeling points Graphics[ {Point[#], Text[ToString[Round[Random[]*100]] <> %, #, {1, -1}]} & /@ data, Frame -> True, PlotRange -> {{0, 1}, {0, 1}}] ?? Jens > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png > > I put the text next to the points in as a post-processing step by hand in > PhotoShop. > > Is there a way to get mathematica to display such information? > > > === Subject: Re: Labeling points pointsandvalues = {{.5, 50, 50}, {1, 50, 75}, {1.5, 50, 88}, {2.0, 50, 94}, {1.0, 100, 25}, {1.5, 100, 50}, {2.0, 100, 69}, {1.5, 150, 13}, {2.0, 150, 31}, {2.0, 200, 6}} Graphics[ {AbsolutePointSize[4], Module[{loc = Part[#, {1, 2}], val = Part[#, 3]}, {Point[loc], Text[Row[{val, Spacer[2], %}], loc, {-1.8, 0}]}] & /@ pointsandvalues}, AspectRatio -> 1, Axes -> True, AxesOrigin -> {0, 0}, AxesLabel -> {Time, Damage}, ImageSize -> 300] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png I put the text next to the points in as a post-processing step by hand in > PhotoShop. Is there a way to get mathematica to display such information? > === Subject: Re: Labeling points > Here's a graphic I created for a discussion on game theory: > http://home.comcast.net/~anglewyrm/thread/dps.png > > I put the text next to the points in as a post-processing step by hand in > PhotoShop. > > Is there a way to get mathematica to display such information? Here are some random points with labels: points = Table[{RandomReal[1, 2], i}, {i, 10}] If the graphic will be sent to people who have Mathematica 6, use Tooltip: Graphics[Tooltip[Point[#1], #2] & @@@ points] Otherwise you could use Text: Graphics[{Point[#1], Text[#2, #1, {-3, 0}]} & @@@ points] === Subject: Re: Asking NonlinearRegression > > I have a problem with nonlinear regression in Mathematica. I want to fit my data (below) to this following equation: > > y = Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])] > > and I would like to find a and b values and also determined r-squared value. > > I try to use NonlinearRegression/NonlinearFit code, but its not working, I hope someone could help me > It is very difficult to guess what went wrong if you don't say what you did. Please describe exactly how you tried to use NonlinearRegression/NonlinearFit, what happened (e.g. what error messages appeared), and what you expected to happen, then re-send the question to MathGroup. I could repeat the examples that are in the documentation, but what use would it be? If you asked the question here then you have already seen those. Also, if you have Mathematica 5 or later, try using FindFit. > > DATA: > x y > 1 0.00 > 2 0.00 > 3 0.00 > 4 0.00 > 5 0.00 > 6 0.00 > 7 0.00 > 8 0.00 > 9 0.00 > 10 0.00 > 11 0.00 > 12 0.00 > 13 0.00 > 14 0.00 > 15 0.00 > 16 0.00 > 17 0.00 > 18 0.00 > 19 0.00 > 20 0.00 > 21 0.00 > 22 0.00 > 23 0.00 > 24 0.00 > 25 0.00 > 26 0.00 > 27 0.00 > 28 0.00 > 29 0.00 > 30 0.00 > 31 0.00 > 32 0.00 > 33 0.00 > 34 0.00 > 35 0.00 > 36 0.00 > 37 0.00 > 38 0.00 > 39 0.00 > 40 0.00 > 42 0.00 > 44 0.00 > 46 0.00 > 48 0.00 > 50 0.00 > 52 0.04 > 54 0.06 > 56 0.08 > 58 0.09 > 60 0.16 > 65 0.24 > 70 0.32 > 75 0.43 > 80 0.49 > 85 0.58 > 90 0.80 > 95 0.91 > 100 1.00 > 105 1 > === Subject: Re: Asking NonlinearRegression Hi Navri, NonlinearRegression as well as FindFit (should be used instead of the older NonlinearFit) seem to work as expected: fun=Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])]; d1={1,0.00,2,0.00,3,0.00,4,0.00,5,0.00,6,0.00,7,0.00,8,0.00,9,0.00,10,0.00,1 1,0.00,12,0.00,13,0.00,14,0.00,15,0.00,16,0.00,17,0.00,18,0.00,19,0.00,20,0.0 0,21,0.00,22,0.00,23,0.00,24,0.00,25,0.00,26,0.00,27,0.00,28,0.00,29,0.00,30, 0.00,31,0.00,32,0.00,33,0.00,34,0.00,35,0.00,36,0.00,37,0.00,38,0.00,39,0.00, 40,0.00,42,0.00,44,0.00,46,0.00,48,0.00,50,0.00,52,0.04,54,0.06,56,0.08,58,0. 09,60,0.16,65,0.24,70,0.32,75,0.43,80,0.49,85,0.58,90,0.80,95,0.91,100,1.00,1 05,1}; FindFit[d1,fun,{a,b},x] NonlinearRegress[d1, fun, {a, b}, x] Could it bee that you had a syntax error? hope this helps, Daniel > > I have a problem with nonlinear regression in Mathematica. I want to fit my data (below) to this following equation: > > y = Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])] > > and I would like to find a and b values and also determined r-squared value. > > I try to use NonlinearRegression/NonlinearFit code, but its not working, I hope someone could help me > > > DATA: > x y > 1 0.00 > 2 0.00 > 3 0.00 > 4 0.00 > 5 0.00 > 6 0.00 > 7 0.00 > 8 0.00 > 9 0.00 > 10 0.00 > 11 0.00 > 12 0.00 > 13 0.00 > 14 0.00 > 15 0.00 > 16 0.00 > 17 0.00 > 18 0.00 > 19 0.00 > 20 0.00 > 21 0.00 > 22 0.00 > 23 0.00 > 24 0.00 > 25 0.00 > 26 0.00 > 27 0.00 > 28 0.00 > 29 0.00 > 30 0.00 > 31 0.00 > 32 0.00 > 33 0.00 > 34 0.00 > 35 0.00 > 36 0.00 > 37 0.00 > 38 0.00 > 39 0.00 > 40 0.00 > 42 0.00 > 44 0.00 > 46 0.00 > 48 0.00 > 50 0.00 > 52 0.04 > 54 0.06 > 56 0.08 > 58 0.09 > 60 0.16 > 65 0.24 > 70 0.32 > 75 0.43 > 80 0.49 > 85 0.58 > 90 0.80 > 95 0.91 > 100 1.00 > 105 1 > > > Rgds, > Navri > > > > > === Subject: Re: Asking NonlinearRegression I have a problem with nonlinear regression in Mathematica. I want to fit my data (below) to this following equation: y = Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])] and I would like to find a and b values and also determined r-squared value. I try to use NonlinearRegression/NonlinearFit code, but its not working, I hope someone could help me > DATA: > x y > 1 0.00 > 2 0.00 > 3 0.00 > 4 0.00 > 5 0.00 > 6 0.00 > 7 0.00 > 8 0.00 > 9 0.00 > 10 0.00 > 11 0.00 > 12 0.00 > 13 0.00 > 14 0.00 > 15 0.00 > 16 0.00 > 17 0.00 > 18 0.00 > 19 0.00 > 20 0.00 > 21 0.00 > 22 0.00 > 23 0.00 > 24 0.00 > 25 0.00 > 26 0.00 > 27 0.00 > 28 0.00 > 29 0.00 > 30 0.00 > 31 0.00 > 32 0.00 > 33 0.00 > 34 0.00 > 35 0.00 > 36 0.00 > 37 0.00 > 38 0.00 > 39 0.00 > 40 0.00 > 42 0.00 > 44 0.00 > 46 0.00 > 48 0.00 > 50 0.00 > 52 0.04 > 54 0.06 > 56 0.08 > 58 0.09 > 60 0.16 > 65 0.24 > 70 0.32 > 75 0.43 > 80 0.49 > 85 0.58 > 90 0.80 > 95 0.91 > 100 1.00 > 105 1 > Rgds, > Navri > When something is not working, it helps to know what not working means (for instance, a function may not be evaluating or there may be something undesirable about the result). A couple of possibilities in this case are that the package wasn't loaded or that non-default starting values are needed for the parameters. Regardless of whether or not part of the problem was package loading, this example will need non-default starting values. By default, 1 is used as the starting value for each parameter if no value is specified and this is not a good starting point for the parameters in this example. Looking at 3D plots as a function of a and b for a couple of the larger x values, it looked like 5 would be reasonable for a and .1 would be reasonable for b and with the sharp nature of the curve it would help to give two starting values so the method didn't take too big of an initial step. Doing so, it worked fine. In[1]:= << NonlinearRegression` In[2]:= data = Import[data.tsv] Out[2]= {{1, 0.}, {2, 0.}, {3, 0.}, {4, 0.}, {5, 0.}, {6, 0.}, {7, 0.}, {8, 0.}, {9, 0.}, > {10, 0.}, {11, 0.}, {12, 0.}, {13, 0.}, {14, 0.}, {15, 0.}, {16, 0.}, {17, 0.}, > {18, 0.}, {19, 0.}, {20, 0.}, {21, 0.}, {22, 0.}, {23, 0.}, {24, 0.}, {25, 0.}, > {26, 0.}, {27, 0.}, {28, 0.}, {29, 0.}, {30, 0.}, {31, 0.}, {32, 0.}, {33, 0.}, > {34, 0.}, {35, 0.}, {36, 0.}, {37, 0.}, {38, 0.}, {39, 0.}, {40, 0.}, {42, 0.}, > {44, 0.}, {46, 0.}, {48, 0.}, {50, 0.}, {52, 0.04}, {54, 0.06}, {56, 0.08}, > {58, 0.09}, {60, 0.16}, {65, 0.24}, {70, 0.32}, {75, 0.43}, {80, 0.49}, {85, 0.58}, > {90, 0.8}, {95, 0.91}, {100, 1.}, {105, 1}} In[3]:= NonlinearRegress[data, Exp[(1 - Exp[a*(1 - Exp[-b*x])])*(Exp[-b*x])/(1 - Exp[-b*x])], {{a, 5, 5.1}, {b, .1, .11}}, x] Out[3]= {BestFitParameters -> {a -> 5.2052, b -> 0.0724853}, > ParameterCITable -> Estimate Asymptotic SE CI , a 5.2052 0.209949 {4.78478, 5.62561} b 0.0724853 0.00290763 {0.0666629, 0.0783077} > EstimatedVariance -> 0.000964242, > ANOVATable -> DF SumOfSq MeanSq , Model 2 4.37984 2.18992 Error 57 0.0549618 0.000964242 Uncorrected Total 59 4.4348 Corrected Total 58 3.78327 > AsymptoticCorrelationMatrix -> 1. 0.985653, 0.985653 1. > FitCurvatureTable -> Curvature} Max Intrinsic 0.105066 Max Parameter-Effects 0.130725 95. % Confidence Region 0.562647 If you are using a version prior to 6.0, instead load Statistics`NonlinearFit` and flip the parameter and variable arguments in NonlinearRegress. Darren Glosemeyer Wolfram Research === Subject: Re: Request for Collective Wisdom... > My humble contribution to the collective wisdom: > Do not forget to tell them about how to trace errors. The simplest way is > often to put print expressions into the code: > > Print[localizing text, var]; > > to check a variable value. If you tell them about pure functions, a variant > of this theme is often useful. The expression > > (Print[text , #]; #) &@ > > can often be inserted inside expressions in appropriate places, without the > need of setting any variable value. It is a good example of the use of pure > functions and of printing as side effect, not disturbing the computational > flow. For instance > > Sin[(Print[mytext , #]; #) &@ Sin[2.]] > > will print > > mytext 0.909297 > > and return > > 0.789072 > > > Ingolf Dahl > ingolf.dahl@telia.com > >> -----Original Message----- === >> Subject: Request for Collective Wisdom... >> (*Below is a request for suggestions for hints for >> beginners. The preface is a bit long-winded *) >> I am working on an applied math for physical scientists >> undergraduate text---I am using Mathematica as the engine to >> learn and solve problems quickly. >> I have an appendix that I have been creating (empirically) >> for a couple years: Common Mathematica Beginners' Errors. >> This wasn't difficult. >> I am now considering how to write another Appendix: >> Mathematica Usage Paradigms for Beginners. This one is not >> as straightforward because it will be a list of short >> sequences of Mathematica code. The size of the list should be >> a compromise between length, completeness, and orthogonality. >> Some topics are obvious to (subjective) me: work symbolically >> and with exact representations; scale to remove units when >> possible; visualize often and when in doubt evaluate as a >> number; pure functions are power; avoid the outdoors unless >> you have applied the documentation, lists are your friends... >> Nota bene, this is a book for undergraduates who have just >> received the physics, chemistry, and multivariable calculus >> catechism, and >> (typically) don't appreciate that there are common themes in >> their education (think back...). >> (* Punchline: *) >> I would sincerely appreciate thoughtful (bullet-type) >> suggestions for paradigms. (off-line or on- as you please). >> PS: Implicit in this is what a dear friend called The >> Homotopy Conjecture. Give me a small working example, and >> it can deformed into a complicated one for my own purposes. >> PPS: I expect a small fraction of snarky answers---I won't respond. >> -- >> W. Craig Carter > > > A variant of the above is to define a function that prints out an expression before and after evaluation separated by '=': SetAttributes[dPrint, HoldFirst]; dPrint[x_] := Module[{ans = x}, StylePrint[SequenceForm[Unevaluated[x], =, ans], Background -> RGBColor[0.6`, 1, 0.6`]]; ans] Using this function, calling dPrint[x] will print something like: x=42 It will also return the original answer (evaluated only once) so that it can be nicely embedded in a bigger calculation. Furthermore, because these debug prints come out with a light green background, they don't get confused with other output from the program. David Bailey http://www.dbaileyconsultancy.co.uk