A43 == I am having trouble figuring out how to change the color and thickness ofErrorBars. Can anyone help me with this problem? ALso, how do you changethe font and font size of an AxesLabel?KenfReply-To: kuska@informatik.uni-leipzig.de ==== Hi,Mathematica 4.2 sayIn[]:=Sum[Binomial[2 j, j + 1] p^j, {j, 1, n}] // FullSimplify //InputFormOut[]= -(-1 + Sqrt[1 - 4*p] + 2*p)/(2*Sqrt[1 - 4*p]*p) - (p^(1 + n)*Gamma[3 + 2*n]* ((1 + n)*(3 + n)*Hypergeometric2F1[1, 3/2 + n, 3 + n, 4*p] + 2*(3 + 2*n)*p*Hypergeometric2F1[2, 5/2 + n, 4 + n, 4*p]))/(Gamma[2 + n]*Gamma[4 + n]) Jens ==== I am not sure what is your problem (which characters do you type?), butcheck if the NumLock key is ON. It should be OFF when you type in theFrontEnd, and upgrading your system has maybe changed the deafult settingsfor the NumLock key upon starting X Window System. Marko----- Original Message ----- ==== hido you have the NUM LOCK key activated? turn it off, otherwise the wonderful and soo stable :-)))) mathematica frontend for linux will not work properly...you can easily verify if it is this problem that bugs you if the ENTER key of the numpad does not work properly.gerald-- *************************************Gerald RothM@th Desktop Development************************************* ==== You can use the OPLinearAlgebra package(http://library.wolfram.com/database/MathSource/4271/) to solve this type ofnoncommutative algebra problem. Here is what the solution looks like (The[Diamond] is a non-commutative multiply.):<< OPLinearAlgebra`SetOperators[Y, C, M, v]{C, M, v, Y}OPSolve[{Y == C + M + v [Diamond] Y}, {Y}]Calling OPLinearEqnToMatrices ... CollectPower is On.Calling OPLinearSolve to give the result ... --Steve LuttrellWest Malvern, UK ==== You may (or may not) be aware that for a little over a year we've been writing a Mathematica ezine for WZ.com.With WZ.com no longer active, we've decided to continue the ezine on our own. It will remain a free ezine, but in a slightly different format. We hope to keep the quick-and-easy feel of the past, combined with some in-depth material. And you'll no longer see any ads for any of the items WZ.com was selling. Plus, it is an opportunity to take a more active role. You can find previous issues at http://omegaconsultinggroup.com/Services/wz.html. To subscribe to the line Subscribe me to the ezine.Concerned about your privacy? Aren't we all! Take a look at our privacy policy at http://omegaconsultinggroup.com/Services/privacy.html. In a address for anything other than sending you the ezine.------------------------------------------------------- -------Omega ConsultingThe final answer to your Mathematica needshttp://omegaconsultinggroup.com ==== Mihajlo Vanevic was kind enough to point out where my system was kaput.He pointed to Cell/DefaultOutputFormatType which was set on to InputForm.I changed it to StandardForm and now my system is (temporarily at least)at peace. No telling how many years ago I screwed that up and only nowI noticed it.Many thanks to you all for helping.Rob ==== In particular, Ted Ersek said something that interested me. However, I tried to put it in my init.m file and it didn't work. Could someone please elaborate on the location of this file and suggestions on the best line of code to do the job.Jonathan Mannmtheory@msn.com ==== Reinhard,I presume that you are _not_ asking whether you can pass a CompiledFunction to Java and then execute it entirely within the Java runtime. That is not possible--to call the CompiledFunction with some arguments you must call back to Mathematica.To pass a CompiledFunction to Java, use J/Link's Expr class, which can store any Mathematica expression. If you have a method that takes an Expr argument, then you can pass anything for that argument slot from Mathematica. Say you have a Java method like this: private Expr storedExpr; public void storeThisExpr(Expr e) { storedExpr = e; }You can call this from Mathematica like this:In[100]:= cf = Compile[....];In[101]:= obj@storeThisExpr[cf]If you are manually reading the CompiledFunction from a link, use the getExpr() method: Expr e = ml.getExpr();No matter which way you get the CompiledFunction into Java as an Expr, to call back to Mathematica to execute it you have to use a relatively obscure sequence of MathLink calls. You cannot use putFunction() because the head is not a symbol--it's the expression CompiledFunction[...]. You must manually build the expression from a head and arguments. Here is the code: // Assume e is an Expr containing a CompiledFunction that // you want to call with the argument 42. ml.putNext(MathLink.MLTKFUNC); ml.putArgCount(1); // Next we put the head ml.put(e); // Then the arguments ml.put(42); ml.waitForAnswer(); // Now read the answer ...Having said all this, do you really need to pass the CompiledFunction itself to Java? Why not just send its name to Java (i.e., assign the function to a symbol and then pass the symbol name to Java)? Let the CompiledFunction live only in Mathematica and just refer to it by name from your Java code.Todd GayleyWolfram ResearchReply-To: kuska@informatik.uni-leipzig.de ==== Hi,it would be possible if there would be a reference of the byte codeavailable. The old references on MathSource are complete out of dateBut I'm sure that a reference exist.Is there a way to make a actual reference of the CompiledFunction[]codes available ?If it is possible, one should bundle the calls to Mathematica, i.e.,if one needs several evaluations it should be one call that return thelist of the results. JensReply-To: jmt@dxdydz.net ==== A short comment :Tomcat web applications MUST follow the web-app document type definition, as specified by Sun :http://java.sun.com/dtd/web-app_2_3.dtdIn such a DTD, order of elements is mandatory. ==== I ran into this problem on Solaris. In looking at the Tomcat log it was not correctly initializing the webMathematica application. It was instantiate the application.The file I am referring to is in the Tomcat directory (or in the .war file). After starting Tomcat it is unzipped into $TOMCAT/webapps/webMathematica/WEB-INF/web.xml.My file now looks like:Sent: Friday, December 13, 2002 10:09 AM>To: mathgroup@smc.vnet.net>>consider the following:>>In[1]:= test[1, 1] = a;> test[1, 3] = b;>>In[2]:= ?test>Global`test>>test[1, 1] = a>test[1, 3] = b>>In[3]:= from := 1;> to := 3;> test[ 1, #1 ] & /@ Range[ from, to ]>>Out[5]= {a, test[1, 2], b}>>Of course the test[ 1, 2 ] is not evaluated; it does not >exist. If I want>to delete the existing ones I could use:>>In[9]:= deletableValue := 1;> ( HoldForm[ test[ deletableValue, #1 ] =. & ] /@ > Range[ from, to ] ) // ReleaseHold>>Unset::norep: Assignment on test for test[1, 2] not found.>>Out[10]= {Null, $Failed, Null}>>Which makes sense. >>In[14]:= ?test >Global`test>>No test in the global context. My question now: is there a mechanism>e.g. something like test[ 1, All ] that does only access the existing>test?>>I am aware of the possibility to use a conditional (If, Case, ..) and>DownValues to avoid the error message, but is there a more direct>(faster?) way?>Oliver>Oliver Ruebenkoenig, Oliver,look at:In[84]:= Clear[test]In[85]:= test[1, 1] = 11; test[1, 3] = 13; test[2, 0] = 20; test[a] := test[1, 4] + 14 test[_] := Print[what test?]In[90]:= DownValues[test]Out[90]= {HoldPattern[test[a]] :> test[1, 4] + 14, HoldPattern[test[1, 1]] :> 11, HoldPattern[test[1, 3]] :> 13, HoldPattern[test[2, 0]] :> 20, HoldPattern[test[_]] :> Print[what test?]}Selectively extract definitions (rules)In[91]:= Cases[DownValues[test], def : (Verbatim[HoldPattern][test[1, _]] :> _) :> def, {1}]Out[91]= {HoldPattern[test[1, 1]] :> 11, HoldPattern[test[1, 3]] :> 13}Try to selectively extract patterns defined...In[92]:= Cases[DownValues[test], def : HoldPattern[test[1, _]] :> HoldPattern[def], {3}]Out[92]= {HoldPattern[test[1, 4]], HoldPattern[test[1, 1]], HoldPattern[test[1, 3]]}...as you see, this is not good enough to clear selected definitions:In[93]:= Cases[DownValues[test], def : HoldPattern[test[1, _]] :> Unset[def], {3}]Unset::norep: Assignment on !(test) for !(test[((1, 4))]) not found.Out[93]= {$Failed, Null, Null}In[94]:= DownValues[test]Out[94]={HoldPattern[test[a]] :> test[1, 4] + 14, HoldPattern[test[2, 0]] :> 20, HoldPattern[test[_]] :> Print[what test?]}But match full definitions to only clear those definitions with matches appearing at lhs:In[95]:= Clear[test]In[96]:= test[1, 1] = 11;test[1, 3] = 13;test[2, 0] = 20;test[a] := test[1, 4] + 14test[_] := Print[what test?]In[101]:= DownValues[test]Out[101]= ....In[102]:= Cases[DownValues[test], (Verbatim[HoldPattern][def : test[1, _]] :> _) :> Unset[def], {1}];In[103]:= DownValues[test]Out[103]={HoldPattern[test[a]] :> test[1, 4] + 14, HoldPattern[test[2, 0]] :> 20, HoldPattern[test[_]] :> Print[what test?]}What, do you think, should or could be made faster?--Hartmut Wolf ==== I'm not an expert... But here a easy way fo obtain 50 significant numbers :In[1]:=Sqrt[1.3`50]Out[1]= 1.14017542509913797913604902556675447907600531091641In[2]:=% %//FullFormOut[2]//FullForm= 1.299999999999999999999999999999999999999999999999999999999999 9694004`50Meilleures salutationsFlorian Jaccard-----Message d'origine-----Envoy.8e : ven., 13. d.8ecembre 2002 10:19è : mathgroup@smc.vnet.netObjet : Question about precision.Dear experts,I try to find the square root of 1.3, but obtain an not so correctanswer. Could someone point me how to do? My trials are thefollowings.In[28]:=Sqrt[1.3]Out[28]=1.14018In[29]:= Precision[Sqrt[1.3]]Out[29]=16In[30]:=N[Sqrt[1.3], 50]Out[30]=1.14018In[31]:=1.14018*1.14018Out[31]=1.30001The more precise answer should beIn[32]:=1.140175425*1.140175425Out[32]=1.3Wen-Feng Hsiao ==== Martin,You can label contour plots, and in fact any plot lines that have a constantfunction on them, using the DrawLineLabels routine in the DrawGraphicspackage at my web site below. There are examples shown in the DrawGraphicsHelp. Here is your example.Needs[DrawGraphics`DrawingMaster`]Draw2D[ {g = ContourDraw[x, {x, -2.5, 2.5}, {y, -2.5, 2.5}, Contours -> Range[-3, 3, 1]], g // DrawLineLabels[#1 &, 0.6 &, DrawLLFormat -> (Round), DrawLLTextOptions -> {Background -> White}]}, Frame -> True, AspectRatio -> Automatic];I will send you a gif image of the resulting plot separately so you can seethat it works.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ c1 = ContourPlot[x, {x, -2.5, 2.5}, {y, -2.5, 2.5}, Contours -> Range[-3, 3, 1], PlotRange -> All];This generates a contour plot with vertical linesat x = {-2, -1, 0, 1, 2}, i.e., five lines.Put labels on the contours:This puts labels {-3, -2, -1, 0, 1} on the vertical linesdescribed above, i.e., the labels start with the lowest valuedefined in the option statement Contours -> Range[-3, 3, 1]Obviously, this is not what I wanted. It seems thatfor the label of the contour line with the lowest value,and so on for increasing values, regardless of the rangeof values actually shown in the plot.My desired behavior would be to label each line accordingto its value. This quick fix (?) appears to produce whatI want (edit in LabelContour.m):(* FindContours[ x_List, {z1_, z2_}] := x Original version *) FindContours[ x_List, {z1_, z2_}] := Table[If[z1 <= x[[m]] <= z2, x[[m]] , {}],{m,Length[x]}]//FlattenIt simply uses the full z-range of the contour plotto remove those contour values (as specified in Contours -> ...)that fall outside the range.Any comments on this? Is there a way to get the original codeto put proper labels on corresponding contour lines?Is there a better (more efficient) way of fixing the problem?TIA,Martin ==== Web-Feng,For machine precision numbers, the default, Mathematica normally onlydisplays 6 places of precision even though it calculates to full machineprecision - 16 places. To show more places use NumberForm.Sqrt[1.3]NumberForm[%, 16]1.140181.140175425099138You can use the Option Inspector to change the number of places normallydisplayed. (Also N is only used to convert exact numbers to approximatenumbers and affects the display ONLY if you specify more than machineprecision. So NumberForm, and not N, is the correct function to control thedisplay.)David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ Precision[Sqrt[1.3]]Out[29]=16In[30]:=N[Sqrt[1.3], 50]Out[30]=1.14018In[31]:=1.14018*1.14018Out[31]=1.30001The more precise answer should beIn[32]:=1.140175425*1.140175425Out[32]=1.3Wen-Feng Hsiao ==== ... is that true?I am trying to export a cell with some greek letters in it as an epsfile from Mathematica to LyX and I end up with messed up symbols forthe greek letters.I don't want to use bitmap, is there any way for eps with mathematica?W.Reply-To: kuska@informatik.uni-leipzig.de ==== Mathematica produce correct eps files, but *you* have notproper configured you ghostscript and your dvips to findand use the Mathematica PostScript fonts. Jens> ... is that true?> I am trying to export a cell with some greek letters in it as an eps> file from Mathematica to LyX and I end up with messed up symbols for> the greek letters.> I don't want to use bitmap, is there any way for eps with mathematica?> W. ==== I've posted the same question a month ago [1], and was answered by somepeople, namely Jens Peer-Kuska, who provided a solution.However, I couldn't get it work, so I wish we could try again, and solvethis tediousness.Borut[1]http://forums.wolfram.com/mathgroup/ archive/2002/Nov/msg00514.html| ... is that true?| I am trying to export a cell with some greek letters in it as an eps| file from Mathematica to LyX and I end up with messed up symbols for| the greek letters.| I don't want to use bitmap, is there any way for eps with mathematica?|| W.|Reply-To: kuska@informatik.uni-leipzig.de ==== I have never used LyX (emacs by brith) and you should consult the LyX manual to configure it properly.I think LyX call ghostscript to render theeps file to a bitmap ian you should set theGS_LIB shell variable properly. First you should try to preview the eps-filewith ghostscript from the command line and look for the error messages, if this worksyou should look if you can configure theghostscript command inside LyX or if yoursetup of the environment variables isoverwritten by LyX. Jens> I've posted the same question a month ago [1], and was answered by some> people, namely Jens Peer-Kuska, who provided a solution.> However, I couldn't get it work, so I wish we could try again, and solve> this tediousness.> Borut> [1]> http://forums.wolfram.com/mathgroup/archive/2002/Nov/msg00514 .html> | ... is that true?> | I am trying to export a cell with some greek letters in it as an eps> | file from Mathematica to LyX and I end up with messed up symbols for> | the greek letters.> | I don't want to use bitmap, is there any way for eps with mathematica?> |> | W.> | ==== I have the following problem with Mathematica 4,now the mathkernel works without problems, and I can also plotting graphs,but when I launch the GUI it crashes every time I try to start the kernel,and i get the error messageMathematica has received the signal: SIGSEGV and has exited.If possible, please report this problem to support@wolfram.comdescribing in in as much detail as possible what you were doingwhen the problem occurred.Segmentation faultthe only solution I've found on the Wolfram web-site is to contact the support,can someone help me ??thanksToio************************************ ** Vittorio Morandi ** ** E-Mail: morandi@lamel.bo.cnr.it ** ************************************ ==== I am wondering whether it is possible to seta Legend Option to adjust the separation betweenboth the legend left border of the enclosing box and the legend SymbolShape and between the legend SymbolShape and the actual legend text.I am trying to write a legend to a MultipleListPlot, butthe above separations are too large that the legend textdoes not fit inside the sorrounding box.Sergio ==== In a previous message Re: Ellipse and circle intersection, I hinted that Solve would not always give the right answer when trying to obtain the intersections of an ellipse and a circle. Two comments were received (Tom Burton and Rasmus Debitsch) suggesting that there was nothing wrong. Still, definitely there is, as shown in the example below. The situation is as follows:In[1]:=ellipse = (x - c)^2/b^2 + (y - d)^2/a^2 == 1;circ = x^2 + y^2 == 1;sol = Solve[{ellipse, circ}, {x, y}];The solution comes out all right in terms of the four parameters a, b, c, d. The following sets of values for the parametrs are tested:In[2]:=example1Tom = {a -> 1.2, b -> 1.3, c -> 0.2, d -> 0.3};example2Tom = {a -> 1.2, b -> 1.3, c -> 1.2, d -> 1.3};example3Rasmus = {a -> 2, b -> 1, c -> 1, d -> 1};example4Tomas = {a -> 0.25, b -> 0.75, c -> 0.5, d -> 0};(the first two come from Tom Burton, the third one from Rasmus, and the fourth one is mine). Numerical solutions are then obtained for each set:In[3]:=sol1=sol/.example1Tom;In[4]:=sol2=sol/.example2Tom ;In[5]:=sol3=sol/.example3Rasmus//N;In[6]:=sol4=sol/. example4Tomas;In each of the first three cases the correct intersections (as observed graphically through ImplicitPlot) are found, in addition to some complex points. However, the fourth case fails to give a correct answer, even if the two curves intersect very nicely at four different points in the plane. This points to a weird behavior of Solve. I hope someone will come forward with some explanation.Tomas GarzaMexico City ==== > In a previous message Re: Ellipse and circle intersection, I> hinted that Solve would not always give the right answer when trying to> obtain the intersections of an ellipse and a circle. Two comments were> received (Tom Burton and Rasmus Debitsch) suggesting that there was> nothing wrong. Still, definitely there is, as shown in the example> below. The situation is as follows:> In[1]:=> ellipse = (x - c)^2/b^2 + (y - d)^2/a^2 == 1;> circ = x^2 + y^2 == 1;> sol = Solve[{ellipse, circ}, {x, y}];> The solution comes out all right in terms of the four parameters a, b,> c, d. The following sets of values for the parametrs are tested:> In[2]:=> example1Tom = {a -> 1.2, b -> 1.3, c -> 0.2, d -> 0.3};> example2Tom = {a -> 1.2, b -> 1.3, c -> 1.2, d -> 1.3};> example3Rasmus = {a -> 2, b -> 1, c -> 1, d -> 1};> example4Tomas = {a -> 0.25, b -> 0.75, c -> 0.5, d -> 0};> (the first two come from Tom Burton, the third one from Rasmus, and the> fourth one is mine). Numerical solutions are then obtained for each set:> In[3]:=> sol1=sol/.example1Tom;> In[4]:=> sol2=sol/.example2Tom;> In[5]:=> sol3=sol/.example3Rasmus//N;> In[6]:=> sol4=sol/.example4Tomas;> In each of the first three cases the correct intersections (as observed> graphically through ImplicitPlot) are found, in addition to some complex> points. However, the fourth case fails to give a correct answer, even if> the two curves intersect very nicely at four different points in the> plane. This points to a weird behavior of Solve. I hope someone will> come forward with some explanation.> Tomas Garza> Mexico CityThe reason is that the generic radical solution does not work for thoseparticular values of parameters. We can see why as follows. First wecreate polynomials and find a quartic in one variable.eqns = {ellipse,circ};polys = Map[#[[1]]-#[[2]]&, eqns];InputForm[uniploy = First[GroebnerBasis[polys, {x,y}, CoefficientDomain->RationalFunctions]]]Out[67]//InputForm= 1 + b^(-4) - 2/b^2 - (2*c^2)/b^4 - (2*c^2)/b^2 + c^4/b^4 - (2*d^2)/a^2 + (2*d^2)/(a^2*b^2) + (2*c^2*d^2)/(a^2*b^2) + d^4/a^4 + ((4*d)/a^2 - (4*d)/(a^2*b^2) - (4*c^2*d)/(a^2*b^2) - (4*d^3)/a^4)*y + (-2/a^2 - 2/b^4 + 2/b^2 + 2/(a^2*b^2) + (2*c^2)/b^4 + (2*c^2)/(a^2*b^2)+ (6*d^2)/a^4 - (2*d^2)/(a^2*b^2))*y^2 + ((-4*d)/a^4 +(4*d)/(a^2*b^2))* y^3 + (a^(-4) + b^(-4) - 2/(a^2*b^2))*y^4We have a quartic univariate in y (in terms of the problem parameters).Now we plug in your values:InputForm[unipoly /. {a->1/4, b->3/4, c->1/2, d->0}]Out[69]//InputForm= (81*(-5/3 + (1024*y^2)/27 + (16384*y^4)/81))/16384Notice that it is biquadratic (that is, quadratic in y^2). But this isexactly the case for which the Cardano formulation of the quarticradical solution does not work.To obtain a solution that does not have this limitation one must avoid aradical formulation. This can be done as below. The solution (not shown)is in terms of parametrized Root[] functions.SetOptions[Roots, Quartics->False];soln = Solve[{ellipse,circ}, {x,y}];In[73]:= InputForm[soln /. N[{a->1/4, b->3/4, c->1/2, d->0}]]Out[73]//InputForm= {{x -> 0.981455818030629, y -> -0.19168849014437103}, {x -> 0.981455818030629, y -> 0.19168849014437103}, {x -> -1.106455818030629 - 8.619810689307775*^-27*I, y -> 1.1376714700528284*^-27 - 0.473544588453747*I}, {x -> -1.106455818030629 + 8.619810689307775*^-27*I, y -> 1.1376714700528284*^-27 + 0.473544588453747*I}}If you are curious as to why the Cardano method fails when the quarticreduces to a biquadratic, I can send a derivation of that formula.Actually I should have put it inhttp://library.wolfram.com/conferences/conference98/ abstracts/various_ways_to_tackle_algebraic_equations.htmlIn the notebook accessible from that link I show how one might derivethe cubic radical solution. My updated version of the notebook alsocovers the quartic derivation so I will try to get that version put atthe web site. The essence of the nongeneric problem is that one isconfronted with a hidden division by zero.Daniel LichtblauWolfram Research ==== > In a previous message Re: Ellipse and circle intersection, I> hinted that Solve would not always give the right answer when trying to> obtain the intersections of an ellipse and a circle. Two comments were> received (Tom Burton and Rasmus Debitsch) suggesting that there was> nothing wrong. Still, definitely there is, as shown in the example> below. The situation is as follows:>> In[1]:=> ellipse = (x - c)^2/b^2 + (y - d)^2/a^2 == 1;> circ = x^2 + y^2 == 1;> sol = Solve[{ellipse, circ}, {x, y}];>> The solution comes out all right in terms of the four parameters a, b,> c, d. The following sets of values for the parametrs are tested:>> In[2]:=> example1Tom = {a -> 1.2, b -> 1.3, c -> 0.2, d -> 0.3};> example2Tom = {a -> 1.2, b -> 1.3, c -> 1.2, d -> 1.3};> example3Rasmus = {a -> 2, b -> 1, c -> 1, d -> 1};> example4Tomas = {a -> 0.25, b -> 0.75, c -> 0.5, d -> 0};>> (the first two come from Tom Burton, the third one from Rasmus, and the> fourth one is mine). Numerical solutions are then obtained for each set:>> In[3]:=> sol1=sol/.example1Tom;> In[4]:=> sol2=sol/.example2Tom;> In[5]:=> sol3=sol/.example3Rasmus//N;> In[6]:=> sol4=sol/.example4Tomas;>> In each of the first three cases the correct intersections (as observed> graphically through ImplicitPlot) are found, in addition to some complex> points. However, the fourth case fails to give a correct answer,You are correct.> This points to a weird behavior of Solve. I hope someone will> come forward with some explanation.I do too! I find this behavior to be very disturbing. (Am I overlookingsome obvious reason for such behavior?)It might be noted, for some _slight_ comfort, that at least if we firstset a = 0.25, b = 0.75, c = 0.5, d = 0, then Solve[{ellipse, circ}, {x, y}]will give us, correctly it seems,{{y -> -0.19168849014437106, x -> 0.9814558180306291}, {y -> 0. - 0.47354458845374703*I, x -> -1.106455818030629}, {y -> 0. + 0.47354458845374703*I, x -> -1.106455818030629}, {y -> 0.19168849014437106, x -> 0.9814558180306291}}As a trivial aside:Just as a curiosity, why does Mathematica see fit to reverse x and y?In other words, since we had asked for {x, y}, why does Mathematica reportthe results in the form {y -> , x -> }, rather than {x -> , y -> }?But back to Tomas' observation of incorrect behavior of Solve:I crave an explanation!-- David Cantrell ==== > The issue is: how do I create a pure recursive function? Normally when> creating a recursive function I use the name of the function to perform> the recursive call:> fact[n_] :=> If[n == 1, 1, n fact[n - 1]]> If[#>1,# #0[#-1],1]&Albert.. ==== Niall,What objection do you have to making fact a Global variable? That is thenormal Mathematica usage. Every symbol you create is put in the Globalcontext (unless you are writing a package and put it in the packagecontext.)Your recursive function could probably be better written with multipledefinitions as follows.fact[0] := 1;fact[n_] := n fact[n - 1]Often it may be useful to use dynamic programming (Section 2.4.9) so as tosave computed values.fact[0] := 1;fact[n_] := fact[n] = n fact[n - 1]David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/The logical step to avoid this seems to be to make the name of thefunction local as in something like the following:Function[fact, fact[5]] @@ {Function[n, If[n==0, 1, n fact[n-1]]]}or maybe:With[{fact = Function[n, If[n == 0, 1, n fact[n - 1]]]}, fact[5]]However both of these solutions steadfastly return the value 5fact[4]. I assume the problem is that the variables initialised inFunction[] and With[] must be symbols, and cannot be patterns. But arecursion requires a pattern (n_ in the first, global, solution above).What do I do to get factorial to work _without_ making the symbol factglobal?I'd be grateful for any help.Niall. ==== I had the same problem. Running ranlib did fix the out-of-date errormessage.However, I still get the message /usr/bin/ld:/usr/lib/libSystem.dylib load command 9 unknown cmd field. Then,make: *** [addtwo] Error 1.Anyone seen this?> I'm trying to get the example addtwo to compile, using ProjectBuilder.> The Developer's guide says in different places, that I should not use> libML.a, and also that I must use it. In any event, I get fatals errors> Ôout of date' if I try to include it. If I leave it out and use> mathlink.framework instead, addtwo compiles but does not run normally.> Any suggestions? I've been working on this for days, it is driving me> crazy. I'm not a professional software developer and not very familair> with ProjectBuilder, either.> MacOS X uses a static library for MathLink, just as has been done with> other UNIX variants.> There is a known issue for MacOS X wherein it is necessary to run the> command line tool ranlib on the library file libML.a before building> executables that are linked against the library. As long as you don't> move the library file to another location, you need only do this once. ==== Whoops, solved this one myself.Had to upgrade the Developer Package after upgrading to Jaguar.After that, no problem, worked fine.> I had the same problem. Running ranlib did fix the out-of-date error> message.> However, I still get the message /usr/bin/ld:> /usr/lib/libSystem.dylib load command 9 unknown cmd field. Then,> make: *** [addtwo] Error 1.> Anyone seen this?> I'm trying to get the example addtwo to compile, using ProjectBuilder.> The Developer's guide says in different places, that I should not use> libML.a, and also that I must use it. In any event, I get fatals errors> Ôout of date' if I try to include it. If I leave it out and use> mathlink.framework instead, addtwo compiles but does not run normally.> Any suggestions? I've been working on this for days, it is driving me> crazy. I'm not a professional software developer and not very familair> with ProjectBuilder, either.> MacOS X uses a static library for MathLink, just as has been done with> other UNIX variants.> There is a known issue for MacOS X wherein it is necessary to run the> command line tool ranlib on the library file libML.a before building> executables that are linked against the library. As long as you don't> move the library file to another location, you need only do this once. ==== >at school the command plot makes mathematica open>a new page witch contains the graphics but it dont seems to>be a preset of mathematica so my question is how can I>configure mathematica to make im plot my grapchics in new page>>thank>s.To set the default action for graphics, you set $DisplayFunction. The function takes a single argument, the graphics expression. For example,In[1]:=PrintShort[gr_] := Print[Short[InputForm[gr]]]In[2]:=$DisplayFunction = PrintShort;In[3]:=Plot[x^2,{x,0,10}]Graphics[{{Line[<<1>>]}}, á nge -> Automatic, <<24>>}]Note that there's no output in this example, so it's a good idea to have your function return the original expression.The second part is learning how to put a graphic into a new notebook. This can be done with DisplayString and NotebookPut.In[4]:=PutToNewNB[gr_] := (NotebookPut[ Notebook[{ Cell[GraphicsData[PostScript, DisplayString[gr]],Graphics, ImageMargins->{{0,0},{0,0}}] },WindowSize->{FitAll, FitAll}, WindowElements->{},WindowFrameElements->{CloseBox}, ShowCellBracket->False, Saveable->False] ]; gr)In[5]:=$DisplayFunction =PutToNewNB;In[6]:=Plot[x^2,{x,0,10}]Out[6]=-Graphics-------- -------------------------------------------------------Omega ConsultingThe final answer to your Mathematica needs ==== > No, you don't. There are infinitely many roots, of which Mathematica> gives you only three: -Pi/2, 0, and Pi/2.>> Actually, you get five different roots, not three.Oops! Sorry, I mistakenly had thought you were solving just f[x]==0, ratherthan f'[x]==0, which indeed gives five roots.> Nevertheless - point taken.> I ment of course that i'd like Mathematica to give me ALL the roots on> form: angle + (period * n). I'll try to be more exact the next time.Well, here's something that might interest you, although it's not reallywhat you wanted. Let's be a bit more general, now asking Mathematica toSolve[f'[x]==a, x]. This gives eight expressions:{{x -> -ArcCos[-Sqrt[5/8 - Sqrt[9 - 16*a]/8]]}, {x -> ArcCos[-Sqrt[5/8 - Sqrt[9 - 16*a]/8]]}, {x -> -ArcCos[Sqrt[5/8 - Sqrt[9 - 16*a]/8]]}, {x -> ArcCos[Sqrt[5/8 - Sqrt[9 - 16*a]/8]]}, {x -> -ArcCos[-Sqrt[5/8 + Sqrt[9 - 16*a]/8]]}, {x -> ArcCos[-Sqrt[5/8 + Sqrt[9 - 16*a]/8]]}, {x -> -ArcCos[Sqrt[5/8 + Sqrt[9 - 16*a]/8]]}, {x -> ArcCos[Sqrt[5/8 + Sqrt[9 - 16*a]/8]]}}Merely substituting 0 for a in the above gives one double and six singleroots:{{x -> (-2*Pi)/3}, {x -> (2*Pi)/3}, {x -> -Pi/3}, {x -> Pi/3}, {x -> -Pi}, {x -> Pi}, {x -> 0}, {x -> 0}}That's still not what you wanted. But to get, at least in some sense, whatyou want, you simply need to interpret all of the inverse cosines above asdenoting not just the principal value (which is what Mathematica does, ofcourse), but rather all values of the inverse cosine relation. Then eachof the eight expressions above would represent infinitely many values.Finally, substituting 0 for a, you would have all solutions represented interms of the multivalued inverse cosine relation:-arccos(-1/2), arccos(-1/2), -arccos(1/2), arccos(1/2),-arccos(-1), arccos(-1), -arccos(1), arccos(1)or equivalently, for integer N,(-2*Pi)/3+2*Pi*N, (2*Pi)/3+2*Pi*N, -Pi/3+2*Pi*N, Pi/3+2*Pi*N,-Pi+2*Pi*N, Pi+2*Pi*N, 0+2*Pi*N, 0+2*Pi*N.To get this final form -- at least the way I did it -- required humanintervention, which I'm sure you had hoped to avoid. Can anyone suggesta simple way, avoiding human intervention, to have Mathematica give anequivalent form of the result?David Cantrell-- -------------------- http://NewsReader.Com/ --------------------Usenet Newsgroup Service New Rate! $9.95/Month 50GB ==== > No, you don't. There are infinitely many roots, of which Mathematica gives> you only three: -Pi/2, 0, and Pi/2.> Actually, you get five different roots, not three. Nevertheless - point> taken.> I ment of course that i'd like Mathematica to give me ALL the roots on form:> angle + (period * n). I'll try to be more exact the next time.> Didn't you notice Mathematica's comment that, since inverse functions were> being used, some solutions might not be found? That's the explanation.> Yes, i did. I wonder why it's the ONLY method used by Mathematica. It feels> pretty bad to know that the program misses some simple roots. I don't> wonder> what kind of algorithm gave that, rather why do they use only that> algorithm.> I appologize if my question caused any trouble by it's fuzziness.> --> V.8anligen> Konrad> -------------------I did not really understand at first the nature of the question. Nowthat I do I'll take a stab at it. Under Solve>Further Examples>Gettinginfinite solution sets for some equations in the Help Browser, there iscode to do something called GeneralizeSolve. It is based on findingperiodic inverses to various known functions, and takes advantage of thefact that Solve will find solutions in terms of these inverse functions.It does not quite work directly on your problem for the simple reasonthat e.g. ArcSin[0] will evaluate to 0. So we make it work by solvingf'[x]==a and substituting a->0 afterward.Here is the code in question.arctrigs = {ArcSin, ArcCos, ArcCsc, ArcSec, ArcTan, ArcCot, ArcSinh,ArcCosh, ArcCsch, ArcSech, ArcTanh, ArcCoth};periods = {2*Pi, 2*Pi, 2*Pi, 2*Pi, Pi, Pi, 2*I*Pi, 2*I*Pi, 2*I*Pi, 2*I*Pi, I*Pi, I*Pi}; (* We use n to denote an arbitrary integer *)Generalize[f_[x_], n_] := f[x] + nperiods[[Position[arctrigs, f][[1, 1]]]] /; MemberQ[arctrigs,f]Generalize[Log[x_],n_]:=Log[x]+2[Pi][ ImaginaryI]nGeneralize[ProductLog[x_],n_]:=ProductLog[n,x] Generalize[x___, n_] := xGeneralizedSolve[eqns_, vars_] := Generalize[#, n] & //@ Solve[eqns,vars]In[12]:=GeneralizedSolve[f'[x]==a,x]/. a->0Solve::ifun: Inverse functions are being used by Solve, so somesolutions may not be found.Out[12]={{x -> -((2*Pi)/3) - 2*n*Pi}, {x -> (2*Pi)/3 + 2*n*Pi}, {x -> -(Pi/3) - 2*n*Pi}, {x -> Pi/3 + 2*n*Pi}, {x -> -Pi - 2*n*Pi}, {x -> Pi + 2*n*Pi}, {x -> -2*n*Pi}, {x -> 2*n*Pi}}A minor inconvenience is that some solutions may be listed more thanonce e.g. the last two are equivalent if we regard n as ranging over allintegers.Daniel LichtblauWolfram Research ==== > I did not really understand at first the nature of the question. Now> that I do I'll take a stab at it. Under Solve>Further Examples>Getting> infinite solution sets for some equations in the Help Browser, there is> code to do something called GeneralizeSolve.Many thanks for pointing this out. I had not see it before.It answers the question at the end of my previous post in this thread:Can anyone suggest a simple way, avoiding human intervention, to haveMathematica give an equivalent form of the result?> It is based on finding> periodic inverses to various known functions, and takes advantage of the> fact that Solve will find solutions in terms of these inverse functions.> It does not quite work directly on your problem for the simple reason> that e.g. ArcSin[0] will evaluate to 0. So we make it work by solving> f'[x]==a and substituting a->0 afterward.(Yes. I had suggested this also.)[snip of code,...]> A minor inconvenience is that some solutions may be listed more than> once e.g. the last two are equivalent if we regard n as ranging over all> integers.OTOH, instead of being viewed as an inconvenience, it might be regardedin some situations as providing valuable information about themultiplicities of the roots.David Cantrell-- -------------------- http://NewsReader.Com/ --------------------Usenet Newsgroup Service New Rate! $9.95/Month 50GB ==== >As I understand it, I can write a Complex java class with a public constructor>method of the form:>> public Complex(double Re, double Im)>>and mehtods re() and im() of the form:>> public double re();> public double im();>If I place this class file in a directory on the JavaClassPath and execute>SetComplexPath[Complex], I should then be able to pass complex numbers from>Mathematica to any java method accepting objects of type Complex.>>Has anyone had any luck with this? I haven't been able to get it to work in>Mac OS 9 or Mac OS X.Mark,This should work as you describe. I have no trouble with it on any OS, including Mac OS 9 and OS X.What happens when you try it? What error messages do you see? What does your complex number class look like? I suggest that you send this query, including the answers to these questions, to jlink@wolfram.com. To resolve your problem we may need to go into more detail than would be of general interest to the mathgroup.Todd GayleyWolfram Research ==== I'm trying to get JLink working and am having some difficulties. I need tochange the CommandLine property for InstallJava[], and I wanted to set it upso it did it automatically. In the Help it says to add a SetOptions[] tothe init.m file. I tried adding the code it suggests:<mypath]but it doesn't work. If I add this line in an external editor, I get anerror when I run Mathematica. If I open the init.m file in Mathematica, itjust doesn't stick. The init.m file has a huge giant SetOptions in it. Infact, that's all it is is one big SetOptions call. Am I supposed to add myoption to that call? If so, how. The format of the SetOptions[] in theinit.m file looks very different. Everything is enclosed in double quotes,including what looks like the property names. Here's the first few lines:SetOptions[$FrontEnd,NotebookDirectory:>FrontEnd` FileName[{$RootDirectory, C:, Documents and Settings, steven, Application Data, Mathematica, FrontEnd}, CharacterEncoding -> WindowsANSI],AutoOpenPalettes->{BasicInput.nb, AlgebraicManipulation.nb},AutoOpenNotebooks->{}, ScreenRectangle->{{0, 1024}, {0, 721}},NotebooksMenu->{If I need to add my option change in here, where should I put it. ThisSetOptions[] is so complex it's hard to see where one thing starts andanother end, especially since I'm so new to Mathematica. Also, where do Iput the <True]----------------How can I make this happen?--Steven Hodgensteven@twitch.net ==== I am due for a new computer and my driving requirement is Mathematica speed.I was wondering if anyone could recommend which processor family (Intel orAMD) and which OS (Win NT or WXP) has the best speed comparison.I read a statement that said the AMD runs circles for FP ops. over Intel,but there was no more detail, so I was wondering.Note: I have always thought about going MAC, but just have too much softwarethat I use and cannot afford to. ==== Do a search on Google.Here are a couple of links:http://www.scientificweb.de/mathstef3.htmlhttp://www2. staff.fh-vorarlberg.ac.at/~ku/karl/mma.htmlCarsten Hansen>> I am due for a new computer and my driving requirement is Mathematicaspeed.>> I was wondering if anyone could recommend which processor family (Intel or> AMD) and which OS (Win NT or WXP) has the best speed comparison.>> I read a statement that said the AMD runs circles for FP ops. over Intel,> but there was no more detail, so I was wondering.>> Note: I have always thought about going MAC, but just have too muchsoftware> that I use and cannot afford to.> ==== For Mathematica users who plot data for presentation to others, the difficulty of controlling the details of graph layout is a recurring annoyance. It has been noted before in this forum that long labels, for example, can play hob with graph formatting and alignment.process of keeping the formatting consistent, but I have always been stopped by a significant omission from Mathematica's graphics capabilities: There seems to be no way to determine the size of a graphical text element. I'm sure this has been pointed out to WR many times (twice by me), but apparently providing a way to determine the size of graphics text has a low development priority, because it hasn't happened yet.Here's an example of how the ability to determine text size could be helpful. Suppose that we want to keep the size and aspect ratio of the plot area from changing if we specify a long plot label. We might allocate a rectangle of a certain size for the label, then make sure that the label fits inside it. If it doesn't, we could programmatically reduce the font size until the formatted label is small enough to fit. But even such a simple scheme as this is unavailable to us, because we have no way to test whether the text fits inside a rectangle without plotting it and looking at it.Given the power of Mathematica, it would seem to be relatively simple for someone with knowledge of a few basics -- for example, font metrics and how PostScript formats text -- to write a function that would return the size of the bounding box for a piece of formatted text. Unfortunately, I'm not that someone; but I am wondering if one of you MathGroupies has either solved this problem or knows roughly how to do it. Or maybe you can point out something simple that I have been overlooking.Dick ZacherTo reply directly, please remove the four-letter prefix Junk from my return ==== > No, you don't. There are infinitely many roots, of which Mathematica > gives> you only three: -Pi/2, 0, and Pi/2.>> Actually, you get five different roots, not three. Nevertheless - >> point>> taken.>> I ment of course that i'd like Mathematica to give me ALL the roots >> on form:>> angle + (period * n). I'll try to be more exact the next time.> Didn't you notice Mathematica's comment that, since inverse > functions were> being used, some solutions might not be found? That's the > explanation.>> Yes, i did. I wonder why it's the ONLY method used by Mathematica. It >> feels>> pretty bad to know that the program misses some simple roots. I >> don't>> wonder>> what kind of algorithm gave that, rather why do they use only that>> algorithm.>> I appologize if my question caused any trouble by it's fuzziness.>> -->> V.81nligen>> Konrad>> ------------------->> I did not really understand at first the nature of the question. Now> that I do I'll take a stab at it. Under Solve>Further Examples>Getting> infinite solution sets for some equations in the Help Browser, there > is> code to do something called GeneralizeSolve. It is based on finding> periodic inverses to various known functions, and takes advantage of > the> fact that Solve will find solutions in terms of these inverse > functions.> It does not quite work directly on your problem for the simple reason> that e.g. ArcSin[0] will evaluate to 0. So we make it work by solving> f'[x]==a and substituting a->0 afterward.>> Here is the code in question.>> arctrigs = {ArcSin, ArcCos, ArcCsc, ArcSec, ArcTan, ArcCot, ArcSinh,> ArcCosh,> ArcCsch, ArcSech, ArcTanh, ArcCoth};>> periods = {2*Pi, 2*Pi, 2*Pi, 2*Pi, Pi, Pi, 2*I*Pi,> 2*I*Pi, 2*I*Pi, 2*I*Pi, I*Pi, I*Pi};>> (* We use n to denote an arbitrary integer *)>> Generalize[f_[x_], n_] :=> f[x] + nperiods[[Position[arctrigs, f][[1, 1]]]] /; MemberQ[arctrigs,> f]>> Generalize[Log[x_],n_]:=Log[x]+2[Pi][ImaginaryI]n>> Generalize[ProductLog[x_],n_]:=ProductLog[n,x]>> Generalize[x___, n_] := x>> GeneralizedSolve[eqns_, vars_] := Generalize[#, n] & //@ Solve[eqns,> vars]>> In[12]:=> GeneralizedSolve[f'[x]==a,x]/. a->0>> Solve::ifun: Inverse functions are being used by Solve, so some> solutions may > not be found.>> Out[12]=> {{x -> -((2*Pi)/3) - 2*n*Pi}, {x -> (2*Pi)/3 + 2*n*Pi},> {x -> -(Pi/3) - 2*n*Pi}, {x -> Pi/3 + 2*n*Pi},> {x -> -Pi - 2*n*Pi}, {x -> Pi + 2*n*Pi},> {x -> -2*n*Pi}, {x -> 2*n*Pi}}>> A minor inconvenience is that some solutions may be listed more than> once e.g. the last two are equivalent if we regard n as ranging over > all> integers.> Daniel Lichtblau> Wolfram Research>This last minor inconvenience can be dealt with as follows:g[x_, y_] := TrueQ[Simplify[Element[x, Integers], Element[y, Integers]] && Simplify[Element[y, Integers], Element[x, Integers]]]l = GeneralizedSolve[Derivative[1][f][x] == a, x] /. a -> 0Solve::ifun:Inverse functions are being used by Solve, so some solutions may not be found.{{x -> -((2*Pi)/3) - 2*n*Pi}, {x -> (2*Pi)/3 + 2*n*Pi}, {x -> -(Pi/3) - 2*n*Pi}, {x -> Pi/3 + 2*n*Pi}, {x -> -Pi - 2*n*Pi}, {x -> Pi + 2*n*Pi}, {x -> -2*n*Pi}, {x -> 2*n*Pi}}Union[l, SameTest -> (g[x /. #1, x /. #2] & )]{{x -> -2*n*Pi}, {x -> -Pi - 2*n*Pi}, {x -> -((2*Pi)/3) - 2*n*Pi}, {x -> -(Pi/3) - 2*n*Pi}, {x -> Pi/3 + 2*n*Pi}, {x -> (2*Pi)/3 + 2*n*Pi}, {x -> Pi + 2*n*Pi}}(One could of course write a version of GeneralizedSolve that does this automatically).Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/Reply-To: kuska@informatik.uni-leipzig.de ==== would you be so kind to read the manual *before* youstart to programm ? Fine.Your first definition > withdraw := Evaluate[> Module[ { balance = 100 },> Function[ amount,> If[ balance >= amount,> balance -= amount; balance,> Print[ Insufficient Funds ]> ]> ]> ]> ]return a pure function that does the If[] test when youcall it withdraw[60]. Since you force to evaluate the Module[] you create globalvariable balance$ that can't removed when theModule[] ends. If you would like to use a fixed constant youshould use With[], i.e.withdraw = With[{balance = 100}, Function[amount, If[balance >= amount, balance - amount, Print[Insufficient Funds]]]]In the next definition> secondWithdraw[ initBalance_ ] := Evaluate[> Module[ { balance = initBalance },> Function[ amount,> If[ balance >= amount,> balance -= amount; balance,> Print[ Insufficient Funds ]> ]> ]> ]> ]you Evaluate[] the right side before you have a given a valuefor initBalance but that can't work, because the patterninitBalance_ has absolute nothing to do with the variableinitBalance. You meanwithdraw::insuff = Insifficuent funds Ô1'.withdraw[amount_, balance_:100] := If[balance >= amount, balance - amount, Message[withdraw::insuff, balance] ]orwithdraw1[amount_,balance_:100]/; balance>amount :=balance-amountwithdraw1[amount_,balance_:100]:=(Message[ withdraw::insuff,balance];balance) Jens> This is a programming example from the wizard book chapter 3.> ( http://mitpress.mit.edu/sicp/full-text/book/book.html )> Consider the following:> withdraw := Evaluate[> Module[ { balance = 100 },> Function[ amount,> If[ balance >= amount,> balance -= amount; balance,> Print[ Insufficient Funds ]> ]> ]> ]> ]> In[2]:= withdraw [ 60 ]> Out[2]= 40> In[2]:= withdraw[ 60 ]> Insufficient Funds> The question now is, can I in Mathematica write a function that takes as> argument the balance, so that I do not have to use the fixed balance => 100. Note that in first example balance is _not_ present in the global> context.> My idea was the following:> secondWithdraw[ initBalance_ ] := Evaluate[> Module[ { balance = initBalance },> Function[ amount,> If[ balance >= amount,> balance -= amount; balance,> Print[ Insufficient Funds ]> ]> ]> ]> ]> In[7]:= W1:=secondWithdraw[ 100 ]> In[8]:= W1[ 60 ]> Out[8]= If[initBalance >= 60, balance$2 -= 60; balance$2,> Print[Insufficient Funds]]> So this however does not work. I _assume_ that Evaluate hits to early.> The evaluation of balance >= amount to initBalance >= amount is too> early. Is this the problem? How can I circumvent it?> I'd be glad for any insights you might have.> Oliver Ruebenkoenig, ==== Your example works fine if you remove Evaluate: In[1]:= secondWithdraw[ initBalance_ ] := Module[ { balance = initBalance }, Function[ amount, If[ balance >= amount, balance -= amount; balance, Print[ Insufficient Funds ] ] ] ]In[4]:= W1:=secondWithdraw[100]In[5]:=W1[60]Out[5]=40 ==== >----- Original Message----->Sent: Friday, December 13, 2002 10:10 AM>To: mathgroup@smc.vnet.net>>This is a programming example from the wizard book chapter 3.>( http://mitpress.mit.edu/sicp/full-text/book/book.html )>>Consider the following: >>withdraw := Evaluate[> Module[ { balance = 100 },> Function[ amount,> If[ balance >= amount,> balance -= amount; balance,> Print[ Insufficient Funds ]> ]> ]> ]> ]>>In[2]:= withdraw [ 60 ]>>Out[2]= 40>>In[2]:= withdraw[ 60 ]>Insufficient Funds>>The question now is, can I in Mathematica write a function >that takes as>argument the balance, so that I do not have to use the fixed balance =>100. Note that in first example balance is _not_ present in the global>context. >>My idea was the following:>>secondWithdraw[ initBalance_ ] := Evaluate[> Module[ { balance = initBalance },> Function[ amount,> If[ balance >= amount,> balance -= amount; balance,> Print[ Insufficient Funds ]> ]> ]> ]> ]>>In[7]:= W1:=secondWithdraw[ 100 ]>>In[8]:= W1[ 60 ] >Out[8]= If[initBalance >= 60, balance$2 -= 60; balance$2, >> Print[Insufficient Funds]]>>So this however does not work. I _assume_ that Evaluate hits to early.>The evaluation of balance >= amount to initBalance >= amount is too>early. Is this the problem? How can I circumvent it?>>I'd be glad for any insights you might have.>Oliver Ruebenkoenig, Oliver,you'r quite right, dispense with that Evaluate: In[5]:= withdraw2[initBalance_] := Module[{balance = initBalance}, Function[amount, If[balance >= amount, balance -= amount; balance, Print[Insufficient Funds]]]]In[11]:= W1 = withdraw2[100];In[12]:= balance$21Out[12]= 100In[13]:= W1[60]Out[13]= 40In[14]:= W1[60]Insufficient FundsThe example from the wizard book, in fact is no good at all, just construedto bewilder little children. Your idea to create an account, an individualobject, is much better. However other methods should be defined, and theconstructor given a different name.Here is something containing several member functions: In[177]:= Remove[createAccount]In[178]:=createAccount /: Set[thisAccount_, createAccount[initial_:1 ]] := (thisAccount = Module[{account, key = Random[Integer, {0, 10^12}]}, With[{key = key}, account[Balance] := SequenceForm[account[key], [ThinSpace][InvisibleComma][InvisibleComma], EUR]; account[key] = initial; account[Withdraw] = (If[account[key] >= #, (account[key] -=#)EUR, Print[Insufficient Funds]; $Failed]) &; account[Deposit] = (account[key] += #; If[account[key] > 10^6, Print[Beware of Taxes!]]; account[key]EUR) &; account]];)In[179]:= myAccount = createAccount[] -- this calls the constructor with default initial balance (a donation from my bank), no output is givenIn[180]:= ?myAccountGlobal`myAccountmyAccount = account$154 -- that's the object createdIn[181]:= ?account$154.... -- you see what's behind the sceneIn[182]:= myAccount[Balance]Out[182]= 1 EUR -- method Balance shows the initial donationIn[183]:= myAccount[Deposit][60]Out[183]= 61 EURIn[184]:= myAccount[Balance]Out[184]= 61 EURIn[185]:= myAccount[Withdraw][50]Out[185]= 11 EURIn[186]:= myAccount[Withdraw][50]Insufficient FundsOut[186]= $FailedIn[187]:= myAccount[Deposit][10^7]Beware of Taxes!Out[187]= 10000011 EURPerhaps it is better to move the methods to a class (and just fix theparameters):In[206]:= Remove[createAccount, Balance, Withdraw, Deposit]In[207]:=createAccount /: Set[thisAccount_, createAccount[initial_:1 ]] := (thisAccount = Module[{account, key = Random[Integer, {0, 10^12}]}, account[key] = initial; With[{key = key}, account[Balance] := Balance[account, key]]; account[Withdraw] = Withdraw[account, key]; account[Deposit] = Deposit[account, key]; account];)In[212]:=Balance[account_, key_] := SequenceForm[account[key], [ThinSpace], EUR]In[213]:=Withdraw[account_, key_][amount_] := (If[account[key] >= amount, (account[key] -= amount)EUR, Print[Insufficient Funds]; $Failed])In[214]:=Deposit[account_, key_][amount_] := (account[key] += amount; If[account[key] > 10^6, Print[Beware of Taxes!]]; account[key]EUR)The key isn't necessary, conside