A103 === Subject: ListDensityPlot / CountryData: Small glitch in the 6.0.2 documentation The documentation for ListDensityPlot contains a very nice example about ozone density around the world. To see it, go to either the documentation center or the WRI.89¥ús website http://reference.wolfram.com/mathematica/ref/ListDensityPlot.html Then, go to Applications -> .89¥[Thorn]Show ozone density around the world:.89¥ÿ Unfortunately,if one evaluates the given example, one gets the following error message: .89¥[Thorn]CountryData::notprop: {SchematicPolygon, Equirectangular} is not a known property for CountryData. Use CountryData[Properties] for a list of properties. >>.89¥ÿ Indeed, it is easy to check that this is the .89¥[Thorn]Equirectangular.89¥ÿ property that has been removed: StringCases[ CountryData[Properties], ___ ~~ poly | equi | rect ~~ ___, IgnoreCase -> True] // Flatten {FullPolygon, Polygon, SchematicPolygon} If I am not fooling myself, by removing the disgraced property and the surrounding curly braces around the remaining .89¥[Thorn]SchematicPolygon.89¥ÿ, one get an identical plot (as far as I can judge, of course). For instance, data = Import[ ExampleData/ozonemap.hdf, {Datasets, TOTAL_OZONE}]; ListDensityPlot[Reverse@data, ColorFunction -> DeepSeaColors, AspectRatio -> Automatic, DataRange -> {{-180, 180}, {-90, 90}}] outlines = Table[DeleteCases[CountryData[r, SchematicPolygon], Polygon[_Missing]], {r, {SouthAmerica, NorthAmerica, Africa, Europe, Asia, Australia}}]; ListDensityPlot[Reverse@data, ColorFunction -> DeepSeaColors, AspectRatio -> Automatic, DataRange -> {{-180, 180}, {-90, 90}}, Epilog -> {FaceForm[], EdgeForm[Opacity[0.5]], outlines}, PlotRange -> {{-180, 180}, {-90, 90}}] The above code has been tested on $Version -> 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) -- Jean-Marc === Subject: A Mathematica implementation of SolvOpt I recently uploaded a Mathematica implementation of SolvOpt (an implementation of Shor's r algorithm for the minimization of nonlinear, possibly non-smooth objective functions) to http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Shor_ Optimization The main package is SolvOpt.m, with shorTest.m and the notebook SolvOptTest.nb being for demonstration purposes. The original (Fortran, C, and other) implementations and documentation are available at http://www.uni-graz.at/imawww/kuntsevich/solvopt/ As this is my 1st mathematica package (I've only ever used notebooks interactively before) I'd appreciate any suggestions or constructive criticism, especially with regard to efficiency and style. For example I'd like a more efficient and elegant way to express Do[ deltax[[j]] = If[ g0[[j]] >= 0.0, h1*ddx, -h1*ddx] , {j,n} ]; which in Fortran 95 can be written very clearly as Where(g0 >= 0.0) g0 = h1*ddx ElseWhere g0 = -h1*ddx End Where where g0 can be any array of up to 7 dimensions, & any number of array assignments can appear in each section (not just the one shown here), moreover the 'Where' can itself be nested inside another where etc.. For now a construct which works for the 1D list above and avoids the do loop would be fine, though if there is a general method for masked array assignments in Mathematica I love to hear about it. Tom === Subject: Re: A Mathematica implementation of SolvOpt >I recently uploaded a Mathematica implementation of SolvOpt >(an implementation of Shor's r algorithm for the minimization of >nonlinear, possibly non-smooth objective functions) to >http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Shor _Optimization >The main package is SolvOpt.m, with shorTest.m and the notebook >SolvOptTest.nb being for demonstration purposes. >The original (Fortran, C, and other) implementations and documentation >are available at >http://www.uni-graz.at/imawww/kuntsevich/solvopt/ > >As this is my 1st mathematica package (I've only ever used notebooks >interactively before) I'd >appreciate any suggestions or constructive criticism, especially with >regard to efficiency and style. > >For example I'd like a more efficient and elegant way to express >Do[ > deltax[[j]] = If[ g0[[j]] >= 0.0, h1*ddx, -h1*ddx] >, {j,n} >]; > > Can't you just do: deltax = Sign[g0] h1 ddx or if you only want to rewrite a portion of the (already existing) delta array: deltax[[;;n]] = Sign[g0[[;;n]]] h1 ddx Since Sign[0] is 0, you may want to consider using something like (2 UnitStep[g0] -1) instead. Carl Woll Wolfram Research >which in Fortran 95 can be written very clearly as > >Where(g0 >= 0.0) > g0 = h1*ddx >ElseWhere > g0 = -h1*ddx >End Where > >where g0 can be any array of up to 7 dimensions, & any number of array >assignments >can appear in each section (not just the one shown here), moreover the >'Where' can itself >be nested inside another where etc.. For now a construct which works >for the 1D list above >and avoids the do loop would be fine, though if there is a general >method for masked array assignments in Mathematica I love to hear >about it. > > >Tom > > === Subject: Re: A Mathematica implementation of SolvOpt > For example I'd like a more efficient and elegant way to express > Do[ > deltax[[j]] = If[ g0[[j]] >= 0.0, h1*ddx, -h1*ddx] > , {j,n} > ]; which in Fortran 95 can be written very clearly as Where(g0 >= 0.0) > g0 = h1*ddx > ElseWhere > g0 = -h1*ddx > End Where where g0 can be any array of up to 7 dimensions, & any number of array > assignments > can appear in each section (not just the one shown here), moreover the > 'Where' can itself > be nested inside another where etc.. For now a construct which works > for the 1D list above > and avoids the do loop would be fine, though if there is a general > method for masked array assignments in Mathematica I love to hear > about it. Tom, You could use higher level built-in functions such as *Sign[]*, *DiracDelta[]*, *UnitStep[]*, etc., functions that automatically thread over lists and returned integer values in the range [-1, 1] (the actual values depend on the function used) for each element of the lists. Here is an example with *Sign[]* g0 = {{{1, -2}, {3, -4, 5}}, {{6, -7, -8, -9}, 10}}; h1 = 12; ddx = 1/2; deltax = h1*ddx*Sign[g0] {{{6, -6}, {6, -6, 6}}, {{6, -6, -6, -6}, 6}} -- Jean-Marc === Subject: Re: A Mathematica implementation of SolvOpt > I recently uploaded a Mathematica implementation of SolvOpt > (an implementation of Shor's r algorithm for the minimization of > nonlinear, possibly non-smooth objective functions) tohttp://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageNam... > The main package is SolvOpt.m, with shorTest.m and the notebook > SolvOptTest.nb being for demonstration purposes. > The original (Fortran, C, and other) implementations and documentation > are available athttp://www.uni-graz.at/imawww/kuntsevich/solvopt/ > > As this is my 1st mathematica package (I've only ever used notebooks > interactively before) I'd > appreciate any suggestions or constructive criticism, especially with > regard to efficiency and style. > > For example I'd like a more efficient and elegant way to express > Do[ > deltax[[j]] = If[ g0[[j]] >= 0.0, h1*ddx, -h1*ddx] > , {j,n} > ]; > > which in Fortran 95 can be written very clearly as > > Where(g0 >= 0.0) > g0 = h1*ddx > ElseWhere > g0 = -h1*ddx > End Where > > where g0 can be any array of up to 7 dimensions, & any number of array > assignments > can appear in each section (not just the one shown here), moreover the > 'Where' can itself > be nested inside another where etc.. For now a construct which works > for the 1D list above > and avoids the do loop would be fine, though if there is a general > method for masked array assignments in Mathematica I love to hear > about it. > > > Tom deltax = h1*ddx*(2*UnitStep[g0] - 1) will do the whole vector. If you want only elements 1...n then use deltax[[1;;n]] = h1*ddx*(2*UnitStep[g0[[1;;n]]] - 1) or deltax[[Range@n]] = h1*ddx*(2*UnitStep[g0[[Range@n]]] - 1) === Subject: Re: A Mathematica implementation of SolvOpt it's probably obvious but the Fortran equivalent should of course have been Where(g0 >= 0.0) deltax = h1*ddx ElseWhere deltax = -h1*ddx End Where > I recently uploaded a Mathematica implementation of SolvOpt > (an implementation of Shor's r algorithm for the minimization of > nonlinear, possibly non-smooth objective functions) tohttp://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageNam... > The main package is SolvOpt.m, with shorTest.m and the notebook > SolvOptTest.nb being for demonstration purposes. > The original (Fortran, C, and other) implementations and documentation > are available athttp://www.uni-graz.at/imawww/kuntsevich/solvopt/ > > As this is my 1st mathematica package (I've only ever used notebooks > interactively before) I'd > appreciate any suggestions or constructive criticism, especially with > regard to efficiency and style. > > For example I'd like a more efficient and elegant way to express > Do[ > deltax[[j]] = If[ g0[[j]] >= 0.0, h1*ddx, -h1*ddx] > , {j,n} > ]; > > which in Fortran 95 can be written very clearly as > > Where(g0 >= 0.0) > g0 = h1*ddx > ElseWhere > g0 = -h1*ddx > End Where > > where g0 can be any array of up to 7 dimensions, & any number of array > assignments > can appear in each section (not just the one shown here), moreover the > 'Where' can itself > be nested inside another where etc.. For now a construct which works > for the 1D list above > and avoids the do loop would be fine, though if there is a general > method for masked array assignments in Mathematica I love to hear > about it. > > > Tom === Subject: Manipulate Hints, Tips, Tricks Here's a compilation of beginner-intermediate tips for using Manipulate toward its max potential - hope it helps. {I'm on WinXP, using 6.0.2} Paste/evaluate the code later below to note the effects of the various elements: 1) Style[Text Label, Bold]: User interface annotation labels for section headings, etc. 2 Tooltip[]: Note usage for text labels (Style[]) versus for control labels. 3) Appearance -> Labeled: to get live readout of control (sliderbar) setting to the right of the control. 4) ImageSize -> Small: to play with the item's real estate allocation in the overall layout 5) Delimiter: Horizontal separating bar (nice window dressing) 6) Row[]: Means of horizontal grouping of elements, e.g., a label and some dynamically updated value. 7) Item[]: Wrapper for elements such as Row[], permitting use of the Alignment option (e.g., Alignment -> Center) 8) ControlPlacement -> {...}: A rudimentary means to get wrap- around layout of controls around the main plot area. Note that each control and annotation declaration (e.g., Row, Item, Style at the nesting level of the control declarations) counts as one item for callout of its placement in the {...} list. Delimiters don't count. 9) The idiom Style[Manipulate[ ...], DynamicEvaluationTimeout -> 10000] is intended to preclude getting an $Abort in place of the plots, due to long evaluation time (>5sec), particularly in the initial building of the interface. Style[ Manipulate[ Plot[a Sin[b x + c], {x, 0, 10}, PlotRange -> {Automatic, {-10, 10}}], Style[Tooltip[Vertical Controls, y-axis], Bold], {{a, 1, Tooltip[amplitude, signal strength]}, 0, 10, Appearance -> Labeled, ImageSize -> Small}, Delimiter, Style[Horizontal Controls, Bold], {{b, 1, frequency}, 0, 10}, {{c, 0, time lag}, -10, 10}, Item[Row[{Style[Phase (radians): , Blue], Dynamic[Mod[2*Pi*c/b, 2*Pi]]}, Spacer[2]], Alignment -> Center], Item[Row[{Style[Value at x=1: , Blue], Dynamic[a Sin[b 1. + c]]}, Spacer[2]], Alignment -> Left], ControlPlacement -> {Top, Top, Right, Right, Right, Right, Bottom} ], DynamicEvaluationTimeout -> 10000] === Subject: Re: A bug in Show[]? PlotRange is a slightly confusing option in that it confounds two purposes: 1) How Plot and other statements select the final set of points to retain. 2) What the actual displayed domain and range will be. This is even more apparant when doing ContourPlots. There it may be necessary to supply the z range in the ContourPlot (where it has a meaning) but this would not be used in the 2D display. You can see these two different uses in the following statement: model[i_] := Log[i] - Log[i - 1]; Show[Plot[(model[ii]), {ii, 2, 51}, PlotRange -> Full], ListPlot[Table[{im, model[im]}, {im, 2, 51}]], PlotRange -> {-.5, 1.1}] So it is not so much a bug as a confusion of these two different purposes. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Consider the following combined plot: > > model[i_] := Log[i] - Log[i - 1]; > Show[Plot[(model[ii]), {ii, 2, 51}], > ListPlot[Table[{im, model[im]}, {im, 2, 51}]], PlotRange -> All] > > You may see that a part of first Plot is absent. It is easily to > demonstrate that only a part of Plot that is not shown without the > option PlotRange -> All is absent: > > Show[Plot[(model[ii]), {ii, 2, 51}], > ListPlot[Table[{im, model[im]}, {im, 2, 51}]]] > > The workaround is to put this option inside first Plot[] instead > outside of those: > > Show[Plot[(model[ii]), {ii, 2, 51}, PlotRange -> All], > ListPlot[Table[{im, model[im]}, {im, 2, 51}]]] > > But in documentation for Show[] one can read: Options explicitly > specified in Show override those included in the graphics > expression.. Thus this is a bug in Show[]! > > Moreover placing this option inside the second command ListPlot[] has > no result at all (the option is ignored): > > Show[Plot[(model[ii]), {ii, 2, 51}], > ListPlot[Table[{im, model[im]}, {im, 2, 51}], PlotRange -> All]] > > But according to the documentation The lists of non-default options > in the Subscript[g, i] are concatenated.. Thus it seems to be the > second bug in Show[]! > === Subject: Re: A bug in Show[]? >Consider the following combined plot: > >model[i_] := Log[i] - Log[i - 1]; >Show[Plot[(model[ii]), {ii, 2, 51}], > ListPlot[Table[{im, model[im]}, {im, 2, 51}]], PlotRange -> All] > >You may see that a part of first Plot is absent. It is easily to >demonstrate that only a part of Plot that is not shown without the >option PlotRange -> All is absent: > >Show[Plot[(model[ii]), {ii, 2, 51}], > ListPlot[Table[{im, model[im]}, {im, 2, 51}]]] > >The workaround is to put this option inside first Plot[] instead >outside of those: > >Show[Plot[(model[ii]), {ii, 2, 51}, PlotRange -> All], > ListPlot[Table[{im, model[im]}, {im, 2, 51}]]] > >But in documentation for Show[] one can read: Options explicitly >specified in Show override those included in the graphics >expression.. Thus this is a bug in Show[]! > >Moreover placing this option inside the second command ListPlot[] has >no result at all (the option is ignored): > >Show[Plot[(model[ii]), {ii, 2, 51}], > ListPlot[Table[{im, model[im]}, {im, 2, 51}], PlotRange -> All]] > >But according to the documentation The lists of non-default options >in the Subscript[g, i] are concatenated.. Thus it seems to be the >second bug in Show[]! > > The documentation says: Show can be used with Graphics and Graphics3D. So, Show can override the options in Graphics and Graphics3D objects. Now Plot isn't a Graphics object until it is evaluated, and the options to Plot will determine what kind of Graphics object is created. In this case, the Graphics object created when using PlotRange->Automatic is different from the Graphics object created when using PlotRange->All. Basically, more points are included in the Line primitive in the Graphics object when Plot is used with the PlotRange->All option. Changing the PlotRange option of a graphic created using the PlotRange->Automatic option will not cause these additional points to magically appear. Carl Woll Wolfram Research === Subject: Re: Trouble computing conjugates I think in this case the simplest approach is: ComplexExpand[Conjugate[c1*u1 + c2*u2], {c1, c2}, TargetFunctions -> Conjugate] u1*Conjugate[c1] + u2*Conjugate[c2] Andrzej Kozlowski > I'm having trouble getting mathematica to compute complex conjugates > of some fairly simple expressions: > > If I type the following: > > $Assumptions = {g [Element] Reals, f [Element] Reals} > u1 = f + [ImaginaryI] g > u2 = f - [ImaginaryI] g > > Then the command: > > Refine[Conjugate [c1 u1]] > > returns: > > f - [ImaginaryI] g) Conjugate[c1] > > and the command: > > Refine[Conjugate[c1 u1 + u2]] > > returns: > > f + [ImaginaryI] g + (f - [ImaginaryI] g) Conjugate[c1] > > as I would expect. But the command: > > Refine[Conjugate[c1 u1 + c2 u2]] > > returns: > > Conjugate[c2 (f - [ImaginaryI] g) + c1 (f + [ImaginaryI] g)] > > i.e. it refuses to distribute the complex conjugate throughout the > expression. What I would like it to tell me is: > > (f + [ImaginaryI] g) Conjugate[c2] + (f - [ImaginaryI] g) > Conjugate[c1] > > The closest I have been able to come to getting what I want is by > using: > > ComplexExpand[Refine[Conjugate[ c1 u1 + c2 u2]], {c1, c2}] > > but this separates c1 and c2 into their real and imaginary parts. The > above expressions are much simpler than the ones I REALLY want > Mathematica's help in simplifying. If I use this ComplexExpand > command, then I'm going to have to recombine them into complex numbers > again, which would be very very bad. > > Roy > === Subject: Re: ListDensityPlot with irregular data and InterpolationOrder > This is not explicitly documented (or at least I could not find any >> mention of it), but from looking at the plots it seems to me that >> with ListDensityPlot (and related functions), an InterpolationOrder >> higher than 1 only work with data that lies on a regular grid. > So for example the following data cannot be plotted with >> InterpolationOrder higher than 1: > data = {#1, #2, Sin[#1] Sin[#2]} & @@@ RandomReal[2 Pi, {100, 2}]; > Is this correct? The array you create above is a regular array and as far as I > can see there is no problem with using an InterpolationOrder > greater than 1. That is, using your code above to assign values > to data > ListDensityPlot[data] > ListDensityPlot[data,InterpolationOrder->1] > ListDensityPlot[data,InterpolationOrder->3] all execute with no error messages. True, all three graphics appear identical. But I believe this is > due the functional relationship you created. Do the following data=RandomReal[2 Pi, {5,5}]; then ListDensityPlot[data] > ListDensityPlot[data,InterpolationOrder->1] > ListDensityPlot[data,InterpolationOrder->3] All three should execute with no error and the images will not > be the same due to the different interpolation order. Exactly this is what I mean, i.e. that when passing arbitrary data points to ListDensityPlot (instead of data on a regular grid), InterpolationOrder seems to only have an effect if we use InterpolationOrder -> 0. Otherwise the result will be the same as with InterpolationOrder -> None. So it seems that ListDensityPlot can only interpolate on a grid, but not in a more general situation. This is not a problem, of course, but I got a bit confused because it gives no error message! === Subject: 2 domain PDE, NDSolve I'm working on solving the basic 1D, transient heat transfer equation in a two layer slab configuration. One side is insulated, the other has a constant heat flux, and there is not contact resistance between the two layers. My formulation looks like this: equation1: T1(0,1)[z,t] == k1/rho1/Cp1*T1(2,0)[z,t] equation2: T2(0,1)[z,t] == k2/rho2/Cp2*T2(2,0)[z,t] IC1: T1[z,0] == T0 IC2: T2[z,0] == T0 BC1: T1(1,0)[0,t] == 0 BC2: -k1*T2(1,0)[L2+L1,t] == qs Match1: k1*T1(1,0)[L1,t] == k2*T2(1,0)[L1,t] Match2: T1(1,0)[L1,t] == T2(1,0)[L1,t] T1[z,t] is solve from 0 to L1, T2[z,t] from L1 to L1+L2. I've tried NDSolve but it doesn't like the matching conditions (it interprets them as BC's and since they're not on the boundary it has issue with it). There's an analytical solution but it's nearly unworkable... Can this be solved in mathematica? === Subject: Re: 2 domain PDE, NDSolve > I'm working on solving the basic 1D, transient heat transfer equation in a > two layer slab configuration. One side is insulated, the other has a > constant heat flux, and there is not contact resistance between the two > layers. My formulation looks like this: > equation1: T1(0,1)[z,t] == k1/rho1/Cp1*T1(2,0)[z,t] > equation2: T2(0,1)[z,t] == k2/rho2/Cp2*T2(2,0)[z,t] > IC1: T1[z,0] == T0 > IC2: T2[z,0] == T0 > BC1: T1(1,0)[0,t] == 0 > BC2: -k1*T2(1,0)[L2+L1,t] == qs > Match1: k1*T1(1,0)[L1,t] == k2*T2(1,0)[L1,t] > Match2: T1(1,0)[L1,t] == T2(1,0)[L1,t] T1[z,t] is solve from 0 to L1, T2[z,t] from L1 to L1+L2. I've tried NDSolve but it doesn't like the matching conditions (it > interprets them as BC's and since they're not on the boundary it has issue > with it). Please, could you post genuine Mathematica expressions as well as what you tried with NDSolve? (I believe that by writing T1(0,1)[z,t] you mean actually Derivative[0, 1][T1][z, t], but I am too lazy today to correct all the expressions :-) -- Jean-Marc === Subject: Re: 2 domain PDE, NDSolve Hello Jeremy, I started looking at this, but I believe that you may have a typo in your Dirichlet condition for T2. Assuming that you are solving a 1d diffusion problem in two connected domains. > You're right, the (0,1) was meant to mean Derivative[0,1]... There was also > a typo in BC2. And so the expressions look like this: > > Derivative[0, 1][T1][z, t] == k1/rho1/Cp1*Derivative[2, 0][T1][z, t] > Derivative[0, 1][T2][z, t] == k2/rho2/Cp2*Derivative[2, 0][T2][z, t] > T1[z, 0] == T0 > T2[z, 0] == T0 > Derivative[1, 0][T1][0, t] == 0 > -k2*Derivative[1, 0][T2][0, t] == qs > k1*Derivative[1, 0][T1][L1, t] == k2*Derivative[1, 0][T2][L1, t] I scaled to remove redundant parameters (you can get rid of T0, make L2=1, L1=rat, etc) (*left domain*) t1de = Derivative[0, 1][T1][z, t] == diff1 Derivative[2, 0][T1][z, t] (*right domain*) t2de = Derivative[0, 1][T2][z, t] == diff2 Derivative[2, 0][T2][z, t] (*ic left*) icleft = T1[z, 0] == 0 (*ic right*) icright = T2[z, 0] == 0 (*bc-left left) dirchleft = Derivative[1, 0][T1][0, t] == 0 (*what ? T2 is defined on (L1,L2)*) dirichwhat = diff2*Derivative[1, 0][T2][0, t] == qsscaled In any case, for this problem I suggest that you use mathematica to do this problem the old-fashioned way: the solution in each domain will be a fourier series... All you need to do is match coefficients of the derivative of each series at the internal interface.... closed form solution. Sorry if I my assumption was incorrect and you were thinking of a different problem.... -- W. Craig Carter === Subject: Re: 2 domain PDE, NDSolve > >> I'm working on solving the basic 1D, transient heat transfer equation in >> a >> two layer slab configuration. One side is insulated, the other has a >> constant heat flux, and there is not contact resistance between the two >> layers. >> >> My formulation looks like this: >> equation1: T1(0,1)[z,t] == k1/rho1/Cp1*T1(2,0)[z,t] >> equation2: T2(0,1)[z,t] == k2/rho2/Cp2*T2(2,0)[z,t] >> IC1: T1[z,0] == T0 >> IC2: T2[z,0] == T0 >> BC1: T1(1,0)[0,t] == 0 >> BC2: -k1*T2(1,0)[L2+L1,t] == qs >> Match1: k1*T1(1,0)[L1,t] == k2*T2(1,0)[L1,t] >> Match2: T1(1,0)[L1,t] == T2(1,0)[L1,t] >> >> T1[z,t] is solve from 0 to L1, T2[z,t] from L1 to L1+L2. >> >> I've tried NDSolve but it doesn't like the matching conditions (it >> interprets them as BC's and since they're not on the boundary it has >> issue >> with it). > > > > Please, could you post genuine Mathematica expressions as well as what > you tried with NDSolve? (I believe that by writing T1(0,1)[z,t] you mean > actually Derivative[0, 1][T1][z, t], but I am too lazy today to correct > all the expressions :-) > > -- Jean-Marc > You're right, the (0,1) was meant to mean Derivative[0,1]... There was also a typo in BC2. And so the expressions look like this: Derivative[0, 1][T1][z, t] == k1/rho1/Cp1*Derivative[2, 0][T1][z, t] Derivative[0, 1][T2][z, t] == k2/rho2/Cp2*Derivative[2, 0][T2][z, t] T1[z, 0] == T0 T2[z, 0] == T0 Derivative[1, 0][T1][0, t] == 0 -k2*Derivative[1, 0][T2][0, t] == qs k1*Derivative[1, 0][T1][L1, t] == k2*Derivative[1, 0][T2][L1, t] What I plugged into NDSolve looks like this... Dummy values for the coefficients: L1=0.005; L2=0.001; k1=10; k2=1; rho1=1; rho2=2; Cp1=1; Cp2=2; T0=10; qs=1000; Attempt at a solution: solution = NDSolve[ {Derivative[0,1][T1][z,t]==k1/rho1/Cp1*Derivative[2,0][T1][z,t], Derivative[0,1][T2][z,t]==k2/rho2/Cp2*Derivative[2,0][T2][z,t], T1[z,0]==T0, T2[z,0]==T0, Derivative[1,0][T1][0,t]==0, -k2*Derivative[1,0][T2][0,t]==qs, k1*Derivative[1,0][T1][L1,t]==k2*Derivative[1,0][T2][L1,t], T1[L1,t]==T2[L1,t]}, {T1,T2},{z,0,L1+L2},{t,0,10}] and the error is: NSSOLVE::bcedge : Boundary condition 10T1(1,0)[0.005,t]=T2(1,0)[0.005,t] is not specified on a single edge of the boundary of the computational domain. === Subject: tablename[[x]]= xth row, how to get xth column hello a very simple question, sometablename[[X]] gives me the Xth row of table , like below. f = {{1, 2, 3, 4}, {1, 4, 6, 77}} {{1, 2, 3, 4}, {1, 4, 6, 77}} f[[1]] {1, 2, 3, 4} I am not able to find the syntax that can give me Xth column of a table. i dont want to transpose it and use. and I tried #, thank you cimon === Subject: Re: tablename[[x]] = xth row, how to get xth column > hello > > a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. > > f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > > > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, sometablename[[All,x]] === Subject: Re: tablename[[x]] = xth row, how to get xth column f[[All, 2]] {2, 4} > hello a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, thank you cimon > -- 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: tablename[[x]] = xth row, how to get xth column > hello > > a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. > > f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > > > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, > > thank you > > cimon As a newbie I would go for, let's say the 3rd column, with: In[4]:= f[[All,3]] Out[4]= {3, 6} === Subject: Re: tablename[[x]]= xth row, how to get xth column > hello a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, thank you cimon > tablename[[All,n]] gives the nth column. === Subject: Re: tablename[[x]]= xth row, how to get xth column Hi cimon, try In[151]:= f[[All, 2]] Out[151]= {2, 4} Best, Markus > hello > > a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. > > f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, > > thank you > > cimon === Subject: Re: tablename[[x]]= xth row, how to get xth column f[[All, 2]] ?? 2th column Jens > hello a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, thank you cimon > === Subject: Re: tablename[[x]]= xth row, how to get xth column > a very simple question, sometablename[[X]] gives me the Xth row of > table , like below. f = {{1, 2, 3, 4}, {1, 4, 6, 77}} > {{1, 2, 3, 4}, {1, 4, 6, 77}} > f[[1]] > {1, 2, 3, 4} > I am not able to find the syntax that can give me Xth column of a > table. i dont want to transpose it and use. and I tried #, f = {{1, 2, 3, 4}, {1, 4, 6, 77}}; f[[All, 2]] (*Returns the second column without explicitly transposing. Read it as: Take all the rows and for each of these rows take only the second element*) {2, 4} (*Similarly, the following extracts the third element of the second row only*) f[[2, 3]] 6 You should read the short tutorial titled Getting Pieces of Lists available in the documentation center or online at http://reference.wolfram.com/mathematica/tutorial/GettingPiecesOfLists.html -- Jean-Marc === Subject: Re: Request for Collective Wisdom... My tip would be to never make global assignments to 1-letter variables. These can so easily get re-used in other expressions and cause havoc. If you have an expression and you wish to substitute x=7, use: expression /.x->7 David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Request for Collective Wisdom... Hi W Craig I'm not sure if this is a paradigm of excellence, or a flag on an error, but as an unrepentant Fortran hacker my leading Mathematica mantra is: 'Mark, if you are writing a loop you are doing it wrong' and whaddya know, I write better Fortran now too ! Mark Westwood > (*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 === Subject: Re: Pattern matching problem If you don't want to multiply by the power, then don't: f[equation_] := Sum[j*Count[equation, D[u[x, t], {x, j}]^k, {0, Infinity}], {j, 1, 50}, {k, 1, 50}] eg = D[u[x, t], {x, 2}]^2; f[eg] 4 Bobby > > Hi all, > Here is my problem: Given a polynomial in the variables u[x,t] and its > spatial derivatives (for example, the polynomial could be 1 + u + > u_xx*u_xxx^2), count the number of spatial derivatives with multiplicity. > That is, after writing the above polynomial as > > > 1 + u + u_xx * u_xxx * u_xxx > > the output should be 2 + 3 + 3 (basically, you count the number of x's). > > I have tried implementing this using a pattern matching approach. Here is > what I tried: > > f[equation_ ] := Sum[ k * j * Count[ equation , D[ u[x, t], {x, j} ] ^ > k , > {0, infinity} ], {j, 1, 50}, {k, 1, 50}] > > This fails to work on, for example, the input u_xx^2, because it outputs > 6 > when it should output 4. This is because the u_xx is counted (+2 to th e > sum), and the u_xx^2 is counted (+4 to the sum). This is because the > u_xx is > nested inside the Power[ , 2] in its representation in Mathematica > and so > it gets counted too many times in my formula. I can't seem to figure out > a > way to use the provided that operator /; to make this formula work. > > I've also tried doing some replacement methods, but to no success. > > > -Charlie > > > -- DrMajorBob@longhorns.com === Subject: Re: Solving on mathematica Your NSolve statement is not legal syntax (in a dozen different ways), and if it were, the knowns you're not solving for -- x[i] and y[i] -- would have to be... you know... KNOWN. That is, they'd have to be numbers, since NSolve solves numerical problems, not algebraic ones. If we try to solve the algebraic problem, we get: eq[i_] = (x[i] - ux)^2 + (y[i] - uy)^2 + z[i] - uz == r[i] - cb; Solve[Array[eq, 4], {ux, uy, uz, cb}] {} That is, there is no solution to the general problem. It's always possible Solve missed an existing solution, but in this case, I doubt it. Here's a second attempt, this time just trying to solve for maxima/minima of the squared error: zeroD[i_] = Equal @@ D[#.# &@(List @@ eq[i]), {{ux, uy, uz, cb, dummy}}] -4 (-ux + x[i]) (-uz + (-ux + x[i])^2 + (-uy + y[i])^2 + z[i]) == -4 (-uy + y[i]) (-uz + (-ux + x[i])^2 + (-uy + y[i])^2+ z[i]) == -2 (-uz + (-ux + x[i])^2 + (-uy + y[i])^2 + z[i]) == -2 (-cb + r[i]) == 0 Solve[Flatten@Array[zeroD, 4], {ux, uy, uz, cb}] {} Bobby > How would i go about solving this equaiton on mathematica > > (Xi -Ux)^2 + (Yi - Uy)^2 + (Zi - Uz) = (Ri - Cb) > i = 1,2,3,4 > > where we need to find Ux, Uy, Uz, Cb tried a few things and they dont > work. > > NSolve[ (Xi - U)^2 + (Yi - V)^2 + (Zi - W)^2 == (Ri - B)^2, {U, V, W, > B}, { i = 1, 2, 3, 4} ] > > any ideas? > > -- = DrMajorBob@longhorns.com === Subject: Re: Question on the Limiting Value of Ratios of Consecuative Primes... Here's a sketchy proof that the limit is one, based on the Prime Number Theorem: prime[primePi_] = First@Quiet[x /. Solve[primePi == x/Log[x], x]] -primePi ProductLog[-(1/primePi)] Limit[prime[i]/prime[i + 1], i -> Infinity] 1 I understand that Mathematica's Prime function works by inverting PrimePi; I've inverted, instead, an asymptotic approximation of PrimePi. Bobby > Is there some analytic limit to the ratio of consecuative primes? The > expression Limit[Prime[i]/Prime[i+1],{i,->Infinity}] returns > unevaluated. > Plotting Table[ Prime[i]/Prime[i+1],{i,1,20000}] shows a lot of structure > with a minimum of 3/5. > -- DrMajorBob@longhorns.com === Subject: Re: Question on the Limiting Value of Ratios of Consecuative Primes... I forgot to add that the question of whether there are infinitely many twin primes or not still remains unsolved (http://mathworld.wolfram.com/TwinPrimes.html ). Cramer's conjecture that I mentioned in my post also seems not to have been proved. But the proof given based on Montgomery's result that I sketched below is a really a proof, and does not depen on any unproved conjectures. Andrzej Kozlowski > > > Is there some analytic limit to the ratio of consecuative primes? >> >> Yes. The limit is 1. >> >> Since there are infinitely many twin primes, it's obvious that, if >> the >> limit exists, it must be 1. >> >> I don't know how to show nicely that the limit exists. > > This result follows from the following one proved in H.L. > Montgomery Topics in Multiplicative Number Theory (Springer 1971): > > For any epsilon >0 and x > x0(epsilon), there is a prime in the > interval [x,x+x^(3/5 + epsilon)]. > > This means that for arbirarily small epsilon and a sufficiently > large Prime[n], the ratio Prime[n+1]/Prime[n] is less than (Prime[n] > +Prime[n]^(3/5+epsilon))/Prime[n] = 1 + Prime[n]^(epsilon-2/5), > which can be made arbitrarily close to 1 (for epsilon <2/5). > > Actually, there has been a lot of interest in the long term > behaviour of the difference of consecutive primes. Montgomery > mentions the following which he attributes to Cramer: > > Limit[(Prime[n+1]-Prime[n])/Log[Prime[n]]^2,n->Infinity] == 1 > > (this is not meant to be a Mathematica formula, since Mathematica > does not have the notion of the limit of a sequence but only a > mathematical statement written in the Mathematica notation) > > but I am not sure if that is a theorem or only a conjecture. > > Andrzej Kozlowski > > >> >> > The expression Limit[Prime[i]/Prime[i+1],{i,->Infinity}] returns > unevaluated. >> >> I suspect that is just as well. My understanding is that >> Mathematica is not >> designed to deal with limits of sequences and that, had you gotten an >> answer, it should not have been trusted. >> > Plotting Table[ Prime[i]/Prime[i+1],{i,1,20000}] shows a lot > of structure with a minimum of 3/5. >> >> I suppose I see the structure to which you refer: various strings >> of >> points which could be visualized as lying on smooth curves. The >> points >> which form the uppermost string correspond to the ratios of the twin >> primes. The points which form the next string down correspond to >> the ratios >> of primes having a difference of 4. And then the points which form >> the next >> string down correspond to the ratios of primes having a difference >> of 6. >> Etc. >> >> David W. Cantrell >> > === Subject: Re: Question on the Limiting Value of Ratios of Consecuative Primes... >> Is there some analytic limit to the ratio of consecuative primes? > > Yes. The limit is 1. > > Since there are infinitely many twin primes, it's obvious that, if the > limit exists, it must be 1. > > I don't know how to show nicely that the limit exists. This result follows from the following one proved in H.L. Montgomery Topics in Multiplicative Number Theory (Springer 1971): For any epsilon >0 and x > x0(epsilon), there is a prime in the interval [x,x+x^(3/5 + epsilon)]. This means that for arbirarily small epsilon and a sufficiently large Prime[n], the ratio Prime[n+1]/Prime[n] is less than (Prime[n] +Prime[n]^(3/5+epsilon))/Prime[n] = 1 + Prime[n]^(epsilon-2/5), which can be made arbitrarily close to 1 (for epsilon <2/5). Actually, there has been a lot of interest in the long term behaviour of the difference of consecutive primes. Montgomery mentions the following which he attributes to Cramer: Limit[(Prime[n+1]-Prime[n])/Log[Prime[n]]^2,n->Infinity] == 1 (this is not meant to be a Mathematica formula, since Mathematica does not have the notion of the limit of a sequence but only a mathematical statement written in the Mathematica notation) but I am not sure if that is a theorem or only a conjecture. Andrzej Kozlowski > > >> The expression Limit[Prime[i]/Prime[i+1],{i,->Infinity}] returns >> unevaluated. > > I suspect that is just as well. My understanding is that Mathematica > is not > designed to deal with limits of sequences and that, had you gotten an > answer, it should not have been trusted. > >> Plotting Table[ Prime[i]/Prime[i+1],{i,1,20000}] shows a lot >> of structure with a minimum of 3/5. > > I suppose I see the structure to which you refer: various strings of > points which could be visualized as lying on smooth curves. The points > which form the uppermost string correspond to the ratios of the twin > primes. The points which form the next string down correspond to the > ratios > of primes having a difference of 4. And then the points which form > the next > string down correspond to the ratios of primes having a difference > of 6. > Etc. > > David W. Cantrell > === Subject: Re: Question on the Limiting Value of Ratios of Consecuative Primes... On May 8, 2008, Lou Talman asked, rhetorically: > Since there are infinitely many twin primes, When was the Twin Prime conjecture proven? and by whom? Between are and infinitely, please insert presumably. David === Subject: Re: Question on the Limiting Value of Ratios of > Since there are infinitely many twin primes, When was the Twin Prime conjecture proven? and by whom? --Lou Talman Department of Mathematical & Computer Sciences Metropolitan State College of Denver === Subject: Re: substitution within a substitution list subs = {a -> 1, b -> 2, c -> 2}; subs /. Rule[b, _] -> Rule[b, 20] {a -> 1, b -> 20, c -> 2} subs /. Rule[b, x_] -> Rule[b, 10 x] {a -> 1, b -> 20, c -> 2} ReplacePart[subs, {2, 2} -> 20] {a -> 1, b -> 20, c -> 2} etc. Bobby > HI, > > I'm trying to find a way of changing the substitution values within a > substitution list. > > For example, if I have the following substitution list:- > > subs = {a->1, b->2, c->2} > > I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with > > subs = {a->1, b->20, c->2} > > Does anyone know of a mathematica function for doing this? > > Bipin. > > -- DrMajorBob@longhorns.com === Subject: Re: substitution within a substitution list >I'm trying to find a way of changing the substitution values within >a substitution list. >For example, if I have the following substitution list:- >subs = {a->1, b->2, c->2} >I want to programmatically replace the value associated with 'b' >from 2 to 20, ie ending up with >subs = {a->1, b->20, c->2} >Does anyone know of a mathematica function for doing this? Sure. Use a replacement rule with HoldPattern. For example, In[4]:= subs /. HoldPattern[a_ -> _] -> a -> 20 Out[4]= {a->20,b->20,c->20} === Subject: Re: substitution within a substitution list Any one of these or similar variants subs = subs /. (b -> _) -> (b -> 20) subs = Join[Select[subs, FreeQ[#, b] &], {b -> 20}] subs = Join[DeleteCases[subs, b -> _], {b -> 20}] You can use Sort in the last two if the order matters to you. Bob Hanlon > HI, I'm trying to find a way of changing the substitution values within a > substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with subs = {a->1, b->20, c->2} Does anyone know of a mathematica function for doing this? Bipin. > === Subject: Re: list of dates Bill's last attempt was nearly twice as fast as mine. This has taught me a lot about handling lists, functions and dates with Mathematica, but also some of its limitations and the hoops one has to jump through. In the end, I finished the job in Stata, which is built primarily around lists and therefore handles them more directly and efficiently (but less flexibly). I had also briefly flirted with using Mathematica as a mathematical word-processor in place of Word & MathType. I need to give more thought to when Mathematica is the most suitable tool for future jobs. Roger === Subject: Solving Large Overdetermined Systems My equation system consists (at the moment - by taking all linear combinations, the cubics surely can be pruned too) of 18 quadratics and 360 cubics in 15 variables. Solve[] is out of question, for NSolve[] it's still too large (not mentioning that there are some 1-parametric solutions), so I turned to FindRoot[] - one found random solution would already be very revealing. But alas, FindRoot[] needs #eq=#var. Bummer. (Of course I can take 15 random equations and plug the solution back in, but the probability of 378 zeroes is zero...) Any other idea what I could try? -- Hauke Reddmann <:-EX8 fc3a501@uni-hamburg.de Er-a svo gott sem gott kve[CapitalYAcute]a .9al alda sonum, ßv.92 a[CapitalYAcute] f.berra veit er fleira drekkur s.92ns til ge[CapitalYAcute]s gumi. === Subject: Re: Formatting Problem with Summation Symbol >I often write short derivations in a single cell with a statement on each >line and sometimes Print statements interspersed as commentary. This gives >one input cell and multiple output cells. Then one can select all the output >cells and double-click to hide the input cell. However, sometimes it is a >bit inconvenient to select all the output cells so I would like to display >them as lines in a Column instead. Then there would be only one output cell >to select. However, it is difficult to obtain the same formatting in Column >as one obtains in output cells. > >Here is an example: > >p[x] == Sum[a[n] x^n, {n, 0, N}] // TraditionalForm > >Now I try to display the same statement as part of a Column. (Usually one >would have more entries but here I just simplify it to one entry.) > >Style[Column[{p[x] == Sum[a[n] x^n, {n, 0, N}]}], > Output] // TraditionalForm > >This does not look like the ordinary Output formatting. I can improve the >limits positioning by using: > >Style[Column[{p[x] == Sum[a[n] x^n, {n, 0, N}]}], Output, > UnderoverscriptBoxOptions -> {LimitsPositioning -> > False}] // TraditionalForm > >This still does not look like normal Output because the Sigma is too >small. I can make the Sigma larger by using: > >Style[Column[{p[x] == Sum[a[n] x^n, {n, 0, N}]}], Output, > UnderoverscriptBoxOptions -> {LimitsPositioning -> False}, > SpanMinSize -> 2] // TraditionalForm > >But now the brackets are too large. Is there a method to use a Column >expression and have each line look like regular Output formatting? > > > Column formats its contents using ScriptLevel->1. So, override this by including an explicit Style directive: Column[{Style[p[x] == Sum[a[n] x^n, {n, 0, N}], ScriptLevel -> 0]}] Carl Woll Wolfram Research === Subject: Re: Formatting Problem with Summation Symbol Here is an elaboration that saves us from wrapping every statement in Style. Column is actually a type of GridBox and the option to use here is AllowScriptLevelChange. We write a definition that allows us to combine a series of statements into a single output cell. Derivation::usage = Derivation[step1,step2,...] will display a series of Mathematica statements as a single Column output cell.; SyntaxInformation[Derivation] = {ArgumentsPattern -> {__}}; Derivation[steps__] := Column[{steps}, Left, 1, BaseStyle -> {GridBoxOptions -> {AllowScriptLevelChange -> False}}] Then an example of its use might be: Derivation[ Style[Row[{The first step involves an intgral: , Sum[a[n] x^n, {n, 0, N}], with , a[n] -> Sin[n x]}], ScriptLevel -> 1], step1 = p[x] == HoldForm@Sum[Sin[n x] x^n, {n, 0, N}], Evaluating, step1 // ReleaseHold, This is the second step:, q[x] == HoldForm@Integrate[x^n Sin[n x], {x, 0, Pi}], etc., etc. ] The output is in a single cell, which can be double-clicked to hide the input statement. We did use a Style statement to revert to ScriptLevel->1 on one of the annotation statements. The only trouble with this construction is that we can't use the %, %% reference notation. David Park djmpark@comcast.net http://home.comcast.net/~djmpark === Subject: Re: Formatting Problem with Summation Symbol >I often write short derivations in a single cell with a statement on each >line and sometimes Print statements interspersed as commentary. This gives >one input cell and multiple output cells. Then one can select all the output >cells and double-click to hide the input cell. However, sometimes it is a >bit inconvenient to select all the output cells so I would like to display >them as lines in a Column instead. Then there would be only one output cell >to select. However, it is difficult to obtain the same formatting in Column >as one obtains in output cells. > >Is there a method to use a Column >expression and have each line look like regular Output formatting? Column formats its contents using ScriptLevel->1. So, override this by including an explicit Style directive: Column[{Style[p[x] == Sum[a[n] x^n, {n, 0, N}], ScriptLevel -> 0]}] Carl Woll Wolfram Research === Subject: Re: Formatting Problem with Summation Symbol David Park djmpark@comcast.net http://home.comcast.net/~djmpark Is there a method to use a Column >expression and have each line look like regular Output formatting? > > > Column formats its contents using ScriptLevel->1. So, override this by including an explicit Style directive: Column[{Style[p[x] == Sum[a[n] x^n, {n, 0, N}], ScriptLevel -> 0]}] Carl Woll Wolfram Research === Subject: Re: substitution within a substitution list > I'm trying to find a way of changing the substitution values within a > substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with subs = {a->1, b->20, c->2} You could use a rule to change the rules: subs /. (b -> x_) -> b -> 20 For instance, In[1]:= subs = {a -> 1, b -> 2, c -> 2} Out[1]= {a -> 1, b -> 2, c -> 2} In[2]:= subs = subs /. (b -> x_) -> b -> 20 Out[2]= {a -> 1, b -> 20, c -> 2} -- Jean-Marc === Subject: Re: substitution within a substitution list Hi Bipin, you need HoldPattern for this. E.g.: subs/.HoldPattern[b->x_]->b->10 x hope this helps, Daniel > HI, I'm trying to find a way of changing the substitution values within a > substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with subs = {a->1, b->20, c->2} Does anyone know of a mathematica function for doing this? Bipin. > === Subject: Re: substitution within a substitution list A solution using ReplaceAll (/.) and RuleDelayed ( :> ): {a -> 1, b -> 2, c -> 2} /. {(b -> i_) :> b -> 10*i} returns {a -> 1, b -> 20, c -> 2} Adriano Pascoletti > HI, > > I'm trying to find a way of changing the substitution values within a > substitution list. > > For example, if I have the following substitution list:- > > subs = {a->1, b->2, c->2} > > I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with > > subs = {a->1, b->20, c->2} > > Does anyone know of a mathematica function for doing this? > > Bipin. > > === Subject: Re: substitution within a substitution list > HI, I'm trying to find a way of changing the substitution values within a > substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with subs = {a->1, b->20, c->2} Does anyone know of a mathematica function for doing this? yes :-). ReplaceAll, or /. for short: subs /. (b -> _) -> (b -> 20) depending on your expression and where they come from this might be more robust: Replace[subs, (Rule | RuleDelayed)[b, _] -> (b -> 20), {1}] hth, albert === Subject: Re: substitution within a substitution list subs = Union[DeleteCases[subs, b -> 2], {b -> 20}] is how I would do it, but there are probably better ways. Thomas Dowling > HI, > > I'm trying to find a way of changing the substitution values within a > substitution list. > > For example, if I have the following substitution list:- > > subs = {a->1, b->2, c->2} > > I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with > > subs = {a->1, b->20, c->2} > > Does anyone know of a mathematica function for doing this? > > Bipin. > > === Subject: Re: substitution within a substitution list Begin forwarded message: === > Subject: Re: substitution within a substitution list > >> HI, >> >> I'm trying to find a way of changing the substitution values within a >> substitution list. >> >> For example, if I have the following substitution list:- >> >> subs = {a->1, b->2, c->2} >> >> I want to programmatically replace the value associated with 'b' from >> 2 to 20, ie ending up with >> >> subs = {a->1, b->20, c->2} >> >> Does anyone know of a mathematica function for doing this? >> >> Bipin. > > > You can use > > subs /. HoldPattern[b -> _] :> (b -> 20) > > or even something like > > subs /. HoldPattern[b -> x_] :> (b -> 10 x) > > Christopher Carlson > User Interface Group > Wolfram Research, Inc. HoldPattern is not necessary here. These suffice: subs /. (b -> _) -> (b -> 20) subs /. (b -> x_) :> (b -> 10 x) Christopher Carlson User Interface Group Wolfram Research, Inc. === Subject: Re: substitution within a substitution list > HI, I'm trying to find a way of changing the substitution values within a > substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with subs = {a->1, b->20, c->2} Does anyone know of a mathematica function for doing this? > ReplaceAll works fine: In[1]:= subs = {a -> 1, b -> 2, c -> 2} Out[1]= {a -> 1, b -> 2, c -> 2} In[2]:= subs /. (b -> _) -> (b -> 20) Out[2]= {a -> 1, b -> 20, c -> 2} === Subject: Re: substitution within a substitution list > HI, > > I'm trying to find a way of changing the substitution values within a > substitution list. > > For example, if I have the following substitution list:- > > subs = {a->1, b->2, c->2} > > I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with > > subs = {a->1, b->20, c->2} > > Does anyone know of a mathematica function for doing this? > > Bipin. You can use subs /. HoldPattern[b -> _] :> (b -> 20) or even something like subs /. HoldPattern[b -> x_] :> (b -> 10 x) Christopher Carlson User Interface Group Wolfram Research, Inc. === Subject: Re: substitution within a substitution list subs /. (b -> _) :> (b -> 2^6) ?? Jens > HI, I'm trying to find a way of changing the substitution values within a > substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with subs = {a->1, b->20, c->2} Does anyone know of a mathematica function for doing this? Bipin. > === Subject: Re: substitution within a substitution list > HI, > > I'm trying to find a way of changing the substitution values within a > substitution list. > > For example, if I have the following substitution list:- > > subs = {a->1, b->2, c->2} > > I want to programmatically replace the value associated with 'b' from > 2 to 20, ie ending up with > > subs = {a->1, b->20, c->2} > > Does anyone know of a mathematica function for doing this? > > Bipin. You can actually do this pretty much like any other pattern matching. Just need some strategic parentheses: {a -> 1, b -> 2, c -> 2} /. (b -> _) -> (b -> 20) {a -> 1, b -> 20, c -> 2} JM === Subject: Tracking a dynamic variable Hello I have a larger program in which I want to look if a value of a dynamic variable has changed. A short version of this program looks like this: Interpretation[{x = 1, y = 1, flag1 = False, flag2 = False}, TabView[{ task 1 -> Dynamic[ Block[{}, (* store old value of x *) y = x; (* test if x changed *) If[x != y, flag1 = True]; (* display input and some outout *) Panel[ Grid[ {{ InputField[Dynamic[x]], Dynamic[x], Dynamic[y], flag1 }} ] ] ] ], task 2 -> Dynamic[ Block[{}, If[x == y, flag2 = True, flag2 = False ]; Panel[ Grid[ {{x, y, flag1, flag2}} ] ] ] ] } ], Print[end] ] I want to track the variable x and if it has changed in task 1 an appropriate action should be accomplished in task 2. The program above works only if for the input in task 1 the Return key is not pressed in the InputField. If I press Return in the InputField the whole task 1 is executed and then y will be equal to x in any case. Now how can I track the value of x so that I can decide in task 2 that x has changed? Matthias === Subject: Re: DynamicModule question > Can someone please explain to me why the following happens? It's a > silly little example to illustrate a problem I ran into recently... First, evaluate the following in separate cells: Needs[PieCharts`]; data = {.25, .75} Then evaluate the following: DynamicModule[{size = 300}, > Column[{ > Slider[Dynamic[size], {100, 500}], > Dynamic[PieChart[data, ImageSize -> size]] > }] > ] Notice that you can not only resize the graphic by dragging the > slider, but if you change the definition of data, that's reflected > automatically in the graphic as well. However, suppose you wrap the DynamicModule in a function like so: foo[data_] := DynamicModule[{size = 300}, > Column[{ > Slider[Dynamic[size], {100, 500}], > Dynamic@PieChart[data, ImageSize -> size] > }] > ] Now evaluate foo[ data ] If you change the definition of data in the notebook, the second > DynamicModule doesn't update the pie charts. I don't understand what > breaks when you wrap the DynamicModule in a function definition. Try Dynamic@foo[data] Now, why Dynamic is needed here? I do not know. Looking at the expressions in the output cells (Shift + Cmd + E ) for the code generated by entering directly the DynamicModule or by using a function both resulting expressions look very similar (even identical, as far as I can trust my sight :-) -- Jean-Marc === Subject: Re: DynamicModule question try SetAttributes[foo, HoldAll] foo[data_] := DynamicModule[{size = 300}, Column[{Slider[Dynamic[size], {100, 500}], Dynamic@PieChart[data, ImageSize -> size]}]] and lst = #/(Plus @@ #) & /@ Table[Random[], {5}, {3}]; Do[ data = lst[[i]]; Pause[1], {i, 1, 3}] Jens > Can someone please explain to me why the following happens? It's a > silly little example to illustrate a problem I ran into recently... First, evaluate the following in separate cells: Needs[PieCharts`]; data = {.25, .75} Then evaluate the following: DynamicModule[{size = 300}, > Column[{ > Slider[Dynamic[size], {100, 500}], > Dynamic[PieChart[data, ImageSize -> size]] > }] > ] Notice that you can not only resize the graphic by dragging the > slider, but if you change the definition of data, that's reflected > automatically in the graphic as well. However, suppose you wrap the DynamicModule in a function like so: foo[data_] := DynamicModule[{size = 300}, > Column[{ > Slider[Dynamic[size], {100, 500}], > Dynamic@PieChart[data, ImageSize -> size] > }] > ] Now evaluate foo[ data ] If you change the definition of data in the notebook, the second > DynamicModule doesn't update the pie charts. I don't understand what > breaks when you wrap the DynamicModule in a function definition. > Jason > -- > 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: Re: Point Symbol and Mesh Tom Dowling > > ith[{m = 1000, c = 10}, > Plot[m x + c, {x, 0, 101}, Mesh -> {Range[40, 100, 10]}, > MeshStyle -> {PointSize[Large], Red}]] /. > Point[xy_] :> (Text[[FilledUpTriangle], #] & /@ xy) > > ?? > > Jens > > > Is there any easy way of changing the Point Symbol given with Mesh from a > circle to, say, a > square or a triangle? An example is given in the following code: > > With[{m = 1000, c = 10}, > Plot[m x + c, {x, 0, 101}, Mesh -> {Range[40, 100, 10]}, > MeshStyle -> {PointSize[Large], Red}]] > > > What I would like to do is to superimpose two or more plots, with each > line > having a different symbol (circle, square, triangle ... ) for > the points generated by Mesh. > > I am aware of PlotMarkers, but this only seem to apply to ListPlot. > > > > Thomas Dowling. > > > > === Subject: Re: Point Symbol and Mesh ith[{m = 1000, c = 10}, Plot[m x + c, {x, 0, 101}, Mesh -> {Range[40, 100, 10]}, MeshStyle -> {PointSize[Large], Red}]] /. Point[xy_] :> (Text[[FilledUpTriangle], #] & /@ xy) ?? Jens Is there any easy way of changing the Point Symbol given with Mesh from a > circle to, say, a > square or a triangle? An example is given in the following code: With[{m = 1000, c = 10}, > Plot[m x + c, {x, 0, 101}, Mesh -> {Range[40, 100, 10]}, > MeshStyle -> {PointSize[Large], Red}]] > What I would like to do is to superimpose two or more plots, with each line > having a different symbol (circle, square, triangle ... ) for > the points generated by Mesh. I am aware of PlotMarkers, but this only seem to apply to ListPlot. Thomas Dowling. === Subject: Re: Stop cell tags propagating to generated cells Hi David, thread, if you want to automatically remove the cell tags from all (and only) the output cells generated by an input cell, you simply need to change the second line in the definition of CellEpilog from SelectionMove[EvaluationNotebook[], Next, Cell]; to SelectionMove[EvaluationNotebook[], All, GeneratedCell]; Jason > > for a while... > > So I did a little bit of research and came up with a possible solution > (though I do wish that WRI would add an option to Cell to take care of > this directly). > > One way to handle this is to assign a CellEpilog option to the Input > cells in your notebook, either directly to those cells or at the > StyleSheet level. Here is an example of such an option that would > remove all the CellTags from the output cells that are a direct result > of executing the given Input cells. it could, of course, be modified > to custom tag those cells as well. Note though that this will change > the CellTags of any cell that immediately follows the Input cell, even > if no output is generated (and, for example, if error messages are > written after the Input cell it would only remove the CellTags from > the first of those). So perhaps you would want to customize this to > behave as you wish it to for your purposes... but I think it's a > decent starting point... > > Here is the option setting: > > > CellEpilog :> ( > SelectionMove[EvaluationNotebook[], After, EvaluationCell]; > SelectionMove[EvaluationNotebook[], Next, Cell]; > SetOptions[NotebookSelection[EvaluationNotebook[]], CellTags -> {}]) > > > 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/ > > > >> Is there a way to stop cell tags that have been manually added to an >> input cell from being automatically assigned to the generated output >> cell? I ask because I have been creating interactive panels for >> controlling Java models (using J/Link) and would like to be able to >> programmatically toggle the CellOpen status of the lengthy >> DynamicModule[...] code. >> >> >> Jason >> >> -- >> 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: Extending ColorData Is there a way to extend ColorData in a way that it will integrate nicely with the rest of the system? E.g. define a new gradient newGradient so that it will get listed by ColorData[Gradients], it will appear in the colour schemes palette, and DensityPlot[ ... , ColorFunction -> newGradient] will work. Is this possible? === Subject: Re: Tracking a dynamic variable One of the optimizations of the Dynamic system (and a very good one if you consider it for a while) is that no Dynamic will update unless it's visible. In the case of TabView, this means that no tab will update unless that tab is presently selected. Since Dynamic is generally about enabling interactivity on an area of your screen, it's a good thing not to spin CPU cycles for things which aren't presently being displayed. I'm uncertain how much to read into the details of your example to see how clever you were trying to be. Possibly, you thought that by leaving flag1 unscoped by anything except the outer Dynamic, thereby forcing the entire TabView to reevaluate, you would force the undelayed rule for task 2 to evaluate. Well, that does happen, but Dynamic of anything merely evaluates to itself. I.e., if you evaluate... Dynamic[2+2] it evaluates *not* to 4, but to Dynamic[2+2]. The computation which returns 4 does not happen until the Dynamic is displayed to the screen. Since, in your example, the second tab is never displayed to the screen, the computation in the Dynamic never happens. Also, your example as at least one bug in it... Dynamic[x=y; If[x!=y, flag1=True]] will virtually never set flag1 to True because the If[] check always evaluates immediately after the x=y. I would have expected something more like this, perhaps... Dynamic[If[x != y, y=x; (* do work *)]] I'm still guessing as to your exact intent, but I think you basically have two options here... * Restructure the code in the Dynamic so that everything can occur in a single Dynamic. It's not clear to me from your example that this is impossible. * Use a second Dynamic whose output is invisible...the Dynamic is onscreen, but has no apparent visual effect. The invisible Dynamic technique would look something like this... Row[{Dynamic[(* real output *)], Dynamic[ (* some computations *); ]}] So the Dynamic does get displayed to the screen, and updated every time the first Dynamic is, but what actually gets displayed is an empty string, and therefore not noticeable. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Hello > > I have a larger program in which I want to look if a value > of a dynamic variable has changed. > > A short version of this program looks like this: > > Interpretation[{x = 1, y = 1, flag1 = False, flag2 > False}, > > TabView[{ > task 1 -> > Dynamic[ > Block[{}, > > (* store old value of x *) > y = x; > > (* test if x changed *) > If[x != y, flag1 = True]; > > (* display input and some outout *) > Panel[ > Grid[ > {{ > InputField[Dynamic[x]], > Dynamic[x], > Dynamic[y], > flag1 > }} > ] > ] > ] > ], > task 2 -> > Dynamic[ > Block[{}, > If[x == y, > flag2 = True, > flag2 = False > ]; > Panel[ > Grid[ > {{x, y, flag1, flag2}} > ] > ] > ] > ] > } > ], > > > Print[end] > > ] > > I want to track the variable x and if it has changed in > task 1 an appropriate action should be accomplished in > task 2. > > The program above works only if for the input in task 1 > the Return key is not pressed in the InputField. If I > press Return in the InputField the whole task 1 is > executed and then y will be equal to x in any case. > > Now how can I track the value of x so that I can decide in > task 2 that x has changed? > > Matthias === Subject: Problem in Evaluate/Manipulate I have a problem with this code: Solution =DSolve[{x^[Prime][t]==a x[t]+b y[t],y^[Prime][t]==c x[t]+d y[t],x[0]==x0,y[0]==-10},{x[t],y[t]},t]; Manipulate[ Solutions = Evaluate [Table[{x[t],y[t]}/.Solution[[1]], {x0,-10,10,10}]] ,{a,-1,1},{b,-1,1},{c,-1,1},{d,-1,1}] I want to solve only one time the PDE, then I placed it outside the Manipulate. The code doesn't evaluate the solution with the dynamic values. === Subject: Re: Problem in Evaluate/Manipulate Hello Wiso, I believe your error is with the first statement, if you leave off the ; you will see why. Try this instead: Solution = DSolve[{D[x[t], t] == a x[t] + b y[t], D[y[t], t] == c x[t] + d y[t], x[0] == x0, y[0] == -10}, {x[t], y[t]}, t] > I have a problem with this code: > > Solution =DSolve[{x^[Prime][t]==a x[t]+b y[t],y^[Prime][t]==c x[t]+d > y[t],x[0]==x0,y[0]==-10},{x[t],y[t]},t]; > > Manipulate[ > Solutions = Evaluate [Table[{x[t],y[t]}/.Solution[[1]], > {x0,-10,10,10}]] > ,{a,-1,1},{b,-1,1},{c,-1,1},{d,-1,1}] > === Subject: Re: Problem in Evaluate/Manipulate > I have a problem with this code: Solution =DSolve[{x^[Prime][t]==a x[t]+b y[t],y^[Prime][t]==c x[t]+d > y[t],x[0]==x0,y[0]==-10},{x[t],y[t]},t]; Manipulate[ > Solutions = Evaluate [Table[{x[t],y[t]}/.Solution[[1]], > {x0,-10,10,10}]] > ,{a,-1,1},{b,-1,1},{c,-1,1},{d,-1,1}] I want to solve only one time the PDE, then I placed it outside the > Manipulate. The code doesn't evaluate the solution with the dynamic > values. > Evaluate only overrides HoldFirst, etc. attributes when it appears directly as the head of the function argument that would otherwise be held. This will work: Manipulate[ Evaluate[Solutions = Table[{x[t], y[t]} /. Solution[[1]], {x0, -10, 10, 10}]], {a, -1, 1}, {b, -1, 1}, {c, -1, 1}, {d, -1, 1}] === Subject: Re: Problem in Evaluate/Manipulate > I have a problem with this code: > > Solution =DSolve[{x^[Prime][t]==a x[t]+b y[t],y^[Prime][t]==c x[t]+d > y[t],x[0]==x0,y[0]==-10},{x[t],y[t]},t]; > > Manipulate[ > Solutions = Evaluate [Table[{x[t],y[t]}/.Solution[[1]], > {x0,-10,10,10}]] > ,{a,-1,1},{b,-1,1},{c,-1,1},{d,-1,1}] > > I want to solve only one time the PDE, then I placed it outside the > Manipulate. The code doesn't evaluate the solution with the dynamic > values. now the problem is to plot with ParametricPlot. Inside the manipulate I do: Evaluate[Solutions = [Table[{x[t],y[t]}/.Solution[[1]], {x0,-10,10,10}]]]; ParametricPlot[Solutions,{t,0,10}] but it doesn't work. === Subject: Re: Problem in Evaluate/Manipulate try Manipulate[ Solutions = Evaluate[Table[{x[t], y[t]} /. Solution[[1]] /. {a -> aa, b -> bb, c -> cc, d -> dd, x0 -> xx0}, {xx0, -10, 10, 10}]], {aa, -1, 1}, {bb, -1, 1}, {cc, -1, 1}, {dd, -1, 1}] Jens > I have a problem with this code: Solution =DSolve[{x^[Prime][t]==a x[t]+b y[t],y^[Prime][t]==c x[t]+d > y[t],x[0]==x0,y[0]==-10},{x[t],y[t]},t]; Manipulate[ > Solutions = Evaluate [Table[{x[t],y[t]}/.Solution[[1]], > {x0,-10,10,10}]] > ,{a,-1,1},{b,-1,1},{c,-1,1},{d,-1,1}] I want to solve only one time the PDE, then I placed it outside the > Manipulate. The code doesn't evaluate the solution with the dynamic > values. > === Subject: PlotLegend not working properly in my Mathematica 6 The PlotLegend option is not working in my Mathematica 6.0. I can't even run the codes provided in the Document center. I got similar errors when running my own codes. http://yangli.public.iastate.edu/PlotLegend.pdf === Subject: Re: PlotLegend not working properly in my Mathematica 6 Yes, super-annoying. I just do the following: ptemp=Plot[{func1[...], func2[...],func3[...]}, {x,0,2 Pi}, DisplayFunction->Identity, PlotStyle->{{Blue,Thickness[0.01]},{Brown,Thickness[0.01]}, {Red,Thickness[0.01]}}, PlotRange->All, Frame->True, ...]; ShowLegend[ptemp, {{{Blue,Style[func1,Black]}, {Brown,Style[func2,Black]}, {Red,Style[func3,Black]}}, LegendPosition->{0.9,0.},LegendTextSpace->5,LegendSize->{0.8,0.3}}] === Subject: Re: PlotLegend not working properly in my Mathematica 6 Did you evaluate the Needs statement? It works for me on Version 6.0.2, except that the PlotLegend and LegendPosition options show up in red because SyntaxInformation for Plot and ListPlot doesn't know about these options. But they work anyway. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > The PlotLegend option is not working in my Mathematica 6.0. I can't even > run the codes provided in the Document center. I got similar errors when > running my own codes. > > > http://yangli.public.iastate.edu/PlotLegend.pdf > === Subject: Re: PlotLegend not working properly in my Mathematica 6 You have not evaluated the statement Needs[PlotLegends`] before evaluating ListPlot[Table[{x, f[x]}, {f, {Sin, Cos, Log}}, {x, 0, 10, 0.5}], PlotLegend -> {Sine, Cosine, Log}, LegendPosition -> {1.1, -0.4}, Joined -> {True, True, False}, PlotMarkers -> Automatic] So the required functions are not yet available. Start a new session of Mathematica, load the package and then you will get the expected result. 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 > The PlotLegend option is not working in my Mathematica 6.0. I can't > even run the codes provided in the Document center. I got similar > errors when running my own codes. > > > http://yangli.public.iastate.edu/PlotLegend.pdf > === Subject: Re: PlotLegend not working properly in my Mathematica 6 you must evaluate the Needs[PlotLegends] command before you ca uses it. Jens > The PlotLegend option is not working in my Mathematica 6.0. I can't even run the codes provided in the Document center. I got similar errors when running my own codes. > http://yangli.public.iastate.edu/PlotLegend.pdf > === Subject: Re: PlotLegend not working properly in my Mathematica 6 > The PlotLegend option is not working in my Mathematica 6.0. I can't even run the codes provided in the Document center. I got similar errors when running my own codes. > http://yangli.public.iastate.edu/PlotLegend.pdf > You probably didn't load the package. Evaluate << PlotLegends` first. === Subject: Re: Display commands in a package First: One of the purposes of a package is, in fact, to shield the user from seeing the internal definitions of objects in that package (especially since the internal definitions might change in subsequent versions yet the functionality remain the same, or at least backward-compatible). Typically, a package keeps only a stub for a definition within the non-private context of the package. Second: For some key packages, the code is simply not available in usual package format, i.e., in human-readable form. This is the case, I believe, with Graphics`, which does have a very short readable .m file you can look at, but essentially nothing of direct interest within it; everything seems to be done at a lower level, probably in some compiled code. This may be for reasons of property protection and/or efficiency. But for a number of other packages, the .m file is right there in the Mathematica file tree. This is the case, for example, with the Combinatorica` package. You can simply open the file and read it -- in a text editor if you really wish; by opening it within Mathematica itself (File > Open, or just dragging the file to the Mathematica menu bar); or in Wolfram Workbench (which I often find provides the most attractive and useful way to view a package when you don't have a source notebook that created it). > In Mathematica, when I load a package, for instance < system load many commands, but Mathematica doesn't display those commands in > the package, how can I see them if I do not want to look into package > document? -- 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: Display commands in a package Hello Budaoy, This is an example of what I think you are looking for: ?Combinatorica`* Needs[Combinatorica`] ?Combinatorica`* > In Mathematica, when I load a package, for instance < system load many commands, but Mathematica doesn't display those commands in > the package, how can I see them if I do not want to look into package > document? > > > -- W. Craig Carter === Subject: Display commands in a package In Mathematica, when I load a package, for instance < In Mathematica, when I load a package, for instance < system load many commands, but Mathematica doesn't display those commands in > the package, how can I see them if I do not want to look into package > document? > The only way to see all symbols used in a package file is to open up the file with a text editor. But if you only want the symbols from a _context_, then you can use Information[]: (* Load Combinatorica package *) << Combinatorica` (* List all symbols from the Combinatorica` context *) ? Combinatorica`* Since most packages put all exported symbols in a single context, this will give what you need most of the time. === Subject: Re: Display commands in a package You can do the following: << BarCharts` ?BarCharts`* which gives a list of the exported symbols from the package. Clicking on anyone gives the usage message. Getting to the Guide page is a little more difficult. If you click BarChart you will obtain a usage message with a link to the Function page. Bringing up the BarChart Function page you can get a link to the package Guide page through the More About section, either at the top or bottom of the page. But other names such as BarStyle do not have a direct link to the package Guide page. It is interesting that if one types 'BarCharts' into the Documentation Center search input then the BarCharts Guide page appears only on the second page of the listing. But if one types 'Bar Charts Package' it appears first on the list. I think it would be very nice if the Documentation Center had a link to a standard packages Guide page right next to the Installed Add-Ons link. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > In Mathematica, when I load a package, for instance < the > system load many commands, but Mathematica doesn't display those commands > in > the package, how can I see them if I do not want to look into package > document? > > === Subject: Re: Display commands in a package > You can do the following: << BarCharts` ?BarCharts`* > V6.02 XP machine. With a fresh kernel this works ok - no error messages. << BarCharts` But in response to this line ?BarCharts`* I get: Syntax::sntxf: ? cannot be followed by BarCharts`*. Syntax::tsntxi: BarCharts`* is incomplete; more input is needed. Syntax::sntxi: Incomplete expression; more input is needed. Do you have any thoughts on why my machine won't respond === Subject: Re: Display commands in a package > In Mathematica, when I load a package, for instance < system load many commands, but Mathematica doesn't display those commands in > the package, how can I see them if I do not want to look into package > document? Packages create one or more public contexts. These can be revealed by the command: Contexts[Graphics`*] Since you are probably only interested in one of these contexts (and simpler packages often only create one context) it is best to pick one context and get a list of the symbols it contains, for example: ?Graphics`Shapes`* Note that not every symbol will be an actual command. As your question implies, this technique is often more convenient that ploughing through the entire package documentation. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Display commands in a package > In Mathematica, when I load a package, for instance < system load many commands, but Mathematica doesn't display those commands in > the package, how can I see them if I do not want to look into package > document? Not totally sure whether this is what you are looking for, but you can list the hierarchy of symbols within a context by adding more back quote + star characters to the name of the context. Well, for instance, try the following and you will see the differences: Needs[Graphics`] ?Graphics`* ?Graphics`*`* -- Jean-Marc === Subject: Re: TreePlots and GraphPlots And not that once the TreePlot is displayed, you may want to move the leaves around a bit so as to keep their labels better separated. YOu can do this by double-clicking on the graphic that gives a particular vertex label and just drag it to a new position. > I have a question regarding TreePlot and GraphPlots. I have the following >> list : >> myList1 = {{1.9124437047927545`, 2.140934695277407`, >> 2.4290608973234304`}, {3.1220434925197633`}, {3.193277882536842`, >> 3.321086033303083`, 3.3624160109272454`}, {3.8240882444935016`, >> 4.778362811870326`}} >> >> One of the elements in this list is set as the root node for a tree - based >> structure. For instance : >> treeRoot = myList1[[2]] >> >> Based on the list above : I would like the root node will have 3 children >> The first child has 3 leaf nodes >> {1.9124437047927545`, 2.140934695277407`, 2.4290608973234304`}, the second >> child has three leaf nodes >> {3.193277882536842`, 3.321086033303083`, 3.3624160109272454`} and finally >> the third child has 2 leaf nodes : >> {3.8240882444935016`, 4.778362811870326`}. >> >> In other words, I am trying to represent myList1 in a tree structure. I am >> not able to create a list of rules for the tree. Any suggestions/ >> ideas would be great. The following may suit your needs. myList1 = {{1.9124437047927545`, 2.140934695277407`, > 2.4290608973234304`}, {3.1220434925197633`}, {3.193277882536842`, > 3.321086033303083`, 3.3624160109272454`}, {3.8240882444935016`, > 4.778362811870326`}}; myList2 = > Thread[Table[myList1[[2]], {Length[myList1] - 1}] -> > Delete[myList1, 2]] TreePlot[myList2, VertexLabeling -> True] {{3.12204} -> {1.91244, 2.14093, > 2.42906}, {3.12204} -> {3.19328, 3.32109, > 3.36242}, {3.12204} -> {3.82409, 4.77836}} [... Tree plot deleted ...] -- Jean-Marc > -- 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: TreePlots and GraphPlots > I have a question regarding TreePlot and GraphPlots. I have the following > list : > myList1 = {{1.9124437047927545`, 2.140934695277407`, > 2.4290608973234304`}, {3.1220434925197633`}, {3.193277882536842`, > 3.321086033303083`, 3.3624160109272454`}, {3.8240882444935016`, > 4.778362811870326`}} One of the elements in this list is set as the root node for a tree - based > structure. For instance : > treeRoot = myList1[[2]] Based on the list above : I would like the root node will have 3 children > The first child has 3 leaf nodes > {1.9124437047927545`, 2.140934695277407`, 2.4290608973234304`}, the second > child has three leaf nodes > {3.193277882536842`, 3.321086033303083`, 3.3624160109272454`} and finally > the third child has 2 leaf nodes : > {3.8240882444935016`, 4.778362811870326`}. In other words, I am trying to represent myList1 in a tree structure. I am > not able to create a list of rules for the tree. Any suggestions/ > ideas would be great. The following may suit your needs. myList1 = {{1.9124437047927545`, 2.140934695277407`, 2.4290608973234304`}, {3.1220434925197633`}, {3.193277882536842`, 3.321086033303083`, 3.3624160109272454`}, {3.8240882444935016`, 4.778362811870326`}}; myList2 = Thread[Table[myList1[[2]], {Length[myList1] - 1}] -> Delete[myList1, 2]] TreePlot[myList2, VertexLabeling -> True] {{3.12204} -> {1.91244, 2.14093, 2.42906}, {3.12204} -> {3.19328, 3.32109, 3.36242}, {3.12204} -> {3.82409, 4.77836}} [... Tree plot deleted ...] -- Jean-Marc === Subject: EventHandler problem I'm trying to design a custom InputField that indicates whether or not the user has pressed Return to submit the changes. It's a simple design: a red or green disk is drawn to the right of the InputField to indicate the state. Here's the definition of the disks: red = Graphics[{Green, AbsolutePointSize[12], Point[{0, 0}]}, ImageSize -> {20, Automatic}] green = Graphics[{Green, AbsolutePointSize[12], Point[{0, 0}]}, ImageSize -> {20, Automatic}] Here's my first attempt at creating the InputField: DynamicModule[{k = 1, changed = False}, Row[{ EventHandler[ InputField[Dynamic[k], Number, FieldSize -> Tiny, ContinuousAction -> True], {KeyDown :> (changed = True), ReturnKeyDown :> (changed = False) }, PassEventsDown -> True ], Dynamic[If[changed, red, green]] }] ] Everything works except setting the value of changed back to False when the Return key is pressed. Mathematica fires the action for *both* KeyDown and ReturnKeyDown, and the KeyDown action is invoked after the ReturnKeyDown action. (This happens regardless of whether one uses {KeyDown :> (...), ReturnKeyDown :> (...) } or {ReturnKeyDown :> (...) KeyDown :> (...)} in the argument to EventHandler.) I've tried detecting the value of the key by using CurrentValue[EventKey] but this doesn't seem to do anything... Any thoughts on how to solve this problem would be greatly appreciated! Jason -- 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: issues with unit package Why won't Mathematica when using the Units package eliminate reciprocal units? Consider an example from E&M, finding the wavelength corresponding to a frequency: < Why won't Mathematica when using the Units package eliminate reciprocal units? Consider an example from E&M, finding the wavelength corresponding to a frequency: < < Freq=100*^6 Hertz; > Wavelength=SpeedOfLight/Freq > Out[1]=(149896229*Meter)/(50000000*Hertz*Second) > In[2]:=N[Wavelength] > Out[2]=(0.299792*Meter)/(Hertz*Second) i.e. Mathematica doesn't know that Meter/(Hertz Second) should reduce to Meter. Shouldn't this be handled? Another example; shouldn't Mathematica reduce expressions in consistent units to a single result? Example: In[5]:=3 Ohm + 1 Volt/Ampere > Out[5] = 3 Ohm + 1 Volt/Ampere Why not 4 Ohm, or 4 Volt/Ampere? After all, the documentation entry for Ohm says it's equivalent to Volt / Ampere, so it's reasonable that Mathematica would be aware of that relationship. Doing SI[] or MKS[] on those expressions doesn't change anything. Maybe the Units package doesn't extend to manipulating variables with quantities that have units. Am I missing something here? > I don't think that a completely automatic reduction of units would be possible. But it would be nice if the Units package provided a function to convert units to one or more canonical forms. This will work in many (but not all) cases: toCanonical[expr_] := SI[expr] //. Units`Private`$ToFundamental In[5]:= toCanonical[3 Ohm + 1 Volt/Ampere] Out[5]= (4 Kilogram Meter^2)/(Ampere^2 Second^3) In[6]:= toCanonical[(0.299792*Meter)/(Hertz*Second)] Out[6]= 0.299792 Meter It is not always clear what the appropriate unit is in certain situations. For example what is the appropriate unit for the torque? Joule is certainly correct dimensionally, but is it reasonable to use it? === Subject: Re: issues with unit package Mathematica does not automatically apply unit conversions just because you have loaded the Units package. How would it know what form of units you wanted? You have to tell it to convert units with the Convert statement. Needs[Units`] Needs[PhysicalConstants`] Freq = 100*^6 Hertz; Wavelength = SpeedOfLight/Freq Convert[N[Wavelength], Meter] giving (149896229 Meter)/(50000000 Hertz Second) 2.99792 Meter 3 Ohm + 1 Volt/Ampere; Convert[%, Ohm] 4 Ohm I'm not certain why SI did not do anything on the second example. Apparently there is a difference between SI units and base SI units. If you use the ExtendUnits6` package from my web site you can use BaseSI and ToUnit as a postfix method of converting: Needs[Units6`ExtendUnits6`] 3 Ohm + 1 Volt/Ampere; % // BaseSI % // ToUnit[Ohm] (4 Kilogram Meter^2)/(Ampere^2 Second^3) 4. Ohm With ExtendUnits6 you can also set up reduced units. Let's set up a system where the ElectronCharge and SpeedOfLight are both set to 1. SetupReducedUnits[{ElectronCharge, SpeedOfLight}, {Meter, Kilogram, Kelvin}] {Ampere -> 2.08194*10^10/Meter, Second -> 2.99792*10^8 Meter} Then we can take you second example through various equivalent reduced units. 3 Ohm + 1 Volt/Ampere; % // ReducedUnits ReducedEquivalent[%, Kilogram Meter, Volt Meter] ReducedEquivalent[%, Volt Meter, Ohm] 3.425*10^-46 Kilogram Meter 1.92128*10^-10 Meter Volt 4. Ohm -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Why won't Mathematica when using the Units package eliminate reciprocal > units? Consider an example from E&M, finding the wavelength > corresponding to a frequency: > > < < > In[1]:= > Freq=100*^6 Hertz; > Wavelength=SpeedOfLight/Freq > Out[1]=(149896229*Meter)/(50000000*Hertz*Second) > In[2]:=N[Wavelength] > Out[2]=(0.299792*Meter)/(Hertz*Second) > > i.e. Mathematica doesn't know that Meter/(Hertz Second) should reduce to > Meter. Shouldn't this be handled? > > Another example; shouldn't Mathematica reduce expressions in consistent > units to a single result? Example: > > In[5]:=3 Ohm + 1 Volt/Ampere > Out[5] = 3 Ohm + 1 Volt/Ampere > > Why not 4 Ohm, or 4 Volt/Ampere? After all, the documentation entry for > Ohm says it's equivalent to Volt / Ampere, so it's reasonable that > Mathematica would be aware of that relationship. Doing SI[] or MKS[] on > those expressions doesn't change anything. > > Maybe the Units package doesn't extend to manipulating variables with > quantities that have units. Am I missing something here? > > === Subject: Tooltip I have a couple of questions: I have the following list created randomly: temp1 = {0.3377278960765553`, 0.4632334331676402`, 0.5932704226124306`, 0.802585815014663`, 0.13570050876228246`, 0.6138050447094408`, 0.337386117458901`}; Based on some prior computations and functions, I get the following: temp2= {0.135701 -> 0.337386, 0.337386 -> 0.337728, 0.337728 -> 0.463233, 0.463233 -> 0.802586, 0.59327 -> 0.613805, 0.613805 -> 0.802586, 0.802586 -> 0.802586} temp3 = Map[Flatten[Position[myList1, #]] &, #] & /@ temp2 TreePlot[temp3, VertexLabeling -> True, SelfLoopStyle -> False] Q1) However, I want the nodes to be labeled as 1, 2, 3 .. instead of {1}, {2}, {3}. Q2) I would like to add a tooltip command to the tree plot such that when I move the mouse on top of the nodes I get the corresponding value from temp1. For instance, if I move the mouse on Node2 I should get a label of 0.4632334331676402` and if I move the mouse on Node7 I get a label of 0.337386117458901 Q3) The node with the maximum value of temp1 should be a different color. In this situation Node2 will have the maximum value and therefore should be a different color. How can the above be accomplished. Any hints and pointers will be of great help. === Subject: Re: issues with unit package >Why won't Mathematica when using the Units package eliminate >reciprocal units? Consider an example from E&M, finding the >wavelength corresponding to a frequency: ><In[1]:= >Freq=100*^6 Hertz; Wavelength=SpeedOfLight/Freq >Out[1]=(149896229*Meter)/(50000000*Hertz*Second) >In[2]:=N[Wavelength] Out[2]=(0.299792*Meter)/(Hertz*Second) >i.e. Mathematica doesn't know that Meter/(Hertz Second) should >reduce to Meter. Shouldn't this be handled? This can be handled as follows: In[4]:= (149896229*Meter)/(50000000*Hertz* Second) /. Units`Private`$ToFundamental Out[4]= (149896229 Meter)/50000000 === Subject: Re: Bug in Plot? >But this causes Mathematica on my machine to hang indefinitely: >a = 0.0025; Plot[1 - Exp[-a * t], {t, 50, 1000}] I have no difficulty with this using In[12]:= {$Version, $ReleaseNumber} Out[12]= {6.0 for Mac OS X PowerPC (32-bit) (March 13, 2008), 2} === Subject: Inputs to Functions - Can they be FORCED to be a predefined type? Fri 9 May 2008 Hello All, I have a strange problem for which there might well be no solution. A simplified version of the problem is this. I would like people who use my system to be able to specify time durations though symbols. For example: dN where N is an integer means N days. So d10 means 10 days. wN means N weeks. So w5 means 5 weeks which is translated into 5 * 5 = 25 days (assuming 5 days per week). I want these string designations for time (e.g. d10 and w5) to be an input to a function (called myFunction) that the user has access to. So far, so good. But, for ease of use, I would prefer that the user not have to remember to use string quote symbols around the duration symbol (like w5) as input to myFunction. This is not a problem if the symbol w5 has not already been defined outside of myFunction. It's head will be Symbol and I can use ToString on it within myFunction so that it would be as if it had been input as the string w5. BUT, if w5 has already been defined before it is used as input to myFunction, that is obviously a problem - . myFunction won't recognize it as w5. Is there a way to define myFunction in such a way that any w5 [or any other duration symbol such as d20 or w12] given to it as input will be interpreted as the String w5. In other words, is there a way to define the input to myFunction so that it FORCES any w5 given to it to be the String w5 OR the UNDEFINED Symbol w5 - even if it had been previously defined outside of myFunction? Don === Subject: Conjugate of Symbolic Expression How can I get the conjugate of following symbolic expression: !((-[ExponentialE]^(2 [ImaginaryI] [Phi]_2)) (([ExponentialE] ^(2 [ImaginaryI] [CapitalDelta]_D) Cos[[Theta]_s]^2 + Sin[[Theta]_s]^2)) m_2 + [ExponentialE]^([ImaginaryI]* [Phi]_3) m_3) I used the following function but it doesn't work: !(Refine[ Conjugate[(-[ExponentialE]^(2 [ImaginaryI] [Phi]_2)) (( [ExponentialE]^(2 [ImaginaryI] [CapitalDelta]_D) Cos[[Theta]_s]^2 + Sin[[Theta]_s]^2)) m_2 + [ExponentialE]^([ImaginaryI]*[Phi]_3) m_3], [CapitalDelta]_D [Element] Reals && [Phi]_2 [Element] Reals && [Phi]_3 [Element] Reals && m_2 [Element] Reals && m_3 [Element] Reals && [Theta]_s [Element] Reals]) === Subject: How to avoid overflow or underflow in mathematica? It's well known that Mathematica can do evaluation to arbitrary precision. But I don't know how to avoid the following trouble in computing: Ef = 0.; mu=0.; KBT = 1.*10^-10; FL[omega_Real] := 1./(1. + E^((omega - mu - Ef)/KBT)); the error message shows General::ovfl: Overflow occurred in computation. >> General::unfl: Underflow occurred in computation. >> === Subject: Re: Intersection of surfaces On May 8, 3:29 am, Jens-Peer Kuska > > TUBE = {.6 Cos[V], 2 U + 3, .6 Sin[V] + 2}; > tube = ParametricPlot3D[TUBE, {U, -1.2, .2}, {V, 0, 2 Pi}, > PlotPoints -> {10, 25}]; > BOWL = {p Cos[q], p^2/2, p Sin[q]}; > bowl = ParametricPlot3D[BOWL, {p, 1, 2.75}, {q, 0, 2 Pi}, > PlotPoints -> {20, 35}]; > > and > > eqn = Eliminate[{TUBE == {x, y, z} // Thread, > BOWL == {x, y, z} // Thread} // Flatten, {p, q, U}]; > > and > sol = Solve[eqn, {x, y, z}]; > > gives > > {{y -> 0.02 (100.+ 9. Cos[V]^2 + 60. Sin[V] + 9. Sin[V]^2), > x -> 0.6 Cos[V], z -> 0.2 (10.+ 3. Sin[V])}} > > and > > ll = ParametricPlot3D[{x, y, z} /. sol[[1]], {V, 0, 2 Pi}]; > > Show[bowl, tube, > ll /. l_Line :> {AbsoluteThickness[4], RGBColor[1, 0, 0], l}] > > show that the result is right. > > Jens > > How to find the space curve formed by intersecting 3D patches in > simple cases like: > > TUBE = {.6 Cos[V], 2 U + 3, .6 Sin[V] + 2}; > tube = ParametricPlot3D[TUBE, {U, -1.2, .2}, {V, 0, 2 Pi}, PlotPoints - >> {10, 25}] > BOWL = {p Cos[q], p^2/2, p Sin[q]}; > bowl = ParametricPlot3D [ BOWL, {p, 1, 2.75}, {q, 0, 2 Pi}, PlotPoints > -> {20, 35}] > Show[bowl, tube] > > or in slightly more complicated surface cases like: > > terr = ParametricPlot3D[{Cos[u + 1] Cos[v + 2.1], 0.6 + u^2/3,Exp[-v/ > 4] }, {v, -3, 3}, {u, -3, 3}, PlotPoints -> {45, 30}] > Show[terr, tube] > > How to solve for x,y and z from {0.6 Cos[V] == p Cos[q], 3 + 2 U == > p^2/2, 2 + 0.6 Sin[V] == p Sin[q]} obtaining t as a function of (U,V,p > and q) so as to be able to Show with > > ParametricPlot3D[{x[t], y[t], z[t]},{t,tmin,tmax}]? > > Narasimham So saw this post and found if useful for something I was doing. But as I looked at the suggested code, I was not sure why thread and flatten were used in this particular case. So I deleted them one at a time and still got the same answer. What is the difference then between. TUBE = {.6 Cos[V], 2 U + 3, .6 Sin[V] + 2}; tube = ParametricPlot3D[TUBE, {U, -1.2, .2}, {V, 0, 2 Pi}, PlotPoints -> {10, 25}]; BOWL = {p Cos[q], p^2/2, p Sin[q]}; bowl = ParametricPlot3D[BOWL, {p, 1, 2.75}, {q, 0, 2 Pi}, PlotPoints -> {20, 35}]; eqn = Eliminate[{TUBE == {x, y, z} // Thread, BOWL == {x, y, z} // Thread} // Flatten, {p, q, U}] eqn1 = Eliminate[{TUBE == {x, y, z}, BOWL == {x, y, z}} // Flatten, {p, q, U}] eqn2 = Eliminate[{TUBE == {x, y, z}, BOWL == {x, y, z}}, {p, q, U}] sol = Solve[eqn, {x, y, z}] sol1 = Solve[eqn1, {x, y, z}] sol2 = Solve[eqn2, {x, y, z}] ll = ParametricPlot3D[{x, y, z} /. sol[[1]], {V, 0, 2 Pi}]; l11 = ParametricPlot3D[{x, y, z} /. sol1[[1]], {V, 0, 2 Pi}]; l12 = ParametricPlot3D[{x, y, z} /. sol2[[1]], {V, 0, 2 Pi}]; Show[bowl, tube, ll /. l_Line :> {AbsoluteThickness[4], RGBColor[1, 0, 0], l}] Show[bowl, tube, l11 /. l_Line :> {AbsoluteThickness[4], RGBColor[1, 0, 0], l}] Show[bowl, tube, l12 /. l_Line :> {AbsoluteThickness[4], RGBColor[1, 0, 0], l}] === Subject: Re: DynamicModule question > >> Can someone please explain to me why the following happens? It's a >> silly little example to illustrate a problem I ran into recently... >> >> First, evaluate the following in separate cells: >> >> Needs[PieCharts`]; >> >> data = {.25, .75} >> >> Then evaluate the following: >> >> DynamicModule[{size = 300}, >> Column[{ >> Slider[Dynamic[size], {100, 500}], >> Dynamic[PieChart[data, ImageSize -> size]] >> }] >> ] >> >> Notice that you can not only resize the graphic by dragging the >> slider, but if you change the definition of data, that's reflected >> automatically in the graphic as well. >> >> However, suppose you wrap the DynamicModule in a function like so: >> >> foo[data_] := DynamicModule[{size = 300}, >> Column[{ >> Slider[Dynamic[size], {100, 500}], >> Dynamic@PieChart[data, ImageSize -> size] >> }] >> ] >> >> Now evaluate >> >> foo[ data ] >> >> If you change the definition of data in the notebook, the second >> DynamicModule doesn't update the pie charts. I don't understand what >> breaks when you wrap the DynamicModule in a function definition. >> > Try > > Dynamic@foo[data] > > Now, why Dynamic is needed here? I do not know. Looking at the > expressions in the output cells (Shift + Cmd + E ) for the code > generated by entering directly the DynamicModule or by using a function > both resulting expressions look very similar (even identical, as far as > I can trust my sight :-) > > -- Jean-Marc Jens knows the answer (his reply to this thread was quite correct), but he expects the student to do all the work to figure out why his solution works. :) I'll provide you some hints. It has to do with evaluation order. When you evaluate foo[data], 'data' evaluates before 'foo' ever sees it. The only thing 'foo' sees is {.25, .75}. Function scoping does a lexical replacement of the data_ variable, so the resulting Dynamic is actually... Dynamic@PieChart[{.25, .75}, ImageSize->size] That's not very helpful. The first example worked because 'data' wasn't a lexically scoped function variable, but a real variable which required evaluation. And no evaluation happens inside of Dynamic until it reaches the front end because Dynamic is HoldFirst. In your final example, Dynamic@foo[data] works because now, the variable data is evaluating inside the Dynamic. So, in the simplest case... a:=2; Function[{x},Dynamic[x]][a] (*creates a Dynamic which evaluates '2', *not* 'a'*) Function[{x},Dynamic[x],{HoldAll}][a] (*creates a Dynamic which evaluates 'a'*) John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. === Subject: Re: Request for Collective Wisdom... When defining a new function, have two windows open: one for building up the new function, and the other for trying out code to make sure it works before adding it to the function window. Don't try to do everything in one window. Seems wasteful at first but it's an enormous time saver in the long run. === Subject: Parameter conditions I'm just curious why the simple code below is not working. Why is happy[4] not returning the number 200 In[1]:= happy[p_?PrimeQ] = 100; happy[p_?Not[PrimeQ]] = 200; In[3]:= Inhappy[4] Out[3]:= happy[4] In[4]:= happy[5] Out[4]:= 100 === Subject: Re: Bug in Plot? Hello John, I can't reproduce it. It works as expected for me: Mac OS 10.4.11, intel 4GB math 6.0 64 bit kernel Have you checked your activity monitor or the command top to see if you have sufficient memory left? WCC > > But this causes Mathematica on my machine to hang indefinitely: > > a = 0.0025; Plot[1 - Exp[-a * t], {t, 50, 1000}] > > I have to quit and re-start the kernel to recover. > > Can anyone reproduce this behavior? If so, can anyone suggest why this > this. > > John Stone (v 6.0.2 / Mac OS-X 10.5.2) > > -- W. Craig Carter === Subject: Re: Bug in Plot? Hi John, I have just checked all four plots in the exact order you did and each gave the expected plot. Since my OS & Mathematica version seem to be identical to yours (with the possible exception of Mathematica 64 bit in my case, and I have a MacBook Pro) I can only point you to using a 64 bit kernel if you are not already doing so. 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 > a = 0.0025; Plot[1 - Exp[-a * t], {t, 50, 1000}] === Subject: Re: Bug in Plot? Works on 6.0.2.1 I think that this is the type of bug that the '.1' release fixed. george > which has worked on many previous versions suddenly broke. I seem to > have isolated the following problem: > > For me, this command produces a simple plot: > > a = 0.25; Plot[1 - Exp[-a * t], {t, 0, 10}] > > As does this: > > a = 0.25; Plot[1 - Exp[-a * t], {t, 0.5, 10}] > > As does this: > > a = 0.0025; Plot[1 - Exp[-a * t], {t, 0, 1000}] > > But this causes Mathematica on my machine to hang indefinitely: > > a = 0.0025; Plot[1 - Exp[-a * t], {t, 50, 1000}] > > I have to quit and re-start the kernel to recover. > > Can anyone reproduce this behavior? If so, can anyone suggest why > this > with > this. > > John Stone (v 6.0.2 / Mac OS-X 10.5.2) > === Subject: Bug in Plot? which has worked on many previous versions suddenly broke. I seem to have isolated the following problem: For me, this command produces a simple plot: a = 0.25; Plot[1 - Exp[-a * t], {t, 0, 10}] As does this: a = 0.25; Plot[1 - Exp[-a * t], {t, 0.5, 10}] As does this: a = 0.0025; Plot[1 - Exp[-a * t], {t, 0, 1000}] But this causes Mathematica on my machine to hang indefinitely: a = 0.0025; Plot[1 - Exp[-a * t], {t, 50, 1000}] I have to quit and re-start the kernel to recover. Can anyone reproduce this behavior? If so, can anyone suggest why this this. John Stone (v 6.0.2 / Mac OS-X 10.5.2) === Subject: Re: Bug in Plot? I had no problem with any of those examples on Windows Vista, Mathematica 6.0.2. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > which has worked on many previous versions suddenly broke. I seem to > have isolated the following problem: > > For me, this command produces a simple plot: > > a = 0.25; Plot[1 - Exp[-a * t], {t, 0, 10}] > > As does this: > > a = 0.25; Plot[1 - Exp[-a * t], {t, 0.5, 10}] > > As does this: > > a = 0.0025; Plot[1 - Exp[-a * t], {t, 0, 1000}] > > But this causes Mathematica on my machine to hang indefinitely: > > a = 0.0025; Plot[1 - Exp[-a * t], {t, 50, 1000}] > > I have to quit and re-start the kernel to recover. > > Can anyone reproduce this behavior? If so, can anyone suggest why this > this. > > John Stone (v 6.0.2 / Mac OS-X 10.5.2) > === Subject: HoldForm, TraditionalForm Bug? 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. HoldForm[x y - x^3 - 1] x y-x^3-1 But then I would also like to display it with TraditionalForm to obtain the single character italics. So I use: HoldForm[x y - x^3 - 1] // TraditionalForm -x^3+y x-1 (actually TraditionalForm but the terms rearranged) I regard it as a bug that Mathematica rearranges the order of the terms in this expression. Furthermore, if the expression were used in a Plot label, TraditionalForm is now automatically used and the terms will be rearranged. A workaround is to use: Style[HoldForm[x y - x^3 - 1], SingleLetterItalics -> True, FontFamily -> Times] x y-x^3-1 (looks like TraditionalForm) If I try to use this in a plot it is quite convoluted! ContourPlot[x y - x^3 + 1 == 0, {x, -5, 5}, {y, -10, 15}, Exclusions -> {x == 0}, PlotLabel -> (Style[HoldForm[V[x y - x^3 - 1]], SingleLetterItalics -> True, FontFamily -> Times] // StandardForm)] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: HoldForm, TraditionalForm Bug? > 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. HoldForm[x y - x^3 - 1] > x y-x^3-1 But then I would also like to display it with TraditionalForm to obtain the > single character italics. So I use: HoldForm[x y - x^3 - 1] // TraditionalForm > -x^3+y x-1 (actually TraditionalForm but the terms rearranged) I regard it as a bug that Mathematica rearranges the order of the terms in > this expression. Furthermore, if the expression were used in a Plot label, > TraditionalForm is now automatically used and the terms will be rearranged. A workaround is to use: Style[HoldForm[x y - x^3 - 1], SingleLetterItalics -> True, > FontFamily -> Times] > x y-x^3-1 (looks like TraditionalForm) If I try to use this in a plot it is quite convoluted! ContourPlot[x y - x^3 + 1 == 0, {x, -5, 5}, {y, -10, 15}, > Exclusions -> {x == 0}, > PlotLabel -> (Style[HoldForm[V[x y - x^3 - 1]], > SingleLetterItalics -> True, FontFamily -> Times] // > StandardForm)] > I think that you might find the following thread interesting: Unfortunately using Infix is not so simple in this case because we have both + and - signs. Another useful thing to know about is the undocumented function PolynomialForm, which has the TraditionalOrder option. It can override the default order in StandardForm or TraditionalForm: PolynomialForm[-1 - x^3 + x y, TraditionalOrder -> True] TraditionalForm[ PolynomialForm[-1 - x^3 + x y, TraditionalOrder -> False] ] I can only guess at how this function works (it's not documented), but with a little experimentation it is possible to construct an expression that is printed in TraditionalForm, but still preserves the term order: TraditionalForm[ PolynomialForm[HoldForm[x y - x^3 - 1], TraditionalOrder -> False]] === Subject: Null Return for a Module Hi all, I'm getting strange output and am trying to track down what might be causing it. I have the following code in my .nb file: (* begin code *) Test[ ] := Module[ {i, thesum}, thesum = 0; For[ i = 1, i <= 3, i++, thesum = thesum + i ] Return[ thesum ] ] Test[ ] (* end code *) The output I would expect would be simply 6 But, I get Null Return[6] Alternatively, if I change the last line of the Test function to be thesum instead of Return[ thesum ] I get 6 Null as the output. If I remove the for loop, I get expected behavior, i.e., Test[ ] := Module[ {i, thesum}, thesum = 1 + 2 + 3; (* For[ i = 1, i <= 3, i++, thesum = thesum + i ] *) Return[ thesum ] ] yields the output 6 as one might expect. I'm not sure what this all means, or what it is complaining about. I have other for-loops that are apparently working properly. So, can anyone give me an idea what might be going wrong here? Dave === Subject: Re: Null Return for a Module try Test[] := Module[{i, thesum}, thesum = 0; For[i = 1, i <= 3, i++, thesum = thesum + i]; (* <= Here *) Return[thesum]] For[] return Null and since you have forgotten the CompoundExpression[] ; the result is interpreted as a product For[__]*Return[_] and since Return[] does not work in expressions, you get Null*Return[6] Jens > Hi all, I'm getting strange output and am trying to track down what might be > causing it. I have the following code in my .nb file: (* begin code *) Test[ ] := Module[ {i, thesum}, > thesum = 0; > For[ i = 1, i <= 3, i++, > thesum = thesum + i > ] > Return[ thesum ] > ] Test[ ] (* end code *) > The output I would expect would be simply 6 But, I get Null Return[6] Alternatively, if I change the last line of the Test function to be thesum instead of Return[ thesum ] I get 6 Null as the output. If I remove the for loop, I get expected behavior, > i.e., > Test[ ] := Module[ {i, thesum}, > thesum = 1 + 2 + 3; > (* > For[ i = 1, i <= 3, i++, > thesum = thesum + i > ] > *) > Return[ thesum ] > ] yields the output 6 as one might expect. I'm not sure what this all means, or what it is > complaining about. I have other for-loops that are apparently working > properly. So, can anyone give me an idea what might be going wrong > here? > Dave > === Subject: Re: Null Return for a Module > Hi all, I'm getting strange output and am trying to track down what might be > causing it. I have the following code in my .nb file: (* begin code *) Test[ ] := Module[ {i, thesum}, > thesum = 0; > For[ i = 1, i <= 3, i++, > thesum = thesum + i > ] > Return[ thesum ] > ] > You forgot a semicolon. The newline after For[] was interpreted as multiplication. The correct version is test[ ] := Module[ {i, thesum}, thesum = 0; For[ i = 1, i <= 3, i++, thesum = thesum + i ]; (* <--- note the semicolon *) Return[ thesum ] ] === Subject: Re: Solving on mathematica Your NSolve statement is not legal syntax (in a dozen different ways), and if it were, the knowns you're not solving for -- x[i] and y[i] -- would have to be... you know... KNOWN. That is, they'd have to be numbers, since NSolve solves numerical problems, not algebraic ones. If we try to solve the algebraic problem, we get: eq[i_] = (x[i] - ux)^2 + (y[i] - uy)^2 + z[i] - uz == r[i] - cb; Solve[Array[eq, 4], {ux, uy, uz, cb}] {} That is, there is no solution to the general problem. It's always possible Solve missed an existing solution, but in this case, I doubt it. Here's a second attempt, this time just trying to solve for maxima/minima of the squared error: zeroD[i_] = Equal @@ D[#.# &@(List @@ eq[i]), {{ux, uy, uz, cb, dummy}}] -4 (-ux + x[i]) (-uz + (-ux + x[i])^2 + (-uy + y[i])^2 + z[i]) == -4 (-uy + y[i]) (-uz + (-ux + x[i])^2 + (-uy + y[i])^2 + z[i]) == -2 (-uz + (-ux + x[i])^2 + (-uy + y[i])^2 + z[i]) == -2 (-cb + r[i]) == 0 Solve[Flatten@Array[zeroD, 4], {ux, uy, uz, cb}] {} Bobby > How would i go about solving this equaiton on mathematica > > (Xi -Ux)^2 + (Yi - Uy)^2 + (Zi - Uz) = (Ri - Cb) > i = 1,2,3,4 > > where we need to find Ux, Uy, Uz, Cb tried a few things and they don't > work. > > NSolve[ (Xi - U)^2 + (Yi - V)^2 + (Zi - W)^2 == (Ri - B)^2, {U, V, W, > B}, { i = 1, 2, 3, 4} ] > > any ideas? > > -- DrMajorBob@longhorns.com === Subject: Creating circular arc arrows Hi All, Can anyone show me how to create a circular arc arrow...maybe create a circular arc then putting the head of the arrow to the ends === Subject: Re: Creating circular arc arrows lst = Table[{Cos[phi], Sin[phi]}, {phi, 0, Pi, Pi/32}]; Graphics[Arrow[lst]] ?? or Manipulate[ Graphics[ Arrow[Table[{Cos[phi], Sin[phi]}, {phi, 0, PhiEnd, Pi/32}]], PlotRange -> {{-1.1, 1.1}, {-1.1, 1.1}} ], {{PhiEnd, Pi/2}, 0, 2 Pi}] Jens > Hi All, Can anyone show me how to create a circular arc arrow...maybe > create a circular arc then putting the head of the arrow to the ends > === Subject: Re: Creating circular arc arrows > Hi All, Can anyone show me how to create a circular arc arrow...maybe > create a circular arc then putting the head of the arrow to the ends > With version 6, arcArrow[centre_, radius_, phi1_, phi2_, resolution_: 30] := Arrow@Table[ centre + radius {Cos[phi], Sin[phi]}, {phi, phi1, phi2, (phi2 - phi1)/Ceiling[(phi2 - phi1)/(Pi/resolution)]}] 'resolution' is the number of segments to use for a 180 degree arc. Usage example: Graphics[arcArrow[{0, 0}, 1, 0.8, 3.14]] === Subject: Flashing Graphs With Manipulate If the coefficient of x is < 0 and the constant term is > 0, this graph flashes as you drag the sliders. Why? NSolve can't be taking that much longer in this case. What can be done to prevent the flashing? Manipulate[ With[ { func = b x + c }, Module[ { rts }, rts = NSolve[func == 0, x]; ListPlot[ {Re[x], Im[x]} /. rts, PlotStyle -> PointSize[0.03], PlotRange -> {{-10, 10}, {-10, 10}}, ImageSize -> {300, 300}, AspectRatio -> 1, PlotLabel -> func] ] ], { {b, -1, coefficient of x}, -9, 9, .1, Appearance -> Labeled}, { {c, 3, constant term}, -10, 10, .1, Appearance -> Labeled} ] === Subject: Bug: Iteration variable in Sum not properly localized when Sum used I tried evaluating the notebook found here: http://library.wolfram.com/infocenter/MathSource/520/ The command that should plot Van der Waerden's function produces some error messages: Plot[Sum[[Phi][n][x], {n, 0, 10}], {x, 0, 1}] Sum::itraw: Raw object 150 cannot be used as an iterator. >> NSum::itraw: Raw object 150 cannot be used as an iterator. >> NSum::itraw: Raw object 150.` cannot be used as an iterator. >> Sum::itraw: Raw object 150 cannot be used as an iterator. >> NSum::itraw: Raw object 150 cannot be used as an iterator. >> General::stop: Further output of NSum::itraw will be suppressed during this calculation. >> Sum::itraw: Raw object 150 cannot be used as an iterator. >> General::stop: Further output of Sum::itraw will be suppressed during this calculation. >> Do::itraw: Raw object 150 cannot be used as an iterator. >> Do::itraw: Raw object 150 cannot be used as an iterator. >> Do::itraw: Raw object 150 cannot be used as an iterator. >> General::stop: Further output of Do::itraw will be suppressed during this calculation. >> Using Plot[Sum[[Phi][n][x] // Evaluate, {n, 0, 10}], {x, 0, 1}] works fine, as well as using the Evaluated option with either Evaluated -> True or Evaluated -> False. The problem appears to be that the variable n has a value. But n should be localized inside Sum, and this problem does not appear in Mathematica 5.2, so this looks like a bug. Even the light green/blue syntax colouring suggests that n is a local variable, and masks the fact that it already has a value. === Subject: Re: Parameter conditions > I'm just curious why the simple code below is not working. Why is happy[4] not returning the number 200 > In[1]:= happy[p_?PrimeQ] = 100; > happy[p_?Not[PrimeQ]] = 200; In[3]:= Inhappy[4] > Out[3]:= happy[4] In[4]:= happy[5] > Out[4]:= 100 > The correct code is happy[p_? PrimeQ] = 100; happy[p_? (Not[PrimeQ[#]]&) ] = 200; PatternTest (the ? operator) should be followed by a function. Not[PrimeQ] is not a function, but we can build a suitable function easily: Not[PrimeQ[#]]&. Now we just have to pay attention to use proper bracketing around it (because happy[p_? Not[PrimeQ[#]]& ] is equivalent to happy[(p_?Not[PrimeQ[#]]&)], which does not make sense). But in this simple case happy[p_? PrimeQ] = 100; happy[p_] = 200; will do the same thing. === Subject: Re: Parameter conditions > I'm just curious why the simple code below is not working. > > Why is happy[4] not returning the number 200 > > In[1]:= happy[p_?PrimeQ] = 100; > happy[p_?Not[PrimeQ]] = 200; > > In[3]:= Inhappy[4] > Out[3]:= happy[4] > > In[4]:= happy[5] > Out[4]:= 100 hi Steven try this (*----------------------------------*) happy[p_?PrimeQ] := 100; happy[p_?(Not[PrimeQ[#]] &)] := 200; happy[4] happy[5] (*-------------------------------------*) Not[PrimeQ[#]] & is patten test expression, wrriten as a pure function in Mathematica, bracket () is necessary here for consideration of precedence of expressions. === Subject: Re: Parameter conditions > I'm just curious why the simple code below is not working. Why is happy[4] not returning the number 200 > In[1]:= happy[p_?PrimeQ] = 100; > happy[p_?Not[PrimeQ]] = 200; In[3]:= Inhappy[4] > Out[3]:= happy[4] In[4]:= happy[5] > Out[4]:= 100 > The pattern p_?Not[PrimeQ] is wrong - try using p_/;Not[PrintQ[p]] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Parameter conditions Hello Steve, ?test has to yield true or false on its argument. Does this make sense? happy[p_?PrimeQ] := 100; happy[p_?(Not[PrimeQ[#]] &)] := 200; happy[4] happy[5] happy[goLucky] Note the := and also /; might be useful to you Craig > I'm just curious why the simple code below is not working. > > Why is happy[4] not returning the number 200 > > > In[1]:= happy[p_?PrimeQ] = 100; > happy[p_?Not[PrimeQ]] = 200; > > In[3]:= Inhappy[4] > Out[3]:= happy[4] > > In[4]:= happy[5] > Out[4]:= 100 > > -- W. Craig Carter === Subject: Re: Inputs to Functions - Can they be FORCED to be a predefined type? > Fri 9 May 2008 Hello All, I have a strange problem for which there might well be no solution. A simplified version of the problem is this. I would like people who use my system to be able to specify time durations though symbols. > For example: dN where N is an integer means N days. So d10 means 10 days. > wN means N weeks. So w5 means 5 weeks which is translated into 5 * 5 = 25 days (assuming 5 days > per week). I want these string designations for time (e.g. d10 and w5) to be an input to a function > (called myFunction) that the user has access to. So far, so good. But, for ease of use, I would prefer that the user not have to remember to use string quote symbols > around the duration symbol (like w5) as input to myFunction. > This is not a problem if the symbol w5 has not already been defined outside of myFunction. It's head > will be Symbol and I can use ToString on it within myFunction so that it would be as if it had > been input as the string w5. BUT, if w5 has already been defined before it is used as input to myFunction, that is obviously a problem - . > myFunction won't recognize it as w5. Is there a way to define myFunction in such a way that any > w5 [or any other duration symbol such as d20 or w12] given to it as input will be interpreted as the String w5. In other words, is there a way to define > the input to myFunction so that it FORCES any w5 given to it to be the String w5 OR the UNDEFINED > Symbol w5 - even if it had been previously defined outside of myFunction? > Here's a way to convert the symbol to a string immediately: In[1]:= SetAttributes[fun, HoldAll] In[2]:= fun[arg_] := ToString[Unevaluated[arg]] In[3]:= hasValue = 1 Out[3]= 1 In[4]:= fun[hasValue] Out[4]= hasValue But this still looks like a misuse to me. If you don't want the users to deal with Mathematica's programming interface, then why not isolate them completely from the system and build a GUI? Take a look at InputField[] in the docs. Here's an example: x = ; {InputField[Dynamic[x], String], Dynamic[x]} === Subject: Re: Inputs to Functions - Can they be FORCED to be a predefined type? Here is the skeleton of an approach illustrated with a simple function. It assignes the Attribute HoldAll to the function and uses Unevaluated to make sure that the argument of the function is turned into a string before its value is used: In[457]:= Attributes[fun] = {HoldAll} Out[457]= {HoldAll} In[458]:= fun[x_] := ToString[Unevaluated[x]] In[459]:= fun[m5] Out[459]= m5 In[460]:= m5 = 9 Out[460]= 9 In[461]:= fun[m5] Out[461]= m5 --David > Fri 9 May 2008 > > Hello All, > > I have a strange problem for which there might well be no solution. > > A simplified version of the problem is this. > > I would like people who use my system to be able to specify time durati= ons though symbols. > For example: dN where N is an integer means N days. So d10 means= 10 days. > wN means N weeks. So w5 means 5 weeks which is translated into 5 * = 5 = 25 days (assuming 5 days > per week). I want these string designations for time (e.g. d10 an= d w5) to be an input to a function > (called myFunction) that the user has access to. So far, so good. > > But, for ease of use, I would prefer that the user not have to remember to= use string quote symbols > around the duration symbol (like w5) as input to myFunction. > This is not a problem if the symbol w5 has not already been defined outsid= e of myFunction. It's head > will be Symbol and I can use ToString on it within myFunction so that it w= ould be as if it had > been input as the string w5. > > BUT, if w5 has already been defined before it is used as input to myFuncti= on, that is obviously a problem - . > myFunction won't recognize it as w5. Is there a way to define myFunct= ion in such a way that any > w5 [or any other duration symbol such as d20 or w12] given to it as= input will be interpreted as the String w5. > > In other words, is there a way to define > the input to myFunction so that it FORCES any w5 given to it to be the Str= ing w5 OR the UNDEFINED > Symbol w5 - even if it had been previously defined outside of myFunctio= n? > > > Don === Subject: Re: Conjugate of Symbolic Expression > How can I get the conjugate of following symbolic expression: > !((-[ExponentialE]^(2 [ImaginaryI] [Phi]_2)) (([ExponentialE] > ^(2 [ImaginaryI] [CapitalDelta]_D) Cos[[Theta]_s]^2 + > Sin[[Theta]_s]^2)) m_2 + [ExponentialE]^([ImaginaryI]* > [Phi]_3) m_3) I used the following function but it doesn't work: > !(Refine[ > Conjugate[(-[ExponentialE]^(2 [ImaginaryI] [Phi]_2)) (( > [ExponentialE]^(2 [ImaginaryI] [CapitalDelta]_D) > Cos[[Theta]_s]^2 + > Sin[[Theta]_s]^2)) m_2 + > [ExponentialE]^([ImaginaryI]*[Phi]_3) m_3], [CapitalDelta]_D > [Element] Reals && [Phi]_2 [Element] Reals && [Phi]_3 [Element] Reals && > m_2 [Element] Reals && > m_3 [Element] Reals && [Theta]_s [Element] Reals]) > There has been a recent question exactly about this. Just replace Refine with FunctionExpand in the expression you posted. === Subject: Re: Display commands in a package >> You can do the following: >> >> << BarCharts` >> >> ?BarCharts`* >> > V6.02 XP machine. With a fresh kernel this works ok - no error messages. > << BarCharts` But in response to this line > ?BarCharts`* I get: Syntax::sntxf: ? cannot be followed by BarCharts`*. Syntax::tsntxi: BarCharts`* is incomplete; more input is > needed. Syntax::sntxi: Incomplete expression; more input is needed. Do you have any thoughts on why my machine won't respond > << BarCharts`* or Information[BarCharts`*] instead. === Subject: Re: How to avoid overflow or underflow in mathematica? >It's well known that Mathematica can do evaluation to arbitrary precision. But I don't know how to avoid the following trouble in computing: > >Ef = 0.; >mu=0.; >KBT = 1.*10^-10; >FL[omega_Real] := 1./(1. + E^((omega - mu - Ef)/KBT)); > >the error message shows > >General::ovfl: Overflow occurred in computation. >> >General::unfl: Underflow occurred in computation. >> > > You don't tell us what value of omega you used. However, keep in mind that there is a maximum number in Mathematica. On my computer this number is: In[34]:= $MaxNumber Out[34]= 1.920224672692357*10^646456887 The log of this number is: In[35]:= Log[$MaxNumber] Out[35]= 1.488521991921978478647057*10^9 So, if (omega-mu-Ef)/KBT is larger than the above number you will get overflow/underflow problem. With your parameters, this means that an order 1 value of omega will cause overflow/underflow problems. Carl Woll Wolfram Research === Subject: Re: How to avoid overflow or underflow in mathematica? > It's well known that Mathematica can do evaluation to arbitrary precision. But I don't know how to avoid the following trouble in computing: Ef = 0.; > mu=0.; > KBT = 1.*10^-10; > FL[omega_Real] := 1./(1. + E^((omega - mu - Ef)/KBT)); the error message shows General::ovfl: Overflow occurred in computation. >> > General::unfl: Underflow occurred in computation. >> > You've practically written E^(10^10.) here. I hope that you do realize how great the magnitude of this double exponential is. Mathematica has its limits too: the biggest number it can handle is $MaxNumber, which is 1.920224672692357*10^646456887 on my computer. The magnitude of your expression is greater than this. === Subject: Re: How to avoid overflow or underflow in mathematica? Hello Quantum Fang, You could use arbitrary precision and do something like this (although I don't advise this approach): fermiseries = Normal[Series[1/(1 + E^((muShift) beta)), {beta, 0, 14}]]; colist = Simplify[CoefficientList[fermiseries, beta]] and then write a function that calls N[beta, bigNumber] and N[mushift, bigNumber] on the product of the two list until you have the accuracy that you want.... This is a bad idea. However your function, except for ((omega - mu - Ef)/KBT) approximately 1, is the unit step function (0 if x<0, 1/2 x=0, 1 if x>0). If you are interested in the physical aspects of this problem then expand (omega - mu - ef) near 1/(kb T). In other words, scale your energies with the thermal energy. WCC > It's well known that Mathematica can do evaluation to arbitrary precision. But I don't know how to avoid the following trouble in computing: > > Ef = 0.; > mu=0.; > KBT = 1.*10^-10; > FL[omega_Real] := 1./(1. + E^((omega - mu - Ef)/KBT)); > > the error message shows > > General::ovfl: Overflow occurred in computation. >> > General::unfl: Underflow occurred in computation. >> > > -- W. Craig Carter === Subject: graphic text style setting before v6 I set the text style for all the graphics and plots in a notebook with one command at the beginning of the notebook, e.g. $TextStyle[{FontFamily -> Arial, FontSize -> 16}]; In v6, that does not work anymore. How can I do such a thing in v6? joerg === Subject: FullForm OK but StandardForm fails Hi all, I'm wondering if this is a bug in 6.0.2.0 or whether anyone can see my problem here. I'm running a model that updates an object called 'data' using a module with the HoldFirst attribute. After I run the module, I can see the Head of data, and its FullForm, but when I try to view its StandardForm, I get a $RecursionLimit error as follows. If I try to Print data, the kernel crashes. However, if I copy the FullForm of data (Out[76]) into a new object, it Prints perfectly. Any ideas? In[75]:= Head[data] Out[75]= localState In[76]:= FullForm[data] Out[76]//FullForm= localState[community[List[population[canola,genotypeInfo[],cohortList[Li st[]],cohortList[List[]], cohortList[List[]],cohortList[List[]]],population[lupin,genotypeInfo[],c ohortList[List[]],cohortList[List[]], cohortList[List[]],cohortList[List[]]],population[ryegrass,genotypeInfo[ List[Rule[List[1,1], 0.9993453217507997`],Rule[List[Blank[Integer],Blank[Integer]], 1]],List[major],List[dominant], List[glyphosate],List[Rational[1,1000000000]],List[0.1`]],cohortList[Lis t[cohort[time[3502828800], hashedMSet[ruleSet[List[Rule[List[List[1],List[1]], 1],Rule[List[List[1],List[2]],2],Rule[List[List[2], List[1]],3],Rule[List[List[2],List[2]], 4]]],List[499345536052604696,327124822795158, 327124822795158,214301804988],List[info[List[]],info[List[]],info[List[]],in fo[List[]]]]]]], cohortList[List[]],cohortList[List[]],cohortList[List[]]],population[wheat ,genotypeInfo[], cohortList[List[cohort[time[3502828800],hashedMSet[ruleSet[List[Rule[List[Li st[1],List[1]], 1]]], List[160000000000000000],List[info[List[]]]]]]],cohortList[List[]],cohortLis t[List[]],cohortList[List[]]], population[wildradish,genotypeInfo[],cohortList[List[]],cohortList[List[ ]],cohortList[List[]], cohortList[List[]]]]],herbicideResidueList[]] In[77]:= StandardForm[data] During evaluation of In[77]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> During evaluation of In[77]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> During evaluation of In[77]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> During evaluation of In[77]:= General::stop: Further output of $RecursionLimit::reclim will be suppressed during this calculation. >> === Subject: Re: Re: Request for Collective Wisdom... Another suggestion which is related to these tips: open new notebooks whenever performing scratch calculations. Once you figure out what works or what is relevant to the task at hand, copy the relevant cells into the notebook which acts as the permanent record for saving. Until I started doing this, my notebooks would gradually accumulate a lot of unnecessary, irrelevant cruft that would drift to the end of the notebook. Jason > This tip is more important than it might at first seem: Many > Mathematica > novices mistakenly believe that evaluations are localized to the > particular notebook in which they are working, rather than to the > session and, where relevant, the context. > > (This misconception may be due to a difference in the way some other > mathematical software handles this situation.) > > >> When defining a new function, have two windows open: >> one for building up the new function, and the other for trying out >> code to make sure it works before adding it to the function >> window. Don't try to do everything in one window. Seems wasteful >> at first but it's an enormous time saver in the long run. >> > > -- > 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 > -- 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: Request for Collective Wisdom... Four more: 1. Avoid symbol names starting with capital letters during interactive work (to avoid conflicts with built-in names). 2. Avoid using inexact numbers in symbolic computations. Here's an example of what can go wrong: (Solve verified the obtained solutions by backsubstitution, but it found that some of them are invalid, because of numerical errors.) 3. One of most common non-trivial mistakes that people make is similar to the following: fun[y_] := NIntegrate[x - 1, {x, 0, y}] FindRoot[fun[x], {x, 1, 3}] (* Won't work because FindRoot evaluates fun[x] with x being a symbol *) The solution is to prevent fun[] from being evaluated with non-numerical arguments: fun[y_?NumericQ] := NIntegrate[x - 1, {x, 0, y}] FindRoot[fun[x], {x, 1, 3}] This brings up another potential problem source: 4. Clear function names before redefining them. In Mathematica, several definitions can be attached to the same symbol name. So the definition fun[y_?NumericQ] := ... will not replace the previous definition fun[y_] := ... but the two will coexist. Use Clear[fun] before redefining fun. === Subject: Re: Request for Collective Wisdom... This tip is more important than it might at first seem: Many Mathematica novices mistakenly believe that evaluations are localized to the particular notebook in which they are working, rather than to the session and, where relevant, the context. (This misconception may be due to a difference in the way some other mathematical software handles this situation.) > When defining a new function, have two windows open: > one for building up the new function, and the other for trying out code to make sure it works before adding it to the function window. Don't try to do everything in one window. Seems wasteful at first but it's an enormous time saver in the long run. > -- 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: Request for Collective Wisdom... [note: message sent to comp.soft-sys.math.mathematica] > This tip is more important than it might at first seem: Many Mathematica > novices mistakenly believe that evaluations are localized to the > particular notebook in which they are working, rather than to the > session and, where relevant, the context. > Yes, this can be a bit confusing in Mathematica 6. Mathematica 6 uses local contexts in the documentation centre, so evaluations *are* (partially) localized to particular cell groups in the doc centre, but *not* to other notebook windows. === Subject: Error messages from FunctionInterpolation (bug?) I know that this is a misuse of FunctionInterpolation, but this should not happen: In[1]:= sin = f/.First@NDSolve[{f''[x]+f[x]==0,f[0]==0,f'[0]==1},f,{x,0,10}] Out[1]= InterpolatingFunction[{{0.,10.}},<>] In[2]:= FunctionInterpolation[sin[x],{x,0,10}] During evaluation of In[2]:= Take::take: Cannot take positions 1 through 3 in {1,1}. >> During evaluation of In[2]:= Take::take: Cannot take positions 1 through 3 in {1.,1.}. >> During evaluation of In[2]:= Take::take: Cannot take positions 1 through 3 in {1,1}. >> During evaluation of In[2]:= General::stop: Further output of Take::take will be suppressed during this calculation. >> Out[2]= InterpolatingFunction[{{0,10}},<>] === Subject: Re: Question about alignment in Grid and TableForm > As you can see, the text _is_ centered, it's the dot-alignment which causes > the look of the table to be different from what you expect: > > Grid[ > Insert[Table[ > Item[N[Pi a^10] // ScientificForm, Alignment -> .], {a, 1, > 5}, {b, 1, 3}], {Item[First Column text, Alignment -> Center], > Item[Second Column text, Alignment -> Center], > Item[Third Column text, Alignment -> Center]}, 3], > Dividers -> All > ] I expected the numbers to be aligned at the center of the text. It is frustrating that the numbers get Right alignment and text shifts from the center of numbers. Is there a way to make text in the column aligned at the center of ALL numbers which are at the same time aligned at .? As I think it is the most expected behavour but I do not know how to force Mathematica to create such obvious and good- looking table. I am pained very much that it is not the default behavour! This is so obvious for scientific table! === Subject: Re: FindClusters & BarCharts > Hi everyone, > I have the following list: > list = {{2, 4, 2, 2, 9}, {7, 2, 8, 5, 4}, {2, 1, 4, 5, 3}} > > > I would like to find clusters in the above list: > > tmpVal = 3; > > temp = FindClusters[Cases[Flatten[Sort[list]], Except[tmpVal]]] > > > This gives me: {{2, 1, 2, 2, 2, 2}, {4, 4, 4}, {5, 5}, {9, 7, 8}} which is > correct. However, I do want one of the clusters to include the value of 3 > and get something as follows: > > {{2, 1, 2, 2, 2, 2}, {4, 4, 4}, {5, 5}, {9, 7, 8}, {3}} > > > If I change tmpVal = 2 I get something that is not desired: > > tmpVal=2 > > temp = FindClusters[Cases[Flatten[list], Except[value]]] > > This gives me: {{4, 5, 4, 1, 4, 5, 3}, {9, 7, 8}}. > > However, I would like the output to be somewhat as the following (In other > words > > {{1}, {2,2,2,2,2}, {3,4,5}, {7,8,9}} > > > Similarly, if I change the variable value=8, I get: > > {{2, 2, 2, 2, 2, 1, 3}, {4, 5, 4, 4, 5}, {9, 7}} > > but would like the output to include: > > {{2, 2, 2, 2, 2, 1, 3}, {4, 5, 4, 4, 5}, {7}, {8}, {9}} > > > In other words, split the list up at the value and then > > > > I would like to plot the above in a BarChart: > > Needs[BarCharts`] > > BarChart[Map[Length[#] &, temp]] > > I would like the bars to have the labels as the minimum and maximum for each > of the lists. For instance: > > {{4, 5, 4, 1, 4, 5, 3}, {9, 7, 8}, {2,2,2,2,2}} > > The first bar would be labeled 1-5 > > Here's an example that takes the clustering for the entire data set and breaks up the cluster containing the value of interest. In[1]:= list = {{2, 4, 2, 2, 9}, {7, 2, 8, 5, 4}, {2, 1, 4, 5, 3}}; In[2]:= clusters = FindClusters[Flatten[Sort[list]]] Out[2]= {{2, 1, 4, 5, 3, 2, 4, 2, 2, 2, 5, 4}, {9, 7, 8}} The following will sort each cluster and break the cluster containing tempval into clusters containing tempval, containing values less than tempval, and containing values greater than tempval. In[3]:= f[tempval_] := Flatten[Map[ tempval || (#1 =!= tempval && #2 =!= tempval)) &] &, clusters], 1] Here are the examples for 3, 2, and 8. In[4]:= f[3] Out[4]= {{1, 2, 2, 2, 2, 2}, {3}, {4, 4, 4, 5, 5}, {7, 8, 9}} In[5]:= f[2] Out[5]= {{1}, {2, 2, 2, 2, 2}, {3, 4, 4, 4, 5, 5}, {7, 8, 9}} In[6]:= f[8] Out[6]= {{1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 5, 5}, {7}, {8}, {9}} In[7]:= Needs[BarCharts`] labelfun will be used to create the bar labels. It uses min-max for clusters containing more than one value, and just the value if there is only one distinct value in the cluster. In[8]:= labelfun[xx_] := Block[{min, max},(*use the fact that the data from f will already be sorted*) min = First[xx]; max = Last[xx]; ToString[min] <> - <> ToString[max]]] In[9]:= With[{vals = f[3]}, BarChart[Map[Length[#] &, vals], BarLabels -> Map[labelfun, vals]]] Out[9]= -Graphics- Darren Glosemeyer Wolfram Research === Subject: Re: Stop cell tags propagating to generated cells Hi Craig, after. Cell labels are different from cell tags. A cell label mostly frequently is the In[n]:= and Out[n]= label for input and output cells, which are automatically generated. A cell tag is a separate string, and the visibility of the cell is controlled via the option ShowCellTags. Jason > Hello Jason. > I hope what this is what you are looking for. > > Options Inspector, Notebook Options, Cell Options, Cell Labels, > ShowCellLabel-> False > > Craig > >> Is there a way to stop cell tags that have been manually added to an >> input cell from being automatically assigned to the generated output >> cell? I ask because I have been creating interactive panels for >> controlling Java models (using J/Link) and would like to be able to >> programmatically toggle the CellOpen status of the lengthy >> DynamicModule[...] code. >> >> >> Jason >> >> -- >> 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 >> >> > > > > -- > W. Craig Carter -- 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: Stop cell tags propagating to generated cells Hello Jason. I hope what this is what you are looking for. Options Inspector, Notebook Options, Cell Options, Cell Labels, ShowCellLabel-> False Craig > Is there a way to stop cell tags that have been manually added to an > input cell from being automatically assigned to the generated output > cell? I ask because I have been creating interactive panels for > controlling Java models (using J/Link) and would like to be able to > programmatically toggle the CellOpen status of the lengthy > DynamicModule[...] code. > > > Jason > > -- > 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 > > -- W. Craig Carter === Subject: Re: Stop cell tags propagating to generated cells for a while... So I did a little bit of research and came up with a possible solution (though I do wish that WRI would add an option to Cell to take care of this directly). One way to handle this is to assign a CellEpilog option to the Input cells in your notebook, either directly to those cells or at the StyleSheet level. Here is an example of such an option that would remove all the CellTags from the output cells that are a direct result of executing the given Input cells. it could, of course, be modified to custom tag those cells as well. Note though that this will change the CellTags of any cell that immediately follows the Input cell, even if no output is generated (and, for example, if error messages are written after the Input cell it would only remove the CellTags from the first of those). So perhaps you would want to customize this to behave as you wish it to for your purposes... but I think it's a decent starting point... Here is the option setting: CellEpilog :> ( SelectionMove[EvaluationNotebook[], After, EvaluationCell]; SelectionMove[EvaluationNotebook[], Next, Cell]; SetOptions[NotebookSelection[EvaluationNotebook[]], CellTags -> {}]) 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/ > Is there a way to stop cell tags that have been manually added to an > input cell from being automatically assigned to the generated output > cell? I ask because I have been creating interactive panels for > controlling Java models (using J/Link) and would like to be able to > programmatically toggle the CellOpen status of the lengthy > DynamicModule[...] code. > > > Jason > > -- > 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 communica= tions disclaimer:http://www.lse.ac.uk/collections/secretariat/legal/disclaim= er.htm === Subject: Re: Intersection of surfaces TUBE = {.6 Cos[V], 2 U + 3, .6 Sin[V] + 2}; tube = ParametricPlot3D[TUBE, {U, -1.2, .2}, {V, 0, 2 Pi}, PlotPoints -> {10, 25}]; BOWL = {p Cos[q], p^2/2, p Sin[q]}; bowl = ParametricPlot3D[BOWL, {p, 1, 2.75}, {q, 0, 2 Pi}, PlotPoints -> {20, 35}]; and eqn = Eliminate[{TUBE == {x, y, z} // Thread, BOWL == {x, y, z} // Thread} // Flatten, {p, q, U}]; and sol = Solve[eqn, {x, y, z}]; gives {{y -> 0.02 (100.+ 9. Cos[V]^2 + 60. Sin[V] + 9. Sin[V]^2), x -> 0.6 Cos[V], z -> 0.2 (10.+ 3. Sin[V])}} and ll = ParametricPlot3D[{x, y, z} /. sol[[1]], {V, 0, 2 Pi}]; Show[bowl, tube, ll /. l_Line :> {AbsoluteThickness[4], RGBColor[1, 0, 0], l}] show that the result is right. Jens > How to find the space curve formed by intersecting 3D patches in > simple cases like: TUBE = {.6 Cos[V], 2 U + 3, .6 Sin[V] + 2}; > tube = ParametricPlot3D[TUBE, {U, -1.2, .2}, {V, 0, 2 Pi}, PlotPoints - >> {10, 25}] > BOWL = {p Cos[q], p^2/2, p Sin[q]}; > bowl = ParametricPlot3D [ BOWL, {p, 1, 2.75}, {q, 0, 2 Pi}, PlotPoints > -> {20, 35}] > Show[bowl, tube] or in slightly more complicated surface cases like: terr = ParametricPlot3D[{Cos[u + 1] Cos[v + 2.1], 0.6 + u^2/3,Exp[-v/ > 4] }, {v, -3, 3}, {u, -3, 3}, PlotPoints -> {45, 30}] > Show[terr, tube] How to solve for x,y and z from {0.6 Cos[V] == p Cos[q], 3 + 2 U == > p^2/2, 2 + 0.6 Sin[V] == p Sin[q]} obtaining t as a function of (U,V,p > and q) so as to be able to Show with ParametricPlot3D[{x[t], y[t], z[t]},{t,tmin,tmax}]? Narasimham === Subject: Re: Intersection of surfaces Hi Narasimham, here is one way of doing it: we first set the components of TUBE == BOWL, this gives 3 equations. We eliminate one sets of parameters (e.g. U,V). This leaves one equation with 2 parameters. We solve for one of these (e.g. p). This gives p as a function of q. We replace p in e.g. BOWL by this function. This gives a parametric representation of the space curve: res1=Eliminate[{TUBE==BOWL},{U,V}]; res2=Solve[res1,p]; intersection=ParametricPlot3D[BOWL/.res2[[1]],{q,0,2Pi},PlotStyle->{Thicknes s[0.02]}] To check, we may show everything together: Show[bowl,tube,intersection] hope this helps, Daniel > How to find the space curve formed by intersecting 3D patches in > simple cases like: TUBE = {.6 Cos[V], 2 U + 3, .6 Sin[V] + 2}; > tube = ParametricPlot3D[TUBE, {U, -1.2, .2}, {V, 0, 2 Pi}, PlotPoints - >> {10, 25}] > BOWL = {p Cos[q], p^2/2, p Sin[q]}; > bowl = ParametricPlot3D [ BOWL, {p, 1, 2.75}, {q, 0, 2 Pi}, PlotPoints > -> {20, 35}] > Show[bowl, tube] or in slightly more complicated surface cases like: terr = ParametricPlot3D[{Cos[u + 1] Cos[v + 2.1], 0.6 + u^2/3,Exp[-v/ > 4] }, {v, -3, 3}, {u, -3, 3}, PlotPoints -> {45, 30}] > Show[terr, tube] How to solve for x,y and z from {0.6 Cos[V] == p Cos[q], 3 + 2 U == > p^2/2, 2 + 0.6 Sin[V] == p Sin[q]} obtaining t as a function of (U,V,p > and q) so as to be able to Show with ParametricPlot3D[{x[t], y[t], z[t]},{t,tmin,tmax}]? Narasimham === Subject: Re: Symbolic Optimization Problem Hello Gonca, I suggest starting with a simpler problem which is a subset of your problem: f = (1/R)^([Beta]/(1 - [Beta])); I examine it's behavior for various values of [Beta] Plot[Table[f, {[Beta], 0.1, .9, .1}], {R, -1, 1}] Now, it seems that there is a more basic question: why doesn't the following evaluate? Maximize[{(1/R)^([Beta]/(1 - [Beta])), 0 < [Beta] < 1}, {R, [Beta]}] It appears that the maximum of this function occurs in the limit [Beta]->1 and R->0. Blake === Subject: DynamicModule question Can someone please explain to me why the following happens? It's a silly little example to illustrate a problem I ran into recently... First, evaluate the following in separate cells: Needs[PieCharts`]; data = {.25, .75} Then evaluate the following: DynamicModule[{size = 300}, Column[{ Slider[Dynamic[size], {100, 500}], Dynamic[PieChart[data, ImageSize -> size]] }] ] Notice that you can not only resize the graphic by dragging the slider, but if you change the definition of data, that's reflected automatically in the graphic as well. However, suppose you wrap the DynamicModule in a function like so: foo[data_] := DynamicModule[{size = 300}, Column[{ Slider[Dynamic[size], {100, 500}], Dynamic@PieChart[data, ImageSize -> size] }] ] Now evaluate foo[ data ] If you change the definition of data in the notebook, the second DynamicModule doesn't update the pie charts. I don't understand what breaks when you wrap the DynamicModule in a function definition. Jason -- 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: Formatting Problem with Summation Symbol I often write short derivations in a single cell with a statement on each line and sometimes Print statements interspersed as commentary. This gives one input cell and multiple output cells. Then one can select all the output cells and double-click to hide the input cell. However, sometimes it is a bit inconvenient to select all the output cells so I would like to display them as lines in a Column instead. Then there would be only one output cell to select. However, it is difficult to obtain the same formatting in Column as one obtains in output cells. Here is an example: p[x] == Sum[a[n] x^n, {n, 0, N}] // TraditionalForm Now I try to display the same statement as part of a Column. (Usually one would have more entries but here I just simplify it to one entry.) Style[Column[{p[x] == Sum[a[n] x^n, {n, 0, N}]}], Output] // TraditionalForm This does not look like the ordinary Output formatting. I can improve the limits positioning by using: Style[Column[{p[x] == Sum[a[n] x^n, {n, 0, N}]}], Output, UnderoverscriptBoxOptions -> {LimitsPositioning -> False}] // TraditionalForm This still does not look like normal Output because the Sigma is too small. I can make the Sigma larger by using: Style[Column[{p[x] == Sum[a[n] x^n, {n, 0, N}]}], Output, UnderoverscriptBoxOptions -> {LimitsPositioning -> False}, SpanMinSize -> 2] // TraditionalForm But now the brackets are too large. Is there a method to use a Column expression and have each line look like regular Output formatting? -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: substitution within a substitution list HI, I'm trying to find a way of changing the substitution values within a substitution list. For example, if I have the following substitution list:- subs = {a->1, b->2, c->2} I want to programmatically replace the value associated with 'b' from 2 to 20, ie ending up with subs = {a->1, b->20, c->2} Does anyone know of a mathematica function for doing this? Bipin. === Subject: Re: Matrix of big dimensions If you are using Mathematica version 6 and your matrix has many zeros, you should check the commands SparseArray and Band in order to work efficiently (save computer memory and time). There are good examples of the use of SparseArray and Band in the Documentation Center of Mathematica version 6. In previous Mathematica version SparseArray does exist, but Band does Not exist. Hope it helps Jose Mexico -----Mensaje original----- De: GGuerreiro [mailto:grg@fct.unl.pt] Enviado el: Mi=E9rcoles, 07 de Mayo de 2008 06:07 a.m. Para: mathgroup@smc.vnet.net Asunto: Matrix of big dimensions Hi. Anyone here already tried to implement calculus on mathematica using a 500*500 dimension matrix? Do you know if it works? GGuerreiro === Subject: Re: Matrix of big dimensions what matrix, numeric or symbolic, dense or sparse. sparse and numeric should work with larger dimensions. dense and numeric will work symbolic and dense may work -- depends what you wish to do. Jens > Hi. Anyone here already tried to implement calculus on mathematica using a 500*500 dimension matrix? Do you know if it works? > GGuerreiro > === 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 === Subject: Re: ListDensityPlot with irregular data and InterpolationOrder >This is not explicitly documented (or at least I could not find any >mention of it), but from looking at the plots it seems to me that >with ListDensityPlot (and related functions), an InterpolationOrder >higher than 1 only work with data that lies on a regular grid. >So for example the following data cannot be plotted with >InterpolationOrder higher than 1: >data = {#1, #2, Sin[#1] Sin[#2]} & @@@ RandomReal[2 Pi, {100, 2}]; >Is this correct? The array you create above is a regular array and as far as I can see there is no problem with using an InterpolationOrder greater than 1. That is, using your code above to assign values to data ListDensityPlot[data] ListDensityPlot[data,InterpolationOrder->1] ListDensityPlot[data,InterpolationOrder->3] all execute with no error messages. True, all three graphics appear identical. But I believe this is due the functional relationship you created. Do the following data=RandomReal[2 Pi, {5,5}]; then ListDensityPlot[data] ListDensityPlot[data,InterpolationOrder->1] ListDensityPlot[data,InterpolationOrder->3] All three should execute with no error and the images will not be the same due to the different interpolation order. === Subject: Re: Question on the Limiting Value of Ratios of Consecuative Primes... > Is there some analytic limit to the ratio of consecuative primes? Yes. The limit is 1. Since there are infinitely many twin primes, it's obvious that, if the limit exists, it must be 1. I don't know how to show nicely that the limit exists. > The expression Limit[Prime[i]/Prime[i+1],{i,->Infinity}] returns > unevaluated. I suspect that is just as well. My understanding is that Mathematica is not designed to deal with limits of sequences and that, had you gotten an answer, it should not have been trusted. > Plotting Table[ Prime[i]/Prime[i+1],{i,1,20000}] shows a lot > of structure with a minimum of 3/5. I suppose I see the structure to which you refer: various strings of points which could be visualized as lying on smooth curves. The points which form the uppermost string correspond to the ratios of the twin primes. The points which form the next string down correspond to the ratios of primes having a difference of 4. And then the points which form the next string down correspond to the ratios of primes having a difference of 6. Etc. David W. Cantrell === Subject: TreePlots and GraphPlots Hi Everyone, I have a question regarding TreePlot and GraphPlots. I have the following list : myList1 = {{1.9124437047927545`, 2.140934695277407`, 2.4290608973234304`}, {3.1220434925197633`}, {3.193277882536842`, 3.321086033303083`, 3.3624160109272454`}, {3.8240882444935016`, 4.778362811870326`}} One of the elements in this list is set as the root node for a tree - based structure. For instance : treeRoot = myList1[[2]] Based on the list above : I would like the root node will have 3 children The first child has 3 leaf nodes {1.9124437047927545`, 2.140934695277407`, 2.4290608973234304`}, the second child has three leaf nodes {3.193277882536842`, 3.321086033303083`, 3.3624160109272454`} and finally the third child has 2 leaf nodes : {3.8240882444935016`, 4.778362811870326`}. In other words, I am trying to represent myList1 in a tree structure. I am not able to create a list of rules for the tree. Any suggestions/ ideas would be great. namrata === Subject: A bug in Show[]? Consider the following combined plot: model[i_] := Log[i] - Log[i - 1]; Show[Plot[(model[ii]), {ii, 2, 51}], ListPlot[Table[{im, model[im]}, {im, 2, 51}]], PlotRange -> All] You may see that a part of first Plot is absent. It is easily to demonstrate that only a part of Plot that is not shown without the option PlotRange -> All is absent: Show[Plot[(model[ii]), {ii, 2, 51}], ListPlot[Table[{im, model[im]}, {im, 2, 51}]]] The workaround is to put this option inside first Plot[] instead outside of those: Show[Plot[(model[ii]), {ii, 2, 51}, PlotRange -> All], ListPlot[Table[{im, model[im]}, {im, 2, 51}]]] But in documentation for Show[] one can read: Options explicitly specified in Show override those included in the graphics expression.. Thus this is a bug in Show[]! Moreover placing this option inside the second command ListPlot[] has no result at all (the option is ignored): Show[Plot[(model[ii]), {ii, 2, 51}], ListPlot[Table[{im, model[im]}, {im, 2, 51}], PlotRange -> All]] But according to the documentation The lists of non-default options in the Subscript[g, i] are concatenated.. Thus it seems to be the second bug in Show[]! === Subject: Point Symbol and Mesh Is there any easy way of changing the Point Symbol given with Mesh from a circle to, say, a square or a triangle? An example is given in the following code: With[{m = 1000, c = 10}, Plot[m x + c, {x, 0, 101}, Mesh -> {Range[40, 100, 10]}, MeshStyle -> {PointSize[Large], Red}]] What I would like to do is to superimpose two or more plots, with each line having a different symbol (circle, square, triangle ... ) for the points generated by Mesh. I am aware of PlotMarkers, but this only seem to apply to ListPlot. Thomas Dowling. === Subject: Re: Trouble computing conjugates I don't think you need to use $Assumptions or Refine. Just use ComplexExpand. u1 = f + I g; u2 = f - I g; Conjugate[c1 u1] ComplexExpand[%] Conjugate[c1] (Conjugate[f] - I Conjugate[g]) c1 f - I c1 g Conjugate[c1 u1 + u2] ComplexExpand[%] Conjugate[f + c1 (f + I g)] + I Conjugate[g] f + c1 f + I (g - c1 g) -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > I'm having trouble getting mathematica to compute complex conjugates > of some fairly simple expressions: > > If I type the following: > > $Assumptions = {g [Element] Reals, f [Element] Reals} > u1 = f + [ImaginaryI] g > u2 = f - [ImaginaryI] g > > Then the command: > > Refine[Conjugate [c1 u1]] > > returns: > > f - [ImaginaryI] g) Conjugate[c1] > > and the command: > > Refine[Conjugate[c1 u1 + u2]] > > returns: > > f + [ImaginaryI] g + (f - [ImaginaryI] g) Conjugate[c1] > > as I would expect. But the command: > > Refine[Conjugate[c1 u1 + c2 u2]] > > returns: > > Conjugate[c2 (f - [ImaginaryI] g) + c1 (f + [ImaginaryI] g)] > > i.e. it refuses to distribute the complex conjugate throughout the > expression. What I would like it to tell me is: > > (f + [ImaginaryI] g) Conjugate[c2] + (f - [ImaginaryI] g) > Conjugate[c1] > > The closest I have been able to come to getting what I want is by > using: > > ComplexExpand[Refine[Conjugate[ c1 u1 + c2 u2]], {c1, c2}] > > but this separates c1 and c2 into their real and imaginary parts. The > above expressions are much simpler than the ones I REALLY want > Mathematica's help in simplifying. If I use this ComplexExpand > command, then I'm going to have to recombine them into complex numbers > again, which would be very very bad. > > Roy > === Subject: Re: Trouble computing conjugates > I'm having trouble getting mathematica to compute complex conjugates > of some fairly simple expressions: If I type the following: $Assumptions = {g [Element] Reals, f [Element] Reals} > u1 = f + [ImaginaryI] g > u2 = f - [ImaginaryI] g Then the command: Refine[Conjugate [c1 u1]] returns: f - [ImaginaryI] g) Conjugate[c1] and the command: Refine[Conjugate[c1 u1 + u2]] returns: f + [ImaginaryI] g + (f - [ImaginaryI] g) Conjugate[c1] as I would expect. But the command: Refine[Conjugate[c1 u1 + c2 u2]] returns: Conjugate[c2 (f - [ImaginaryI] g) + c1 (f + [ImaginaryI] g)] i.e. it refuses to distribute the complex conjugate throughout the > expression. What I would like it to tell me is: (f + [ImaginaryI] g) Conjugate[c2] + (f - [ImaginaryI] g) > Conjugate[c1] For this particular example, you could manually distribute Conjugate over the sum: Refine@Distribute[Conjugate[c1 u1 + c2 u2]] FunctionExpand works, too: Conjugate[c1 u1 + c2 u2] // FunctionExpand The closest I have been able to come to getting what I want is by > using: ComplexExpand[Refine[Conjugate[ c1 u1 + c2 u2]], {c1, c2}] but this separates c1 and c2 into their real and imaginary parts. The > above expressions are much simpler than the ones I REALLY want > Mathematica's help in simplifying. If I use this ComplexExpand > command, then I'm going to have to recombine them into complex numbers > again, which would be very very bad. > I hope that FunctionExpand will work for your more complicated example. If it doesn't (or it has side effects that you want to avoid), you could experiment with something like Refine[ expr /. HoldPattern@Conjugate@Plus[terms__] :> Distribute@Conjugate@Plus[terms] ] The HoldPattern was necessary to prevent Plus[terms__] from evaluating to terms__ === Subject: Re: Trouble computing conjugates ComplexExpand is your friend! It automatically assumes that symbolic quantities within it are real. So: ComplexExpand[Conjugate[c1 u1 + c2 u2]] c1*f + c2*f - I*(c1*g - c2*g) > I'm having trouble getting mathematica to compute complex conjugates > of some fairly simple expressions: If I type the following: $Assumptions = {g [Element] Reals, f [Element] Reals} > u1 = f + [ImaginaryI] g > u2 = f - [ImaginaryI] g Then the command: Refine[Conjugate [c1 u1]] returns: f - [ImaginaryI] g) Conjugate[c1] and the command: Refine[Conjugate[c1 u1 + u2]] returns: f + [ImaginaryI] g + (f - [ImaginaryI] g) Conjugate[c1] as I would expect. But the command: Refine[Conjugate[c1 u1 + c2 u2]] returns: Conjugate[c2 (f - [ImaginaryI] g) + c1 (f + [ImaginaryI] g)] i.e. it refuses to distribute the complex conjugate throughout the > expression. What I would like it to tell me is: (f + [ImaginaryI] g) Conjugate[c2] + (f - [ImaginaryI] g) > Conjugate[c1] The closest I have been able to come to getting what I want is by > using: ComplexExpand[Refine[Conjugate[ c1 u1 + c2 u2]], {c1, c2}] but this separates c1 and c2 into their real and imaginary parts. The > above expressions are much simpler than the ones I REALLY want > Mathematica's help in simplifying. If I use this ComplexExpand > command, then I'm going to have to recombine them into complex numbers > again, which would be very very bad. Roy > -- 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: Trouble computing conjugates Hi Roy, mathematica thinks the distributed form is more complicated, therefore, you get the undistributed form. You may tell mma to distribute by e.g.: Refine[Conjugate[c1 u1+c2 u2]//Distribute] hope this helps, Daniel > I'm having trouble getting mathematica to compute complex conjugates > of some fairly simple expressions: If I type the following: $Assumptions = {g [Element] Reals, f [Element] Reals} > u1 = f + [ImaginaryI] g > u2 = f - [ImaginaryI] g Then the command: Refine[Conjugate [c1 u1]] returns: f - [ImaginaryI] g) Conjugate[c1] and the command: Refine[Conjugate[c1 u1 + u2]] returns: f + [ImaginaryI] g + (f - [ImaginaryI] g) Conjugate[c1] as I would expect. But the command: Refine[Conjugate[c1 u1 + c2 u2]] returns: Conjugate[c2 (f - [ImaginaryI] g) + c1 (f + [ImaginaryI] g)] i.e. it refuses to distribute the complex conjugate throughout the > expression. What I would like it to tell me is: (f + [ImaginaryI] g) Conjugate[c2] + (f - [ImaginaryI] g) > Conjugate[c1] The closest I have been able to come to getting what I want is by > using: ComplexExpand[Refine[Conjugate[ c1 u1 + c2 u2]], {c1, c2}] but this separates c1 and c2 into their real and imaginary parts. The > above expressions are much simpler than the ones I REALLY want > Mathematica's help in simplifying. If I use this ComplexExpand > command, then I'm going to have to recombine them into complex numbers > again, which would be very very bad. Roy > === Subject: Re: FrameLabels in ContourPlot How about an example. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > The vertical frame labels in Version 6.0 are so far away from the > Contour Plot and so close to the border that they are partially > obscured if one asks for anything larger than about a 12 point font. Someone asked about this back in October without a reply. > Is there some solution? > Does Wolfram try to fix these things? > === Subject: A very strange calculation in Mathematica 6 To whom it my concern, I have found a very strange calculation with Mathematica 6. I have checked with Mathematica 5.1 and I understood that there are some missed functions (maybe wrong definition) in Mathematica 6. So, this is a reason that I write you this e-mail. (Last week I have sent it to some people in Wolfram Research but they did not answer to me yet). For start you may use the following function which is hypergeometric 2F0, and try to evaluate the following example by Mathematica 6 and 5.1; *********** Evaluate by Mathematica 6 ************** input: HypergeometricPFQ[{-3/2, 5/2}, {}, 1] output:ComplexInfinity *********** Evaluate by Mathematica 5 ************** input: HypergeometricPFQ[{-3/2, 5/2}, {}, 1] output: I calculated this by hand and it becomes to BesselK function which Mathematica 5.1 answered. I have evaluated the HypergeometricPFQ[{a, b}, {}, z] by Mathematica 5.1 and it answered to me . You may evaluate the same function by Mathematica 6, you will receive no answer. Moreover, there are some missing hypergeometicPFQ in the Mathematica 6, which I strongly suggest to people to check all of their calculations by Mathematica 5.1 . Ebrahim Karimi Dipartimento di Scienze Fisiche, Universit.88 di Napoli Federico II, Complesso di Monte S. Angelo, via Cintia, 80126 Napoli, ITALY Office Phone: +39-081-676 433 Mobile (phone): +39-389-3448689 Homepage: http://people.na.infn.it/~karimi/ === Subject: Re: Identical elements Please disregard my suggestion of KroneckerDelta. I didn't realize it is not efficient for large data. (By a large factor) d = Table[5, {100000}]; Timing[KroneckerDelta @@ d] {93.32, 1} Timing[Boole[SameQ @@ d]] {0., 1} -- Dana DeLouis Mathematica 6.01 (Windows Vista) I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. Your help is highly appreciated. > HMQ > === Subject: Re: Pattern matching problem > Hi all, > Here is my problem: Given a polynomial in the variables u[x,t] and its > spatial derivatives (for example, the polynomial could be 1 + u + > u_xx*u_xxx^2), count the number of spatial derivatives with multiplicity. > That is, after writing the above polynomial as > 1 + u + u_xx * u_xxx * u_xxx the output should be 2 + 3 + 3 (basically, you count the number of x's). I have tried implementing this using a pattern matching approach. Here is > what I tried: f[equation_ ] := Sum[ k * j * Count[ equation , D[ u[x, t], {x, j} ] ^ k , > {0, infinity} ], {j, 1, 50}, {k, 1, 50}] This fails to work on, for example, the input u_xx^2, because it outputs 6 > when it should output 4. This is because the u_xx is counted (+2 to the > sum), and the u_xx^2 is counted (+4 to the sum). This is because the u_xx is > nested inside the Power[ , 2] in its representation in Mathematica and so > it gets counted too many times in my formula. I can't seem to figure out a > way to use the provided that operator /; to make this formula work. I've also tried doing some replacement methods, but to no success. One possibility is replacing the Power[] with an explicit product: In[1]:= ee=1+u[x,t]+D[u[x,t],{x,2}] D[u[x,t],{x,3}]^2 Out[1]= 1+u[x,t]+(u^(2,0))[x,t] (u^(3,0))[x,t]^2 In[2]:= ee1 = ee /. expr_^n_Integer /; n>1 :> (HoldForm@Times[##]&) @@ ConstantArray[expr,n] Out[2]= 1+u[x,t]+((u^(3,0))[x,t] (u^(3,0))[x,t]) (u^(2,0))[x,t] In[3]:= Cases[ee1, HoldPattern[Derivative[n_,_][u][__]] :> n, Infinity] Out[3]= {3,3,2} In[4]:= Plus@@% Out[4]= 8 Just a consistency check: In[5]:= ReleaseHold[ee1] == ee Out[5]= True === Subject: Re: Pattern matching problem *when* you implement it, using pattern matching than there is no Sum[] and no Count[] but patterns instead, i.e., myCount[u_[x_], u_, x_] := 0 myCount[Derivative[n_][u_][x_], u_, x_] := n myCount[expr_, _, x_] /; FreeQ[expr, x] := 0 myCount[expr_Plus, u_, x_] := myCount[#, u, x] & /@ expr myCount[expr_Times, u_, x_] := myCount[#, u, x] & /@ (Plus @@ expr) myCount[Power[expr_, i_Integer], u_, x_] := i*myCount[expr, u, x] and myCount[1 + u[x] + D[u[x], {x, 2}]*D[u[x], {x, 3}]^2, u, x] gives 8 as you expect. Jens > Hi all, > Here is my problem: Given a polynomial in the variables u[x,t] and its > spatial derivatives (for example, the polynomial could be 1 + u + > u_xx*u_xxx^2), count the number of spatial derivatives with multiplicity. > That is, after writing the above polynomial as > 1 + u + u_xx * u_xxx * u_xxx the output should be 2 + 3 + 3 (basically, you count the number of x's). I have tried implementing this using a pattern matching approach. Here is > what I tried: f[equation_ ] := Sum[ k * j * Count[ equation , D[ u[x, t], {x, j} ] ^ k , > {0, infinity} ], {j, 1, 50}, {k, 1, 50}] This fails to work on, for example, the input u_xx^2, because it outputs 6 > when it should output 4. This is because the u_xx is counted (+2 to the > sum), and the u_xx^2 is counted (+4 to the sum). This is because the u_xx is > nested inside the Power[ , 2] in its representation in Mathematica and so > it gets counted too many times in my formula. I can't seem to figure out a > way to use the provided that operator /; to make this formula work. I've also tried doing some replacement methods, but to no success. > -Charlie === Subject: Re: Pattern matching problem Hello Charlie, I have an inelegant solution. I'll put it in steps so that you can see what it is doing: (*representative data*) poly =1 + u[x] + Sum[Product[ D[u[x], {x, RandomInteger[{1, 6}]}], {i, 1, RandomInteger[{1, 4}]}], {4}] InputForm[poly] (*Take each termp in poly and turn it into a list, @@@ applies list a first level*) temp = Flatten[Apply[List, Flatten[List @@@ poly]]] (*Replace each derivative it its order, so that powers are counted*) temp2 = temp /. Derivative[n_][u][x] :> n (*take the product of all the integers*) Times @@ Cases[temp2, _Integer] You could put it all together and make it look more elegant and (even) more unreadable... Craig > Hi all, > Here is my problem: Given a polynomial in the variables u[x,t] and its > spatial derivatives (for example, the polynomial could be 1 + u + > u_xx*u_xxx^2), count the number of spatial derivatives with multiplicity. > That is, after writing the above polynomial as > > > 1 + u + u_xx * u_xxx * u_xxx > > the output should be 2 + 3 + 3 (basically, you count the number of x's). > > I have tried implementing this using a pattern matching approach. Here is > what I tried: > > f[equation_ ] := Sum[ k * j * Count[ equation , D[ u[x, t], {x, j} ] ^ k , > {0, infinity} ], {j, 1, 50}, {k, 1, 50}] > > This fails to work on, for example, the input u_xx^2, because it outputs 6 > when it should output 4. This is because the u_xx is counted (+2 to the > sum), and the u_xx^2 is counted (+4 to the sum). This is because the u_xx is > nested inside the Power[ , 2] in its representation in Mathematica and so > it gets counted too many times in my formula. I can't seem to figure out a > way to use the provided that operator /; to make this formula work. > > I've also tried doing some replacement methods, but to no success. > > > -Charlie > > > -- W. Craig Carter === Subject: Re: Pattern matching problem Hi Charlie, use ReplaceAll (/.) instead of Count. ReplaceAll treats any piece at most once. Here is an example, where expression is your expression. We prevent any evaluation of the found multiplicity by my[..] and use Total to add all arguments to my: t=expression/. D[u[x],{x,i_}]^k_.:>my[i k] Cases[t,my[x_]:>x,Infinity]//Total hope this helps, Daniel > Hi all, > Here is my problem: Given a polynomial in the variables u[x,t] and its > spatial derivatives (for example, the polynomial could be 1 + u + > u_xx*u_xxx^2), count the number of spatial derivatives with multiplicity. > That is, after writing the above polynomial as > 1 + u + u_xx * u_xxx * u_xxx the output should be 2 + 3 + 3 (basically, you count the number of x's). I have tried implementing this using a pattern matching approach. Here is > what I tried: f[equation_ ] := Sum[ k * j * Count[ equation , D[ u[x, t], {x, j} ] ^ k , > {0, infinity} ], {j, 1, 50}, {k, 1, 50}] This fails to work on, for example, the input u_xx^2, because it outputs 6 > when it should output 4. This is because the u_xx is counted (+2 to the > sum), and the u_xx^2 is counted (+4 to the sum). This is because the u_xx is > nested inside the Power[ , 2] in its representation in Mathematica and so > it gets counted too many times in my formula. I can't seem to figure out a > way to use the provided that operator /; to make this formula work. I've also tried doing some replacement methods, but to no success. > -Charlie === Subject: 2*m^z - m^z = ? What do you think about this: Table[ {2*m^z - m^z, FullSimplify[2*m^z - m^z]}, {m, 1, 21}] // TableForm The answer is very interesting (only odd numbers are treated well): 1 1 -2^z + 2^(1 + z) 2^z 3^z 3^z 2^(1 + 2*z) - 4^z 4^z 5^z 5^z 2^(1 + z)*3^z - 6^z 2^(1 + z)*3^z - 6^z 7^z 7^z 2^(1 + 3*z) - 8^z 8^z 9^z 9^z 2^(1 + z)*5^z - 10^z 2^(1 + z)*5^z - 10^z 11^z 11^z 2^(1 + 2*z)*3^z - 12^z 2^(1 + 2*z)*3^z - 12^z 13^z 13^z 2^(1 + z)*7^z - 14^z 2^(1 + z)*7^z - 14^z 15^z 15^z 2^(1 + 4*z) - 16^z 16^z 17^z 17^z 2^(1 + z)*9^z - 18^z 2^(1 + z)*9^z - 18^z 19^z 19^z 2^(1 + 2*z)*5^z - 20^z 2^(1 + 2*z)*5^z - 20^z 21^z 21^z Can anyone explain the reason for this behavior? === Subject: Re: Fourier transform in arbitrary dimension? Hi Barrow, I think the easiest would be to go to hyperspherical coordinates. Calling theta the angle between Q and x, such that Qcdot x = q*x*cos(theta), the transformation is d^Dq --> P(D) * q^{d-1} * sin(theta)^{d-2} dq dtheta with P(D) = 2 * pi^{(D-1)/2} / Gamma((D-1)/2) In Mathematica writing: substituting d for D because of pre-assigned meaning of D, P[d_] = 2*Pi^((d-1)/2)/Gamma[(d-1)/2]; A[d_] := Integrate[q^(d-1) Sin[th]^(d-2) P[d]/(2 Pi)^d*Exp[- I*q*x*Cos[th]] * 1/q^2, {q, 0, Infinity}, {th, 0, Pi}, Assumptions -> x > 0] Doing the angular integral first, you get A[d_] := Integrate[(q^(d/2)*x^(1-d/2)*BesselJ[d/2-1,q*x])/(2*Pi)^(d/2) * 1/q^2, {q, 0, Infinity}, Assumptions -> x > 0] where your function to be transformed, 1/q^2, is still recognizable. Mathematica cannot do this last step directly; it takes some manual fiddling with intermediate results to see that the angular integral is really just a Bessel function. Assuming that 1/q^2 is really the function you wish to transform, you can simplify by substituting z=q*x, getting A[d_] := (2*Pi)^(-d/2) * x^(2-d) * Integrate[z^(d/2-2)*BesselJ[d/ 2-1,z], {z, 0, Infinity}] This integral does not converge for d>=5. However, it is oscillatory, and by neglecting the oscillating part we can get a decent result: J[d_, Z_] = Integrate[z^(d/2-2)*BesselJ[d/2-1, z], {z, 0, Z}, Assumptions -> {Z > 0, d > 2}]; Series[J[d, Z], {Z, Infinity, 0}] // Normal // Expand You see that the result contains three terms: the first two are oscillatory, and the third one is constant in Z, equal to 2^(d/2-2)*Gamma[d/2-1]. Only the last one is relevant. Putting everything together, the result of the d-dimensional Fourier transform of 1/q^2 is A[d_] = Gamma[d/2-1]/(4*Pi^(d/2)*x^(d-2)) Since you knew this already (up to the prefactor), I hope you are more interested in the general solution. The last step, neglecting the divergent oscillatory terms in the integral for d>=5, is a bit icky, but seems to work. Maybe somebody else has a good explanation of whats happening here? Roman. I would like to calculate a Fourier transform in arbitrary dimension > , say D, of the function 1/q^2, where q denotes the absolute value > of a D dimensional spatial vector. > The integral I have to perform is int frac{d^Dq}{(2pi)^D}exp(-iQcdot x)frac{1}{q^2} where |Q| = q. > But I cant find a way to tell Mathematica to calculate this integral > of dimension D. > PS. The answer is proportional to Gamma(D/2 - 1)(x^2/4)^{1-D/2} Any ideas would be appreciated. === Subject: OpenerView (with cells?) In the Mathematica documentation viewer, it looks as though sections and subsection headers are implemented using an OpenerView that can contain cells. At least when you click on the disclosure triangle next to sections like Examples, More Information, Options, and so on, the view reveals a number of input, output, and text cells. How are those section headers implemented? An ordinary OpenerView, as far as I can tell, cannot contain cells (although you can fake it a little bit using DisplayForm). I looked at the cell expression for one using Show Expression but what I found was just a reference to a stylesheet: Cell[TextData[{ Basic Examples, , Cell[(4), ExampleCount] }], ExampleSection, CellID->454094506] Any ideas on how that effect is achieved? Id like to use something similar in my own notebooks. Jason -- 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: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph The following works as expected to highlight two of the edges of a graph with a different color each: <{Red,Blue}]] And the docs say that AnimateGraph takes the same options as Highlight. But the following does NOT work -- it uses just the first color, Red, when animating the highlighting of the two edges: AnimateGraph[g, {{1, 2}, {2, 3}}, HighlightedEdgeColors -> {Red, Blue}] Whats wrong? (I do know that I used different syntax in the 2nd argument of Highlight, on the one hand, and in the 2nd argument of AnimateGraph, on the other hand. For Highlight to work within ShowGraph so as to animate edges, it is necessary to put the extra level of nesting in each edge specification. But such extra nesting in the case of AnimateGraph would not work: it gives no animation of edges.) -- 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: Print[Plot] vs Print[text,Plot]? There are a *lot* of extremely useful things New in 6.0 that are very > much worth the effort to learn. > Yes, I totally agree. So, could you please point me to the well-organized, well-written, well-illustrated introduction to (repeat: Introduction to, not Detailed Reference Documentation for) the most important and useful of these new things (and the ones most changed since 5.n), --that I can order for $20 or $30 from amazon (a very small fraction of the cost of Mathematica itself) (although something that, with more savvy software developers, comes in the box with the product itself) --and can read in the evening, or on my next plane trip, or in the dentists waiting room, or during a particularly dull meeting --and can thereby get an _overview_ --- a _roadmap_ -- a _preview_ --- of these useful new things, to let me know what I need to dig into further to meet my particular, specific needs as a user (and which of these I wont immediately need and can ignore). What? You want me to go to the Mathematica Documentation Center? Several _hundred_ tersely labeled clickable links just on the initial page? Each of which leads, not to a simple introduction, but to a complex formal documentation page with multiple further links to click? And all of which can only be read and navigated _on screen_? You and I, Im afraid, just think differently. === Subject: ReplacePart and Compile in Mathematica 6.0 the syntax of the function ReplacePart[] changed significantly as compared to earlier versions. While the old syntax is not documented any more, it still seems to work in V6.0.2.1: New syntax: ReplacePart[{1, 2, 3}, 3 -> 1] {1, 2, 1} Old, now undocumented syntax: ReplacePart[{1, 2, 3}, 1, 3] {1, 2, 1} Unfortunately, in compiled functions the new syntax does not seem to work Compile[{}, ReplacePart[{1, 2, 3}, 3 -> 1]] // InputForm During evaluation of In[14]:= ReplacePart::argrx: ReplacePart called with 2 arguments; 3 arguments are expected. >> CompiledFunction[{}, {{2, 1, 1}}, {0, 3, 0, 0, 2}, {{1, 5}, {45, {1, 2, 3}, 2, 3, 0}, {54, Function[{}, 3 -> 1],2,0, 2}, {55, ReplacePart, 2, 1, 0, 2, 0, 2, 2, 1, 1}, {2}}, Function[{}, ReplacePart[{1, 2, 3}, 3 -> 1]], Evaluate] while the old syntax produces nicely compiled code: InputForm[Compile[{}, ReplacePart[{1, 2, 3}, 1, 3]]] CompiledFunction[{}, {{2, 1, 0}}, {0, 2, 0, 0, 1}, {{1, 5}, {45, {1, 2, 3}, 2, 3, 0}, {7, 3, 0}, {7, 1, 1}, {71, 0, 0, 0, 0, 1}, {2}}, Function[{}, ReplacePart[{1, 2, 3}, 1, 3]], Evaluate] This situation is somewhat confusing (the error message seems to be clearly wrong) and either a bug or a misconception on my side? Is it intended that the new ReplacePart cannot be compiled any more? Is the documentation of ReplacePart in V6 incomplete, and should also mention the old syntax? (More generally: Could it be annotated in the documentation, which functions can be compiled and which functions cannot be compiled. For me it is always an adventure to figure out a compiled version of a routine I need, because of this lack of basic information.) Michael Weyrauch === Subject: Re: Wolfram User Interface Research? >> Its really all a matter of what one has learned, and how well, and how >> accustomed one is to the language. As just one rather simple-minded >> example, suppose you want to form the running cumulative sum of a list >> (in APL-speak, a vector) of numbers. In APL, this is given by >> + vec But I suspect that most users of Mathematica are mathematicians (or physicists or engineers or the like) and so come from a background of standard mathematical notation. Whilst Mathematica does try hard to stick with this it doesnt always and special symbols (like #, @) and so on are not transparent to a new user and not something that you would ordinarily search on. I have the advantage of an old fashioned thing made of paper, with hard covers (called a book) for Mathematica 5 and can flick through, see a symbol I dont recognise and read about it and think there may be better ways of expressing things than the way I am used to. With an online help I dont know that you would ever go and just look up random symbols unless someone had pointed you in the right direction. Whilst this is also true for standard mathematical notation, it is just that - standard. Mathematica isnt, it differs in some notations from other similar software (yes they do exist) and for the casual user (such as myself) it is very hard to learn this. One thing that would help me enormously from this forum is that when someone posts a suggestion for how to encode a particular issue (and I find these posts extremely helpful)is a bit of explanation of some of the more obscure terminology. I realise this adds a little to the effort involved in posting but if the idea is to help users learn how better to use Mathematica rather than just provide one off solutions to problems then this would be a big benefit. > A useful tip when deciphering code such as you describe, is to wrap it in Hold (to stop it evaluating, and FullForm, to see what it is really made of. For example: f @@ g /@ ll // Hold // FullForm generates Hold[Apply[f,Map[g,ll]]] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Wolfram User Interface Research? Is the primary market for Mathematica supposed to be > Mathematica programmers, skilled in the arcana of the > more abstruse parts of Mathematica, or ordinary users > whose primary interests and skills lie in many, many other > fields -- and who want Mathematica to be (for them) just > an easy to learn, easy to use, easy to remember tool? Mathematica could not function the way it does unless it satisfied > both types of users. It has to be powerful enough for professional > programmers if not for other reason than just the fact that a large > part of Mathematica itself (and all add on packages) are written in > the Mathematica programming language. It also has to satisfy enough > ordinary users for even more obvious reasons. In my opinion it has > always performed both functions admirably. Fully and totally agree. > These abstruse parts of Mathematica are not obligatory for ordinary > users but for Mathematica programmers and developers (and many power > users) they make life a lot easier. Also agree -- but my expectation would be that there are (or could be -- and should be) a *great* many more ordinary users than power users. So its important for both types that *both* markets be well served -- and especially the ordinary users, because there are so many more of them. Getting their $$ is vital to the success of Matheamtica . The power users are savvy enough that if Mathematica is very good -- which it is -- theyll wade through minor difficulties. The ordinary users wont --- theyll go elsewhere. > I believe you are familiar with TeX; at least you mention it often > enough. Do you seriously claim that Mathematica has more of these > abstruse parts than TeX? Have you ever heard words like TeXPert, > TexMaster etc? Are you able to program or even understand a set of Im quite familiar with TeX and can program in it, though Im not really a TeXpert. Plain TeX is *much* less complex than Mathematica. Several decades ago, in fact, the lab I was in had several secretaries/technical typists in the so-called Reports Group, several of whom had not finished high school --- but one could hand a hand-written draft of a ms to them, full of complex math -- and theyd turn it into TeX source. TeX is *much* smaller than Mathematica by whatever measure you like (syntax, size of code), and very well documented for ordinary or power users (have a look at Knuths TeXBook to understand this). LaTeX and other macro packages built on TeX are much more complex than plain TeX; I use them but would never try to dig into their internals. I can, however, go to amazon and buy any of several introductory manuals that tell me in understandable terms how to use them. > Finally, in all your posts you never seem to mention the very essential > (in the case of Mathematica) distinction between the Front End and the > Kernel. The great majority of new functionality in v. 6 concerns the > former. In principle there is no reason why Mathematica should not be > available with alternative Front Ends. It used to be possible to run > later versions with earlier Front Ends. I have not tried this with v. > 6 but that would be one way to do away with most of the new > complexity that you seems to displease you so. If that can be done --- and documented for ordinary users --- have at it! === Subject: Re: Dynamic: feature? > I have a cell containing this: > Dynamic[f[a, b]] > Then I do this: > a /: f[a, b] = 12 > and the dynamic cell updates to 12, as I would expect. > When I do this: > b /: f[a, b] = 45 > The dynamic cell does *not* update for some reason. >> It seems as though it does not realize an update has occurred when it >> is associated with b. > Does anyone know why this is? > Chris Weird. I witness the same behavior if the cells are evaluated in the > given order. However, ff one change the order of the assignments (i.e. b > first, then a) Dynamic[] works as expected. Evaluating the following > expressions in that order, Dynamic[f[a, b]] > (* The first output cell is: f[a, b] *) b /: f[a, b] = 45 > (* The first output cell is now: 45 *) a /: f[a, b] = 12 > (* The first output cell is now: 12 *) $Version => 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) I have also recorded the sessions in a PDF file. See http://homepages.nyu.edu/~jmg336/mathematica/weirddynamic.pdf -- A principle rule of debugging Dynamics...consider what Shift-Enter evaluations > do. In this case, exactly the same thing. In fact, Dynamic correctly reflects > what a Shift-Enter evaluation on f[a,b] would do at that very moment. > John Fultz > jfu...@wolfram.com > User Interface Group > Wolfram Research, Inc. It seems that I was creating two separate rules, one associated with a and one associated with b (I had expected the 2nd one to overwrite the 1st). Because a is the first argument, its rule takes precedence. enter does. Chris === Subject: Re: ? (*now Do and Table*) Craig, Just a (tongue in cheek) reminder that Mathematica is a wonderful all purpose environment in which to do Mathematics. 221 years ago the 10 year old Gauss would have solved the problem by coding:- n = 10000000; Timing[total = n (n + 1)/2] {0.000035, 50000005000000} Which is a whole lot faster! I realize that this is not very helpful in deciding usage of Table vs Do. But the precocious Gauss also might have tried Timing[total = Table[i (i + 1)/2, {i, 10000000}]] {20.46425400000001, {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, <<9999974>>, 49999885000066, 49999895000055, 49999905000045, 49999915000036, 49999925000028, 49999935000021, 49999945000015, 49999955000010, 49999965000006, 49999975000003, 49999985000001, 49999995000000, 50000005000000}} or better yet Timing[Total[Table[i (i + 1)/2, {i, 10000000}]]] {31.7433, 166666716666670000000} Just to show off ... :) PS Where would we be now if Stephen Wolfram had provided Gauss with a free Mathematica License back then? BTW What a surprising result (1666667)(1666667)(0000000) I wonder if anyone has computed this result before and explained its repetition of the first 7 digits? 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 > This is problem with a known simple result, but it will serve: lets > find the sum of the first 10000000 integers. (*lets use a do loop*) > Timing[ > icount = 0; > Do[icount = icount + i, {i, 1, 10000000, 1}]; > icount > ] (*this returns {10.2826, 50000005000000} on my machine.*) > (*10.28 being a measure of how long the computation took to run*) (*lets try a table*) > Timing[ > Total[Table[i, {i, 1, 10000000, 1}]] > ] (*This returns {3.25516, 50000005000000} on my machine*) === Subject: 3D Arrows Apparently Arrows is only a 2D graphic. Is there a way to make an arrow in 3D? Robert M Lurie === Subject: Re: Exclusions > On Apr 22, 2:39 am, Gulliet pasting. In my notebook, the syntax is correct. I dont expect an automatic exclusion, but I do get an additional > (unwanted) exclusion at y==0 && x<0 when I use the following command: Plot3D[ pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, > Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, > ClippingStyle -> None, > Exclusions -> { {ArcTan[x, y] == 0.5, > x > 0 && y > 0}, {ArcTan[x, y] == -Pi + 0.5, x < 0 && y < 0}},= > ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, > AxesLabel -> {x, y}] > Exclusion search effectively works by bracketing the root, so when you have ArcTan jump from -Pi to Pi it will also count as a root, similar to FindRoot[x - Round[x], {x, .25, .75}]. You can try adding a condition that excludes the unwanted region: Plot3D[Arg[((x + I y) E^(-.5 I))], {x, -1, 1}, {y, -1, 1}, Exclusions -> {{Arg[x + I y] == -Pi + 0.5, Abs@ Arg[x + I y] < Pi - .25}}, ExclusionsStyle -> {None, Red}, Method -> {RotationControl -> ArcBall}] Maxim Rytin m.r@inbox.ru === Subject: Re: Wolfram User Interface Research? >>Its really all a matter of what one has learned, and how well, and >>how accustomed one is to the language. As just one rather >>simple-minded example, suppose you want to form the running >>cumulative sum of a list (in APL-speak, a vector) of numbers. In >>APL, this is given by >>+ vec >But I suspect that most users of Mathematica are mathematicians (or >physicists or engineers or the like) and so come from a background >of standard mathematical notation. Whilst Mathematica does try hard >to stick with this it doesnt always and special symbols (like #, @) >and so on are not transparent to a new user and not something that >you would ordinarily search on. I have the advantage of an old >fashioned thing made of paper, with hard covers (called a book) for >Mathematica 5 and can flick through, see a symbol I dont recognise >and read about it and think there may be better ways of expressing >things than the way I am used to. While I also have the book that came with earlier versions of Mathematica and find it useful, it is very easy to determine what new symbols do without the book. And the documentation in version 6, while harder to browse, is much more efficient for finding information on a known symbol. For example, if I type @@ in a cell, select what I typed and use the keyboard short cut (cmd-shift-f on a Mac) I am almost instantly taken to a page that provides considerable detail as to what this is and how it can be used. >With an online help I dont know that you would ever go and just look >up random symbols unless someone had pointed you in the right direction. The online documentation certainly isnt optimum for say finding all odd symbols used in Mathematica. Browsing the book is better for this. But once you know a symbol is used, the new document center is very efficient for finding information for that symbol. === Subject: Re: installing Playe rPro killed using Mathematica itself: > Such a gross oversight on Wolframs part is unexpected. I suspect that > unless the problem is fixed in short order that PlayerPro will not make > it for very long. Given all that I have heard, I would not install it on > my system. I am just thankful that my procrastination delayed prevented > this problem for me. I would like to thank all those who quickly alerted > the group. Kevin > I am quite convinced that PlayerPro will be a valuable tool for creating Mathematica applications. The problem discussed is only an inconvenience to the creator of an application, because almost by definition, the recipient will not have Mathematica. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Mathematica courses and news from the Benelux Due to the support of the Katholieke Universiteit Leuven CANdiensten will be providing Mathematica courses in Belgium. We are aiming at some course dates in June and September. More news about this will follow. Topics of this newsletter __ o International Mathematica Symposium 2008 o Course: Dynamic Interactivity o Course: Introduction to Mathematica o Course: Programming with Mathematica Check out our complete event list at: http://www.can.nl/events/ International Mathematica Symposium __ June 20-24 in Maastricht Celebrate the 20th Mathematica anniversary on the 23rd of June in the heart of Europe. The International Mathematica Symposium 2008 is a 5 day bi-annual event. Many special key note speakers will be present. The event is hosted by the University of Maastricht and the organization is in the hands of the Technical University of Eindhoven. The now bi-annual meeting is an interdisciplinary conference for Mathematica users in mathematics, natural and life sciences, engineering, computer science, education, industry and commerce, social sciences and law, graphics, design and architecture, arts and music. If you use Mathematica in research or teaching, or if you are developing products based on Mathematica, then the Symposium is a unique opportunity to share your results with like-minded colleagues. IMS has a deserved reputation as an exceptionally convivial and friendly gathering. More detailed information is available from the IMS 08 web site: http://www.ims08.org Course: Dynamic Interactivity by Professor Fred Simons __ June 17 and October 28 in Amsterdam The course is meant for those users of Mathematica who want to have a better insight in the new structures and functions in Mathematica, in particular in dynamic objects. But other topics, such as the completely new and innovative documentation system, new features of graphics, the new function Grid and functions for creating buttons and links, will be discussed as well. Participation costs EURO 95,-- per person excluding VAT Registration and more information: http://www.can.nl/events/details.php?id=48 Course: Introduction to Mathematica by Professor Fred Simons __ May 20, October 7 and December 16 in Amsterdam The course offers an overview of Mathematicas many rich features. The broad knowledge you acquire enables you to explore Mathematica after the course at your own pace. Participation costs EURO 95,-- per person excluding VAT Registration and more information: http://www.can.nl/events/details.php?id=6 Course: Programming with Mathematica by Professor Fred Simons September 16 and November 18 in Amsterdam All programming language functionality is available in Mathematica. Programs written in a standard programming language can be translated into a Mathematica program. However, this leads rarely to an efficient program. Often we can improve such a translation by using some more advanced Mathematica commands. Even better is to start from the very beginning and to use the structure of the dataset and the available functions in Mathematica for manipulation to arrive at the desired output. These principles will be demonstrated by many examples. Much attention will be paid to the speed of the programs. Participation costs EURO 250,-- per person excluding VAT Registration and more information: http://www.can.nl/events/details.php?id If you have any questions, please feel free to contact me. Dick Verkerk _ CANdiensten, Nieuwpoortkade 23-25, NL-1055 RX Amsterdam voice: +31 20 5608400 fax: +31 20 5608448 verkerk@can.nl _ Your Partner in Finance, Mathematics and Statistics! === Subject: 9th International Mathematica Conference 2008 9th International Mathematica Conference 2008 20-24th of June, Maastricht, the Netherlands the International Mathematica Conference is the (bi-)annual event by and for all Mathematica enthusiasts worldwide. Attendants from all continents except Antarctica come to Maastricht this year to exhibit their exciting Mathematica applications, to learn about the latest Mathematica features from key developers, and to celebrate Mathematicas 20th anniversary. The International Mathematica Symposium is a 2-track, 5-day, interdisciplinary conference with topics ranging from theoretical physics, engineering, and education to medicine, art, and law. The common denominator is Mathematica, its core technologies and applied mathematics. You can find more information on our website www.ims08.org. The submission deadline has passed but do not miss the early registration deadline on the 1st of May. You may never discover the full potential of Mathematica if you do not join the global community of Mathematica users! We hope to welcome you in Maastricht, a delightful, medieval city in the heart of Europe, right next to Aachen, Germany. the IMS08 organizing committee P.S. for budget minded travelers we have compiled a list of cheap but good hotels in Maastricht that are still available: Orangerie, =80 77, www.hotels.nl/maastricht/orangerie/ Hotel Poshoorn, =80 80, (still available, except Saturday) www.poshoorn.nl Hotel Randwyck, =80 60, (only very few rooms) www.hotelrandwyck.nl/en/home/Booking.com StayOkay Maastricht, dorm beds, =80 26, membership HI required: www.stayokay.com/index.php?pageID=3207&hostelID=356047 Hotel Les Charmes, =80 105, 200 meter from conference location: www.hotellescharmes.nl/uk/index.htm WeekendjeWeg, =80 50-90, almost full: www.weekendjeweg.nl/hotels/nl/hotel-maastricht/?mf=9&df=18 === Subject: Re: Re: installing Playe rPro killed using Mathematica itself: Really? What have you heard or read that gives you such a negative impression? Ive read every remark about Player Pro on the group, and I believe this thread represents the only bug/negative remark about the product Ive seen. If I missed something, please let me know! Specifically, Murray reported one bug in two different ways, conceded by me both times, complete with mea culpas and workarounds... http://forums.wolfram.com/mathgroup/archive/2008/Apr/msg00605.html http://forums.wolfram.com/mathgroup/archive/2008/Apr/msg00924.html John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Such a gross oversight on Wolframs part is unexpected. I suspect that > unless the problem is fixed in short order that PlayerPro will not make > it for very long. Given all that I have heard, I would not install it on > my system. I am just thankful that my procrastination delayed prevented > this problem for me. I would like to thank all those who quickly alerted > the group. Kevin > Yes, this fixes the problem with the mathpass for Player Pro under my >> configuration effectively killing the mathpass for Mathematica itself. >> Of course the problem should have been avoidable by the installer >> program, or at least by installation directions, in the first place. > Yes, this is because of the overlapping use of MATHEMATICA_USERBASE. > Anybody > who does not set this variable will not see the problem. To work > around this... * Take your current mathpass file and move it into Mathematicas > installation > directory in ConfigurationLicensing. > * Start Player Pro and enter your password. > * Take the newly generated mathpass file and move it into Player Pros > installation directory in ConfigurationLicensing. > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. > With an existing installation of Mathematica 6.0.2 under Windows, I >> just >> installed Player Pro. The result: if I start Mathematica itself and >> open a new notebook there, I am prohibited from typing any and all >> input. >> This sort of thing is intolerable! An utterly time-frittering >> aggravation. >> I suspect that the scenario involved here was not tested by WRI: My >> mathpass for Mathematica itself is in the Licensing subdirectory of >> my >> USERBASE directory, which is the same as my BASE directory (both >> set by >> Windows environment variables MATHEMATICA_BASE and >> MATHEMATICA_USERBASE). >> This is hardly the first time I have run into trouble with multiple >> passwords from multiple Wolfram Research products. It is something >> they >> have just not yet gotten right. Beware! >> What I did as a temporary fix was to use my Windows backup program >> to >> restore my pre-existing mathpass file. Now regular Mathematica >> works. >> But of course Player Pro does not. === Subject: Re: Print[Plot] vs Print[text,Plot]? (*now Do and Table*) And I was surprised much more when I have tried the more simple form of the first expression: Timing[icount = 0; Do[icount += i, {i, 1, 10000000, 1}]; icount] (*this returns {36.042, 50000005000000} on my machine*) It means that using the += operator takes about 50% more time than the usual form icount = icount + i; It is sad and very surprising! Table is usually a better choice than Do, but that is a choice and the= > language is accommodating enough to allow you to make that choice; and= > if you should be curious, to explore. > =9A_Why_ (or, in what circumstances?) would Table be a better choice tha= n Do? =9AI appreciate that their logical behavior is similar, and indeed they = can be > coded very similarly. I am happy to try to answer. Ill take the time to answer at length, because I find that many > people that I try to help out have similar viewpoints as yours. > Perhaps, I may have something useful to contribute. Primarily, it is a matter of choice and familiarity. =9AAnd they (Table > and Do) are just about interchangeable, except in a few unusual (and > technical) cases. =9ATables advantage is speed and efficiency. (Once I > asked someone at Wolfram how I should explain this to my students, and > the kind answer was because Do has to access the =9Amain kernels > evaluation loop, and Table doesnt). =9AIll try to demonstrate this as an example. Ill try to explain my > steps carefully, and Ill avoid the use of #&/.^= syntax. =9AIt took me > a while to cook this up--I hope that my example doesnt go amiss. This is problem with a known simple result, but it will serve: lets > find the sum of the first 10000000 integers. (*lets use a do loop*) > Timing[ > =9Aicount = 0; > =9ADo[icount = icount + i, {i, 1, 10000000, 1}]; > =9Aicount > =9A] (*this returns {10.2826, 50000005000000} on my machine.*) > (*10.28 being a measure of how long the computation took to run*) (*lets try a table*) > Timing[ > =9ATotal[Table[i, {i, 1, 10000000, 1}]] > =9A] (*This returns {3.25516, 50000005000000} on my machine*) This is a simple example, but it illustrates the difference nicely. ( > Personally, Ive yet to > find a case for which I can replace a Do with a Table or similar list > construct, although I am sure readers of this group could easily > construct one as a challenge.) Another way to think of this is that Mathematica is very good at > operating on lists. =9ATable and Lists work together nicely, and many of > the functions like Total are designed to help you make your > programming easier. Now, if you put yourself =9Ain the mind of a beginner who has neither > seen Do, For, While, or Table. Which style would you recommend based > on speed alone? =9AWhich style would you recommend on readability alone? So, a typical beginning user might find themselves tending to use > Lists. =9AThey are content for a couple years, but soon master the idea > so that begin to do what is natural, abbreviate (ASAP, RJ46, LOL, > AWOL, PM. FM...). =9AThey find shortcuts and optimize their time: First attempt may be something like this: > (*create a list*) Table[i,{i,1,10000000}] (*horrors, the output is too long, and I know what it might look like anyw= ay*) (*they graduate to this*) > mytable= Table[i,{i,1,1000000}]; > Total[mytable] (* soon they get tired of typing and find an abbreviated version *) Total[Table[i,{i,1,1000000}]] (* soon they get tired of moving around the screen to type the two bracket= s,*) > (* so they find another way to do the same thing, no better, arguably > less readable > (*at first*) > Total@Total[Table[i,{i,1,1000000}] > (*or, depending on where your cursor tends to be sitting*) > Table[i, {i, 1, 1000000}] // Total (*thus they learn a semaphore for analogous constructs*) > (*but theres more, with ever more symbols, the efficiency and power goes*= ) > (*up rapidly, but the readability goes down for beginners*) > (*where you find the happy medium is entirely up to you*) In my opinion, this is the fun part of mathematica. I get to decide > how to share the labor with mathematica, and I get to decide how > obscure to make my code. =9ASometimes, for my own pleasure, I write it > as obscurely as possible (and I am no master at this by a long shot). > If I am writing code that I hope someone else will use and modify, or > learn from, I try to write as readable as possible. -- W. Craig Carter === Subject: Re: Print[Plot] vs Print[text,Plot]? (*now Do and Table*) I should notice that it is VERY strange behavour that the simplest Do[] loop takes MUCH more time than constructing a list of elements and summing them. I do not understand the reason. It looks like a defect. W_Craig Carter: Table is usually a better choice than Do, but that is a choice and the > language is accommodating enough to allow you to make that choice; and > if you should be curious, to explore. > _Why_ (or, in what circumstances?) would Table be a better choice than Do? I appreciate that their logical behavior is similar, and indeed they can be > coded very similarly. I am happy to try to answer. Ill take the time to answer at length, because I find that many > people that I try to help out have similar viewpoints as yours. > Perhaps, I may have something useful to contribute. Primarily, it is a matter of choice and familiarity. And they (Table > and Do) are just about interchangeable, except in a few unusual (and > technical) cases. Tables advantage is speed and efficiency. (Once I > asked someone at Wolfram how I should explain this to my students, and > the kind answer was because Do has to access the main kernels > evaluation loop, and Table doesnt). Ill try to demonstrate this as an example. Ill try to explain my > steps carefully, and Ill avoid the use of #&/.^= syntax. It took me > a while to cook this up--I hope that my example doesnt go amiss. This is problem with a known simple result, but it will serve: lets > find the sum of the first 10000000 integers. (*lets use a do loop*) > Timing[ > icount = 0; > Do[icount = icount + i, {i, 1, 10000000, 1}]; > icount > ] (*this returns {10.2826, 50000005000000} on my machine.*) > (*10.28 being a measure of how long the computation took to run*) (*lets try a table*) > Timing[ > Total[Table[i, {i, 1, 10000000, 1}]] > ] (*This returns {3.25516, 50000005000000} on my machine*) This is a simple example, but it illustrates the difference nicely. ( > Personally, Ive yet to > find a case for which I can replace a Do with a Table or similar list > construct, although I am sure readers of this group could easily > construct one as a challenge.) > Another way to think of this is that Mathematica is very good at > operating on lists. Table and Lists work together nicely, and many of > the functions like Total are designed to help you make your > programming easier. Now, if you put yourself in the mind of a beginner who has neither > seen Do, For, While, or Table. Which style would you recommend based > on speed alone? Which style would you recommend on readability alone? So, a typical beginning user might find themselves tending to use > Lists. They are content for a couple years, but soon master the idea > so that begin to do what is natural, abbreviate (ASAP, RJ46, LOL, > AWOL, PM. FM...). They find shortcuts and optimize their time: First attempt may be something like this: > (*create a list*) Table[i,{i,1,10000000}] (*horrors, the output is too long, and I know what it might look like anyway*) (*they graduate to this*) > mytable= Table[i,{i,1,1000000}]; > Total[mytable] (* soon they get tired of typing and find an abbreviated version *) Total[Table[i,{i,1,1000000}]] (* soon they get tired of moving around the screen to type the two brackets,*) > (* so they find another way to do the same thing, no better, arguably > less readable > (*at first*) > Total@Total[Table[i,{i,1,1000000}] > (*or, depending on where your cursor tends to be sitting*) > Table[i, {i, 1, 1000000}] // Total (*thus they learn a semaphore for analogous constructs*) > (*but theres more, with ever more symbols, the efficiency and power goes*) > (*up rapidly, but the readability goes down for beginners*) > (*where you find the happy medium is entirely up to you*) > In my opinion, this is the fun part of mathematica. I get to decide > how to share the labor with mathematica, and I get to decide how > obscure to make my code. Sometimes, for my own pleasure, I write it > as obscurely as possible (and I am no master at this by a long shot). > If I am writing code that I hope someone else will use and modify, or > learn from, I try to write as readable as possible. > -- W. Craig Carter === Subject: Re: Print[Plot] vs Print[text,Plot]? (*now Do and Table*) > (*lets use a do loop*) > Timing[ > =9Aicount = 0; > =9ADo[icount = icount + i, {i, 1, 10000000, 1}]; > =9Aicount > =9A] (*this returns {10.2826, 50000005000000} on my machine.*) > (*10.28 being a measure of how long the computation took to run*) (*lets try a table*) > Timing[ > =9ATotal[Table[i, {i, 1, 10000000, 1}]] > =9A] (*This returns {3.25516, 50000005000000} on my machine*) W. Craig Carter Lets try the following: mmu = MaxMemoryUsed[]; Timing[icount = 0; Do[icount = icount + i, {i, 1, 10000000, 1}]; icount] MaxMemoryUsed[] - mmu (*This returns {25.657, 50000005000000} 1118080 on my machine*) mmu = MaxMemoryUsed[]; Timing[Total[Table[i, {i, 1, 10000000, 1}]]] MaxMemoryUsed[] - mmu (*This returns {7.651, 50000005000000} 479959784 on my machine but takes much more time because of using PAGEFILE*) 479959784/1118080=429.271 Constructing Table takes 429 times more memory than using Do[]! === Subject: Re: Defining output formats Hi Szabolcs, this seems a bug of TeXForm. In other forms it seems to work. If you say: Format[x]:={bf x}; without explizite format, your example seems to work: In[3]:= TeXForm[1+x^2] Out[3]//TeXForm= text{${backslash backslash $bf x$}$}^2+1 hope this helps, Daniel > On the doc page tutorial/DefiningOutputFormats there is an example: > This specifies the TeXForm for the symbol x. In[1]:= Format[x, TeXForm] := {bf x} The output format for x that you specified is now used whenever the TeX > form is needed. In[2]:= TeXForm[1 + x^2] Out[2]//TeXForm= > x^2+1 > Quite obviously, this does not work in the way the documentation > suggests. I would have expected {bf x}^2 + 1. Lets try another example: In[3]:= TeXForm[x] Out[3]//TeXForm= > text{${backslash backslash $bf x$}$} So is there a way to tell Mathematica that x should always be formatted > in bold in TeXForm? > === Subject: Re: When Find finds something - - it sometimes highlights the thing and sometimes puts a > little dotted box around it. Whats the difference? Its very hard to > see the dotted box sometimes and I have to Find it visually! Is there > a way to change this found indicator to make it more conspicuous? Steve Gray Ive noticed that if you first click on Find All then each > subsequent Find Next puts the found text in reverse video rather > than a hollow box otherwise. -Bob Also if you first click Find Next (hollow box highlight) and than close the window and use F3 to highlight subsequent matches, the higlight box will be black. Istvan === Subject: Re: Problem with RegionFunction Hello Zac, This was explained to me the following way. WIthin Manipulate, the PerformanceGoal option switches from Speed to Quality when a manipulate variable stops changing. Thus, the change in appearance of Graphics3D objects while sliding. To handle the boundaries of a plot well, values are probed on either side of the boundary even though they are not going to appear on the final plot. PerformanceGoal as I understand it, changes the way that plot resolves the boundaries and thus your 0^0. I hope this explanation is not too far off the mark. WCC I understand that the case where x=0 and y=0 is undefined, but I dont > understand why does Mathematica compute this case when ranges are > given explicitely to avoid such situations? Why do I have to define > the regionfunction to exclude x=0 and y=0 (as Fred suggested it)? Is > it not trivial to exclude these as the PlotRange dictates it? Why is > it that the problem does not surface when I omit the Manipulate[...] > wrap? > Istvan On Apr 23, 10:10 am, -Peer Kuska try > > Manipulate[ > Plot3D[Sin[x]*Cos[y], {x, 1, 10}, {y, 2, 10}, > RegionFunction -> Function[{x, y}, 45 <= (y^x)], > Exclusions -> x == 0], {dummy, {True, False}}] > > because y^x for x==0 and y==0 is undefined. > > -- W. Craig Carter