A59 === Here's an odd result:r = 2 - Sin[t];f = Sqrt[r^2 + D[r, t]^2]g = Simplify@fIntegrate[f, {t, 0, Pi/2}] // NIntegrate[g, {t, 0, Pi/2}] // NNIntegrate[f, {t, 0, Pi/2}]NIntegrate[g, {t, 0, Pi/2}]-14.474963421625041 + 3.552713678800501*^-15*I2.382540126500918 + 0.*I2.38254012650091832.3825401265009183(Three of those answers are correct.)Simplifying f changed the result from Integrate, even though it doesn't change the plot:DisplayTogetherArray[Plot[f, {t, 0, Pi/2}], Plot[g, {t, 0, Pi/2}], AspectRatio -> Automatic, ImageSize -> 500];The moral, as always, is caveat emptor.BobbyOn Sat, 8 Mar 2003 02:50:48 -0500 (EST), Garry Helzer To: mathgroup@smc.vnet.net>> To: mathgroup@smc.vnet.net>> Integrals> -----Original Message----->> To: mathgroup@smc.vnet.net> Sent: Saturday, March 01, 2003 8:48 AM> To: mathgroup@smc.vnet.net> Integrals> The antiderivative of Sqrt[1+Cos[x]] discussed here recently (sorry, I> lost the thread) provides an amusing illustration of the fact that> Mathematica does not always evaluate definite integrals by first> finding an antiderivative and then substituting in the upper and lower> limits. (See the Mathematica book A.9.5) Make the definitions>> f[x_] = Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]> g[x_] := Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]>> Then f[2Pi] is 0 (wrong) and g[2Pi] if 4Sqrt[2] (correct). Of course> f[x]==g[x] returns True.>> Garry Helzer> Department of Mathematics> University of Maryland> 1303 Math Bldg> College Park, MD 20742-4015>> You might be interested to observe:>> In[1]:= f[x_] = Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]>> Out[1]= 2*Sqrt[1 + Cos[x]]*Tan[x/2]>> In[2]:= g[x_] := Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]>> In[3]:= ?g>> Global`g>> g[x_] := Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]>> In[4]:= Plot[f[x], {x, 0, 2Pi}] // Timing>> Out[4]= {0.03 Second, = Graphics =}>> ...what you called wrong. 1. A function defined as an integral with a variable upper limit is an > antiderivative.> 2. An antiderivative is, by definition, differentiable.> 3. A differentiable function is continuous. So, by this plot, f[x] is not the antiderivative of any function. But this may be too rigid a view. After all, D[f[x],x]//FullSimplify > brings you back to the integrand. This is a formal computation that > misses the points of discontinuity. Perhaps the algorithms used by > Mathematica are guaranteed only to produce such formal antiderivatives. A > superficial look a the Risch algorithm suggests that this might be the > case since it proceeds by formal manipulation in extension fields of > fields of rational functions. As I was typing this a stranger wandered in looking for an arc length(it > happens). His problem provides another example. Let r=2-Sin[t] and try > Integrate[Sqrt[r^2 +D[r,t]^2],{t,0,Pi/2}]//N. The result is about -15, > but arc length should not be negative. Set h[x_]= Integrate[Sqrt[r^2 +D[r,t]^2],{t,0,x}] and again we get a formal antiderivative , the plot of which reveals > discontinuities. It cannot be carelessly used to evaluate definite > integrals. (If you simplify Sqrt[r^2 +D[r,t]^2] before integrating you > get an honest antiderivative.) In[5]:=>> Plot[g[x], {x, 0, 2Pi}, PlotRange -> {All, {0, 6}}] // Timing>> Out[5]= {4.096 Second, = Graphics =}>> ...what you called right. It is right. But the corresponding function for the arc length problem is > wrong.>> Redefine:>> In[6]:= f[x_] /; -Pi < x < Pi = f[x]>> Out[6]= 2*Sqrt[1 + Cos[x]]*Tan[x/2]>> In[7]:= f[x_] /; Pi < x < 3 Pi = f[x] + 4*Sqrt[2]>> Out[7]= 4*Sqrt[2] + 2*Sqrt[1 + Cos[x]]*Tan[x/2] Or 4Sqrt[2]Round[x/(2Pi)]+ 2*Sqrt[1 + Cos[x]]*Tan[x/2] . But these > formulas are less than perfect since they are indeterminate at odd > multiples of Pi.> In[9]:=>> Plot[f[x], {x, 0, 2Pi}, PlotRange -> {All, {0, 6}}] // Timing>> Out[9]= {0.03 Second, = Graphics =}>> Don't be confused by that double use of f (as a function, and as a >> shortcut>> for an algebraic expression).>> -->> Hartmut Wolf> Garry Helzer> Department of Mathematics> University of Maryland> 1303 Math Bldg> College Park, MD 20742-4015>-- majort@cox-internet.comBobby R. Treat ==== You say when I shut the program and start allover. Do you mean you quit Mathematica altogether, or just close yournotebook? Perhaps you have a shadowing problem, but it would be important tolook at your actual sequence of steps.Tomas GarzaMexico City----- Original Message -----> for example> << Graphics`Graphics` PercentileBarChart[{1, -3, 4, 5, 2, 3},> {3, 6, 4, 3}] when its work i will see the chartbar on the screen and other time I> will see the number above again> izzy> ==== Input:s^10 + 10 s^9 + 10 s^8 + 10 s^7 + 10 s^6 + 10 s^5 + 10 s^4 + 1 /. s -> -8.999981180131652Output:-4.76837158203125*^-7Acceptably close to zero?Matthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de-----Ursprí.b9ngliche Nachricht-----Gesendet: Donnerstag, 6. Míórz 2003 08:35An: mathgroup@smc.vnet.netBetreff: Emergent Help: NSolve Problems!Hi, guysI have some complicated polynomials, and I want to calculate its roots.HOwever, when I use NSolve, it creates some problems. Say a simpleexample:temp[s_]=s^10+10 s^9+ 10 s^8 +10 s^7 +10 s^6+ 10 s^5 +10 s^4 +1; NSolve[temp[s]==0, s]It will give:Out[4]= {{s -> -8.99998}, {s -> -1.06539}, {s -> -0.468828 - 0.886239 I}, > {s -> -0.468828 + 0.886239 I}, {s -> -0.409684 - 0.469948 I}, > {s -> -0.409684 + 0.469948 I}, {s -> 0.401048 - 0.312597 I}, > {s -> 0.401048 + 0.312597 I}, {s -> 0.51015 - 0.878693 I}, > {s -> 0.51015 + 0.878693 I}}But when I plug in the first number, which is -8.99998, it should give avalue close to zero. However, it gives:In[5]:= temp[-8.99998]Out[5]= -411.473The other roots seems OK. Does anyone know why? This is just a simpleexample. I have some more complicated polynomials to deal with. --Chengzhou ==== try:1*1and1.0*1and have a look at THE BOOK:3.1.3 Converting between Different Forms of NumbersMatthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de-----Ursprí.b9ngliche Nachricht-----Gesendet: Donnerstag, 6. Míórz 2003 08:36An: mathgroup@smc.vnet.netBetreff: output.Solve posts some funny parameters when i solve a set of 6 simultaneous eqns.eg.x1 == 1.*(X - 1.*Bx*Cos([Psi]) + Bz*Cos([Psi])*Cot(B)*Sec(A) - 1.*UFly*Cos(A)* Sin(B) + (1.*Bz*m1*Cos(B)*Cos([Psi]))/(1.*Cos(A)*Cos(B) - 1.*m1*Cos(A)*Sin(B)) + (1.*Bx*Cos(A)*Cos(B)* Cos([Psi]))/(1.*Cos(A)*Cos(B) - 1.*m1*Cos(A)*Sin(B)) +(1.*b1* Cos(A)*Sin(B))/(1.*Cos(A)*Cos(B) - 1.*m1*Cos(A)*Sin(B)) +(1.*....what does the 1. mean????? I also occasionally get a 0. many thanks,Ryan H ==== -----Urspr.9fngliche Nachricht-----Von: Wolf, Hartmut Gesendet: Freitag, 7. M.8arz 2003 16:40An: ÔGara Kuta'; mathgroup@smc.vnet.netBetreff: RE: pattern matching with repeated named patterns[...]The most simple application might be just to use the pattern as filter forthose records which qualify, or don't: In[31]:= Cases[alist, person : {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500&)}]Out[31]= {{Adam, M, 38, 73}, {Eve, F, 37, 65.5}}In[33]:= Cases[alist, _?(! MatchQ[#, {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500 &)}] &)]Out[33]= {{Kain, M, 17, 501}, {Abel, M, 15, 58}}It's possibly easy to see how I drew myself into that obfuscation, but Ican't let it stay: the right way to do that is (of course!)In[8]:=DeleteCases[alist, person : {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500 &)}]Out[8]= {{Kain, M, 17, 501}, {Abel, M, 15, 58}}--Hartmut Wolf ==== have a look at the menu:File -> Palettes ->BasicInput.Matthias Bode.-----Ursprí.b9ngliche Nachricht-----Gesendet: Freitag, 7. Míórz 2003 09:40An: mathgroup@smc.vnet.netBetreff: Problem for exponent and indiceI want to put an exponent and an indice on a same Letter like that : 2X iHow can I do ? ==== try:a = 123*3ToExpression[a]Matthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de-----Ursprí.b9ngliche Nachricht-----Gesendet: Freitag, 7. Míórz 2003 09:41An: mathgroup@smc.vnet.netBetreff: type castingI am I new Mathematica user and am trying to master input/output. Is thereany way to type cast a string into number format?Ellen Tolonenentolonen@utep.edu ==== use of TextForm, as suggested by David Park, seems to be closest to what I want:-> Plain Text works the same way.I could not find TextForm in my Mac/Mathematica 4.2.1 help file (wish I had; in fact I searched for PlainTextForm PlainForm, etc., before the OP). I wonder if itappears in the helpfile for other machines, or is an undocumented/experimental feature.Carlos FelippaReply-To: drbob@bigfoot.com ==== TextForm is undocumented, and that really seems dumb.Sometimes I get around the THOUSANDS of keywords missing from the installed help files by searching at the online Documentation Center --- but that However, a search of the MathGroup archives yields 20 matches, some of which should be useful.You can't search for it unless you already know its name, of course.BobbyOn Sat, 8 Mar 2003 02:52:27 -0500 (EST), Carlos Felippa > use of TextForm, as suggested by David Park, seems to be closest to what > I want: -> Plain Text works the same way. I could not find TextForm in my Mac/Mathematica 4.2.1 help file (wish I > had; in fact I searched for PlainTextForm PlainForm, etc., before the > OP). I wonder if it> appears in the helpfile for other machines, or is an > undocumented/experimental feature. Carlos Felippa-- majort@cox-internet.comBobby R. TreatReply-To: drbob@bigfoot.com ==== It's dumb to have ANY undocumented functions in the default package load.Part of the problem is that the help browser is only a keyword index, not a search tool.BobbyOn Sat, 08 Mar 2003 14:21:10 -0700, Carlos Felippa > TextForm is undocumented, and that really seems dumb.> Yes, a pity because at least for me it seems useful. Sometimes> one wants to connect output of Mathematica with downstream codes, without> any superßuous formatting characters. That's the Unix approach.> Sometimes I get around the THOUSANDS of keywords missing from the >> installed>> help files by searching at the online Documentation Center --- but that>> However, a search of the MathGroup archives yields 20 matches, some of>> which should be useful.>> You can't search for it unless you already know its name, of course.>> Bobby>> On Sat, 8 Mar 2003 02:52:27 -0500 (EST), Carlos Felippa-- majort@cox-internet.comBobby R. Treat ==== > It's dumb to have ANY undocumented functions in the default package load.> Part of the problem is that the help browser is only a keyword index, not a > search tool.> Bobby ?TextForm gives a terse reply: System`TextForm Attributes[TextForm] = {Protected}so it is likely a protected system object. ==== Hi,I use Matematica 4.0 on Windows 2000.When I Export[] a Mathematica graphic to EPS, the resulting EPS filehas its BoundingBox bottom left corner at (88,4), instead of just(0,0).E.g., If I do:Export[test.eps, Plot[Sin[x], {x, -1, 1}], EPS]the output file starts with:%!PS-Adobe-2.0 EPSF-1.2%%BoundingBox: 88 4 376 182%%HiResBoundingBox: 88 4 376 181.938%%Creator: (Mathematica 4.0 for Microsoft Windows)When I use Mathematica 4.0 (UNIX) then the same command gives an EPS filestarting with:%!PS-Adobe-3.0 EPSF-3.0%%Creator: Mathematica-PSRender%%BoundingBox: 0 55 288 233(bottom left corner is at 0 55)In the two cases the BoundingBox fits correctly around the graphic,but the bottom left corner isn't at 0 0.How can I use Export[] to generate EPS files with BoundingBoxes withbottom left corner at 0 0?Ignaceps: I think this worked correctly in 3.0.Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,FortranForm[] ?but there are fancy packages on MathSource thathttp://www.feyncalc.org/has a nice FORTRAN exporter too Jens> How can I transfer an expression which I get from mathematica to a fortran> readable format? cut and paste doesn't work.> Please help.> Raj ==== > How can I transfer an expression which I get from mathematica to a fortran> readable format? cut and paste doesn't work.> Have you tried FortranForm?f[x_] := a*x^2+b*x+c;f[x]//InputFormc + b*x + a*x^2f[x]//FortranFormc + b*x + a*x**2Bob Hanlon ==== >How can I transfer an expression which I get from mathematica to a>fortran readable format? cut and paste doesn't work.Try FortranForm as in FortranForm[x^2] ==== Try FortranForm[]See the Help on it for detailsAdam Smith> How can I transfer an expression which I get from mathematica to a fortran> readable format? cut and paste doesn't work.> Please help.> > RajReply-To: rolf@mertig.com ==== Hi there,Hi,for the continuum case I once programmed this, see:http://www.feyncalc.org/FeynCalcBook/FunctionalD/http:// www.feyncalc.org/FeynCalcBook/FeynRule/You may have to modify it for lattice calculations.Just download FeynCalc, look at the source and adapt it to your needs (and contribute if you want).Rolf MertigMertig Consultinghttp://www.mertig.com ==== ============I've just recently decided that the maths I have to do at the moment reallydemand the use of a CAS. I'm absolutely new to Mathematica, but the problemI have is probably a bit hard to get moving on. Perhaps someone can give mea simple solution to start out on?What I need to do could probably be called a Functional differentiation ona lattice. To give one very simply example:I have the functional S[A] := sum_x (A(x+1)-A(x))^2(where x is integer - in my case there are periodic boundaries, but thatdoes not matter at that point)now I want to calculate dS/dA(y)which should result in - 2(A(y+1)-A(y)) + 2(A(y)-A(y-1))or simplified -2A(y+1) + 4A(y) - 2A(y-1)Lateron, the whole thing will get 4-dimensional and A will get indices thatwill be summed over as well.Is there a simple way to do that in Mathematica? I would really appreciate apiece of code to get me started on.Nobbi ==== > To: mathgroup@smc.vnet.net>> -----Original Message-----> To: mathgroup@smc.vnet.net>> Sent: Saturday, March 01, 2003 8:48 AM>> To: mathgroup@smc.vnet.net>> The antiderivative of Sqrt[1+Cos[x]] discussed here recently (sorry, I>> lost the thread) provides an amusing illustration of the fact that>> Mathematica does not always evaluate definite integrals by first>> finding an antiderivative and then substituting in the upper and lower>> limits. (See the Mathematica book A.9.5) Make the definitions>> f[x_] = Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]>> g[x_] := Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]>> Then f[2Pi] is 0 (wrong) and g[2Pi] if 4Sqrt[2] (correct). Of course>> f[x]==g[x] returns True.>> Garry Helzer>> Department of Mathematics>> University of Maryland>> 1303 Math Bldg>> College Park, MD 20742-4015>> You might be interested to observe:> In[1]:= f[x_] = Integrate[Sqrt[1 + Cos[t]], {t, 0, x}]> Out[1]= 2*Sqrt[1 + Cos[x]]*Tan[x/2] In[2]:= g[x_] := Integrate[Sqrt[1 + Cos[t]], {t, 0, x}] In[3]:= ?g> Global`g> g[x_] := Integrate[Sqrt[1 + Cos[t]], {t, 0, x}] In[4]:= Plot[f[x], {x, 0, 2Pi}] // Timing> Out[4]= {0.03 Second, = Graphics =} ...what you called wrong.1. A function defined as an integral with a variable upper limit is an antiderivative.2. An antiderivative is, by definition, differentiable.3. A differentiable function is continuous.So, by this plot, f[x] is not the antiderivative of any function.But this may be too rigid a view. After all, D[f[x],x]//FullSimplify brings you back to the integrand. This is a formal computation that misses the points of discontinuity. Perhaps the algorithms used by Mathematica are guaranteed only to produce such formal antiderivatives. A superficial look a the Risch algorithm suggests that this might be the case since it proceeds by formal manipulation in extension fields of fields of rational functions.As I was typing this a stranger wandered in looking for an arc length(it happens). His problem provides another example. Let r=2-Sin[t] and try Integrate[Sqrt[r^2 +D[r,t]^2],{t,0,Pi/2}]//N. The result is about -15, but arc length should not be negative. Seth[x_]= Integrate[Sqrt[r^2 +D[r,t]^2],{t,0,x}]and again we get a formal antiderivative , the plot of which reveals discontinuities. It cannot be carelessly used to evaluate definite integrals. (If you simplify Sqrt[r^2 +D[r,t]^2] before integrating you get an honest antiderivative.)In[5]:=> Plot[g[x], {x, 0, 2Pi}, PlotRange -> {All, {0, 6}}] // Timing> Out[5]= {4.096 Second, = Graphics =} ...what you called right.It is right. But the corresponding function for the arc length problem is wrong.> Redefine: In[6]:= f[x_] /; -Pi < x < Pi = f[x]> Out[6]= 2*Sqrt[1 + Cos[x]]*Tan[x/2] In[7]:= f[x_] /; Pi < x < 3 Pi = f[x] + 4*Sqrt[2]> Out[7]= 4*Sqrt[2] + 2*Sqrt[1 + Cos[x]]*Tan[x/2]Or 4Sqrt[2]Round[x/(2Pi)]+ 2*Sqrt[1 + Cos[x]]*Tan[x/2] . But these formulas are less than perfect since they are indeterminate at odd multiples of Pi.> In[9]:=> Plot[f[x], {x, 0, 2Pi}, PlotRange -> {All, {0, 6}}] // Timing> Out[9]= {0.03 Second, = Graphics =} Don't be confused by that double use of f (as a function, and as a > shortcut> for an algebraic expression). --> Hartmut Wolf>Garry HelzerDepartment of MathematicsUniversity of Maryland1303 Math BldgCollege Park, MD 20742-4015 ==== [snip]> > Redefine:> In[6]:= f[x_] /; -Pi < x < Pi = f[x]> Out[6]= 2*Sqrt[1 + Cos[x]]*Tan[x/2]> In[7]:= f[x_] /; Pi < x < 3 Pi = f[x] + 4*Sqrt[2]> Out[7]= 4*Sqrt[2] + 2*Sqrt[1 + Cos[x]]*Tan[x/2] Or 4Sqrt[2]Round[x/(2Pi)]+ 2*Sqrt[1 + Cos[x]]*Tan[x/2] . But these> formulas are less than perfect since they are indeterminate at odd> multiples of Pi.But of course there are perfect formulas for the antiderivative ofSqrt[1 + Cos[x]]. I mentioned one such formula in the parent thread ofthis one. If we let y denote Floor[(x+Pi)/(2*Pi)], then a perfect (andmaximally neat?) formula for the antiderivative is 2*Sqrt[2]*( (-1)^y*Sin[x/2] + 2*y )David CantrellReply-To: ==== Dear friend,I've problem with FindRoot[lhs==rhs, {x, x0}] .The description of the function in Help suggest that,if lhs and rhs are real then x will be real;if lhs and/or rhs are complex the x likely will be complex;if lhs and rhs are real but you want also x be complex then youneed to add +0.I to lhs or rhs.My problem is that lhs is complex, rhs is real and I want only realsolutions for x.How can I do it? How say to Mathematica to look for only real solution? ==== If you use sufficient WorkingPrecision and a reasonable starting point than you will be able to get rid of the tiny complex part with Chop. Eg:FindRoot[3*x^4 - 46 + I*(x - 2) == 2, {x, 1}]{x -> 2.0000000005164145 - 3.195328365745672*^-10*I}butChop[FindRoot[3*x^4 - 46 + I*(x - 2) == 2, {x, 1}, WorkingPrecision -> 30]]{x->2.00000000000000000000000000000}Of course you can simply get rid of the unwanted small complex part manually:FindRoot[3*x^4 - 46 + I*(x - 2) == 2, {x, 1}] /. Complex[a_, b_]/;b<10^-8 -> a{x->2.}This get rids of the imaginary part if it is less than 10^-8.There is however no way to make Mathematica look for real solutions in such cases, since there no purely numerical way to distinguish a real solution from a complex one with a very small imaginary part.Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> Dear friend, I've problem with FindRoot[lhs==rhs, {x, x0}] .> The description of the function in Help suggest that,> if lhs and rhs are real then x will be real;> if lhs and/or rhs are complex the x likely will be complex;> if lhs and rhs are real but you want also x be complex then you> need to add +0.I to lhs or rhs.> My problem is that lhs is complex, rhs is real and I want only real> solutions for x.> How can I do it? How say to Mathematica to look for only real solution? dsfa.fisica.unipa.it>Reply-To: tgarza01@prodigy.net.mx ==== Look in the Help browser for AddOns | Miscelaneous |RealOnly. That willguide you into solving the problem.Tomas GarzaMexico CityOriginal Message:-----------------solutions for x.How can I do it? How say to Mathematica to look for only real solution?---------------------------------------------------- ----------------Reply-To: Diana ==== Friends,I have some notes in text mode. I formatted the background with the CellGray Box feature. I noticed that when I had a group of characters which werecreated with a control key, that a little box appeared around thecharacters. For example, x^6, with the control ^ creating a nice lookingexponent.I am unable to get rid of the box, even when I change the background back tonone.Is there a fix for this?Diana-- ==== ============================================= ==== God made the integers, all else is the work of man.L. Kronecker, Jahresber. DMV 2, S. 19.Reply-To: kuska@informatik.uni-leipzig.de ==== Hm,what may ToExpression[w] do ?Generate a symbol w ??? Jens> Howdy,> > I'm trying to write a loop that assigns functions to a series of variables> which I'd like to name z, y, x, w, ... and so on. The functions are matrix> operator of a group, which I would use like this, for example:> state // w // z // w // w> Clearly I can generate the strings z, y, x, w ... in my loop. But> for a given string, how can I assign to the variable whose name is defined> by that string?> --> -- Bob Harris ==== ===================================================+> | If stupidity got us into this mess, how come it can't get us out |> | of it? |> + ==== ======================================================== ==== ====+====I would do it the following way:ToExpression[z = .....];Hermann Schmitt----- Original Message ----- Clearly I can generate the strings z, y, x, w ... in my loop. But> for a given string, how can I assign to the variable whose name is defined> by that string? --> -- Bob Harris ==== ===================================================+> | If stupidity got us into this mess, how come it can't get us out |> | of it? |> + ==== ======================================================== ==== ====+>====Bob,Use the Symbol statement. Symbol[w] gives the symbol w.Symbol[w]% // HeadwSymbolDavid Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ -- Bob Harris ==== ===================================================+| If stupidity got us into this mess, how come it can't get us out || of it? |+ ==== ======================================================= ==== =====+====Use Symbol[x] to refer to a symbol with a specified name.--Steve LuttrellWest Malvern, UK> Howdy, I'm trying to write a loop that assigns functions to a series of variables> which I'd like to name z, y, x, w, ... and so on. The functions arematrix> operator of a group, which I would use like this, for example: state // w // z // w // w Clearly I can generate the strings z, y, x, w ... in my loop. But> for a given string, how can I assign to the variable whose name is defined> by that string? --> -- Bob Harris ==== ===================================================+> | If stupidity got us into this mess, how come it can't get us out |> | of it? |> + ==== ======================================================== ==== ====+>====>> ... for a given string, how can I assign to the variable whose name is>> defined by that string?and Hermann Schmitt replied:> I would do it the following way:> ToExpression[z = .....];contains the entire assignment.A couple people suggested using Symbol[], but I don't see how that wouldwork. For example, Symbol[x] = 13doesn't create a symbol x with value 13. Instead, it simply produces anBob H ==== It does work, but you need to evaluate the left hand side:Evaluate[Symbol[x]]=13;In[14]:=xOut[14]=13Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> ... for a given string, how can I assign to the variable whose name > is> defined by that string? and Hermann Schmitt replied:>> I would do it the following way:>> ToExpression[z = .....]; that> contains the entire assignment. A couple people suggested using Symbol[], but I don't see how that > would> work. For example, Symbol[x] = 13 doesn't create a symbol x with value 13. Instead, it simply produces > an> Protected. Bob H ==== Bob, if you want to get to that kind of programming (scriptingMathematica inside Mathematica) it pays to understand the way thingsare evaluated in Mathematica.Symbol[x] IS indeed the Ônatural' way to create a symbol named x.To answer your question on why Symbol[x]=13 does not work, try ToExpression[x]=13...it doesn't work either.The answer is that Set(=) has the Attribute HoldFirst which keeps theleft-hand side of the assignment from being created.A direct solution is Evaluate[Symbol[x]]=13 orEvaluate[ToExpression[x]]=13.Now, you seem to believe that ToExpression[x=13] is the way to doit.I do not agree:the string inside ToExpression does not interact properly with scopingconstructs like Module,With and asignments.Try:With[{a=13},ToExpression[x=a]]orassigntox[n_ ]:=ToExpression[x=n]The scoping constructs just can't see the symbols inside the string!I think the best way to go is something like:With[{var=Symbol[x]},...stuff with var...]Orestis>> ... for a given string, how can I assign to the variable whose name is>> defined by that string?> and Hermann Schmitt replied:> I would do it the following way:> ToExpression[z = .....];> contains the entire assignment.> A couple people suggested using Symbol[], but I don't see how that would> work. For example,> Symbol[x] = 13> doesn't create a symbol x with value 13. Instead, it simply produces an> Bob H ==== > I am looking for best, in the statistical sense, basic (longest but shorter> than length of the whole sequence, of course) period estimation of the> integer sequence. The integer sequence may be corrupted by fading (randomly> missing sequence elements).> The integer sequence with the basic period P has length L and contain every> integer numbers i = 1,2, ..., N at least once. Where N<=P In the real application will be L ~ 100-10000, N ~ 3-100 and P ~ 3-100> Are there any suitable, robust and efficient algorithms?> MichalI don't know about robust but the ideas below are reasonably efficientand may help you to start on this. The quality of these variousapproaches will very likely depend alot on how the quantity of fading,as well as on statistics of the sequences themselves (e.g. is a basicperiod highly structured?).(i) You could try matching a piece of the sequence to later pieces andsee how far apart they tend to lie. I do not pursue this method belowbut I would suspect one could use it to advantage.(ii) You could work with Fourier transforms. I illustrate with anexample.We create a random period of length 20.data = Table[Random[Integer,2^4-1], {20}];Form 100 of these.new = Flatten[Table[data, {100}]];Make the end ragged so we do not have an exact multiple of periods.new2 = Join[new, Take[new,4]];Pick some elements at random to be removed, to simulate fading.leaveout = Table[Random[Integer,Length[new]], {10}];new3 = Part[new2, Complement[Range[Length[new]], leaveout]];Now we will take the Fourier transform, then take absolute values. As ithappened, I did not much like the result (too many small frequencies,perhaps some form of smearing), so I repeated the process.nn = Abs[Fourier[Abs[Fourier[new3]]]];Let's see how big is the largest component.In[19]:= Max[nn]Out[19]= 100.577Arbitrarily I threshhold at about 25% of the maximum. The idea is tohave large components become 1, small become zero, and check the runlength at the ends (we will see below that the frequencies in themiddle tend to be too small and homogenized).thresh = Map[If[Abs[#]>25,1,0]&, nn];In[21]:= lens = Map[Length,Split[thresh]]Out[21]= {1, 19, 1, 19, 1, 19, 1, 19, 1, 1829, 1, 19, 1, 19, 1, 19, 1,19}At this point we just need to pair off the large and small frequencies,look at the ends, sum the pairs, and average.newsplit = Partition[lens,2];ends = Join[Take[newsplit,2],Take[newsplit,-2]];< En/Na Roland Nilsson ha escrit: > Hi,> --Short form:> Is the sorting algorithm implemented by Sort[] stable?> --Long form:> I'm doing a thingy where I need to take out subsets of data and look at them> individually. I have a labeled data set, with labels being a vector of 1,2> ... denoting class membership, and I've tried to pick out subset using> either e.g.> Extract[data, Position[labels,1]]> => the data points in class 1> or using Sort to sort data according to labels (so I get e.g. {1,1,1,1, ...> 2,2,2, ... 3,3,3}, and which is nice for plotting data sets. This work ok,> but it seems like Sort[] is rearranging the data points within classes> different from Extract[]. Does anyone know i Is the Sort[] algorithm stable?> Could there be something else lurking here?> --> ---------------------------------------------> Roland Nilsson> IFM Computational Biology> Link.9aping University, Sweden> rolle@ifm.liu.se MySort[n_, data_] :=> Sort[Sort[Select[data, First[#] == n &], #1[[2]] <= #2[[2]] &],> Apply[Plus, Rest[#1]] <= Apply[Plus, Rest[#2]] &] data = Table[{Random[Integer, {1, 3}], Random[Integer, {1, 3}],> Random[]}, {30}]; Flatten[Map[MySort[#, data] &, Union[Map[First, data]]], 1]MySort[n_, data_] := Sort[Sort[Select[data, First[#] == n &], #1[[2]] <= #2[[2]] &], Apply[Plus, Rest[#1]] <= Apply[Plus, Rest[#2]] &]Ifdata = Table[{Random[Integer, {1, 3}], Random[Integer, {1, 3}], Random[]}, {30}];data1 = Flatten[Map[MySort[#, data] &, Union[Map[First, data]]], 1] and ifdata = Table[{Random[Integer, {1, 3}], Random[Integer, {1, 3}], Random[Integer,{1, 3}]}, {30}];data2 = Sort[ Flatten[Map[MySort[#, data] &, Union[Map[First, data]]], 1], #1[[3]] <=#2[[3]] &] // SortReply-To: kuska@informatik.uni-leipzig.de ==== Hi,you get the OutputForm[] but your wish is the InputForm[]In the OutputForm[] you have 72.93219 x 10and that is in you string because 012 is an carrige return.Just tell Mathematica that you need the InputForm[] of youroutput. Jens> I hope someone can help me with the following problem:> I am using Mathematica via a Mathlink Connection. As commands I am sending> text-packets and I want to receive the calculated result also as> Returntext-packet.> This so far works well unless the calculated result is in an exponential> format like p.ex.> In this case I would receive in the Returntext-packet something like this:> 70122.93219 10 (with 10 leading blanks)> which is very unsatisfying for me.> Any help is highly appreciated.> Greetings,> Rolf ==== Say I have a list of k integers and I want to produce a list containing thefirst differences? For example, given {1, 2, 5, 7, 8, 9} the firstdifferences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,0}, the third are {-3, 0, 1}, etc ==== Here is one way:f[l_List,n_Integer?Positive]:=Nest[ListConvolve[{1,-1},#] &,l,n]l={1,2,5,7,8,9};f[l,1]{1,3,2,1,1}f[l,2]{2,-1,-1,0}In[5] :=f[l,3]{-3,0,1}Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> Say I have a list of k integers and I want to produce a list > containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, > -1, -1,> 0}, the third are {-3, 0, 1}, etc> ==== Zachary,list = {1, 2, 5, 7, 8, 9};To obtain the first differences.To obtain the first differences...Drop[RotateLeft[list] - list, -1]{1, 3, 2, 1, 1}For the original list and all orders of differences...NestList[Drop[RotateLeft[#] - #, -1] &, list, Length[list] - 1]{{1, 2, 5, 7, 8, 9}, {1, 3, 2, 1, 1}, {2, -1, -1, 0}, {-3, 0, 1}, {3, 1}, {-2}}Otherwise you have to wait for the next day's postings.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== These definitions generate the lists you want in traditional form fordifferences:Differences[input_] := Partition[input, 2, 1] /. {{a_, b_} -> b - a};DifferencesTable[input_] := DT[FixedPointList[Differences, input, Length[input] - 1, SameTest -> (Length[Union[#2]] == 1 & )]]DT[e_] := TableForm[Transpose[ (MapThread[Prepend[#1, [CapitalDelta]^StringJoin[(, ToString[#2 - 1], )]] & , {#1, Range[Length[#1]]}] & )[ (PadRight[#1, Length[e[[1]]], ] & ) /@ e]]]Ken LevasseurMath. Sci.UMass Lowell> To: mathgroup@smc.vnet.net> Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etc> ==== Zachary: After entering the list of k integers, evaluate the following: #[[2]]-#[[1]]&/@Partition[%,2,1]Then you can evaluate exactly the same expression again, and again,until the nth difference is a single number. The easiest way to do thatis to type +L, which automatically inserts, for evaluation, theprior input. Hope that helps. Best, Harvey-----Original Message----- ==== > Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etc>v = {1, 2, 5, 7, 8, 9};Rest[v-RotateRight[v]]{1,3,2,1,1}nthDifference[v_List, n_Integer] := Nest[Rest[#-RotateRight[#]]&,v,n] /; 0 <= n <= Length[v];nthDifferenceList[v_List, n_:Length[v]] := NestList[Rest[#-RotateRight[#]]&,v,n] /; 0 <= n <= Length[v] && IntegerQ[n];nthDifference[v,3]{-3,0,1}nthDifferenceList[v,3]{ {1,2,5,7,8,9},{1,3,2,1,1},{2,-1,-1,0},{-3,0,1}} nthDifferenceList[v]{{1,2,5,7,8,9},{1,3,2,1,1},{2,-1,-1,0},{- 3,0,1},{3,1},{-2},{}}Bob Hanlon ==== > Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etcIn[1]:= lis = {1, 2, 5, 7, 8, 9}Out[1]= {1, 2, 5, 7, 8, 9}In[2]:= diff[x_List] := Rest[x - RotateRight[x]]In[3]:= diff[lis]Out[3]= {1, 3, 2, 1, 1}In[4]:= Nest[diff, lis, 2]Out[4]= {2, -1, -1, 0}In[5]:= NestList[diff, lis, 3]Out[5]= {{1, 2, 5, 7, 8, 9}, {1, 3, 2, 1, 1}, {2, -1, -1, 0}, {-3, 0, 1}}Rob PrattDepartment of Operations ResearchThe University of North Carolina at Chapel Hillhttp://www.unc.edu/~rpratt/ ==== On 3/8/03 at 2:52 AM, _NOzturnerSPAM_@cyberonic.com (Zachary Turner)>Say I have a list of k integers and I want to produce a list>containing the first differences? For example, given {1, 2, 5, 7, 8,>9} the first differences are {1, 3, 2, 1, 1}, and the second>differences are {2, -1, -1, 0}, the third are {-3, 0, 1}, etcListConvolve[{1,-1},{1, 2, 5, 7, 8, 9}] will compute what you are calling the first difference andNest[ListConvolve[{1, -1}, #] &, {1, 2, 5, 7, 8, 9}, n] will compute the nth differenceReply-To: drbob@bigfoot.com ==== differences[a_List] := NestList[Drop[RotateLeft@# - #, -1] &, a, Length@a - 1]differences@{1, 2, 5, 7, 8, 9}BobbyOn Sat, 8 Mar 2003 02:52:13 -0500 (EST), Zachary Turner > Say I have a list of k integers and I want to produce a list containing > the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, - > 1,> 0}, the third are {-3, 0, 1}, etc-- majort@cox-internet.comBobby R. Treat ==== diff[lst_List]:=Drop[lst,1]-Drop[lst,-1]then Nest[diff, myList, {n}] to get the n-th difference of myListOrestis> Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etc ==== > Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etc> Differences[A_List] := Drop[A, 1] - Drop[A, -1];NestList[Differences[#] &, {1, 2, 5, 7, 8, 9}, 3]{{1, 2, 5, 7, 8, 9}, {1, 3, 2, 1, 1}, {2, -1, -1, 0}, {-3, 0, 1}}Differences[{1, 2, 5, 7, 8, 9}]{1, 3, 2, 1, 1}--Ed Pegg Jr ==== difs[x_] := (#2-#1&) @@@ Partition[x, 2, 1]For the nth differences, you can do Nest[difs, x, n]--- / FROM Zachary Turner AT 03.03.08 08:29 (Today) / ---> Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etc-- Daniel Reeves -- http://ai.eecs.umich.edu/people/dreeves/ Mathematicians do it continuously and discretely. -- bumper sticker by Robert L Dawes ==== Say I have a list of k integers and I want to produce a list containing the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, -1,> 0}, the third are {-3, 0, 1}, etc v = {1, 2, 5, 7, 8, 9};> Rest[v-RotateRight[v]]> {1,3,2,1,1}> nthDifference[v_List, n_Integer] :=> Nest[Rest[#-RotateRight[#]]&,v,n] /;> 0 <= n <= Length[v]; nthDifferenceList[v_List, n_:Length[v]] :=> NestList[Rest[#-RotateRight[#]]&,v,n] /;> 0 <= n <= Length[v] && IntegerQ[n]; nthDifference[v,3]> {-3,0,1}> nthDifferenceList[v,3]> {{1,2,5,7,8,9},{1,3,2,1,1},{2,-1,-1,0},{-3,0,1}}> nthDifferenceList[v]> {{1,2,5,7,8,9},{1,3,2,1,1},{2,-1,-1,0},{-3,0,1},{3,1},{-2},{} }> Bob HanlonThis shows a slightly faster method using listCorrelatenthDifference1[v_List, n_Integer] := Nest[Rest[#-RotateRight[#]]&,v,n] /; 0 <= n <= Length[v];nthDifferenceList1[v_List, n_:Length[v]] := NestList[Rest[#-RotateRight[#]]&,v,n] /; 0 <= n <= Length[v] && IntegerQ[n];nthDifference2[v_List, n_Integer] := Nest[ListCorrelate[{-1,1},#]&,v,n] /; 0 <= n <= Length[v];nthDifferenceList2[v_List, n_:Length[v]] := NestList[ListCorrelate[{-1,1},#]&,v,n] /; 0 <= n <= Length[v] && IntegerQ[n];v = Table[Random[], {100000}];d1 = nthDifferenceList1[v];//Timing{0.38 Second,Null}d2 = nthDifferenceList2[v];//Timing{0.28 Second,Null}d1==d2TrueBob Hanlon ==== Try the following:FixedPointList[(#1[[2]] - #1[[1]] & ) /@ Partition[#1, 2, 1] & , {1, 2, 5, 7, 8, 9}]which produces the list{{1, 2, 5, 7, 8, 9}, {1, 3, 2, 1, 1}, {2, -1, -1, 0}, {-3, 0, 1}, {3, 1},{-2}, {}, {}}Just strip off the last two elements and it does what you want.--Steve LuttrellWest Malvern, UK> Say I have a list of k integers and I want to produce a list containingthe> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are{2, -1, -1,> 0}, the third are {-3, 0, 1}, etc>Reply-To: drbob@bigfoot.com ==== Try this:differences[a_List] := NestList[ Subtract @@@ Partition[#, 2, 1] &, -a, Length@a - 1]s = {1, 2, 5, 7, 8, 9};differences@s // TableFormBobbyOn Sun, 9 Mar 2003 05:27:13 -0500 (EST), Harvey P. Dale Zachary:> After entering the list of k integers, evaluate the following:> #[[2]]-#[[1]]&/@Partition[%,2,1]> Then you can evaluate exactly the same expression again, and again,> until the nth difference is a single number. The easiest way to do that> is to type +L, which automatically inserts, for evaluation, the> prior input.> Hope that helps.> Best,> Harvey -----Original Message-----> To: mathgroup@smc.vnet.net Say I have a list of k integers and I want to produce a list containing> the> first differences? For example, given {1, 2, 5, 7, 8, 9} the first> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1,> -1,> 0}, the third are {-3, 0, 1}, etc-- majort@cox-internet.comBobby R. TreatReply-To: drbob@bigfoot.com ==== Or:nthDifferenceList3[v_List] := nthDifferenceList3[v, Length@v - 1]nthDifferenceList3[v_List, n_Integer] /; 0 <= n < Length[v] := NestList[ListCorrelate[{-1, 1}, #] &, v, n]Bobby>> Say I have a list of k integers and I want to produce a list containing >> the>> first differences? For example, given {1, 2, 5, 7, 8, 9} the first>> differences are {1, 3, 2, 1, 1}, and the second differences are {2, -1, - >> 1,>> 0}, the third are {-3, 0, 1}, etc>> v = {1, 2, 5, 7, 8, 9};>> Rest[v-RotateRight[v]]>> {1,3,2,1,1}>> nthDifference[v_List, n_Integer] :=>> Nest[Rest[#-RotateRight[#]]&,v,n] /;>> 0 <= n <= Length[v];>> nthDifferenceList[v_List, n_:Length[v]] :=>> NestList[Rest[#-RotateRight[#]]&,v,n] /;>> 0 <= n <= Length[v] && IntegerQ[n];>> nthDifference[v,3]>> {-3,0,1}>> nthDifferenceList[v,3]>> {{1,2,5,7,8,9},{1,3,2,1,1},{2,-1,-1,0},{-3,0,1}}>> nthDifferenceList[v]>> {{1,2,5,7,8,9},{1,3,2,1,1},{2,-1,-1,0},{-3,0,1},{3,1},{-2},{} }>> Bob Hanlon>> This shows a slightly faster method using listCorrelate nthDifference1[v_List, n_Integer] := Nest[Rest[#-RotateRight[#]]&,v,n] /; 0 <= n <= Length[v]; nthDifferenceList1[v_List, n_:Length[v]] := NestList[Rest[#-RotateRight[#]]&,v,n] /; 0 <= n <= Length[v] && IntegerQ[n];> nthDifference2[v_List, n_Integer] := Nest[ListCorrelate[{-1,1},#]&,v,n] /; 0 <= n <= Length[v];> nthDifferenceList2[v_List, n_:Length[v]] := NestList[ListCorrelate[{-1,1},#]&,v,n] /; 0 <= n <= Length[v] && IntegerQ[n]; v = Table[Random[], {100000}]; d1 = nthDifferenceList1[v];//Timing {0.38 Second,Null} d2 = nthDifferenceList2[v];//Timing {0.28 Second,Null} d1==d2 True Bob Hanlon-- majort@cox-internet.comBobby R. TreatReply-To: marc.noel@skynet.be ==== Hi,It would be very nice to be able to write the apps in one window and see the result (output) in another oneCan anybody tell me how to do this.please, I a not a mathematician, only someone who wants the math done by s.o.else(mathematica) and focus on problems, so if you have an answer try to be as plain as possible.I also tend to think this would be useful for a lot of peopleMarc ==== Marc,You can open another notebook (window) and write output to it. This is doneusing notebook programming. In the Help browser look under Built InFunctionsNotebooksNotebook Operations and Notebook Manipulations.However from the tenor of your question, I suspect that you would not wantto get into this kind of programming. What is wrong with working in a singlenotebook? If you learn how to use the automatic grouping, to put in Titlesand Section Headings, etc., you can make the notebook look and perform quitenicely.Are you new to Mathematica? What level of math are you willing to do? Theidea that Mathematica has a command to solve every math problem, evenrelatively simple ones, is far from correct. For example, high schoolstudents may learn how to complete the square but there is no Mathematicacommand for it. It is easy enough to program a routine to do it. The pointis that mathematics, even relatively simple mathematics, not to speak ofengineering and science, is so vast that it is impossible for Mathematica tohave a command for everything; there would be millions of commands and youcouldn't find the one you wanted.So if you are not willing to do SOME mathematics and SOME programming, youmay be disappointed in what Mathematica will do for you. On the other hand,if you are willing to do some math and programming, then Mathematica is awonderful tool and will greatly amplify your efforts.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== >-- ---Original Message----->Sent: Friday, March 07, 2003 9:43 AM>To: mathgroup@smc.vnet.net>Hi>I have a list of data records which are all of the same type, for>example person:{name_Sting, sex:M|F, age_Integer, weight_?((1<#<500)&)}.>I want to access the different fields so I have given them names in the >pattern. I have a list of these records and I want to use pattern>matching to test the the whole list such as >{person:{name_Sting, sex:M|F, age_Integer, weight_?((1<#<500)&)}...} >but once you name the parts of the pattern, they have to be the same for>every record. I could leave the names out and use a pattern like >{{_Sting, M|F, _Integer, _?((1<#<500)&)}...} >which matches different records with the same structure but then I can't>access the field values by name. Is there any way I can do both at once?>G>Reformulate your problem. See e.g.In[1]:= alist = {{Adam, M, 38, 73}, {Eve, F, 37, 65.5}, {Kain, M, 17, 501}, {Abel, M, 15, 58}};In[2]:= ToString[Count[alist, person : {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500 &)} /; (Print[Name: , name, nSex , sex, nAge = , age, nweight is , weight]; True)]] <> matches out of <> ToString[Length[alist]]Name: AdamSex MAge = 38weight is 73Name: EveSex FAge = 37weight is 65.5Out[2]= 2 matches out of 4If a name appears in a pattern it must get the same value for eachoccurance, else the pattern as a whole cannot match:In[6]:=MatchQ[{{Adam, M, 38, 73}, {Adam, M, 38, 73}, {Eve, F, 37, 65.5}, {Adam, M, 38, 73},}, {({name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500 &)} /; (Print[Name: , name, nSex , sex, nAge = , age, nweight is , weight]; True)) ...}]Name: AdamSex MAge = 38weight is 73Name: AdamSex MAge = 38weight is 73Out[6]= FalseHere you see how Adam is matched at his first occurrance and the patternvariables get their values, which then are printed. The next list elementmatches because now all values of all pattern variables match, that matchthen issues the second print. After that Eve doesn't match to Adam andthe pattern as whole won't match and thus is abandoned, the third occurranceof Adam will not be considered.Perhaps you also might be interested in this observation:In[18]:=MatchQ[{{Adam, M, 38, 73}, {Adam, M, 38, 73}, {Eve, F, 37, 65.5}, {Adam, M, 38, 73},}, {_?(MatchQ[#, Null | {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500 &)} /; (Print[Name: , name, nSex , sex, nAge = , age, nweight is , weight]; True)] &) ...}]Name: AdamSex MAge = 38weight is 73Name: AdamSex MAge = 38weight is 73Name: EveSex FAge = 37weight is 65.5Name: AdamSex MAge = 38weight is 73Name: Sex Age = weight is Out[18]= TrueHere the pattern for the element has no name, hence each element in the Listwill be tried. This (matched) element then will be matched to constituentsas part of the PatternTest (?test). We included Null into that pattern asNull is tried for RepeatedNull (or Repeated) and MatchQ then gives True. Thepattern variables of the constituents, however, don't get a value in thiscase, as you see. Had we not included Null into that test, all persons stillwould have been printed, but the pattern as a whole would have failed. You also might like to look at:MatchQ[Join[ alist, {{Adam, M, 38, 73}}], {_?((MatchQ[#1, Null | {name_String, sex : (M | F), age_Integer, weight_?(1 <= #1 <= 500 &)} /; (Print[Name: , name, nSex , sex, nAge = , age, nweight is ,weight]; True)]; True) &) ...}]The most simple application might be just to use the pattern as filter forthose records which qualify, or don't: In[31]:= Cases[alist, person : {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500&)}]Out[31]= {{Adam, M, 38, 73}, {Eve, F, 37, 65.5}}In[33]:= Cases[alist, _?(! MatchQ[#, {name_String, sex : M | F, age_Integer, weight_?(1 <= # <= 500 &)}] &)]Out[33]= {{Kain, M, 17, 501}, {Abel, M, 15, 58}}--Hartmut Wolf ==== Hi, I am working on a presentation. What is the best way to arrange graphs,tables and text (like in PowerPoint)? E.g.: ==== ============Title----------------| | text || graph |-------| | table|---------------- ==== ============ thanks for your help, -akos ==== Akos,Hmm, Mathematica is very vertically oriented - input, below that output, next input, next output, and so on down the page. If you are using v4.2 I suggest that you open the OpenAuthorTools palette and start experimenting with BilateralCells. Also, you might want to play around with the StyleSheet, paying particular attention to the Presentation versions of the styles you are using. I'm not sure I can provide any better advice than this, I tend to view the Front End as something of a black box, and I usually just dive in, start messing about, and decide that the best I can do in the time available is what I really wanted all along.Mark Westwood> Hi,> I am working on a presentation. What is the best way to arrange graphs,> tables and text (like in PowerPoint)?> E.g.:> ==== ============> Title> ----------------> | | text |> | graph |-------> | | table|> ----------------> ==== ============> thanks for your help,> > -akos> ==== Hi,i have the exactly same problem.i tried re-rename my admin-accoutn back to Administrator, since i changed it once to my real name. no effect...I have Win2k, 512MB ram, 8 gb free disk space,sp3!Nvida geforce mx 440, and athlon xp 2000+soundblaster live value, asus a7m266.realtek network card, 10 mbiti had mathematica 4.1 installed, deinstalled, installed 4.2it crashed saying it coulnd create start menu entry.i didnt care, and made one myself, to problem....there seem to be quite a few people out there who have this problem.:a guy posted something in year 2002 already..found it on them mathgroup forums on wolfram pageaswell in this forum: by Eri 08.02.2003so somebody, please solve it!!!!maybe people who have the same prob, please give their hardware/softwaredescription, maybe it only occures on athlon or something??So lets find out!!cause i really enjoy the faster File Import, that's a great thing!!Bernhard> Hi,> I'm running Mathematica 4.2 (Win2k, 2GB RAM,2GB swap> file, sp3, administrator's rights) and I'm unable to> build the help browser; Mathematica freezes and never> ends, I have to kill the task. I read all the> available info's in the news group but couldn't find> any valuable answer to fix this problem. Mathematica> 4.01 doesn't have this problem.> Could someone give me a clue to fix it?> Fred> __________________________________________________> Do You Yahoo!?> Everything you'll ever need on one web page> http://uk.my.yahoo.com> Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,SubsuperscriptBox[x, j, 2] // DisplayForm Jens> I want to put an exponent and an indice on a same Letter like that :> 2> X> i> How can I do ? ==== > I want to put an exponent and an indice on a same Letter like that : 2> X> i How can I do ?>Use the BasicTypesetting palette orSubscript[x, i]^2Bob Hanlon ==== Rodolphe,x Ctrl _ i Ctrl space Ctrl ^ 2 Ctrl spaceDavid Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== The easiest way is to use the Basic Typesetting palette. There you will finda template for the situation you describe. If the palette doesn't show up onstarting Mathematica, use File | Palettes | 5 BasicTypesetting. Now, bear inmind that whereas the exponent 2 is understood as such, the subscript ihas no meaning by itself and if you want to use it to denote the i-th partofthe list x you must previously define it to mean that (see The Book,2.8.15). The x with subscript i obtained with the palette is equivalent toSubscript[x, i]. Then for example, defineIn[1]:=Subscript[x_, i_] := x[[i]]In[2]:=x = {1, 3, 8}; a = {4, 5, 6};In[3]:=Subscript[x, 1]Out[3]=1In[4]:=Subscript[a, 2]Out[4]=5Tomas GarzaMexico City----- Original Message ----- ==== On the BasicTypesetting palette you will find a template that does what youwant (3rd across in row 8), plus lots of other related templates. Have fun!For instance this will represent x^i_j as the following Mathematicaexpression:BoxData[SubsuperscriptBox[x, i, j]]--Steve LuttrellWest Malvern, UK I want to put an exponent and an indice on a same Letter like that : 2> X> i How can I do ?> ==== >I want to put an exponent and an indice on a same Letter like that :A simple way would be to use the Basic Type Setting Palette. Look under File->Palettes.Alternatively, there is Power[Subscript[x,i],2] ==== Look at the BasicTypsetting Palette. You can find it under File->Palettes->.I think it has exactly what you want.Adam Smith> I want to put an exponent and an indice on a same Letter like that :> 2> X> i> How can I do ? ==== Hi,I am trying to run ssh (with background-option -f) from within Mathematica 4.2 to start a program on a remote computer, which I need.The command I use is:Run[ssh -X -f username@machinename.de execute-command]If there is no password check of ssh, there is no problem, but if ssh is asking for a password, this is prompted to the console from which mathematica was started and the kernel has a hang up, because ssh is not able to finish.I know I managed mathematica to open a small interactive window, in which you could enter the password, and so it worked, but I am not able to reproduce this, although I've changed nothing in my configuration.Can you tell me, if it is possible to run ssh from within Mathematica with a password check.I am thankful for helpSirko StraubeOpenSSL 0x0090602f ==== has anyone here implemented said algorithm in Mathematica and is willing to shareit?Flip ==== The problem I am working on involves 28 variables in 192 inequalities.I tried a simpler problem (one that involves 6 variables and 16 inequalities)using InequalitySolve and it gave me a solution that was very difficult tocomprehend. The sample problem is solving {a,b,c,d,e,f,g}, from c0,b0,a0,a+b+c+4g2d+2e+2f,2eb,2eca+2eb+c,a+4g2d+2f,2fa,b+2fa+ c,2fc,b+4g2d+2e,c+2da+b,2da,2db,c+4g2e+efSolving the set of inequatlities by hand allows us to express all variables with dependence on g. Is there a way Mathematica can do that? ChristinaInequalitySolve represents the solution of a system in cylindrical form, which is usually the most convenient for further processing. In general there is nothing simpler available, although in special cases humans rather than computer can find simpler representations. To decide if your case is one of these one would have either to see the full problem or at least a toy problem with the same sort of structure. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ Hi, I have 192 linear inequalities containing 28 variables and I want to find the constraints for each of the variables. I am thinking about solving the system by eiliminating the variables one by one (similar to the Gaussian Elimination). Is there a way I can do it with Mathematica? The function InequalitySolve gives me a solution that is more complicated than the problem itself.Is there any other Christina ==== Even your toy system is in fact too complicated for Mathematica to solve in reasonable time, or at least in any time that I can spare. So answer that was more complicated than the original problem you probably made a mistake in the input. I very much doubt that InequalitySolve can produce any answer to the original question in any reasonable time.Moreover, I am not sure what you mean by:Solving the set of inequatlities by hand allows us to express all variables with dependence on g.Do you mean to say that once we are given the value of g we can determine the bounds for each of the other variables, in a way that is equivalent to the original equations? This seems to be false. To see that, let's first of all simplify your inequalities so that Mathematica can handle them reasonably quickly, say by substituting some arbitrary values for a, b and c. For example,{a, b, c} = {1, 2, 3};Now, your inequalities take the form:ineqs = And @@ {a + b + c + 4*g > 2*d + 2*e + 2*f, 2*e > b, 2*e > c, a + 2*e > b + c, a + 4*g > 2*d + 2*f, 2*f > a, b + 2*f > a + c, 2*f > c, b + 4*g > 2*d + 2*e, c + 2*d > a + b, 2*d > a, 2*d > b, c + 4*g > 2*e + e*f}6 + 4*g > 2*d + 2*e + 2*f && 2*e > 2 && 2*e > 3 && 1 + 2*e > 5 && 1 + 4*g > 2*d + 2*f && 2*f > 1 && 2 + 2*f > 4 && 2*f > 3 && 2 + 4*g > 2*d + 2*e && 3 + 2*d > 3 && 2*d > 1 && 2*d > 2 && 3 + 4*g > 2*e + e*fHere are the variables, (the order is chosen deliberately):vars=Reverse[Union[Cases[ineqs,_Symbol,Infinity] ]]{g,f,e,d}Let's load in the Experimental context, which contains the fastest functions for this sort of problem: << Experimental`The fastest function for this sort of thing is GenericCylindricalAlgebraicDecompositionGenericCylindricalAlge braicDecomposition[ineqs, vars][[1]]1 < g < 7/4 && (3/2 < f < -(5/4) + (1/4)*Sqrt[57 + 64*g] && (2 < e < (1/2)*(1 + 2*f) && 1 < d < (1/2)*(1 - 2*f + 4*g) || (1/2)*(1 + 2*f) < e < (3 + 4*g)/(2 + f) && 1 < d < 1 - e + 2*g) || -(5/4) + (1/4)*Sqrt[57 + 64*g] < f < (1/2)*(-1 + 4*g) && 2 < e < (3 + 4*g)/(2 + f) && 1 < d < (1/2)*(1 - 2*f + 4*g)) || g > 7/4 && (3/2 < f < 2 && (2 < e < (1/2)*(1 + 2*f) && 1 < d < (1/2)*(1 - 2*f + 4*g) || (1/2)*(1 + 2*f) < e < (3 + 4*g)/(2 + f) && 1 < d < 1 - e + 2*g) || 2 < f < (1/5)*(-4 + 8*g) && (2 < e < 5/2 && 1 < d < (1/2)*(1 - 2*f + 4*g) || 5/2 < e < (3 + 4*g)/(2 + f) && 1 < d < 3 - e - f + 2*g) || (1/5)*(-4 + 8*g) < f < (1/2)*(-1 + 4*g) && 2 < e < (3 + 4*g)/(2 + f) && 1 < d < (1/2)*(1 - 2*f + 4*g))Looking at it carefully you see that you can't express the bounds for the other parameters in terms of g alone. Perhaps I have misunderstood you, but it seems to me that the problem you are trying to solve is much more complex than you seem to realize.Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> The problem I am working on involves 28 variables in 192 inequalities. > I tried a simpler problem (one that involves 6 variables and 16 > inequalities) using InequalitySolve and it gave me a solution that was > very difficult to comprehend. The sample problem is solving > {a,b,c,d,e,f,g}, from c>0, b>0, a>0, a+b+c+4g>2d+2e+2f, 2e>b, 2e>c a+2e>b+c, a+4g>2d+2f, 2f>a, b+2f>a+c, 2f>c, b+4g>2d+2e, c+2d>a+b, 2d>a, 2d>b, c+4g>2e+ef Solving the set of inequatlities by hand allows us to express all > variables with dependence on g. Is there a way Mathematica can do > that? Christina>To: Christina Chan >CC: mathgroup@smc.vnet.net >Mathematica has in fact a very rich collection of functions for>that the kind of solution you seem to expect to get for your system >is actually possible. You say that InequalitySolve gives me a >solution that is more complicated than the problem itself. Actually >InequalitySolve represents the solution of a system in cylindrical >form, which is usually the most convenient for further processing. >In general there is nothing simpler available, although in special >cases humans rather than computer can find simpler representations. >To decide if your case is one of these one would have either to see >the full problem or at least a toy problem with the same sort of >structure. >Andrzej Kozlowski >Yokohama, Japan >http://www.mimuw.edu.pl/~akoz/ >http://platon.c.u-tokyo.ac.jp/andrzej/ >>Hi, >>I have 192 linear inequalities containing 28 variables and I want >>to find the constraints for each of the variables. I am thinking >>about solving the system by eiliminating the variables one by one >>(similar to the Gaussian Elimination). Is there a way I can do it >>with Mathematica? The function InequalitySolve gives me a solution >>that is more complicated than the problem itself.Is there any other>> >>Christina >>dd[[1]], b->d[[3]], c->d[[4]], ...}c/.ssRules will return the Ôvalue' of cand First/@ssRules will give back ss.Hope that helped,Orestis> Dear MathGroup,> I am doing something much more complicated but this trivial example> expresses my difficulty.> If I have a list of symbols and a list of data such as > ss = {a, b, c, d, e}> > dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}> how do I take a symbol from the list ss and associated it with data from the> list dd?> A wrong attempt is to try> ss[[3]] = dd[[4]]> This replaces element 3 in ss with element 4 from dd.> What I need is an assignment so that, in this case, the symbol c is> associated with the data. Equivalent to writing > c = dd[[4]]> so that c could then be used in subsequent expressions and the list ss is> unchanged.> Note that this is a trivial example for pedagogic purposes - I can't do the> simple assignment in my actual case.> Hugh Goyder ==== Evaluate[ss[[3]]] = dd[[4]]will do what you want.Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> Dear MathGroup, I am doing something much more complicated but this trivial example> expresses my difficulty. If I have a list of symbols and a list of data such as ss = {a, b, c, d, e} dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415} how do I take a symbol from the list ss and associated it with data > from the> list dd? A wrong attempt is to try ss[[3]] = dd[[4]] This replaces element 3 in ss with element 4 from dd. What I need is an assignment so that, in this case, the symbol c is> associated with the data. Equivalent to writing c = dd[[4]] so that c could then be used in subsequent expressions and the list ss > is> unchanged. Note that this is a trivial example for pedagogic purposes - I can't > do the> simple assignment in my actual case.> Hugh Goyder ==== it's somewhat desperate, maybe a better way is possible(the infixoperator <> joins strings)ss = {a, b, c, d, e}dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415} ToExpression[ ss[[3]] <> = <> ToString[ dd[[4]] ] ] ]Goyder Dr HGD schrieb:> Dear MathGroup,> I am doing something much more complicated but this trivial example> expresses my difficulty.> If I have a list of symbols and a list of data such as > ss = {a, b, c, d, e}> dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}> how do I take a symbol from the list ss and associated it with data from the> list dd?> A wrong attempt is to try> ss[[3]] = dd[[4]]> This replaces element 3 in ss with element 4 from dd.> What I need is an assignment so that, in this case, the symbol c is> associated with the data. Equivalent to writing > c = dd[[4]]> so that c could then be used in subsequent expressions and the list ss is> unchanged.> Note that this is a trivial example for pedagogic purposes - I can't do the> simple assignment in my actual case.> Hugh Goyder> ==== On 3/8/03 at 2:49 AM, H.Goyder@rmcs.cranfield.ac.uk (Goyder Dr HGD)>If I have a list of symbols and a list of data such as>ss = {a, b, c, d, e}>dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}>how do I take a symbol from the list ss and associated it with data>from the list dd?>What I need is an assignment so that, in this case, the symbol c is>associated with the data. Equivalent to writing>c = dd[[4]]>so that c could then be used in subsequent expressions and the list ss>is unchanged.I see the two example lists you've given are two different lengths. That makes it unclear as to which elements of dd you want assigned to which elements of ss. If the two lists were the same length and both ordered so that corresponding elements of each list were in the same positions in their respective lists the following would do what you wantMapThread[Set[#1, #2] &, {list1, list2}]Reply-To: drbob@bigfoot.com ==== ss = {a, b, c, d, e}dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}ToExpression[ToString@ss[[3]] <> = <> ToString@dd[[4]]];cBobbyOn Sat, 8 Mar 2003 02:49:47 -0500 (EST), Goyder Dr HGD > Dear MathGroup, I am doing something much more complicated but this trivial example> expresses my difficulty. If I have a list of symbols and a list of data such as ss = {a, b, c, d, e} dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415} how do I take a symbol from the list ss and associated it with data from > the> list dd? A wrong attempt is to try ss[[3]] = dd[[4]] This replaces element 3 in ss with element 4 from dd. What I need is an assignment so that, in this case, the symbol c is> associated with the data. Equivalent to writing c = dd[[4]] so that c could then be used in subsequent expressions and the list ss is> unchanged. Note that this is a trivial example for pedagogic purposes - I can't do > the> simple assignment in my actual case.> Hugh Goyder>-- majort@cox-internet.comBobby R. Treat ==== > ==== ============ The original posting ==== =====================> I am converting an old code written 8 yrs ago in Mathematica 2.2 to> 4.2, and would like to keep the same plain text tabular output.> To see what I mean, consider the 2.2 fragment> PrintNodeCoordinates[xyzcoor_]:= Module[> {numnod=Length[xyzcoor],t,n,c},> t=Table[ ,{numnod+1},{4}];> For [n=1,n<=numnod,n++,c=xyzcoor[[n]];> If [Length[c]<=2, AppendTo[c,0]];> If [Length[c]==1, AppendTo[c,0]];> t[[n+1,1]]=ToString[n];> t[[n+1,2]]=PaddedForm[c[[1]]];> t[[n+1,3]]=PaddedForm[c[[2]]];> t[[n+1,4]]=PaddedForm[c[[3]]];> ];> t[[1]] = {node,x,y,z};> Print[TableForm[t,TableAlignments->{Right},> TableDirections->{Column,Row},TableSpacing->{0,1}]];> ];> PrintNodeCoordinates[> {{2,3,2000},{5,a+b,168.09},{x_dir,y_dir,z_dir}}];> The output from 2.2 is> node x y z> 1 2 3 2000> 2 5 a + b 168.09> 3 x_dir y_dir z_dir> What you see is exactly what you get if you move the output cell> to another program like TeX, e.g. for verbatim display.You can use TextForm to do this -- and there is no need to use Print.PrintNodeCoordinates[xyzcoor_]:= Module[ {numnod=Length[xyzcoor],t,n,c}, t=Table[ ,{numnod+1},{4}]; For [n=1,n<=numnod,n++,c=xyzcoor[[n]]; If [Length[c]<=2, AppendTo[c,0]]; If [Length[c]==1, AppendTo[c,0]]; t[[n+1,1]]=ToString[n]; t[[n+1,2]]=PaddedForm[c[[1]]]; t[[n+1,3]]=PaddedForm[c[[2]]]; t[[n+1,4]]=PaddedForm[c[[3]]]; ]; t[[1]] = {node,x,y,z}; TextForm[TableForm[t,TableAlignments->{Right}, TableDirections->{Column,Row},TableSpacing->{0,1}]] ]If you Put this output to a temporary file you get exactly what you want: PrintNodeCoordinates[ {{2,3,2000},{5,a+b,168.09},{x_dir,y_dir,z_dir}}] >> /tmp/tmp.outThe file /tmp/tmp.out readsnode x y z1 2 3 20002 5 a + b 168.093 x_dir y_dir z_dirPaul-- The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling HighwayAUSTRALIA http://physics.uwa.edu.au/~paulReply-To: rolf@mertig.com ==== ], Print], which is quite plain text.BTW: does anybody know if there exists a ConversionOptions setting for ExportString to not get the n at the end of ExportString? Right nowExportString[{a},Table] returns an .This may be fine in some situations, but not for the case above (this is why I added the StringDrop[ ,-1]There should be more ConversionOptions documentation really.E.g., does Export[ { { ... }, ... {} }, Table ]also take ConversionOptionssimilar to TableForm? I don't know ... (anybody?, PJ?)Maybe one could also get this type of formatting with J/Link and the apropriate Java (JTable?) classes, but I found this too complicated.Rolf MertigMertig Consultinghttp://www.mertig.comhttp://www.mathxls.com ==== Hi,group. Now I am clear for this problem, which is quite important for myresearch. I am really indebted to you guys.--Chengzhou> Hi, guys> I have some complicated polynomials, and I want to calculate its roots.> > HOwever, when I use NSolve, it creates some problems. Say a simple> example:> temp[s_]=s^10+10 s^9+ 10 s^8 +10 s^7 +10 s^6+ 10 s^5 +10 s^4 +1;> NSolve[temp[s]==0, s]> It will give:> Out[4]= {{s -> -8.99998}, {s -> -1.06539}, {s -> -0.468828 - 0.886239 I},> {s -> -0.468828 + 0.886239 I}, {s -> -0.409684 - 0.469948 I},> {s -> -0.409684 + 0.469948 I}, {s -> 0.401048 - 0.312597 I},> > {s -> 0.401048 + 0.312597 I}, {s -> 0.51015 - 0.878693 I},> > {s -> 0.51015 + 0.878693 I}}> But when I plug in the first number, which is -8.99998, it should give a> value close to zero. However, it gives:> In[5]:= temp[-8.99998]> Out[5]= -411.473> The other roots seems OK. Does anyone know why? This is just a simple> example. I have some more complicated polynomials to deal with.> --> Chengzhou> You are only plugging in the first 6 significant digits of the actual> solution, and error from this truncation is sufficiently large to make> the residual appear big.> temp[s_]=s^10+10 s^9+ 10 s^8 +10 s^7 +10 s^6+ 10 s^5 +10 s^4 +1;> In[14]:= soln = NSolve[temp[s]==0, s];> In[15]:= InputForm[First[soln]]> Out[15]//InputForm= {s -> -8.999981180131652}> In[16]:= temp[-8.999981180131652]> -7> Out[16]= -4.76837 10> If you plug in via rule replacement you do not risk this problem of> inadvertantly truncating needed digits.> In[17]:= InputForm[temp[s] /. soln]> Out[17]//InputForm= > {-4.76837158203125*^-7, 2.220446049250313*^-15, > 2.581268532253489*^-15 - 1.5543122344752192*^-15*I, > 2.581268532253489*^-15 + 1.5543122344752192*^-15*I, > 1.8388068845354155*^-16 - 1.0234868508263162*^-16*I, > 1.8388068845354155*^-16 + 1.0234868508263162*^-16*I, > 1.968911145233676*^-16 - 2.2036409155767878*^-16*I, > 1.968911145233676*^-16 + 2.2036409155767878*^-16*I, > -8.770761894538737*^-15 + 7.549516567451064*^-15*I, > -8.770761894538737*^-15 - 7.549516567451064*^-15*I}> By the way, if you take into account the magnitude of that solution> (around 10^1), the degree of the equation (10), magnitude of coefficient> sizes (1 for lead, 10 for the rest), and the fact that the error is> around the 7th digit, you can estimate that the error in residual> computation may be as large as roughly 10^(-6)*10^10. So obtaining a> residual around O(10^3) using the truncated solution is not surprising.> Daniel Lichtblau> Wolfram Research> Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,what may ToExpression[1.2345] do ? Jens> I am I new Mathematica user and am trying to master input/output. Is there> any way to type cast a string into number format?> Ellen Tolonen> entolonen@utep.edu ==== > I am I new Mathematica user and am trying to master input/output. Is there> any way to type cast a string into number format?>Use ToExpressionBob Hanlon ==== Presumably your string has numbers in string format. Use ToExpression toconvert numbers in string format to numbers.In[1]:=aString = {2, 4, 5.5};In[2]:=Head /@ aStringOut[2]={String, String, String}In[3]:=ToExpression[aString]Out[3]={2, 4, 5.5}In[4]:=Head /@ %Out[4]={Integer, Integer, Real}Tomas GarzaMexico City----- Original Message -----> entolonen@utep.edu ==== You can do lots of useful things with ToExpression, which takes any stringand converts it into the corresponding Mathematica expression. For instance.ToExpression[1.23] will return the real number 1.23, andToExpression[2/7] will return the rational number 2/7, and so on. You canthen manipulate and output these expressions in any way that you please.--Steve LuttrellWest Malvern, UK I am I new Mathematica user and am trying to master input/output. Isthere> any way to type cast a string into number format?> Ellen Tolonen> entolonen@utep.edu> ==== >I am I new Mathematica user and am trying to master input/output. Is>there any way to type cast a string into number format?Try ToExpression[56]Reply-To: drbob@bigfoot.com ==== Bookmarks are obviously not the answer --- the reorganization broke all our bookmarks, and the same may occur again.Wolfram responded to my queries and added keywords, so maybe those particular searches work now, but I guarantee a thousand others won't. I just don't know which ones they are until I try them.Bobby> have i missed something here or are those things called bookmarks not the> solution to your problem?!> it looks like the doc centre is uptodate now as i typed ßash in to the > doc> hmmm....> That's barely half an answer.>> telling me where they are? I won't remember the address, and may not>> Searching for animated functions or Flash at the Documentatian >> Center>> doesn't work, so how would we do that? (I didn't know they were done >> with>> Flash anyway.)>> Bobby>> On Fri, 28 Feb 2003 04:47:04 -0500 (EST), Ed Pegg Somewhere on the Wolfram web site I recently found animations showing> how Map, Thread, Apply, etc., work. Can you tell me the URL?>> You are thinking of the Flash animations by Keehong Song. A recent>> addition of his is at the following link:>> http://library.wolfram.com/database/MathSource/4771/>> His original animations are linked to from there, you can see them at>> http://documents.wolfram.com/ßash/>> --Ed Pegg Jr, www.wolfram.com>> -->> majort@cox-internet.com>> Bobby R. Treat>-- majort@cox-internet.comBobby R. Treat ==== Hi, Can someone help me decipher how this function is working and whatit is doingSelect[Flatten[coord,2], OddQ[Plus @@ #] & ];coord= {{{0,0,0},{1,0,0},{1,1,0}...etccoord is a list of 3d position. I've looked up what each fucntionJMD ==== I think it is supposed to output the coordinate triplets where the sum ofthe coordinates are odd numbers, however it does not work as it stands, ifyou write Select[Flatten[coord,1], OddQ[Plus @@ #] & ] instead, it does dowhat I think it is supposed to do.there could be some other intention to I guess(the original Function just pics the odd numbers from the Flattened list)er..just in case... with the semicolon at the end it does not seem to doanything, so remove that.Best ..Peter W> Hi,> Can someone help me decipher how this function is working and what> it is doing Select[Flatten[coord,2], OddQ[Plus @@ #] & ];> coord= {{{0,0,0},{1,0,0},{1,1,0}...etc> coord is a list of 3d position. I've looked up what each fucntion JMD ==== It should probably be Flatten[coord,1] since Flatten[coord,2] willeliminate all internal brackets leaving just a long list of numbers.Anyway, assuming that it is Flatten[coord,1] which creates a simplelist of vectors, Select[Flatten[coord,1],OddQ[Plus@@#]&] will returnthose vectors in coord ,whose sum of coordinates is an odd number.In the example you gave that would be,{{1,0,0},...}Orestis> Hi,> Can someone help me decipher how this function is working and what> it is doing> Select[Flatten[coord,2], OddQ[Plus @@ #] & ];> coord= {{{0,0,0},{1,0,0},{1,1,0}...etc> coord is a list of 3d position. I've looked up what each fucntion> JMDReply-To: drbob@bigfoot.com ==== That's the result I get as well. There's no way to change c without changing s, with that initial value of s --- and I was restricting myself to that.It can be done easily if s = {a, b, c, d, e}, however.ss = {a, b, c, d, e}dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}ToExpression[ss[[3]] <> = <> ToString@dd[[4]]];css{a, b, c, d, e}{1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}7{a, b, c, d, e}BobbyOn Sun, 09 Mar 2003 21:41:24 +0100, Friedrich Laher Hi,> do we use different versions of mathematica? ss = {a, b, c, d, e}> dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}> ToExpression[ToString@ss[[3]] <> = <> ToString@dd[[4]]]; for me results in (ref. attachment) and> then an assignement to c with another value is no longer possible> with ToExpression[ToString@ss[[3]] <> = <> ToString@dd[[4]]];>-- majort@cox-internet.comBobby R. Treat ==== Perhaps something like this?In[1]:=Sum[If[PrimeQ[i], i^2, 0], {i, 1, 5}]Out[1]=38Tomas GarzaMexico City----- Original Message -----Reply-To: drbob@bigfoot.com ==== Easy. For instance,f[i_] = 1/i;Sum[f@Prime@i, {i, 1, 10}]% // NBobbyOn Wed, 12 Mar 2003 02:29:09 -0500 (EST), Anthony Felder Can you tell me if, when calculating a summation of f(i) where i goes > from> imin to imax, Mathematica can be forced to only use prime values for i?> Anthony Felder>-- majort@cox-internet.comBobby R. Treat ==== How about this?SumOverPrimes[expr_, {i_, iMin_, iMax_}] := Module[{primeList, j, k}, primeList = Cases[Table[j, {j, iMin, iMax}], j_?PrimeQ] ; Return[Sum[expr /. i -> primeList[[k]], {k, 1, Length[primeList]}] ]; ]dan kefford> Can you tell me if, when calculating a summation of f(i) where i goes from> imin to imax, Mathematica can be forced to only use prime values for i?> Anthony Felder ==== > Can you tell me if, when calculating a summation of f(i) where i goes from> imin to imax, Mathematica can be forced to only use prime values for i?> > Anthony FelderSum[If[PrimeQ[i],f[i],0],{i,imin,imax}]or betterSum[f[Prime[i]], {i, PrimePi[imin-1]+1, PrimePi[imax]}]-- +------------------------------------------------------------ ----------+I Dr. Olaf Rogalsky Institut f. Theo. Physik I II rogalsky@theorie1.physik.uni-erlangen.de D-91058 Erlangen I+----------------------------------------------------------- -----------+ ==== Anthony: It's not clear to me whether you wish i to be the index of theprime number, or merely an integer. If you wish the former, this shoulddo it (assuming i goes from 30 to 70, for example): Sum[Prime[i],{i,30,70}]If you wish the latter, this should do it (assuming i goes from 30 to70, for example: Plus@@Select[Range[30,70],PrimeQ]but if the range is large, e.g., from 30 to 7000, the following might befaster: Plus@@Prime[Range[PrimePi[30]+1,PrimePi[7000]]] Best, HarveyHarvey P. DaleUniversity Professor of Philanthropy and the LawDirector, National Center on Philanthropy and the LawNew York University School of LawRoom 206A110 West 3rd StreetNew York, N.Y. 10012-1074-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== AnthonyThe function Prime[n] returns the n-th prime number. You should be ableto cobble together what you want with that, I think. The Help Browsersays that Prime[n] is quite quick for n up to about 10^8.Mark Westwood> Can you tell me if, when calculating a summation of f(i) where i goes from> imin to imax, Mathematica can be forced to only use prime values for i?> Anthony Felder ==== There are two options:If you want the primes Prime[i1] through Prime[i2] then useSum[f[Prime[i]],{i,i1,i2}]The problem is that you'll need to find the appropriate i1,i2 so thatimin<=Prime[i1] Can you tell me if, when calculating a summation of f(i) where i goes from> imin to imax, Mathematica can be forced to only use prime values for i?> Anthony Felder ==== >Can you tell me if, when calculating a summation of f(i) where i goes>from imin to imax, Mathematica can be forced to only use prime values>for i?Yes, by adding the appropriate code. That is there isn't a built in directive to do what you want.I think there are two basic approaches. First would be to generate a list of primes, map f to the elements of that list then sum. For example:Tr[f/@Select[Range[imin, imax], PrimeQ]] will do the trickThis approach might be made more efficient using the NextPrime function in the package NumberTheory`NumberTheoryFunctions`The other approach would be to modify f so that it returned zero for non-prime arguments. I think this approach is likely to be slower than the first approach. ==== Bonjour,Methinks that the following expression should evaluate to zero,but it does not, even with FullSimplify : ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10Could anyone explain ? ==== Just out of curiosity I tried to see if I can force Simplify to return 0 with a suitable choice of ComplextityFunction and TransformationFunctions. Here is one way that works:h[Log[x_] + a_ Log[y_]] := Log[FullSimplify[x*y^a]]Simplify[ArcSinh[1] - Log[3363 + 2378*Sqrt[ 2]]/10,ComplexityFunction->( Count[#,ArcSinh,Infinity,Heads->True]&), TransformationFunctions->Composition[h,TrigToExp]]0Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/>> Bonjour,>> Methinks that the following expression should evaluate to zero,>> but it does not, even with FullSimplify :>> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10>> Could anyone explain ?>> Presumably, the reason is that the built in transformation rules that > FullSimplify tries are simply insufficient to reach that answer. > However:> Log[Exp[TrigToExp[ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10]]// FullSimplify] 0 We can get a different perspective on the difficulties by trying a > somewhat different approach. We first define a new transformation > function: h[Log[x_] + a_ Log[y_]] := Log[x*y^a] Of course this only makes sense for suitable values of x,y and a but > since the rule holds in our case we won't bother about this point. Now > consider the following:> v=Simplify[TrigToExp[ArcSinh[1] - Log[3363 + 2378*Sqrt[2]]/10],> TransformationFunctions -> {Automatic, h}]> Log[(1 + Sqrt[2])/(3363 + 2378*Sqrt[2])^(1/10)] The expression inside the Log is in fact 1. Mathematica can show this > but if we now simply apply FullSimplify we will get back to formula we > started with:> FullSimplify[v]> ArcSinh[1] - (1/10)*Log[3363 + 2378*Sqrt[2]]> However, if we apply FullSimplify only to the expression inside the > Log we get the right answer:> Map[FullSimplify,v] 0 I think this kind of problems are unavoidable. FullSimplify can only > perform a limited number of transformations on any given expression, > and there will always be cases when the needed transformation, or > right order of performing transformations or the correct way of > grouping an expression into subexpressions isn't tried without human > guidance. Andrzej Kozlowski> Yokohama, Japan> http://www.mimuw.edu.pl/~akoz/> http://platon.c.u-tokyo.ac.jp/andrzej/ ==== It seems to be known that no general algorithm exists for simplification ofexpressions. Therefore Simplify and FullSimplify are just boxes of tricksthat might simplify certain expressions. No matter how large the boxes are,we can always find expressions for which Simplify and FullSimplify will notwork. So the boxes are not large enough to simplify your expression. But itcan be done by Mathematica:In[27]:=x = ArcSinh[1] - Log[3363 + 2378*Sqrt[2]]/10;Log[Exp[TrigToExp[x]] // FullSimplify]Out[28]=0Fred SimonsEindhoven University of Technology> -----Original Message-----> Sent: woensdag 12 maart 2003 8:28> To: mathgroup@smc.vnet.net> Bonjour,> Methinks that the following expression should evaluate to zero,> but it does not, even with FullSimplify :> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10> Could anyone explain ?> > ==== An extension of my previous reply: FullSimplify[10 x] returns 0.Fred SimonsEindhoven University of Technology> -----Original Message-----> Sent: woensdag 12 maart 2003 8:28> To: mathgroup@smc.vnet.net> Bonjour,> Methinks that the following expression should evaluate to zero,> but it does not, even with FullSimplify :> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10> Could anyone explain ?> > ==== Hi,As you have written it, your expression is exact. Forcing a numericalapproximation of the expression withN[ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10]gives0.-- a very very small number which for all purpose and sense is zero.Rather than use integers in your expression you can use reals by writingthe decimal point. Mathematica will retrun a very very small numberdepending on the setting of the variable $MaxExtraPrecision and the verysmall number can be carried through in subsequent calculations. Somedegree of care must be taken in deciding what level of numerical precisionis needed and the actual problem at hand.Yas> Bonjour,> Methinks that the following expression should evaluate to zero,> but it does not, even withFullSimplify :> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10> Could anyone explain ? ==== jf,Mathematica doesn't simplify because there are multiple solutions.You could do this..ArcSinh[1] - Log[3363 + 2378*Sqrt[2]]/10 // N0.But if you want to work with exact numbers do the following...ArcSinh[1] - Log[3363 + 2378*Sqrt[2]]/10TrigToExp[%]% /. Log[a_] + b_*Log[c_] -> Log[a*c^b]givingArcSinh[1] - (1/10)*Log[3363 + 2378*Sqrt[2]]Log[1 + Sqrt[2]] - (1/10)*Log[3363 + 2378*Sqrt[2]]Log[(1 + Sqrt[2])/(3363 + 2378*Sqrt[2])^(1/10)]Then it is clear that we have to find the 10th root of the denominator. Itturns out there are two real roots and only one positive real root. We canselect that and substitute with the following statement...sols = First[Select[Solve[z^10 == 3363 + 2378*Sqrt[2]], With[{x = #1[[1,2]]}, Im[x] == 0 && Re[x] > 0] & ]]Log[(1 + Sqrt[2])/z] /. sols{z -> 1 + Sqrt[2]}0David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== Sounds like mighty magic, but just insert a decimal point after any of theintegers you have in your expression:In[1]:=ArcSinh[1.] - Log[3363 + 2378*Sqrt[2]]/10Out[1]=0.Tomas GarzaMexico City----- Original Message ----- ==== Here's a proof that the answer is zero:{ArcSinh[1], Log[3363 + 2378*Sqrt[2]]/10}% // TrigToExpExp /@ %% // Simplify#^10 & /@ %% // ExpandHowever, Simplify and FullSimplify can't be expected to know this.BobbyOn Wed, 12 Mar 2003 02:28:18 -0500 (EST), jf alcover Bonjour,> Methinks that the following expression should evaluate to zero,> but it does not, even with FullSimplify :> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10> Could anyone explain ?-- majort@cox-internet.comBobby R. Treat ==== >-----Original Message----->Sent: Wednesday, March 12, 2003 8:28 AM>To: mathgroup@smc.vnet.net>Bonjour,>Methinks that the following expression should evaluate to zero,>but it does not, even with FullSimplify :> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10>Could anyone explain ?>If that helps:In[5]:= TrigToExp[ArcSinh[1]] == 1/10 Log[(1 + Sqrt[2])^10]Out[5]= TrueIn[6]:= (1 + Sqrt[2])^10 // ExpandOut[6]= 3363 + 2378*Sqrt[2]Such, what you think, is confirmed.--Hartmut Wolf ==== Actually, ArcSinh[1] is equal to Log[1+Sqrt[2]]Orestis > Bonjour,> Methinks that the following expression should evaluate to zero,> but it does not, even with FullSimplify :> ArcSinh[1]-Log[3363+2378*Sqrt[2]]/10> Could anyone explain ? ==== Are there any Mathematica Packages for Time Series Analysis?Reply-To: kuska@informatik.uni-leipzig.de ==== Hi,for what is the first argument in u[x,t] ??You have only derivatives with respect to tand it is an ordinary differential equation foru[t]. But you gave not an intial conditionu[x,0]==0 *and* Derivative[0,1][u][x,0]==blubBlubyou gave D[u[L, 0], t] == 0 and this evaluates to True, and Mathematica miss a second initial condition. Jens> Hi everyone> I keeping getting the following error:> NDSolve::deql: The first argument must have both an equation and an > initial condition.> > when i try to solve the following second order partial differential> equation> (wherein the function u is a function of variables x and t):> NDSolve[{m*D[u[x, t], t, t] + 6*Pi*n*r*D[u[x, t], t] -> 0.5*mu*i*ndash*pm*((L - u[x, t])^2/(R^2 + (L - u[x, t])^2)^1.5> -> 1/(R^2 + (L - u[x, t])^2)^0.5 - (L + u[x, t])^2/(R^2 + (L +> u[x, t])^2)^1.5 +> 1/(R^2 + (L + u[x, t])^2)^0.5) == 0,> u[L, 0] == L,> D[u[L, 0], t] == 0},> u, {x, 0, L}, {t, 0, 1}]> I have specified 2 initial conditions already, so i can't understand why> i get the error.> does anyone know whats the problem?> Karlo> PS I'm relatively new at mathematica. ==== Good day everyone,I have problem trying to implement an iterative function that attempts temperature (air temperature is function of time, e.g. Tair[t_]=600+t*5).The function is the following (hc is the heat transfer coeficient):Fignition[t_, hc_] := Block[{ Tfuel = Tini, Tini = 300, Fcp = 2100, Fd = 0.005, Fl = 0.1, ?f = 520, FMC = 0.7, Wcp = 2417, Whv = 2257000}, {While[Tfuel < 373, Print[Tfuel]; Save[test01.dat, Tfuel];{S = ?f*Fv[ Fd, Fl]*(Fcp + (Wcp*FMC)); Q = hc*Fa[Fd, Fl]*(Tair[t] - Tfuel); Xtp = Tfuel + (Q/S); Tfuel = Xtp}]} {While[Tfuel > 373, Print[Tfuel]; Save[test01.dat, Tfuel]; { S = ?f*Fv[Fd, Fl]*(Fcp); Q = hc*Fa[Fd, Fl]*(Tair[t] - Tfuel); Xtp = Tfuel + (Q/S); Tfuel = Xtp}; If[Tfuel > 600, Break[]] ] } ]My problem is that I want the Fignition[t_, hc_] function to be computed for each time step by reading the Tair at that time step. the time step should be the iterator. Currently the function does its thing but uses a fixed Tair.Miguel********************************************Miguel Cruz460 The Bullpen Science ComplexSchool of ForestryUniversity of MontanaMissoula, MT 59812******************************************** ==== In the following function, most of which you can ignore,there is an If [ enalist ... etc. where several statements to beexecuted if the If succeeds are grouped with ( ) . This works but Ithought the right way to group several statements together was with{ }. The latter does not work and I find I don't know what the correctway is. As usual, Mathematica did not complain with the { } or the ( ). Theeffect was to have the If always fail and for the function to alwaysReturn [ failu ]. Whether the comments get in the way, I don't know, but if someonewould define what's legal here, I would appreciate it.ranqrs := Module[{res2}, ptab = Table[0, {i, NN}]; If[changeq == 1, qtab = Table[Random[Integer, {1, NN - 1}], {i, NN- 1}]]; If[changer == 1, rtab = Table[Random[Integer, {0, NN - 1}], {i, NN - 1}]]; If[changes == 1, stab = Mod[Table[1, {i, NN - 1}] - rtab, NN]]; matall; (* Make matrices from model. *) matmul; (* Compute matrix product. *) result = newres; If [ enalist[[result]] == 1, (* If a good value = > try again; *) ( newmmt; (* make a new model &target, *) res2 = newres; (* do another test.*) If [res2 == result, Return[result]]; (* If agree, return good result. *) )]; Return[failu]; (*If no agree or nointerest, 0. *) ] ==== >-----Original Message----->Sent: Wednesday, March 12, 2003 8:32 AM>To: mathgroup@smc.vnet.net> In the following function, most of which you can ignore,>there is an If [ enalist ... etc. where several statements to be>executed if the If succeeds are grouped with ( ) . >This works but I thought the right way to group several statements > together was with { }. *** This is not the case, and this example exactly shows why!! ***>The latter does not work and I find I don't know what the correct>way is. As usual, Mathematica did not complain with the { } or the ( ). The>effect was to have the If always fail and for the function to always>Return [ failu ]. Whether the comments get in the way, I don't know, but if someone>would define what's legal here, I would appreciate it.ranqrs := Module[{res2}, > ptab = Table[0, {i, NN}];> If[changeq == 1, qtab = Table[Random[Integer, {1, NN - 1}], {i, NN>- 1}]];> If[changer == 1, > rtab = Table[Random[Integer, {0, NN - 1}], {i, NN - 1}]]; > If[changes == 1, stab = Mod[Table[1, {i, NN - 1}] - rtab, NN]];> matall; (* > Make matrices from model. *)> matmul; (* > Compute matrix product. *)> result = newres;> If [ enalist[[result]] == 1, (* > If a good value = > try again; *)> ( newmmt; (* make a new model &>target, *)> res2 = newres; (* do another test.>*)> If [res2 == result, Return[result]]; (* If agree, > return good result. *)> )];> Return[failu]; (*If no agree or no>interest, > 0. *)> ]>Steve, well, the explanation is given from a careful inspection of the programminglanguage semantics.First, make up a descrambled, reasonable simple model of your computation: In[67]:=runcode1 := Module[{res}, If[True, (res = 1; If[res == 1, Return[Yes]])]]In[68]:= runcode1Out[68]= YesThis works, as expected.In[69]:=runcode2 := Module[{res}, If[True, {res = 1, If[res == 1, Return[Yes]]}]]In[70]:= runcode2Out[70]= {1, Return[Yes]}What happend? Just the List has been returned, Return[Yes] has not beenexecuted, but obviously the assignment to res worked, as well as the innerIf. Consult Help!Return[expr] exits control structures within the definition of a function,and gives the value expr for the whole function.Obviously List isn't a control structure, such runcode2 didn't executeReturn[Yes], but silently kept it within List; whereas in runcode1,Return[Yes] after having become the value of the inner If, shows up inCompoundExpression, which *is* a control structure, that is left now, showsup in Module, which again is a control structure, which is left again,delivering Yes as result (of the function).Observe again this case: In[71]:= runcode3 := Module[{res}, Do[#, {1}] & /@ If[True, {res = 1, If[res == 1, Return[Yes]]}]]In[72]:= runcode3Out[72]= {Null, Yes}When Mapping Do, Return[Yes] gets into the body of a control structure(Do), such Return is executed, but further confined in List, which is nocontrol structure and such intercepts nowthe _value_ of Return[Yes], namely Yes. This is in contrast to Line 70,where Return[Yes] isn't executed. But, hold, you can make that good:In[107]:= c := Last[%70]In[108]:= cOut[108]= YesAnother demonstration:In[73]:= runcode4 := Module[{res}, Scan[Identity, If[True, {res = 1, If[res == 1, Return[Yes]]}]]]In[74]:= runcode4Out[74]= YesHere Return[Yes] shows up in the execution machinery of Scan which --contrary to Map -- isn't confined within a (resulting) List; such Scan isleft, we arrive at Module, a control structure, left and finally Yesdelivered as value of the function (runcode4).If you want to return from an arbitrary expression, however, you may useCatch and Throw:In[115]:=runcode7 := Module[{res}, If[True, {res = 1, If[res == 1, Throw[Yes]]}]]In[116]:= Catch[runcode7]Out[116]= Yes--Hartmut WolfReply-To: drbob@bigfoot.com ==== You're breaking all the rules of functional programming, but never mind that for now.Look up the syntax of the If statement, and you'll see that it has 2, 3, or 4 arguments. Each argument (of ANY function) is an expression. Enclosing an expression in parentheses has no effect whatsoever, except that sometimes the parentheses are necessary for grouping, as ina[x_] := (expr1; expr2; expr3)a[2]expr3versusb[x_] := expr1; expr2; expr3b[2]expr3expr1or an expression like(1 - x)^2Note that expr1; expr2; expr3 is a CompoundExpression (look it up). This is how expressions are grouped together. Evaluating {expr1; expr2; expr3} results in the list {expr3}, while evaluating (expr1; expr2; expr3) results in the value of expr3.If your code returns failu, it is because either enalist[[result]] isn't 1 or res2 isn't equal to result. Only when both are true does Return[result] get evaluated.Also, Return is rarely needed, and tends to lead to spaghetti code. Your code is equivalent to the following code:ranqrs := Module[{res2}, ptab = Table[0, {i, NN}]; If[changeq == 1, qtab = Table[Random[Integer, {1, NN - 1}], {i, NN - 1}]]; If[changer == 1, rtab = Table[Random[Integer, {0, NN - 1}], {i, NN - 1}]]; If[changes == 1, stab = Mod[Table[1, {i, NN - 1}] - rtab, NN]]; matall; matmul; result = newres; If[enalist[[result]] == 1, newmmt; res2 = newres; If[res2 == result, result, failu], failu]]BobbyOn Wed, 12 Mar 2003 02:31:36 -0500 (EST), Steve Gray In the following function, most of which you can ignore,> there is an If [ enalist ... etc. where several statements to be> executed if the If succeeds are grouped with ( ) . This works but I> thought the right way to group several statements together was with> { }. The latter does not work and I find I don't know what the correct> way is. As usual, Mathematica did not complain with the { } or the ( ). > The> effect was to have the If always fail and for the function to always> Return [ failu ]. Whether the comments get in the way, I don't know, but if someone> would define what's legal here, I would appreciate it. ranqrs := Module[{res2}, ptab = Table[0, {i, NN}];> If[changeq == 1, qtab = Table[Random[Integer, {1, NN - 1}], {i, NN> - 1}]];> If[changer == 1, rtab = Table[Random[Integer, {0, NN - 1}], {i, NN - > 1}]]; If[changes == 1, stab = Mod[Table[1, {i, NN - 1}] - rtab, NN]];> matall; (* Make matrices from model. > *)> matmul; (* Compute matrix product. > *)> result = newres;> If [ enalist[[result]] == 1, (* If a good value = > try > again; *)> ( newmmt; (* make a new model &> target, *)> res2 = newres; (* do another test.> *)> If [res2 == result, Return[result]]; (* If agree, return good result. *)> )];> Return[failu]; (*If no agree or no> interest, 0. *)> ]-- majort@cox-internet.comBobby R. Treat ==== On Wed, 12 Mar 2003 07:43:09 +0000 (UTC), Steve Gray> In the following function, most of which you can ignore,>there is an If [ enalist ... etc. where several statements to be>executed if the If succeeds are grouped with ( ) . This works but I>thought the right way to group several statements together was with>{ }. The latter does not work and I find I don't know what the correct>way is. As usual, Mathematica did not complain with the { } or the ( ). The>effect was to have the If always fail and for the function to always>Return [ failu ]. Whether the comments get in the way, I don't know, but if someone>would define what's legal here, I would appreciate it.[snip code] The work I'm doing with Mathematica involves searches over a hugeparameter domain for a certain class of geometry theorem. It is acontinuation of work appearing in the March 2003 American MathematicalSteve Gray ==== >In the following function, most of which you can ignore, there is an>If [ enalist ... etc. where several statements to be executed if the>If succeeds are grouped with ( ) . This works but I thought the right>way to group several statements together was with { }.No, {} is always used to create a list. So,If[test, {expr1, expr2, expr3 ...}]will return a list containing the values of the expressions when test is trueThe simplest way to have a block of expressions execute if true is as follows:If[test, expr1; expr2; expr3; , (* block executed if test = true *) fexpr1; fexpr2; expr3 (* block executed if test = false *) ] That is the separator between statements in a block to be executed is a semicolon. The separator between the true and false block is a comma. If you are used to C progamming this swaps the roles of the semicolon and comma.