A1 Troy, The reason for your difficulty shows up in the following: eqn = 2 +5x+ (x - 1)^2 == 3 +7x+ (x - 1)^3; Collect[eqn, x] 2 + (-1 + x)^2 + 5*x == 3 + (-1 + x)^3 + 7*x (Collect[#1, x] & ) /@ eqn 3 + 3*x + x^2 == 2 + 10*x - 3*x^2 + x^3 You need to map the use of Collect onto the sides of the equation. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > I apologize for the length of this post, but I don't see how else to be > precise about my question. > > The short story is this: > -- copy and paste the lines below into Mathematica > -- execute > -- the result is a really big expresssion, but I want the terms in this > expression > to be grouped in powers of my variable b. > > However, Collect[] doesn't appear to be working right. I call Collect[%, > b] and I think I'm getting % back. At the very least, I can clearly see > more than one term in the expression that includes b^9, for example. > > I'd be very grateful if someone a little more knowledgeable than I could > execute these lines and see if they can get Collect[] to work. Of, if > this is how Collect[] is supposed to work, what command should I be > using? > > > Troy. > > > So, here's what I did. First, to get my equation: > > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom > > pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) > > HH = -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 > > Now, my equation is really HH == 0, but there's some manipulations I > want to do first. I don't know Mathematica well, so all I could see to > do was to perform operations on HH, then put the equation together. > > H2 = Expand[HH] > H3 = Collect[HH, Sqrt[B^2 - b^2]] > H4 = H3*( (4 * (b*r)^2 + (B^2 - r^2)^2)^2 ) > H7 = H4*(r^2) > H8 = Collect[ Cancel[H7], Sqrt[-b^2 + B^2] ] > H9 = Equal[H8, 0] /. Equal[ > aa_ + Sqrt[B^2 - b^2]*bb_, 0] -> Equal[ Sqrt[B^2 - b^2]*bb, -aa] > H10 = Thread[#^2 &[H9], Equal] // ExpandAll > H11 = H10 /. Equal[ mm_ , nn_] -> Equal[ mm - nn , 0] > H12 = H10 /. Equal[ qq_ , 0] -> qq > > For H3 and H8, Collect[] seems to work. > The command to get H10 I copied from a post by Andrzej Kozlowski. > > H13 = Collect[H11,b] > H14 = Collect[H12,b] > > but the results don't seem to be 'collected' polynomials. > ==== Max: Your problem is due to the necessary space to the left of the y-axis to locate the ticks. Try, for example, eliminating the y-ticks: Plot[Sin[x], {x, 0, 10}, Ticks -> {Automatic, None}]; Plot[1000Sin[x], {x, 0, 10}, Ticks -> {Automatic, None}]; With an additional space in the x-range, it is possible to accommodate the y-ticks for both graphs keeping the alignment. Plot[Sin[x], {x, 0, 10}, PlotRange -> {{-1.5, 10}, Automatic}]; Plot[1000Sin[x], {x, 0, 10}, PlotRange -> {{-1.5, 10}, Automatic}]; Greetings Germ.87n Buitrago A. ----- Original Message ----- > > > At the display and printout, the y axes are not aligned. Even using the > PlotRegion and ImageSize Options doesn't help. The only way I found > was to align it manually with the mouse. > Is there a package that solves the problem? > The problem is, I have many, many plots to align... > I use Mathematica 4.0.2.0 on a Windows 2000 PC. > Who can help? > > Max > > Answers please to: > > ulbrich@biochem.mpg.de > > ==== The position of the plot in the cell is determined by option ImageMargins, and you may check that it is the same for both plots. But the plot includes the ticks along the axes, so the reason why the vertical axes are not aligned is that the ticks along them have different lengths, and this causes the position of each axis to move left or right, according to what is needed to include the ticks. You may check this by using the option Ticks->None in both plots. You'll see that the axes are now aligned. One possibility is to have the space assigned to the vertical ticks to be the same in both plots, and this may be achieved by using strings of the same length for the ticks, instead of letting them be automatically assigned. Try the following: In[1]:= Plot[Sin[x], {x, 0, 10}, Ticks -> {Automatic, {{-1, -1}, {-0.5, -0.5}, {0, 0}, {0.5, 0.5}, {1, 1}}}]; Plot[1000*Sin[x], {x, 0, 10}, Ticks -> {Automatic, {{-1000, 1000}, {-500, -500}, {0, 0}, {500, 500}, {1000, 1000}}}]; Here I left 5 positions as the maximum string length in both cases, corresponding to -0.5 and -1000, respectively. The vertical axes are now aligned. BTW, it is a relatively simple matter to construct the ticks without having to type a lot of stuff. Suppose t is the list of ticks you would like to have along the vertical axis, e.g.: In[2]:= t = Table[1000*j, {j, -1, 1, 0.25}]; In[3]:= tks = Transpose[{t, ToString /@ Round[t]}]; Then try In[4]:= Plot[Sin[x], {x, 0, 10}, Ticks -> {Automatic, {{-1, -1}, {-0.5, -0.5}, {0, 0}, {0.5, 0.5}, {1, 1}}}]; Plot[1000*Sin[x], {x, 0, 10}, Ticks -> {Automatic, tks}]; and you'll get an even nicer output. Tomas Garza Mexico City ----- Original Message ----- > > > At the display and printout, the y axes are not aligned. Even using the > PlotRegion and ImageSize Options doesn't help. The only way I found > was to align it manually with the mouse. > Is there a package that solves the problem? > The problem is, I have many, many plots to align... > I use Mathematica 4.0.2.0 on a Windows 2000 PC. > Who can help? > > Max > > Answers please to: > > ulbrich@biochem.mpg.de > > > ==== >I have 2 or more separate Plots which have different y but the same x >axes. >Like: > >Plot[Sin[x],{x,0,10}]; >Plot[1000Sin[x],{x,0,10}]; > > >At the display and printout, the y axes are not aligned. Even using the >PlotRegion and ImageSize Options doesn't help. The only way I found >was to align it manually with the mouse. >Is there a package that solves the problem? >The problem is, I have many, many plots to align... >I use Mathematica 4.0.2.0 on a Windows 2000 PC. > Pad each axis label with a string of blanks that makes both axes labels take up the same space. showplot[plt_] := Show[plt, Ticks -> {Automatic, Prepend[(Ticks /. AbsoluteOptions[plt])[[2]], {0.001, StringJoin[Table[ , {5}]]}]}, DisplayFunction -> $DisplayFunction] p1 = Plot[Sin[x], {x, 0, 10}, DisplayFunction -> Identity]; p2 = Plot[1000Sin[x], {x, 0, 10}, DisplayFunction -> Identity]; showplot[p1]; showplot[p2]; Bob Hanlon Reply-To: ==== Why make a list of them at all? That is, you know what the pairs are without listing them, and you can form any pair you want without listing them. So -- why spend all that memory, even if you have it? (And you don't.) I just see no reason for it. Bobby -----Original Message----- h=4;w=5; points=Flatten[Outer[List,Range[w],Range[h]],1]; pairs=Flatten[Map[Outer[List,{#},Drop[points,Position[points,#][[1,1]]-1 ],1][[1]]&,points],1]; The speed of the above calculation is reasonably fast. But I run into the memory problem. For example, for h=64 and w=64, the length of the list pairs will be w*h (w*h+1)/2 = 8,390,656. In my case, The numbers for h and w will be a lot larger than 64. How can I get around this memory problem or that's the dead end for my calculation (I do have 1 GB physical mem in Cheng >Dear group, > > I have the following question regarding a lengthy calculation >using Mathematica: > >For given w points in x direction and h points in y direction, I can >construct all the points using > > h=10; w=8; > points=Flatten[Transpose[Outer[List,Range[w],Range[h]]],1] > >Next, I need to find all the possible pairs of point including points >themselves, i.e., pair AA. I can use > > pairs=Outer[List,points,points,1] > >Then, I have to clear those pairs that repeat themselves, i.e., pair AB and >pair BA. Also, when w and h are of the order of 1000s, the computation >takes a very long time. Is there a better way of doing the second part of > >Sincerely > >Cheng > > >==================================================== >Cheng Liu, Ph.D. >MST-8, Structure/Property Relations >Materials Science and Technology Division >Los Alamos National Laboratory >Los Alamos, New Mexico 87545 > >==================================================== ==================================================== Cheng Liu, Ph.D. MST-8, Structure/Property Relations Materials Science and Technology Division Los Alamos National Laboratory Los Alamos, New Mexico 87545 ==================================================== ==== How do you remove the In[] and Out[] lines so they don't appear when you print? Brian (averso@yahoo.com) ==== I reported this to Wolfram Research, but have had no confirmation yet. Have others observed that there are problems displaying the headers in some of the help notebooks? Here's a demonstration of the problem: http://baldur.globalsymmetry.com/proprietary/com/wri/ch05.html#id3186296 I originally took this to be a font related issue, but I'm not sure anymore where the problem originates. The code for the notebooks is still a bit beyond my depth of understanding of Mathematica. I'm thinking about switching all Helvetica instances to Primasans which I got from WordPerfect. My understanding of how fonts work is fairly limited, though I've learned a great deal from investigating the origins of this problem I really believe there is a minor bug in the ToFileName[{$TopDirectory, SystemFiles, StyleSheets}, HelpBrowser.nb]. Any observations on this? -- Hatton's Law: There is only One inviolable Law. Reply-To: ==== Wolf, I timed your methods plus my own entry in the contest, for 500,000 elements: list = {# - Random[], # + Random[]} & /@ NestList[# + Random[] &, 0, 500000]; List @@ IntervalUnion @@ Interval /@ list // Length // Timing high = Sequence[]; {#[[1, 1]], Max[#[[All, -1]]]} & /@ Split[ Sort[list], (high = Max[high, Last[#1]]) ? First[#2] || (high = Last[#1]) &] // Length // Timing maxExtends[list_] := (sl = Sort[list]; length = Length[sl]; r = collect[]; i = 1; While[i ? length, {low, high} = sl[[i]]; If[++i ? length, {curlow, curhigh} = sl[[i]]; While[high ? curlow && (high = Max[ high, curhigh]; ++i ? length), {curlow, curhigh} = sl[[i]]]]; r = collect[r, {low, high}]]; List @@ Flatten[r]) maxExtends[list] // Length // Timing Timing[Length@(List @@ Interval @@ list)] (* <======= mine, Dave Park's, Carl Woll's, Mark Westwood's *) {8.625*Second, 57021} {7.75*Second, 57021} {8.202999999999989*Second, 57021} {6.578000000000003*Second, 57021} and here's a second trial, after more memory has been tied up: {9.5*Second, 56841} {8.202999999999975*Second, 56841} {8.875*Second, 56841} {7.125*Second, 56841} I'm a little surprised the built-in method wins so narrowly. Here's Daitaro's method: Timing[data = Sort[list, #[[1]] < #2[[1]] &];Length[{{data[[1, 1]], Fold[If[# < #2[[1]], #, Max[#, #2[[2]]]] &, data[[1, 2]], Rest[data]]}, {Fold[If[# > #2[[2]], #, Min[#, #2[[1]]]] &, ( data = Reverse@data)[[1, 1]], Rest[data]], data[[1, 2]]}}]] {26.359 Second, 2} It always returns two intervals. Bobby Treat -----Original Message----- > >This problem can be solved by conventional programming, but I >wonder if >there is an elegant Mathematica solution ? > >A list contains pairs of values, with each pair representing >the lower and >upper edge of a sub-range. Some of the sub-ranges partially >overlap, some >fully overlap, others don't overlap at all. The problem is to >produce a >second list that contains the overall upper and lower edges of the >overlapping sub-ranges. > >A simple example : {{100,200},{150,250},{120,270},{300,400}} >would result >in {{100,270},{300,400}}. > >In the real case, the input list has several hundred elements and the >output list typically has five elements. > >I have a working solution based on loops, but there must be a >more elegant >one. I would be very grateful for any suggestions. > > > >John Leary > > John, several proposals (without any attempt to moduralize): (1) use IntervalUnion: List @@ IntervalUnion @@ Interval /@ list (2) use Split (it's a little bit tricky to be correct): high = Sequence[]; {#[[1, 1]], Max[#[[All, -1]]]} & /@ Split[Sort[list], (high = Max[high,Last[#1]]) >= First[#2] || (high = Last[#1])&] (3) procedural programming: maxExtends[list_] := (sl = Sort[list]; length = Length[sl]; r = collect[]; i = 1; While[i <= length, {low, high} = sl[[i]]; If[++i <= length, {curlow, curhigh} = sl[[i]]; While[high >= curlow && (high = Max[high, curhigh]; ++i <= length), {curlow, curhigh} = sl[[i]] ]]; r = collect[r, {low, high}] ]; List @@ Flatten[r]) Let's do some benchmarks: 10,000 Intervals: list = {# - Random[], # + Random[]} & /@ NestList[# + Random[] &, 0, 10000]; List @@ IntervalUnion @@ Interval /@ list // Length // Timing {2.503 Second, 1181} high = Sequence[]; {#[[1, 1]], Max[#[[All, -1]]]} & /@ Split[Sort[ list], (high = Max[high, Last[#1]]) >= First[#2] || (high = Last[#1]) &] // Length // Timing {2.934 Second, 1181} maxExtends[list] // Length // Timing {3.926 Second, 1181} The corresponding results for 100,000 Intervals: {27.329 Second, 11266} {30.234 Second, 11266} {35.791 Second, 11266} and for 500,000 Intervals {144.058 Second, 56728} {154.782 Second, 56728} {181.111 Second, 56728} To look at scaling behaviour I just collected the prior results IntervalUnion: {%355, %345 , %350}[[All, 1, 1]] {2.503, 27.329, 144.058} % // {#[[2]]/(10*#[[1]]), #[[3]]/(5*#[[2]])} & {1.09185, 1.05425} Split: {%357, %347, %352}[[All, 1, 1]] {2.934, 30.234, 154.782} % // {#[[2]]/(10*#[[1]]), #[[3]]/(5*#[[2]])} & {1.03047, 1.02389} Procedural: {%358, %348, %353}[[All, 1, 1]] {3.926, 35.791, 181.111} % // {#[[2]]/(10*#[[1]]), #[[3]]/(5*#[[2]])} & {0.91164, 1.01205} Due to Sort, the Split and the Procedural versions should behave as O[n log n], I'm not shure whether IntervalUnion does (seems to be a little bit more progressive at costs). -- Hartmut Wolf ==== Do you have some package that helps me vizualize subj. when i start from __________________________________________________________________ ckkm __________________________________________________________________ ==== Not entirely sure what you're asking for, but here's a simple routine that plots a Poincare section for a pair of ODEs with vector field (f,g): PoincareSection[{f_,g_}, {t_,t0_,tmax_,dt_}, {x_,x0_}, {y_,y0_}] := Module[{xsoln, ysoln}, {xsoln, ysoln} = {x, y} /. First@ NDSolve[{x'[t] == (f /. {x -> x[t], y -> y[t]}), y'[t] ==(g /. {x -> x[t], y -> y[t]}), x[0]==x0, y[0]==y0}, {x, y}, {t, t0, tmax}, MaxSteps -> Infinity]; ListPlot[Table[{xsoln[t], ysoln[t]}, {t, t0, tmax, dt}]]] And this is the classic example with Duffing's equation: PoincareSection[{y, x - x^3 - 0.2y + 0.3Cos[t]},{t,0,3000,2Pi}, {x, -1}, {y, 1}] --- Selwyn Hollis > Do you have some package that helps me vizualize subj. when i start from > __________________________________________________________________ ckkm > __________________________________________________________________ > > > > > > Reply-To: kuska@informatik.uni-leipzig.de ==== that work only for non-autonomos systems but the original message speak about Hamiltonian systems. For a autonomous system your function does not work at all, because you have to find the intersection points of the solution with a plane in phase space. Jens > > Not entirely sure what you're asking for, but here's a simple routine > that plots a Poincare section for a pair of ODEs with vector field (f,g): > > PoincareSection[{f_,g_}, {t_,t0_,tmax_,dt_}, {x_,x0_}, {y_,y0_}] := > Module[{xsoln, ysoln}, > {xsoln, ysoln} = {x, y} /. First@ > NDSolve[{x'[t] == (f /. {x -> x[t], y -> y[t]}), > y'[t] ==(g /. {x -> x[t], y -> y[t]}), > x[0]==x0, y[0]==y0}, {x, y}, > {t, t0, tmax}, MaxSteps -> Infinity]; > ListPlot[Table[{xsoln[t], ysoln[t]}, {t, t0, tmax, dt}]]] > > And this is the classic example with Duffing's equation: > > PoincareSection[{y, x - x^3 - 0.2y + 0.3Cos[t]},{t,0,3000,2Pi}, > {x, -1}, {y, 1}] > > --- > Selwyn Hollis > > > Do you have some package that helps me vizualize subj. when i start from > > __________________________________________________________________ ckkm > > __________________________________________________________________ > > > > > > > > > > > > Reply-To: kuska@informatik.uni-leipzig.de ==== try my package http://phong.informatik.uni-leipzig.de/~kuska/visualsupp/RungeKuttaNDSolve.m it has an option to return the Poincare section. And my solver vor Hamiltonian systems http://phong.informatik.uni-leipzig.de/~kuska/visualsupp/ManifoldNDSolve.m has the same option for Poincare sections. Jens > > Do you have some package that helps me vizualize subj. when i start from > __________________________________________________________________ ckkm > __________________________________________________________________ ==== Dear MathGroup, I would like to raise the graphics generated by a contour plot to 3D. But there is a problem. Here is a simple example. Here I make a simple contour plot. I then have two cases of converting the graphics to 3D. In the first case I just keep the surface in the xy-plane, simply adding a 0 z coordinate. In the second case I do a simple affine transformation. In both cases some of the contour regions are improperly rendered. Notice that the ContourGraphics has to be first converted to Graphics. cplot = ContourPlot[x y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; cgraphics3d = First[Graphics[cplot]] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0}; cgraphics3d = First[Graphics[cplot]] /. {x_?NumericQ, y_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y}; Show[Graphics3D[ {cgraphics3d}, Lighting -> False, ImageSize -> 450]]; The reason that this problem occurs is that Mathematica does not draw nonintersecting Polygons for each region, but instead will overlay smaller regions on top of larger regions. If we look at the Polygons that ContourPlot produces, after being converted to Graphics, we see that each one goes to a corner of plot domain. Cases[First[Graphics[cplot]], _Polygon, Infinity] The result is that when the graphics are converted to 3D, with slight numerical errors, perhaps in the rendering, some of the Polygons can interlace and produce an incorrect plot. Is there any remedy for this problem? David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ ==== David, A more considered proposal. The idea is that when we find the graphics version of the ContourGraphics object the lines and polygons are rendered with the later ones over the earlier ones. We can simulate this in the 3D version by pulling the coresponding 3D objects towards the view point by small amount, increasing as we go along the list. Here is a rough implementation: Get the contour plot: cplot = ContourPlot[x*y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; Convert to graphics objects grs = Graphics[cplot][[1]]; Make the affine transformation grs3D1 = Graphics3D[grs] /. {(x_)?NumericQ, y_} :> {2*x + y, -x + 2*y, -1.5*x + y}; Display with Graphics3D options as required: grs3D2 = Show[grs3D1, Lighting -> False, ViewPoint -> {1, -2, 2}]; Find the view point used - it might be the current default value and so not explicit in the preceding. vp = ViewPoint /. AbsoluteOptions[grs3D2, ViewPoint] {1.,-2.,2.} The order that the polygons and lines appear in grs is the order in which they will be rendered, the later ones on top of the earlier ones. Simulate this in three dimensions: Lift the polygons and lines slightly towards the view point the later ones more than the later ones (strictly, we should get the viewpoint in user coordinates, but with such small adjustments this may not be necessary) grs3D2 = (ph = 0.; lh = 1.; grs3D1 /. {pl_Polygon :> (pl /. {x_, y_, (z_)?NumericQ} -> {x, y, z} + vp*(ph++/100000)), ln_Line :> (ln /. {x_, y_, (z_)?NumericQ} -> {x, y, z} + vp*(ph++/100000))}); Show the result Show[grs3D2, Lighting -> False]; -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Dear MathGroup, > > I would like to raise the graphics generated by a contour plot to 3D. But > there is a problem. Here is a simple example. Here I make a simple contour > plot. I then have two cases of converting the graphics to 3D. In the first > case I just keep the surface in the xy-plane, simply adding a 0 z > coordinate. In the second case I do a simple affine transformation. In both > cases some of the contour regions are improperly rendered. Notice that the > ContourGraphics has to be first converted to Graphics. > > cplot = ContourPlot[x y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; > > cgraphics3d = > First[Graphics[cplot]] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0}; > > cgraphics3d = > First[Graphics[cplot]] /. {x_?NumericQ, > y_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y}; > > Show[Graphics3D[ > {cgraphics3d}, > Lighting -> False, > ImageSize -> 450]]; > > The reason that this problem occurs is that Mathematica does not draw > nonintersecting Polygons for each region, but instead will overlay smaller > regions on top of larger regions. If we look at the Polygons that > ContourPlot produces, after being converted to Graphics, we see that each > one goes to a corner of plot domain. > > Cases[First[Graphics[cplot]], _Polygon, Infinity] > > The result is that when the graphics are converted to 3D, with slight > numerical errors, perhaps in the rendering, some of the Polygons can > interlace and produce an incorrect plot. > > Is there any remedy for this problem? > > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > > ==== David, The following works for your example, but it does not always work (for example with ContourPlot[x*y, {x, -3, 0}, {y, 0, 3}, ColorFunction -> Hue]) cplot = ContourPlot[x*y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; cgraphics3d = First[Graphics[SetPrecision[cplot, Infinity]]] /. {(x_)?NumericQ, (y_)?NumericQ} -> {2*x + y, -x + 2*y, -1.5*x + y}; Show[Show[Graphics3D[{SetPrecision[cgraphics3d, Infinity]}, PolygonIntersections -> False, ImageSize -> 450], Lighting -> False], Lighting -> False] -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Dear MathGroup, > > I would like to raise the graphics generated by a contour plot to 3D. But > there is a problem. Here is a simple example. Here I make a simple contour > plot. I then have two cases of converting the graphics to 3D. In the first > case I just keep the surface in the xy-plane, simply adding a 0 z > coordinate. In the second case I do a simple affine transformation. In both > cases some of the contour regions are improperly rendered. Notice that the > ContourGraphics has to be first converted to Graphics. > > cplot = ContourPlot[x y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; > > cgraphics3d = > First[Graphics[cplot]] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0}; > > cgraphics3d = > First[Graphics[cplot]] /. {x_?NumericQ, > y_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y}; > > Show[Graphics3D[ > {cgraphics3d}, > Lighting -> False, > ImageSize -> 450]]; > > The reason that this problem occurs is that Mathematica does not draw > nonintersecting Polygons for each region, but instead will overlay smaller > regions on top of larger regions. If we look at the Polygons that > ContourPlot produces, after being converted to Graphics, we see that each > one goes to a corner of plot domain. > > Cases[First[Graphics[cplot]], _Polygon, Infinity] > > The result is that when the graphics are converted to 3D, with slight > numerical errors, perhaps in the rendering, some of the Polygons can > interlace and produce an incorrect plot. > > Is there any remedy for this problem? > > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > > ==== I don't know how much there is to be documented, but I vaguely recall there being a few trick such as a way to execute the last command with a key combination. I've looked around the documentation, but didn't find much. Is there any such documentation? Where? -- Hatton's Law: There is only One inviolable Law. ==== > I don't know how much there is to be documented, but I vaguely recall there > being a few trick such as a way to execute the last command with a key > combination. I've looked around the documentation, but didn't find much. Is > there any such documentation? Where? I don't remember a key combination, but of course you can use In[n]: In[1]:= Random[] Out[1]= 0.25644088025646 In[2]:= In[1] Out[2]= 0.32916748004794 In[3]:= linenum := In[$Line - 1] In[4]:= Random[] Out[4]= 0.26460679270733 In[5]:= linenum Out[5]= 0.87105509807481 -- Bhuvanesh, Wolfram Research. ==== MathGroup, This provides additional information and examples for my earlier posting. I am trying to use ContourPlot to generate colored planar Polygons representing contour regions, and then map them into 3D planar Polygons. There are two problems. 1) The output from converting ContourGraphics to Graphics is not separate polygons for each contour region, but a series of overlapping polygons. Mathematica takes advantage of the fact that in 2D you can lay one Polygon on top of another. But when we convert the Polygons to 3D objects, Mathematica has difficulties. Laying one polygon over another in 3D generally confuses Mathematica's rendering, and perhaps is a difficult 3D problem in general. There is a solution. We can just separate the Polygons into layers with separations just large enough to unconfuse the rendering. As long as we only look at the top side, this works. I illustrate a case below. 2) Mathematica does not correctly render planar polygons that have a concave edge. This despite the fact that the Polygon Help says: In three dimensions, planar polygons that do not intersect themselves will be drawn exactly as you specify them. But how does Mathematica determine that a Polygon is planar, once approximate numbers have been introduced? Somehow we need a method to specify that a 3D Polygon is to be taken as planar, regardless of round off errors. Now for examples. Needs[Graphics`Animation`] cplot = ContourPlot[x y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; Mathematica does not draw the edges of Polygons; in 3D it does.) cgraphics2d = Cases[First[Graphics[cplot]], a : {Hue[_], Polygon[_], ___} :> Take[a, 2], Infinity]; Now we convert the Polygons to 3D objects, introduce an exaggerated spacing between layers and plot it. It illustrates how Mathematica uses an overlay technique on ContourPlots. cgraphics3da = Table[Part[cgraphics2d, i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.1 i}, {i, 1, Length[cgraphics2d]}]; Show[Graphics3D[ {cgraphics3da}, Lighting -> False, ImageSize -> 450]]; Here is the same case with close spacing and an affine transformation to 3D space. cgraphics3da = Table[Part[cgraphics2d, i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.000001 i}, {i, 1, Length[cgraphics2d]}]; cgraphics3db = cgraphics3da /. {x_?NumericQ, y_?NumericQ, z_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y + z}; plot1 = Show[Graphics3D[ {cgraphics3db}, Lighting -> False, ImageSize -> 450]]; SpinShow[plot1, SpinOrigin -> {0, 0, 0}, SpinDistance -> 5] SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate] That works well, but if our contour regions have concave edges, we run into the second problem. cplot = ContourPlot[x^2 + y^2, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; cgraphics2d = Cases[First[Graphics[cplot]], a : {Hue[_], Polygon[_], ___} :> Take[a, 2], Infinity]; cgraphics3da = Table[Part[cgraphics2d, i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.1 i}, {i, 1, Length[cgraphics2d]}]; Show[Graphics3D[ {cgraphics3da}, Lighting -> False, ImageSize -> 450]]; The 3D Polygons are rendered to extend outside the actual region, presumably because Mathematica does not recognize them as planar. So, if we do a closely spaced 3D plot as with the other function, we do not obtain properly colored regions. cgraphics3da = Table[Part[cgraphics2d, i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.00001 i}, {i, 1, Length[cgraphics2d]}]; cgraphics3db = cgraphics3da /. {x_?NumericQ, y_?NumericQ, z_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y + z}; plot1 = Show[Graphics3D[ {cgraphics3db}, Lighting -> False, ImageSize -> 450]]; SpinShow[plot1, SpinOrigin -> {0, 0, 0}, SpinDistance -> 5] SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate] Does anyone have any ideas for solving this problem? David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Reply-To: kuska@informatik.uni-leipzig.de ==== a) Mathematica can't render non convex polygons in 3d and you have to triangulate the polygons with http://library.wolfram.com/packages/polygontriangulation/ b) at the end of the (in german) notebook: http://phong.informatik.uni-leipzig.de/~kuska/signal/MathGraphIntro.zip is a function that slice a 3d plot with contour lines and make a true shadow plot -- using the true shadow plot it should be easy to shift the polygons to the height values Jens > > MathGroup, > > This provides additional information and examples for my earlier posting. > > I am trying to use ContourPlot to generate colored planar Polygons > representing contour regions, and then map them into 3D planar Polygons. > > There are two problems. > > 1) The output from converting ContourGraphics to Graphics is not separate > polygons for each contour region, but a series of overlapping polygons. > Mathematica takes advantage of the fact that in 2D you can lay one Polygon > on top of another. But when we convert the Polygons to 3D objects, > Mathematica has difficulties. Laying one polygon over another in 3D > generally confuses Mathematica's rendering, and perhaps is a difficult 3D > problem in general. There is a solution. We can just separate the Polygons > into layers with separations just large enough to unconfuse the rendering. > As long as we only look at the top side, this works. I illustrate a case > below. > > 2) Mathematica does not correctly render planar polygons that have a concave > edge. This despite the fact that the Polygon Help says: In three > dimensions, planar polygons that do not intersect themselves will be drawn > exactly as you specify them. But how does Mathematica determine that a > Polygon is planar, once approximate numbers have been introduced? Somehow we > need a method to specify that a 3D Polygon is to be taken as planar, > regardless of round off errors. > > Now for examples. > > Needs[Graphics`Animation`] > > cplot = ContourPlot[x y, {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]; > > Mathematica does not draw the edges of Polygons; in 3D it does.) > > cgraphics2d = > Cases[First[Graphics[cplot]], a : {Hue[_], Polygon[_], ___} :> Take[a, > 2], > Infinity]; > > Now we convert the Polygons to 3D objects, introduce an exaggerated spacing > between layers and plot it. It illustrates how Mathematica uses an overlay > technique on ContourPlots. > > cgraphics3da = > Table[Part[cgraphics2d, > i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.1 i}, {i, 1, > Length[cgraphics2d]}]; > Show[Graphics3D[ > {cgraphics3da}, > Lighting -> False, > ImageSize -> 450]]; > > Here is the same case with close spacing and an affine transformation to 3D > space. > > cgraphics3da = > Table[Part[cgraphics2d, > i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.000001 i}, {i, 1, > Length[cgraphics2d]}]; > cgraphics3db = > cgraphics3da /. {x_?NumericQ, y_?NumericQ, > z_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y + z}; > plot1 = > Show[Graphics3D[ > {cgraphics3db}, > Lighting -> False, > ImageSize -> 450]]; > SpinShow[plot1, SpinOrigin -> {0, 0, 0}, SpinDistance -> 5] > SelectionMove[EvaluationNotebook[], All, GeneratedCell] > FrontEndTokenExecute[OpenCloseGroup] > FrontEndTokenExecute[SelectionAnimate] > > That works well, but if our contour regions have concave edges, we run into > the second problem. > > cplot = ContourPlot[x^2 + y^2, {x, -3, 3}, {y, -3, 3}, ColorFunction -> > Hue]; > cgraphics2d = > Cases[First[Graphics[cplot]], a : {Hue[_], Polygon[_], ___} :> Take[a, > 2], > Infinity]; > cgraphics3da = > Table[Part[cgraphics2d, > i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.1 i}, {i, 1, > Length[cgraphics2d]}]; > Show[Graphics3D[ > {cgraphics3da}, > Lighting -> False, > ImageSize -> 450]]; > > The 3D Polygons are rendered to extend outside the actual region, presumably > because Mathematica does not recognize them as planar. So, if we do a > closely spaced 3D plot as with the other function, we do not obtain properly > colored regions. > > cgraphics3da = > Table[Part[cgraphics2d, > i] /. {x_?NumericQ, y_?NumericQ} -> {x, y, 0.00001 i}, {i, 1, > Length[cgraphics2d]}]; > cgraphics3db = > cgraphics3da /. {x_?NumericQ, y_?NumericQ, > z_?NumericQ} -> {2x + y, -x + 2y, -1.5x + y + z}; > plot1 = > Show[Graphics3D[ > {cgraphics3db}, > Lighting -> False, > ImageSize -> 450]]; > SpinShow[plot1, SpinOrigin -> {0, 0, 0}, SpinDistance -> 5] > SelectionMove[EvaluationNotebook[], All, GeneratedCell] > FrontEndTokenExecute[OpenCloseGroup] > FrontEndTokenExecute[SelectionAnimate] > > Does anyone have any ideas for solving this problem? > > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ ==== > -----Original Message----- > Sent: Friday, October 18, 2002 11:18 AM > To: mathgroup@smc.vnet.net > > > > I have 2 or more separate Plots which have different y but the same x > axes. > Like: > > Plot[Sin[x],{x,0,10}]; > Plot[1000Sin[x],{x,0,10}]; > > At the display and printout, the y axes are not aligned. Even > using the > PlotRegion and ImageSize Options doesn't help. The only way I found > was to align it manually with the mouse. > Is there a package that solves the problem? > The problem is, I have many, many plots to align... > I use Mathematica 4.0.2.0 on a Windows 2000 PC. > Who can help? > > Max > > Max, this seems to be not so easy, because of Mathematicas way to scale pictures containing text (and axes labels, tick labels etc. are texts). Texts are not rescaled when the image size changes. Tom Wickham-Jones tells in his book Mathematica Graphics in ¤10.2 at bottom of page 176: Thus Mathematica scales pictures to work with text when the PostScript is displayed. The advantage of a scaling like this is that the picture looks right. When a picture is made there is no need to ensure that enough space is left for labels. The disadvantage is that it is not possible to set the mapping of the graphic onto the page from Mathematica. This would make it possible to do things like line up sub-pictures in a GraphicsArray, something that is hard to do at present. I found out a way to do this however, with minimal experimentation (one parameter cannot be calculated, and depends on ImageSize, fonts, length of texts etc.). Before showing this, let me mention that there is (or was) a package from Michele Cappellari called MongoArray at MathSource/Enhancements/Graphics/2D/0208-538 Array of Framed Plots with Shared or Inverted Axes. He made this to plot astrophysical data, so it is somewhat specialized, but you might like to try it out. Before doing so, fix a bug which went unnoticed in prior versions of Mathematica. Replace the last line of the function linearScale e.g. with If[# == 0``5 || Log[10., Abs[#]] < 4 && # == Round[#], Round[#], #] & /@ t The idea of that package is to compose the plots and construct all embellishments, FrameTicks, TickLabels etc. as graphic objects by own means at the composed graphics.. Here now my method which uses GraphicsArray and thus preserves the full power of plotting. For example let's have two plots Plot[500*Tan[x], {x, 0, 2Pi}, PlotRange -> {{0, 2 Pi}, {-12000, 12000}}, Show[GraphicsArray[{{g1}, {g2}}]] ...does not align the plots properly, but Show[GraphicsArray[ Map[Show[FullGraphics[#], DisplayFunction -> Identity, PlotRegion -> {{0.1, 1}, {0, 1}}, PlotRange -> Tr[{FullOptions[g1, PlotRange], FullOptions[#, PlotRange]}, List, 2]] &, {{g1}, {g2}}, {2}], GraphicsSpacing -> -0.08], ImageSize -> 500] The trick is to shrink the PlotRegion such that the FullGraphics of all parts can be displayed in the plot area, and to properly adjust the PlotRanges. Of course you may include more than two plots (of functions with same domain), instead of g1 to define the PlotRange for x, you may take any of the plots involved. I reduced the GraphicsSpacing to better demonstrate the perfect match. The experimental parameter is the left edge of PlotRegion (0.1). You may lower it for larger images or must increase for larger tick labels. More complicated is to align plots with different aspect ratios, since (from Help:) GraphicsArray sets up identical rectangular display areas for each of the graphics objects it contains However I can trick that out (with more complicated manipulations of PlotRegion). The remaining problem is to adjust the final total display area. If Wolfram's show me the code of GraphicsArray (or give me more documentation) I could make it (without any modifications to GraphicsArray); until then, some experimentation is needed. If you really need that, I can tell you how, otherwise we might code our own version of GraphicsArray. But I dislike to do that, because my philosophy is to stick to standards as long as possible. -- Hartmut Wolf ==== I just installed the MathReader under MAC OS X 10.2.1 and open some demo notebook files. I found that the MathReader sometimes display a 'solid square' box on some part of the equation. Is it a bug on MathReader or OS X? Willy Reply-To: spammers-get-bounced@yahoo.com ==== Sorry for so much cross posting, but perhaps the problem has to with each / many of the NG's I am including / might find a suitable respondent on any of these. I am using Mathematica to generate a PDF plot (using Display[]), but when I look at the generated PDF file (to be subsequently included in a tex do cument using pdflatex), I get font errors. Especially if I use greek fonts, I ge t only dots in the generated pdf file. How do I fix this ? MS. ==== ``Comparison of Mathematica on Various Computers'' is now on http://www2.staff.fh-vorarlberg.ac.at/~ku/karl/mma.html (or http://smc.vnet.net/mathbench.html ) karl.unterkofler@fh-vorarlberg.ac.at for the latest version. New results Mathematica 4: Gateway 700XL Pentium 4, 2.2Ghz, 1GB RDRAM, 512kb, Windows Apple iBook 700 MHz G3, 256 MB Ram, Mac OS 9.2.2 Apple Titanium Powerbook G4, 800Mhz, 1GB, Mac OS 10.1.5 Apple PowerBook G4 400 MHz, 384 MB, Mac OS 10.1.5 Apple PowerBook G4 400 MHz, 384 MB, Mac OS 10.1.5 Pentium 4, 2.2GHz, 1GB DDR, Windows Athlon XP 1800+, ASUS A7V333, 1024 MB RAM, WinXP Pentium 4, 2.441Mhz, 1GHZ RAM, Windows .NET Server PowerBook G4, 800 Mhz, 512 MB RAM, MacOS 10.1.4 Sony Vaio GRX560, 1.6GHz Pentium 4, 512 MB, Windows XP PowerMac G4, 500MHz, 512MB, MacOS 10.1.5 Pentium III, 933 Mhz, 512 Mb, Win 98SE PowerBook G4, 800Mhz, 1GB, MacOSX 10.2.1 Compaq Deskpro EN, PIII 800, 512 MB RAM, WinNT 4.0 SP6a Intel Pentium 4, 2.53Ghz, 512 MB DDR Ram, Windows XP Pro Intel Pentium 4, overclocked to 2.764Ghz, 512 MB, Windows XP Pro PowerMac Dual G4, 1.25GHz, 2GB, MacOS 10.2.1 ==== G'day all, How do I return errors to Mathematica from a MathLink program? For e.g. ... ptr = malloc( HUGE_VAL ); if (ptr == NULL) { // How do I return an error value to mathematica here? } Yas ==== >-----Original Message----- >Sent: Monday, October 21, 2002 8:29 AM >To: mathgroup@smc.vnet.net > > >I would like to replace Dt[x_] in a complex >expression. For example consider > >Dt[x]/.Dt[arg_]->f[arg] > >where x is a pure Symbol (has no value). >However, Mathematica refuses apply the rule. >Various other attempts, for example >Unevaluted[Dt[arg_]]:>f[arg] >and HoldForm[...] were unsuccessful. > >I managed to circumvent the problem by >Dt[x]/.Dt->fun >However, I were more happy if I understood why the >first attempt was not successful. >Can someone explain? > > Johannes Ludsteck Johannes, Dt[x] /. HoldPattern[Dt[arg_]] -> f[arg] .... Dt[arg_] Dt[arg]*Derivative[1, 0][Pattern][arg, _] ....the total derivative of arg_ ! -- Hartmut ==== The correct function to use is (as the name suggests) HoldPattern: In[76]:= Dt[x]/.HoldPattern[Dt[arg_]]:>f[arg] Out[76]= f[x] Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > I would like to replace Dt[x_] in a complex > expression. For example consider > > Dt[x]/.Dt[arg_]->f[arg] > > where x is a pure Symbol (has no value). > However, Mathematica refuses apply the rule. > Various other attempts, for example > Unevaluted[Dt[arg_]]:>f[arg] > and HoldForm[...] were unsuccessful. > > I managed to circumvent the problem by > Dt[x]/.Dt->fun > However, I were more happy if I understood why the > first attempt was not successful. > Can someone explain? > > Johannes Ludsteck > <><><><><><><><><><><><> > Johannes Ludsteck > Economics Department > University of Regensburg > Universitaetsstrasse 31 > 93053 Regensburg > > > > ==== Johannes, You need to use HoldPattern to prevent the lhs of the rule from being evaluated. Dt[x] /. HoldPattern[Dt[arg_]] -> f[arg] David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I managed to circumvent the problem by Dt[x]/.Dt->fun However, I were more happy if I understood why the first attempt was not successful. Can someone explain? Johannes Ludsteck <><><><><><><><><><><><> Johannes Ludsteck Economics Department University of Regensburg Universitaetsstrasse 31 93053 Regensburg Reply-To: ==== This works: Dt[x] /. HoldPattern@Dt[arg_] -> f[arg] The problem apparently is this: In[7]:=Dt[x_] Out[7]=Dt[x]*Derivative[1, 0][Pattern][x, _] That seems odd to me, and I'm not sure why Unevaluated doesn't help. DrBob -----Original Message----- and HoldForm[...] were unsuccessful. I managed to circumvent the problem by Dt[x]/.Dt->fun However, I were more happy if I understood why the first attempt was not successful. Can someone explain? Johannes Ludsteck <><><><><><><><><><><><> Johannes Ludsteck Economics Department University of Regensburg Universitaetsstrasse 31 93053 Regensburg ==== Except in some degenerate cases, you're not going to get analytical solutions. Typically the best you can hope for is an implicit relation involving y and x. For instance, if you have dx/dt = f[x,y], dy/dt = g[x,y], then dy/dx = g[x,y]/f[x,y], and this is solvable (in principle) for the types of equations you describe. --- Selwyn Hollis > students from south america. Due to our final work, > certain coupled non-linear ODE systems have appear, > and we don't have any idea about how to resolve it, > in spite we attempt to. For our purposes, we would > need > analytical solutions -if there exist- for the > following systems, > > dx/dt = ax^2 + by^2 > dx/dt = cx^2 > > dx/dt = axy + by^2 > dy/dt = cxy + dx^2 > > Where a, b, c and d are known constants paremeters > of the problem. We would be very grateful if you can > help us with this matter. We were able to fit > numerically the solutions for both systems, in a > relatively wide range of values, but we did not find > anything aboout the analytical solutions for none of > the systems. In brief words, for our work we would > need the explicit expressions for x(t) and y(t), if > they are known, of course. If you can help us, please > contact us at, > > estudfis@yahoo.com.au > > We are very grateful, since this moment. > Sincerely, > > Javier Krshpa S.87nchez and H.8ector Rivera > Firpo > > Montevideo,Uruguay. > > > > http://careers.yahoo.com.au - Yahoo! Careers > - 1,000's of jobs waiting online for you! > > ==== students from south america. Due to our final work, certain coupled non-linear ODE systems have appear, and we don't have any idea about how to resolve it, in spite we attempt to. For our purposes, we would need analytical solutions -if there exist- for the following systems, dx/dt = ax^2 + by^2 dx/dt = cx^2 dx/dt = axy + by^2 dy/dt = cxy + dx^2 Where a, b, c and d are known constants paremeters of the problem. We would be very grateful if you can help us with this matter. We were able to fit numerically the solutions for both systems, in a relatively wide range of values, but we did not find anything aboout the analytical solutions for none of the systems. In brief words, for our work we would need the explicit expressions for x(t) and y(t), if they are known, of course. If you can help us, please contact us at, estudfis@yahoo.com.au We are very grateful, since this moment. Sincerely, Javier Krshpa S.87nchez and H.8ector Rivera Firpo Montevideo,Uruguay. http://careers.yahoo.com.au - Yahoo! Careers - 1,000's of jobs waiting online for you! ==== Is there any wisdom on whether one should employ or avoid the 2-argument form of ArcTan[], versus ArcTan[y/x], in expressions involving Solve[] and Integrate[]? Is there any harm? Is there any benefit? Reply-To: kuska@informatik.uni-leipzig.de ==== a potential division by 0 in ArcTan[y/x] ? Jens > > > Is there any wisdom on whether one should employ or avoid the > 2-argument form of ArcTan[], versus ArcTan[y/x], in expressions > involving Solve[] and Integrate[]? > > Is there any harm? Is there any benefit? > ==== I installed a Windows Patch upgrade for my win98 machine and it messed up my Mathematica functionality! I am trying to work with Mathematica, but thought that someone here may have seen the same thing. I am running Mathematica 4.0 on a Windows 98 PC. After reinstalling Mathematica (painful), I am getting the following Mathematica error code when I try to run Mathematica (it aborts shortly after the windows erro code for this issue) Mathematica Error : Illegal program operation, ERROR TYPE 160. Am I supposed to know what this means? The Windows error shows (whatever this means). MATHEMATICA caused an invalid page fault in module MATHEMATICA.EXE at 0167:0045297f. Registers: EAX=00000000 CS=0167 EIP=0045297f EFLGS=00010246 EBX=0089fbf4 SS=016f ESP=0089fbcc EBP=0089fc04 ECX=00000000 DS=016f ESI=00000000 FS=0faf EDX=00000000 ES=016f EDI=005f13d0 GS=0000 Bytes at CS:EIP: 8b 4c 90 04 8b 41 08 33 d2 66 8b 15 3e f2 5f 00 Stack dump: 0089fbf4 004bab7e 00000000 bff512de 00400000 000004a4 bff512de 00400000 0089fbd8 0089f9fc 0089fd9c 005e1d48 005f13d0 ffffffff 00000001 0059ada7 Can anyone provide guidance, anyone have ideas? ==== I'd like to know how I can extract the parameter values used by ParametricPlot in plotting a curve, e.g. if ParametricPlot used points corresponding to parameter values 2, 4, 6, etc... I need a way to get the list {2, 4, 6, ...}. One solution I know is this: list={}; ParametricPlot[(AppendTo[list,t]; {f[t] g[t]}),{t,tmin,tmax}]; The problem with this is that I get an error that ParametricPlot cannot compile the function, and that the plotting time is considerably slowed down. especially if I have a high PlotPoints setting. Any ideas? Jan Mangaldan (~_~) __________________________________________________ Do you Yahoo!? Y! Web Hosting - Let the expert host your web site http://webhosting.yahoo.com/ ==== Someone known if is possible to create a 3DPlot Vector Field using Cylindrical coordinates. Using Calculus`VectorAnalysis` Add-on, I can set coordinates but Graphics`PlotField3D` seems not using the coordinates setted, it works in Cartesian system in any case. Any idea? Stefano Fricano. ______________________________________________________________________ Mio Yahoo!: personalizza Yahoo! come piace a te ==== >-----Original Message----- >Sent: Tuesday, October 22, 2002 10:49 AM >To: mathgroup@smc.vnet.net > > >I'd like to know how I can extract the parameter >values used by ParametricPlot in plotting a curve, >e.g. if ParametricPlot used points corresponding to >parameter values 2, 4, 6, etc... I need a way to get >the list {2, 4, 6, ...}. > >One solution I know is this: > >list={}; >ParametricPlot[(AppendTo[list,t]; {f[t] >g[t]}),{t,tmin,tmax}]; > >The problem with this is that I get an error that >ParametricPlot cannot compile the function, and that >the plotting time is considerably slowed down. >especially if I have a high PlotPoints setting. > >Any ideas? > > Jan Mangaldan (~_~) Jan, please observe: In[1]:= a = {0.5, 0.25, 0.3}; b = {0.125, 0.35, 0.03}; In[2]:= f[t_] := a . {Sin[t], Sin[2*t], Sin[3*t]}; g[t_] := b . {Cos[t], Cos[2*t], Cos[3*t]} In[4]:= {tmin, tmax} = {0, 2*Pi}; In[5]:= list = {}; s = {f[t], g[t]}; Timing[ParametricPlot[list = {list, t}; s, {t, tmin, tmax}]] ParametricPlot::ppcom: Function !(((list = (({list, t})))) ; s) cannot be compiled; plotting will proceed with the uncompiled function. Out[6]= {0.231 Second, - Graphics -} In[7]:= tt = Flatten[list]; Length[tt] ss = -Apply[Subtract, Partition[tt, 2, 1], {1}]; Out[8]= 271 In[10]:= ListPlot[tt] In[11]:= ListPlot[ss, PlotJoined -> True, PlotRange -> All] In[12]:= Timing[ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}]] Out[12]= {0.25 Second, - Graphics -} You see the uncompiled version, including registering of the t-samples is faster than the compiled version? In[13]:= Timing[ParametricPlot[Evaluate[{f[t], g[t]}], {t, tmin, tmax}]] Out[13]= {0.04 Second, - Graphics -} In[14]:= list = {}; s = Compile[t,{f[t], g[t]}]; Timing[ParametricPlot[list = {list, t}; s[t], {t, tmin, tmax}];] Out[15]= {0.32 Second, Null} In[16]:= list = {}; s = Compile[t,Evaluate[{f[t], g[t]}]]; Timing[ParametricPlot[list = {list, t}; s[t], {t, tmin, tmax}];] Out[17]= {0.1 Second, Null} -- Hartmut Wolf ==== > G'day all, > How do I return errors to Mathematica from a MathLink program? > > For e.g. > > ... > ptr = malloc( HUGE_VAL ); > if (ptr == NULL) { > // How do I return an error value to mathematica here? > } > > Simply put the information into the link. For example here is an error check in some of my MathLink code: MLCheckFunction( stdlink, list, &len); if (len != c) { MLEvaluateString( stdlink, Message[GUPTRI::sizemsmtch]); MLPutNext( stdlink, MLTKSYM); MLPutSymbol( stdlink, $Failed); goto finish; } The finish label simply terminates the program. You can put the messages into the .tm file with Evaluate lines. Ssezi ==== Allan's posting made me realize a problem that affects all users of Mathematica and Apple's Mail.app for MacOS X. If you use Mail.app and carry out Allan's instruction below you will not get the expected result. The reason is that Mail.app inserts an extra character into the text when pasting into a Carbon application (like the Mathematica Front End). This ruins Mathematica's ability to interpret the text as a Mathematica expression. One way around this problem is to paste the expression first into TextEdit and then copy it form TextEdit and paste into Mathematica. I think this is a good place make a plea to Wolfram Research to seriously consider a Cocoa FrontEnd for MacOS X Mathematica. It is in fact somewhat surprising that it has not been done yet, given the advantages of Cocoa and the fact that it is essentially NextStep, with which WRI has a longer experience than most software developers. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > The notebook code below contains ways of speeding up some uses of > Table, > Sort and Split and avoiding building up inefficienlty large > intermediate > expressions. > I put them together while looking into the various solutions in the > thread > grouping and averaging {x,y} pairs of data -- they helped give what > seems > to be the fastest uncompiled solution yet. > > Allan > > --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > > > To make a notebook from the following, copy between the two lines > +++++++, > past into a notebook, click Yes in the panel that pops up. > > +++++++ > > Notebook[{ > > Cell[CellGroupData[{ > Cell[TextData[{ > Speedups n, > StyleBox[Table, Sort, Split, > FontSize->18] > }], Title], > > Cell[Allan Hayes October 2002, Subsubtitle], > > Cell[BoxData[ > (Off[General::, General::])], Input, > InitializationCell->True], > > Cell[CellGroupData[{ > > Cell[General Techniques, Section], > > Cell[CellGroupData[{ > > Cell[Table, Subsection], > > Cell[TextData[{ > The following illustrates a generally applicable point: that > inserting large expressions directly using a function or , > StyleBox[With, > FontFamily->Courier], > can lead to inefficiently large expressions. This can be avoided > by storing in a local variable. > }], Text], > > Cell[BoxData[{ > ((ranges = Table[{1, 200}, {10000}];)), n, > ((data = Range[100000];))}], Input], > > Cell[This is quite slow., Text], > > Cell[BoxData[ > (takesX[data_, > ranges_] := [IndentingNewLine](Take[data, #] &) /@ > ranges)], Input], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((takesX[data, ranges];) // Timing)], Input], > > Cell[BoxData[ > ({3.789999999999992` Second, Null})], Output] > }, Closed]], > > Cell[TextData[{ > The use of the local variable , > StyleBox[dd, > FontFamily->Courier], > below gives much quicker code > }], Text], > > Cell[BoxData[ > (takes[data_, > ranges_] := [IndentingNewLine]Module[{dd = > data}, (Take[dd, #] &) /@ ranges])], Input, > InitializationCell->True, > FontColor->RGBColor[0, 0, 1]], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((takes[data, ranges];) // Timing)], Input], > > Cell[BoxData[ > ({1.4899999999999807` Second, Null})], Output] > }, Closed]], > > Cell[TextData[{ > We might have expected that the direct insertion of , > StyleBox[data, > FontFamily->Courier], > into , > StyleBox[Take[data,#]&, > FontFamily->Courier New], > would be quicker, but it looks as if the very big expression that > is built up when using this technique slows things down.nIn the > second form , > StyleBox[dd, > FontFamily->Courier], > is evaluated once as each expressionntt, > StyleBox[Take[dd,#]&[{1,200}], > FontFamily->Courier New], > nis evaluated. > }], Text], > > Cell[TextData[{ > As an extra check, use , > StyleBox[With, > FontFamily->Courier], > to input directly: > }], Text], > > Cell[BoxData[ > (takesY[data_, > ranges_] := [IndentingNewLine]With[{dd = > data}, (Take[dd, #] &) /@ ranges])], Input], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((takesY[data, ranges];) // Timing)], Input], > > Cell[BoxData[ > ({3.240000000000002` Second, Null})], Output] > }, Closed]] > }, Closed]], > > Cell[CellGroupData[{ > > Cell[Sort, Subsection], > > Cell[BoxData[{ > ((k = 2;)), [IndentingNewLine], > ((data = ((SeedRandom[0]; > Table[Random[ > Integer, {1, 100}], {100000}, {k}]));))}], Input], > > Cell[Let's sort the data:, Text], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((Sort[data];) // Timing)], Input], > > Cell[BoxData[ > ({1.9299999999999997` Second, Null})], Output] > }, Closed]], > > Cell[< > Sorting by the first coordinate might be expected to be quicker, but > the following slows the calculation down markedly! > >, Text], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((Sort[data, #1[([1])] [LessEqual] #2[([1])] &];) // > Timing)], Input], > > Cell[BoxData[ > ({150.16` Second, Null})], Output] > }, Closed]], > > Cell[TextData[{ > But using , > StyleBox[Ordering, > FontFamily->Courier], > , as below will usually speed things up (the advantage increases > with the size of k). > }], Text], > > Cell[BoxData[ > (sortn[dat_, > n_] := [IndentingNewLine]dat[([Ordering[ > dat[([All, n])]]])])], Input, > InitializationCell->True, > FontColor->RGBColor[0, 0, 1]], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((sortn[data, 1];) // Timing)], Input], > > Cell[BoxData[ > ({1.4799999999999898` Second, Null})], Output] > }, Closed]] > }, Closed]], > > Cell[CellGroupData[{ > > Cell[Split, Subsection], > > Cell[BoxData[{ > ((data = ((SeedRandom[0]; > Table[Random[ > Integer, {1, 100}], {100000}, {2}]));)), n, > ((sd = Sort[data];))}], Input], > > Cell[TextData[{ > Split , > StyleBox[data, > FontFamily->Courier], > by the first coordinate > }], Text], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((Split[sd, #1[([1])] [Equal] #2[([1])] &];) // > Timing)], Input], > > Cell[BoxData[ > ({10.549999999999999` Second, Null})], Output] > }, Closed]], > > Cell[The following (following Hartmut Wolf) is quicker , Text], > > Cell[BoxData[ > (splitnX[dat_, > n_] := [IndentingNewLine]Module[{s, p, > tks}, [IndentingNewLine]s = Split[dat[([All, n])]]; > p = FoldList[ #1 + #2 &, > 0, Length /@ s]; [IndentingNewLine](Take[ > dat, #] &) /@ > Transpose[{Drop[p, (-1)] + 1, > Rest[p]}][IndentingNewLine]])], Input], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((splitnX[sd, 1];) // Timing)], Input], > > Cell[BoxData[ > ({4.939999999999998` Second, Null})], Output] > }, Closed]], > > Cell[TextData[{ > And using the trick we found above when looking at, > StyleBox[ Table , > FontFamily->Courier New], > it gets still quicker > }], Text], > > Cell[BoxData[ > (splitn[dat_, > n_] := [IndentingNewLine]Module[{s, p, tks, > dd}, [IndentingNewLine]ss = (s = > Split[dat[([All, n])]]); > p = FoldList[ #1 + #2 &, > 0, Length /@ s]; [IndentingNewLine]dd = > dat; [IndentingNewLine](Take[dd, #] &) /@ > Transpose[{Drop[p, (-1)] + 1, > Rest[p]}][IndentingNewLine]])], Input, > InitializationCell->True, > FontColor->RGBColor[0, 0, 1]], > > Cell[CellGroupData[{ > > Cell[BoxData[ > ((splitn[sd, 1];) // Timing)], Input], > > Cell[BoxData[ > ({2.09` Second, Null})], Output] > }, Closed]] > }, Closed]] > }, Closed]], > > Cell[CellGroupData[{ > > Cell[Application to Binned Averages, Section], > > Cell[< > Daniel Lichtblau's elegant compiled solution is quickest. The > uncompiled version, 2., comes fairly close, but will probably fall > further behind with very big inputs. > >, Text], > > Cell[TextData[{ > To make the timings more comparable, each section below starts > with , > StyleBox[Quit, > FontFamily->Courier New], > . This must be evaluated separately before the rest of the code. > You will be asked if you want to evaluate the initialization cells > when continuing with rest of the code - click Yes. > }], Text], > > Cell[CellGroupData[{ > > Cell[1. Hartmut Wolf, Subsection, > CellDingbat->None, > CellMargins->{{10, Inherited}, {Inherited, Inherited}}], > > Cell[BoxData[ > (Quit)], Input], > > Cell[BoxData[ > ((data = ((SeedRandom[0]; > Table[Random[ > Integer, {1, 100}], {100000}, {2}]));))], Input], > > Cell[BoxData[ > (((binnedAverage1[data_, max_] := > Module[{v, i, ix, ixx, ixxx}, {i, v} = > With[{rr = Range[max]}, > Transpose[ > Sort[Join[data, > Transpose[{rr, > rr - rr}]]]]]; [IndentingNewLine]ix = > Split[i]; [IndentingNewLine]ixx = > FoldList[Plus[#1, Length[#2]] &, 0, > ix]; [IndentingNewLine]ixxx = > Transpose[ > Transpose[Partition[ixx, 2, 1]] + {1, > 0}]; [IndentingNewLine]Transpose[{First /@ > ix, ((((Plus @@ #))/Max[Length[#] - 1, 1] &)[ > Take[v, #]] &) /@ ixxx}]])(n) > ))], Input], > > Cell[CellGroupData[{ > > Cell[BoxData[ > (Table[((((r1 = binnedAverage1[data, 100]));) // Timing) // > First, {5}])], Input], > > Cell[BoxData[ > ({3.790000000000001` Second, 4.609999999999999` Second, > 4.17` Second, 5.` Second, > 4.010000000000002` Second})], Output] > }, Closed]] > }, Closed]], > > Cell[CellGroupData[{ > > Cell[2. Allan Hayes, Subsection, > CellDingbat->None, > CellMargins->{{10, Inherited}, {Inherited, Inherited}}], > > Cell[TextData[{ > Note that , > StyleBox[Tr[lst], > FontFamily->Courier], > StyleBox[ is used , > FontFamily->Times New Roman], > StyleBox[ins, > FontFamily->Times New Roman], > tead o, > StyleBox[f , > FontFamily->Times New Roman], > StyleBox[Plus@@lst, > FontFamily->Courier], > StyleBox[ , > FontFamily->Times New Roman], > StyleBox[to sum, > FontFamily->Times New Roman], > StyleBox[ , > FontFamily->Times New Roman], > StyleBox[lst, > FontFamily->Courier], > . > }], Text], > > Cell[BoxData[ > (Quit)], Input], > > Cell[BoxData[ > ((data = ((SeedRandom[0]; > Table[Random[ > Integer, {1, 100}], {100000}, {2}]));))], Input], > > Cell[BoxData[ > (binnedAverage2[data_, > max_: 0] := [IndentingNewLine]Module[{spl, avs, inds, dd, > zs}, [IndentingNewLine]spl = > splitn[sortn[data, 1], > 1]; [IndentingNewLine]avs = (((Tr[#1[([All, 2])]]/ > Length[#1])) &) /@ > spl; [IndentingNewLine]inds = > spl[([All, 1, 1])]; [IndentingNewLine]dd = > Range[Max[Last[inds], max]]; [IndentingNewLine]zs = > dd - dd; [IndentingNewLine]zs[([inds])] = > avs; [IndentingNewLine]Transpose[{dd, > zs}][IndentingNewLine]])], Input], > > Cell[CellGroupData[{ > > Cell[BoxData[ > (Table[(binnedAverage2[data] // Timing) // > First, {5}])], Input], > > Cell[BoxData[ > ({2.8100000000000005` Second, 3.0700000000000003` Second, > 2.799999999999999` Second, 2.799999999999999` Second, > 2.75` Second})], Output] > }, Closed]] > }, Closed]], > > Cell[CellGroupData[{ > > Cell[3. Daniel Lichtblau, Subsection, > CellDingbat->None, > CellMargins->{{10, Inherited}, {Inherited, Inherited}}], > > Cell[BoxData[ > (Quit)], Input], > > Cell[BoxData[ > ((data = ((SeedRandom[0]; > Table[Random[ > Integer, {1, 100}], {100000}, {2}]));))], Input], > > Cell[BoxData[ > StyleBox[(averageByBin3[ > data : {{_, _} .. }] := [IndentingNewLine]Module[n > {res = Transpose[data]}, n > res = averagebyBinC[res[([1])], res[([2])]]; n > Transpose[{Range[Length[res]], res}]n]), > FormatType->StandardForm]], Input], > > Cell[BoxData[ > StyleBox[((n)((averagebyBinC = > Compile[{{xvals, _Integer, 1}, {yvals, _Real, 1}}, n > Module[{len = Max[xvals], binsizes, averages, > len2 = Length[xvals], indx}, n > binsizes = Table[0, {len}]; n > averages = Table[0. , {len}]; n > Do [nindx = > xvals[([j])]; n(binsizes[([indx])]++); n > averages[([indx])] += yvals[([j])], n{j, > len2}n]; n > binsizes = Map[If [# == 0, 1, #] &, binsizes]; n > averages / binsizesn]n];)(n) > )), > FormatType->StandardForm]], Input], > > Cell[CellGroupData[{ > > Cell[BoxData[ > (Table[((averageByBin3[data];) // Timing) // > First, {5}])], Input], > > Cell[BoxData[ > ({2.3099999999999996` Second, 2.1400000000000006` Second, > 2.3599999999999994` Second, 2.3100000000000005` Second, > 2.3599999999999994` Second})], Output] > }, Closed]] > }, Closed]] > }, Closed]] > }, Open ]] > }, > ScreenRectangle->{{0, 1024}, {0, 723}}, > AutoGeneratedPackage->None, > WindowToolbars->RulerBar, > WindowSize->{459, 310}, > WindowMargins->{{250, Automatic}, {Automatic, -20}}, > ShowSelection->True > ] > > +++++++ > > > > > > ==== Jan, Why do you want the t values? They are only an artifact of Mathematica's plot making? If what you really want is the points then here is an example of what you can do. We extract the graphics, g, and the points, pts, from the Line in g. Then show them both. curve[t_] := {t, Sin[t]} g = First[ ParametricPlot[Evaluate[curve[t]], {t, 0, 2Pi}, DisplayFunction -> Identity]]; pts = Cases[g, Line[a_] -> a, Infinity] // First; Show[Graphics[ {g, AbsolutePointSize[5], Point /@ pts}], Frame -> True, ImageSize -> 450]; In general you could solve for t from the x or y point coordinates (trivial in my example) but the method you propose is better. Add Compiled -> False to eliminate the error message and don't worry about the extra time because you are asking for extra information. I don't think there is actually significant extra time. list = {}; ParametricPlot[(AppendTo[list, t]; curve[t]), {t, 0, 2Pi}, Compiled -> False]; For our example, the two methods give the same t values, but list is not in order. If you look at the two set of t values you can see how the Mathematica plotting routine backtracks to fill in regions of high curvature. (First /@ pts) == Sort[list] True David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ The problem with this is that I get an error that ParametricPlot cannot compile the function, and that the plotting time is considerably slowed down. especially if I have a high PlotPoints setting. Any ideas? Jan Mangaldan (~_~) __________________________________________________ Do you Yahoo!? Y! Web Hosting - Let the expert host your web site http://webhosting.yahoo.com/ ==== > > I want solve a non linear system of 4 algebric equations with the command > NSolve. > > I get the error messages: > > NSolve::zerosol Scale of possible solution value -8.656393839455443`*^-7 > for variable A4 is too small. Must set this value to zero in order to avoid > generation of spurious solutions. This may cause the loss of some solutions. > > and: > > NSolve::sfail: Subsystem could not be solved forA3 at value > 0.00002176757227083404`. The likely cause is failure to detect zero due to > low precision. The likely effect is the loss of one or more solutions. > Increasing WorkingPrecision might prevent some solutions from being lost. > > Where can I find informations about these? > The messages indicate that the NSolve algorithm is running into a problem with ill conditioning. This may be due to multiplicity of the solution set of perhaps just multiplicity (or near multiplicity) of one or more coordinate values in the solution set. The latter type of problem has been addressed in version 4.2. Was this run in version 4.2 of Mathematica? If not, you might get better results there. Hard to say for certain since you did not post the actual equations. Another possibility might be to set WorkingPrecision high, say to 400, and see what happens. Daniel Lichtblau Wolfram Research Reply-To: ==== Try this: plot = ParametricPlot[{Cos[5t], Sin[3t]}, { t, 0, 2[CapitalYAcute]}, AspectRatio -> Automatic]; lines = Cases[plot, _Line, Infinity] To learn more about what's going on, look at Head[plot] plot[[1]] plot[[2]] Also note that you can operate on a graph my manipulating its first argument. For instance, to do a coordinate transformation: A = {{1, 2}, {-3, 1}}; Show[Graphics[plot[[1]] /. {x_, y_} -> A.{x, y}, plot[[2]]]] Bobby -----Original Message----- g[t]}),{t,tmin,tmax}]; The problem with this is that I get an error that ParametricPlot cannot compile the function, and that the plotting time is considerably slowed down. especially if I have a high PlotPoints setting. Any ideas? Jan Mangaldan (~_~) __________________________________________________ Do you Yahoo!? Y! Web Hosting - Let the expert host your web site http://webhosting.yahoo.com/ ==== I am a beginner with mathematica. I have a student version of the software deleted a part of my home directory, but I am sure that I havn't deleted .Mathematica) and my disk had crashed I have problems during the start of my mathematica version. First the software tell me in a window that the fonts which mathematica use are not at this system. Further I get a message with a warning: Actions not found: delete-next-character. Could someone explain why the software do that and how I can solve these problem? Stefan ==== David park was converting ContourGraphics to Graphics. He was then using the resulting Graphics to make some Graphics3D (with concave polygons in 3D). Mathematica wouldn't correctly render the concave polygons in 3D. I don't have time for further experimenting, but I think you can solve your problem with the concave 3D polygons if you decompose them into triangles using the package at http://library.wolfram.com/packages/ ---- Ted Ersek ==== This may be really simple but I am having trouble setting the variables to the values returned by solve. If solution={S0 -> 0,S1 -> 5....}the numbers of S# are subscripts I can get to the idivdual parts with solution[[1]][[1]] and solution[[1]][[2]] but when I try to set the one equal to the other I get this error Set::setps: solution[[1]] in assignment of part is not a symbol. What is going on and how can I fix this? ==== I'm trying to write a function similar to Save, but can't find how to stop the main loop from evaluating the argument. Let's say I have the definition a=x^2 if I do Save[filename,a] the definition goes into the file, what I want is to get the definition into a variable inside my function, so I can do: MyFunction[a] and within MyFunction some variable gets assigned with a=x^2 (and not just with x^2). Is there a way of doing this? I don't like having to write MyFunction[a]. In some way Save seems to know how to tell the system not to replace 'a' with its value. TIA Elcofres ==== > MyFunction[a] > > and within MyFunction some variable gets assigned with a=x^2 (and not > just with x^2). Is there a way of doing this? I don't like having to > write MyFunction[a]. In some way Save seems to know how to tell the > system not to replace 'a' with its value. Save has the attribute HoldRest, you can attach this to MyFunction with SetAttributes[MyFunction, HoldRest] -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > > I'm trying to write a function similar to Save, but can't find how to > stop the main loop from evaluating the argument. Let's say I have the > definition > > a=x^2 > > if I do > > Save[filename,a] > > the definition goes into the file, what I want is to get the > definition into a variable inside my function, so I can do: > > MyFunction[a] > > and within MyFunction some variable gets assigned with a=x^2 (and not > just with x^2). Is there a way of doing this? I don't like having to > write MyFunction[a]. In some way Save seems to know how to tell the > system not to replace 'a' with its value. > > TIA > Elcofres > Reply-To: murray@math.umass.edu ==== No, a standard Windows magnifier does NOT seem to work here -- the student is already using a (commercial) magnifier, ZoomText, at my university's Assistive Technologies Center. The problem is that you have to begin with a high quality, pre-magnified page; otherwise the fonts come out looking very dotty. If you use Mathematica's built-in magnifier in a notebook, it does provide enlarged, fairly smooth fonts. Then when you zoom further -- and this student has to magnify things really large -- the resulting text is still readable. > Murray, > > On my Windows98 OS there is a Magnifier utility, activated by > > StartProgramsAccessoriesAccessibilityMagnifier > > It splits the screen into two panels and provides a magnified view in the > top panel of the pointer region in the lower panel. It magnifies anything on > the screen, including all portions of the Mathematica Help. > > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > > > > I have a student using Mathematica 4.2 (under Windows) who has major > visual impairment. With the aid of a standard utility (ZoomText) > together with Mathematica's built-in magnification, he is able to read > ordinary Mathematica notebooks. But not the all-important Help Browser. > > How can one mangify the Help Browser window -- not just the main panel > but especially the rows of buttons at the top and the 4 panes between > the buttons and the main panel? > > -- > 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 > Amherst, MA 01375 > > > > -- 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 Amherst, MA 01375 Reply-To: murray@math.umass.edu ==== I have a student using Mathematica 4.2 (under Windows) who has major visual impairment. With the aid of a standard utility (ZoomText) together with Mathematica's built-in magnification, he is able to read ordinary Mathematica notebooks. But not the all-important Help Browser. How can one mangify the Help Browser window -- not just the main panel but especially the rows of buttons at the top and the 4 panes between the buttons and the main panel? -- 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 Amherst, MA 01375 ==== I am trying to evalute a function which looks like this. This is an analogous problem not the actual problem. test[x_] := p /. FindRoot[Sin[p] == x, {p, 1}][[1]] data[x_] := D[test[x], x] Plot[data[x], {x, 0, 1}] Now, when trying to evaluate the derivative mathematica replaces both the x's with the number at which it is trying to calculate the datapoint. This gives an error of 'xxxx is not a valid variable'. Replacing D[test[x]] with test'[x] doesn't help either though it results in a different set of errors. Is there any of way of getting around this problem? Farhat ==== I'd like to plot the solution of an equation which depends on two parameters, e.g. a*Tanh[b*x] == x So, I'd like to see it in 3D, one axis is a, other is b, and the last is solution. I've tried naively to do it as follows: sol[a_,b_]:=FindRoot[a*Tanh[b*x] == x, {x, {0.01, 0.1}}] Plot[sol[a,b], {a, 1, 2}, {b, 1, 2}] And it doesn't work. Help me, please. What can I do? Veniamin ==== > > >I have understood that parentheses ( ) are displayed as HL in >exported postscript due to the fact that postscript viewers are not >accessing the Mathematica Fonts that encode ( ). I thought I >could avoid this problem by specifying a different font, in this >case Courier for the parentheses. This didn't work. Is there a >related idea that will work? > >parenGraphic = Show[Graphics[{ Text[ StyleForm[(, FontFamily -> >Courier, FontWeight -> Plain] , {0, 0}] >}]]; > >Export[parenGraphic.eps, parenGraphic] > > >Todd Will UW-LaCrosse Try this instead... parenGraphic = Show[Graphics[{Text[ StyleForm[(, PrivateFontOptions -> {OperatorSubstitution -> False}], {0, 0}]}]]; (and actually you don't need to make a separate graphic out of this, you can just throw this in the TextStyle option for the whole graphic) You can also set the OperatorSubstitution option to False at the global level using the Option Inspector, which would affect all uses of parens, brackets, etc., in Mathematica...in input and output cells as well as graphics. Of course, you'll still need to include the Mathematica fonts for those characters which have no corresponding characters in the regular fonts, like Greek letters and radicals. Sincerely, John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. ==== Can I also get the real fortran file, the file that it will be going to be compiled. so the file begins at 7-th column and ends at 72-th........ thanks for the help alessandro agresti ==== >How do you remove the In[] and Out[] lines so they don't appear when you >print? > >Brian (averso@yahoo.com) In the option inspector: Set Show option values for to notebook. Then set Cell Options|Cell Labels|ShowCellLabel->False -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html ==== > This may be really simple but I am having trouble setting the > variables to the values returned by solve. If > solution={S0 -> 0,S1 -> 5....}the numbers of S# are subscripts > I can get to the idivdual parts with > solution[[1]][[1]] and solution[[1]][[2]] but when I try to set the > one equal to the other I get this error > Set::setps: solution[[1]] in assignment of part is not a symbol. > What is going on and how can I fix this? Sam, you're working too hard :) If you really want permanent assignments, then substitute (Apply) Rule for Set: assignments=Set@@@solution Tom Burton Reply-To: ==== Here's a method that's not blindingly fast, but still interesting: a = {0.5, 0.25, 0.3}; b = {0.125, 0.35, 0.03}; {tmin, tmax} = {0, 2*Pi}; f[t_] := a . {Sin[t], Sin[2*t], Sin[3*t]}; g[t_] := b . {Cos[t], Cos[2*t], Cos[3*t]} h[t_, {x_, y_}] = (f[t] - x)^2 + (g[t] - y)^2; j[t_, {x_, y_}] = Simplify[ D[h[t, {x, y}], t]]; i[t_, {x_, y_}] := guess=2*t - guess /. FindRoot[h[t,{x, y}], {t, guess},Jacobian -> {{j[t, {x, y}]}}] Timing[plot = ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}]; list = Cases[plot, {x_, y_}, Infinity]; guess = tmin; tvals = (i[t, #1] & ) /@ list; ] ListPlot[tvals] {0.281 Second, Null} This is slightly faster, though probably not worth the extra effort: nextGuess := guess.{1, -3, 3} (* quadratic extrapolation from previous guesses *) i[t_, {x_, y_}] := (guess = Join[Rest@guess, {t}] /. FindRoot[h[t, {x, y}], {t, nextGuess}, Jacobian -> {{j[t, {x, y}]}}]) Timing[plot = ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}]; list = Cases[plot, {x_, y_}, Infinity]; guess = tmin{1, 1, 1}; tvals2 = Last@i[t, #] & /@ list; ] {0.266 Second, Null} DrBob -----Original Message----- >values used by ParametricPlot in plotting a curve, >e.g. if ParametricPlot used points corresponding to >parameter values 2, 4, 6, etc... I need a way to get >the list {2, 4, 6, ...}. > >One solution I know is this: > >list={}; >ParametricPlot[(AppendTo[list,t]; {f[t] >g[t]}),{t,tmin,tmax}]; > >The problem with this is that I get an error that >ParametricPlot cannot compile the function, and that >the plotting time is considerably slowed down. >especially if I have a high PlotPoints setting. > >Any ideas? > > Jan Mangaldan (~_~) Jan, please observe: In[1]:= a = {0.5, 0.25, 0.3}; b = {0.125, 0.35, 0.03}; In[2]:= f[t_] := a . {Sin[t], Sin[2*t], Sin[3*t]}; g[t_] := b . {Cos[t], Cos[2*t], Cos[3*t]} In[4]:= {tmin, tmax} = {0, 2*Pi}; In[5]:= list = {}; s = {f[t], g[t]}; Timing[ParametricPlot[list = {list, t}; s, {t, tmin, tmax}]] ParametricPlot::ppcom: Function !(((list = (({list, t})))) ; s) cannot be compiled; plotting will proceed with the uncompiled function. Out[6]= {0.231 Second, - Graphics -} In[7]:= tt = Flatten[list]; Length[tt] ss = -Apply[Subtract, Partition[tt, 2, 1], {1}]; Out[8]= 271 In[10]:= ListPlot[tt] In[11]:= ListPlot[ss, PlotJoined -> True, PlotRange -> All] In[12]:= Timing[ParametricPlot[{f[t], g[t]}, {t, tmin, tmax}]] Out[12]= {0.25 Second, - Graphics -} You see the uncompiled version, including registering of the t-samples is faster than the compiled version? In[13]:= Timing[ParametricPlot[Evaluate[{f[t], g[t]}], {t, tmin, tmax}]] Out[13]= {0.04 Second, - Graphics -} In[14]:= list = {}; s = Compile[t,{f[t], g[t]}]; Timing[ParametricPlot[list = {list, t}; s[t], {t, tmin, tmax}];] Out[15]= {0.32 Second, Null} In[16]:= list = {}; s = Compile[t,Evaluate[{f[t], g[t]}]]; Timing[ParametricPlot[list = {list, t}; s[t], {t, tmin, tmax}];] Out[17]= {0.1 Second, Null} -- Hartmut Wolf ==== I want to write a program that will create an array of equilateral triangles such that in the first row there is 1 triangle, in the second row there is 3 triangles, in the third row there will be 5 triangles...in the nth row there will be 2n - 1 triangles. Putting all of these triangles together and calling the first row, row 0, we would have a large triangle with n + 1 rows along the side of the large triangle and 2n - 1 columns along the base of the triangle. This would be phase one of the project. Phase 2: Fill in the binomial coefficients into the triangle. Phase 3: Color all odd numbered triangles blue. Phase 4: Color all even numbered triangles red. Phase 5: Any triangle that shares an edge with a red triangle, color red. The result is Zierpinski's Triangle! I have done this by hand for a triangle with 16 rows. Needless to say the work was tedious. The result, however, is quite satisfying and remarkable. I would like to be able to use this as a tool to teach some of the other derivations that are possible from Pascal's triangle other than binomial coefficients and combinations. Therefore it would be beneficial to be able to reproduce this work at will. Since my Mathematica programming skills are practically nil, any help would be appreciated. following: althemannon@attbi.com Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you won't > get the same answer as when you use exact numbers because of the way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > ==== > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster used. > You on the other hand choose to assume that the posting shows that its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything wrong. > After all, one can always check the accuracy of your answer: > > In[1]:= > a = 77617.; b = 33096.; > > In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) > > In[3]:= > f > > Out[3]= > -1.1805916207174113*^21 > > In[4]:= > Accuracy[%] > > Out[4]= > -5 > > which tells you that it can't be very reliable. What more do you demand? > As you are dealing here only with machine-precision numbers, your When you do calculations with arbitrary-precision numbers, as discussed in the previous section, Mathematica always keeps track of the precision of your results, and gives only those digits which are known to be correct, given the precision of your input. When you do calculations with machine-precision numbers, however, Mathematica always gives you a machine-[CapitalEth]precision result, whether or not all the digits in the result can, in fact, be determined to be correct on the basis of your input. In practice, to rely on a numerical result, you ALWAYS have to check its accuracy. How reliable is Accuracy anyway? In[1]:= a = SetAccuracy[77617., Infinity]; b = SetAccuracy[33096., Infinity]; In[3]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity] Out[3]= 1180591620717411303424 In[4]:= Accuracy[f] Out[4]= Infinity We got completely wrong result with Infinite accuracy. In conclusion, one can not rely on Accuracy. Checking numerical results in Mathematica sounds like a tough task.:-) --PK > Andrzej > > > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > [...] > > ==== Andrzej Yes, like you I took the original question to be about how to get the result of using the naive rational versions in place of the inexact numbers. Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means that Mathematica keeps no check on the accuracy and precision of the computation, and Mathematica gives the default accuracy value without any real signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the computation to be in bignums (bigfloat, arbitrary precision) arithmetic. Mathematica then keeps track of the accuracy and precision that it can guarantee. Clear[f,a,b,k] k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/(2*b),k]; a=77617.;b=33096.; a=SetAccuracy[a,k]; b=SetAccuracy[b,k]; f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: - is the precision (accuracy) of rhe input known? - how does Mathematica interpret what one gives it? - how does Mathematica go about the calculation? -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster used. > You on the other hand choose to assume that the posting shows that its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > > Actually, we don't know whether SetAccuracy succeeds, because we > > don't > > know how inexact those numbers really are. If they are known to more > > digits than shown in the original post, they should be entered with as > > much precision as they deserve. If not, there's no trick or algorithm > > that will give the result precision, because the value of f really is > > in the noise. That is, we have no idea what the value of f should > > be. > > Mathematica's failing is in returning a value without pointing out that > > it has no precision. > > Bobby > > -----Original Message----- > > Sent: Monday, September 30, 2002 11:59 AM > > Andrzej, Bobby, Peter > > It looks as if using SetAccuracy succeeds here because the inexact > > numbers > > that occur have finite binary representations. If we change them > > slightly to > > avoid this then we have to use Rationalize: > > 1) Using SetAccuracy > > Clear[a,b,f] > > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > > (2*b), > > Infinity]; > > a=77617.1; > > b=33096.1; > > a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; > > f > > -1564032114908486835197494923989618867972540153873951942813115514949 > > 3891236234 > > 52500771916869370459119776018798804630436149786919912931962574301029236 > > 3 > > 1246 > > 75 > > / > > 10867106143970760551000357827554793888198143135975649579607989867743572 > > 8240 > > 16 > > 0653953612982932181371232436367739737604096 > > 2) Rewriting as fractions > > a=776171/10; > > b=330961/10; > > f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) > > -(5954133808997234115690303589909929091649391296257/ > > 41370125000000) > > 3) Using Rationalize > > Clear[a,b,f] > > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > > (2*b), > > 0]; > > a=77617.1; > > b=33096.1; > > a=Rationalize[a,0];b=Rationalize[b,0]; > > f > > -(5954133808997234115690303589909929091649391296257/ > > 41370125000000) > > I use Rationalize[. , 0] besause of results like > > Rationalize[3.1415959] > > 3.1416 > > Rationalize[3.1415959,0] > > 31415959/10000000 > > -- > > Allan > > --------------------- > > Allan Hayes > > Mathematica Training and Consulting > > Leicester UK > > www.haystack.demon.co.uk > > hay@haystack.demon.co.uk > > Voice: +44 (0)116 271 4198 > > Well, first of of all, your using SetAccuracy and SetPrecision does > > nothing at all here, since they do not change the value of a or b. You > > should use a = SetAccuracy[a, Infinity] etc. But even then you won't > > get the same answer as when you use exact numbers because of the way > > you evaluate f. Here is the order of evaluation that will give you the > > same answer, and should explain what is going on: > > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; > > a = 77617.; > > b = 33096.; > > a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; > > f > > 54767 > > -(-----) > > 66192 > > Andrzej Kozlowski > > Toyama International University > > JAPAN > > Could someone explain what is going on here, please? > > In[1]:= > > a = 77617.; b = 33096.; > > In[2]:= > > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; > > In[4]:= > > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > > a/(2*b) > > In[5]:= > > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; > > In[6]:= > > f > > > > Out[6]= > > -1.1805916207174113*^21 > > In[7]:= > > a = 77617; b = 33096; > > In[8]:= > > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > > (55/10)*b^8 + a/(2*b) > > In[9]:= > > g > > Out[9]= > > -(54767/66192) > > In[10]:= > > N[%] > > Out[10]= > > -0.8273960599468214 > > PK > ==== These expressions are condensation of larger ones (about 700 lines or so each) but they illustrate random substitution failures in 4.2. Question: how can the substitution Sqrt[...]->Q always be made to work? The help file under ReplaceAll, ReplaceRepeated, etc, does not address this problem. f=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]/4*F^2); Print[(f/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + (4*C)/(F^2*Sqrt[X + Y + Z]) (* fails *) g=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]*4*F^2); Print[(g/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + C/(4*F^2*Sqrt[X + Y + Z]) (* fails *) h=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]+4*F^2); Print[(h/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + C/(4*F^2 + Q) (* works *) Reply-To: kuska@informatik.uni-leipzig.de ==== Sqrt[a] is internal Power[a,Rational[1,2]] and 1/Sqrt[a] is interal Power[a,Rational[-1,2]] and so a rule Sqrt[a]->q will not match with 1/Sqrt[a]. You need f = B*(A + Sqrt[X + Y + Z]) + C/(Sqrt[X + Y + Z]/4*F^2); (f /. (X + Y + Z)^Rational[n_, 2] -> Q^n) Jens > > These expressions are condensation of larger ones > (about 700 lines or so each) but they illustrate random > substitution failures in 4.2. Question: how can the > substitution Sqrt[...]->Q always be made to work? > The help file under ReplaceAll, ReplaceRepeated, etc, > does not address this problem. > > > f=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]/4*F^2); > Print[(f/.Sqrt[X+Y+Z]->Q)//InputForm]; > > B*(A + Q) + (4*C)/(F^2*Sqrt[X + Y + Z]) (* fails *) > > g=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]*4*F^2); > Print[(g/.Sqrt[X+Y+Z]->Q)//InputForm]; > > B*(A + Q) + C/(4*F^2*Sqrt[X + Y + Z]) (* fails *) > > h=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]+4*F^2); > Print[(h/.Sqrt[X+Y+Z]->Q)//InputForm]; > > B*(A + Q) + C/(4*F^2 + Q) (* works *) ==== > > > Sqrt[a] is internal Power[a,Rational[1,2]] and > 1/Sqrt[a] is interal Power[a,Rational[-1,2]] > and so a rule Sqrt[a]->q will not match with > 1/Sqrt[a]. You need > > f = B*(A + Sqrt[X + Y + Z]) + C/(Sqrt[X + Y + Z]/4*F^2); > (f /. (X + Y + Z)^Rational[n_, 2] -> Q^n) > > Jens ought to be in the help Examples under . and . I should clarify three things. First, why use of FullForm is impractical. The source expressions I am dealing with are highly complex, with thousands of terms. The subexpressions to be replaced appear in hundreds of places, in many nested combinations. Detailed eye examination after each run would take a long time. Second, the operation subexpression->letter is used as preparation for conversion of those expressions to C. The letters will be names of temps (temporary variables) in C code. Upon replacing all subexpressions the source contracts to about 1-5% of original size. Third, there is a brute force replacement method which can be used (and was): output in InputForm, save cell as text, use a smart text editor that ignores blanks and CRs (e.g. emacs), and re-input for C conversion. This is cumbersome (the text has to be telnet'd to a Unix machine and back) and error prone but available as last resort. Perhaps a future version of Mathematica may incorporate a <- operator for this kind of reverse expansion to extract common subexpressions. The output would be the contracted expression and a temps list. ==== Dear Colleagues, I calculated: Sum[1/Prime[n], {n, 15000}] // N Result: 2.74716 Now I wonder if this sum will converge or keep on growing, albeit very slowly. Matthias Bode Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== > I calculated: Sum[1/Prime[n], {n, 15000}] // N Result: 2.74716 Now I wonder if this sum will converge or keep on growing, albeit very > slowly. The latter. It is a well known fact that the series diverges (which, by the way, shows that there are infinitely many primes :-). David -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service ==== Hm, I wonder whose failures are you referring to when write substitution failures in 4.2? When using Mathematica's pattern matching there is one fundamental rule (very frequently restated on this list) you should adhere to: check the FullForm of the expression you are trying to match. So taking just your first case: In[1]:= FullForm[f = B*(A + Sqrt[X + Y + Z]) + C/((Sqrt[X + Y + Z]/4)*F^2)] Out[2]//FullForm= Plus[Times[4,C,Power[ F,-2],Power[Plus[X,Y,Z],Rational[-1,2]]],Times[B,Plus[A,Power[Plus[X, Y,Z],Rational[1,2]]]]] This ought to make the reason for the failure of your substitution clear. To make it work you must find a way to much the right pattern and not forget that the matching is purely syntactic. In[2]:= f /. (X + Y + Z)^(Rational[x_, 2]) -> Q^x Out[2]= (4*C)/(F^2*Q) + B*(A + Q) There are of course other ways you can get this to work, e.g. In[3]:= PowerExpand[f /. X + Y + Z -> Q^2] Out[3]= (4*C)/(F^2*Q) + B*(A + Q) There is even a rather crazy method that sometimes actually works: In[4]:= ToExpression[StringReplace[ToString[Evaluate[InputForm[f]]], Sqrt[X + Y + Z] -> Q]] Out[4]= (4*C)/(F^2*Q) + B*(A + Q) Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ > These expressions are condensation of larger ones > (about 700 lines or so each) but they illustrate random > substitution failures in 4.2. Question: how can the > substitution Sqrt[...]->Q always be made to work? > The help file under ReplaceAll, ReplaceRepeated, etc, > does not address this problem. f=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]/4*F^2); > Print[(f/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + (4*C)/(F^2*Sqrt[X + Y + Z]) (* fails *) g=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]*4*F^2); > Print[(g/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + C/(4*F^2*Sqrt[X + Y + Z]) (* fails *) h=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]+4*F^2); > Print[(h/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + C/(4*F^2 + Q) (* works *) > ==== I was trying to run one of the Mathematica Book -> Graphics Gallery -> Animations -> Rolling Square. I don't recall the exact sequence of actions I took. I believe I selected the cell with the square (the only cell in the notebook) and from the menu, Cell -> Animate Selected Graphics. This resulted in a set of animation control buttons appearing in the bottom frame of the window. I clicked on one of these buttons, but nothing happened. I looke back in the menu and saw M-y as a keyboard shorcut to run an animation. I tried that with no result. I clicked another button in graphics control set, and my X windows locked up. This included the keyboard's ability to give me another display by using Ctl+Alt+F1. I went to another system and ssh-ed in and found Mathematica had over 50% of my user resources, and was climbing. The same was true for VM. I have a gig of physical RAM. Once I killed Mathematica, my X came back to life. I've had several bad experiences with Mathematica and X. I honestly believe there isolate and fix these. Have others had such problems? STH ==== > XFree86 4.0.2. I was trying to run one of the Mathematica Book -> Graphics > Gallery - Animations -> Rolling Square. I don't recall the exact sequence of > actions > I took. I never had these problems. But I'm not longer able to export gif's etc. -- Hendrik van Hees Fakult.8at f.9fr Physik http://theory.gsi.de/~vanhees/ D-33615 Bielefeld ==== Dear MathGroup Members, I want to minimize a function which returns the minimizing value (arg min) of another function. For a simple example consider the following function opt which returns the arg min of x-2.5(1+Erf[x-s]). opt[s_]:=Block[{x}, x/. Last[ FindMinimum[x-2.5(1+Erf[x-s]), {x,1,3}]]] Now in a second step I want (again this is only a simple example for illustrative purposes) to minimize (opt[s]-2)^2 with respect to s. FindMininum has no problems with this. FindMinimum[(opt[s]-2)^2,{s,0.9,1.1}] {3.18689*^-23, {s -> 0.9816}}) However, NMinimize surrenders(!!!). Typing <<><><><><><><><><><><> Johannes Ludsteck Economics Department University of Regensburg Universitaetsstrasse 31 93053 Regensburg Reply-To: kuska@informatik.uni-leipzig.de ==== you guess right and if you hinder Mathematica to evaluate opt[] for symbolic arguments, with opt[s_?NumericQ] := Block[{x}, x /. Last[FindMinimum[x - 2.5(1 + Erf[x - s]), {x, 1, 3}]]] NMinimize[] works as expected. Jens > > Dear MathGroup Members, > > I want to minimize a function which returns the > minimizing value (arg min) of another function. > > For a simple example consider the following > function opt which returns the arg min of x-2.5(1+Erf[x-s]). > > opt[s_]:=Block[{x}, x/. Last[ > FindMinimum[x-2.5(1+Erf[x-s]), {x,1,3}]]] > > Now in a second step I want (again this is only > a simple example for illustrative purposes) to minimize > (opt[s]-2)^2 with respect to s. > > FindMininum has no problems with this. > > FindMinimum[(opt[s]-2)^2,{s,0.9,1.1}] > {3.18689*^-23, {s -> 0.9816}}) > > However, NMinimize surrenders(!!!). Typing > > < NMinimize[(opt[s]-2)^2,{s,0.9,1.1}] > only leads to the error message > > FindMinimum::fmnum: Objective function > 0.1 - 2.5 (1. +Erf[0.1 - 1. s]) is not real at {x} = {1.}. > > There is nothing wrong with minimand. It has exactly > one minimum in the Interval[{0.9,1.1}]. > > I guess the reason is that NMinimize calls opt[s] > not with a numerical value for s. This causes the > problem, since opt again calls FindMinimum. > Why? Can someone explain the failure and tell me > how to avoid this drawback? Wolfram Research boasts > that NMinimize can handle any function... > > I hope that nobody will recommend me to use FindMinimum > here instead. I know that the example here could of > course be solved by FindMinimum, but my real world > application can not. > > Johannes Ludsteck > > <><><><><><><><><><><>< Johannes Ludsteck > Economics Department > University of Regensburg > Universitaetsstrasse 31 > 93053 Regensburg ==== Your Mathematica 4.2 is certainly not like the one most of us have: > This reveals us another integral which Mathematica 4.1 fails to > calculate In[1] := Integrate[Cos[Pi/4 - z]^2/z, {z, 1, Infinity}] // N > Out[1]= -0.0173083 Out[2]= 4.1 for Microsoft Windows (November 2, 2000) but Mathematica 4.2 handles correctly In[1] := Integrate[Cos[Pi/4 - z]^2/z, {z, 1, Infinity}] > Out[1] = Integrate::idiv: Integral of... does not converge on > {1, Infinity). Out[2]= 4.2 for Microsoft Windows (February 28, 2002) Well, actually with my 4.2 we get: In[1]:= Integrate[Cos[Pi/4 - z]^2/z, {z, 1, Infinity}] Out[1]= (1/4)*(Pi - 2*SinIntegral[2]) > Even simpler, In[1] := Integrate[Cos[z]^2/z, {z, 1, Infinity}] > Out[1] = -EulerGamma/2 - Log[2]/2 + (EulerGamma - CosIntegral[2] + > Log[2])/2 Out[2]= 4.1 for Microsoft Windows (November 2, 2000) which is wrong while Mathematica 4.2 works excellent In[1] := Integrate[Cos[z]^2/z, {z, 1, Infinity}] > Out[1] = Integrate::idiv: Integral of...does not converge on > {1, Infinity). Out[2]= 4.2 for Microsoft Windows (February 28, 2002) Not so fast: In[2]:= Integrate[Cos[z]^2/z, {z, 1, Infinity}] Out[2]= -(EulerGamma/2) - Log[2]/2 + (1/2)*(EulerGamma - CosIntegral[2] + Log[2]) I'd speculate that fixing these two integrals in the beta stage some more important ones, so the original way of doing things was restored in the released version. However, it gets even more interesting if we load: << Calculus`Limit` In[4]:= Integrate[Cos[Pi/4-z]^2/z,{z,1,Infinity}] ReplaceRepeated:: rrlim :Exiting after Interval[{-1,1}]/z + Interval[{0, 1}]/z scanned 65536 times. Integrate:: idiv :Integral of Cos[Pi]/4 - z^2/z does not converge on {1, Infinity]. Out[4]= Integrate[Cos[Pi/4 - z]^2/z, {z, 1, Infinity}] In[5]:= Integrate[Cos[z]^2/z, {z, 1, Infinity}] ReplaceRepeated::rrlim:Exiting after Interval[{0,1}] scanned 65536 times. Integrate::idiv:Integral of Cos[z]^2/z does not converge on {1, Infinity} Out[5]= Integrate[Cos[z]^2/z, {z, 1, Infinity}] In[6]:= Out[6]= 4.2 for Mac OS X (June 4, 2002) > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== Murray, I don't like TraditionalForm for Inline cells either. I just use MenuCellDefault Inline Format TypeStandard Form. Also, when I design my own style sheets I often define a bolder font for Inline cells so they stand out better. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ soon as I press the Control-^ key combination, an Inline cell is created beginning with the x, and then when I type the exponent 2 everything in that Inline cell is now in Times, and the x is Italic. To change both characters to Courier is not so easy: it seems to require separately the entire Inline cell and selecting Courier does not change the exponent!) So to avoid this annoyance I normally must first type the desired expression in a separate Input cell, then copy the contents of that cell to the desired point in the Text cell. Any suggestions on a more efficient method for handling this? > In receiving notebooks from many different people I have noticed that > beginners often do not know how to use Text cells .... Some users may hesitate to use Text cells because they want to include a > mathematical expression in the comments.... > Just use an Inline cell within the text cell.... -- 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 Amherst, MA 01375 Reply-To: murray@math.umass.edu ==== That approach wouldn't work for me, since I often DO have to include within text cells some expressions in traditional mathematical notation and others in Mathematica's Standard Form. (The reason is that I'm often writing exposition as to how to express mathematical ideas and procedures in terms of Mathematica.) So probably the best way -- I'm not sure yet how to do it nicely -- would be a palette that more quickly allows me to change the format of a highlighted Inline cell to one or the other. Which reminds me of a related formatting matter. Often I need to include several paragraphs within a text cell, including displayed Inline cells on their own, separate lines. (No separate text cells would NOT meet my needs here.) The thing I usually do is to select the whole cell and from the Options Inspector sucessively select Formatting Options > Text Layout Options > ParagraphSpacing and then change the setting multiply from its default value 0 to 0.5. That provides just the right amount of inter-paragraph space. One of these days I'll figure out how to program a button on a palette to do that. General observation: It's stuff like this that makes Mathematica so much harder than a traditional tool, such as TeX/LaTeX, for typesetting mathematical exposition. Nothing beats a markup language for speed of entry. At least a sufficiently generous supply of formatting buttons would be the next best thing (far superior to having to burrow down through a nested menu in the Options Inspector). For example, I always keep open the palette FormattingTools.nb that allows changing the text face, size, or font (Courier, Times, Helvetica) at a click. (Not sure where I got the FormattingTools.nb palette from; it's not part of the standard Mathematica distribution. Perhaps it was from Publicon?) > Murray, > > I don't like TraditionalForm for Inline cells either. I just use > MenuCellDefault Inline Format TypeStandard Form.... -- 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 Amherst, MA 01375 ==== What is the TMJ style sheet? In any case, when people design new style sheets they would be well advised to keep Alt-7 as the key for Text style, and maintain the keys for other common styles also. Mathematica assigns keys in the order that the cell definitions appear in the style sheet. That means that new cell styles should be moved lower in the style sheet, even if that would not be their natural order. It would be nice if WRI allowed us to explicitly assign the keys for the styles. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Here's a better version of DotPlot that is improved by Borut's and Allan's idea: Needs[Utilities`FilterOptions`]; DotPlot[data_?MatrixQ, opts___Rule] := Module[{colorfn, scale, dotsize, m, scalefn}, colorfn = ColorFunction/.{opts}/.{ColorFunction->Hue}; scale = ColorFunctionScaling/.{opts}/.{ColorFunctionScaling->True}; dotsize = DotSize/.{opts}/.{DotSize->0.01}; m = If[scale, {Min[#],Max[#]}& @ Last[Transpose[data]], {0,1}]; scalefn = (# - m[[1]])/(m[[2]]-m[[1]])& ; Show[ Graphics[ {PointSize[dotsize],colorfn[scalefn[#3]],Point[{#1,#2}]}&@@@data], FilterOptions[Graphics, opts] ] ] --Selwyn ==== Here's a refinement of my previous post. Everything is wrapped up in a function named DotPlot, which takes the following options: ColorFunction (default: Hue) ColorFunctionScaling (default: True) DotSize (default: 0.01) You can also provide other options such as Axes, Frame, Background, etc. Needs[Utilities`FilterOptions`]; DotPlot[data_?MatrixQ, opts___Rule] := Module[{colorfn, scale, dotsize}, colorfn = ColorFunction/.{opts}/.{ColorFunction->Hue}; scale = ColorFunctionScaling/.{opts}/.{ColorFunctionScaling->True}; dotsize = DotSize/.{opts}/.{DotSize->.01}; With[{m = If[scale,{Min[#],Max[#]}&@Transpose[data][[3]], {0,1}]}, Show[(Graphics[ {colorfn[#[[3]]],PointSize[dotsize],Point[{#[[1]],#[[2]]}]}]&)/@ (data /. {x_,y_,z_}-> {x,y,(z-m[[1]])/(m[[2]]-m[[1]])}), FilterOptions[Graphics, opts] ] ] ] Example: vals = Table[{Random[], Random[], .5 Random[]}, {100}]; DotPlot[vals, ColorFunction -> (Hue[#, 1, 1-#] & ), ColorFunctionScaling -> False, DotSize -> 0.02, Frame -> True] --- Selwyn Hollis ==== With verision 3.0 on a machine running Windows NT the following code produces rotated text with each of the charaters rotated as well degstr[th_]:=StringJoin[ToString[th], Degrees] str[th_,offset_]:={Point[{th,1}], Text[degstr[th],{th,1},offset,{Cos[th Degree],Sin[th Degree]}]} pic[offset_,plotrange_,angles_]:= Show[ Graphics[{PointSize[.015],str[#,offset]&/@angles},PlotRange->plotrange, AspectRati->.2,Frame[Rule]True,FrameTick->None, DefaultFon->{Courier,10}]]; pic[{0,0},{{-10,95},{-.1,2.1}},Range[0,90,10]]; With version 4.2 on a machine running Mac OS 10.2.1 the text is rotated but the characters in the text are not. That is the position of the chacters relative to each other changes but their orientation remains constant. I would like to have the character orientation change as it does when this code is run under Windows NT. Does anyone know if there is a setting somewhere that controls character orientation when text is rotated? ==== This should be on faq. Mac Mathematica lack this particular feature (This is not a bug, according to WRI). You can use HERSHEY package available from MathSource (ftp.mathsource.com). Example: s=.08; g=Plot[Sin[x],{x,0,Pi},DisplayFunction->Identity]; g1=Graphics[{AbsoluteThickness[.5], hText[x-axis values,{0,0}], Hue[0,0,1],hText[(,{-14,0}]}, AspectRatio->Automatic]; s1=s/2*Divide@@(Max@#-Min@#&/@ Transpose[Sequence@@#&/@Join[g1[[1,2]],g1[[1,4]]]/. Line->(Sequence@@#&)]); g2=Graphics[{AbsoluteThickness[.5], hText[y-axis values,{0,0},1,90 Degree], Hue[0,0,1],hText[(,{0,-14},1,90 Degree]}, AspectRatio->Automatic]; s2=s/2/Divide@@(Max@#-Min@#&/@ Transpose[Sequence@@#&/@Join[g2[[1,2]],g2[[1,4]]]/. Line->(Sequence@@#&)]); Show[Graphics@Rectangle[Scaled@{s,s},Scaled@{1,1},g], Graphics@Rectangle[Scaled@{.56-s1,0},Scaled@{.56+s1,s},g1], Graphics@Rectangle[Scaled@{0,.56-s2},Scaled@{s,.56+s2},g2], DisplayFunction->$DisplayFunction]; DH ==== Andrzej, observe: a = 77617; b = 33096; f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) f Accuracy[f] Precision[f] Accuracy[10.^21] Precision[10.^21] 1.1805916207174113*^21 -5 16 -5 16 The two numbers supposedly have the same accuracy and precision, yet the first is in doubt by about 22 ORDERS OF MAGNITUDE -- never mind the digits! Mathematica computed this beast without giving any indication it was just noise -- without REALIZING it was noise. >>What more do you demand? I'm not demanding, objecting, or criticizing. I'm pointing out the problem. On the one hand, the poster is computing something that's simply not well-behaved. Unless he knows the coefficients with VERY high precision, he can't know even the magnitude of the result -- and that's not Mathematica's fault at all. On the other hand, Mathematica doesn't notice that precision is lost in the computation, and perhaps it should. You thought it DID notice, after all -- but it didn't. Bobby -----Original Message----- the same answer using the two different routes the original poster used. You on the other hand choose to assume that the posting shows that its author does not understand not just the mechanism of significance arithmetic used by Mathematica but also computations with inexact numbers in general. I do not think this is necessarily the correct assumption. I also don't see that Mathematica is doing anything wrong. After all, one can always check the accuracy of your answer: In[1]:= a = 77617.; b = 33096.; In[2]:= f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) In[3]:= f Out[3]= -1.1805916207174113*^21 In[4]:= Accuracy[%] Out[4]= -5 which tells you that it can't be very reliable. What more do you demand? Andrzej Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or algorithm > that will give the result precision, because the value of f really is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 52500771916869370459119776018798804630436149786919912931962574301029236 > 3 > 1246 > 75 / > 10867106143970760551000357827554793888198143135975649579607989867743572 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you won't > get the same answer as when you use exact numbers because of the way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > ==== Consider the total differential of f, with respect to the inexact numbers: Clear[a, b, x, y, f] f[a_, b_, x_, y_] := x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b) Simplify[Dt[f[a, b, x, y]] /. {Dt[a] -> da, Dt[b] -> db, Dt[x] -> dx, Dt[y] -> dy} /. {a -> 77617, b -> 33096, x -> 333.75, y -> 5.5}] -2.0400456966858126*^32*da + 4.784331242850472*^32*db + 1.3141745343712155*^27*dx + 1.4394747892125385*^36*dy f is sensitive to inaccuracy in the various numbers to widely varying degrees. Since the correct answer is small, we need a LOT of precision in the inputs to get there. If any of the inputs are merely machine precision numbers, we have NO precision in the result. The second and third terms are nearly the same magnitude with different signs. Even worse, the first term almost perfectly fills the gap: a = 77617; b = 33096; (33375/100)*b^6 438605750846393161930703831040 a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) -7917111779274712207494296632228773890 (55/10)*b^8 7917111340668961361101134701524942848 % + %% + %%% -2 Bobby Treat -----Original Message----- b = SetAccuracy[33096., Infinity]; In[4]:= f Out[4]= -(54767/66192) In[5]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity] Out[5]= 1180591620717411303424 Similarily: In[1]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 50]; a = SetAccuracy[77617., 100]; b = SetAccuracy[33096., 100]; In[4]:= f Out[4]= -0.8273960599468212641107299556`11.4133 In[5]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; Out[5]= 1.180591620717411303424`121.0721*^21 -PK ==== To Technical Support and the Mathematica User community, I'm writing to report what I consider to be a bug. First, I want to show a simplified example of the problem. Consider the following expression: expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; When simplified I expected to get some real number plus x[0]+3x[1]/4+9x[2]/16, but instead I get the following: Simplify[expr] 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] As you can see, for some reason Mathematica converted the fractions 3/4 and 9/16 to real machine numbers. I consider this to be a bug. Now, for an example more representative of the situation that I've been coming across. expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}]; expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}]; expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}]; As you can see, I have replaced the real numbers by extended precision numbers. The simplified example above demonstrates that the problem exists when using machine numbers. Now, we'll see what happens when we use arbitrary precision numbers. First, let's simplify the expression with 12 terms. Simplify[expr12] (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 x[5] + 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) / 4096 As you can see, a sum with 12 terms upon simplification has coefficients which are still integers as they should be. However, increasing the number of terms to 13 yields Simplify[expr13] 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] + 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] + 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 x[8] + 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 x[11] + 0.000244140625000 x[12] + 0.0001220703125000 x[13] Now, all of the coefficients are converted to real numbers, replicating the bug from the simplified example. Finally, let's see what happens when we have 55 terms. Rather than putting the resulting expression here, I will just leave it at the end of the post. The result though is somewhat surprising. Each of the coefficients of the x[i] are again real numbers, but now their precision is only 0! The proper result of course is the sum of some real number (with a precision close to 0 due to numerical cancellation) and an expression consisting of rational numbers multiplied by x[i]. The loss of precision of the coefficients of the x[i] is precisely what occurred to me. Of course, in this simple example, simply using Expand instead of Simplify produces the expected result, and is my workaround. I hope you agree with me that this is a bug, and one that Wolfram needs to correct. Carl Woll Physics Dept U of Washington Simplify[expr55] -16 -1 -1 -1 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10 x[5] + -2 -2 -2 -3 -3 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10 x[10] + -3 -3 -4 -4 -4 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10 x[15] + -5 -5 -5 -6 -6 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10 x[20] + -6 -6 -7 -7 -7 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10 x[25] + -8 -8 -8 -9 -9 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10 x[30] + -9 -9 -10 -10 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] + -10 -11 -11 -11 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] + -12 -12 -12 -12 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] + -13 -13 -13 -14 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] + -14 -14 -15 -15 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] + -15 -15 -16 -16 - 16 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] + 0. 10 x[55] ==== Look at the FullForm of your expressions: FullForm[Sqrt[X + Y + Z]] Power[Plus[X, Y, Z], Rational[1, 2]] FullForm[f] Plus[Times[Rational[1, 4], C, Power[F, -2], Power[Plus[X, Y, Z], Rational[-1, 2]]], Times[B, Plus[A, Power[Plus[X, Y, Z], Rational[1, 2]]]]] FullForm[h] Plus[Times[B, Plus[A, Power[Plus[X, Y, Z], Rational[1, 2]]]], Times[C, Power[Plus[Times[4, Power[F, 2]], Power[Plus[X, Y, Z], Rational[1, 2]]], -1]]] The square root appears in two different forms! A solution is to replace both patterns: f = B*(A + Sqrt[X + Y + Z]) + C/(Sqrt[X + Y + Z]/4*F^2); f /. {Sqrt[X + Y + Z] -> Q, 1/Sqrt[X + Y + Z] -> 1/Q} (4*C)/(F^2*Q) + B*(A + Q) This is very annoying, of course, and it may not take care of every case. Looking at the FullForm should help, when it fails. Bobby -----Original Message----- Print[(f/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + (4*C)/(F^2*Sqrt[X + Y + Z]) (* fails *) g=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]*4*F^2); Print[(g/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + C/(4*F^2*Sqrt[X + Y + Z]) (* fails *) h=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]+4*F^2); Print[(h/.Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + C/(4*F^2 + Q) (* works *) ==== >>I should add that the solution is over natural numbers.. this will probably make a big difference.. Yes, that probably removes the nearly from nearly impossible. I'd be curious to see the actual problem. Bobby -----Original Message----- eqns.. > preferably ones that will minimize the computation time for the other 14). > These equation are not linearly related.. the highest degree in any one eqn > is degree 4 i believe.. and there are some cross terms in the equations but > not every equation depends on every variable.. (some are actually rather > simple eqns). Any ideas on how to get started with this using > mathematica (any ideas for algorithms).. Anything will be helpful.. I can be reached at ngupta2@seas.upenn.edu Many thanks, Nachi ==== Group, in the help browser (V4.2) there is the following about Return[]: (* Return [expr] returns the value expr, existing all procedures and loops in a function *). Besides, from 2.5.9 Loops and control structures (also in Help browser) we can conclude that While, Do, Module, With, etc. must be understood as loops and/or control structures. But let us have a look at these two function definitions: yes[a_]:=With[{Ever=True},While[Ever,If[a==7,Return[Terminate] ];Print[loop]]], In (*yes[]*), Return[] exits the function breaking all loops and control structures, and yields Terminate as expected. not[a_]:=With[{Ever=True},While[Ever,While[Ever,If[a==7,Do[Return[Terminat e];Print[foo] ]];Print[loop]]]], However, in (*not[]*), Return[] only breaks the Do[] construct and keeps looping inside While[]. To my understanding, this contradicts that Return [expr] returns the value expr, existing all procedures and loops in a function as stated executing Return[] anywhere at any deep of nested looping constructs inside the function. I would appreciate any feedback. Emilio Martin-Serrano ==== > > > One of these days the company I work for will buy one Mathematica 4.2 > versions of the product. > > window manager. Our Windows systems are running on top of VMWare in Windows > XP Professional. > In testing using an evaluation version I found that the VMWare/XP version is > performing pretty well so that wouldn't be an issue. > > My main concern (and probably the grounds on which we will base our > decision) is the quality of the front-end. The Windows frontend works > flawlessly; however, in test-driving earlier versions of Mathematica (3.0 > satisfactorily. I didn't spend much time to hunt down the source of the > problem, but it is probable that some X key-mapping was wrong making, for > example, keyboard shortcuts for 'Copy' and 'Paste' malfunctioning. On the > Windows frontend. > > to full satisfaction? I'd be willing to spend a couple of hours to fix some > settings, but only if I'm sure it could be done. The bottom line is that I I > not if that would mean putting up with a quircky front-end. For what it is worth, I have no problems with the front end under Solaris - another varient of Unix. -- Dr. David Kirkby PhD, web page: http://www.david-kirkby.co.uk Amateur radio callsign: G8WRB ==== > > > One of these days the company I work for will buy one Mathematica 4.2 > Windows versions of the product. > > window manager. Our Windows systems are running on top of VMWare in > Windows XP Professional. > In testing using an evaluation version I found that the VMWare/XP version > is performing pretty well so that wouldn't be an issue. > > My main concern (and probably the grounds on which we will base our > decision) is the quality of the front-end. The Windows frontend works > flawlessly; however, in test-driving earlier versions of Mathematica (3.0 > satisfactorily. I didn't spend much time to hunt down the source of the > problem, but it is probable that some X key-mapping was wrong making, for > example, keyboard shortcuts for 'Copy' and 'Paste' malfunctioning. On the > Windows frontend. > > working to full satisfaction? I'd be willing to spend a couple of hours > to fix some settings, but only if I'm sure it could be done. The bottom > VMWare/Windows, but not if that would mean putting up with a quircky > front-end. > > For what it is worth, I have no problems with the front end under Solaris > - another varient of Unix. I sincerely wish WRI were more relaxed about allowing people to use the same license on the same hardware, but with a different OS. My understanding is that I would have to buy two licenses if I wanted to switch back and forth That's how open source is paid for. Not everybody has the same amount of spare blood in their veins, or willingness to spill it. For those who release of Mathematica, it would be nice to have a dual boot option. Perhaps it's simply a support issue. It would potentially cause the same customer to require more support if he were switching back and forth between OSs. http://public.globalsymmetry.com/proprietary/com/wri/ch05.html http://66.92.149.152/proprietary/com/wri/ch05.html I still have some tweaks to add to this, such as M-k -> C-k, but it at least demonstrates that (all) things aren't cast in stone. STH ==== Sidney, (or other Unix) for some years so perhaps my experience could help with your decision. Most of the time I run on Windows (2000, not yet XP) because: 1. The Front End is more stable. 2. The Front End is more comfortable in the sense that the keys for deleting, copying, pasting etc. are the ones my fingers expect them to be. 3. Command completion via Ctrl-k, which I use all the time, does not work 4. Generally speaking it takes more mouse clicks and keystrokes to do things I think these are general differences between the user interfaces on these operating systems rather than something specific to the Mathematica implementations. I have tried to overcome them at various time without success. Since I switched from Windows 95 to Windows NT several years ago, 2. I need to have access to certain files created on that system by other people. 3. I want to run long calculations on additional CPUs, leaving my desktop computer free for other things. You can do this between Windows machines kernel via Mathlink. This is very simple and more reliable and robust than Front End and it is easy, say, to transfer input or output betwen systems within a single Front End. I should add that in our lab we can access the the additional convenience of being able to save a notebook from the Windows Front End in the same directory as other files the kernel may be working with. You may not have this option and, of course, you need Mathematica on both systems. These are my personal opinions based on practical experience, I really do not want to enter into any controversy about operating systems. John Jowett One of these days the company I work for will buy one Mathematica 4.2 Windows > versions of the product. window manager. Our Windows systems are running on top of VMWare in Windows > XP Professional. > In testing using an evaluation version I found that the VMWare/XP version is > performing pretty well so that wouldn't be an issue. My main concern (and probably the grounds on which we will base our > decision) is the quality of the front-end. The Windows frontend works > flawlessly; however, in test-driving earlier versions of Mathematica (3.0 > satisfactorily. I didn't spend much time to hunt down the source of the > problem, but it is probable that some X key-mapping was wrong making, for > example, keyboard shortcuts for 'Copy' and 'Paste' malfunctioning. On the > Windows frontend. > working > to full satisfaction? I'd be willing to spend a couple of hours to fix some > settings, but only if I'm sure it could be done. The bottom line is that I I but > not if that would mean putting up with a quircky front-end. > Sidney Cadot > Reply-To: jmt@dxdydz.net ==== I would like to add : Some characters, at least with a french keyboard, are not directly available typed through their Mathematica entities : [EHat] , [OHat], etc. While this is not an issue when programming, it can become quite painful when writing documentation. > Hoi, > it depends a bit what you want to do. > E.g.: If you want to write applications for clients then go with that > systems your clients use (probably Windows). > If you just use it for yourself, for development: use what you like more. > anymore, like > there were in 3.0 times. > The copy and paste problems are gone if you switch off the KDE Klipper. > > On the other hand, there are a few OS- (or better Window-manager-specific) > 1.: you cannot rotate text (i.e., FrameLabel settings will look weird > (vertically arranged > horizontal letters), you have to use > RotateLabel -> False generally, or play with the Fonts settings > such that horizontal > tick marks still fit) > > 2.: If you work with bigger graphics in notebooks I suggest Windows (or > MacOS X) since > least on my XFree 4.2 > installation with a not too modern graphics card). > Also I find resizing of larger notebooks somewhat slow. > > 3.: If you like to work with keyboard shortcuts: Windows is better, clearly. > > 4.: There are a couple of Font issues which are better on Windows since > not all fonts > > engels, nederlands, duits of spaans) > > Rolf Mertig > > Mertig Consulting > Berlin > > > ==== Hoi, it depends a bit what you want to do. E.g.: If you want to write applications for clients then go with that systems your clients use (probably Windows). If you just use it for yourself, for development: use what you like more. anymore, like there were in 3.0 times. The copy and paste problems are gone if you switch off the KDE Klipper. On the other hand, there are a few OS- (or better Window-manager-specific) 1.: you cannot rotate text (i.e., FrameLabel settings will look weird (vertically arranged horizontal letters), you have to use RotateLabel -> False generally, or play with the Fonts settings such that horizontal tick marks still fit) 2.: If you work with bigger graphics in notebooks I suggest Windows (or MacOS X) since least on my XFree 4.2 installation with a not too modern graphics card). Also I find resizing of larger notebooks somewhat slow. 3.: If you like to work with keyboard shortcuts: Windows is better, clearly. 4.: There are a couple of Font issues which are better on Windows since not all fonts engels, nederlands, duits of spaans) Rolf Mertig Mertig Consulting Berlin ==== You are of course right, I forgot that Mathematica does not try to keep precision or accuracy of machine arithmetic computations. But I think the actual precision you set need not be higher than machine precision, it just has to be set explicitely (is that right?). For example: In[1]:= Clear[f,a,b,k] In[2]:= k = $MachinePrecision; In[3]:= f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ (2*b),k]; In[4]:= a=77617.;b=33096.; In[5]:= a=SetAccuracy[a,k]; In[6]:= b=SetAccuracy[b,k]; In[7]:= f Out[7]= !((-5.51716400890319`-2.8311*^19)) In[8]:= Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; bounding by $MinPrecision instead. Out[8]= -20 Andrzej > Andrzej Yes, like you I took the original question to be about how to get the > result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more > than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to more > digits than shown in the original post, they should be entered with > as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / > 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] > > 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. > You > should use a = SetAccuracy[a, Infinity] etc. But even then you won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you > the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== So? It's just as it should be, isn't it? Andrzej Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ > Go one step further: Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I think I'd prefer that Mathematica gave me a clue -- without being asked explicitly in JUST the right way that only you know and had forgotten -- that there's a precision problem. Oddly enough, when you DO ask it nicely, you get error messages, but if you're not aware there's a problem, it lets you go on your merry way, working with noise. Bobby -----Original Message----- Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I've been looking over the file and directory manipulation functions in Mathematica 4.1, and I'm not finding good examples of how to test for the existence of a file or directory before I attempt to create, access, or delete it. Are there any good examples of this somewhere? STH ==== FileNames[] does what you want. Steve Luttrell > I've been looking over the file and directory manipulation functions in Mathematica > 4.1, and I'm not finding good examples of how to test for the existence of > a file or directory before I attempt to create, access, or delete it. Are > there any good examples of this somewhere? STH > Reply-To: kuska@informatik.uni-leipzig.de ==== FileNames[] returns an empty list if there are no files. So FileNames[blub.txt] will return {} if the file does not exist. Jens > > I've been looking over the file and directory manipulation functions in Mathematica > 4.1, and I'm not finding good examples of how to test for the existence of > a file or directory before I attempt to create, access, or delete it. Are > there any good examples of this somewhere? > > STH ==== If you don't wont error messages all you need to do is to set MinPrecision low enough: In[1]:= $MinPrecision = -3; In[2]:= k = $MachinePrecision; In[3]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), k]; In[4]:= a = 77617.; b = 33096.; In[5]:= a = SetAccuracy[a, k]; In[6]:= b = SetAccuracy[b, k]; In[7]:= f Out[7]= -5.517164009`-2.8311*^19 In[8]:= Accuracy[f] Out[8]= -23 In[9]:= Precision[f] Out[9]= -3 In any case the answer you get is meaningless. > I think I'd prefer that Mathematica gave me a clue -- without being > asked explicitly in JUST the right way that only you know and had > forgotten -- that there's a precision problem. Oddly enough, when you DO ask it nicely, you get error messages, but if > you're not aware there's a problem, it lets you go on your merry way, > working with noise. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 8:05 PM > Cc: 'Allan Hayes'; mathgroup@smc.vnet.net So? It's just as it should be, isn't it? Andrzej Andrzej Kozlowski > Toyama International University > JAPAN > http://sigma.tuins.ac.jp/~andrzej/ > Go one step further: Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to > keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine > precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the > result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it > can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which > Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other > words, > it was why are the results of these two computations not the > same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f > should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; > f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision > does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 > + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== >>In any case the answer you get is meaningless. Precisely. Bobby -----Original Message----- 121*b^4 - 2) + 5.5*b^8 + a/(2*b), k]; In[4]:= a = 77617.; b = 33096.; In[5]:= a = SetAccuracy[a, k]; In[6]:= b = SetAccuracy[b, k]; In[7]:= f Out[7]= -5.517164009`-2.8311*^19 In[8]:= Accuracy[f] Out[8]= -23 In[9]:= Precision[f] Out[9]= -3 In any case the answer you get is meaningless. > I think I'd prefer that Mathematica gave me a clue -- without being > asked explicitly in JUST the right way that only you know and had > forgotten -- that there's a precision problem. Oddly enough, when you DO ask it nicely, you get error messages, but if > you're not aware there's a problem, it lets you go on your merry way, > working with noise. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 8:05 PM > Cc: 'Allan Hayes'; mathgroup@smc.vnet.net So? It's just as it should be, isn't it? Andrzej Andrzej Kozlowski > Toyama International University > JAPAN > http://sigma.tuins.ac.jp/~andrzej/ > Go one step further: Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to > keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine > precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the > result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it > can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 message > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which > Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other > words, > it was why are the results of these two computations not the > same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f > should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; > f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision > does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 > + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== >Many thanks to all who replied. > >The original problem was as follows: > >In a presentation I wish to use Plot to generate a sequence of frames and >then animate them. The problem is that the audience sees the animation >twice. Once when the frames are being generated and then again after I have >closed the group and double clicked on the top graphic. However, the first >showing during generation is enough (but uncontrolled). > >Is it possible to tidy up the generation of the graphic so that it becomes >the animation? >There were two main solutions which I now apply to my real problem and not >the simple, generic, problem in the original post. >The real problem was how to build up a probably density function (PDF) in >real time. In the examples below I redraw the PDF every time I add 10 >points. > >Initialise <<<<< JLink`; >wb=WeibullDistribution[2.101349094155377,22.58126779173235`]; >midpts=Table[i,{i,0.5,50,1}]; > >Solution from Omega Consulting > >GraphicCell[graphics_] := > Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics] > >Block[{$DisplayFunction=Identity, graphs}, > data={}; > graphs = > Table[data=Flatten[Join[data,RandomArray[wb,10]]]; > freq=BinCounts[data,{0,50,1}]; > GraphicCell[ > BarChart[Transpose[{freq,midpts}],ImageSize ->500] ], {500}]; > NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs,Closed]]]; > SelectionMove[EvaluationNotebook[], All, GeneratedCell]; > FrontEndExecute[{FrontEndToken[EvaluationNotebook[], > SelectionAnimate]}] > ] > >This solution works but it generates 500 frames and sometimes exceeds the >memory. >The paradigm here is generate all frames, then animate all frames. We >really need a loop that does: generate next frame, delete last frame, show next frame > >Is it possible to do this? Yes, however, I thought you didn't want to see the selection bar moving around during the animation. That's why I chose to generate the whole animation in one shot. Also, when you write the new cell over the old cell there is a flash between frames as the old frame is deleted. Here's an example of a frame-by-frame method. GraphicCell[graphics_] := Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics] CellPrint[Cell[,Graphics]]; Block[{$DisplayFunction=Identity}, Do[ SelectionMove[EvaluationNotebook[], All, GeneratedCell]; NotebookWrite[EvaluationNotebook[], GraphicCell[Plot[x y,{x,0,1}, PlotRange->{0,50}]]], {y,50} ] ] Also, if you add ShowCellBracket->False to GraphicCell and a Pause to the loop, then things get much better visually. -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html ==== I am trying to use FindRoot in mathematica 4.0 to find the zeros of a complex-valued function of one complex variable. In particular, I am looking for the one root with a positive imaginary part. I have a rough approximation for where the root should be, and this is good enough to give a reasonable guess. However, there are always two other roots near the one I want - one with 0 imaginary part and another with negative imag part. (For those who are interested, the zeros are the roots of the dispersion relation for a plasma interacting with a laser). Sometimes FindRoot picks up one of these instead of the one I want. So, I'd like to tell mathematica to look for a root only in a certain rectangular region of the complex plane. Well, if I could tell it, 'look for roots with imag. part > something', I'd be happy too. I tried specifying complex values for the start and stop points of an interval, hoping mathematica would interpret these as the corners of a rectangle. No such luck. Any help would be greatly appreciated. I'd also like to point out that this and other issues about complex roots are not clearly addressed in the built-in help files. ==== Just a shot: Try using the DampingFactor option to force FindRoot to take smaller steps. --- Selwyn Hollis ==== > > > I am trying to use FindRoot in mathematica 4.0 to find the zeros of a > complex-valued function of one complex variable. In particular, I am > looking for the one root with a positive imaginary part. I have a rough > approximation for where the root should be, and this is good enough to > give a reasonable guess. > > However, there are always two other roots near the one I want - one with > 0 imaginary part and another with negative imag part. (For those who > are interested, the zeros are the roots of the dispersion relation for a > plasma interacting with a laser). Sometimes FindRoot picks up one of > these instead of the one I want. > > So, I'd like to tell mathematica to look for a root only in a certain > rectangular region of the complex plane. Well, if I could tell it, > 'look for roots with imag. part > something', I'd be happy too. > > I tried specifying complex values for the start and stop points of an > interval, hoping mathematica would interpret these as the corners of a > rectangle. No such luck. > > Any help would be greatly appreciated. > > I'd also like to point out that this and other issues about complex > roots are not clearly addressed in the built-in help files. > I believe it is difficult to restrict FindRoot. Below are several suggestions. (1) You might try rigging the function, say with g[x_?NumberQ] := f[x] + If[Im[x]<=0,1000,0] (2) If you have version 4.2 a related approach would be to take advantage of constrained optimization and do NMinimize[{Re[f[x,y]]^2 + Im[f[x,y]]^2, rectangle range constraints}, {x,y}] or something along those lines. (3) If proximity of the other roots is the main problem it might be alleviated by rescaling your variable. (4) Alternatively you could write your function as a pair of real valued functions of two real valued arguments. Then you can use Interval to split the rectangle into parts, keeping subrectangles for which {0,0} lives in f[Interval[x],Interval[y]] where Interval[x], for example, is a shorthand for an interval for the x part of the rectangle being split. Daniel Lichtblau Wolfram Research Reply-To: kuska@informatik.uni-leipzig.de ==== and solving the real and imaginary part for for z->x+I*y with FindRoot[Evaluate[({Re[#] == 0, Im[#] == 0} &[ z^3 - 1]) /. z -> x + I y], {x, -3/2, 0}, {y, 0.5, 0.9}] helps not ? Jens > > > I am trying to use FindRoot in mathematica 4.0 to find the zeros of a > complex-valued function of one complex variable. In particular, I am > looking for the one root with a positive imaginary part. I have a rough > approximation for where the root should be, and this is good enough to > give a reasonable guess. > > However, there are always two other roots near the one I want - one with > 0 imaginary part and another with negative imag part. (For those who > are interested, the zeros are the roots of the dispersion relation for a > plasma interacting with a laser). Sometimes FindRoot picks up one of > these instead of the one I want. > > So, I'd like to tell mathematica to look for a root only in a certain > rectangular region of the complex plane. Well, if I could tell it, > 'look for roots with imag. part > something', I'd be happy too. > > I tried specifying complex values for the start and stop points of an > interval, hoping mathematica would interpret these as the corners of a > rectangle. No such luck. > > Any help would be greatly appreciated. > > I'd also like to point out that this and other issues about complex > roots are not clearly addressed in the built-in help files. > ==== The last part of my message you are quoting was completely wrong, as was pointed out by Allan Hayes. Mathematica does not track precision of machine arithmetic computations. In order for Mathematica to give reliable information about the precision of a computation you have to explicitly set the precision of all the numerical quantities. Your own example at the bottom simply shows you have not understood the evaluation mechanism of Mathematica. What you are doing is this: In[1]:= a = SetAccuracy[77617., Infinity]; b = SetAccuracy[33096., Infinity]; At this point you have converted a and be to have the following exact values: In[3]:= a Out[3]= 77617 In[4]:= b Out[4]= 33096 Next you evaluate: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity] but this is a two step process (which is what you seem not to have grasped). First Mathematica computes: In[5]:= 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) Out[5]= 1.1805916207174113*^21 Now, because there were machine floats in the formula (333.75 and 5.5 ) the whole expression was computed using machine arithmetic without keeping track of precision. The answer is therefore completely inacurate. Mathematica returns the purely formal accuracy: In[6]:= Accuracy[%] Out[6]= -5 But the second part of your evaluation tells it to take this inaccurate answer and convert it to an exact number. In[7]:= SetAccuracy[%%, Infinity] Out[7]= 1180591620717411303424 In[8]:= Accuracy[%] Out[8]= Infinity But of course doing this is meaningless, after converting an inexact answer to an exact number does not make it a an exact answer! Of course had you evaluated f before you assigned the values to a and b you would not have encountered the problem because no machine reals would have appeared in the computation. ALternatively you might have used: f = SetAccuracy[333.75, Infinity]*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + SetAccuracy[5.5, Infinity]*b^8 + a/(2*b) Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? > As you are dealing here only with machine-precision numbers, your When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine-Áçprecision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. In practice, to rely on a numerical result, you ALWAYS have to check > its accuracy. How reliable is Accuracy anyway? In[1]:= > a = SetAccuracy[77617., Infinity]; > b = SetAccuracy[33096., Infinity]; In[3]:= > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b), Infinity] Out[3]= > 1180591620717411303424 In[4]:= > Accuracy[f] Out[4]= > Infinity We got completely wrong result with Infinite accuracy. In conclusion, > one can not rely on Accuracy. Checking numerical results in > Mathematica sounds like a tough task.:-) --PK Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ [...] > ==== leap to MathGroup so I'll respond there as well to some of the issues raised herein. > > Daniel, > > >>The precision/accuracy tracking mechanism will generally let you know, > >>in some fashion, that you have no trustworthy digits. But it is up to > >>the user to check that sort of thing. > > In this case Mathematica did NOT let us know, in any fashion, that we > had no trustworthy digits. Precision and Accuracy outputs were > completely misleading. (16 and -5 respectively.) Precision, in this case, is itself a bit misleading. As I recall machine arithmetic was in use. For that domain just regard 16 as the definition of precision. Moreover no tracking is done. It is only when bignums are used that significance arithmetic will be at play. By the way, the distinction between precision for machine numbers vs. bignums will be more clear with our next big release. At present one does not know if 16 refers to a machine number or a bignum of that same precision. > Even Andrzej > Kozlowski, who's adept in Mathematica, thought that would be meaningful, > and never came up with a better way to check (other than using infinite > precision for numbers that probably aren't known that exactly). Peter > Kosta demonstrated that he could get a completely erroneous answer with > Infinite precision. > > I blame the problem primarily, and I don't think there's any way to make > the answer meaningful. That's not Mathematica's fault at all, and users > need to be aware of that old maxim: garbage in, garbage out. Right. One cannot artificially raise precision or accuracy after the fact and expect a meaningful result. Again, had significance arithmetic been used, I think there would have been adequate information to assess the problem. > comes up with a 22-digit result, it doesn't take much sophistication to > realize the answer can't have 16-digit precision. > > Here's an even more extreme result: > > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 50]; > a = 77617.; b = 33096.; > f > Precision[f] > > -1.180591620717411303424`71.0721*^21 > 71 > > 71.0721 digits of precision? I don't think so!! It's correct, albeit the number is garbage. You start with a number that is, in your words, all noise. (I assume you had set a and b before f, because otherwise I get a different result for Precision[f]). Now f ~ 10^21, and so has accuracy of around 71 digits. Garbage notwithstanding, this behavior is entirely correct and as it should be. > We can do the following instead: > > x = Interval[333.75]; > y = Interval[5.5]; > a = Interval[77617.]; > b = Interval[33096.]; > x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b) > > Interval[{-4.486248158726164*^22, 4.2501298345826815*^22}] > > and that looks like the right answer, finally!! I like that method. Yes, it's a useful way to show that the result has no digits to trust. Actually you can achieve a similar effect using significance arithmetic, as below. x = SetPrecision[33375/100, 16]; y = SetPrecision[11/2, 16]; a = SetPrecision[77617, 16]; b = SetPrecision[33096, 16]; In[18]:= InputForm[x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b)] Out[18]//InputForm= -1.1339143158169`0*^14 This tells you there are NO reliable digits. The advantage to this is that is is more flexible than interval arithmetic in Mathematica which will not, for example, deal well with complex-valued functions or complex domains. Also significance arithmetic (aka arbitrary precision arithmetic) is much faster than interval arithmetic for large problems. > However, that doesn't change the fact that Accuracy, Precision, and > SetAccuracy appear to be completely useless. My own experience is that they are quite useful. But only if used with care and in appropriate ways. Raising accuracy after the fact does not fall into that category. > I haven't seen an example > in which they did what anyone (but you) thought they should do. > > Bobby Maybe. But, curiously enough, I am a user rather than developer when it comes to that stuff. I used the precision mechanism alot in polynomial NSolve, and it did indeed work to my liking. Which counts for something from the ordinary users' perspective, because now NSolve works better than it otherwise might. > -----Original Message----- > > > I think I'd prefer that Mathematica gave me a clue -- without being > > asked explicitly in JUST the right way that only you know and had > > forgotten -- that there's a precision problem. > > Oddly enough, when you DO ask it nicely, you get error messages, but > if > > you're not aware there's a problem, it lets you go on your merry way, > > working with noise. > > Bobby > > Mathematica is not a mind reader. But the evaluation sequence, while > complicated, is reasonably well documented. If you perform machine > arithmetic, or for that matter significance arithmetic, and there is > massive cancellation error, no use of SetAccuracy after the fact will > fix it. > > The precision/accuracy tracking mechanism will generally let you know, > in some fashion, that you have no trustworthy digits. But it is up to > the user to check that sort of thing. It is not obvious to me what sort > of error the software might notice to report. If you have a concise > example of input, and expected output, I can look further. I've not seen > anything in this thread that struck me as a failure of the software to > warn the user, but maybe I missed something. > > Daniel Daniel Lichtblau Wolfram Research ==== > > The more I play with the example the more depressing it gets. Start > with floating point numbers but explicitely arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine[CapitalEth]precision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers Mathematica should display > only those digits that are correct, that is none. No, 26 digits are correct (check Precision instead of Accuracy to see this). You appear to be showing output in InputForm. If you use OutputForm or StandardForm only 26 digits will be shown. 32 Out[3]= -4.7833916866605540257808360 10 InputForm is showing more because it exposes bad digits as well as good ones. > To relax a bit, set a new input cell to StandardForm and type > 77617.000000000000000000000000000000000 > > Convert it to InputForm. You get > 77616.999999999999999999999999999999999999999999952771`37.9031 > > Convert back to StandardForm > 77616.99999999999999999999999999999999999999999976637`37.9031 > > Again to InputForm > 77616.99999999999999999999999999999999999999999963735`37.9031 > > Back to StandardForm > 77616.99999999999999999999999999999999999999999951376`37.9031 > > See what you can get if you have enough patience or a small program. > > PK Agreed, it's not very pretty. I am uncertain as to whether this indicates a bug in StandardForm or elsewhere in the underlying numerics code, and will defer to our numerics experts on that issue. My guess is it is a bug if only because it violates the spirit of IEEE arithmetic wherein floats that have integer values should be representable as such (or something to that effect). I will point out, however, that the two numbers in question are equal to the specified precision. Also it appears to be improved in our development kernel. Daniel Lichtblau Wolfram Research ==== The more I play with the example the more depressing it gets. Start with floating point numbers but explicitely arbitrary-precision ones. In[1]:= a=77617.00000000000000000000000000000; b=33095.00000000000000000000000000000; In[3]:= !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 b^2 - b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + a/(2 b)) Out[3]= !((-4.78339168666055402578083604864320577443814`26.6715*^32)) In[4]:= Accuracy[%] Out[4]= -6 Due to the manual section 3.1.6: When you do calculations with arbitrary-precision numbers, as discussed in the previous section, Mathematica always keeps track of the precision of your results, and gives only those digits which are known to be correct, given the precision of your input. When you do calculations with machine-precision numbers, however, Mathematica always gives you a machine[CapitalEth]precision result, whether or not all the digits in the result can, in fact, be determined to be correct on the basis of your input. Because I started with arbitrary-precision numbers Mathematica should display only those digits that are correct, that is none. To relax a bit, set a new input cell to StandardForm and type 77617.000000000000000000000000000000000 Convert it to InputForm. You get 77616.999999999999999999999999999999999999999999952771`37.9031 Convert back to StandardForm 77616.99999999999999999999999999999999999999999976637`37.9031 Again to InputForm 77616.99999999999999999999999999999999999999999963735`37.9031 Back to StandardForm 77616.99999999999999999999999999999999999999999951376`37.9031 See what you can get if you have enough patience or a small program. PK ==== > The more I play with the example the more depressing it gets. Start > with floating point numbers but explicitely arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine[CapitalEth]precision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers Mathematica should display > only those digits that are correct, that is none. I retract the above comment. I did not notice that was an error in the input. b=33095.00000000000000000000000000000 intstead of intended b=33096.00000000000000000000000000000 I am sorry for the mistake. PK > > > To relax a bit, set a new input cell to StandardForm and type > 77617.000000000000000000000000000000000 > > Convert it to InputForm. You get > 77616.999999999999999999999999999999999999999999952771`37.9031 > > Convert back to StandardForm > 77616.99999999999999999999999999999999999999999976637`37.9031 > > Again to InputForm > 77616.99999999999999999999999999999999999999999963735`37.9031 > > Back to StandardForm > 77616.99999999999999999999999999999999999999999951376`37.9031 > > See what you can get if you have enough patience or a small program. > > PK ==== > The last part of my message you are quoting was completely wrong, as > was pointed out by Allan Hayes. Mathematica does not track precision of > machine arithmetic computations. In order for Mathematica to give > reliable information about the precision of a computation you have to > explicitly set the precision of all the numerical quantities. > > Your own example at the bottom simply shows you have not understood the > evaluation mechanism of Mathematica. Just opposite, thanks to you and other participants, I completely understood it. SetAccuracy just takes anything and calls it accurate. This behavior is useless if not stupid. It was apparently intended by Mathematica developers but that doesn't make it right. On a side note, I hate the argument It is descibed in the manual, therefore it is correct. Legal doesn't mean right. Besides there is no supreme court here to overrule some stupid law. :-) PK > > [...] ==== >Dear Colleagues, > >I calculated: > >Sum[1/Prime[n], {n, 15000}] // N > >Result: 2.74716 > >Now I wonder if this sum will converge or keep on growing, albeit very >slowly. >Matthias Bode >Sal. Oppenheim jr. & Cie. KGaA >Koenigsberger Strasse 29 >D-60487 Frankfurt am Main >GERMANY >Mobile: +49(0)172 6 74 95 77 >Internet: http://www.oppenheim.de > The serie is divergent! I suggest you to look at this beautiful introduction to primes distribution http://www.maths.ex.ac.uk/%7Emwatkins/zeta/vardi.html Bye, rob Roberto Brambilla CESI Via Rubattino 54 20134 Milano tel +39.02.2125.5875 fax +39.02.2125.5492 rlbrambilla@cesi.it ==== > I've been looking over the file and directory manipulation functions in Mathematica > 4.1, and I'm not finding good examples of how to test for the existence of > a file or directory before I attempt to create, access, or delete it. Are > there any good examples of this somewhere? STH Steven, Directory[] returns the current directory $Path returns the directories in your path where files can be found. SetDirectory[] changes to the specified directory and makes it the current directory. FileNames[] returns a list of all the file names (text documents, picture documents etc) and subdirectory (folder) names in the current directory. Since FileNames returns a list of elements, you can use all sorts of tests to see if a file you're looking for is in a said directory or not or whether it is a subdirectory or not. I hope that this will get you started. Yas ==== has anybody tried to modify the classes.m package in the way, it would be possible to have several superclasses? Oleg. ==== What does this page say, auf Englisch? I only pretend to understand German. http://www.mertig.com/neu/HTMLLinks/index_6.html STH ==== The sum diverges. See Elementary Number Theory, 5th edition by David M. Burton, pages 355-356. -----Original Message----- Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== Technical support has responded to my query. They say that one of the simplifications that Mathematica does when using Simplify is to Factor the expression, and factoring an expression consisting of inexact numbers leads to the type of behavior I observed. They stated that changing the behavior of Simplify to avoid the problems I noticed would make Simplify less capable, and that the majority of users would prefer to have Simplify behave the way it currently does. Of course, that doesn't answer the question about why the number of terms in the expression would cause the coefficients to go from rational to inexact to rational again. At any rate, I have another lesson learned. When using Simplify, check the result if you are mixing infinite precision and inexact numbers, as the result may not be what you wanted. In the past I always assumed that the result of using Simplify on an expression produced a result equivalent to the original expression, but now I discover that this is not true. Carl Woll Physics Dept U of Washington ----- Original Message ----- > {i, > n}]], x[1]] Now lets try CW for the first 100 values of n: > In[30]:= > Table[CW[n], {n, 100}] Out[30]= > {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, > 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, > 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, > 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, > 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, > 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, > 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, > 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, > 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, > 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423, > 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2} In[31]:= Map[Length,Split[#]] Out[31]= > {12,43,45} This is indeed curious.The problem seems to occur for values between 13 > and 55 and then go away (for good???) At first I thought it maybe in > some fascinating way related to some properties of the integer n, but > now I am not sure. It certainly worth a careful examination. I hope > whoever discovers the cause of this will let us know. Andrzej Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > To Technical Support and the Mathematica User community, > > I'm writing to report what I consider to be a bug. First, I want to > > show a > > simplified example of the problem. Consider the following expression: > > expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; > > When simplified I expected to get some real number plus > > x[0]+3x[1]/4+9x[2]/16, but instead I get the following: > > Simplify[expr] > > 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] > > As you can see, for some reason Mathematica converted the fractions > > 3/4 and > > 9/16 to real machine numbers. I consider this to be a bug. > > Now, for an example more representative of the situation that I've been > > coming across. > > expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}]; > > expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}]; > > expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}]; > > As you can see, I have replaced the real numbers by extended precision > > numbers. The simplified example above demonstrates that the problem > > exists > > when using machine numbers. Now, we'll see what happens when we use > > arbitrary precision numbers. First, let's simplify the expression with > > 12 > > terms. > > Simplify[expr12] > > (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 > > x[5] + > > 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) > > / 4096 > > As you can see, a sum with 12 terms upon simplification has > > coefficients > > which are still integers as they should be. However, increasing the > > number > > of terms to 13 yields > > Simplify[expr13] > > 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] + > > 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] + > > 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 > > x[8] + > > 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 > > x[11] > > + > > 0.000244140625000 x[12] + 0.0001220703125000 x[13] > > Now, all of the coefficients are converted to real numbers, > > replicating the > > bug from the simplified example. Finally, let's see what happens when > > we > > have 55 terms. Rather than putting the resulting expression here, I > > will > > just leave it at the end of the post. The result though is somewhat > > surprising. Each of the coefficients of the x[i] are again real > > numbers, but > > now their precision is only 0! The proper result of course is the sum > > of > > some real number (with a precision close to 0 due to numerical > > cancellation) > > and an expression consisting of rational numbers multiplied by x[i]. > > The > > loss of precision of the coefficients of the x[i] is precisely what > > occurred > > to me. Of course, in this simple example, simply using Expand instead > > of > > Simplify produces the expected result, and is my workaround. I hope you > > agree with me that this is a bug, and one that Wolfram needs to > > correct. > > Carl Woll > > Physics Dept > > U of Washington > > Simplify[expr55] > > -16 -1 -1 -1 > > 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10 > > x[5] + > > -2 -2 -2 -3 -3 > > 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10 > > x[10] > > + > > -3 -3 -4 -4 > > -4 > > 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10 > > x[15] + > > -5 -5 -5 -6 > > -6 > > 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10 > > x[20] + > > -6 -6 -7 -7 > > -7 > > 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10 > > x[25] + > > -8 -8 -8 -9 > > -9 > > 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10 > > x[30] + > > -9 -9 -10 -10 > > 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] + > > -10 -11 -11 -11 > > 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] + > > -12 -12 -12 -12 > > 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] + > > -13 -13 -13 -14 > > 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] + > > -14 -14 -15 -15 > > 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] + > > -15 -15 -16 -16 > > - > > 16 > > 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] + > > 0. 10 > > x[55] > ==== Dear Carl You have discovered what is perhaps a bug but maybe something even mor einteresting . However, I think you stopped your investigation a little prematurely. Here is a function that just computes the coefficient of x[1] in your Simplified expression for various values of n: CW[n_] := Coefficient[Simplify[1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, n}]], x[1]] Now lets try CW for the first 100 values of n: In[30]:= Table[CW[n], {n, 100}] Out[30]= {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423, 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2} In[31]:= Map[Length,Split[#]] Out[31]= {12,43,45} This is indeed curious.The problem seems to occur for values between 13 and 55 and then go away (for good???) At first I thought it maybe in some fascinating way related to some properties of the integer n, but now I am not sure. It certainly worth a careful examination. I hope whoever discovers the cause of this will let us know. Andrzej Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > To Technical Support and the Mathematica User community, I'm writing to report what I consider to be a bug. First, I want to > show a > simplified example of the problem. Consider the following expression: expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; When simplified I expected to get some real number plus > x[0]+3x[1]/4+9x[2]/16, but instead I get the following: Simplify[expr] > 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] As you can see, for some reason Mathematica converted the fractions > 3/4 and > 9/16 to real machine numbers. I consider this to be a bug. Now, for an example more representative of the situation that I've been > coming across. expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}]; > expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}]; > expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}]; As you can see, I have replaced the real numbers by extended precision > numbers. The simplified example above demonstrates that the problem > exists > when using machine numbers. Now, we'll see what happens when we use > arbitrary precision numbers. First, let's simplify the expression with > 12 > terms. Simplify[expr12] > (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 > x[5] + 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) > / 4096 As you can see, a sum with 12 terms upon simplification has > coefficients > which are still integers as they should be. However, increasing the > number > of terms to 13 yields Simplify[expr13] > 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] + 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] + 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 > x[8] + 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 > x[11] > + 0.000244140625000 x[12] + 0.0001220703125000 x[13] Now, all of the coefficients are converted to real numbers, > replicating the > bug from the simplified example. Finally, let's see what happens when > we > have 55 terms. Rather than putting the resulting expression here, I > will > just leave it at the end of the post. The result though is somewhat > surprising. Each of the coefficients of the x[i] are again real > numbers, but > now their precision is only 0! The proper result of course is the sum > of > some real number (with a precision close to 0 due to numerical > cancellation) > and an expression consisting of rational numbers multiplied by x[i]. > The > loss of precision of the coefficients of the x[i] is precisely what > occurred > to me. Of course, in this simple example, simply using Expand instead > of > Simplify produces the expected result, and is my workaround. I hope you > agree with me that this is a bug, and one that Wolfram needs to > correct. Carl Woll > Physics Dept > U of Washington Simplify[expr55] > -16 -1 -1 -1 > 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10 > x[5] + -2 -2 -2 -3 -3 > 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10 > x[10] > + -3 -3 -4 -4 > -4 > 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10 > x[15] + -5 -5 -5 -6 > -6 > 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10 > x[20] + -6 -6 -7 -7 > -7 > 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10 > x[25] + -8 -8 -8 -9 > -9 > 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10 > x[30] + -9 -9 -10 -10 > 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] + -10 -11 -11 -11 > 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] + -12 -12 -12 -12 > 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] + -13 -13 -13 -14 > 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] + -14 -14 -15 -15 > 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] + -15 -15 -16 -16 > - > 16 > 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] + > 0. 10 > x[55] > ==== I think, for input of that many numbers (and other inputs), I might use an input file that has textual names or descriptions in the first ten or twenty columns, followed by values starting at a fixed column after that. Mathematica or Java could easily read inputs from that, and a human could read it as well. If you're concerned that a human might jumble the file format -- accidentally deleting lines, etc. -- a program could key on the names or descriptions rather than trusting them to be in correct order, and point out missing values. A strategy like that allows you to start with a previous input file (not from scratch) and change only what needs to change. Also, Mathematica 4.2 adds XML support to the picture, and that might be useful. Bobby -----Original Message----- > I agree with Mr. Kuska, that the system Mr Nagesh describes is not > > userfriendly. But I think, the suggestions of Mr. Kuska do not make it more > > userfriendly, rather the opposite is true. > > Mr. Nagesh asks > > Is any body here have expertise or information about the capability of > > Mathematica as a system simulation tool? > > Mr. Kuska answers: > > Since the most system simulation tools are simply solving a system of > > ordinary differntial equations it is simple to do this with NDSolve[]. > > My comment: > > That is: He sees the simulation system merely as a set of differential > > equations. hmm, since the original poster write My refrigeration system simulation package is likely to have > approximately 60 First order Differential equations. it seems not completly wrong to assume that the system consists of > of ode's .. > Yout should not ignore the word merely. It is not enough to have a set 60 differential equations and a set of 200-250 numbers. That is not simulation system, which can be used by users with the exception, perhaps, of the programmer of the system himself. How does e.g. the user know what meaning a number in the set has, ought he count the numbers from the beginning? Your nice command shows only, if there is an input, which is not a number. But I think the user would like to know, which of the 200 elements are not numbers. The only good of your command is, that it looks nice and shows your knowledge! > > The question of Mr. Nagesh: > > My 4th Objective:- How can I program the check for correctness of the > > input values supplied by the package user ? > > The answer of Mr. Kuska is: > > And @@ (NumericQ /@ {aListOfAllYourNumericParameters}) > > My comment: > > This is a nice command and shows the knowledge of Mr.Kuska. But does Mr. > > Nagesh understand it and is it sufficient to check, if all inputs are > > numerical? It seems you have a deeper knowlege about the things that Mr. Nagesh > understand. You know him personally ? It is not very polite to > make speculations *what* a other person understand. And no it is not sufficent to check that all parameters are numbers. > Typical paramters described by intervals, where the assumptions of > a model are valid. But for this checks one needs more knowlege > about the meaning of the parameters. And one needs the knowlege about > the differntial equations, to find out the eigenvalues of the jacobian > ... > Additionally I think, it is not userfriendly to see the input merely as a > > set of 200-250 numbers. > > My suggestion is, that JLink is used, a suggestion Mr. Kusk takes into > > consideration, too. That will be fast as lightning ! > But further I suggest, that classes are defined in Java, which represent the > > parts of the system. That is notable nonsense! When the differntial equations should be > solved with Mathematica, the parts can't be Java classes. Mathematica's > NDSolve[] need a explicit expression to integrate the equations. That's not nonsense, the Mathematica program does not fetch the classes but the numbers in the classes (or better in the objects). in the Java classes in textform. They can then be fetched from the Mathematica program and transformed into expressions by the Command ToExpression. The aim is, to have a clear separation of the system into components, which are manageable and understandable. OK you can call a Java class member from Mathematica but this will > be incredible slow when the right hand side is evaluated 200-300 > times and every evaluation make several callbacks to the Java source. > Event handler of the Java main program (without some modification in > the event loop) while it is evaluating an other command. My idea is to fetch the values once from the Java objects at the beginning. 200-250 numbers is not so much.. > Constructors of the classes should build objects with default values. That's a great idea. If a simulation run should be documented, one > always > need the full listing of the Java source to find the actual parameter > settings. That is not my opinion. I think not every user of the simulation system should have to know Java and Mathematica. The user must look for the values in the objects. And the values are in the objects, if they come from the constructor or from the graphical user interface. I think, there should be listings of the objects including names of the variables. In the objects the values are in an meaningful environment. > Graphical user interfaces > > should give the opportunity to change the data fields in the objects and > > check the input for correctness. *and* what has a GUI for 200-250 variables to do with Mathematica ? > BTW one has typical much less variables because many parameters > are fixed and it make no sense to change, for example, material > constants of materials that can't exchanged > The system should give the opportunity, to store the objects on harddisk > > (serialization). > > accessed directly. > > Can you be so kind, to explain *how* your posting help a person that > ask How can I build a simulation system with Mathematica ? You *can* say Don't use Mathematica, use Java! but this has nothing > to do with the question or with my reply. It is you, who proposes to solve the problem with C/C++ and not to use Mathematica (see below!) My point of view is: Use Mathematica, for what Mathemtica is good, and Java, for what Java is good. Mathematica is not so good as Java for data entry and Java is better than Mathematica to represent the simulation system (by objects). But I still would suggest to use C/C++ and a numerical > ode-solver, make a fancy GUI/Script > interface and don't use Mathematica for such a simple task. > The ode-solver is the smallest part of such a simulation system. Jens > > > > > > My name is Nagesh and pursuing research studies in Refrigeration. At > > > > present I am writing a Dynamic Refrigeration System Simulation Package. > > I > > > > am using Mathematica as a programming language for the same since last > > one > > > > year. I don't have any programming experience before this. I have > > following > > > > querries:- > > > > 1. Is any body here have expertise or information about the capability > > of > > > > Mathematica as a system simulation tool? > > > > Since the most system simulation tools are simply solving a system of > > > ordinary differntial equations it is simple to do this with NDSolve[]. > > > > > 2. Is is possible to program a user friendly interface for my system > > > > simulation package with Mathematica or I have to use some other > > software? > > > > Write a MathLink or J/Link frontend that launch the kernel. But you > > > should keep > > > in mind that the user interface is typical 80-90 % of your code. > > > If you just whant to solve some ode's it is probably easyer to > > > include one of the excelent ode-solvers from netlib in your C-code > > > than to call Mathematica to do that. As long as you dont wish to change > > > the ode's very often (than Mathematica is more flexible) you should > > > not use Mathematica. > > > > > 3. My refrigeration system simulation package is likely to have > > > > approximately 60 First order Differential equations. Is is possible to > > > > solve these in Mathematica ? > > > > Sure. > > > > If yes then can anybody here guide me about > > > > this further. > > > > Write down the equations and call NDSolve[]. > > > > > > > I am explaining below in short about the objectives I want to fulfill > > from > > > > coding out of my main input file > > > > > > 1. Example from Main Input File ( this will contain about 200-250 > > variables > > > > which will be entered by the user of this package) > > > > This sounds like a *very* userfiendly interface ;-) > > > > > > > Below is examples of two variables entered into this file, which will be > > > > used in other analysis files for further evaluation. > > > > > > 2. Example from other analysis file ( there will be about 20-25 other > > such > > > > component analysis files ) where the above mentioned variables from main > > > > input file will be used for further evaluations:- > > > > > > Below is one example from this file explaining how the variables from > > main > > > > input file will be used in other files. > > > > > > I hope that this short information will be useful for guiding me to > > solve > > > > the following problems that I am facing. I am facing follwing problems > > or > > > > objectives:- > > > > > > 1. My 1st Objective:- The user of this package must be able to change > > only > > > > the value of the variable in the main input file but he must not be able > > to > > > > change the name of the variable itself. For example he must be able to > > > > change the value of the variable but he must not be able to change > > the > > > > name of this variable itself. > > > > Here our problem is how to achieve or program it so that our objective > > will > > > > be fullfilled. > > > > Options with defaulf values ? or something like > > > > {aParam,bParam}={ODEParameter1,ODEParameter2} /. > > > userRules /. > > > {ODEParameter1->1,ODEParameter2->2} > > > > > > > 2. My 2nd Objective:- How I can program the main input file so that it > > will > > > > be user friendly in terms of its visuals and satisfying the constraint > > > > mentioned above in objective1. > > > > What is *userfiendly* in a file with 250 variables ??? > > > > > > > 3. My 3rd Objective:- How can I program the optional values for each > > > > variable in the main input file ? so that there will be always a value > > > > assigned to each variable listed in main input file whenever the user > > opens > > > > up this file. If user want to change the values of some variables then > > he > > > > can change them and run the simulation otherwise the simulation run will > > be > > > > done with optional values assigned to each variable in the input file. > > > > See above. > > > > > > > 4. My 4th Objective:- How can I program the check for correctness of the > > > > input values supplied by the package user ? > > > > And @@ (NumericQ /@ {aListOfAllYourNumericParameters}) > > > > > > Jens > > ==== hi > AFAIK, Mac OS is now BSD or something like that. That makes it almost > certain that it could support QT. As I pointed out in another post, I can > run the KDE on Windows XP. I haven't been in the trenches with the Qt > impression is, it really is 'code once, run everywhere'. i've checked the trolltech hp. qt fully supports the following OS: MS Windows 95/98/Me, NT4, 2000 and XP. Mac OS X. > This is one of the reasons I am such a Mozilla fan. Konqueror works quite > like. But Mozilla runs everywhere with more or less a uniform look and > feel. Yes, Mozilla is written with Gtk and not with Qt, but that just > shows that WRI has options. i'm not sure if it is allowed to create a closed-source product like the mathematica fronend based on a gpl'ed library like gtk. with qt you have the possibility to buy licenses for the commercial version of qt, allowing you to create closed-source apps. > I'm a KDE fan. I've used the KDE since it was in alpha 0.4. I remember > back when it would compile in a few minutes on a pentium II. Now it takes > several hours on a P4. i started with beta1 (if i remember correctly) - sure it is really big now, but i think kde is still far away from being bloated..... imagine the mathematica frontend being seamlessly integrated into the linux ui's look and feel.... > I've always hated motif. The file chooser simply stinks. And that's just a > start. the whole motif ui stinks....:-) gerald ************************************* Gerald Roth M@th Desktop Development ************************************* ==== > hi, > > moving the frontend over to QT would have some neat side effects: > consistent look & feel with the modern linux gui, themeability, source > antialiased > truetype fonts as QT supports Xrender and Xft (looks great - see KDE3). i > think all of those points are of value, but the most important might be > source compatibility. ONE frontend for MOST (or ALL) platforms - sounds > like a dream :-)) AFAIK, Mac OS is now BSD or something like that. That makes it almost certain that it could support QT. As I pointed out in another post, I can run the KDE on Windows XP. I haven't been in the trenches with the Qt impression is, it really is 'code once, run everywhere'. This is one of the reasons I am such a Mozilla fan. Konqueror works quite like. But Mozilla runs everywhere with more or less a uniform look and feel. Yes, Mozilla is written with Gtk and not with Qt, but that just shows that WRI has options. I'm a KDE fan. I've used the KDE since it was in alpha 0.4. I remember back when it would compile in a few minutes on a pentium II. Now it takes several hours on a P4. But if WRI wanted to go the Gtk route, they could achieve the same ends. I've always hated motif. The file chooser simply stinks. And that's just a start. > > gerald > STH ==== Can I solve this inequality with Mathematica? Log[x,a]+Log[a x,a]>0 I've tried all know, but I get get any good result. CeZaR ==== > > First thanks to all, and in particular Bobby Treat, for your help with > this question. > > The best solution was as follows: > > lst = ReadList[c:data.txt, {Number, Number}] > adjacenceMatrix[ > x:{{_, _}..}] := Module[{actors, events}, > {actors, events} = Union /@ Transpose[x]; > Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , > {Length[actors], Length[events]}]] > > a = adjacenceMatrix[lst]; > b = a . Transpose[a]; > c = b (1 - IdentityMatrix[Length[b]]) > > C is the desired symmetric matrix with off diagonal values of >=0, > indicating the number of times two actors participate in the same event. > The diagonal is set to 0. > > A few items in response to Bobby's message, below. While c is, in fact, > a huge matrix with lots of cells equal to zero, that is exactly how we > need it structured for our analysis and research question (not relevant > to the list, but I'd be happy to discuss off list). Processing time is > actually not too bad!! I'm running a PIII 900 with 512 SDRAM, and the > code ran a 177 x 3669 matrix in under 90 seconds. MatrixForm [c] > presented no problems in viewing in the front end, but then it's only > 177 x 177. > > > Tom > > ********************************************** > Thomas P. Moliterno > Graduate School of Management > University of California, Irvine > tmoliter@uci.edu > ********************************************** > [...] There are several ways to go about this and which is best will vary based on relative number of events vs. number of actors. Below I show three variations. The first is a minor recoding of the one above. The second iterates over all pairs of actors. The third looks at all events for common actors. I then show three examples. The first two methods have the advantage that they do not require that events be positive integers. With some extra work the third method could also get around this restriction. toAdjacency0[data:{{_, _}..}] := Module[ {actors, events, mat1, mat2}, {actors, events} = Union /@ Transpose[data]; mat1 = Array[If[MemberQ[data, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]; mat2 = mat1 . Transpose[mat1]; mat2 * (1-IdentityMatrix[Length[mat2]]) ] toAdjacency1[origdata_] := Module[ {data=Union[origdata], mat}, data = Map[Last, Split[data,#1[[1]]===#2[[1]]&], {2}]; mat = Table [If [j>k, Length[Intersection[data[[j]],data[[k]]]], 0], {j,Length[data]}, {k,Length[data]}]; mat+Transpose[mat] ] toAdjacency2[origdata_] := Module[ {data=Sort[Map[Reverse,Union[origdata]]], mat, len, event}, data = Map[Last, Split[data,#1[[1]]===#2[[1]]&], {2}]; dim = Length[Union[Flatten[data]]]; len = Length[data]; mat = Table[0, {dim}, {dim}]; Do [ event = data[[j]]; Do [ Do [ mat[[event[[m]],event[[k]]]] += 1; mat[[event[[k]],event[[m]]]] += 1, {m,k-1}], {k,Length[event]}], {j,len}]; mat ] data1 = Table[{Random[Integer,{1,1000}], Random[Integer,50]}, {10000}]; data2 = Table[{Random[Integer,{1,1000}], Random[Integer,100]}, {10000}]; data3 = Table[{Random[Integer,{1,1000}], Random[Integer,200]}, {10000}]; Timings are on a 1.5 GHz machine running the Mathematica 4.2 kernel In[107]:= Timing[m0 = toAdjacency0[data1];] Out[107]= {5.44 Second, Null} In[108]:= Timing[m1 = toAdjacency1[data1];] Out[108]= {10.5 Second, Null} In[109]:= Timing[m2 = toAdjacency2[data1];] Out[109]= {16.24 Second, Null} In[110]:= m0 === m1 === m2 Out[110]= True Note that for this example the result is not terrible sparse (less than 20%). In[112]:= Count[Flatten[m0], 0] Out[112]= 191374 In[115]:= Timing[m0 = toAdjacency0[data2];] Out[115]= {11.51 Second, Null} In[116]:= Timing[m1 = toAdjacency1[data2];] Out[116]= {10.92 Second, Null} In[117]:= Timing[m2 = toAdjacency2[data2];] Out[117]= {9.07 Second, Null} Curiously this was the first example I tried, and all three methods perform about the same in this case. The result, not suprisingly, is more sparse (40%) because we have the same number of actors and pairs as previously, but now with more events to spread out over the pairs. In[118]:= Count[Flatten[m0], 0] Out[118]= 403232 When we get sparser still, the third method begins to dominate and the first is relatively slower. In[119]:= Timing[m0 = toAdjacency0[data3];] Out[119]= {22.73 Second, Null} In[120]:= Timing[m1 = toAdjacency1[data3];] Out[120]= {10.88 Second, Null} In[121]:= Timing[m2 = toAdjacency2[data3];] Out[121]= {4.96 Second, Null} Now sparsity is over 60%. In[122]:= Count[Flatten[m0], 0] Out[122]= 624350 The relative speed of this last method, in this instance, is derived from the fact that individual event lists are on average half the size of the previous case. Hence the main loop is expected to improve on average by a factor of 2 (you get a factor of 4 for iterating over all pairs in each event, but lose a factor of 2 because there are twice as many event lists). My guess is that a preprocessor that assesses number of actors vs. number of events would be the best way to choose between the first and third methods (which, inexplicably, are labelled as methods 0 and 2). It is not clear to me whether the middle approach will ever dominate. I have not given much thought to concocting examples where it would because offhand I suspect they would be pathological as in dense and with large intersections. As a last remark I'll note that these might run significantly faster if coded with Compile. Whether that is viable depends on the form of the data. In the above example where everything is a machine integer that approach would certainly work. Daniel Lichtblau Wolfram Research ==== First thanks to all, and in particular Bobby Treat, for your help with this question. The best solution was as follows: lst = ReadList[c:data.txt, {Number, Number}] adjacenceMatrix[ x:{{_, _}..}] := Module[{actors, events}, {actors, events} = Union /@ Transpose[x]; Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]] a = adjacenceMatrix[lst]; b = a . Transpose[a]; c = b (1 - IdentityMatrix[Length[b]]) C is the desired symmetric matrix with off diagonal values of >=0, indicating the number of times two actors participate in the same event. The diagonal is set to 0. A few items in response to Bobby's message, below. While c is, in fact, a huge matrix with lots of cells equal to zero, that is exactly how we need it structured for our analysis and research question (not relevant to the list, but I'd be happy to discuss off list). Processing time is actually not too bad!! I'm running a PIII 900 with 512 SDRAM, and the code ran a 177 x 3669 matrix in under 90 seconds. MatrixForm [c] presented no problems in viewing in the front end, but then it's only 177 x 177. Tom ********************************************** Thomas P. Moliterno Graduate School of Management University of California, Irvine tmoliter@uci.edu ********************************************** -----Original Message----- columns will be numbered from 1 to the number of observed actors or events, and will correspond to actors and events in sorted order. That said, you're asking for a VERY large matrix, and most of its entries will be zero. I'll suggest another way, later. The following indicates AT MOST 13.4% of the entries could be non-zero: lst = ReadList[moliterno-test1996.txt, {Number, Number}]; {actors, events} = Union /@ Transpose[lst]; N[Length[lst]/(Length[actors]*Length[actors])] 0.13350994338800987 However, a random sample shows that less than 1% will be non-zero: Timing[ Count[(MemberQ[lst, {actors[[Random[Integer, Length[actors]]]], events[[Random[Integer, Length[events]]]]}] & ) /@ Range[10000], True]/ 10000.] {7.515999999999998*Second, 0.008} Nevertheless, the following code should build the matrices you want. I'm using a 2.2GHz P4 and 1024MB RDRAM, so if you have a slower machine, be warned. adjacenceMatrix[ x:{{_, _}..}] := Module[{actors, events}, {actors, events} = Union /@ Transpose[x]; Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]] Timing[a = adjacenceMatrix[lst]; ] Dimensions[a] {5.671999999999997*Second, Null} {166, 1778} Timing[b = a . Transpose[a]; ] {0.5309999999999988*Second, Null} You don't want to display a or b in MatrixForm. It will crash your anything at all from the result, and use something like b[[Range[20],Range[4]]]//MatrixForm {{47, 0, 0, 0}, {0, 3, 0, 0}, {0, 0, 7, 1}, {0, 0, 1, 59}, {0, 0, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 0, 0, 1}, {0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}} to get a glimpse at some of it. It's the 'a' matrix that's terribly sparse -- the 'b' matrix isn't unreasonable. Elements of the 'a' matrix can be quickly computed by the function aFunction = If[MemberQ[lst, {actors[[#1]], events[[#2]]}], 1, 0] &; That stores a line of code rather than all those ones and zeroes. The b matrix (call it bb this time) can be computed as: Timing[bb = (#1 . Transpose[#1] & ) [Array[aFunction, {Length[actors], Length[events]}]]; ] bb == b {6.1569999999999965*Second, Null} True Bobby Treat -----Original Message----- posting a this was the most helpful solution message to the list, but first I hoped to ask you a follow up question, if I may (and I'll capture your off-line response here in my final posting to the list). I've run the code (copied from you) below, and get the correct output for made-up data, but when I import in real data, I get an error message. Here's the input I'm running: lst = ReadList[c:test1996.txt, {Number, Number}] AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj] MatrixForm[a = AdjacenceMatrix[lst]] MatrixForm[b = a.Transpose[a]] And here's what I get for output: Set::partw : Part 300007 of <<1> does not exist. Set::partw : Part 300007 of <<1> does not exist. Set::partw : Part 300007 of <<1> does not exist. General::stop : Further output of Set::partw will be suppressed during this calculation. Then I get the two matrices (a & b as per your code), but they are just filled with zeros. So it gets to about the 4th line of your code, but then doesn't fill-in from my data. Finally, I should note that 30007 is one of the actors in the data that I've read in. In case you want to run this yourself, I've attached the raw data file. There are 166 actors and 1778 events: both actors and events are coded with 6-digit numbers, actors begin with 3's, events with 2's. I'm sure this is a silly question, and that there is an easy answer ... But I sure can't find it. So I really appreciate your help and interest!!!! Tom ********************************************** Thomas P. Moliterno Graduate School of Management University of California, Irvine tmoliter@uci.edu ********************************************** -----Original Message----- If you multiply it by its transpose, you get something else that's useful: lst = {{1, A}, {1, B}, {2, B}, {3, C}, {3, D}, {1, D}, {1, C}}; AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj] MatrixForm[a = AdjacenceMatrix[lst]] MatrixForm[b = a.Transpose[a]] Matrix 'b' records how many events two actors have in common. On the diagonal, it shows the total number of events each actor is connected to. It's easy to put zeroes on the diagonal: MatrixForm[c = b (1 - IdentityMatrix[Length[b]])] To get the originally intended incidence matrix, this works: d = c /. {_?Positive -> 1} However, I think matrices 'a' and 'b' are actually more useful, and 'a' easily leads to all the others. Bobby -----Original Message----- AdjacenceMatrix[lst : {{_, _} ..}] := Module[ {actors,events adj}, {events, actors} = Union /@ Transpose[lst]; adj = Table[0, {Length[events]}, {Length[actors]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, actors]]; adj ] you get In[]:=AdjacenceMatrix[lst] Out[]={{1, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}} Jens > > I need to create an adjacency matrix from my data, which is currently in > the form of a .txt file and is basically a two column incidence list. > For example: > > 1 A > 1 B > 2 B > 3 C > . . > . . > . . > m n > > Where 1 to m represent actors and A to n represent events. My goal is to > have an (m x m) matrix where cell i,j equals 1 if two actors are > incident to the same event (in the sample above, 1 and 2 are both > incident to B) and 0 otherwise (w/ zeros on the diagonal). > > I'm new to Mathmatica, and so I'm on the steep part of the learning > curve ... All I've been able to figure out so far is how to get my > incidence list into the program using Import[filename.txt]. But then > what? How do I convert to the adjacency matrix? I've found the > ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't > seem to get it to work ... > > > Tom > > ********************************************** > Thomas P. Moliterno > Graduate School of Management > University of California, Irvine > tmoliter@uci.edu > ********************************************** ==== These are working for me. If anybody wants to try this modified keymapping http://66.92.149.152/proprietary/com/wri/proprietary/com/wri/ch05.html http://public.globalsymmetry.com/proprietary/com/wri/KeyEventTranslations.tr .txt STH ==== > These are working for me. If anybody wants to try this modified > keymapping > > http://66.92.149.152/proprietary/com/wri/proprietary/com/wri/ch05.html > http://public.globalsymmetry.com/proprietary/com/wri/KeyEventTranslations.tr .txt > > STH I found a bug in my hack of the KeyEventTranslations.tr file which didn't manifest itself in 4.1, but did in 4.2. I had a trailing ',' which was causing Mathematica to hang on startup after the chched KeyEventTranslations.m was created (second launch with the buggy file.) I also discovered that the file I was trying to share had been chmod'ed to 400. I am not sure if that is a daemon running, or scp which did it. It's open now, and I'll keep an eye on it. I'm attaching it as well, just in case. I put it here on my box: ~/.Mathematica/SystemFiles/FrontEnd/TextResources STH @@resource KeyEventTranslations (* Modifiers can be Shift, Control, Command, Option For Macintosh: Command = Command Key, Option = Option Key For X11: Command = Mod1, Option = Mod2 For Windows: Command = Alt, Option = Alt NOTE: I Hacked this for my purposes. I find it more natural. There may be problems. It comes with all the warranty that GNU software does. *) EventTranslations[{ (* Evaluation *) Item[KeyEvent[Enter], EvaluateCells], Item[KeyEvent[KeypadEnter], EvaluateCells], Item[KeyEvent[Return, Modifiers -> {Shift}], EvaluateCells], Item[KeyEvent[KP_Enter], EvaluateCells], Item[KeyEvent[KeypadEnter, Modifiers -> {Shift}], EvaluateNextCell], Item[KeyEvent[KP_Enter, Modifiers -> {Shift}], EvaluateNextCell], Item[KeyEvent[Enter, Modifiers -> {Shift}], EvaluateNextCell], Item[KeyEvent[Return, Modifiers -> {Command}], Evaluate[All]], Item[KeyEvent[Return, Modifiers -> {Option}], SimilarCellBelow], Item[KeyEvent[Escape], ShortNameDelimiter], (* Cursor control *) Item[KeyEvent[Up], MovePreviousLine], Item[KeyEvent[Down], MoveNextLine], Item[KeyEvent[Left], MovePrevious], Item[KeyEvent[Right], MoveNext], Item[KeyEvent[Up, Modifiers -> {Option}], MovePreviousLine], Item[KeyEvent[Down, Modifiers -> {Option}], MoveNextLine], Item[KeyEvent[Right, Modifiers -> {Option}], MoveNextWord], Item[KeyEvent[Left, Modifiers -> {Option}], MovePreviousWord], Item[KeyEvent[Right, Modifiers->{Control}], MoveNextWord], Item[KeyEvent[Left, Modifiers->{Control}], MovePreviousWord], Item[KeyEvent[End], MoveLineEnd], Item[KeyEvent[Home], MoveLineBeginning], (* Selection *) Item[KeyEvent[Right, Modifiers -> {Shift}], SelectNext], Item[KeyEvent[Left, Modifiers -> {Shift}], SelectPrevious], Item[KeyEvent[Right, Modifiers -> {Control, Shift}], SelectNextWord], Item[KeyEvent[Left, Modifiers -> {Control, Shift}], SelectPreviousWord], Item[KeyEvent[Down, Modifiers -> {Shift}], SelectNextLine], Item[KeyEvent[Up, Modifiers -> {Shift}], SelectPreviousLine], Item[KeyEvent[Home, Modifiers -> {Shift}], SelectLineBeginning], Item[KeyEvent[End, Modifiers -> {Shift}], SelectLineEnd], Item[KeyEvent[., Modifiers -> {Control}], ExpandSelection], (* Notebook window control *) Item[KeyEvent[PageUp], ScrollPageUp], Item[KeyEvent[PageDown], ScrollPageDown], Item[KeyEvent[Prior], ScrollPageUp], Item[KeyEvent[Next], ScrollPageDown], Item[KeyEvent[Home, Modifiers -> {Control}], ScrollNotebookStart], Item[KeyEvent[End, Modifiers -> {Control}], ScrollNotebookEnd], (* Input *) Item[KeyEvent[Return], Linebreak], Item[KeyEvent[Tab], Tab], Item[KeyEvent[i, Modifiers -> {Control}], Tab], Item[KeyEvent[Backspace], DeletePrevious], Item[KeyEvent[Delete], DeleteNext], Item[KeyEvent[ForwardDelete], DeleteNext], (* Typesetting input *) Item[KeyEvent[6, Modifiers -> {Control}], Superscript], Item[KeyEvent[Keypad6, Modifiers -> {Control}], Superscript], Item[KeyEvent[^, Modifiers -> {Control}], Superscript], Item[KeyEvent[-, Modifiers -> {Control}], Subscript], Item[KeyEvent[_, Modifiers ->{Control}], Subscript], Item[KeyEvent[/, Modifiers -> {Control}], Fraction], Item[KeyEvent[KP_Divide, Modifiers -> {Control}], Fraction], Item[KeyEvent[2, Modifiers -> {Control}], Radical], Item[KeyEvent[Keypad2, Modifiers -> {Control}], Radical], Item[KeyEvent[@, Modifiers -> {Control}], Radical], Item[KeyEvent[7, Modifiers -> {Control}], Above], Item[KeyEvent[&, Modifiers -> {Control}], Above], Item[KeyEvent[Keypad7, Modifiers -> {Control}], Above], Item[KeyEvent[=, Modifiers -> {Control}], Below], Item[KeyEvent[+, Modifiers -> {Control}], Below], Item[KeyEvent[,, Modifiers -> {Control}], NewColumn], Item[KeyEvent[Return, Modifiers -> {Control}], NewRow], Item[KeyEvent[9, Modifiers -> {Control}], CreateInlineCell], Item[KeyEvent[(, Modifiers -> {Control}], CreateInlineCell], Item[KeyEvent[Keypad9, Modifiers -> {Control}], CreateInlineCell], Item[KeyEvent[), Modifiers -> {Control}], MoveNextCell], Item[KeyEvent[0, Modifiers -> {Control}], MoveNextCell], Item[KeyEvent[Keypad0, Modifiers -> {Control}], MoveNextCell], Item[KeyEvent[Left, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeLeft], Item[KeyEvent[Right, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeRight], Item[KeyEvent[Down, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeDown], Item[KeyEvent[Up, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeUp], Item[KeyEvent[8, Modifiers -> {Control}], InsertRawExpression], Item[KeyEvent[*, Modifiers -> {Control}], InsertRawExpression], Item[KeyEvent[Keypad8, Modifiers -> {Control}], InsertRawExpression], Item[KeyEvent[5, Modifiers -> {Control}, CellClass -> BoxFormData], Otherscript], Item[KeyEvent[Keypad5, Modifiers -> {Control}, CellClass -> BoxFormData], Otherscript], Item[KeyEvent[%, Modifiers -> {Control}, CellClass -> BoxFormData], Otherscript], (* Typesetting motion commands *) Item[KeyEvent[ , Modifiers -> {Control}], MoveExpressionEnd], Item[KeyEvent[Tab, Modifiers -> {Shift}, CellClass -> BoxFormData], MovePreviousPlaceHolder], Item[KeyEvent[s, Modifiers -> {Command, Control}, CellClass -> BoxFormData], MovePreviousExpression], Item[KeyEvent[S, Modifiers -> {Control, Command, Shift}, CellClass -> BoxFormData], MoveNextExpression], Item[KeyEvent[S, Modifiers -> {Control, Shift}, CellClass -> BoxFormData], DeleteNextExpression], Item[KeyEvent[s, Modifiers -> {Control}, CellClass -> BoxFormData], DeletePreviousExpression], Item[KeyEvent[k, Modifiers -> {Control}], CompleteSelection[True]], (* Miscellaneous menu commands *) Item[KeyEvent[Delete, Modifiers -> {Control}], Cut], Item[KeyEvent[Insert, Modifiers -> {Control}], Copy], Item[KeyEvent[Insert, Modifiers -> {Shift}], Paste[After]], Item[KeyEvent[z, Modifiers -> {Control}], Undo], Item[KeyEvent[c, Modifiers -> {Control}], Copy], Item[KeyEvent[x, Modifiers -> {Control}], Cut], Item[KeyEvent[v, Modifiers -> {Control}], Paste[After]], Item[KeyEvent[F1], SelectionHelpDialog] (* Unsupported features and examples *) (* Item[KeyEvent[v, Modifiers -> {Control}], SelectionSpeakSummary], *) (* Item[KeyEvent[v, Modifiers -> {Control, Shift}], SelectionSpeak] *) }] ==== >particular, the y-axis label is typically rotated by 90deg so that it >reads up the y-axis. This works fine on macs and windoze, but under >linux the label runs up the y-axis; however, the letters are rotated >so that they are the same orientation as that for the x-axis. >Printouts of the NB are fine, but it looks really stupid when using a >video projector to teach or give a talk. I have mentioned this before, >perhaps, but it is also a real problem with Mathematica. I personally >don't care why the label looks peculiar, just that it does and that >there is no easy workaround. ==== >I'm writing to report what I consider to be a bug. First, I want to >show a simplified example of the problem. Consider the following >expression: > >expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; > >When simplified I expected to get some real number plus >x[0]+3x[1]/4+9x[2]/16, but instead I get the following: > >Simplify[expr] 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] > >As you can see, for some reason Mathematica converted the fractions >3/4 and 9/16 to real machine numbers. I consider this to be a bug. You really are not seeing a loss of precision here. When simplify carries out the indicated multiplication such as 9*.546/16 a machine precision number is returned because on of the arguments only has machine precision. It would be incorrect for Mathematica to return a result with greater precision than the arguements. It would also be incorrect for Mathematica to refuse to preform the required multiplications when simplifying this expression. Or said differently, if you want an exact result from Mathematica *all* of the information you supply Mathematica must also be exact. It is not sensible for Mathematica to do otherwise. ==== There is nothing imprecise about a floating point number. Mathematica's non-standard usage is to treat some numbers as intervals. This non-standard usage comes from the attitude that everything I need to know about numerical computations I learned in Freshman physics lab. Anyway, I'm just pointing this out so that you realize that you are not talking about truth and beauty, but about decisions made in the Mathematica design. For example, 0.25 in IEEE floating point format is representing the EXACT value 1/4. The rational number 1/3 does not have an exact corresponding binary floating point number. That does not prevent one from computing the closest number, which from that point on that (other) number is EXACTLY represented. An analysis of your arithmetic or simplification in which each floating point number aaaa*2^bb is changed to that exact rational number may give you more satisfactory answers that an interval-like computation in which all data is submerged in mush. RJF > > >>It seems to me that you are arguing that if you have an expression >>consisting of one term which is very inprecise and another term which >>is very precise or exact, then the total expression is only as precise >>as the least precise portion of the expression. > Yes. > > >>This is total nonsense. > Not exactly. > > >>Consider adding the following terms: >1.234567890123456`16 + 0.00000000000000001`1 >>consisting of one term with precision 16 and another term with >>precision 1. By your argument, Mathematica should return an answer >>with only a single digit of precision. Of course, Mathematica does no >>such thing. > I had not considered adding two terms with much different magnitude and much different precision. > > Consider a different example i.e., > > 1.234567890123456`16 + 0.1`1 > > Mathematica does not and should not return a result with 16 digits of precision > > ==== Bill, See my comments below. There is no logical reason to insist part of the expression to be exact when another part is inexact. You cannot gain more precision than the least precise portion of the expression. Further, there is extra processing overhead associated with maintaining exact epressions as well as additional storage requirements. For a simple expression such as your example the additional overhead is insignificant. But it increases for every exact term in the expression. It doesn't take all that many terms until the overhead associate with exact computation becomes noticeable. > It seems to me that you are arguing that if you have an expression consisting of one term which is very inprecise and another term which is very precise or exact, then the total expression is only as precise as the least precise portion of the expression. This is total nonsense. Consider adding the following terms: 1.234567890123456`16 + 0.00000000000000001`1 consisting of one term with precision 16 and another term with precision 1. By your argument, Mathematica should return an answer with only a single digit of precision. Of course, Mathematica does no such thing. > >Even more troubling (to me, at least) is the > >following: > >x[0]+3x[1]/4+9x[2]/16+.4//Simplify > >0.4 + x[0] + 0.75 x[1] + 0.5625 x[2] > >I don't want Simplify to change my nice rational numbers to machine > >number approximations. If you want exact answers you *must* have *all* terms in the expresssion exact. Simply put either an expression is exact or not. No expression can be exact unless *all* of the terms within it are exact. When did I ever say that I wanted exact answers? In the example above, I wanted Simplify to do nothing, that is, leave the expression as a sum of an inexact quantity with some exact quantities. In the work where this situation arose, the inexact quantities are typically very small and the exact quantities are large, so that the precision of the overall expression when extended precision numbers are substituted for the x[i] is typically the same as the precision of the numbers being substituted. For example, suppose x[0] and x[2] are zero, and x[1] is 1`25 10^25. Substituting these numbers into the original expression will yield a result with a precision of 25, whereas substituting these numbers into the simplified expression will only have a precision of 16. I've worked very hard to keep the precision of my numbers as high as possible, and I don't want Mathematica to arbitrarily turn those very high precision numbers into much lower precision numbers. Carl Woll Physics Dept U of Washington ==== Bill, Let's step through the expansion here. 9*(0.546+x[2]))/16 can be expanded to 9*0.546/16 + 9*x[2]/16 which becomes .307125 + 9*x[2]/16 My question was why the 9/16 gets converted to .5625, as I see no reason to do so. Even more troubling (to me, at least) is the following: x[0]+3x[1]/4+9x[2]/16+.4//Simplify 0.4 + x[0] + 0.75 x[1] + 0.5625 x[2] I don't want Simplify to change my nice rational numbers to machine number approximations. Carl Woll Physics Dept U of Washington >I'm writing to report what I consider to be a bug. First, I want to > >show a simplified example of the problem. Consider the following > >expression: > >expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; > >When simplified I expected to get some real number plus > >x[0]+3x[1]/4+9x[2]/16, but instead I get the following: > >Simplify[expr] 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] > >As you can see, for some reason Mathematica converted the fractions > >3/4 and 9/16 to real machine numbers. I consider this to be a bug. You really are not seeing a loss of precision here. When simplify carries out the indicated multiplication such as 9*.546/16 a machine precision number is returned because on of the arguments only has machine precision. It would be incorrect for Mathematica to return a result with greater precision than the arguements. It would also be incorrect for Mathematica to refuse to preform the required multiplications when simplifying this expression. Or said differently, if you want an exact result from Mathematica *all* of the information you supply Mathematica must also be exact. It is not sensible for Mathematica to do otherwise. > ==== No, Euler proved that series divergent in 1737. It's the usual theorem used to show that while the primes are sparse, they're not as sparse as the squares (as the sum of THEIR inverses converges). Bobby -----Original Message----- Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== Timing[Sum[1./Prime[n], {n, 1000000}]] {13.860000000000001*Second, 3.0682190480544405} Bobby -----Original Message----- Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== That makes about twenty posts this week detailing nothing but problems the FrontEnd). I had been really considering it. Bobby -----Original Message----- resulted in a set of animation control buttons appearing in the bottom frame of the window. I clicked on one of these buttons, but nothing happened. I looke back in the menu and saw M-y as a keyboard shorcut to run an animation. I tried that with no result. I clicked another button in graphics control set, and my X windows locked up. This included the keyboard's ability to give me another display by using Ctl+Alt+F1. I went to another system and ssh-ed in and found Mathematica had over 50% of my user resources, and was climbing. The same was true for VM. I have a gig of physical RAM. Once I killed Mathematica, my X came back to life. I've had several bad experiences with Mathematica and X. I honestly believe there help isolate and fix these. Have others had such problems? STH ==== > That makes about twenty posts this week detailing nothing but problems > the FrontEnd). > > I had been really considering it. > > Bobby > A few other points on this topic, if I may. I've found solutions to a lot of the problems I was having, and documented them. For example, I have the keyboard working the way I want it. C-x, C-v, C-c, C-z, all do what I expect them to, as does Delete. I used to have X restarts after extended periods of running Mathematica. That I haven't had recently. I may simply have thrashed X when I clicked too many buttons in sequence. I just wanted to report that it happened. The same thing might happen on XP. I've had my problems there as well. Not with Mathematica, but with other programs. I haven't even attempted Mathematica on XP. I'm sure it is a bit smoother to use. I guess I was just a bit upset at the sense that WRI are still stuck in the just completing my download of KDE 3.1 Beta 2. Things have changed. Gotta go install a few rpms and restart X. Bye, STH ==== > That makes about twenty posts this week detailing nothing but problems > the FrontEnd). > > I had been really considering it. > > Bobby Please keep in mind that this was on Mathematica 4.1, I'll have 4.2 tomorrow, and we'll see how that goes. This isn't really the result I had hoped for by I very much wish WRI would give us a dual boot license. That way, we can use Mathematica in either environment the current situation dictates as the best. with Windows. I just don't do that as a matter of course. I've been related issuse, either because they aren't sure if the problem is their that second reason one bit. Hey, if it locks up my X, I want to know if that happens to others, and I want to identify the source of the problem. What I really would like to gain from all my negative statements is solutions to what I perceive as problems. If not that, then perhaps the perspective which makes me understand that what I see as problems are really just my unfamiliarity with the product. I also want to get others platform. That's how open source works. All that being said, if you are in a situation where an X lockup would really do harm to your project, I would say that I cannot claim it won't happen to you. OTOH, I am able to break just about any system. I can't swear to you that Mathematica won't lock up your Windows system. I can say you will not have as easy a time shelling into it and trying to recover your system without rebooting. STH Reply-To: jmt@dxdydz.net ==== Sorry, I thought I had seen a demonstration, some years ago ! > This sum converges, see a math text book ! > > > > Dear Colleagues, > > > > I calculated: > > > > Sum[1/Prime[n], {n, 15000}] // N > > > > Result: 2.74716 > > > > Now I wonder if this sum will converge or keep on growing, albeit very > > slowly. > > > > > > Matthias Bode > > Sal. Oppenheim jr. & Cie. KGaA > > Koenigsberger Strasse 29 > > D-60487 Frankfurt am Main > > GERMANY > > Mobile: +49(0)172 6 74 95 77 > > Internet: http://www.oppenheim.de > > > > > > > > Reply-To: murray@math.umass.edu ==== It is well known that the infinite series of reciprocals of the primes DIVERGES! See, for example: http://www.utm.edu/research/primes/infinity.shtml > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > > > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de > > > > -- 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 Amherst, MA 01375 Reply-To: jmt@dxdydz.net ==== This sum converges, see a math text book ! > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > > > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de > > > ==== The fact that Sum[1/Prime[n], {n, 1,Infinity}]==Infinity is a rather famous theorem of Euler. It implies that there must be infinitely many primes (otherwise the sum would be finite), and was the beginning of a vast area of mathematics, which includes such concepts as Dirichlet series, Riemann's zeta function etc. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Wednesday, October 2, 2002, at 04:31 PM, Matthias.Bode@oppenheim.de > Dear Colleagues, I calculated: Sum[1/Prime[n], {n, 15000}] // N Result: 2.74716 Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de ==== Here's a start. If you want the thing to be greater than zero, set it equal to z (which we'll assume is greater than zero) and solve for Log[x]: Log[x, a] + Log[a*x, a] == z /. Log[a_*b_] -> Log[a] + Log[b] {f, g} = Log[x] /. Simplify[Solve[%, Log[x]]] Log[a]/Log[x] + Log[a]/(Log[a] + Log[x]) == z {-(((-2 + z + Sqrt[4 + z^2])*Log[a])/(2*z)), ((2 - z + Sqrt[4 + z^2])* Log[a])/(2*z)} Neither solution appears to be extraneous. Now the task is to find the range of these functions over positive z. Take a look at their derivatives: D[f, z] // Simplify D[g, z] // Simplify ((-1 + 2/Sqrt[4 + z^2])* Log[a])/z^2 ((-1 - 2/Sqrt[4 + z^2])*Log[a])/z^2 A little study shows that f' and g' have their signs opposite to Log[a]. Both functions are monotone. The following limits: Outer[Limit[#1, z -> #2] &, {f, g}, {0, Infinity}] Exp@% {{-(Log[a]/2), -Log[a]}, {Infinity*Log[a], 0}} {{1/Sqrt[a], 1/a}, {Indeterminate, 1}} show that f varies from -Log[a]/2 to -Log[a] and g varies from 0 to Infinity if Log[a]>0 and 0 to -Infinity if Log[a]<0. Exponentiation gives ranges for x: -1/Sqrt[a] to 1/a for f, for instance. But what does all this mean? When a>1, either x>1 or 1/a < x < 1/Sqrt[a]. When a<1, either 0, Moderator Reply-To: ==== Try this: To the original function, add a function that's (a) zero when the imaginary part is larger than some epsilon value you choose, (b) fairly large when the imaginary part is 0 or negative, and (c) as smooth as possible. For instance, something like: f=Max[(1 - x/epsilon)^5, 0] This function has four continuous derivatives in the real components -- though not in the complex variable! If it doesn't penalize the real root enough, multiply f by a constant bigger than 1 and try again. Bobby Treat -----Original Message----- are interested, the zeros are the roots of the dispersion relation for a plasma interacting with a laser). Sometimes FindRoot picks up one of these instead of the one I want. So, I'd like to tell mathematica to look for a root only in a certain rectangular region of the complex plane. Well, if I could tell it, 'look for roots with imag. part > something', I'd be happy too. I tried specifying complex values for the start and stop points of an interval, hoping mathematica would interpret these as the corners of a rectangle. No such luck. Any help would be greatly appreciated. I'd also like to point out that this and other issues about complex roots are not clearly addressed in the built-in help files. ==== > > This sum converges, see a math text book ! That's nonsense http://mathworld.wolfram.com/PrimeSums.html Jens > > > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > > slowly. > > Matthias Bode > > Sal. Oppenheim jr. & Cie. KGaA > > Koenigsberger Strasse 29 > > D-60487 Frankfurt am Main > > GERMANY > > Mobile: +49(0)172 6 74 95 77 > > Internet: http://www.oppenheim.de > > ==== You need to see: http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eisA.cgi?An um=A016088 >This sum converges, see a math text book ! >That's nonsense > >http://mathworld.wolfram.com/PrimeSums.html Jens >Dear Colleagues, >I calculated: >Sum[1/Prime[n], {n, 15000}] // N >Result: 2.74716 >Now I wonder if this sum will converge or keep on growing, albeit very >>slowly. >>Matthias Bode >>Sal. Oppenheim jr. & Cie. KGaA >>Koenigsberger Strasse 29 >>D-60487 Frankfurt am Main >>GERMANY >>Mobile: +49(0)172 6 74 95 77 >>Internet: http://www.oppenheim.de > ==== I have updated my package Biokmod. It can be downloaded from: http://web.usal.es/~guillerm/biokmod.htm I developped this package thinking in biokinetic application and internal dosimetry, but it can be also applied for other kind of problems envolving System of ODE with many variables. I will appreciate any coments Guillermo Sanchez http://web.usal.es/~guillerm ==== I use BinaryImport to read a file as follows: BinaryImport[file,{Byte..}] then I use Partition to rebuild the data of dimensions 252 x 253 x 255.... This works but it takes about half an hour to read the file....it's a 16 MByte file.....any way to improve this? thanks....jerry blimbaum Reply-To: kuska@informatik.uni-leipzig.de ==== BinaryImport[] is complet unusable for this task. I tryed the same with similar data sets and run out of kernel memory (with 1.5 GByte RAM) & 3GB swap). The WRI support respondet, that BinaryImport[] is not for reading *large* binary data. You can have the beta version of MathGL3d 3.1 that has an extra C-Function for that task. Since it also include excelent volume rendering functions and a native format for reading and writing compressed volume data files you should use MathGL3d 3.1b. Contact me direct if you wish to beta test the new version. Jens > > I use BinaryImport to read a file as follows: > > BinaryImport[file,{Byte..}] > > then I use Partition to rebuild the data of dimensions 252 x 253 x 255.... > > This works but it takes about half an hour to read the file....it's a 16 > MByte file.....any way to improve this? > > thanks....jerry blimbaum ==== Does any one know of a way to produce Phase Plane Diagrams in mathematica? I need to draw a couple of direction field and analyse the stability of critical points for my systems of equations . Ajadi __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page http://uk.my.yahoo.com Reply-To: kuska@informatik.uni-leipzig.de ==== if you don't like PlotField[] you should try to get a copy of the book Visual DSolve http://store.wolfram.com/view/book/D0706.str and the book package. Jens > > > Does any one know of a way to produce Phase Plane > Diagrams in mathematica? > I need to draw a couple of direction field and > analyse the stability of critical points for my > systems of equations . > > > Ajadi > > __________________________________________________ > Do You Yahoo!? > Everything you'll ever need on one web page > http://uk.my.yahoo.com ==== Please ignore a similar question I just posted about BinaryImport...I forgot an hour to import 16 MByte file, whereas this technique took less then 5 seconds...special thanks to Mariusz... jerry blimbaum NSWC panama city, fl -----Original Message----- Mariusz Jankowski University of Southern Maine mjkcc@usm.maine.edu 207-780-5580 > The question: > What is the fastest way to read binary files in Mathematica 4.0 ? > I think the fastest is with ReadList (indeed ReadSounFile that use it, seems > to be better than BinaryImport), but when i use this command... > data = ReadList[filePath, Byte] > ....it doesn't read whole file; can somebody tell me the reason? Raf. P.S.: > I made some simple tests (@ 16 bit): << Experimental` > data = BinaryImport[fileRawPath, Table[Integer16, {4000}], > ByteOrdering -> -1]; => 10 seconds data = ReadListBinary[fileRawPath, SignedInt16, ByteOrder - LeastSignificantByteFirst]; = > 26 seconds << Miscellaneous`Audio` > data = ReadSoundfile[fileWavPath] => 1.54 seconds ==== I came across this, and thought I would share. This may be OBE if the font selection is better in 4.2. I'll that installed by this time tomorrow...I hope. http://cgm.cs.mcgill.ca/~luc/math.html I started reading through this list, and had visions of recursively downloading the entire internet looking for the font's I really need. Anybody know what fonts I should have installed on my SuSE box to satisfy Mathematica's default expectations? STH ==== In: DSolve[y*D[u[x, y],x] == x*D[u[x, y],y], u[x,y], {x, y}] Out: {{u[x, y] -> C[1][(1/2)*(x^2 + y^2)]}} Square brackets are used as grouping symbols in the result!?? :^O Somebody say it isn't so. --- Selwyn Hollis ==== It isn't so. C[1] is an arbitrary (smooth) function. After all, what you have got is a partial differential equation. For example, you can take C[1] to be Sin: In[1]:= v[x_, y_] = u[x, y] /. DSolve[y*D[u[x, y], x] == x*D[u[x, y], y], u[x, y], {x, y}] /. C[1] -> Sin Out[1]= {Sin[(1/2)*(x^2 + y^2)]} In[2]:= y*D[v[x, y], x] == x*D[v[x, y], y] Out[2]= True Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ In: DSolve[y*D[u[x, y],x] == x*D[u[x, y],y], u[x,y], {x, y}] Out: {{u[x, y] -> C[1][(1/2)*(x^2 + y^2)]}} Square brackets are used as grouping symbols in the result!?? :^O Somebody say it isn't so. --- > Selwyn Hollis Reply-To: ==== My OPINION is that extra graphics RAM is useful primarily for 3D games (which are themselves completely useless). A static 3D plot doesn't need that much graphics RAM -- it's the rapid transformation of it, to simulate live action, that may require it. On the other hand, if the manufacturer's limits are that low for graphics RAM, I would get another manufacturer. Who knows what other limitations and compromises they'll saddle you with? I would be very suspicious. Bobby -----Original Message----- Is 32 MB adequate not just now, but likely to be adequate as well for the near future (say, a 3- to 5-year equipment lifetime)? -- 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 Amherst, MA 01375 Reply-To: kuska@informatik.uni-leipzig.de ==== > > My OPINION is that extra graphics RAM is useful primarily for 3D games Or complex 3d scientific visualizations ? Textures ? Try to render the skull from a 256^3 CT scan or the output of a 3d plasma simulation and you will know *what* can be done with extra 3d RAM > (which are themselves completely useless). The major effect is, that 3d Games make 3d graphics hardware less expensive. Five years ago a SGI cost 20-30 000 $ and today you can have more 3d power for 400 $ Jens > A static 3D plot doesn't > need that much graphics RAM -- it's the rapid transformation of it, to > simulate live action, that may require it. > > On the other hand, if the manufacturer's limits are that low for > graphics RAM, I would get another manufacturer. Who knows what other > limitations and compromises they'll saddle you with? I would be very > suspicious. > > Bobby > > -----Original Message----- > > We are about to order new PCs for a university student lab in which > Mathematica will be installed. Of course they will be using 2D and 3D > graphics -- plots of surfaces, e.g. Sooner or later students will want > to rotate such plots, too. > > An unresolved issue is how much graphics RAM to get. On existing > machines we typically have 64MB. But for the PCs we are looking at, > manufacturer's limits on graphics RAM, rather than cost, seems to limit > us to 32 MB. > > Is 32 MB adequate not just now, but likely to be adequate as well for > the near future (say, a 3- to 5-year equipment lifetime)? > > -- > 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 > Amherst, MA 01375 ==== Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and also a new user of Mathematica; so please forgive this rather simple question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth Harker School http://www.harker.org/ ==== Steve The notebook given after NOTEBOOK below contains functions for factoring and partial fractioning. Here is an application to your problem: the first stage avoids our needing to know anything about the answer. fc=FactorR[x^4+x^3+x^2+x+1,x] (1 - (1/2)*(-1 - Sqrt[5])*x + x^2)* (1 - (1/2)*(-1 + Sqrt[5])*x + x^2) Now we need to get rid of Sqrt[5] in terms of GoldenRatio. This is rather messy: Simplify/@(fc/. Sqrt[5][Rule]2 GoldenRatio-1) (1 + x - GoldenRatio*x + x^2)*(1 + GoldenRatio*x + x^2) Simplify/@(%/.-GoldenRatio[Rule] 1/GoldenRatio -1) (1 + x/GoldenRatio + x^2)*(1 + GoldenRatio*x + x^2) Another example PartialFractionsR[(1 + x)x/(1 - 3*x + x^2), x] 1 - (2*(-1 + 4*x))/((3 + Sqrt[5] - 2*x)*(-3 + 2*x)) + (2*(-1 + 4*x))/((-3 + 2*x)*(-3 + Sqrt[5] + 2*x)) Simplify[%] (x*(1 + x))/(1 - 3*x + x^2) NOTEBOOK: to make a notebook from the following, copy from the next line to the line preceding XXX and paste into a new Mathematica notebook. Notebook[{ Cell[CellGroupData[{ Cell[Factors and PartialFractions, Subtitle], Cell[Allan Hayes, 16 August 2001, Text], Cell[< Here are some functions for factoring and expressing in partial fractions over the reals and over the complex numbers. >, Text], Cell[BoxData[ (Quit)], Input], Cell[BoxData[{ (Off[General::spell1, General::spell]), n, ((FactorC::usage = ;)n), n, ((FactorR::usage = ;)n), n, ((PartialFractionsC::usage = ;)n), n, ((PartialFractionsR::usage = ;)), n, (On[General::spell1, General::spell])}], Input, InitializationCell->True], Cell[TextData[{ FactorC[p_, x_] := , StyleBox[(*over complex numbers*), FontFamily->Arial, FontWeight->Plain], nTimes @@ Cases[Roots[p == 0, x, n Cubics -> False], u_ == v_ -> x - v]n nFactorR[p_, x_] := , StyleBox[(*over reals, coefficients must be real*), FontFamily->Arial, FontWeight->Plain], n (Times @@ Join[Cases[#1, u_ == v_ /; Im[v] == 0 :> n x - v], Cases[#1, u_ == v_ /; Im[v] > 0 :> n x^2 - x*2*Re[v] + Abs[v]^2]] & )[n Roots[p == 0, x, Cubics -> False]] }], Input, InitializationCell->True], Cell[TextData[{ PartialFractionsC[p_, x_] := , StyleBox[(*over complex numbers*), FontFamily->Arial, FontWeight->Plain], n(#+Apart[#2/FactorC[#3,x]])&@@Flatten[{PolynomialReduce[#,#2], #2}]&[Numerator[#],Denominator[#]]&[Together[p]]n n PartialFractionsR[p_, x_] := , StyleBox[(*over reals, coefficients must be real*), FontFamily->Arial, FontWeight->Plain], n(#+Apart[#2/FactorR[#3,x]])&@@Flatten[{PolynomialReduce[#,#2], #2}]&[Numerator[#],Denominator[#]]&[Together[p]] }], Input, InitializationCell->True], Cell[CellGroupData[{ Cell[PROGRAMMING NOTES, Subsubsection], Cell[TextData[{ The option , StyleBox[Cubics->False, FontFamily->Courier], is used to keep the roots of cubics in , StyleBox[Root[....], FontFamily->Courier], form. This is better for computation.n, StyleBox[Re[v], FontFamily->Courier], and , StyleBox[Abs[v]^2, FontFamily->Courier], are used rather than , StyleBox[v+Conjugate[v] , FontFamily->Courier], and , StyleBox[v*Conjugate[v], FontFamily->Courier], to prevent , StyleBox[Apart, FontFamily->Courier], from factorising , StyleBox[x^2 - x*2*Re[v] + Abs[v]^2], FontFamily->Courier], back to complex form. }], Text] }, Closed]], Cell[CellGroupData[{ Cell[EXAMPLES, Subsubsection], Cell[pol = Expand[(x - 1)*(x + 1)^2*(x^2 + x + 1)^2*(x^2 + 4)]; , Input], Cell[CellGroupData[{ Cell[f1 = FactorC[pol, x], Input], Cell[BoxData[ ((((-1) + x)) (((-2) [ImaginaryI] + x)) ((2 [ImaginaryI] + x)) ((1 + x))^2 (((((-1)))^(1/3) + x))^2 (((-(((-1)))^(2/3)) + x))^2)], Output] }, Open ]], Cell[CellGroupData[{ Cell[f2 = FactorR[pol, x], Input], Cell[BoxData[ ((((-1) + x)) ((1 + x))^2 ((4 + x^2)) ((1 + x + x^2))^2)], Output] }, Open ]], Cell[CellGroupData[{ Cell[f3 = FactorR[x^3 + x + 1, x], Input], Cell[BoxData[ (((x - Root[1 + #1 + #1^3 &, 1])) ((x^2 - 2 x Root[(-1) + 2 #1 + 8 #1^3 &, 1] + Root[(-1) - #1^4 + #1^6 &, 2]^2)))], Output] }, Open ]], Cell[< Root objects appear because of the option Cubics->False in Roots. We can sometimes get radical forms, but notice the complication. >, Text], Cell[CellGroupData[{ Cell[ToRadicals[f3], Input], Cell[BoxData[ (((((2/(3 (((-9) + @93)))))^(1/3) - ((1/2 (((-9) + @93))))^(1/3)/3^(2/3) + x)) ((1/3 + 1/3 ((29/2 - (3 @93)/2))^(1/3) + 1/3 ((1/2 ((29 + 3 @93))))^(1/3) - 2 ((((1/2 ((9 + @93))))^(1/3)/(2 3^(2/3)) - 1/(2^(2/3) ((3 ((9 + @93))))^(1/3)))) x + x^2)))], Output] }, Open ]], Cell[Inexact forms can be found, from f3 :, Text], Cell[CellGroupData[{ Cell[N[f3], Input], Cell[BoxData[ (((((0.6823278038280193`)([InvisibleSpace])) + x)) ((((1.4655712318767682`)([InvisibleSpace])) - 0.6823278038280193` x + x^2)))], Output] }, Open ]], Cell[or directly, Text], Cell[CellGroupData[{ Cell[f3 = FactorR[x^3 + x + 1//N, x], Input], Cell[BoxData[ (((((0.6823278038280193`)([InvisibleSpace])) + x)) ((((1.4655712318767682`)([InvisibleSpace])) - 0.6823278038280193` x + x^2)))], Output] }, Open ]], Cell[Partial fractions, Text], Cell[CellGroupData[{ Cell[pf1 = PartialFractionsR[(2 + x)/pol, x], Input], Cell[BoxData[ (1/(60 (((-1) + x))) - 1/(10 ((1 + x))^2) - 39/(100 ((1 + x))) + ((-54) - 31 x)/(4225 ((4 + x^2))) + ((-1) + 3 x)/(13 ((1 + x + x^2))^2) + (44 + 193 x)/(507 ((1 + x + x^2))))], Output] }, Open ]], Cell[CellGroupData[{ Cell[pf2 = PartialFractionsR[(1 + x)x/(1 - 3*x + x^2), x], Input], Cell[< 1 - (2*(-1 + 4*x))/((3 + Sqrt[5] - 2*x)*(-3 + 2*x)) + (2*(-1 + 4*x))/((-3 + 2*x)*(-3 + Sqrt[5] + 2*x)) >, Output] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ (Simplify[%])], Input], Cell[(x*(1 + x))/(1 - 3*x + x^2), Output] }, Open ]], Cell[Partial fractions will often involve Root objects , Text], Cell[CellGroupData[{ Cell[pf3 = PartialFractionsR[(1 + x)/(x^3 - x + 1), x], Input], Cell[BoxData[ (((1 + Root[1 - #1 + #1^3 &, 1]))/((((x - Root[1 - #1 + #1^3 &, 1])) ((Root[1 - #1 + #1^3 &, 1]^2 - 2 Root[1 - #1 + #1^3 &, 1] Root[(-1) - 2 #1 + 8 #1^3 &, 1] + Root[(-1) + #1^4 + #1^6 &, 2]^2)))) + ((x + Root[1 - #1 + #1^3 &, 1] + x Root[1 - #1 + #1^3 &, 1] - 2 Root[(-1) - 2 #1 + 8 #1^3 &, 1] - Root[(-1) + #1^4 + #1^6 &, 2]^2))/(((((-x^2) + 2 x Root[(-1) - 2 #1 + 8 #1^3 &, 1] - Root[(-1) + #1^4 + #1^6 &, 2]^2)) ((Root[1 - #1 + #1^3 &, 1]^2 - 2 Root[1 - #1 + #1^3 &, 1] Root[(-1) - 2 #1 + 8 #1^3 &, 1] + Root[(-1) + #1^4 + #1^6 &, 2]^2)))))], Output] }, Open ]], Cell[This can in fact be put in radical form:, Text], Cell[CellGroupData[{ Cell[ToRadicals[pf3], Input], Cell[BoxData[ (((1 - ((2/(3 ((9 - @69)))))^(1/3) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3)))/(((((-(1/3)) + 1/3 ((25/2 - (3 @69)/2))^(1/3) + 1/3 ((1/2 ((25 + 3 @69))))^(1/3) + (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3)))^2 - 2 (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3))) ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))))) ((((2/(3 ((9 - @69)))))^(1/3) + ((1 /2 ((9 - @69))))^(1/3)/3^(2/3) + x)))) + ((1/3 - 1/3 ((25/2 - (3 @69)/2))^(1/3) - ((2/(3 ((9 - @69)))))^(1/3) - ((1/2 ((9 - @69))))^(1/3)/3 ^(2/3) - 1/3 ((1/2 ((25 + 3 @69))))^(1/3) - 2 ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))) + x + (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3))) x))/(((((-(1 /3)) + 1/3 ((25/2 - (3 @69)/2))^(1/3) + 1/3 ((1/2 ((25 + 3 @69))))^(1/3) + (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3)))^2 - 2 (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3))) ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))))) ((1/3 - 1/3 ((25/2 - (3 @69)/2))^(1/3) - 1/3 ((1/2 ((25 + 3 @69))))^(1/3) + 2 ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))) x - x^2)))))], Output] }, Closed]], Cell[We could have found the inexact form directly., Text], Cell[CellGroupData[{ Cell[BoxData[ (PartialFractionsR[((1 + x))/((x^3 - x + 1)) // N, x])], Input], Cell[BoxData[ ((-(0.07614206365252976`/(((1.324717957244746`)( [InvisibleSpace])) + 1.` x))) + (((0.7982664819556426`)( [InvisibleSpace])) + 0.07614206365252976` x)/(((0.754877666246693`)([InvisibleSpace])) - 1.324717957244746` x + 1.` x^2))], Output] }, Open ]] }, Closed]] }, Open ]] }, ScreenRectangle->{{0, 1024}, {0, 709}}, AutoGeneratedPackage->None, WindowSize->{534, 628}, WindowMargins->{{199, Automatic}, {0, Automatic}}, ShowCellLabel->False, StyleDefinitions -> Default.nb ] XXX -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and also a > new user of Mathematica; so please forgive this rather simple question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ > Reply-To: kuska@informatik.uni-leipzig.de ==== In[]:=Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio, 1/GoldenRatio}] Out[]=-((-3 - 2*x + Sqrt[5]*x + GoldenRatio*x - 3*x^2)* (3 + x + Sqrt[5]*x + GoldenRatio*x + 3*x^2))/9 Jens > > Greetings MathGroup, > > My name is Steve Earth, and I am a new subscriber to this list and also a > new user of Mathematica; so please forgive this rather simple question... > > I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica > and have it be able to tell me that it factors into > > (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) > > What instructions do I need to execute to achieve this output? > > -Steve Earth > Harker School > http://www.harker.org/ ==== > > The last part of my message you are quoting was completely wrong, as > > was pointed out by Allan Hayes. Mathematica does not track precision of > > machine arithmetic computations. In order for Mathematica to give > > reliable information about the precision of a computation you have to > > explicitly set the precision of all the numerical quantities. > > Your own example at the bottom simply shows you have not understood the > > evaluation mechanism of Mathematica. Just opposite, thanks to you and other participants, I completely > understood it. SetAccuracy just takes anything and calls it accurate. > This behavior is useless if not stupid. I am not sure I understand what you are referring to as useless if not stupid. The main purpose of SetAccuracy is to allow people who have done their own error analysis to specify the numerical error in an input or in a result. It is often possible through careful numerical analysis, for example, to come up with a better error estimate than can be given by generic rules for propogation of error. Another common use of SetAccuracy is for converting machine numbers or exact numbers into variable-precision numbers in situations when it is desired that a calculation be done using variable-precision arithmetic. Is there some aspect of this that you think is useless if not stupid, or was that remark referring to something else? Dave Withoff Wolfram Research ==== > The more I play with the example the more depressing it gets. Start > with floating point numbers but explicitely arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine?precision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers Mathematica should display > only those digits that are correct, that is none. An accuracy of -6 means that the least significant correct digit is 6 digits to the left of the decimal point. The result Out[3] in the example above has 26 significant digits to the left of that (the most sigificant digit is 26+6=32 digits to the left of the decimal point), so there are 26 correct digits to display. Was there some other result you were referring to as a result in which the number of correct digits is none? Dave Withoff Wolfram Research ==== > I came across this, and thought I would share. This may be OBE if the font > selection is better in 4.2. I'll that installed by this time tomorrow...I > hope. > > http://cgm.cs.mcgill.ca/~luc/math.html > > I started reading through this list, and had visions of recursively > downloading the entire internet looking for the font's I really need. > Anybody know what fonts I should have installed on my SuSE box to satisfy > Mathematica's default expectations? The contents of the page at this URL are interesting, but probably not relevant for your purposes. The only fonts which are absolutely needed by the front end are the fonts that supply the special glyphs for mathematical notation, grouping characters, Greek letters, etc. These fonts were developed by Wolfram Research and are installed as part of the Mathematica installation. There are two generations of these fonts. The first generation was introduced in Mathematica 3.0 in the fall of 1996 and were used through the release of Mathematica 4.1. There were five families known as Math1 - Math5. Each familiy had four variants: a proportionaly-spaced medium face, a monospaced medium, a proportional bold, and a monospaced bold. The second generation is used by Mathematica 4.2. There are seven families named Mathematica1 - Mathematica7. Aside from the math fonts, the front end should be able to function properly provided that you have a font that supports the encoding for your chosen locale. The style sheets bundled with the front end use only Times, Helvetica, and Courier. Should these fonts not be available on your system, the front end has some substitution rules. For example, the Windows front end knows to use the fonts Times New Roman, Arial, and Courier New. The X Window System ships with bitmap versions of Times, Helvetica, and Courier as well as an outline of Courier. If one of these fonts must be drawn at a size for which there are no bitmaps, outline fonts provided with Mathematica are used. Helvetica is aliased to Swiss721, and Times is aliased to Utopia through a fonts.alias file in the Mathematica fonts directory. Under MacOS and Windows, you should be albe to use whatever fonts are available on your system. Under X, things are a little more complicated. The front end can display whatever fonts are made available to your X server, but it can generate PostScript only for those fonts where an Adobe Font Metric (AFM) file is available. If you wish to display or print the PostScript, you must also make the Type 1 font file available to the rendering device. Note also that the X front end has an adjustable setting for the amount of memory to reserve for storing font data. If your system has a large number of fonts, you may need to increase this setting per this FAQ page: http://support.wolfram.com/mathematica/systems/linux/interface/fonterrors.ht ml -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== > > I came across this, and thought I would share. This may be OBE if the > font > selection is better in 4.2. I'll that installed by this time > tomorrow...I hope. > > http://cgm.cs.mcgill.ca/~luc/math.html > > I started reading through this list, and had visions of recursively > downloading the entire internet looking for the font's I really need. > Anybody know what fonts I should have installed on my SuSE box to satisfy > Mathematica's default expectations? > > The contents of the page at this URL are interesting, but probably not > relevant for your purposes. That's kind'o' what I thought. [snip - history lesson - thanks] > The second generation is used by Mathematica 4.2. There are seven > families named Mathematica1 - Mathematica7. Where is the documentation for installing these? This is dated: http://support.wolfram.com/mathematica/systems/linux/interface/fonterrors.ht ml I grabbed these off the net: http://support.wolfram.com/mathematica/systems/linux/general/latestfonts.htm l http://support.wolfram.com/mathematica/systems/linux/general/MathBDF_42.tar. gz http://support.wolfram.com/mathematica/systems/linux/general/MathPCF_42.tar. gz http://support.wolfram.com/mathematica/systems/linux/general/MathT1_42.tar.g z > su - ****** # cd /usr/X11/lib/X11/fonts/ # mkdir -p local/mma # cd local/mma # tar xvfz /download/com/wri/MathBDF_42.tar.gz # tar xvfz /download/com/wri/MathPCF_42.tar.gz # tar xvfz /download/com/wri/MathT1_42.tar.gz # xemacs /etc/X11/XF86Config .... # grep FontPath /etc/X11/XF86Config FontPath /usr/X11R6/lib/X11/fonts/100dpi:unscaled FontPath /usr/X11R6/lib/X11/fonts/75dpi:unscaled FontPath /usr/X11R6/lib/X11/fonts/CID FontPath /usr/X11R6/lib/X11/fonts/Speedo FontPath /usr/X11R6/lib/X11/fonts/Type1 FontPath /usr/X11R6/lib/X11/fonts/URW FontPath /usr/X11R6/lib/X11/fonts/kwintv:unscaled FontPath /usr/X11R6/lib/X11/fonts/latin2/Type1 FontPath /usr/X11R6/lib/X11/fonts/misc:unscaled FontPath /usr/X11R6/lib/X11/fonts/misc/sgi:unscaled FontPath /usr/X11R6/lib/X11/fonts/truetype FontPath /usr/X11R6/lib/X11/fonts/uni:unscaled FontPath /usr/X11R6/lib/X11/fonts/local/mma/BDF FontPath /usr/X11R6/lib/X11/fonts/local/mma/PCF FontPath /usr/X11R6/lib/X11/fonts/local/mma/T1 # SuSEconfig .... # init 3 [assuming you are already at a TTY console] # init 5 > Aside from the math fonts, the front end should be able to function > properly provided that you have a font that supports the encoding for your > chosen locale. The style sheets bundled with the front end use only > Times, Helvetica, and Courier. Should these fonts not be available on > your system, the front end has some substitution rules. > > For example, the Windows front end knows to use the fonts Times New Roman, > Arial, and Courier New. The X Window System ships with bitmap versions of > Times, Helvetica, and Courier as well as an outline of Courier. If one of > these fonts must be drawn at a size for which there are no bitmaps, > outline fonts provided with Mathematica are used. Helvetica is aliased to > Swiss721, and Times is aliased to Utopia through a fonts.alias file in the > Mathematica fonts directory. This is what I find anoying. Every time Mathematica does one of these substitutions, it beeps. This is what I'm calling a font fault. It's like the boy who cried wolf. I start ignoring beeps. It also bothers me that I am not seeing what the author had intended. I *believe* it is the author of the notebook or help document who determines what fonts should be used. This is a point of confusion. When I opened a help page, and didn't like the size of the fonts, I tried to adjust them without the desired result. I now believe the proper remedy is to use magnification, not a font adjustment. I have far fewer chirps (beeps) in 4.2, but I do get them when changing the magnification. > Under MacOS and Windows, you should be albe to use whatever fonts are > available on your system. Under X, things are a little more complicated. > The front end can display whatever fonts are made available to your X > server, but it can generate PostScript only for those fonts where an Adobe > Font Metric (AFM) file is available. If you wish to display or print the > PostScript, you must also make the Type 1 font file available to the > rendering device. This is for another day. I believe I have done this in years gone by, but, for now, I just want to get the optimal behavior form the crt. [snip] Here's my question in a nutshell. When I do xlsfonts, what should be listed in order to run Mathematica 4.2 and not experiece font faults generated by content provided on the CD? Please note that I *just* finished installing the fonts off the web, so I'm not sure what, if any problems still remain. I suspect the helvetica faults will still occur. STH . ==== I'm a newbie and, of course, the first thing I want to do is apparently one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I want the equation to be written out with terms grouped by powers of x, but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at least point me to some tutorial in the Mathematica documentation. I've been looking over the documentation and I found Appendix A.5 in The Mathematica Book, but that doesn't help me. I _need_ some examples. I did find a couple of well-written posts in this newsgroup, but not quite close enough to what I want. Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] cnu = (2*b^2 - B^2 + r^2)/denom snu = -2*b*Sqrt[B^2 - b^2]/denom sif = 2*r*b/denom cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b that I'm after. ==== Troy, True, interactive manipulation can be difficult. However, here is one way to do what you want. We have to do the same thing to both sides of the equation. (# - D*Sqrt[K]/C)&/@(A+B/C+D*Sqrt[K]/C[Equal]0 A + B/C == -((D*Sqrt[K])/C) Together/@% (B + A*C)/C == -((D*Sqrt[K])/C) #C&/@% B + A*C == (-D)*Sqrt[K] #^2&/@% (B + A*C)^2 == D^2*K NOTES. Here is how #C&/@ (lhs ==rhs) works: #C&/@ (lhs ==rhs) --> #C&[lhs]==#C&[rhs] --> lhs C == rhs C --> ... f/@( expr) is special for for Map[f, expr] expr& is special for Function[expr] Please look up Map and Function in the Help Browser. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > I'm a newbie and, of course, the first thing I want to do is apparently > one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x > I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at > least point me to some tutorial in the Mathematica documentation. I've > been looking over the documentation and I found Appendix A.5 in The > Mathematica Book, but that doesn't help me. I _need_ some examples. I > did find a couple of well-written posts in this newsgroup, but not quite > close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b > that I'm after. > ==== > Troy, > True, interactive manipulation can be difficult. > However, here is one way to do what you want. > We have to do the same thing to both sides of the equation. > > (# - D*Sqrt[K]/C)&/@(A+B/C+D*Sqrt[K]/C[Equal]0 > > A + B/C == -((D*Sqrt[K])/C) I think I have to apologize for the lack of clarity in my original post. I had tried to word it carefully, but I deceived myself. I should have said: I have an expression that can be put into this form: A + B/C + D*Sqrt[K]/C = 0 A,B,C,D, & K are all polynomials in x I need to get it into that form and, in the end, I want it to look like this (D^2)*K = (A*C + B)^2 I think I gave the impression that I have polynomials A,B,C,D, & K at my fingertips. I don't. The expression I have is given at the end of this message. I'm still trying to digest the respones I've garned so far. In the meantime, I decided to post this clarification. > > I'm a newbie and, of course, the first thing I want to do is > apparently one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[K]/C = 0 A,B,C,D, & K are all polynomials in x > I want it to look like this (D^2)*K = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, > at least point me to some tutorial in the Mathematica documentation. > I've been looking over the documentation and I found Appendix A.5 in > The Mathematica Book, but that doesn't help me. I _need_ some > examples. I did find a couple of well-written posts in this newsgroup, > but not quite close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in > b that I'm after. > > > ==== I'm only a little embarassed for not having realized what was happening. (Perhaps I should have slept on it.) Surely I'm not alone in thinking this symbolism is highly nonintuitive. But of course, for it to be otherwise would require another protected symbol... --- Selwyn > > >>In: DSolve[y*D[u[x, y],x] == x*D[u[x, y],y], u[x,y], {x, y}] >Out: {{u[x, y] -> C[1][(1/2)*(x^2 + y^2)]}} >Square brackets are used as grouping symbols in the result!?? :^O >Somebody say it isn't so. > > It isn't so > > The square bracket is not delineating a factor it is enclosing the argument > to an arbitrary function named C[1]. While the function is dependent on both > x and y the dependence only occurs in the combination (x^2+y^2). > > > Bob Hanlon > Reply-To: ==== It isn't so. The solution is an arbitrary function of (1/2)*(x^2 + y^2)]}}. Bobby -----Original Message----- ==== Does anyone know what happened to the < > Does anyone know what happened to the < in Mathematica 4.x? In some version I know I used it, but it seems to > have gone away. It allowed for real time manipulation of 3D graphics. > > > Ray Gittings ==== > > it's still there > > << RealTime3D` > > but MathGL3d may be the better solution > http://phong.informatik.uni-leipzig.de/~kuska/mathgl3dv3/ > > Jens > > >>Does anyone know what happened to the <>in Mathematica 4.x? In some version I know I used it, but it seems to >>have gone away. It allowed for real time manipulation of 3D graphics. >>Ray Gittings > > ==== > > > > The more I play with the example the more > depressing it gets. Start > > with floating point numbers but explicitly > arbitrary-precision ones. > > > > In[1]:= > > a=77617.00000000000000000000000000000; > > b=33095.00000000000000000000000000000; > > > > In[3]:= > > !(333.7500000000000000000000000000000 b^6 + > a^2 ((11 a^2 > > b^2 - > > b^6 - 121 b^4 - 2)) + > 5.500000000000000000000000000000 b^8 + > > a/(2 > > b)) > > > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > > > In[4]:= > > Accuracy[%] > > > > Out[4]= > > -6 > > > > Due to the manual section 3.1.6: > > > > When you do calculations with arbitrary-precision > numbers, as > > discussed in the previous section, Mathematica > always keeps track of > > the precision of your results, and gives only > those digits which are > > known to be correct, given the precision of your > input. When you do > > calculations with machine-precision numbers, > however, Mathematica > > always gives you a machine[CapitalEth]precision result, > whether or not all the > > digits in the result can, in fact, be determined > to be correct on the > > basis of your input. > > > > Because I started with arbitrary-precision numbers > Mathematica should display > > only those digits that are correct, that is none. > > No, 26 digits are correct Here is the number: -0.8273960599468213681 Here is the same number computed by Mathematica with 26 correct digits: -4.78339168666055402578083604864320577443814[Times]10^32 It looks like I have been using some wrong definition of correct.:-) You just proved that Precision is useless as a measure how good your numerical result is. > (check Precision instead > of Accuracy to see > this). > > You appear to be showing output in InputForm. If you > use OutputForm or > StandardForm only 26 digits will be shown. > > 32 > Out[3]= -4.7833916866605540257808360 10 > > InputForm is showing more because it exposes bad > digits as well as > good ones. > > > > To relax a bit, set a new input cell to > StandardForm and type > > 77617.000000000000000000000000000000000 > > > > Convert it to InputForm. You get > 77616.999999999999999999999999999999999999999999952771`37.9031 > > > > Convert back to StandardForm > 77616.99999999999999999999999999999999999999999976637`37.9031 > > > > Again to InputForm > 77616.99999999999999999999999999999999999999999963735`37.9031 > > > > Back to StandardForm > 77616.99999999999999999999999999999999999999999951376`37.9031 > > > > See what you can get if you have enough patience > or a small program. > > > > PK > > Agreed, it's not very pretty. I am uncertain as to > whether this > indicates a bug in StandardForm or elsewhere in the > underlying numerics > code, and will defer to our numerics experts on that > issue. My guess is > it is a bug if only because it violates the spirit > of IEEE arithmetic > wherein floats that have integer values should be > representable as such > (or something to that effect). I will point out, > however, that the two > numbers in question are equal to the specified > precision. Also it > appears to be improved in our development kernel. > > > Daniel Lichtblau > Wolfram Research __________________________________________________ Do you Yahoo!? http://faith.yahoo.com ==== > You are entitled to your opinion. For my applications > this behavior IS useless. > I agree that Mathematica is probably useless for you. This is however not because it is useless or useless for your application, but because to use its full power you have to study it, understand it, and in particular, for numerical work, understand the model of arithmetic it uses. Lie with mathematics they are really no shortcuts that will lead you to its full power. In addition, since it is a computer program, it has certain conventions, which may not be the same as the conventions of other programs (they all have conventions) but which you have to accept to be able to use it. Now, once you have done that, you may still not like the way Mathematica does things and there are genuine experts in numerics who indeed do not like and are quite vocal about it. But they never say it is useless, because by saying that you are either displaying your own ignorance or engaging in stupid and pointless abuse. On a more serious level, there seem to be two basic approaches to numeric computation relevant to this discussion. It seems to me (though I am no expert in this sort of thing) that there are three types of situations that one may encounter. Firstly, there is the vast majority of rather simple computations for which built-in machine floating point arithmetic , which carries no guarantee of precision at all is meant for. It clearly must be sufficient for the majority of purposes, since most general purpose and even technical software available uses not other method. The reason of course is that it is by far the fastest way to do such computations (as well as being sufficient for most situations). The second type of situation is when you actually know the precision of your input and would like the program to give you some idea about the precision of the output you might expect. This is the most likely situation in empirical science and is exactly what SetPrecision is meant for. Most reasonable people would agree that Mathematica works well in this situation. There is finally one more situation, to which the only reasonable criticism that I have read in this thread appears to be directed at. That is the situation when you actually know your input exactly, but working with exact numbers is far too slow. So what you have to do is to replace your exact numbers with inexact ones padded with 0's. In Mathematica you have to take a guess at how much padding you will need, than use SetPrecision to pad the numbers, and then check the Precision of your answer. It may turn out that you did not get as much precision as you needed, in which case you have to use more zeros. Or it may be that you used more than enough, which mans that your computation could have been done faster. I learned from Leszek Sczaniecki that there is an approach due to Oliver Aberth which lets you only specify the desired precision of your answer and the program itself will choose the correct padding for your input. It woudl ertainly be nice to have this ability, but I honestly think that it would be only of marginal advantage over making your own guess. It seems to me that the checking that the Aberth mthod must require will be time consuming and wiht a bit of practice one can probably get better results as far as speed is concerned using the Mathematica approach. But this is just pure speculation and certainly it woudl be nice if such a possibility existed. Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ ==== >Yes, there seems to be a lot of people who have a visceral hatred for >Microsoft and Windows. They are even willing to shed blood to avoid >Windows. But why? Windows works and you don't have to become a systems >programmer. > >Furthermore, I think that Steven Wolfram uses some version of Windows. >So guess which system Mathematica will be best tuned up for? If it is true Wolfram uses Mathematica on a Windows based machine my experience is it doesn't translate to Mathematica running better on Windows. I use Mathematica on WindowsNT and on a Mac (currently Mac OS X). I have found Mathematica to be more stable on a Mac than on Windows. On more than one occassion I've seen errors I made Mathematica code to crash the entire machine under WindowsNT. I've never had this happen running things on a Mac. ==== > >>Yes, there seems to be a lot of people who have a visceral hatred for >>Microsoft and Windows. They are even willing to shed blood to avoid >>Windows. But why? Windows works and you don't have to become a systems >>programmer. >Furthermore, I think that Steven Wolfram uses some version of Windows. >>So guess which system Mathematica will be best tuned up for? > > If it is true Wolfram uses Mathematica on a Windows based machine my > experience is it doesn't translate to Mathematica running better on > Windows. I use Mathematica on WindowsNT and on a Mac (currently Mac OS X). > I have found Mathematica to be more stable on a Mac than on Windows. On > more than one occassion I've seen errors I made Mathematica code to crash > the entire machine under WindowsNT. I've never had this happen running > things on a Mac. I believe you hit the nail on the head. I suspect Dr. Wolfram is running on Mac. I have the feeling WRI is a clandestine Mac holdout. STH . ==== I ran Turbo XML http://www.tibco.com/solutions/products/extensibility/turbo_xml.jsp on ToFileName[{$TopDirectory, SystemFiles, IncludeFiles, XML}, notebookml1.dtd ] It gave me an error saying: There is more than one attribute named class. My guess is this was the intention: hattons@ljosalfr:~/.Mathematica/SystemFiles/IncludeFiles/XML/NotebookML1> diff /opt/Wolfram/Mathematica/4.2/SystemFiles/IncludeFiles/XML/NotebookML1/notebo okml.dtd /home/hattons/.Mathematica/SystemFiles/IncludeFiles/XML/NotebookML1/notebook ml.dtd 91c91 Comments? STH . ==== I've posted Mathematica notebooks and packages illustrating most of the neural networks discussed in James Anderson's book An Introduction to Neural Networks to the Brainstage Research web site (www.brainstage.com). Have fun! Don Donald Doherty, Ph.D. Brainstage Research, Inc. donald.doherty@brainstage.com ==== can I have mathematica solver things like a(over)b, (in how many ways can you pick b items from a items)? I have mathematica 4. Stefan ==== Stefan You certainly can - try Binomial[a,b]. Mark Westwood > > > can I have mathematica solver things like a(over)b, (in how many ways > can you pick b items from a items)? > > I have mathematica 4. > > Stefan ==== There are two basic ways, the second of which has two forms. The basic ways are: 1. Using the built in function ContourPlot, e.g.: ContourPlot[x^3y + y^3 - 9, {x, -9, 9}, {y, -27, 27}, Contours -> {0}, ContourShading -> False, Axes -> True, Frame -> False, PlotPoints -> 50, AxesOrigin -> {0, 0}] alternatively you can use a Standard package: <{0,0}] or ImplicitPlot[x^3y+y^3-==9,{x,-9,9},{y,-27,27},AxesOrigin->{0,0}] The difference between these two is that the first one gives you a smoother picture but requires the equation to be solvable (by Mathematica) for y. The second will give a picture very similar to that produced by the first method. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? ==== Since you already know the answer, the simplest way is: In[51]:= Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio}] Out[51]= (-(-1 - x + GoldenRatio*x - x^2))*(1 + GoldenRatio*x + x^2) Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and > also a > new user of Mathematica; so please forgive this rather simple > question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into > Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and > also a > new user of Mathematica; so please forgive this rather simple > question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into > Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I confess I am not 100% sure what you mean. Would you like to do this in steps, like you would do it by hand? In[1]:= a + b/c + d*(Sqrt[e]/c) == 0; In[2]:= Thread[(#1 - a - b/c & )[%], Equal] Out[2]= (d*Sqrt[e])/c == -a - b/c In[3]:= Thread[(#1*c & )[%], Equal] Out[3]= d*Sqrt[e] == (-a - b/c)*c In[4]:= Thread[(#1^2 & )[%], Equal] Out[4]= d^2*e == (-a - b/c)^2*c^2 In[5]:= Simplify[%] Out[5]= d^2*e == (b + a*c)^2 Of course you can combine all the steps into a single function, but I think it will be fairly complicated. My own favourite way to do this sort of thing is: In[1]:= Simplify[d^2*e == (d^2*e /. AlgebraicRules[ a + b/c + d*(Sqrt[e]/c) == 0, e])] Out[1]= d^2*e == (b + a*c)^2 However, AlgebraicRules has not been documented since version 4. It should be possible to do this using PolynomialReduce but it seems to require the sort of skill only Daniel Lichtblau possesses;) Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ > I'm a newbie and, of course, the first thing I want to do is apparently > one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x > I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at > least point me to some tutorial in the Mathematica documentation. I've > been looking over the documentation and I found Appendix A.5 in The > Mathematica Book, but that doesn't help me. I _need_ some examples. I > did find a couple of well-written posts in this newsgroup, but not > quite > close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b > that I'm after. ==== Only on second reading I noticed the part about a,b,c,d being polynomials in x. Both methods will still work if first perform the same operation as below and finally use the replacement rule %/.{a->p[x],b->q[x],c->r[x],d->u[x],e->v[x]}, where p[x] etc are the given polynomials. Of course collecting of terms can be done with Collect[%,x]. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > I confess I am not 100% sure what you mean. Would you like to do this > in steps, like you would do it by hand? In[1]:= > a + b/c + d*(Sqrt[e]/c) == 0; In[2]:= > Thread[(#1 - a - b/c & )[%], Equal] Out[2]= > (d*Sqrt[e])/c == -a - b/c In[3]:= > Thread[(#1*c & )[%], Equal] Out[3]= > d*Sqrt[e] == (-a - b/c)*c In[4]:= > Thread[(#1^2 & )[%], Equal] Out[4]= > d^2*e == (-a - b/c)^2*c^2 In[5]:= > Simplify[%] Out[5]= > d^2*e == (b + a*c)^2 Of course you can combine all the steps into a single function, but I > think it will be fairly complicated. My own favourite way to do this sort of thing is: In[1]:= > Simplify[d^2*e == (d^2*e /. AlgebraicRules[ > a + b/c + d*(Sqrt[e]/c) == 0, e])] Out[1]= > d^2*e == (b + a*c)^2 However, AlgebraicRules has not been documented since version 4. It > should be possible to do this using PolynomialReduce but it seems to > require the sort of skill only Daniel Lichtblau possesses;) Andrzej Kozlowski > Toyama International University > JAPAN > http://sigma.tuins.ac.jp/~andrzej/ I'm a newbie and, of course, the first thing I want to do is > apparently > one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x > I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at > least point me to some tutorial in the Mathematica documentation. > I've > been looking over the documentation and I found Appendix A.5 in The > Mathematica Book, but that doesn't help me. I _need_ some examples. I > did find a couple of well-written posts in this newsgroup, but not > quite > close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in > b > that I'm after. ==== <{-1,5}] ImplicitPlot[x^3y + y^3 == 9, {x, -10, 10}] Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : dim., 6. octobre 2002 11:34 Ë : mathgroup@smc.vnet.net Objet : Plotting ellipses and other functions How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? ==== >How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 > >and > >x^3y + y^3 = 9 > >using Mathematica? > Needs[Graphics`ImplicitPlot`]; ImplicitPlot[(x - 2)^2 + 2(y - 3)^2 == 6, {x, -1, 5}, {y, 1, 5}]; ImplicitPlot[x^3 y + y^3 == 9, {x, -6, 6}, {y, -6, 6}]; Bob Hanlon ==== >Could somebody please inform me how to Round numbers to a >certain Accuracy using Mathematica 4.2. This is not as easy as it >sounds. >Every function that I have read Rounds the Display, and not the actual >number. myRound[x_, n_] := Round[10^n*x]/10.^n; Table[myRound[Random[], 3], {10}] {0.044, 0.019, 0.738, 0.298, 0.917, 0.171, 0.021, 0.314, 0.658, 0.153} Bob Hanlon Reply-To: tgarza01@prodigy.net.mx ==== You might use ImplicitPlot: In[1]:= << Graphics`ImplicitPlot` In[2]:= eqn1 = (x - 2)^2 + 2*(y - 3)^2 == 6; In[3]:= ImplicitPlot[eqn1, {x, -2, 6}]; In[4]:= eqn2 = x^3*y + y^3 == 9; In[5]:= ImplicitPlot[eqn2, {x, -8, 8}]; Tomas Garza Mexico City Original Message: ----------------- ==== You may use Binomial. It could also be useful to look at the AddOn package DiscreteMath`Combinatorica`, where you will find a wealth of interesting things related to that. In[1]:= Binomial[6,2] Out[1]= 15 Tomas Garza Mexico City Original Message: ----------------- ==== I feel as if I've finally had the breakthrough in intuitively understanding the Mathematica editor, or at least the basics. I want to explain to others what they really need to know about the editor to use it for basic purposes. Part of the reason I now understand the editor better is that I've since worked with LyX http://www.devel.lyx.org and XEmacs http://www.xemacs.org, and I've also become proficient with DocBook XML. When I first started using the editor, reading the Mathematica Help didn't seem to help. It seemed to tell me a whole lot more than I needed to know, and didn't tell me what I really needed to know. Now I'm in the position of being able to use it, but not being able to explain exactly what it is I've learned. Is there any documentation directed toward the beginner, which tells him or her what to do, what to expect, what quirks to be aware of, and etc.? I'm looking for something along the lines of click here to make this happen. If you see this, it may seem weird, but that's normal. Those brackedt on the left really mean... . STH . ==== >I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica >and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) > >What instructions do I need to execute to achieve this output? > soln = Factor[x^4 + x^3 + x^2 + x + 1, Extension -> GoldenRatio] // Simplify (x^2 - GoldenRatio*x + x + 1)*(x^2 + GoldenRatio*x + 1) soln = Simplify /@ (soln /. -GoldenRatio -> -1 - 1/GoldenRatio) (x^2 - x/GoldenRatio + 1)*(x^2 + GoldenRatio*x + 1) soln // FunctionExpand // FullSimplify x^4 + x^3 + x^2 + x + 1 Bob Hanlon ==== Stefan, I don't think I completely understand your question, but I think you are looking for the Binomial function in Mathematica. Binomial[4, 2] 6 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Steve, You could use the Extension feature of Factor as documented in Help. expr = x^4 + x^3 + x^2 + x + 1 ans = Factor[expr, Extension -> {1/GoldenRatio}] (-(1/4))*(-2 - x + Sqrt[5]*x - 2*x^2)* (2 + x + Sqrt[5]*x + 2*x^2) You could also use... Factor[expr, Extension -> {Sqrt[5]}] It took me some effort to figure out how to manipulate the answer into your form. ans /. {x + Sqrt[5]*x -> (2*GoldenRatio)*x, -x + Sqrt[5]*x -> (2/GoldenRatio)*x} % /. (-4^(-1))*a_*b_ :> Simplify[-a/2]*Simplify[b/2] (-(1/4))*(-2 + (2*x)/GoldenRatio - 2*x^2)* (2 + 2*GoldenRatio*x + 2*x^2) (1 - x/GoldenRatio + x^2)*(1 + GoldenRatio*x + x^2) David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ http://www.harker.org/ ==== David, To plot equations like that, simply use ImplicitPlot. Needs[Graphics`ImplicitPlot`] ImplicitPlot[(x - 2)^2 + 2(y - 3)^2 == 6, {x, -1, 5}, {y, 1, 5}]; ImplicitPlot[x^3*y + y^3 == 9, {x, -10, 10}, {y, -10, 10}]; You may have to fish a little to obtain the appropriate x and y ranges. Start by making them larger and then narrow down to the region that you want. I have put a new package at my web site for solving conic section problems in the plane. You can solve for complete information on any conic section and obtain a parametric representation for plotting it. The package also comes with complete Help documentation and examples. Using your first example (the second is not a conic). Needs[ConicSections`ConicSections`] eqn = (x - 2)^2 + 2(y - 3)^2 == 6; The routine ParseConic will take any quadratic equation and return the scale a, eccentricity e, a parametrization, and rotation matrix P, translation T and reflection matrix R that transforms the conic from standard position to its actual position. (In standard position the conic has its foci and verticies on the x-axis with the center at zero.) {{a, e}, curve[t_], {P, T, R}} = ParseConic[eqn] {{Sqrt[6], 1/Sqrt[2]}, {2 + Sqrt[6]*Cos[t], 3 + Sqrt[3]*Sin[t]}, {{{1, 0}, {0, 1}}, {2, 3}, {{1, 0}, {0, 1}}}} We could then plot the curve using ParametricPlot, which is more efficient and controllable. ParametricPlot[Evaluate[curve[t]], {t, -Pi, Pi}, AspectRatio -> Automatic, Frame -> True, Axes -> None, PlotLabel -> eqn]; Knowing a and e we can use the StandardConic routine to obtain all the information about the conic in standard position as a set of rules. standarddata = StandardConic[{a, e}] {conictype -> Ellipse, conicequation -> x^2/6 + y^2/3 == 1, coniccurve -> {Sqrt[6]*Cos[t], Sqrt[3]*Sin[t]}, coniccurvedomain -> {-Pi, Pi}, coniccenter -> {0, 0}, conicfocus -> {{Sqrt[3], 0}, {-Sqrt[3], 0}}, conicdirectrix -> {x == -2*Sqrt[3], x == 2*Sqrt[3]}, conicvertex -> {{Sqrt[6], 0}, {-Sqrt[6], 0}}} routine to obtain the same information for the conic in its actual position. standarddata // TransformEllipseRules[P, T, R] {conictype -> Ellipse, conicequation -> (1/6)*((-2 + x)^2 + 2*(-3 + y)^2) == 1, coniccurve -> {2 + Sqrt[6]*Cos[t], 3 + Sqrt[3]*Sin[t]}, coniccurvedomain -> {-Pi, Pi}, coniccenter -> {2, 3}, conicfocus -> {{2 + Sqrt[3], 3}, {2 - Sqrt[3], 3}}, conicdirectrix -> {2*Sqrt[3] + x == 2, x == 2*(1 + Sqrt[3])}, conicvertex -> {{2 + Sqrt[6], 3}, {2 - Sqrt[6], 3}}} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: ==== Try this: A + B/C + D*(Sqrt[E]/C) == 0 (#1 - %[[1,{1, 2}]] & ) /@ % (C*#1 & ) /@ % (#1^2 & ) /@ % Simplify[%] Also, be aware that E is the natural logarithm base, reserved for that purpose. DrBob -----Original Message----- want the equation to be written out with terms grouped by powers of x, but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at least point me to some tutorial in the Mathematica documentation. I've been looking over the documentation and I found Appendix A.5 in The Mathematica Book, but that doesn't help me. I _need_ some examples. I did find a couple of well-written posts in this newsgroup, but not quite close enough to what I want. Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] cnu = (2*b^2 - B^2 + r^2)/denom snu = -2*b*Sqrt[B^2 - b^2]/denom sif = 2*r*b/denom cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b that I'm after. Reply-To: ==== It's a little ugly, but here's my solution: x^4 + x^3 + x^2 + x + 1 Simplify@Factor[%, Extension -> {GoldenRatio, 1/GoldenRatio}] Collect[%[[2]]/3, x]Collect[%[[3]]/3, x] % /. Sqrt[5] -> 2GoldenRatio - 1 % // Simplify Collect[#, x] & /@ % % /. {1 - GoldenRatio -> -1/GoldenRatio} FullSimplify@Expand@% (The last line is a check.) Bobby -----Original Message----- (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth Harker School http://www.harker.org/ ==== >How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 > >and > >x^3y + y^3 = 9 > >using Mathematica? Use ImplicitPlot in the package Graphics`ImplicitPlot` ==== David, <{0,0}] -----Original Message----- Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: jcd@q-e-d.org ==== I look for a way to right align entries output by MatrixForm. There is an ad hoc option, but I haven't figured out how it is supposed to work in Mathematica 4.0 (if it works at all). m={{MatrixForm[{0,0,0}],-123456789},{123456789,1}}; MatrixForm[m,TableAlignments->{Right,Top}] appears identical to MatrixForm[m] (with no SetOptions override) Strangely, Mathematica doesn't complain if you input ill options like: MatrixForm[m,TableAlignments->{WhateverIsIllegal,Right,Top,MakeSomeSpiralOfI t}] In Mathematica 2.2x, the behavior is rather strange: one option alone works, but when two are given (e.g. {Right,Top}), only the last seems to be acted upon. I didn't bother to try hard with the older version, so don't flame me if I'm wrong. At the other hand, when a TableAlignments->Right is given to TableForm, entries are right-aligned correctly. Can someone provide a way out (even a slow external module) or tell me how to use this option. I apologize for using a phony address in an attempt ==== I decided to export one of my notebooks to html/mathml http://baldur.globalsymmetry.com/proprietary/com/wri/notebooks/essential/ 66.92.149.152 baldur.globalsymmetry.com When I try to view it with Mozilla, I get a '?' in place of the imaginary number symbol. When I first load the page with Mozilla, I get an error telling me To properly display the MathML on this page you need to install the following fonts: CMSY 10, CMEX 10, Math1, Math2, Math4. For further infromation see: http://www.mozilla.org/projects/mathml/fonts I did what the instructions at the URL told me, and I still get the error. I looked through the fonts in the Mathematica font directory, and I found: Mathematica1Mono.9.bdf -wri-mathematica1mono-medium-r-normal--9-90-75-75-m-50-adobe-fontspecific Mathematica3.12.bdf -wri-mathematica3-medium-r-normal--12-120-75-75-p-70-adobe-fontspecific Mathematica3.24.bdf -wri-mathematica3-medium-r-normal--24-240-75-75-p-130-adobe-fontspecific Mathematica3.36.bdf -wri-mathematica3-medium-r-normal--36-360-75-75-p-210-adobe-fontspecific .... Mathematica7.12.bdf -wri-mathematica7-medium-r-normal--12-120-75-75-p-40-adobe-fontspecific Mathematica7.24.bdf .... -wri-mathematica6-medium-r-normal--12-120-75-75-p-30-adobe-fontspecific Mathematica6.24.bdf -wri-mathematica6-medium-r-normal--24-240-75-75-p-70-adobe-fontspecific Mathematica6.36.bdf -wri-mathematica6-medium-r-normal--15-150-75-75-p-50-adobe-fontspecific Mathematica5.12.bdf -wri-mathematica5-medium-r-normal--12-120-75-75-p-50-adobe-fontspecific Mathematica5.24.bdf -wri-mathematica5-medium-r-normal--24-240-75-75-p-110-adobe-fontspecific Mathematica5.36.bdf -wri-mathematica5-medium-r-normal--36-360-75-75-p-160-adobe-fontspecific Mathematica5.13.bdf -wri-mathematica5-medium-r-normal--13-130-75-75-p-50-adobe-fontspecific Mathematica4.18.bdf -wri-mathematica4-medium-r-normal--18-180-75-75-p-130-adobe-fontspecific Mathematica5.10.bdf .... I suspect this is what mozilla is looking for, but I don't know exactly how to tell it as much. Any ideas? STH . Reply-To: ==== I suppose my silliness is understandable, in light of all the confusion, both here and in the Browser on what significance arithmetic is, what bignums and bigfloats might be, etc. If many smart people are confused, there's a possibility --- just a possibility, mind you --- that it isn't entirely their fault. Yes? No? >>like 71 above, or -5 for Accuracy in the example that fooled me), but it's not a big deal For people who don't understand it as well as you, yes, it's a big deal. My purpose in all this is to understand the issue well enough to know how to proceed. I think that I do, now, but I doubt everybody on the list does. Daniel says this will all be clearer in the next release, and that's good! Bobby -----Original Message----- -1.180591620717411303424`71.0721*^21 > 71 71.0721 digits of precision? I don't think so!! Either I am it altogether or you are just simply beating to death the point that in case of machine arithmetic (only!) Precision and Accuracy are purely formal and essentially meaningless. One can argue whether in this case there is any point of returning any value for Precision, or Accuracy (like 71 above, or -5 for Accuracy in the example that fooled me), but it's not a big deal and it most certainly does not make SetPrecision meaningless. On the contrary, SetPrecision is very useful and in fact it is SetPrecision that can tell you that the answer above is meaningless: In[8]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 50]; a=SetPrecision[77617.,$MachinePrecision]; b = SetPrecision[ 33096.,$MachinePrecision]; In[10]:= {f,Precision[f]} Out[10]= {1.19801754103509`0*^19, 0} I would say this is correct and show that SetPrecision is very useful indeed. It tells you (what of course you ought to already know in this case anyway) that machine precision will not give you a realiable answer in this case. If you know your numbers with a great deal of accuracy you can get an accurate answer: In[24]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; a=SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; In[26]:= {f, Precision[f]} Out[26]= {-0.82739605994682136814116509547981629199903311578438481991 781484167246798617832`61.2597, 61} Again you can be pretty sure that you got an accurate answer, provided of course your original setting of precision was valid. Honestly, to say that SetPrecision and SetAccuaracy are useless is one of the silliest thing I have read on this list in years. > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? Reply-To: kuska@informatik.uni-leipzig.de ==== look what Graphics`ImplicitPlot` does. Jens > > How can I plot functions like: > > (x-2)^2 + 2(y-3)^2 = 6 > > and > > x^3y + y^3 = 9 > > using Mathematica? ==== David: For a start you can try the following: Using ContourPlot ContourPlot[(x - 2)^2 + 2(y - 3)^2 - 6, {x, -1, 5}, {y, -1, 5}, Contours -> {0}, ContourShading -> False, ContourSmoothing -> 5] Or using ImplicitPlot << Graphics`ImplicitPlot` ImplicitPlot[(x - 2)^2 + 2(y - 3)^2 == 6, {x, -1, 5}] ImplicitPlot[x^3y + y^3 == 9, {x, -4, 4}] Hans > How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? ==== Try reading help under the keyword ImplicitPlot | How can I plot functions like: | | (x-2)^2 + 2(y-3)^2 = 6 | | and | | x^3y + y^3 = 9 | | using Mathematica? | | | | ==== David Enquire within the Help Browser for the ImplicitPlot package and all will be revealed. For example, I snipped the following lines from the documentation: << Graphics`ImplicitPlot` ImplicitPlot[x^2 + 2 y^2 == 3, {x, -2, 2}] Hope this is of sufficient help to get you started - post again if you have any further questions. Mark Westwood > > How can I plot functions like: > > (x-2)^2 + 2(y-3)^2 = 6 > > and > > x^3y + y^3 = 9 > > using Mathematica? ==== you can. Use: <