A21 You are of course right, I forgot that Mathematica does not try to keep precision or accuracy of machine arithmetic computations. But I think the actual precision you set need not be higher than machine precision, it just has to be set explicitely (is that right?). For example: In[1]:= Clear[f,a,b,k] In[2]:= k = $MachinePrecision; In[3]:= f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ (2*b),k]; In[4]:= a=77617.;b=33096.; In[5]:= a=SetAccuracy[a,k]; In[6]:= b=SetAccuracy[b,k]; In[7]:= f Out[7]= !((-5.51716400890319`-2.8311*^19)) In[8]:= Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; bounding by $MinPrecision instead. Out[8]= -20 Andrzej > Andrzej Yes, like you I took the original question to be about how to get the > result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more > than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to more > digits than shown in the original post, they should be entered with > as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / > 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. > You > should use a = SetAccuracy[a, Infinity] etc. But even then you won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you > the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== So? It's just as it should be, isn't it? Andrzej Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ > Go one step further: Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I think I'd prefer that Mathematica gave me a clue -- without being asked explicitly in JUST the right way that only you know and had forgotten -- that there's a precision problem. Oddly enough, when you DO ask it nicely, you get error messages, but if you're not aware there's a problem, it lets you go on your merry way, working with noise. Bobby -----Original Message----- Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f > -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I've been looking over the file and directory manipulation functions in Mathematica 4.1, and I'm not finding good examples of how to test for the existence of a file or directory before I attempt to create, access, or delete it. Are there any good examples of this somewhere? STH ==== FileNames[] does what you want. Steve Luttrell > I've been looking over the file and directory manipulation functions in Mathematica > 4.1, and I'm not finding good examples of how to test for the existence of > a file or directory before I attempt to create, access, or delete it. Are > there any good examples of this somewhere? STH > Reply-To: kuska@informatik.uni-leipzig.de ==== FileNames[] returns an empty list if there are no files. So FileNames[blub.txt] will return {} if the file does not exist. Jens > > I've been looking over the file and directory manipulation functions in Mathematica > 4.1, and I'm not finding good examples of how to test for the existence of > a file or directory before I attempt to create, access, or delete it. Are > there any good examples of this somewhere? > > STH ==== If you don't wont error messages all you need to do is to set MinPrecision low enough: In[1]:= $MinPrecision = -3; In[2]:= k = $MachinePrecision; In[3]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), k]; In[4]:= a = 77617.; b = 33096.; In[5]:= a = SetAccuracy[a, k]; In[6]:= b = SetAccuracy[b, k]; In[7]:= f Out[7]= -5.517164009`-2.8311*^19 In[8]:= Accuracy[f] Out[8]= -23 In[9]:= Precision[f] Out[9]= -3 In any case the answer you get is meaningless. > I think I'd prefer that Mathematica gave me a clue -- without being > asked explicitly in JUST the right way that only you know and had > forgotten -- that there's a precision problem. Oddly enough, when you DO ask it nicely, you get error messages, but if > you're not aware there's a problem, it lets you go on your merry way, > working with noise. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 8:05 PM > Cc: 'Allan Hayes'; mathgroup@smc.vnet.net So? It's just as it should be, isn't it? Andrzej Andrzej Kozlowski > Toyama International University > JAPAN > http://sigma.tuins.ac.jp/~andrzej/ > Go one step further: Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to > keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine > precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the > result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it > can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which > Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other > words, > it was why are the results of these two computations not the > same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f > should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; > f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) > > -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision > does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 > + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== >>In any case the answer you get is meaningless. Precisely. Bobby -----Original Message----- 121*b^4 - 2) + 5.5*b^8 + a/(2*b), k]; In[4]:= a = 77617.; b = 33096.; In[5]:= a = SetAccuracy[a, k]; In[6]:= b = SetAccuracy[b, k]; In[7]:= f Out[7]= -5.517164009`-2.8311*^19 In[8]:= Accuracy[f] Out[8]= -23 In[9]:= Precision[f] Out[9]= -3 In any case the answer you get is meaningless. > I think I'd prefer that Mathematica gave me a clue -- without being > asked explicitly in JUST the right way that only you know and had > forgotten -- that there's a precision problem. Oddly enough, when you DO ask it nicely, you get error messages, but if > you're not aware there's a problem, it lets you go on your merry way, > working with noise. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 8:05 PM > Cc: 'Allan Hayes'; mathgroup@smc.vnet.net So? It's just as it should be, isn't it? Andrzej Andrzej Kozlowski > Toyama International University > JAPAN > http://sigma.tuins.ac.jp/~andrzej/ > Go one step further: Clear[f, a, b, k] > k = $MachinePrecision; > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + > 5.5*b^8 + a/(2*b), k]; > a = 77617.; b = 33096.; > a = SetAccuracy[a, k]; > b = SetAccuracy[b, k]; > f > Accuracy[f] > Precision[f] -5.517164009`0*^19 Accuracy::mnprec:Value -23 would be inconsistent with $MinPrecision; > bounding by $MinPrecision instead. -20 0 Accuracy::mnprec:Value !(-23) would be inconsistent with > $MinPrecision; > bounding by $MinPrecision instead. See that? NO precision. Bobby -----Original Message----- > Sent: Tuesday, October 01, 2002 5:53 PM > Cc: drbob@bigfoot.com You are of course right, I forgot that Mathematica does not try to > keep precision or accuracy of machine arithmetic computations. But I think > the actual precision you set need not be higher than machine > precision, it just has to be set explicitely (is that right?). For example: In[1]:= > Clear[f,a,b,k] In[2]:= > k = $MachinePrecision; In[3]:= > f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; In[4]:= > a=77617.;b=33096.; In[5]:= > a=SetAccuracy[a,k]; In[6]:= > b=SetAccuracy[b,k]; > In[7]:= > f Out[7]= > !((-5.51716400890319`-2.8311*^19)) In[8]:= > Accuracy[f] Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; > > bounding by $MinPrecision instead. Out[8]= > -20 > Andrzej Andrzej Yes, like you I took the original question to be about how to get the result > of using the naive rational versions in place of the inexact numbers. > Bobby raises the question of how we might know accuracy of the > result. You answer this with > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 > > However this computation is done in machine arithmetic, which means > that > Mathematica keeps no check on the accuracy and precision of the > computation, > and Mathematica gives the default accuracy value without any real > signifcance: $MachinePrecision - Log[10,Abs[f]]//Round -5 To get meaningful accuracy and precision values we need to force the > computation to be in bignums (bigfloat, arbitrary precision) > arithmetic. > Mathematica then keeps track of the accuracy and precision that it > can > guarantee. Clear[f,a,b,k] > k=50; f=SetAccuracy[333.75*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.5*b^8+a/ > (2*b),k]; > a=77617.;b=33096.; > a=SetAccuracy[a,k]; > b=SetAccuracy[b,k]; > f -0.82739605995 Accuracy[f] 11 Precision[f] 11 Which tells us that the error in the computed value of f is not more than 10^-11 > The above results are rounded. More accurately we get Accuracy[f, Round->False] 11.4956 Precision[f, Round->False] 11.4133 There are several related issues here: > - is the precision (accuracy) of rhe input known? > - how does Mathematica interpret what one gives it? > - how does Mathematica go about the calculation? -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 message > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which > Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other > words, > it was why are the results of these two computations not the > same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that > its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything > wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually, we don't know whether SetAccuracy succeeds, because we > don't > know how inexact those numbers really are. If they are known to > more > digits than shown in the original post, they should be entered with as > much precision as they deserve. If not, there's no trick or > algorithm > that will give the result precision, because the value of f really > is > in the noise. That is, we have no idea what the value of f > should > be. Mathematica's failing is in returning a value without pointing out > that > it has no precision. Bobby -----Original Message----- > Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact > numbers > that occur have finite binary representations. If we change them > slightly to > avoid this then we have to use Rationalize: 1) Using SetAccuracy > > Clear[a,b,f] > f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > Infinity]; a=77617.1; > b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity]; f -1564032114908486835197494923989618867972540153873951942813115514949 > 3891236234 > 525007719168693704591197760187988046304361497869199129319625743010292 > 36 > 3 > 1246 > 75 / 108671061439707605510003578275547938881981431359756495796079898677435 > 72 > 8240 > 16 > 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10; > b=330961/10; > f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b) -(5954133808997234115690303589909929091649391296257/ > 41370125000000) 3) Using Rationalize Clear[a,b,f] > f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ > (2*b), > 0]; a=77617.1; > b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ > 41370125000000) > I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000 > -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > Well, first of of all, your using SetAccuracy and SetPrecision > does > nothing at all here, since they do not change the value of a or b. You > should use a = SetAccuracy[a, Infinity] etc. But even then you > won't > get the same answer as when you use exact numbers because of the > way > you evaluate f. Here is the order of evaluation that will give you the > same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* > b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.; > b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767 > -(-----) > 66192 Andrzej Kozlowski > Toyama International University > JAPAN > Could someone explain what is going on here, please? In[1]:= > a = 77617.; b = 33096.; In[2]:= > SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; > SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 > + > a/(2*b) In[5]:= > SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:= > f Out[6]= > -1.1805916207174113*^21 In[7]:= > a = 77617; b = 33096; In[8]:= > g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:= > g Out[9]= > -(54767/66192) In[10]:= > N[%] Out[10]= > -0.8273960599468214 > PK > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== >Many thanks to all who replied. > >The original problem was as follows: > >In a presentation I wish to use Plot to generate a sequence of frames and >then animate them. The problem is that the audience sees the animation >twice. Once when the frames are being generated and then again after I have >closed the group and double clicked on the top graphic. However, the first >showing during generation is enough (but uncontrolled). > >Is it possible to tidy up the generation of the graphic so that it becomes >the animation? >There were two main solutions which I now apply to my real problem and not >the simple, generic, problem in the original post. >The real problem was how to build up a probably density function (PDF) in >real time. In the examples below I redraw the PDF every time I add 10 >points. > >Initialise <<<<< JLink`; >wb=WeibullDistribution[2.101349094155377,22.58126779173235`]; >midpts=Table[i,{i,0.5,50,1}]; > >Solution from Omega Consulting > >GraphicCell[graphics_] := > Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics] > >Block[{$DisplayFunction=Identity, graphs}, > data={}; > graphs = > Table[data=Flatten[Join[data,RandomArray[wb,10]]]; > freq=BinCounts[data,{0,50,1}]; > GraphicCell[ > BarChart[Transpose[{freq,midpts}],ImageSize ->500] ], {500}]; > NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs,Closed]]]; > SelectionMove[EvaluationNotebook[], All, GeneratedCell]; > FrontEndExecute[{FrontEndToken[EvaluationNotebook[], > SelectionAnimate]}] > ] > >This solution works but it generates 500 frames and sometimes exceeds the >memory. >The paradigm here is generate all frames, then animate all frames. We >really need a loop that does: generate next frame, delete last frame, show next frame > >Is it possible to do this? Yes, however, I thought you didn't want to see the selection bar moving around during the animation. That's why I chose to generate the whole animation in one shot. Also, when you write the new cell over the old cell there is a flash between frames as the old frame is deleted. Here's an example of a frame-by-frame method. GraphicCell[graphics_] := Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics] CellPrint[Cell[,Graphics]]; Block[{$DisplayFunction=Identity}, Do[ SelectionMove[EvaluationNotebook[], All, GeneratedCell]; NotebookWrite[EvaluationNotebook[], GraphicCell[Plot[x y,{x,0,1}, PlotRange->{0,50}]]], {y,50} ] ] Also, if you add ShowCellBracket->False to GraphicCell and a Pause to the loop, then things get much better visually. -------------------------------------------------------------- Omega Consulting The final answer to your Mathematica needs Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html ==== I am trying to use FindRoot in mathematica 4.0 to find the zeros of a complex-valued function of one complex variable. In particular, I am looking for the one root with a positive imaginary part. I have a rough approximation for where the root should be, and this is good enough to give a reasonable guess. However, there are always two other roots near the one I want - one with 0 imaginary part and another with negative imag part. (For those who are interested, the zeros are the roots of the dispersion relation for a plasma interacting with a laser). Sometimes FindRoot picks up one of these instead of the one I want. So, I'd like to tell mathematica to look for a root only in a certain rectangular region of the complex plane. Well, if I could tell it, 'look for roots with imag. part > something', I'd be happy too. I tried specifying complex values for the start and stop points of an interval, hoping mathematica would interpret these as the corners of a rectangle. No such luck. Any help would be greatly appreciated. I'd also like to point out that this and other issues about complex roots are not clearly addressed in the built-in help files. ==== Just a shot: Try using the DampingFactor option to force FindRoot to take smaller steps. --- Selwyn Hollis ==== > > > I am trying to use FindRoot in mathematica 4.0 to find the zeros of a > complex-valued function of one complex variable. In particular, I am > looking for the one root with a positive imaginary part. I have a rough > approximation for where the root should be, and this is good enough to > give a reasonable guess. > > However, there are always two other roots near the one I want - one with > 0 imaginary part and another with negative imag part. (For those who > are interested, the zeros are the roots of the dispersion relation for a > plasma interacting with a laser). Sometimes FindRoot picks up one of > these instead of the one I want. > > So, I'd like to tell mathematica to look for a root only in a certain > rectangular region of the complex plane. Well, if I could tell it, > 'look for roots with imag. part > something', I'd be happy too. > > I tried specifying complex values for the start and stop points of an > interval, hoping mathematica would interpret these as the corners of a > rectangle. No such luck. > > Any help would be greatly appreciated. > > I'd also like to point out that this and other issues about complex > roots are not clearly addressed in the built-in help files. > I believe it is difficult to restrict FindRoot. Below are several suggestions. (1) You might try rigging the function, say with g[x_?NumberQ] := f[x] + If[Im[x]<=0,1000,0] (2) If you have version 4.2 a related approach would be to take advantage of constrained optimization and do NMinimize[{Re[f[x,y]]^2 + Im[f[x,y]]^2, rectangle range constraints}, {x,y}] or something along those lines. (3) If proximity of the other roots is the main problem it might be alleviated by rescaling your variable. (4) Alternatively you could write your function as a pair of real valued functions of two real valued arguments. Then you can use Interval to split the rectangle into parts, keeping subrectangles for which {0,0} lives in f[Interval[x],Interval[y]] where Interval[x], for example, is a shorthand for an interval for the x part of the rectangle being split. Daniel Lichtblau Wolfram Research Reply-To: kuska@informatik.uni-leipzig.de ==== and solving the real and imaginary part for for z->x+I*y with FindRoot[Evaluate[({Re[#] == 0, Im[#] == 0} &[ z^3 - 1]) /. z -> x + I y], {x, -3/2, 0}, {y, 0.5, 0.9}] helps not ? Jens > > > I am trying to use FindRoot in mathematica 4.0 to find the zeros of a > complex-valued function of one complex variable. In particular, I am > looking for the one root with a positive imaginary part. I have a rough > approximation for where the root should be, and this is good enough to > give a reasonable guess. > > However, there are always two other roots near the one I want - one with > 0 imaginary part and another with negative imag part. (For those who > are interested, the zeros are the roots of the dispersion relation for a > plasma interacting with a laser). Sometimes FindRoot picks up one of > these instead of the one I want. > > So, I'd like to tell mathematica to look for a root only in a certain > rectangular region of the complex plane. Well, if I could tell it, > 'look for roots with imag. part > something', I'd be happy too. > > I tried specifying complex values for the start and stop points of an > interval, hoping mathematica would interpret these as the corners of a > rectangle. No such luck. > > Any help would be greatly appreciated. > > I'd also like to point out that this and other issues about complex > roots are not clearly addressed in the built-in help files. > ==== The last part of my message you are quoting was completely wrong, as was pointed out by Allan Hayes. Mathematica does not track precision of machine arithmetic computations. In order for Mathematica to give reliable information about the precision of a computation you have to explicitly set the precision of all the numerical quantities. Your own example at the bottom simply shows you have not understood the evaluation mechanism of Mathematica. What you are doing is this: In[1]:= a = SetAccuracy[77617., Infinity]; b = SetAccuracy[33096., Infinity]; At this point you have converted a and be to have the following exact values: In[3]:= a Out[3]= 77617 In[4]:= b Out[4]= 33096 Next you evaluate: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity] but this is a two step process (which is what you seem not to have grasped). First Mathematica computes: In[5]:= 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) Out[5]= 1.1805916207174113*^21 Now, because there were machine floats in the formula (333.75 and 5.5 ) the whole expression was computed using machine arithmetic without keeping track of precision. The answer is therefore completely inacurate. Mathematica returns the purely formal accuracy: In[6]:= Accuracy[%] Out[6]= -5 But the second part of your evaluation tells it to take this inaccurate answer and convert it to an exact number. In[7]:= SetAccuracy[%%, Infinity] Out[7]= 1180591620717411303424 In[8]:= Accuracy[%] Out[8]= Infinity But of course doing this is meaningless, after converting an inexact answer to an exact number does not make it a an exact answer! Of course had you evaluated f before you assigned the values to a and b you would not have encountered the problem because no machine reals would have appeared in the computation. ALternatively you might have used: f = SetAccuracy[333.75, Infinity]*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + SetAccuracy[5.5, Infinity]*b^8 + a/(2*b) Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > It seems clear to me that what Allan and what you mean by succeeds > here refer to quite different things and your objection is therefore > beside the point. There are obviously two ways in which one can > interpret the original posting. The first interpretation, which Allan > and myself adopted, was that the question concerned purely the > computational mechanism of Mathematica. Or, to put it in other words, > it was why are the results of these two computations not the same?. > In this sense success means no more than making Mathematica return > the same answer using the two different routes the original poster > used. > You on the other hand choose to assume that the posting shows that its > author does not understand not just the mechanism of significance > arithmetic used by Mathematica but also computations with inexact > numbers in general. I do not think this is necessarily the correct > assumption. I also don't see that Mathematica is doing anything wrong. > After all, one can always check the accuracy of your answer: In[1]:= > a = 77617.; b = 33096.; In[2]:= > f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > 5.5*b^8 + a/(2*b) In[3]:= > f Out[3]= > -1.1805916207174113*^21 In[4]:= > Accuracy[%] Out[4]= > -5 which tells you that it can't be very reliable. What more do you > demand? > As you are dealing here only with machine-precision numbers, your When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine-Áçprecision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. In practice, to rely on a numerical result, you ALWAYS have to check > its accuracy. How reliable is Accuracy anyway? In[1]:= > a = SetAccuracy[77617., Infinity]; > b = SetAccuracy[33096., Infinity]; In[3]:= > f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b), Infinity] Out[3]= > 1180591620717411303424 In[4]:= > Accuracy[f] Out[4]= > Infinity We got completely wrong result with Infinite accuracy. In conclusion, > one can not rely on Accuracy. Checking numerical results in > Mathematica sounds like a tough task.:-) --PK Andrzej > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ [...] > ==== leap to MathGroup so I'll respond there as well to some of the issues raised herein. > > Daniel, > >>The precision/accuracy tracking mechanism will generally let you know, >>in some fashion, that you have no trustworthy digits. But it is up to >>the user to check that sort of thing. > > In this case Mathematica did NOT let us know, in any fashion, that we > had no trustworthy digits. Precision and Accuracy outputs were > completely misleading. (16 and -5 respectively.) Precision, in this case, is itself a bit misleading. As I recall machine arithmetic was in use. For that domain just regard 16 as the definition of precision. Moreover no tracking is done. It is only when bignums are used that significance arithmetic will be at play. By the way, the distinction between precision for machine numbers vs. bignums will be more clear with our next big release. At present one does not know if 16 refers to a machine number or a bignum of that same precision. > Even Andrzej > Kozlowski, who's adept in Mathematica, thought that would be meaningful, > and never came up with a better way to check (other than using infinite > precision for numbers that probably aren't known that exactly). Peter > Kosta demonstrated that he could get a completely erroneous answer with > Infinite precision. > > I blame the problem primarily, and I don't think there's any way to make > the answer meaningful. That's not Mathematica's fault at all, and users > need to be aware of that old maxim: garbage in, garbage out. Right. One cannot artificially raise precision or accuracy after the fact and expect a meaningful result. Again, had significance arithmetic been used, I think there would have been adequate information to assess the problem. > comes up with a 22-digit result, it doesn't take much sophistication to > realize the answer can't have 16-digit precision. > > Here's an even more extreme result: > > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 50]; > a = 77617.; b = 33096.; > f > Precision[f] > > -1.180591620717411303424`71.0721*^21 > 71 > > 71.0721 digits of precision? I don't think so!! It's correct, albeit the number is garbage. You start with a number that is, in your words, all noise. (I assume you had set a and b before f, because otherwise I get a different result for Precision[f]). Now f ~ 10^21, and so has accuracy of around 71 digits. Garbage notwithstanding, this behavior is entirely correct and as it should be. > We can do the following instead: > > x = Interval[333.75]; > y = Interval[5.5]; > a = Interval[77617.]; > b = Interval[33096.]; > x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b) > > Interval[{-4.486248158726164*^22, 4.2501298345826815*^22}] > > and that looks like the right answer, finally!! I like that method. Yes, it's a useful way to show that the result has no digits to trust. Actually you can achieve a similar effect using significance arithmetic, as below. x = SetPrecision[33375/100, 16]; y = SetPrecision[11/2, 16]; a = SetPrecision[77617, 16]; b = SetPrecision[33096, 16]; In[18]:= InputForm[x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b)] Out[18]//InputForm= -1.1339143158169`0*^14 This tells you there are NO reliable digits. The advantage to this is that is is more flexible than interval arithmetic in Mathematica which will not, for example, deal well with complex-valued functions or complex domains. Also significance arithmetic (aka arbitrary precision arithmetic) is much faster than interval arithmetic for large problems. > However, that doesn't change the fact that Accuracy, Precision, and > SetAccuracy appear to be completely useless. My own experience is that they are quite useful. But only if used with care and in appropriate ways. Raising accuracy after the fact does not fall into that category. > I haven't seen an example > in which they did what anyone (but you) thought they should do. > > Bobby Maybe. But, curiously enough, I am a user rather than developer when it comes to that stuff. I used the precision mechanism alot in polynomial NSolve, and it did indeed work to my liking. Which counts for something from the ordinary users' perspective, because now NSolve works better than it otherwise might. > -----Original Message----- > > > I think I'd prefer that Mathematica gave me a clue -- without being > asked explicitly in JUST the right way that only you know and had > forgotten -- that there's a precision problem. > > Oddly enough, when you DO ask it nicely, you get error messages, but > if > you're not aware there's a problem, it lets you go on your merry way, > working with noise. > > Bobby > > Mathematica is not a mind reader. But the evaluation sequence, while > complicated, is reasonably well documented. If you perform machine > arithmetic, or for that matter significance arithmetic, and there is > massive cancellation error, no use of SetAccuracy after the fact will > fix it. > > The precision/accuracy tracking mechanism will generally let you know, > in some fashion, that you have no trustworthy digits. But it is up to > the user to check that sort of thing. It is not obvious to me what sort > of error the software might notice to report. If you have a concise > example of input, and expected output, I can look further. I've not seen > anything in this thread that struck me as a failure of the software to > warn the user, but maybe I missed something. > > Daniel Daniel Lichtblau Wolfram Research ==== > > The more I play with the example the more depressing it gets. Start > with floating point numbers but explicitely arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine[CapitalEth]precision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers Mathematica should display > only those digits that are correct, that is none. No, 26 digits are correct (check Precision instead of Accuracy to see this). You appear to be showing output in InputForm. If you use OutputForm or StandardForm only 26 digits will be shown. 32 Out[3]= -4.7833916866605540257808360 10 InputForm is showing more because it exposes bad digits as well as good ones. > To relax a bit, set a new input cell to StandardForm and type > 77617.000000000000000000000000000000000 > > Convert it to InputForm. You get > 77616.999999999999999999999999999999999999999999952771`37.9031 > > Convert back to StandardForm > 77616.99999999999999999999999999999999999999999976637`37.9031 > > Again to InputForm > 77616.99999999999999999999999999999999999999999963735`37.9031 > > Back to StandardForm > 77616.99999999999999999999999999999999999999999951376`37.9031 > > See what you can get if you have enough patience or a small program. > > PK Agreed, it's not very pretty. I am uncertain as to whether this indicates a bug in StandardForm or elsewhere in the underlying numerics code, and will defer to our numerics experts on that issue. My guess is it is a bug if only because it violates the spirit of IEEE arithmetic wherein floats that have integer values should be representable as such (or something to that effect). I will point out, however, that the two numbers in question are equal to the specified precision. Also it appears to be improved in our development kernel. Daniel Lichtblau Wolfram Research ==== The more I play with the example the more depressing it gets. Start with floating point numbers but explicitely arbitrary-precision ones. In[1]:= a=77617.00000000000000000000000000000; b=33095.00000000000000000000000000000; In[3]:= !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 b^2 - b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + a/(2 b)) Out[3]= !((-4.78339168666055402578083604864320577443814`26.6715*^32)) In[4]:= Accuracy[%] Out[4]= -6 Due to the manual section 3.1.6: When you do calculations with arbitrary-precision numbers, as discussed in the previous section, Mathematica always keeps track of the precision of your results, and gives only those digits which are known to be correct, given the precision of your input. When you do calculations with machine-precision numbers, however, Mathematica always gives you a machine[CapitalEth]precision result, whether or not all the digits in the result can, in fact, be determined to be correct on the basis of your input. Because I started with arbitrary-precision numbers Mathematica should display only those digits that are correct, that is none. To relax a bit, set a new input cell to StandardForm and type 77617.000000000000000000000000000000000 Convert it to InputForm. You get 77616.999999999999999999999999999999999999999999952771`37.9031 Convert back to StandardForm 77616.99999999999999999999999999999999999999999976637`37.9031 Again to InputForm 77616.99999999999999999999999999999999999999999963735`37.9031 Back to StandardForm 77616.99999999999999999999999999999999999999999951376`37.9031 See what you can get if you have enough patience or a small program. PK ==== > The more I play with the example the more depressing it gets. Start > with floating point numbers but explicitely arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine[CapitalEth]precision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers Mathematica should display > only those digits that are correct, that is none. I retract the above comment. I did not notice that was an error in the input. b=33095.00000000000000000000000000000 intstead of intended b=33096.00000000000000000000000000000 I am sorry for the mistake. PK > > > To relax a bit, set a new input cell to StandardForm and type > 77617.000000000000000000000000000000000 > > Convert it to InputForm. You get > 77616.999999999999999999999999999999999999999999952771`37.9031 > > Convert back to StandardForm > 77616.99999999999999999999999999999999999999999976637`37.9031 > > Again to InputForm > 77616.99999999999999999999999999999999999999999963735`37.9031 > > Back to StandardForm > 77616.99999999999999999999999999999999999999999951376`37.9031 > > See what you can get if you have enough patience or a small program. > > PK ==== > The last part of my message you are quoting was completely wrong, as > was pointed out by Allan Hayes. Mathematica does not track precision of > machine arithmetic computations. In order for Mathematica to give > reliable information about the precision of a computation you have to > explicitly set the precision of all the numerical quantities. > > Your own example at the bottom simply shows you have not understood the > evaluation mechanism of Mathematica. Just opposite, thanks to you and other participants, I completely understood it. SetAccuracy just takes anything and calls it accurate. This behavior is useless if not stupid. It was apparently intended by Mathematica developers but that doesn't make it right. On a side note, I hate the argument It is descibed in the manual, therefore it is correct. Legal doesn't mean right. Besides there is no supreme court here to overrule some stupid law. :-) PK > > [...] ==== >Dear Colleagues, > >I calculated: > >Sum[1/Prime[n], {n, 15000}] // N > >Result: 2.74716 > >Now I wonder if this sum will converge or keep on growing, albeit very >slowly. >Matthias Bode >Sal. Oppenheim jr. & Cie. KGaA >Koenigsberger Strasse 29 >D-60487 Frankfurt am Main >GERMANY >Mobile: +49(0)172 6 74 95 77 >Internet: http://www.oppenheim.de > The serie is divergent! I suggest you to look at this beautiful introduction to primes distribution http://www.maths.ex.ac.uk/%7Emwatkins/zeta/vardi.html Bye, rob Roberto Brambilla CESI Via Rubattino 54 20134 Milano tel +39.02.2125.5875 fax +39.02.2125.5492 rlbrambilla@cesi.it ==== > I've been looking over the file and directory manipulation functions in Mathematica > 4.1, and I'm not finding good examples of how to test for the existence of > a file or directory before I attempt to create, access, or delete it. Are > there any good examples of this somewhere? STH Steven, Directory[] returns the current directory $Path returns the directories in your path where files can be found. SetDirectory[] changes to the specified directory and makes it the current directory. FileNames[] returns a list of all the file names (text documents, picture documents etc) and subdirectory (folder) names in the current directory. Since FileNames returns a list of elements, you can use all sorts of tests to see if a file you're looking for is in a said directory or not or whether it is a subdirectory or not. I hope that this will get you started. Yas ==== has anybody tried to modify the classes.m package in the way, it would be possible to have several superclasses? Oleg. ==== What does this page say, auf Englisch? I only pretend to understand German. http://www.mertig.com/neu/HTMLLinks/index_6.html STH ==== The sum diverges. See Elementary Number Theory, 5th edition by David M. Burton, pages 355-356. -----Original Message----- Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== Technical support has responded to my query. They say that one of the simplifications that Mathematica does when using Simplify is to Factor the expression, and factoring an expression consisting of inexact numbers leads to the type of behavior I observed. They stated that changing the behavior of Simplify to avoid the problems I noticed would make Simplify less capable, and that the majority of users would prefer to have Simplify behave the way it currently does. Of course, that doesn't answer the question about why the number of terms in the expression would cause the coefficients to go from rational to inexact to rational again. At any rate, I have another lesson learned. When using Simplify, check the result if you are mixing infinite precision and inexact numbers, as the result may not be what you wanted. In the past I always assumed that the result of using Simplify on an expression produced a result equivalent to the original expression, but now I discover that this is not true. Carl Woll Physics Dept U of Washington ----- Original Message ----- > {i, > n}]], x[1]] Now lets try CW for the first 100 values of n: > In[30]:= > Table[CW[n], {n, 100}] Out[30]= > {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, > 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, > 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, > 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, > 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, > 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, > 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, > 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, > 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, > 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423, > 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, > 1/2, 1/2, 1/2} In[31]:= Map[Length,Split[#]] Out[31]= > {12,43,45} This is indeed curious.The problem seems to occur for values between 13 > and 55 and then go away (for good???) At first I thought it maybe in > some fascinating way related to some properties of the integer n, but > now I am not sure. It certainly worth a careful examination. I hope > whoever discovers the cause of this will let us know. Andrzej Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > To Technical Support and the Mathematica User community, > > I'm writing to report what I consider to be a bug. First, I want to > show a > simplified example of the problem. Consider the following expression: > > expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; > > When simplified I expected to get some real number plus > x[0]+3x[1]/4+9x[2]/16, but instead I get the following: > > Simplify[expr] > 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] > > As you can see, for some reason Mathematica converted the fractions > 3/4 and > 9/16 to real machine numbers. I consider this to be a bug. > > Now, for an example more representative of the situation that I've been > coming across. > > expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}]; > expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}]; > expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}]; > > As you can see, I have replaced the real numbers by extended precision > numbers. The simplified example above demonstrates that the problem > exists > when using machine numbers. Now, we'll see what happens when we use > arbitrary precision numbers. First, let's simplify the expression with > 12 > terms. > > Simplify[expr12] > (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 > x[5] + > > 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) > / 4096 > > As you can see, a sum with 12 terms upon simplification has > coefficients > which are still integers as they should be. However, increasing the > number > of terms to 13 yields > > Simplify[expr13] > 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] + > > 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] + > > 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 > x[8] + > > 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 > x[11] > + > > 0.000244140625000 x[12] + 0.0001220703125000 x[13] > > Now, all of the coefficients are converted to real numbers, > replicating the > bug from the simplified example. Finally, let's see what happens when > we > have 55 terms. Rather than putting the resulting expression here, I > will > just leave it at the end of the post. The result though is somewhat > surprising. Each of the coefficients of the x[i] are again real > numbers, but > now their precision is only 0! The proper result of course is the sum > of > some real number (with a precision close to 0 due to numerical > cancellation) > and an expression consisting of rational numbers multiplied by x[i]. > The > loss of precision of the coefficients of the x[i] is precisely what > occurred > to me. Of course, in this simple example, simply using Expand instead > of > Simplify produces the expected result, and is my workaround. I hope you > agree with me that this is a bug, and one that Wolfram needs to > correct. > > Carl Woll > Physics Dept > U of Washington > > Simplify[expr55] > -16 -1 -1 -1 > 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10 > x[5] + > > -2 -2 -2 -3 -3 > 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10 > x[10] > + > > -3 -3 -4 -4 > -4 > 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10 > x[15] + > > -5 -5 -5 -6 > -6 > 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10 > x[20] + > > -6 -6 -7 -7 > -7 > 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10 > x[25] + > > -8 -8 -8 -9 > -9 > 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10 > x[30] + > > -9 -9 -10 -10 > 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] + > > -10 -11 -11 -11 > 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] + > > -12 -12 -12 -12 > 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] + > > -13 -13 -13 -14 > 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] + > > -14 -14 -15 -15 > 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] + > > -15 -15 -16 -16 > - > 16 > 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] + > 0. 10 > x[55] > ==== Dear Carl You have discovered what is perhaps a bug but maybe something even mor einteresting . However, I think you stopped your investigation a little prematurely. Here is a function that just computes the coefficient of x[1] in your Simplified expression for various values of n: CW[n_] := Coefficient[Simplify[1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, n}]], x[1]] Now lets try CW for the first 100 values of n: In[30]:= Table[CW[n], {n, 100}] Out[30]= {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423, 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2} In[31]:= Map[Length,Split[#]] Out[31]= {12,43,45} This is indeed curious.The problem seems to occur for values between 13 and 55 and then go away (for good???) At first I thought it maybe in some fascinating way related to some properties of the integer n, but now I am not sure. It certainly worth a careful examination. I hope whoever discovers the cause of this will let us know. Andrzej Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > To Technical Support and the Mathematica User community, I'm writing to report what I consider to be a bug. First, I want to > show a > simplified example of the problem. Consider the following expression: expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; When simplified I expected to get some real number plus > x[0]+3x[1]/4+9x[2]/16, but instead I get the following: Simplify[expr] > 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] As you can see, for some reason Mathematica converted the fractions > 3/4 and > 9/16 to real machine numbers. I consider this to be a bug. Now, for an example more representative of the situation that I've been > coming across. expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}]; > expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}]; > expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}]; As you can see, I have replaced the real numbers by extended precision > numbers. The simplified example above demonstrates that the problem > exists > when using machine numbers. Now, we'll see what happens when we use > arbitrary precision numbers. First, let's simplify the expression with > 12 > terms. Simplify[expr12] > (1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 > x[5] + 64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) > / 4096 As you can see, a sum with 12 terms upon simplification has > coefficients > which are still integers as they should be. However, increasing the > number > of terms to 13 yields Simplify[expr13] > 0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] + 0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] + 0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 > x[8] + 0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 > x[11] > + 0.000244140625000 x[12] + 0.0001220703125000 x[13] Now, all of the coefficients are converted to real numbers, > replicating the > bug from the simplified example. Finally, let's see what happens when > we > have 55 terms. Rather than putting the resulting expression here, I > will > just leave it at the end of the post. The result though is somewhat > surprising. Each of the coefficients of the x[i] are again real > numbers, but > now their precision is only 0! The proper result of course is the sum > of > some real number (with a precision close to 0 due to numerical > cancellation) > and an expression consisting of rational numbers multiplied by x[i]. > The > loss of precision of the coefficients of the x[i] is precisely what > occurred > to me. Of course, in this simple example, simply using Expand instead > of > Simplify produces the expected result, and is my workaround. I hope you > agree with me that this is a bug, and one that Wolfram needs to > correct. Carl Woll > Physics Dept > U of Washington Simplify[expr55] > -16 -1 -1 -1 > 0. 10 + 0. x[1] + 0. x[2] + 0. 10 x[3] + 0. 10 x[4] + 0. 10 > x[5] + -2 -2 -2 -3 -3 > 0. 10 x[6] + 0. 10 x[7] + 0. 10 x[8] + 0. 10 x[9] + 0. 10 > x[10] > + > > -3 -3 -4 -4 > -4 > 0. 10 x[11] + 0. 10 x[12] + 0. 10 x[13] + 0. 10 x[14] + 0. 10 > x[15] + -5 -5 -5 -6 > -6 > 0. 10 x[16] + 0. 10 x[17] + 0. 10 x[18] + 0. 10 x[19] + 0. 10 > x[20] + -6 -6 -7 -7 > -7 > 0. 10 x[21] + 0. 10 x[22] + 0. 10 x[23] + 0. 10 x[24] + 0. 10 > x[25] + -8 -8 -8 -9 > -9 > 0. 10 x[26] + 0. 10 x[27] + 0. 10 x[28] + 0. 10 x[29] + 0. 10 > x[30] + -9 -9 -10 -10 > 0. 10 x[31] + 0. 10 x[32] + 0. 10 x[33] + 0. 10 x[34] + -10 -11 -11 -11 > 0. 10 x[35] + 0. 10 x[36] + 0. 10 x[37] + 0. 10 x[38] + -12 -12 -12 -12 > 0. 10 x[39] + 0. 10 x[40] + 0. 10 x[41] + 0. 10 x[42] + -13 -13 -13 -14 > 0. 10 x[43] + 0. 10 x[44] + 0. 10 x[45] + 0. 10 x[46] + -14 -14 -15 -15 > 0. 10 x[47] + 0. 10 x[48] + 0. 10 x[49] + 0. 10 x[50] + -15 -15 -16 -16 > - > 16 > 0. 10 x[51] + 0. 10 x[52] + 0. 10 x[53] + 0. 10 x[54] + > 0. 10 > x[55] > ==== I think, for input of that many numbers (and other inputs), I might use an input file that has textual names or descriptions in the first ten or twenty columns, followed by values starting at a fixed column after that. Mathematica or Java could easily read inputs from that, and a human could read it as well. If you're concerned that a human might jumble the file format -- accidentally deleting lines, etc. -- a program could key on the names or descriptions rather than trusting them to be in correct order, and point out missing values. A strategy like that allows you to start with a previous input file (not from scratch) and change only what needs to change. Also, Mathematica 4.2 adds XML support to the picture, and that might be useful. Bobby -----Original Message----- > I agree with Mr. Kuska, that the system Mr Nagesh describes is not > userfriendly. But I think, the suggestions of Mr. Kuska do not make it more > userfriendly, rather the opposite is true. > > Mr. Nagesh asks > > Is any body here have expertise or information about the capability of > Mathematica as a system simulation tool? > Mr. Kuska answers: > Since the most system simulation tools are simply solving a system of > ordinary differntial equations it is simple to do this with NDSolve[]. > > My comment: > > That is: He sees the simulation system merely as a set of differential > equations. hmm, since the original poster write My refrigeration system simulation package is likely to have > approximately 60 First order Differential equations. it seems not completly wrong to assume that the system consists of > of ode's .. > Yout should not ignore the word merely. It is not enough to have a set 60 differential equations and a set of 200-250 numbers. That is not simulation system, which can be used by users with the exception, perhaps, of the programmer of the system himself. How does e.g. the user know what meaning a number in the set has, ought he count the numbers from the beginning? Your nice command shows only, if there is an input, which is not a number. But I think the user would like to know, which of the 200 elements are not numbers. The only good of your command is, that it looks nice and shows your knowledge! > > The question of Mr. Nagesh: > > My 4th Objective:- How can I program the check for correctness of the > input values supplied by the package user ? > The answer of Mr. Kuska is: > And @@ (NumericQ /@ {aListOfAllYourNumericParameters}) > > My comment: > > This is a nice command and shows the knowledge of Mr.Kuska. But does Mr. > Nagesh understand it and is it sufficient to check, if all inputs are > numerical? It seems you have a deeper knowlege about the things that Mr. Nagesh > understand. You know him personally ? It is not very polite to > make speculations *what* a other person understand. And no it is not sufficent to check that all parameters are numbers. > Typical paramters described by intervals, where the assumptions of > a model are valid. But for this checks one needs more knowlege > about the meaning of the parameters. And one needs the knowlege about > the differntial equations, to find out the eigenvalues of the jacobian > ... > Additionally I think, it is not userfriendly to see the input merely as a > set of 200-250 numbers. > > My suggestion is, that JLink is used, a suggestion Mr. Kusk takes into > consideration, too. That will be fast as lightning ! > But further I suggest, that classes are defined in Java, which represent the > parts of the system. That is notable nonsense! When the differntial equations should be > solved with Mathematica, the parts can't be Java classes. Mathematica's > NDSolve[] need a explicit expression to integrate the equations. That's not nonsense, the Mathematica program does not fetch the classes but the numbers in the classes (or better in the objects). in the Java classes in textform. They can then be fetched from the Mathematica program and transformed into expressions by the Command ToExpression. The aim is, to have a clear separation of the system into components, which are manageable and understandable. OK you can call a Java class member from Mathematica but this will > be incredible slow when the right hand side is evaluated 200-300 > times and every evaluation make several callbacks to the Java source. > Event handler of the Java main program (without some modification in > the event loop) while it is evaluating an other command. My idea is to fetch the values once from the Java objects at the beginning. 200-250 numbers is not so much.. > Constructors of the classes should build objects with default values. That's a great idea. If a simulation run should be documented, one > always > need the full listing of the Java source to find the actual parameter > settings. That is not my opinion. I think not every user of the simulation system should have to know Java and Mathematica. The user must look for the values in the objects. And the values are in the objects, if they come from the constructor or from the graphical user interface. I think, there should be listings of the objects including names of the variables. In the objects the values are in an meaningful environment. > Graphical user interfaces > should give the opportunity to change the data fields in the objects and > check the input for correctness. *and* what has a GUI for 200-250 variables to do with Mathematica ? > BTW one has typical much less variables because many parameters > are fixed and it make no sense to change, for example, material > constants of materials that can't exchanged > The system should give the opportunity, to store the objects on harddisk > (serialization). > > accessed directly. > > Can you be so kind, to explain *how* your posting help a person that > ask How can I build a simulation system with Mathematica ? You *can* say Don't use Mathematica, use Java! but this has nothing > to do with the question or with my reply. It is you, who proposes to solve the problem with C/C++ and not to use Mathematica (see below!) My point of view is: Use Mathematica, for what Mathemtica is good, and Java, for what Java is good. Mathematica is not so good as Java for data entry and Java is better than Mathematica to represent the simulation system (by objects). But I still would suggest to use C/C++ and a numerical > ode-solver, make a fancy GUI/Script > interface and don't use Mathematica for such a simple task. > The ode-solver is the smallest part of such a simulation system. Jens > > > > My name is Nagesh and pursuing research studies in Refrigeration. At > present I am writing a Dynamic Refrigeration System Simulation Package. > I > am using Mathematica as a programming language for the same since last > one > year. I don't have any programming experience before this. I have > following > querries:- > 1. Is any body here have expertise or information about the capability > of > Mathematica as a system simulation tool? > > Since the most system simulation tools are simply solving a system of > ordinary differntial equations it is simple to do this with NDSolve[]. > > 2. Is is possible to program a user friendly interface for my system > simulation package with Mathematica or I have to use some other > software? > > Write a MathLink or J/Link frontend that launch the kernel. But you > should keep > in mind that the user interface is typical 80-90 % of your code. > If you just whant to solve some ode's it is probably easyer to > include one of the excelent ode-solvers from netlib in your C-code > than to call Mathematica to do that. As long as you dont wish to change > the ode's very often (than Mathematica is more flexible) you should > not use Mathematica. > > 3. My refrigeration system simulation package is likely to have > approximately 60 First order Differential equations. Is is possible to > solve these in Mathematica ? > > Sure. > If yes then can anybody here guide me about > this further. > > Write down the equations and call NDSolve[]. > > > I am explaining below in short about the objectives I want to fulfill > from > coding out of my main input file > > 1. Example from Main Input File ( this will contain about 200-250 > variables > which will be entered by the user of this package) > > This sounds like a *very* userfiendly interface ;-) > > > Below is examples of two variables entered into this file, which will be > used in other analysis files for further evaluation. > > 2. Example from other analysis file ( there will be about 20-25 other > such > component analysis files ) where the above mentioned variables from main > input file will be used for further evaluations:- > > Below is one example from this file explaining how the variables from > main > input file will be used in other files. > > I hope that this short information will be useful for guiding me to > solve > the following problems that I am facing. I am facing follwing problems > or > objectives:- > > 1. My 1st Objective:- The user of this package must be able to change > only > the value of the variable in the main input file but he must not be able > to > change the name of the variable itself. For example he must be able to > change the value of the variable but he must not be able to change > the > name of this variable itself. > Here our problem is how to achieve or program it so that our objective > will > be fullfilled. > > Options with defaulf values ? or something like > > {aParam,bParam}={ODEParameter1,ODEParameter2} /. > userRules /. > {ODEParameter1->1,ODEParameter2->2} > > > 2. My 2nd Objective:- How I can program the main input file so that it > will > be user friendly in terms of its visuals and satisfying the constraint > mentioned above in objective1. > > What is *userfiendly* in a file with 250 variables ??? > > > 3. My 3rd Objective:- How can I program the optional values for each > variable in the main input file ? so that there will be always a value > assigned to each variable listed in main input file whenever the user > opens > up this file. If user want to change the values of some variables then > he > can change them and run the simulation otherwise the simulation run will > be > done with optional values assigned to each variable in the input file. > > See above. > > > 4. My 4th Objective:- How can I program the check for correctness of the > input values supplied by the package user ? > > And @@ (NumericQ /@ {aListOfAllYourNumericParameters}) > > > Jens > ==== hi > AFAIK, Mac OS is now BSD or something like that. That makes it almost > certain that it could support QT. As I pointed out in another post, I can > run the KDE on Windows XP. I haven't been in the trenches with the Qt > impression is, it really is 'code once, run everywhere'. i've checked the trolltech hp. qt fully supports the following OS: MS Windows 95/98/Me, NT4, 2000 and XP. Mac OS X. > This is one of the reasons I am such a Mozilla fan. Konqueror works quite > like. But Mozilla runs everywhere with more or less a uniform look and > feel. Yes, Mozilla is written with Gtk and not with Qt, but that just > shows that WRI has options. i'm not sure if it is allowed to create a closed-source product like the mathematica fronend based on a gpl'ed library like gtk. with qt you have the possibility to buy licenses for the commercial version of qt, allowing you to create closed-source apps. > I'm a KDE fan. I've used the KDE since it was in alpha 0.4. I remember > back when it would compile in a few minutes on a pentium II. Now it takes > several hours on a P4. i started with beta1 (if i remember correctly) - sure it is really big now, but i think kde is still far away from being bloated..... imagine the mathematica frontend being seamlessly integrated into the linux ui's look and feel.... > I've always hated motif. The file chooser simply stinks. And that's just a > start. the whole motif ui stinks....:-) gerald ************************************* Gerald Roth M@th Desktop Development ************************************* ==== > hi, > > moving the frontend over to QT would have some neat side effects: > consistent look & feel with the modern linux gui, themeability, source > antialiased > truetype fonts as QT supports Xrender and Xft (looks great - see KDE3). i > think all of those points are of value, but the most important might be > source compatibility. ONE frontend for MOST (or ALL) platforms - sounds > like a dream :-)) AFAIK, Mac OS is now BSD or something like that. That makes it almost certain that it could support QT. As I pointed out in another post, I can run the KDE on Windows XP. I haven't been in the trenches with the Qt impression is, it really is 'code once, run everywhere'. This is one of the reasons I am such a Mozilla fan. Konqueror works quite like. But Mozilla runs everywhere with more or less a uniform look and feel. Yes, Mozilla is written with Gtk and not with Qt, but that just shows that WRI has options. I'm a KDE fan. I've used the KDE since it was in alpha 0.4. I remember back when it would compile in a few minutes on a pentium II. Now it takes several hours on a P4. But if WRI wanted to go the Gtk route, they could achieve the same ends. I've always hated motif. The file chooser simply stinks. And that's just a start. > > gerald > STH ==== Can I solve this inequality with Mathematica? Log[x,a]+Log[a x,a]>0 I've tried all know, but I get get any good result. CeZaR ==== > > First thanks to all, and in particular Bobby Treat, for your help with > this question. > > The best solution was as follows: > > lst = ReadList[c:data.txt, {Number, Number}] > adjacenceMatrix[ > x:{{_, _}..}] := Module[{actors, events}, > {actors, events} = Union /@ Transpose[x]; > Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , > {Length[actors], Length[events]}]] > > a = adjacenceMatrix[lst]; > b = a . Transpose[a]; > c = b (1 - IdentityMatrix[Length[b]]) > > C is the desired symmetric matrix with off diagonal values of >=0, > indicating the number of times two actors participate in the same event. > The diagonal is set to 0. > > A few items in response to Bobby's message, below. While c is, in fact, > a huge matrix with lots of cells equal to zero, that is exactly how we > need it structured for our analysis and research question (not relevant > to the list, but I'd be happy to discuss off list). Processing time is > actually not too bad!! I'm running a PIII 900 with 512 SDRAM, and the > code ran a 177 x 3669 matrix in under 90 seconds. MatrixForm [c] > presented no problems in viewing in the front end, but then it's only > 177 x 177. > > > Tom > > ********************************************** > Thomas P. Moliterno > Graduate School of Management > University of California, Irvine > tmoliter@uci.edu > ********************************************** > [...] There are several ways to go about this and which is best will vary based on relative number of events vs. number of actors. Below I show three variations. The first is a minor recoding of the one above. The second iterates over all pairs of actors. The third looks at all events for common actors. I then show three examples. The first two methods have the advantage that they do not require that events be positive integers. With some extra work the third method could also get around this restriction. toAdjacency0[data:{{_, _}..}] := Module[ {actors, events, mat1, mat2}, {actors, events} = Union /@ Transpose[data]; mat1 = Array[If[MemberQ[data, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]; mat2 = mat1 . Transpose[mat1]; mat2 * (1-IdentityMatrix[Length[mat2]]) ] toAdjacency1[origdata_] := Module[ {data=Union[origdata], mat}, data = Map[Last, Split[data,#1[[1]]===#2[[1]]&], {2}]; mat = Table [If [j>k, Length[Intersection[data[[j]],data[[k]]]], 0], {j,Length[data]}, {k,Length[data]}]; mat+Transpose[mat] ] toAdjacency2[origdata_] := Module[ {data=Sort[Map[Reverse,Union[origdata]]], mat, len, event}, data = Map[Last, Split[data,#1[[1]]===#2[[1]]&], {2}]; dim = Length[Union[Flatten[data]]]; len = Length[data]; mat = Table[0, {dim}, {dim}]; Do [ event = data[[j]]; Do [ Do [ mat[[event[[m]],event[[k]]]] += 1; mat[[event[[k]],event[[m]]]] += 1, {m,k-1}], {k,Length[event]}], {j,len}]; mat ] data1 = Table[{Random[Integer,{1,1000}], Random[Integer,50]}, {10000}]; data2 = Table[{Random[Integer,{1,1000}], Random[Integer,100]}, {10000}]; data3 = Table[{Random[Integer,{1,1000}], Random[Integer,200]}, {10000}]; Timings are on a 1.5 GHz machine running the Mathematica 4.2 kernel In[107]:= Timing[m0 = toAdjacency0[data1];] Out[107]= {5.44 Second, Null} In[108]:= Timing[m1 = toAdjacency1[data1];] Out[108]= {10.5 Second, Null} In[109]:= Timing[m2 = toAdjacency2[data1];] Out[109]= {16.24 Second, Null} In[110]:= m0 === m1 === m2 Out[110]= True Note that for this example the result is not terrible sparse (less than 20%). In[112]:= Count[Flatten[m0], 0] Out[112]= 191374 In[115]:= Timing[m0 = toAdjacency0[data2];] Out[115]= {11.51 Second, Null} In[116]:= Timing[m1 = toAdjacency1[data2];] Out[116]= {10.92 Second, Null} In[117]:= Timing[m2 = toAdjacency2[data2];] Out[117]= {9.07 Second, Null} Curiously this was the first example I tried, and all three methods perform about the same in this case. The result, not suprisingly, is more sparse (40%) because we have the same number of actors and pairs as previously, but now with more events to spread out over the pairs. In[118]:= Count[Flatten[m0], 0] Out[118]= 403232 When we get sparser still, the third method begins to dominate and the first is relatively slower. In[119]:= Timing[m0 = toAdjacency0[data3];] Out[119]= {22.73 Second, Null} In[120]:= Timing[m1 = toAdjacency1[data3];] Out[120]= {10.88 Second, Null} In[121]:= Timing[m2 = toAdjacency2[data3];] Out[121]= {4.96 Second, Null} Now sparsity is over 60%. In[122]:= Count[Flatten[m0], 0] Out[122]= 624350 The relative speed of this last method, in this instance, is derived from the fact that individual event lists are on average half the size of the previous case. Hence the main loop is expected to improve on average by a factor of 2 (you get a factor of 4 for iterating over all pairs in each event, but lose a factor of 2 because there are twice as many event lists). My guess is that a preprocessor that assesses number of actors vs. number of events would be the best way to choose between the first and third methods (which, inexplicably, are labelled as methods 0 and 2). It is not clear to me whether the middle approach will ever dominate. I have not given much thought to concocting examples where it would because offhand I suspect they would be pathological as in dense and with large intersections. As a last remark I'll note that these might run significantly faster if coded with Compile. Whether that is viable depends on the form of the data. In the above example where everything is a machine integer that approach would certainly work. Daniel Lichtblau Wolfram Research ==== First thanks to all, and in particular Bobby Treat, for your help with this question. The best solution was as follows: lst = ReadList[c:data.txt, {Number, Number}] adjacenceMatrix[ x:{{_, _}..}] := Module[{actors, events}, {actors, events} = Union /@ Transpose[x]; Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]] a = adjacenceMatrix[lst]; b = a . Transpose[a]; c = b (1 - IdentityMatrix[Length[b]]) C is the desired symmetric matrix with off diagonal values of >=0, indicating the number of times two actors participate in the same event. The diagonal is set to 0. A few items in response to Bobby's message, below. While c is, in fact, a huge matrix with lots of cells equal to zero, that is exactly how we need it structured for our analysis and research question (not relevant to the list, but I'd be happy to discuss off list). Processing time is actually not too bad!! I'm running a PIII 900 with 512 SDRAM, and the code ran a 177 x 3669 matrix in under 90 seconds. MatrixForm [c] presented no problems in viewing in the front end, but then it's only 177 x 177. Tom ********************************************** Thomas P. Moliterno Graduate School of Management University of California, Irvine tmoliter@uci.edu ********************************************** -----Original Message----- columns will be numbered from 1 to the number of observed actors or events, and will correspond to actors and events in sorted order. That said, you're asking for a VERY large matrix, and most of its entries will be zero. I'll suggest another way, later. The following indicates AT MOST 13.4% of the entries could be non-zero: lst = ReadList[moliterno-test1996.txt, {Number, Number}]; {actors, events} = Union /@ Transpose[lst]; N[Length[lst]/(Length[actors]*Length[actors])] 0.13350994338800987 However, a random sample shows that less than 1% will be non-zero: Timing[ Count[(MemberQ[lst, {actors[[Random[Integer, Length[actors]]]], events[[Random[Integer, Length[events]]]]}] & ) /@ Range[10000], True]/ 10000.] {7.515999999999998*Second, 0.008} Nevertheless, the following code should build the matrices you want. I'm using a 2.2GHz P4 and 1024MB RDRAM, so if you have a slower machine, be warned. adjacenceMatrix[ x:{{_, _}..}] := Module[{actors, events}, {actors, events} = Union /@ Transpose[x]; Array[If[MemberQ[x, {actors[[#1]], events[[#2]]}], 1, 0] & , {Length[actors], Length[events]}]] Timing[a = adjacenceMatrix[lst]; ] Dimensions[a] {5.671999999999997*Second, Null} {166, 1778} Timing[b = a . Transpose[a]; ] {0.5309999999999988*Second, Null} You don't want to display a or b in MatrixForm. It will crash your anything at all from the result, and use something like b[[Range[20],Range[4]]]//MatrixForm {{47, 0, 0, 0}, {0, 3, 0, 0}, {0, 0, 7, 1}, {0, 0, 1, 59}, {0, 0, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 0, 0, 1}, {0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}} to get a glimpse at some of it. It's the 'a' matrix that's terribly sparse -- the 'b' matrix isn't unreasonable. Elements of the 'a' matrix can be quickly computed by the function aFunction = If[MemberQ[lst, {actors[[#1]], events[[#2]]}], 1, 0] &; That stores a line of code rather than all those ones and zeroes. The b matrix (call it bb this time) can be computed as: Timing[bb = (#1 . Transpose[#1] & ) [Array[aFunction, {Length[actors], Length[events]}]]; ] bb == b {6.1569999999999965*Second, Null} True Bobby Treat -----Original Message----- posting a this was the most helpful solution message to the list, but first I hoped to ask you a follow up question, if I may (and I'll capture your off-line response here in my final posting to the list). I've run the code (copied from you) below, and get the correct output for made-up data, but when I import in real data, I get an error message. Here's the input I'm running: lst = ReadList[c:test1996.txt, {Number, Number}] AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj] MatrixForm[a = AdjacenceMatrix[lst]] MatrixForm[b = a.Transpose[a]] And here's what I get for output: Set::partw : Part 300007 of <<1> does not exist. Set::partw : Part 300007 of <<1> does not exist. Set::partw : Part 300007 of <<1> does not exist. General::stop : Further output of Set::partw will be suppressed during this calculation. Then I get the two matrices (a & b as per your code), but they are just filled with zeros. So it gets to about the 4th line of your code, but then doesn't fill-in from my data. Finally, I should note that 30007 is one of the actors in the data that I've read in. In case you want to run this yourself, I've attached the raw data file. There are 166 actors and 1778 events: both actors and events are coded with 6-digit numbers, actors begin with 3's, events with 2's. I'm sure this is a silly question, and that there is an easy answer ... But I sure can't find it. So I really appreciate your help and interest!!!! Tom ********************************************** Thomas P. Moliterno Graduate School of Management University of California, Irvine tmoliter@uci.edu ********************************************** -----Original Message----- If you multiply it by its transpose, you get something else that's useful: lst = {{1, A}, {1, B}, {2, B}, {3, C}, {3, D}, {1, D}, {1, C}}; AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj] MatrixForm[a = AdjacenceMatrix[lst]] MatrixForm[b = a.Transpose[a]] Matrix 'b' records how many events two actors have in common. On the diagonal, it shows the total number of events each actor is connected to. It's easy to put zeroes on the diagonal: MatrixForm[c = b (1 - IdentityMatrix[Length[b]])] To get the originally intended incidence matrix, this works: d = c /. {_?Positive -> 1} However, I think matrices 'a' and 'b' are actually more useful, and 'a' easily leads to all the others. Bobby -----Original Message----- AdjacenceMatrix[lst : {{_, _} ..}] := Module[ {actors,events adj}, {events, actors} = Union /@ Transpose[lst]; adj = Table[0, {Length[events]}, {Length[actors]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, actors]]; adj ] you get In[]:=AdjacenceMatrix[lst] Out[]={{1, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}} Jens > > I need to create an adjacency matrix from my data, which is currently in > the form of a .txt file and is basically a two column incidence list. > For example: > > 1 A > 1 B > 2 B > 3 C > . . > . . > . . > m n > > Where 1 to m represent actors and A to n represent events. My goal is to > have an (m x m) matrix where cell i,j equals 1 if two actors are > incident to the same event (in the sample above, 1 and 2 are both > incident to B) and 0 otherwise (w/ zeros on the diagonal). > > I'm new to Mathmatica, and so I'm on the steep part of the learning > curve ... All I've been able to figure out so far is how to get my > incidence list into the program using Import[filename.txt]. But then > what? How do I convert to the adjacency matrix? I've found the > ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't > seem to get it to work ... > > > Tom > > ********************************************** > Thomas P. Moliterno > Graduate School of Management > University of California, Irvine > tmoliter@uci.edu > ********************************************** ==== These are working for me. If anybody wants to try this modified keymapping http://66.92.149.152/proprietary/com/wri/proprietary/com/wri/ch05.html http://public.globalsymmetry.com/proprietary/com/wri/KeyEventTranslations.tr .txt STH ==== > These are working for me. If anybody wants to try this modified > keymapping > > http://66.92.149.152/proprietary/com/wri/proprietary/com/wri/ch05.html > http://public.globalsymmetry.com/proprietary/com/wri/KeyEventTranslations.tr .txt > > STH I found a bug in my hack of the KeyEventTranslations.tr file which didn't manifest itself in 4.1, but did in 4.2. I had a trailing ',' which was causing Mathematica to hang on startup after the chched KeyEventTranslations.m was created (second launch with the buggy file.) I also discovered that the file I was trying to share had been chmod'ed to 400. I am not sure if that is a daemon running, or scp which did it. It's open now, and I'll keep an eye on it. I'm attaching it as well, just in case. I put it here on my box: ~/.Mathematica/SystemFiles/FrontEnd/TextResources STH @@resource KeyEventTranslations (* Modifiers can be Shift, Control, Command, Option For Macintosh: Command = Command Key, Option = Option Key For X11: Command = Mod1, Option = Mod2 For Windows: Command = Alt, Option = Alt NOTE: I Hacked this for my purposes. I find it more natural. There may be problems. It comes with all the warranty that GNU software does. *) EventTranslations[{ (* Evaluation *) Item[KeyEvent[Enter], EvaluateCells], Item[KeyEvent[KeypadEnter], EvaluateCells], Item[KeyEvent[Return, Modifiers -> {Shift}], EvaluateCells], Item[KeyEvent[KP_Enter], EvaluateCells], Item[KeyEvent[KeypadEnter, Modifiers -> {Shift}], EvaluateNextCell], Item[KeyEvent[KP_Enter, Modifiers -> {Shift}], EvaluateNextCell], Item[KeyEvent[Enter, Modifiers -> {Shift}], EvaluateNextCell], Item[KeyEvent[Return, Modifiers -> {Command}], Evaluate[All]], Item[KeyEvent[Return, Modifiers -> {Option}], SimilarCellBelow], Item[KeyEvent[Escape], ShortNameDelimiter], (* Cursor control *) Item[KeyEvent[Up], MovePreviousLine], Item[KeyEvent[Down], MoveNextLine], Item[KeyEvent[Left], MovePrevious], Item[KeyEvent[Right], MoveNext], Item[KeyEvent[Up, Modifiers -> {Option}], MovePreviousLine], Item[KeyEvent[Down, Modifiers -> {Option}], MoveNextLine], Item[KeyEvent[Right, Modifiers -> {Option}], MoveNextWord], Item[KeyEvent[Left, Modifiers -> {Option}], MovePreviousWord], Item[KeyEvent[Right, Modifiers->{Control}], MoveNextWord], Item[KeyEvent[Left, Modifiers->{Control}], MovePreviousWord], Item[KeyEvent[End], MoveLineEnd], Item[KeyEvent[Home], MoveLineBeginning], (* Selection *) Item[KeyEvent[Right, Modifiers -> {Shift}], SelectNext], Item[KeyEvent[Left, Modifiers -> {Shift}], SelectPrevious], Item[KeyEvent[Right, Modifiers -> {Control, Shift}], SelectNextWord], Item[KeyEvent[Left, Modifiers -> {Control, Shift}], SelectPreviousWord], Item[KeyEvent[Down, Modifiers -> {Shift}], SelectNextLine], Item[KeyEvent[Up, Modifiers -> {Shift}], SelectPreviousLine], Item[KeyEvent[Home, Modifiers -> {Shift}], SelectLineBeginning], Item[KeyEvent[End, Modifiers -> {Shift}], SelectLineEnd], Item[KeyEvent[., Modifiers -> {Control}], ExpandSelection], (* Notebook window control *) Item[KeyEvent[PageUp], ScrollPageUp], Item[KeyEvent[PageDown], ScrollPageDown], Item[KeyEvent[Prior], ScrollPageUp], Item[KeyEvent[Next], ScrollPageDown], Item[KeyEvent[Home, Modifiers -> {Control}], ScrollNotebookStart], Item[KeyEvent[End, Modifiers -> {Control}], ScrollNotebookEnd], (* Input *) Item[KeyEvent[Return], Linebreak], Item[KeyEvent[Tab], Tab], Item[KeyEvent[i, Modifiers -> {Control}], Tab], Item[KeyEvent[Backspace], DeletePrevious], Item[KeyEvent[Delete], DeleteNext], Item[KeyEvent[ForwardDelete], DeleteNext], (* Typesetting input *) Item[KeyEvent[6, Modifiers -> {Control}], Superscript], Item[KeyEvent[Keypad6, Modifiers -> {Control}], Superscript], Item[KeyEvent[^, Modifiers -> {Control}], Superscript], Item[KeyEvent[-, Modifiers -> {Control}], Subscript], Item[KeyEvent[_, Modifiers ->{Control}], Subscript], Item[KeyEvent[/, Modifiers -> {Control}], Fraction], Item[KeyEvent[KP_Divide, Modifiers -> {Control}], Fraction], Item[KeyEvent[2, Modifiers -> {Control}], Radical], Item[KeyEvent[Keypad2, Modifiers -> {Control}], Radical], Item[KeyEvent[@, Modifiers -> {Control}], Radical], Item[KeyEvent[7, Modifiers -> {Control}], Above], Item[KeyEvent[&, Modifiers -> {Control}], Above], Item[KeyEvent[Keypad7, Modifiers -> {Control}], Above], Item[KeyEvent[=, Modifiers -> {Control}], Below], Item[KeyEvent[+, Modifiers -> {Control}], Below], Item[KeyEvent[,, Modifiers -> {Control}], NewColumn], Item[KeyEvent[Return, Modifiers -> {Control}], NewRow], Item[KeyEvent[9, Modifiers -> {Control}], CreateInlineCell], Item[KeyEvent[(, Modifiers -> {Control}], CreateInlineCell], Item[KeyEvent[Keypad9, Modifiers -> {Control}], CreateInlineCell], Item[KeyEvent[), Modifiers -> {Control}], MoveNextCell], Item[KeyEvent[0, Modifiers -> {Control}], MoveNextCell], Item[KeyEvent[Keypad0, Modifiers -> {Control}], MoveNextCell], Item[KeyEvent[Left, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeLeft], Item[KeyEvent[Right, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeRight], Item[KeyEvent[Down, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeDown], Item[KeyEvent[Up, Modifiers -> {Control}, CellClass -> BoxFormData], NudgeUp], Item[KeyEvent[8, Modifiers -> {Control}], InsertRawExpression], Item[KeyEvent[*, Modifiers -> {Control}], InsertRawExpression], Item[KeyEvent[Keypad8, Modifiers -> {Control}], InsertRawExpression], Item[KeyEvent[5, Modifiers -> {Control}, CellClass -> BoxFormData], Otherscript], Item[KeyEvent[Keypad5, Modifiers -> {Control}, CellClass -> BoxFormData], Otherscript], Item[KeyEvent[%, Modifiers -> {Control}, CellClass -> BoxFormData], Otherscript], (* Typesetting motion commands *) Item[KeyEvent[ , Modifiers -> {Control}], MoveExpressionEnd], Item[KeyEvent[Tab, Modifiers -> {Shift}, CellClass -> BoxFormData], MovePreviousPlaceHolder], Item[KeyEvent[s, Modifiers -> {Command, Control}, CellClass -> BoxFormData], MovePreviousExpression], Item[KeyEvent[S, Modifiers -> {Control, Command, Shift}, CellClass -> BoxFormData], MoveNextExpression], Item[KeyEvent[S, Modifiers -> {Control, Shift}, CellClass -> BoxFormData], DeleteNextExpression], Item[KeyEvent[s, Modifiers -> {Control}, CellClass -> BoxFormData], DeletePreviousExpression], Item[KeyEvent[k, Modifiers -> {Control}], CompleteSelection[True]], (* Miscellaneous menu commands *) Item[KeyEvent[Delete, Modifiers -> {Control}], Cut], Item[KeyEvent[Insert, Modifiers -> {Control}], Copy], Item[KeyEvent[Insert, Modifiers -> {Shift}], Paste[After]], Item[KeyEvent[z, Modifiers -> {Control}], Undo], Item[KeyEvent[c, Modifiers -> {Control}], Copy], Item[KeyEvent[x, Modifiers -> {Control}], Cut], Item[KeyEvent[v, Modifiers -> {Control}], Paste[After]], Item[KeyEvent[F1], SelectionHelpDialog] (* Unsupported features and examples *) (* Item[KeyEvent[v, Modifiers -> {Control}], SelectionSpeakSummary], *) (* Item[KeyEvent[v, Modifiers -> {Control, Shift}], SelectionSpeak] *) }] ==== >particular, the y-axis label is typically rotated by 90deg so that it >reads up the y-axis. This works fine on macs and windoze, but under >linux the label runs up the y-axis; however, the letters are rotated >so that they are the same orientation as that for the x-axis. >Printouts of the NB are fine, but it looks really stupid when using a >video projector to teach or give a talk. I have mentioned this before, >perhaps, but it is also a real problem with Mathematica. I personally >don't care why the label looks peculiar, just that it does and that >there is no easy workaround. ==== >I'm writing to report what I consider to be a bug. First, I want to >show a simplified example of the problem. Consider the following >expression: > >expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; > >When simplified I expected to get some real number plus >x[0]+3x[1]/4+9x[2]/16, but instead I get the following: > >Simplify[expr] 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] > >As you can see, for some reason Mathematica converted the fractions >3/4 and 9/16 to real machine numbers. I consider this to be a bug. You really are not seeing a loss of precision here. When simplify carries out the indicated multiplication such as 9*.546/16 a machine precision number is returned because on of the arguments only has machine precision. It would be incorrect for Mathematica to return a result with greater precision than the arguements. It would also be incorrect for Mathematica to refuse to preform the required multiplications when simplifying this expression. Or said differently, if you want an exact result from Mathematica *all* of the information you supply Mathematica must also be exact. It is not sensible for Mathematica to do otherwise. ==== Bill, See my comments below. There is no logical reason to insist part of the expression to be exact when another part is inexact. You cannot gain more precision than the least precise portion of the expression. Further, there is extra processing overhead associated with maintaining exact epressions as well as additional storage requirements. For a simple expression such as your example the additional overhead is insignificant. But it increases for every exact term in the expression. It doesn't take all that many terms until the overhead associate with exact computation becomes noticeable. > It seems to me that you are arguing that if you have an expression consisting of one term which is very inprecise and another term which is very precise or exact, then the total expression is only as precise as the least precise portion of the expression. This is total nonsense. Consider adding the following terms: 1.234567890123456`16 + 0.00000000000000001`1 consisting of one term with precision 16 and another term with precision 1. By your argument, Mathematica should return an answer with only a single digit of precision. Of course, Mathematica does no such thing. >Even more troubling (to me, at least) is the >following: > >x[0]+3x[1]/4+9x[2]/16+.4//Simplify > >0.4 + x[0] + 0.75 x[1] + 0.5625 x[2] > >I don't want Simplify to change my nice rational numbers to machine >number approximations. If you want exact answers you *must* have *all* terms in the expresssion exact. Simply put either an expression is exact or not. No expression can be exact unless *all* of the terms within it are exact. When did I ever say that I wanted exact answers? In the example above, I wanted Simplify to do nothing, that is, leave the expression as a sum of an inexact quantity with some exact quantities. In the work where this situation arose, the inexact quantities are typically very small and the exact quantities are large, so that the precision of the overall expression when extended precision numbers are substituted for the x[i] is typically the same as the precision of the numbers being substituted. For example, suppose x[0] and x[2] are zero, and x[1] is 1`25 10^25. Substituting these numbers into the original expression will yield a result with a precision of 25, whereas substituting these numbers into the simplified expression will only have a precision of 16. I've worked very hard to keep the precision of my numbers as high as possible, and I don't want Mathematica to arbitrarily turn those very high precision numbers into much lower precision numbers. Carl Woll Physics Dept U of Washington ==== Bill, Let's step through the expansion here. 9*(0.546+x[2]))/16 can be expanded to 9*0.546/16 + 9*x[2]/16 which becomes .307125 + 9*x[2]/16 My question was why the 9/16 gets converted to .5625, as I see no reason to do so. Even more troubling (to me, at least) is the following: x[0]+3x[1]/4+9x[2]/16+.4//Simplify 0.4 + x[0] + 0.75 x[1] + 0.5625 x[2] I don't want Simplify to change my nice rational numbers to machine number approximations. Carl Woll Physics Dept U of Washington >I'm writing to report what I consider to be a bug. First, I want to >show a simplified example of the problem. Consider the following >expression: > >expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16; > >When simplified I expected to get some real number plus >x[0]+3x[1]/4+9x[2]/16, but instead I get the following: > >Simplify[expr] 0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2] > >As you can see, for some reason Mathematica converted the fractions >3/4 and 9/16 to real machine numbers. I consider this to be a bug. You really are not seeing a loss of precision here. When simplify carries out the indicated multiplication such as 9*.546/16 a machine precision number is returned because on of the arguments only has machine precision. It would be incorrect for Mathematica to return a result with greater precision than the arguements. It would also be incorrect for Mathematica to refuse to preform the required multiplications when simplifying this expression. Or said differently, if you want an exact result from Mathematica *all* of the information you supply Mathematica must also be exact. It is not sensible for Mathematica to do otherwise. > ==== No, Euler proved that series divergent in 1737. It's the usual theorem used to show that while the primes are sparse, they're not as sparse as the squares (as the sum of THEIR inverses converges). Bobby -----Original Message----- Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== Timing[Sum[1./Prime[n], {n, 1000000}]] {13.860000000000001*Second, 3.0682190480544405} Bobby -----Original Message----- Sal. Oppenheim jr. & Cie. KGaA Koenigsberger Strasse 29 D-60487 Frankfurt am Main GERMANY Mobile: +49(0)172 6 74 95 77 Internet: http://www.oppenheim.de ==== That makes about twenty posts this week detailing nothing but problems the FrontEnd). I had been really considering it. Bobby -----Original Message----- resulted in a set of animation control buttons appearing in the bottom frame of the window. I clicked on one of these buttons, but nothing happened. I looke back in the menu and saw M-y as a keyboard shorcut to run an animation. I tried that with no result. I clicked another button in graphics control set, and my X windows locked up. This included the keyboard's ability to give me another display by using Ctl+Alt+F1. I went to another system and ssh-ed in and found Mathematica had over 50% of my user resources, and was climbing. The same was true for VM. I have a gig of physical RAM. Once I killed Mathematica, my X came back to life. I've had several bad experiences with Mathematica and X. I honestly believe there help isolate and fix these. Have others had such problems? STH ==== > That makes about twenty posts this week detailing nothing but problems > the FrontEnd). > > I had been really considering it. > > Bobby Please keep in mind that this was on Mathematica 4.1, I'll have 4.2 tomorrow, and we'll see how that goes. This isn't really the result I had hoped for by I very much wish WRI would give us a dual boot license. That way, we can use Mathematica in either environment the current situation dictates as the best. with Windows. I just don't do that as a matter of course. I've been related issuse, either because they aren't sure if the problem is their that second reason one bit. Hey, if it locks up my X, I want to know if that happens to others, and I want to identify the source of the problem. What I really would like to gain from all my negative statements is solutions to what I perceive as problems. If not that, then perhaps the perspective which makes me understand that what I see as problems are really just my unfamiliarity with the product. I also want to get others platform. That's how open source works. All that being said, if you are in a situation where an X lockup would really do harm to your project, I would say that I cannot claim it won't happen to you. OTOH, I am able to break just about any system. I can't swear to you that Mathematica won't lock up your Windows system. I can say you will not have as easy a time shelling into it and trying to recover your system without rebooting. STH Reply-To: jmt@dxdydz.net ==== Sorry, I thought I had seen a demonstration, some years ago ! > This sum converges, see a math text book ! > > > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > > > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de > > > > > Reply-To: murray@math.umass.edu ==== It is well known that the infinite series of reciprocals of the primes DIVERGES! See, for example: http://www.utm.edu/research/primes/infinity.shtml > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > > > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de > > > > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street Amherst, MA 01375 Reply-To: jmt@dxdydz.net ==== This sum converges, see a math text book ! > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > > > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de > > > ==== The fact that Sum[1/Prime[n], {n, 1,Infinity}]==Infinity is a rather famous theorem of Euler. It implies that there must be infinitely many primes (otherwise the sum would be finite), and was the beginning of a vast area of mathematics, which includes such concepts as Dirichlet series, Riemann's zeta function etc. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Wednesday, October 2, 2002, at 04:31 PM, Matthias.Bode@oppenheim.de > Dear Colleagues, I calculated: Sum[1/Prime[n], {n, 15000}] // N Result: 2.74716 Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de ==== Here's a start. If you want the thing to be greater than zero, set it equal to z (which we'll assume is greater than zero) and solve for Log[x]: Log[x, a] + Log[a*x, a] == z /. Log[a_*b_] -> Log[a] + Log[b] {f, g} = Log[x] /. Simplify[Solve[%, Log[x]]] Log[a]/Log[x] + Log[a]/(Log[a] + Log[x]) == z {-(((-2 + z + Sqrt[4 + z^2])*Log[a])/(2*z)), ((2 - z + Sqrt[4 + z^2])* Log[a])/(2*z)} Neither solution appears to be extraneous. Now the task is to find the range of these functions over positive z. Take a look at their derivatives: D[f, z] // Simplify D[g, z] // Simplify ((-1 + 2/Sqrt[4 + z^2])* Log[a])/z^2 ((-1 - 2/Sqrt[4 + z^2])*Log[a])/z^2 A little study shows that f' and g' have their signs opposite to Log[a]. Both functions are monotone. The following limits: Outer[Limit[#1, z -> #2] &, {f, g}, {0, Infinity}] Exp@% {{-(Log[a]/2), -Log[a]}, {Infinity*Log[a], 0}} {{1/Sqrt[a], 1/a}, {Indeterminate, 1}} show that f varies from -Log[a]/2 to -Log[a] and g varies from 0 to Infinity if Log[a]>0 and 0 to -Infinity if Log[a]<0. Exponentiation gives ranges for x: -1/Sqrt[a] to 1/a for f, for instance. But what does all this mean? When a>1, either x>1 or 1/a < x < 1/Sqrt[a]. When a<1, either 0, Moderator Reply-To: ==== Try this: To the original function, add a function that's (a) zero when the imaginary part is larger than some epsilon value you choose, (b) fairly large when the imaginary part is 0 or negative, and (c) as smooth as possible. For instance, something like: f=Max[(1 - x/epsilon)^5, 0] This function has four continuous derivatives in the real components -- though not in the complex variable! If it doesn't penalize the real root enough, multiply f by a constant bigger than 1 and try again. Bobby Treat -----Original Message----- are interested, the zeros are the roots of the dispersion relation for a plasma interacting with a laser). Sometimes FindRoot picks up one of these instead of the one I want. So, I'd like to tell mathematica to look for a root only in a certain rectangular region of the complex plane. Well, if I could tell it, 'look for roots with imag. part > something', I'd be happy too. I tried specifying complex values for the start and stop points of an interval, hoping mathematica would interpret these as the corners of a rectangle. No such luck. Any help would be greatly appreciated. I'd also like to point out that this and other issues about complex roots are not clearly addressed in the built-in help files. ==== > > This sum converges, see a math text book ! That's nonsense http://mathworld.wolfram.com/PrimeSums.html Jens > > Dear Colleagues, > > I calculated: > > Sum[1/Prime[n], {n, 15000}] // N > > Result: 2.74716 > > Now I wonder if this sum will converge or keep on growing, albeit very > slowly. > > Matthias Bode > Sal. Oppenheim jr. & Cie. KGaA > Koenigsberger Strasse 29 > D-60487 Frankfurt am Main > GERMANY > Mobile: +49(0)172 6 74 95 77 > Internet: http://www.oppenheim.de > > ==== I have updated my package Biokmod. It can be downloaded from: http://web.usal.es/~guillerm/biokmod.htm I developped this package thinking in biokinetic application and internal dosimetry, but it can be also applied for other kind of problems envolving System of ODE with many variables. I will appreciate any coments Guillermo Sanchez http://web.usal.es/~guillerm ==== I use BinaryImport to read a file as follows: BinaryImport[file,{Byte..}] then I use Partition to rebuild the data of dimensions 252 x 253 x 255.... This works but it takes about half an hour to read the file....it's a 16 MByte file.....any way to improve this? thanks....jerry blimbaum Reply-To: kuska@informatik.uni-leipzig.de ==== BinaryImport[] is complet unusable for this task. I tryed the same with similar data sets and run out of kernel memory (with 1.5 GByte RAM) & 3GB swap). The WRI support respondet, that BinaryImport[] is not for reading *large* binary data. You can have the beta version of MathGL3d 3.1 that has an extra C-Function for that task. Since it also include excelent volume rendering functions and a native format for reading and writing compressed volume data files you should use MathGL3d 3.1b. Contact me direct if you wish to beta test the new version. Jens > > I use BinaryImport to read a file as follows: > > BinaryImport[file,{Byte..}] > > then I use Partition to rebuild the data of dimensions 252 x 253 x 255.... > > This works but it takes about half an hour to read the file....it's a 16 > MByte file.....any way to improve this? > > thanks....jerry blimbaum ==== Does any one know of a way to produce Phase Plane Diagrams in mathematica? I need to draw a couple of direction field and analyse the stability of critical points for my systems of equations . Ajadi __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page http://uk.my.yahoo.com Reply-To: kuska@informatik.uni-leipzig.de ==== if you don't like PlotField[] you should try to get a copy of the book Visual DSolve http://store.wolfram.com/view/book/D0706.str and the book package. Jens > > > Does any one know of a way to produce Phase Plane > Diagrams in mathematica? > I need to draw a couple of direction field and > analyse the stability of critical points for my > systems of equations . > > > Ajadi > > __________________________________________________ > Do You Yahoo!? > Everything you'll ever need on one web page > http://uk.my.yahoo.com ==== Please ignore a similar question I just posted about BinaryImport...I forgot an hour to import 16 MByte file, whereas this technique took less then 5 seconds...special thanks to Mariusz... jerry blimbaum NSWC panama city, fl -----Original Message----- Mariusz Jankowski University of Southern Maine mjkcc@usm.maine.edu 207-780-5580 > The question: > What is the fastest way to read binary files in Mathematica 4.0 ? > I think the fastest is with ReadList (indeed ReadSounFile that use it, seems > to be better than BinaryImport), but when i use this command... > data = ReadList[filePath, Byte] > ....it doesn't read whole file; can somebody tell me the reason? Raf. P.S.: > I made some simple tests (@ 16 bit): << Experimental` > data = BinaryImport[fileRawPath, Table[Integer16, {4000}], > ByteOrdering -> -1]; => 10 seconds data = ReadListBinary[fileRawPath, SignedInt16, ByteOrder - LeastSignificantByteFirst]; = > 26 seconds << Miscellaneous`Audio` > data = ReadSoundfile[fileWavPath] => 1.54 seconds ==== I came across this, and thought I would share. This may be OBE if the font selection is better in 4.2. I'll that installed by this time tomorrow...I hope. http://cgm.cs.mcgill.ca/~luc/math.html I started reading through this list, and had visions of recursively downloading the entire internet looking for the font's I really need. Anybody know what fonts I should have installed on my SuSE box to satisfy Mathematica's default expectations? STH ==== In: DSolve[y*D[u[x, y],x] == x*D[u[x, y],y], u[x,y], {x, y}] Out: {{u[x, y] -> C[1][(1/2)*(x^2 + y^2)]}} Square brackets are used as grouping symbols in the result!?? :^O Somebody say it isn't so. --- Selwyn Hollis ==== It isn't so. C[1] is an arbitrary (smooth) function. After all, what you have got is a partial differential equation. For example, you can take C[1] to be Sin: In[1]:= v[x_, y_] = u[x, y] /. DSolve[y*D[u[x, y], x] == x*D[u[x, y], y], u[x, y], {x, y}] /. C[1] -> Sin Out[1]= {Sin[(1/2)*(x^2 + y^2)]} In[2]:= y*D[v[x, y], x] == x*D[v[x, y], y] Out[2]= True Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ In: DSolve[y*D[u[x, y],x] == x*D[u[x, y],y], u[x,y], {x, y}] Out: {{u[x, y] -> C[1][(1/2)*(x^2 + y^2)]}} Square brackets are used as grouping symbols in the result!?? :^O Somebody say it isn't so. --- > Selwyn Hollis Reply-To: ==== My OPINION is that extra graphics RAM is useful primarily for 3D games (which are themselves completely useless). A static 3D plot doesn't need that much graphics RAM -- it's the rapid transformation of it, to simulate live action, that may require it. On the other hand, if the manufacturer's limits are that low for graphics RAM, I would get another manufacturer. Who knows what other limitations and compromises they'll saddle you with? I would be very suspicious. Bobby -----Original Message----- Is 32 MB adequate not just now, but likely to be adequate as well for the near future (say, a 3- to 5-year equipment lifetime)? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street Amherst, MA 01375 Reply-To: kuska@informatik.uni-leipzig.de ==== > > My OPINION is that extra graphics RAM is useful primarily for 3D games Or complex 3d scientific visualizations ? Textures ? Try to render the skull from a 256^3 CT scan or the output of a 3d plasma simulation and you will know *what* can be done with extra 3d RAM > (which are themselves completely useless). The major effect is, that 3d Games make 3d graphics hardware less expensive. Five years ago a SGI cost 20-30 000 $ and today you can have more 3d power for 400 $ Jens > A static 3D plot doesn't > need that much graphics RAM -- it's the rapid transformation of it, to > simulate live action, that may require it. > > On the other hand, if the manufacturer's limits are that low for > graphics RAM, I would get another manufacturer. Who knows what other > limitations and compromises they'll saddle you with? I would be very > suspicious. > > Bobby > > -----Original Message----- > > We are about to order new PCs for a university student lab in which > Mathematica will be installed. Of course they will be using 2D and 3D > graphics -- plots of surfaces, e.g. Sooner or later students will want > to rotate such plots, too. > > An unresolved issue is how much graphics RAM to get. On existing > machines we typically have 64MB. But for the PCs we are looking at, > manufacturer's limits on graphics RAM, rather than cost, seems to limit > us to 32 MB. > > Is 32 MB adequate not just now, but likely to be adequate as well for > the near future (say, a 3- to 5-year equipment lifetime)? > > -- > Murray Eisenberg murray@math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street > Amherst, MA 01375 ==== Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and also a new user of Mathematica; so please forgive this rather simple question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth Harker School http://www.harker.org/ ==== Steve The notebook given after NOTEBOOK below contains functions for factoring and partial fractioning. Here is an application to your problem: the first stage avoids our needing to know anything about the answer. fc=FactorR[x^4+x^3+x^2+x+1,x] (1 - (1/2)*(-1 - Sqrt[5])*x + x^2)* (1 - (1/2)*(-1 + Sqrt[5])*x + x^2) Now we need to get rid of Sqrt[5] in terms of GoldenRatio. This is rather messy: Simplify/@(fc/. Sqrt[5][Rule]2 GoldenRatio-1) (1 + x - GoldenRatio*x + x^2)*(1 + GoldenRatio*x + x^2) Simplify/@(%/.-GoldenRatio[Rule] 1/GoldenRatio -1) (1 + x/GoldenRatio + x^2)*(1 + GoldenRatio*x + x^2) Another example PartialFractionsR[(1 + x)x/(1 - 3*x + x^2), x] 1 - (2*(-1 + 4*x))/((3 + Sqrt[5] - 2*x)*(-3 + 2*x)) + (2*(-1 + 4*x))/((-3 + 2*x)*(-3 + Sqrt[5] + 2*x)) Simplify[%] (x*(1 + x))/(1 - 3*x + x^2) NOTEBOOK: to make a notebook from the following, copy from the next line to the line preceding XXX and paste into a new Mathematica notebook. Notebook[{ Cell[CellGroupData[{ Cell[Factors and PartialFractions, Subtitle], Cell[Allan Hayes, 16 August 2001, Text], Cell[< Here are some functions for factoring and expressing in partial fractions over the reals and over the complex numbers. >, Text], Cell[BoxData[ (Quit)], Input], Cell[BoxData[{ (Off[General::spell1, General::spell]), n, ((FactorC::usage = ;)n), n, ((FactorR::usage = ;)n), n, ((PartialFractionsC::usage = ;)n), n, ((PartialFractionsR::usage = ;)), n, (On[General::spell1, General::spell])}], Input, InitializationCell->True], Cell[TextData[{ FactorC[p_, x_] := , StyleBox[(*over complex numbers*), FontFamily->Arial, FontWeight->Plain], nTimes @@ Cases[Roots[p == 0, x, n Cubics -> False], u_ == v_ -> x - v]n nFactorR[p_, x_] := , StyleBox[(*over reals, coefficients must be real*), FontFamily->Arial, FontWeight->Plain], n (Times @@ Join[Cases[#1, u_ == v_ /; Im[v] == 0 :> n x - v], Cases[#1, u_ == v_ /; Im[v] > 0 :> n x^2 - x*2*Re[v] + Abs[v]^2]] & )[n Roots[p == 0, x, Cubics -> False]] }], Input, InitializationCell->True], Cell[TextData[{ PartialFractionsC[p_, x_] := , StyleBox[(*over complex numbers*), FontFamily->Arial, FontWeight->Plain], n(#+Apart[#2/FactorC[#3,x]])&@@Flatten[{PolynomialReduce[#,#2], #2}]&[Numerator[#],Denominator[#]]&[Together[p]]n n PartialFractionsR[p_, x_] := , StyleBox[(*over reals, coefficients must be real*), FontFamily->Arial, FontWeight->Plain], n(#+Apart[#2/FactorR[#3,x]])&@@Flatten[{PolynomialReduce[#,#2], #2}]&[Numerator[#],Denominator[#]]&[Together[p]] }], Input, InitializationCell->True], Cell[CellGroupData[{ Cell[PROGRAMMING NOTES, Subsubsection], Cell[TextData[{ The option , StyleBox[Cubics->False, FontFamily->Courier], is used to keep the roots of cubics in , StyleBox[Root[....], FontFamily->Courier], form. This is better for computation.n, StyleBox[Re[v], FontFamily->Courier], and , StyleBox[Abs[v]^2, FontFamily->Courier], are used rather than , StyleBox[v+Conjugate[v] , FontFamily->Courier], and , StyleBox[v*Conjugate[v], FontFamily->Courier], to prevent , StyleBox[Apart, FontFamily->Courier], from factorising , StyleBox[x^2 - x*2*Re[v] + Abs[v]^2], FontFamily->Courier], back to complex form. }], Text] }, Closed]], Cell[CellGroupData[{ Cell[EXAMPLES, Subsubsection], Cell[pol = Expand[(x - 1)*(x + 1)^2*(x^2 + x + 1)^2*(x^2 + 4)]; , Input], Cell[CellGroupData[{ Cell[f1 = FactorC[pol, x], Input], Cell[BoxData[ ((((-1) + x)) (((-2) [ImaginaryI] + x)) ((2 [ImaginaryI] + x)) ((1 + x))^2 (((((-1)))^(1/3) + x))^2 (((-(((-1)))^(2/3)) + x))^2)], Output] }, Open ]], Cell[CellGroupData[{ Cell[f2 = FactorR[pol, x], Input], Cell[BoxData[ ((((-1) + x)) ((1 + x))^2 ((4 + x^2)) ((1 + x + x^2))^2)], Output] }, Open ]], Cell[CellGroupData[{ Cell[f3 = FactorR[x^3 + x + 1, x], Input], Cell[BoxData[ (((x - Root[1 + #1 + #1^3 &, 1])) ((x^2 - 2 x Root[(-1) + 2 #1 + 8 #1^3 &, 1] + Root[(-1) - #1^4 + #1^6 &, 2]^2)))], Output] }, Open ]], Cell[< Root objects appear because of the option Cubics->False in Roots. We can sometimes get radical forms, but notice the complication. >, Text], Cell[CellGroupData[{ Cell[ToRadicals[f3], Input], Cell[BoxData[ (((((2/(3 (((-9) + @93)))))^(1/3) - ((1/2 (((-9) + @93))))^(1/3)/3^(2/3) + x)) ((1/3 + 1/3 ((29/2 - (3 @93)/2))^(1/3) + 1/3 ((1/2 ((29 + 3 @93))))^(1/3) - 2 ((((1/2 ((9 + @93))))^(1/3)/(2 3^(2/3)) - 1/(2^(2/3) ((3 ((9 + @93))))^(1/3)))) x + x^2)))], Output] }, Open ]], Cell[Inexact forms can be found, from f3 :, Text], Cell[CellGroupData[{ Cell[N[f3], Input], Cell[BoxData[ (((((0.6823278038280193`)([InvisibleSpace])) + x)) ((((1.4655712318767682`)([InvisibleSpace])) - 0.6823278038280193` x + x^2)))], Output] }, Open ]], Cell[or directly, Text], Cell[CellGroupData[{ Cell[f3 = FactorR[x^3 + x + 1//N, x], Input], Cell[BoxData[ (((((0.6823278038280193`)([InvisibleSpace])) + x)) ((((1.4655712318767682`)([InvisibleSpace])) - 0.6823278038280193` x + x^2)))], Output] }, Open ]], Cell[Partial fractions, Text], Cell[CellGroupData[{ Cell[pf1 = PartialFractionsR[(2 + x)/pol, x], Input], Cell[BoxData[ (1/(60 (((-1) + x))) - 1/(10 ((1 + x))^2) - 39/(100 ((1 + x))) + ((-54) - 31 x)/(4225 ((4 + x^2))) + ((-1) + 3 x)/(13 ((1 + x + x^2))^2) + (44 + 193 x)/(507 ((1 + x + x^2))))], Output] }, Open ]], Cell[CellGroupData[{ Cell[pf2 = PartialFractionsR[(1 + x)x/(1 - 3*x + x^2), x], Input], Cell[< 1 - (2*(-1 + 4*x))/((3 + Sqrt[5] - 2*x)*(-3 + 2*x)) + (2*(-1 + 4*x))/((-3 + 2*x)*(-3 + Sqrt[5] + 2*x)) >, Output] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ (Simplify[%])], Input], Cell[(x*(1 + x))/(1 - 3*x + x^2), Output] }, Open ]], Cell[Partial fractions will often involve Root objects , Text], Cell[CellGroupData[{ Cell[pf3 = PartialFractionsR[(1 + x)/(x^3 - x + 1), x], Input], Cell[BoxData[ (((1 + Root[1 - #1 + #1^3 &, 1]))/((((x - Root[1 - #1 + #1^3 &, 1])) ((Root[1 - #1 + #1^3 &, 1]^2 - 2 Root[1 - #1 + #1^3 &, 1] Root[(-1) - 2 #1 + 8 #1^3 &, 1] + Root[(-1) + #1^4 + #1^6 &, 2]^2)))) + ((x + Root[1 - #1 + #1^3 &, 1] + x Root[1 - #1 + #1^3 &, 1] - 2 Root[(-1) - 2 #1 + 8 #1^3 &, 1] - Root[(-1) + #1^4 + #1^6 &, 2]^2))/(((((-x^2) + 2 x Root[(-1) - 2 #1 + 8 #1^3 &, 1] - Root[(-1) + #1^4 + #1^6 &, 2]^2)) ((Root[1 - #1 + #1^3 &, 1]^2 - 2 Root[1 - #1 + #1^3 &, 1] Root[(-1) - 2 #1 + 8 #1^3 &, 1] + Root[(-1) + #1^4 + #1^6 &, 2]^2)))))], Output] }, Open ]], Cell[This can in fact be put in radical form:, Text], Cell[CellGroupData[{ Cell[ToRadicals[pf3], Input], Cell[BoxData[ (((1 - ((2/(3 ((9 - @69)))))^(1/3) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3)))/(((((-(1/3)) + 1/3 ((25/2 - (3 @69)/2))^(1/3) + 1/3 ((1/2 ((25 + 3 @69))))^(1/3) + (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3)))^2 - 2 (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3))) ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))))) ((((2/(3 ((9 - @69)))))^(1/3) + ((1 /2 ((9 - @69))))^(1/3)/3^(2/3) + x)))) + ((1/3 - 1/3 ((25/2 - (3 @69)/2))^(1/3) - ((2/(3 ((9 - @69)))))^(1/3) - ((1/2 ((9 - @69))))^(1/3)/3 ^(2/3) - 1/3 ((1/2 ((25 + 3 @69))))^(1/3) - 2 ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))) + x + (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3))) x))/(((((-(1 /3)) + 1/3 ((25/2 - (3 @69)/2))^(1/3) + 1/3 ((1/2 ((25 + 3 @69))))^(1/3) + (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3)))^2 - 2 (((-((2/(3 ((9 - @69)))))^(1/3)) - ((1/2 ((9 - @69))))^(1/3)/3^(2/3))) ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))))) ((1/3 - 1/3 ((25/2 - (3 @69)/2))^(1/3) - 1/3 ((1/2 ((25 + 3 @69))))^(1/3) + 2 ((1/24 ((864 - 96 @69))^(1/3) + ((1/2 ((9 + @69))))^(1/3)/(2 3^(2/3)))) x - x^2)))))], Output] }, Closed]], Cell[We could have found the inexact form directly., Text], Cell[CellGroupData[{ Cell[BoxData[ (PartialFractionsR[((1 + x))/((x^3 - x + 1)) // N, x])], Input], Cell[BoxData[ ((-(0.07614206365252976`/(((1.324717957244746`)( [InvisibleSpace])) + 1.` x))) + (((0.7982664819556426`)( [InvisibleSpace])) + 0.07614206365252976` x)/(((0.754877666246693`)([InvisibleSpace])) - 1.324717957244746` x + 1.` x^2))], Output] }, Open ]] }, Closed]] }, Open ]] }, ScreenRectangle->{{0, 1024}, {0, 709}}, AutoGeneratedPackage->None, WindowSize->{534, 628}, WindowMargins->{{199, Automatic}, {0, Automatic}}, ShowCellLabel->False, StyleDefinitions -> Default.nb ] XXX -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and also a > new user of Mathematica; so please forgive this rather simple question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ > Reply-To: kuska@informatik.uni-leipzig.de ==== In[]:=Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio, 1/GoldenRatio}] Out[]=-((-3 - 2*x + Sqrt[5]*x + GoldenRatio*x - 3*x^2)* (3 + x + Sqrt[5]*x + GoldenRatio*x + 3*x^2))/9 Jens > > Greetings MathGroup, > > My name is Steve Earth, and I am a new subscriber to this list and also a > new user of Mathematica; so please forgive this rather simple question... > > I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica > and have it be able to tell me that it factors into > > (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) > > What instructions do I need to execute to achieve this output? > > -Steve Earth > Harker School > http://www.harker.org/ ==== > The last part of my message you are quoting was completely wrong, as > was pointed out by Allan Hayes. Mathematica does not track precision of > machine arithmetic computations. In order for Mathematica to give > reliable information about the precision of a computation you have to > explicitly set the precision of all the numerical quantities. > > Your own example at the bottom simply shows you have not understood the > evaluation mechanism of Mathematica. Just opposite, thanks to you and other participants, I completely > understood it. SetAccuracy just takes anything and calls it accurate. > This behavior is useless if not stupid. I am not sure I understand what you are referring to as useless if not stupid. The main purpose of SetAccuracy is to allow people who have done their own error analysis to specify the numerical error in an input or in a result. It is often possible through careful numerical analysis, for example, to come up with a better error estimate than can be given by generic rules for propogation of error. Another common use of SetAccuracy is for converting machine numbers or exact numbers into variable-precision numbers in situations when it is desired that a calculation be done using variable-precision arithmetic. Is there some aspect of this that you think is useless if not stupid, or was that remark referring to something else? Dave Withoff Wolfram Research ==== > The more I play with the example the more depressing it gets. Start > with floating point numbers but explicitely arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision numbers, as > discussed in the previous section, Mathematica always keeps track of > the precision of your results, and gives only those digits which are > known to be correct, given the precision of your input. When you do > calculations with machine-precision numbers, however, Mathematica > always gives you a machine?precision result, whether or not all the > digits in the result can, in fact, be determined to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers Mathematica should display > only those digits that are correct, that is none. An accuracy of -6 means that the least significant correct digit is 6 digits to the left of the decimal point. The result Out[3] in the example above has 26 significant digits to the left of that (the most sigificant digit is 26+6=32 digits to the left of the decimal point), so there are 26 correct digits to display. Was there some other result you were referring to as a result in which the number of correct digits is none? Dave Withoff Wolfram Research ==== > I came across this, and thought I would share. This may be OBE if the font > selection is better in 4.2. I'll that installed by this time tomorrow...I > hope. > > http://cgm.cs.mcgill.ca/~luc/math.html > > I started reading through this list, and had visions of recursively > downloading the entire internet looking for the font's I really need. > Anybody know what fonts I should have installed on my SuSE box to satisfy > Mathematica's default expectations? The contents of the page at this URL are interesting, but probably not relevant for your purposes. The only fonts which are absolutely needed by the front end are the fonts that supply the special glyphs for mathematical notation, grouping characters, Greek letters, etc. These fonts were developed by Wolfram Research and are installed as part of the Mathematica installation. There are two generations of these fonts. The first generation was introduced in Mathematica 3.0 in the fall of 1996 and were used through the release of Mathematica 4.1. There were five families known as Math1 - Math5. Each familiy had four variants: a proportionaly-spaced medium face, a monospaced medium, a proportional bold, and a monospaced bold. The second generation is used by Mathematica 4.2. There are seven families named Mathematica1 - Mathematica7. Aside from the math fonts, the front end should be able to function properly provided that you have a font that supports the encoding for your chosen locale. The style sheets bundled with the front end use only Times, Helvetica, and Courier. Should these fonts not be available on your system, the front end has some substitution rules. For example, the Windows front end knows to use the fonts Times New Roman, Arial, and Courier New. The X Window System ships with bitmap versions of Times, Helvetica, and Courier as well as an outline of Courier. If one of these fonts must be drawn at a size for which there are no bitmaps, outline fonts provided with Mathematica are used. Helvetica is aliased to Swiss721, and Times is aliased to Utopia through a fonts.alias file in the Mathematica fonts directory. Under MacOS and Windows, you should be albe to use whatever fonts are available on your system. Under X, things are a little more complicated. The front end can display whatever fonts are made available to your X server, but it can generate PostScript only for those fonts where an Adobe Font Metric (AFM) file is available. If you wish to display or print the PostScript, you must also make the Type 1 font file available to the rendering device. Note also that the X front end has an adjustable setting for the amount of memory to reserve for storing font data. If your system has a large number of fonts, you may need to increase this setting per this FAQ page: http://support.wolfram.com/mathematica/systems/linux/interface/fonterrors.ht ml -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== > > I came across this, and thought I would share. This may be OBE if the > font > selection is better in 4.2. I'll that installed by this time > tomorrow...I hope. > > http://cgm.cs.mcgill.ca/~luc/math.html > > I started reading through this list, and had visions of recursively > downloading the entire internet looking for the font's I really need. > Anybody know what fonts I should have installed on my SuSE box to satisfy > Mathematica's default expectations? > > The contents of the page at this URL are interesting, but probably not > relevant for your purposes. That's kind'o' what I thought. [snip - history lesson - thanks] > The second generation is used by Mathematica 4.2. There are seven > families named Mathematica1 - Mathematica7. Where is the documentation for installing these? This is dated: http://support.wolfram.com/mathematica/systems/linux/interface/fonterrors.ht ml I grabbed these off the net: http://support.wolfram.com/mathematica/systems/linux/general/latestfonts.htm l http://support.wolfram.com/mathematica/systems/linux/general/MathBDF_42.tar. gz http://support.wolfram.com/mathematica/systems/linux/general/MathPCF_42.tar. gz http://support.wolfram.com/mathematica/systems/linux/general/MathT1_42.tar.g z > su - ****** # cd /usr/X11/lib/X11/fonts/ # mkdir -p local/mma # cd local/mma # tar xvfz /download/com/wri/MathBDF_42.tar.gz # tar xvfz /download/com/wri/MathPCF_42.tar.gz # tar xvfz /download/com/wri/MathT1_42.tar.gz # xemacs /etc/X11/XF86Config .... # grep FontPath /etc/X11/XF86Config FontPath /usr/X11R6/lib/X11/fonts/100dpi:unscaled FontPath /usr/X11R6/lib/X11/fonts/75dpi:unscaled FontPath /usr/X11R6/lib/X11/fonts/CID FontPath /usr/X11R6/lib/X11/fonts/Speedo FontPath /usr/X11R6/lib/X11/fonts/Type1 FontPath /usr/X11R6/lib/X11/fonts/URW FontPath /usr/X11R6/lib/X11/fonts/kwintv:unscaled FontPath /usr/X11R6/lib/X11/fonts/latin2/Type1 FontPath /usr/X11R6/lib/X11/fonts/misc:unscaled FontPath /usr/X11R6/lib/X11/fonts/misc/sgi:unscaled FontPath /usr/X11R6/lib/X11/fonts/truetype FontPath /usr/X11R6/lib/X11/fonts/uni:unscaled FontPath /usr/X11R6/lib/X11/fonts/local/mma/BDF FontPath /usr/X11R6/lib/X11/fonts/local/mma/PCF FontPath /usr/X11R6/lib/X11/fonts/local/mma/T1 # SuSEconfig .... # init 3 [assuming you are already at a TTY console] # init 5 > Aside from the math fonts, the front end should be able to function > properly provided that you have a font that supports the encoding for your > chosen locale. The style sheets bundled with the front end use only > Times, Helvetica, and Courier. Should these fonts not be available on > your system, the front end has some substitution rules. > > For example, the Windows front end knows to use the fonts Times New Roman, > Arial, and Courier New. The X Window System ships with bitmap versions of > Times, Helvetica, and Courier as well as an outline of Courier. If one of > these fonts must be drawn at a size for which there are no bitmaps, > outline fonts provided with Mathematica are used. Helvetica is aliased to > Swiss721, and Times is aliased to Utopia through a fonts.alias file in the > Mathematica fonts directory. This is what I find anoying. Every time Mathematica does one of these substitutions, it beeps. This is what I'm calling a font fault. It's like the boy who cried wolf. I start ignoring beeps. It also bothers me that I am not seeing what the author had intended. I *believe* it is the author of the notebook or help document who determines what fonts should be used. This is a point of confusion. When I opened a help page, and didn't like the size of the fonts, I tried to adjust them without the desired result. I now believe the proper remedy is to use magnification, not a font adjustment. I have far fewer chirps (beeps) in 4.2, but I do get them when changing the magnification. > Under MacOS and Windows, you should be albe to use whatever fonts are > available on your system. Under X, things are a little more complicated. > The front end can display whatever fonts are made available to your X > server, but it can generate PostScript only for those fonts where an Adobe > Font Metric (AFM) file is available. If you wish to display or print the > PostScript, you must also make the Type 1 font file available to the > rendering device. This is for another day. I believe I have done this in years gone by, but, for now, I just want to get the optimal behavior form the crt. [snip] Here's my question in a nutshell. When I do xlsfonts, what should be listed in order to run Mathematica 4.2 and not experiece font faults generated by content provided on the CD? Please note that I *just* finished installing the fonts off the web, so I'm not sure what, if any problems still remain. I suspect the helvetica faults will still occur. STH . ==== Bobby, One point: >.... bigfloats ... [are] the result of using N[expr,k] or SetAccuracy[expr,k] where k is bigger than machine precision. If k <= > machine > precision, the result is a machine precision number. We get bigfloats with k<=machine precision with SetAccuracy and SetPrecision but not with N: Example a=SetPrecision[2.3,5] 2.3000 Precision[a] 5. Precision[a^2000] 1.69897 Also, of course, when more than machine precision significant digits are given a=1.01234567891234500; Precision[a] 17.301 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 Reply-To: ==== Please allow me to summarize what I've learned in the recent discussion, and retract my claim that Accuracy, Precision, and SetAccuracy are useless. Numbers come in three varieties - machine precision, Infinite precision, and bignum or bigfloat. Bignums and bigfloats (synonymous?) aren't called that in the Help Browser, but they're the result of using N[expr,k] or SetAccuracy[expr,k] where k is bigger than machine precision. If k <= machine precision, the result is a machine precision number, even if you know the expression isn't that precise. If, when you use N or SetAccuracy as described above, the expression contains undefined symbols, you get an expression with all its numerics replaced by bignums of the indicated precision. When the symbols are defined later, if ANY of them are machine precision, the expression is computed with machine arithmetic - with the side-effect that coefficients that originally were Infinite-precision are now only machine precision. That is, x^2 might have become x^2.0000000000000000000000000000000000 but later became x^2., for instance. If all the symbols have been set to bignum or Infinite precision values, the computation will be done taking precision into account, and the result has a Precision or Accuracy that makes sense. In all other cases, Precision returns Infinity for entirely Infinite-precision expressions and 16 for everything else. When one of the experts says significance arithmetic that's what they mean - using SetAccuracy or N to give things more than 16 digits, leaving no machine precision numbers anywhere in the expression, and using Accuracy or Precision, which ARE meaningful in that case, to judge the result. (It's meaningful if all your inputs really have more than 16 digits of precision, that is.) You can't use significance arithmetic to determine how much precision a result has if your inputs have 16 or 15 or 2 digits of precision. In the example we've been looking at, you can give the inputs MORE accuracy than you really believe they have, and still get back 0 digits from Precision at the end, so there are clearly no trustworthy digits when you use the original inputs either. If an expression is on the razor's edge, and has lost only a few digits of precision, that wouldn't work so well. Oddly enough, significance arithmetic in the Browser doesn't take you to any of that. Instead, it takes you to Interval arithmetic, a more sophisticated method, which may give a more accurate gauge of how much precision you really have, and WILL deal with machine precision numbers and numbers with even less precision. It does a very good job on the example. However, it isn't very suitable for Complex numbers, matrices, etc. NSolve and NIntegrate probably can't handle it, either. Daniel Lichtblau promises that all this will be clearer in the next release. DrBob ==== I'm a newbie and, of course, the first thing I want to do is apparently one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I want the equation to be written out with terms grouped by powers of x, but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at least point me to some tutorial in the Mathematica documentation. I've been looking over the documentation and I found Appendix A.5 in The Mathematica Book, but that doesn't help me. I _need_ some examples. I did find a couple of well-written posts in this newsgroup, but not quite close enough to what I want. Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] cnu = (2*b^2 - B^2 + r^2)/denom snu = -2*b*Sqrt[B^2 - b^2]/denom sif = 2*r*b/denom cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b that I'm after. ==== Troy, True, interactive manipulation can be difficult. However, here is one way to do what you want. We have to do the same thing to both sides of the equation. (# - D*Sqrt[K]/C)&/@(A+B/C+D*Sqrt[K]/C[Equal]0 A + B/C == -((D*Sqrt[K])/C) Together/@% (B + A*C)/C == -((D*Sqrt[K])/C) #C&/@% B + A*C == (-D)*Sqrt[K] #^2&/@% (B + A*C)^2 == D^2*K NOTES. Here is how #C&/@ (lhs ==rhs) works: #C&/@ (lhs ==rhs) --> #C&[lhs]==#C&[rhs] --> lhs C == rhs C --> ... f/@( expr) is special for for Map[f, expr] expr& is special for Function[expr] Please look up Map and Function in the Help Browser. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > I'm a newbie and, of course, the first thing I want to do is apparently > one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x > I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at > least point me to some tutorial in the Mathematica documentation. I've > been looking over the documentation and I found Appendix A.5 in The > Mathematica Book, but that doesn't help me. I _need_ some examples. I > did find a couple of well-written posts in this newsgroup, but not quite > close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b > that I'm after. > ==== > Troy, > True, interactive manipulation can be difficult. > However, here is one way to do what you want. > We have to do the same thing to both sides of the equation. > > (# - D*Sqrt[K]/C)&/@(A+B/C+D*Sqrt[K]/C[Equal]0 > > A + B/C == -((D*Sqrt[K])/C) I think I have to apologize for the lack of clarity in my original post. I had tried to word it carefully, but I deceived myself. I should have said: I have an expression that can be put into this form: A + B/C + D*Sqrt[K]/C = 0 A,B,C,D, & K are all polynomials in x I need to get it into that form and, in the end, I want it to look like this (D^2)*K = (A*C + B)^2 I think I gave the impression that I have polynomials A,B,C,D, & K at my fingertips. I don't. The expression I have is given at the end of this message. I'm still trying to digest the respones I've garned so far. In the meantime, I decided to post this clarification. > > I'm a newbie and, of course, the first thing I want to do is > apparently one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[K]/C = 0 A,B,C,D, & K are all polynomials in x > I want it to look like this (D^2)*K = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, > at least point me to some tutorial in the Mathematica documentation. > I've been looking over the documentation and I found Appendix A.5 in > The Mathematica Book, but that doesn't help me. I _need_ some > examples. I did find a couple of well-written posts in this newsgroup, > but not quite close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in > b that I'm after. > > > ==== I'm only a little embarassed for not having realized what was happening. (Perhaps I should have slept on it.) Surely I'm not alone in thinking this symbolism is highly nonintuitive. But of course, for it to be otherwise would require another protected symbol... --- Selwyn > > >>In: DSolve[y*D[u[x, y],x] == x*D[u[x, y],y], u[x,y], {x, y}] >Out: {{u[x, y] -> C[1][(1/2)*(x^2 + y^2)]}} >Square brackets are used as grouping symbols in the result!?? :^O >Somebody say it isn't so. > > It isn't so > > The square bracket is not delineating a factor it is enclosing the argument > to an arbitrary function named C[1]. While the function is dependent on both > x and y the dependence only occurs in the combination (x^2+y^2). > > > Bob Hanlon > Reply-To: ==== It isn't so. The solution is an arbitrary function of (1/2)*(x^2 + y^2)]}}. Bobby -----Original Message----- ==== Does anyone know what happened to the < > Does anyone know what happened to the < in Mathematica 4.x? In some version I know I used it, but it seems to > have gone away. It allowed for real time manipulation of 3D graphics. > > > Ray Gittings ==== > > The more I play with the example the more > depressing it gets. Start > with floating point numbers but explicitly > arbitrary-precision ones. > > In[1]:= > a=77617.00000000000000000000000000000; > b=33095.00000000000000000000000000000; > > In[3]:= > !(333.7500000000000000000000000000000 b^6 + > a^2 ((11 a^2 > b^2 - > b^6 - 121 b^4 - 2)) + > 5.500000000000000000000000000000 b^8 + > a/(2 > b)) > > Out[3]= > !((-4.78339168666055402578083604864320577443814`26.6715*^32)) > > In[4]:= > Accuracy[%] > > Out[4]= > -6 > > Due to the manual section 3.1.6: > > When you do calculations with arbitrary-precision > numbers, as > discussed in the previous section, Mathematica > always keeps track of > the precision of your results, and gives only > those digits which are > known to be correct, given the precision of your > input. When you do > calculations with machine-precision numbers, > however, Mathematica > always gives you a machine[CapitalEth]precision result, > whether or not all the > digits in the result can, in fact, be determined > to be correct on the > basis of your input. > > Because I started with arbitrary-precision numbers > Mathematica should display > only those digits that are correct, that is none. > > No, 26 digits are correct Here is the number: -0.8273960599468213681 Here is the same number computed by Mathematica with 26 correct digits: -4.78339168666055402578083604864320577443814[Times]10^32 It looks like I have been using some wrong definition of correct.:-) You just proved that Precision is useless as a measure how good your numerical result is. > (check Precision instead > of Accuracy to see > this). > > You appear to be showing output in InputForm. If you > use OutputForm or > StandardForm only 26 digits will be shown. > > 32 > Out[3]= -4.7833916866605540257808360 10 > > InputForm is showing more because it exposes bad > digits as well as > good ones. > > > To relax a bit, set a new input cell to > StandardForm and type > 77617.000000000000000000000000000000000 > > Convert it to InputForm. You get > 77616.999999999999999999999999999999999999999999952771`37.9031 > > Convert back to StandardForm > 77616.99999999999999999999999999999999999999999976637`37.9031 > > Again to InputForm > 77616.99999999999999999999999999999999999999999963735`37.9031 > > Back to StandardForm > 77616.99999999999999999999999999999999999999999951376`37.9031 > > See what you can get if you have enough patience > or a small program. > > PK > > Agreed, it's not very pretty. I am uncertain as to > whether this > indicates a bug in StandardForm or elsewhere in the > underlying numerics > code, and will defer to our numerics experts on that > issue. My guess is > it is a bug if only because it violates the spirit > of IEEE arithmetic > wherein floats that have integer values should be > representable as such > (or something to that effect). I will point out, > however, that the two > numbers in question are equal to the specified > precision. Also it > appears to be improved in our development kernel. > > > Daniel Lichtblau > Wolfram Research __________________________________________________ Do you Yahoo!? http://faith.yahoo.com ==== >Yes, there seems to be a lot of people who have a visceral hatred for >Microsoft and Windows. They are even willing to shed blood to avoid >Windows. But why? Windows works and you don't have to become a systems >programmer. > >Furthermore, I think that Steven Wolfram uses some version of Windows. >So guess which system Mathematica will be best tuned up for? If it is true Wolfram uses Mathematica on a Windows based machine my experience is it doesn't translate to Mathematica running better on Windows. I use Mathematica on WindowsNT and on a Mac (currently Mac OS X). I have found Mathematica to be more stable on a Mac than on Windows. On more than one occassion I've seen errors I made Mathematica code to crash the entire machine under WindowsNT. I've never had this happen running things on a Mac. ==== > >>Yes, there seems to be a lot of people who have a visceral hatred for >>Microsoft and Windows. They are even willing to shed blood to avoid >>Windows. But why? Windows works and you don't have to become a systems >>programmer. >Furthermore, I think that Steven Wolfram uses some version of Windows. >>So guess which system Mathematica will be best tuned up for? > > If it is true Wolfram uses Mathematica on a Windows based machine my > experience is it doesn't translate to Mathematica running better on > Windows. I use Mathematica on WindowsNT and on a Mac (currently Mac OS X). > I have found Mathematica to be more stable on a Mac than on Windows. On > more than one occassion I've seen errors I made Mathematica code to crash > the entire machine under WindowsNT. I've never had this happen running > things on a Mac. I believe you hit the nail on the head. I suspect Dr. Wolfram is running on Mac. I have the feeling WRI is a clandestine Mac holdout. STH . ==== I ran Turbo XML http://www.tibco.com/solutions/products/extensibility/turbo_xml.jsp on ToFileName[{$TopDirectory, SystemFiles, IncludeFiles, XML}, notebookml1.dtd ] It gave me an error saying: There is more than one attribute named class. My guess is this was the intention: hattons@ljosalfr:~/.Mathematica/SystemFiles/IncludeFiles/XML/NotebookML1> diff /opt/Wolfram/Mathematica/4.2/SystemFiles/IncludeFiles/XML/NotebookML1/notebo okml.dtd /home/hattons/.Mathematica/SystemFiles/IncludeFiles/XML/NotebookML1/notebook ml.dtd 91c91 Comments? STH . ==== I've posted Mathematica notebooks and packages illustrating most of the neural networks discussed in James Anderson's book An Introduction to Neural Networks to the Brainstage Research web site (www.brainstage.com). Have fun! Don Donald Doherty, Ph.D. Brainstage Research, Inc. donald.doherty@brainstage.com ==== can I have mathematica solver things like a(over)b, (in how many ways can you pick b items from a items)? I have mathematica 4. Stefan ==== Stefan You certainly can - try Binomial[a,b]. Mark Westwood > > > can I have mathematica solver things like a(over)b, (in how many ways > can you pick b items from a items)? > > I have mathematica 4. > > Stefan ==== There are two basic ways, the second of which has two forms. The basic ways are: 1. Using the built in function ContourPlot, e.g.: ContourPlot[x^3y + y^3 - 9, {x, -9, 9}, {y, -27, 27}, Contours -> {0}, ContourShading -> False, Axes -> True, Frame -> False, PlotPoints -> 50, AxesOrigin -> {0, 0}] alternatively you can use a Standard package: <{0,0}] or ImplicitPlot[x^3y+y^3-==9,{x,-9,9},{y,-27,27},AxesOrigin->{0,0}] The difference between these two is that the first one gives you a smoother picture but requires the equation to be solvable (by Mathematica) for y. The second will give a picture very similar to that produced by the first method. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? ==== Since you already know the answer, the simplest way is: In[51]:= Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio}] Out[51]= (-(-1 - x + GoldenRatio*x - x^2))*(1 + GoldenRatio*x + x^2) Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and > also a > new user of Mathematica; so please forgive this rather simple > question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into > Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and > also a > new user of Mathematica; so please forgive this rather simple > question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into > Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I confess I am not 100% sure what you mean. Would you like to do this in steps, like you would do it by hand? In[1]:= a + b/c + d*(Sqrt[e]/c) == 0; In[2]:= Thread[(#1 - a - b/c & )[%], Equal] Out[2]= (d*Sqrt[e])/c == -a - b/c In[3]:= Thread[(#1*c & )[%], Equal] Out[3]= d*Sqrt[e] == (-a - b/c)*c In[4]:= Thread[(#1^2 & )[%], Equal] Out[4]= d^2*e == (-a - b/c)^2*c^2 In[5]:= Simplify[%] Out[5]= d^2*e == (b + a*c)^2 Of course you can combine all the steps into a single function, but I think it will be fairly complicated. My own favourite way to do this sort of thing is: In[1]:= Simplify[d^2*e == (d^2*e /. AlgebraicRules[ a + b/c + d*(Sqrt[e]/c) == 0, e])] Out[1]= d^2*e == (b + a*c)^2 However, AlgebraicRules has not been documented since version 4. It should be possible to do this using PolynomialReduce but it seems to require the sort of skill only Daniel Lichtblau possesses;) Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ > I'm a newbie and, of course, the first thing I want to do is apparently > one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x > I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at > least point me to some tutorial in the Mathematica documentation. I've > been looking over the documentation and I found Appendix A.5 in The > Mathematica Book, but that doesn't help me. I _need_ some examples. I > did find a couple of well-written posts in this newsgroup, but not > quite > close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b > that I'm after. ==== Only on second reading I noticed the part about a,b,c,d being polynomials in x. Both methods will still work if first perform the same operation as below and finally use the replacement rule %/.{a->p[x],b->q[x],c->r[x],d->u[x],e->v[x]}, where p[x] etc are the given polynomials. Of course collecting of terms can be done with Collect[%,x]. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ > I confess I am not 100% sure what you mean. Would you like to do this > in steps, like you would do it by hand? In[1]:= > a + b/c + d*(Sqrt[e]/c) == 0; In[2]:= > Thread[(#1 - a - b/c & )[%], Equal] Out[2]= > (d*Sqrt[e])/c == -a - b/c In[3]:= > Thread[(#1*c & )[%], Equal] Out[3]= > d*Sqrt[e] == (-a - b/c)*c In[4]:= > Thread[(#1^2 & )[%], Equal] Out[4]= > d^2*e == (-a - b/c)^2*c^2 In[5]:= > Simplify[%] Out[5]= > d^2*e == (b + a*c)^2 Of course you can combine all the steps into a single function, but I > think it will be fairly complicated. My own favourite way to do this sort of thing is: In[1]:= > Simplify[d^2*e == (d^2*e /. AlgebraicRules[ > a + b/c + d*(Sqrt[e]/c) == 0, e])] Out[1]= > d^2*e == (b + a*c)^2 However, AlgebraicRules has not been documented since version 4. It > should be possible to do this using PolynomialReduce but it seems to > require the sort of skill only Daniel Lichtblau possesses;) Andrzej Kozlowski > Toyama International University > JAPAN > http://sigma.tuins.ac.jp/~andrzej/ I'm a newbie and, of course, the first thing I want to do is > apparently > one of the most complicated... I have an expression that looks like this: A + B/C + D*Sqrt[E]/C = 0 A,B,C,D, & E are all polynomials in x > I want it to look like this (D^2)*E = (A*C + B)^2 At that point, I'll have polynomials in x on both sides. Finally, I > want the equation to be written out with terms grouped by powers of x, > but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at > least point me to some tutorial in the Mathematica documentation. > I've > been looking over the documentation and I found Appendix A.5 in The > Mathematica Book, but that doesn't help me. I _need_ some examples. I > did find a couple of well-written posts in this newsgroup, but not > quite > close enough to what I want. > Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. > denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] > cnu = (2*b^2 - B^2 + r^2)/denom > snu = -2*b*Sqrt[B^2 - b^2]/denom > sif = 2*r*b/denom > cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + > cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( > r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* > r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in > b > that I'm after. ==== <{-1,5}] ImplicitPlot[x^3y + y^3 == 9, {x, -10, 10}] Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : dim., 6. octobre 2002 11:34 Ë : mathgroup@smc.vnet.net Objet : Plotting ellipses and other functions How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? ==== >How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 > >and > >x^3y + y^3 = 9 > >using Mathematica? > Needs[Graphics`ImplicitPlot`]; ImplicitPlot[(x - 2)^2 + 2(y - 3)^2 == 6, {x, -1, 5}, {y, 1, 5}]; ImplicitPlot[x^3 y + y^3 == 9, {x, -6, 6}, {y, -6, 6}]; Bob Hanlon ==== >Could somebody please inform me how to Round numbers to a >certain Accuracy using Mathematica 4.2. This is not as easy as it >sounds. >Every function that I have read Rounds the Display, and not the actual >number. myRound[x_, n_] := Round[10^n*x]/10.^n; Table[myRound[Random[], 3], {10}] {0.044, 0.019, 0.738, 0.298, 0.917, 0.171, 0.021, 0.314, 0.658, 0.153} Bob Hanlon Reply-To: tgarza01@prodigy.net.mx ==== You might use ImplicitPlot: In[1]:= << Graphics`ImplicitPlot` In[2]:= eqn1 = (x - 2)^2 + 2*(y - 3)^2 == 6; In[3]:= ImplicitPlot[eqn1, {x, -2, 6}]; In[4]:= eqn2 = x^3*y + y^3 == 9; In[5]:= ImplicitPlot[eqn2, {x, -8, 8}]; Tomas Garza Mexico City Original Message: ----------------- ==== You may use Binomial. It could also be useful to look at the AddOn package DiscreteMath`Combinatorica`, where you will find a wealth of interesting things related to that. In[1]:= Binomial[6,2] Out[1]= 15 Tomas Garza Mexico City Original Message: ----------------- ==== > Yes, there seems to be a lot of people who have a visceral hatred for > Microsoft and Windows. They are even willing to shed blood to avoid > Windows. But why? Windows works and you don't have to become a systems > programmer. > > Furthermore, I think that Steven Wolfram uses some version of Windows. So > guess which system Mathematica will be best tuned up for? > > I have no problems with Mathematica and Windows on my single computer. > There may be reasons for using a non-Microsoft operating system. But if > you are going to do it, make certain that they are good reasons. that of Windows XP by orders of magnitude. I recall when I first started been using Windows NT since October of 1992. (Yes, I know it hadn't been paper on the architecture of NT. In 1997 I was well on my way to being an MCSE. no stinkin' GUI' to 'have a look at the KDE project'. I took the latter route. The KDE has gone from a simple graphical desktop with a few more features than the CDE, (and a lot more glitches) to being the best desktop available. It's growth seems to be exponential. Windows seems, at best, to be linear. All of these are usability issues. There is another reason I don't like using Microsoft products. I've also been using Mozilla since 1995. (Yes, it has always been called Mozilla.) I was one of the original beta testers for the Netscape line of internet servers. When I saw what Netscape Communications were aiming for, Windows quickly lost its luster. Netscape products were designed from the ground up with portability in mind. They were striving for uniform functionality across all platforms. I also saw what Microsoft did to undermine Netscape's R & D resources. Microsoft would condescend to having not competition in their market. Where I come from, people don't put up with that. Where do I come from? I was born in Illinois. I'm obviously not of the opinion that closed source is unacceptable. I wouldn't be using Mathematica if I were. I suspect one day Mathematica will face a real open source challeng. Her name is Charolette. She is the mother of Mozilla. That will probably be years from now. WRI need to be prepared to adjust to that eventuality when it comes. > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ STH . ==== I feel as if I've finally had the breakthrough in intuitively understanding the Mathematica editor, or at least the basics. I want to explain to others what they really need to know about the editor to use it for basic purposes. Part of the reason I now understand the editor better is that I've since worked with LyX http://www.devel.lyx.org and XEmacs http://www.xemacs.org, and I've also become proficient with DocBook XML. When I first started using the editor, reading the Mathematica Help didn't seem to help. It seemed to tell me a whole lot more than I needed to know, and didn't tell me what I really needed to know. Now I'm in the position of being able to use it, but not being able to explain exactly what it is I've learned. Is there any documentation directed toward the beginner, which tells him or her what to do, what to expect, what quirks to be aware of, and etc.? I'm looking for something along the lines of click here to make this happen. If you see this, it may seem weird, but that's normal. Those brackedt on the left really mean... . STH . ==== >I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into Mathematica >and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) > >What instructions do I need to execute to achieve this output? > soln = Factor[x^4 + x^3 + x^2 + x + 1, Extension -> GoldenRatio] // Simplify (x^2 - GoldenRatio*x + x + 1)*(x^2 + GoldenRatio*x + 1) soln = Simplify /@ (soln /. -GoldenRatio -> -1 - 1/GoldenRatio) (x^2 - x/GoldenRatio + 1)*(x^2 + GoldenRatio*x + 1) soln // FunctionExpand // FullSimplify x^4 + x^3 + x^2 + x + 1 Bob Hanlon ==== Stefan, I don't think I completely understand your question, but I think you are looking for the Binomial function in Mathematica. Binomial[4, 2] 6 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Steve, You could use the Extension feature of Factor as documented in Help. expr = x^4 + x^3 + x^2 + x + 1 ans = Factor[expr, Extension -> {1/GoldenRatio}] (-(1/4))*(-2 - x + Sqrt[5]*x - 2*x^2)* (2 + x + Sqrt[5]*x + 2*x^2) You could also use... Factor[expr, Extension -> {Sqrt[5]}] It took me some effort to figure out how to manipulate the answer into your form. ans /. {x + Sqrt[5]*x -> (2*GoldenRatio)*x, -x + Sqrt[5]*x -> (2/GoldenRatio)*x} % /. (-4^(-1))*a_*b_ :> Simplify[-a/2]*Simplify[b/2] (-(1/4))*(-2 + (2*x)/GoldenRatio - 2*x^2)* (2 + 2*GoldenRatio*x + 2*x^2) (1 - x/GoldenRatio + x^2)*(1 + GoldenRatio*x + x^2) David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ http://www.harker.org/ ==== David, To plot equations like that, simply use ImplicitPlot. Needs[Graphics`ImplicitPlot`] ImplicitPlot[(x - 2)^2 + 2(y - 3)^2 == 6, {x, -1, 5}, {y, 1, 5}]; ImplicitPlot[x^3*y + y^3 == 9, {x, -10, 10}, {y, -10, 10}]; You may have to fish a little to obtain the appropriate x and y ranges. Start by making them larger and then narrow down to the region that you want. I have put a new package at my web site for solving conic section problems in the plane. You can solve for complete information on any conic section and obtain a parametric representation for plotting it. The package also comes with complete Help documentation and examples. Using your first example (the second is not a conic). Needs[ConicSections`ConicSections`] eqn = (x - 2)^2 + 2(y - 3)^2 == 6; The routine ParseConic will take any quadratic equation and return the scale a, eccentricity e, a parametrization, and rotation matrix P, translation T and reflection matrix R that transforms the conic from standard position to its actual position. (In standard position the conic has its foci and verticies on the x-axis with the center at zero.) {{a, e}, curve[t_], {P, T, R}} = ParseConic[eqn] {{Sqrt[6], 1/Sqrt[2]}, {2 + Sqrt[6]*Cos[t], 3 + Sqrt[3]*Sin[t]}, {{{1, 0}, {0, 1}}, {2, 3}, {{1, 0}, {0, 1}}}} We could then plot the curve using ParametricPlot, which is more efficient and controllable. ParametricPlot[Evaluate[curve[t]], {t, -Pi, Pi}, AspectRatio -> Automatic, Frame -> True, Axes -> None, PlotLabel -> eqn]; Knowing a and e we can use the StandardConic routine to obtain all the information about the conic in standard position as a set of rules. standarddata = StandardConic[{a, e}] {conictype -> Ellipse, conicequation -> x^2/6 + y^2/3 == 1, coniccurve -> {Sqrt[6]*Cos[t], Sqrt[3]*Sin[t]}, coniccurvedomain -> {-Pi, Pi}, coniccenter -> {0, 0}, conicfocus -> {{Sqrt[3], 0}, {-Sqrt[3], 0}}, conicdirectrix -> {x == -2*Sqrt[3], x == 2*Sqrt[3]}, conicvertex -> {{Sqrt[6], 0}, {-Sqrt[6], 0}}} routine to obtain the same information for the conic in its actual position. standarddata // TransformEllipseRules[P, T, R] {conictype -> Ellipse, conicequation -> (1/6)*((-2 + x)^2 + 2*(-3 + y)^2) == 1, coniccurve -> {2 + Sqrt[6]*Cos[t], 3 + Sqrt[3]*Sin[t]}, coniccurvedomain -> {-Pi, Pi}, coniccenter -> {2, 3}, conicfocus -> {{2 + Sqrt[3], 3}, {2 - Sqrt[3], 3}}, conicdirectrix -> {2*Sqrt[3] + x == 2, x == 2*(1 + Sqrt[3])}, conicvertex -> {{2 + Sqrt[6], 3}, {2 - Sqrt[6], 3}}} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: ==== Try this: A + B/C + D*(Sqrt[E]/C) == 0 (#1 - %[[1,{1, 2}]] & ) /@ % (C*#1 & ) /@ % (#1^2 & ) /@ % Simplify[%] Also, be aware that E is the natural logarithm base, reserved for that purpose. DrBob -----Original Message----- want the equation to be written out with terms grouped by powers of x, but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at least point me to some tutorial in the Mathematica documentation. I've been looking over the documentation and I found Appendix A.5 in The Mathematica Book, but that doesn't help me. I _need_ some examples. I did find a couple of well-written posts in this newsgroup, but not quite close enough to what I want. Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] cnu = (2*b^2 - B^2 + r^2)/denom snu = -2*b*Sqrt[B^2 - b^2]/denom sif = 2*r*b/denom cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b that I'm after. Reply-To: ==== It's a little ugly, but here's my solution: x^4 + x^3 + x^2 + x + 1 Simplify@Factor[%, Extension -> {GoldenRatio, 1/GoldenRatio}] Collect[%[[2]]/3, x]Collect[%[[3]]/3, x] % /. Sqrt[5] -> 2GoldenRatio - 1 % // Simplify Collect[#, x] & /@ % % /. {1 - GoldenRatio -> -1/GoldenRatio} FullSimplify@Expand@% (The last line is a check.) Bobby -----Original Message----- (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth Harker School http://www.harker.org/ ==== >How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 > >and > >x^3y + y^3 = 9 > >using Mathematica? Use ImplicitPlot in the package Graphics`ImplicitPlot` ==== David, <{0,0}] -----Original Message----- Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: jcd@q-e-d.org ==== I look for a way to right align entries output by MatrixForm. There is an ad hoc option, but I haven't figured out how it is supposed to work in Mathematica 4.0 (if it works at all). m={{MatrixForm[{0,0,0}],-123456789},{123456789,1}}; MatrixForm[m,TableAlignments->{Right,Top}] appears identical to MatrixForm[m] (with no SetOptions override) Strangely, Mathematica doesn't complain if you input ill options like: MatrixForm[m,TableAlignments->{WhateverIsIllegal,Right,Top,MakeSomeSpiralOfI t}] In Mathematica 2.2x, the behavior is rather strange: one option alone works, but when two are given (e.g. {Right,Top}), only the last seems to be acted upon. I didn't bother to try hard with the older version, so don't flame me if I'm wrong. At the other hand, when a TableAlignments->Right is given to TableForm, entries are right-aligned correctly. Can someone provide a way out (even a slow external module) or tell me how to use this option. I apologize for using a phony address in an attempt ==== I decided to export one of my notebooks to html/mathml http://baldur.globalsymmetry.com/proprietary/com/wri/notebooks/essential/ 66.92.149.152 baldur.globalsymmetry.com When I try to view it with Mozilla, I get a '?' in place of the imaginary number symbol. When I first load the page with Mozilla, I get an error telling me To properly display the MathML on this page you need to install the following fonts: CMSY 10, CMEX 10, Math1, Math2, Math4. For further infromation see: http://www.mozilla.org/projects/mathml/fonts I did what the instructions at the URL told me, and I still get the error. I looked through the fonts in the Mathematica font directory, and I found: Mathematica1Mono.9.bdf -wri-mathematica1mono-medium-r-normal--9-90-75-75-m-50-adobe-fontspecific Mathematica3.12.bdf -wri-mathematica3-medium-r-normal--12-120-75-75-p-70-adobe-fontspecific Mathematica3.24.bdf -wri-mathematica3-medium-r-normal--24-240-75-75-p-130-adobe-fontspecific Mathematica3.36.bdf -wri-mathematica3-medium-r-normal--36-360-75-75-p-210-adobe-fontspecific .... Mathematica7.12.bdf -wri-mathematica7-medium-r-normal--12-120-75-75-p-40-adobe-fontspecific Mathematica7.24.bdf .... -wri-mathematica6-medium-r-normal--12-120-75-75-p-30-adobe-fontspecific Mathematica6.24.bdf -wri-mathematica6-medium-r-normal--24-240-75-75-p-70-adobe-fontspecific Mathematica6.36.bdf -wri-mathematica6-medium-r-normal--15-150-75-75-p-50-adobe-fontspecific Mathematica5.12.bdf -wri-mathematica5-medium-r-normal--12-120-75-75-p-50-adobe-fontspecific Mathematica5.24.bdf -wri-mathematica5-medium-r-normal--24-240-75-75-p-110-adobe-fontspecific Mathematica5.36.bdf -wri-mathematica5-medium-r-normal--36-360-75-75-p-160-adobe-fontspecific Mathematica5.13.bdf -wri-mathematica5-medium-r-normal--13-130-75-75-p-50-adobe-fontspecific Mathematica4.18.bdf -wri-mathematica4-medium-r-normal--18-180-75-75-p-130-adobe-fontspecific Mathematica5.10.bdf .... I suspect this is what mozilla is looking for, but I don't know exactly how to tell it as much. Any ideas? STH . Reply-To: ==== I suppose my silliness is understandable, in light of all the confusion, both here and in the Browser on what significance arithmetic is, what bignums and bigfloats might be, etc. If many smart people are confused, there's a possibility --- just a possibility, mind you --- that it isn't entirely their fault. Yes? No? >>like 71 above, or -5 for Accuracy in the example that fooled me), but it's not a big deal For people who don't understand it as well as you, yes, it's a big deal. My purpose in all this is to understand the issue well enough to know how to proceed. I think that I do, now, but I doubt everybody on the list does. Daniel says this will all be clearer in the next release, and that's good! Bobby -----Original Message----- -1.180591620717411303424`71.0721*^21 > 71 71.0721 digits of precision? I don't think so!! Either I am it altogether or you are just simply beating to death the point that in case of machine arithmetic (only!) Precision and Accuracy are purely formal and essentially meaningless. One can argue whether in this case there is any point of returning any value for Precision, or Accuracy (like 71 above, or -5 for Accuracy in the example that fooled me), but it's not a big deal and it most certainly does not make SetPrecision meaningless. On the contrary, SetPrecision is very useful and in fact it is SetPrecision that can tell you that the answer above is meaningless: In[8]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 50]; a=SetPrecision[77617.,$MachinePrecision]; b = SetPrecision[ 33096.,$MachinePrecision]; In[10]:= {f,Precision[f]} Out[10]= {1.19801754103509`0*^19, 0} I would say this is correct and show that SetPrecision is very useful indeed. It tells you (what of course you ought to already know in this case anyway) that machine precision will not give you a realiable answer in this case. If you know your numbers with a great deal of accuracy you can get an accurate answer: In[24]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; a=SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; In[26]:= {f, Precision[f]} Out[26]= {-0.82739605994682136814116509547981629199903311578438481991 781484167246798617832`61.2597, 61} Again you can be pretty sure that you got an accurate answer, provided of course your original setting of precision was valid. Honestly, to say that SetPrecision and SetAccuaracy are useless is one of the silliest thing I have read on this list in years. > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? Reply-To: kuska@informatik.uni-leipzig.de ==== look what Graphics`ImplicitPlot` does. Jens > > How can I plot functions like: > > (x-2)^2 + 2(y-3)^2 = 6 > > and > > x^3y + y^3 = 9 > > using Mathematica? ==== David: For a start you can try the following: Using ContourPlot ContourPlot[(x - 2)^2 + 2(y - 3)^2 - 6, {x, -1, 5}, {y, -1, 5}, Contours -> {0}, ContourShading -> False, ContourSmoothing -> 5] Or using ImplicitPlot << Graphics`ImplicitPlot` ImplicitPlot[(x - 2)^2 + 2(y - 3)^2 == 6, {x, -1, 5}] ImplicitPlot[x^3y + y^3 == 9, {x, -4, 4}] Hans > How can I plot functions like: (x-2)^2 + 2(y-3)^2 = 6 and x^3y + y^3 = 9 using Mathematica? ==== Try reading help under the keyword ImplicitPlot | How can I plot functions like: | | (x-2)^2 + 2(y-3)^2 = 6 | | and | | x^3y + y^3 = 9 | | using Mathematica? | | | | ==== David Enquire within the Help Browser for the ImplicitPlot package and all will be revealed. For example, I snipped the following lines from the documentation: << Graphics`ImplicitPlot` ImplicitPlot[x^2 + 2 y^2 == 3, {x, -2, 2}] Hope this is of sufficient help to get you started - post again if you have any further questions. Mark Westwood > > How can I plot functions like: > > (x-2)^2 + 2(y-3)^2 = 6 > > and > > x^3y + y^3 = 9 > > using Mathematica? ==== you can. Use: < >I am facing the problem in starting the link to math kernel from within >Excel. > >Specifically, when I get the message link failed to open when I click >Launch button in the 'Start Mathematica Link' dialog box. I have tried using >Multilink too so that I am able to access the kernel from Mathematica and >Excel simultaneously but I still get the same message. > >I am currently using Mathematica 4.0 and Excel 2002 (Excel XP). The programs >Mathematica and Excel otherwise appear to work fine. I am using Windows XP >home edition on Dell 8100 laptop. I have used the Mathematica Link for MS >Excel for Excel 2000 in my installation as there were no specific files for >Excel 2002. Given that I was able to successfully add the menus within excel >I think the addin should work fine but it does not? > >All help would be sincerely appreciated. > >Sincerely, > >Tahir Sheikh. ==== I did not request any accuracy for f. I set the accuracy of the numerical components of the expression f. You cannot request the accuracy of the result of your computation in Mathematica, you can only set the accuracy of the input and later check what accuracy of the output results form it. In my last message on this topic I tried to explain this in the plainest and simplest way I could think of. There is nothing more left for me to say. I feel like Sisyphus but unlike him I can at least give up! Andrzej Kozlowski [...] I would say this is correct and show that SetPrecision is very useful > indeed. It tells you (what of course you ought to already know in this > case anyway) that machine precision will not give you a realiable > answer in this case. If you know your numbers with a great deal of > accuracy you can get an accurate answer: In[24]:= > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > a=SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; > In[26]:= > {f, Precision[f]} Out[26]= > {-0.82739605994682136814116509547981629199903311578438481991 > 781484167246798617832`61.2597, 61} > Congratulations! You just requested accuracy of 100 for f and got 61 ( > to convince yourself add Accuracy[f] to In[26]). If In[24] one > replaces SetAccuracy by SetPrecision the result is similar. PK Again you can be pretty sure that you got an accurate answer, provided > of course your original setting of precision was valid. Honestly, to say that SetPrecision and SetAccuaracy are useless is one > of the silliest thing I have read on this list in years. Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== > > >[...] > > I would say this is correct and show that SetPrecision is very useful > indeed. It tells you (what of course you ought to already know in this > case anyway) that machine precision will not give you a realiable > answer in this case. If you know your numbers with a great deal of > accuracy you can get an accurate answer: > > In[24]:= > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > a=SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; > > In[26]:= > {f, Precision[f]} > > Out[26]= > {-0.82739605994682136814116509547981629199903311578438481991 > 781484167246798617832`61.2597, 61} > > Congratulations! You just requested accuracy of 100 for f and got 61 ( > to convince yourself add Accuracy[f] to In[26]). If In[24] one > replaces SetAccuracy by SetPrecision the result is similar. > > PK > [...] One has (initially) an accuracy of 100 for an expression that contains variables. In[25]:= Clear[a,b,f] In[26]:= 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]; In[27]:= Accuracy[f] Out[27]= 100. Now we assign values to some indeterminants in f. In[28]:= a = SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; In[29]:= {f, Precision[f], Accuracy[f]} Out[29]= {-0.8273960599468213681411650954798162919990331157843848199178148, 61.2599, 61.3422} The precision and accuracy has dropped. This is all according to standard numerical analysis regarding cancellation error. You'll find it in any textbook on the topic. As for what happens when you artificially raise precision (or accuracy) of machine numbers far beyond that guaranteed by their internal representation, that falls into to category of garbage in, garbage out. It is, howoever, valid to use SetPrecision to raise precision in (typically iterative) algorithms where significance arithmetic might be unduly pessimistic due to incorrect assumptions about uncorollatedness of numerical error. Examples of such usage have appeared in this news group. Daniel Lichtblau Wolfram Research ==== > >[...] > > I would say this is correct and show that SetPrecision is very useful > indeed. It tells you (what of course you ought to already know in this > case anyway) that machine precision will not give you a realiable > answer in this case. If you know your numbers with a great deal of > accuracy you can get an accurate answer: > > In[24]:= > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > a=SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; > > > In[26]:= > {f, Precision[f]} > > Out[26]= > {-0.82739605994682136814116509547981629199903311578438481991 > 781484167246798617832`61.2597, 61} > Congratulations! You just requested accuracy of 100 for f and got 61 ( to convince yourself add Accuracy[f] to In[26]). If In[24] one replaces SetAccuracy by SetPrecision the result is similar. PK > Again you can be pretty sure that you got an accurate answer, provided > of course your original setting of precision was valid. > > Honestly, to say that SetPrecision and SetAccuaracy are useless is one > of the silliest thing I have read on this list in years. > > > Andrzej Kozlowski > Yokohama, Japan > http://www.mimuw.edu.pl/~akoz/ > http://platon.c.u-tokyo.ac.jp/andrzej/ ==== > You are entitled to your opinion. For my applications > this behavior IS useless. > I agree that Mathematica is probably useless for you. This is however not because it is useless or useless for your application, but because to use its full power you have to study it, understand it, and in particular, for numerical work, understand the model of arithmetic it uses. Lie with mathematics they are really no shortcuts that will lead you to its full power. In addition, since it is a computer program, it has certain conventions, which may not be the same as the conventions of other programs (they all have conventions) but which you have to accept to be able to use it. Now, once you have done that, you may still not like the way Mathematica does things and there are genuine experts in numerics who indeed do not like and are quite vocal about it. But they never say it is useless, because by saying that you are either displaying your own ignorance or engaging in stupid and pointless abuse. On a more serious level, there seem to be two basic approaches to numeric computation relevant to this discussion. It seems to me (though I am no expert in this sort of thing) that there are three types of situations that one may encounter. Firstly, there is the vast majority of rather simple computations for which built-in machine floating point arithmetic , which carries no guarantee of precision at all is meant for. It clearly must be sufficient for the majority of purposes, since most general purpose and even technical software available uses not other method. The reason of course is that it is by far the fastest way to do such computations (as well as being sufficient for most situations). The second type of situation is when you actually know the precision of your input and would like the program to give you some idea about the precision of the output you might expect. This is the most likely situation in empirical science and is exactly what SetPrecision is meant for. Most reasonable people would agree that Mathematica works well in this situation. There is finally one more situation, to which the only reasonable criticism that I have read in this thread appears to be directed at. That is the situation when you actually know your input exactly, but working with exact numbers is far too slow. So what you have to do is to replace your exact numbers with inexact ones padded with 0's. In Mathematica you have to take a guess at how much padding you will need, than use SetPrecision to pad the numbers, and then check the Precision of your answer. It may turn out that you did not get as much precision as you needed, in which case you have to use more zeros. Or it may be that you used more than enough, which mans that your computation could have been done faster. I learned from Leszek Sczaniecki that there is an approach due to Oliver Aberth which lets you only specify the desired precision of your answer and the program itself will choose the correct padding for your input. It woudl ertainly be nice to have this ability, but I honestly think that it would be only of marginal advantage over making your own guess. It seems to me that the checking that the Aberth mthod must require will be time consuming and wiht a bit of practice one can probably get better results as far as speed is concerned using the Mathematica approach. But this is just pure speculation and certainly it woudl be nice if such a possibility existed. Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/~andrzej/ Reply-To: ==== Here's a more intuitive method, perhaps: a + b/c + d*(Sqrt[e]/c) == 0 f = %[[1, 3]] %% /. f -> g First@Solve[%, g] f^2 == (g^2 /. %) However, it occurs to me you might want a more general method to collect a radical on one side and then square both sides. If so, here's a clumsy first attempt: expr = a + b/c + d*(Sqrt[e]/c) == 0 f = First@Cases[expr, Power[a_, Rational[b_, c_]], Infinity] power = First@Cases[f, Rational[b_, c_] -> Rational[c, b], Infinity] coefficient = First@Cases[expr, Times[a_, f] -> a, Infinity] Solve[expr /. coefficient f -> g, g][[1, 1]] g^2 == (g^2 /. %) % /. g -> coefficient f DrBob -----Original Message----- DrBob -----Original Message----- want the equation to be written out with terms grouped by powers of x, but I think I can do that part :) I'll be very grateful to anyone who can give me some pointers. Or, at least point me to some tutorial in the Mathematica documentation. I've been looking over the documentation and I found Appendix A.5 in The Mathematica Book, but that doesn't help me. I _need_ some examples. I did find a couple of well-written posts in this newsgroup, but not quite close enough to what I want. Troy. =-=-=-=-=-=-=-=-=-= FYI, here's the expression I'm working with. denom = Sqrt[(B^2 - r^2)^2 + 4*(r^2)*(b^2)] cnu = (2*b^2 - B^2 + r^2)/denom snu = -2*b*Sqrt[B^2 - b^2]/denom sif = 2*r*b/denom cif = (r^2 - B^2)/denom pdr = -Cos[ds]*Sin[q]*(snu*cif + cnu*sif) - Sin[ds]*(cnu*cif - snu*sif) 0 == -(B^2 - b^2)*V^2/(r^2) + (((B*V)^2)/( r^2) - 2*w*b*V*Cos[q]*Cos[ds] + (w* r)^2 - (w*r*pdr)^2)*(Cos[qr])^2 Although I said it's a polynomial in x, it's really a polynomial in b that I'm after. ==== > > On Friday, October 4, 2002, at 06:01 PM, DrBob > >[...] > > I would say this is correct and show that > SetPrecision is very useful > indeed. It tells you (what of course you ought > to already know in this > case anyway) that machine precision will not > give you a realiable > answer in this case. If you know your numbers > with a great deal of > accuracy you can get an accurate answer: > > In[24]:= > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - > b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > a=SetPrecision[77617.,100]; b = > SetPrecision[33096.,100]; > > > In[26]:= > {f, Precision[f]} > > Out[26]= > {-0.82739605994682136814116509547981629199903311578438481991 > 781484167246798617832`61.2597, 61} > > > Congratulations! You just requested accuracy of > 100 for f and got 61 ( > to convince yourself add Accuracy[f] to In[26]). > If In[24] one > replaces SetAccuracy by SetPrecision the result is > similar. > > PK > [...] > > One has (initially) an accuracy of 100 for an > expression that contains > variables. > > In[25]:= Clear[a,b,f] > > In[26]:= 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]; > > In[27]:= Accuracy[f] > Out[27]= 100. > > Now we assign values to some indeterminants in f. > > In[28]:= a = SetPrecision[77617.,100]; b = > SetPrecision[33096.,100]; > > In[29]:= {f, Precision[f], Accuracy[f]} > Out[29]= > {-0.8273960599468213681411650954798162919990331157843848199178148, > > 61.2599, 61.3422} > > The precision and accuracy has dropped. This is all > according to > standard numerical analysis regarding cancellation > error. You'll find it > in any textbook on the topic. > Assume that I want accuracy and precision of 100 for f. You advice me to make experiments to find out, what should be the initial precision and accuracy of a and b to reach the requested accuracy and precision for f. Notice, that you cannot just repeat I[26], we saw already what happens. I have to re-type I[24], I[25], I[26], I[27], I[28], and I[29] as many times as needed to get f with accuracy and precision 100. Dan, you simply advocate to do MANUAL WORK that should be done by machine. Let's suppose that in the above example I just want 60 digits not 61. Precisely, I want 60 digits and nothing or zeros afterwards. Let's see if I could use SetAccuracy. In[30]:= SetAccuracy[%, 60] Out[30]= -0.82739605994682136814116509547981629199903311578438481991781 In[31]:= % // FullForm Out[30]//FullForm= -0.827396059946821368141165095479816291999033115784384819917814841672467988` 59.9177 Oops, it did not work (as expected). Let's highlight with mouse the expression in Out[30] and copy to a new cell. Oops, we got -0.827396059946821368141165095479816291999033115784384819917814841672467988` 59.9177 again. Let's change Out[30] to a text cell and then copy. In[31]:= -0.82739605994682136814116509547981629199903311578438481991781 Out[31]= -0.82739605994682136814116509547981629199903311578438481991781 Success? Not so fast. In[32]:= % // FullForm Out[32]//FullForm= -0.8273960599468213681411650954798162919990331157843848199178099999999999986 35 08`59.2041 Dan, is there any simple way to get what I want? As I repeated already number of times, at this stage of the development of computer technology, software should do it for me (!). We both know that this is doable. Some of the textbooks that you just advised me to read describe it. As a developer of Mathematica, tell us why do you consider this to be a bad idea? Peter Kosta > As for what happens when you artificially raise > precision (or accuracy) > of machine numbers far beyond that guaranteed by > their internal > representation, that falls into to category of > garbage in, garbage out. > It is, howoever, valid to use SetPrecision to raise > precision in > (typically iterative) algorithms where significance > arithmetic might be > unduly pessimistic due to incorrect assumptions > about uncorollatedness > of numerical error. Examples of such usage have > appeared in this news > group. > > > Daniel Lichtblau > Wolfram Research __________________________________________________ Do you Yahoo!? http://faith.yahoo.com ==== > Are there any known issues with simpy treating the JLink.jar as a Java > extension as follows? > cp JLink.jar $JAVA_HOME/jre/lib/ext? > According to my understanding of the discussion in the Java Tutorial on > extensions, that should work: It does; starting with M4.2, J/Link 2.0 gets preinstalled and comes with a 1.4 murphee ==== Are there any known issues with simpy treating the JLink.jar as a Java extension as follows? cp JLink.jar $JAVA_HOME/jre/lib/ext? According to my understanding of the discussion in the Java Tutorial on extensions, that should work: http://java.sun.com/docs/books/tutorial/ext/basics/install.html Commants? STH . ==== >Are there any known issues with simpy treating the JLink.jar as a Java >extension as follows? >cp JLink.jar $JAVA_HOME/jre/lib/ext? > >According to my understanding of the discussion in the Java Tutorial on >extensions, that should work: >http://java.sun.com/docs/books/tutorial/ext/basics/install.html > >Commants? You should not do this. Code from the jre/lib/ext directory is trusted, so this poses a security risk from malicious applets. Leave JLink.jar where it lives in the JLink directory. If you want it to be available to all Java programs on your system, add its location to your CLASSPATH environment variable (this is not a security risk, as remote applets cannot load classes from CLASSPATH). Todd Gayley Wolfram Research ==== The key is in using the command Factor with the option Extension: In[1]:= Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio}] Out[1]= -((-1 - x + GoldenRatio*x - x^2)*(1 + GoldenRatio*x + x^2)) For manual verification you should keep in mind that: 1/GoldenRatio = GoldenRatio - 1 Germ.87n Buitrago ----- Original Message ----- > (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ > ==== Actually, including 1/GoldenRatio in the extension leads to an unnecessarily complicated formula. In this case there is no real need to so, since by definition In[30]:= Unevaluated[1/GoldenRatio==GoldenRatio-1]//FullSimplify Out[30]= True If one really insists on having the answer in the form proposed in Steve's original posting one can simply do: (Collect[#1, x] & ) /@ Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio}] /. -1 + GoldenRatio -> 1/GoldenRatio (-(-1 + x/GoldenRatio - x^2))*(1 + GoldenRatio*x + x^2) In[]:=Factor[x^4 + x^3 + x^2 + x + 1, Extension -> {GoldenRatio, > 1/GoldenRatio}] > Out[]=-((-3 - 2*x + Sqrt[5]*x + GoldenRatio*x - 3*x^2)* > (3 + x + Sqrt[5]*x + GoldenRatio*x + 3*x^2))/9 Jens > Greetings MathGroup, My name is Steve Earth, and I am a new subscriber to this list and > also a > new user of Mathematica; so please forgive this rather simple > question... I would like to enter the quartic x^4 + x^3 + x^2 + x + 1 into > Mathematica > and have it be able to tell me that it factors into (x^2 + GoldenRatio x + 1) ( x^2 - 1/GoldenRatio x + 1) What instructions do I need to execute to achieve this output? -Steve Earth > Harker School > http://www.harker.org/ > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== I want to apply a function to every k-th element of a long list and add the result to the k+1 element. [Actually k = 3 and I just want to multiply myList[[k]] by a constant (independent of k) and add the result to myList[[k+1]] for every value of k that's divisible by 3.] Is there a way to do this -- or in general to get at every k-th element of a list -- that's faster and more elegant than writing a brute force Do[] loop or using Mod[] operators, and that will take advantage of native List operators, but still not be too recondite? I've been thinking about multiplying a copy of myList by a mask list {0,0,1,0,0,1,..} to generate a masked copy and approaches like that. Better ways??? ==== How can I run mathematica program in background? Is there any way similar to fortran or c where one can runs his program in the background? Please suggest. Raj Reply-To: kuska@informatik.uni-leipzig.de ==== math < someresults.m & ??? BTW this is a problem of your operating system and not of Mathematica. Jens > > > How can I run mathematica program in background? Is there any way > similar to fortran or c where one can runs his program in the > background? > > Please suggest. > > Raj ==== First define the functions z[x_] := x^2 + 4; y1[x_] := 4 - x^2; y2[x_] := 3x; Figure out where the y limits coincide: Solve[y1[x] == y2[x], x] {{x -> -4}, {x -> 1}} Which is bigger in between? y1[0] - y2[0] 4 y1 is. Confirm that with a plot. (y2 is linear): Plot[{y1[x], y2[x]}, {x, -5, 5}] Next figure out where z is zero: Solve[z[x] == 0, x] {{x -> -2*I}, {x -> 2*I}} It's never zero for real x, but is it positive, or negative? z[0] 4 Look at the plot, just for fun: Plot[{z[x]}, {x, -4, 1}] z is positive for all x (but only the interval [-4,1] MATTERS). The volume you want, therefore, is Integrate[z[x]*(y1[x] - y2[x]), {x, -4, 1}] 625/4 or: g[x_] = Integrate[z[x]*(y1[x] - y2[x]), x] g[1] - g[-4] 16*x - 6*x^2 - (3*x^4)/4 - x^5/5 625/4 Bobby Treat -----Original Message----- Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: kuska@informatik.uni-leipzig.de ==== you mean: In[]:=Needs[Calculus`Integration`] Integrate[Boole[x^2 + 4 - z > 0 && 4 - x^2 - y > 0 && 3 - x - y < 0 && z > 0], {x, -1, 2}, {y, 1, 5}, {z, -1, 10}]] Out[]=(15*Sqrt[5])/4 and to plot the volume: In[]:=Get[MathGL3d`OpenGLViewer`] In[]:=MVContourPlot3D[ If[1 == Boole[x^2 + 4 - z > 0 && 4 - x^2 - y > 0 && 3 - x - y < 0 && z > 0], 1., -1.], {x, -1, 2}, {y, 1, 5}, {z, -0.1, 7}, Contours -> {0.}, PlotPoints -> 64, MVNewScene -> True] Jens > > First of all, I would like to thanks to all for trying to help. > Sorry, I must have something missing in my previous description. > > I need to find out the volumn of a 3D object which form by the equation : > z=x^2 +4 (as bottom surface) > and on the xy plane which bounded by a parabola y=4-x^2 and y=3x line. > > How would I use Mathematica to plot out this 3D object or find out its volumn > with only the equation given? > > Shz Shz > > ============================================================================= ===== > > of the individual or entity to which they are addressed. Any disclosure, copying, > distribution and diversion contrary to the applicable export control laws and > regulations including US Export Administration Regulations is strictly prohibited. > > and do not disclose it to others. Please notify the postmaster@hitachi.com.my > of the delivery error by replying to this message and then delete it from your > ============================================================================= ===== ==== Constantine, If you break your problem up into two cases, even n and odd n, then Mathematica can sum up your problem and get results, albeit with hypergeometric functions. Consider the following (make sure you look at this with a fixed font): In[21]:= evenans = Sum[Binomial[2*n, k]*p^(2*n - k)*(1 - p)^k, {k, 0, n - 1}]; In[22]:= PowerExpand[FunctionExpand[FullSimplify[evenans, n [Element] Integers]]] Out[22]= 2 n n n 1 p - 1 2 (1 - p) p Gamma[n + -] Hypergeometric2F1[1, -n, n + 1, -----] 2 p 1 - -------------------------------------------------------------------- Sqrt[Pi] Gamma[n + 1] In[23]:= oddans = Sum[Binomial[2*n + 1, k]*p^(2*n + 1 - k)*(1 - p)^k, {k, 0, n - 1}]; In[24]:= PowerExpand[FunctionExpand[FullSimplify[oddans, n [Element] Integers]]] Out[24]= 2 n + 1 n n + 1 3 p - 1 2 (1 - p) p Gamma[n + -] Hypergeometric2F1[1, -n - 1, n + 1, -----] 2 p 1 - ------------------------------------------------------------------------ -------- Sqrt[Pi] Gamma[n + 2] Is this what you were looking for? Carl Woll Physics Dept U of Washington > I want to get some F and R such that: F[n,p] + R[n,p] = Sum[Binomial[n,k] p^(n-k) (1-p)^k, {k, 0, Floor[n/2] - 1}], > when F[n,p] is an approximation to the sum and the R is the remaining error. Constantine. > >>I'm looking for a way of finding the approximation for partitial binomial >>sum. >>I'll be pleasant for any hint.. > >Use the standard add-on package Statistics`NonlinearFit` to do a >NonlinearFit to whatever model you want to use for the approximation. > >Bob Hanlon >Chantilly, VA USA Constantine Elster > Computer Science Dept. > Technion I.I.T. > Office: Taub 411 ==== Can someone provide me more information on how ListIntegrate works than what is contained in the version 4 manual ? Is there a website perhaps or tutorial ? I would like to know how the beginning and end of a list of {x,y} pairs that is being integrated is dealt with by ListIntegrate. I know a series of polynomials is somehow used but how ? Do these overlap ? Are they piecewise continuous ? Are these polynomials available for inspection ? How do they change as a function of k ? optimum k value for a given list ? For any given list, will accuracy monotonically increase with increasing values of k ? Is there anything in the Option Inspector that could cause unexpected behaivor with ListIntegrate ? Are there any good rules of thumb or procedures that will help ensure a reasonable answer is produced ? Is there a way of estimating the error or accuracy of integration performed by ListIntegrate ? ==== Be sure to note the following and what comes after it near the end of the Help Browser info on ListIntegrate: ``This package has been included for compatibility with previous versions of Mathematica. The functionality of this package has been superseded by improvements made to InterpolatingFunction. In other words, ListIntegrate is a dinosaur that you don't need at all! To integrate a list of data with Mathematica, one can proceed in either of two ways: (1) Construct an interpolating function and use NIntegrate (or, better, NIntegrateInterpolatingFunction) on that (which is what ListIntegrate apparently does); or (2) apply a simple routine that implements the trapezoidal rule, Simpson's rule, or maybe some higher order method. Assuming you've chosen to take path #1, you need to realize the following: (a) NIntegrate[Interpolation[data, InterpolationOrder->1][x], {x,a,b}] is equivalent to the trapezoidal rule; (b) NIntegrate[Interpolation[data, InterpolationOrder->2][x], {x,a,b}] is *not* equivalent to Simpson's rule (because of the peculiar way that Interpolation works); (c) Interpolation[data, InterpolationOrder->k] generally does not return a smooth function unless you set InterpolationOrder->n-1, where n is the number of data points, which is the case where a single polynomial of degree n-1 fits the data points. (d) If you want to integrate a smooth interpolant, you can do this: <k][x], {x, 0, 5}, PlotRange -> All], {k, 1, 6}] (The last of those plots will give a warning message.) Having said all that, you really should consider path #2 instead. Here are a couple of links to a MathGroup discussion of last July (somehow the thread got split up): http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00490.html http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00519.html I hope all this helps some. ---- Selwyn Hollis > Can someone provide me more information on how ListIntegrate works > than what is contained in the version 4 manual ? Is there a website > perhaps or tutorial ? > > I would like to know how the beginning and end of a list of {x,y} > pairs that is being integrated is dealt with by ListIntegrate. > > I know a series of polynomials is somehow used but how ? Do these > overlap ? Are they piecewise continuous ? > > Are these polynomials available for inspection ? How do they change as > a function of k ? > > optimum k value for a given list ? For any given list, will accuracy > monotonically increase with increasing values of k ? Is there > anything in the Option Inspector that could cause unexpected behaivor > with ListIntegrate ? > > Are there any good rules of thumb or procedures that will help ensure > a reasonable answer is produced ? > > Is there a way of estimating the error or accuracy of integration > performed by ListIntegrate ? > > > > ==== I timed Daniel's three solutions and Gary's one (plus a couple of my own a little later): perps1[v_] := If[v[[1]] == v[[2]] == 0, {{1, 0, 0}, {0, 1, 0}}, {{v[[2]], -v[[ 1]], 0}, Cross[v, {v[[2]], -v[[1]], 0}]}] perps2[v_] := With[{vecs = NullSpace[{v}]}, {vecs[[ 1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]}] perps2C = Compile[{{v, _Real, 1}}, Module[{vecs = NullSpace[{v}]}, { vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]}]] helzer[v : {a1_, a2_, a3_}] := With[{w = First[Sort[{{a2, -a1, 0}, {a3, 0, -a1}, {0, a3, -a2}}, OrderedQ[{Plus @@ Abs[#2], Plus @@ Abs[#1]}] &]]}, {w, Cross[v, w]}] vecs = Table[Random[], {10000}, {3}]; Timing[perps1 /@ vecs; ] Timing[perps2 /@ vecs; ] Timing[perps2c /@ vecs; ] Timing[helzer /@ vecs; ] {1.7350000000000012*Second, Null} {0.5619999999999994*Second, Null} {0.219 Second, Null} {2.7349999999999994*Second, Null} I made a small change to Daniel's perps1, and got a solution as fast as perps2c, WITHOUT compiling. Compiling tripled the speed again, so treatC is the fastest solution I've seen so far. treat[{a_, b_, c_}] := If[a == b == 0, {{1, 0, 0}, {0, 1, 0}}, {{b, -a, 0}, {a*c, b*c, -a^2 - b^2}}] treatC = Compile[{{v, _Real, 1}}, If[v[[1]] == v[[2]] == 0, {{1, 0, 0}, {0, 1, 0}}, {{v[[2]], -v[[1]], 0}, {v[[1]]*v[[3]], v[[2]]*v[[3]], -v[[1]]^2 - v[[2]]^2}}]] vecs = Table[Random[], {10000}, {3}]; Timing[perps2c /@ vecs; ] Timing[helzer /@ vecs; ] Timing[treat /@ vecs; ] Timing[treatC /@ vecs;] {0.2190000000000083*Second, Null} {2.7339999999999947*Second, Null} {0.25*Second, Null} {0.07800000000000296*Second, Null} None of these solutions reliably return normalized vectors. Bobby Treat -----Original Message----- > pose the problem to MathGroup. Who has the most elegant Mathematica > routine... > > OrthogonalUnitVectors::usage = OrthogonalUnitVectors[v:{_,_,_}] will return > two unit vectors orthogonal to each other and to v. > > You can assume that v is nonzero. > > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ Some possibilities: perps1[v_] := If [v[[1]]==v[[2]]==0, {{1,0,0},{0,1,0}}, {{v[[2]],-v[[1]],0}, Cross[v,{v[[2]],-v[[1]],0}]} ] perps2[v_] := With[{vecs=NullSpace[{v}]}, {vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]} ] This appears to be 2-3 times faster than perps1 for vectors of machine reals. I get another factor of 2 using Compile, which is appropriate for e.g. graphics use. perps2C = Compile[{{v,_Real,1}}, Module[{vecs=NullSpace[{v}]}, {vecs[[1]], vecs[[2]] - (vecs[[2]].vecs[[1]])*vecs[[1]]} ]] In[61]:= vecs = Table[Random[], {10000}, {3}]; In[62]:= Timing[p2 = Map[perps1C,vecs];] Out[62]= {0.49 Second, Null} This is on a 1.5 GHz processor. Daniel Lichtblau Wolfram Research ==== >I was wondering if there is a method for resizing Raster graphics >(resizing the actual matrix of pixels, not just the display size). I >am processing a large number of JPEG images, and we sometimes need to >reduce the image size to allow data processing algorithms to function >without running out of memory. In the past we simply used a program >such as Photoshop to resize them before importing them into >Mathematica. Due to the number of images we are processing now this >is very inconvenient and it would be very useful if there was a method >for accomplishing it in Mathematica, but I can't find one. I also >thought about doing something simple like sampling every few pixels or >averaging, but I thought there might be a method with more efficacy >than this. I also tried exporting the graphics with the Export command >as new JPEGs and manipulating the ImageResolution and ImageSize >options but this seemed to have no effect. Any help would be much >appreciated. >Aaron Urbas In 4.2, the following should work (as long as you define newsize). in = Import[file.jpg]; Export[newfile.jpg, in, ImageSize->newsize] In 4.1 and earlier, this will not work because an optimization interferes with the ImageSize and rasters are written out with the raster size, not the ImageSize. There is a ConversionOption to force the behavior you want. in = Import[file.jpg]; Export[newfile.jpg, Show[in, ImageSize->newsize], ConversionOptions->{RasterExport->Graphics} ] -Dale ==== Borrowing liberally from Daniel, I like the following: ClearAll[sumBin, sumBinOdd, sumBinEven, index] sumBinOdd = Sum[Binomial[2index + 1, k]*p^(2index + 1 - k)*(1 - p)^k, { k, 0, index - 1}]; sumBinEven = Sum[Binomial[2index, k]* p^(2index - k)*(1 - p)^k, {k, 0, index - 1}]; sumBin[n_, Odd] = sumBinOdd /. {index -> (n - 1)/2}; sumBin[n_, Even] = sumBinEven /. {index -> n/2}; sumBin[n_?EvenQ] = sumBin[n, Even]; sumBin[n_?OddQ] = sumBin[n, Odd]; It allows you to see the solution symbolically for both odd and even n, and also to calculate it when n is a known integer. We also have the opportunity, for instance, to assume that 3x is even and calculate sumBin[3x, Even] p^(3*x)*((1/p)^(3*x) - ((-4 + 4/p)^((3*x)/2)* Gamma[1/2 + (3*x)/2]*Hypergeometric2F1[1, -((3*x)/2), 1 + (3*x)/2, (-1 + p)/p])/(Sqrt[Pi]*Gamma[1 + (3*x)/2])) or assume 3x is odd and calculate sumBin[3*x, Odd] p^(3*x)*((1/p)^(3*x) - (2^(3*x)*(-1 + 1/p)^((1/2)*(-1 + 3*x))* Gamma[3/2 + (1/2)*(-1 + 3*x)]*Hypergeometric2F1[1, -1 + (1/2)*(1 - 3*x), 1 + (1/2)*(-1 + 3*x), (-1 + p)/p])/(Sqrt[Pi]* Gamma[2 + (1/2)*(-1 + 3*x)])) Bobby Treat -----Original Message----- > when F[n,p] is an approximation to the sum and the R is the remaining error. > > Constantine. > > >In a message dated 8/28/02 4:44:13 AM, celster@cs.technion.ac.il > >>I'm looking for a way of finding the approximation for partitial binomial >>sum. >>I'll be pleasant for any hint.. > [...] > Office: Taub 411 You can get a closed form in terms of special functions if you split into two cases depending on whether n is even or odd. In[39]:= n = 2*m; In[40]:= InputForm[Sum[Binomial[n,k]*p^(n-k)*(1-p)^k, {k,0,m-1}]] Out[40]//InputForm= p^(2*m)*((p^(-1))^(2*m) - ((-4 + 4/p)^m*Gamma[1/2 + m]* Hypergeometric2F1[1, -m, 1 + m, (-1 + p)/p])/(Sqrt[Pi]*Gamma[1 + m])) In[41]:= n = 2*m+1; In[42]:= InputForm[Sum[Binomial[n,k]*p^(n-k)*(1-p)^k, {k,0,m-1}]] Out[42]//InputForm= p^(1 + 2*m)*((p^(-1))^(1 + 2*m) - (2^(1 + 2*m)*(-1 + p^(-1))^m*Gamma[3/2 + m]* Hypergeometric2F1[1, -1 - m, 1 + m, (-1 + p)/p])/(Sqrt[Pi]*Gamma[2 + m])) Daniel Lichtblau Wolfram Research ==== I've found that Mathematica 4.2 takes too long to finish to generate first time help browser. Is this normal? How many time should it take? Calimero ==== Please excuse me if this has been discussed before; I haven't been monitoring the group very much. A long time ago I posted to this group as well as to Wolfram about the errors in many or all functions involving Fourier transforms when values of FourierParameters other than the default values are used. The group responded that indeed there was a problem so I'm wondering if it was ever fixed. My version (then and now) is 4.0.1 for Macintosh. Jerry ==== Could you help me? I'm to solve heat conductivity equation (Laplas equation) - partial differential equation. Are there any ready-to-use packages that will help me do the job? Standard function DSolve cannot! And so do functions from package Calculus`DSolveIntegrals`. More info: the space where the equation is to be solved is cylindre (not infinite). Andrew. ==== When I multiply an expression with 0 it is giving 0.expression which is creating problem in the further calculation. eg. In[1]:=func1[r_]:=Exp[-r/2] In[2]:coeff[[1,1]]=0.0; ; ; In[34]:=func1[r]coeff[[1,1]] Out[34]:=0.Exp[-r/2] I want anything to be multiply by zero must be zero. How can I do that? Your suggestion will be highly appreciated. Raj ==== > When I multiply an expression with 0 it is giving 0.expression which > is creating problem in the further calculation. No. Your trouble comes when you multiply an expression by the floating-point number 0.0, rather than by the precise symbolic 0 (having no decimal point). Merely make the coefficient 0 (rather than 0.0) and everything should work as you wish. David > eg. In[1]:=func1[r_]:=Exp[-r/2] > In[2]:coeff[[1,1]]=0.0; > ; > ; > In[34]:=func1[r]coeff[[1,1]] Out[34]:=0.Exp[-r/2] I want anything to be multiply by zero must be zero. How can I do that? -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service Reply-To: kuska@informatik.uni-leipzig.de ==== Unprotect[Times] Times[0., __] := 0 Protect[Times] Jens > > > When I multiply an expression with 0 it is giving 0.expression which > is creating problem in the further calculation. > > eg. > > In[1]:=func1[r_]:=Exp[-r/2] > In[2]:coeff[[1,1]]=0.0; > ; > ; > In[34]:=func1[r]coeff[[1,1]] > > Out[34]:=0.Exp[-r/2] > > I want anything to be multiply by zero must be zero. > > How can I do that? > Your suggestion will be highly appreciated. > > > Raj ==== Now I'm trying to calculate this formula: Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] eq has this form a x^2 + b x + c But there is a problem with the x^0 coefficient! How can I overcome that? CeZaR Reply-To: kuska@informatik.uni-leipzig.de ==== and Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x,2] Coefficient[eq, x,0] does what you want. Because the Help-Browser say: Coefficient[expr, form, 0] picks out terms that are not proportional to form. Jens > > > Now I'm trying to calculate this formula: > > Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] > > eq has this form a x^2 + b x + c > > But there is a problem with the x^0 coefficient! > How can I overcome that? > > > CeZaR ==== I need to fill the space between two contour lines, C1 and C2, with red color, and leave the other place white. What trick I have to use? Any suggestion and advice will be appreciated. Jun Lin Reply-To: kuska@informatik.uni-leipzig.de ==== gr = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, Contours -> {0.2, 0.4}, ColorFunction -> (If[# >= 0.2 && # <= 0.4, RGBColor[1, 0, 0], RGBColor[1, 1, 1]] &), ColorFunctionScaling -> False ] Jens > > I need to fill the space between two contour lines, C1 and C2, with > red color, and leave the other place white. What trick I have to use? > Any suggestion and advice will be appreciated. > > Jun Lin ==== I am trying to find an example that will demonstrate the difference between $PrePrint and $Post. I found an old thread in this news group where a user wanted to display all matrices using MatrixForm. Some users suggested the following: In[1]:= $Post=(#/.mtrx_?MatrixQ:>MatrixForm[mtrx]&); Then Dave Withoff said it's better to assign this to $PrePrint since the objective here is to adjust the display rather than the result of the calculation. With the assignment to $Post you could, for example, get unexpected results from calculations using %, since matrices will be wrapped in MatrixForm. -------- However, if we use $Post above, the next input will compute the inverse the matrix. I did verify that Inverse can't take a matrix wrapped in MatrixForm. Can somebody give an example where doing this with $PrePrint instead of $Post gives a different result. In[2]:= m={{2,3},{0,1}}; Inverse[%] Out[3]= (* Inverse of (m) in MatrixForm, not shown. *) ------ Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html Reply-To: kuska@informatik.uni-leipzig.de ==== yo can just try In[]:=$Post = (# /. mtrx_?MatrixQ :> AnyHead[mtrx] &); In[]:=m = {{2, 3}, {0, 1}} In[]:=q=%; In[]:=Head[q] and In[]:=$PrePost = (# /. mtrx_?MatrixQ :> AnyHead[mtrx] &); In[]:=m = {{2, 3}, {0, 1}} In[]:=q=%; In[]:=Head[q] But you are right -- the behaviour of MatrixForm[] in your example is strange. Jens > > I am trying to find an example that will demonstrate the difference between > $PrePrint and $Post. I found an old thread in this news group where a > user wanted to display all matrices using MatrixForm. Some users suggested > the following: > > In[1]:= $Post=(#/.mtrx_?MatrixQ:>MatrixForm[mtrx]&); > > Then Dave Withoff said it's better to assign this to $PrePrint since the > objective here is to adjust the display rather than the result of the > calculation. With the assignment to $Post you could, for example, get > unexpected results from calculations using %, since matrices will be wrapped > in MatrixForm. > -------- > > However, if we use $Post above, the next input will compute the inverse > the matrix. I did verify that Inverse can't take a matrix wrapped in > MatrixForm. Can somebody give an example where doing this with $PrePrint > instead of $Post gives a different result. > > In[2]:= m={{2,3},{0,1}}; > Inverse[%] > > Out[3]= (* Inverse of (m) in MatrixForm, not shown. *) > > ------ > Ted Ersek > Get Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html ==== myArray is a list of triplets which look like {n,k,p}, where n and k are integers and p is real number. repetitions in n and k are allowed but no two triplets ar the same. I define a function, myfunc[n_,pthreshold_] as follows. myfunc[n_,pthreshold_] := Module[{t}, t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; If[t>=0,t,-1]] It prints the largest k for which p is greater than pthreshold for a given n and -1 if there is no such k. The function does its job fine. My problem is as follows. I would like to plot a collection of plots, myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the following does not work as desired. Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] because the Table gets evaluated to numeric value (-1) before Plot is invoked. ==== I made a mistake in the definition of the question. The function is correctly defined as myfunc[n_,pthreshold_] := Module[{t}, t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> k, 2]]; If[t>=0,t,-1]] Please note that inserting Evaluate before Table does not work correctly either, because evaluating myfunc[n,p] when p is not a number, gives -1. > Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] > > because the Table gets evaluated to numeric value (-1) before Plot is > invoked. Reply-To: kuska@informatik.uni-leipzig.de ==== could you supply a complete example next time ? Try myfunc[] with a more restrictive pattern and it works: myArray = Flatten[Table[{n, 1, Random[]}, {15}, {n, 1, 21}], 1]; myfunc[n_, pthreshold_?NumericQ] := Module[{t}, t = Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; If[t >= 0, t, -1]] Plot[Evaluate[Table[myfunc[n, p], {n, 1, 21}]], {p, 0.0, 1.0}] Jens > > myArray is a list of triplets which look like {n,k,p}, where n and k > are integers and p is real number. repetitions in n and k are allowed > but no two triplets ar the same. > > I define a function, myfunc[n_,pthreshold_] as follows. > > myfunc[n_,pthreshold_] := Module[{t}, > t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; > If[t>=0,t,-1]] > > It prints the largest k for which p is greater than pthreshold for a > given n and > -1 if there is no such k. The function does its job fine. > > My problem is as follows. I would like to plot a collection of plots, > myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the > following does not work as desired. > > Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] > > because the Table gets evaluated to numeric value (-1) before Plot is > invoked. ==== For my PDE class we have been calculating Fourier transforms. The instructor arrived today with a printout of two plots of a certain Fourier transform, done with a different CAS. The first plot was to 30 terms, the second was to 120 terms. Curious, I translated the functions into Mathematica (4.0 on Windows2000 on a PIII 700) to see how much time this required to process. I was Staggered at how much time it took. Here's the code: L = 2; f[x_] := UnitStep[x - 1]; b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] Out[23]= {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} In this case the number of terms is 30. The time required per number of terms seems to fit the following polynomial: y = 0.3926x^2 + 2.2379x This is a large amount of time. I understand that the code is not optimized, and was more or less copied from the code in the other CAS, but is this a reasonable amount of time, or is something going wrong? I don't use Mathematica because of the speed, but should it be this slow? Just curious, Steve Story ==== > I don't use Mathematica > because of the speed, but should it be this slow? Mathematica has become more competitive in the speed department in recent years. See for example the attached comparison (not sent to newsgroup) by Stephan Steinhaus (steinhaus-net.de). So when Mathematica takes a very long time, you should investigate. In this case inserting Evaluate[] in two places In[91]:=b[n_] := Evaluate[(2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; .... In[104]:=Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]] Out[104]={0.18 Second,[SkeletonIndicator]Graphics[SkeletonIndicator]} speeds the process enormously (18 milliseconds to plot 120 terms on my feeble old 500MHz PowerBook). Why was it so slow before? When I switch from an ordinary numerical language to Mathematica, I enter into an implicit bargain with Mathematica: the software will go the extra mile to get me a good answer, including (1) using exra precision (sometimes without being asked) and (2) carrying around unevaluated mathematical expressions (usually without being asked) that could possibly be evaluated more appropriately at a later time. Most tools cannot do either of these things, so I don't have to worry about it, except for the bad answers that result now and then. But I need to take care that Mathematica does not burden itself unnecessarily. That's my side of the bargain. Number (2) is the issue here. Your definition of b[n] is written so that Mathematica analytically evaluates b separately for each n. But you know in this case that the integration can be done safely once for all n. So do it! The huge difference, though, comes from pre-evaluating the argument to Plot. Read the on-line help! You should pre-evaluate where possible. In some cases, the most common of which involve branching within the definition of function to plot, you cannot pre-evaluate so, in keeping with the bargain, Mathematica goes the extra mile and holds back just in case. You need to steer it into the shortcut when it's OK. Hope this helps, Tom Burton -- Reply-To: kuska@informatik.uni-leipzig.de ==== with your code you compute the expansion coefficents every time when FS[] is evaluated. Store the values for b[n] with L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] and you need only a 1-3 seconds (depending on your machine) Jens > > For my PDE class we have been calculating Fourier transforms. The instructor > arrived today with a printout of two plots of a certain Fourier transform, > done with a different CAS. The first plot was to 30 terms, the second was to > 120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 > on a PIII 700) to see how much time this required to process. I was > Staggered at how much time it took. Here's the code: > > L = 2; > f[x_] := UnitStep[x - 1]; > b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; > > FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; > > Timing[Plot[FS[30, x], {x, 0, 2}]] > > Out[23]= > {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} > > In this case the number of terms is 30. > > The time required per number of terms seems to fit the following polynomial: > > y = 0.3926x^2 + 2.2379x > > This is a large amount of time. I understand that the code is not optimized, > and was more or less copied from the code in the other CAS, but is this a > reasonable amount of time, or is something going wrong? I don't use Mathematica > because of the speed, but should it be this slow? > > Just curious, > > Steve Story ==== I would like to use mathematica type papers for my math courses, but I'm having trouble formatting documents. Despite searching, I've been unable to find a complete guide to word processing with mathematica. Does anyone know where such a document could be found? ==== Look at in the Help browser or in the Mathematica Book Style Sheet Also, you have the documentation included for package Author Tools (only in Mathematica 4.2). Guillermo Sanchez > I would like to use mathematica type papers for my math courses, but > I'm having trouble formatting documents. Despite searching, I've been > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== Kenny, Sympathy but no solution. I too have been trying to use Mathematica (v4.2 most recently) to type maths papers and the like but I'm not ready to ditch LaTeX yet. There are just too many cases where I cannot figure out how to achieve what I want in Mathematica, things like: - left brackets spanning multiple lines for defining hybrid functions; - vertical alignment of equals signs in multi-line equations or derivations; - setting typefaces in tables of material. I figure most of this is do-able, but I don't have the time, or patience, to spend too much time on it. So, I'll be the first customer when you write the guide to math publishing in Mathematica - I just hope you won't have to use LaTeX to write it. Mark Westwood > > I would like to use mathematica type papers for my math courses, but > I'm having trouble formatting documents. Despite searching, I've been > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== OrthogonalUnitVectors that I sent a few minutes ago doesn't do what I thought it would. After making either definition below I get the following: In[2]:= s1=OrthogonalUnitVectors[{1,0,1/2,1,0},{0,1,-1,1/2,2}] Out[2]= {{0, -2/Sqrt[5], 0, 0, 1/Sqrt[5]}, {-2/3, -1/3, 0, 2/3, 0}, {-1/3, 2/3, 2/3, 0, 0}} The dot products below aren't zero, so the vectors aren't orthogonal. What went wrong? In[3]:= Part[s1,1].Part[s1,2] Out[3]= 2/(3*Sqrt[5]) In[4]:= Part[s1,1].Part[s1,3] Out[3]= -4/(3*Sqrt[5]) -------------- > Hugh Goyder and David Park gave a most elegant function to find two > vectors that are orthogonal to one vector in 3D. The key to coming up > with the elegant solution is an understanding of Mathematica's NullSpace > function. We can easily make the version from Hugh and David much more > general with the version below. > ------------- > OrthogonalUnitVectors[vect__?VectorQ]:= > #/Sqrt[#.#]&/@NullSpace[{vect}] > > ------------- > The version above will give a set of unit orthogonal vectors if given any > number of vectors in any dimension. > So besides giving it a 3D vector we can give it the following: > OrthogonalUnitVectors[{2,1,0,-1,1}] > or > OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] > > ------------ > But the short version above isn't very robust. > (1) Clear[x,y,z];NullSpace[{{x,y,z}}] > returns two vectors orthogonal to {x,y,z}, but the two vectors > NullSpace returns aren't orthogonal to each other. > So (OrthogonalUnitVectors) should only work with numeric vectors. > > (2) We should ensure all the vectors have the same dimension and length >1. > > I give a less concise version below that corrects these problems. > ------------ > > OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; > (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= > #/Sqrt[#.#]&/@NullSpace[{vect}] > > -------------- > Ted Ersek > Get Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html > ==== Daniel Lichtblau has pointed out that NullSpace does not generally give orthogonal vectors. Therefore the routines that depended upon that were in error. He says that it does give orthogonal vectors when the input vector contains approximate numbers. For graphical purposes this will be good enough for me. Therefore I modify Ted's routine to OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] and the short version for 3D vectors OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ NullSpace[{v//N}] For exact vectors I might use for 3D OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ {temp = First[NullSpace[{v}]], v[Cross]temp} I'm still looking for something that is easy to remember. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ The version above will give a set of unit orthogonal vectors if given any number of vectors in any dimension. So besides giving it a 3D vector we can give it the following: OrthogonalUnitVectors[{2,1,0,-1,1}] or OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] ------------ But the short version above isn't very robust. (1) Clear[x,y,z];NullSpace[{{x,y,z}}] returns two vectors orthogonal to {x,y,z}, but the two vectors NullSpace returns aren't orthogonal to each other. So (OrthogonalUnitVectors) should only work with numeric vectors. (2) We should ensure all the vectors have the same dimension and length >1. I give a less concise version below that corrects these problems. ------------ OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= #/Sqrt[#.#]&/@NullSpace[{vect}] -------------- Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html ==== I am unsure if my messages are making it through to the usegroup so I will try again. I have several differential equations I would like to plot in Mathematica. I would like to plot the Slope Fields of them though. Can anyone lead me in the right direction? I can solve the equations trivially but I want to display the slope fields. An example follows : y' + 2y = 3 -John ==== John, You can do it from scratch with PlotVectorField from the Graphics`PlotField` package, but you make make your life easier (and get prettier plots) by using my DEGraphics package, which can be found at MathSource (it's part of the DiffEqs suite of packages) or here: http://www.math.armstrong.edu/faculty/hollis/mmade/DiffEqs --- Selwyn Hollis > I am unsure if my messages are making it through to the usegroup so I > will try again. I have several differential equations I would like to > plot in Mathematica. I would like to plot the Slope Fields of them > though. Can anyone lead me in the right direction? I can solve the > equations trivially but I want to display the slope fields. An example > follows : > > y' + 2y = 3 > > > > -John > Reply-To: kuska@informatik.uni-leipzig.de ==== Needs[Graphics`PlotField`] PlotVectorField[{x, 3 - 2 y}, {x, 0, 4}, {y, -1, 4}, Axes -> True] ??? Jens > > I am unsure if my messages are making it through to the usegroup so I > will try again. I have several differential equations I would like to > plot in Mathematica. I would like to plot the Slope Fields of them > though. Can anyone lead me in the right direction? I can solve the > equations trivially but I want to display the slope fields. An example > follows : > > y' + 2y = 3 > > > -John ==== You can proceed like this : delta[poly2_, var_] := Coefficient[poly2, var, 1]^2 - 4*Coefficient[poly2, var, 0]*Coefficient[poly2, var, 2] Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : ven., 6. septembre 2002 09:17 Ë : mathgroup@smc.vnet.net Objet : Coefficient problem Now I'm trying to calculate this formula: Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] eq has this form a x^2 + b x + c But there is a problem with the x^0 coefficient! How can I overcome that? CeZaR ==== This works: eq = a x^2 + b x + c discriminant[eq_, x_] := Coefficient[eq, x]^2 - 4 Coefficient[eq, x, 2] Coefficient[eq, x, 0] discriminant[eq, x] x^0 is reduced to 1 and the Coefficient of 1 doesn't make sense to Mathematica, because it depends on what the variable is (a, b, c, or x?). So, the other form of the Coefficient call is needed. I used it for the second power too, but that wasn't necessary. I think that form is best, though, since it allows no ambiguity. I renamed the function because that's what the quantity is often called, for a quadratic. Bobby Treat -----Original Message----- CeZaR ==== >-----Original Message----- >Sent: Friday, September 06, 2002 9:17 AM >myArray is a list of triplets which look like {n,k,p}, where n and k >are integers and p is real number. repetitions in n and k are allowed >but no two triplets ar the same. > >I define a function, myfunc[n_,pthreshold_] as follows. > >myfunc[n_,pthreshold_] := Module[{t}, >t=Max[Cases[myArray, {n, k_, p_} /; (p >= pthreshold) -> p, 2]]; >If[t>=0,t,-1]] > >It prints the largest k for which p is greater than pthreshold for a >given n and >-1 if there is no such k. The function does its job fine. > >My problem is as follows. I would like to plot a collection of plots, >myfunc[n,p], for 1<=n<=21 with respect to p. unfortunately the >following does not work as desired. > >Plot[Table[myfunc[n,p],{n,1,21}],{p,0.0,1.0}] > >because the Table gets evaluated to numeric value (-1) before Plot is >invoked. > The problem with your calculation indented is (1) to evaluate Table (within Plot), which gives {myfunc[1, p], ..., myfunc[21, p]} but (2) *then* to prevent further evaluation of myfunc[.., p] to -1. There are several tricks to do so, e.g. ... Hold[Plot[toPlot, {p, 0, 1}]] /. toPlot -> Table[headPlaceholder[n, p], {n, 3}] /. headPlaceholder -> myfunc // ReleaseHold ...but in your case just simply prevent evaluation of myfunc[.., p] with p being a Symbol by defining: myfunc2[n_, pthreshold_?NumericQ] := ... now... Plot[Evaluate[Table[myfunc2[n, p], {n, 21}]], {p, 0, 1}] ...works as expected. BTW, what do you want to read off the plot, that you didn't know from Table[myfunc[n, 0], {n, 21}] ? -- Hartmut Wolf ==== >-----Original Message----- >Sent: Friday, September 06, 2002 9:17 AM When I multiply an expression with 0 it is giving 0.expression which >is creating problem in the further calculation. > >eg. > >In[1]:=func1[r_]:=Exp[-r/2] >In[2]:coeff[[1,1]]=0.0; >; >; >In[34]:=func1[r]coeff[[1,1]] > >Out[34]:=0.Exp[-r/2] > >I want anything to be multiply by zero must be zero. How can I do that? >Your suggestion will be highly appreciated. > Raj > Raj, this simply is, because 0. Exp[-r/2] is not always zero! func1[-Infinity]coeff[[1, 1]] Infinity::indet: Indeterminate expression 0. Infinity encountered. Out[90]= Indeterminate -- Hartmut Wolf ==== I have a mathematica notebook showing using the alternating direction implicit method for solving heat conduction in 2D via finite difference methods. Moving from 2D to 3D is pretty simple although I can't find my notebook on this anymore :( . The 3D method is sometimes called Brian's method. http://mid-ohio.mse.berkeley.edu/scott/projects/index.html Scott > Could you help me? > I'm to solve heat conductivity equation (Laplas > equation) - partial differential equation. Are there > any ready-to-use packages that will help me do the job? > Standard function DSolve cannot! And so do functions > from package Calculus`DSolveIntegrals`. > > More info: the space where the equation is to be > solved is cylindre (not infinite). > > Andrew. > ==== I am working with Mathematica 4.0, and I would like pass my data to do one graphic in Origin 5.0. How can I do this in more simple manner? ==== > I need to fill the space between two contour lines, C1 and C2, with > red color, and leave the other place white. What trick I have to use? > Any suggestion and advice will be appreciated. Over the years I have alighted upon the following scheme. Suppose I want to color only between contour levels 1 and 2: In[84]:=Needs[Graphics`Colors`] In[88]:=ContourPlot[x, {x, -1, 3}, {y, 0, 1}, Contours -> {0, 1, 2, 3, 4}, ColorFunction -> (If[1 < # < 2, Red, White] & ), ColorFunctionScaling -> False]; 1. Specify the specific contour levels instead of specifying only the count. 2. Disable ColorFunctionScaling so the argument to ColorFunction corresponds to the contour levels. Hope this helps, Tom Burton ==== David Park replied with ---------------- Daniel Lichtblau has pointed out that NullSpace does not generally give orthogonal vectors. Therefore the routines that depended upon that were in error. He says that it does give orthogonal vectors when the input vector contains approximate numbers. For graphical purposes this will be good enough for me. Therefore I modify Ted's routine to OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] ---------------- Lets see what NullSpace does with approximate complex vectors. In[1]:= v1 = {1.0 I, 0.0, 0.5 I, 0.0, 1.0}; v2 = {0.0, 2.0, 1.0 I, 2.0, 0.5}; {v3,v4,v5} = NullSpace[{v1,v2}] Out[3]= {{-0.730153 + 0.*I, 0. - 0.138254*I, 0.250585 + 0.*I, 0. - 0.138254*I, 0. + 0.60486*I}, {0. + 0.*I, -0.515861 + 0.*I, 0. + 0.457321*I, 0.687357 + 0.*I, 0.22866 + 0.*I}, {0. + 0.*I, 0.510406 + 0.*I, 0. + 0.740442*I, -0.23274 + 0.*I, 0.370221 + 0.*I}} -------- In the next line we see NullSpace returned vectors that are orthogonal to the vectors we gave NullSpace. In[4]:= {v1.v3, v1.v4, v1.v5, v2.v3, v2.v4, v2.v5}//Chop Out[4]= {0, 0, 0, 0, 0, 0} ---------- However, the vectors returned aren't orthogonal to each other. In[5]:= {v3.v4, v3.v5, v4.v5}//Chop Out[5]= {0.229195*I, 0.371087*I, -0.677239} --------- I suppose an OrthogonalUnitVectors function that uses NullSpace should (1) Only accept real valued vectors. (2) Ensure NullSpace is given approximate vectors. ------ Ted Ersek ==== >OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; > (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := > #/Sqrt[#.#] & /@ NullSpace[{vect}// N] ---------------- > >Lets see what NullSpace does with approximate complex vectors. > >In[1]:= > v1 = {1.0 I, 0.0, 0.5 I, 0.0, 1.0}; > v2 = {0.0, 2.0, 1.0 I, 2.0, 0.5}; > {v3,v4,v5} = NullSpace[{v1,v2}] > >Out[3]= > {{-0.730153 + 0.*I, 0. - 0.138254*I, 0.250585 + 0.*I, 0. - 0.138254*I, >0. >+ 0.60486*I}, > {0. + 0.*I, -0.515861 + 0.*I, 0. + 0.457321*I, 0.687357 + 0.*I, 0.22866 >+ 0.*I}, > {0. + 0.*I, 0.510406 + 0.*I, 0. + 0.740442*I, -0.23274 + 0.*I, 0.370221 >+ 0.*I}} -------- >In the next line we see NullSpace returned vectors that are orthogonal to >the vectors we gave NullSpace. > >In[4]:= > {v1.v3, v1.v4, v1.v5, v2.v3, v2.v4, v2.v5}//Chop > >Out[4]= > {0, 0, 0, 0, 0, 0} ---------- >However, the vectors returned aren't orthogonal to each other. > >In[5]:= > {v3.v4, v3.v5, v4.v5}//Chop > >Out[5]= > {0.229195*I, 0.371087*I, -0.677239} --------- >I suppose an OrthogonalUnitVectors function that uses NullSpace should > (1) Only accept real valued vectors. > (2) Ensure NullSpace is given approximate vectors. ------ > Ted Ersek I think you will find that the output vectors are orthogonal if you use the complex conjugate. for example v4.Conjugate[v5] is zero. Dennis Wangsness ==== >I need to fill the space between two contour lines, C1 and C2, with >red color, and leave the other place white. What trick I have to use? >Any suggestion and advice will be appreciated. Needs[Graphics`FilledPlot`]; Needs[Graphics`Colors`]; FilledPlot[{4 - x^2, 3x}, {x, -4, 1}, Fills -> Red]; Bob Hanlon ==== >For my PDE class we have been calculating Fourier transforms. The instructor >arrived today with a printout of two plots of a certain Fourier transform, >done with a different CAS. The first plot was to 30 terms, the second was >to >120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 >on a PIII 700) to see how much time this required to process. I was >Staggered at how much time it took. Here's the code: > >L = 2; >f[x_] := UnitStep[x - 1]; >b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; > >FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; > >Timing[Plot[FS[30, x], {x, 0, 2}]] > >Out[23]= >{419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} > >In this case the number of terms is 30. > >The time required per number of terms seems to fit the following polynomial: > >y = 0.3926x^2 + 2.2379x > >This is a large amount of time. I understand that the code is not optimized, >and was more or less copied from the code in the other CAS, but is this >a >reasonable amount of time, or is something going wrong? I don't use Mathematica >because of the speed, but should it be this slow? > >Just curious, Your definition of b recalculates the integral for every call. To evaluate the integral once include Evaluate. Clear[f, b, FS]; L = 2; f[x_] := UnitStep[x - 1]; b[n_] := Evaluate[ (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; In the case of FS it is best to wait for an integer value of N prior to performing the Sum. FS[N_Integer, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Now Evaluate the argument of the Plot to cause the Sum to be done once. Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]][[1]] 0.366667 Second While my computer may be faster than yours, this result for N=120 is 1000 times faster than your result for N=30. Bob Hanlon ==== > > > Now I'm trying to calculate this formula: > > Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x^0] > > eq has this form a x^2 + b x + c > > But there is a problem with the x^0 coefficient! > How can I overcome that? > > > CeZaR Coefficient cannot figure out who is and is not a variable when a variable of 1 is specified. To work around this you might instead do delta1[poly_, x_] := Coefficient[poly,x]^2 - 4*Coefficient[poly,x,2]*Coefficient[poly,x,0] I prefer instead to use CoefficientList: delta2[poly_, x_] := (#[[2]]^2 - 4*#[[1]]*#[[3]])& [CoefficientList[poly,x]] In[25]:= poly = a*x^2+b*x+c; In[26]:= delta1[poly,x] === delta2[poly,x] Out[26]= True Daniel Lichtblau Wolfram Research ==== > >Delta[eq_, x_]:=Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, >x^0] > >eq has this form a x^2 + b x + c > >But there is a problem with the x^0 coefficient! >How can I overcome that? see on-line help for Coefficient delta[eq_, x_] := Coefficient[eq, x, 1]^2 - 4 *Coefficient[eq, x, 2] *Coefficient[eq, x, 0]; eq = a*x^2 + b*x + c; delta[eq, x] b^2 - 4*a*c Bob Hanlon ==== Would someone with a very fast machine and lots of memory be willing to try this Solve for me? It is the inverse of the 20 node quadratic hexahedral mapping used in finite element analysis. None of my computers can handle this - they run out of memory (using (*Hex20 Node definition in global coordinates *) Clear[ x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20, z20]; (* local coordinates *) Clear[u, v, w]; (* Global co-ordinates *) Clear[x, y, z]; (* corner nodes *) N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; (* to u nodes *) N2= (1-u^2)*(1-v)*(1-w)/4; N6= (1-u^2)*(1+v)*(1-w)/4; N14=(1-u^2)*(1-v)*(1+w)/4; N18=(1-u^2)*(1+v)*(1+w)/4; (* to v nodes *) N4= (1+u)*(1-v^2)*(1-w)/4; N8= (1-u)*(1-v^2)*(1-w)/4; N16=(1+u)*(1-v^2)*(1+w)/4; N20=(1-u)*(1-v^2)*(1+w)/4; (* to w nodes *) N9= (1-u)*(1-v)*(1-w^2)/4; N10=(1+u)*(1-v)*(1-w^2)/4; N11=(1+u)*(1+v)*(1-w^2)/4; N12=(1-u)*(1-v)*(1-w^2)/4; (* solve the inverse transform *) Solve[{ x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19+x20* N20-x==0, y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19+y20* N20-y==0, z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19+z20* N20-z==0}, {u,v,w}] Christopher J. Purcell Defence R&D Canada ö Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== Needs[Graphics`Colors`]; ContourPlot[Sin[x y], {x, -5, 5}, {y, -5, 5}, ColorFunction -> (If[0.5 < # < 0.7, Red, White] &)]; Bob Hanlon >ContourPlot? >Jun Lin > In a message dated 9/6/02 3:53:58 AM, > >I need to fill the space between two contour lines, > C1 and C2, with >red color, and leave the other place white. What > trick I have to use? >Any suggestion and advice will be appreciated. > > Needs[Graphics`FilledPlot`]; > Needs[Graphics`Colors`]; > FilledPlot[{4 - x^2, 3x}, {x, -4, 1}, Fills -> Red]; ==== Jun Lin, Here is an example. Needs[Graphics`Colors`] Let's make a contour plot of this function. f[x_, y_] := Sin[x]Sin[2y] Let's specify the exact contours to use. I got rid of the 0. contour because it is difficult to obtain in this plot. contourvalues = Complement[Range[-1, 1, 0.2], {0.}] {-1, -0.8, -0.6, -0.4, -0.2, 0.2, 0.4, 0.6, 0.8, 1.} Now we define a ColorFunction for the plot. I actually colored two different bands to show how you can make a general color function to give each band a desired color. cfun[z_] := Which[ -0.6 < z < -0.42, RoyalBlue, 0.4 < z < 0.6, Red, True, White] ContourPlot[f[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30, ColorFunctionScaling -> False, ColorFunction -> cfun, Contours -> contourvalues]; Using the option ColorFunctionScaling -> False says that the z value will be the actual value of f[x,y]. Otherwise, in general, it will be scaled between 0 and 1. It is easier to write a color function when z is the actual value of the function. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Reply-To: ==== I checked again the six solutions I had previously timed, and they DO give orthogonal results. (None of them depend on NullSpace for that.) By the way, I reused my combinations function (from a recent problem on adding fractions to get 1) to check for orthogonality: ClearAll[orthogonalQ] orthogonalQ[v : {__?VectorQ}] := And @@ (Chop@( Dot @@ #) == 0 & /@ combinations[v, {2}]) << DiscreteMath`Combinatorica`; ClearAll[combinations]; r = Range[1, 9]; combinations::usage = combinations[list,n:{__Integer}] lists the combinations of list taken n at a time; combinations[r_List, n_Integer, {}] := If[n > Length@r, {}, DiscreteMath`Combinatorica`KSubsets[r, n]]; combinations[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@ DiscreteMath`Combinatorica`KSubsets[Complement[r, e], n]; combinations[r_List, n_Integer, e : {__?VectorQ}] := Flatten[ combinations[r, n, #] & /@ e, 1]; combinations[r_List, n : {__Integer}] := Which[Plus @@ n == Length@r, Join[#, Complement[r, #]] & /@ combinations[r, Drop[n, -1]], Plus @@ n > Length@r, {}, True, Fold[ combinations[r, #2, #1] &, {}, n]] Bobby -----Original Message----- (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] and the short version for 3D vectors OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ NullSpace[{v//N}] For exact vectors I might use for 3D OrthogonalUnitVectors[v : {_, _, _}] := #/Sqrt[#.#] & /@ {temp = First[NullSpace[{v}]], v[Cross]temp} I'm still looking for something that is easy to remember. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ OrthogonalUnitVectors[vect__?VectorQ]:= #/Sqrt[#.#]&/@NullSpace[{vect}] ------------- The version above will give a set of unit orthogonal vectors if given any number of vectors in any dimension. So besides giving it a 3D vector we can give it the following: OrthogonalUnitVectors[{2,1,0,-1,1}] or OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] ------------ But the short version above isn't very robust. (1) Clear[x,y,z];NullSpace[{{x,y,z}}] returns two vectors orthogonal to {x,y,z}, but the two vectors NullSpace returns aren't orthogonal to each other. So (OrthogonalUnitVectors) should only work with numeric vectors. (2) We should ensure all the vectors have the same dimension and length >1. I give a less concise version below that corrects these problems. ------------ OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= #/Sqrt[#.#]&/@NullSpace[{vect}] -------------- Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html ==== I have substituted the letters SS, CC, X, Y and Z1 and Z2 for some complicated expressions just to illustrate the form of the function. This function works and all the conditions are necessary but I am sure a more elegant programming solution perhaps using While could be found. Any f[{Sa_, Ca_, Aa_, Sb_, Cb_, Ab_, a_, b_}] := {If[Aa == Ab, a Sa + b Sb, If[Ca == 0 || Cb == 0, a Sa + b Sb, SS]], If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== Check out the Help for Coefficient. Coefficient[expr, form, 0] picks out terms that are not proportional to form. Delta[eq_, x_] := Coefficient[eq, x]^2 - 4 Coefficient[eq, x^2] Coefficient[eq, x, 0] Delta[a x^2 + b x + c, x] b^2 - 4*a*c David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ ==== Dear all, 1.) How to find the General Solution for below's partial differential equation? (y + u) du/dx + y (du/dy) = x - y ** I use d to represent the partial differential symbol. Can it be solved by function NDSolve in mathematica 4.1? How? 2.) I manage to get the roots of complex equation z^5 = i from Solve[z^5 == i, z]. It gave me straight the 5 roots in the output. Is there any way to view the steps in mathematica? Shz Shz ============================================================================ ====== of the individual or entity to which they are addressed. Any disclosure, copying, distribution and diversion contrary to the applicable export control laws and regulations including US Export Administration Regulations is strictly prohibited. and do not disclose it to others. Please notify the postmaster@hitachi.com.my of the delivery error by replying to this message and then delete it from your ============================================================================ ====== ==== I have been trying to code Sethian's Fast Marching Method in 2D but Mathematica has been very slow (taking something like 1-2 hours for something that should take much less than a second in C++). I am sure part of the problem my time. I looked at the list archives and there was mention of an profiling package for Mathematica but a)I can't find it & b)It may not work with Mathematica 4.*. My questions: 1. Any general suggestions on how to figure out which functions are taking most of the time? I guess I could manually have each function I am interested in monitoring keep a variable that counts the amount of CPU time that has been spent on it by doing something like: function[args_]:=Module[{},functionTimer+=Timing[ .... My actual function ..... ][[1]]] but it would very cumbersome to do this to all of the functions in my program and I am not sure I will get accurate results anyway. 2. Compiling functions is not always that easy. I did read the on-line docs and the archives and it does take some work to make a function compile usefully. Is there an FAQ or a tutorial somewhere? 3. Am I the only one who finds the lack of a profiler really really annoying ? Mathematica is powerful and it is usually easy to ask it to do what u want. The challenge a lot of times is doing so without taking too long. Husain PS: One more quick one: Why does the front end act funny when I have the Reply-To: jmt@dxdydz.net ==== mathematica -primaryModifierMask etc see man mathematica for other (very useful) options > PS: One more quick one: Why does the front end act funny when I have the > > Your X server is set up so that the NumLock key is mapped to Mod2. I > learned by accident that Mod2 is actually quite useful. Mod2-click on a > cell selects all cells of that type in the current notebook. This is an > easy way to delete all the graphics cells and output cells in a notebook to > reduce file size. An annoying aspect is that Mod2-click means press > NumLock, click, then press NumLock again to turn it off. You should be able > to map a different key to Mod2 using xmodmap. Remapping modifier keys in X > is awfully annoying, though. I recommend xkeycaps > (http://www.jwz.org/xkeycaps/). > > > Reply-To: kuska@informatik.uni-leipzig.de ==== a Mathematica profiler is described in The Mathematica Journal Volume 5, Issue 3, Summer 1995 The Mathematica Toolbox: A Mathematica Profiler by Todd Gayley The electronic material for this issue isn not on MathSource but it may be that Todd has the code some where and can make is acessible. Jens > > > I have been trying to code Sethian's Fast Marching Method in 2D but Mathematica > has been very slow (taking something like 1-2 hours for something that > should take much less than a second in C++). I am sure part of the problem > my time. > > I looked at the list archives and there was mention of an profiling > package for Mathematica but a)I can't find it & b)It may not work with Mathematica 4.*. > My questions: > 1. Any general suggestions on how to figure out which functions are taking > most of the time? I guess I could manually have each function I am > interested in monitoring keep a variable that counts the amount of CPU > time that has been spent on it by doing something like: > function[args_]:=Module[{},functionTimer+=Timing[ .... My actual function > ..... ][[1]]] > but it would very cumbersome to do this to all of the functions in my > program and I am not sure I will get accurate results anyway. > 2. Compiling functions is not always that easy. I did read the on-line > docs and the archives and it does take some work to make a function > compile usefully. Is there an FAQ or a tutorial somewhere? > 3. Am I the only one who finds the lack of a profiler really really > annoying ? Mathematica is powerful and it is usually easy to ask it to do what u > want. The challenge a lot of times is doing so without taking too long. > > Husain > PS: One more quick one: Why does the front end act funny when I have the ==== > PS: One more quick one: Why does the front end act funny when I have the Your X server is set up so that the NumLock key is mapped to Mod2. I learned by accident that Mod2 is actually quite useful. Mod2-click on a cell selects all cells of that type in the current notebook. This is an easy way to delete all the graphics cells and output cells in a notebook to reduce file size. An annoying aspect is that Mod2-click means press NumLock, click, then press NumLock again to turn it off. You should be able to map a different key to Mod2 using xmodmap. Remapping modifier keys in X is awfully annoying, though. I recommend xkeycaps (http://www.jwz.org/xkeycaps/). ==== Caution: the definition b[n_] := Evaluate[(2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; doesn't immediately compute the integral unless f is already defined at this point, and in that case you may as well write b[n_] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; instead. If b will be computed more than once for the same n, its even better to do it THIS way (if f and L do not change): f[x_] = Cos[x] (* for example *) Simplify[Integrate[f[x]*Sin[n*Pi*(x/L)], {x, 0, L}]] (L*((-n)*Pi + n*Pi*Cos[L]*Cos[n*Pi] + L*Sin[L]*Sin[n*Pi]))/ ((L - n*Pi)*(L + n*Pi)) b[n_] := b[n] = (L*((-n)*Pi + n*Pi*Cos[L]*Cos[n*Pi] + L*Sin[L]*Sin[n*Pi]))/ ((L - n*Pi)*(L + n*Pi)) Bobby -----Original Message----- Stephan Steinhaus (steinhaus-net.de). So when Mathematica takes a very long time, you should investigate. In this case inserting Evaluate[] in two places In[91]:=b[n_] := Evaluate[(2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]]; .... In[104]:=Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]] Out[104]={0.18 Second,[SkeletonIndicator]Graphics[SkeletonIndicator]} speeds the process enormously (18 milliseconds to plot 120 terms on my feeble old 500MHz PowerBook). Why was it so slow before? When I switch from an ordinary numerical language to Mathematica, I enter into an implicit bargain with Mathematica: the software will go the extra mile to get me a good answer, including (1) using exra precision (sometimes without being asked) and (2) carrying around unevaluated mathematical expressions (usually without being asked) that could possibly be evaluated more appropriately at a later time. Most tools cannot do either of these things, so I don't have to worry about it, except for the bad answers that result now and then. But I need to take care that Mathematica does not burden itself unnecessarily. That's my side of the bargain. Number (2) is the issue here. Your definition of b[n] is written so that Mathematica analytically evaluates b separately for each n. But you know in this case that the integration can be done safely once for all n. So do it! The huge difference, though, comes from pre-evaluating the argument to Plot. Read the on-line help! You should pre-evaluate where possible. In some cases, the most common of which involve branching within the definition of function to plot, you cannot pre-evaluate so, in keeping with the bargain, Mathematica goes the extra mile and holds back just in case. You need to steer it into the shortcut when it's OK. Hope this helps, Tom Burton -- ==== With the second method below (mine), the times add up to 40% less than with the first method (Jens-Peer's), for what SEEMS to be exactly the same work. Go figure! Can anybody explain that? (* Jens-Peer *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.547 Second, .89ª°Graphics.89ª°} (* Treat #1 *) Timing[(2/L)*Integrate[f[x]*Sin[n*Pi*(x/L)], {x, 0, L}]] {0.016000000000000014*Second, (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi)} ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi); FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.297 Second, .89ª°Graphics.89ª°} Even stranger, it SLOWS the Plot if we precompute b before Timing starts: (* Treat #2 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi); b /@ Range[30]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.328 Second, .89ª°Graphics.89ª°} But here's a winner: (* Treat #3 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/ (n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.204 Second, .89ª°Graphics.89ª°} Apparently, computing b within the Plot causes machine-precision arithmetic to be used, and that saves time. Precomputing b and then converting exact expressions to approximate ones within the Plot seems to take longer. For that to make sense, I think it must be that n is approximate (not Integer) when it is passed to b within Plot. Bobby Treat -----Original Message----- and you need only a 1-3 seconds (depending on your machine) Jens For my PDE class we have been calculating Fourier transforms. The instructor > arrived today with a printout of two plots of a certain Fourier transform, > done with a different CAS. The first plot was to 30 terms, the second was to > 120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 > on a PIII 700) to see how much time this required to process. I was > Staggered at how much time it took. Here's the code: L = 2; > f[x_] := UnitStep[x - 1]; > b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] Out[23]= > {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} In this case the number of terms is 30. The time required per number of terms seems to fit the following polynomial: y = 0.3926x^2 + 2.2379x This is a large amount of time. I understand that the code is not optimized, > and was more or less copied from the code in the other CAS, but is this a > reasonable amount of time, or is something going wrong? I don't use Mathematica > because of the speed, but should it be this slow? Just curious, Steve Story ==== Even better -- MUCH better -- add Bob Hanlon's Evaluate to the other tricks: ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[Evaluate[FS[30, x]], {x, 0, 2}]] {0.015 Second, .89ª°Graphics.89ª°} ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[Evaluate[FS[120, x]], {x, 0, 2}]] {0.063 Second, .89ª°Graphics.89ª°} Bobby Treat -----Original Message----- Timing[Plot[FS[30, x], {x, 0, 2}]] {0.547 Second, .89ª°Graphics.89ª°} (* Treat #1 *) Timing[(2/L)*Integrate[f[x]*Sin[n*Pi*(x/L)], {x, 0, L}]] {0.016000000000000014*Second, (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi)} ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - Cos[n*Pi]))/(n*Pi); FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.297 Second, .89ª°Graphics.89ª°} Even stranger, it SLOWS the Plot if we precompute b before Timing starts: (* Treat #2 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = (2*(Cos[(n*Pi)/2] - (-1)^n))/(n*Pi); b /@ Range[30]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.328 Second, .89ª°Graphics.89ª°} But here's a winner: (* Treat #3 *) ClearAll[f, b, FS] L = 2; f[x_] := UnitStep[x - 1]; b[n_] := b[n] = N[(2*(Cos[(n*Pi)/2] - (-1)^n))/ (n*Pi)]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*(x/L)], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] {0.204 Second, .89ª°Graphics.89ª°} Apparently, computing b within the Plot causes machine-precision arithmetic to be used, and that saves time. Precomputing b and then converting exact expressions to approximate ones within the Plot seems to take longer. For that to make sense, I think it must be that n is approximate (not Integer) when it is passed to b within Plot. Bobby Treat -----Original Message----- and you need only a 1-3 seconds (depending on your machine) Jens For my PDE class we have been calculating Fourier transforms. The instructor > arrived today with a printout of two plots of a certain Fourier transform, > done with a different CAS. The first plot was to 30 terms, the second was to > 120 terms. > Curious, I translated the functions into Mathematica (4.0 on Windows2000 > on a PIII 700) to see how much time this required to process. I was > Staggered at how much time it took. Here's the code: L = 2; > f[x_] := UnitStep[x - 1]; > b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}]; FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}]; Timing[Plot[FS[30, x], {x, 0, 2}]] Out[23]= > {419.713 Second, [SkeletonIndicator]Graphics[SkeletonIndicator]} In this case the number of terms is 30. The time required per number of terms seems to fit the following polynomial: y = 0.3926x^2 + 2.2379x This is a large amount of time. I understand that the code is not optimized, > and was more or less copied from the code in the other CAS, but is this a > reasonable amount of time, or is something going wrong? I don't use Mathematica > because of the speed, but should it be this slow? Just curious, Steve Story ==== How can I plot with Mathematica two function in the same graphic? I explain better: compare a and b). Reply-To: kuska@informatik.uni-leipzig.de ==== Plot[{x,x^2},{x,-1,1}] may do it. Jens > > How can I plot with Mathematica two function in the same graphic? > I explain better: > compare a and b). > ==== Other than Plot[{x,x^2},...] you can use Show[] as well. plt1=Plot[x,{x,0,1}]; plt2=Plot[x^2,{x,0,1}]; Show[plt1,plt2] Lawrence > How can I plot with Mathematica two function in the same graphic? > I explain better: > compare a and b). > > > > > Mario, > > Here is a fancy version of your plot. I used Text statements within an > Epilog option to label the two curves. The regular plot statement allows you > to plot a series of functions inclosed in a list. > > Needs[Graphics`Colors`] > > > Plot[{x, x^2}, {x, 0, 1}, > PlotStyle -> {Black, Blue}, > Frame -> True, > FrameLabel -> {x, y}, > PlotLabel -> Comparison of Two Functions, > Epilog -> {Text[x, {0.5, 0.55}], Blue, Text[x^2, {0.7, 0.4}]}, > Background -> Linen, > ImageSize -> 500]; > > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > > > > How can I plot with Mathematica two function in the same graphic? > I explain better: > compare a and b). > > > > > ==== (1) Is there a way in Mathematica 4.2 to put two separate gifs into a single, cell side by side (with some intervening space), without having to combine them in some graphics program first? In particular, I'd like to do that within a text cell. Even in a new Input cell, if I first create a GridBox (via Inut>Create Table/Matrix/Palette) and then try to insert the first gif (via Edit>Insert Object>Create from File ....), Mathematica promptly crashes. (Mathematica 4.2 under Windows 2000.) I just don't see how to get anything other than a single gif into a cell. (2) Is there a way to cause a gif imported into a Mathematica 4.2 notebook to become a hyperlink -- so that when the user clicks on the gif the hyperlink's target is summoned? (My aim in all this is to use Mathematica to create web pages with high mathematical content -- saving the notebook as HTML+MathML -- without having to do any extensive editing of the resulting .xml and related files. That way as the source Mathematica notebook changes, I would need only to re-export without further tinkering with the .xml file, etc.) -- Murray Eisenberg Internet: murray@math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) Reply-To: kuska@informatik.uni-leipzig.de ==== it works with any graphics NotebookWrite[SelectedNotebook[], GridBox[{Cell[GraphicsData[PostScript, DisplayString[#, MPS]], Graphics] & /@ {leftGraphics, rightGraphics}}]] Jens > > (1) Is there a way in Mathematica 4.2 to put two separate gifs into a > single, cell side by side (with some intervening space), without > having to combine them in some graphics program first? > > In particular, I'd like to do that within a text cell. > > Even in a new Input cell, if I first create a GridBox (via Inut>Create > Table/Matrix/Palette) and then try to insert the first gif (via > Edit>Insert Object>Create from File ....), Mathematica promptly > crashes. (Mathematica 4.2 under Windows 2000.) > > I just don't see how to get anything other than a single gif into a > cell. > > (2) Is there a way to cause a gif imported into a Mathematica 4.2 > notebook to become a hyperlink -- so that when the user clicks on the > gif the hyperlink's target is summoned? > > (My aim in all this is to use Mathematica to create web pages with > high mathematical content -- saving the notebook as HTML+MathML -- > without having to do any extensive editing of the resulting .xml and > related files. That way as the source Mathematica notebook changes, I > would need only to re-export without further tinkering with the .xml > file, etc.) > > -- > Murray Eisenberg Internet: murray@math.umass.edu > Mathematics & Statistics Dept. Voice: 413-545-2859 (W) > University of Massachusetts 413-549-1020 (H) ==== Your method 1), below, does not produce correct results if one then uses menu>Save As Special>HTML+MathML. I view the resulting .xml file in a MathML-enabled browser (e.g., Mozilla with appropriate TrueType fonts installed -- the four BaKoMa cm fonts, the old Mathematica Math1, etc., fonts, and the two MT fonts. Then the everything in the originally multi-line inline cell appears on one line separate by a ?, as do the alignment markers. In the page source, these unrendered symbols have codes #8289 and #63328, respectively. Is there an issue of the encoding used in the browser here? I did try Unicode-7, Unicode-8, and several of the Western encodings available under Mozilla's Default Character Encoding. Or is it something else? Note that I do also have the new Mathematica TrueType fonts (Mathematica1, etc.). P.S. I don't think Mathematica documents this, but if one wants a file exported from Mathematica as HTML+MathML to be rendered correctly by a browser, it seems to require an extension of .xml rather than .html. > >>When writing a series of equations in mathematica (in a text cell) >>is there any way to align the equations at the = similar to >>what can be done in the equation editor made by math type (used >>in word etc.)? > > > Mike, > Two ways > 1) Start an inline cell in your text cell (menu>Edit>Expression Input>Start > Inline Cell) > Type in your equations with the alignment marker (Esc am Esc) in after each > equal sign. > Close the inline cell (menu>Edit>Expression Input>End Inline Cell). > Select the text cell (or the inline cell, though this is a delicate > operation, do it by repeatedly double clicking in it}. > Use menu> Format>Text Alignment>On Alignment Marker. > -- you will find that all single letters are now italic - you can select > individual letters and change this - alternatively you can select the inline > cell and use the option inspector (menu>Format>Option Inspector) to set > SingleLetterItalics->False) > > -- you can put existing text in an inline cell by selcting it and using > menu>Edit>Expression Input>Start Inline Cell, but you may have to adjust > the line breaks after this.... -- Murray Eisenberg Internet: murray@math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) ==== Group, Can anyone help me with the following? I guess this is something trivial for most of you, but I have being struggling with it for weeks. The problem is to construct a taxonomic hierarchy whose structure is hereby described by example: << DiscreteMath`Combinatorica` n[1]:= m = 10; (*with the following I get the 1th level (1--element) partition*) in[2]:= ks1 = Partition[Range[m], 1] (*Now the following gives all the 2th-level (?) different partitions that can be set up by joining two elements in the 1-element partition and leaving the rest as they are?*) (*First, these are all possible 'joinings' to generate the two elements 'pieces' from 1th level (1--element) partition*) in[3]:= ks2 = KSubsets[Range[m], 2] (*And this generates all the 2th-level (?) different partitions that can be set up by joining two elements in the 1-element partition and leaving the rest as they are.*) in[4]:= p2 = MapThread[Complement[Append[#1, #2], (Sequence @@ {#} & /@ Partition[#2, 1])] &, {Array[ks1&, Length[ks2]], ks2}]; Length[p2] in[5]:= p2[[1]] out[5]:= {{3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2}} in[6]:= p2[[Length[p2]]] out[6]:= {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9, 10}} (*compute in[4] t and see the full output*) (*Now I need to solve the problem of given the ith-level (?) different partitions to set up all the i+1th different partitions by joining two elements in the ith level partition and leaving the rest as they are? *) (*for example given the following 2th-level partition*) {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2} (*we should get*) {{{4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2, 3}}, {{3}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2, 4}}, {{3}, {4}, {6}, {7}, {8}, {9}, {10}, {1, 2, 5}}, {{3}, {4}, {5}, {7}, {8}, {9}, {10}, {1, 2, 6}}, {{3}, {4}, {5}, {6}, {8}, {9}, {10}, {1, 2, 7}}, {{3}, {4}, {5}, {6}, {7}, {9}, {10}, {1, 2, 8}}, {{3}, {4}, {5}, {6}, {7}, {8}, {10}, {1, 2, 9}}, {{3}, {4}, {5}, {6}, {7}, {8}, {9}, {1, 2, 10}}} (*The process would end up to *) {1,{2,3,4,5,6,7,8,9,10}} {2,{1,3,4,5,6,7,8,9,10}} {3,{1,2,4,5,6,7,8,9,10}} {4,{1,2,3,5,6,7,8,9,10}} {5,{1,2,3,4,6,7,8,9,10}} {6,{1,2,3,4,5,7,8,9,10}} {7,{1,2,3,4,5,6,8,9,10}} {8,{1,2,3,4,5,6,7,9,10}} {9,{1,2,3,4,5,6,7,8,10}} {10,{1,2,3,4,5,6,7,8,9}} (* and*) {1,2,3,4,5,6,7,8,9,10} Emilio Martin-Serrano Reply-To: tharter@attglobal.net ==== Your machine information and OS EXACTLY matches mine (except that my pagefile is NOT on a separate physical drive -- perhaps this is a clue as to where to start), and I had no problem building the help file. Hence, as you say, this must be a problem for Wolfram to address. Perhaps, someone from WRI will enlighten us via this newsgroup. ....Terry I too have been unable to get the help browser functioning. I have > exactly the same problem. When trying to open the help browser it gets > to the point where it says scanning index file and freezes. I tried > all the suggestions in the faq and the links provided here to no > avail. I'm running Winows 2000 with service pack 3. I have 512mb of > memory with a 768mb pagefile on a separate drive, so I don't think > that's an issue. Mathematica 4.1 ran just fine on this setup, so > judging by the number of other people affected by this, I'd say it's > some kind of bug with 4.2. Hopefully Wolfram will address this with > either a link that will provide a fix that actually works, or a patch. >What is your operating system? How much memory do you have in your machine? >Also, how big is your pagefile? Sounds to me like the rebuild ran out >of room to do its thing in. > > I just installed Mathematica 4.2, and had no problem rebuilding the help index. >Subsequently, I ahd no problem using the Help browser either. >Hope that helps! >....Terry > >I'd start with the following FAQ. > > >http://support.wolfram.com/mathematica/interface/helpbrowser/howrebuildindex .html > >-Dale > > Sorry that i failed say it immediately in a first place, but of course > i did try it FAQ at first, and both tried to delete cache and rebuild > index, but results where the same - whenever i try to invoke help > browser (or rebuild index, for that matter), mathematica stops > responding (i did read your answer to the same question asked > a week ago before - actually that is why i turned to the FAQ). > ==== Try deleting ... Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb > Your machine information and OS EXACTLY matches mine (except that my pagefile > is NOT on a separate physical drive -- perhaps this is a clue as to where to start), > and I had no problem building the help file. Hence, as you say, this must > be a problem for Wolfram to address. Perhaps, someone from WRI will enlighten > us via this newsgroup. > ....Terry > > I too have been unable to get the help browser functioning. I have > exactly the same problem. When trying to open the help browser it gets > to the point where it says scanning index file and freezes. I tried > all the suggestions in the faq and the links provided here to no > avail. I'm running Winows 2000 with service pack 3. I have 512mb of > memory with a 768mb pagefile on a separate drive, so I don't think > that's an issue. Mathematica 4.1 ran just fine on this setup, so > judging by the number of other people affected by this, I'd say it's > some kind of bug with 4.2. Hopefully Wolfram will address this with > either a link that will provide a fix that actually works, or a patch. > >What is your operating system? How much memory do you have in your machine? >Also, how big is your pagefile? Sounds to me like the rebuild ran out >of room to do its thing in. > > I just installed Mathematica 4.2, and had no problem rebuilding the help index. >Subsequently, I ahd no problem using the Help browser either. >Hope that helps! >....Terry > > >I'd start with the following FAQ. > > >http://support.wolfram.com/mathematica/interface/helpbrowser/howrebuildinde x.html > >-Dale > > Sorry that i failed say it immediately in a first place, but of course > i did try it FAQ at first, and both tried to delete cache and rebuild > index, but results where the same - whenever i try to invoke help > browser (or rebuild index, for that matter), mathematica stops > responding (i did read your answer to the same question asked > a week ago before - actually that is why i turned to the FAQ). > > ==== >Try deleting ... >Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb > > ==== > I too have been trying to use Mathematica (v4.2 most recently) to type > maths papers and the like but I'm not ready to ditch LaTeX yet. There > are just too many cases where I cannot figure out how to achieve what I > want in Mathematica, things like: > - left brackets spanning multiple lines for defining hybrid functions; You can accomplish this by doing the following: 1) Put your function braches in the rows of a grid box structure. 2) Add the following options to your cell: ShowAutoStyles -> False SpanMaxSize -> Infinity The following cell snippet demonstrates how this influences the result. To view it, paste the Cell[] expression into a notebook and then click on Yes when you are prompted on whether the front end should interpret the result. Cell[BoxData[ FormBox[ RowBox[{ RowBox[{f, (, x, )}], =, RowBox[{{, GridBox[{ {x, RowBox[{x, , <, 0}]}, { SuperscriptBox[x, 2], RowBox[{0, [LessEqual], x, <, 1}]}, { RowBox[{sin, (, x, )}], RowBox[{1, [LessEqual], x, <, 2}]}, { RowBox[{[CapitalGamma], (, x, )}], RowBox[{x, [GreaterEqual], 2}]} }]}]}], TraditionalForm]], DisplayFormula, ShowAutoStyles->False, SpanMaxSize->Infinity] > - vertical alignment of equals signs in multi-line equations or > derivations; Put your equations in a GridBox and set the ColumnAlignments option to a string containing the equal sign. Cell[BoxData[ FormBox[GridBox[{ { RowBox[{ RowBox[{ RowBox[{3, x}], , +, , RowBox[{4, , y}]}], , =, , 9}]}, { RowBox[{ RowBox[{ RowBox[{2, x}], , -, , RowBox[{7, , y}]}], =, RowBox[{32, , -, , RowBox[{sin, (, x, )}]}]}]} }], TraditionalForm]], DisplayFormula, GridBoxOptions->{ColumnAlignments->{=}}] > - setting typefaces in tables of material. I think the Author Tools material that comes with Mathematica 4.2 might be able to help you do this. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== You have three nonlinear (fourth-order) equations and 23 unknowns. A faster computer won't help any. Bobby -----Original Message----- (*Hex20 Node definition in global coordinates *) Clear[ x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8, x9, y9, z9, x10, y10, z10, x11, y11, z11, x12, y12, z12, x13, y13, z13, x14, y14, z14, x15, y15, z15, x16, y16, z16, x17, y17, z17, x18, y18, z18, x19, y19, z19, x20, y20, z20]; (* local coordinates *) Clear[u, v, w]; (* Global co-ordinates *) Clear[x, y, z]; (* corner nodes *) N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; (* to u nodes *) N2= (1-u^2)*(1-v)*(1-w)/4; N6= (1-u^2)*(1+v)*(1-w)/4; N14=(1-u^2)*(1-v)*(1+w)/4; N18=(1-u^2)*(1+v)*(1+w)/4; (* to v nodes *) N4= (1+u)*(1-v^2)*(1-w)/4; N8= (1-u)*(1-v^2)*(1-w)/4; N16=(1+u)*(1-v^2)*(1+w)/4; N20=(1-u)*(1-v^2)*(1+w)/4; (* to w nodes *) N9= (1-u)*(1-v)*(1-w^2)/4; N10=(1+u)*(1-v)*(1-w^2)/4; N11=(1+u)*(1+v)*(1-w^2)/4; N12=(1-u)*(1-v)*(1-w^2)/4; (* solve the inverse transform *) Solve[{ x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19+ x20*N20-x==0, y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19+ y20*N20-y==0, z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19+ z20*N20-z==0}, {u,v,w}] Christopher J. Purcell Defence R&D Canada - Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== If I haven't missed a step, the following should work nicely -- best done before defining any of the symbols that appear: Attributes[dummyIf] = HoldAll; Attributes[dummyWhich] = HoldAll; expr = {If[Aa == Ab, a Sa + b Sb, If[Ca == 0 || Cb == 0, a Sa + b Sb, SS]], If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[ Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} /. {If -> dummyIf}; rule1 = dummyIf[a_, b_, dummyIf[c_, d_, e_]] -> dummyWhich[a, b, c, d, True, e]; rule2 = dummyIf[a_, dummyIf[ b_, c_, d_], e_] -> dummyWhich[a && b, c, a, d, True, e]; rule3 = dummyIf[a_, dummyIf[b_, c_, d_]] -> dummyWhich[a && b, c, a, d]; rule4 = dummyWhich[a__, b_, dummyIf[c_, d_, e_], f___] -> dummyWhich[a, b && c, d, b, e, f]; rule5 = dummyWhich[a__, b_, dummyWhich[c_, d_, e___], f___] -> dummyWhich[a, b && c, d, b, dummyWhich[e], f]; rule6 = dummyWhich[] :> Null; rule7 = HoldPattern[True && a_] :> a; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7} /. {dummyWhich -> Which The result of that last line is: {Which[Aa == Ab, a Sa + b Sb, Ca == 0 || Cb == 0, a Sa + b Sb, True, SS], Which[Aa == Ab, a Ca + b Cb, Ca == 0 || Cb == 0, a Ca + b Cb, True, CC], Which[Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X]} I've used Null where that would be the result of your original logic -- maybe you want it to be Nil. Or maybe you want to use Null instead of Nil. Your choice. Wherever you see Null, there's possibly a case you haven't covered. Bobby Treat -----Original Message----- If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== Dear Group, I have a program to take the local polynomial non parametric regression of two variables. It uses Compile, unfortunately, and regularly, but inconsistently, causes Mathematica to crash (in Win2K, with I forget what error, and in Win98/Mathematica4.0 with an invalid memory access from MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently on 4 different machines. Here is the code, if it doesn't crash the first time, it will the second or third: (* w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, 0}, {nn, _Integer, 0}, {ord, _Integer, 0}}, First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, 1], {q, 0, ord}], Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; *) (* !(tt = MemoryInUse[]; ListPlot[Table[{((i + 1))^2, (Timing[ nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, nn}]; testX = Table[i* .3 - Random[]*2, {i, nn}]; testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; Map[w[#, testX, testY, .1 + Random[], nn, 0] &, testX];])[([1])]/Second}, {i, 15}], PlotJoined -> True, PlotLabel -> ]; MemoryInUse[] - tt) *) I have followed Ted Ersek's tips and tricks (http://www.verbeia.com/mathematica/tips/tip_index.html) about Compile, and have tried changing all variable names (works sometimes), removing any hidden spaces, restructuring the formulas, changing all 0's to 0. 's and all 1's to 1. 's, etcetera etcetera, but I still can't comprehend what the problem might be. Doing w[[-2]] shows a list of op-code numbers, and one function name, Inverse[#1]&, so it seems to me that there are no problems with the use of Compile here. Would anyone have any thoughts??? Bernard Gress burnthebiscuit@netscape.net ==== Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2, however after working with this program for more than a month, trying every possible permutation and manipulation, and having it still crash, I am still worried that upgrading to 4.2 won't solve my problem. Can anyone else with 4.2 try running this program for me a good number of times, say 3 or 4, and see if they get similar good results? Bernard Gress Dear Group, I have a program to take the local polynomial non parametric regression of two variables. It uses Compile, unfortunately, and regularly, but inconsistently, causes Mathematica to crash (in Win2K, with I forget what error, and in Win98/Mathematica4.0 with an invalid memory access from MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently on 4 different machines. Here is the code, if it doesn't crash the first time, it will the second or third: (* w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, 0}, {nn, _Integer, 0}, {ord, _Integer, 0}}, First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, 1], {q, 0, ord}], Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; *) (* !(tt = MemoryInUse[]; ListPlot[Table[{((i + 1))^2, (Timing[ nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, nn}]; testX = Table[i* .3 - Random[]*2, {i, nn}]; testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; Map[w[#, testX, testY, .1 + Random[], nn, 0] &, testX];])[([1])]/Second}, {i, 15}], PlotJoined -> True, PlotLabel -> ]; MemoryInUse[] - tt) *) ==== I ran it 10 times on 4.2 with no crashes. > Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2, however after working > with this program for more than a month, trying every possible permutation and > manipulation, and having it still crash, I am still worried that upgrading to 4.2 > won't solve my problem. Can anyone else with 4.2 try running this program for me a > good number of times, say 3 or 4, and see if they get similar good results? > Bernard Gress Dear Group, I have a program to take the local polynomial non parametric regression > of two variables. It uses Compile, unfortunately, and regularly, but > inconsistently, causes Mathematica to crash (in Win2K, with I forget > what error, and in Win98/Mathematica4.0 with an invalid memory access from > MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently > on 4 different machines. Here is the code, if it doesn't crash the first time, it will the second > or third: (* > w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, > 0}, > {nn, _Integer, 0}, {ord, _Integer, 0}}, > First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, > 1], {q, 0, ord}], > Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, > ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . > Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* > E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; > *) (* > !(tt = MemoryInUse[]; > ListPlot[Table[{((i + 1))^2, (Timing[ > nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, > nn}]; > testX = Table[i* .3 - Random[]*2, {i, nn}]; > testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; > Map[w[#, testX, testY, .1 + Random[], nn, 0] &, > testX];])[([1])]/Second}, {i, 15}], PlotJoined - True, > PlotLabel -> ]; > MemoryInUse[] - tt) > *) > Reply-To: kuska@informatik.uni-leipzig.de ==== my Mathematica 4.2 does not crash and you may upgrade your version. Jens > > Dear Group, > > I have a program to take the local polynomial non parametric regression > of two variables. It uses Compile, unfortunately, and regularly, but > inconsistently, causes Mathematica to crash (in Win2K, with I forget > what error, and in Win98/Mathematica4.0 with an invalid memory access from > MathDLL.dll). I am running Mathematica 4.1, and have this problem consistently > on 4 different machines. > > Here is the code, if it doesn't crash the first time, it will the second > or third: > > (* > w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real, > 0}, > {nn, _Integer, 0}, {ord, _Integer, 0}}, > First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q, > 1], {q, 0, ord}], > Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, > ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] . > Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])* > E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]]; > *) > > (* > !(tt = MemoryInUse[]; > ListPlot[Table[{((i + 1))^2, (Timing[ > nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i, > nn}]; > testX = Table[i* .3 - Random[]*2, {i, nn}]; > testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon]; > Map[w[#, testX, testY, .1 + Random[], nn, 0] &, > testX];])[([1])]/Second}, {i, 15}], PlotJoined - True, > PlotLabel -> ]; > MemoryInUse[] - tt) > *) > > I have followed Ted Ersek's tips and tricks > (http://www.verbeia.com/mathematica/tips/tip_index.html) about Compile, > and have tried changing all variable names (works sometimes), removing > any hidden spaces, restructuring the formulas, changing all 0's to 0. 's > and all 1's to 1. 's, etcetera etcetera, but I still can't comprehend > what the problem might be. Doing w[[-2]] shows a list of op-code > numbers, and one function name, Inverse[#1]&, so it seems to me that > there are no problems with the use of Compile here. Would anyone have > any thoughts??? > > > Bernard Gress > burnthebiscuit@netscape.net ==== Mr Kuska, 4.2, I thought I had solved this problem so many times and still it would suddenly start crashing again our of the blue, after 20 or 30 executions. Bernard my Mathematica 4.2 does not crash and you may upgrade > your version. > ==== Expanding on my earlier simplification of the Moran Research code, I studied the problem a little more and found another useful Rule and a Rule that should help but doesn't. Maybe somebody can explain what I'm doing wrong on that one. My earlier result (after applying rule1, ... rule7) had the following as third element of a List in the definition of f: Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X] Several things occurred to me in terms of simplifying this. The first was that the last six arguments of Which could be replaced with two, as follows: Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True,Mod[X,180]] This probably has no advantage other than clarity, but that's worth the others: rule8 = dummyIf[a_ > b_, a_ - b_, dummyIf[a_ < 0, a_ + b_, a_]] :> Mod[a, b]; but it had no effect on the expression. Apparently there was no match, and I can't see why. The second thing I noticed was that the condition Ca == 0 && Cb == 0 occurs twice in the Which statement. The following rule fixes that kind of situation: rule9 = dummyWhich[a___, b_, c_, d__, b_, e_, f__] /; EvenQ[Length[List[a]]] && EvenQ[Length[List[d]]] && EvenQ[Length[List[f]]] :> dummyWhich[a, b, c, d, f]; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule9} The third thing I noticed was the treatment of Aa and Ab. The expressions If[Aa > 90, Aa - 90, Aa + 90] If[Ab > 90, Ab - 90, Ab + 90] in the original expression may be equivalent (depending on what's known about Aa and Ab a priori) to: Mod[Aa+90,180] Mod[Ab+90,180] If that is a valid assumption in the situation (no way for me to know), the expression is now Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] The next thing I notice is that the sixth condition, Z1==Z2, which results in Null if found True, isn't needed. If Z1==Z2 then one of the first five conditions is also true, so execution wouldn't get that far. Hence we can delete that condition-response pair. Finally, I'm stopping with this: Which[ Ca == 0 == Cb, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] I have no idea what you're actually doing with this code, but it looks weird even AFTER I've simplified it. Bobby Treat -----Original Message----- 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[ Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} /. {If -> dummyIf}; rule1 = dummyIf[a_, b_, dummyIf[c_, d_, e_]] -> dummyWhich[a, b, c, d, True, e]; rule2 = dummyIf[a_, dummyIf[ b_, c_, d_], e_] -> dummyWhich[a && b, c, a, d, True, e]; rule3 = dummyIf[a_, dummyIf[b_, c_, d_]] -> dummyWhich[a && b, c, a, d]; rule4 = dummyWhich[a__, b_, dummyIf[c_, d_, e_], f___] -> dummyWhich[a, b && c, d, b, e, f]; rule5 = dummyWhich[a__, b_, dummyWhich[c_, d_, e___], f___] -> dummyWhich[a, b && c, d, b, dummyWhich[e], f]; rule6 = dummyWhich[] :> Null; rule7 = HoldPattern[True && a_] :> a; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7} /. {dummyWhich -> Which The result of that last line is: {Which[Aa == Ab, a Sa + b Sb, Ca == 0 || Cb == 0, a Sa + b Sb, True, SS], Which[Aa == Ab, a Ca + b Cb, Ca == 0 || Cb == 0, a Ca + b Cb, True, CC], Which[Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X]} I've used Null where that would be the result of your original logic -- maybe you want it to be Nil. Or maybe you want to use Null instead of Nil. Your choice. Wherever you see Null, there's possibly a case you haven't covered. Bobby Treat -----Original Message----- If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== Sorry... ONE MORE simplification: Which[ Ca == 0 == Cb, Nil, Z1 == Z2, Which[Ca < 0, Aa, Cb < 0, Ab, Ca > 0, Mod[Aa + 90, 180], Cb > 0, Mod[Ab + 90, 180]], Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] I didn't like repeating the Z1==Z2 test. Upon noticing this, I thought at first that my rule5 caused this situation to occur, but actually I have to delete both rule 4 AND rule5 to eliminate it, and the resulting expression wouldn't be as easy to understand. Bobby Treat -----Original Message----- Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X] Several things occurred to me in terms of simplifying this. The first was that the last six arguments of Which could be replaced with two, as follows: Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True,Mod[X,180]] This probably has no advantage other than clarity, but that's worth the others: rule8 = dummyIf[a_ > b_, a_ - b_, dummyIf[a_ < 0, a_ + b_, a_]] :> Mod[a, b]; but it had no effect on the expression. Apparently there was no match, and I can't see why. The second thing I noticed was that the condition Ca == 0 && Cb == 0 occurs twice in the Which statement. The following rule fixes that kind of situation: rule9 = dummyWhich[a___, b_, c_, d__, b_, e_, f__] /; EvenQ[Length[List[a]]] && EvenQ[Length[List[d]]] && EvenQ[Length[List[f]]] :> dummyWhich[a, b, c, d, f]; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule9} The third thing I noticed was the treatment of Aa and Ab. The expressions If[Aa > 90, Aa - 90, Aa + 90] If[Ab > 90, Ab - 90, Ab + 90] in the original expression may be equivalent (depending on what's known about Aa and Ab a priori) to: Mod[Aa+90,180] Mod[Ab+90,180] If that is a valid assumption in the situation (no way for me to know), the expression is now Which[ Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] The next thing I notice is that the sixth condition, Z1==Z2, which results in Null if found True, isn't needed. If Z1==Z2 then one of the first five conditions is also true, so execution wouldn't get that far. Hence we can delete that condition-response pair. Finally, I'm stopping with this: Which[ Ca == 0 == Cb, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, Z1 == Z2 && Ca > 0, Mod[Aa + 90, 180], Z1 == Z2 && Cb > 0, Mod[Ab + 90, 180], Aa == Ab, Aa, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, True, Mod[X, 180]] I have no idea what you're actually doing with this code, but it looks weird even AFTER I've simplified it. Bobby Treat -----Original Message----- 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[ Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} /. {If -> dummyIf}; rule1 = dummyIf[a_, b_, dummyIf[c_, d_, e_]] -> dummyWhich[a, b, c, d, True, e]; rule2 = dummyIf[a_, dummyIf[ b_, c_, d_], e_] -> dummyWhich[a && b, c, a, d, True, e]; rule3 = dummyIf[a_, dummyIf[b_, c_, d_]] -> dummyWhich[a && b, c, a, d]; rule4 = dummyWhich[a__, b_, dummyIf[c_, d_, e_], f___] -> dummyWhich[a, b && c, d, b, e, f]; rule5 = dummyWhich[a__, b_, dummyWhich[c_, d_, e___], f___] -> dummyWhich[a, b && c, d, b, dummyWhich[e], f]; rule6 = dummyWhich[] :> Null; rule7 = HoldPattern[True && a_] :> a; expr //. {rule1, rule2, rule3, rule4, rule5, rule6, rule7} /. {dummyWhich -> Which The result of that last line is: {Which[Aa == Ab, a Sa + b Sb, Ca == 0 || Cb == 0, a Sa + b Sb, True, SS], Which[Aa == Ab, a Ca + b Cb, Ca == 0 || Cb == 0, a Ca + b Cb, True, CC], Which[Ca == 0 && Cb == 0, Nil, Z1 == Z2 && Ca < 0, Aa, Z1 == Z2 && Cb < 0, Ab, (Z1 == Z2 && Ca > 0) && Aa > 90, Aa - 90, Z1 == Z2 && Ca > 0, Aa + 90, Z1 == Z2 && (Cb > 0 && Ab > 90), Ab - 90, Z1 == Z2 && Cb > 0, Ab + 90, Z1 == Z2, Null, Aa == Ab, Aa, Ca == 0 && Cb == 0, Nil, Ca == 0, Ab, Cb == 0, Aa, Y == 0, Nil, X > 180, X - 180, X < 0, X + 180, True, X]} I've used Null where that would be the result of your original logic -- maybe you want it to be Nil. Or maybe you want to use Null instead of Nil. Your choice. Wherever you see Null, there's possibly a case you haven't covered. Bobby Treat -----Original Message----- If[Aa == Ab, a Ca + b Cb, If[Ca == 0 || Cb == 0, a Ca + b Cb, CC]], If[Ca == 0 && Cb == 0, Nil, If[Z1 == Z2, If[Ca < 0, Aa, If[Cb < 0, Ab, If[Ca > 0, If[Aa > 90, Aa - 90, Aa + 90], If[Cb > 0, If[Ab > 90, Ab - 90, Ab + 90]]]]], If[Aa == Ab, Aa, If[Ca == 0 && Cb == 0, Nil, If[Ca == 0, Ab, If[Cb == 0, Aa, If[Y == 0, Nil, If[X > 180, X - 180, If[X < 0, X + 180, X]]]]]]]]]} ==== If x1 through x20 aren't unknowns, you should have told me their values. If you can't, they are UNKNOWN. True, you're not solving for them... but they affect the dimensionality of the problem just as if you WERE solving for them. You have a 20-dimensional space full of contingencies -- solution forms that depend on the values of x1 through x20. The Solve function won't deal with contingencies even if it could, and if it tried, there would be too many. Bobby -----Original Message----- >Bobby -----Original Message----- >Sent: Saturday, September 07, 2002 1:54 AM >resend >Would someone with a very fast machine and lots of memory be willing to >try >this Solve for me? >It is the inverse of the 20 node quadratic hexahedral mapping used in >finite element analysis. >None of my computers can handle this - they run out of memory (using (*Hex20 Node definition in global coordinates *) >Clear[ >x1, y1, z1, >x2, y2, z2, >x3, y3, z3, >x4, y4, z4, >x5, y5, z5, >x6, y6, z6, >x7, y7, z7, >x8, y8, z8, >x9, y9, z9, >x10, y10, z10, >x11, y11, z11, >x12, y12, z12, >x13, y13, z13, >x14, y14, z14, >x15, y15, z15, >x16, y16, z16, >x17, y17, z17, >x18, y18, z18, >x19, y19, z19, >x20, y20, z20]; (* local coordinates *) >Clear[u, v, w]; (* Global co-ordinates *) >Clear[x, y, z]; (* corner nodes *) >N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; >N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; >N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; >N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; >N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; >N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; >N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; >N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; >(* to u nodes *) >N2= (1-u^2)*(1-v)*(1-w)/4; >N6= (1-u^2)*(1+v)*(1-w)/4; >N14=(1-u^2)*(1-v)*(1+w)/4; >N18=(1-u^2)*(1+v)*(1+w)/4; >(* to v nodes *) >N4= (1+u)*(1-v^2)*(1-w)/4; >N8= (1-u)*(1-v^2)*(1-w)/4; >N16=(1+u)*(1-v^2)*(1+w)/4; >N20=(1-u)*(1-v^2)*(1+w)/4; >(* to w nodes *) >N9= (1-u)*(1-v)*(1-w^2)/4; >N10=(1+u)*(1-v)*(1-w^2)/4; >N11=(1+u)*(1+v)*(1-w^2)/4; >N12=(1-u)*(1-v)*(1-w^2)/4; (* solve the inverse transform *) >Solve[{ >x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ >x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19 + >x20*N20-x==0, >y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ >y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19 + >y20*N20-y==0, >z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ >z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19 + >z20*N20-z==0}, >{u,v,w}] >Christopher J. Purcell >Defence R&D Canada - Atlantic >9 Grove St., PO Box 1012 >Dartmouth NS Canada B2Y 3Z7 Christopher J. Purcell Defence R&D Canada - Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== If we do think of x1...x20 as constants, it's still fourth-order, with three simultaneous equations. Evaluate this: Solve[a x^4 + b x^3 + c x^2 + d x + e == 0, x] and look at the four solutions found -- for a single variable and one equation! For your problem, I'm thinking there'd be at least 4^3 solutions, each of them even more complicated than these, and an unknown number of contingencies to deal with, depending on values of the xi. Check each radical for a negative argument, and the special cases multiply quickly. For some values of the xi, there'd be no solutions; for other values, many solutions. If you do manage to solve this, I'd love to see the method! Bobby -----Original Message----- many. Bobby -----Original Message----- >Bobby -----Original Message----- >Sent: Saturday, September 07, 2002 1:54 AM >resend >Would someone with a very fast machine and lots of memory be willing to >try >this Solve for me? >It is the inverse of the 20 node quadratic hexahedral mapping used in >finite element analysis. >None of my computers can handle this - they run out of memory (using (*Hex20 Node definition in global coordinates *) >Clear[ >x1, y1, z1, >x2, y2, z2, >x3, y3, z3, >x4, y4, z4, >x5, y5, z5, >x6, y6, z6, >x7, y7, z7, >x8, y8, z8, >x9, y9, z9, >x10, y10, z10, >x11, y11, z11, >x12, y12, z12, >x13, y13, z13, >x14, y14, z14, >x15, y15, z15, >x16, y16, z16, >x17, y17, z17, >x18, y18, z18, >x19, y19, z19, >x20, y20, z20]; (* local coordinates *) >Clear[u, v, w]; (* Global co-ordinates *) >Clear[x, y, z]; (* corner nodes *) >N1= (1-u)*(1-v)*(1-w)*(-2-u-v-w)/8; >N3= (1+u)*(1-v)*(1-w)*(-2+u-v-w)/8; >N5= (1+u)*(1+v)*(1-w)*(-2+u+v-w)/8; >N7= (1-u)*(1+v)*(1-w)*(-2-u+v-w)/8; >N13=(1-u)*(1-v)*(1+w)*(-2-u-v+w)/8; >N15=(1+u)*(1-v)*(1+w)*(-2+u-v+w)/8; >N17=(1+u)*(1+v)*(1+w)*(-2+u+v+w)/8; >N19=(1-u)*(1+v)*(1+w)*(-2-u+v+w)/8; >(* to u nodes *) >N2= (1-u^2)*(1-v)*(1-w)/4; >N6= (1-u^2)*(1+v)*(1-w)/4; >N14=(1-u^2)*(1-v)*(1+w)/4; >N18=(1-u^2)*(1+v)*(1+w)/4; >(* to v nodes *) >N4= (1+u)*(1-v^2)*(1-w)/4; >N8= (1-u)*(1-v^2)*(1-w)/4; >N16=(1+u)*(1-v^2)*(1+w)/4; >N20=(1-u)*(1-v^2)*(1+w)/4; >(* to w nodes *) >N9= (1-u)*(1-v)*(1-w^2)/4; >N10=(1+u)*(1-v)*(1-w^2)/4; >N11=(1+u)*(1+v)*(1-w^2)/4; >N12=(1-u)*(1-v)*(1-w^2)/4; (* solve the inverse transform *) >Solve[{ >x1*N1+x2*N2+x3*N3+x4*N4+x5*N5+x6*N6+x7*N7+x8*N8+x9*N9+x10*N10+ >x11*N11+x12*N12+x13*N13+x14*N14+x15*N15+x16*N16+x17*N17+x18*N18+x19*N19 + >x20*N20-x==0, >y1*N1+y2*N2+y3*N3+y4*N4+y5*N5+y6*N6+y7*N7+y8*N8+y9*N9+y10*N10+ >y11*N11+y12*N12+y13*N13+y14*N14+y15*N15+y16*N16+y17*N17+y18*N18+y19*N19 + >y20*N20-y==0, >z1*N1+z2*N2+z3*N3+z4*N4+z5*N5+z6*N6+z7*N7+z8*N8+z9*N9+z10*N10+ >z11*N11+z12*N12+z13*N13+z14*N14+z15*N15+z16*N16+z17*N17+z18*N18+z19*N19 + >z20*N20-z==0}, >{u,v,w}] >Christopher J. Purcell >Defence R&D Canada - Atlantic >9 Grove St., PO Box 1012 >Dartmouth NS Canada B2Y 3Z7 Christopher J. Purcell Defence R&D Canada - Atlantic 9 Grove St., PO Box 1012 Dartmouth NS Canada B2Y 3Z7 ==== The documentation you're talking about doesn't even deserve to be called documentation. A few hints; that's it. Bobby Treat -----Original Message----- > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== This is a question that's been asked and answered a number of times. One answer, by me, can be found by going to www.wolfram.com and selecting first Resource Library and then MathGroup on the Resource Library page; then search for direction field. You'll find, among many others, the URL: http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00163.html (This is not to chastise you for not first looking there, but to suggest a way for you to find answers more efficiently than waiting for the ou need to load the package, then manufacture a vector field whose plot is the slope field (what you call vector flow diagram). To do the latter, let me separately define the function giving the right-hand side of the ODE; you don't really have to do that, but could instead directly use as the first argument to PlotVectorField the right-hand side of my definition of f. << Graphics`PlotField` f[t_, y_] := {1, 1/y} field = PlotVectorField[f[t, y], {t, 0, 3}, {y, 0.05, 3}]; I gave a name to the graphics result just in order to re-display the field below along with the graph of one solution. First, find a general solution: soln = First @ DSolve[{y'[t] == 1/y[t], y[0] == 1}, y[t], t] {y[t] -> Sqrt[2]*Sqrt[1/2 + t]} grf = Plot[y[t] /. soln, {t, 0, 3}]; Now combine the plot with the field: Show[grf, field]; Note that PlotVectorField does not always give quite the result you might want, since the vector lengths are scaled with respect to the magnitude of the actual vectors. You might want just a direction field in which all arrows have the same length. You can produce such a graphic by using the ScaleFunction and ScaleFactor options to PlotVectorField. For example: field = PlotVectorField[f[t, y], {t, 0, 3}, {y, 0.05, 3}, ScaleFunction -> (1 &), ScaleFactor -> 0.175]; ... I have several differential equations I would like to plot in Mathematica. I would like to plot the Slope Fields of them though. Can anyone lead me in the right direction? I can solve the equations trivially but I want to display the slope fields. An example follows : y' + 2y = 3 ... -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street Amherst, MA 01375 ==== I am trying to implement a very simple sorted tree to quickly store some real numbers I need. I have written an add, delete, minimum, and pop (delete the lowest value) function and they seem to work ok but are very slow. Let's just look @ my implementation of the add part: nums=Null;(*my initial blank Tree) In[326]:= Clear[add] In[327]:= add[Null,x_Real]:=node[x,Null,Null] add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher] In[328]:= add[node[x_Real,lower_,higher_],y_Real]:= If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y]]] In[288]:= add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery_]]:=If[x>y, node[x,add[lowerx,node[y,lowery,highery]],higherx], node[x,lowerx,add[higherx,node[y,lowery,highery]]] ] Now this is my attempt to test how fast my add works: SeedRandom[5]; Do[nums=add[nums,Random[]],{5000}];//Timing Out[333]= {13.279 Second,Null} running on an 1.4GHz Athlon with 1GB of ram). Questions: 1. Is this as fast as I can get my code to run? 2. Am I doing something obviously stupid? 3. would Compiling things help? Husain ==== The vectors that NullSpace gives do not need to be orthogonal to each other. What about the following variant, that adds one vector at a time? It may not be fast enough for serious number crunching. OrthogonalComplement[v__ /; MatrixQ[{v}]] := With[{n = Length[NullSpace[{v}]]}, Take[Nest[Join[{First[NullSpace[#]]}, #] &, {v}, n], n]]; OrthonormalComplement[v__ /; MatrixQ[{v}]] := Map[#/Sqrt[#.#] &, OrthogonalComplement[v]]; When the input of OrthogonalComplement is integer, I expect the output to be integer too: OrthogonalComplement[{1, 2, 3}] {{1, -5, 3}, {-3, 0, 1}} Gianluca Gorni > > OrthogonalUnitVectors that I sent a few minutes ago doesn't do what I > thought it would. > After making either definition below I get the following: > > In[2]:= > s1=OrthogonalUnitVectors[{1,0,1/2,1,0},{0,1,-1,1/2,2}] > > Out[2]= > {{0, -2/Sqrt[5], 0, 0, 1/Sqrt[5]}, {-2/3, -1/3, 0, 2/3, 0}, {-1/3, 2/3, > 2/3, 0, 0}} > > > The dot products below aren't zero, so the vectors aren't orthogonal. What > went wrong? > > > In[3]:= > Part[s1,1].Part[s1,2] > > Out[3]= > 2/(3*Sqrt[5]) > > > In[4]:= > Part[s1,1].Part[s1,3] > > Out[3]= > -4/(3*Sqrt[5]) > > > -------------- > Hugh Goyder and David Park gave a most elegant function to find two > vectors that are orthogonal to one vector in 3D. The key to coming up > with the elegant solution is an understanding of Mathematica's NullSpace > function. We can easily make the version from Hugh and David much more > general with the version below. > ------------- > OrthogonalUnitVectors[vect__?VectorQ]:= > #/Sqrt[#.#]&/@NullSpace[{vect}] > > ------------- > The version above will give a set of unit orthogonal vectors if given any > number of vectors in any dimension. > So besides giving it a 3D vector we can give it the following: > OrthogonalUnitVectors[{2,1,0,-1,1}] > or > OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] > > ------------ > But the short version above isn't very robust. > (1) Clear[x,y,z];NullSpace[{{x,y,z}}] > returns two vectors orthogonal to {x,y,z}, but the two vectors > NullSpace returns aren't orthogonal to each other. > So (OrthogonalUnitVectors) should only work with numeric vectors. > > (2) We should ensure all the vectors have the same dimension and length > 1. > > I give a less concise version below that corrects these problems. > ------------ > > OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; > (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= > #/Sqrt[#.#]&/@NullSpace[{vect}] > > -------------- > Ted Ersek > Get Mathematica tips, tricks from > http://www.verbeia.com/mathematica/tips/Tricks.html > > ==== I am using MultipleListPlot to plot a range of 2D graphs and have found that the last graph, which has a much greater (by a factor of 4) x range than the others does not plot completely but is truncated in the x direction. By removing the Frame, I can see the points where these lie outside the Frame but these are not joined etc. How do I get over this? - Malcolm Woodruff Reply-To: kuska@informatik.uni-leipzig.de ==== set the PlotRange explicit PlotRange->{{0,largeX},Automatic} Jens > > I am using MultipleListPlot to plot a range of 2D graphs and have found that > the last graph, which has a much greater (by a factor of 4) x range than the > others does not plot completely but is truncated in the x direction. By > removing the Frame, I can see the points where these lie outside the Frame > but these are not joined etc. How do I get over this? > - > Malcolm Woodruff ==== I noticed the same thing when I attempted to plot data with disjoint x-ranges. One way is not to use the MultipleListPlot[] function. You can plot both the lines and the markers by applying Line and Point graphics to your datasets. And use Show[] to display everything on one plot. You can use the PlotSymbol[] function instead of Point. The PlotSymbol function is available in the MultipleListPlot package to get the diamond, star, square, etc. Another way is to modify the MultipleListPlot[] function. I modified the function to do multiple plots on a polar grid. WARNING - I advise you not to change any of the standpackages. Instead, first make a copy then modify it. One of the modifications I made was to change 'pts = First[Transpose[data]]' in the handleset function to 'pts=data'. This seems to work for my application. Hope this helps. Lawrence > I am using MultipleListPlot to plot a range of 2D graphs and have found that > the last graph, which has a much greater (by a factor of 4) x range than the > others does not plot completely but is truncated in the x direction. By > removing the Frame, I can see the points where these lie outside the Frame > but these are not joined etc. How do I get over this? > - > Malcolm Woodruff > > ==== Group, Sorry for the previous posting. The following solves (to some extent my problem) < (1) Is there a way in Mathematica 4.2 to put two separate gifs into a > single, cell side by side (with some intervening space), without > having to combine them in some graphics program first? In particular, I'd like to do that within a text cell. Even in a new Input cell, if I first create a GridBox (via Inut>Create > Table/Matrix/Palette) and then try to insert the first gif (via > Edit>Insert Object>Create from File ....), Mathematica promptly > crashes. (Mathematica 4.2 under Windows 2000.) You could do something like this: grlist = Map[Import[#, GIF]&, {, }] celist = Map[Cell[GraphicsData[PostScript, DisplayString[#]]]&, grlist] CellPrint[Cell[BoxData[GridBox[{celist}]], Text]] This embeds the PostScript versions of these graphics each as inline cells in a GridBox[] structure. > (2) Is there a way to cause a gif imported into a Mathematica 4.2 > notebook to become a hyperlink -- so that when the user clicks on the > gif the hyperlink's target is summoned? Again, we embed the PostScript graphic within an inline cell. Here is a function that does what you describe: createGIFHyperlink[gifImage_String, url_String] := NotebookWrite[EvaluationNotebook[], Cell[BoxData[ ButtonBox[ Cell[GraphicsData[PostScript, DisplayString[Import[gifImage, GIF]]]], ButtonStyle -> Hyperlink, ButtonData :> {URL[url], None}]], Text]] -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== > 1.) How to find the General Solution for below's partial differential > equation? > (y + u) du/dx + y (du/dy) = x - y > ** I use d to represent the partial differential symbol. > Can it be solved by function NDSolve in mathematica 4.1? How? It's been a while, but I suspect that the presence of the nonlinear convective term u du/dx alone makes a general solution unlikely. It's easy to get a numerical solution for a particular set of boundary conditions, but you are not guaranteed a solution. For instance, the following choice of a and b are skirting failure, as the diagnostic contour plot shows. Tom Burton Needs[Graphics`Colors`] !((soln = With[{a = (-1), b = 1.27, e = 0.001}, solutions = NDSolve[{((y + u[x, y])) [PartialD]_x u[x, y] + y [PartialD]_y u[x, y] == x - y, u[x, b] == 0, u[a, y] == 0}, u, {x, a, 10}, {y, b, 10}]; [IndentingNewLine]Plot3D[ Evaluate[u[x, y] /. [InvisibleSpace]First[solutions]], {x, a, 10}, {y, b, 10}, PlotPoints [Rule] 50]; [IndentingNewLine]ContourPlot[ Evaluate[y + u[x, y] /. [InvisibleSpace]First[solutions]], {x, a, 10}, {y, b, 10}, PlotPoints [Rule] 50, ColorFunction [Rule] ((If[#1 > e, Green, Red] &))][IndentingNewLine]];)) ==== I'd be happier if I could just control pagination, or if automatic pagination were done sensibly. Yes, I can make a page break where I want one, but I can't eliminate page-breaks that leave tons of white-space at the end of some pages. In some of my notebooks, Mathematica puts the first cell on a page by itself, using less than an inch --- and NOT because the next cell takes a whole page. If I force the first two cells to stay together, the problem just moves to the next page. It's enough to make Mathematica useless as a word processor all by itself. Bobby Treat -----Original Message----- derivations; - setting typefaces in tables of material. I figure most of this is do-able, but I don't have the time, or patience, to spend too much time on it. So, I'll be the first customer when you write the guide to math publishing in Mathematica - I just hope you won't have to use LaTeX to write it. Mark Westwood > > I would like to use mathematica type papers for my math courses, but > I'm having trouble formatting documents. Despite searching, I've been > unable to find a complete guide to word processing with mathematica. > Does anyone know where such a document could be found? ==== Bobby, Have a look at the Glue palette found here: --- Selwyn Hollis > I'd be happier if I could just control pagination, or if automatic > pagination were done sensibly. > > Yes, I can make a page break where I want one, but I can't eliminate > page-breaks that leave tons of white-space at the end of some pages. In > some of my notebooks, Mathematica puts the first cell on a page by > itself, using less than an inch --- and NOT because the next cell takes > a whole page. If I force the first two cells to stay together, the > problem just moves to the next page. > > It's enough to make Mathematica useless as a word processor all by > itself. > > Bobby Treat > > -----Original Message----- > > > Kenny, > > Sympathy but no solution. > > I too have been trying to use Mathematica (v4.2 most recently) to type > maths papers and the like but I'm not ready to ditch LaTeX yet. There > are just too many cases where I cannot figure out how to achieve what I > want in Mathematica, things like: > - left brackets spanning multiple lines for defining hybrid functions; > - vertical alignment of equals signs in multi-line equations or > derivations; > - setting typefaces in tables of material. > > I figure most of this is do-able, but I don't have the time, or > patience, to spend too much time on it. So, I'll be the first customer > when you write the guide to math publishing in Mathematica - I just hope > you won't have to use LaTeX to write it. > > Mark Westwood > > >>I would like to use mathematica type papers for my math courses, but >>I'm having trouble formatting documents. Despite searching, I've been >>unable to find a complete guide to word processing with mathematica. >>Does anyone know where such a document could be found? > > > > > ==== > > Wouldn't it be nice if NullSpace's behavior were DOCUMENTED? Otherwise, > it's futile to give it approximate numbers expecting any particular > behavior. Even if it always works, it may not work in the next version > of Mathematica. > > Bobby The expected, and documented, behavior is that the output should be a basis for the null space, that is, solutions of the homogeneous matrix equation A.x==0. If this were to stop working then that would be a serious bug. Is this the behavior you mean? The implementation notes of the manual mention that approximate NullSpace is based on a singular values decomposition. This in fact gives resulting vectors that are orthonormal by the usual conjugate-symmetric inner product on C (though these are now not normal to the original vector in this same inner product, unless they are real-valued). But this basis-orthogonality is not part of the mission of NullSpace and moreover should not become part of it. Hence that particular (and implementation dependent) aspect of NullSpace should not become documented. Daniel Lichtblau Wolfram Research ==== Wouldn't it be nice if NullSpace's behavior were DOCUMENTED? Otherwise, it's futile to give it approximate numbers expecting any particular behavior. Even if it always works, it may not work in the next version of Mathematica. Bobby -----Original Message----- enough for me. Therefore I modify Ted's routine to OrthogonalUnitVectors[vect__?(VectorQ[#, NumericQ] &)] /; (SameQ @@ Length /@ {vect}) && (Length[First[{vect}]] > 1) := #/Sqrt[#.#] & /@ NullSpace[{vect}// N] ---------------- Lets see what NullSpace does with approximate complex vectors. In[1]:= v1 = {1.0 I, 0.0, 0.5 I, 0.0, 1.0}; v2 = {0.0, 2.0, 1.0 I, 2.0, 0.5}; {v3,v4,v5} = NullSpace[{v1,v2}] Out[3]= {{-0.730153 + 0.*I, 0. - 0.138254*I, 0.250585 + 0.*I, 0. - 0.138254*I, 0. + 0.60486*I}, {0. + 0.*I, -0.515861 + 0.*I, 0. + 0.457321*I, 0.687357 + 0.*I, 0.22866 + 0.*I}, {0. + 0.*I, 0.510406 + 0.*I, 0. + 0.740442*I, -0.23274 + 0.*I, 0.370221 + 0.*I}} -------- In the next line we see NullSpace returned vectors that are orthogonal to the vectors we gave NullSpace. In[4]:= {v1.v3, v1.v4, v1.v5, v2.v3, v2.v4, v2.v5}//Chop Out[4]= {0, 0, 0, 0, 0, 0} ---------- However, the vectors returned aren't orthogonal to each other. In[5]:= {v3.v4, v3.v5, v4.v5}//Chop Out[5]= {0.229195*I, 0.371087*I, -0.677239} --------- I suppose an OrthogonalUnitVectors function that uses NullSpace should (1) Only accept real valued vectors. (2) Ensure NullSpace is given approximate vectors. ------ Ted Ersek ==== Plot[{x,x^2},{x,0,10}] Tomas Garza Mexico City ----- Original Message ----- ==== Mario, Here is a fancy version of your plot. I used Text statements within an Epilog option to label the two curves. The regular plot statement allows you to plot a series of functions inclosed in a list. Needs[Graphics`Colors`] Plot[{x, x^2}, {x, 0, 1}, PlotStyle -> {Black, Blue}, Frame -> True, FrameLabel -> {x, y}, PlotLabel -> Comparison of Two Functions, Epilog -> {Text[x, {0.5, 0.55}], Blue, Text[x^2, {0.7, 0.4}]}, Background -> Linen, ImageSize -> 500]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== >How can I plot with Mathematica two function in the same graphic? I >explain better: I'd like to draw a) y=x and b) y=x^2 in the same axes Plot[{x, x^2},{x,-2,2}] ==== This might be a convenient way of defining color functions: ClearAll[cfun] cfun[colors_List, brkPts_List] /; Length@colors == Length@brkPts := Function[z, Which @@ Sequence@Flatten@Transpose[{Less[z, #] & /@ brkPts, colors}]] colors = {White, RoyalBlue, White, Red, White}; brkPts = {-0.6, -0.42, 0.4, 0.6, Infinity}; ContourPlot[f[x, y], { x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30, ColorFunctionScaling -> False, ColorFunction -> cfun[colors, brkPts], Contours -> contourvalues]; colors = {Yellow, Peru, Salmon, Apricot, HotPink, Linen}; brkPts = {-0.6, -0.42, 0.2, 0.4, 0.6, Infinity}; Timing[ContourPlot[f[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30, ColorFunctionScaling -> False, ColorFunction -> cfun[colors, brkPts], Contours -> contourvalues];] Bobby Treat -----Original Message----- it is difficult to obtain in this plot. contourvalues = Complement[Range[-1, 1, 0.2], {0.}] {-1, -0.8, -0.6, -0.4, -0.2, 0.2, 0.4, 0.6, 0.8, 1.} Now we define a ColorFunction for the plot. I actually colored two different bands to show how you can make a general color function to give each band a desired color. cfun[z_] := Which[ -0.6 < z < -0.42, RoyalBlue, 0.4 < z < 0.6, Red, True, White] ContourPlot[f[x, y], {x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 30, ColorFunctionScaling -> False, ColorFunction -> cfun, Contours -> contourvalues]; Using the option ColorFunctionScaling -> False says that the z value will be the actual value of f[x,y]. Otherwise, in general, it will be scaled between 0 and 1. It is easier to write a color function when z is the actual value of the function. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== For what it's worth, here's a version of Simpson's rule that works with both equally spaced and unequally spaced points. simp = Compile[{x1,y1,x2,y2,x3,y3}, With[{h13=x1-x3, h12=x1-x2, h23=x2-x3}, (-y1*h23*(2x1-3x2+x3) - y2*h13^2 + y3*h12*(x1-3x2+2x3))*h13/(6h12*h23)]]; ListSimpson[vals_?VectorQ, dx_Real]:= With[{n=Length[vals]}, If[OddQ[n], (dx/3)*(First[vals] + Last[vals] + 4*Plus@@vals[[Range[2,n-1,2]]] + 2*Plus@@vals[[Range[3,n-2,2]]]), $Failed]]; ListSimpson[datapts_?MatrixQ] := If[OddQ[Length[datapts]], Plus@@(simp@@Flatten[#]&/@ Partition[datapts,3,2]), $Failed] (* equally spaced points*) data = Table[100*Sin[x], {x, 0, 100, 0.001}]; ListSimpson[data, .001] // Timing {0.21 Second, 13.7681} (* randomly spaced points *) Table[ {data = Sort[Table[With[{x = Random[Real,{0,100}]},{x,100*Sin[x]}],{100001}]]; ListSimpson[data] // Timing, With[{xvals = Transpose[data][[1]]}, gaps = Drop[RotateLeft[xvals] - xvals, -1]; {Min[gaps], Max[gaps]}]}, {4}] {{{1.62 Second, 13.8348}, {1.32223*10^-8, 0.0114454}}, {{1.59 Second, 13.8261}, {2.42163*10^-8, 0.0127803}}, {{1.62 Second, 13.8455}, {1.08923*10^-9, 0.0119059}}, {{1.54 Second, 13.7987}, {9.66814*10^-9, 0.0106988}}} --- Selwyn Hollis > Mathew, Some possibilities < Integrate[ > Interpolation[data, InterpolationOrder[Rule]1][x], > {x,0,100}]//Timing {4.56 Second,13.768} Trapezium rule with equal steps: #[[1]]+#[[-1]]+ 2 Tr[Take[#,{2,-2}]]&[data[[All,2]]] 0.01/2//Timing {0.22 Second,13.768} Trapezium rule with possibly unequal steps (Drop[#1,1] - Drop[#1,-1]).(Drop[#2,-1] + Drop[#2,1])&[ > data[[All,1]], data[[All,2]]]/2//Timing {0.83 Second,13.768} -- > Allan --------------------- > Allan Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > I've tracked down the slow operation of my Mathematica simulation > code to > lie in the ListIntegrate command: > > G[n_] := ListIntegrate[xsec Phi[n], 1] > > where both xsec and Phi[n] are 400 values long. > > Is there a way to speed up ListIntegrate via Compile or a similar > technique? > > Matt > --- > Matthew Rosen > Harvard-Smithsonian Center for Astrophysics > Mail Stop 59 > 60 Garden Street > Cambridge, MA 02138 > > e: mrosen@cfa.harvard.edu > o: (617) 496-7614 > > ==== Check out the NumericalMath`GaussianQuadrature` and NumericalMath`NewtonCotes` packages. Bobby Treat -----Original Message----- (or, better, NIntegrateInterpolatingFunction) on that (which is what ListIntegrate apparently does); or (2) apply a simple routine that implements the trapezoidal rule, Simpson's rule, or maybe some higher order method. Assuming you've chosen to take path #1, you need to realize the following: (a) NIntegrate[Interpolation[data, InterpolationOrder->1][x], {x,a,b}] is equivalent to the trapezoidal rule; (b) NIntegrate[Interpolation[data, InterpolationOrder->2][x], {x,a,b}] is *not* equivalent to Simpson's rule (because of the peculiar way that Interpolation works); (c) Interpolation[data, InterpolationOrder->k] generally does not return a smooth function unless you set InterpolationOrder->n-1, where n is the number of data points, which is the case where a single polynomial of degree n-1 fits the data points. (d) If you want to integrate a smooth interpolant, you can do this: <k][x], {x, 0, 5}, PlotRange -> All], {k, 1, 6}] (The last of those plots will give a warning message.) Having said all that, you really should consider path #2 instead. Here are a couple of links to a MathGroup discussion of last July (somehow the thread got split up): http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00490.html http://library.wolfram.com/mathgroup/archive/2002/Jul/msg00519.html I hope all this helps some. ---- Selwyn Hollis > Can someone provide me more information on how ListIntegrate works > than what is contained in the version 4 manual ? Is there a website > perhaps or tutorial ? > > I would like to know how the beginning and end of a list of {x,y} > pairs that is being integrated is dealt with by ListIntegrate. > > I know a series of polynomials is somehow used but how ? Do these > overlap ? Are they piecewise continuous ? > > Are these polynomials available for inspection ? How do they change as > a function of k ? > > optimum k value for a given list ? For any given list, will accuracy > monotonically increase with increasing values of k ? Is there > anything in the Option Inspector that could cause unexpected behaivor > with ListIntegrate ? > > Are there any good rules of thumb or procedures that will help ensure > a reasonable answer is produced ? > > Is there a way of estimating the error or accuracy of integration > performed by ListIntegrate ? > > > > ==== P.J., I'd be very interested in how you created these fancy cells. Do you open a cell, push Ctrl-Shift-e, type in all that text, then push Ctrl-Shift-e again? Bobby Treat -----Original Message----- 1) Put your function braches in the rows of a grid box structure. 2) Add the following options to your cell: ShowAutoStyles -> False SpanMaxSize -> Infinity The following cell snippet demonstrates how this influences the result. To view it, paste the Cell[] expression into a notebook and then click on Yes when you are prompted on whether the front end should interpret the result. Cell[BoxData[ FormBox[ RowBox[{ RowBox[{f, (, x, )}], =, RowBox[{{, GridBox[{ {x, RowBox[{x, , <, 0}]}, { SuperscriptBox[x, 2], RowBox[{0, [LessEqual], x, <, 1}]}, { RowBox[{sin, (, x, )}], RowBox[{1, [LessEqual], x, <, 2}]}, { RowBox[{[CapitalGamma], (, x, )}], RowBox[{x, [GreaterEqual], 2}]} }]}]}], TraditionalForm]], DisplayFormula, ShowAutoStyles->False, SpanMaxSize->Infinity] > - vertical alignment of equals signs in multi-line equations or > derivations; Put your equations in a GridBox and set the ColumnAlignments option to a string containing the equal sign. Cell[BoxData[ FormBox[GridBox[{ { RowBox[{ RowBox[{ RowBox[{3, x}], , +, , RowBox[{4, , y}]}], , =, , 9}]}, { RowBox[{ RowBox[{ RowBox[{2, x}], , -, , RowBox[{7, , y}]}], =, RowBox[{32, , -, , RowBox[{sin, (, x, )}]}]}]} }], TraditionalForm]], DisplayFormula, GridBoxOptions->{ColumnAlignments->{=}}] > - setting typefaces in tables of material. I think the Author Tools material that comes with Mathematica 4.2 might be able to help you do this. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== > I'd be very interested in how you created these fancy cells. Do you > open a cell, push Ctrl-Shift-e, type in all that text, then push > Ctrl-Shift-e again? Surely you have grossly overestimated my expertise with Mathematica typesetting language syntax. :-) Here is the walkthrough for creating each sample cell. Example 1: 1) Set down a cell insertion point in your notebook. 3) Click on the cell's bracket. 4) Click on the front end menu command sequence: Format -> Cell Style -> DisplayFormula 5) Click on the front end menu command sequence: Cell -> Display As -> TraditionalForm 6) Click on the front end menu command: Format -> Option Inspector... 7) Make sure that the Option Inspector scope indicator is set to selection. 8) Enter the name of the option ShowAutoStyles into the search field and press the Lookup button. 9) Change the value of the option ShowAutoStyles from True to False. This prevents the front end from showing the left brace with the umatched syntax coloring. 10) Look up the option SpanMaxSize as was done in step (8). 11) Change the value of this option to Infinity. 12) Close the Option Inspector dialog. 13) Click within the cell you just created to create an editor caret. 14) Type in the text f(x) = { 4 x 2. 17) Enter in the function branch definitions in the left column, and the domains of definition in the right column. You can use the Tab key to navigate between grid elements. Example 2: 1) Repeat Steps (1) - (11) in Example 1. 2) With the cell bracket still selected, look up the option named ColumnAlignments. Change it from {Center} to {=}. 3) Close the Option Inspector dialog. 4) Click within the cell you just created to create an editor caret. 6) Enter in the equations, with one equation per grid element. I used the front end menu command Edit -> Copy As -> Cell Expression to get the underlying expressions. Hope that demystifies the procedure for you. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== You're not doing anything dumb as far as I can see, but you're using far more memory than necessary. Here are statistics for your algorithm on my machine: SeedRandom[5]; nums = Null Do[nums = add[nums, Random[]], {5000}]; // Timing nums // LeafCount nums // ByteCount Count[nums, Null, Infinity] Count[nums, node[_, Null, _], Infinity] Count[nums, node[_, _, Null], Infinity] Count[nums, node[_, Null, Null], Infinity] Count[nums, node[___], Infinity] Count[nums, node[_, _node | _?NumericQ, _node | _?NumericQ], Infinity] Depth[nums] {4.406000000000001*Second, Null} 15001 240000 5001 (* Null values in the tree *) 2458 (* nodes without left offspring *) 2543 (* nodes without right offspring *) 1669 (* leaf nodes *) 4999 (* total nodes *) 1667 (* nodes with both left and right offspring *) 28 (* minus one, makes 27 levels in the tree *) It's clearly not ideal to store 5001 Nulls for 5000 actual values! Here's a method that doesn't change the algorithm much, but changes the storage method a great deal: First of all, I'm lazy, so I'll redefine <,>,<=,>=, etc. to make the code simpler: Unprotect[Less, Greater, LessEqual, GreaterEqual]; Less[a : _node ..] := Less @@ (First /@ {a}) LessEqual[a : _node ..] := LessEqual @@ (First /@ {a}) Greater[a : _node ..] := Greater @@ (First /@ {a}) GreaterEqual[a : _node ..] := GreaterEqual @@ (First /@ {a}) Protect[Less, Greater, LessEqual, GreaterEqual]; Again because I'm lazy, I'll define node so that I don't have to consciously avoid leaf nodes and unnecessary nesting: ClearAll[node] node[a___, node[b_], c___] = node[a, b, c]; node[node[a__]] = node[a]; Here's my add function: Clear[add] add[Null, x_] = node[x]; add[x_, (y_)?NumericQ] := add[node[x], node[y]] add[(x_)?NumericQ, y_] := add[node[x], node[y]] add[node[x_], node[y_]] := If[x > y, node[x, y], node[y, x]] (* <-- THERE! *) add[node[x_, lower_], y_node] := Which[y >= node[x], node[x, lower, y], y <= node[lower], node[lower, y, x], True, node[y, lower, x]] add[node[x_, lower_, higher_], y_node] /; node[y] <= node[x] := node[x, add[lower, y], higher] add[node[x_, lower_, higher_], y_node] := node[x, lower, add[higher, y]] Where I have a pointer is the code that prevents adding right-offspring to a leaf node. That avoids nodes like your node[a,Null,c]. When you would have node[a,b,Null], I have node[a,b]. When you would have node[a,Null,Null], I use a itself. Timing and space requirements are much better now: SeedRandom[5]; nums = Null Timing[Do[nums = add[nums, Random[]], {5000}]; ] {2.109*Second, Null} LeafCount[nums] ByteCount[nums] Count[nums, Null, Infinity] Count[nums, node[_], Infinity] Count[nums, node[_, _], Infinity] Count[nums, node[_, _, _], Infinity] Count[nums, node[___], Infinity] Depth[nums] 7852 (* 48% fewer leaf expressions, mostly due to Nulls and right-offspring eliminated *) 165624 (* 31% less storage *) 0 (* no Nulls, versus 5001 *) 0 (* no leaf nodes, versus 1669 *) (* no nodes without left-offspring, versus 2458 *) 705 (* nodes without right offspring, versus 2543 *) 2146 (* nodes with both left and right offspring, versus 1667 *) 2851 (* total nodes *) 21 (* 21 tree levels versus 27 *) The logical structure is identical to yours except that there are no nodes with only right-offspring. This incidentally tends to reduce tree depth. The storage format is far different: there are no trivial (childless) nodes, and nodes with left-offspring but no right-offspring are stored without a Null on the right. I could make this quite a bit faster, I think, if I spent time on the code to eliminate changes to Less, Greater, etc. and the frequent nesting followed by unnesting that goes on in the algorithm. It might take twice as much code, however, so I like it as is. You're probably better off storing these things in a heap, of course. Or -- better yet -- use the built-in Sort and Ordering functions. Bobby Treat -----Original Message----- In[327]:= add[Null,x_Real]:=node[x,Null,Null] add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher] In[328]:= add[node[x_Real,lower_,higher_],y_Real]:= If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y]]] In[288]:= add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery_]]:=If[x>y , node[x,add[lowerx,node[y,lowery,highery]],higherx], node[x,lowerx,add[higherx,node[y,lowery,highery]]] ] Now this is my attempt to test how fast my add works: SeedRandom[5]; Do[nums=add[nums,Random[]],{5000}];//Timing Out[333]= {13.279 Second,Null} RH7.3 running on an 1.4GHz Athlon with 1GB of ram). Questions: 1. Is this as fast as I can get my code to run? 2. Am I doing something obviously stupid? 3. would Compiling things help? Husain ==== > I am using MultipleListPlot to plot a range of 2D graphs and > have found that > the last graph, which has a much greater (by a factor of 4) x > range than the > others does not plot completely but is truncated in the x > direction. By > removing the Frame, I can see the points where these lie > outside the Frame > but these are not joined etc. How do I get over this? The easiest way is to expand your PlotRange to include the errant points. Dave. ==== Probably a rather simple question: what is the easiest way to open a notebook, execute it, then quit, from the command line? I would like to be able to do this from a Makefile. Sidney Reply-To: kuska@informatik.uni-leipzig.de ==== what may be in the *.m files? Mathematica commands ? that you can load into the kernel ? Makr all your input cells in the notebook as initialization, save it as an *.m file, add a Quit[] as the last command to the *.m file and run it with math << yourJustGeneratedMFile Jens Regardds > > > Probably a rather simple question: what is the easiest way to open a > notebook, execute it, then quit, from the command line? I would like to be > able to do this from a Makefile. > > > Sidney ==== I made the algorithm more than twice as fast with very little change, while eliminating modifications to <,>,<=, and >=. Most of the improvement, in fact, was due to eliminating those changes AFTER the code was changed so they wouldn't be used anyway. That's because the comparisons appear everywhere, so adding rules to those functions really slows down pattern matching. Clear[add, node] node[a___, node[b_], c___] = node[a, b, c]; node[node[a__]] = node[a]; add[Null, x_] = node[x]; add[x_, (y_)?NumericQ] := add[node[x], node[y]] add[(x_)?NumericQ, y_] := add[node[x], node[y]] add[node[x_], node[y_]] := If[x >= y, node[x, y], node[y, x]] add[node[x_, lower_], y_node] := Which[First[y] >= x, node[x, lower, y], First[y] <= lower, node[lower, y, x], True, node[y, lower, x]] add[node[x_, lower_, higher_], y_node] /; First[y] <= x := node[x, add[lower, y], higher] add[node[x_, lower_, higher_], y_node] := node[x, lower, add[higher, y]] SeedRandom[5]; nums = Null Timing[Do[nums = add[nums, Random[]], {5000}]; ] {0.968*Second, Null} None of the other stats changed. Bobby Treat -----Original Message----- Count[nums, Null, Infinity] Count[nums, node[_, Null, _], Infinity] Count[nums, node[_, _, Null], Infinity] Count[nums, node[_, Null, Null], Infinity] Count[nums, node[___], Infinity] Count[nums, node[_, _node | _?NumericQ, _node | _?NumericQ], Infinity] Depth[nums] {4.406000000000001*Second, Null} 15001 240000 5001 (* Null values in the tree *) 2458 (* nodes without left offspring *) 2543 (* nodes without right offspring *) 1669 (* leaf nodes *) 4999 (* total nodes *) 1667 (* nodes with both left and right offspring *) 28 (* minus one, makes 27 levels in the tree *) It's clearly not ideal to store 5001 Nulls for 5000 actual values! Here's a method that doesn't change the algorithm much, but changes the storage method a great deal: First of all, I'm lazy, so I'll redefine <,>,<=,>=, etc. to make the code simpler: Unprotect[Less, Greater, LessEqual, GreaterEqual]; Less[a : _node ..] := Less @@ (First /@ {a}) LessEqual[a : _node ..] := LessEqual @@ (First /@ {a}) Greater[a : _node ..] := Greater @@ (First /@ {a}) GreaterEqual[a : _node ..] := GreaterEqual @@ (First /@ {a}) Protect[Less, Greater, LessEqual, GreaterEqual]; Again because I'm lazy, I'll define node so that I don't have to consciously avoid leaf nodes and unnecessary nesting: ClearAll[node] node[a___, node[b_], c___] = node[a, b, c]; node[node[a__]] = node[a]; Here's my add function: Clear[add] add[Null, x_] = node[x]; add[x_, (y_)?NumericQ] := add[node[x], node[y]] add[(x_)?NumericQ, y_] := add[node[x], node[y]] add[node[x_], node[y_]] := If[x > y, node[x, y], node[y, x]] (* <-- THERE! *) add[node[x_, lower_], y_node] := Which[y >= node[x], node[x, lower, y], y <= node[lower], node[lower, y, x], True, node[y, lower, x]] add[node[x_, lower_, higher_], y_node] /; node[y] <= node[x] := node[x, add[lower, y], higher] add[node[x_, lower_, higher_], y_node] := node[x, lower, add[higher, y]] Where I have a pointer is the code that prevents adding right-offspring to a leaf node. That avoids nodes like your node[a,Null,c]. When you would have node[a,b,Null], I have node[a,b]. When you would have node[a,Null,Null], I use a itself. Timing and space requirements are much better now: SeedRandom[5]; nums = Null Timing[Do[nums = add[nums, Random[]], {5000}]; ] {2.109*Second, Null} LeafCount[nums] ByteCount[nums] Count[nums, Null, Infinity] Count[nums, node[_], Infinity] Count[nums, node[_, _], Infinity] Count[nums, node[_, _, _], Infinity] Count[nums, node[___], Infinity] Depth[nums] 7852 (* 48% fewer leaf expressions, mostly due to Nulls and right-offspring eliminated *) 165624 (* 31% less storage *) 0 (* no Nulls, versus 5001 *) 0 (* no leaf nodes, versus 1669 *) (* no nodes without left-offspring, versus 2458 *) 705 (* nodes without right offspring, versus 2543 *) 2146 (* nodes with both left and right offspring, versus 1667 *) 2851 (* total nodes *) 21 (* 21 tree levels versus 27 *) The logical structure is identical to yours except that there are no nodes with only right-offspring. This incidentally tends to reduce tree depth. The storage format is far different: there are no trivial (childless) nodes, and nodes with left-offspring but no right-offspring are stored without a Null on the right. I could make this quite a bit faster, I think, if I spent time on the code to eliminate changes to Less, Greater, etc. and the frequent nesting followed by unnesting that goes on in the algorithm. It might take twice as much code, however, so I like it as is. You're probably better off storing these things in a heap, of course. Or -- better yet -- use the built-in Sort and Ordering functions. Bobby Treat -----Original Message----- In[327]:= add[Null,x_Real]:=node[x,Null,Null] add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher] In[328]:= add[node[x_Real,lower_,higher_],y_Real]:= If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y]]] In[288]:= add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery_]]:=If[x>y , node[x,add[lowerx,node[y,lowery,highery]],higherx], node[x,lowerx,add[higherx,node[y,lowery,highery]]] ] Now this is my attempt to test how fast my add works: SeedRandom[5]; Do[nums=add[nums,Random[]],{5000}];//Timing Out[333]= {13.279 Second,Null} RH7.3 running on an 1.4GHz Athlon with 1GB of ram). Questions: 1. Is this as fast as I can get my code to run? 2. Am I doing something obviously stupid? 3. would Compiling things help? Husain ==== > > Daniel, > > I don't mean to be overly critical of WRI's documentation -- it's very > good, as such things go. Nor do I like to overlook chances to make it > better. Do you? I'll try to address your specific remarks below and then return to this. > Your own comments below point out that we should expect vectors > resulting from NullSpace to be orthonormal by the usual > conjugate-symmetric inner product on C. But that's not spelled out > (documented) for dummies like myself who don't know that's a natural > result of singular values decomposition. My comments indicate that they will be orthonormal, for approximate numeric matrix input, so long as the implementation is based on SVD. But that's not by any means part of what NullSpace is required to do, and it is quite clearly implementation dependent. > The mission of NullSpace (or any function) is to adhere to > documentation, so reasonable persons may differ on whether orthogonality > is a feature we should depend on. Well... the name NullSpace gives a pretty good idea of what it needs to do. When you stop to consider all the matrix types (approximate numbers, exact numbers, symbolic, numeric but with non-number elements e.g. Pi and Sqrt[2]) you quickly realize that different types will most likely be handled by different methods, and these may have different characteristics of output e.g. normalized vectors, vectors with last nonzero component equal to one, or other quirks. But these are artifacts of implementation, not part of the requirements of a null space. > The mission of documentation is to tell us what to expect. When it > doesn't, the result is that we spend all this time discussing issues > online, trying to figure things out. A simple don't depend on > orthogonal results would be nice, if that's the intent. Perhaps. If there is strong reason to expect that people might depend on such results in the first place. I don't think there is. > In any case, I just spent ten minutes LOOKING for implementation notes > for NullSpace, and have not found any. Searching for implementation > notes doesn't help and there's no link from NullSpace. What use is > documentation I can't find? > > In general, I don't like Mathematica's quirky Help Browser, in which I > cannot search for anything that's not indexed. Every other help engine > on my computer (and there are hundreds) allows me to search for words, > and that's exactly what I need in order to find all mentions of > NullSpace. I found it in the back of the book, appendix A.9, Some Notes on Internal Implementation. See A.9.4, Approximate numerical linear algebra. In the Help Browser, click on The Mathematica Book and then type implementation in the window. The second URL it gives is A.9. I'll grant you one might reasonably desire a good search engine. I just want to indicate that what is there now is not entirely useless in this instance provided you at least know about the existance of these notes in the book. > Bobby Treat > [...] To respond to your question at the beginning, yes, I also like to see improvements in documentation. I certainly agree that a good search engine would be useful in this case. Though note that I also may not be using the Help Browser to its fullest capabilities (I claim no great familiarity with the Mathematica user interface). As for the specific issue of what to document about NullSpace, suffice it to say that I do not favor making claims beyond what it is required to do. Daniel Lichtblau Wolfram Research ==== Daniel, I don't mean to be overly critical of WRI's documentation -- it's very good, as such things go. Nor do I like to overlook chances to make it better. Do you? Your own comments below point out that we should expect vectors resulting from NullSpace to be orthonormal by the usual conjugate-symmetric inner product on C. But that's not spelled out (documented) for dummies like myself who don't know that's a natural result of singular values decomposition. The mission of NullSpace (or any function) is to adhere to documentation, so reasonable persons may differ on whether orthogonality is a feature we should depend on. The mission of documentation is to tell us what to expect. When it doesn't, the result is that we spend all this time discussing issues online, trying to figure things out. A simple don't depend on orthogonal results would be nice, if that's the intent. In any case, I just spent ten minutes LOOKING for implementation notes for NullSpace, and have not found any. Searching for implementation notes doesn't help and there's no link from NullSpace. What use is documentation I can't find? In general, I don't like Mathematica's quirky Help Browser, in which I cannot search for anything that's not indexed. Every other help engine on my computer (and there are hundreds) allows me to search for words, and that's exactly what I need in order to find all mentions of NullSpace. Bobby Treat -----Original Message----- > of Mathematica. > > Bobby The expected, and documented, behavior is that the output should be a basis for the null space, that is, solutions of the homogeneous matrix equation A.x==0. If this were to stop working then that would be a serious bug. Is this the behavior you mean? The implementation notes of the manual mention that approximate NullSpace is based on a singular values decomposition. This in fact gives resulting vectors that are orthonormal by the usual conjugate-symmetric inner product on C (though these are now not normal to the original vector in this same inner product, unless they are real-valued). But this basis-orthogonality is not part of the mission of NullSpace and moreover should not become part of it. Hence that particular (and implementation dependent) aspect of NullSpace should not become documented. Daniel Lichtblau Wolfram Research ==== I've this problem with NIntegrate: ********************************************** In[1]=f[y_,z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[z]+1) ) In[2]=F[z_]: = NIntegrate[f[y,z], {z, 0, Infinity} ********************************************** Mathematica 4.0 says: **************************************************************************** * NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is not numerical at {y}={1.}. **************************************************************************** ** What is it?? -- Rob_jack Reply-To: kuska@informatik.uni-leipzig.de ==== do you realy think that 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) with the z inside is numerical ? or do you mean F[z_?NumericQ]: = NIntegrate[f[y,z], {y, 0, Infinity}] Jens > > > I've this problem with NIntegrate: > ********************************************** > In[1]=f[y_,z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[z]+1) ) > > In[2]=F[z_]: = NIntegrate[f[y,z], {z, 0, Infinity} > ********************************************** > > Mathematica 4.0 says: > > **************************************************************************** > * > NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is not > numerical at {y}={1.}. > **************************************************************************** > ** > > What is it?? > > > -- > Rob_jack ==== do you realy think that 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) with the z inside is numerical ? or do you mean F[z_?NumericQ]: = NIntegrate[f[y,z], {y, 0, Infinity}] > I'm a newbie, bat I mean: ************************* In[1]= NumericQ[z] Out[1]=False ************************* BTW, z is a real number. -- Rob_jack ==== There is an error in the previous message. This is the just msg: ********************************************** In[1]=f[y_,z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[y]+1) ) In[2]=F[z_]: = NIntegrate[f[y,z], {y, 0, Infinity} ********************************************** Mathematica 4.0 says: **************************************************************************** NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is not numerical at {y}={1.}. **************************************************************************** What is it?? Moreover, I have used the following procedure: ****************************************************** If z<<1, f[y,z]=Sum[(-1)^n*a^n*(1+z)^2n *(y^(2n+4)/(Exp[y]+1),{n, 0, N} ] here a=(8.44*10^-4)^2 therefore: F[z]:=Sum[(-1)^n*a^n*(1+z)^2n *(y^(2n+4)/(Exp[y]+1) * Gamma[2 n+5]*Zeta[2 n+5],{n, 0, N} ] this series (N<+oo) only approximates the function for small z, and me it interests the behavior of F for z in the range 800-1300. Thx in advance. Rob_jack ==== > > I've this problem with NIntegrate: > ********************************************** > In[1]=f[y_,z_]: = (y^4/( (1+(8.44*10^-4)^2 * (1+z)^2 y^2) (Exp[z]+1) ) > > In[2]=F[z_]: = NIntegrate[f[y,z], {z, 0, Infinity} > ********************************************** > > Mathematica 4.0 says: > > **************************************************************************** > * > NIntegrate: : inum : Integrand 1.07577/( 1+7.12336*10^-7 (1. + z)^2 ) is not > numerical at {y}={1.}. > **************************************************************************** > ** > > What is it?? > I doubt that you could input your equations as you stated: The first input has a missing ) The second one a missing ] In both equations there should be no space in := Apart from that the second definitions doesn't seem to make much sense, maybe it should be F[y_] := ... Have you assigned y some value before (I get a different error message, when I mix up the y and z as you did.) Good luck Alois -- Vienna University of Technology, A-1040 Wiedner Hauptstr. 8-10 ==== Daniel, We mostly agree. I simply look at things from a slightly different (user, non-WRI) perspective. My original point was -- in line with your own comments -- that people shouldn't depend on NullSpace to return orthogonal vectors even when it seems to do so, because it's not documented behavior. (Although YOU knew about it and could point to documentation of it! Sort of.) Unlike you, perhaps, I consider the lack of search capabilities in Help an EGREGIOUS failing -- a mistake no other Help engine makes (so far as I know). Fix that, and 90% of my complaints about documentation would go away; I could have found the implementation notes on NullSpace, for instance, without already KNOWING where they are. That is precisely what annoys me most of the time; the information is there, but I can't find it. (If searching for implementation works, why doesn't implementation notes yield anything at all?) Now that I've found this page, I'll add it to all the other information locations I'm trying to remember. (There's not much there anyway, though.) Bobby -----Original Message----- I'll try to address your specific remarks below and then return to this. > Your own comments below point out that we should expect vectors > resulting from NullSpace to be orthonormal by the usual > conjugate-symmetric inner product on C. But that's not spelled out > (documented) for dummies like myself who don't know that's a natural > result of singular values decomposition. My comments indicate that they will be orthonormal, for approximate numeric matrix input, so long as the implementation is based on SVD. But that's not by any means part of what NullSpace is required to do, and it is quite clearly implementation dependent. > The mission of NullSpace (or any function) is to adhere to > documentation, so reasonable persons may differ on whether orthogonality > is a feature we should depend on. Well... the name NullSpace gives a pretty good idea of what it needs to do. When you stop to consider all the matrix types (approximate numbers, exact numbers, symbolic, numeric but with non-number elements e.g. Pi and Sqrt[2]) you quickly realize that different types will most likely be handled by different methods, and these may have different characteristics of output e.g. normalized vectors, vectors with last nonzero component equal to one, or other quirks. But these are artifacts of implementation, not part of the requirements of a null space. > The mission of documentation is to tell us what to expect. When it > doesn't, the result is that we spend all this time discussing issues > online, trying to figure things out. A simple don't depend on > orthogonal results would be nice, if that's the intent. Perhaps. If there is strong reason to expect that people might depend on such results in the first place. I don't think there is. > In any case, I just spent ten minutes LOOKING for implementation notes > for NullSpace, and have not found any. Searching for implementation > notes doesn't help and there's no link from NullSpace. What use is > documentation I can't find? > > In general, I don't like Mathematica's quirky Help Browser, in which I > cannot search for anything that's not indexed. Every other help engine > on my computer (and there are hundreds) allows me to search for words, > and that's exactly what I need in order to find all mentions of > NullSpace. I found it in the back of the book, appendix A.9, Some Notes on Internal Implementation. See A.9.4, Approximate numerical linear algebra. In the Help Browser, click on The Mathematica Book and then type implementation in the window. The second URL it gives is A.9. I'll grant you one might reasonably desire a good search engine. I just want to indicate that what is there now is not entirely useless in this instance provided you at least know about the existance of these notes in the book. > Bobby Treat > [...] To respond to your question at the beginning, yes, I also like to see improvements in documentation. I certainly agree that a good search engine would be useful in this case. Though note that I also may not be using the Help Browser to its fullest capabilities (I claim no great familiarity with the Mathematica user interface). As for the specific issue of what to document about NullSpace, suffice it to say that I do not favor making claims beyond what it is required to do. Daniel Lichtblau Wolfram Research ==== Bobby Treat -----Original Message----- > > Yes, I can make a page break where I want one, but I can't eliminate > page-breaks that leave tons of white-space at the end of some pages. In > some of my notebooks, Mathematica puts the first cell on a page by > itself, using less than an inch --- and NOT because the next cell takes > a whole page. If I force the first two cells to stay together, the > problem just moves to the next page. > > It's enough to make Mathematica useless as a word processor all by > itself. > > Bobby Treat > > -----Original Message----- > > > Kenny, > > Sympathy but no solution. > > I too have been trying to use Mathematica (v4.2 most recently) to type > maths papers and the like but I'm not ready to ditch LaTeX yet. There > are just too many cases where I cannot figure out how to achieve what I > want in Mathematica, things like: > - left brackets spanning multiple lines for defining hybrid functions; > - vertical alignment of equals signs in multi-line equations or > derivations; > - setting typefaces in tables of material. > > I figure most of this is do-able, but I don't have the time, or > patience, to spend too much time on it. So, I'll be the first customer > when you write the guide to math publishing in Mathematica - I just hope > you won't have to use LaTeX to write it. > > Mark Westwood > > >>I would like to use mathematica type papers for my math courses, but >>I'm having trouble formatting documents. Despite searching, I've been >>unable to find a complete guide to word processing with mathematica. >>Does anyone know where such a document could be found? > > > > > ==== Group, Sorry for the previous posting. The following solves (to some extent my problem) <1 0.02 times2=First[Timing[fLPartition[3,20];]]/. Second->1 0.18 times3=First[Timing[fLPartition[3,30];]]/. Second->1 0.701 times4=First[Timing[fLPartition[3,40];]]/. Second->1 1.913 times5=First[Timing[fLPartition[3,50];]]/. Second->1 4.236 times6=First[Timing[fLPartition[3,60];]]/. Second->1 8.222 times7=First[Timing[fLPartition[3,70];]]/. Second->1 14.39 times8=First[Timing[fLPartition[3,80];]]/. Second->1 23.563 So far so good. But for times9=First[Timing[fLPartition[3,90];]]/. Second->1 The computation does not always end. Some times it ends some times it does not (I aborted the process four times after 1 hour of computing and running out of, 2Gbites of, virtual memory) Emilio Martin-Serrano ___________________________________ Emilio Martin-Serrano Schlumberger Oil & Gas Business Consulting Principal 1325 South Dairy Ashford Road Houston, TX 77077 ==== I'm going to try using Mathematica to typeset some mathematics because I know that my students would benefit from being able to do the same., and they'll need someone who can answer their questions, etc. etc. I'm pretty comfortable with some things (e.g., Mathematica's recognition of latex commands for most characters), and now I'm ready to push the envelope a bit. Q1: How can I typeset a table or array of information (e.g., list of variables with definitions) so that information in one column is centered and information in another column is aligned flush left? I know exactly how I would do this in LaTeX, but I find no information on how to do this in Mathematica. Q2. How can I embed a Quicktime movie into a Mathematica notebook (e.g., so someone with MathReader can play the animation)? That's all for now. -- Jason Miller, Ph.D. Division of Mathematics and Computer Science Truman State University 100 East Normal St. Kirksville, MO 63501 http://vh216801.truman.edu 660.785.7430 ==== Jason, On item #1 I can help you. I have a notebook that explains the basics of creating tables using either TableForm or Gridboxes. Should get you started. It can be downloaded from my Mathematica course web site: http://www.higgins.ucdavis.edu/ECH198.php Use the link for lecture 3. Brian > I'm going to try using Mathematica to typeset some mathematics > because I know that my students would benefit from being able to do > the same., and they'll need someone who can answer their questions, > etc. etc. > > I'm pretty comfortable with some things (e.g., Mathematica's > recognition of latex commands for most characters), and now I'm ready > to push the envelope a bit. > > Q1: How can I typeset a table or array of information (e.g., list of > variables with definitions) so that information in one column is > centered and information in another column is aligned flush left? I > know exactly how I would do this in LaTeX, but I find no information > on how to do this in Mathematica. > > Q2. How can I embed a Quicktime movie into a Mathematica notebook > (e.g., so someone with MathReader can play the animation)? > > That's all for now. ==== It seems there is an error in the BinCounts function of Mathematica's standard <Left, FontSize->18], Cell[< Sept. 9, 2002 Mark D. Normand UMass Dept. of Food Science mnormand@foodsci.umass.edu >, Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[< Load the Data Manipulation functions from the Statistics Standard Package. >, Text, TextAlignment->Left], Cell[BoxData[ (<< Statistics`DataManipulation`)], Input] }, Open ]], Cell[CellGroupData[{ Cell[Assign data to the vector (1D list) dat., Text, TextAlignment->Left], Cell[BoxData[ ((dat = {63, 184, 23, 14, 17, 32, 26, 666, 27, 11, 28, 53, 37, 29, 4, 60, 7, 23, 94, 18, 43, 15, 74, 42, 81, 8, 7, 19, 0, 27, 87, 35, 3, 24, 94, 42, 4, 7, 18, 7, 38, 1, 0, 61, 3, 40, 22, 8, 3, 2, 0, 2, 5, 5, 7, 0, 9, 2, 11, 13, 105, 51, 36, 149, 147, 12, 1, 1, 7, 8, 10, 1, 7, 25, 38, 142, 15, 8, 9, 16, 0, 1, 4, 3, 31, 30, 10};))], Input] }, Open ]], Cell[CellGroupData[{ Cell[Count the number of dat data rows., Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ (datRows = Length[dat])], Input], Cell[BoxData[ (87)], Output] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[Find the minimum value in the dat data rows., Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ (datMin = Min[dat])], Input], Cell[BoxData[ (0)], Output] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[Find the maximum value in the dat data rows., Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ (datMax = Max[dat])], Input], Cell[BoxData[ (666)], Output] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[Calculate the number of histogram bins to use., Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ (datBins = Ceiling[Log[2, datRows]])], Input], Cell[BoxData[ (7)], Output] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[Set the width of a histogram bin., Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ (datBinWidth = N[((datMax - datMin))/datBins])], Input], Cell[BoxData[ (95.14285714285714`)], Output] }, Open ]] }, Open ]], Cell[CellGroupData[{ TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ Cell[BoxData[ ({76, 5, 0, 0, 0, 0, 0, 1})], Output] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[< For the above dat list, if datBins equals, for example, 5,7,10,14 of histogram bins generated) is one more than the assigned datBins value. Yet 13 or 16. Why!? (Is this a bug?) >, Text, TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ Cell[BoxData[ (8)], Output] }, Open ]] }, Open ]] }, ScreenRectangle->{{0, 1024}, {0, 748}}, CellGrouping->Manual, WindowSize->{520, 626}, WindowMargins->{{-1, Automatic}, {Automatic, -1}}, MacintoshSystemPageSetup->< 0080001804P000000_82@?okonh34`9B;@<5:0?l00;m009H0UP0000068dB`0B` 02d5X5k/02H80@4101P00BL?00400@00000000000000P0010000020D00000000 0000000000000000000004T400002004> ] ==== On my machine, replacing Null with made Husain's code 8 times faster on the same test: 0.592 seconds versus 4.688. I suppose making the same change in my code makes no difference because there are no Nulls in the tree (except one, very briefly), or perhaps because I have fewer patterns that involve Nulls. By rearranging the order of my rules, and deleting a couple that were never used, I made my algorithm about 15% faster, getting the time down to 0.906. Mihajlo's amazing discovery beats that, of course -- it's 50% faster. I suppose what we've found is that (1) my algorith makes the code four to five times faster by reducing expression complexity, tree depth, and memory use, but it's a slower algorithm otherwise (too many rules?); and (2) Mathematica pattern matching and code execution has a real problem with Null used as if it means something. Bobby -----Original Message----- add[node[x_Real, lower_, higher_], y_Real] := node[x, lower, add[higher, y]]; nums = NULL; SeedRandom[5]; Do[nums = add[nums, Random[]], {5000}] // Timing Out {5.11 Second, Null} Clear[add]; add[Null, x_Real] := node[x, Null, Null]; add[node[x_Real, lower_, higher_], y_Real] /; x > y := node[x, add[lower, y], higher]; add[node[x_Real, lower_, higher_], y_Real] := node[x, lower, add[higher, y]]; nums = Null; SeedRandom[5]; Do[nums = add[nums, Random[]], {5000}] // Timing Out {41.03 Second, Null} Also: Simplify[1==Null] 1==Null doesn't evaluate to false!! Btw. changing Null to NULL in your code doesn't infulence the speed... Mihajlo Vanevic mvane@EUnet.yu 2002-09-09 ************************************************************** * At 2002-09-09, 00:29:00 ************************************************************** >You're not doing anything dumb as far as I can see, but you're using far >more memory than necessary. Here are statistics for your algorithm on >my machine: > >SeedRandom[5]; >nums = Null >Do[nums = add[nums, Random[]], {5000}]; // Timing >nums // LeafCount >nums // ByteCount >Count[nums, Null, Infinity] >Count[nums, node[_, Null, _], Infinity] >Count[nums, node[_, _, Null], Infinity] >Count[nums, node[_, Null, Null], Infinity] >Count[nums, node[___], Infinity] >Count[nums, node[_, _node | _?NumericQ, _node | _?NumericQ], Infinity] >Depth[nums] {4.406000000000001*Second, Null} >15001 >240000 >5001 (* Null values in the tree *) >2458 (* nodes without left offspring *) >2543 (* nodes without right offspring *) >1669 (* leaf nodes *) >4999 (* total nodes *) >1667 (* nodes with both left and right offspring *) >28 (* minus one, makes 27 levels in the tree *) > >It's clearly not ideal to store 5001 Nulls for 5000 actual values! > >Here's a method that doesn't change the algorithm much, but changes the >storage method a great deal: > >First of all, I'm lazy, so I'll redefine <,>,<=,>=, etc. to make the >code simpler: > >Unprotect[Less, Greater, LessEqual, GreaterEqual]; >Less[a : _node ..] := Less @@ (First /@ {a}) >LessEqual[a : _node ..] := LessEqual @@ (First /@ {a}) >Greater[a : _node ..] := Greater @@ (First /@ {a}) >GreaterEqual[a : _node ..] := GreaterEqual @@ (First /@ {a}) >Protect[Less, Greater, LessEqual, GreaterEqual]; > >Again because I'm lazy, I'll define node so that I don't have to >consciously avoid leaf nodes and unnecessary nesting: > >ClearAll[node] >node[a___, node[b_], c___] = node[a, b, c]; >node[node[a__]] = node[a]; > >Here's my add function: > >Clear[add] >add[Null, x_] = node[x]; >add[x_, (y_)?NumericQ] := add[node[x], node[y]] >add[(x_)?NumericQ, y_] := add[node[x], node[y]] >add[node[x_], node[y_]] := If[x > y, node[x, y], node[y, x]] (* <-- >THERE! *) >add[node[x_, lower_], y_node] := > Which[y >= node[x], node[x, lower, y], > y <= node[lower], node[lower, y, x], True, node[y, lower, x]] >add[node[x_, lower_, higher_], y_node] /; > node[y] <= node[x] := node[x, add[lower, y], higher] >add[node[x_, lower_, higher_], y_node] := node[x, lower, add[higher, >y]] > >Where I have a pointer is the code that prevents adding right-offspring >to a leaf node. That avoids nodes like your node[a,Null,c]. When you >would have node[a,b,Null], I have node[a,b]. When you would have >node[a,Null,Null], I use a itself. > >Timing and space requirements are much better now: > >SeedRandom[5]; >nums = Null >Timing[Do[nums = add[nums, Random[]], {5000}]; ] {2.109*Second, Null} > >LeafCount[nums] >ByteCount[nums] >Count[nums, Null, Infinity] >Count[nums, node[_], Infinity] >Count[nums, node[_, _], Infinity] >Count[nums, node[_, _, _], Infinity] >Count[nums, node[___], Infinity] >Depth[nums] 7852 (* 48 fewer leaf expressions, > mostly due to Nulls and right-offspring eliminated *) >165624 (* 31 less storage *) >0 (* no Nulls, versus 5001 *) >0 (* no leaf nodes, versus 1669 *) > (* no nodes without left-offspring, versus 2458 *) >705 (* nodes without right offspring, versus 2543 *) >2146 (* nodes with both left and right offspring, versus 1667 *) >2851 (* total nodes *) >21 (* 21 tree levels versus 27 *) > >The logical structure is identical to yours except that there are no >nodes with only right-offspring. This incidentally tends to reduce tree >depth. > >The storage format is far different: there are no trivial (childless) >nodes, and nodes with left-offspring but no right-offspring are stored >without a Null on the right. > >I could make this quite a bit faster, I think, if I spent time on the >code to eliminate changes to Less, Greater, etc. and the frequent >nesting followed by unnesting that goes on in the algorithm. It might >take twice as much code, however, so I like it as is. > >You're probably better off storing these things in a heap, of course. > >Or -- better yet -- use the built-in Sort and Ordering functions. > >Bobby Treat -----Original Message----- So Slow? > >I am trying to implement a very simple sorted tree to quickly store some >real numbers I need. I have written an add, delete, minimum, and pop >(delete the lowest value) function and they seem to work ok but are very >slow. Let's just look @ my implementation of the add part: >nums=Null;(*my initial blank Tree) >In[326]:= >Clear[add] > >In[327]:= >add[Null,x_Real]:=node[x,Null,Null] > >add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher] > >In[328]:= >add[node[x_Real,lower_,higher_],y_Real]:= > If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y]]] > >In[288]:= >add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery_]]:=If[x> y >, > node[x,add[lowerx,node[y,lowery,highery]],higherx], > node[x,lowerx,add[higherx,node[y,lowery,highery]]] > ] > >Now this is my attempt to test how fast my add works: > >SeedRandom[5]; >Do[nums=add[nums,Random[]],{5000}];//Timing > >Out[333]= >{13.279 Second,Null} > >RH7.3 >running on an 1.4GHz Athlon with 1GB of ram). > >Questions: >1. Is this as fast as I can get my code to run? >2. Am I doing something obviously stupid? >3. would Compiling things help? >Husain ************************************************************** ==== The following is a button that will export a selected graphic as a JPEG, ButtonBox[JPEG, ButtonFunction :> Module[{sel}, SelectionMove[InputNotebook[], All, Cell]; sel = NotebookRead[InputNotebook[]]; If[Head[sel] === Cell, If[!ValueQ[dpi], dpi = Automatic]; ImageSize -> Automatic, ImageResolution -> dpi, ConversionOptions -> {Quality -> 75}]]], ButtonEvaluator -> Automatic, Active -> True]//DisplayForm It works fine as long as the graphic is no wider than about 330 pixels. If the graphic is wider than 330 pixels, then the size of exported graphic is correct, but everything on the right beyond the first 330 pixels is blank. There seems to be no problem with the height though. Any ideas on how to fix or get around this problem? --- Selwyn Hollis Reply-To: kuska@informatik.uni-leipzig.de ==== not with Mathematica 4.2. But the problem can be the page width that may be used to convert the Cell[], if you can you should use the Graphics[]/Graphics3D[] .. inside the Cell or the PostScript string in the GraphicsData[] Jens > > The following is a button that will export a selected graphic as a JPEG, > > ButtonBox[JPEG, > ButtonFunction : Module[{sel}, > SelectionMove[InputNotebook[], All, Cell]; > sel = NotebookRead[InputNotebook[]]; > If[Head[sel] === Cell, > If[!ValueQ[dpi], dpi = Automatic]; > ImageSize -> Automatic, ImageResolution -> dpi, > ConversionOptions -> {Quality -> 75}]]], > ButtonEvaluator -> Automatic, Active -> True]//DisplayForm > > It works fine as long as the graphic is no wider than about 330 pixels. > If the graphic is wider than 330 pixels, then the size of exported > graphic is correct, but everything on the right beyond the first 330 > pixels is blank. There seems to be no problem with the height though. > > Any ideas on how to fix or get around this problem? > > --- > Selwyn Hollis ==== I am having some trouble with numerical integration. !(((Timing[ ansOUT = {}; [IndentingNewLine]For[EbNo = 0, EbNo <= 2, EbNo += 10/10, [IndentingNewLine]linEbNo = 10^(EbNo/10); [IndentingNewLine]M = 64; [IndentingNewLine]K = Log[2, M]; [IndentingNewLine]p = (M/2)/(M - 1) Sum[ Binomial[M - 1, n] (((-1)))^(n + 1)/(1 + n) Exp[(- linEbNo) K n/(1 + n)], {n, 1, M - 1}]; [IndentingNewLine]Pm = (1/@(2 [Pi])) NIntegrate[ 1 - ((((1/@(2 [Pi])) NIntegrate[ Exp[(-x^2)/2], {x, (-[Infinity]), y}, WorkingPrecision -> 32 ]))^(M - 1)) Exp[((-1)/2) ((y - @(2 K linEbNo)))^2], {y, (- [Infinity]), [Infinity]}, WorkingPrecision -> 32]; [IndentingNewLine]Pb = ((M/2)/(M - 1)) Pm; [IndentingNewLine]AppendTo[ ansOUT, {N[a, 4], N[p, 8], N[Pb, 8]}];[IndentingNewLine]];])([IndentingNewLine]))) TableForm[ansOUT] The code can also be downloaded from http://www.itee.uq.edu.au/~dsalman/_downloads/Proakis.nb Col. 2(symblic formula) and 3 (result of numerical integration) of the variable ansOUT should be identical. However the numerical integration is giving a 0 answer. Can anyone please suggest how a solution to this problem. Salman ==== Reply-To: kuska@informatik.uni-leipzig.de ==== Needs[Graphics`Graphics`] LogPlot[Exp[-x],{x,0,10}] ?? Jens > > ==== <>ac.dat all done in an instant (relatively speaking) and without the transient burst of kernel memory usage. Ditto Import and Get. Can anyone explain this? Mike ==== Dear DrBob, I fear that your diagnosis of the efficiency problems in Husain's binary tree implementation is not correct. Furthermore your code is inefficient and awkward. Consider the following implementation using list to represent the tree. It is three lines long and is three times faster than yours on my computer though it uses twice as much memory as your representation. myadd[{},x_]:={x,{},{}}; myadd[{v_,a_,b_},x_]:=If[v>x, {v,myadd[a,x],b}, {v,a,myadd[b,x]}] t={}; Timing[Do[t=myadd[t,Random[]],{5000}];] {1.98 Second,Null} The real problem with the implementation is probably that the tree structure has to be 'copied' each time when add is called. You have to write tree = add[tree, x] t2 = add[t1, x] then you have *two* trees t1 and t2 which differ by the one element inserted by add. To the best of my knowledge, the internal representation of t1 and t2 in Mathematica is a tree too. But in principle the user code is duplicated in Mathematica. A further problem of all direct implementations is that they cannot be compiled (since they use pattern matching and the tree is a nested structure). Thus I guess that the efficient way to implement tree data structures is the indirect one using heaps (i.e. a combination of contiguous arrays with length known in advance and hashing). Johannes Ludsteck > You're not doing anything dumb as far as I can see, but you're using far > more memory than necessary. Here are statistics for your algorithm on > my machine: > > SeedRandom[5]; > nums = Null > Do[nums = add[nums, Random[]], {5000}]; // Timing > nums // LeafCount > nums // ByteCount > Count[nums, Null, Infinity] > Count[nums, node[_, Null, _], Infinity] > Count[nums, node[_, _, Null], Infinity] > Count[nums, node[_, Null, Null], Infinity] > Count[nums, node[___], Infinity] > Count[nums, node[_, _node | _?NumericQ, _node | _?NumericQ], Infinity] > Depth[nums] > > {4.406000000000001*Second, Null} > 15001 > 240000 > 5001 (* Null values in the tree *) > 2458 (* nodes without left offspring *) > 2543 (* nodes without right offspring *) > 1669 (* leaf nodes *) > 4999 (* total nodes *) > 1667 (* nodes with both left and right offspring *) > 28 (* minus one, makes 27 levels in the tree *) > > It's clearly not ideal to store 5001 Nulls for 5000 actual values! > > Here's a method that doesn't change the algorithm much, but changes the > storage method a great deal: > > First of all, I'm lazy, so I'll redefine <,>,<=,>=, etc. to make the > code simpler: > > Unprotect[Less, Greater, LessEqual, GreaterEqual]; > Less[a : _node ..] := Less @@ (First /@ {a}) > LessEqual[a : _node ..] := LessEqual @@ (First /@ {a}) > Greater[a : _node ..] := Greater @@ (First /@ {a}) > GreaterEqual[a : _node ..] := GreaterEqual @@ (First /@ {a}) > Protect[Less, Greater, LessEqual, GreaterEqual]; > > Again because I'm lazy, I'll define node so that I don't have to > consciously avoid leaf nodes and unnecessary nesting: > > ClearAll[node] > node[a___, node[b_], c___] = node[a, b, c]; > node[node[a__]] = node[a]; > > Here's my add function: > > Clear[add] > add[Null, x_] = node[x]; > add[x_, (y_)?NumericQ] := add[node[x], node[y]] > add[(x_)?NumericQ, y_] := add[node[x], node[y]] > add[node[x_], node[y_]] := If[x > y, node[x, y], node[y, x]] (* <-- > THERE! *) > add[node[x_, lower_], y_node] := > Which[y >= node[x], node[x, lower, y], > y <= node[lower], node[lower, y, x], True, node[y, lower, x]] > add[node[x_, lower_, higher_], y_node] /; > node[y] <= node[x] := node[x, add[lower, y], higher] > add[node[x_, lower_, higher_], y_node] := node[x, lower, add[higher, > y]] > > Where I have a pointer is the code that prevents adding right-offspring > to a leaf node. That avoids nodes like your node[a,Null,c]. When you > would have node[a,b,Null], I have node[a,b]. When you would have > node[a,Null,Null], I use a itself. > > Timing and space requirements are much better now: > > SeedRandom[5]; > nums = Null > Timing[Do[nums = add[nums, Random[]], {5000}]; ] > > {2.109*Second, Null} > > LeafCount[nums] > ByteCount[nums] > Count[nums, Null, Infinity] > Count[nums, node[_], Infinity] > Count[nums, node[_, _], Infinity] > Count[nums, node[_, _, _], Infinity] > Count[nums, node[___], Infinity] > Depth[nums] > > 7852 (* 48% fewer leaf expressions, > mostly due to Nulls and right-offspring eliminated *) > 165624 (* 31% less storage *) > 0 (* no Nulls, versus 5001 *) > 0 (* no leaf nodes, versus 1669 *) > (* no nodes without left-offspring, versus 2458 *) > 705 (* nodes without right offspring, versus 2543 *) > 2146 (* nodes with both left and right offspring, versus 1667 *) > 2851 (* total nodes *) > 21 (* 21 tree levels versus 27 *) > > The logical structure is identical to yours except that there are no > nodes with only right-offspring. This incidentally tends to reduce tree > depth. > > The storage format is far different: there are no trivial (childless) > nodes, and nodes with left-offspring but no right-offspring are stored > without a Null on the right. > > I could make this quite a bit faster, I think, if I spent time on the > code to eliminate changes to Less, Greater, etc. and the frequent > nesting followed by unnesting that goes on in the algorithm. It might > take twice as much code, however, so I like it as is. > > You're probably better off storing these things in a heap, of course. > > Or -- better yet -- use the built-in Sort and Ordering functions. > > Bobby Treat > > -----Original Message----- > > > > I am trying to implement a very simple sorted tree to quickly store some > real numbers I need. I have written an add, delete, minimum, and pop > (delete the lowest value) function and they seem to work ok but are very > slow. Let's just look @ my implementation of the add part: > nums=Null;(*my initial blank Tree) > In[326]:= > Clear[add] > > In[327]:= > add[Null,x_Real]:=node[x,Null,Null] > > add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher] > > In[328]:= > add[node[x_Real,lower_,higher_],y_Real]:= > If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y]]] > > In[288]:= > add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery_]]:=If[x>y > , > node[x,add[lowerx,node[y,lowery,highery]],higherx], > node[x,lowerx,add[higherx,node[y,lowery,highery]]] > ] > > > > Now this is my attempt to test how fast my add works: > > SeedRandom[5]; > Do[nums=add[nums,Random[]],{5000}];//Timing > > Out[333]= > {13.279 Second,Null} > > RH7.3 > running on an 1.4GHz Athlon with 1GB of ram). > > Questions: > 1. Is this as fast as I can get my code to run? > 2. Am I doing something obviously stupid? > 3. would Compiling things help? > > > Husain > > > <><><><><><><><><><><><> Johannes Ludsteck Economics Department University of Regensburg Universitaetsstrasse 31 93053 Regensburg ==== Is it possible to configure a style sheet so that functions or data shown in graphs are coloured (colored :)) in working but black in printing...without actually re-executing the function that created the graphics? thanks Mike Reply-To: kuska@informatik.uni-leipzig.de ==== no because the PostScript creation know nothing about the notebook frontend. Mathematica does its graphics in PostScript since version 1.0 but the notebook frontend was introduced in version 2.x and the actual typsetting/markup format was introduced in version 3.0. Jens > > Is it possible to configure a style sheet so that functions or data shown in > graphs are coloured (colored :)) in working but black in printing...without > actually re-executing the function that created the graphics? > > thanks > > Mike ==== A commonly used symbol for the Floor function is a square bracket with the upper indents removed. Is this symbol part of Mathematica's built-in symbols? I think not, so then, can it be constructed by hand. Jack ==== It turns out that Mathematica does have the floor symbols! Use esc l f esc for the left floor and esc r f esc for the right floor. In fact, if you type in esc l f esc a esc r f esc Mathematica will interpret the input as Floor[a]. Carl Woll Physics Dept U of Washington A commonly used symbol for the Floor function is a square bracket with the > upper indents removed. Is this symbol part of Mathematica's built-in symbols? I > think not, so then, can it be constructed by hand. Jack ==== > A commonly used symbol for the Floor function is a square bracket with > the upper indents removed. Is this symbol part of Mathematica's built-in > symbols? Sure. Just look for Floor in A.10 Listing of Major Built-In Mathematica Objects! For example, you can use [LeftFloor] and [RightFloor] to get the symbols you want. David Reply-To: kuska@informatik.uni-leipzig.de ==== what may [LeftFloor] and [RightFloor] show on screen ? It's easy to find in the complete characters palette | Operators | General Jens > > > A commonly used symbol for the Floor function is a square bracket with the > upper indents removed. Is this symbol part of Mathematica's built-in symbols? I > think not, so then, can it be constructed by hand. > > Jack ==== > > > A commonly used symbol for the Floor function is a square bracket with the > upper indents removed. Is this symbol part of Mathematica's built-in symbols? I > think not, so then, can it be constructed by hand. > > Jack [LeftFloor] and [RightFloor] can be used for this. Look at Chapter Advanced Mathematics/Mathematical and Other Notations/ Operators. Yours, Alexander -- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== Needs[Graphics`Graphics`] LogLinearPlot[Sqrt[x], {x, 1., 1000}, ImageSize -> 500]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Approved: Steven M. Christensen , Moderator ==== > I'm pretty comfortable with some things (e.g., Mathematica's > recognition of latex commands for most characters), and now I'm ready > to push the envelope a bit. > > Q1: How can I typeset a table or array of information (e.g., list of > variables with definitions) so that information in one column is > centered and information in another column is aligned flush left? I > know exactly how I would do this in LaTeX, but I find no information > on how to do this in Mathematica. See Section 2.8.11 of _The Mathematica Book_. http://documents.wolfram.com/v4/MainBook/2.8.11.html At the beginning of that section, you will find a description of the options that one may apply to GridBox[] objects, which are used to construct tables, matrices, and button palettes. More information on the values that these options may take can be found in the front end option documentation. http://documents.wolfram.com/v4/OtherInformation/GridBoxOptions.html With the current selection in your notebook being the table itself, you can use the Option Inspector dialog (with its scope set to selection) to change the ColumnAlignments option to {Center, Left}, which means that first column elements should be centered, and that subsequent columns should be left justified. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== I don't know about elegance or simplicity, but I do have a FASTER solution, incidentally using combinations code that often comes in handy for me. Here's that code: << DiscreteMath`Combinatorica`; ClearAll[combinations]; r = Range[1, 9]; combinations::usage = combinations[list,n:{__Integer}] lists the combinations of list taken n at a time; combinations[r_List, n_Integer, {}] := If[n > Length@r, {}, DiscreteMath`Combinatorica`KSubsets[r, n]]; combinations[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@ DiscreteMath`Combinatorica`KSubsets[Complement[r, e], n]; combinations[r_List, n_Integer, e : {__?VectorQ}] := Flatten[combinations[r, n, #] & /@ e, 1]; combinations[r_List, n : {__Integer}] := Which[Plus @@ n == Length@r, Join[#, Complement[r, #]] & /@ combinations[r, Drop[n, -1]], Plus @@ n > Length@r, {}, True, Fold[combinations[r, #2, #1] &, {}, n]] The following duplicates your fLPartitions function, but is about 40% faster and uses about 15% less memory (for this example): Quit << DiscreteMath`Combinatorica` fLPartition[ksN_, r_] := With[{ks = KSubsets[ Range[r], ksN], ks1 = Partition[Range[r], 1]}, MapThread[ Complement[Append[#1, #2], (Sequence @@ {#1} & ) /@ Partition[#2, 1]] & , {Array[ks1 & , Length[ ks]], ks}]] Module[{ksN = 2}, While[ksN < r + 1, s = fLPartition[ksN, r]; ksN = ksN + 1; Print[s]]] Timing[fLPartition[3, 80]; ] {11.389999999999999*Second, Null} MaxMemoryUsed[] 233956264 Quit wantCombinations (* this loads my cominations function definition *) ClearAll[mine] mine[k_, n_] := (Join[List /@ Complement[ Range[n], #1], {#1}] & ) /@ combinations[Range[n], {k}] Timing[mine[3, 80]; ] {6.734999999999999*Second, Null} MaxMemoryUsed[] 195828264 However, I would change the storage structure to replace {{1},{2},...,{7}} with just {1,2,...7}. That cuts memory usage by 85% from your method for this example: Quit wantCombinations ClearAll[mySecond] mySecond[k_, n_] := (Join[Complement[Range[n], #1], {#1}] & ) /@ combinations[Range[n], {k}] Timing[mySecond[3, 80]; ] {2.922*Second, Null} (* versus 11.485 with your code, 6.7 with my other code *) MaxMemoryUsed[] 43996408 (* 44MB versus 234MB with your code, 196 MB with my other code *) Those comparisons include memory used during code execution; byte counts for that example are 134,742,424 for my storage method and 287,560,024 for yours. If you sometimes have to have a partition in your format, its easy enough to temporarily convert it from mine with the following function: f = Join[List /@ Drop[#1,-1], {Last[#1]}] & ; First[mySecond[2, 10]] f[%] {3, 4, 5, 6, 7, 8, 9, 10, {1, 2}} {{3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2}} First[fLPartition[2, 10]] {{3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {1, 2}} Bobby Treat -----Original Message----- [ksN<(r+1),s=fLPartition[ksN,r];ksN=ksN+1;Print[s]]] However, I do not like this solution since to my taste is to complex and rather inelegant. Nest or Fold would do better. Any Idea? Just an additional remark. Besides, I do not need the whole taxonomy, but a subset satisfying a minimizing condition on connectivity implied by some relationships among the elements. This condition is satisfied by one and only one element, or class of equivalence in each level of the hierarchy. So it is that very class which matter and consequently the procedure should give control on each class as the total structure is being generated. Once it is known which class satisfies the condition it is possible to avoid generating the whole structure and the subsequent combinatorial explosion. With just This an addition to the previous posting In fact, the thing is even worst. These are the CPU times for the following computations times1=First[Timing[fLPartition[3,10];]]/. Second->1 0.02 times2=First[Timing[fLPartition[3,20];]]/. Second->1 0.18 times3=First[Timing[fLPartition[3,30];]]/. Second->1 0.701 times4=First[Timing[fLPartition[3,40];]]/. Second->1 1.913 times5=First[Timing[fLPartition[3,50];]]/. Second->1 4.236 times6=First[Timing[fLPartition[3,60];]]/. Second->1 8.222 times7=First[Timing[fLPartition[3,70];]]/. Second->1 14.39 times8=First[Timing[fLPartition[3,80];]]/. Second->1 23.563 So far so good. But for times9=First[Timing[fLPartition[3,90];]]/. Second->1 The computation does not always end. Some times it ends some times it does not (I aborted the process four times after 1 hour of computing and running out of, 2Gbites of, virtual memory) Emilio Martin-Serrano ___________________________________ Emilio Martin-Serrano Schlumberger Oil & Gas Business Consulting Principal 1325 South Dairy Ashford Road Houston, TX 77077 ==== I am interested in creating a slide presentation using slide view mode in Mathematica 4.2. I would like to have hyperlinks between different slides ( e.g., a hyperlink in say slide 6 takes me back to slide 3). I have no difficulty in creating such a hyperlink (using tags) when I am in the author mode. But the hyperlink does not work when a revert back to slide view mode. I guess it has somthing to do with the fact that in author view mode your slides are a subset of a single notebook but in slide view mode each slide becomes a distinct notebook. So my question: Is there a way to reference the individual slides using the hyperlink command? Brian ==== This graphs f from 0 to 8 Pi on a logarithmic horizontal scale: f[x_] := 1 + Abs[Sin[x]/x] Plot[f@Exp@x, {x, 0, Log[8Pi]}, PlotRange -> All]; If you want both scales to be logarithmic, use Plot[Log@f@Exp@x, {x, 0, Log[8Pi]}, PlotRange -> All]; The first is always possible if you only have positive x to deal with, and the second is possible if x and y are BOTH positive. Bobby Treat -----Original Message----- Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== > This graphs f from 0 to 8 Pi on a logarithmic horizontal scale: f[x_] := 1 + Abs[Sin[x]/x] > Plot[f@Exp@x, {x, 0, Log[8Pi]}, PlotRange -> All]; The graph itself is indeed what is desired, but the labelling of the x-axis is then incorrect for a logarithmic scale. For example, regardless of the scale used, any proper graph must show that the first minimum occurs at x = Pi. But the method you suggest makes it seem that it occurs at approx. 1.14 (precisely Log[Pi]). David > -----Original Message----- > ==== > Stefan, > > To find n digits before the decimal point of a number, we can proceed in the > following way. We compute the number in sufficiently many digits, then take > the Floor of the result (i.e. we round it downwards to an integer) and > finally take the result modulo 10^n. > > Mod[Floor[ N[(Sqrt[2] + Sqrt[3])^2002 , 1000]], 10^2] > > results in 9, so the last two digits before the decimal point are 09. > > With a slight modification we can find the first n digits after the decimal > point. Simply find the last n digits before the decimal point of 10^n times > the number. > > Mod[Floor[ N[10^2 (Sqrt[2] + Sqrt[3])^2002 , 1000]], 10^2] > > results in 99, so these are the digits you are interested in. > > But there is something curious about this number. > > Mod[Floor[N[10^1000 (Sqrt[2] + Sqrt[3])^2002 , 2000]], 10^1000] > > results in 996 digits 9 followed by 7405. > > You can also play with the following command, resulting in the digits around > the decimal point: > > Mod[ N[(Sqrt[2] + Sqrt[3])^2002, 2300], 10^6] > > The decimal expansion of (Sqrt[2]+Sqrt[3])^2002 contains a sequence of > 997 consecutive digits 9. Do you have any idea why? Not unusual. Try other even exponents and there should be large blocks of 9s . Smaller number for small exponents. Some kind of propagation of 9s as the exponent grows. Try other odd values for 3 and the same thing happens for some values. Also for other values for 2. Larry > > Fred Simons > Eindhoven University of Technology > > > > > ==== >-----Original Message----- >Sent: Wednesday, September 11, 2002 9:28 AM > >A commonly used symbol for the Floor function is a square >bracket with the >upper indents removed. Is this symbol part of Mathematica's >built-in symbols? I >think not, so then, can it be constructed by hand. > >Jack Jack, yes it is already built-in! Bring up the palette with menu: File > Palettes > CompleteCharachters; there is a section Operators > General, where you'll find what you want. Alternatively type 'esc' l f 'esc' 'esc' r f 'esc', or instead of the esc-sequence use the corresponding mark-ups. For output try TraditionalForm. If you don't like that for all of your output, you may just add a formatting rule for Floor: In[7]:= Unprotect[Floor] In[8]:= Floor /: MakeBoxes[Floor[expr_], StandardForm] := RowBox[{[LeftFloor], MakeBoxes[expr, StandardForm], [RightFloor]}] In[9]:= Protect[Floor] In[11]:= Floor /@ ([Pi] + [Lambda]) Out[11]= 3 + [LeftFloor][Lambda][RightFloor] Same thing with Ceiling, BTW. -- Hartmut ==== >-----Original Message----- >Sent: Wednesday, September 11, 2002 9:28 AM >Is it possible to configure a style sheet so that functions or >data shown in >graphs are coloured (colored :)) in working but black in >printing...without >actually re-executing the function that created the graphics? > >thanks > >Mike Mike, if for some reason you can't configure your color printer when printing, you may rerender your graphics in Mathematica with different options, such avoiding costly recalculation. You may either use something special, as in... In[1]:= ContourPlot[Sin[x]^2 Sin[y]^2, {x, 0, Pi}, {y, 0, Pi}, ColorFunction -> Hue, ContourStyle -> GrayLevel[1], PlotPoints -> 100] Out[1]= [SkeletonIndicator]ContourGraphics[SkeletonIndicator] In[2]:= Show[%, ColorFunction -> (GrayLevel[1 - #] &)] ...using a B/W color function. Or in general you may use the option ColorOutput: In[3]:= Plot3D[Sin[x]^2 Sin[y]^2, {x, 0, Pi}, {y, 0, Pi}] Out[3]= [SkeletonIndicator]SurfaceGraphics[SkeletonIndicator] ... In[5]:= Show[%%, ColorOutput -> GrayLevel] -- Hartmut ==== I'm trying to write a fast empirical cummulative distribution function (CDF). Empirical CDFs are step functions that can be expressed in terms of a Which statement. For example, given the list of observations {1, 2, 3}, f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]& is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1} and f is continuous from the right. When the number of observations is large, the Which statement evaluates fairly slowly (even if it has been Compiled). Since InterpolationFunction evaluates so much faster in general, I've tried to use Interpolation with InterpolationOrder -> 0. The problem is that the resulting InterpolatingFunction doesn't behave the way (I think) it ought to. For example, let g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder -> 0] Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}. In addition, g is continuous from the left rather than from the right. Obviously I am not aware of the considerations that went into determining the behavior of InterpolationFunction when InterpolationOrder -> 0. So I have two questions: (1) Does anyone have any opinions about how InterpolatingFunction ought to behave with InterpolationOrder -> 0? (2) Does anyone have a faster way to evaluate an empirical CDF than a compiled Which function? By the way, here's my current version: CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] := Block[{x}, Compile[{{x, _Real}}, Evaluate[ Which @@ Flatten[ Append[ Transpose[{ Thread[x < Sort[list]], Range[0, 1 - 1/#, 1/#] & @ Length[list] }], {True, 1}]] ]]] --Mark ==== Daniel Lichtblau made two suggestions that allow one to use Interpolation the way I wanted. First, to make the resulting function right-continuous, change the sign twice. Second, to make the end point return the correct value, add an extra (phantom) observation (with an extra (irrelevant) value). (The phantom observation is made at the high end because of the sign reversals.) Here's the code I cooked up based on his suggestions: MakeEmpiricalCDF::usage = MakeEmpiricalCDF[list] returns a function that evaluates the empirical CDF given the observations in the list. The function is defined on the entire real line. MakeEmpiricalCDF[list_?(VectorQ[#, NumericQ]&)] := Module[{n, s, a, r, idata}, n = Length[list]; s = Sort[list]; a = Append[s, s[[-1]] + 1]; (* phantom obs. *) r = Range[1/n, 1 + 1/n, 1/n]; (* phantom value 1 + 1/n *) idata = Last /@ Split[Transpose[{-a, r}], #1[[1]] == #2[[1]]&]; (* -a is the first sign change *) Block[{x}, Function @@ {x, Which @@ { x < s[[ 1]], 0., x > s[[-1]], 1., True, Interpolation[idata, InterpolationOrder -> 0][-x] (* -x is the second sign change *) }}] ] The construction Last /@ Split[ ... ] accounts for duplicate values. Here are two examples. Needs[Statistics`ContinuousDistributions`] list1 = RandomArray[NormalDistribution[0, 1], 100]; f1 = MakeEmpiricalCDF[list1]; Plot[f1[x], {x, -4, 4}] list2 = Table[Random[Integer, {1, 10}], {10}]; f2 = MakeEmpiricalCDF[list2]; Plot[f2[x], {x, 0, 11}] --Mark > I'm trying to write a fast empirical cummulative distribution function > (CDF). Empirical CDFs are step functions that can be expressed in > terms of a Which statement. For example, given the list of > observations {1, 2, 3}, > > f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]& > > is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1} > and f is continuous from the right. > > When the number of observations is large, the Which statement > evaluates fairly slowly (even if it has been Compiled). Since > InterpolationFunction evaluates so much faster in general, I've tried > to use Interpolation with InterpolationOrder -> 0. The problem is that > the resulting InterpolatingFunction doesn't behave the way (I think) > it ought to. For example, let > > g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder - 0] > > Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}. > In addition, g is continuous from the left rather than from the right. > > Obviously I am not aware of the considerations that went into > determining the behavior of InterpolationFunction when > InterpolationOrder -> 0. > > So I have two questions: > > (1) Does anyone have any opinions about how InterpolatingFunction > ought to behave with InterpolationOrder -> 0? > > (2) Does anyone have a faster way to evaluate an empirical CDF than a > compiled Which function? > > By the way, here's my current version: > > CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] := > Block[{x}, Compile[{{x, _Real}}, Evaluate[ > Which @@ Flatten[ > Append[ > Transpose[{ > Thread[x < Sort[list]], > Range[0, 1 - 1/#, 1/#] & @ Length[list] > }], > {True, 1}]] > ]]] > > --Mark ==== I am new to numerical computing. I have a equation dQ/dz = exp(-i*4*a^2*z - i*pi/4)*f(z,t)/sqrt(4*pi*z) where z is the position range from 0 to 10, t is the time range from 0 to 10 f(z,t) = integration of exp(i*(t-t1-z)^2/z)*g(t1) from t1=-100 to 100 g(t1) = d^3 sech(t1) / dt^3 I would like to solve Q(z,t), however, I am a new to mathematica. Can anyone help me? ==== I know that there is an input form. I want the output to have the same form rather than look like Floor[x]. Sorry, Jack A commonly used symbol for the Floor function is a square bracket with the > upper indents removed. Is this symbol part of Mathematica's built-in symbols? I > think not, so then, can it be constructed by hand. Jack Reply-To: kuska@informatik.uni-leipzig.de ==== does MakeBoxes[Floor[x_], fmt_:StandardForm] := RowBox[{[LeftFloor], ToBoxes[x, fmt], [RightFloor]}] help you ? Jens > > I know that there is an input form. I want the output to have the same > form rather than look like Floor[x]. Sorry, > > Jack > > > > A commonly used symbol for the Floor function is a square bracket with the > upper indents removed. Is this symbol part of Mathematica's built-in symbols? I > think not, so then, can it be constructed by hand. > > Jack > > ==== Recent threads about word processing and typesetting have got me dreaming again... Wouldn't it be nice if someone developed a package that provided a function like this: DisplayTeX[ some TeX code ] which would cause the kernel to generate PostScript for the typeset text, to be displayed by the front end? I doubt that WRI will ever consider this, but surely there's someone out there who's both a TeXpert and a Mathematica guru who can do it. No doubt there's money to be made. Probably just a pipe dream... --- Selwyn Hollis Reply-To: kuska@informatik.uni-leipzig.de ==== you mean the inverse of TeXForm[] ? For what ? A TeXpert && Mathematica guru && MathLink expert has a TeX frontend, that translate a TeXNotebook (that is a TeX file with some Mathematica Input/Output environments) and send the input cells to a kernel and insert the output into the final TeX file ... The most of the remaining work like creating hyperlinks to references and figures is done my LaTeX and pdfLaTeX, with help of CTAN and some macros one generate almost every layout *and* I have more than 20 books about TeX/LaTeX (including Don Knuths excelent manuals) but I have not a single book about the Mathematica Frontend. The way is not to teach TeX to the frontend, the way is to teach TeX a bit Mathematica. And a TeXpert will never switch from his beloved TeX to the Frontend and it's typesetting -- that's why he is a TeXpert. Jens > > Recent threads about word processing and typesetting have got me > dreaming again... > > Wouldn't it be nice if someone developed a package that provided a > function like this: > > DisplayTeX[ some TeX code ] > > which would cause the kernel to generate PostScript for the typeset > text, to be displayed by the front end? > > I doubt that WRI will ever consider this, but surely there's someone out > there who's both a TeXpert and a Mathematica guru who can do it. No > doubt there's money to be made. > > Probably just a pipe dream... > > --- > Selwyn Hollis ==== > > you mean the inverse of TeXForm[] ? > For what ? A TeXpert && Mathematica guru && MathLink expert > has a TeX frontend, that translate a TeXNotebook > (that is a TeX file with some Mathematica Input/Output > environments) and send the input cells to a kernel > and insert the output into the final TeX file ... Congratulations to you if you can do that and if you're happy with it. I'd prefer life to be a bit simpler. The point is that many users of Mathematica already have sufficient knowledge of TeX/LaTeX to typeset very complicated mathematics and get excellent results with little or no grief. To achieve even close to the same quality with Mathematica alone can require ten times the effort and a hundred times the grief. ---Selwyn > > The most of the remaining work like creating hyperlinks > to references and figures is done my LaTeX and pdfLaTeX, > with help of CTAN and some macros one generate almost every > layout *and* I have more than 20 books about TeX/LaTeX > (including Don Knuths excelent manuals) but I have not > a single book about the Mathematica Frontend. > > The way is not to teach TeX to the frontend, the way is > to teach TeX a bit Mathematica. > > And a TeXpert will never switch from his beloved TeX > to the Frontend and it's typesetting -- that's why > he is a TeXpert. > > Jens > > > >>Recent threads about word processing and typesetting have got me >>dreaming again... >Wouldn't it be nice if someone developed a package that provided a >>function like this: DisplayTeX[ some TeX code ] >which would cause the kernel to generate PostScript for the typeset >>text, to be displayed by the front end? >I doubt that WRI will ever consider this, but surely there's someone out >>there who's both a TeXpert and a Mathematica guru who can do it. No >>doubt there's money to be made. >Probably just a pipe dream... --- >>Selwyn Hollis > > ==== Mike, I don't think so. Style sheets do not control the styles used within an output graphics cell. I think you will have to set the plot style as a statement in the notebook, change it and re-evaluate for printing. This might not be all that inconvenient because you probably won't be printing that often. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Dear MathGroup, To plot FrameTicks outward with the same style as the Frame, I use ExtendGraphics in the following way. Needs[ExtendGraphics`Ticks`]; tf[min_,max_] := TickFunction[min, max, MajorStyle -> {Thickness[0.003]}, MajorLength - > {0, 0.01}, MinorStyle -> {Thickness[0.003]}, MinorLength -> {0, 0.005}] Plot [-2.4 (x+6) (x-8), {x, -6.2, 9.2}, FrameTicks -> {tf, tf, None, None}, AspectRatio -> 18/25, Frame -> True, DefaultFont -> {Helvetica-Bold, 12}, Axes -> None, FrameStyle -> Thickness[0.003], FrameLabel -> {x, y, None, None}, PlotStyle -> Thickness[0.006], ImageSize -> 504]; (instead of the same Plot statement with FrameTicks -> {Automatic, Automatic, None, None}) This arrangement of major and minor ticks is clearly unacceptable. The minor ticks do not divide intervals of adjacent labelled major ticks into equal parts. Are there other solutions? I have noticed that some major statistical (plotting) programs don't do minor ticks at all. Tom Aldenberg RIVM Bilthoven Netherlands ==== I need to create an adjacency matrix from my data, which is currently in the form of a .txt file and is basically a two column incidence list. For example: 1 A 1 B 2 B 3 C . . . . . . m n Where 1 to m represent actors and A to n represent events. My goal is to have an (m x m) matrix where cell i,j equals 1 if two actors are incident to the same event (in the sample above, 1 and 2 are both incident to B) and 0 otherwise (w/ zeros on the diagonal). I'm new to Mathmatica, and so I'm on the steep part of the learning curve ... All I've been able to figure out so far is how to get my incidence list into the program using Import[filename.txt]. But then what? How do I convert to the adjacency matrix? I've found the ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't seem to get it to work ... Tom ********************************************** Thomas P. Moliterno Graduate School of Management University of California, Irvine tmoliter@uci.edu ********************************************** Reply-To: kuska@informatik.uni-leipzig.de ==== with In[]:=lst = {{1, A}, {1, B}, {2 , B}, {3, C}, {3, D}, {1, D}}; and In[]:= AdjacenceMatrix[lst : {{_, _} ..}] := Module[ {actors,events adj}, {events, actors} = Union /@ Transpose[lst]; adj = Table[0, {Length[events]}, {Length[actors]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, actors]]; adj ] you get In[]:=AdjacenceMatrix[lst] Out[]={{1, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}} Jens > > I need to create an adjacency matrix from my data, which is currently in > the form of a .txt file and is basically a two column incidence list. > For example: > > 1 A > 1 B > 2 B > 3 C > . . > . . > . . > m n > > Where 1 to m represent actors and A to n represent events. My goal is to > have an (m x m) matrix where cell i,j equals 1 if two actors are > incident to the same event (in the sample above, 1 and 2 are both > incident to B) and 0 otherwise (w/ zeros on the diagonal). > > I'm new to Mathmatica, and so I'm on the steep part of the learning > curve ... All I've been able to figure out so far is how to get my > incidence list into the program using Import[filename.txt]. But then > what? How do I convert to the adjacency matrix? I've found the > ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't > seem to get it to work ... > > > Tom > > ********************************************** > Thomas P. Moliterno > Graduate School of Management > University of California, Irvine > tmoliter@uci.edu > ********************************************** ==== >Probably a rather simple question: what is the easiest way to open a >notebook, execute it, then quit, from the command line? I would like to be >able to do this from a Makefile. actually, this is not as simple as it should be and one needs the extremely useful JLink to really manipulate Notebooks from the similar under MacOSX and even Windows. Maybe others can try this. ================================================= Execute this in the FrontEnd to create a test notebook, then quit the FrontEnd completely: NotebookSave[NotebookPut[Notebook[{ Cell[< Plot3D[Sin[x]*Cos[y], {x, 0, 10}, {y, 0, 10}, PlotLabel -> >, Input], Cell[Integrate[Log[1 - x]^2/(1 + x), {x, 0, 1}], Input] } ]],/tmp/test.nb] (* **************************** *) Next, create a file t.m : [rolf@uranus tmp]$ cat t.m nb = /tmp/test.nb; (* ***************************** *) <, Input], Cell[NotebookSave[en, Interactive -> False], Input]}]]; SelectionMove[m, All, Notebook]; SelectionEvaluate[m]; ]; Pause[1]; (* **************************************** *) Now you can run it like this in the background: [rolf@uranus tmp]$ math < t.m > t.out & This will open /tmp/test.nb , evaluate it and save it under the same name. (* ******************************* *) Maybe there is an easier and cleaner way, but the problem here is that the kernel and the FrontEnd are really two different programs, i.e., the kernel is not waiting until the FrontEnd finished certain tasks (like NotebookSave), i.e., think of it as threads. Therefore I used the trick with a second steering notebook. (One usually has similar problems when writing more intricate buttons.) If you are not, e.g. you work remotely at a Unix-box without an virtual frame buffer (Xvfb), like in webMathematica. ask Wolfram Tech Support. Rolf Mertig Mertig Consulting Efficient Software http://www.mertig.com ==== > I'm curious about the different efficiencies of Export vs. Put; Import vs. > Get. > > Eg. Saving a list called c with approx. 16,000 elements, each element > being a three element list of reals. > > Export[ac.dat,c] takes forever and consumes heaps of kernel memory > > c>>ac.dat all done in an instant (relatively speaking) and without the > transient burst of kernel memory usage. > > Ditto Import and Get. Can anyone explain this? The comparison is that of apples and oranges. Get[] and Put[] deal with reading and writing Mathematica expressions in InputForm syntax. They are implemented in C, so they are fairly fast, and the target format is human readable. However the output might not be readily parsable by other computer programs. The functions may be used with Mathematica expressions of all kinds. In the event that human readability and platform independence are not important, one can use DumpSave[] in lieu of Put[]. Export[] and Import[] for the cases you describe are using the Table target format. They are implemented in top-level Mathematica code, so they are not as fast as Get[] and Put[]. The target is a regularly formatted array of data, so not all Mathematica expressions are appropriate for this kind of conversion. In the case of Export[], the expression is formatted completely in memory using TableForm[] before being saved out to file. In the case of Import[], there are a number of heuristics that are applied to each field to determine whether the field should be converted to a number or a string. This should explain why they are slower and require more memory. If you are dealing with a large collection of machine precision numbers, then neither of these approaches may be suitable for your purposes. You might be better off using the free add-on FastBinaryFiles, which is available up on MathSource at this URL: readable by C programs. -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== > A commonly used symbol for the Floor function is a square bracket with > the upper indents removed. Is this symbol part of Mathematica's > built-in symbols? I think not, so then, can it be constructed by > hand. Is this what you're describing? In[1]:= [LeftFloor]x[RightFloor] Out[1]= Floor[x] This notation is documented in Section A.2.6 of _The Mathematica Book_ (Fourth Edition). -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== Jack, Check pages 959 and 960 in Section 3.10.4 of The Mathematica Book. You can use LeftFloor and RightFloor as bracketing operators, which in turn are intrepreted as Floor. [LeftFloor] 3.2 [RightFloor] 3 These can also be entered as esc-lf-esc and esc-rf-esc. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Hugh Goyder and David Park gave a most elegant function to find two vectors that are orthogonal to one vector in 3D. The key to coming up with the elegant solution is an understanding of Mathematica's NullSpace function. We can easily make the version from Hugh and David much more general with the version below. ------------- OrthogonalUnitVectors[vect__?VectorQ]:= #/Sqrt[#.#]&/@NullSpace[{vect}] ------------- The version above will give a set of unit orthogonal vectors if given any number of vectors in any dimension. So besides giving it a 3D vector we can give it the following: OrthogonalUnitVectors[{2,1,0,-1,1}] or OrthogonalUnitVectors[{0,1,0,1/2,1},{1,0,-1,1/2}] ------------ But the short version above isn't very robust. (1) Clear[x,y,z];NullSpace[{{x,y,z}}] returns two vectors orthogonal to {x,y,z}, but the two vectors NullSpace returns aren't orthogonal to each other. So (OrthogonalUnitVectors) should only work with numeric vectors. (2) We should ensure all the vectors have the same dimension and length >1. I give a less concise version below that corrects these problems. ------------ OrthogonalUnitVectors[vect__?(VectorQ[#,NumericQ]&)]/; (SameQ@@Length/@{vect})&&(Length[First[{vect}]]>1):= #/Sqrt[#.#]&/@NullSpace[{vect}] -------------- Ted Ersek Get Mathematica tips, tricks from http://www.verbeia.com/mathematica/tips/Tricks.html ==== I have installed 128 MB RAM extra in my computer. I had 64 before, so now I have 3 times as much. I expected some calculations that took very long before, to be executed in less time. To the contrary, my computer still goes to the hard drive fro memory for its calculations, and Mathematica stops with an out of memory message. Windows is recognizing this new memory. I dont know if Mathematica is. How can I find out about this? Julio ==== > It seems there is an error in the BinCounts function of Mathematica's > standard < returns one more than the expected number of histogram bins. An example > of this is shown in the notebook code below where the comment in the > last notebook cell explicitly describes the problem. If anyone can > explain this behavior it would be appreciated, otherwise Wolfram > Research should be made aware of this feature of the function when it > is called as: BinCounts[{x1, x2, ...}, {xmin, xmax, dx}] A developer of Mathematica's Standard Packages has requested that this response be posted to the forum: [begin developer's comments] Note that if you don't apply N when computing datBinWidth, you will always get the expected number of bins; i.e., datBinWidth = (datMax - datMin)/datBins (assuming datMax and datMin are also exact numbers). Given input {xmin, xmax, dx}, BinCounts determines the number of bins to be computed via Ceiling[(xmax - xmin)/dx]. For numericalized values, it's possible for dx to end up such that the Ceiling forces an additional bin to be added; presumably, it's better to have too many rather than too few bins -- for example, if the dx was deliberately given such that the xmax is not at an integer bin boundary... If you use exact values for bin bounds and increment, then there will be no problem. [end developer's comments] -- User Interface Programmer paulh@wolfram.com Wolfram Research, Inc. ==== I would like to create a 3D chart from an ASCII file using Mathematica 3.0. Can anyone give me some help? ==== You might want to tell us how to find A.10. Anyway, it's easier to simply go to Floor in the help browser (in version 4.2, anyway). Bobby Treat -----Original Message----- David ==== I doubt there's any money to be made here. Lots of people have created very valuable additions to Mathematica, but they're all being given away, so far as I can tell. It's too bad, too. And here we are, giving away our time. Sigh... Bobby -----Original Message----- there who's both a TeXpert and a Mathematica guru who can do it. No doubt there's money to be made. Probably just a pipe dream... --- Selwyn Hollis ==== OK, I give up; how would I find Chapter Advanced Mathematics/Mathematical and Other Notations/Operators in the Help Browser? Bobby Treat -----Original Message----- > think not, so then, can it be constructed by hand. > > Jack [LeftFloor] and [RightFloor] can be used for this. Look at Chapter Advanced Mathematics/Mathematical and Other Notations/ Operators. Yours, Alexander -- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / ==== > You might want to tell us how to find A.10. Open your fourth edition of _The Mathematica Book_ to page 1065. That's where part 10 of the Appendix starts. > Anyway, it's easier to simply go to Floor in the help browser (in > version 4.2, anyway). I suppose you're right. But I -- call me old-fashioned if you wish -- prefer to use the book. David ==== I'll assume you have the information in a matrix like x: TableForm[x = {{1, A }, {1, B }, {2, B}, {3, D}, {4, D}, {5, C}}] First find the highest actor number (or use what you've input elsewhere): m = Last[Union[x[[All,1]]]] 5 Define the incidence function: f[x_, a_, b_] /; a == b := 0 f[x_, a_, b_] := If[{} $B!b(B Intersection[Cases[x, {a, y_} -> y], Cases[x, {b, y_} -> y]], 1, 0] Here's the incidence matrix: Array[f[x, #1, #2] &, {m, m}] {{0, 1, 0, 0, 0}, {1, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 1, 0, 0}, { 0, 0, 0, 0, 0}} Once you have the incidence function, the only reason to store the incidence matrix is to avoid computing over again the same answers, and that can be accomplished in other ways. If you won't have other x matrices, it's convenient to define f this way: f[a_, b_] /; a == b := f[a, b] = 0 f[a_, b_] /; a < b := f[a, b] = If[{} $B!b(B Intersection[Cases[x, {a, y_} -> y], Cases[x, {b, y_} -> y]], 1, 0] f[a_, b_] := f[b, a] Array[f, {m, m}] {{0, 1, 0, 0, 0}, {1, 0, 0, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}} Whenever you would want the {j,k} element of the adjacency matrix, just use f[j,k] instead. Each pair is computed only once. In this version, I've taken advantage of the symmetry of the problem, too, to cut the work in half. Bobby Treat -----Original Message----- . . . . m n Where 1 to m represent actors and A to n represent events. My goal is to have an (m x m) matrix where cell i,j equals 1 if two actors are incident to the same event (in the sample above, 1 and 2 are both incident to B) and 0 otherwise (w/ zeros on the diagonal). I'm new to Mathmatica, and so I'm on the steep part of the learning curve ... All I've been able to figure out so far is how to get my incidence list into the program using Import[filename.txt]. But then what? How do I convert to the adjacency matrix? I've found the ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but I can't seem to get it to work ... Tom ********************************************** Thomas P. Moliterno Graduate School of Management University of California, Irvine tmoliter@uci.edu ********************************************** ==== Well, I don't know how fast, but it is fairly simple, anyway. Suppose you have a series of values s for which you wish to obtain the edf. In[1]:= s = Table[Random[Integer, {0, 3}], {10}] Out[1]= {2,2,1,2,0,0,1,1,1,3} If no specification is made about their position on the x-axis, we assume that they correspond to the integers from 1 to 10. What we have then is the collection of pairs In[2]:= porig = Transpose[{Range[10], s}] Out[2]= {{1, 2}, {2, 2}, {3, 1}, {4, 2}, {5, 0}, {6, 0}, {7, 1}, {8, 1}, {9, 1}, {10, 3}} The edf gives, for each x, the proportion of points in s that are less than or equal to x, for all x. We obtain these proportions through the cumulative sums In[3]:= N[CumulativeSums[s]/Plus @@ s] Out[3]= {0.153846,0.307692,0.384615,0.538462,0.538462,0.538462,0.615385,0.692308,0. 769231,1.} so that for each of the pairs (x, y) below, y gives the proportion of points in s that are less than or equal to x: In[4]:= cumporig = Transpose[{Range[10], N[CumulativeSums[s]/Plus @@ s]}] Out[4]= {{1, 0.15384615384615385}, {2, 0.3076923076923077}, {3, 0.38461538461538464}, {4, 0.5384615384615384}, {5, 0.5384615384615384}, {6, 0.5384615384615384}, {7, 0.6153846153846154}, {8, 0.6923076923076923}, {9, 0.7692307692307693}, {10, 1.}} Now shift the x values one unit to the left, by dropping the last value and prepending 0 to them: In[5]:= ps = Transpose[{Prepend[Drop[Range[1, 10], -1], 0], CumulativeSums[s]/Plus @@ s}] Out[5]= {{0, 2/13}, {1, 4/13}, {2, 5/13}, {3, 7/13}, {4, 7/13}, {5, 7/13}, {6, 8/13}, {7, 9/13}, {8, 10/13}, {9, 1}} Then use Interpolation on this shifted set of points: In[6]:= ips=Interpolation[ps,InterpolationOrder[Rule]0] Out[6]= InterpolatingFunction[{{0,9}},<>] ips[x-1] is the edf you are looking for, as you may check by plotting it and displaying in the same graph together with the ListPlot of cumporig above. Tomas Garza Mexico City ----- Original Message ----- > and f is continuous from the right. When the number of observations is large, the Which statement > evaluates fairly slowly (even if it has been Compiled). Since > InterpolationFunction evaluates so much faster in general, I've tried > to use Interpolation with InterpolationOrder -> 0. The problem is that > the resulting InterpolatingFunction doesn't behave the way (I think) > it ought to. For example, let g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder - 0] Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}. > In addition, g is continuous from the left rather than from the right.