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 wi