A6 === You would need to make assumptions about y, and you canÕt. The function> and the limits have to take care of that, and when you try to do that,> you end up with an expression that has different antiderivatives on> different regions, for different values of x. So, you have to break it> up. The assumption x > 0 implies that x is real, so Im[x]==0 is> unnecessary.> one = Integrate[Cosh[2 (y - x)]> 2 y, {y, Min[x, 1/2], 1/2}, Assumptions -> {x > 0}];> two = Integrate[Cosh[2 (x - y)] 2> y, {y, 0, Min[x, 1/2]}, Assumptions -> {x > 0}];> one + two // FullSimplify> Plot[{one, two, one + two}, {x, 0, 1/2}];> (1/4)*E^(-1 - 2*x)*(E + (-2 + E)*E^(4*x))> Bobby Treat> -----Original Message-----> I have been trying to integrate the following :> Integrate[Cosh[2 Abs[x-y]] 2 y, {y,0,1/2},> Assumptions->{Im[x]==0,x>0}]> However, Mathematica chokes and simply returns the integral as> it is. However, if I> split up the integral into two portions, it quickly gives me an answer> for the parts. Is> there something implicit that I am missing in the Assumptions ?> MS.> ?Anyways, I will try what you suggest.-- 12:53pm up 27 min, 1 user, load average: 0.19, 0.15, 0.09 ==== Put this after the Plot statement, in the same cell:SelectionMove[EvaluationNotebook[], All, GeneratedCell]FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate]Bobby Treat-----Original Message-----Do[Plot[Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1, 1}},ImageSize -> 400]; SelectionMove[EvaluationNotebook[], All, GeneratedCell];FrontEndExecute[{FrontEnd`SelectionAnimate[0.1 ]}]; FrontEndExecute[{FrontEndToken[Clear]}], {t, 0, 15, 0.1}]This works but the cell dividing line ßashes on and off spoiling theanimation and if there is anything in the cell below this jumps up anddown.Is there a proper way of doing this?Hugh Goyder ==== >>So would it take about the same amont of time for the completeprintoutof digits? Of course it would take a few additional seconds to formatthe output...I think it would take FAR more time for a complete printout, and mightcrash the Front End. I was thinking about the fact that I calculatedall those digits and then threw them away. I could save them with Saveor DumpSave, and read them in with Get the next time I wanted any ofthem, although the file would be close to 70 MB (if not more). I may dothat, in fact -- I have plenty of disk space.The next step would be to somehow reuse the stored digits if I wantedMORE digits. But how?The Bailey-Borwein-Plouffe Pi algorithm is an avenue of attack, since itcan calculate digits far from the decimal point, without calculatingthose in between. Unfortunately, it calculates hexadecimal digits inthat way, not decimal digits. (ThatÕs true for the version IÕve seen,anyway.) Still, I could take the stored digits, convert to hexadecimal,add more hexadecimal digits with the B-B-P algorithm, and then convertback to decimal. In both conversions, IÕd have to be very cognizant ofhow much precision I end up with, but that shouldnÕt be too difficult.It might go faster if I store hexadecimal digits, as well as decimaldigits, to eliminate one of those conversions at each increase in thenumber of digits.The next step would be to set up an application that allowed anyone toping for digits across the Internet, and would return them if theyÕrestored.HasnÕt someone already done that? It seems as if someone would have.Bobby Treat-----Original Message----->Could you tell me the CPU you used and its speed etc...i am curious,to>other programs out there.> I used one processor of a dual 1GH Mac and got the same answer withthe> following speed:> 4.2 for Mac OS X (June 4, 2002)> oldmax = $MaxPrecision> 6> 1. 10> $MaxPrecision = Infinity> Infinity> With[{n = 2^26}, Timing[> pd = RealDigits[N[Pi, n + 1], 10, 20,> 19 - n]; ]]> {28794.1 Second, Null}> MaxMemoryUsed[]> 512055204> pd> {{3, 3, 8, 6, 3, 2, 2, 0, 8, 9, 6, 2, 2, 3,> > 4, 0, 9, 8, 0, 3}, -67108844}> Tom Burton ==== IÕve been trying to get my Mathematica 4.1 properly configured. I set:######################################################### ##########/usr/local/mathematica/SystemFiles/FrontEnd/ TextResources/X/Specific.tr: @@resource maxForXListFonts 10000# xlsfonts | wc -l 5572/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/local/mma/Type1 FontPath /usr/X11R6/lib/X11/fonts/local/mma/X:unscaled 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# ls -R /usr/X11R6/lib/X11/fonts/ | grep //usr/X11R6/lib/X11/fonts/:/usr/X11R6/lib/X11/fonts/100dpi:/ usr/X11R6/lib/X11/fonts/75dpi:/usr/X11R6/lib/X11/fonts/CID:/ usr/X11R6/lib/X11/fonts/Speedo:/usr/X11R6/lib/X11/fonts/Type1 :/usr/X11R6/lib/X11/fonts/URW:/usr/X11R6/lib/X11/fonts/ encodings:/usr/X11R6/lib/X11/fonts/encodings/large:/usr/X11R6 /lib/X11/fonts/kwintv:/usr/X11R6/lib/X11/fonts/latin2:/usr/ X11R6/lib/X11/fonts/latin2/Type1:/usr/X11R6/lib/X11/fonts/ local:/usr/X11R6/lib/X11/fonts/local/mma:/usr/X11R6/lib/X11/ fonts/local/mma/Type1:/usr/X11R6/lib/X11/fonts/local/mma/X:/ usr/X11R6/lib/X11/fonts/misc:/usr/X11R6/lib/X11/fonts/misc/ sgi:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/ fonts/uni:/usr/X11R6/lib/X11/fonts/util:##################### ###################################When I open the Mathematica Book Reference Guide in the Help Browser, I get a beep and the message says:Unable to find font with family Helvetica, weight Bold, slant Plain, and size 26. Substituting Courier.Compared to the things which *were* broken, this is a minor problem. I can live with the beep. What I would now like to know is how to tell Mathematica what fonts to use by default. This seemingly simple question seems to have no simple answer. Could someone please help me.TIA,^LReply-To: kuska@informatik.uni-leipzig.de ==== I expect that the Helvetica request comes from theFrontend menues and this is lited I your X resources$TopDirectory/SystemFiles/FontEnd/SystemResources/X/ XMathematicarequest the helvetica font:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!! GENERAL GUI STYLE / COLOR SETTINGS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!! Choose your GUI widget background color.! CDE: Comment this out.*background: #c0c0c0! Choose a font for buttons/text fields, etc.! You can use xfontsel to get a listing of fonts.!*Menu*fontList: -*-helvetica-medium-r-*-*-*-100-*-*-*-*-*-*! Or just set all the fonts at once.*fontList: -*-helvetica-medium-r-*-*-*-100-*-*-*-*-*-* Jens> IÕve been trying to get my Mathematica 4.1 properly configured.> I set:> ############################################################## #####> /usr/local/mathematica/SystemFiles/FrontEnd/TextResources/X/ Specific.tr:> @@resource maxForXListFonts> 10000> # xlsfonts | wc -l> 5572> /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/local/mma/Type1> FontPath /usr/X11R6/lib/X11/fonts/local/mma/X:unscaled> 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> # ls -R /usr/X11R6/lib/X11/fonts/ | grep /> /usr/X11R6/lib/X11/fonts/:> /usr/X11R6/lib/X11/fonts/100dpi:> /usr/X11R6/lib/X11/fonts/75dpi:> /usr/X11R6/lib/X11/fonts/CID:> /usr/X11R6/lib/X11/fonts/Speedo:> /usr/X11R6/lib/X11/fonts/Type1:> /usr/X11R6/lib/X11/fonts/URW:> /usr/X11R6/lib/X11/fonts/encodings:> /usr/X11R6/lib/X11/fonts/encodings/large:> /usr/X11R6/lib/X11/fonts/kwintv:> /usr/X11R6/lib/X11/fonts/latin2:> /usr/X11R6/lib/X11/fonts/latin2/Type1:> /usr/X11R6/lib/X11/fonts/local:> /usr/X11R6/lib/X11/fonts/local/mma:> /usr/X11R6/lib/X11/fonts/local/mma/Type1:> /usr/X11R6/lib/X11/fonts/local/mma/X:> /usr/X11R6/lib/X11/fonts/misc:> /usr/X11R6/lib/X11/fonts/misc/sgi:> /usr/X11R6/lib/X11/fonts/truetype:> /usr/X11R6/lib/X11/fonts/uni:> /usr/X11R6/lib/X11/fonts/util:> ########################################################> When I open the Mathematica Book Reference Guide in the Help Browser, I get> a beep and the message says:> Unable to find font with family Helvetica, weight Bold, slant Plain, and> size 26. Substituting Courier.> Compared to the things which *were* broken, this is a minor problem. I can> live with the beep. What I would now like to know is how to tell Mathematica what> fonts to use by default. This seemingly simple question seems to have no> simple answer.> Could someone please help me.> TIA,> ^L ==== > I expect that the Helvetica request comes from the> Frontend menues and this is lited I your X resources> $TopDirectory/SystemFiles/FontEnd/SystemResources/X/ XMathematica$PreferencesDirectory? This is where I expected to find this kind of thing in the first place. The idea of chaning user preferences in a system file bothers me.> request the helvetica font:> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!> !> ! GENERAL GUI STYLE / COLOR SETTINGS> !> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!> ! Choose your GUI widget background color.> ! CDE: Comment this out.> *background: #c0c0c0> ! Choose a font for buttons/text fields, etc.> ! You can use xfontsel to get a listing of fonts.> !*Menu*fontList: -*-helvetica-medium-r-*-*-*-100-*-*-*-*-*-*> ! Or just set all the fonts at once.> *fontList: -*-helvetica-medium-r-*-*-*-100-*-*-*-*-*-*I still donÕt know why Mathematica would ship with the font defaults arranged in such a way as to cause it to give me errors when viewing the help files. It makes me think something is still amiss. Were they expecting my system to have these already installed? Should I have other fonts installed? Where would I get them, if I wanted them?> Jens> STH ==== I have spent far more time attempting to get Mathematica configured than I have using it. IÕve found the the product to be exceptionally difficult to As an example, I spent several hours trying to figure out how to tell Mathematica to understand the delete key in the way most contemporary systems understand it. I wanted to avoid modifying system configuration files such as:/usr/local/mathematica/SystemFiles/FrontEnd/TextResources/ KeyEventTranslations.trI expected to be able to change something in my own ~/.Mathematic directory, but I could not figure out an obvious way to affect this modification. I want to adjust the font size used in the widgets, but again, I see no ovbious means of modifying these attributes. I suspect it can be accomplished by modifying the ~/.Mathematica/4.1/FrontEnd/init.m. Perhaps to an experienced Mathematica user, the syntax and semantics of this file are obvious. They arenÕt to me.I also find the overall look & feel of the interface to be archaic. I understand that Mathematica 4.1 was written years ago, and much of the desktops for Unix which exist today did not exist when it was written. I should be receiving Mathematica 4.2 in a few days, so perhaps these concerns will prove undounded. Something tells me that not a lot has changed in this respect.What have others observed?Reply-To: kuska@informatik.uni-leipzig.de ==== I canÕt understand your criticism. Open a terminal windowand type >maththe delete key work perfect, due to your terminal settings anda command line is the most modern interface I can imagine.It still comes with Mathematica 4.2 and is perfect as before. Jens> I have spent far more time attempting to get Mathematica configured than I> have using it. IÕve found the the product to be exceptionally difficult to> As an example, I spent several hours trying to figure out how to tell Mathematica to> understand the delete key in the way most contemporary systems understand> it. I wanted to avoid modifying system configuration files such as:> /usr/local/mathematica/SystemFiles/FrontEnd/TextResources/ KeyEventTranslations.tr> I expected to be able to change something in my own ~/.Mathematic directory,> but I could not figure out an obvious way to affect this modification. I> want to adjust the font size used in the widgets, but again, I see no> ovbious means of modifying these attributes. I suspect it can be> accomplished by modifying the ~/.Mathematica/4.1/FrontEnd/init.m. Perhaps> to an experienced Mathematica user, the syntax and semantics of this file are> obvious. They arenÕt to me.> I also find the overall look & feel of the interface to be archaic. I> understand that Mathematica 4.1 was written years ago, and much of the desktops for> Unix which exist today did not exist when it was written. I should be> receiving Mathematica 4.2 in a few days, so perhaps these concerns will prove> undounded. Something tells me that not a lot has changed in this respect.> What have others observed? ==== > I canÕt understand your criticism. Open a terminal window> and type>>math> the delete key work perfect, due to your terminal settings and> a command line is the most modern interface I can imagine.> It still comes with Mathematica 4.2 and is perfect as before.> Jens> If I could use bash to edit the command line, recall the command history, and other sorts of things that bash is good at, that would make the command line attractive. There *are* certain advantages to the gui side of things. For example the M-k code completion. That can really speed things up with languages such as Java and C++. I donÕt believe there is any fundamental reason such a thing could not exist with the command line. IMHO, a well conceived XEmacs lisp package could provide a wonderful frontend. I played around with mma.el for a few minutes, but it wasnÕt acting like a normal XEmacs package, so I switched back to cursing the Mod1<->Ctrl inversion of the Mathematica frontend.gui front end, get in the way of what really matters. The last thing I Mathematica. What I want to do is improve the overal experience for all of us.STH ==== Dear friendsI have the following problem with Legend and LogPlot and LogPlotPlot: Needs[Graphics`Graphics`]Needs[Graphics`Legend`]{q1[t_],q2[t_ ],q3[t_]}={0.1 Exp[-0.02 t], 0.2 Exp[-0.025 t], 0.4 Exp[-0.028 t]};(*With Plot legend works fine*)Plot[{q1[t],q2[t],q3[t]}, {t, 0, 100},PlotStyle[Rule]{ {AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]}, AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1,8}]}}, AxesLabel[Rule]{Y, X}, PlotLabel[Rule]Title, PlotLegend[Rule]{1,3,5}, LegendPosition[Rule] {0.5,0}](*However with LogPlot or LogLogPlot the legend desappear*)LogLogPlot[{q1[t],q2[t],q3[t]}, {t, 0, 100},PlotStyle[Rule]{ {AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]}, AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1,8}]}}, AxesLabel[Rule]{Y, X}, PlotLabel[Rule]Title, PlotLegend[Rule]{1,3,5}, LegendPosition[Rule] {0.5,0}]I have shown a particular case, but I has this problem always with Legend and LogPlot and LogPlotPlot. I will appreciate any help.GuillermoSanchez---------------------------------------- -----This message was sent using Endymion MailMan. ==== IIRC, there is a way to get a list of all the symbols defined in the currently running session. I canÕt seem to find the reference to that command. Could somone point me in the direction of documentation which will tell me how to get information about the current session?TIA,Reply-To: murray@math.umass.edu ==== 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.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375Reply-To: kuska@informatik.uni-leipzig.de ==== MathematicaÕs PostScript does not need a 3d graphics cardand will not use it.Only the RealTime3D` package make use of the 3d graphics and itÕsmemory. Since it make an off screen rendering it will be slow and since one must be mad to use it for 10^5 polygons it does notmatter how much graphics memory you have. The tiny polygon countsof Plot3D[] & friends can be handled wit 8 MByte :-)MathGL3d will run fine (not fast) with 8 MByte. For the mostMathGL3d applications 64 MByte sufficient.With more than 10^6 polygons or many huge (1024^2) textures you mayrun into problems. For the MathGL3d development I have GeForce 3/4 cardswith 128 MByte RAM.BTW the RAM of the 3d graphics cards is for textures and Mathematicadoes not know what a texture is or how usefull it is for scientificvisualization. Jens> 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 01375Reply-To: kuska@informatik.uni-leipzig.de ==== Names[Global`*]?? Jens> IIRC, there is a way to get a list of all the symbols defined in the> currently running session. I canÕt seem to find the reference to that> command. Could somone point me in the direction of documentation which> will tell me how to get information about the current session?> TIA, ==== To get a complete list of all variables that have been defined for thecurrent Mathematica session, please try:?`*which should return a list of all variables that have been defined for thecurrent Mathematica session.Steven Shippee ==== > IIRC, there is a way to get a list of all the symbols defined in the> currently running session. I canÕt seem to find the reference to that> command. Could somone point me in the direction of documentation which> will tell me how to get information about the current session?> TIA,LetÕs begin with a fresh sessionQuitMake some entries, notice that b, x and y have no definitions - they aresimply created. a=3; b; p= 3x +1; f[y_]:=y^2;We can find all the symbols we have created so far. Names[`*] {a,b,f,p,x,y}Actually, they are the strings of the symbols (otherwise, for example, awould immediately evaluate to 3). InputForm[%] {a, b, f, p, x, y}How can we take out the strings of the undefined symbols?I make a function that test if the symbol has been defined (or has anattribute assigned): SetAttributes[definedQ, HoldFirst]; definedQ[x_String]:= Or[DownValues@@#=!={}, UpValues@@#=!={},OwnValues@@#=!={}, SubValues@@#=!={},DefaultValues@@#=!={},NValues@@#=!={}, Attributes@@#=!={}]&[ ToExpression[x, InputForm, Hold]] definedQ[x_]:= definedQ[Evaluate[ToString[Unevaluated[x]]]]Using this we get Select[Names[`*], definedQ] {a,definedQ,f,p}To get information about the symbolsInformation/@Select[Names[`*], definedQ]; a a = 3 definedQ Attributes[definedQ] = {HoldFirst} definedQ[x_String] := (DownValues @@ #1 =!= {} || UpValues @@ #1 =!= {} || OwnValues @@ #1 =!= {} || SubValues @@ #1 =!= {} || DefaultValues @@ #1 =!= {} || NValues @@ #1 =!= {} & )[ToExpression[x, InputForm, Hold]] definedQ[x_] := definedQ[Evaluate[ ToString[Unevaluated[x]]]] f f[y_] := y^2 p p = 1 + 3*xI have assumed that you are interested only in the symbols in the symbols inthe default context Global`.Other context can be provided for.--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198 ==== There are several ways (note that newly defined things are by default inGlobal` context) , one would be ?@bye,Borut| IIRC, there is a way to get a list of all the symbols defined in the| currently running session. I canÕt seem to find the reference to that| command. Could somone point me in the direction of documentation which| will tell me how to get information about the current session?||| TIA,| ==== Dear all,As far as I understand, FindMinimum can be requested to use theBerndt-Hall-Hall-Hausman method, if the option Method->QuasiNewton is specified. I am pretty convinced that there is no way to tellmathematica to produce as an output the Jacobian vector and the Hessianmatrix at every step. In addition, I have not found a way to specify theDavidon-Fletcher-Powell algorithm to be used.Before I start to program it myself, I was wondering if anybody has writtensome [non-commercial] code that produces such an output for BFGS and evenbetter for DFP optimization.Kyriakos _____+**+____+**+___+**+__+**+_Kyriakos ChourdakisLecturer in Financial EconomicsURL: http://www.qmw.ac.uk/~te9001tel: (++44) (+20) 7882 5086Dept of EconomicsUniversity of London, QMLondon E1 4NSU.K. ==== Both Simplify and ImpliesQ need the assumption that all variablesare real in order to use the CAD algorithm. However, Simplifyuses many other methods trying to simplify each subexpressionof the input, while ImpliesQ only tries to prove that the wholeinput is implied by the assumptions.Here is the series of simplifications that Simplify does in thisexample.- An inequality simplification heuristic using the inequality assumption y6 >= -1 is applied to the whole system. We getsimplification:y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6 -> 1 + y4 >= 0 && y5 >= y6 && 1 + y4 + y6 >= y5- We go into simplification of subexpressions, and get thesesimplifications using reduction modulo a GroebnerBasis ofequation assumptions y4 == -1 and y5 == y6 (Simplify keepsthe result of this transformation even if it has the samecomplexity as the original expression.)1 + y4 -> 0y5 -> y61 + y4 + y6 -> y6y5 -> y6- As the result of subexpression simplifications the three inequalities become then:1 + y4 >= 0 -> 0 >= 0y5 >= y6 -> y6 >= y61 + y4 + y6 >= y5 -> y6 >= y6- 0 >= 0 evaluates to True, y6 >= y6 is simplified to True using transformation x >= y -> x - y >= 0.Adam StrzebonskiWolfram Research> That makes everything clear, except for just one small mystery:> In[1]:=> << Experimental`> In[2]:=> FullSimplify[y4 >= -1 && y6 >= -1 &&> y6 <= y5 <= 1 + y4 + y6, y4 == -1 && y6 >= -1 && y5 == y6]> Out[2]=> True> In[3]:=> ImpliesQ[y4 == -1 && y6 >= -1 && y5 == y6,> y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> Out[3]=> False> I now understand why the last one returns False, but why does the> second one return True? Should not the same arument apply in both> cases? Or is it because FullSimplify does not actually need the> assumption that the variables are real while ImliesQ does?> Andrzej>Actually, the reason why ImpliesQ (and FullSimplify) fail to>prove the implication is not that the hypothesis is a disjunction.>To use the cylindrical algebraic decomposition algorithm they>need to know that the assumptions imply that all variables are>real.> > The assumptions mechanism infers variable domains in a purely>syntactical way, i.e. v is assumed to be real if there is>an Element[v, Reals] statement or v appears in an inequality.>It does not attempt to analyze assumptions further, to figure>out that, say y6 >= -1 implies that y6 is real, and then if>we have y5 == y6 then y5 must be real too. Doing such an analysis>in general would require solving the assumptions over complex>numbers, and then finding out which variables need to be real.>This would be in general too time consuming to do, but analyzing>linear dependencies like the ones in your example is a possible>future improvement.> > ImpliesQ cannot prove the implication here, because it knows only>that y6 is real.> > In[1]:= < > In[2]:= ImpliesQ[y4 == -1 && y6 >= -1 && y5 == y6,>y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> > Out[2]= False> > If we add an explicit assumption that y4 and y5 are real, ImpliesQ>(and FullSimplify) can prove this implication, and the full version>of your example.> > In[3]:= ImpliesQ[Element[y4|y5, Reals] && y4 == -1 && y6 >= -1 && y5 ==>y6,>y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> > Out[3]= True> > In[4]:= ImpliesQ[Element[y4|y5, Reals] && (y4 == -1 && y6 >= -1 &&>y5 == y6 || y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6),>y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> > Out[4]=>True> > In[5]:= FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>Element[y4|y5, Reals] && (y4 == -1 && y6 >= -1 && y5 == y6 ||>y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6)]> > Out[5]=>True> > Adam Strzebonski>Wolfram Research> >> On second thoughts I realized that there seems to be an inherent>> ambiguity about what one coudl mean by using alternatives (statements>> joned by Or) assumptions. In fact it now seems to me that the>> reasonable intertpretation for ImpliesQ and FullSimplify ought to>> perhaps be different. It seems to me that ImpliesQ[Or[a,b],c] ought to>> return True if aand only if ImpliesQ[a,c] and ImpliesQ[b,c] both>> return>> True. If so this could be acomplished by adding the rule>> ImpliesQ[Or[a,b],c] = And[ImpliesQ[a,c],ImpliesQ[b,c]]. That could>> then>> be used in proving that the two answers to the system of inequalities>> that of VincentÕs original posting are equivalent. On the other hand>> probably FullSimplify[a, Or[p,q]] ought to return>> Or[FullSimplify[a,p],FullSimplify[a,q]] (or do nothing as it doe>> snow).>> The first approach would seem to be consistent with the way>> FullSimplify works with domain specifications but would however have>> the strange effect of returning True if just one of the alternatives>> were true and the other false. So perhaps after all it is best to>> leave FullSimplify as it is. However, it seems to me that ImpliesQ>> shoud be able to handle such cases (?)> Andrzej Kozlowski>> Toyama International University>> JAPAN>> The modification to FullSimplify that I sent earlier works correctly> only for assumptions of the form Or[a,b] (and even then not is not> always what one would like). For what itÕs worth here is a better> (but> slow) version:>> In[1]:=> Unprotect[FullSimplify];>> In[2]:=> FullSimplify[expr_, x_ || y__] := FullSimplify[> FullSimplify[expr, x] || FullSimplify[expr, Or[y]]];>> In[3]:=> Protect[FullSimplify];>> For example:>> In[4]:=> FullSimplify[Sqrt[(x - 1)^2] + Sqrt[(x - 2)^2] +> Sqrt[(x - 3)^2], x > 1 || x > 2 || x > 3]>> Out[4]=> -1 + x + Abs[-3 + x] + Abs[-2 + x] ||> -3 + 2*x + Abs[-3 + x] || 3*(-2 + x)>> Andrzej Kozlowski> Toyama International University> JAPAN>>>> On Thursday, September 26, 2002, at 11:14 AM, Andrzej Kozlowski>>> The reason why InequalitySolve returns itÕs answer in what sometimes>> turns out to be unnecessarily complicated form is that the>> underlying>> algorithm, Cylindrical Agebraic Decomposition (CAD) returns its>> answers in this form. Unfortunately it seems to me unlikely that a>> simplification of the kind you need can be can be accomplished in>> any>> general way. To see why observe the following. First of all:>> In[1]:=>> FullSimplify[x > 0 || x == 0]>> Out[1]=>> x >= 0>> This is fine. However:>> In[2]:=>> FullSimplify[x > 0 && x < 2 || x == 0 && x < 2]>> Out[2]=>> x == 0 || 0 < x < 2>> Of course what you would like is simply 0 <= x < 2. One reason why>> you canÕt get it is that while Mathematica can perform a>> LogicalExpand, as in:>> In[3]:=>> LogicalExpand[(x > 0 || x == 0) && x < 2]>> Out[3]=>> x == 0 && x < 2 || x > 0 && x < 2>> There i no LogicalFactor or anything similar that would reverse>> what LogicalExpand does. if there was then you could perform the>> sort>> of simplifications you need for:>> In[4]:=>> FullSimplify[(x > 0 || x == 0) && x < 2]>> Out[4]=>> 0 <= x < 2>> However, it does not seem to me very likely that such logical>> factoring can be performed by a general enough algorithm (though I>> am no expert in this field). In any case, certainly Mathematica>> canÕt>> do this.>> I also noticed that Mathematica seems unable to show that the answer>> it returns to your problem is actually equivalent to your simpler>> one. In fact this looks like a possible bug in Mathematica. LetÕs>> first try the function ImpliesQ from the Experimental context:>> << Experimental`>> Now Mathematica correctly gives:>> In[6]:=>> ImpliesQ[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 && y6 <=>> y5>> <= 1 + y4 + y6]>> Out[6]=>> True>> However:>> In[7]:=>> ImpliesQ[y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 &&>> y6 <= y5 <= 1 + y4 + y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 +>> y4 + y6]>> Out[7]=>> False>> That simply means that ImpliesQ cannot show the implication, not>> that>> it does not hold. ImpliesQ relies on CAD, as does FullSimplify.>> Switching to FullSimplify we see that:>> In[8]:=>> FullSimplify[y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1>> &&>> y6 <= y5 <= 1 + y4 + y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 +>> y4 + y6]>> Out[8]=>> True>> while>> In[9]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 && y6 <=>> y5>> <= 1 + y4 + y6]>> Out[9]=>> y4 >= -1 && y6 <= y5 <= 1 + y4 + y6>> On the other hand, taking just the individual summands of Or as>> hypotheses;>> In[10]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]>> Out[10]=>> True>> In[11]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 ]>> Out[11]=>> True>> In fact FullSimplify is unable to use Or in assumptions, which can>> be>> demonstrated on an abstract example:>> In[12]:=>> FullSimplify[C,(A||B)&&(C)]>> Out[12]=>> True>> In[13]:=>> FullSimplify[C,LogicalExpand[(A||B)&&(C)]]>> Out[13]=>> C>> This could be fixed by modifying FullSimplify:>> In[14]:=>> Unprotect[FullSimplify];>> In[14]:=>> FullSimplify[expr_,Or[x_,y__]]:=Or[FullSimplify[expr,x], FullSimplify>> [e>> xpr,y]];>> In[15]:=>> Protect[FullSimplify];>> Now at least we get as before:>> In[16]:=>> FullSimplify[y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1>> &&>> y6 <= y5 <= 1 + y4 + y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 +>> y4 + y6]>> Out[16]=>> True>> but also:>> In[17]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 && y6 <=>> y5>> <= 1 + y4 + y6]>> Out[17]=>> True>> This seems to me a possible worthwhile improvement in FullSimplify,>> though of course not really helpful for your problem.>> Andrzej Kozlowski>> Toyama International University>> JAPAN>> On Wednesday, September 25, 2002, at 02:51 PM, Vincent Bouchard> I have a set of inequalities that I solve with InequalitySolve. But> then> it gives a complete set of solutions, but not in the way I would> like it> to be! :-) For example, the simple following calculation will give:>> In[1]:= ineq = {y4 >= -1, y5 >= -1, y6 + y4 >= y5 - 1, y5 >= y6, y6>> = -1};> InequalitySolve[ineq,{y4,y6,y5}]>> Out[1]:= y4 == -1 && y6 >= -1 && y5 == y6 ||> y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6>> the result is good, but I would like it to be in the simpler but> equivalent form>> y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6>> How can I tell InequalitySolve to do that? It is simple for this> example,> but for a large set of simple inequalities InequalitySolve gives> lines and> lines of results instead of a simple result.>>> Vincent Bouchard>>>>>>> Andrzej Kozlowski> Toyama International University> JAPAN ==== That makes everything clear, except for just one small mystery:In[1]:=<< Experimental`In[2]:=FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6, y4 == -1 && y6 >= -1 && y5 == y6]Out[2]=TrueIn[3]:=ImpliesQ[y4 == -1 && y6 >= -1 && y5 == y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]Out[3]=FalseI now understand why the last one returns False, but why does the second one return True? Should not the same arument apply in both cases? Or is it because FullSimplify does not actually need the assumption that the variables are real while ImliesQ does?Andrzej> Actually, the reason why ImpliesQ (and FullSimplify) fail to> prove the implication is not that the hypothesis is a disjunction.> To use the cylindrical algebraic decomposition algorithm they> need to know that the assumptions imply that all variables are> real.> The assumptions mechanism infers variable domains in a purely> syntactical way, i.e. v is assumed to be real if there is> an Element[v, Reals] statement or v appears in an inequality.> It does not attempt to analyze assumptions further, to figure> out that, say y6 >= -1 implies that y6 is real, and then if> we have y5 == y6 then y5 must be real too. Doing such an analysis> in general would require solving the assumptions over complex> numbers, and then finding out which variables need to be real.> This would be in general too time consuming to do, but analyzing> linear dependencies like the ones in your example is a possible> future improvement.> ImpliesQ cannot prove the implication here, because it knows only> that y6 is real.> In[1]:= < In[2]:= ImpliesQ[y4 == -1 && y6 >= -1 && y5 == y6,> y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> Out[2]= False> If we add an explicit assumption that y4 and y5 are real, ImpliesQ> (and FullSimplify) can prove this implication, and the full version> of your example.> In[3]:= ImpliesQ[Element[y4|y5, Reals] && y4 == -1 && y6 >= -1 && y5 ==> y6,> y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> Out[3]= True> In[4]:= ImpliesQ[Element[y4|y5, Reals] && (y4 == -1 && y6 >= -1 &&> y5 == y6 || y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6),> y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]> Out[4]=> True> In[5]:= FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,> Element[y4|y5, Reals] && (y4 == -1 && y6 >= -1 && y5 == y6 ||> y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6)]> Out[5]=> True> Adam Strzebonski> Wolfram Research>> On second thoughts I realized that there seems to be an inherent>> ambiguity about what one coudl mean by using alternatives (statements>> joned by Or) assumptions. In fact it now seems to me that the>> reasonable intertpretation for ImpliesQ and FullSimplify ought to>> perhaps be different. It seems to me that ImpliesQ[Or[a,b],c] ought to>> return True if aand only if ImpliesQ[a,c] and ImpliesQ[b,c] both >> return>> True. If so this could be acomplished by adding the rule>> ImpliesQ[Or[a,b],c] = And[ImpliesQ[a,c],ImpliesQ[b,c]]. That could >> then>> be used in proving that the two answers to the system of inequalities>> that of VincentÕs original posting are equivalent. On the other hand>> probably FullSimplify[a, Or[p,q]] ought to return>> Or[FullSimplify[a,p],FullSimplify[a,q]] (or do nothing as it doe >> snow).>> The first approach would seem to be consistent with the way>> FullSimplify works with domain specifications but would however have>> the strange effect of returning True if just one of the alternatives>> were true and the other false. So perhaps after all it is best to>> leave FullSimplify as it is. However, it seems to me that ImpliesQ>> shoud be able to handle such cases (?)>> Andrzej Kozlowski>> Toyama International University>> JAPAN> The modification to FullSimplify that I sent earlier works correctly> only for assumptions of the form Or[a,b] (and even then not is not> always what one would like). For what itÕs worth here is a better > (but> slow) version:>> In[1]:=> Unprotect[FullSimplify];>> In[2]:=> FullSimplify[expr_, x_ || y__] := FullSimplify[> FullSimplify[expr, x] || FullSimplify[expr, Or[y]]];>> In[3]:=> Protect[FullSimplify];>> For example:>> In[4]:=> FullSimplify[Sqrt[(x - 1)^2] + Sqrt[(x - 2)^2] +> Sqrt[(x - 3)^2], x > 1 || x > 2 || x > 3]>> Out[4]=> -1 + x + Abs[-3 + x] + Abs[-2 + x] ||> -3 + 2*x + Abs[-3 + x] || 3*(-2 + x)>> Andrzej Kozlowski> Toyama International University> JAPAN>> On Thursday, September 26, 2002, at 11:14 AM, Andrzej Kozlowski > The reason why InequalitySolve returns itÕs answer in what sometimes>> turns out to be unnecessarily complicated form is that the >> underlying>> algorithm, Cylindrical Agebraic Decomposition (CAD) returns its>> answers in this form. Unfortunately it seems to me unlikely that a>> simplification of the kind you need can be can be accomplished in >> any>> general way. To see why observe the following. First of all:>> In[1]:=>> FullSimplify[x > 0 || x == 0]>> Out[1]=>> x >= 0>> This is fine. However:>> In[2]:=>> FullSimplify[x > 0 && x < 2 || x == 0 && x < 2]>> Out[2]=>> x == 0 || 0 < x < 2>> Of course what you would like is simply 0 <= x < 2. One reason why>> you canÕt get it is that while Mathematica can perform a>> LogicalExpand, as in:>> In[3]:=>> LogicalExpand[(x > 0 || x == 0) && x < 2]>> Out[3]=>> x == 0 && x < 2 || x > 0 && x < 2>> There i no LogicalFactor or anything similar that would reverse>> what LogicalExpand does. if there was then you could perform the >> sort>> of simplifications you need for:>> In[4]:=>> FullSimplify[(x > 0 || x == 0) && x < 2]>> Out[4]=>> 0 <= x < 2>> However, it does not seem to me very likely that such logical>> factoring can be performed by a general enough algorithm (though I>> am no expert in this field). In any case, certainly Mathematica >> canÕt>> do this.>> I also noticed that Mathematica seems unable to show that the answer>> it returns to your problem is actually equivalent to your simpler>> one. In fact this looks like a possible bug in Mathematica. LetÕs>> first try the function ImpliesQ from the Experimental context:>> << Experimental`>> Now Mathematica correctly gives:>> In[6]:=>> ImpliesQ[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 && y6 <= >> y5>> <= 1 + y4 + y6]>> Out[6]=>> True>> However:>> In[7]:=>> ImpliesQ[y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 &&>> y6 <= y5 <= 1 + y4 + y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 +>> y4 + y6]>> Out[7]=>> False>> That simply means that ImpliesQ cannot show the implication, not >> that>> it does not hold. ImpliesQ relies on CAD, as does FullSimplify.>> Switching to FullSimplify we see that:>> In[8]:=>> FullSimplify[y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1>> &&>> y6 <= y5 <= 1 + y4 + y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 +>> y4 + y6]>> Out[8]=>> True>> while>> In[9]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 && y6 <= >> y5>> <= 1 + y4 + y6]>> Out[9]=>> y4 >= -1 && y6 <= y5 <= 1 + y4 + y6>> On the other hand, taking just the individual summands of Or as>> hypotheses;>> In[10]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6]>> Out[10]=>> True>> In[11]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 ]>> Out[11]=>> True>> In fact FullSimplify is unable to use Or in assumptions, which can >> be>> demonstrated on an abstract example:>> In[12]:=>> FullSimplify[C,(A||B)&&(C)]>> Out[12]=>> True>> In[13]:=>> FullSimplify[C,LogicalExpand[(A||B)&&(C)]]>> Out[13]=>> C>> This could be fixed by modifying FullSimplify:>> In[14]:=>> Unprotect[FullSimplify];>> In[14]:=>> FullSimplify[expr_,Or[x_,y__]]:=Or[FullSimplify[expr,x], FullSimplify >> [e>> xpr,y]];>> In[15]:=>> Protect[FullSimplify];>> Now at least we get as before:>> In[16]:=>> FullSimplify[y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1>> &&>> y6 <= y5 <= 1 + y4 + y6, y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 +>> y4 + y6]>> Out[16]=>> True>> but also:>> In[17]:=>> FullSimplify[y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6,>> y4 == -1 && y6 >= -1 && y5 == y6 || y4 > -1 && y6 >= -1 && y6 <= >> y5>> <= 1 + y4 + y6]>> Out[17]=>> True>> This seems to me a possible worthwhile improvement in FullSimplify,>> though of course not really helpful for your problem.>> Andrzej Kozlowski>> Toyama International University>> JAPAN>> On Wednesday, September 25, 2002, at 02:51 PM, Vincent Bouchard > I have a set of inequalities that I solve with InequalitySolve. But> then> it gives a complete set of solutions, but not in the way I would> like it> to be! :-) For example, the simple following calculation will give:>> In[1]:= ineq = {y4 >= -1, y5 >= -1, y6 + y4 >= y5 - 1, y5 >= y6, y6>> = -1};> InequalitySolve[ineq,{y4,y6,y5}]>> Out[1]:= y4 == -1 && y6 >= -1 && y5 == y6 ||> y4 > -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6>> the result is good, but I would like it to be in the simpler but> equivalent form>> y4 >= -1 && y6 >= -1 && y6 <= y5 <= 1 + y4 + y6>> How can I tell InequalitySolve to do that? It is simple for this> example,> but for a large set of simple inequalities InequalitySolve gives> lines and> lines of results instead of a simple result.> Vincent Bouchard>>Andrzej KozlowskiToyama International UniversityJAPAN ==== inside a program I need to solve this linear equation in terms of p1.However something odds happens. Sometimes the solution is computed andsometimes the result is empty [I mean no output...]. Is this a bug of thesolve command or am I doing something wrong? The problem is robust to:changing name to the variables and other makeups..Davidps: Sorry for the stupid way in which I copied the command...Solve[(x^2*((-0.9*x^7*(p^2*(-1 - 5.8*x^6 - 14.010000000000002*x^12 - 18.04*x^18 - 13.06*x^24 - 5.040000000000001*x^30 - 0.81*x^36) + x*(7.777777777777779 - 9.074074074074076*x + 30.333333333333336*x^6 - 21.51851851851852*x^7 - 16.333333333333336*x^8 + 44.33333333333334*x^12 + 3.188888888888883*x^13 - 65.68333333333332*x^14 + 28.777777777777786*x^18 + 47.937037037037044*x^19 - 100.10000000000002*x^20 + 7.*x^24 + 45.6037037037037*x^25 - 69.53333333333333*x^26 + 13.299999999999999*x^31 - 19.833333333333332*x^32 - 1.0499999999999996*x^38) + p*(-6 + 8.296296296296296*x - 28.799999999999997*x^6 + 32.785185185185185*x^7 + 9.333333333333336*x^8 - 55.260000000000005*x^12 + 49.04777777777776*x^13 + 38.38333333333334*x^14 - 52.980000000000004*x^18 + 34.20518518518518*x^19 + 60.20000000000001*x^20 - 25.380000000000003*x^24 + 11.736296296296294*x^25 + 43.63333333333334*x^26 - 4.86*x^30 + 2.8999999999999986*x^31 + 13.533333333333333*x^32 + 0.81*x^37 + 1.0499999999999996*x^38)))/(x + 1.9*x^7 + 0.9*x^13)^2 - ((-1 + p - 7*x^6 + p*x^6 + 6*x^7)*(1.2962962962962965 - 3.111111111111112*x^6 + 9.333333333333336*x^7 - 10.111111111111114*x^12 + 22.05*x^13 - 5.703703703703705*x^18 + 17.15*x^19 + 5.483333333333331*x^25 + 1.0499999999999996*x^31 + p1*x^5*(7.000000000000002 - 7.000000000000002*x + 14.000000000000004*x^6 - 14.000000000000004*x^7 + 7.000000000000002*x^12 - 6.999999999999998*x^13) - 1.166666666666667*p*x^4*x1 - 3.500000000000001*p*x^10*x1 - 1.0500000000000003*p*x^11*x1 - 3.500000000000001*p*x^16*x1 - 3.150000000000001*p*x^17*x1 - 1.166666666666667*p*x^22*x1 - 3.150000000000001*p*x^23*x1 - 1.0500000000000003*p*x^29*x1))/((1 + 0.9*x^6)^2*(1 + x^6)^2)))/(p^2*(1 + x^6)^3) == 0, p1] ==== YouÕre right; I misunderstood your problem. First of all, never use Do-- forget it exists -- and donÕt put the SelectionMove, etc. commandsinside a loop. ThatÕs your biggest problem.This should help:Table[Plot[ Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1, 1}}], {t, 0, 2Pi - Pi/32, Pi/32}];SelectionMove[EvaluationNotebook[], All, GeneratedCell]FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate]The first time through the animation is a bit slow because the framesare being generated, but then the cell group collapses and things arebetter. I used an increment thatÕs an exact divisor of the period inorder to catch the max and min values of Sin[t], as well as the zerovalue, on each swing. Use the period MINUS the step-size as the upperlimit in order to avoid having a last frame identical to the first.IÕm a bit annoyed at the tendency for the plot to jump near zero andPi, but thatÕs because the derivative of Sin is higher there, and weÕrenot compensating by picking more points there. If we do pick morepoints there, however, we wonÕt perceive t as time. If thatÕs not aconsideration, you could do it this way:f = Which[ -1 ? # ? 1, #, 1 < # ? 3, 2 - #, True, f@Mod[#, 4, -1] ] &;Table[Plot[ f[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1, 1}}], { t, -1, 2.9, 0.1}];SelectionMove[EvaluationNotebook[], All, GeneratedCell]FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate]Bobby-----Original Message-----Put this after the Plot statement, in the same cell:SelectionMove[EvaluationNotebook[], All, GeneratedCell]FrontEndTokenExecute[OpenCloseGroup] FrontEndTokenExecute[SelectionAnimate]Bobby Treat-----Original Message-----Is it possible to tidy up the generation of the graphic so that itbecomesthe animation?I have tried the followingDo[Plot[Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1, 1}},ImageSize -> 400]; SelectionMove[EvaluationNotebook[], All, GeneratedCell];FrontEndExecute[{FrontEnd`SelectionAnimate[0.1 ]}]; FrontEndExecute[{FrontEndToken[Clear]}], {t, 0, 15, 0.1}]This works but the cell dividing line ßashes on and off spoiling theanimation and if there is anything in the cell below this jumps up anddown.Is there a proper way of doing this?Hugh Goyder ==== ThatÕs nice because it avoids watching the frames being slowly created,and the group doesnÕt always collapse as it should, the way IÕve beendoing it.However, a couple of small changes give a smoother animation with 64frames rather than 151, while GENERATING only 33 frames.Block[{$DisplayFunction = Identity, half, graphs, step = Pi/32}, half = Table[GraphicCell[Plot[Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1, 1}}, ImageSize -> 400]], {t, -Pi/2, Pi/2 - step, step}]; graphs = Rest@Join[half, Rest@Reverse@half]; NotebookWrite[EvaluationNotebook[], Cell[CellGroupData[graphs,Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}]]Bobby-----Original Message----->showing during generation is enough (but uncontrolled).>Hugh GoyderThis creates a graphics cell from a graphics expression.GraphicCell[graphics_] := Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics]cellgroup.Block[{$ DisplayFunction=Identity, graphs}, graphs = Table[GraphicCell[ Plot[Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1,1}}, ImageSize -> 400]], {t,0,15,.1}]; NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs, Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}] ]------------------------------------------------------------ --Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== IÕm woking on a kind of a Mathematica cheat-sheet. So I donÕt have to repeatthe same learning process if I get pulled away for another 6 months.IÕve attempted to get my domain name to resolve to my IP address, but it seems Verisign and I have different ideas about what 24 hours is.The site is supposed to be www.globalsymmetry.com, but that will not currently resolve. HereÕs the IP and path:http://66.92.149.152/proprietary/com/wri/index.htmlThis is not a literary masterpiece. ItÕs probably proof that giving just anybody the power to publish is, perhaps, not a guaranty that more quality publication will take place.If anybody has answers to the questions IÕve come up with, or comments about the answeres, etc. IÕd be happy to know. ==== Edit ->Preferences -> Font OptionsIn Preferences you will find everything you need to configure yourMathematica environment. Also you may want to look up Style Sheets in thebook or the on line help.Yas> IÕve been trying to get my Mathematica 4.1 properly configured.> I set:> ############################################################# ######> /usr/local/mathematica/SystemFiles/FrontEnd/TextResources/X/ Specific.tr:> @@resource maxForXListFonts> 10000> # xlsfonts | wc -l> 5572> /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/local/mma/Type1> FontPath /usr/X11R6/lib/X11/fonts/local/mma/X:unscaled> 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> # ls -R /usr/X11R6/lib/X11/fonts/ | grep /> /usr/X11R6/lib/X11/fonts/:> /usr/X11R6/lib/X11/fonts/100dpi:> /usr/X11R6/lib/X11/fonts/75dpi:> /usr/X11R6/lib/X11/fonts/CID:> /usr/X11R6/lib/X11/fonts/Speedo:> /usr/X11R6/lib/X11/fonts/Type1:> /usr/X11R6/lib/X11/fonts/URW:> /usr/X11R6/lib/X11/fonts/encodings:> /usr/X11R6/lib/X11/fonts/encodings/large:> /usr/X11R6/lib/X11/fonts/kwintv:> /usr/X11R6/lib/X11/fonts/latin2:> /usr/X11R6/lib/X11/fonts/latin2/Type1:> /usr/X11R6/lib/X11/fonts/local:> /usr/X11R6/lib/X11/fonts/local/mma:> /usr/X11R6/lib/X11/fonts/local/mma/Type1:> /usr/X11R6/lib/X11/fonts/local/mma/X:> /usr/X11R6/lib/X11/fonts/misc:> /usr/X11R6/lib/X11/fonts/misc/sgi:> /usr/X11R6/lib/X11/fonts/truetype:> /usr/X11R6/lib/X11/fonts/uni:> /usr/X11R6/lib/X11/fonts/util:> ########################################################> When I open the Mathematica Book Reference Guide in the Help Browser, I get> a beep and the message says:> Unable to find font with family Helvetica, weight Bold, slant Plain, and> size 26. Substituting Courier.> Compared to the things which *were* broken, this is a minor problem. I can> live with the beep. What I would now like to know is how to tell Mathematica what> fonts to use by default. This seemingly simple question seems to have no> simple answer.> Could someone please help me.> TIA,> ^L ==== > Edit ->Preferences -> Font Options> In Preferences you will find everything you need to configure your> Mathematica environment. Also you may want to look up Style Sheets in the> book or the on line help.> Yas> I went into the preferences browser, and it was not clear to me what I was modifying. At one point I clicked on a field filled with text. I had inteded to edit it, and all the text vanished. It didnÕt bother me as much as such things use to, because I believe I know a backout strategy. ItÕs been a while since I looked at this stuff, and I have to admit it seems far more tractible than it did a year ago. IÕll look at the discussion again, and see if it makes more sence to me now.STH ==== > As an example, I spent several hours trying to figure out how to tell> Mathematica to understand the delete key in the way most contemporary> systems understand it. I wanted to avoid modifying system> configuration files such as:> /usr/local/mathematica/SystemFiles/FrontEnd/TextResources/ KeyEventTranslations.tr> I expected to be able to change something in my own ~/.Mathematic> directory, but I could not figure out an obvious way to affect this> modification.If you could post a precise description of what you expect the Delete keyto do when depressed, we could probably provide you with a clear cutanswer of what needs to be done.> I want to adjust the font size used in the widgets, but again, I see> no ovbious means of modifying these attributes. I suspect it can be> accomplished by modifying the ~/.Mathematica/4.1/FrontEnd/init.m.> Perhaps to an experienced Mathematica user, the syntax and semantics> of this file are obvious. They arenÕt to me.The size of fonts in user interface elements is not specified through theMathemtica init.m file. It is set through an X resource. If you are notfamiliar with resources, you may want to track down an introductory texton the X Window System. Information on application-specific resourcesettings can be found in the Mathematica Getting Started Guide:http://documents.wolfram.com/v4/GettingStarted/ TroubleshootingUnixX.htmlThe setting that you would need to adjust is XMathematica*fontList. Thevalue of the resource is an X Logical Font Description field.> I also find the overall look & feel of the interface to be archaic.ThatÕs because Mathematica relies on the Motif library for user interfaceelements.http://www.opengroup.org/desktop/ motif.htmlThe appearance of these elements, such as the menu and scroll bars, wouldbe the same for any other Motif application, such as the DDD debugger orreleases of Netscape prior to verison 4.-- User Interface Programmer paulh@wolfram.comWolfram Research, Inc. ==== hi,> I sholdnÕt have to. If I start messing with X resource settings for my> user environment, I am sure to break something else which is configured> based on the current settings. There should either be a GUI interface, or a> clearly documented, and easily accessible configuration file to modify such> properties as the size of the fonts in the GUI widgets. This is> functionality which is rightfully expected of a modern desktop UI.[snip]> And IÕm sure there is some configuration file in which I could place that,> and hope that what you think will be read by my system *will* in fact be> read, and not subsequently overridden during xsession startup. Things> arenÕt the way they used to be back in the 1980s. The modern Unix desktop> has moved beyond the paradigm of openlook and motif. See for example> http://www.trolltech.com, http://www.gnome.org, and http://www.kde.orgmoving the frontend over to QT would have some neat side effects: consistent look & feel with the modern linux gui, themeability, source code 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 :-))gerald -- *************************************Gerald RothM@th Desktop Development************************************* ==== > If you could post a precise description of what you expect the Delete key> to do when depressed, we could probably provide you with a clear cut> answer of what needs to be done.Item[KeyEvent[Delete], DeleteNext]ÕMost' means Ômore than half.'>> I want to adjust the font size used in the widgets, but again, I see>> no ovbious means of modifying these attributes. I suspect it can be>> accomplished by modifying the ~/.Mathematica/4.1/FrontEnd/init.m.>> Perhaps to an experienced Mathematica user, the syntax and semantics>> of this file are obvious. They arenÕt to me.> The size of fonts in user interface elements is not specified through the> Mathemtica init.m file. It is set through an X resource. If you are not> familiar with resources, you may want to track down an introductory text> on the X Window System. I sholdnÕt have to. If I start messing with X resource settings for my user environment, I am sure to break something else which is configured based on the current settings. There should either be a GUI interface, or a clearly documented, and easily accessible configuration file to modify such properties as the size of the fonts in the GUI widgets. This is functionality which is rightfully expected of a modern desktop UI.> Information on application-specific resource> settings can be found in the Mathematica Getting Started Guide:> http://documents.wolfram.com/v4/GettingStarted/ TroubleshootingUnixX.htmlIt should be in a clear and easy to access configuraton interface, or at least be redily available through the help system in such a way that reasonable queries will locate it. Changing fonts does not belong in a section on trouble shooting, unless this is an acknowledgement that the UI is broken.> The setting that you would need to adjust is XMathematica*fontList. The> value of the resource is an X Logical Font Description field.And IÕm sure there is some configuration file in which I could place that, and hope that what you think will be read by my system *will* in fact be read, and not subsequently overridden during xsession startup. Things arenÕt the way they used to be back in the 1980s. The modern Unix desktop has moved beyond the paradigm of openlook and motif. See for example http://www.trolltech.com, http://www.gnome.org, and http://www.kde.org >> I also find the overall look & feel of the interface to be archaic.> ThatÕs because Mathematica relies on the Motif library for user interface> elements.> http://www.opengroup.org/desktop/motif.html> The appearance of these elements, such as the menu and scroll bars, would> be the same for any other Motif application, such as the DDD debugger or> releases of Netscape prior to verison 4.My point exactly. ==== Awk! Legends!Basically, the answer to your question is that the PlotLegend option worksONLY for the Plot command and does not work for other types of plots. Forother types of plots you have to use ShowLegend. And ShowLegend is not allthat easy to use, especially since WRI does not give an example for multiplecurves in the Help.Needs[Graphics`Graphics`]Needs[Graphics`Legend`]{q1[t_], q2[t_], q3[t_]} = {0.1 Exp[-0.02 t], 0.2 Exp[-0.025 t], 0.4 Exp[-0.028 t]};LetÕs look at your first plot.Plot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> {{AbsoluteThickness[0.5], AbsoluteDashing[{4, 4}]}, AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1, 8}]}}, AxesLabel -> {Y, X}, PlotLabel -> Title, PlotLegend -> {1, 3, 5}, LegendPosition -> {0.5, 0}, ImageSize -> 500];The legend is almost as big as the plot. It distracts from the realinformation you are trying to convey. Furthermore, the order of the curvesin the legend is the reverse of their order in the plot.The following shows how to put the legend in a LogLogPlot, or other types ofplots. I defined the plot styles independently because they are used inseveral places. I made the legend much smaller and put it in an empty areaof the plot. I also reversed the order of the keys so they would match theorder of the curves in the plot.styles={{AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]},{AbsoluteThickness[1.5]},{ AbsoluteThickness[ 2],AbsoluteDashing[{1,8}]}};ShowLegend[ LogLogPlot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> styles, AxesLabel -> {Y, X}, PlotLabel -> Title, ImageSize -> 500, DisplayFunction -> Identity], {MapThread[{Graphics[{Sequence @@ #1, Line[{{0, 0}, {1, 0}}]}], #2} &, {styles, {1, 3, 5}}] // Reverse, LegendPosition -> {-0.7, -0.4}, LegendSize -> {0.2, 0.3}, LegendShadow -> {0.02, -0.02}, LegendSpacing -> 0.5} ];But why use a legend at all? After all, a legend is nothing but another plotin which you have put labels on the curves. Why not put the labels directlyon the curves in the real plot in the first place?LogLogPlot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> styles, AxesLabel -> {Y, X}, PlotLabel -> Title, ImageSize -> 500, Epilog -> MapThread[ Text[SequenceForm[Case , #1], {Log[10, 0.01], Log[10, #2[0.01]]}, {0, -1}] &, {{1, 2, 3}, {q1, q2, q3}}]];In the legend you have keyed the curves to numbers 1, 3 and 5. (Perhaps youjust used these as examples and meant to use something different in the realplots?) But these donÕt seem to have any obvious relation to your functions.I suppose the reader will have to look at another table or look into thetext of your paper or notebook to find out what 1, 3 and 5 mean. So thereader has to go from the graph to the legend then to the text and thenmentally transfer the meaning of the curve back to the main plot. It is somuch nicer to put the meaning right on the curve if you can.For the most part, legends are just computer junk and not even easy tonicely construct. When the legend urge comes over you - try to resist.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1,8}]}}, AxesLabel[Rule]{Y, X}, PlotLabel[Rule]Title, PlotLegend[Rule]{1,3,5}, LegendPosition[Rule] {0.5,0}](*However with LogPlot or LogLogPlot the legend desappear*)LogLogPlot[{q1[t],q2[t],q3[t]}, {t, 0, 100},PlotStyle[Rule]{ {AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]}, AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1,8}]}}, AxesLabel[Rule]{Y, X}, PlotLabel[Rule]Title, PlotLegend[Rule]{1,3,5}, LegendPosition[Rule] {0.5,0}]I have shown a particular case, but I has this problem always with LegendandLogPlot and LogPlotPlot. I will appreciate any help.GuillermoSanchez---------------------------------------- -----This message was sent using Endymion MailMan. ==== Using the Front End as a interface with the kernel I was running some calulations when suddenly pressing Shift+Enter causes the contents of the cell being evaluated to transform to the next text underlined with a red line: NotebookObject[FrontEndObject[LinkObject[dd8,1,1]],8] foollowed by the next messages:An unknown box name (NotebookObject) was sent as the BoxForm for the expression. Check the format rules for the expression.An unknown box name (FrontEndObject) was sent as the BoxForm for the expression. Check the format rules for the expression.An unknown box name (LinkObject) was sent as the BoxForm for the expression. Check the format rules for the expression.An invalid typeset structure was generated: Missing BoxFormData.Any suggestions will be very aprreciated.Cesar ==== I have an odd problem. I need to use and simplify functions that havebeen provided by a piece of software that insists on outputing thefunctional results of a data mining proceedure, using e whenoutputing numbers in scientific notation.IÕm having difficultly using Replace, Hold, etc. to correctly evaluatethese types of function formats. For example, y = 5e+5x1+2e-1x2,should be transcribed into 5 10^5 x1 + 0.2 x2.ChuckReply-To: kuska@informatik.uni-leipzig.de ==== str = 5e+5x1+2e-1x2;StringJoin[Characters[str] /. e -> *10^] // ToExpression??Work fine for me.But this type of output is typical generated by a C/FORTRANProgram and you should rewrite the formating rules inthe code that produce this output. Jens> I have an odd problem. I need to use and simplify functions that have> been provided by a piece of software that insists on outputing the> functional results of a data mining proceedure, using e when> outputing numbers in scientific notation.> IÕm having difficultly using Replace, Hold, etc. to correctly evaluate> these types of function formats. For example, y = 5e+5x1+2e-1x2,> should be transcribed into 5 10^5 x1 + 0.2 x2.> Chuck ==== RB> I am considering the following integralRB> W[m_,n_]:=Integrate[BesselJ[m, x]*BesselJ[n, x], {x, 0, Infinity}]RB> where m,n are reals >=0. With Mathematica 4.1 I obtain:RB> If[Re[m+n]>-1, -Cos[(m-n)Pi/2]/(2 Pi)*RB> (2 EulerGamma + Log[4] +RB> PolyGamma[0, 1/2(1 + m - n)] +RB> PolyGamma[0, 1/2(1 - m + n)] +RB> 2PolyGamma[0, 1/2(1 + m + n)])RB> Any explanation about the analytical expression will beRB> gratefully accepteed.The expression for W[m_,n_] returned by Mathematica is wrong.To prove, just substitute m = n = 0 which is exactly what you had doneand observe that the output you had hadW[0,0]=-(2 EulerGamma + Log[4] + 4 PolyGamma[0, 1/2])/(2 Pi)= 0.84564was incorrect. The correct answer is 1/2.Mathematica can handle the numeric integration successfullyIn[1] := NIntegrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}, Method -> Oscillatory] (* The warnings are skipped *)Out[1] = 0.5Using NIntegrate[BesselJ[0, x]*BesselJ[0, x], {x, 0, Infinity}]without Method -> Oscillatory is not the optimal choice asthe integrand oscillates fairly rapidly over the integrationregion.RB> I suspect that these integrals are divergent (*).In fact, not exactly.Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]is equal to 1/2, and Mathematica 4.1 for Microsoft Windows(November 2, 2000) does it correctly, while Mathematica 4.2for Microsoft Windows (February 28, 2002) concocts a strangemixture of a wrong divergence message and the warning thatit cannot check the convergence [should I trust to the secondwarning? or the first?]As a matter of fact,Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]converges because the integrand is regular at x=0, bounded overthe whole right semi-axis, and decays as2*Cos[Pi/4 - x]*Cos[(3*Pi)/4 - x]/(Pi*x) + o(1/x)at x -> Infinity .Say, calculateNormal[Series[BesselJ[1, x], {x, Infinity, 1}]] Normal[Series[BesselJ[0, x], {x, Infinity, 1}]] // InputForm->(2*(Cos[Pi/4 - x] - Sin[Pi/4 - x]/(8*x))*(Cos[(3*Pi)/4 - x] +(3*Sin[(3*Pi)/4 - x])/(8*x)))/(Pi*x)then Plot[%,{x,1,10}]and Plot[BesselJ[1,x]*BesselJ[0,x],{x,1,10}]and you could hardly see the difference.Generally, to get to the convergence domain for W in terms ofm and n is easy via the asymtotics of the Bessel functions(use something likeExpand[Normal[Series[BesselJ[m, x], {x, Infinity, 1}]]Normal[Series[BesselJ[n, x], {x, Infinity, 1}]]]then analyze the main term).Best wishes,Vladimir BondarenkoMathematical DirectorSymbolic Testing GroupWeb : http://www.CAS-testing.org/ http://maple.bug-list.org/VER2/ (under tuning) http://maple.bug-list.org/VER3/ (under tuning) http://maple.bug-list.org/VER1/ (under tuning) http://www.beautyriot.com/ (teamwork) http://www.ohaha.com/ (teamwork) Voice: (380)-652-447325 Mon-Fri 9 a.m. - 6 p.m.Mail : 76 Zalesskaya Str, Simferopol, Crimea, Ukraine ==== > inside a program I need to solve this linear equation in terms of p1.> However something odds happens. Sometimes the solution is computed and> sometimes the result is empty [I mean no output...]. Is this a bug of the> solve command or am I doing something wrong? The problem is robust to:> changing name to the variables and other makeups..> DavidThatÕs the weirdest bug IÕve seen in weeks. As it happens, itÕs mine. Atleast the inconsistent behavior, that is. IÕll fix it, and maybe alsotry to address the issue of how to handle approximate numbers in testingsubexpressions for zero.IÕve excised your code and put in place a substantially smaller examplethat I believe is responsible. The table will tend to give erraticresults.zz = (-1.*x^7*(-1. + p - 7.*x^6 + p*x^6 + 6.*x^7)* (7.000000000000002 - 7.000000000000002*x + 14.000000000000004*x^6 - 14.000000000000004*x^7 + 7.000000000000002*x^12 -6.999999999999998*x^13))/ (p^2*(1. + 0.9*x^6)^2*(1. + x^6)^5);One workaround would be to use exact input, say by preprocessing withRationalize.Daniel LichtblauWolfram Research ==== >inside a program I need to solve this linear equation in terms of p1.>However something odds happens. Sometimes the solution is computed and>sometimes the result is empty [I mean no output...]. Is this a bug of the>solve command or am I doing something wrong? The problem is robust to:>changing name to the variables and other makeups..>David>ps: Sorry for the stupid way in which I copied the command...>Solve[(x^2*((-0.9*x^7*(p^2*(-1 - 5.8*x^6 - 14.010000000000002*x^12 -> 18.04*x^18 - 13.06*x^24 -> 5.040000000000001*x^30 - 0.81*x^36) +> x*(7.777777777777779 - 9.074074074074076*x +> 30.333333333333336*x^6 -> 21.51851851851852*x^7 -> 16.333333333333336*x^8 +> 44.33333333333334*x^12 +> 3.188888888888883*x^13 -> 65.68333333333332*x^14 +> 28.777777777777786*x^18 +> 47.937037037037044*x^19 -> 100.10000000000002*x^20 + 7.*x^24 +> 45.6037037037037*x^25 -> 69.53333333333333*x^26 +> 13.299999999999999*x^31 -> 19.833333333333332*x^32 -> 1.0499999999999996*x^38) +> p*(-6 + 8.296296296296296*x -> 28.799999999999997*x^6 +> 32.785185185185185*x^7 +> 9.333333333333336*x^8 -> 55.260000000000005*x^12 +> 49.04777777777776*x^13 +> 38.38333333333334*x^14 -> 52.980000000000004*x^18 +> 34.20518518518518*x^19 +> 60.20000000000001*x^20 -> 25.380000000000003*x^24 +> 11.736296296296294*x^25 +> 43.63333333333334*x^26 - 4.86*x^30 +> 2.8999999999999986*x^31 +> 13.533333333333333*x^32 + 0.81*x^37 +> 1.0499999999999996*x^38)))/(x + 1.9*x^7 +> 0.9*x^13)^2 - ((-1 + p - 7*x^6 + p*x^6 +> 6*x^7)*(1.2962962962962965 - 3.111111111111112*x^6>+> 9.333333333333336*x^7 - 10.111111111111114*x^12>+> 22.05*x^13 - 5.703703703703705*x^18 + 17.15*x^19>+> 5.483333333333331*x^25 + 1.0499999999999996*x^31>+> p1*x^5*(7.000000000000002 - 7.000000000000002*x>+> 14.000000000000004*x^6 -> 14.000000000000004*x^7 +> 7.000000000000002*x^12 -> 6.999999999999998*x^13) -> 1.166666666666667*p*x^4*x1 -> 3.500000000000001*p*x^10*x1 -> 1.0500000000000003*p*x^11*x1 -> 3.500000000000001*p*x^16*x1 -> 3.150000000000001*p*x^17*x1 -> 1.166666666666667*p*x^22*x1 -> 3.150000000000001*p*x^23*x1 -> 1.0500000000000003*p*x^29*x1))/((1 + 0.9*x^6)^2*(1>+> x^6)^2)))/(p^2*(1 + x^6)^3) == 0, p1]You might find it more robust (and the results cleaner) if you Simplify the equation prior to using Solve. Such asSolve[eqn // Rationalize // Simplify, p1]However, if you are assigning values to p or x prior to using Solve, there may not be a solution. That is, for whenever the numerator of the expression for p1 would be zero, e.g., p = (-6 x^7 + 7 x^6 +1)/(x^6 + 1).Bob Hanlon ==== > Could someone calculate the number Pi to 67,108,864 (2^26) decimal places> I made the calculation in another program and would like to verify itsDoes it really matter what program is used to verify it? If not,hereÕs the digits (computed with the fastest pi crunching program fora PC):33863220896223409803 ==== >>I believe the complexity is O(n log n), so this should be good enough.Umm ...good enough? I understand the words individually, but thephrase makes no sense to me.Bobby Treat-----Original Message-----> crash the Front End. I was thinking about the fact that I calculated> all those digits and then threw them away. I could save them withSave> or DumpSave, and read them in with Get the next time I wanted any of> them, although the file would be close to 70 MB (if not more). I maydo> that, in fact -- I have plenty of disk space.> The next step would be to somehow reuse the stored digits if I wanted> MORE digits. But how?> The Bailey-Borwein-Plouffe Pi algorithm is an avenue of attack, sinceit> can calculate digits far from the decimal point, without calculating> those in between. Unfortunately, it calculates hexadecimal digits in> that way, not decimal digits. (ThatÕs true for the version IÕve seen,> anyway.) Still, I could take the stored digits, convert tohexadecimal,> add more hexadecimal digits with the B-B-P algorithm, and then convert> back to decimal. In both conversions, IÕd have to be very cognizantof> how much precision I end up with, but that shouldnÕt be too difficult.> It might go faster if I store hexadecimal digits, as well as decimal> digits, to eliminate one of those conversions at each increase in the> number of digits.> The next step would be to set up an application that allowed anyone to> ping for digits across the Internet, and would return them if theyÕre> stored.> HasnÕt someone already done that? It seems as if someone would have.> Bobby TreatIf youÕre interested in decimal digits, I donÕt think the BBP algorithmis theway to go. In order to get the nth decimal digit of Pi you need tocompute theprevious n-1 digits, since base conversion is global, not local. ThealgorithmMathematica uses for computing Pi is quite fast - I believe thecomplexity is O(nlog n), so this should be good enough.David> -----Original Message-----calculation in> So would it take about the same amont of time for the completeprintout> of digits? Of course it would take a few additional seconds to format> the output...> Or does Mathematica take alot less time when it truncates the output?> >Could you tell me the CPU you used and its speed etc...i amcurious,performance> to>> other programs out there.> > I used one processor of a dual 1GH Mac and got the same answer with> the>following speed:> > 4.2 for Mac OS X (June 4, 2002)>oldmax = $MaxPrecision> 6>1. 10>$MaxPrecision = Infinity>Infinity>With[{n = 2^26}, Timing[> pd = RealDigits[N[Pi, n + 1], 10, 20,> 19 - n]; ]]>{28794.1 Second, Null}>MaxMemoryUsed[]>512055204>pd>{{3, 3, 8, 6, 3, 2, 2, 0, 8, 9, 6, 2, 2, 3,> > 4, 0, 9, 8, 0, 3}, -67108844}> > Tom Burton ==== I prefer to delete all output and then Copy As>Notebook expression. ItBobby-----Original Message-----andoutput --- I try to use one tab indent for input and two tabs indent foroutput, plus some blank line adjustment.I wonder if anyone has a way of automatically achieving thisreformating.--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Often posters to MathGroup copy and paste in the complete cellexpression,> including the In and Out numbers, when posting to MathGroup.> I wonder if this is the best method because one canÕt then just copyoutall> the statements and paste them into a Mathematica notebook. All thestatement> numbers have to be edited out and if there are many statementdefinitions> this is an extended task for any responder. This, of course, decreasesthe> chances for a response. A better method is for the poster to just copyand> paste the CONTENTS of each cell. This is more work for the poster, butit> may pay off in better responses.> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/ ==== 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]:=fOut[6]=-1.1805916207174113*^21In[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]:=gOut[9]=-(54767/66192)In[10]:=N[%]Out[10]=- 0.8273960599468214PK ==== Peter,I hope that the following example will help - it is a matter or when thingsevaluate.The a in SetAccuracy[a, Infinity], below, evaluates before SetAccuracy acts,so we getSetAccuracy[2.3, Infinity]. The value of a is not changed. a = 2.3; aa = SetAccuracy[a, Infinity] 2589569785738035/1125899906842624But, a 2.3Whereas aa 2589569785738035/1125899906842624--Allan--------------------- Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> 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 ==== In receiving notebooks from many different people I have noticed thatbeginners often do not know how to use Text cells and write all of theircomments as Input cells. I have even run across some extremely advancedusers who did not know the easy method for entering Text cells. A goodnotebook is usually a blend of Text cells, Input/Output cells and graphicscells. Text cells are very useful for documenting what you are doing andpassing information to other people. Since many people do not know how touse Text cells, I thought I would write a little explanation for beginnerswho are followers of MathGroup.The very easiest method for entering a Text cell is to put the insertionpoint where you want the new cell to be (at the end of the notebook orbetween two existing cells) and then type Alt-7. Then just start typing andyou will have a Text cell.Alternatively you can use MenuFormatStyleText to start a new Text cell.Often, it is useful to put the ToolBar at the top of the notebook. UseMenuFormatShow ToolBar. The drop-down menu on the ToolBar has the variouskinds of cells available for the current style of the notebook. You canselect Text (or any other style) from there.Some users may hesitate to use Text cells because they want to include amathematical expression in the comments. However, that is also very easy.Just use an Inline cell within the text cell. At the point within the textcell where you want to include a mathematical expression, start an Inlinecell by typing Ctrl-(. A selection placeholder will appear on a pinkbackground. You can type a Mathematica expression there just as in an Inputcell. Use Ctrl-) to complete the Inline cell, or Shift-Space. You can evenselect an Inline cell and evaluate it with Shift-Ctrl-Enter.Putting comments in Text cells is far better than using Input cells (or cellgroup header cells). Mathematica wonÕt try to evaluate Text cells, the textwill wrap properly and adjust better to the notebook width if you change it.You can also check the spelling of words by putting the cursor after a wordand using Ctrl-K. (In an Input cell Mathematica doesnÕt use the dictionary,but uses the table of symbols instead and hence it wonÕt check spelling.)David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== This is because inline cells are not in StandardForm by default, but TraditionalForm.Use the menu item Cell -> Default Inline Format Type -> StandardForm.>David ParkÕs posting reminded me of a frequent annoyance when I am>trying to include some Mathematica expressions within text cells -- a>Mathematica input expression in Standard Form that involves use of a>Control-key combination to form a superscript, square-root, or built-up>fraction:>For example, suppose I want to include within a text cell a Standard>Form expression for the square of x, with the exponent 2 raised. If I>type the x first, even if I immediately highlight it and change it to>Courier (to match the default font for Input cells in Standard Form), as>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-------------------------------------------------------- ------Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.htmlReply-To: murray@math.umass.edu ==== David ParkÕs posting reminded me of a frequent annoyance when I am trying to include some Mathematica expressions within text cells -- a Mathematica input expression in Standard Form that involves use of a Control-key combination to form a superscript, square-root, or built-up fraction:For example, suppose I want to include within a text cell a Standard Form expression for the square of x, with the exponent 2 raised. If I type the x first, even if I immediately highlight it and change it to Courier (to match the default font for Input cells in Standard Form), as 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.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375 ==== correctly, all you need to do is to make sure the default inline cell formatis StandardForm. Go to the menu item Cell, select Default Inline FormatType,and change it to StandardForm.Carl WollPhysics DeptU of Washington----- Original Message -----> type the x first, even if I immediately highlight it and change it to> Courier (to match the default font for Input cells in Standard Form), as> 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 theexponent!)> 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 01375Reply-To: kuska@informatik.uni-leipzig.de ==== just one comment: the meaning of the Alt-7 key depend on the style sheet that is in use.The TMJ style use Alt-8 for text and one hasto learn new key short-cuts for every style sheet ! Jens> In receiving notebooks from many different people I have noticed that> beginners often do not know how to use Text cells and write all of their> comments as Input cells. I have even run across some extremely advanced> users who did not know the easy method for entering Text cells. A good> notebook is usually a blend of Text cells, Input/Output cells and graphics> cells. Text cells are very useful for documenting what you are doing and> passing information to other people. Since many people do not know how to> use Text cells, I thought I would write a little explanation for beginners> who are followers of MathGroup.> The very easiest method for entering a Text cell is to put the insertion> point where you want the new cell to be (at the end of the notebook or> between two existing cells) and then type Alt-7. Then just start typing and> you will have a Text cell.> Alternatively you can use MenuFormatStyleText to start a new Text cell.> Often, it is useful to put the ToolBar at the top of the notebook. Use> MenuFormatShow ToolBar. The drop-down menu on the ToolBar has the various> kinds of cells available for the current style of the notebook. You can> select Text (or any other style) from there.> Some users may hesitate to use Text cells because they want to include a> mathematical expression in the comments. However, that is also very easy.> Just use an Inline cell within the text cell. At the point within the text> cell where you want to include a mathematical expression, start an Inline> cell by typing Ctrl-(. A selection placeholder will appear on a pink> background. You can type a Mathematica expression there just as in an Input> cell. Use Ctrl-) to complete the Inline cell, or Shift-Space. You can even> select an Inline cell and evaluate it with Shift-Ctrl-Enter.> Putting comments in Text cells is far better than using Input cells (or cell> group header cells). Mathematica wonÕt try to evaluate Text cells, the text> will wrap properly and adjust better to the notebook width if you change it.> You can also check the spelling of words by putting the cursor after a word> and using Ctrl-K. (In an Input cell Mathematica doesnÕt use the dictionary,> but uses the table of symbols instead and hence it wonÕt check spelling.)> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/ ==== Solve[youre equation, p1, VerifySolutions->True] will return a solution. So willSolve[Rationalize[your equation],p1].Andrzej KozlowskiToyama International UniversityJAPAN> inside a program I need to solve this linear equation in terms of p1.> However something odds happens. Sometimes the solution is computed and> sometimes the result is empty [I mean no output...]. Is this a bug of > the> solve command or am I doing something wrong? The problem is robust to:> changing name to the variables and other makeups..> David> ps: Sorry for the stupid way in which I copied the command...> Solve[(x^2*((-0.9*x^7*(p^2*(-1 - 5.8*x^6 - 14.010000000000002*x^12 -> 18.04*x^18 - 13.06*x^24 -> 5.040000000000001*x^30 - 0.81*x^36) +> x*(7.777777777777779 - 9.074074074074076*x +> 30.333333333333336*x^6 -> 21.51851851851852*x^7 -> 16.333333333333336*x^8 +> 44.33333333333334*x^12 +> 3.188888888888883*x^13 -> 65.68333333333332*x^14 +> 28.777777777777786*x^18 +> 47.937037037037044*x^19 -> 100.10000000000002*x^20 + 7.*x^24 +> 45.6037037037037*x^25 -> 69.53333333333333*x^26 +> 13.299999999999999*x^31 -> 19.833333333333332*x^32 -> 1.0499999999999996*x^38) +> p*(-6 + 8.296296296296296*x -> 28.799999999999997*x^6 +> 32.785185185185185*x^7 +> 9.333333333333336*x^8 -> 55.260000000000005*x^12 +> 49.04777777777776*x^13 +> 38.38333333333334*x^14 -> 52.980000000000004*x^18 +> 34.20518518518518*x^19 +> 60.20000000000001*x^20 -> 25.380000000000003*x^24 +> 11.736296296296294*x^25 +> 43.63333333333334*x^26 - 4.86*x^30 +> 2.8999999999999986*x^31 +> 13.533333333333333*x^32 + 0.81*x^37 +> 1.0499999999999996*x^38)))/(x + 1.9*x^7 +> 0.9*x^13)^2 - ((-1 + p - 7*x^6 + p*x^6 +> 6*x^7)*(1.2962962962962965 - > 3.111111111111112*x^6 +> 9.333333333333336*x^7 - > 10.111111111111114*x^12 +> 22.05*x^13 - 5.703703703703705*x^18 + > 17.15*x^19 +> 5.483333333333331*x^25 + > 1.0499999999999996*x^31 +> p1*x^5*(7.000000000000002 - > 7.000000000000002*x +> 14.000000000000004*x^6 -> 14.000000000000004*x^7 +> 7.000000000000002*x^12 -> 6.999999999999998*x^13) -> 1.166666666666667*p*x^4*x1 -> 3.500000000000001*p*x^10*x1 -> 1.0500000000000003*p*x^11*x1 -> 3.500000000000001*p*x^16*x1 -> 3.150000000000001*p*x^17*x1 -> 1.166666666666667*p*x^22*x1 -> 3.150000000000001*p*x^23*x1 -> 1.0500000000000003*p*x^29*x1))/((1 + > 0.9*x^6)^2*(1 +> x^6)^2)))/(p^2*(1 + x^6)^3) == 0, p1]Reply-To: murray@math.umass.edu ==== For all names, perhaps: Names[*`*]For names you defined at a normal session (without changing to some other context than the default Global`): Names[Global`*]> IIRC, there is a way to get a list of all the symbols defined in the > currently running session. I canÕt seem to find the reference to that > command. Could somone point me in the direction of documentation which > will tell me how to get information about the current session?> TIA,> -- Murray Eisenberg murray@math.umass.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375 ==== > For all names, perhaps:> Names[*`*]> For names you defined at a normal session (without changing to some> other context than the default Global`):> Names[Global`*]>> IIRC, there is a way to get a list of all the symbols defined in the>> currently running session. I canÕt seem to find the reference to that>> command. Could somone point me in the direction of documentation which>> will tell me how to get information about the current session?>>>> TIA,>>>> I think I asked the wrong question. IÕll have to look at things some more. What you gave me resulted in far more than I was looking for.http://public.globalsymmetry.com/proprietary/com/wri/ system-symbols.htmlhttp://66.92.149.152/proprietary/com/wri/ system-symbols.htmlI think I really hosed the code for generating that table. I used 5 lines. I probably didnÕt need more than two, but IÕm too tired right now to think about it. Mathematica is totaly awesome when it comes to what it was intended for. They really need to rent a Troll for a few months and fix this interface. Qt will run on just about anything. Heck, my Win-XP partition runs XFree86, with the KDE, or it did when I booted into XP a month ago.STH ==== ?*does the trick. You can limit it to Global variables with?Global`*Bobby-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== > Has anyone had any luck getting Mathematica 4.2 to work> on a Sun running Solaris 6?> I get the following error message when starting Mathematica:> ./Mathematica> ld.so.1: ./Mathematica: fatal: librt.so.1: open failed: No such file or> directory> Killed> But math works.> Any thoughts on this would be appreciated - even if itÕs just> Solaris 6 sucks - Reinstall with Solaris 8/9. IÕd rather not go to the> trouble of reinstalling the box unless absolutely necessary (It is a> 270mhz Ultra 5)IÕd be tempted to run Ôldd'and see what libraries it needs. On my Solaris 9box, with Mathematica 4.2 I see:wren /usr/local/stow/Mathematica-4.2/SystemFiles/FrontEnd/Binaries /Solaris % ldd../Mathematica libXt.so.4 => /usr/lib/libXt.so.4 libXext.so.0 => /usr/lib/libXext.so.0 libXmu.so.4 => /usr/lib/libXmu.so.4 libX11.so.4 => /usr/lib/libX11.so.4 libnsl.so.1 => /usr/lib/libnsl.so.1 libsocket.so.1 => /usr/lib/libsocket.so.1 libc.so.1 => /usr/lib/libc.so.1 libucb.so.1 => /usr/ucblib/libucb.so.1 librt.so.1 => /usr/lib/librt.so.1 libpthread.so.1 => /usr/lib/libpthread.so.1 libSM.so.6 => /usr/lib/libSM.so.6 libICE.so.6 => /usr/lib/libICE.so.6 libm.so.1 => /usr/lib/libm.so.1 libdl.so.1 => /usr/lib/libdl.so.1 libmp.so.2 => /usr/lib/libmp.so.2 libelf.so.1 => /usr/lib/libelf.so.1 libaio.so.1 => /usr/lib/libaio.so.1 libmd5.so.1 => /usr/lib/libmd5.so.1 /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1 libthread.so.1 => /usr/lib/libthread.so.1 /usr/platform/SUNW,Ultra-60/lib/libmd5_psr.so.1You should be able to find the libraries itÕs using, and hopefully it might justbe looking in the wrong place, in which case you may be able to create asymbolic link. However, if Solaris 2.6 is not supported (I donÕt know if it is) it is quitepossible it wants a library you donÕt have, in which case you are stuck unlessyou re-install a later OS. -- Dr. David Kirkby,Senior Research Fellow,Department of Medical Physics,University College London,11-20 Capper St, London, WC1E 6JA.Internal telephone: ext 46408 ==== 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-(-----) 66192Andrzej KozlowskiToyama International UniversityJAPAN> 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, Bobby, PeterIt looks as if using SetAccuracy succeeds here because the inexact numbersthat occur have finite binary representations. If we change them slightly toavoid 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 - 15640321149084868351974949239896188679725401538739519428131155 14949389123623452500771916869370459119776018798804630436149786 9199129319625743010292363124675/ 10867106143970760551000357827554793888198143135975649579607989 867743572824016 06539536129829321813712324363677397376040962) 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 HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +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> > ==== > Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]> is equal to 1/2, and Mathematica 4.1 for Microsoft Windows> (November 2, 2000) does it correctly, while Mathematica 4.2> for Microsoft Windows (February 28, 2002) concocts a strange> mixture of a wrong divergence message and the warning that> it cannot check the convergence [should I trust to the second> warning? or the first?]In[6]:=Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]Out[6]=1/2In[7]:=Out[7]=4.2 for Mac OS X (June 4, 2002)Andrzej KozlowskiToyama International UniversityJAPAN ==== That should read ...denominator of the expression for p1... Bob>You might find it more robust (and the results cleaner) if you Simplify>the >equation prior to using Solve. Such as>Solve[eqn // Rationalize // Simplify, p1]>However, if you are assigning values to p or x prior to using Solve, there>may not be a solution. That is, for whenever the numerator of the expression>for p1 would be zero, e.g., >p = (-6 x^7 + 7 x^6 +1)/(x^6 + 1).Bob Hanlon ==== > The expression for W[m_,n_] returned by Mathematica is wrong.> To prove, just substitute m = n = 0 which is exactly what you had done> and observe that the output you had had> W[0,0]=-(2 EulerGamma + Log[4] + 4 PolyGamma[0, 1/2])/(2 Pi)> = 0.84564> was incorrect. The correct answer is 1/2.> Mathematica can handle the numeric integration successfully> In[1] := NIntegrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity},> Method -> Oscillatory]> (* The warnings are skipped *)> Out[1] = 0.5YouÕll find that W[m=1,n=0]=1/2, so Mathematica gets that right. W[0,0]diverges. Mathematica gets that wrong.I note that Mathematica yields a result forIntegrate[BesselJ[m, a*x]*BesselJ[n, b*x], {x, 0, Infinity}]that appears to agree with formula 6.512(1) of Gradshteyn and Ryshik (4thed., 1965), including the condition b True]If the ziÕs need to be scaled, then you can do something like this:colorfn = Hue[.67#]&;With[{ m = {Min[#],Max[#]}&@vals }, Show[Graphics[ {colorfn[#[[3]]], PointSize[.01], Point[{#[[1]],#[[2]]}]}]& /@ (data /. {x_,y_,z_} -> {x, y, (z-m[[1]])/(m[[2]]-m[[1]])}), Axes -> True]]---Selwyn Hollis> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of > ==== John,It is easier to do without ListPlot:Make some data,dat= Table[Random[],{10},{3}];Show[Graphics[{PointSize[.05],{Hue[2 /3#3],Point[{#1,#2}]}&@@@dat} ], Frame->True ];If the points need to be joined then something likeShow[Graphics[{ Line /@Partition[dat[[All,{1,2}]],2,1], PointSize[.05],{Hue[2/3#3],Point[{#1,#2}]}&@@@dat } ], Frame->True ];--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of ==== A few years ago we made a package that do just this. Seehttp://cern.ch/jowett/Mathematica/Graphics/ ColorListPlot.htmlThe type of plot you want is covered in the section Examples thenThree-dimensional data. The Introduction gives links for downloading thepackage.JMJ> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of ==== Your problem can be solved in numerous ways of course, try something like .:Module[ { data=Flatten[Table[{x,y,Random[]},{x,10},{y,10}],1] }, Show[ Graphics[ { AbsolutePointSize[10], data/.{x_,y_,z_}[Rule]{Hue[z],Point[{x,y}]} } ] ,AspectRatio[Rule]Automatic ] ]Note that you can replace the main part, ie the transforming rule from pointlists to colored point directives with a function for example .:{Hue[#3],Point[{#1,#2}]}&@@@databye,Borut| I have a list of points l1={xi,yi,zi} how can I make a 2D list plot ofReply-To: kuska@informatik.uni-leipzig.de ==== data = Table[{Random[], Random[], Random[]}, {20}];Show[Graphics[ {Hue[Last[#]], Point[Take[#, 2]]} & /@ data, Axes -> True ] ] Jens> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of ==== input = 5e+5x1+2e-1x2;StringJoin[Characters[input] //. e -> *10^]5*10^+5x1+2*10^-1x2ToExpression[%]500000*x1 + x2/5Bobby Treat-----Original Message-----should be transcribed into 5 10^5 x1 + 0.2 x2.Chuck ==== Neither SetAccuracy[expr,n] nor SetPrecisions[expr,n] modify expr. These functions modify the prinout not the internal representation. So, the first computation of f is done with approximate numbers and doesnÕt result in a correct answer due to approximate arithmetic.By assigning a rational expression to each of the variables, you have made them exact numbers and Mathematica responds with an exact solution.>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 ==== SetAccuracy. However, I still donÕt understand why the order in which we set the accuracies for f, a, and b matters.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), Infinity]; a = SetAccuracy[77617., Infinity]; b = SetAccuracy[33096., Infinity]; In[4]:=fOut[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]=1180591620717411303424Similarily: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]:=fOut[4]=-0.8273960599468212641107299556`11.4133In[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 ==== Hallo,I have the problem, that I want to determine the numerical solution of a double integral, like e.g. the following:<< Statistics`ContinuousDistributions`ndist = NormalDistribution[0, 1];N[Sigma^2/(Abs[Mu_1^2 - Mu_2^2]) Integrate[(Integrate[1/y_1 1/(y - y_1) PDF[ndist, d*Log[y_1] + c*Log[y - y_1] + f]*PDF[ndist, Sigma*(c*Log[y_1] + d*Log[y - y_1] + g)], {y_1,0,y}]), {y,0,Lambda}]]wherebyLambda := 3;Mu_1 := 4;Mu_2 := 5;Sigma := 0.25;a = 1/2 (Mu_1^2 + Mu_2^2/Sigma^2)b = 1/2 (Mu_2^2 + Mu_1^2/Sigma^2)c = -Mu_2/(Mu_1^2 - Mu_2^2)d = -Mu_1/(Mu_2^2 - Mu_1^2)f = d*a + c*bg = c*a + d*bSorry for the poor code... The problem is, that Mathematica doesnÕt give me a result (after waiting 2 hours I turned my machine off).Thus, the question is, if there is still a possibility of solving such complicated expressions...TIA,Sven. ==== I am trying to solve a system of simultaneous equations with 26 variablesand 14 equations (the 12 free variables can be any of the 26 from the 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 eqnis degree 4 i believe.. and there are some cross terms in the equations butnot every equation depends on every variable.. (some are actually rathersimple 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.eduMany thanks,Nachi ==== I should add that the solution is over natural numbers.. this willprobably make a big difference..Nachi> I am trying to solve a system of simultaneous equations with 26 variables> and 14 equations (the 12 free variables can be any of the 26 from the 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 ==== This may seem like a trivial issue, but I find it very frustrating. I use variety of intellectual domains. In every package (JBuilder, KMail, Emacs, XEmacs, Mozilla, xterm, Konsole, etc.) the keyboar mapping is a bit differnt from the other. There are certain idioms which I find to be fairly invaraint between these different packages. I tend to use this common subset more than the package specific idioms.Switching from one package to the next can be a very disorienting experience. It can be even trickier to try and copy and paste from one to the next. I also use Ôspecial'characters in certain domains, .8d,?,.81,?,[CapitalYAcute],fi, §, ø, etc. Add to all of this, that I run beta code for just about everything. The function of my keyboard changed like the weather. I have spent hours trying to figure out why I can no longer type Ô.9aÕ. This doesnÕt even address the problems of switching between character encodings, or keyboard compose modes. The last thing I want to start doing is messing with the key mappings in my user environment. I want to control the way my keyboard works with Mathematica from within the Mathematica runtime environment. That is, the configuration should be loaded when Mathematica loads, and should not impact the rest of my X environment.If I have come across as a bit jaded regarding this issue, there are reasons. There is a history. I donÕt find keyboard configuration issues interesting. I want my fine keyboard to just work, the way I want it to Shift+point movement = select text.Ctrl+Insert = copyShift+Insert = pasteCtrl+c = copyCtrl+x = cutCtrl+v = pasteShift+End = select to end of line.etc.Yes, I said I use XEmacs, and Emacs. Yes (X)Emacs is different, but adding yet another alteration with Mathematica is just too much. Is there a way around this?STH ==== >FrontEndExecute[{> FrontEnd`NotebookWrite[FrontEnd`SelectedNotebook[],> [LeftDoubleBracket][RightDoubleBracket],After]}] FrontEndExecute[{ FrontEnd`NotebookWrite[FrontEnd`SelectedNotebook[], [LeftDoubleBracket][RightDoubleBracket],After], FrontEnd`SelectionMove[FrontEnd`SelectedNotebook[], Previous, Character]}]orFrontEndExecute[{ FrontEnd`NotebookWrite[FrontEnd`SelectedNotebook[], [LeftDoubleBracket][SelectionPlaceholder][RightDoubleBracket] , Placeholder]}]----------------------------------------------- ---------------Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== IÕm trying to address the special issues related to using Mathematica on the would not if I used a Windows system. These are typically not all that big if a problem _once I figure out whatÕs going on_. What I hope to do is collect all such matters and document them effectively in something like a havenÕt discussed here http://66.92.149.152/proprietary/com/wri/index.html IÕm interested in hearing what you have to say. Of particular interest are the issues faced by a person who is not familiar with the technical aspects would help make this less painful?STH ==== particular, the y-axis label is typically rotated by 90deg so that it readsup the y-axis. This works fine on macs and windoze, but under linux thelabel runs up the y-axis; however, the letters are rotated so that they arethe 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 atalk. I have mentioned this before, and the stock answer is that ... it isMathematica. I personally donÕt care why the label looks peculiar, just thatit does and that there is no easy workaround.--Kevin J. McCannJoint Center for Earth Systems Technology (JCET)Department of PhysicsUMBCBaltimore MD 21250> IÕm trying to address the special issues related to using Mathematica onthe> would not if I used a Windows system. These are typically not all thatbig> if a problem _once I figure out whatÕs going on_. What I hope to do is> collect all such matters and document them effectively in something like awhich I> havenÕt discussed here http://66.92.149.152/proprietary/com/wri/index.html> IÕm interested in hearing what you have to say. Of particular interestare> the issues faced by a person who is not familiar with the technicalaspects> would help make this less painful?> STHReply-To: jmt@dxdydz.net ==== See the MathLink API for C, or the JLink API for java.JLink is easier to use, MathLink is a lower level but native interface. JLink is built on MathLink.As far as I know, the perl API Math::ematica has not been upgraded to Mathematica 4.> Is it possible to get a document of the description of how to> interface with the kernel? Kind of what should an interface say to the> kernel and how to connect to it.> Paulo> ==== Is it possible to get a document of the description of how tointerface with the kernel? Kind of what should an interface say to thekernel and how to connect to it.Paulo ==== for your extensive answer but I still have some doubts about convergence of the following integral (m,nintegrers>=0)W[m_,n_]:=Integrate[BesselJ[m, x]*BesselJ[n, x], {x, 0, Infinity}]for wich Mathematica gives the close form W[m_,n_]:= -Cos[(m-n)Pi/2]/(2 Pi)* ( 2 EulerGamma + Log[4] + PolyGamma[0, 1/2(1 + m - n)] + PolyGamma[0, 1/2(1 - m + n)] + 2PolyGamma[0, 1/2(1 + m + n)] )You say this integral is convergent to 1/2 for m=0 and n=1.Also Mathematica agrees to you since for m>=0W[m,m+1]=1/2W[m,m+3]=-1/2Numerically we haveNIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, 0, Infinity}]NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy....0.597973NIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, 0, Infinity}, Method ->Oscillatory]NIntegrate::ploss : ....0.5So I define also the corresponding numeric definitionNW[m_, n_] := NIntegrate[BesselJ[m, x]*BesselJ[n, x], {x, 0, Infinity},Method -> Oscillatory]THEORYThe integral is the critical case of Weber-Schafheitlin integral(see Watson book on Bessel function p.402, or Ryzhik-Gradshteyn 6.574(2)).According to this theoryWS[m_,n_,p_]:=Integrate[BesselJ[m, x]*BesselJ[n, x] x^-p, {x, 0, Infinity}]= A/BwhereA=Gamma[p]*Gamma[(n+m-p+1)/2]B=2^p Gamma[(n-m+p+1)/2]Gamma[(n+m+p+1)/2]Gamma[(m-n+p+1)/2]By the presence of Gamma[p] in numerator A, in the case p=0 as in W[m,n]all these integrals are divergent since Gamma[0]=Infinity.The integral exist if m+n+1 > p > 0.ASYMPTOTICSThe Watson theory is in conßict with Mathematica and your notes accordingwhichthe asyntotic trend 1/x of the integrand in W[m,n] is enough forconvergernce. I divide the integral in two partsWasy[m_,n_,a_]=NIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, 0, a]+ NIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, a, Infinity}]and if a>>1 I use asyntotic expansion of Bessel function in the secondintegralso that I can writeWasy[m_,n_,a_]= int1[m,n,a]+int2[m,n,a]whereint1[m_,n_,a_]:=NIntegrate[ BesselJ[0, x]*BesselJ[1, x], {x, 0, a]+int2[m_,n_,a_]:=(2/Pi)Integrate[Cos[x-(2m+1)Pi/4]*Cos[x-( 2n+1)Pi/4], {x, a,Infinity}]The first integral is a quite normal finite integral. The second (int2) issingularand according to Mathematica 4.1 int2[m_, n_, a_] := -(1/Pi)*Log[a]*Cos[1/2(m - n)Pi]*]Log[a] + (1/Pi)*CosIntegral[2 a]*Sin[1/2(m+n)Pi] + 1/(2*Pi)*Cos[1/2(m+n)Pi]*(Pi-SinIntegral[2*a]) RESULTSm=1;n=0;a=20.;WS[m,n,0]=divergentW[m,n]=1/2NW[m,n]= 0.5Wasy[m,n,a]=.49816m=2;n=0;a=20.;WS[m,n,0]=divergentW[m,n]= 0.427599NW[m,n]=-2.43818Wasy[m,n,a]=-1.48052m=3;n=1;a=20.;WS[ m,n,0]=divergentW[m,n]=0.639806NW[m,n]=-2.31957Wasy[m,n,a]=- 1.26822m=4;n=0;a=20.;WS[m,n,0]=divergentW[m,n]=-.852012NW[m,n ]=1.45786Wasy[m,n,a]=1.06835The cases W[m,m+1],W[m,m+3] well agrre with the numerical counterpart.Other case are doubtfully.I think the main problem is the convergence of this kind of integrals.Any suggestion will be well considerd.RobertRoberto BrambillaCESIVia Rubattino 5420134 Milanotel +39.02.2125.5875fax +39.02.2125.5492rlbrambilla@cesi.it ==== On Sun, 29 Sep 2002 09:35:41, in the message Re: A Bessel integral,VB>> The expression for W[m_,n_] returned by Mathematica is wrong.VB>>VB>> To prove, just substitute m = n = 0 which is exactly what you had doneVB>>VB>> and observe that the output you had hadVB>>VB>> W[0,0]=-(2 EulerGamma + Log[4] + 4 PolyGamma[0, 1/2])/(2 Pi)VB>>VB>> = 0.84564VB>>VB>> was incorrect. The correct answer is 1/2. ^^^^^^^^^^^^^^^^^^^^^^^^^^TB> W[0,0]diverges. Mathematica gets that wrong.(That my terrible bug shows how it is dangerous to do severalposting to the MathGroup before sending them ;-)Why sure, you are right, the integral Integrate[BesselJ[0, z]^2, {z, 0, Infinity}]diverges because the integrand is bounded everywhereover the integration region and decays at z -> Infinityas Cos[Pi/4 - z]^2/z + o(z), that is as In[1] := Expand[TrigExpand[Cos[Pi/4 - z]^2/z]] // InputForm Out[1] = 1/(2*z) + (Cos[z]*Sin[z])/zwhich means that the integral Integrate[BesselJ[0, z]^2, {z, 0, x}]diverges logarithmically in x.By the way, the main term of Expand[Normal[Series[BesselJ[0, z], {z, Infinity, 1}]]^2]is (2*Cos[Pi/4 - z]^2)/(Pi*z) which conveys the suggestion thatwe should try it, too.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)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)Best wishes,Vladimir BondarenkoMathematical DirectorSymbolic Testing GroupWeb : http://www.CAS-testing.org/ http://maple.bug-list.org/VER2/ (under tuning) http://maple.bug-list.org/VER3/ (under tuning) http://maple.bug-list.org/VER1/ (under tuning) http://www.beautyriot.com/ (teamwork) http://www.ohaha.com/ (teamwork) Voice: (380)-652-447325 Mon-Fri 9 a.m. - 6 p.m.Mail : 76 Zalesskaya Str, Simferopol, Crimea, Ukraine ==== John,You could do something like this.points = With[{del = 2Pi/24}, Table[{Cos[t], Sin[t], t/(2Pi)}, {t, 0, 2Pi - del, del}]];Show[Graphics[ {AbsolutePointSize[7], {Hue[Last[#]], Point[#[[{1, 2}]]]} & /@ points, Line[Drop[#, -1] & /@ points]}], AspectRatio -> Automatic, Background -> GrayLevel[0.4], ImageSize -> 400];When I made the point list I made certain the z values were between 0 and 1.Otherwise you will have to define a color function that will associate aproper color with each value of z.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ Approved: Steven M. Christensen , Moderator ==== 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 andthen animate them. The problem is that the audience sees the animationtwice. Once when the frames are being generated and then again after I haveclosed the group and double clicked on the top graphic. However, the firstshowing during generation is enough (but uncontrolled). Is it possible to tidy up the generation of the graphic so that it becomesthe animation?There were two main solutions which I now apply to my real problem and notthe simple, generic, problem in the original post. The real problem was how to build up a probably density function (PDF) inreal time. In the examples below I redraw the PDF every time I add 10points.Initialise<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 thememory. The paradigm here is generate all frames, then animate all frames. Wereally need a loop that does: generate next frame, delete last frame, show next frameIs it possible to do this?Bobby Treat also offered a solution involving SelectionMove.The second solution was from Jerry Blimbaum and uses JAVAInstallJava[];UseFrontEndForRendering = False;createWindow[] := Module[{frame}, frame = JavaNew[com.wolfram.jlink.MathFrame, Probability DensityFunction]; drawArea = JavaNew[com.wolfram.jlink.MathCanvas]; drawArea@setUsesFE[UseFrontEndForRendering]; drawArea@setSize[800, 600];JavaBlock[frame@setLayout[JavaNew[java.awt.BorderLayout] ]; frame@add[drawArea, ReturnAsJavaObject[BorderLayout`CENTER]]; frame@pack[]; frame@setSize[800, 600]; frame@setLocation[100, 100]; JavaShow[frame]];frame]ClearAll[drawString]; drawString[] :=( data=Flatten[Join[data,RandomArray[wb,10]]]; freq=BinCounts[data,{0,50,1}]; BarChart[Transpose[{freq,midpts}],ImageSize ->500, DisplayFunction -> Identity]) LoadJavaClass[java.lang.Thread]; AnimationPlot[n_] := JavaBlock[ Block[{frm}, frm = createWindow[]; Do[(obj = drawString[]; drawArea@setMathCommand[obj]; drawArea@repaintNow[]; Thread@sleep[];) ,{n} ]]]data={}; AnimationPlot[500];This solution works and does not use significant memory. However, we havenot managed to control the speed of this animation. The JAVA code sleep doesnot work nor does the use of a Mathematica Pause which always rounds up toan integer (is this a bug?).Hugh Goyder ==== >>I need a loop that goes generate next frame, delete old frame, shownew frame so that the number of frames does not become excessive.IÕm pinging the group for that. IÕm just following along in this, otherthan the trick of taking advantage of the half-period.IÕll be very interested in a solution myself, as I frequently run out ofmemory in animations of fairly modest size -- despite having 1024MB ofRAM.Bobby-----Original Message-----need a loop that goes generate next frame, delete old frame, show new frameso that the number of frames does not become excessive.Any ideas?Hugh Goyder-----Original Message----- graphs = Rest@Join[half, Rest@Reverse@half]; NotebookWrite[EvaluationNotebook[], Cell[CellGroupData[graphs,Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}]]Bobby-----Original Message----->showing during generation is enough (but uncontrolled).>Hugh GoyderThis creates a graphics cell from a graphics expression.GraphicCell[graphics_] := Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics]cellgroup.Block[{$ DisplayFunction=Identity, graphs}, graphs = Table[GraphicCell[ Plot[Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1,1}}, ImageSize -> 400]], {t,0,15,.1}]; NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs, Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}] ]------------------------------------------------------------ --Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== Actually, we donÕt know whether SetAccuracy succeeds, because we donÕtknow how inexact those numbers really are. If they are known to moredigits than shown in the original post, they should be entered with asmuch precision as they deserve. If not, thereÕs no trick or algorithmthat will give the result precision, because the value of f really isin 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 thatit has no precision.Bobby-----Original Message----- 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 - 15640321149084868351974949239896188679725401538739519428131155 14949389123623452500771916869370459119776018798804630436149786 9199129319625743010292363124675/ 10867106143970760551000357827554793888198143135975649579607989 867743572824016 06539536129829321813712324363677397376040962) 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 HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +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> > ==== 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]:=fOut[3]=-1.1805916207174113*^21In[4]:=Accuracy[ %]Out[4]=-5which tells you that it canÕt be very reliable. What more do you demand?AndrzejAndrzej KozlowskiYokohama, Japanhttp://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> - 15640321149084868351974949239896188679725401538739519428131155 14949> 3891236234> 52500771916869370459119776018798804630436149786919912931962574 301029236 > 3> 1246> 75> / > 10867106143970760551000357827554793888198143135975649579607989 867743572> 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> ==== > 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, yourWhen you do calculations with arbitrary-precision numbers, asdiscussed in the previous section, Mathematica always keeps track ofthe precision of your results, and gives only those digits which areknown to be correct, given the precision of your input. When you docalculations with machine-precision numbers, however, Mathematicaalways gives you a machine-[CapitalEth]precision result, whether or not all thedigits in the result can, in fact, be determined to be correct on thebasis of your input. In practice, to rely on a numerical result, you ALWAYS have to checkits 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]=1180591620717411303424In[4]:=Accuracy[f]Out[4] =InfinityWe got completely wrong result with Infinite accuracy. In conclusion,one can not rely on Accuracy. Checking numerical results inMathematica 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/> [...]> ==== AndrzejYes, like you I took the original question to be about how to get the resultof 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]=> -5However this computation is done in machine arithmetic, which means thatMathematica keeps no check on the accuracy and precision of the computation,and Mathematica gives the default accuracy value without any realsignifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5To get meaningful accuracy and precision values we need to force thecomputation to be in bignums (bigßoat, arbitrary precision) arithmetic.Mathematica then keeps track of the accuracy and precision that it canguarantee. 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] 11Which tells us that the error in the computed value of f is not more than 10^-11The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133There 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 HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +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> > - 15640321149084868351974949239896188679725401538739519428131155 14949>3891236234> > 52500771916869370459119776018798804630436149786919912931962574 301029236>3>1246>75> > /> 10867106143970760551000357827554793888198143135975649579607989 867743572>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 randomsubstitution failures in 4.2. Question: how can thesubstitution 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]] and1/Sqrt[a] is interal Power[a,Rational[-1,2]] and so a rule Sqrt[a]->q will not match with1/Sqrt[a]. You needf = 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)> Jensought 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 preparationfor conversion of those expressions to C. The letters will be namesof 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 <- operatorfor 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}] // NResult: 2.74716Now I wonder if this sum will converge or keep on growing, albeit veryslowly.Matthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: 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, bythe 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^xOut[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 KozlowskiToyama International UniversityJAPANhttp://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 theminimizing value (arg min) of another function.For a simple example consider the followingfunction 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 onlya 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 LudsteckEconomics DepartmentUniversity of RegensburgUniversitaetsstrasse 3193053 RegensburgReply-To: kuska@informatik.uni-leipzig.de ==== you guess right andif you hinder Mathematica toevaluate opt[] for symbolicarguments, withopt[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 KozlowskiYokohama, Japanhttp://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 useMenuCellDefault Inline Format TypeStandard Form. Also, when I design myown style sheets I often define a bolder font for Inline cells so they standout better.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/soon as I press the Control-^ key combination, an Inline cell is createdbeginning with the x, and then when I type the exponent 2 everything inthat Inline cell is now in Times, and the x is Italic. To change bothcharacters to Courier is not so easy: it seems to require separatelythe entire Inline cell and selecting Courier does not change the exponent!)So to avoid this annoyance I normally must first type the desiredexpression in a separate Input cell, then copy the contents of that cellto 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.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375Reply-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.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375 ==== What is the TMJ style sheet? In any case, when people design new stylesheets 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 keysin the order that the cell definitions appear in the style sheet. That meansthat new cell styles should be moved lower in the style sheet, even if thatwould not be their natural order. It would be nice if WRI allowed us toexplicitly assign the keys for the styles.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: 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 codeproduces rotated text with each of the charaters rotated as welldegstr[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 butthe characters in the text are not. That is the position of the chactersrelative to each other changes but their orientation remains constant.I would like to have the character orientation change as it does when thiscode is run under Windows NT. Does anyone know if there is a settingsomewhere 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)fAccuracy[f]Precision[f]Accuracy[10.^21]Precision[10. ^21]1.1805916207174113*^21-516-516The two numbers supposedly have the same accuracy and precision, yet thefirst is in doubt by about 22 ORDERS OF MAGNITUDE -- never mind thedigits! Mathematica computed this beast without giving any indicationit was just noise -- without REALIZING it was noise.>>What more do you demand?IÕm not demanding, objecting, or criticizing. IÕm pointing out theproblem. On the one hand, the poster is computing something thatÕssimply not well-behaved. Unless he knows the coefficients with VERYhigh precision, he canÕt know even the magnitude of the result -- andthatÕs not MathematicaÕs fault at all. On the other hand, MathematicadoesnÕt notice that precision is lost in the computation, and perhaps itshould. 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]:=fOut[3]=-1.1805916207174113*^21In[4]:=Accuracy[ %]Out[4]=-5which tells you that it canÕt be very reliable. What more do you demand?AndrzejAndrzej KozlowskiYokohama, Japanhttp://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 outthat> 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> - 15640321149084868351974949239896188679725401538739519428131155 14949> 38912362345250077191686937045911977601879880463043614978691991 2931962574301029236 > 3> 1246> 75> / 10867106143970760551000357827554793888198143135975649579607989 867743572> 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 youthe>> 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 inexactnumbers: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*dyf is sensitive to inaccuracy in the various numbers to widely varyingdegrees. Since the correct answer is small, we need a LOT ofprecision in the inputs to get there. If any of the inputs are merelymachine precision numbers, we have NO precision in the result.The second and third terms are nearly the same magnitude with differentsigns. Even worse, the first term almost perfectly fills the gap:a = 77617; b = 33096;(33375/100)*b^6438605750846393161930703831040a^2*(11*a^ 2*b^2 - b^6 - 121*b^4 - 2)-7917111779274712207494296632228773890(55/10)*b^ 87917111340668961361101134701524942848% + %% + %%%-2Bobby Treat-----Original Message-----b = SetAccuracy[33096., Infinity]; In[4]:=fOut[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]=1180591620717411303424Similarily: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]:=fOut[4]=-0.8273960599468212641107299556`11.4133In[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 asimplified 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 plusx[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 and9/16 to real machine numbers. I consider this to be a bug.Now, for an example more representative of the situation that IÕve beencoming 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 precisionnumbers. The simplified example above demonstrates that the problem existswhen using machine numbers. Now, weÕll see what happens when we usearbitrary precision numbers. First, letÕs simplify the expression with 12terms.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]) / 4096As you can see, a sum with 12 terms upon simplification has coefficientswhich are still integers as they should be. However, increasing the numberof terms to 13 yieldsSimplify[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 thebug from the simplified example. Finally, letÕs see what happens when wehave 55 terms. Rather than putting the resulting expression here, I willjust leave it at the end of the post. The result though is somewhatsurprising. Each of the coefficients of the x[i] are again real numbers, butnow their precision is only 0! The proper result of course is the sum ofsome real number (with a precision close to 0 due to numerical cancellation)and an expression consisting of rational numbers multiplied by x[i]. Theloss of precision of the coefficients of the x[i] is precisely what occurredto me. Of course, in this simple example, simply using Expand instead ofSimplify produces the expected result, and is my workaround. I hope youagree with me that this is a bug, and one that Wolfram needs to correct.Carl WollPhysics DeptU of WashingtonSimplify[expr55] -16 -1 -1 -10. 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. 10x[15] + -5 -5 -5 -6 -6 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10x[20] + -6 -6 -7 -7 -7 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10x[25] + -8 -8 -8 -9 -9 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10x[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. 10x[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 toreplace 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 everycase. 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 willprobably 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 other14).> These equation are not linearly related.. the highest degree in anyone eqn> is degree 4 i believe.. and there are some cross terms in theequations but> not every equation depends on every variable.. (some are actuallyrather> 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[Terminate];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 ==== 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]:=fOut[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]=-20Andrzej> 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 (bigßoat, 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> - 15640321149084868351974949239896188679725401538739519428131155 14949> 3891236234>> 52500771916869370459119776018798804630436149786919912931962574 3010292 > 36> 3> 1246> 75>> /> 10867106143970760551000357827554793888198143135975649579607989 8677435 > 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 KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/ ==== So? ItÕs just as it should be, isnÕt it?AndrzejAndrzej KozlowskiToyama International UniversityJAPANhttp://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 (bigßoat, 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>> - 15640321149084868351974949239896188679725401538739519428131155 14949>> 3891236234> 52500771916869370459119776018798804630436149786919912931962574 3010292>> 36>> 3>> 1246>> 75>> /> 10867106143970760551000357827554793888198143135975649579607989 8677435>> 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 beingasked explicitly in JUST the right way that only you know and hadforgotten -- that thereÕs a precision problem.Oddly enough, when you DO ask it nicely, you get error messages, but ifyouÕ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 tokeep> precision or accuracy of machine arithmetic computations. But I think> the actual precision you set need not be higher than machineprecision,> 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 theresult.>> 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 (bigßoat, arbitrary precision)>> arithmetic.>> Mathematica then keeps track of the accuracy and precision that itcan>> 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, whichAllan> and myself adopted, was that the question concerned purely the> computational mechanism of Mathematica. Or, to put it in otherwords,> it was why are the results of these two computations not thesame?.> 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 fshould>> 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>>- 15640321149084868351974949239896188679725401538739519428131155 14949>> 3891236234> 52500771916869370459119776018798804630436149786919912931962574 3010292>> 36>> 3>> 1246>> 75>> /> 10867106143970760551000357827554793888198143135975649579607989 8677435>> 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 SetPrecisiondoes> 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 inMathematica> 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?> STHReply-To: kuska@informatik.uni-leipzig.de ==== FileNames[] returns an empty list if there are nofiles. SoFileNames[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]:=fOut[7]=-5.517164009`-2.8311*^19In[8]:=Accuracy[f] Out[8]=-23In[9]:=Precision[f]Out[9]=-3In 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 (bigßoat, 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>> - 15640321149084868351974949239896188679725401538739519428131155 14949> 3891236234>> 52500771916869370459119776018798804630436149786919912931962574 3010292> 36> 3> 1246> 75>> /> 10867106143970760551000357827554793888198143135975649579607989 8677435> 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 KozlowskiYokohama, Japanhttp://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]:=fOut[7]=-5.517164009`-2.8311*^19In[8]:=Accuracy[f] Out[8]=-23In[9]:=Precision[f]Out[9]=-3In 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, butif> 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 getthe> result> of using the naive rational versions in place of the inexactnumbers.> 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 (bigßoat, 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 notmore> 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 bysucceeds>> here refer to quite different things and your objection istherefore>> 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 Mathematicareturn>> 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 enteredwith> 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>> - 15640321149084868351974949239896188679725401538739519428131155 14949> 3891236234>> 52500771916869370459119776018798804630436149786919912931962574 3010292> 36> 3> 1246> 75>> /> 10867106143970760551000357827554793888198143135975649579607989 8677435> 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 orb.>> 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 giveyou>> 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 KozlowskiYokohama, Japanhttp://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 ßash 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 ConsultingThe final answer to your Mathematica needsSpend 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 severalsuggestions. (1) You might tryrigging the function, say withg[x_?NumberQ] := f[x] + If[Im[x]<=0,1000,0](2) If you have version 4.2 a related approach would be to takeadvantage of constrained optimization and doNMinimize[{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 bealleviated by rescaling your variable.(4) Alternatively you could write your function as a pair of real valuedfunctions of two real valued arguments. Then you can use Interval tosplit the rectangle into parts, keeping subrectangles for which {0,0}lives in f[Interval[x],Interval[y]] where Interval[x], for example, is ashorthand for an interval for the x part of the rectangle being split.Daniel LichtblauWolfram ResearchReply-To: kuska@informatik.uni-leipzig.de ==== and solving the real and imaginary part for for z->x+I*y withFindRoot[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]:=aOut[3]=77617In[4]:=bOut[4]=33096Next 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*^21Now, because there were machine ßoats 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]=-5But 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]=1180591620717411303424In[8]:=Accuracy[%]Out[8] =InfinityBut 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 KozlowskiYokohama, Japanhttp://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-ç.8dprecision 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 issuesraised 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 machinearithmetic was in use. For that domain just regard 16 as the definitionof precision. Moreover no tracking is done. It is only when bignums areused 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 onedoes not know if 16 refers to a machine number or a bignum of that sameprecision.> 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 thefact and expect a meaningful result. Again, had significance arithmeticbeen used, I think there would have been adequate information to assessthe 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 thatis, 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]). Nowf ~ 10^21, and so has accuracy of around 71 digits. Garbagenotwithstanding, 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*^14This tells you there are NO reliable digits. The advantage to this isthat is is more ßexible than interval arithmetic in Mathematica whichwill not, for example, deal well with complex-valued functions orcomplex domains. Also significance arithmetic (aka arbitrary precisionarithmetic) 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 withcare and in appropriate ways. Raising accuracy after the fact does notfall into that category.> I havenÕt seen an example> in which they did what anyone (but you) thought they should do.> BobbyMaybe. But, curiously enough, I am a user rather than developer when itcomes to that stuff. I used the precision mechanism alot in polynomialNSolve, and it did indeed work to my liking. Which counts for somethingfrom the ordinary users'perspective, because now NSolve works betterthan 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.> DanielDaniel LichtblauWolfram Research ==== > The more I play with the example the more depressing it gets. Start> with ßoating 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 seethis).You appear to be showing output in InputForm. If you use OutputForm orStandardForm only 26 digits will be shown. 32Out[3]= -4.7833916866605540257808360 10InputForm is showing more because it exposes bad digits as well asgood 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.> PKAgreed, itÕs not very pretty. I am uncertain as to whether thisindicates a bug in StandardForm or elsewhere in the underlying numericscode, and will defer to our numerics experts on that issue. My guess isit is a bug if only because it violates the spirit of IEEE arithmeticwherein ßoats that have integer values should be representable as such(or something to that effect). I will point out, however, that the twonumbers in question are equal to the specified precision. Also itappears to be improved in our development kernel.Daniel LichtblauWolfram Research ==== The more I play with the example the more depressing it gets. Startwith ßoating 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^2b^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]=-6Due to the manual section 3.1.6:When you do calculations with arbitrary-precision numbers, asdiscussed in the previous section, Mathematica always keeps track ofthe precision of your results, and gives only those digits which areknown to be correct, given the precision of your input. When you docalculations with machine-precision numbers, however, Mathematicaalways gives you a machine[CapitalEth]precision result, whether or not all thedigits in the result can, in fact, be determined to be correct on thebasis of your input. Because I started with arbitrary-precision numbers Mathematica should displayonly those digits that are correct, that is none.To relax a bit, set a new input cell to StandardForm and type 77617.000000000000000000000000000000000Convert it to InputForm. You get77616.999999999999999999999999999999999999999999952771` 37.9031Convert back to StandardForm77616.99999999999999999999999999999999999999999976 637`37.9031Again to InputForm77616.99999999999999999999999999999999999999999963735 `37.9031Back to StandardForm77616.99999999999999999999999999999999999999999951 376`37.9031See 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 ßoating 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.00000000000000000000000000000intstead of intended b=33096.00000000000000000000000000000I 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 completelyunderstood it. SetAccuracy just takes anything and calls it accurate.This behavior is useless if not stupid. It was apparently intended byMathematica 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 isno 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.deThe serie is divergent!I suggest you to look at this beautiful introduction to primes distributionhttp://www.maths.ex.ac.uk/%7Emwatkins/zeta/ vardi.htmlBye, robRoberto BrambillaCESIVia Rubattino 5420134 Milanotel +39.02.2125.5875fax +39.02.2125.5492rlbrambilla@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?> STHSteven,Directory[]returns the current directory$Pathreturns 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 documentsetc) and subdirectory (folder) names in the current directory.Since FileNames returns a list of elements, you can use all sorts of teststo see if a file youÕre looking for is in a said directory or not orwhether 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 wouldbe 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.htmlSTH=== =The sum diverges. See Elementary Number Theory, 5th edition by David M.Burton, pages 355-356.-----Original Message-----Sal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de ==== ====I need FrameLabels of the kind of H^s_z / H^p_Z and tried somethinglikeFrameLabel->{FontForm{HSuperscript[s]Subscript[z ] ...}}but s is too far away from z. How can I manage it that s isdirectly above z ? Are there some backspace-characters to be used?Harry ==== TryPower[Subscript[H, z], s] I need FrameLabels of the kind of H^s_z / H^p_Z and tried something> like FrameLabel->{FontForm{HSuperscript[s]Subscript[z] ...}} but s is too far away from z. How can I manage it that s is> directly above z ? Are there some backspace-characters to be used? Harry ==== TryPower[Subscript[H, z], s] I need FrameLabels of the kind of H^s_z / H^p_Z and tried something> like FrameLabel->{FontForm{HSuperscript[s]Subscript[z] ...}} but s is too far away from z. How can I manage it that s is> directly above z ? Are there some backspace-characters to be used? Harry ==== >-----Original Message----->Sent: Thursday, August 29, 2002 7:38 AM>I would like to match a named pattern in an expression and >then square the>result. But my attempt fails.Clear[f, g, x, y, a]>expr = 3*f[x]*g[y] + 2 + x^2;expr /. a:(f[_]*g[_]) :> a^2>2 + x^2 + 3*f[x]*g[y]If I drop the name on the pattern, it matches - but it doesnÕt >do what I>want.expr /. f[_]*g[_] :> a^2>2 + 3*a^2 + x^2How can I name such a pattern and use it on the rhs of a rule?David Park>djmp@earthlink.net>http://home.earthlink.net/~djmp/Dear David,just donÕt insist on a single name! In[17]:=expr /. (a : f[_])*(b : g[_]) :> (a*b)^2Out[17]=2 + x^2 + 3*f[x]^2*g[y]^2In[29]:=3*ff[z]*f[x]*g[y] + 2 + x^2 /. (a : f[_])*(b : g[_]) :> (a*b)^2Out[29]=2 + x^2 + 3*f[x]^2*ff[z]*g[y]^2We might tend to understand this behaviour of the pattern matcher. As Timeshas the Flat, Orderless attributes, the components of the pattern have to betaken apart to match separated subexpressions at the lhs, what should thepattern variable then designate in the course of this procedure?Look at the FullFormIn[31]:=(a : f[_])*(b : g[_]) // FullFormOut[31]//FullForm=Times[Pattern[a, f[Blank[]]], Pattern[b, g[Blank[]]]]compared to In[12]:=a : f[_]*g[_] // FullFormOut[12]//FullForm=Pattern[a, Times[f[Blank[]], g[Blank[]]]]Depending on your real problem...In[43]:=expr /. a_?NumericQ *b_ :> a*Times[b]^2Out[43]=2 + x^2 + 3*f[x]^2*g[y]^2...might be a more elegant (but risky) solution (?), or perhaps else (more robust if you know the names f,g)...In[79]:=expr /. a:(f | g)[___] :> a^2Out[79]=2 + x^2 + 3*f[x]^2*g[y]^2In[139]:=expr /. a : h_[___] /; MemberQ[{f, g}, h] :> a^2Out[139]=2 + x^2 + 3*f[x]^2*g[y]^2Perhaps a fine way would beIn[74]:=2 + x^2 + 3 f[x]*g[y] /. HoldPattern[Times[a:(_[___]..)]] :> Times[a]^2Out[74]=2 + x^2 + 3*f[x]^2*g[y]^2but of course this only works if you have at least two factors f[] and g[](and no mixed powers of x and y!) In that case come back to something likeIn[103]:=2 + x^2*y^2 + 3*x*y^3*f[x]*g[y] + f[x] /. a : (_[___]) :> a^2 /; FreeQ[a, Power | Times]Out[103]=2 + x^2*y^2 + f[x]^2 + 3*x*y^3*f[x]^2*g[y]^2--Hartmut ==== version4.1.5.0 I try to do the simple task of transposing a matrix. X = {{a,b},{c,d},{e,f}}> whereas Transpose[{{a,b},{c,d},{e,f}}] works well. What is wrong with writing Transpose[X] ? Terje Johnsen ==== Andrzej,That doesnÕt work because I donÕt want to square the 3. Of course, I coulddivide by p but not in my actual example. In my actual example I am notsquaring but doing a MetricSimplify tensor operation and the whole purposeis to operate on only two of four factors. I can do it by giving a specificpattern but not by using a general pattern.Here is a better example.expr = f[a]g[b]h[c];This works...expr /. g[b]h[c] :> op[g[a]h[c]]f[a] op[g[a] h[c]]This even works with a more general pattern but is a silly way to do it...expr /. g[_]h[_] :> op[g[a]h[c]]f[a] op[g[a] h[c]]This is what I want to do, but again it doesnÕt work:expr /. p_. (sub : g[_]h[_]) :> p op[sub]f[a] g[b] h[c]I have to be able to obtain a name for the match to the g[_]h[_] pattern.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/In[13]: =expr /. a:((p_.)*f[_]*g[_]) :> p*a^2Out[13]=2 + x^2 + 27*f[x]^2*g[y]^2Andrzej KozlowskiToyama International UniversityJAPAN> I would like to match a named pattern in an expression and then square> the> result. But my attempt fails. Clear[f, g, x, y, a]> expr = 3*f[x]*g[y] + 2 + x^2; expr /. a:(f[_]*g[_]) :> a^2> 2 + x^2 + 3*f[x]*g[y] If I drop the name on the pattern, it matches - but it doesnÕt do what> I> want. expr /. f[_]*g[_] :> a^2> 2 + 3*a^2 + x^2 How can I name such a pattern and use it on the rhs of a rule? David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/ ==== David,> I would like to match a named pattern in an expression and then square the> result. But my attempt fails.> Clear[f, g, x, y, a]> expr = 3*f[x]*g[y] + 2 + x^2;> expr /. a:(f[_]*g[_]) :> a^2> 2 + x^2 + 3*f[x]*g[y] ...Well, I see that expr /. a:Times[f[_],g[_],h___]:> a^2works, and I think I understand why your form above does not work (examineFullForm of expr--your form does not account for 3), but I donÕtunderstand why eliminating a: from your form allows the pattern to match.Tom Burton ==== I would expect thatPlot[Sin[x]/Sin[x], {x, -2.5, -1.5}]would produce a horizontal line at y=1.However, on my Windows XP computer it produces a graph where the y value isless than 1 at several points. Most notibly between x=-1.6 and x=-1.8Is this just an isolated case? Or does it happen to others? If so - why?Ken. ==== This results from:a) the fact that Mathematica implements division as multiplication andreciprocationb) the use of machine precision for plotting the graphc) the default scaling of the y axis revealing the resultant inaccuraciesAlthough Sin[x]/Sin[x] gives 1 when evaluated symbolically (x undefined),substituting a ßoating-point value for x results in composite divisionbeing performed numerically, with consequent inaccuracy. This can beverified by the following:In[1]:= FullForm[HoldForm[Sin[x]/Sin[x]]Out[1]//FullForm= HoldForm[Times[Sin[x], Power[Sin[x], -1]]]By default, Mathematica scales the y axis such that the small discrepanciesare visible. The PlotRange option may be given to explicitly specify therange for the y axis (for example PlotRange->{0, 2}).Ian McInnes.> I would expect that Plot[Sin[x]/Sin[x], {x, -2.5, -1.5}] would produce a horizontal line at y=1. However, on my Windows XP computer it produces a graph where the y valueis> less than 1 at several points. Most notibly between x=-1.6 and x=-1.8 Is this just an isolated case? Or does it happen to others? If so - why? Ken.> ==== I get very small dips (vees?) at the same spots using 4.1.What is your experience with the presentation feature of version 4.2 ?That is what is attracting me to upgrade and I want to hear experiences.> I would expect that Plot[Sin[x]/Sin[x], {x, -2.5, -1.5}] would produce a horizontal line at y=1. However, on my Windows XP computer it produces a graph where the y valueis> less than 1 at several points. Most notibly between x=-1.6 and x=-1.8 Is this just an isolated case? Or does it happen to others? If so - why? Ken.> ==== I eventually figured this one out:(1) change the default font to smaller (10 pts vs 12). This solves theproblem, but makes the help text illegibly small. This is cured by step 2:(2) go into preferences and change the default zoom to larger (1.25 from 1).> The Windows, the Mathematica Help browser has a categories section, where> the headings and subheadings of each help file appear. In version 3.x,those> fonts (by default) appear nice and small (smaller than the text on the> menu). In 4.1, the font is so large I cannot read the entire heading. How> can I revert to the proper display?> Nicholas> ==== I am fairly new to Mathematica and once before asked a question andreceived somevery helpful responses. This time the problem seems very odd and I may bemaking a veryelementary error. Here is the context: I define a function of the form: f[...,listA_, newEntry_,...]:= Which[...]Here Which has the form of a set of logically exclusive and exhausivetests, each test with its ownaction that modifies the concrete list subsituted for listA_. For instance, if there were only two tests the rhs above would beone that puts the newEntryat the start of listA and the other that puts it at the end: Which[ test1, listA = Insert[listA, newEntry, 1], test2, listA = Insert[listA, newEntry, -1] ]Then I try to use the function, substituting values for the arguments:f[..., listA, newEntry, ...]. Theoutput should be the appropriately modified list. But my actual outputreproduces the input form,i.e., it is simply f[...listA,newEntry,...]. Yet, the program does do something, as the use of evaluate inplaceshows: Suppose that test1 is satisfied by the particular values of thearguments. Then whenI apply evaluate in place to the lhs of the action that is supposed tooccur when test1 is true,in fact the value of Insert[listA,newEntry,1] is correct, but the rhs givesonly the initial value oßistA and not the modified value that is on the rhs. Concretely, suppose that in the function argument listA is {121} andnewEntry is 200.Then after evaluation of the function (input to the kernel), that linereads, according toevaluate in place: true, {121} = {200, 121}So it seems that only part of the correct action was taken: 200 was put atthe start of listA. Butthe assignment of this value -- the extended list -- to be the new value oßistA did not take place. I then tried using a new name for the modified list, substituting thisprogram line for test1: test1, newListA = Insert[listA, newEntry,1]What I get here, applying evaluate in place after evaluating the functionwith concrete values as aboveis: true, newListA = {200, 121} Trace doesnÕt help because all I get back is the function name withits concrete arguments. Any thoughts? Tom ==== > In order to do some transformations on a tree I need to be able to replace> an expression with head hdA if and if only its parent has head hdB and its> grandparent had head hdC. Furthermore, the item itself and its parent may> have any number sibling elements.> What I do now is the following. Give the expression:> ttexpr = grandparent[> parent1[grandchild2[], grandchild1[], grandchild4[], grandchild1[]],> grandchild1[],> parent2[grandchild2[], grandchild1[], grandchild4[], grandchild1[]]];> I apply a rule:> ttexpr /. {> grandparent[left1___, parent1[left2___, grandchild1[], right2___],> right1___] - grandparent[left1, parent1[left2, MATCHED[], right2], right1]}> which gives the desired expression:> grandparent[parent1[grandchild2[], MATCHED[], grandchild4[], grandchild1[]],> grandchild1[],> parent2[grandchild2[], grandchild1[], grandchild4[], grandchild1[]]]> But I have the feeling that it should be possible to do this more elegantly.> Does anybody have an idea in this respect?> Sidney CadotI think your technique is fine for small to medium size trees. For largeones it might be very slow due to all the work of patten matching. Ifyou anticipate large inputs you might thus want to code a simpletree-walk using old-fashioned procedural code. Any time you match agrandparent head, put that subtree onto a stack that enters the nextstate, looking for parent nodes, etc.Daniel LichtblauWolfram Research ==== with the output your own solution is giving you. I would have thought not, since only one grandchild1[] with parent parent1 and grandparent grandparent. is being matched. You can get a complete match by using ReplaceRepeated instead of ReplaceAll:In[33]:=ttexpr// .{grandparent[left1___,parent1[left2___,grandchild1[],right2_ __], right1___]-> grandparent[left1,parent1[left2,MATCHED[],right2],right1]}Out [33]=grandparent[parent1[grandchild2[],MATCHED[],grandchild4[ ],MATCHED[]], grandchild1[], parent2[grandchild2[],grandchild1[],grandchild4[],grandchild1 []]]exactly the same result can be achieved in a rather different way, which may perhaps be seen as more elegant.In[34]:=ttexpr /. expr_grandparent :> (expr /. expr1_parent1 :> (expr1 /. expr2_grandchild1 :> Matched[]))Out[34]=grandparent[parent1[grandchild2[], Matched[], grandchild4[], Matched[]], grandchild1[], parent2[grandchild2[], grandchild1[], grandchild4[], grandchild1[]]]Andrzej KozlowskiToyama International UniversityJAPAN In order to do some transformations on a tree I need to be able to > replace> an expression with head hdA if and if only its parent has head hdB and > its> grandparent had head hdC. Furthermore, the item itself and its parent > may> have any number sibling elements. What I do now is the following. Give the expression: ttexpr = grandparent[> parent1[grandchild2[], grandchild1[], grandchild4[], > grandchild1[]],> grandchild1[],> parent2[grandchild2[], grandchild1[], grandchild4[], > grandchild1[]]]; I apply a rule: ttexpr /. {> grandparent[left1___, parent1[left2___, grandchild1[], right2___],> right1___] - grandparent[left1, parent1[left2, MATCHED[], right2], right1]} which gives the desired expression: grandparent[parent1[grandchild2[], MATCHED[], grandchild4[], > grandchild1[]],> grandchild1[],> parent2[grandchild2[], grandchild1[], grandchild4[], grandchild1[]]]> But I have the feeling that it should be possible to do this more > elegantly.> Does anybody have an idea in this respect?> Sidney Cadot ==== >IÕm finding that the ImageSize option in Export has no effect when>exporting Cell or Notebook objects. For instance, the following two>commands produce precisely the same graphic: Export[image1.jpg, Cell[Some cell contents, Text, FontSize -> 100]] Export[image2.jpg, Cell[Some cell contents, Text, FontSize -100], ImageSize -> {576, 288}]Has anyone encountered this problem before?(This is with Mathematica 4.1.5 and Mac OS X.)---->Selwyn Hollis>slhollis@mac.comExport takes two options that control the size of a graphic, ImageSize and ImageResolution. The difference is sometimes subtle. ImageSize changes the coordinates while ImageResolution changes the size of objects. This may sound like the same thing, but theyÕre actually different.If I have a plot with a line. Changing ImageSize changes the location of the points in the line, which may make the line shorter or longer, but the thickness is unchanged (if it is an AbsoluteThichness). ImageResolution draws the image with a different number of pixels, so lengths and thicknesses are changed. The same is true with fonts.Why does it matter? Because there is no equivalent to ImageSize for cells or notebooks. However, Magnification is a good equivalent of ImageResolution. So ImageSize does nothing, but ImageResolution does.In[1]:= cont=Cell[Some cell contents, Text, FontSize -> 100]In[2]:= Show@ImportString[ExportString[cont, JPEG], JPEG]In[3]:= Show@ImportString[ExportString[cont, JPEG, ImageResolution ->72*3/2], JPEG]-Dale ==== I was wondering if there is a method for resizing Raster graphics(resizing the actual matrix of pixels, not just the display size). Iam processing a large number of JPEG images, and we sometimes need toreduce the image size to allow data processing algorithms to functionwithout running out of memory. In the past we simply used a programsuch as Photoshop to resize them before importing them intoMathematica. Due to the number of images we are processing now thisis very inconvenient and it would be very useful if there was a methodfor accomplishing it in Mathematica, but I canÕt find one. I alsothought about doing something simple like sampling every few pixels oraveraging, but I thought there might be a method with more efficacythan this. I also tried exporting the graphics with the Export commandas new JPEGs and manipulating the ImageResolution and ImageSizeoptions but this seemed to have no effect. Any help would be muchappreciated.Aaron UrbasReply-To: kuska@informatik.uni-leipzig.de ==== take the matrix of gray values or the matrix of the color channels,apply ListInterpolation[] and generate a resampled table withthe interpolated function. Jens> I was wondering if there is a method for resizing Raster graphics> (resizing the actual matrix of pixels, not just the display size). I> am processing a large number of JPEG images, and we sometimes need to> reduce the image size to allow data processing algorithms to function> without running out of memory. In the past we simply used a program> such as Photoshop to resize them before importing them into> Mathematica. Due to the number of images we are processing now this> is very inconvenient and it would be very useful if there was a method> for accomplishing it in Mathematica, but I canÕt find one. I also> thought about doing something simple like sampling every few pixels or> averaging, but I thought there might be a method with more efficacy> than this. I also tried exporting the graphics with the Export command> as new JPEGs and manipulating the ImageResolution and ImageSize> options but this seemed to have no effect. Any help would be much> appreciated.> Aaron UrbasReply-To: kuska@informatik.uni-leipzig.de ==== take the matrix of gray values or the matrix of the color channels,apply ListInterpolation[] and generate a resampled table withthe interpolated function. Jens> I was wondering if there is a method for resizing Raster graphics> (resizing the actual matrix of pixels, not just the display size). I> am processing a large number of JPEG images, and we sometimes need to> reduce the image size to allow data processing algorithms to function> without running out of memory. In the past we simply used a program> such as Photoshop to resize them before importing them into> Mathematica. Due to the number of images we are processing now this> is very inconvenient and it would be very useful if there was a method> for accomplishing it in Mathematica, but I canÕt find one. I also> thought about doing something simple like sampling every few pixels or> averaging, but I thought there might be a method with more efficacy> than this. I also tried exporting the graphics with the Export command> as new JPEGs and manipulating the ImageResolution and ImageSize> options but this seemed to have no effect. Any help would be much> appreciated.> Aaron Urbas ==== > I was wondering if there is a method for resizing Raster graphics> (resizing the actual matrix of pixels, not just the display size). I> am processing a large number of JPEG images, and we sometimes need to> reduce the image size to allow data processing algorithms to function> without running out of memory. In the past we simply used a program> such as Photoshop to resize them before importing them into> Mathematica. Due to the number of images we are processing now this> is very inconvenient and it would be very useful if there was a method> for accomplishing it in Mathematica, but I canÕt find one. I also> thought about doing something simple like sampling every few pixels or> averaging, but I thought there might be a method with more efficacy> than this. I also tried exporting the graphics with the Export command> as new JPEGs and manipulating the ImageResolution and ImageSize> options but this seemed to have no effect. Any help would be much> appreciated.> Aaron Urbas>Aaron, with the Digital Image Processing package see Downsample, Decimate orResize.Else, the simplest method is to take every kÕth sample, which can be donewith the Take command.This imports the image and returns the raw data.img = Import[somefile.jpg][[1,1]];For an image with dimensions nr x nc, and if you want to take every othersample use:small = Take[img, {1, nr, 2}, {1, nc, 2}];You can also perform smoothing using ListConvolve prior to downsampling toeliminate some of the visual artifacts of downsampling.Done.-- ==== ===========================Mariusz JankowskiUniversity of Southern Mainemjkcc@usm.maine.edu207-780-5580 ==== Yesterday I posted a question on using named patterns in a rule. I receiveda number of useful replies and thank all those who responded. Today I have aquestion that actually generated yesterdayÕs question. I am using a newsubject heading to reßect the actual nature of the question.What is the best way in Mathematica to operate on some, but not all, levelparts of an expression or subexpression?Suppose I have the following expression...expr = f1[a]f2[b]f3[c]f4[d];and I want to do an operation, op, separately on f1[a]f3[c] and f2[b]f4[d].The operation must be done on the given pairs and not on all four factors atonce. One method is to use explicit exact substitution rules.expr /. f1[a]f3[c] :> op[f1[a]f3[c]] /. f2[b]f4[d] :> op[f2[b]f4[d]]op[f1[a] f3[c]] op[f2[b] f4[d]]If a,b,c,d were long expressions, we might not want to type or copy them in.This raised my question of using named patterns. Hartmut Wolf pointed outthat each factor must be named to create a match with ßat expressions. Sowe could use...expr /. (a : f1[_])(b : f3[_])(c : f2[_])(d : f4[_]) :> op[a b]op[c d]op[f1[a] f3[c]] op[f2[b] f4[d]]Andrzej Kozlowski suggested a method using Take, but using Part works betterhere, so we could use...expr /. a_ :> op[a[[{1, 3}]]]*op[a[[{2, 4}]]]op[f1[a] f3[c]] op[f2[b] f4[d]]All of the above methods use rules. Is it possible to do it withReplacePart? I donÕt think so, but maybe somebody knows how to do it. Howabout using MapAt? I donÕt think that works either in regular Mathematica.Ted Ersek and I did a package, Algebra`ExpressionManipulation` at my website, that implements extended positions. An extended position gives theposition of an expression and a list of the desired subparts and is packagedin a header eP. So the extended position of a + c inf[a + b + c + d] is eP[{1},{1,3}]. The package modifies MapAt to acceptextended positions. Then we can use...MapAt[op, expr, {eP[{}, {1, 3}], eP[{}, {2, 4}]}]op[f1[a] f3[c]] op[f2[b] f4[d]]However, I donÕt always like to drag in the package just to do that. I thinkthat operating on selected level parts of a subexpression is not all thatuncommon.Here is another example.1 - Cos[x]^2% // TrigFactor1 - Cos[x]^2Sin[x]^2But...1 - a - Cos[x]^2% // TrigFactor1 - a - Cos[x]^2(1/2)*(1 - 2*a - Cos[2*x])I was hoping for -a + Sin[x]^2. What are the best methods for handling thiskind of problem in regular Mathematica?David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== and from kde2 to kde3 my Mathematica 3.0 doesnÕt work as usual any more:All the characters have become little rectangles,I canÕt read even the error message at the beginning.I followed the wolfram support pageHow do I resolve certain font-related error message whenvery carefully, but the error remains.Markus Koecher ==== I look for an operator, which has a higher precedence than @ and can beoberloaded with a new definition.According to the table in A.2, only PatternTest (?) could be a candidate.But according to my tests, PartitionTest cannot be overloaded with an newdefinition.What is your opinion?Hermann Schmitt ==== I have been trying to get emmathfnt to work for the past few hours butwhatever I do the output file is slightly smaller than the input so Iguess it isnÕt working and emmathfnt cannot find the font files. Ialso set FONTDIR.I am using the dos commandemmathfnt -d C:Progra~1Wolfra~1Mathem~14.2System~1FontsType1-o c:output.eps c:input.epsand the following is outputC:WINDOWS>dir c:*put.eps Volume in drive C has no label Volume Serial Number is 0508-1ED9 Directory of C:OUTPUT EPS 26,324 08-30-02 9:57a output.epsINPUT EPS 26,324 08-30-02 10:21a input.eps 2 file(s) 52,648 bytes 0 dir(s) 4,896.69 MB freeand if i run dir C:Progra~1Wolfra~1Mathem~14.2System~1FontsType1I see the font files OK.input.eps was produced using the following Mathematica gr = Plot[Sin[[Alpha]], {[Alpha], -[Pi], [Pi]}, AxesLabel -> {[Alpha], Sin([Alpha])}]Export[c:input.eps, gr, EPS]both input and output set to StandardFormI wonder what I am doing wrong.C:WINDOWS>SETTMP=C:WINDOWSTEMPTEMP=C:WINDOWSTEMPPROMPT= $p$gwinbootdir=C:WINDOWSCOMSPEC=C:WINDOWSCOMMAND.COMPATH=C: DOWNLOADFONTZEMMATH~1;C:UTILSGHOSTGHOSTGUMGSVIEW;C: TEXMFMIKTEXBIN;C:WINDOWS;C:WINDOWSCOMMAND;C:MATLAB_ SV12BINWIN32FONTDIR=C:Program FilesWolframResearchMathematica4.2SystemFilesFontsType1windir =C:WINDOWSBLASTER=A220 I5 D3 T4CMDLINE=emmathfnt -dC:Progra~1Wolfra~1Mathem~14.2System~1FontsType1 -oc:output.eps c:input.epsthankyou ==== > I would expect that Plot[Sin[x]/Sin[x], {x, -2.5, -1.5}] would produce a horizontal line at y=1. However, on my Windows XP computer it produces a graph where the y value is> less than 1 at several points. Most notibly between x=-1.6 and x=-1.8 Is this just an isolated case? Or does it happen to others? If so - why?>4.1 for Mac OS X (November 5, 2001)p = Plot[Sin[x]/Sin[x],{x,-2.5,-1.5}];Note that the Ticks on the y-axis are all 1, that is, in trying to findsomethingof interest the adaptive range has zoomed in and is looking at the machineprecision representations of 1.(First /@(Ticks /. AbsoluteOptions[p])[[2]])//InputFormZoom out using the PlotRangePlot[Sin[x]/Sin[x],{x,-2.5,-1.5}, PlotRange->{-0.1,2.1}];Or as stated in the on-line help for Plot: You should use Evaluate to evaluatethe function to be plotted if this can safely be done before specific numericalvalues are supplied.Plot[Evaluate[Sin[x]/Sin[x]],{x,-2.5,-1.5}];Bob HanlonChantilly, VA USA ==== I am trying to implement the inner product in the space ofcomplex-valued, square integrable functions over [-1/2,1/2], which canbe expressed in Mathematica code asinner[f_Function,g_function]:=Integrate[Conjugate[f[x]]*g[x ],{x,-1/2,1/2}]This is simple enough. Problem is, Mathematica seamingly cannotevaluate the Integral for even the simplest of functions:In[10]:=inner[#&,#&]Out[10]:=!([Integral]_(-(1/2))%( 1/2)(x Conjugate[ x]) [DifferentialD]x)As you see, the Integrate returns unevaluated. It works fine if Iremove the Conjugate. Unfortunately the Conjugate is needed forpositive definiteness.Various variants with Composition, Re and Im etc. donÕt work either.This should be a So how do I get Integrate to work with Conjugate? Andreas -- True Pleasure in this society is more dangerous than bank robbery. ==== Andreas Dietrich schrieb:> I am trying to implement the inner product in the space of> complex-valued, square integrable functions over [-1/2,1/2], which can> be expressed in Mathematica code as> inner[f_Function,g_function]:=Integrate[Conjugate[f[x]]*g[x], {x,-1/2,1/2}]> This is simple enough. Problem is, Mathematica seamingly cannot> evaluate the Integral for even the simplest of functions:> In[10]:=inner[#&,#&]> Out[10]:=!([Integral]_(-(1/2))%(1/2)(x Conjugate[> x]) [DifferentialD]x)> Andreas,Conjugate does not evaluate the expression, if the variables arenÕtknown to be real. Your example (inner[#&,#&]) works if you define yourfunction using ComplexExpand:inner[f_,g_]:=Integrate[ComplexExpand[Conjugate [f[x]]]g[x], ...]You may also use a home-made Conjugate, IÕll call it Konjugiert, eg:ruKonjugiert={Complex[re_,im_]:>Complex[re,-im]}; Konjugiert[ausdr__]:=ausdr /. ruKonjugiert;Replacing Conjugate with Konjugiert in your Definition works for yoursimple Example, but more komplex functions will need a ComplexExpand toget the wanted real result.Gru¤ Peter-- =--=--=--=--=--=--=--=--=--=--=--=--=--= http://home.t-online.de/home/phbrf ==== Steve,here...). I am sending it pretty much in the same way as last time,with cc to mathgroup@smc.vnet.net (only this time with the intent thatit not appear there).Daniel-------------------------------------------> NDSolve seems to have difficulties with solving integral equation.> n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0}*[Sigma]norm[z,> t], {z, 0.01, 1}, {t, 0.01, 2}]> Mathematica returns a message> NDSolve::deql: The first argument must have both an equation and an > initial condition.> which I cannot understand.> Can anybody tell whatÕs wrong with my attempt?> -ToshiIÕll show a couple of approaches to this sort of problem. The first isto iteratively solve for sn[k][z,t] in terms of sn[k-1][z,t], withsn[0][z,t] initialized to something appropriate (I used 3/2*z). The snÕsare computed as interpolating functions based on results from solvingODEs in t for many fixed values of z. The code below does this for n=2.The plots at first appear to ßip between two states but eventuallystabilize. Note that this takes many minutes to run to completion.n = 2;sn[0][z_,t_] := 3/2*z;Do [ Do [ sn[k][z,t_] = sn[k][z,t] /. First[NDSolve[{D[sn[k][z,t], t] == 3*z*NIntegrate[sn[k-1][w,t]^n*w, {w,0,1}] -sn[k-1][z,t]^n, sn[k][z,0] == 3/2*z}, sn[k][z,t], {t,0,2}]], {z,0,1,1/100} ]; snew = Interpolation[Flatten[Table[{z,t,sn[k][z,t]}, {z,0,1,1/100}, {t,0,2,1/100}], 1],InterpolationOrder->7]; sn[k] = snew; Print[iteration , k]; Plot3D[sn[k][z,t], {z,0,1}, {t,0,2}], {k, 1, 15} ]One can test for convergence as below; it is apparently quite good.NIntegrate[Abs[sn[15][z,t]-sn[14][z,t]], {z,0,1}, {t,0,2}]A drawback to this method is that it appears to break down beyond n = 2.Possibly one simply needs a much better starting function for sn[0], IÕmnot sure.Below is another method that Michael Trott showed me. We expand in a setof basis functions in z, set up a system of ODEs in t, and solve them. Itried this using monomials in z for basis functions and ran into sometrouble with the ODE solving, so I will show MichaelÕs attempt usingtrig functions for the basis. Note that we now handle the desired casen=5; another advantage is that this is alot faster than the methodabove, though still not exactly blinding in speed. Michael used theinterval {0,2} for z so as to achieve pointwise (not just L^2)convergence; otherwise there would be a sharp drop-off just before z=1as all the trigs vanish there. In other words, the basis functions areof the form Sin[k/2*Pi] rather than Sin[k*Pi] for 1<=k<=deg. Cosines areexcluded due to the vanishing condition at z=0.integrate[p_Plus, {z_, 0, 1}] := Integrate[#, {z, 0, 1}]& /@ p;integrate[p_, {z_, 0, 1}] := Integrate[p, {z, 0, 1}];n = 5;deg = 6;vars[t_] = Map[#[t]&,Array[a,deg]];zFuns = Sin[Range[deg] Pi/2 z];sn[z_,t_] = vars[t].zFuns;eqs1 = 3*z*integrate[Expand[sn[w,t]^n*w],{w,0,1}] - sn[z,t]^n - D[sn[z,t],t];eqs2 = integrate[Expand[eqs1 #], {z, 0, 1}]& /@ zFuns;iCs = integrate[Expand[(sn[z,0] - 3/2*z) #], {z, 0, 1}]& /@ zFuns; fulleqns = # == 0& /@ Join[eqs2, iCs];nsd = NDSolve[fulleqns, vars[t], {t,0,2}, SolveDelayed->True];Plot3D[Evaluate[sn[z,t] /. nsd[[1]]],{z,0,1},{t,0,2}];an initializer for the iteration/interpolation method above in anattempt to refine the solution.Daniel LichtblauWolfram Research ==== > NDSolve seems to have difficulties with solving integral equation.> n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0}*[Sigma]norm[z,> t], {z, 0.01, 1}, {t, 0.01, 2}]> Mathematica returns a message> NDSolve::deql: The first argument must have both an equation and an > initial condition.> which I cannot understand.> Can anybody tell whatÕs wrong with my attempt?> -ToshiIÕll show a couple of approaches to this sort of problem. The first isto iteratively solve for sn[k][z,t] in terms of sn[k-1][z,t], withsn[0][z,t] initialized to something appropriate (I used 3/2*z). The snÕsare computed as interpolating functions based on results from solvingODEs in t for many fixed values of z. The code below does this for n=2.The plots at first appear to ßip between two states but eventuallystabilize. Note that this takes many minutes to run to completion.n = 2;sn[0][z_,t_] := 3/2*z;Do [ Do [ sn[k][z,t_] = sn[k][z,t] /. First[NDSolve[{D[sn[k][z,t], t] == 3*z*NIntegrate[sn[k-1][w,t]^n*w, {w,0,1}] - sn[k-1][z,t]^n, sn[k][z,0] == 3/2*z}, sn[k][z,t], {t,0,2}]], {z,0,1,1/100} ]; snew = Interpolation[Flatten[Table[{z,t,sn[k][z,t]}, {z,0,1,1/100}, {t,0,2,1/100}], 1], InterpolationOrder->7]; sn[k] = snew; Print[iteration , k]; Plot3D[sn[k][z,t], {z,0,1}, {t,0,2}], {k, 1, 15} ]One can test for convergence as below; it is apparently quite good.NIntegrate[Abs[sn[15][z,t]-sn[14][z,t]], {z,0,1}, {t,0,2}]A drawback to this method is that it appears to break down beyond n = 2.Possibly one simply needs a much better starting function for sn[0], IÕmnot sure.Below is another method that Michael Trott showed me. We expand in a setof basis functions in z, set up a system of ODEs in t, and solve them. Itried this using monomials in z for basis functions and ran into sometrouble with the ODE solving, so I will show MichaelÕs attempt usingtrig functions for the basis. Note that we now handle the desired casen=5; another advantage is that this is alot faster than the methodabove, though still not exactly blinding in speed. Michael used theinterval {0,2} for z so as to achieve pointwise (not just L^2)convergence; otherwise there would be a sharp drop-off just before z=1as all the trigs vanish there. In other words, the basis functions areof the form Sin[k/2*Pi] rather than Sin[k*Pi] for 1<=k<=deg. Cosines areexcluded due to the vanishing condition at z=0.integrate[p_Plus, {z_, 0, 1}] := Integrate[#, {z, 0, 1}]& /@ p;integrate[p_, {z_, 0, 1}] := Integrate[p, {z, 0, 1}];n = 5;deg = 6;vars[t_] = Map[#[t]&,Array[a,deg]];zFuns = Sin[Range[deg] Pi/2 z];sn[z_,t_] = vars[t].zFuns;eqs1 = 3*z*integrate[Expand[sn[w,t]^n*w],{w,0,1}] - sn[z,t]^n - D[sn[z,t],t];eqs2 = integrate[Expand[eqs1 #], {z, 0, 1}]& /@ zFuns;iCs = integrate[Expand[(sn[z,0] - 3/2*z) #], {z, 0, 1}]& /@ zFuns; fulleqns = # == 0& /@ Join[eqs2, iCs];nsd = NDSolve[fulleqns, vars[t], {t,0,2}, SolveDelayed->True];Plot3D[Evaluate[sn[z,t] /. nsd[[1]]],{z,0,1},{t,0,2}];an initializer for the iteration/interpolation method above in anattempt to refine the solution.Daniel LichtblauWolfram Research ==== On 8/23/02 at 12:25 AM, meshii@mech.fukui-u.ac.jp (Toshiyuki (Toshi)>NDSolve seems to have difficulties with solving integral equation.>n = 5; NDSolve[{D[[Sigma]norm[z, t], t] ==>3*z*Integrate[[Sigma]norm[z, t]^n*z, {z, 0, 1}] - [Sigma]norm[z,>t]^n, [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] ==>0}*[Sigma]norm[z, t], {z, 0.01, 1}, {t, 0.01, 2}]>Mathematica returns a messageNDSolve::deql: The first argument must have both an equation and an> initial condition.A general solution to a differential equation includes a constant of integration. It isnÕt possible to arrive a numerical solution without providing sufficient information to determine this constant. Specifying the initial condition provides this information.Look at the examples using the help browser to see what NDSolve needs. ==== -----Original Message----->a number of useful replies and thank all those who responded. >Today I have a>question that actually generated yesterdayÕs question. I am using a new>subject heading to reßect the actual nature of the question.What is the best way in Mathematica to operate on some, but >not all, level>parts of an expression or subexpression?Suppose I have the following expression...expr = f1[a]f2[b]f3[c]f4[d];and I want to do an operation, op, separately on f1[a]f3[c] >and f2[b]f4[d].>The operation must be done on the given pairs and not on all >four factors at>once. One method is to use explicit exact substitution rules.expr /. f1[a]f3[c] :> op[f1[a]f3[c]] /. f2[b]f4[d] :> op[f2[b]f4[d]]>op[f1[a] f3[c]] op[f2[b] f4[d]]If a,b,c,d were long expressions, we might not want to type or >copy them in.>This raised my question of using named patterns. Hartmut Wolf >pointed out>that each factor must be named to create a match with ßat >expressions. So>we could use...expr /. (a : f1[_])(b : f3[_])(c : f2[_])(d : f4[_]) :> op[a b]op[c d]>op[f1[a] f3[c]] op[f2[b] f4[d]]Andrzej Kozlowski suggested a method using Take, but using >Part works better>here, so we could use...expr /. a_ :> op[a[[{1, 3}]]]*op[a[[{2, 4}]]]>op[f1[a] f3[c]] op[f2[b] f4[d]]All of the above methods use rules. Is it possible to do it with>ReplacePart? I donÕt think so, but maybe somebody knows how to >do it. How>about using MapAt? I donÕt think that works either in regular >Mathematica.>Ted Ersek and I did a package, Algebra`ExpressionManipulation` >at my web>site, that implements extended positions. An extended position >gives the>position of an expression and a list of the desired subparts >and is packaged>in a header eP. So the extended position of a + c in>f[a + b + c + d] is eP[{1},{1,3}]. The package modifies MapAt to accept>extended positions. Then we can use...MapAt[op, expr, {eP[{}, {1, 3}], eP[{}, {2, 4}]}]>op[f1[a] f3[c]] op[f2[b] f4[d]]However, I donÕt always like to drag in the package just to do >that. I think>that operating on selected level parts of a subexpression is >not all that>uncommon.Here is another example.1 - Cos[x]^2>% // TrigFactor>1 - Cos[x]^2>Sin[x]^2But...1 - a - Cos[x]^2>% // TrigFactor>1 - a - Cos[x]^2>(1/2)*(1 - 2*a - Cos[2*x])I was hoping for -a + Sin[x]^2. What are the best methods for >handling this>kind of problem in regular Mathematica?David Park>djmp@earthlink.net>http://home.earthlink.net/~djmp/David Park>djmp@earthlink.net>http://home.earthlink.net/~djmp/>Dear David,itÕs possible that I miss something..., but look atIn[6]:=1 - a - Cos[x]^2 /. {1 - Cos[x_]^2 :> Sin[x]^2}Out[6]=-a + Sin[x]^2I donÕt know what TrigFactor is doing exactly (or intended to do), itsanswer might well be consistent with that.if... In[7]:= expr = f1[a]f2[b]f3[c]f4[d]...whats wrong with..In[8]:=op[#[[{1, 3}]]]op[#[[{2, 4}]]]Take[expr, {5, -1}] &[expr]Out[8]=op[f1[a] f3[c]] op[f2[b] f4[d]]...?The problem with this of course is, that you must know the Sequence of theelements of the expression in advance (at programming time). The followingneeds not, uses extract and rebuilds the expression (it is assumed the fare at level {1}, this must be checked, not well done here, just to pass theidea):In[7]:=betteropat[ee : head_[__], {e1_, e3_}, {e2_, e4_}, op_] /; (len = Length[ee]) >= 4 := Module[{pos13 = Position[ee, e1[___] | e3[___], {1}], pos24 = Position[ee, e2[___] | e4[___], {1}], posr}, posr = List /@ Complement[Range[len], Flatten[{pos13, pos24}]]; head @@ Join[{op[head @@ Extract[ee, pos13]]}, {op[ head @@ Extract[ee, pos24]]}, Extract[ee, posr]] ]In[8]:=betteropat[expr, {f1, f3}, {f2, f4}, ox]Out[8]=ox[f1[a] f3[c]] ox[f2[b] f4[d]]In[9]:=betteropat[[Alpha] f1[a]f4[b][Beta] f2[c]f3[d], {f1, f3}, {f2, f4}, ox]Out[9]=[Alpha] [Beta] ox[f1[a] f3[d]] ox[f2[c] f4[b]]If you donÕt need all of this functionality, just reduce.--Hartmut___________________Addendum:Here two other solutions, one using Part, the other ReplacePart + Replace:is not possible, since you _must_ reorder your data, not applying a functionat parts of it). Here now another, simpler opat version (using Part, insteadof Extract):In[19]:=mapopat[ee : head_[__], {e1_, e3_}, {e2_, e4_}, op_] /; (len = Length[ee]) >= 4 := Block[{pos13 = Flatten[Position[ee, e1[___] | e3[___], {1}]], pos24 = Flatten[Position[ee, e2[___] | e4[___], {1}]], posr}, posr = Complement[Range[len], pos13, pos24]; head[op[ee[[pos13]]], op[ee[[pos24]]], ee[[posr]]] ]Of course this all is most senseful only for heads with Flat attribute.In[20]:=mapopat[expr, {f4, f2}, {f1, f3}, ox]Out[20]=ox[f1[a] f3[c]] ox[f2[b] f4[d]]In[23]:=mapopat[[Alpha] f1[a]f4[b][Beta] f2[c]f3[d], {f1, f3}, {f2, f4}, ox]Out[23]=[Alpha] [Beta] ox[f1[a] f3[d]] ox[f2[c] f4[b]]In[22]:=mapopat[h[f1[a], f4[b], f2[c], f3[d]], {f1, f3}, {f2, f4}, ox]Out[22]=h[ox[h[f1[a], f3[d]]], ox[h[f4[b], f2[c]]], h[]]finally another version using ReplacePart; not all ReplacePart though, butin that spirit:In[99]:=expr = f1[a]f2[b]f3[c]f4[d]In[100]:=rplopat[ee : head_[__], {e1_, e3_}, {e2_, e4_}, op_] /; (len = Length[ee]) >= 4 := Block[{head}, Module[{ pos = Join @@ (Position[ee, #, {1}] &) /@ Through[{e1, e3, e2,e4}[___]], posr, allpos = List /@ Range[len], rr}, posr = Complement[allpos, pos]; rr = ReplacePart[ee, ee, allpos, Join[pos, posr]]; Replace[rr, head[a_, b_, c_, d_, r___] :> head[op[head[a, b]], op[head[c, d]], head[r]]] ]]Blocking head prevents reordering (of rr) in case head has the Orderlessattribute.In[101]:=rplopat[expr, {f4, f2}, {f1, f3}, ox]Out[101]=ox[f1[a] f3[c]] ox[f2[b] f4[d]]In[103]:=rplopat[[Alpha] f1[a]f4[b][Beta] f2[c]f3[d], {f1, f3}, {f2, f4}, ox]Out[103]=[Alpha] [Beta] ox[f1[a] f3[d]] ox[f2[c] f4[b]]In[104]:=rplopat[h[f1[a], f4[b], f2[c], f3[d]], {f1, f3}, {f2, f4}, ox]Out[104]=h[ox[h[f1[a], f3[d]]], ox[h[f2[c], f4[b]]], h[]]--Hartmut ==== I need FrameLabels of the kind of H^s_z / H^p_Z and tried something>likeFrameLabel->{FontForm{HSuperscript[s]Subscript[ z] ...}}but s is too far away from z. How can I manage it that s is>directly above z ? Are there some backspace-characters to be used?HarrySubsuperscript[H, s, z]-Dale ==== >I would expect thatPlot[Sin[x]/Sin[x], {x, -2.5, -1.5}]would produce a horizontal line at y=1.However, on my Windows XP computer it produces a graph where the y value is>less than 1 at several points. Most notibly between x=-1.6 and x=-1.8Is this just an isolated case? Or does it happen to others? If so - why?Ken.The y axis has a very narrow range. The differences are very small. To see that, you can pull out the tick marks.In[13]:=yticks=FullOptions[gr,Ticks][[2]]In[15]:= InputForm[First/@yticks]Out[15]//InputForm={ 0.9999999999999981, 0.9999999999999991, 1., 1.000000000000001, 1.000000000000002, 0.9999999999999983, 0.9999999999999986, 0.9999999999999987, 0.9999999999999989, 0.9999999999999993, 0.9999999999999996, 0.9999999999999997, 0.9999999999999999, 1.0000000000000002, 1.0000000000000004, 1.0000000000000007, 1.0000000000000009, 1.0000000000000013, 1.0000000000000016, 1.0000000000000018, 1.000000000000002, 0.9999999999999979, 0.9999999999999977, 1.0000000000000022}The ragged shape is caused by roundoff error, if you increase the PlotRange of the y-axis you see what you expect.gr = Plot[Sin[x]/Sin[x], {x, -2.5, -1.5}, PlotRange -> {0, 2}]-Dale ==== Harald,You could try something like this...Plot[x, {x, 0, 1}, Frame -> True, FrameLabel -> {z, DisplayForm[ StyleBox[ RowBox[{SubsuperscriptBox[H, z, s], /, SubsuperscriptBox[H, z, p]}], FontSize -> 16]]}, ImageSize -> 500];where I enlarged the font size to make the label more legible.FontForm is an obsolete function and probably shouldnÕt be used. David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== Lucas,An addendum to my previous post (by the way, did you try to changeprecedences as I recommended?).If you are interested in using something like the normal summation notation,the summation symbol canÕt be CirclePlus, as CirclePlus is not an extensiblecharacter. I donÕt know all of the extensible characters, but onepossibility is [UnionPlus], which looks a bit like CirclePlus, with anopening on top. Of course, the usual syntax for [UnionPlus] is as a binaryoperator, and this is not what we want for our summation notation. So, weneed to incorporate new syntactical rules. There are three rules neededhere. A rule to convert 2 dimensional input into a mathematica internalexpression, a rule to convert the internal expression into a box structure,and a rule to convert the internal expression into a regular CirclePlusexpression. I give these three rules below:Clear[MakeExpression]MakeExpression[ RowBox[{UnderoverscriptBox[[UnionPlus],RowBox[{i_,=,k_}],n_], y_}], StandardForm]:=MakeExpression[RowBox[{BigCirclePlus[,y,,{,i,, ,k,,,n,}]}],StandardForm]Clear[MakeBoxes]MakeBoxes[ BigCirclePlus[y_, {i_, k_, n_}], f_] := RowBox[{UnderoverscriptBox[[UnionPlus], RowBox[{MakeBoxes[i, f], =, MakeBoxes[k, f]}], MakeBoxes[n, f]], MakeBoxes[y, f]}]BigCirclePlus[y_, {i_, k_Integer, n_Integer}] := CirclePlus @@ Table[y, {i, k, n}]As you can see, BigCirclePlus is used in the Mathematica internalrepresentation. If BigCirclePlus can be converted into a CirclePlusexpression (when the summation indices are integers), then the BigCirclePlusrule acts. Here are a couple of examples:!(([UnionPlus]+(i = 1)%M g[i]))!(([UnionPlus]+(i = 1)%5 g[i]/(1 + h[i]/5)))Just copy each of the above expressions into Mathematica and evaluate afterevaluating the above rules.Of course, if [UnionPlus] is not an acceptable substitute for an extensibleCirclePlus, then you will just need to petition Mathematica to include sucha feature in the future.Carl WollPhysics DeptU of Washington----- Original Message ----- Open up the file, search for CirclePlus, change the precedence from 450 to> 420, and then save. Of course, it would be wise to make a backup copy ofthe> file before you make any changes. Also, 420 is low enough to get the> behavior you desire, but you may want to experiment with otherprecedences.> Then, start mathematica and you will get the behavior you want. Carl Woll> Physics Dept> U of Washington > IÕm attempting to implement an abstract mathematica package in>mathematica that utilized the [CirclePlus] operator in an unusual>way. Specifically, the [CirclePlus] has a precidence lower than +>and introduces barriers in the computation. So, an expression such as> > a + b [CirclePlus] c + d --> (a+b) [CirclePlus] (c+d)> > The mathematica ouput of> > a + d + (b [CirclePlus] c) is incorrect. IÕve tried playing with the>PrecedenceForm[] function, but that does not seem able to produce the>desired effect.> > Also, I would like to introduce a notation like> > N>[BigCirclePlus] x[[i]] --> x[[1]] [CirclePlus] x[[2]] [CirclePlus]>....> i=0> > analagous to summation, but mathematica does not appear to offer the>CirclePlus in a large format. to relate this to the case above, x[1]>= (a + b) and>x[2] = (c + d), so each indexed element is a subexpression.> > Finally, I would like to be able to set up the CirclePlus operator>such that the following algebraic relations hold:> > Sum BigCirclePlus E = BigCirclePlus Sum E> i j ij j i ij> > d d>-- BigCirclePlus E = BigCirclePlus -- E>dx j j j dx j> > -Lucas Scharenbroich>-MLS Group / JPL> ==== I plot several curve depending on a parameter p and I want the PlotLabel toshow the value of p.What is wrong with the following ?pl[p_]:=Plot[Sin[x^p],{x,0,Pi},PlotLabel[Rule] p = p, DisplayFunction[Rule]Identity]Table[Show[pl[k], DisplayFunction[Rule]$DisplayFunction],{k,3}] ==== What is your operating system? How much memory do you have in your machine?Also, how big is your pagefile? Sounds to me like the rebuild ran outof room to do its thing in. I just installed Mathematica 4.2, and had no problem rebuilding the help index.Subsequently, I ahd no problem using the Help browser either.Hope that helps!....Terry>IÕd start with the following FAQ.> >http://support.wolfram.com/mathematica/interface/helpbrowser /howrebuildindex.html> >-Dale Sorry that i failed say it immediately in a first place, but of course> i did try it FAQ at first, and both tried to delete cache and rebuild> index, but results where the same - whenever i try to invoke help> browser (or rebuild index, for that matter), mathematica stops> responding (i did read your answer to the same question asked> a week ago before - actually that is why i turned to the FAQ). ==== I too have been unable to get the help browser functioning. I haveexactly the same problem. When trying to open the help browser it getsto the point where it says scanning index file and freezes. I triedall the suggestions in the faq and the links provided here to noavail. IÕm running Winows 2000 with service pack 3. I have 512mb ofmemory with a 768mb pagefile on a separate drive, so I donÕt thinkthatÕs an issue. Mathematica 4.1 ran just fine on this setup, sojudging by the number of other people affected by this, IÕd say itÕssome kind of bug with 4.2. Hopefully Wolfram will address this witheither a link that will provide a fix that actually works, or a patch.>What is your operating system? How much memory do you have in your machine?>Also, how big is your pagefile? Sounds to me like the rebuild ran out>of room to do its thing in. I just installed Mathematica 4.2, and had no problem rebuilding the help index.>Subsequently, I ahd no problem using the Help browser either.>Hope that helps!>....Terry>>IÕd start with the following FAQ.>http://support.wolfram.com/mathematica/interface/ helpbrowser/howrebuildindex.html>-Dale>> Sorry that i failed say it immediately in a first place, but of course>> i did try it FAQ at first, and both tried to delete cache and rebuild>> index, but results where the same - whenever i try to invoke help>> browser (or rebuild index, for that matter), mathematica stops>> responding (i did read your answer to the same question asked>> a week ago before - actually that is why i turned to the FAQ).>Reply-To: tharter@attglobal.net ==== Your machine information and OS EXACTLY matches mine (except that my pagefileis NOT on a separate physical drive -- perhaps this is a clue as to where to start),and I had no problem building the help file. Hence, as you say, this mustbe a problem for Wolfram to address. Perhaps, someone from WRI will enlightenus via this newsgroup.....Terry I too have been unable to get the help browser functioning. I have> exactly the same problem. When trying to open the help browser it gets> to the point where it says scanning index file and freezes. I tried> all the suggestions in the faq and the links provided here to no> avail. IÕm running Winows 2000 with service pack 3. I have 512mb of> memory with a 768mb pagefile on a separate drive, so I donÕt think> thatÕs an issue. Mathematica 4.1 ran just fine on this setup, so> judging by the number of other people affected by this, IÕd say itÕs> some kind of bug with 4.2. Hopefully Wolfram will address this with> either a link that will provide a fix that actually works, or a patch. >What is your operating system? How much memory do you have in your machine?>Also, how big is your pagefile? Sounds to me like the rebuild ran out>of room to do its thing in.> > I just installed Mathematica 4.2, and had no problem rebuilding the help index.>Subsequently, I ahd no problem using the Help browser either.>Hope that helps!>....Terry> >>IÕd start with the following FAQ.>> >>http://support.wolfram.com/mathematica/interface/ helpbrowser/howrebuildindex.html>> >>-Dale> Sorry that i failed say it immediately in a first place, but of course>> i did try it FAQ at first, and both tried to delete cache and rebuild>> index, but results where the same - whenever i try to invoke help>> browser (or rebuild index, for that matter), mathematica stops>> responding (i did read your answer to the same question asked>> a week ago before - actually that is why i turned to the FAQ).> ==== Try deleting ...Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb> Your machine information and OS EXACTLY matches mine (except that mypagefile> is NOT on a separate physical drive -- perhaps this is a clue as to whereto start),> and I had no problem building the help file. Hence, as you say, thismust> be a problem for Wolfram to address. Perhaps, someone from WRI willenlighten> us via this newsgroup.> ....Terry> > I too have been unable to get the help browser functioning. I have>exactly the same problem. When trying to open the help browser it gets>to the point where it says scanning index file and freezes. I tried>all the suggestions in the faq and the links provided here to no>avail. IÕm running Winows 2000 with service pack 3. I have 512mb of>memory with a 768mb pagefile on a separate drive, so I donÕt think>thatÕs an issue. Mathematica 4.1 ran just fine on this setup, so>judging by the number of other people affected by this, IÕd say itÕs>some kind of bug with 4.2. Hopefully Wolfram will address this with>either a link that will provide a fix that actually works, or a patch.> >What is your operating system? How much memory do you have in yourmachine?>>Also, how big is your pagefile? Sounds to me like the rebuild ran out>>of room to do its thing in.> I just installed Mathematica 4.2, and had no problem rebuildingthe help index.>>Subsequently, I ahd no problem using the Help browser either.>>Hope that helps!>>....Terry> >>IÕd start with the following FAQ.> >http://support.wolfram.com/mathematica/interface/helpbrowser /howrebuildindex.html> >>-Dale>> Sorry that i failed say it immediately in a first place, but ofcourse> i did try it FAQ at first, and both tried to delete cache and rebuild> index, but results where the same - whenever i try to invoke help> browser (or rebuild index, for that matter), mathematica stops> responding (i did read your answer to the same question asked> a week ago before - actually that is why i turned to the FAQ).>> ==== >What is your operating system? How much memory do you have in your machine?>Also, how big is your pagefile? Sounds to me like the rebuild ran out>of room to do its thing in.I use W2k Pro + SP2, Athlon 1.33, 260MB RAM (DDR) + 630MB swap file -doesnÕt seems to me like a memory problem... ==== does anyone know whether there is an effective way of simulatingpaths of Brownian motion (Wiener process) in dimensions 1, 2, 3?I could you a random walk approach, but this seems to be computationallynot very efficient and I am not sure whether it is even a goodapproximation to the 3-D BM. Any help on Mathematica codingand in the forms of algorithms will be greatly appreciated.Janusz Kawczak. ==== What is the problem with this integration. Its keep on running andnot coming out.[CapitalPsi][r_, [Theta]_, [Phi]_][4] := r Exp[-r/2]Sin[[Theta]]Cos[[Phi]];[CapitalPsi][r_, [Theta]_, [Phi]_][11] := r^2 Exp[-r/2]Sin[[Theta]]Cos[[Theta]]Cos[[Phi]];[ScriptCapitalH][ r_, [Theta]_, [Phi]_] := (-[HBar]/ 2 m (1/(r^2 Sin[[Theta]]))(Sin[[Theta]]D[r^2 D[#, r], r]+ D[Sin[[Theta]] D[#, [Theta]], [Theta]] + 1/(Sin[[Theta]])(D[D[#, [Phi]], [Phi]])) + e V &)Ç_bho = Sum[ Sum[ Integrate[[CapitalPsi][r, [Theta], [Phi]][ j]([ScriptCapitalH][r, [Theta], [Phi]])[[CapitalPsi][ r, [Theta], [Phi]][i]], {r, 0, h}, {[Theta], 0, Pi}, {[Phi], 0, 2 Pi}], {i, 11, 11}], {j, 4, 4}] Raj Kumar Gupta ==== I know its not a good idea to run programs as root on a Unix machine and donÕtnormally do so. However, can anyone tell me what is happening here? A mathematical program ÔMathematica'has been installed in /usr/local on thisSun Ultra 60. The correct password was entered and it all runs fine with mynormal login (davek), which has a shell of /bin/tcsh. If I switch user to root, which has the normal /sbin/sh shell, Mathematica runsfine. However, if I switch user to ÔroottcshÕ, which as a uid of 0, but a shellof /bin/tcsh, Mathematica fails to run, saying the password file is invalid. I canÕt understand while executing a program that works fine as root, fine as anormal user, yet does not when run when execution is attempted as another userwith root privileges. *** Runs fine as a formal user ÔdavekÕ******wren /export/home/davek % mathMathematica 4.0 for SolarisCopyright 1988-1999 Wolfram Research, Inc. -- Motif graphics initialized -- In[1]:= Quit***Mathematica is run from /usr/local/bin/math, which is a symbolic link****wren /export/home/davek % which math/usr/local/bin/mathwren /export/home/davek % ls -l /usr/local/bin/mathlrwxrwxrwx 1 root other 53 Jun 16 08:18 /usr/local/bin/math ->/usr/local/mathematica-4.0.2/Executables/Solaris/math*** Mathematica runs fine as root****wren /export/home/davek % suPassword: # /usr/local/bin/mathMathematica 4.0 for SolarisCopyright 1988-1999 Wolfram Research, Inc. -- Motif graphics initialized -- In[1]:= Quit***Switch to a user with uid=0, shell =/bin/tcsh ***wren /export/home/davek % su - roottcshPassword: Sun Microsystems Inc. SunOS 5.9 Generic May 2002***Now Mathematica does not run***wren / # /usr/local/bin/mathMathematica 4.0 for SolarisCopyright 1988-1999 Wolfram Research, Inc./usr/local/mathematica-4.0.2/Configuration/Licensing/ mathpass:1: Incomplete password entry.No valid single-machine password entry for Mathematica found.Machine name: wrenMathID: [deleted by moderator]You will need a valid license ID and password in orderto proceed. Go to http://register.wolfram.com orconsult your Getting Started documentation.Enter the name of your organization: ***Here are the contents of the password files*******with the contents of /etc/shadow changed for security resons***wren / # cat /etc/passwd | grep rootroot:x:0:1:Super-User:/:/sbin/shroottcsh:x:0:1:Dr. David Kirkby:/:/bin/tcshwren / # cat /etc/shadow | grep rootroot:TA9addfsfsdsdfdddMTxHU:11266::::::roottcsh: dgddsdfsdffsdnSw:11198::::::-- Dr. David Kirkby PhD,web page: http://www.david-kirkby.co.ukAmateur radio callsign: G8WRB ==== I managed to post this on alt.math.recreational by mistake, and confuseeveryone!I am having a bit of trouble with showing the shapes of pentominoes. Thelist of pentominoes is 12 x 5 x 2, for 12 pentominoes x 5 squares x {X,Y}coordinate of the square on a zero-origin basis.Just for completeness ...pentominoes ={ {{0, 0}, {1, 0}, {1, 1}, {1, 2}, {2, 1}}, (*F*){{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}, (*I*){{0, 0}, {1, 0}, {2, 0}, {3, 0}, {0, 1}}, (*L*){{0, 0}, {1, 0}, {2, 0}, {2, 1}, {3, 1}}, (*N*){{0, 0}, {1, 0}, {2, 0}, {0, 1}, {1, 1}}, (*P*){{0, 0}, {1, 0}, {2, 0}, {1, 1}, {1, 2}}, (*T*){{0, 0}, {1, 0}, {2, 0}, {0, 1}, {2, 1}}, (*U*){{0, 0}, {1, 0}, {2, 0}, {0, 1}, {0, 2}}, (*V*){{0, 0}, {1, 0}, {1, 1}, {2, 1}, {2, 2}}, (*W*){{1, 0}, {0, 1}, {1, 1}, {2, 1}, {1, 2}}, (*X*){{0, 0}, {1, 0}, {2, 0}, {3, 0}, {1, 1}}, (*Y*){{0, 0}, {1, 0}, {1, 1}, {1, 2}, {2, 2}} (*Z*)}When I display them with the code below, the aspect ratio is correct *within each pentomino* but they are not scaled equivalently. I would appreciate a pointer to what I have done wrong. The only solution I have been able to develop so far effectively places each of the 12 pentominoes at a different location in the plane, and then draws the whole region in one go.Show[ GraphicsArray[ Partition[ Table[ Graphics[ Map[Rectangle[#, (# + {1, 1})] &, pentominoes[[i]]], AspectRatio -> Automatic ], {i, 12}], 6] ]]-- Mark R. Diamond ==== > I plot several curve depending on a parameter p and I want the PlotLabel to> show the value of p.> What is wrong with the following ? pl[p_]:=Plot[Sin[x^p],{x,0,Pi},PlotLabel[Rule] p = p,> DisplayFunction[Rule]Identity] Table[Show[pl[k],DisplayFunction[Rule]$DisplayFunction],{k,3} ]>Use ToString and StringJoinpl[p_]:=Plot[Sin[x^p],{x,0,Pi}, PlotLabel->p = <> ToString[p], DisplayFunction->Identity];Alternatively, you could use StringFormpl[p_]:=Plot[Sin[x^p],{x,0,Pi}, PlotLabel->StringForm[p = `` , p], DisplayFunction->Identity];Bob HanlonChantilly, VA USA ==== In a message dated 8/31/02 1:58:36 AM, berlusconi_pagliusi@fis.unical.it> IÕd like to use Mathematica 4.0 to write a function having different> expressions in different domainÕs intervals.> LetÕs say: F[x_]= x^2 if 0 x+1 if x>=6 I know ItÕs a stupid syntax problem, but I really do not know how/where to> search the solution on the Mathematica Book>Just for grins here are several methods:f1[x_/;x<=0] := 0 ;f1[x_/;0=6] := x+1;f2[x_] := x^2*UnitStep[x]+(x+1-x^2)*UnitStep[x-6];f3[x_] := Which[ x<=0, 0, 0=6, x+1];f4[x_] := If[0=6, x+1,0]];f5[x_] := Switch[x, _?(#<=0&), 0, _?(0<#<6&), x^2, _?(#>=6&), x+1 ]f6[x_?NumericQ] := {0,x^2,x+1}[[Position[ {x<=0,0=6}, True][[1,1]]]];Needs[Calculus`Integration`];(* needed for definition of Boole *)f7a[x_?NumericQ] := Evaluate[ (Boole /@ {0=6}). {x^2,x+1}];Off[Part::pspec];f7b[x_?NumericQ] := Evaluate[ {0,x^2,x+1}[[1+Tr[Boole /@ {x>0, x>=6}]]]];f8[x_?NumericQ] := Cases[ {{x<=0, 0}, {0=6, x+1}}, {True, z_} :>z][[1]];f9[x_?NumericQ] := DeleteCases[ {{x<=0, 0}, {0=6, x+1}}, {False, z_}][[1,2]];f10[x_?NumericQ] := Select[ {{x<=0, 0}, {0=6, x+1}}, First[#]&][[1,2]];f11[x_?NumericQ] := Last[Sort[ {{x<=0, 0}, {0=6, x+1}}]][[2]];f12[x_?NumericQ] := Module[{n=1}, While[{x<6,x<0, False}[[n]], n++]; {x+1,x^2,0}[[n]]];Generating some test points:ts = {Random[Real,{-5,0}],0, Random[Real,{0,6}],6,Random[Real,{6,15}]};Checking the different representationsEqual[(# /@ pts)& /@ {f1,f2,f3,f4,f5,f6,f7a,f7b,f8,f9,f10,f11,f12}]TrueTo pick a favorite, look at how the different definitions behave.Of the definitions that evaluate with symbolic input, only f2 and f4simplify with assumptions. For example,FullSimplify[#[x]& /@ {f2,f4}, 1 I am trying to implement the inner product in the space of> complex-valued, square integrable functions over [-1/2,1/2], which can> be expressed in Mathematica code as inner[f_Function,g_function]:=Integrate[Conjugate[f[x]]*g[x], {x,-1/2,1/2}] This is simple enough. Problem is, Mathematica seamingly cannot> evaluate the Integral for even the simplest of functions:> In[10]:=inner[#&,#&] Out[10]:=!([Integral]_(-(1/2))%(1/2)(x Conjugate[> x]) [DifferentialD]x) As you see, the Integrate returns unevaluated. It works fine if I> remove the Conjugate. Unfortunately the Conjugate is needed for> positive definiteness. Various variants with Composition, Re and Im etc. donÕt work either. This should be a So how do I get Integrate to work with Conjugate?Would including Simplify or FullSimplify provide the results that youn want?inner[f_Function,g_Function]:= Integrate[Simplify[Conjugate[f[x]]*g[x], Element[x, Reals]], {x, -1/2, 1/2}];inner[#&,#&]1/12Bob HanlonChantilly, VA USA ==== I was wondering if there are any scripts/functions out there to allow me todo decision tree classification with Mathematica, similar to S+ typeanalysis?--j-- Jonathan GreenbergGraduate Group in Ecology, U.C. Davishttp://www.cstars.ucdavis.edu/~jongreenhttp:// www.cstars.ucdavis.eduAIM: jgrn307 or jgrn3007MSN: jgrn307@msn.com or jgrn3007@msn.com ==== PasKo,You could look up piecewise functions in the Master Index in Help.Unfortunately, the book does not have a unified discussion of methods fordefining piecewise functions.The first method is to use a set of conditional definitions. Forcompleteness I made f[x] = 0 if one of the conditional definitions is notmet.f[x_] /; 0 < x < 6 := x^2f[x_] /; x >= 6 := x + 1f[x_] := 0Plot[f[x], {x, 0, 10}];The second method is to use a Which statement.Clear[f];f[x_] := Which[ 0 < x < 6, x^2, x >= 6, x + 1, True, 0]Plot[f[x], {x, 0, 10}];The above methods are fine in many cases, but if you want to performfunctions on f, such as differentiation or integration, you should use theUnitStep function. So our third method is...Clear[f]f[x_] := x^2(UnitStep[x] - UnitStep[x - 6]) + (x + 1)UnitStep[x - 6]Plot[fÕ[x], {x, 0, 10}];Plot[Integrate[f[y], {y, 0, x}] // Evaluate, {x, 0, 10}];David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/PasKo.= ===> I am trying to implement the inner product in the space of> complex-valued, square integrable functions over [-1/2,1/2], which can> be expressed in Mathematica code as> inner[f_Function,g_function]:=Integrate[Conjugate[f[x]]*g[x], {x,-1/2,1/2}]> This is simple enough. Problem is, Mathematica seamingly cannot> evaluate the Integral for even the simplest of functions:> In[10]:=inner[#&,#&]> Out[10]:=!([Integral]_(-(1/2))%(1/2)(x Conjugate[> x]) [DifferentialD]x)> As you see, the Integrate returns unevaluated. It works fine if I> remove the Conjugate. Unfortunately the Conjugate is needed for> positive definiteness.> Various variants with Composition, Re and Im etc. donÕt work either.> This should be a So how do I get Integrate to work with Conjugate?> Andreas> --> True Pleasure in this society is more dangerous than bank robbery.The deficiency has been addressed in our development version, at leastto the extent that it works on the simple example given above. For awork-around in version 4 one might do as below.inner2[f_Function, g_Function] := Integrate[(Re[f[x]] - I*Im[f[x]])*g[x], {x, -1/2, 1/2}] In[2]:= inner2[# &, # &] 1Out[2]= -- 12Daniel LichtblauWolfram Research ==== Andreas,inner[f_Function, g_Function] := Integrate[ComplexExpand[Conjugate[f[x]]]*g[x], {x, -1/2, 1/2}]inner[# &, # &]1/12IÕm not too knowledgable about using complex functions in Mathematica butsometimes I think that ComplexExpand should be renamed ComplexSimplify.One very often needs it.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ x]) [DifferentialD]x)As you see, the Integrate returns unevaluated. It works fine if Iremove the Conjugate. Unfortunately the Conjugate is needed forpositive definiteness.Various variants with Composition, Re and Im etc. donÕt work either.This should be a So how do I get Integrate to work with Conjugate?Andreas--True Pleasure in this society is more dangerous than bank robbery. ==== I work for Gould Academy and am trying to make it really easy for thescripts which I thought did that really well. But, the scienceteachers said it was too hard. So, I have been making it so that Inputboxes prompt the students for the filename type, regression type, etc.I now have been thinking that it would be great if there could be anInput box which asks the student what they want to name there graph,function, data, and have them simply call that variable when they wantto use the graph, function, data. this is Instead of typingVariableName = FilePlot[] which the science teachers think is forcingthe students to become mathematica programmers.Charles ==== Use Condition (/;):In[1]:=f[x_] := x^2 /; 0 < x < 6;f[x_] := x + 1 /; 6 <= x;Plot[f[x], {x, 0, 10}];Avoid using capital initial letters for your definitions: they are usuallyreserved for in-built functions in Mathematica.Tomas GarzaMexico City----- Original Message -----> I know ItÕs a stupid syntax problem, but I really do not know how/where to> search the solution on the Mathematica Book> PasKo. ==== try something like this:foo[x_] := Block[{y}, If[x > 0 && x < 6, y = x^2, If[x >= 6, y = x + 1]] ]for details look at:?And?If?Block----- Original Message -----> I know ItÕs a stupid syntax problem, but I really do not know how/where to> search the solution on the Mathematica Book> PasKo.> ==== You can use If, Which, Conditionf[x_] := If[0 <= x && x <= 6, x^2, x + 1];g[x_] := 2*x^2 /; 0 <= x <= 6;g[x_] := 2*x + 1 /; x > 6;h[x_] := Which[0 <= x <= 6, 3*x^2, 6 < x, 3*x + 1]Plot[{f[x], g[x], h[x]}, {x, 0, 10}]> IÕd like to use Mathematica 4.0 to write a function having different> expressions in different domainÕs intervals.> LetÕs say: F[x_]= x^2 if 0 x+1 if x>=6 I know ItÕs a stupid syntax problem, but I really do not know how/where to> search the solution on the Mathematica Book*******************milkcartmilkcart@m17.alpha-net.ne.jp** ********************* ==== Dear MathGroup,IÕd like to use Mathematica 4.0 to write a function having differentexpressions in different domainÕs intervals.LetÕs say:F[x_]= x^2 if 0=6I know ItÕs a stupid syntax problem, but I really do not know how/where tosearch the solution on the Mathematica BookPasKo. ==== > Dear MathGroup,> IÕd like to use Mathematica 4.0 to write a function having different> expressions in different domainÕs intervals.> LetÕs say: F[x_]= x^2 if 0 x+1 if x>=6IÕd like to thank everyone. :-)In the meantime IÕve found an answer to my problem using Which statement,but as far as you suggest IÕm going to use the more versatile UnitStepfunction.PasKoP.S.Delete berlusconi_ to reply. ==== Andreas,One simple approach is to write:F[x_]:= x^2 /; 0=6Hope this helps. You want want to look up /; in the Help Browser.Mark Westwood> Dear MathGroup,> IÕd like to use Mathematica 4.0 to write a function having different> expressions in different domainÕs intervals.> LetÕs say:> F[x_]= x^2 if 0 x+1 if x>=6> I know ItÕs a stupid syntax problem, but I really do not know how/where to> search the solution on the Mathematica Book> PasKo. ==== Try the following (IÕm quoting from Tom Wickham-Jones'book on MathematicaGraphics, p. 41):In[1]:=pl[p_] := Plot[Sin[x^p], {x, 0, Pi}, PlotLabel -> StringForm[p = `1`, p], DisplayFunction -> Identity]In[12]:=Table[Show[pl[k], DisplayFunction -> $DisplayFunction], {k, 3}]Tomas GarzaMexico City----- Original Message ----- Table[Show[pl[k],DisplayFunction[Rule]$DisplayFunction],{k,3} ] ==== Andre,You should use SequenceForm in your definition (instead of multiplicationwhich reorders the items) .pl[p_] := Plot[Sin[x^p], {x, 0, Pi}, PlotLabel -> SequenceForm[p = , p], DisplayFunction -> Identity]David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== > I am trying to implement the inner product in the space of> complex-valued, square integrable functions over [-1/2,1/2], which can> be expressed in Mathematica code as> inner[f_Function,g_function]:=Integrate[Conjugate[f[x]]*g[x], {x,-1/2,1/2}]> ...Mathematica cannot Integrate through Conjugate in general. I suspect,however, that most or all specific cases where you cannot expand Conjugateare not integrable in closed form anyway. So I suggest that you attempt toexpand the Conjugate before integrating:inner[f_Function, g_Function] := Integrate[ComplexExpand[f[x] Conjugate[g[x]]], {x, -1/2, 1/2}]Although the above function works for the few simple cases I tried just now,my experience tells me that the following, more cumbersome form might bemore robust: inner[f_Function, g_Function] := Integrate[Simplify[ComplexExpand[ f[x] Conjugate[g[x]], TargetFunctions -> {Re, Im}]], {x, -1/2, 1/2}]Hope this helps,Tom Burton ==== > IÕd like to use Mathematica 4.0 to write a function having different> expressions in different domainÕs intervals.> LetÕs say:> F[x_]= x^2 if 0 x+1 if x>=6> I know ItÕs a stupid syntax problem, but I really do not know how/where to> search the solution on the Mathematica Book> Several choices exist. An advantage of the following choice,F[x_] := If[ x<6, x^2, x+1 ]is that Mathematica can integrate and different this form analytically.Tom BurtonReply-To: Peltio ==== Sergio Milo ha scritto nel messaggio ...> Dear Math Group.> Anybody can explain me what this it means.> Out[22]=!(Null^49)It seems that Mathematica has produced 49 times in a row a Null result andinterpreted it as a variable in a multiplication.As far as I know Mathematica shouldnÕt compute the powers of Null, though.And most importantly, it should not output a Null, at least in standardconditions.Could it be that you inadvertently redefined Null, after unprotecting it?(yes I know, it woldnÕt be much of an inadvertent behaviour...)Does this happen in a fresh new Mathematica session?saluti,Peltiopeltio at despammed dot comantispam address in reply-to ==== Dear group.I am trying to figure out how I can do multi-dimensional kernel densityestimation with Mathematica. I know how I can do it with one variable, butI was wondering if Mathematica supports kernel density estimation with 3variables.Sincerely,Marcelo--------------------------------- -----------------------------Marcelo MoreiraDepartment of Economics - Harvard UniversityLittauer M6 - North Yard1875 Cambridge StreetCambridge, MA 02138http://post.economics.harvard.edu/faculty/moreira/ moreira.html------------------------------------------------- ------------- ==== I liked this very much.For n=4 there are 3^n=81 possible combinations, but only 40 positive ones -the rest would be 0 and each of the positive ones multiplied by -1. As Bobstated, this is obtained by:(3^n-1)/2=40For these 40 positive integers to match 1 to 40 correspondingly, the biggestshould be 40 (also, the smallest should be 1). So we have:a+b+c+d=40 or 1+b+c+d=40 (we state that a> I have a very interesting math problem:If I have a scales,and I>> have 40 things that their mass range from 1~40 which each is a nature>> number,and now I can only make 4 counterweights to measure out each>> mass of those things.Question:What mass should the counterweights>> be???>> The answer is that 1,3,9,27 and I wnat to use mathematica to solve>> this problem.>> In fact,I think that this physical problem has various>> answer,ex.2,4,10,28>> this way also work,because if I have a thing which weight 3 , and I>> can measure out by comparing 2<3<4 . But,If I want to solve this math>> problem:>> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature> numbers.>> and {k1,k2,k3,k4}={1,0,-1}>> How to solve it ??>> mathematica solving method. appreciate any idea sharing>> sincerely>> bryan> Just use brute force. Needs[DiscreteMath`Combinatorica`]; var = {a, b, c, d}; n = Length[var]; s = Outer[Times, var, {-1, 0, 1} ]; f = Flatten[Outer[Plus, Sequence@@s]]; Since the length of f is just 3^n then the range of numbers> to be covered should be {-(3^n-1)/2, (3^n-1)/2}.> Consequently, the largest of the weights can not exceed> (3^n-1)/2 - (1+2+...+(n-1)) or ((3^n-1) - n(n-1))/2 34 Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ KSubsets[Range[((3^n-1) - n(n-1))/2], n], Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&]) {{a -> 1, b -> 3, c -> 9, d -> 27}}> Bob Hanlon> Chantilly, VA USA> ==== >IÕm sorry for that my question is not clear,I have correct below.>>ajvp7h$ibk$1@smc.vnet.net>...> I have a very interesting math problem:If I have a scales,and I> have 40 things that their mass range from 1~40 which each is a nature> number,and now I can only make 4 counterweights to measure out each> mass of those things.Question:What mass should the counterweights> be???> The answer is that 1,3,9,27 and I wnat to use mathematica to solve> this problem.> In fact,I think that this physical problem has various> answer,ex.2,4,10,28> this way also work,because if I have a thing which weight 3 , and I> can measure out by comparing 2<3<4 . But,If I want to solve this math> problem:> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature>numbers.> and {k1,k2,k3,k4}={1,0,-1}> How to solve it ?? > mathematica solving method. appreciate any idea sharing> sincerely > bryan>>Just use brute force.Needs[DiscreteMath`Combinatorica`];>var = {a, b, c, d}; n = Length[var];>s = Outer[Times, var, {-1, 0, 1} ];>f = Flatten[Outer[Plus, Sequence@@s]];>Since the length of f is just 3^n then the range of numbers>to be covered should be {-(3^n-1)/2, (3^n-1)/2}.>Consequently, the largest of the weights can not exceed>(3^n-1)/2 - (1+2+...+(n-1)) or ((3^n-1) - n(n-1))/2>34>Thread[var->#]& /@> (First /@ Select[{var,f} /. Thread[var->#]& /@> KSubsets[Range[((3^n-1) - n(n-1))/2], n],> Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&])>{{a -> 1, b -> 3, c -> 9, d -> 27}}>A modification to my earlier response. Since you are try to cover all of the values up to (3^n-1)/2 then you can speed up the brute force method by requiring that a+b+c+d == (3^n-1)/2Needs[DiscreteMath`Combinatorica`];var = {a,b,c,d}; n = Length[var]; m = (3^n-1)/2;s = Outer[Times, var, {-1,0,1} ];f = Flatten[Outer[Plus, Sequence@@s]];k= Select[KSubsets[Range[m - n(n-1)/2], n], (Plus @@ #) == m&];Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ k, Sort[#[[2]]] == Range[-m,m]&]){{a -> 1, b -> 3, c -> 9, d -> 27}}Bob HanlonChantilly, VA USA ==== On 8/31/02 at 1:25 AM, berlusconi_pagliusi@fis.unical.it (Paskoski)>Dear MathGroup, IÕd like to use Mathematica 4.0 to write a function>having different expressions in different domainÕs intervals. LetÕs>say:F[x_]= x^2 if 0=6Tryf[x_]:= x^2 /; 0=6The /; specfies a conditional rule. You can define a fuction with as many pieces as you like in this manner ==== help,urgent how do you put the numbers in the circles ==== There are many cases in graphics, and otherwise, where it is useful toobtain two orthogonal unit vectors to a given vector. I know a number ofways to do it, but they all seem to be slightly inelegant. I thought I wouldpose the problem to MathGroup. Who has the most elegant Mathematicaroutine...OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will returntwo unit vectors orthogonal to each other and to v.You can assume that v is nonzero.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== My 2 cents'worth:OrthogonalUnitVectors[v:{_, _, _}] := With[{u = Which[ (w = {0,v[[3]],-v[[2]]}).w != 0, w, (w = {v[[3]],0,-v[[1]]}).w != 0, w, (w = {v[[2]],-v[[1]],0}).w != 0, w ] }, #/Sqrt[#.#]& /@ {u, Cross[u,v]}]---Selwyn Hollis> There are many cases in graphics, and otherwise, where it is useful to> obtain two orthogonal unit vectors to a given vector. I know a number of> ways to do it, but they all seem to be slightly inelegant. I thought I would> pose the problem to MathGroup. Who has the most elegant Mathematica> routine...> OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will return> two unit vectors orthogonal to each other and to v.> You can assume that v is nonzero.> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/> ==== My 2 centsÕ worth:OrthogonalUnitVectors[v:{_, _, _}] := With[{u = Which[ (w = {0,v[[3]],-v[[2]]}).w != 0, w, (w = {v[[3]],0,-v[[1]]}).w != 0, w, (w = {v[[2]],-v[[1]],0}).w != 0, w ] }, #/Sqrt[#.#]& /@ {u, Cross[u,v]}]---Selwyn Hollis> There are many cases in graphics, and otherwise, where it is useful to> obtain two orthogonal unit vectors to a given vector. I know a number of> ways to do it, but they all seem to be slightly inelegant. I thought I would> pose the problem to MathGroup. Who has the most elegant Mathematica> routine...> OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will return> two unit vectors orthogonal to each other and to v.> You can assume that v is nonzero.> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/> ==== The following behavior seems to have gone undetected through severalrevisions of Mathematica:When a SeriesData object is multiplied by 0, Mathematica (versions 3.0,4.02, 4.1 for Mac, and 4.0 for Windows) does not give 0. For example,0*Series[f[x], {x,0,3}]gives O[x]^4, even though 0*x_SeriesData gives 0!Because of this, the following incorrect result is obtained in version4:DiagonalMatrix[{a,b}].{{x^2 + O[x]^3, O[x]^2}, {O[x]^2, x^2 + O[x]^3}}gives {{O[x]^2, O[x]^2}, {O[x]^2, O[x]^2}} !!In this example version 3 gives the correct result, even though,a*(x^2 + O[x]^3) + 0*O[x]^2gives O[x]^2 - same as in version 4. (Apparently, Dot in version 3 doesnot include in the sum terms multiplied by 0).The easiest way to correct this bug, without altering Times, is to useUpSet:Unprotect[SeriesData]; Times[0,x_SeriesData]^= 0; Protect[SeriesData];(ignore the UpSet::write message)I wonder how many people have obtained incorrect results because of thisbug...Sotirios Bonanoshttp://www.inp.demokritos.gr/~sbonano/SB.html ==== In[4] := f[x_ /; 0 < x < 6] := x^2In[5]:=f[x_/; x >= 6]:=x+1Meilleures salutationsFlorian JaccardEICN-HES-----Message dÕorigine-----Envoy.8e : sam., 31. ao.9et 2002 07:26è : mathgroup@smc.vnet.netObjet : How to ...?Dear MathGroup,IÕd like to use Mathematica 4.0 to write a function having differentexpressions in different domainÕs intervals.LetÕs say:F[x_]= x^2 if 0=6I know ItÕs a stupid syntax problem, but I really do not know how/where tosearch the solution on the Mathematica BookPasKo. ==== This works :pl[p_] := Plot[Sin[x^p], {x, 0, Pi}, DisplayFunction -> Identity]lab[p_] := Graphics[{Text[p = , {1.5, 1.2}], Text[p, {1.7, 1.2}]}]Table[Show[{pl[k], lab[k]}, DisplayFunction -> $DisplayFunction], {k, 3}]Meilleures salutationsFlorian JaccardEICN-HES-----Message dÕorigine-----Envoy.8e : sam., 31. ao.9et 2002 07:26è : mathgroup@smc.vnet.netObjet : PlotLabelI plot several curve depending on a parameter p and I want the PlotLabel toshow the value of p.What is wrong with the following ?pl[p_]:=Plot[Sin[x^p],{x,0,Pi},PlotLabel[Rule] p = p, DisplayFunction[Rule]Identity]Table[Show[pl[k], DisplayFunction[Rule]$DisplayFunction],{k,3}] ==== David,Here is my solution, using NullSpace:OrthogonalUnitVectors[v:{_,_,_}]:=(Needs[ LinearAlgebra`Orthogonalization`]; Map[LinearAlgebra`Orthogonalization`Normalize, NullSpace[{v,{0,0,0},{0,0,0}}]])One problem with any solution is that it should never be possible to obtainthe two output vectors as continuous functions of the input vector, sincethat would be equivalent to the combing of a hedgehog in a vortexfree way.Ingolf Dahlf9aid@fy.chalmers.seChalmers UniversitySweden-----Original Message-----David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== > OrthogonalUnitVectors[v:{_,_,_}]:=(Needs[LinearAlgebra` Orthogonalization`]> ;> Map[LinearAlgebra`Orthogonalization`Normalize,> NullSpace[{v,{0,0,0},{0,0,0}}]])> One problem with any solution is that it should never be possible to obtain> the two output vectors as continuous functions of the input vector, since> that would be equivalent to the combing of a hedgehog in a vortexfree way.NullSpace is fast, but LinearAlgebra`Orthogonalization`Normalize is slow. Soif you care about speed, perhaps #/Sqrt[#.#]& is better.I donÕt know hedgehogs, but if I visualize a fur-covered ball, then I cansee as how a continuous solution is not possible everywhere. In that case, Imight like to control the discontinuity. NullSpace create a curve ondiscontinuities on the unit sphere (a vortex curve, if you will). Try, e.g.,ContourPlot[{v, w} = NullSpace[{{y, .3, x}, {0, 0, 0}, {0, 0, 0}}]; v[[3]],{x, -1, 1}, {y, -1, 1}, PlotPoints -> 100]ItÕs not obvious to me where this curve is going to be. A nice feature ofthe following simple scheme,triad[u_, r_:{1, 0, 0}] := Module[{v = Cross[u, r]}, #/Sqrt[# . #] & /@{u, v, Cross[u, v]}]is that you know that the two points of discontinuity are where r and -rcross the unit sphere. triad is slow, but if you commit to a particular rand then evaluate and simplify,FullSimplify[trial[{u,v,w}]the resulting expression evaluates pretty fast for specific numerical{u,v,w}.Tom Burton ==== > OrthogonalUnitVectors[v:{_,_,_}]:=(Needs[LinearAlgebra` Orthogonalization`]> ;> Map[LinearAlgebra`Orthogonalization`Normalize,> NullSpace[{v,{0,0,0},{0,0,0}}]])> One problem with any solution is that it should never be possible to obtain> the two output vectors as continuous functions of the input vector, since> that would be equivalent to the combing of a hedgehog in a vortexfree way.NullSpace is fast, but LinearAlgebra`Orthogonalization`Normalize is slow. Soif you care about speed, perhaps #/Sqrt[#.#]& is better.I donÕt know hedgehogs, but if I visualize a fur-covered ball, then I cansee as how a continuous solution is not possible everywhere. In that case, Imight like to control the discontinuity. NullSpace create a curve ondiscontinuities on the unit sphere (a vortex curve, if you will). Try, e.g.,ContourPlot[{v, w} = NullSpace[{{y, .3, x}, {0, 0, 0}, {0, 0, 0}}]; v[[3]],{x, -1, 1}, {y, -1, 1}, PlotPoints -> 100]ItÕs not obvious to me where this curve is going to be. A nice feature ofthe following simple scheme,triad[u_, r_:{1, 0, 0}] := Module[{v = Cross[u, r]}, #/Sqrt[# . #] & /@{u, v, Cross[u, v]}]is that you know that the two points of discontinuity are where r and -rcross the unit sphere. triad is slow, but if you commit to a particular rand then evaluate and simplify,FullSimplify[trial[{u,v,w}]the resulting expression evaluates pretty fast for specific numerical{u,v,w}.Tom Burton ==== HereÕs an interesting side note. It seems that Cross is horribly slow. For instance:In: vecs = Table[Random[], {10000}, {2}, {3}]; Timing[Cross[Sequence@@ #]& /@ vecs;]Out: {3.14 Second, Null}A homemade substitute, cross = Compile[{{a, _Real, 1}, {b, _Real, 1}}, {a[[2]]b[[3]] - a[[3]]b[[2]], a[[3]]b[[1]] - a[[1]]b[[3]], a[[1]]b[[2]] - a[[2]]b[[1]]} ]is ten times as fast:In: Timing[cross[Sequence@@ #]& /@ vecs;]Out: {0.3 Second, Null}---Selwyn Hollis ==== Adding my two cents to:> There are many cases in graphics, and otherwise, where it is useful to> obtain two orthogonal unit vectors to a given vector. I know a number of> ways to do it, but they all seem to be slightly inelegant. I thought I would> pose the problem to MathGroup. Who has the most elegant Mathematica> routine...To this I would like to add a criterion of smoothness. Armed with a secondvector b not parallel to the given vector a, itÕs a trivial matter toorthogonalize b WRT a by Gram-Schmidt and then form the third vector c = a xb. (Normalize as needed.)I donÕt need more elegance that this, but I would like a scheme to selectthe vector b that results in a triad {a,b,c} that various smoothly as avaries over all possible directions. Each of my attempts to date involve abranched algorithm and jumps in the resulting triad for certain smallchanges in a.To DavidÕs call for elegance I add a call for smoothness.Tom Burton ==== Mark,Just add a PlotRange option and that each pentomino will be plotted to thesame scale.Show[ GraphicsArray[ Partition[ Table[ Graphics[ Map[Rectangle[#, (# + {1, 1})] &, pentominoes[[i]]], AspectRatio -> Automatic, PlotRange -> {{0, 5}, {0, 5}} ], {i, 12}], 6] ]]David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}, (*I*){{0, 0}, {1, 0}, {2, 0}, {3, 0}, {0, 1}}, (*L*){{0, 0}, {1, 0}, {2, 0}, {2, 1}, {3, 1}}, (*N*){{0, 0}, {1, 0}, {2, 0}, {0, 1}, {1, 1}}, (*P*){{0, 0}, {1, 0}, {2, 0}, {1, 1}, {1, 2}}, (*T*){{0, 0}, {1, 0}, {2, 0}, {0, 1}, {2, 1}}, (*U*){{0, 0}, {1, 0}, {2, 0}, {0, 1}, {0, 2}}, (*V*){{0, 0}, {1, 0}, {1, 1}, {2, 1}, {2, 2}}, (*W*){{1, 0}, {0, 1}, {1, 1}, {2, 1}, {1, 2}}, (*X*){{0, 0}, {1, 0}, {2, 0}, {3, 0}, {1, 1}}, (*Y*){{0, 0}, {1, 0}, {1, 1}, {1, 2}, {2, 2}} (*Z*)}When I display them with the code below, the aspect ratio is correct *withineach pentomino* but they are not scaled equivalently. I would appreciate apointer to what I have done wrong. The only solution I have been able todevelop so far effectively places each of the 12 pentominoes at a differentlocation in the plane, and then draws the whole region in one go.Show[ GraphicsArray[ Partition[ Table[ Graphics[ Map[Rectangle[#, (# + {1, 1})] &, pentominoes[[i]]], AspectRatio -> Automatic ], {i, 12}], 6] ]]--Mark R. Diamond ==== Does anybody have Benchmarks for Mathematica 4.2 to share?If possible the same or similar machine and different OSes.to the Windows version.I tried http://www2.staff.fh-vorarlberg.ac.at/~ku/karl/timings40. htmlvalue of 6.4.---more details--Times = [InvisibleSpace]{1.18, 1.14, 1.08, 0.55, 1.18, 2.48, 0.74, 0.79, 0.41, 0.11, 0.38, 0.96, 0.97, 1.26, 1.11}Time = [InvisibleSpace]17.Benchmark = [InvisibleSpace]6.40784-------------------------------------- ----------I would like to see how Mathematica 4.2 improved in speedcompared to Mathematica 4 or 3. Armin ==== Can I use Mathematica to find out the volumn of this 3 dimensional object fromthe equations :z=x^2 +4, y=4-x^2, y=3xShz Shz ==== Use Text statements. Click of a coordinate point on the plot, copy it andpaste it into the Text statement. Here is an example.Show[Graphics[ {Circle[{1, 1}, 2], Text[A, {1.75659, 2.03292}], Circle[{0, 0}, 2], Text[B, {-1.38818, -0.0197372}], Circle[{1, -1}, 2], Text[C, {1.57238, -1.99344}]}], AspectRatio -> Automatic, ImageSize -> 400];To click off a coordinate:1) Select the plot by putting the cursor in it and clicking.2) Press and hold Ctrl. When you move the cursor you will obtain crosshairs.3) Move the cursor to where you want to put the text and left click.4) Right click and use Copy. (Or use Ctrl-C or the menu).5) Paste the copied coordinate as the second argument in the Text statement.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== On 8/31/02 at 1:25 AM, berlusconi_pagliusi@fis.unical.it (Paskoski)>Dear MathGroup, IÕd like to use Mathematica 4.0 to write a function>having different expressions in different domainÕs intervals. LetÕs>say:F[x_]= x^2 if 0=6TryIn[4]:=F[x_]:=Which[0=6,x+1]you can plot the function withIn[5]:=Plot[F[x],{x,0,8}]Sincerely yours,Dr. Juan E. Fuentes BetancourtFacultad de Fisica Universidad de la Habana ==== I have spent an enormous amount of time (far too much) on this question.Indeed, I have just completed a program that handles all sorts ofpiecewise defined functions. I am in the process of writing it up tooffer it to all of you. In my opinion the best, cleansest method is toinvoke the UnitStep function as illustrated in David ParkÕs solutions.To make everything cleaner, define a characteristic functionChi[x_,a_,b_] := UnitStep[x-a]-UnitStep[x-b]This function is continuous on the right, vanishes outside of [a,b) and isone in the half-open interval [a,b). Now your answer is x^2 Chi[x,0,6] + (x+1) Chi[x,6,Infinity]The integrator handles UnitSteps easily and smoothly.My program handles these cases easily and many more, including suchoddities as Integrate[Abs[x],x] and (for amusement sake only)UnitStep[ Abs[x]-Sign[x]+3]Another virtue of this approach (also handled in my program) is thepeculiar error messages and poor answers given by NIntegrate for simplepiecewise continuous functions at jump discontinuites. The limit functionalso fails dismally on some examples where it really shouldnÕtI am rather naive about how to transmit programs to interested users, soif you would like a copy of my program and about 100 worked examples, Iwill be glad to send them to you IF YOU TELL ME HOW TO DO IT!Jack Goldberg> In a message dated 8/31/02 1:58:36 AM, berlusconi_pagliusi@fis.unical.it>IÕd like to use Mathematica 4.0 to write a function having different>expressions in different domainÕs intervals.>LetÕs say:> > F[x_]= x^2 if 0 x+1 if x>=6> > I know ItÕs a stupid syntax problem, but I really do not know how/where to>search the solution on the Mathematica Book> Just for grins here are several methods: f1[x_/;x<=0] := 0 ; f1[x_/;0=6] := x+1;> f2[x_] := x^2*UnitStep[x]+(x+1-x^2)*UnitStep[x-6];> f3[x_] := Which[ x<=0, 0, 0=6, x+1];> f4[x_] := If[0=6, x+1,0]];> f5[x_] := Switch[x, _?(#<=0&), 0, _?(0<#<6&), x^2, _?(#>=6&), x+1 ]> f6[x_?NumericQ] := {0,x^2,x+1}[[Position[ {x<=0,0=6}, True][[1,1]]]];> Needs[Calculus`Integration`]; (* needed for definition of Boole *)> f7a[x_?NumericQ] := Evaluate[ (Boole /@ {0=6}). {x^2,x+1}];> Off[Part::pspec]; f7b[x_?NumericQ] := Evaluate[ {0,x^2,x+1}[[1+Tr[Boole /@ {x>0, x>=6}]]]];> f8[x_?NumericQ] := Cases[ {{x<=0, 0}, {0=6, x+1}}, {True, z_} :>z][[1]];> f9[x_?NumericQ] := DeleteCases[ {{x<=0, 0}, {0=6, x+1}}, {False, z_}][[1,2]];> f10[x_?NumericQ] := Select[ {{x<=0, 0}, {0=6, x+1}}, First[#]&][[1,2]];> f11[x_?NumericQ] := Last[Sort[ {{x<=0, 0}, {0=6, x+1}}]][[2]];> f12[x_?NumericQ] := Module[{n=1}, While[{x<6,x<0, False}[[n]], n++]; {x+1,x^2,0}[[n]]];> Generating some test points: ts = {Random[Real,{-5,0}],0, Random[Real,{0,6}],6,Random[Real,{6,15}]};> Checking the different representations Equal[(# /@ pts)& /@ {f1,f2,f3,f4,f5,f6,f7a,f7b,f8,f9,f10,f11,f12}]> True To pick a favorite, look at how the different definitions behave.> Of the definitions that evaluate with symbolic input, only f2 and f4> simplify with assumptions> . For example, FullSimplify[#[x]& /@ {f2,f4}, 1 f2 through f5 respond immediately to differentiation> #Õ[x]& /@ {f2,f3,f4,f5} // Simplify //ColumnForm> Only f2 responds immediately to integration> Integrate[f2[x],x]//Simplify Consequently, f2 (UnitStep) appears to be the most versatile.> Bob Hanlon> Chantilly, VA USA ==== Mathematica could do this sort of thing if there were a three dimensional object described by your equations (as boundaries) but there isnÕt one. More precisely, the pair of equations {z=x^2 +4, y=4-x^2} describes a parabola in three space which you can plot with:g1=ParametricPlot3D[{x, 4 - x^2, x^2 + 4}, {x, -5, 5}]The equation y=3x describes the plane:g2 = ParametricPlot3D[{x, 3x, z}, {x, -5, 5}, {z, -25, 25}]You can see the two together in< 5, y -> 3, x -> 1}, {z -> 20, y -> -12, x -> -4}}So where is the 3D object whose volume you want to find?Andrzej KozlowskiToyama International UniversityJAPAN Can I use Mathematica to find out the volumn of this 3 dimensional > object from> the equations : z=x^2 +4, y=4-x^2, y=3x> Shz Shz> ==== There are many cases in graphics, and otherwise, where it is useful toobtain two orthogonal unit vectors to a given vector. I know a number ofways to do it, but they all seem to be slightly inelegant. I thought I wouldpose the problem to MathGroup. Who has the most elegant Mathematicaroutine...OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will returntwo unit vectors orthogonal to each other and to v.You can assume that v is nonzero.David ParkDavid,My suggestionIn[1]:=<< LinearAlgebra`Orthogonalization`In[2]:=OrthogonalUnitVectors[ v:{_, _, _}] := GramSchmidt[NullSpace[{v}]]In[3]:=v = {1, 2, 3}; {v1, v2} = OrthogonalUnitVectors[v]Out[4]={{-(3/Sqrt[10]), 0, 1/Sqrt[10]}, {-(1/Sqrt[35]), Sqrt[5/7], -(3/Sqrt[35])}}In[5]:={v . v1, v . v2, v1 . v2, v1 . v1, v2 . v2}Out[5]={0, 0, 0, 1, 1}Also works with symbolic expressionsHugh Goyder ==== OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will > return> two unit vectors orthogonal to each other and to v. You can assume that v is nonzero. David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/Well the Mathematica routine cannot be more elegant than the mathematics. There are an infinite number of solutions and so an arbitrary choice must be made.I will omit the unit condition because orthogonal sets of integral vectors are useful in examples and exercises --and I prefer to do graphics in a projective context where orthogonal is well defined but unit is not. For unit vectors just map the output with something like #/Sqrt[#.#]&.The vector v=(a1,a2,a3) is nonzero if and only if at most one of the vectors (a2,-a1,0), (a3,0,-a1), or (0,a3,-a2) is zero. These vectors are all orthogonal to v. But which one to choose? For numerical stability we should probably take the vector largest in some norm. The 1-norm, Plus@@Abs[#]&, is easy to compute. Having picked the second vector find the third with a cross product. This assures a right-handed system.OrthogonalVectors[v : {a1_, a2_, a3_}] := With[{w = First[Sort[{{a2, -a1, 0}, {a3, 0, -a1}, {0, a3, -a2}}, OrderedQ[{Plus @@ Abs[#2], Plus @@ Abs[#1]}] &]]}, {w, Cross[v, w]} ]Garry HelzerDepartment of MathematicsUniversity of Maryland1303 Math BldgCollege Park, MD 20742-4015 ==== What is a efficient way to use output expression to define new function. PeterReply-To: kuska@informatik.uni-leipzig.de ==== what is with:In[]:=expr = Integrate[Cos[x], {x, 0, y}];myfun[y_] := Evaluate[expr];myfun[z]Out[]=Sin[z] Jens> What is a efficient way to use output expression to define new function.> Peter ==== I want to do these operations:eq = m x^2 + 2(m + 1)x + m + 2l = {}For[i = -30, i < 30, i++, AppendTo[l, eq /. m -> i]]Plot[l, {x, -50, 50}]but i get this error:l is not a machine-size real number at x = -49.99999583333334Can someone exaplain to me what i am doing wrong here??CeZaR ==== You need to alter the last line to readPlot[Evaluate[l],{x,-50,50}] I want to do these operations: eq = m x^2 + 2(m + 1)x + m + 2> l = {}> For[i = -30, i < 30, i++, AppendTo[l, eq /. m -> i]]> Plot[l, {x, -50, 50}] but i get this error:> l is not a machine-size real number at x = -49.99999583333334 Can someone exaplain to me what i am doing wrong here??> CeZaR>Reply-To: kuska@informatik.uni-leipzig.de ==== Plot[Evaluate[ Table[eq, {m, -30, 29}] ],{x, -50, 50}]Plot[] has the attribute HoldAll and if you donÕt evaluate it,it canÕt find out, that a list of expressions should be plotted instead of a single expression.*And* you should avoid For[] loops. You donÕt need explicitloops in Mathematica. Jens> I want to do these operations:> eq = m x^2 + 2(m + 1)x + m + 2> l = {}> For[i = -30, i < 30, i++, AppendTo[l, eq /. m -> i]]> Plot[l, {x, -50, 50}]> but i get this error:> l is not a machine-size real number at x = -49.99999583333334> Can someone exaplain to me what i am doing wrong here??> CeZaR ==== > There are many cases in graphics, and otherwise, where it is useful to> obtain two orthogonal unit vectors to a given vector. I know a number of> ways to do it, but they all seem to be slightly inelegant. I thought I would> pose the problem to MathGroup. Who has the most elegant Mathematica> routine...> OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will return> two unit vectors orthogonal to each other and to v.> You can assume that v is nonzero.> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/Some possibilities:perps1[v_] := If [v[[1]]==v[[2]]==0, {{1,0,0},{0,1,0}}, {{v[[2]],-v[[1]],0}, Cross[v,{v[[2]],-v[[1]],0}]} ]perps2[v_] := With[{vecs=NullSpace[{v}]}, {vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]} ]This appears to be 2-3 times faster than perps1 for vectors of machinereals. I get another factor of 2 using Compile, which is appropriate fore.g. graphics use.perps2C = Compile[{{v,_Real,1}}, Module[{vecs=NullSpace[{v}]}, {vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]} ]]In[61]:= vecs = Table[Random[], {10000}, {3}];In[62]:= Timing[p2 = Map[perps1C,vecs];]Out[62]= {0.49 Second, Null}This is on a 1.5 GHz processor.Daniel LichtblauWolfram ResearchReply-To: jbrowne@swin.edu.au ==== > There are many cases in graphics, and otherwise, where it is useful to> obtain two orthogonal unit vectors to a given vector. I know a number of> ways to do it, but they all seem to be slightly inelegant. I thought I would> pose the problem to MathGroup. Who has the most elegant Mathematica> routine... OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will return> two unit vectors orthogonal to each other and to v. You can assume that v is nonzero.David, here is a solution generating two random vectors:OrthogonalUnitVectors[v : {_, _, _}] := Module[{r, v1, v2}, r = {Random[], Random[], Random[]}; v1 = Cross[v, r]; v2 = Cross[v1, v]; {v1/Sqrt[Dot[v1, v1]], v2/Sqrt[Dot[v2, v2]]}]Test:v = {Random[], Random[], Random[]}{0.864587, 0.727747, 0.669729}{A,B} = OrthogonalUnitVectors[v]{{0.279985, -0.808701, 0.517311}, {-0.698881, 0.19773, 0.687363}}Chop[{A.v, B.v, A.B, A.A, B.B}]{0, 0, 0, 1., 1.}John-- _________________________________John BrowneSchool of Engineering and ScienceSwinburne University of TechnologyJohn Street, Hawthorn, Victoria, AustraliaQuantica phone: +613 9431 4007Quantica fax: +613 9431 0940 ==== In my previous post, I proposedOrthogonalUnitVectors[v:{_, _, _}] := With[{u = Which[ (w = {0,v[[3]],-v[[2]]}).w != 0, w, (w = {v[[3]],0,-v[[1]]}).w != 0, w, (w = {v[[2]],-v[[1]],0}).w != 0, w ] }, #/Sqrt[#.#]& /@ {u, Cross[u,v]}]The trouble with this is that w ends up being a global variable. The only way I see around that is to use Module instead of With. (May as well put in a Return[$Failed] too.)OrthogonalUnitVectors[v:{_, _, _}] := Module[{u, w}, u = Which[(w = {0,v[[3]],-v[[2]]}).w != 0, w, (w = {v[[3]],0,-v[[1]]}).w != 0, w, (w = {v[[2]],-v[[1]],0}).w != 0, w, True, Return[$Failed]]; #/Sqrt[#.#]& /@ {u, Cross[u, v]} ]----Selwyn Hollis ==== I use Mathematica 4.2, but most of my colleagues still have version 4.1.If they open a notebook from me they get the following warning messagein a dialogue box:This notebook was created in a more recent version of Mathematica, and may notfunction properly with the older front end you are using. ContactWolfram Research for upgrade information.Is there any way that I can set some save option so that they donÕt getthis message when they open my notebooks? (I donÕt want to annoy them.)Bruce Atwood ==== Bruce,HereÕs a quick-and-dirty fix. Open your notebook with a text editor. whatever. Change the 4.2 to 4.1. Then go back up to the top and delete editted by another program.---Selwyn Hollis> I use Mathematica 4.2, but most of my colleagues still have version 4.1.> If they open a notebook from me they get the following warning message> in a dialogue box:> This notebook was created in a more recent version of Mathematica, and may not> function properly with the older front end you are using. Contact> Wolfram Research for upgrade information.> Is there any way that I can set some save option so that they donÕt get> this message when they open my notebooks? (I donÕt want to annoy them.)> Bruce Atwood> Reply-To: kuska@informatik.uni-leipzig.de ==== no. You can take a ASCII text editor, move to (nearly) the end of the notebook and changeoption toOr you can reopen the notebook in a old 4.1 version and saveit again. Jens> I use Mathematica 4.2, but most of my colleagues still have version 4.1.> If they open a notebook from me they get the following warning message> in a dialogue box:> This notebook was created in a more recent version of Mathematica, and may not> function properly with the older front end you are using. Contact> Wolfram Research for upgrade information.> Is there any way that I can set some save option so that they donÕt get> this message when they open my notebooks? (I donÕt want to annoy them.)> Bruce Atwood ==== Several people have asked recently for implementing Doppler Effectanimations with Mathematica...while trying to learn JLink and doing somescouting around, I happened to find the following interesting Javaimplementation...jerry blimbaum NSWC panama city, ßhttp://www.netzmedien.de/shop/evaluation/12/index_uk.html=== =I am trying to make the wheel on my mouse to scroll the Mathematica notebook wheel working for other applications in X (e.g. Mozilla, terminals). Any ideas?Tim Eagan ==== First of all, I would like to thanks to all for trying to help.Sorry, I must have something missing in my previous description.I need to find out the volumn of a 3D object which form by the equation :z=x^2 +4 (as bottom surface)and on the xy plane which bounded by a parabola y=4-x^2 and y=3x line.How would I use Mathematica to plot out this 3D object or find out its volumnwith only the equation given?Shz Shz ==== ====================================================== ==== ====================of the individual or entity to which they are addressed. Any disclosure, copying,distribution and diversion contrary to the applicable export control laws andregulations including US Export Administration Regulations is strictly prohibited.and do not disclose it to others. Please notify the postmaster@hitachi.com.myof the delivery error by replying to this message and then delete it from your ==== ===================================================== ==== =========================This works just as well:OrthogonalUnitVectors[v:{_, _, _}] := (#1/Sqrt[#1 . #1] & ) /@ NullSpace[{v, {0, 0, 0}, {0, 0, 0}}]The Dot product will never be zero, since NullSpace will not return ananswer with zero vectors even if v={0,0,0}.Bobby Treat-----Original Message-----One problem with any solution is that it should never be possible toobtainthe two output vectors as continuous functions of the input vector,sincethat would be equivalent to the combing of a hedgehog in a vortexfreeway.Ingolf Dahlf9aid@fy.chalmers.seChalmers UniversitySweden-----Original Message-----returntwo unit vectors orthogonal to each other and to v.You can assume that v is nonzero.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== HereÕs my output on a Gateway 700XL, 2.2GHz Pentium 4, 1024MB RAM,Windows XP Home. My clockspeed is considerably faster but the benchmarkTimes = {1.25, 1.297, 1.2969999999999997, 0.4060000000000006, 0.9219999999999997, 1.5780000000000003, 0.75, 0.7809999999999997, 0.3130000000000006, 0.0779999999999994, 0.3119999999999994, 0.75, 0.8130000000000006, 1.1869999999999994, 1.4690000000000012}Benchmark = 6.869748851775977Bobby Treat-----Original Message-----value of 6.4.---more details--Times = [InvisibleSpace]{1.18, 1.14, 1.08, 0.55, 1.18, 2.48,0.74, 0.79, 0.41, 0.11, 0.38, 0.96, 0.97, 1.26, 1.11}Time = [InvisibleSpace]17.Benchmark = [InvisibleSpace]6.40784-------------------------------------- ----------I would like to see how Mathematica 4.2 improved in speedcompared to Mathematica 4 or 3. Armin ==== By taking sums and differences of the counterweights 1, 3, ... 3^(k-1)you can precisely express all integers up to the integer whose base 3notation is composed of k ones.By doubling those counterweights, you can precisely express all the EVENintegers up to TWICE that limit, or -1 + 3^k. If you know that unknownsare limited to the integers from 1 to 3^k, this allows you to preciselyweight the even numbers and bracket the odd numbers. Hencecounterweights 2, 6, ... 2*3^(k-1) are sufficient for unknowns up to3^k.Notice that this is an efficient coding scheme: Each counterweight ismultiplied by -1, 0, or 1, so there can be at most 3^k distinctcounterweight sums. More than half are negative or zero, however; thepositive sums and differences number at most (3^k - 1)/2. Since we needto enumerate (and CAN enumerate with even weights) only the even numbersand because we get the maximum unknown 3^k by elimination, we cover upto twice as many as we can enumerate, plus one. Twice (3^k - 1)/2 plusone is 3^k, so weÕre getting the maximum coverage possible for a givennumber of counterweights.Bobby Treat-----Original Message-----For these 40 positive integers to match 1 to 40 correspondingly, thebiggestshould be 40 (also, the smallest should be 1). So we have:a+b+c+d=40 or 1+b+c+d=40 (we state that a> I have a very interesting math problem:If I have a scales,and I>> have 40 things that their mass range from 1~40 which each is anature>> number,and now I can only make 4 counterweights to measure out each>> mass of those things.Question:What mass should the counterweights>> be???>> The answer is that 1,3,9,27 and I wnat to use mathematica tosolve>> this problem.>> In fact,I think that this physical problem has various>> answer,ex.2,4,10,28>> this way also work,because if I have a thing which weight 3 , and I>> can measure out by comparing 2<3<4 . But,If I want to solve thismath>> problem:>> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where a,b,c,d is nature> numbers.>> and {k1,k2,k3,k4}={1,0,-1}>> How to solve it ??>> mathematica solving method. appreciate any idea sharing>> sincerely>> bryan> Just use brute force. Needs[DiscreteMath`Combinatorica`]; var = {a, b, c, d}; n = Length[var]; s = Outer[Times, var, {-1, 0, 1} ]; f = Flatten[Outer[Plus, Sequence@@s]]; Since the length of f is just 3^n then the range of numbers> to be covered should be {-(3^n-1)/2, (3^n-1)/2}.> Consequently, the largest of the weights can not exceed> (3^n-1)/2 - (1+2+...+(n-1)) or ((3^n-1) - n(n-1))/2 34 Thread[var->#]& /@ (First /@ Select[{var,f} /. Thread[var->#]& /@ KSubsets[Range[((3^n-1) - n(n-1))/2], n], Sort[#[[2]]] == Range[-(3^n-1)/2,(3^n-1)/2]&]) {{a -> 1, b -> 3, c -> 9, d -> 27}}> Bob Hanlon> Chantilly, VA USA> ==== Plot[Evaluate[Sin[x]/Sin[x]], {x, -2.5, -1.5}]Gives the expected graph.Bobby Treat-----Original Message-----substituting a ßoating-point value for x results in composite divisionbeing performed numerically, with consequent inaccuracy. This can beverified by the following:In[1]:= FullForm[HoldForm[Sin[x]/Sin[x]]Out[1]//FullForm= HoldForm[Times[Sin[x], Power[Sin[x], -1]]]By default, Mathematica scales the y axis such that the smalldiscrepanciesare visible. The PlotRange option may be given to explicitly specify therange for the y axis (for example PlotRange->{0, 2}).Ian McInnes.> I would expect that Plot[Sin[x]/Sin[x], {x, -2.5, -1.5}] would produce a horizontal line at y=1. However, on my Windows XP computer it produces a graph where the yvalueis> less than 1 at several points. Most notibly between x=-1.6 and x=-1.8 Is this just an isolated case? Or does it happen to others? If so -why? Ken.> ==== >>But my actual output reproduces the input form, i.e., it is simplyf[...listA,newEntry,...].That means your arguments donÕt fit a pattern for which the function isdefined. That is, it has nothing to do with whatÕs on the right side of:=. ItÕs about making sure there are the right number and type ofarguments passed to the function. You havenÕt told us what the patternis or what the arguments are, so we canÕt help you.Bobby-----Original Message----- I define a function of the form: f[...,listA_, newEntry_,...]:= Which[...]Here Which has the form of a set of logically exclusive and exhausivetests, each test with its ownaction that modifies the concrete list subsituted for listA_. For instance, if there were only two tests the rhs above wouldbeone that puts the newEntryat the start of listA and the other that puts it at the end: Which[ test1, listA = Insert[listA, newEntry, 1], test2, listA = Insert[listA, newEntry, -1] ]Then I try to use the function, substituting values for the arguments:f[..., listA, newEntry, ...]. Theoutput should be the appropriately modified list. But my actual outputreproduces the input form,i.e., it is simply f[...listA,newEntry,...]. Yet, the program does do something, as the use of evaluate inplaceshows: Suppose that test1 is satisfied by the particular values of thearguments. Then whenI apply evaluate in place to the lhs of the action that is supposed tooccur when test1 is true,in fact the value of Insert[listA,newEntry,1] is correct, but the rhsgivesonly the initial value oßistA and not the modified value that is on the rhs. Concretely, suppose that in the function argument listA is {121}andnewEntry is 200.Then after evaluation of the function (input to the kernel), that linereads, according toevaluate in place: true, {121} = {200, 121}So it seems that only part of the correct action was taken: 200 was putatthe start of listA. Butthe assignment of this value -- the extended list -- to be the new valueoßistA did not take place. I then tried using a new name for the modified list, substituting thisprogram line for test1: test1, newListA = Insert[listA,newEntry,1]What I get here, applying evaluate in place after evaluating thefunctionwith concrete values as aboveis: true, newListA = {200, 121} Trace doesnÕt help because all I get back is the function namewithits concrete arguments. Any thoughts? Tom ==== The problem is that I do not think there is any bounded 3d body described by your conditions. Anyway, this is how you can use Mathematica (in general) to solve this sort of problem.You need two packages:In[1]:=< 3x && y < 4 - x^2 && z < x^2 + 4, {x}, {y}, {z}]However, you will just get some error messages and a picture that looks two dimensional. If you wanted the volume, evaluate:In[3]:=Integrate[Boole[y>3x&&y<4-x^2&&z3x&&y<4-x^2&&z 3x&&y<4-x^2&&z equation :> z=x^2 +4 (as bottom surface)> and on the xy plane which bounded by a parabola y=4-x^2 and y=3x line. How would I use Mathematica to plot out this 3D object or find out its > volumn with only the equation given? Shz Shz>> Andrzej Kozlowski 3/September/2002 04:33pm >> Mathematica could do this sort of thing if there were a three> dimensional object described by your equations (as boundaries) but> there isnÕt one. More precisely, the pair of equations {z=x^2 +4,> y=4-x^2} describes a parabola in three space which you can plot with: g1=ParametricPlot3D[{x, 4 - x^2, x^2 + 4}, {x, -5, 5}] The equation y=3x describes the plane: g2 = ParametricPlot3D[{x, 3x, z}, {x, -5, 5}, {z, -25, 25}]> You can see the two together in> < Show[{g1,g2}] There are clearly two points of intersection. They can be found with:> Solve[{z == x^2 + 4, y == 4 - x^2, y == 3*x}, {x, y, z}]> {{z -> 5, y -> 3, x -> 1}, {z -> 20, y -> -12, x -> -4}} So where is the 3D object whose volume you want to find? Andrzej Kozlowski> Toyama International University> JAPAN>> Can I use Mathematica to find out the volumn of this 3 dimensional>> object from>> the equations :>> z=x^2 +4, y=4-x^2, y=3x>> Shz Shz> ==== How can I run mathematica program in background? Is there any waysimilar to fortran or c where one can runs his program in thebackground? Please suggest. RajReply-To: kuska@informatik.uni-leipzig.de ==== math <> someresults.m &???BTW this is a problem of your operating systemand not of Mathematica. Jens> How can I run mathematica program in background? Is there any way> similar to fortran or c where one can runs his program in the> background?> Please suggest.> Raj ==== All works fine but now I wanted to generate an animated gif with help of Now the same file which worked earlier produces errors:In[4]:=Export[schwing.gif, schwing, GIF]LinkConnect::linkc: !([LeftSkeleton] 1 [RightSkeleton]) is dead; attempt to connect failed.Out[4]=schwing.gifAlso a dialogue box appears withsuch file or directorysuch file or directoryThe files are at the place and are executable etc. But if one tries to execute them always this No such file or directory error message appears.Does anyone know what to do?-- Hendrik van Hees Fakult.8at f.9fr Physik http://theory.gsi.de/~vanhees/ D-33615 Bielefeld ==== First define the functionsz[x_] := x^2 + 4;y1[x_] := 4 - x^2;y2[x_] := 3x;Figure out where the y limits coincide:Solve[y1[x] == y2[x], x]{{x -> -4}, {x -> 1}}Which is bigger in between?y1[0] - y2[0]4y1 is. Confirm that with a plot. (y2 is linear):Plot[{y1[x], y2[x]}, {x, -5, 5}]Next figure out where z is zero:Solve[z[x] == 0, x]{{x -> -2*I}, {x -> 2*I}}ItÕs never zero for real x, but is it positive, or negative?z[0]4Look at the plot, just for fun:Plot[{z[x]}, {x, -4, 1}]z is positive for all x (but only the interval [-4,1] MATTERS). Thevolume you want, therefore, isIntegrate[z[x]*(y1[x] - y2[x]), {x, -4, 1}]625/4or:g[x_] = Integrate[z[x]*(y1[x] - y2[x]), x]g[1] - g[-4]16*x - 6*x^2 - (3*x^4)/4 - x^5/5625/4Bobby Treat-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== >-----Original Message----->Sent: Wednesday, September 04, 2002 8:56 AM>previous output?What is a efficient way to use output expression to define new >function. PeterPeter,IÕd say none,... Ôcause look at In[1]:= y = x^2Out[1]= x^2In[2]:= f1[x_] = Out[1]Out[2]= x^2In[3]:= f2[x_] := Out[1]In[4]:= x = 5Out[4]= 5In[5]:= f3[x_] = Out[1]Out[5]= 25In[6]:= Block[{x}, f4[x_] = Out[1]]Out[6]= 25In[7]:= Block[{x}, f5[x_] := Out[1]]In[9]:= f6[x_] = yOut[9]= 25In[10]:= Block[{x}, f7[x_] = y]Out[10]= 25In[11]:= f8[x_] := yIn[12]:= Through[{f1, f2, f3, f4, f5, f6, f7, f8}[#]] & /@ {0, 1}Out[12]= {{0, 25, 25, 0, 25, 25, 0, 25}, {1, 25, 25, 1, 25, 25, 1, 25}}In[13]:= Block[{x}, f9[x_] = Out[1]]Out[13]= %1In[14]:= Through[{f1, f2, f3, f4, f5, f6, f7, f8, f9}[#]] & /@ {0, 1}Out[14]= {{0, %1, 25, 0, %1, 25, 0, 25, %1}, {1, %1, 25, 1, %1, 25, 1, 25, %1}}f1, f4 and f7 come out right, but f1 is based on the condition that thepattern variables of the expression have not been redefined, and f4 is onlycorrect if the history is remembered well. So what rests is f7, but thatwasnÕt you question.--Hartmut Wolf ==== If we are in the business of giving good links to Doppler demonstrations,here is another one (freeware):http://www.phy.ntnu.edu.tw/java/Doppler/ Doppler.htmlFor anyone interested in good Java implementations of physics phenomena,NTNU Virtual Physics Laboratory athttp://www.phy.ntnu.edu.tw/java/index.html is a treasure chest.This is not Mathematica stuff (as far as I know), but might be of interestto several Mathgroup readers.Ingolf DahlChalmers UniversitySwedenf9aid@fy.chalmers.se-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== My main application for this is in drawing a piece of a plane at a pointnormal to a vector. For me, efficiency is not an important criterion. But Iwant orthogonal vectors so the plane will be composed of squares and notdiamonds. I want unit vectors so that I can easily specify the size of thepiece I am drawing.I posted a summary last evening and it doesnÕt seem to have appeared today.In any case, I have realized that none of the routines really require theLinearAlgebra`Orthogonalization package, and run faster without it. I havemodified the original routines to use a pure function instead of Normalizeor GramSchmidt.Here is a summary of the responses so far. The timings were done with thefollowing exact vector. They are faster with a machine precision vector.vtest = {1, 2, 1};__________________________________________________________ Hugh Goyder...The original routine wasOrthogonalUnitVectors[v : {_, _, _}] := GramSchmidt[NullSpace[{v}]]but I changed it toOrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ NullSpace[{v}]OrthogonalUnitVectors[vtest]{{-(1/Sqrt[2]), 0, 1/Sqrt[2]}, {-(1/Sqrt[3]), 1/Sqrt[3], -(1/Sqrt[3])}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{2.53 Second, Null}This appears to be the shortest and fastest routine. I would give it theprize for elegance. It is certainly easy to remember.____________________________________________________ ____Ingolf Dahl...OrthogonalUnitVectors[v:{_, _, _}] := (#1/Sqrt[#1 . #1] & ) /@ NullSpace[{v, {0, 0, 0}, {0, 0, 0}}]OrthogonalUnitVectors[vtest]{{-(1/Sqrt[2]), 0, 1/Sqrt[2]}, {-(2/Sqrt[5]), 1/Sqrt[5], 0}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{2.59 Second, Null}This is really the same as Hugh GoyderÕs routine. It isnÕt necessary to addthe zero rows to the matrix. NullSpace automatically does it.________________________________________________________ Selwyn Hollis...OrthogonalUnitVectors[v : {_, _, _}] := Module[{u, w}, u = Which[(w = {0, v[[3]], -v[[2]]}).w != 0, w, (w = {v[[3]], 0, -v[[1]]}).w != 0, w, (w = {v[[2]], -v[[1]], 0}).w != 0, w, True, Return[$Failed]]; #/Sqrt[#.#] & /@ {u, Cross[u, v]} ]OrthogonalUnitVectors[vtest]{{0, 1/Sqrt[5], -(2/Sqrt[5])}, {Sqrt[5/6], -Sqrt[2/15], -(1/Sqrt[30])}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{11.92 Second, Null}I wish I understood the reason for using rows of the v Cross matrix as testvectors. It does have the advantage that a dot product is used to give ascalar test for zero. Why not...OrthogonalUnitVectors[v : {_, _, _}] := Module[{u, w}, u = Which[(w = {1, 0, 0})[Cross]v != {0, 0, 0}, w, (w = {0, 1, 0})[Cross]v != {0, 0, 0}, w, True, Return[$Failed]]; #/Sqrt[#.#] & /@ {u, Cross[u, v]} ]OrthogonalUnitVectors[vtest]{{1, 0, 0}, {0, -(1/Sqrt[5]), 2/Sqrt[5]}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{10.33 Second, Null}________________________________________________________ ____John Browne...OrthogonalUnitVectors[v : {_, _, _}] := Module[{r, v1, v2}, r = {Random[], Random[], Random[]}; v1 = Cross[v, r]; v2 = Cross[v1, v]; {v1/Sqrt[Dot[v1, v1]], v2/Sqrt[Dot[v2, v2]]}]OrthogonalUnitVectors[vtest]{{0.26601, -0.534209, 0.802408}, {-0.873254, 0.218984, 0.435286}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{9.17 Second, Null}This has the problem that the r vector might be parallel to v. But in 100000test cases it never happened.____________________________________________________ ________Daniel Lichblau...(Daniel left out the normalization, which I added.)OrthogonalUnitVectors[v:{_, _, _}] := With[{vecs = NullSpace[{v}]}, (#1/Sqrt[#1 . #1] & ) /@ {vecs[[1]], vecs[[2]] - vecs[[2]] . vecs[[1]]*vecs[[1]]}]OrthogonalUnitVectors[vtest]{{-(1/Sqrt[2 ]), 0, 1/Sqrt[2]}, {0, 1/Sqrt[5], -(2/Sqrt[5])}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{3.35 Second, Null}________________________________________________________ ______Garry HelzerOrthogonalVectors[v : {a1_, a2_, a3_}] := With[{w = First[Sort[{{a2, -a1, 0}, {a3, 0, -a1}, {0, a3, -a2}}, OrderedQ[{Plus @@ Abs[#2], Plus @@ Abs[#1]}] &]]}, {w, Cross[v, w]} ]OrthogonalUnitVectors[vtest]{{-(1/Sqrt[2]), 0, 1/Sqrt[2]}, {-(2/Sqrt[5]), 1/Sqrt[5], 0}}Do[OrthogonalUnitVectors[vtest], {10000}] // Timing{2.64 Second, Null}________________________________________________________ __________Tom BurtonA nice feature of the following simple scheme is that you know that the twopoints of discontinuity are where r and -r cross the unit sphere.triad[u_, r_:{1, 0, 0}] := Module[{v = Cross[u, r]}, #/Sqrt[# . #] & /@{u, v, Cross[u, v]}]triad[vtest]{{1/Sqrt[6], Sqrt[2/3], 1/Sqrt[6]}, {0, 1/Sqrt[5], -(2/Sqrt[5])}, {-Sqrt[5/6], Sqrt[2/15], 1/Sqrt[30]}}Do[triad[vtest], {10000}] // Timing{17.02 Second, Null}David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/djmp@ earthlink.nethttp://home.earthlink.net/~djmp/ ==== CeZaR,Sort of confused about what you really wanted. If you have forgotten toassign x = ? then you can do the following,Clear[x, eq, m, l]eq = m x^2 + 2(m + 1)x + m + 2l = {};x = 1;For[i = -30, i < 30, i++, AppendTo[l, eq /. m -> i]]ListPlot[l]But if you really intend to make a list of quadratics and then plot theresults for each of the quadratics then you can try the followingClear[x, eq, m, l]eq = m x^2 + 2(m + 1)x + m + 2;l = {};For[i = -30, i < 30, i++, AppendTo[l, eq /. m -> i]];test = Table[l[[i]], {i, 1, Length[l], 1}, {x, -50, 50}];MultipleListPlot[test[[5]], test[[10]], test[[15]], test[[20]],test[[25]], test[[30]], test[[35]], test[[40]], test[[45]], test[[50]], test[[55]], test[[60]], PlotJoined -> True, SymbolShape -> None, ImageSize -> 500 ]Essentially your For loop generates a list of quadratics if x is left out.Yas I want to do these operations: eq = m x^2 + 2(m + 1)x + m + 2> l = {}> For[i = -30, i < 30, i++, AppendTo[l, eq /. m -> i]]> Plot[l, {x, -50, 50}] but i get this error:> l is not a machine-size real number at x = -49.99999583333334 Can someone exaplain to me what i am doing wrong here??> CeZaR ==== Plot[l // Evaluate, {x, -30, 30}, Frame -> True];CeZaR