A44 === 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?>> STH>Reply-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>> /> 108671061439707605510003578275547938881981431359756495796079898 677435> 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>> /> 108671061439707605510003578275547938881981431359756495796079898 677435> 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 StandardForm 77616.99999999999999999999999999999999999999999976637`37.9031 Again to InputForm 77616.99999999999999999999999999999999999999999963735`37.9031 Back to StandardForm 77616.99999999999999999999999999999999999999999951376`37.9031 See what you can get if you have enough patience or a small program.PK ==== > The more I play with the example the more depressing it gets. Start> with ß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.de>The 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?>> STH>>Steven,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 ==== Technical support has responded to my query. They say that one of thesimplifications that Mathematica does when using Simplify is to Factor theexpression, and factoring an expression consisting of inexact numbers leadsto the type of behavior I observed. They stated that changing the behaviorof Simplify to avoid the problems I noticed would make Simplify lesscapable, and that the majority of users would prefer to have Simplify behavethe way it currently does.Of course, that doesn't answer the question about why the number of terms inthe expression would cause the coefficients to go from rational to inexactto rational again.At any rate, I have another lesson learned. When using Simplify, check theresult if you are mixing infinite precision and inexact numbers, as theresult may not be what you wanted. In the past I always assumed that theresult of using Simplify on an expression produced a result equivalent tothe original expression, but now I discover that this is not true.Carl WollPhysics DeptU of Washington----- Original Message -----> {i, > n}]], x[1]]>> Now lets try CW for the first 100 values of n:> In[30]:=> Table[CW[n], {n, 100}]>> Out[30]=> {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,> 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054,> 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012,> 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971,> 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492,> 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879,> 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837,> 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796,> 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755,> 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724,> 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423,> 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,> 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,> 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,> 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,> 1/2, 1/2, 1/2}>> In[31]:= Map[Length,Split[#]]>> Out[31]=> {12,43,45}>> This is indeed curious.The problem seems to occur for values between 13> and 55 and then go away (for good???) At first I thought it maybe in> some fascinating way related to some properties of the integer n, but> now I am not sure. It certainly worth a careful examination. I hope> whoever discovers the cause of this will let us know.>> Andrzej>> Andrzej Kozlowski> Yokohama, Japan> http://www.mimuw.edu.pl/~akoz/> http://platon.c.u-tokyo.ac.jp/andrzej/>> To Technical Support and the Mathematica User community,>> I'm writing to report what I consider to be a bug. First, I want to> show a> simplified example of the problem. Consider the following expression:>> expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16;>> When simplified I expected to get some real number plus> x[0]+3x[1]/4+9x[2]/16, but instead I get the following:>> Simplify[expr]> 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2]> >> As you can see, for some reason Mathematica converted the fractions> 3/4 and> 9/16 to real machine numbers. I consider this to be a bug.>> Now, for an example more representative of the situation that I've been> coming across.>> expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}];> expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}];> expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}];>> As you can see, I have replaced the real numbers by extended precision> numbers. The simplified example above demonstrates that the problem> exists> when using machine numbers. Now, we'll see what happens when we use> arbitrary precision numbers. First, let's simplify the expression with> 12> terms.>> Simplify[expr12]> (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128> x[5] +>> 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12])> / 4096>> As you can see, a sum with 12 terms upon simplification has> coefficients> which are still integers as they should be. However, increasing the> number> of terms to 13 yields>> Simplify[expr13]> 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] +>> 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] +>> 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000> x[8] +>> 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000> x[11]> +>> > 0.000244140625000 x[12] + 0.0001220703125000 x[13]>> Now, all of the coefficients are converted to real numbers,> replicating the> bug from the simplified example. Finally, let's see what happens when> we> have 55 terms. Rather than putting the resulting expression here, I> will> just leave it at the end of the post. The result though is somewhat> surprising. Each of the coefficients of the x[i] are again real> numbers, but> now their precision is only 0! The proper result of course is the sum> of> some real number (with a precision close to 0 due to numerical> cancellation)> and an expression consisting of rational numbers multiplied by x[i].> The> loss of precision of the coefficients of the x[i] is precisely what> > occurred> to me. Of course, in this simple example, simply using Expand instead> of> Simplify produces the expected result, and is my workaround. I hope you> agree with me that this is a bug, and one that Wolfram needs to> correct.>> Carl Woll> Physics Dept> U of Washington>> Simplify[expr55]> -16 -1 -1 -1> 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10> x[5] +> >> -2 -2 -2 -3 -3> 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10> x[10]> +>> -3 -3 -4 -4> -4> 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10> x[15] +>> -5 -5 -5 -6> -6> 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10> x[20] +>> -6 -6 -7 -7> -7> 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10> x[25] +>> -8 -8 -8 -9> -9> 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10> x[30] +>> -9 -9 -10 -10> 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] +>> -10 -11 -11 -11> 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] +>> -12 -12 -12 -12> 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] +>> -13 -13 -13 -14> 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] +>> -14 -14 -15 -15> 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] +>> -15 -15 -16 -16> -> 16> 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] +> 0. 10> x[55]> >> ==== Dear CarlYou have discovered what is perhaps a bug but maybe something even mor einteresting . However, I think you stopped your investigation a little prematurely. Here is a function that just computes the coefficient of x[1] in your Simplified expression for various values of n:CW[n_] := Coefficient[Simplify[1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, n}]], x[1]]Now lets try CW for the first 100 values of n:In[30]:=Table[CW[n], {n, 100}]Out[30]={1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423, 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2}In[31]:= Map[Length,Split[#]]Out[31]={12,43,45}This is indeed curious.The problem seems to occur for values between 13 and 55 and then go away (for good???) At first I thought it maybe in some fascinating way related to some properties of the integer n, but now I am not sure. It certainly worth a careful examination. I hope whoever discovers the cause of this will let us know.AndrzejAndrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> To Technical Support and the Mathematica User community,>> I'm writing to report what I consider to be a bug. First, I want to > show a> simplified example of the problem. Consider the following expression:>> expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16;>> When simplified I expected to get some real number plus> x[0]+3x[1]/4+9x[2]/16, but instead I get the following:>> Simplify[expr]> 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2]>> As you can see, for some reason Mathematica converted the fractions > 3/4 and> 9/16 to real machine numbers. I consider this to be a bug.>> Now, for an example more representative of the situation that I've been> coming across.>> expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}];> expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}];> expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}];>> As you can see, I have replaced the real numbers by extended precision> numbers. The simplified example above demonstrates that the problem > exists> when using machine numbers. Now, we'll see what happens when we use> arbitrary precision numbers. First, let's simplify the expression with > 12> terms.>> Simplify[expr12]> (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 > x[5] +>> 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) > / 4096>> As you can see, a sum with 12 terms upon simplification has > coefficients> which are still integers as they should be. However, increasing the > number> of terms to 13 yields>> Simplify[expr13]> 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] +>> 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] +>> 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 > x[8] +>> 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 > x[11]> +>> 0.000244140625000 x[12] + 0.0001220703125000 x[13]>> Now, all of the coefficients are converted to real numbers, > replicating the> bug from the simplified example. Finally, let's see what happens when > we> have 55 terms. Rather than putting the resulting expression here, I > will> just leave it at the end of the post. The result though is somewhat> surprising. Each of the coefficients of the x[i] are again real > numbers, but> now their precision is only 0! The proper result of course is the sum > of> some real number (with a precision close to 0 due to numerical > cancellation)> and an expression consisting of rational numbers multiplied by x[i]. > The> loss of precision of the coefficients of the x[i] is precisely what > occurred> to me. Of course, in this simple example, simply using Expand instead > of> Simplify produces the expected result, and is my workaround. I hope you> agree with me that this is a bug, and one that Wolfram needs to > correct.>> Carl Woll> Physics Dept> U of Washington>> Simplify[expr55]> -16 -1 -1 -1> 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10 > x[5] +>> -2 -2 -2 -3 -3> 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10 > x[10]> +>> -3 -3 -4 -4 > -4> 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10> x[15] +>> -5 -5 -5 -6 > -6> 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10> x[20] +>> -6 -6 -7 -7 > -7> 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10> x[25] +>> -8 -8 -8 -9 > -9> 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10> x[30] +>> -9 -9 -10 -10> 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] +>> -10 -11 -11 -11> 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] +>> -12 -12 -12 -12> 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] +>> -13 -13 -13 -14> 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] +>> -14 -14 -15 -15> 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] +>> -15 -15 -16 -16 > -> 16> 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] + > 0. 10> x[55]> ==== I think, for input of that many numbers (and other inputs), I might usean input file that has textual names or descriptions in the first ten ortwenty columns, followed by values starting at a fixed column afterthat. Mathematica or Java could easily read inputs from that, and ahuman could read it as well. If you're concerned that a human mightjumble the file format -- accidentally deleting lines, etc. -- a programcould key on the names or descriptions rather than trusting them to bein correct order, and point out missing values. A strategy like thatallows you to start with a previous input file (not from scratch) andchange only what needs to change.Also, Mathematica 4.2 adds XML support to the picture, and that might beuseful.Bobby-----Original Message----->> I agree with Mr. Kuska, that the system Mr Nagesh describes is not> userfriendly. But I think, the suggestions of Mr. Kuska do not makeitmore> userfriendly, rather the opposite is true.>> Mr. Nagesh asks>> Is any body here have expertise or information about the capabilityof> > Mathematica as a system simulation tool?> Mr. Kuska answers:> Since the most system simulation tools are simply solving asystem of> ordinary differntial equations it is simple to do this withNDSolve[].>> My comment:>> That is: He sees the simulation system merely as a set ofdifferential> equations.>> hmm, since the original poster write>> My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations.>> it seems not completly wrong to assume that the system consists of> of ode's ..>Yout should not ignore the word merely.It is not enough to have a set 60 differential equations and a set of200-250 numbers. That is not simulation system, which can be used byuserswith the exception, perhaps, of the programmer of the system himself.How does e.g. the user know what meaning a number in the set has, oughthecount the numbers from the beginning?Your nice command shows only, if there is an input, which is not anumber.But I think the user would like to know, which of the 200 elements arenotnumbers.The only good of your command is, that it looks nice and shows yourknowledge!>> The question of Mr. Nagesh:>> My 4th Objective:- How can I program the check for correctness ofthe> input values supplied by the package user ?> The answer of Mr. Kuska is:> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})>> My comment:>> This is a nice command and shows the knowledge of Mr.Kuska. But doesMr.> Nagesh understand it and is it sufficient to check, if all inputsare> numerical?>> It seems you have a deeper knowlege about the things that Mr. Nagesh> understand. You know him personally ? It is not very polite to> make speculations *what* a other person understand.>> And no it is not sufficent to check that all parameters are numbers.> Typical paramters described by intervals, where the assumptions of> a model are valid. But for this checks one needs more knowlege> about the meaning of the parameters. And one needs the knowlege about> the differntial equations, to find out the eigenvalues of the jacobian> ...> Additionally I think, it is not userfriendly to see the input merelyasa> set of 200-250 numbers.>> My suggestion is, that JLink is used, a suggestion Mr. Kusk takesinto> consideration, too.>> That will be fast as lightning !> But further I suggest, that classes are defined in Java, whichrepresentthe> parts of the system.>> That is notable nonsense! When the differntial equations should be> solved with Mathematica, the parts can't be Java classes.Mathematica's> NDSolve[] need a explicit expression to integrate the equations.That's not nonsense, the Mathematica program does not fetch the classesbutthe numbers in the classes (or better in the objects).inthe Java classes in textform. They can then be fetched from theMathematicaprogram and transformed into expressions by the Command ToExpression.The aim is, to have a clear separation of the system into components,whichare manageable and understandable.>> OK you can call a Java class member from Mathematica but this will> be incredible slow when the right hand side is evaluated 200-300> times and every evaluation make several callbacks to the Java source.> Event handler of the Java main program (without some modification in> the event loop) while it is evaluating an other command.My idea is to fetch the values once from the Java objects at thebeginning.200-250 numbers is not so much..> Constructors of the classes should build objects with defaultvalues.>> That's a great idea. If a simulation run should be documented, one> always> need the full listing of the Java source to find the actual parameter> settings.That is not my opinion. I think not every user of the simulation systemshould have to know Java and Mathematica.The user must look for the values in the objects. And the values are intheobjects, if they come from the constructor or from the graphical userinterface.I think, there should be listings of the objects including names of thevariables. In the objects the values are in an meaningful environment.>> Graphical user interfaces> should give the opportunity to change the data fields in the objectsand> check the input for correctness.>> *and* what has a GUI for 200-250 variables to do with Mathematica ?> BTW one has typical much less variables because many parameters> are fixed and it make no sense to change, for example, material> constants of materials that can't exchanged> The system should give the opportunity, to store the objects onharddisk> (serialization).>> accessed directly.> Can you be so kind, to explain *how* your posting help a person that> ask How can I build a simulation system with Mathematica ?>> You *can* say Don't use Mathematica, use Java! but this has nothing> to do with the question or with my reply.It is you, who proposes to solve the problem with C/C++ and not to useMathematica (see below!)My point of view is:Use Mathematica, for what Mathemtica is good, and Java, for what Java isgood.Mathematica is not so good as Java for data entry and Java is betterthanMathematica to represent the simulation system (by objects).>> But I still would suggest to use C/C++ and a numerical> ode-solver, make a fancy GUI/Script> interface and don't use Mathematica for such a simple task.> The ode-solver is the smallest part of such a simulation system.>> Jens> My name is Nagesh and pursuing research studies inRefrigeration. At> > present I am writing a Dynamic Refrigeration System SimulationPackage.> I> am using Mathematica as a programming language for the samesincelast> one> > year. I don't have any programming experience before this. Ihave> following> querries:-> 1. Is any body here have expertise or information about thecapability> of> Mathematica as a system simulation tool?>> Since the most system simulation tools are simply solving asystemof> ordinary differntial equations it is simple to do this withNDSolve[].>> 2. Is is possible to program a user friendly interface for mysystem> simulation package with Mathematica or I have to use some other> software?>> Write a MathLink or J/Link frontend that launch the kernel. Butyou> should keep> in mind that the user interface is typical 80-90 % of your code.> If you just whant to solve some ode's it is probably easyer to> include one of the excelent ode-solvers from netlib in your C-code> than to call Mathematica to do that. As long as you dont wish tochange> the ode's very often (than Mathematica is more ßexible) youshould> not use Mathematica.>> 3. My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations. Is ispossibleto> > solve these in Mathematica ?>> Sure.> If yes then can anybody here guide me about> this further.> >> Write down the equations and call NDSolve[].>> >> I am explaining below in short about the objectives I want tofulfill> from> coding out of my main input file>> 1. Example from Main Input File ( this will contain about200-250> variables> which will be entered by the user of this package)>> This sounds like a *very* userfiendly interface ;-)> > Below is examples of two variables entered into this file, whichwill be> used in other analysis files for further evaluation.>> 2. Example from other analysis file ( there will be about 20-25other> such> component analysis files ) where the above mentioned variablesfrommain> input file will be used for further evaluations:->> Below is one example from this file explaining how the variablesfrom> main> input file will be used in other files.>> I hope that this short information will be useful for guiding meto> solve> the following problems that I am facing. I am facing follwingproblems> or> objectives:->> 1. My 1st Objective:- The user of this package must be able tochange> only> the value of the variable in the main input file but he must notbeable> to> change the name of the variable itself. For example he must beableto> change the value of the variable but he must not be able tochange> the> name of this variable itself.> > Here our problem is how to achieve or program it so that ourobjective> will> be fullfilled.>> Options with defaulf values ? or something like>> {aParam,bParam}={ODEParameter1,ODEParameter2} /.> userRules /.> {ODEParameter1->1,ODEParameter2->2}>> >> 2. My 2nd Objective:- How I can program the main input file sothatit> will> be user friendly in terms of its visuals and satisfying theconstraint> mentioned above in objective1.>> What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values foreach> > variable in the main input file ? so that there will be always avalue> assigned to each variable listed in main input file whenever theuser> opens> up this file. If user want to change the values of somevariablesthen> he> can change them and run the simulation otherwise the simulationrunwill> be> > done with optional values assigned to each variable in the inputfile.>> See above.> 4. My 4th Objective:- How can I program the check forcorrectness ofthe> input values supplied by the package user ?> >> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})> Jens> >> ==== hi> AFAIK, Mac OS is now BSD or something like that. That makes it almost> certain that it could support QT. As I pointed out in another post, I can> run the KDE on Windows XP. I haven't been in the trenches with the Qt> impression is, it really is Ôcode once, run everywhere'.i've checked the trolltech hp. qt fully supports the following OS:MS Windows 95/98/Me, NT4, 2000 and XP. Mac OS X. > This is one of the reasons I am such a Mozilla fan. Konqueror works quite> like. But Mozilla runs everywhere with more or less a uniform look and> feel. Yes, Mozilla is written with Gtk and not with Qt, but that just> shows that WRI has options.i'm not sure if it is allowed to create a closed-source product like the mathematica fronend based on a gpl'ed library like gtk. with qt you have the possibility to buy licenses for the commercial version of qt, allowing you to create closed-source apps. > I'm a KDE fan. I've used the KDE since it was in alpha 0.4. I remember> back when it would compile in a few minutes on a pentium II. Now it takes> several hours on a P4. i started with beta1 (if i remember correctly) - sure it is really big now, but i think kde is still far away from being bloated..... imagine the mathematica frontend being seamlessly integrated into the linux ui's look and feel.... > I've always hated motif. The file chooser simply stinks. And that's just a> start.the whole motif ui stinks....:-)gerald************************************* Gerald RothM@th Desktop Development************************************* ==== > hi,> moving the frontend over to QT would have some neat side effects:> consistent look & feel with the modern linux gui, themeability, source> antialiased> truetype fonts as QT supports Xrender and Xft (looks great - see KDE3). i> think all of those points are of value, but the most important might be> source compatibility. ONE frontend for MOST (or ALL) platforms - sounds> like a dream :-))AFAIK, Mac OS is now BSD or something like that. That makes it almost certain that it could support QT. As I pointed out in another post, I can run the KDE on Windows XP. I haven't been in the trenches with the Qt impression is, it really is Ôcode once, run everywhere'.This is one of the reasons I am such a Mozilla fan. Konqueror works quite like. But Mozilla runs everywhere with more or less a uniform look and feel. Yes, Mozilla is written with Gtk and not with Qt, but that just shows that WRI has options. I'm a KDE fan. I've used the KDE since it was in alpha 0.4. I remember back when it would compile in a few minutes on a pentium II. Now it takes several hours on a P4. But if WRI wanted to go the Gtk route, they could achieve the same ends.I've always hated motif. The file chooser simply stinks. And that's just a start.> gerald> STH ==== Can I solve this inequality with Mathematica?Log[x,a]+Log[a x,a]>0I've tried all know, but I get get any good result.CeZaR ==== > First thanks to all, and in particular Bobby Treat, for your help with> this question.> The best solution was as follows:> lst = ReadList[c:data.txt, {Number, Number}]> adjacenceMatrix[> x:{{_, _}..}] := Module[{actors, events},> {actors, events} = Union /@ Transpose[x];> Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & ,> {Length[actors], Length[events]}]]> a = adjacenceMatrix[lst];> b = a . Transpose[a];> c = b (1 - IdentityMatrix[Length[b]])> C is the desired symmetric matrix with off diagonal values of >=0,> indicating the number of times two actors participate in the same event.> The diagonal is set to 0.> A few items in response to Bobby's message, below. While c is, in fact,> a huge matrix with lots of cells equal to zero, that is exactly how we> need it structured for our analysis and research question (not relevant> to the list, but I'd be happy to discuss off list). Processing time is> actually not too bad!! I'm running a PIII 900 with 512 SDRAM, and the> code ran a 177 x 3669 matrix in under 90 seconds. MatrixForm [c]> presented no problems in viewing in the front end, but then it's only> 177 x 177.> Tom> **********************************************> Thomas P. Moliterno> Graduate School of Management> University of California, Irvine> tmoliter@uci.edu> **********************************************> [...]There are several ways to go about this and which is best will varybased on relative number of events vs. number of actors. Below I showthree variations. The first is a minor recoding of the one above. Thesecond iterates over all pairs of actors. The third looks at all eventsfor common actors. I then show three examples. The first two methodshave the advantage that they do not require that events be positiveintegers. With some extra work the third method could also get aroundthis restriction.toAdjacency0[data:{{_, _}..}] := Module[ {actors, events, mat1, mat2}, {actors, events} = Union /@ Transpose[data]; mat1 = Array[If[MemberQ[data, {actors[[#1]], events[[#2]]}], 1, 0] &, {Length[actors], Length[events]}]; mat2 = mat1 . Transpose[mat1]; mat2 * (1-IdentityMatrix[Length[mat2]]) ]toAdjacency1[origdata_] := Module[ {data=Union[origdata], mat}, data = Map[Last, Split[data,#1[[1]]===#2[[1]]&], {2}]; mat = Table [If [j>k, Length[Intersection[data[[j]],data[[k]]]], 0], {j,Length[data]}, {k,Length[data]}]; mat+Transpose[mat] ]toAdjacency2[origdata_] := Module[ {data=Sort[Map[Reverse,Union[origdata]]], mat, len, event}, data = Map[Last, Split[data,#1[[1]]===#2[[1]]&], {2}]; dim = Length[Union[Flatten[data]]]; len = Length[data]; mat = Table[0, {dim}, {dim}]; Do [ event = data[[j]]; Do [ Do [ mat[[event[[m]],event[[k]]]] += 1; mat[[event[[k]],event[[m]]]] += 1, {m,k-1}], {k,Length[event]}], {j,len}]; mat ]data1 = Table[{Random[Integer,{1,1000}], Random[Integer,50]}, {10000}];data2 = Table[{Random[Integer,{1,1000}], Random[Integer,100]}, {10000}];data3 = Table[{Random[Integer,{1,1000}], Random[Integer,200]}, {10000}];Timings are on a 1.5 GHz machine running the Mathematica 4.2 kernelIn[107]:= Timing[m0 = toAdjacency0[data1];]Out[107]= {5.44 Second, Null}In[108]:= Timing[m1 = toAdjacency1[data1];]Out[108]= {10.5 Second, Null}In[109]:= Timing[m2 = toAdjacency2[data1];]Out[109]= {16.24 Second, Null}In[110]:= m0 === m1 === m2Out[110]= TrueNote that for this example the result is not terrible sparse (less than20%).In[112]:= Count[Flatten[m0], 0]Out[112]= 191374In[115]:= Timing[m0 = toAdjacency0[data2];]Out[115]= {11.51 Second, Null}In[116]:= Timing[m1 = toAdjacency1[data2];]Out[116]= {10.92 Second, Null}In[117]:= Timing[m2 = toAdjacency2[data2];]Out[117]= {9.07 Second, Null}Curiously this was the first example I tried, and all three methodsperform about the same in this case. The result, not suprisingly, ismore sparse (40%) because we have the same number of actors and pairs aspreviously, but now with more events to spread out over the pairs.In[118]:= Count[Flatten[m0], 0]Out[118]= 403232When we get sparser still, the third method begins to dominate and thefirst is relatively slower.In[119]:= Timing[m0 = toAdjacency0[data3];]Out[119]= {22.73 Second, Null}In[120]:= Timing[m1 = toAdjacency1[data3];]Out[120]= {10.88 Second, Null}In[121]:= Timing[m2 = toAdjacency2[data3];]Out[121]= {4.96 Second, Null}Now sparsity is over 60%.In[122]:= Count[Flatten[m0], 0]Out[122]= 624350The relative speed of this last method, in this instance, is derivedfrom the fact that individual event lists are on average half the sizeof the previous case. Hence the main loop is expected to improve onaverage by a factor of 2 (you get a factor of 4 for iterating over allpairs in each event, but lose a factor of 2 because there are twice asmany event lists).My guess is that a preprocessor that assesses number of actors vs.number of events would be the best way to choose between the first andthird methods (which, inexplicably, are labelled as methods 0 and 2). Itis not clear to me whether the middle approach will ever dominate. Ihave not given much thought to concocting examples where it wouldbecause offhand I suspect they would be pathological as in dense andwith large intersections.As a last remark I'll note that these might run significantly faster ifcoded with Compile. Whether that is viable depends on the form of thedata. In the above example where everything is a machine integer thatapproach would certainly work.Daniel LichtblauWolfram Research ==== First thanks to all, and in particular Bobby Treat, for your help withthis question.The best solution was as follows:lst = ReadList[c:data.txt, {Number, Number}]adjacenceMatrix[ x:{{_, _}..}] := Module[{actors, events}, {actors, events} = Union /@ Transpose[x]; Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]]a = adjacenceMatrix[lst];b = a . Transpose[a];c = b (1 - IdentityMatrix[Length[b]])C is the desired symmetric matrix with off diagonal values of >=0,indicating the number of times two actors participate in the same event.The diagonal is set to 0. A few items in response to Bobby's message, below. While c is, in fact,a huge matrix with lots of cells equal to zero, that is exactly how weneed it structured for our analysis and research question (not relevantto the list, but I'd be happy to discuss off list). Processing time isactually not too bad!! I'm running a PIII 900 with 512 SDRAM, and thecode ran a 177 x 3669 matrix in under 90 seconds. MatrixForm [c]presented no problems in viewing in the front end, but then it's only177 x 177.Tom********************************************** Thomas P. MoliternoGraduate School of ManagementUniversity of California, Irvinetmoliter@uci.edu************************************ **********-----Original Message-----columns will be numbered from 1 to the number of observed actors orevents, and will correspond to actors and events in sorted order.That said, you're asking for a VERY large matrix, and most of itsentries will be zero. I'll suggest another way, later.The following indicates AT MOST 13.4% of the entries could be non-zero:lst = ReadList[moliterno-test1996.txt, {Number, Number}]; {actors, events} = Union /@ Transpose[lst]; N[Length[lst]/(Length[actors]*Length[actors])] 0.13350994338800987However, a random sample shows that less than 1% will be non-zero:Timing[ Count[(MemberQ[lst, {actors[[Random[Integer, Length[actors]]]], events[[Random[Integer, Length[events]]]]}] & ) /@ Range[10000], True]/ 10000.]{7.515999999999998*Second, 0.008}Nevertheless, the following code should build the matrices you want.I'm using a 2.2GHz P4 and 1024MB RDRAM, so if you have a slower machine,be warned.adjacenceMatrix[ x:{{_, _}..}] := Module[{actors, events}, {actors, events} = Union /@ Transpose[x]; Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]]Timing[a = adjacenceMatrix[lst]; ]Dimensions[a]{5.671999999999997*Second, Null}{166, 1778}Timing[b = a . Transpose[a]; ]{0.5309999999999988*Second, Null}You don't want to display a or b in MatrixForm. It will crash youranything at all from the result, and use something likeb[[Range[20],Range[4]]]//MatrixForm{{47, 0, 0, 0}, {0, 3, 0, 0}, {0, 0, 7, 1}, {0, 0, 1, 59}, {0, 0, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 0, 0, 1}, {0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}}to get a glimpse at some of it. It's the Ôa' matrix that's terriblysparse -- the Ôb' matrix isn't unreasonable. Elements of the Ôa' matrixcan be quickly computed by the functionaFunction = If[MemberQ[lst, {actors[[#1]], events[[#2]]}], 1, 0] &;That stores a line of code rather than all those ones and zeroes. The bmatrix (call it bb this time) can be computed as:Timing[bb = (#1 . Transpose[#1] & ) [Array[aFunction, {Length[actors], Length[events]}]]; ]bb == b{6.1569999999999965*Second, Null}TrueBobby Treat-----Original Message-----posting a this was the most helpful solution message to the list, butfirst I hoped to ask you a follow up question, if I may (and I'llcapture your off-line response here in my final posting to the list).I've run the code (copied from you) below, and get the correct outputfor made-up data, but when I import in real data, I get an errormessage. Here's the input I'm running:lst = ReadList[c:test1996.txt, {Number, Number}]AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj]MatrixForm[a = AdjacenceMatrix[lst]]MatrixForm[b = a.Transpose[a]]And here's what I get for output:Set::partw : Part 300007 of <<1>> does not exist.Set::partw : Part 300007 of <<1>> does not exist.Set::partw : Part 300007 of <<1>> does not exist.General::stop : Further output of Set::partw will be suppressed duringthis calculation.Then I get the two matrices (a & b as per your code), but they are justfilled with zeros. So it gets to about the 4th line of your code, butthen doesn't fill-in from my data. Finally, I should note that30007 is one of the actors in the data that I've read in. In caseyou want to run this yourself, I've attached the raw data file. Thereare 166 actors and 1778 events: both actors and events are coded with6-digit numbers, actors begin with 3's, events with 2's.I'm sure this is a silly question, and that there is an easy answer... But I sure can't find it. So I really appreciate your help andinterest!!!!Tom*************************************** *******Thomas P. MoliternoGraduate School of ManagementUniversity of California, Irvinetmoliter@uci.edu************************************ **********-----Original Message-----If you multiply it by its transpose, you get something else that'suseful:lst = {{1, A}, {1, B}, {2, B}, {3, C}, {3, D}, {1, D}, {1, C}};AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj]MatrixForm[a = AdjacenceMatrix[lst]]MatrixForm[b = a.Transpose[a]]Matrix Ôb' records how many events two actors have in common. On thediagonal, it shows the total number of events each actor is connectedto.It's easy to put zeroes on the diagonal:MatrixForm[c = b (1 - IdentityMatrix[Length[b]])]To get the originally intended incidence matrix, this works:d = c /. {_?Positive -> 1}However, I think matrices Ôa' and Ôb' are actually more useful, and Ôa'easily leads to all the others.Bobby-----Original Message-----AdjacenceMatrix[lst : {{_, _} ..}] := Module[ {actors,events adj}, {events, actors} = Union /@ Transpose[lst]; adj = Table[0, {Length[events]}, {Length[actors]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, actors]]; adj ]you getIn[]:=AdjacenceMatrix[lst]Out[]={{1, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}} Jens> I need to create an adjacency matrix from my data, which is currentlyin> the form of a .txt file and is basically a two column incidence list.> For example:> 1 A> 1 B> 2 B> 3 C> . .> . .> . .> m n> Where 1 to m represent actors and A to n represent events. My goal isto> have an (m x m) matrix where cell i,j equals 1 if two actors are> incident to the same event (in the sample above, 1 and 2 are both> incident to B) and 0 otherwise (w/ zeros on the diagonal).> I'm new to Mathmatica, and so I'm on the steep part of the learning> curve ... All I've been able to figure out so far is how to get my> incidence list into the program using Import[filename.txt]. But then> what? How do I convert to the adjacency matrix? I've found the> ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but Ican't> seem to get it to work ...> Tom> **********************************************> Thomas P. Moliterno> Graduate School of Management> University of California, Irvine> tmoliter@uci.edu> ********************************************** ==== ====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 01375>>Reply-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 149493891236234 52500771916869370459119776018798804630436149786919912931962574 3010292363124675/ 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?>> STH>Reply-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 ==== I want to add a further suggestion:Probably each differential equation logically belongs to one of the definedclasses in the sense, that it helps to define the behaviour of thecomponent.In this case, each differential equation should be stored in one of thesesclasses as textstring in a form appropriate for the execution inMathematica.Hermann Schmitt----- Original Message ----->> Is any body here have expertise or information about the capability of> Mathematica as a system simulation tool?> Mr. Kuska answers:> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].>> My comment:>> That is: He sees the simulation system merely as a set of differential> equations.>> The question of Mr. Nagesh:>> My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?> The answer of Mr. Kuska is:> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})>> My comment:>> This is a nice command and shows the knowledge of Mr.Kuska. But does Mr.> Nagesh understand it and is it sufficient to check, if all inputs are> numerical?>> Additionally I think, it is not userfriendly to see the input merely as a> set of 200-250 numbers.>> My suggestion is, that JLink is used, a suggestion Mr. Kusk takes into> consideration, too.>> But further I suggest, that classes are defined in Java, which representthe> parts of the system.>> Constructors of the classes should build objects with default values.> Graphical user interfaces>> should give the opportunity to change the data fields in the objects and> check the input for correctness.>> The system should give the opportunity, to store the objects on harddisk> (serialization).>> accessed directly.> My name is Nagesh and pursuing research studies in Refrigeration. At> present I am writing a Dynamic Refrigeration System SimulationPackage.> I> am using Mathematica as a programming language for the same since last> one> year. I don't have any programming experience before this. I have> following> querries:-> 1. Is any body here have expertise or information about the capability> of> > Mathematica as a system simulation tool?>> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].>> 2. Is is possible to program a user friendly interface for my system> simulation package with Mathematica or I have to use some other> software?>> Write a MathLink or J/Link frontend that launch the kernel. But you> should keep> in mind that the user interface is typical 80-90 % of your code.> If you just whant to solve some ode's it is probably easyer to> include one of the excelent ode-solvers from netlib in your C-code> than to call Mathematica to do that. As long as you dont wish to change> the ode's very often (than Mathematica is more ßexible) you should> not use Mathematica.>> 3. My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations. Is is possible to> solve these in Mathematica ?>> Sure.> If yes then can anybody here guide me about> this further.>> Write down the equations and call NDSolve[].> I am explaining below in short about the objectives I want to fulfill> from> > coding out of my main input file>> 1. Example from Main Input File ( this will contain about 200-250> variables> > which will be entered by the user of this package)>> This sounds like a *very* userfiendly interface ;-)> > Below is examples of two variables entered into this file, which willbe> used in other analysis files for further evaluation.>> 2. Example from other analysis file ( there will be about 20-25 other> such> component analysis files ) where the above mentioned variables frommain> input file will be used for further evaluations:->> Below is one example from this file explaining how the variables from> main> input file will be used in other files.>> I hope that this short information will be useful for guiding me to> solve> the following problems that I am facing. I am facing follwing problems> or> objectives:->> 1. My 1st Objective:- The user of this package must be able to change> only> the value of the variable in the main input file but he must not beable> to> change the name of the variable itself. For example he must be able to> change the value of the variable but he must not be able tochange> the> name of this variable itself.> Here our problem is how to achieve or program it so that our objective> will> be fullfilled.>> Options with defaulf values ? or something like>> {aParam,bParam}={ODEParameter1,ODEParameter2} /.> userRules /.> {ODEParameter1->1,ODEParameter2->2}> 2. My 2nd Objective:- How I can program the main input file so that it> will> be user friendly in terms of its visuals and satisfying the constraint> mentioned above in objective1.>> What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values for each> variable in the main input file ? so that there will be always a value> assigned to each variable listed in main input file whenever the user> opens> up this file. If user want to change the values of some variables then> he> can change them and run the simulation otherwise the simulation runwill> be> done with optional values assigned to each variable in the input file.>> See above.> 4. My 4th Objective:- How can I program the check for correctness ofthe> input values supplied by the package user ?>> > And @@ (NumericQ /@ {aListOfAllYourNumericParameters})>> >> Jens> ==== I have developed one package where it is included a functions forsolving System of ODE. You can downloaded from:http://web.usal.es/~guillerm/biokmod.The functions are: SystemDSolve and SystemNDSolve Guillermo Sanchez> I want to add a further suggestion:> Probably each differential equation logically belongs to one of the defined> classes in the sense, that it helps to define the behaviour of the> component.> In this case, each differential equation should be stored in one of theses> classes as textstring in a form appropriate for the execution in> Mathematica.> Hermann Schmitt> ----- Original Message ----->> I agree with Mr. Kuska, that the system Mr Nagesh describes is not> userfriendly. But I think, the suggestions of Mr. Kuska do not make it> more> userfriendly, rather the opposite is true.>> Mr. Nagesh asks>> Is any body here have expertise or information about the capability of> Mathematica as a system simulation tool?> Mr. Kuska answers:> Since the most system simulation tools are simply solving a system of> > ordinary differntial equations it is simple to do this with NDSolve[].>> My comment:>> That is: He sees the simulation system merely as a set of differential> equations.>> The question of Mr. Nagesh:>> My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?> The answer of Mr. Kuska is:> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})>> My comment:>> This is a nice command and shows the knowledge of Mr.Kuska. But does Mr.> Nagesh understand it and is it sufficient to check, if all inputs are> numerical?>> Additionally I think, it is not userfriendly to see the input merely as a> > set of 200-250 numbers.>> My suggestion is, that JLink is used, a suggestion Mr. Kusk takes into> consideration, too.>> But further I suggest, that classes are defined in Java, which represent> the> parts of the system.>> Constructors of the classes should build objects with default values.> Graphical user interfaces> >> should give the opportunity to change the data fields in the objects and> check the input for correctness.>> The system should give the opportunity, to store the objects on harddisk> (serialization).>> accessed directly.> > My name is Nagesh and pursuing research studies in Refrigeration. At> present I am writing a Dynamic Refrigeration System Simulation> Package.> I> am using Mathematica as a programming language for the same since last> one> year. I don't have any programming experience before this. I have> following> > querries:-> 1. Is any body here have expertise or information about the capability> of> Mathematica as a system simulation tool?>> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].>> 2. Is is possible to program a user friendly interface for my system> simulation package with Mathematica or I have to use some other> software?> >> Write a MathLink or J/Link frontend that launch the kernel. But you> should keep> in mind that the user interface is typical 80-90 % of your code.> If you just whant to solve some ode's it is probably easyer to> include one of the excelent ode-solvers from netlib in your C-code> than to call Mathematica to do that. As long as you dont wish to change> the ode's very often (than Mathematica is more ßexible) you should> not use Mathematica.>> 3. My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations. Is is possible to> solve these in Mathematica ?>> Sure.> If yes then can anybody here guide me about> this further.> >> Write down the equations and call NDSolve[].>> >> I am explaining below in short about the objectives I want to fulfill> from> coding out of my main input file>> 1. Example from Main Input File ( this will contain about 200-250> variables> which will be entered by the user of this package)>> This sounds like a *very* userfiendly interface ;-)> Below is examples of two variables entered into this file, which will> be> used in other analysis files for further evaluation.>> 2. Example from other analysis file ( there will be about 20-25 other> such> > component analysis files ) where the above mentioned variables from> main> input file will be used for further evaluations:->> Below is one example from this file explaining how the variables from> main> input file will be used in other files.>> I hope that this short information will be useful for guiding me to> solve> the following problems that I am facing. I am facing follwing problems> or> objectives:->> > 1. My 1st Objective:- The user of this package must be able to change> only> the value of the variable in the main input file but he must not be> able> to> change the name of the variable itself. For example he must be able to> change the value of the variable but he must not be able to> change> the> name of this variable itself.> Here our problem is how to achieve or program it so that our objective> will> be fullfilled.>> Options with defaulf values ? or something like>> {aParam,bParam}={ODEParameter1,ODEParameter2} /.> userRules /.> {ODEParameter1->1,ODEParameter2->2}>> >> 2. My 2nd Objective:- How I can program the main input file so that it> will> be user friendly in terms of its visuals and satisfying the constraint> mentioned above in objective1.>> What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values for each> > variable in the main input file ? so that there will be always a value> assigned to each variable listed in main input file whenever the user> opens> up this file. If user want to change the values of some variables then> he> can change them and run the simulation otherwise the simulation run> will> be> done with optional values assigned to each variable in the input file.> >> See above.> 4. My 4th Objective:- How can I program the check for correctness of> the> input values supplied by the package user ?>> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})> > Jens> ==== I agree with Mr. Kuska, that the system Mr Nagesh describes is notuserfriendly. But I think, the suggestions of Mr. Kuska do not make it moreuserfriendly, rather the opposite is true.Mr. Nagesh asksIs any body here have expertise or information about the capability ofMathematica as a system simulation tool?Mr. Kuska answers:Since the most system simulation tools are simply solving a system ofordinary differntial equations it is simple to do this with NDSolve[].My comment:That is: He sees the simulation system merely as a set of differentialequations.The question of Mr. Nagesh:My 4th Objective:- How can I program the check for correctness of the input values supplied by the package user ?The answer of Mr. Kuska is:And @@ (NumericQ /@ {aListOfAllYourNumericParameters})My comment:This is a nice command and shows the knowledge of Mr.Kuska. But does Mr.Nagesh understand it and is it sufficient to check, if all inputs arenumerical?Additionally I think, it is not userfriendly to see the input merely as aset of 200-250 numbers.My suggestion is, that JLink is used, a suggestion Mr. Kusk takes intoconsideration, too.But further I suggest, that classes are defined in Java, which represent theparts of the system.Constructors of the classes should build objects with default values.Graphical user interfacesshould give the opportunity to change the data fields in the objects andcheck the input for correctness.The system should give the opportunity, to store the objects on harddisk(serialization).accessed directly.>> My name is Nagesh and pursuing research studies in Refrigeration. At> present I am writing a Dynamic Refrigeration System Simulation Package.I> am using Mathematica as a programming language for the same since lastone> year. I don't have any programming experience before this. I havefollowing> querries:-> 1. Is any body here have expertise or information about the capabilityof> Mathematica as a system simulation tool?>> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].>> 2. Is is possible to program a user friendly interface for my system> simulation package with Mathematica or I have to use some othersoftware?>> Write a MathLink or J/Link frontend that launch the kernel. But you> should keep> in mind that the user interface is typical 80-90 % of your code.> If you just whant to solve some ode's it is probably easyer to> include one of the excelent ode-solvers from netlib in your C-code> than to call Mathematica to do that. As long as you dont wish to change> the ode's very often (than Mathematica is more ßexible) you should> not use Mathematica.>> 3. My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations. Is is possible to> solve these in Mathematica ?>> Sure.> If yes then can anybody here guide me about> this further.>> Write down the equations and call NDSolve[].> I am explaining below in short about the objectives I want to fulfillfrom> coding out of my main input file>> 1. Example from Main Input File ( this will contain about 200-250variables> which will be entered by the user of this package)>> This sounds like a *very* userfiendly interface ;-)> Below is examples of two variables entered into this file, which will be> used in other analysis files for further evaluation.>> 2. Example from other analysis file ( there will be about 20-25 othersuch> component analysis files ) where the above mentioned variables from main> input file will be used for further evaluations:->> Below is one example from this file explaining how the variables frommain> input file will be used in other files.>> I hope that this short information will be useful for guiding me tosolve> the following problems that I am facing. I am facing follwing problemsor> objectives:->> 1. My 1st Objective:- The user of this package must be able to changeonly> the value of the variable in the main input file but he must not be ableto> change the name of the variable itself. For example he must be able to> change the value of the variable but he must not be able to changethe> name of this variable itself.> Here our problem is how to achieve or program it so that our objectivewill> be fullfilled.>> Options with defaulf values ? or something like>> {aParam,bParam}={ODEParameter1,ODEParameter2} /.> userRules /.> {ODEParameter1->1,ODEParameter2->2}> 2. My 2nd Objective:- How I can program the main input file so that itwill> be user friendly in terms of its visuals and satisfying the constraint> mentioned above in objective1.>> What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values for each> variable in the main input file ? so that there will be always a value> assigned to each variable listed in main input file whenever the useropens> up this file. If user want to change the values of some variables thenhe> can change them and run the simulation otherwise the simulation run willbe> done with optional values assigned to each variable in the input file.>> See above.> 4. My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?>> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})> Jens> ==== See my comments in the following text!Hermann Schmitt----- Original Message ----->> Is any body here have expertise or information about the capability of> Mathematica as a system simulation tool?> Mr. Kuska answers:> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].>> My comment:>> That is: He sees the simulation system merely as a set of differential> equations.>> hmm, since the original poster write>> My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations.>> it seems not completly wrong to assume that the system consists of> of ode's ..>Yout should not ignore the word merely.It is not enough to have a set 60 differential equations and a set of200-250 numbers. That is not simulation system, which can be used by userswith the exception, perhaps, of the programmer of the system himself.How does e.g. the user know what meaning a number in the set has, ought hecount the numbers from the beginning?Your nice command shows only, if there is an input, which is not a number.But I think the user would like to know, which of the 200 elements are notnumbers.The only good of your command is, that it looks nice and shows yourknowledge!>> The question of Mr. Nagesh:>> My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?> The answer of Mr. Kuska is:> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})>> My comment:>> This is a nice command and shows the knowledge of Mr.Kuska. But does Mr.> Nagesh understand it and is it sufficient to check, if all inputs are> numerical?>> It seems you have a deeper knowlege about the things that Mr. Nagesh> understand. You know him personally ? It is not very polite to> make speculations *what* a other person understand.>> And no it is not sufficent to check that all parameters are numbers.> Typical paramters described by intervals, where the assumptions of> a model are valid. But for this checks one needs more knowlege> about the meaning of the parameters. And one needs the knowlege about> the differntial equations, to find out the eigenvalues of the jacobian> ...> Additionally I think, it is not userfriendly to see the input merely asa> set of 200-250 numbers.>> My suggestion is, that JLink is used, a suggestion Mr. Kusk takes into> consideration, too.>> That will be fast as lightning !> But further I suggest, that classes are defined in Java, which representthe> parts of the system.>> That is notable nonsense! When the differntial equations should be> solved with Mathematica, the parts can't be Java classes. Mathematica's> NDSolve[] need a explicit expression to integrate the equations.That's not nonsense, the Mathematica program does not fetch the classes butthe numbers in the classes (or better in the objects).the Java classes in textform. They can then be fetched from the Mathematicaprogram and transformed into expressions by the Command ToExpression.The aim is, to have a clear separation of the system into components, whichare manageable and understandable.>> OK you can call a Java class member from Mathematica but this will> be incredible slow when the right hand side is evaluated 200-300> times and every evaluation make several callbacks to the Java source.> Event handler of the Java main program (without some modification in> the event loop) while it is evaluating an other command.My idea is to fetch the values once from the Java objects at the beginning.200-250 numbers is not so much..> Constructors of the classes should build objects with default values.>> That's a great idea. If a simulation run should be documented, one> always> need the full listing of the Java source to find the actual parameter> settings.That is not my opinion. I think not every user of the simulation systemshould have to know Java and Mathematica.The user must look for the values in the objects. And the values are in theobjects, if they come from the constructor or from the graphical userinterface.I think, there should be listings of the objects including names of thevariables. In the objects the values are in an meaningful environment.>> Graphical user interfaces> should give the opportunity to change the data fields in the objects and> check the input for correctness.>> *and* what has a GUI for 200-250 variables to do with Mathematica ?> BTW one has typical much less variables because many parameters> are fixed and it make no sense to change, for example, material> constants of materials that can't exchanged> The system should give the opportunity, to store the objects on harddisk> (serialization).>> accessed directly.> Can you be so kind, to explain *how* your posting help a person that> ask How can I build a simulation system with Mathematica ?>> You *can* say Don't use Mathematica, use Java! but this has nothing> to do with the question or with my reply.It is you, who proposes to solve the problem with C/C++ and not to useMathematica (see below!)My point of view is:Use Mathematica, for what Mathemtica is good, and Java, for what Java isgood.Mathematica is not so good as Java for data entry and Java is better thanMathematica to represent the simulation system (by objects).>> But I still would suggest to use C/C++ and a numerical> ode-solver, make a fancy GUI/Script> interface and don't use Mathematica for such a simple task.> The ode-solver is the smallest part of such a simulation system.>> Jens> My name is Nagesh and pursuing research studies in Refrigeration. At> > present I am writing a Dynamic Refrigeration System SimulationPackage.> I> am using Mathematica as a programming language for the same sincelast> one> year. I don't have any programming experience before this. I have> following> querries:-> 1. Is any body here have expertise or information about thecapability> of> Mathematica as a system simulation tool?>> Since the most system simulation tools are simply solving a systemof> ordinary differntial equations it is simple to do this with NDSolve[].>> 2. Is is possible to program a user friendly interface for my system> simulation package with Mathematica or I have to use some other> software?>> Write a MathLink or J/Link frontend that launch the kernel. But you> should keep> > in mind that the user interface is typical 80-90 % of your code.> If you just whant to solve some ode's it is probably easyer to> include one of the excelent ode-solvers from netlib in your C-code> than to call Mathematica to do that. As long as you dont wish tochange> > the ode's very often (than Mathematica is more ßexible) you should> not use Mathematica.>> 3. My refrigeration system simulation package is likely to have> > approximately 60 First order Differential equations. Is is possibleto> solve these in Mathematica ?>> Sure.> If yes then can anybody here guide me about> > this further.>> Write down the equations and call NDSolve[].> I am explaining below in short about the objectives I want tofulfill> from> coding out of my main input file>> 1. Example from Main Input File ( this will contain about 200-250> variables> which will be entered by the user of this package)>> This sounds like a *very* userfiendly interface ;-)> Below is examples of two variables entered into this file, whichwill be> used in other analysis files for further evaluation.>> 2. Example from other analysis file ( there will be about 20-25other> such> component analysis files ) where the above mentioned variables frommain> input file will be used for further evaluations:->> Below is one example from this file explaining how the variablesfrom> > main> input file will be used in other files.>> > I hope that this short information will be useful for guiding me to> solve> the following problems that I am facing. I am facing follwingproblems> or> objectives:->> 1. My 1st Objective:- The user of this package must be able tochange> only> the value of the variable in the main input file but he must not beable> to> change the name of the variable itself. For example he must be ableto> change the value of the variable but he must not be able tochange> the> name of this variable itself.> > Here our problem is how to achieve or program it so that ourobjective> will> be fullfilled.>> Options with defaulf values ? or something like>> {aParam,bParam}={ODEParameter1,ODEParameter2} /.> userRules /.> {ODEParameter1->1,ODEParameter2->2}>> >> 2. My 2nd Objective:- How I can program the main input file so thatit> will> be user friendly in terms of its visuals and satisfying theconstraint> mentioned above in objective1.>> What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values for each> > variable in the main input file ? so that there will be always avalue> assigned to each variable listed in main input file whenever theuser> opens> up this file. If user want to change the values of some variablesthen> he> can change them and run the simulation otherwise the simulation runwill> be> done with optional values assigned to each variable in the inputfile.>> See above.> 4. My 4th Objective:- How can I program the check for correctness ofthe> input values supplied by the package user ?> >> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})> Jens> >>Reply-To: kuska@informatik.uni-leipzig.de ==== > I agree with Mr. Kuska, that the system Mr Nagesh describes is not> userfriendly. But I think, the suggestions of Mr. Kuska do not make it more> userfriendly, rather the opposite is true.> Mr. Nagesh asks> Is any body here have expertise or information about the capability of> Mathematica as a system simulation tool?> Mr. Kuska answers:> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].> My comment:> That is: He sees the simulation system merely as a set of differential> equations.hmm, since the original poster writeMy refrigeration system simulation package is likely to have approximately 60 First order Differential equations.it seems not completly wrong to assume that the system consists ofof ode's ..> The question of Mr. Nagesh:> My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?> The answer of Mr. Kuska is:> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})> My comment:> This is a nice command and shows the knowledge of Mr.Kuska. But does Mr.> Nagesh understand it and is it sufficient to check, if all inputs are> numerical?It seems you have a deeper knowlege about the things that Mr. Nagesh understand. You know him personally ? It is not very polite tomake speculations *what* a other person understand.And no it is not sufficent to check that all parameters are numbers.Typical paramters described by intervals, where the assumptions ofa model are valid. But for this checks one needs more knowlege about the meaning of the parameters. And one needs the knowlege aboutthe differntial equations, to find out the eigenvalues of the jacobian...> Additionally I think, it is not userfriendly to see the input merely as a> set of 200-250 numbers.> My suggestion is, that JLink is used, a suggestion Mr. Kusk takes into> consideration, too.That will be fast as lightning ! > But further I suggest, that classes are defined in Java, which represent the> parts of the system.That is notable nonsense! When the differntial equations should besolved with Mathematica, the parts can't be Java classes. Mathematica'sNDSolve[] need a explicit expression to integrate the equations.OK you can call a Java class member from Mathematica but this willbe incredible slow when the right hand side is evaluated 200-300times and every evaluation make several callbacks to the Java source.Event handler of the Java main program (without some modification inthe event loop) while it is evaluating an other command.> Constructors of the classes should build objects with default values.That's a great idea. If a simulation run should be documented, onealwaysneed the full listing of the Java source to find the actual parametersettings. > Graphical user interfaces> should give the opportunity to change the data fields in the objects and> check the input for correctness.*and* what has a GUI for 200-250 variables to do with Mathematica ?BTW one has typical much less variables because many parametersare fixed and it make no sense to change, for example, materialconstants of materials that can't exchanged> The system should give the opportunity, to store the objects on harddisk> (serialization).> accessed directly.> Can you be so kind, to explain *how* your posting help a person thatask How can I build a simulation system with Mathematica ?You *can* say Don't use Mathematica, use Java! but this has nothingto do with the question or with my reply. But I still would suggest to use C/C++ and a numerical ode-solver, make a fancy GUI/Scriptinterface and don't use Mathematica for such a simple task.The ode-solver is the smallest part of such a simulation system. Jens>> > My name is Nagesh and pursuing research studies in Refrigeration. At> present I am writing a Dynamic Refrigeration System Simulation Package.> I> am using Mathematica as a programming language for the same since last> one> year. I don't have any programming experience before this. I have> following> querries:-> > 1. Is any body here have expertise or information about the capability> of> Mathematica as a system simulation tool?>> Since the most system simulation tools are simply solving a system of> ordinary differntial equations it is simple to do this with NDSolve[].>> 2. Is is possible to program a user friendly interface for my system> simulation package with Mathematica or I have to use some other> software?>> Write a MathLink or J/Link frontend that launch the kernel. But you> should keep> in mind that the user interface is typical 80-90 % of your code.> If you just whant to solve some ode's it is probably easyer to> include one of the excelent ode-solvers from netlib in your C-code> than to call Mathematica to do that. As long as you dont wish to change> the ode's very often (than Mathematica is more ßexible) you should> not use Mathematica.>> 3. My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations. Is is possible to> solve these in Mathematica ?>> Sure.> If yes then can anybody here guide me about> this further.>> Write down the equations and call NDSolve[].> I am explaining below in short about the objectives I want to fulfill> from> coding out of my main input file>> > 1. Example from Main Input File ( this will contain about 200-250> variables> which will be entered by the user of this package)>> This sounds like a *very* userfiendly interface ;-)> Below is examples of two variables entered into this file, which will be> used in other analysis files for further evaluation.>> 2. Example from other analysis file ( there will be about 20-25 other> such> component analysis files ) where the above mentioned variables from main> input file will be used for further evaluations:->> Below is one example from this file explaining how the variables from> main> input file will be used in other files.>> I hope that this short information will be useful for guiding me to> solve> > the following problems that I am facing. I am facing follwing problems> or> objectives:->> 1. My 1st Objective:- The user of this package must be able to change> only> the value of the variable in the main input file but he must not be able> to> change the name of the variable itself. For example he must be able to> change the value of the variable but he must not be able to change> the> name of this variable itself.> Here our problem is how to achieve or program it so that our objective> will> be fullfilled.>> Options with defaulf values ? or something like>> {aParam,bParam}={ODEParameter1,ODEParameter2} /.> userRules /.> {ODEParameter1->1,ODEParameter2->2}> 2. My 2nd Objective:- How I can program the main input file so that it> will> be user friendly in terms of its visuals and satisfying the constraint> mentioned above in objective1.>> What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values for each> variable in the main input file ? so that there will be always a value> assigned to each variable listed in main input file whenever the user> opens> up this file. If user want to change the values of some variables then> he> can change them and run the simulation otherwise the simulation run will> be> done with optional values assigned to each variable in the input file.>> See above.> 4. My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?>> And @@ (NumericQ /@ {aListOfAllYourNumericParameters})>> >> Jens>Reply-To: kuska@informatik.uni-leipzig.de ==== > My name is Nagesh and pursuing research studies in Refrigeration. At> present I am writing a Dynamic Refrigeration System Simulation Package. I> am using Mathematica as a programming language for the same since last one> year. I don't have any programming experience before this. I have following> querries:-> 1. Is any body here have expertise or information about the capability of> Mathematica as a system simulation tool?Since the most system simulation tools are simply solving a system ofordinary differntial equations it is simple to do this with NDSolve[].> 2. Is is possible to program a user friendly interface for my system> simulation package with Mathematica or I have to use some other software?Write a MathLink or J/Link frontend that launch the kernel. But youshould keepin mind that the user interface is typical 80-90 % of your code.If you just whant to solve some ode's it is probably easyer toinclude one of the excelent ode-solvers from netlib in your C-codethan to call Mathematica to do that. As long as you dont wish to changethe ode's very often (than Mathematica is more ßexible) you shouldnot use Mathematica.> 3. My refrigeration system simulation package is likely to have> approximately 60 First order Differential equations. Is is possible to> solve these in Mathematica ?Sure. > If yes then can anybody here guide me about> this further.Write down the equations and call NDSolve[].> I am explaining below in short about the objectives I want to fulfill from> coding out of my main input file> 1. Example from Main Input File ( this will contain about 200-250 variables> which will be entered by the user of this package)This sounds like a *very* userfiendly interface ;-)> > Below is examples of two variables entered into this file, which will be> used in other analysis files for further evaluation.> 2. Example from other analysis file ( there will be about 20-25 other such> component analysis files ) where the above mentioned variables from main> input file will be used for further evaluations:-> Below is one example from this file explaining how the variables from main> input file will be used in other files.> I hope that this short information will be useful for guiding me to solve> the following problems that I am facing. I am facing follwing problems or> objectives:-> 1. My 1st Objective:- The user of this package must be able to change only> the value of the variable in the main input file but he must not be able to> change the name of the variable itself. For example he must be able to> change the value of the variable but he must not be able to change the> name of this variable itself.> Here our problem is how to achieve or program it so that our objective will> be fullfilled.Options with defaulf values ? or something like{aParam,bParam}={ODEParameter1,ODEParameter2} /. userRules /. {ODEParameter1->1,ODEParameter2->2}> 2. My 2nd Objective:- How I can program the main input file so that it will> be user friendly in terms of its visuals and satisfying the constraint> mentioned above in objective1.What is *userfiendly* in a file with 250 variables ???> 3. My 3rd Objective:- How can I program the optional values for each> variable in the main input file ? so that there will be always a value> assigned to each variable listed in main input file whenever the user opens> up this file. If user want to change the values of some variables then he> can change them and run the simulation otherwise the simulation run will be> done with optional values assigned to each variable in the input file.See above.> 4. My 4th Objective:- How can I program the check for correctness of the> input values supplied by the package user ?And @@ (NumericQ /@ {aListOfAllYourNumericParameters})> Jens ==== 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]=divergent W[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 GoyderReply-To: spammers-go-here@yahoo.com ==== On Friday 27 September 2002 04:18 am, DrBob, as drbob@bigfoot.com, held forth the following in comp.soft-sys.math.mathematica () :> 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 ==== >>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 149493891236234 52500771916869370459119776018798804630436149786919912931962574 3010292363124675/ 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> ==== 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.org>moving 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. ==== 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> 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 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 ==== > One of these days the company I work for will buy one Mathematica 4.2> versions of the product.> window manager. Our Windows systems are running on top of VMWare in Windows> XP Professional.> In testing using an evaluation version I found that the VMWare/XP version is> performing pretty well so that wouldn't be an issue.> My main concern (and probably the grounds on which we will base our> decision) is the quality of the front-end. The Windows frontend works> ßawlessly; however, in test-driving earlier versions of Mathematica (3.0> satisfactorily. I didn't spend much time to hunt down the source of the> problem, but it is probable that some X key-mapping was wrong making, for> example, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On the> Windows frontend.> to full satisfaction? I'd be willing to spend a couple of hours to fix some> settings, but only if I'm sure it could be done. The bottom line is that I I> not if that would mean putting up with a quircky front-end.For what it is worth, I have no problems with the front end under Solaris -another varient of Unix. -- Dr. David Kirkby PhD,web page: http://www.david-kirkby.co.ukAmateur radio callsign: G8WRB ==== >> One of these days the company I work for will buy one Mathematica 4.2>> Windows versions of the product.> window manager. Our Windows systems are running on top of VMWare in>> Windows XP Professional.>> In testing using an evaluation version I found that the VMWare/XP version>> is performing pretty well so that wouldn't be an issue.> My main concern (and probably the grounds on which we will base our>> decision) is the quality of the front-end. The Windows frontend works>> ßawlessly; however, in test-driving earlier versions of Mathematica (3.0>> satisfactorily. I didn't spend much time to hunt down the source of the>> problem, but it is probable that some X key-mapping was wrong making, for>> example, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On the>> Windows frontend.> working to full satisfaction? I'd be willing to spend a couple of hours>> to fix some settings, but only if I'm sure it could be done. The bottom>> VMWare/Windows, but not if that would mean putting up with a quircky>> front-end.> For what it is worth, I have no problems with the front end under Solaris> - another varient of Unix.I sincerely wish WRI were more relaxed about allowing people to use the same license on the same hardware, but with a different OS. My understanding is that I would have to buy two licenses if I wanted to switch back and forth That's how open source is paid for. Not everybody has the same amount of spare blood in their veins, or willingness to spill it. For those who release of Mathematica, it would be nice to have a dual boot option. Perhaps it's simply a support issue. It would potentially cause the same customer to require more support if he were switching back and forth between OSs.http://public.globalsymmetry.com/proprietary/com/wri/ ch05.htmlhttp://66.92.149.152/proprietary/com/wri/ch05.html I still have some tweaks to add to this, such as M-k -> C-k, but it at least demonstrates that (all) things aren't cast in stone.STH ==== 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/>> ==== this is almost the solution.but it creates some artificial rests.when the sounds are created, there is some silence between the different notes.when after creation one clicks the play sound icon of the group with all the sounds, these rests disappear.is there a way of Play creating ghte waves, but NOT playing them,and then, doubleclicking the sound icon,hearing the sound without rests immediately?> I get the same result in 4.2 (under Windows). Not sure why. But you > could try this modification:> PlaySeq[L_, dur_] := Do[PlayTone[L[[i]], dur];> Pause[dur], {i, Length[L]}]> Then> PlaySeq[{224, 256, 384}, 3]> seems to work as expected, prolonging the notes before the last one to > their full expected duration.>>PlayTone[F_, dur_] := Play[Sin[2*Pi*F*t], {t, 0, dur}]>>allows me to play a sine wave of frequency F and duration dur>>PlaySeq[L_, dur_] := Do[PlayTone[L[[i]], dur], {i, Length[L]}]>>should allow me to play a sequence of tones>>with a given list of frequencies L>>and all the same duration dur.>>It does not work at least in 4.1>>all tones but the last one are much shorter than dur.>>any help?> -- --Erich Neuwirth, Computer Supported Didactics Working GroupVisit our SunSITE at http://sunsite.univie.ac.at ==== 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?>> STH>Reply-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>> /> 108671061439707605510003578275547938881981431359756495796079898 677435> 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>> /> 108671061439707605510003578275547938881981431359756495796079898 677435> 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