A22 ==== My experience with changing the defualt complexity function isthat for each complexity function there are cases in whichit does not agree with the intuitive notion of simplicity.The more complicated the complexity function becomes the stranger(and harder to understand) such examples get.Your function has the advantage of being defined in a prettysimple to understand way, and may be useful for small examples.Certainly by its very definition it will produce answers thathave the smallest size when printed.However, another important property that the default complexityfunction should have is that computing its value should takea negligible amount of time compared to the rest of the Simplifyalgorithm. A complexity function that involves formatting ofexpressions does not have this property.In[1]:= e=Sum[Random[Integer, {-10, 10}] x^i y^j z^k, {i, 0, 4}, {j, 0, 4}, {k, 0, 4}];In[2]:= Simplify[e];//TimingOut[2]= {0.96 Second, Null}In[3]:= Simplify[e, ComplexityFunction -> (StringLength[ToString[TraditionalForm[#]]] & )];//TimingOut[3]= {4.09 Second, Null}Here computing the complexity function takes 3 times longerthen the rest of the Simplify algorithm (and a polynomialis not the hardest expression to format).One could try to find a function that estimates the size ofthe printed expression, without quite formatting it, and thecurrent default complexity function gives a simply definedestimate of size. Each such function, given it only estimatesthe size of output, is bound to have cases where it isincorrect, and we come back to my first comment, i.e. the morecomplicated the complexity function the stranger its unintendedconsequences.Adam StrzebonskiWolfram Research> In fact the following ComplexityFunction, (which I have used on this > list before to deal with similar problems), works quite well: Simplify[Abs[x], x < 0, ComplexityFunction - (StringLength[ToString[TraditionalForm[#]]] & )] > -x > The only problem is that it penalizes functions with long names, like > KroneckerDelta. If one could deal with that problem I think it would be > the ideal choice for the default ComplexityFZunction in Simplify. Andrzej Kozlowski >> Yes, but although I have known this for years, I kept getting deceived >> by this silly point. WOuld it not however be easier if the default >> ComplexityFunction in Mathematica reßected more closely the visible >> number of characters rather then the Mathematica FullForm? > (LeafCount).>> It should be possible to create a VisibleCharacterLength function >> that would do that.>> A.> This is an issue of deciding what is simpler. With the default> ComplexityFunction -x is not simpler than Abs[x]. Simplify's> built in complexity measure is based on FullForm of expressions,> rather than on the size of printed output.>> In[1]:= LeafCount/@{-x, Abs[x]}> Out[1]= {3, 2}>> In[2]:= -x // FullForm> Out[2]//FullForm= Times[-1, x]>> In[3]:= Abs[x] // FullForm> Out[3]//FullForm= Abs[x]>> With a ComplexityFunction attributing additional weight to Abs> Simplify will transform Abs[x] to -x.>> In[4]:= f=1000 Count[#, _Abs, {0, Infinity}]+LeafCount[#]&;>> In[5]:= Simplify[ Abs[x] , x<0, ComplexityFunction -> f ]> Out[5]= -x> Adam Strzebonski> Wolfram Research>> Almost certainly an oversight. However, if you replace Abs by >> something equivalent, things work as they should, e.g:>> Simplify[Sqrt[x*Conjugate[x]], x < 0]>> -x>> or>> Simplify[Sqrt[Im[x]^2 + Re[x]^2], x < 0]>> -x>> etc.> Hi,>> Simplify[ Abs[x] , x>0 ] returns x.> But, Simplify[ Abs[x] , x<0] returns Abs[x], and not -x.>> Why is that?>> Uri>> Andrzej Kozlowski>> Yokohama, Japan>> http://www.mimuw.edu.pl/~akoz/>> http://platon.c.u-tokyo.ac.jp/andrzej/>> Andrzej Kozlowski>> Yokohama, Japan>> http://www.mimuw.edu.pl/~akoz/>> http://platon.c.u-tokyo.ac.jp/andrzej/>Andrzej Kozlowski> Yokohama, Japan> http://www.mimuw.edu.pl/~akoz/> http://platon.c.u-tokyo.ac.jp/andrzej/> ==== I have a simple (supposedly) question...I used the following command to draw a plot, but Mathematica could not runproperly.Plot[x^(2/3),{x,-1,0}]I know the problem is about calculating (-1)^(1/3) in mathematica. Although(-1)^(1/3) = -1,mathematica tries to calculate it numerically and gives complex results0.5+0.8iHow to solve this problem and restrict the solution to be only real numbers? ==== Hi All,does anyone know where I may be able to get Mathematica code for factoring methods(I know about FactorInteger of course), but am interesting in simplefactoring (like trial division), Fermat's Factoring Methods, Pollards'methods, all the way up to the sophisticated elliptic type methods?I am curious more than than anything and would like to explore/experimentwith these algorithms.I have the four wonderful books Knuth, Riesel, Cohen and Pomerance/Crandalland they have most of these algorithms. I also have the book byBressoud/Wagon (computation number theory).I tried MathSource, but no luck.FlipReply-To: drbob@bigfoot.com ==== Great work, Mihajlo! It seems always a little more accurate except when n=2, and then it gives the same answer as my method.BobbyOn Tue, 11 Feb 2003 04:41:58 -0500 (EST), Mihajlo Vanevic (but more accurate, I think)><< Statistics`DescriptiveStatistics`Clear[mihajlo2];mihajlo2[ xlist_, dr_:0.1, error_:0.01] :=> Module[> {xxlist, gaps, ratios, rationalRatios, lcm, intRatios, xvals, linefit, a, > b},> xxlist = Mean /@ Split[Sort[xlist], #2 - #1 < error &];> gaps = ListConvolve[{1., -1.}, xxlist];> ratios = gaps/Min[gaps];> rationalRatios = Rationalize[ratios, dr];> lcm = LCM @@ Denominator[rationalRatios];> intRatios = rationalRatios*lcm;> xvals = FoldList[Plus, lcm, intRatios];> linefit = Fit[Transpose[{xvals, xxlist}], {1, x}, x];> {a, b} = CoefficientList[linefit, x];> {Mod[a, b], b, Max[xvals]}> ];test:xlist := 0.202 + 1.618 Table[0.001 Random[] + Random[Integer, {3, 17}], > {20}];> TableForm[Table[{{mihajlo2[xlist]}}, {50}]]>andxlist := 0.202 + 1.618 Table[0.001 Random[] + Random[Integer, {3, 17}], > {4}];> TableForm[Table[{{mihajlo2[xlist]}}, {50}]]>Mihajlo*********************************************** ***************> ************************************************************* *>> Mihajlo's method doesn't work well with small sample sizes, so I'd >> suggest this:>> << Statistics`DescriptiveStatistics`>> xlist = 0.202 + 1.618 Table[0.001 Random[] + Random[Integer, {3, 17}], >> {20}];>> error = 0.5;>> xxlist = Mean /@ Split[Sort[xlist], #2 - #1 < error &];>> Fit[xxlist, {1, x, x^2}, x];>> {a, b, c} = CoefficientList[, x];>> {Mod[a, b], b}>> gaps = Subtract @@@ Transpose@{Rest@xxlist, Drop[xxlist, -1]};>> ratios = gaps/Min@gaps;>> gcd[ratios_List] := Module[{n = 2, k},>> While[n < 10 && (k = n/GCD @@ Round[n*ratios]) í¢.89´Á.8c« n, n++];>> k>> ]>> b2 = Min[gaps]/gcd@ratios;>> {a2 = Mean@Mod[xxlist, b2], b2}>> {1.18984, 1.39711} (* Mihajlo's method with Mean in place of First *)>> {0.207753, 1.6175} (* better *)>> With as few as four samples, this often returns the right period, while >> the other method rarely gets it right even with 20 samples.>> You shouldn't make the error estimate too small --- a fourth of the >> period is about right. (But you don't know the period in advance.) A >> more complete method would adjust the error estimate after estimating >> the period, to see if the answer changes.>> Bobby>-- majort@cox-internet.comBobby R. Treat ==== Hi,ReplaceAll will help.e.g.ans = FindRoot[Exp[x]==x^2, {x, -0.5}]{x -> -0.703467}x /. ans-0.703467ORReplaceAll[x,ans]-0.703467YasDear Friends,> I need to use the root of a simple equation in subsequent operations.> After extracting the root, it comes in the form ->root. I have not been> able to get rid of the symbol -> .Can someone help?>>Naser Mostaghel> Professor, Civil Engineering> T: (419) 530-8131> F: (419) 530-8116> E: nmostag@utnet.utoledo.edu>> ==== Mostaghel, Naser schrieb:> Dear Friends,> I need to use the root of a simple equation in subsequent operations.> After extracting the root, it comes in the form ->root. I have not been > able to get rid of the symbol -> . Can someone help? Naser Mostaghel> Professor, Civil Engineering> T: (419) 530-8131> F: (419) 530-8116> E: nmostag@utnet.utoledo.edu > r = Solve[x^2 + a x + b == 0, x]!(TraditionalForm`{{x -> 1/2 (((-a) - @(a^2 - 4 b)))}, {x -> 1/2 ((@(a^2 - 4 b) - a))}})r[[1, 1, 2]]isolates the 1st root!(TraditionalForm`1/2 (((-a) - @(a^2 - 4 b))))r[[1, 1, 2]]isolates the 2nd root!(TraditionalForm`1/2 ((@(a^2 - 4 b) - a))) ==== Naser,It is not a matter of getting rid of the symbol -> but rather of usingit.For example.soln=Solve[{x^2+y^2==4, x+y==0},{x,y}] {{x -> -Sqrt[2], y -> Sqrt[2]}, {x -> Sqrt[2], y -> -Sqrt[2]}}This gives the two solutions for the pair x and y --- that's why we need alist of lists.The replacement rule form lets us put the solutions into expressionsx+y^2/.soln {2 - Sqrt[2], 2 + Sqrt[2]}The first number comes from the first solution, the second one from thesecond solution.If we want to use only the first solution we can get its list of rules out:firstsoln = soln[[1]] {x -> -Sqrt[2], y -> Sqrt[2]}and use itx+y^2/.firstsoln 2 - Sqrt[2]--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198Dear Friends,> I need to use the root of a simple equation in subsequent operations.> After extracting the root, it comes in the form ->root. I have not been> able to get rid of the symbol -> .Can someone help?>>Naser Mostaghel> Professor, Civil Engineering> T: (419) 530-8131> F: (419) 530-8116> E: nmostag@utnet.utoledo.edu> ==== Mostaghel,Mathematica almost always returns the results of various solving routinesas a set of rules. Often there may be multiple variables and/or multiplevalues and then you get sets of rules. You could save the rules and use themlater to substitute into some expression. Here is an example.xsol = FindRoot[Cos[x] == x, {x, 1}]{x -> 0.739085}I saved the rule in the variable xsol. Then suppose you have an expressionin x. You can replace using xsol.x^2 + 2x - 3% /. xsol-3 + 2*x + x^2-0.975583/. is the shortcut for ReplaceAll. (Lookup ReplaceAll in Help. Also lookupRule.) It uses the rule to replace each value of x.Or you could replace x and save it once and for all.Clear[x];FindRoot[Cos[x] == x, {x, 1}]x = x /. %{x -> 0.739085}0.739085Now everytime you use x in an expression it will be replaced by its value.x^2 + 2x - 3-0.975583I like the first procedure a little better because I don't like to assignpermanent values to a symbol like x.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/F: (419) 530-8116E: nmostag@utnet.utoledo.edu ==== This is indeed a recurring problem with Mathematica beginners. So, eitherthe topic of transformation rules and the use of ReplaceAll is not welldocumented at a tutorial level, or many people simply skip it and hence findthemselves with an apparently unsurmountable problem (I would even classifymyself in this second class, although eventually and with a little patiencethe situation became clear).So, first of all, Mathematica gives the output of evaluations of Solve,FindRoot and other such functions in terms of rules of the form x ->solution. That's the way it works, and nothing to be done there.Now, what does one do with that? One possibility is to look at the internalform of the transformation rule. For example,In[1]:=Solve[x - 1 == 0, x]Out[1]={{x -> 1}}The double curly bracket means that, in general, one could expect a list ofseveral solutions, but in this case there is only one, namely {x -> 1}. Thisis a Mathematica expression, a transformation rule, and in fact a list witha single element, x -> 1. This, again, is a Mathematica expression which hastwo parts (see Part in the on-line Help):In[2]:=(x -> 1)[[1]]Out[2]=xIn[3]:=(x -> 1)[[2]]Out[3]=1Then, if you take the result of your evaluation and take its first (andonly, in this case) part, and then again its first part, and finally itssecond part, you getIn[4]:=Solve[x - 1 == 0, x][[1,1,2]]Out[4]=1which is the bare, naked value of the solution. Presumably you areacquainted with the use of Part; if not, forget it all, spend the next fouror five weeks reading the first sections of The Mathematica Book, and startall over again.But there's another approach, using the function ReplaceAll (/.)(see theon-line Help). Take the particular solution {x -> 1} and writeIn[5]:=x /. x -> 1Out[5]=1 or, equivalently,In[6]:=x /. Solve[x - 1 == 0, x][[1]]Out[6]=1A little practice will be extremely useful. Another example:In[7]:=x /. Solve[x^2 - 2*x + 2 == 0, x]Out[7]={1 - I, 1 + I}Here you have the list of values of the two solutions to the second degreeequation.Tomas GarzaMexico City----- Original Message ----->Naser Mostaghel> Professor, Civil Engineering> T: (419) 530-8131> F: (419) 530-8116> E: nmostag@utnet.utoledo.edu>> ==== You'll want to read about Rule in the help browser: Understanding thisconstruct is critical to your understanding of Mathematica.When you have an output like a->3, you can use that rule to (say)replace all instances of a in an expression with 3. For example,a x + 7 /. {a->3}will replace the a with 3. This operation is quite general, vastlymore powerful than you might imagine by this simple example.If you just want to remove the ->, then r={a->3}a/.rwill do as you wish. Dear Friends,> I need to use the root of a simple equation in subsequent operations.> After extracting the root, it comes in the form ->root. I have not been> able to get rid of the symbol -> . Can someone help? > Naser Mostaghel> Professor, Civil Engineering> T: (419) 530-8131> F: (419) 530-8116> E: nmostag@utnet.utoledo.edu ==== On Tue, 11 Feb 2003 10:00:26 +0000 (UTC), Garry Helzer>Steve,>>If you operate on an object with a linear transformation the >area/volume of the image is the original area/volume multiplied by the >determinant of the matrix of the linear transformation.[snip]>You now have rescaled the object without moving its center of gravity. >This is the fix mentioned below.Gray: Right. I knew that but the poster didn't say he wanted thecentroid invariant. Rather than think of the determinant, I find it much simplerjust to use the fact that the area of anything with constant shapegoes as the square of its linear dimensions. This would also work for3-D (with the cube), etc., and one can find the centroid in the sameway. ==== Ann, I am assuming that the nested lists are rgb triplets and that you arereferring to a 90 degree rotation using transpose. If so, for a discussionhow to rotate by some arbitrary angle go tohttp://www.usm.maine.edu/~mjkcc/docs/ele489/labs/index.htm and downloadNotebook 6: Geometric Operations.Hope that helps, Mariusz= = = = = = = = = = = = = = = = = = = =Mariusz Jankowski, Ph.D.University of Southern Mainemjkcc@usm.maine.edu> Mathgroup,I have an image in the form of nested lists. I would like to rotate thisimage. In the standard package, I can rotate it 90 degrees at a time.Do you meanI would like to rotate the image by non-specific intervals. Does anyoneknow how I can do this with the standard package.>Reply-To: drbob@bigfoot.com ==== Try this:<< Graphics`Graphics`<< Graphics`Colors`f[x_] = x^2 - 2;newton[x_] = Simplify[x - f[x]/f'[x]];ap = NestList[newton, 4., 7];g = {Line@{{#, f@#}, {newton@#, 0}, {newton@#, f@newton@#}}, Point@{#, f@#}} &;h = Text[#, {#, f@#}, {1, -1}] &;DisplayTogether[ Plot[f@x, {x, 0, Max@ap}], Graphics[{Blue, AbsolutePointSize[5], g /@ ap, h /@ Take[ap, 3], h@Last@ap } ], AxesOrigin -> {0, 0}, PlotRange -> {f@0, 1 + f@Max@ap}, ImageSize -> 500 ];BobbyOn Tue, 11 Feb 2003 04:42:14 -0500 (EST), Allan Hayes > Baruch,> The basic problem is that Plot decides what kind of expression {t} is > before> evaluating {t}. In this case it decides that Flatten[{t}] must be a list > of> one real number for the sample values of x that it uses. This is not so, > in> fact Flatten[{t}] becomes a list of several real numbers.> We can supply Plot with information to make the correct decision by > causing> {t} to evaluate before is makes its decision ( I have included f[x] in > the> plot, and used df = f' (note =, not :=) to avoid evluating f' at each> iteration).> You might like to consider avoiding the use of Plot for the tangent > lines> by adding fo each approximation,a, Line[{a,f[a]},{b,0}] where {b,0} is> where the tangent at a meets the x-axis -- Epilog might be used.f[x_] := x^2 - 2> Ne[x_] := x - f[x]/f'[x]> ap = NestList[Ne, 4., 5]> tang[h_] := f[h] + f'[h]*(x - h)> t = tang /@ apPlot[Evaluate[Prepend[t, f[x]]], {x, -5, 5},> AxesOrigin -> {0, 0}, PlotRange -> {-3, f[4]}]Allan---------------------> Allan Hayes> Mathematica Training and Consulting> Leicester UK> www.haystack.demon.co.uk> hay@haystack.demon.co.uk> Voice: +44 (0)116 271 4198> f[x_] := x^2 - 2>> Ne[x_] := x - f[x]/f'[x]>> ap = NestList[Ne, 1.5, 5]>> tang[h_] := f[h] + f'[h](x - h)>> t = tang /@ ap>> Plot[{t}, {x, -10, 10}, AxesOrigin -> {0, 0},>> PlotRange -> {{-5, 5}, {-3, 5}}]>> Now, How can I plot the last command?>> I got the following errors:>> Plot::plnr: !(te[x]) is not a machine-size real number at>> !(x) = >> !(-9.999999166666667`).>> Plot::plnr: !(te[x]) is not a machine-size real number at>> !(x) = >> !(-9.188660168541684`).>> I want to make a program that will plot the successives tangent>> lines of approximations of any function (when possible) using the>> Newton Methods... any idea on how can I implement or solve that>> problem?>>-- majort@cox-internet.comBobby R. Treat ==== >Why when I save a notebook, the input output disappears? I assume the input output disappears means the In[n] and Out[n] that appears to the left of an expression after it is evaluated by Mathematica. I also assume, by save you mean save, *close* then re-open the particular notebook.Basically, the In[] and Out[] are pointers to memory where the results of an expression reside. While you have the notebook open (before closing it) there is a clear link between the contents of memory and expressions in that notebook that have been executed. Once the notebook is closed, that link is severed. There is no practical way to re-link expressions in a notebook to the location in memory where the results are once the notebook as been closed.>Is there any way to correct this?Assuming I've understood your question properly, no. But I am curious as to what you are trying to do that prompts the question. ==== It is true... If you don't specify direction, the direction is automaticallychosen as -1(I think), so you can't trust Limit without checking the twodirections.So in your example, the limit effectively does not exist !Here a limit function if direction is not specified that is not bad fortypically school-type examples :In[14]:=limReal[y_, x_ -> a_] := If[Limit[y, x -> a, Direction -> 1] == Limit[y, x -> a, Direction -> -1] && Im[y /. x -> a + 10^(-6)] == 0 && Im[y /. x -> a - 10^(-6)] == 0, Limit[y, x -> a], doesn't exist !]a[x_]:=1/xIn[15]:=limReal[a[x], x -> 0]Out[15]=doesn't exist !Meilleures salutationsFlorian Jaccardprofesseur de Math.8ematiquesEICN-HES-----Message d'origine-----Envoy.8e : mar., 11. f.8evrier 2003 10:47è : mathgroup@smc.vnet.netObjet : Limits: Is there something I'm missing Here?Dear all,One thing I've noticed that if we have a function which has two differentlimits (given two different directions) at one points , mathematica would bestill give an answer though to my understanding the limit doesn't exist insuch a case.Consider the following example:a[x_]:=1/xLimit[a[x],x->0,Direction->+1] +InfLimit[a[x],x->0,Direction->+1] -InfLimit[a[x],x->0]. +Inf.... Maybe my calculus knowledge is a bitrusty but does the limit exist in this case?? ==== > One thing I've noticed that if we have a function which has two different> limits (given two different directions) at one points , mathematica would> be still give an answer though to my understanding the limit doesn't> exist in such a case.You're correct. Mathematica _sometimes_ does that. And I think thatbehavior can be terribly deceptive to a naive user!> Consider the following example:> a[x_]:=1/xLimit[a[x],x->0,Direction->+1] +InfYou had probably intended to writeLimit[a[x],x->0,Direction->-1] +Inf> Limit[a[x],x->0,Direction->+1] -InfLimit[a[x],x->0]. +Inf.... Maybe my calculus knowledge is a> bit rusty but does the limit exist in this case??That depends. In an ordinary calculus course, yes, we'd normally just saythat the limit doesn't exist. But a perfect answer should be available toMathematica: ComplexInfinityIf Mathematica doesn't give that, then no answer would be preferable togiving +Infinity, in my opinion.BTW, it amazes me that Mathematica can't even do something as simple asLimit[Floor[x], x->0], even if a Direction of +1 or -1 is specified!David ==== Ashraf,Strictly speaking you are correct. The limit does not exist. But there issuch a thing as a one-sided limit, which is not a true limit but stilluseful.In this case even the one-sided limits do not really exist because theresult is unbounded. But again, it is useful to signify this by saying thatthe limit is infinite. So it is rather loose language by both mathematiciansand Mathematica.Perhaps one of the mathematicians in the group will give you a fullerexplanation.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Limit[a [x],x->0]. +Inf.... Maybe my calculus knowledge is a bitrusty but does the limit exist in this case?? ==== Hi everybody,If I have 9 points in a 2 dimensional space how do I decide if theyfit better a linear function or a logarithmic function?Jay ==== > Apparently Mathematica randomly returns roots a root of a complex number.> Is there a way I can write my own function that will return a set consisting> of all n roots of a given complex number. For example, Root[z,n] = {a set> consisting of n elements}Actually Root is a built-in object -- and it can be used to do what you want. In[1]:= root[n_][z_] := Table[Root[#1^n - z & , k], {k, n}] In[2]:= root[4][1] Out[2]= {-1, 1, -I, I} In[3]:= root[4][1 + I] Out[3]= {Root[#1^8 - 2*#1^4 + 2 &, 1], Root[#1^8 - 2*#1^4 + 2 &, 4], Root[#1^8 - 2*#1^4 + 2 &, 5], Root[#1^8 - 2*#1^4 + 2 &, 8]} In[4]:=N[%] Out[4]={-1.0695539323639858 - 0.21274750472674303*I, -0.21274750472674303 + 1.0695539323639858*I, 0.21274750472674303 - 1.0695539323639858*I, 1.0695539323639858 + 0.21274750472674303*I}Paul ==== > You are in the midst of editing in a cell. You decide you want to> change the style of the cell (e.g. from text to small text). There are> the Alt- shortcuts, but those only seem to work when the cell itself is> selected. On a Macintosh, to change to style of a cell to style number n you use [CommandKey][LeftModified]n[RightModified]If the cursor is inside the cell then you use [OptionKey][CommandKey][LeftModified]n[RightModifi ed] Under Windows, [AltKey] replaces [CommandKey] so I'd try [OptionKey][AltKey][LeftModified]n[RightModified] Paul ==== Good day all, I just installed Signals and Systems package with Mathematica 4.2(Students) on a PC. After installation I did a Rebuild Help Index. Nowwhen I type, in a notebook, the first few letters of a function in thatpackage and hit ctl-K (complete selection) nothing appears in the selectionfrom Signals and Systems package. Same if I do a search for a function inthe help menu, all functions from that package are not listed. For exampleif I look for convolution I get all entries in Digital Image Processing(an installed package) and the entry in the Mathematica book, but nothingfrom Signals and Systems package. Even if I look for a function that I knowthat is in the package, I do not get any entry for it, no help. The add-onsmenu for Signals and Systems package listing stops at the first level ofentries, I mean just the titles are listed and nothing after (nosub-titles...). Am I doing something wrong during installation ? I have four otherpackages installed and the all work correctly.RobertReply-To: kuska@informatik.uni-leipzig.de ==== Hi,no, because Message[] is written in the way, that ic can beswitched on/off and you should rewirte the package tounse Message[] instead of Print[] Jens Group, I have a program with a lot of *Print[Something] * calls imbedded.> This calls are there for intermediate computation tracing purposes; in> other words, I want this in case I need to trace some points in some> instances of some computations, as a (standard) service of my program. But> I would like to be able to disable this printing facility by using some> standard Mathematica variable/option like *DisplayFunction -> Identitiy* if> available. Any clue? > E. Martin-Serrano ==== Emilio,I'm sure you will get a number of suggestions on this. Here is one method.subroutine[range_, fprint_] := Module[{print = fprint, f, x}, f = x^2 - 2x + Sin[x]; print[SequenceForm[Function is , f]]; Plot[f, {x, 0, range}]; ]subroutine[10, Print]subroutine[10, Identity]David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/E. Martin-Serrano ==== Hi Emilio, I have a program with a lot of *Print[Something] * calls > imbedded. > This calls are there for intermediate computation tracing > purposes; in > other words, I want this in case I need to trace some points in some > instances of some computations, as a (standard) service of my > program. But > I would like to be able to disable this printing facility by > using some > standard Mathematica variable/option like *DisplayFunction - Identitiy* if > available. Any clue?You might try setting the program up with an option called Debug. Printingwould then be controlled by statements like:- If[Debug, Print[... stuff ...]];Dave. ==== ====================================== Dr. David Annetts EM Modelling Analyst Australia David.Annetts@csiro.au ==== =================================== ==== ====On occasion I get the exception below in the Tomcat servlet log. I am not conversant in Java and need some kind of pointer. When the error occurs the user's web browser seems to timeout. I suspect that an error in the user's script is causing an error and MSP wants to display it on their browser but cannot because of this missing class.Other than this error the product is working well.We are using Tomcat 3.3.1 but I got the same error from 4.1.17.Daryl Fonseca-Holt - UNIX Software Adminstrator - University of Manitoba2003-02-10 18:39:33 - /webMathematica: MSP: Java::excptn: A Java exception occurred: java.lang.ClassNotFoundException: org.apache.tomcat.facade.HttpServletRequestFacade at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at MSP.evaluateMSP(MSP.java:149) at MSP.processMSP(MSP.java:342) at MSP.doGet(MSP.java:356) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.tomcat.facade.ServletHandler.doService( ServletHandler.java:5 74) at org.apache.tomcat.core.Handler.invoke(Handler.java:322) at org.apache.tomcat.core.Handler.service(Handler.java:235) at org.apache.tomcat.facade.ServletHandler.service( ServletHandler.java:485 ) at org.apache.tomcat.core.ContextManager.internalService( ContextManager.ja va:917) at org.apache.tomcat.core.ContextManager.service( ContextManager.java:833) at org.apache.tomcat.modules.server.Http10Interceptor.processConn ection(Ht tp10Interceptor.java:176) at org.apache.tomcat.util.net.TcpWorkerThread.runIt( PoolTcpEndpoint.java:4 94) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run (ThreadPoo l.java:516) at java.lang.Thread.run(Thread.java:536) . ==== As happens wiht quite a few such cases the problem seems to be with Limit. It still sometimes helps to load in the Calculus`Limit` package. Another useful trick is to evaluate the integral with a finite bound, then use FullSimplify and then take take the limit as the bound goes to infinity.In[1]:=<< Calculus`Limit`In[2]:=FullSimplify[Integrate[x^p/E^x^2, {x, z, t}]]Out[2]=(1/2)*((-t^(1 + p))*ExpIntegralE[1/2 - p/2, t^2] + z^(1 + p)*ExpIntegralE[1/2 - p/2, z^2])So much does not need the limit package and seems correct.In[3]:=Limit[%, t -> Infinity]Out[3]=(1/2)*z^(1 + p)*ExpIntegralE[1/2 - p/2, z^2]The built-in Limit is not able to do evaluate this.ALthough the answer returned by Mathematica does not look like yours I believe they are in fact equal, at least in most of the complex plane (I have not considered this carefully but quick numerical experiments indicate this is almost certainly true). They are not equal for z==0; however in this case Mathematica gives:Integrate[x^p/E^x^2, {x, 0, Infinity}]If[Re[p] > -1, (1/2)*Gamma[(1 + p)/2], Integrate[x^p/E^x^2, {x, 0, Infinity}]]which again agrees with your answer for values of p for which the integral is convergent.Andrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> Consider the following integral...Integrate[x^p*E^(-x^2), {x, z, Infinity}]Using the substitution x = t^2 it is easy to show that the answer is> half the incomplete gamma function, (1/2)*Gamma[(p + 1)/2, z^2].However, if I ask Mathematica to do this integral, here's what I get...Integrate[x^p E^(-x^2), {x, z, Infinity}]> PowerExpand[%]> % /. z -> 0> %% /. z -> InfinityOut[146]=> (1/2)*(z^(p + 1)*Gamma[(p + 1)/2, z^2]*> (z^2)^((1/2)*(-p - 1)) + Gamma[(p + 1)/2])Out[147]=> (1/2)*(Gamma[(p + 1)/2] + Gamma[(p + 1)/2, z^2])Out[148]=> Gamma[(p + 1)/2]Out[149]=> (1/2)*Gamma[(p + 1)/2]This is incorrect. The correct result should be:Out[147]=> (1/2)*Gamma[(p + 1)/2, z^2]>Out[148]=> (1/2)*Gamma[(p + 1)/2]Out[149]=> 0Does anyone understand why Mathematica screws up on such a simple > integral?-Bob Stagat-> -- > ==== Martin,In a post a while ago, I introduced a function called NInverse which oughtto be able to help you out. The message can be found athttp://library.wolfram.com/mathgroup/archive/2001/Jun/ msg00125.htmlThe output of NInverse (in your case) is a function which given a value of yreturns the corresponding value of t.In your case, you would use NInverse something like the following:NInverse[y, {t0,y0}, {yy, ymin, ymax}]You will probably get some error messages, but the answer should be okay.The function NInverse can be improved (witness the inclusion of yy above),and I will post an improved version sometime.Carl WollPhysics DeptU of Washington> Dear NG> Mabye this is too simple, but I cant just figure it out> I want to get an inverse function for y[t] where> y[t_]:=NIntegrate[R[x]^4,{x,0,t}] /. ndsolution[[1]]> and> R[t] is an interpolatingfunction(R>0 from NDSolve) on the interval 0= after that I hope to be able to calculate the integral :> a = (1/y[T])*> NIntegrate[R[InvFunction[y[t]]*Cos[y[t]], {y[t], 0, y[T]}]> it works with a constant instead of R[t].> Hope you can help, and that the above is understandable.> Martin Skogstad ==== There is a very nice java applet athttp://statman.stat.sc.edu/~west/javahtml/classes/ , in which you caninclude your own data by replacing what is in the Applet with your own,which gives you a real time histogram plot and lets you alter the bin widthand see how this effects the histogram....it wasnt until I saw this that iunderstood the significance of choosing the bin width......jerry blimbaum-----Original Message-----http://www.mathstatica.com for details.Obviously, it is less expensive to write your own functions.Just recently in message Mark Fisher posted code that addressesthe empirical CDF. However, in this code you may want to replace 1/n with1/(n+1) or (j-0.5)/n depending on your application. Note, these will have nosignificant effect for large data sets.The key issue with an empirical PDF is deciding the bin width. A simpleapproach would be to use the functions in Statistics`DataManipulation` andBinListCounts. More sophisticated approaches involve kernel methods. Thesemethods will generate smoother estimates for the PDF. Again, the key isbandwidth. There is no apriori choice for bin width or bandwith. Bad choiceswill obscure significant features in the data set. ==== A while back someone asked if Mathematica could plot data one point at atime....most answers were no, with one exception, where someone showed howto use the same Graphic Cell repeatedly....here is some Mathematica, JLinkprogram that will do just that... << JLink` InstallJava[CommandLine -> c:j2sdk1.4.1binjava.exe] (* or setcommand line to where your java.exe is *)UseFrontEndForRendering = False;createWindow[] := Module[{frame}, frame = JavaNew[com.wolfram.jlink.MathFrame, Drawing Sine Wave AnimationOne Point at a Time]; drawArea = JavaNew[com.wolfram.jlink.MathCanvas]; drawArea@setUsesFE[UseFrontEndForRendering]; drawArea@setSize[800, 600];JavaBlock[frame@setLayout[JavaNew[java.awt.BorderLayout ]]; frame@add[drawArea, ReturnAsJavaObject[BorderLayout`CENTER]]; frame@pack[]; points = Range[data // Length] frame@setSize[800, 600]; frame@setLocation[200, 200]; JavaShow[frame]];frame]data = Table[{x, Sin[x]}, {x, -0.0000000000001, 2 Pi, .1}]; frame[n_] := ListPlot[Take[data, {1, n}], PlotRange -> {{0, 2 Pi}, {-1.5, 1.5}}, PlotStyle -> {PointSize[.005], Hue[0]}, DisplayFunction -> Identity] drawPoints[ptNow_] := Show[frame[ptNow], AspectRatio -> Automatic]; points = Range[data // Length];AnimationPlot[pt_List] := JavaBlock[ Block[{frm}, frm = createWindow[]; Map[(obj = drawPoints[#]; drawArea@setMathCommand[obj]; drawArea@repaintNow[]; Pause[0.0001];) &, pt]; ] ] AnimationPlot[points]jerry blimbaum NSWC panama city, ß ==== I never liked the function, but now I have need of it. I hope someone can help me see the way to implement it.For a class I am teaching I want to write a simple function that does a random search for a function's maxima. I feed the function N randomly generated inputs and look at the outputs. Provided N is large enough, the largest of the outputs I obtain should be near the function's maximum value.What I want to be able to do is to identify the input that gave me that largest output. Any ideas?My only idea is this: create a table of pairs {output, input{ and find the element of the table that has the largest first entry. This will give me the input I seek. Is there a slick way of doing this in mathematica?-- Jason Miller, Ph.D.Division of Mathematics and Computer ScienceTruman State University100 East Normal St.Kirksville, MO 63501http://vh216801.truman.edu660.785.7430 ==== Here's one way:argMax::usage = argMax[f, domain] returns the element of domain for which f of that element is maximal -- breaks ties in favor of first occurrence.;SetAttributes[argMax, HoldFirst];argMax[f_, dom_List] := Fold[If[f[#1]>=f[#2], #1, #2]&, First[dom], Rest[dom]]And here's another way (defining it in terms of tupleMax)...tupleMax::usage = tupleMax[list] returns the tuple that is lexicographically maximal.;tupleMax[l_List] := Fold[If[OrderedQ[{#1, #2}], #2, #1]&, First[l], Rest[l]]argMax[f_, dom_List] := tupleMax[{f[#],#}& /@ dom][[2]]--- / FROM Jason Miller AT 02.09.18 06:18 (Today) / ---> I never liked the function, but now I have need of it. I hope > someone can help me see the way to implement it.> For a class I am teaching I want to write a simple function that does > a random search for a function's maxima. I feed the function N > randomly generated inputs and look at the outputs. Provided N is > large enough, the largest of the outputs I obtain should be near the > function's maximum value.> What I want to be able to do is to identify the input that gave me > that largest output. Any ideas?> My only idea is this: create a table of pairs {output, input{ and > find the element of the table that has the largest first entry. This > will give me the input I seek. Is there a slick way of doing this in > mathematica?-- -- -- -- -- -- -- -- -- -- -- -- Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/In science it often happens that scientists say, ÔYou know that's a really good argument; my position is mistaken,' and then they would actually change their minds and you never hear that old view from them again. They really do it. It doesn't happen as often as it should, because scientists are human and change is sometimes painful. But it happens every day. I cannot recall the last time something like that happened in politics or religion. -- Carl Sagan, 1987 CSICOP Keynote AddressReply-To: kuska@informatik.uni-leipzig.de ==== fun[x_, y_] := x^2 + y^2RandomMin[n_Integer] := First[Sort[ {#, fun @@ #} & /@ Table[{Random[], Random[]}, {n}], Last[#1] < Last[#2] &]]should do it. Jens> I never liked the function, but now I have need of it. I hope> someone can help me see the way to implement it.> For a class I am teaching I want to write a simple function that does> a random search for a function's maxima. I feed the function N> randomly generated inputs and look at the outputs. Provided N is> large enough, the largest of the outputs I obtain should be near the> function's maximum value.> What I want to be able to do is to identify the input that gave me> that largest output. Any ideas?> My only idea is this: create a table of pairs {output, input{ and> find the element of the table that has the largest first entry. This> will give me the input I seek. Is there a slick way of doing this in> mathematica?> --> Jason Miller, Ph.D.> Division of Mathematics and Computer Science> Truman State University> 100 East Normal St.> Kirksville, MO 63501> http://vh216801.truman.edu> 660.785.7430Reply-To: murray@math.umass.edu ==== The same principles that allow particular cases for defining a function of a single variable would apply here, because Mathematica applies particular rules before it applies general ones. For example: f[0, y_] := 0 f[2 Pi, y_] := y - 2 f[4 Pi, y_] := y - 4 f[x_, y_] := x^2 + y^3This will do exactly what it looks like it does!If you have a general family of particular cases, say at all even integral multiples of Pi, then you could use something like the following in place of the first three lines above: f[k_ Pi, y_] := y - k /; IntegerQ[k] && EvenQ[k]There are variants as to where to place the condition IntegerQ[k] && EvenQ[k], for example: f[k_ Pi , y_] /; IntegerQ[k] && EvenQ[k] := y - k f[k_ Pi /; IntegerQ[k] && EvenQ[k], y_] := y - k> I have quite an easy and annoying problem with mathematica:> I need to define a function f(x,y) which takes some values for> x=0,2pi,4pi (indepently of y) and has a different expression for all> the other values of y. This is easily done for one-dimensional> functions but I am in serious troubles for my two-dimensional problem:> any suggestion?> Fabio -- Murray Eisenberg murray@math.umass.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375 ==== >>and has a different expression for all the other values of y.Do you mean all the other values of x? You can't expect to makeyourself understood to Mathematica, if you don't say what you mean.Mathematica can't guess, like we can.If that's what you meant, it's really easy:f[0 | N[0], y_] := yf[2*Pi | N[2*Pi], y_] := y^2f[4*Pi | 4.*Pi, y_] := y^3f[x_, y_] := y^4If the first three of those expressions are supposed to be the same, youcan substitutef[0 | N[0] | 2*Pi | N[2*Pi] | 4*Pi | 4.*Pi, y_] := y^3Bobby Treat-----Original Message-----FabioReply-To: kuska@informatik.uni-leipzig.de ==== a) you must change the fonts, because the Mathematica symbols are designed to fit to Times/Helvetica/Courier and not to Computer Modern ! Mixing Computer Modern and the Mathematica fonts look not very nice because Comuter Modern has smaler strokes. You need atleast wrisym.sty, i.e. usepackage[monospacemath]{wrisym} but this will switch the main document font to Times and the mono-space font to courier. With Mathematica 4.2 you can use Adobe-Garamond and Janson as document fonts too, with usepackage[monospacemath,garamond]{wrisym} but this are commercial fonts and you have to buy it from Adobe.b) If you like the narrow monotype fonts similar to Computer Modern you can use the CMTT fonts, now included in Mathematica 4.2 Just use the package option usepackage[cmtt]{wrisym}c) I have a TeX frontend that use only the wrisym package and a preprocessor. It run fine with the most style files But you have to use TeX notebooks that are essential TeX files with mathinput environments. The TeX frontend send the contents of the mathinput environments to the kernel and paste the output into the final TeX file. It also does some fancy formating with the Mathematica input and replace -> with Rule, :> with RuleDelayed .. You can have the program and the style files if you like. Jens> Dear all,> I want to include some Mathematica code in some lecture notes I am writing.> For that purpose, I use the LaTeX style provided with Mathematica. It seems> to be working fine when I produce a document that is just Mathematica code.> The problem - as expected - is that when I include the Mathematica code as> a part of a larger document, there are> (1) clashes with existing packages> (2) some LaTeX elements, such as the equations, start to use the> Mathematica fonts too. My objective would be to typeset a document in> standard LaTeX, where only the Mathematica code has the Mathematica feeling.> Does anyone know of any style available that is completely seperated from> all other LaTeX definitions?> Best> Kyriakos> _____+**+____+**+___+**+__+**+_> Kyriakos Chourdakis> Lecturer in Financial Economics> URL: http://www.qmw.ac.uk/~te9001> tel: (++44) (+20) 7882 5086> Dept of Economics> University of London, QM> London E1 4NS> U.K.Reply-To: kuska@informatik.uni-leipzig.de ==== BeginPackage[ OtherPackage` ]BigVariable::usage=exampleBegin[`Private`]BigVariable= Table[x y,{x,1000},{y,1000}]End[ ]EndPackage[ ]Print[Loading ...];andBeginPackage[ ThisPackage` ]function::usage=exampleBegin[`Private`]function[x_]:= Module[{y}, y=If[x>1000, Needs[OtherPackage`]; OtherPackage`BigVariable[[x]], x] ]End[ ]EndPackage[ ]should do that. Jens> DeclarePackage[OtherPackage`, {BigVariable} ]. The idea was to prevent> the loading of a large file in routine cases. However, when ThisPackage`> defines its functions, inside the Private` area, it includes a conditional> call to BigVariable. It turns out that OtherPackage is loaded when that> function is defined. I was wondering if there is a way to avoid this.> Roughly speaking, here is the setting:> BeginPackage[ OtherPackage` ]> BigVariable::usage=example> Begin[Private`]> BigVariable=Table[x y,{x,1000},{y,1000}]> End[ ]> EndPackage[ ]> BeginPackage[ ThisPackage` ]> function::usage=example> Begin[Private`]> function[x_]:=Module[{y},> y=If[x>1000,BigVariable[[x]],x] ]> End[ ]> EndPackage[ ]> I don't want OtherPakage to be loaded unless function[x] is called with> x>1000 but it loads when function is defined. Any ideas? Nicholas ==== Dynamic programming might help: replace the line defining BigVariablewithBigVariable:=BigVariable=Table[x y,{x,1000},{y,1000}]Then the table will not be calculated unless it is needed.(See the section on Functions that Remember Values They Have Found, 2.4.9in the Mathematica Book).John Jowett> DeclarePackage[OtherPackage`, {BigVariable} ]. The idea was to prevent> the loading of a large file in routine cases. However, when ThisPackage`> defines its functions, inside the Private` area, it includes a conditional> call to BigVariable. It turns out that OtherPackage is loaded when that> function is defined. I was wondering if there is a way to avoid this.> Roughly speaking, here is the setting:> BeginPackage[ OtherPackage` ]> BigVariable::usage=example> Begin[Private`]> BigVariable=Table[x y,{x,1000},{y,1000}]> End[ ]> EndPackage[ ]> BeginPackage[ ThisPackage` ]> function::usage=example> Begin[Private`]> function[x_]:=Module[{y},> y=If[x>1000,BigVariable[[x]],x] ]> End[ ]> EndPackage[ ]> I don't want OtherPakage to be loaded unless function[x] is called with> x>1000 but it loads when function is defined. Any ideas?> Nicholas ==== How can I invert a funcion? For example In:=f[h_]:=Exp[-h](a*h+b*h^2);I want to invert it as h as a function of fHow can I do that? Please suggest. Raj ==== Well, you can just solve for h. However, in this case there isn't a symbolicsolution.> How can I invert a funcion? For example> In:=f[h_]:=Exp[-h](a*h+b*h^2);> I want to invert it as> h as a function of f> How can I do that?> Please suggest.> RajReply-To: kuska@informatik.uni-leipzig.de ==== Solve[ f=Exp[-h](a*h+b*h^2),h]will not help you but you can try to invert the seriesexpansion as long as the function is monotonser = Series[Exp[-h](a*h + b*h^2), {h, 0, 4}];InverseSeries[ser, f] Jens How can I invert a funcion? For example> In:=f[h_]:=Exp[-h](a*h+b*h^2);> I want to invert it as> h as a function of f> How can I do that?> Please suggest.> Raj ==== I don't have any idea about how to solve next problem.Back space key when I am in the front end don't workcorrectly. It advances instead of go back and there is pointer mark of the mouse looks like a hand insteadof an arrow, and this don't work fine too.Configuration one? How can I solve this?Note: This problem seems to appear just in myworkspacei mean this not happen for other users. Cesar. __________________________________________________Do you Yahoo!?Yahoo! News - Today's headlineshttp://news.yahoo.com ==== > I don't have any idea about how to solve next problem.> Back space key when I am in the front end don't work> correctly. It advances instead of go back and there is> pointer mark of the mouse looks like a hand instead> of an arrow, and this don't work fine too.> Configuration one? How can I solve this?> Note: This problem seems to appear just in my> workspace> i mean this not happen for other users. >> __________________________________________________> Do you Yahoo!?> Yahoo! News - Today's headlines> http://news.yahoo.com> Pressing the ÔNum'-Key maybe solves your problem: If you switch off the ÔNum Lock' your Ôhand pointer mark' should turn into an Ôarrow pointer mark' and you can place the cursor in a notebook.You get more details on-- Rainer Gruber ==== this thing. Here is what I'm using now:In[1]:=a=ReadList[197-tst.txt,Word,RecordLists->True, WordSeparators->None];In[2]:=ßds={{25,31}, {32,39},{40,46},{47,54},{55,62},{63,70},{71,78},{79,86},{87, 94},{95,102},{103,110}};Define this function:In[3]:=f[x_]:=ToExpression[StringTake[x[[1]],#]]&/@ ßdsNow, map this function onto a:In[8]:=f/@aOut[8]={{5935.8,5946.66,27.06,-1281.9,-229.,321. ,317.,367.,-115.,126.,146.},{5935.8....************The data is now in a matrix of numbers and each variable is in a column.Now I just transpose this to get each variable in a row for easy access (apparentlyMathematica has no way to directly access a column in a matrix, you gotta transpose I think)Rob> I've got to extract some numbers from a file that are in lines of text. Since the line contents are not numbers, I presume I must pull the line out as a string. Here I start by pulling out just one line:> inFile = OpenRead[197-tst.txt]> y = ReadList[inFile, String, 1, RecordLists -> True]> Close[inFile];> This appears to pull in a line. Now I want to take characters 25 to 110 to get just the stuff I want:> y1=StringTake[y ,{25,110}];> Here's the output. StringTake doesn't seem to work.> It doesn't take loading another package as far> as I can tell from the help. I'm thinking that it doesn't work because it's trying to work on a list> rather than a string. I've tried Flatten, and other stuff to try to get to just a string and not a list but> nothing has worked so far. I'm a long way from getting to those numbers in there but heck, I> can't even get to the string. Can anyone point me in the right direction? ==== > The data is now in a matrix of numbers and each variable is in a column.> Now I just transpose this to get each variable in a row for easy access> (apparently Mathematica has no way to directly access a column in a matrix,> you gotta transpose I think)You can use All:In[1]:= mat = {{a,b,c},{d,e,f}};In[2]:= mat[[All,2]]Out[2]= {b, e}--Bhuvanesh,Wolfram Research. ==== Help!After using SetOptions[Graphics3D, ...] I am trying to set the default options of Graphics3D back to what they were when I started up Mathematica. I cannot find a command to do this. Is this possible? ==== o = Options[Graphics3D]; (* save the original options *)SetOptions[Graphics3D, ...]; (* mess with them *)SetOptions[Graphics3D, Sequence@@o]; (* restore them *)--- / FROM David Sagan AT 02.09.18 06:29 (Today) / ---> Help!> After using SetOptions[Graphics3D, ...] I am trying to set the default > options of Graphics3D back to what they were when I started up > Mathematica. I cannot find a command to do this. Is this possible?> -- -- -- -- -- -- -- -- -- -- -- -- Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/The idea of programming in a low level language like C will seem asspecialized and esoteric as programming in microcode or assembler seems today. -- Stephen Wolfram, creator of MathematicaReply-To: kuska@informatik.uni-leipzig.de ==== Hmm,oldOptions=Options[ Graphics3D];SetOptions[Graphics3D,Boxed->False](* do something with it *)SetOptions[Graphics3D, Sequence @@ oldOptions]works fine. Jens> Help!> After using SetOptions[Graphics3D, ...] I am trying to set the default> options of Graphics3D back to what they were when I started up> Mathematica. I cannot find a command to do this. Is this possible?> ==== > This code is almost identical to yours in principle, yet 30% faster:> (compared with the code in your notebook, not the code in the post> below)> ClearAll[emptyTree, treeInsert];> emptyTree = {};> treeInsert[emptyTree, elem_] := {emptyTree, elem, emptyTree}> treeInsert[tree_, elem_] /; SameQ[tree[[2]], elem] := tree> treeInsert[tree_, elem_] /; OrderedQ[{tree[[2]], elem}] :=> {First[tree], tree[[2]], treeInsert[Last[tree], elem]}> treeInsert[tree_, elem_] := {treeInsert[First[tree], elem], tree[[2]], > Last[tree]}> Here's an even simpler version, same speed:> ClearAll[emptyTree, treeInsert];> emptyTree = {};> treeInsert[emptyTree, elem_] := {emptyTree, elem, emptyTree}> treeInsert[tree_, elem_] := Which[> SameQ[tree[[2]], elem], tree, OrderedQ[{tree[[2]], elem}],> {First@tree, tree[[2]], treeInsert[Last@tree, elem]},> True, {treeInsert[First@tree, elem], tree[[2]], Last@tree}]I had tried variations on this but they all seemed ever so slightlyslower. Might be version an OS dependent.> I see one obvious advantage of your algorithm over Husain's and my> earlier code; though I'm not sure it explains its better behavior. That> is, while my algorithm made pattern matching more burdensome, yours> virtually eliminated it.> Also, the biggest improvement I've seen comes simply from replacing Null> with anything else in Husain's code. Again, that seems to suggest that> time spent on pattern matching is the problem. All the algorithms do> approximately the same real work on the tree structure.> I really like how Flatten changes your tree into a sorted list. Very> nice!Goes by the name of tree sort. Using Flatten is basically a shortcutfor walking the tree left-to-right. > Bobby TreatIt seems I did not look hard enough at the original post or thefollow-ups. In point of fact, regarding speed, there IS no obviousadvantage of my code over that first version. The advantage is there, ofcourse, as timing checks indicate. But it is quite far from obvious.The reason is related to the (rare) need for Update. It is pointed outin the manual that infinite evaluation is not in fact possible (nosurprise thus far). A consequence is that Mathematica requires internaloptimization features to keep reevaluation to a minimum. Update may berequired in cases where such optimizations are overzealous.What we have in the case of this example is, roughly, the opposite. Thecode that determines need for reevaluation is simply not workingsufficiently well. It does make the correct determination, but onlyafter looking over the entire structure that is being evaluated. As wehave a structure growing linearly in the number of iterations, and itgets mostly traversed each iteration, the algorithmic complexity becomesat least O(n^2). Not a disaster unless the appropriate complexity issmaller, which was the case for this example.This is not a bug insofar as it is a (regretably) necessary consequenceof Mathematica evaluation semantics. The problems it can cause are allthe same quite undesirable. We've made some inroads on this problem byenlarging substantially the class of expressions for which reevaluationmay be quickly short-circuited, with the idea of fixing all but the mostpathological of examples. The status of that work is unfortunately notknown to me at present, though I'll try to find out about it.Daniel LichtblauWolfram Research ==== This code is almost identical to yours in principle, yet 30% faster:(compared with the code in your notebook, not the code in the postbelow)ClearAll[emptyTree, treeInsert];emptyTree = {};treeInsert[emptyTree, elem_] := {emptyTree, elem, emptyTree}treeInsert[tree_, elem_] /; SameQ[tree[[2]], elem] := treetreeInsert[tree_, elem_] /; OrderedQ[{tree[[2]], elem}] := {First[tree], tree[[2]], treeInsert[Last[tree], elem]}treeInsert[tree_, elem_] := {treeInsert[First[tree], elem], tree[[2]], Last[tree]}Here's an even simpler version, same speed:ClearAll[emptyTree, treeInsert];emptyTree = {};treeInsert[emptyTree, elem_] := {emptyTree, elem, emptyTree}treeInsert[tree_, elem_] := Which[ SameQ[tree[[2]], elem], tree, OrderedQ[{tree[[2]], elem}], {First@tree, tree[[2]], treeInsert[Last@tree, elem]}, True, {treeInsert[First@tree, elem], tree[[2]], Last@tree}]I see one obvious advantage of your algorithm over Husain's and myearlier code; though I'm not sure it explains its better behavior. Thatis, while my algorithm made pattern matching more burdensome, yoursvirtually eliminated it.Also, the biggest improvement I've seen comes simply from replacing Nullwith anything else in Husain's code. Again, that seems to suggest thattime spent on pattern matching is the problem. All the algorithms doapproximately the same real work on the tree structure.I really like how Flatten changes your tree into a sorted list. Verynice!Bobby Treat-----Original Message-----> (delete the lowest value) function and they seem to work ok but arevery> slow. Let's just look @ my implementation of the add part:> nums=Null;(*my initial blank Tree)> In[326]:=> Clear[add]> In[327]:=> add[Null,x_Real]:=node[x,Null,Null]> add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher]> In[328]:=> add[node[x_Real,lower_,higher_],y_Real]:=> If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y] ]]> In[288]:=add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery _,highery_]]:=If[x>y,> node[x,add[lowerx,node[y,lowery,highery]],higherx],> node[x,lowerx,add[higherx,node[y,lowery,highery]]]> ]> Now this is my attempt to test how fast my add works:> SeedRandom[5];> Do[nums=add[nums,Random[]],{5000}];//Timing> Out[333]=> {13.279 Second,Null}> RH7.3> running on an 1.4GHz Athlon with 1GB of ram).> Questions:> 1. Is this as fast as I can get my code to run?> 2. Am I doing something obviously stupid?> 3. would Compiling things help?> HusainI'll respond to your third question first. No, use of Compile will nothelp. You do not have a tensor structure and moreover it will copy itsarguments. Hence invoking it within a loop would be quite slow for aproblem where the argument grows in size.One thing you did not check is the actual run-time complexity of yourcode. On my 15.GHz machine I get:In[6]:= SeedRandom[5];In[7]:= ee = Table[Random[], {10000}];In[8]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,1000}];]Out[8]= {0.34 Second, Null}In[9]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,2000}];]Out[9]= {1.28 Second, Null}In[10]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,4000}];]Out[10]= {4.94 Second, Null}In[11]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,8000}];]Out[11]= {25.08 Second, Null}We see this is clearly of no better than quadratic complexity, whereas Iwould guess you were expecting O(n*Log[n]). So this indicates a problem.Offhand I do not know what aspect of your code is responsible, but I'llgive some different code that has the desired complexity.Note that some of this, and code very similar to that below, isdiscussed at:http://library.wolfram.com/conferences/devconf99/lichtblau /in the section entitled Trees.There is a corresponding Mathematica notebook available at:http://library.wolfram.com/conferences/devconf99/near the bottom of the web page.The code I used to implement a tree structure similar to yours is below.One difference is that, as I place node values in the center, when theyare ßattened the tree is automatically sorted. You might (or might not)regard this as an added benefit.leftsubtree[node[left_, _, _]] := leftrightsubtree[node[_, _, right_]] := rightnodevalue[node[_, val_, _]] := valemptyTree = node[];Clear[treeInsert]treeInsert[emptyTree, elem_] := node[emptyTree, elem, emptyTree]treeInsert[tree_, elem_] /; OrderedQ[{nodevalue[tree], elem}] := node[leftsubtree[tree], nodevalue[tree], treeInsert[rightsubtree[tree], elem]]treeInsert[tree_, elem_] := node[treeInsert[leftsubtree[tree],elem], nodevalue[tree], rightsubtree[tree]]Now for some tests.In[40]:= tt1k = First[Timing[ff1k = node[]; Do[ff1k = treeInsert[ff1k, ee[[j]]], {j,1000}];]] Out[40]= 0.15 SecondWe will check that the ßattened version is actually sorted.In[41]:= gg1k = Apply[List,Flatten[ff1k]];In[42]:= gg1k === Sort[Take[ee,1000]]Out[42]= TrueAlso we will observe that the maximum depth is reasonable.In[43]:= Depth[ff1k]Out[43]= 23In the perfectly balanced case it would be 10 so this is not too bad.For larger examples I'll just show timings.In[44]:= tt2k = First[Timing[ff2k = node[]; Do[ff2k = treeInsert[ff2k, ee[[j]]], {j,2000}];]]Out[44]= 0.32 SecondIn[45]:= tt4k = First[Timing[ff4k = node[]; Do[ff4k = treeInsert[ff4k, ee[[j]]], {j,4000}];]]Out[45]= 0.73 SecondIn[47]:= tt8k = First[Timing[ff8k = node[]; Do[ff8k = treeInsert[ff8k, ee[[j]]], {j,8000}];]]Out[47]= 1.58 SecondIn[53]:= SeedRandom[5]; ee = Table[Random[], {32000}];In[54]:= tt32k = First[Timing[ff32k = node[]; Do[ff32k = treeInsert[ff32k, ee[[j]]], {j,32000}];]]Out[54]= 7.58 SecondThis is not of blinding speed but it has the advantage of exhibiting theappropriate run-time complexity. One can, with careful coding, cut downon tree size but if you check with LeafCount you will find that theversion above is already not too wasteful (3x larger than #valuesstored). Moreover the code needed would run a bit slower as it wouldhave more cases to check.As for removing nodes, I think you will need to use some form of heldattribute so as to avoid copying the entire tree when you alterelements.Daniel LichtblauWolfram Research ==== Daniel,I'd say your algorithm (as an ALGORITHM) is precisely the same asHusain's. The implementation is different, but the logical steps arethe same (except perhaps for <= vs. <), and so is the logical structureof the tree produced. Even the storage method is pretty much the same.Using {} instead of Null and List instead of Ônode', and putting valuesin the middle position, doesn't add up to a change that could affectalgorithmic complexity.Even the fact that Flatten gives a sorted List with your implementationis something you get for free, and the advantage comes only when it'stime to output a sorted list. It has nothing to do with the work ofbuilding the tree.Algorithmic complexity (absent hidden factors under the kernel'scontrol) is precisely the same for your solution and Husain's (mine too,I think). The speed differences we're seeing have to do with nuances ofthe kernel, pattern matching costs, etc. Our three nearly equivalentalgorithms simply incur different hidden costs.That's the case with many of the problems that turn into speed warsamong us. We compare implementation speed (including hidden costs), notpure algorithmic complexity. Compiled code or packed arrays often makeall the difference, and it usually happens in the background where wecan't see it.As you've hinted below, the vagaries of Update can make a linearalgorithm quadratic, but may NOT so plague a slightly differentimplementation of the very same algorithm.So... I'm suggesting we might want to be careful when we leap toconclusions about algorithmic complexity based on a few timedexperiments.Bobby Treat-----Original Message-----> ClearAll[emptyTree, treeInsert];> emptyTree = {};> treeInsert[emptyTree, elem_] := {emptyTree, elem, emptyTree}> treeInsert[tree_, elem_] /; SameQ[tree[[2]], elem] := tree> treeInsert[tree_, elem_] /; OrderedQ[{tree[[2]], elem}] :=> {First[tree], tree[[2]], treeInsert[Last[tree], elem]}> treeInsert[tree_, elem_] := {treeInsert[First[tree], elem], tree[[2]],> Last[tree]}> Here's an even simpler version, same speed:> ClearAll[emptyTree, treeInsert];> emptyTree = {};> treeInsert[emptyTree, elem_] := {emptyTree, elem, emptyTree}> treeInsert[tree_, elem_] := Which[> SameQ[tree[[2]], elem], tree, OrderedQ[{tree[[2]], elem}],> {First@tree, tree[[2]], treeInsert[Last@tree, elem]},> True, {treeInsert[First@tree, elem], tree[[2]], Last@tree}]I had tried variations on this but they all seemed ever so slightlyslower. Might be version an OS dependent.> I see one obvious advantage of your algorithm over Husain's and my> earlier code; though I'm not sure it explains its better behavior.That> is, while my algorithm made pattern matching more burdensome, yours> virtually eliminated it.> Also, the biggest improvement I've seen comes simply from replacingNull> with anything else in Husain's code. Again, that seems to suggestthat> time spent on pattern matching is the problem. All the algorithms do> approximately the same real work on the tree structure.> I really like how Flatten changes your tree into a sorted list. Very> nice!Goes by the name of tree sort. Using Flatten is basically a shortcutfor walking the tree left-to-right. > Bobby TreatIt seems I did not look hard enough at the original post or thefollow-ups. In point of fact, regarding speed, there IS no obviousadvantage of my code over that first version. The advantage is there, ofcourse, as timing checks indicate. But it is quite far from obvious.The reason is related to the (rare) need for Update. It is pointed outin the manual that infinite evaluation is not in fact possible (nosurprise thus far). A consequence is that Mathematica requires internaloptimization features to keep reevaluation to a minimum. Update may berequired in cases where such optimizations are overzealous.What we have in the case of this example is, roughly, the opposite. Thecode that determines need for reevaluation is simply not workingsufficiently well. It does make the correct determination, but onlyafter looking over the entire structure that is being evaluated. As wehave a structure growing linearly in the number of iterations, and itgets mostly traversed each iteration, the algorithmic complexity becomesat least O(n^2). Not a disaster unless the appropriate complexity issmaller, which was the case for this example.This is not a bug insofar as it is a (regretably) necessary consequenceof Mathematica evaluation semantics. The problems it can cause are allthe same quite undesirable. We've made some inroads on this problem byenlarging substantially the class of expressions for which reevaluationmay be quickly short-circuited, with the idea of fixing all but the mostpathological of examples. The status of that work is unfortunately notknown to me at present, though I'll try to find out about it.Daniel LichtblauWolfram Research ==== I'm curious, why the built-in boolean functions And and Oraren't commutative?Attributes/@{Or,And}//ColumnForm {Flat, HoldAll, OneIdentity, Protected} {Flat, HoldAll, OneIdentity, Protected} However, the arithmetical functions are Orderless:Attributes/@{Plus,Times}//ColumnForm {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}{Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}-------------------Evgeni TrifonovVladivostok, Russia ==== Evgeni,Note that both And and Or can return a value without evaluating all oftheir arguments. For example, if the first argument to And is False, thereis no reason to look at the other arguments. Suppose a user knows that oneof the arguments is usually false, and so would like to look at thatargument before any of the others, to avoid unneeded computations of theother arguments. He would put that argument first. If Mathematica turnedaround and sorted the arguments (which is what happens when a function isorderless), then that argument might end up being evaluated last. If thearguments take a significant amount of time to compute, then sorting firstmay cause the function to take much longer to evaluate.At any rate, if the above is not a concern for you, you may always changethe attributes of And and Or to anything you want.Carl WollPhysics DeptU of Washington----- Original Message -----> However, the arithmetical functions are Orderless:> Attributes/@{Plus,Times}//ColumnForm> {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}> {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}> -------------------> Evgeni Trifonov> Vladivostok, Russia ==== I have defined two functions (Math 4.1)In[1]:= integrate[c_ y_,t_]:=c*integrate[y,t]/;FreeQ[c,t];In[2]:= integrate[Exp[(a_.)*tau], t_]:=(E^(a*t)-1)/a/; FreeQ[a,t]&&FreeQ[a,tau];when I applied these functions the solution is different if the coefficient is the letter d or lower (solution fine) or f or higher (solution wrong) . Here is an example: Using letter fIn[3]:=integrate[f Exp[-0.8316*tau], t]Out[3]:=integrate[f, t]/E^(0.8316*tau) (*wrong*)Using letter a (the solution is rigthIn[4]:=integrate[a Exp[-0.8316*tau], t]Out[4]:=-1.20250*a*(-1 + E^(-0.8316*t))What it wrong?GuillermoSanchez--------------------------------------- ------This message was sent using Endymion MailMan. ==== Neither of your solutions are wrong according to your rules.Lets step through themIn[3]:=integrate[f Exp[-0.8316*tau], t]lexographical (sp) order asIn[3]:=integrate[Exp[-0.8316*tau] f, t]It then applies rule 1:integrate[c_ y_,t_]:=c*integrate[y,t]/;FreeQ[c,t]Well, The term Exp[-0.8316*tau] contains no t, so according to yourrule it is equal toExp[-0.8316*tau] integrate[f, t]At this point none of your rules apply, so the kernel stops.When you use a instead of f the ordering of the constant and theexponential are reversed, and you get the behaviour that you actuallydesired. A simple fix is to replace the condition in rule 1 byFreeQ[c,t]&&FreeQ[c,tau]You may however want to think carefully about exactly what you want yourfunction integrate to do. For example, with the rules given, thevariable t and the variable tau seem to be playing the same role.Erich> I have defined two functions (Math 4.1)> In[1]:= integrate[c_ y_,t_]:=c*integrate[y,t]/;FreeQ[c,t];> In[2]:= integrate[Exp[(a_.)*tau], t_]:=(E^(a*t)-1)/a/;> FreeQ[a,t]&&FreeQ[a,tau];> when I applied these functions the solution is different if the coefficient is> the letter d or lower (solution fine) or f or higher (solution wrong) . Here is> an example:> Using letter f> In[3]:=integrate[f Exp[-0.8316*tau], t]> Out[3]:=integrate[f, t]/E^(0.8316*tau) (*wrong*)> Using letter a (the solution is rigth> In[4]:=integrate[a Exp[-0.8316*tau], t]> Out[4]:=-1.20250*a*(-1 + E^(-0.8316*t))> What it wrong?> Guillermo> Sanchez> ---------------------------------------------> This message was sent using Endymion MailMan. ==== << Graphics`ImplicitPlot`does the job.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: Mittwoch, 18. September 2002 08:09An: mathgroup@smc.vnet.netBetreff: Drawing an ellipseI am new with Mathematica, I have one question,I know that the sollution might be very easy, but I wasn't able tofind it by now.I would like to draw an ellipse, the formula let's say is as follows:0.09 x^2 +0.04 x y + 0.06 y^2 = 4Maciej ==== Solve[eqn, var] and InverseFunction are designed to do what you want, inprinciple. TrySolve[(a*h+b*h^2) == f, h]For your eqn, however, it is impossible to solve for h since h appears as afactor in a sum *and* as an exponent.TrySolve[Exp[-h]*(a*h+b*h^2) == f, h] and study Mathematica's message.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: Mittwoch, 18. September 2002 08:10An: mathgroup@smc.vnet.netBetreff: Invert a function How can I invert a funcion? For example In:=f[h_]:=Exp[-h](a*h+b*h^2);I want to invert it as h as a function of fHow can I do that? Please suggest. Raj ==== > Map[(obj = drawMembrane[#];> drawArea@setMathCommand[obj];> drawArea@repaintNow[];> Pause[.0001];) &, t ]This is the exact code you use?Maybe I am missing something here, but you seem to pass onlythe String obj to the setMathCommand method, not the contentof the obj variable;> public class My_DisplayGraphicsViaJava {> public void displayGraphics(String cmds[]) { > for (int i = 0; i < cmds.length-1; i++) > drawArea.setMathCommand(cmds[i]);> drawArea.repaintNow();> Thread.sleep(200);} }er... this won't work; you are using the drawArea variable, withoutever declaring or assigning something to it!pff... hm... you could try this:import com.wolfram.jlink.MathCanvas;public class My_DisplayGraphicsViaJava { public static void displayGraphics(String cmds[], MathCanvas drawArea){ for (int i = 0; i < cmds.length-1; i++){ drawArea.setMathCommand(cmds[i]); drawArea.repaintNow(); Thread.sleep(200); } } }save this to a file called My_DisplayGraphicsViaJava.javaand compile it. Put the class file in a directory that is inyour CLASSPATH (or look up how the CLASSPATH works in J/Link2.0 in the J/Link documentation, its properly explained there);If all that has worked, load the class:LoadJavaClass[My_DisplayGraphicsViaJava];then use the static method displayGraphics, by passing it theString array and the drawArea variablen (which is the MathCanvasobject, you have instantiated in your Mathematica Notebook):My_DisplayGraphicsViaJava`displayGraphics[obj, drawArea];obj being the String array (or string List in M_) that holds yourGraphics Expressions (or what you want to show);> But needless to say this dont work....LoadJavaClass responds by saying Class> not Found.....so what should I do to correct this? Also , on the java> routine, was i supposed to add: Extends MathFrame, etc....how will my> java routine know what drawArea.setMathCommand is, etc..... > am I also supposed to compile my java routine?Yes! ... use the Java code I proposed above, that should at leastcompile properly;Place the compiled class file in a directory on your CLASSPATH (consultJ/Link docu if you don't know about CLASSPATH) and then try theMathematica code again.I hope this was not too confusing;I don't have a working Mathematica here, so I can't verify, if my proposed code would really work; there migth be typos/errors in mycode.murphee ==== I am trying to write an animation using JLink.....basically asfollows...(using Mathematica 4.1, JLink 2.01 and java 1.4.1)...frm = createWindow[]; (* basically to create a MathFrame and a drawArea= MathCanvas *)Here is my drawing routine.... Map[(obj = drawMembrane[#];drawArea@setMathCommand[obj]; drawArea@repaintNow[]; Pause[.0001];) &, t ]t = time list ={0,.25,etc}.... and drawMembrane is a function that uses thetime value to make a graphics plot......unfortunately, this routine drawsthe next time plot very slowly, plus I also notice that without the Pause[]statement, Mathematica only draws the graph for the final time value...Following an example in the JLink documentation, I have written thefollowing java routine....which I saved in the same dir as MathFrame,etc....public class My_DisplayGraphicsViaJava { public void displayGraphics(String cmds[]) { // declare String Arrayfor Graphics Objects for (int i = 0; i < cmds.length-1; i++) drawArea.setMathCommand(cmds[i]); drawArea.repaintNow(); Thread.sleep(200);} }and then in Mathematica I have LoadJavaClass[My_DisplayGraphicsViaJava];My_ DisplayGraphicsViaJava`displayGraphics[obj]; (* where obj is thearray of Graphics plots created *)But needless to say this dont work....LoadJavaClass responds by saying Classnot Found.....so what should I do to correct this? Also , on the javaroutine, was i supposed to add: Extends MathFrame, etc....how will myjava routine know what drawArea.setMathCommand is, etc.....am I alsosupposed to compile my java routine? thanks....jerry blimbaum NSWC panama city, ß ==== Dear colleagues,I'm trying to plot the next exponential functionPlot[Exp[1/(Abs[x-1]-Abs[x-2])],Range]If the Range is positive there arenÇt problems. However if the Range isnegative Mathematica plots a strange beast...Have anyone found anything of this sort? I would apreciate to know how toresolve this problem.Juan Egea GarciaBullas - Murcia - Espa.96a ==== The function you are plotting is constant for negative x. You might wantto specify a plotrange, such as PlotRange->{0,2}, or Mathematica may tryto zoom in on the line and show you a picture of numerical noise.Erich> Dear colleagues,> I'm trying to plot the next exponential function> Plot[Exp[1/(Abs[x-1]-Abs[x-2])],Range]> If the Range is positive there arenÇt problems. However if the Range is> negative Mathematica plots a strange beast...> Have anyone found anything of this sort? I would apreciate to know how to> resolve this problem.> Juan Egea Garcia> Bullas - Murcia - Espa.96a ==== I need to solve algebraic-differential-equations(some of index 1, maybe some of higher index as well)from within Mathematica 4.2.Is there an implementation of numerical (like DASSL)or symbolic algorithms capable of doing that around?I know that some numerical software systems whichmay have DASSL-routines that do whatI want. Has anybody suggestions on which of thesesystems is easy to interface with Mathematica?Is there a C++ library that contains such routines and can beinterfaced with Mathematica? Yours, Reinhard Oldenburg ==== > I need to solve algebraic-differential-equations> (some of index 1, maybe some of higher index as well)> from within Mathematica 4.2.> Is there an implementation of numerical (like DASSL)> or symbolic algorithms capable of doing that around?> I know that some numerical software systems which> may have DASSL-routines that do what> I want. Has anybody suggestions on which of these> systems is easy to interface with Mathematica?> Is there a C++ library that contains such routines and can be> interfaced with Mathematica?Reinhard,have you tried the NDAESolve package that comes with the circuitanalysis toolbox Analog Insydes? You can get a free evaluation versionof Analog Insydes from www.analog-insydes.de. Eckhard Hennig ==== Dear Colleagues,I intend to make an animation in which ball A rolls down on an inclined plane from the left whilstball B - starting from the same height - rolls down Cosh[t]'s path from theright.x-axis is time t, y-axis is height h.Ball A is fine; ball B - which should arrive at h=0 before A - is beyond mymeans.Matthias BodeSal. Oppenheim jr. & Cie. KGaAKoenigsberger Strasse 29D-60487 Frankfurt am MainGERMANYMobile: +49(0)172 6 74 95 77Internet: http://www.oppenheim.de ==== Matthias,The simplest way to get the equation of motion is to set up the Lagrangian. Let's assume a 1 kg mass. Then the kinetic energy is KE = Simplify[(1/2)*(x'[t]^2 + D[Cosh[x[t]],t]^2)]and the potential energy is PE = 9.8*Cosh[x[t]]The Lagrangian is L = KE - PEand the equation of motion is diffeq = Simplify[ D[D[L, x'[t]], t] ] == Simplify[ D[L, x[t]] ]Now solve and animate ... xx[t_] = x[t]/. First[ NDSolve[{diffeq, x[0] == -1, x'[0] == 0}, x[t], {t, 0, 5}]] curve = Plot[Cosh[x], {x, -1, 1}] Do[ Show[curve, Graphics[Disk[{xx[t], Cosh[xx[t]]}, 0.025]], PlotRange -> {{-1.2, 1.2}, {0.9, 1.65}}, AspectRatio -> Automatic, Axes->None], {t, 0, 5, 0.1}]----Selwyn Hollis> Dear Colleagues,> I intend to make an animation in which > ball A rolls down on an inclined plane from the left whilst> ball B - starting from the same height - rolls down Cosh[t]'s path from the> right.> x-axis is time t, y-axis is height h.> Ball A is fine; ball B - which should arrive at h=0 before A - is beyond my> means. Matthias Bode> Sal. Oppenheim jr. & Cie. KGaA> Koenigsberger Strasse 29> D-60487 Frankfurt am Main> GERMANY> Mobile: +49(0)172 6 74 95 77> Internet: http://www.oppenheim.de> ==== Having noticed your statement ... BEYOND MY MEANS I thing you aren't yetfamiliar with Lagrangian formalism. It's quite easy to derive a generalequation of motion for a point mass, subjected to gravity and to moving on acurve f = y(x) (i.e. f = Cosh[#]&).1) I'll leave re-deriving equation to you, here is what I've got (just copypaste it).:!(getEq[ f_] := [IndentingNewLine](x'')[ t] + (x')[t]^2 (2 (f')[x[t]] (f'')[x[t]])/(1 +(f')[x[t]]^2) + (g (f')[x[t]])/(1 + (f')[x[t]]^2) == 0 /. g ->1)2) Next, you integrate it .:getSol[f_, x0_] := Module[{tStop}, NDSolve[{getEq[f], x[0] == x0, x'[0] == 0} , x , {t, 0, 10} , MaxStepSize -> 1/100 , StoppingTest :> If[x0 < 0, x > 0, x < 0] ] // First ]3) Here follows animation code, specially for linear versus cosh case, applymy initial conditions (below)makeDuo[f_, g_, x0_, fpt_] := Module[{ solf = getSol[f, x0], solg = getSol[g, x0], tf, tg, maxT, minT }, tf = solf[[1, 2, 1, 1, 2]]; tg = solg[[1, 2, 1, 1, 2]]; maxT = Max[{tf, tg}]; minT = Min[{tf, tg}]; Do[ Plot[{f@x, g@x} , {x, 0, x0} , AspectRatio -> Automatic , Frame -> True , Axes -> False , Epilog -> { AbsolutePointSize[10], Hue[0], Point[{x[t], f@x[t]} /. solf], Hue[.6], Point[{x[t], g@x[t]} /. solg] } ] , {t, 0, minT, minT/fpt} ] ]4) My initial conditions. In my opinion, you weren't true on this. Saying STARTING FROM THE SAME HEIGHT is not enough - you should specify x aswell, thus specifing starting POINT and not just height y.makeDuo[(Cosh[1.] - 1) # &, Cosh[#] - 1 &, 1, 23]Feel free to modify the code, it should be easy.bye,Borut| Dear Colleagues,|| I intend to make an animation in which|| ball A rolls down on an inclined plane from the left whilst|| ball B - starting from the same height - rolls down Cosh[t]'s path fromthe| right.|| x-axis is time t, y-axis is height h.|| Ball A is fine; ball B - which should arrive at h=0 before A - is beyondmy| means.||| Matthias Bode| Sal. Oppenheim jr. & Cie. KGaA| Koenigsberger Strasse 29| D-60487 Frankfurt am Main| GERMANY| Mobile: +49(0)172 6 74 95 77| Internet: http://www.oppenheim.de|| ==== As I derived a generalization for a 3D parameterized curve yesterday, I'dnoticed a mistake in my equation posted below, a factor Ô2' in expressioninvolving x'[t]^2, should be Ô1'.Since this forum is of an alt. type, I've published the whole notebook athttp://www2.arnes.si/~gljpoljane22/math/ FallingCurve3D.nbBye,Borutp.s. A Ôfill-the-gap' riddle for those interested in physics lore. RichardFeynman once said:Science is like _ _ _, sometimes something useful comes out, but that isnot the reason why we are doing it.| ...| 1) I'll leave re-deriving equation to you, here is what I've got (justcopy| paste it).:|| !(getEq[| f_] := [IndentingNewLine](x'')[| t] + (x')[t]^2 (2 (f')[x[t]] (f'')[x[t]])/(1 +| (f'| )[x[t]]^2) + (g (f')[x[t]])/(1 + (f')[x[t]]^2) == 0 /. g ->| 1)| ... ==== David,There is no command such as RestoreDefaults. But you can do the following:saveGraphics3DOptions = Options[Graphics3D];SetOptions[Graphics3D, Boxed -> False]; (say)Make your plots.SetOptions[Graphics3D, Sequence @@ saveGraphics3DOptions];The example in the Help for SetOptions shows a similar example.My own personal preference would be to not change the Graphics3D options,but to add the option change to the plot itself.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== I have the following code and am trying to include a legend. The BarChartappears, but with no legend. I have followed the Ôhelp files', but I thinkI'm missing something.In my code, SortTime and SessTime are value pairs. Photog is a string arraycontaining labels./* *Begin code here */ ShowLegend[BarChart[SortTime, SessTime, BarSpacing -> -.3,, BarGroupSpacing -> .5, BarLabels -> Photog, BarStyle -> {RGBColor[1, 0, 0], RGBColor[0.5, 0.5, 1]}, PlotLabel -> Photographer Time , DefaultFont -> {Helvetica, 9}], {{{RGBColor[1, 0, 0], Sort Time }, {RGBColor[0.5, 0.5, 1], Session Time }}, LegendLabel -> Mean Time}]pete ==== How's this:maxima[f_, x_List] := Last@Sort@({f[#], #} & /@ x)maxima[Sin,Range[0,2Pi,0.1]]{0.999574,1.6}That gives you both f[x] and x at the maximum.Bobby Treat-----Original Message-----that largest output. Any ideas?My only idea is this: create a table of pairs {output, input{ and find the element of the table that has the largest first entry. This will give me the input I seek. Is there a slick way of doing this in mathematica?-- Jason Miller, Ph.D.Division of Mathematics and Computer ScienceTruman State University100 East Normal St.Kirksville, MO 63501http://vh216801.truman.edu660.785.7430 ==== want base 12 numbers, for instance, stored in -- a List of digits? Acharacter string? A list of digits, highest power to lowest, is easy tohandle:ClearAll[convertBase]convertBase[(from_Integer)? (#1 > 1 & ), (to_Integer)?(#1 > 1 & ), n:{_Integer..}] /; Max[n] < from := from], to]convertBase[5, 3, {1, 2}]{2, 1}Bobby Treat-----Original Message-----example,ConvertBase[from_, to_, num_]would convert from base to base 9 using the number num as the number toconvert (it would best be allowed to let users input in that specificbasesince they'd be going from base 3 to base 9, for example so maybe num isneeded at all). ==== This came up some time ago. Can't remember exactly what my reply was but Idiscovered later that it is because the number lock is on. Turn it off andthe hand will disappear. May even fix the back space trouble.Yas> I don't have any idea about how to solve next problem.> Back space key when I am in the front end don't work> correctly. It advances instead of go back and there is> pointer mark of the mouse looks like a hand instead> of an arrow, and this don't work fine too.> Configuration one? How can I solve this?> Note: This problem seems to appear just in my> workspace> i mean this not happen for other users.>> __________________________________________________> Do you Yahoo!?> Yahoo! News - Today's headlines> http://news.yahoo.com ==== I believe that's not the adjacency matrix Thomas asked for. It doesn'thave zeroes on the diagonal (it isn't square) and it doesn't have onesto indicate that two actors are associated with the same event.Instead, it shows connections between actors and events, which isactually more useful, as I'll demonstrate.(In addition -- though it doesn't really matter -- Jens-Peer switchedthe Ôactors' and Ôevents' nomenclature within the function.)If you multiply it by its transpose, you get something else that'suseful:lst = {{1, A}, {1, B}, {2, B}, {3, C}, {3, D}, {1, D}, {1, C}};AdjacenceMatrix[lst : {{_, _} ..}] := Module[{actors, events, adj}, {actors, events} = Union /@ Transpose[lst]; adj = Table[0, {Length[actors]}, {Length[events]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, events]]; adj]MatrixForm[a = AdjacenceMatrix[lst]]MatrixForm[b = a.Transpose[a]]Matrix Ôb' records how many events two actors have in common. On thediagonal, it shows the total number of events each actor is connectedto.It's easy to put zeroes on the diagonal:MatrixForm[c = b (1 - IdentityMatrix[Length[b]])]To get the originally intended incidence matrix, this works:d = c /. {_?Positive -> 1}However, I think matrices Ôa' and Ôb' are actually more useful, and Ôa'easily leads to all the others.Bobby-----Original Message-----AdjacenceMatrix[lst : {{_, _} ..}] := Module[ {actors,events adj}, {events, actors} = Union /@ Transpose[lst]; adj = Table[0, {Length[events]}, {Length[actors]}]; Scan[(Part[adj, Sequence @@ #] = 1) &, lst /. MapIndexed[Rule[#1, First[#2]] &, actors]]; adj ]you getIn[]:=AdjacenceMatrix[lst]Out[]={{1, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}} Jens> I need to create an adjacency matrix from my data, which is currentlyin> the form of a .txt file and is basically a two column incidence list.> For example:> 1 A> 1 B> 2 B> 3 C> . .> . .> . .> m n> Where 1 to m represent actors and A to n represent events. My goal isto> have an (m x m) matrix where cell i,j equals 1 if two actors are> incident to the same event (in the sample above, 1 and 2 are both> incident to B) and 0 otherwise (w/ zeros on the diagonal).> I'm new to Mathmatica, and so I'm on the steep part of the learning> curve ... All I've been able to figure out so far is how to get my> incidence list into the program using Import[filename.txt]. But then> what? How do I convert to the adjacency matrix? I've found the> ToAdjacencyMatrix[] command in DiscreteMath`Combinatorica`, but Ican't> seem to get it to work ... Tom> **********************************************> Thomas P. Moliterno> Graduate School of Management> University of California, Irvine> tmoliter@uci.edu> ********************************************** ==== Maybe this will help. I had to do some guessing, and I fabricated myown R function (r). I never start user-defined symbols with capitalletters.ClearAll[r]t = Pi/2.;r = Interpolation[{#, Abs@Cos@#} & /@ Range[0, N@t, Pi/100.]];y[z_] := NIntegrate[r[x]^4, {x, 0, z}]Timing[yInverse = Interpolation[{y[#], #} & /@ Range[0, N@t, Pi/100.]];]{0.030999999999998806*Second, Null}a = NIntegrate[r[yInverse[z]*Cos[z]], {z, 0, y[t]}]/y[t]0.9249048118568042Bobby Treat-----Original Message-----a = (1/y[T])* NIntegrate[R[InvFunction[y[t]]*Cos[y[t]], {y[t], 0, y[T]}]it works with a constant instead of R[t]. Hope you can help, and that the above is understandable.Martin Skogstad ==== << Graphics`ImplicitPlot`eqn = 0.09*x^2 + 0.04*x*y + 0.06*y^2 == 4; maxX = 1.1*Sqrt[4/0.09]; ImplicitPlot[eqn, {x, -maxX, maxX}];You could also use ParametricPlot:polarEqn = eqn /. {x -> r Sin[t], y -> r Cos[t]}radius[t_] = r /. Last@Solve[polarEqn, r]ParametricPlot[radius[x]{Cos[x], Sin[x]}, {x, 0, 2Pi}, AspectRatio ->1];I tried and failed with InequalityGraphics:<< Graphics`InequalityGraphics`InequalityPlot[{LessEqual @@ eqn}, {x, -xMax, xMax}, {y, -yMax, yMax}]InequalityPlot::region:The region defined by[LeftSkeleton]1[RightSkeleton] could not be broken down intocylinders.InequalityPlot[ 0.09*x^2 + 0.04*x*y + 0.06*y^2 <= 4, {x, -xMax, xMax}, {y, -yMax,yMax}]Plot can be used very neatly, if you first figure out the true extent ofthe x-values:positiveX[y_] = x /. Last@Solve[eqn, x]Solve[positiveX'[y] == 0]xMax = First@(positiveX[y] /. %)Plot[Evaluate[y /. Solve[eqn, y]], {x, -xMax, xMax}, AspectRatio -> 1];Bobby Treat-----Original Message----- ==== That function isn't easily inverted and, in fact, has no inverse unlessyou limit the range of h. In this plot, for instance, you see that thesame f[h] values are taken on for two different values of h:Plot[f@h /. {a -> 3, b -> 0.2}, {h, 0, 10}]The peak of the graph depends on the parameters a and b, so the domainof an inverse (if it exists) also depends on a and b. That's exactlythe kind of situation Solve can't handle.For specific a, b and y, FindRoot can find h for you:FindRoot[Evaluate[f[h] == 1 /. {a -> 3, b -> 0.2}], {h, 2}]{h -> 1.799292219454869}FindRoot[Evaluate[f[h] == 1 /. {a -> 3, b -> 0.2}], {h, 0.5}]{h -> 0.5654110956582447}Bobby Treat-----Original Message----- ==== I'd say the applet demonstrates that histograms are useless unless wechoose a pretty small bin-width. Choosing a bin-width of significantsize that doesn't yield a misleading histogram is an unlikely accident.Bobby-----Original Message-----understood the significance of choosing the bin width......jerryblimbaum-----Original Message-----very nice package that does all of the above and more is mathStatica.Seehttp://www.mathstatica.com for details.Obviously, it is less expensive to write your own functions.Just recently in message Mark Fisher posted code thataddressesthe empirical CDF. However, in this code you may want to replace 1/nwith1/(n+1) or (j-0.5)/n depending on your application. Note, these willhave nosignificant effect for large data sets.The key issue with an empirical PDF is deciding the bin width. A simpleapproach would be to use the functions in Statistics`DataManipulation`andBinListCounts. More sophisticated approaches involve kernel methods.Thesemethods will generate smoother estimates for the PDF. Again, the key isbandwidth. There is no apriori choice for bin width or bandwith. Badchoiceswill obscure significant features in the data set. ==== > I'm curious, why the built-in boolean functions And and Or> aren't commutative?The on-line help explains why. (Look up And or Or and then link A.4.2.) Youare assured that the argments of And or Or are evaluated left to right,stopping on the first False (for And) or True (for Or).Tom Burton ==== True, but in this case, excitement means being misled far too often.I've never favored histograms much, except when there are lots of barsand little apparent noise. Otherwise, unless you're very lucky, ahistogram doesn't even locate the mode well.very nice package that does all of the above and more is mathStatica.Seehttp://www.mathstatica.com for details.Obviously, it is less expensive to write your own functions.Just recently in message Mark Fisher posted code thataddressesthe empirical CDF. However, in this code you may want to replace 1/nwith1/(n+1) or (j-0.5)/n depending on your application. Note, these willhave nosignificant effect for large data sets.The key issue with an empirical PDF is deciding the bin width. A simpleapproach would be to use the functions in Statistics`DataManipulation`andBinListCounts. More sophisticated approaches involve kernel methods.Thesemethods will generate smoother estimates for the PDF. Again, the key isbandwidth. There is no apriori choice for bin width or bandwith. Badchoiceswill obscure significant features in the data set. ==== Could someone calculate the number Pi to 67,108,864 (2^26) decimal placesI made the calculation in another program and would like to verify its ==== > Could someone calculate the number Pi to 67,108,864 (2^26) decimal places I made the calculation in another program and would like to verify itsDoes it really matter what program is used to verify it? If not,here's the digits (computed with the fastest pi crunching program fora PC):33863220896223409803 ==== >I am trying to write an animation using JLink.....basically as>follows...(using Mathematica 4.1, JLink 2.01 and java 1.4.1)...>frm = createWindow[]; (* basically to create a MathFrame and a drawArea>= MathCanvas *)>Here is my drawing routine....> Map[(obj = drawMembrane[#];>drawArea@setMathCommand[obj];> drawArea@repaintNow[];> Pause[.0001];) &, t ]>t = time list ={0,.25,etc}.... and drawMembrane is a function that uses the>time value to make a graphics plot......unfortunately, this routine draws>the next time plot very slowly, plus I also notice that without the Pause[]>statement, Mathematica only draws the graph for the final time value...Jerry,You did a nice job with this one-frame-at-a-time plot. (I'm replying here to this message and your previous one where you presented the full code.) The main reason that it is slow drawing the frames is that the Pause[] function only works with integer second intervals. If you say Pause[.0001] it pauses for a whole second, which inserts a 1-second delay between each frame. If I take out the Pause, I get about 5 frames per second on my laptop (for your Sin plot). This still seems slow to me, but it turns out that Java is just slow at taking GIF data and making it into pixels to be displayed. That step consumes virtually all the time for the animation.If you make the image smaller, the animation runs much faster. Try making your window size 400 x 300 instead of 800 x 600. At that size, the animation runs at a good speed on my machine. If you want to insert a delay between frames, you need to use Java instead of calling Pause[]:LoadJavaClass[java.lang.Thread];Map[(obj = drawMembrane[#]; drawArea@setMathCommand[obj]; drawArea@repaintNow[]; (* Add a 100 ms delay *) Thread`sleep[100];) &, t ]You said that without the Pause[] you only get the last frame drawn, but that shouldn't have any effect. Perhaps you took out the call to repaintNow() along with the Pause?>Following an example in the JLink documentation, I have written the>following java routine....which I saved in the same dir as MathFrame,>etc....>public class My_DisplayGraphicsViaJava {> public void displayGraphics(String cmds[]) { // declare String Array>for Graphics Objects> for (int i = 0; i < cmds.length-1; i++)> drawArea.setMathCommand(cmds[i]);> drawArea.repaintNow();> Thread.sleep(200);} }>and then in Mathematica I have> LoadJavaClass[My_DisplayGraphicsViaJava];>My_ DisplayGraphicsViaJava`displayGraphics[obj]; (* where obj is the>array of Graphics plots created *)>But needless to say this dont work....LoadJavaClass responds by saying Class>not Found.....so what should I do to correct this? Also , on the java>routine, was i supposed to add: Extends MathFrame, etc....how will my>java routine know what drawArea.setMathCommand is, etc.....am I also>supposed to compile my java routine?You will definitely need to compile any Java classes you write! But writing this in Java won't change anything because the delay is in Java itself, not in J/Link or the MathLink communication. This Java class would need a lot of work before it would compile. You would need to either create drawArea in the Java class rather than in Mathematica code, or pass it as an argument to displayGraphics() (which needs to be static, by the way). Anyway, there is no point in thinking about any of that, since this displayGraphics() method just duplicates functionality that you have already (much more conveniently) scripted in Mathematica code.One final general note for J/Link programmers: It's OK to create Java names with underscores in them, but you have to remember how they are handled in Mathematica. When you refer to a Java name in Mathematica code as a string, you keep the underscore: LoadJavaClass[My_DisplayGraphicsViaJava];But when a name appears as a symbol in Mathematica, J/Link maps it to a U because _ is not legal in a symbol name: MyUDisplayGraphicsViaJava`displayGraphics[....]It's often easiest to just avoid using _ in the names of Java classes and methods that you write for use with Mathematica.Todd GayleyWolfram Research ==== >-----Original Message----->Sent: Wednesday, September 18, 2002 8:09 AM>I am new with Mathematica, I have one question,>I know that the sollution might be very easy, but I wasn't able to>find it by now.>I would like to draw an ellipse, the formula let's say is as follows:Two methods: (1) solve for explit functions y = f[x] and plot those:In[2]:= eqn = 0.09 x^2 + 0.04 x y + 0.06 y^2 == 4... just for convenience;In[5]:= sols = Solve[eqn, y]In[6]:= y /. sols...these are the two functions for y expressed by x. To find the minimum andmaximum values for x, we spot the discriminant, and solve for x:In[12]:={xmin, xmax} = x /. Solve[ Cases[y /. sols[[1]], Sqrt[disc_] :> disc, Infinity] == 0, x]...now we may use Plot:In[18]:=Plot[Evaluate[y /. sols], {x, xmin, xmax}, AspectRatio -> Automatic](2) guess approximate values for xmin, xmax and let Mathematica do all thatwork:In[1]:= << Graphics`ImplicitPlot`...load the packageIn[19]:= ImplicitPlot[eqn, {x, -7, 7}]...done. ==== b = 2; r = 4;n = 10101111p = Reverse[Characters[n]]{1, 1, 1, 1, 0, 1, 0, 1}z = Reverse[Partition[p, r]]{{0, 1, 0, 1}, {1, 1, 1, 1}} (* this is okay *)b = 2; r = 3;z = Reverse[Partition[p, r]]{{1, 0, 1}, {1, 1, 1}} (* this is wrong, want output to be{{0,1,0},{1,0,1},{1,1,1}}*)What I want is a function that takes a string as input, parses eachcharacter, partitions that to whatever length I want and Prepends zeros tothe input as needed to create an appropriate length array.What is the correct syntax for Partition (or is there a better way?). ==== > b = 2; r = 4;> n = 10101111> p = Reverse[Characters[n]]> {1, 1, 1, 1, 0, 1, 0, 1}> z = Reverse[Partition[p, r]]> {{0, 1, 0, 1}, {1, 1, 1, 1}} (* this is okay *)> b = 2; r = 3;> z = Reverse[Partition[p, r]]> {{1, 0, 1}, {1, 1, 1}} (* this is wrong, want output to be> {{0,1,0},{1,0,1},{1,1,1}}*)> What I want is a function that takes a string as input, parses each> character, partitions that to whatever length I want and Prepends zeros to> the input as needed to create an appropriate length array.> What is the correct syntax for Partition (or is there a better way?).z = Reverse[Partition[p, r, r, {1,1}, 0]pads 0 on the right before partitioning. This doesn't completely do what you want because when you reverse, those digits are still on the right in the first element (i.e., they are appended instead of prepended. To have them prepended, just addz[[1]] = RotateRight[z[[1]], r Length[z] - Length[p]];and z will have what you want.Here is an example with Range (easier to see what is happening)In[1]:= p = Range[8]; b = 2; r = 3;In[2]:= z = Reverse[Partition[p, r, r, {1, 1}, 0]]Out[2]= {{7, 8, 0}, {4, 5, 6}, {1, 2, 3}}In[3]:= z[[1]] = RotateRight[z[[1]], r Length[z] - Length[p]];In[4]:= zOut[4]= {{0, 7, 8}, {4, 5, 6}, {1, 2, 3}}Rob Knapp > ==== Has anyone had any luck getting Mathematica 4.2 to workon a Sun running Solaris 6? I get the following error message when starting Mathematica:./Mathematica ld.so.1: ./Mathematica: fatal: librt.so.1: open failed: No such file ordirectoryKilledBut math works. Any thoughts on this would be appreciated - even if it's just Solaris 6 sucks - Reinstall with Solaris 8/9. I'd rather not go to thetrouble of reinstalling the box unless absolutely necessary (It is a270mhz Ultra 5)-- Alex Dawson 08 9380 1587School of Electrical, Electronic and Computer EngineeringSystems Administrator http://www.ee.uwa.edu.au/~alex ==== Has anyone had any luck getting Mathematica 4.2 to work> on a Sun running Solaris 6?> I get the following error message when starting Mathematica:> ./Mathematica> ld.so.1: ./Mathematica: fatal: librt.so.1: open failed: No such file or> directory> Killed> But math works.> Any thoughts on this would be appreciated - even if it's just> Solaris 6 sucks - Reinstall with Solaris 8/9. I'd rather not go to the> trouble of reinstalling the box unless absolutely necessary (It is a> 270mhz Ultra 5)I'd be tempted to run Ôldd' and see what libraries it needs. On my Solaris 9box, with Mathematica 4.2 I see:wren /usr/local/stow/Mathematica-4.2/SystemFiles/FrontEnd/Binaries /Solaris % ldd../Mathematica libXt.so.4 => /usr/lib/libXt.so.4 libXext.so.0 => /usr/lib/libXext.so.0 libXmu.so.4 => /usr/lib/libXmu.so.4 libX11.so.4 => /usr/lib/libX11.so.4 libnsl.so.1 => /usr/lib/libnsl.so.1 libsocket.so.1 => /usr/lib/libsocket.so.1 libc.so.1 => /usr/lib/libc.so.1 libucb.so.1 => /usr/ucblib/libucb.so.1 librt.so.1 => /usr/lib/librt.so.1 libpthread.so.1 => /usr/lib/libpthread.so.1 libSM.so.6 => /usr/lib/libSM.so.6 libICE.so.6 => /usr/lib/libICE.so.6 libm.so.1 => /usr/lib/libm.so.1 libdl.so.1 => /usr/lib/libdl.so.1 libmp.so.2 => /usr/lib/libmp.so.2 libelf.so.1 => /usr/lib/libelf.so.1 libaio.so.1 => /usr/lib/libaio.so.1 libmd5.so.1 => /usr/lib/libmd5.so.1 /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1 libthread.so.1 => /usr/lib/libthread.so.1 /usr/platform/SUNW,Ultra-60/lib/libmd5_psr.so.1You should be able to find the libraries it's using, and hopefully it might justbe looking in the wrong place, in which case you may be able to create asymbolic link. However, if Solaris 2.6 is not supported (I don't know if it is) it is quitepossible it wants a library you don't have, in which case you are stuck unlessyou re-install a later OS. -- Dr. David Kirkby,Senior Research Fellow,Department of Medical Physics,University College London,11-20 Capper St, London, WC1E 6JA.Internal telephone: ext 46408 ==== One of these days the company I work for will buy one Mathematica 4.2versions of the product.window manager. Our Windows systems are running on top of VMWare in WindowsXP Professional.In testing using an evaluation version I found that the VMWare/XP version isperforming pretty well so that wouldn't be an issue.My main concern (and probably the grounds on which we will base ourdecision) is the quality of the front-end. The Windows frontend worksßawlessly; however, in test-driving earlier versions of Mathematica (3.0satisfactorily. I didn't spend much time to hunt down the source of theproblem, but it is probable that some X key-mapping was wrong making, forexample, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On theWindows frontend.to full satisfaction? I'd be willing to spend a couple of hours to fix somesettings, but only if I'm sure it could be done. The bottom line is that I Inot if that would mean putting up with a quircky front-end. Sidney Cadot ==== One of these days the company I work for will buy one Mathematica 4.2> versions of the product.> window manager. Our Windows systems are running on top of VMWare in Windows> XP Professional.> In testing using an evaluation version I found that the VMWare/XP version is> performing pretty well so that wouldn't be an issue.> My main concern (and probably the grounds on which we will base our> decision) is the quality of the front-end. The Windows frontend works> ßawlessly; however, in test-driving earlier versions of Mathematica (3.0> satisfactorily. I didn't spend much time to hunt down the source of the> problem, but it is probable that some X key-mapping was wrong making, for> example, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On the> Windows frontend.> to full satisfaction? I'd be willing to spend a couple of hours to fix some> settings, but only if I'm sure it could be done. The bottom line is that I I> not if that would mean putting up with a quircky front-end.For what it is worth, I have no problems with the front end under Solaris -another varient of Unix. -- Dr. David Kirkby PhD,web page: http://www.david-kirkby.co.ukAmateur radio callsign: G8WRB ==== One of these days the company I work for will buy one Mathematica 4.2> Windows versions of the product.> window manager. Our Windows systems are running on top of VMWare in> Windows XP Professional.> In testing using an evaluation version I found that the VMWare/XP version> is performing pretty well so that wouldn't be an issue.> My main concern (and probably the grounds on which we will base our> decision) is the quality of the front-end. The Windows frontend works> ßawlessly; however, in test-driving earlier versions of Mathematica (3.0> satisfactorily. I didn't spend much time to hunt down the source of the> problem, but it is probable that some X key-mapping was wrong making, for> example, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On the> Windows frontend.> working to full satisfaction? I'd be willing to spend a couple of hours> to fix some settings, but only if I'm sure it could be done. The bottom> VMWare/Windows, but not if that would mean putting up with a quircky> front-end.> For what it is worth, I have no problems with the front end under Solaris> - another varient of Unix.I sincerely wish WRI were more relaxed about allowing people to use the same license on the same hardware, but with a different OS. My understanding is that I would have to buy two licenses if I wanted to switch back and forth That's how open source is paid for. Not everybody has the same amount of spare blood in their veins, or willingness to spill it. For those who release of Mathematica, it would be nice to have a dual boot option. Perhaps it's simply a support issue. It would potentially cause the same customer to require more support if he were switching back and forth between OSs.http://public.globalsymmetry.com/proprietary/com/wri/ch05 .htmlhttp://66.92.149.152/proprietary/com/wri/ch05.htmlI still have some tweaks to add to this, such as M-k -> C-k, but it at least demonstrates that (all) things aren't cast in stone.STH ==== Sidney,(or other Unix) for some years so perhaps my experience could help with yourdecision.Most of the time I run on Windows (2000, not yet XP) because:1. The Front End is more stable.2. The Front End is more comfortable in the sense that the keys fordeleting, copying, pasting etc. are the ones my fingers expect them to be.3. Command completion via Ctrl-k, which I use all the time, does not work4. Generally speaking it takes more mouse clicks and keystrokes to do thingsI think these are general differences between the user interfaces on theseoperating systems rather than something specific to the Mathematicaimplementations. I have tried to overcome them at various time withoutsuccess. Since I switched from Windows 95 to Windows NT several years ago,2. I need to have access to certain files created on that system by otherpeople.3. I want to run long calculations on additional CPUs, leaving my desktopcomputer free for other things. You can do this between Windows machineskernel via Mathlink. This is very simple and more reliable and robust thanFront End and it is easy, say, to transfer input or output betwen systemswithin a single Front End. I should add that in our lab we can access thethe additional convenience of being able to save a notebook from the WindowsFront End in the same directory as other files the kernel may be workingwith. You may not have this option and, of course, you need Mathematica onboth systems.These are my personal opinions based on practical experience, I really donot want to enter into any controversy about operating systems.John Jowett> One of these days the company I work for will buy one Mathematica 4.2Windows> versions of the product.> window manager. Our Windows systems are running on top of VMWare inWindows> XP Professional.> In testing using an evaluation version I found that the VMWare/XP versionis> performing pretty well so that wouldn't be an issue.> My main concern (and probably the grounds on which we will base our> decision) is the quality of the front-end. The Windows frontend works> ßawlessly; however, in test-driving earlier versions of Mathematica (3.0> satisfactorily. I didn't spend much time to hunt down the source of the> problem, but it is probable that some X key-mapping was wrong making, for> example, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On the> Windows frontend.working> to full satisfaction? I'd be willing to spend a couple of hours to fixsome> settings, but only if I'm sure it could be done. The bottom line is that IIbut> not if that would mean putting up with a quircky front-end. ==== > One of these days the company I work for will buy one Mathematica 4.2> Windows versions of the product.The Redmond chaos code is IMHO no system at all (SCNR).I have only one problem with my Mathematica 4.0 for students, which is that the Export function does not work for gif and other graphics formats. I have posted a question about this into this group but nobody has answered, so I guess there is no fix for that, but on the other hand 4.2 is much newer and should work.> My main concern (and probably the grounds on which we will base our> decision) is the quality of the front-end. The Windows frontend works> ßawlessly; however, in test-driving earlier versions of Mathematica (3.0> satisfactorily. I didn't spend much time to hunt down the source of the> problem, but it is probable that some X key-mapping was wrong making, for> example, keyboard shortcuts for ÔCopy' and ÔPaste' malfunctioning. On the> Windows frontend.I have no problem concerning the frontend. One has only to adjust the font settings (if you need it, I can send you a pdf file explaining how).-- Hendrik van Hees Fakult.8at f.9fr Physik http://theory.gsi.de/~vanhees/ D-33615 Bielefeld ==== > What I want is a function that takes a string as input, parses each> character, partitions that to whatever length I want and Prepends zeros to> the input as needed to create an appropriate length array.> What is the correct syntax for Partition (or is there a better way?).Although you can't see it in your particular example, I think your twoReverse functions would lead to reversed partitions, so I got rid of them.Then it's a matter of following directions for Partition in Help. The onlyissue is computing kL. The following way is a bit complicated. Perhapssomeone will post a simpler way.n = 10101111; r = 3; p = Characters[n]; kL = r + 1 - Mod[Length[p], r, 1];kR = r; z = Partition[p, r, r, {kL, kR}, 0]Tom Burton ==== Although And and Or don't have to evaluate all their arguments, I findthat this is useless in many situations I run into. For instance, Imight have a long list ÔboolList' of Boolean expressions and I want toknow if ANY of them are False, so I calculateAnd@@boolListIn this situation, ALL the expressions in ÔboolList' are calculated,even though the first may be False. Here's an example in which Iovercome that:boolList = Hold[Print@#; PrimeQ@#] & /@ Range[3, 1000, 2];ReleaseHold[And @@ boolList]3579FalseBobby Treat-----Original Message-----argument before any of the others, to avoid unneeded computations of theother arguments. He would put that argument first. If Mathematica turnedaround and sorted the arguments (which is what happens when a functionisorderless), then that argument might end up being evaluated last. If thearguments take a significant amount of time to compute, then sortingfirstmay cause the function to take much longer to evaluate.At any rate, if the above is not a concern for you, you may alwayschangethe attributes of And and Or to anything you want.Carl WollPhysics DeptU of Washington----- Original Message -----> However, the arithmetical functions are Orderless:> Attributes/@{Plus,Times}//ColumnForm> {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}> {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}> ------------------- ==== Maybe this will work for you:groupDigits[n_String, k_Integer] := Partition[ PadLeft[Characters[n], k Ceiling[StringLength[n]/k], 0], k]Bobby Treat-----Original Message-----{{1, 0, 1}, {1, 1, 1}} (* this is wrong, want output to be{{0,1,0},{1,0,1},{1,1,1}}*)What I want is a function that takes a string as input, parses eachcharacter, partitions that to whatever length I want and Prepends zerostothe input as needed to create an appropriate length array.What is the correct syntax for Partition (or is there a better way?). ==== After I load a package using< b = 2; r = 4;> n = 10101111> p = Reverse[Characters[n]]> {1, 1, 1, 1, 0, 1, 0, 1}> z = Reverse[Partition[p, r]]> {{0, 1, 0, 1}, {1, 1, 1, 1}} (* this is okay *)> b = 2; r = 3;> z = Reverse[Partition[p, r]]> {{1, 0, 1}, {1, 1, 1}} (* this is wrong, want output tobe> {{0,1,0},{1,0,1},{1,1,1}}*)> What I want is a function that takes a string as input, parses each> character, partitions that to whatever length I want and Prependszeros to> the input as needed to create an appropriate length array.> What is the correct syntax for Partition (or is there a better way?).> ==== NDSolve seems to have difficulties with solving integral equation. n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == 3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] - [Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z, [Sigma]norm[0, t] == 0}*[Sigma]norm[z,> t], {z, 0.01, 1}, {t, 0.01, 2}] Mathematica returns a message NDSolve::deql: The first argument must have both an equation and an > initial condition. which I cannot understand.> Can anybody tell what's wrong with my attempt? I am not really sure that your question isn't a joke.NDSolve solves differential equations, not integral equations.Although there are relations between these topics, they are certainlynot the same.Alois-- Vienna University of Technology, ==== evaluating the following gives you a sample x=x+1 button:NotebookPut@Notebook[{Cell[BoxData[ ButtonBox[(x = (x + 1)), RuleDelayed[ButtonFunction, CompoundExpression[If[Not[ ValueQ[x]], Set[x, 0]], Set[x, Plus[x, 1]]]], Rule[ButtonEvaluator, Automatic]] ], NotebookDefault, PageBreakAbove -> True, CellTags -> GeneratedButtonBoxx=x+1]}, ClosingAutoSave -> True, Editable -> False, WindowToolbars -> {}, PageWidth -> 299.5, WindowSize -> {89., 29.}, WindowMargins -> {{92., Automatic}, {Automatic, 56.}}, WindowFrame -> Palette, WindowElements -> {}, WindowFrameElements -> CloseBox, WindowClickSelect -> False, ScrollingOptions -> {PagewiseScrolling -> True}, ShowCellBracket -> False, CellMargins -> {{0., 0.}, {Inherited, 0.}}, Active -> True, CellOpen -> True, ShowCellLabel -> False, ShowCellTags -> False, ImageMargins -> {{0., Inherited}, {Inherited, 0.}}, Magnification -> 1.5](* ********************************* *)Now, how do you create such a button in less than a minute? ... :One way is to just create a section cell and the underlying ButtonFunction code as input cells, i.e., type interactively such that you get something like:NotebookPut[Notebook[ {Cell[CellGroupData[ {Cell[x=x+1, Section], Cell[If[!ValueQ[x], x=0], Input], Cell[x=x+1, Input]}, Open]]}]]Then hit the F2B (function to Button) button in ButtonTools.nb ( my freewarebutton tools from http://www.mertig.com/mathdepot ) and you get the button.With the HP and VP you can easily and quickly generate (horizontally orverically) palettes. Check out the Help button, or also the source code.It basically is all straightforward and there is actually documentation about all those ButtonFunction features somewhere. I agree that the whole Button-design could have been made better, but up to a point is quite useful. Of course the world is used to better GUI's these days but if you really need nice GUI's and buttons, use Java and JLink ( and there are also simple examples in the JLink manual of how to do this ).If you don't like Java, go with VBA and use the nice Mahematica for Active Xproduct from http://www.episoft.comRolf MertigMertig Consultinghttp://www.mertig.com ==== tryIn[1]:=Clear[a,b,c,d,x, y]x= {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};y = {a,b,c,d}; LinearSolve[x,y]s01= LinearSolve[x,y][[1]]Out[4]={-a+b,-a+c,a-b-c+d,a}Out[5]=-a+ bIn[6]:=g[a_,b_] =s01Out[6]=-a+bIn[7]:=g[1,3]Out[7]=2*NEVER* use capital letters at the beginning of a variable's name! Never!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, 23. August 2002 06:25An: mathgroup@smc.vnet.netBetreff: := Does not assign variables properly.Why?Here's a piece of a conversion I had with Mathematica.Why is a[A_,B_] := LinearSolve[X,Y][[1]] not givingme the function I expect?In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};In[262]:= Y = {A,B,C,D};In[263]:= LinearSolve[X,Y]Out[263]= {-A+B,-A+C,A-B-C+D,A}In[264]:= LinearSolve[X,Y][[1]]Out[264]= -A+BIn[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]In[266]:= a[1,3]Out[266]= -A+BThe output above is not what I want. I want 2. Here'swhat I expect:In[267]:= a[A_,B_] := -A+B;In[268]:= a[1,3]Out[268]= 2This output is what I expect. What is the difference betweenthe two?