mm-989 === Subject: Re: Non-numeric arguments to Compile-d functions > Here's a compiled function that does some (made-up) operation on a > real-valued function f: Compile[{}, > Do[If[f[i] < 0, Return[{i, f[i]}]], {i, 10}], > {{f[_], _Real}} > ] (It finds the first integer i such that f[i] is negative.) For the usual reasons of modularity, I would like to make compiled functions > like this not refer to global variables named f. (We can't put f as one of > the elements of the first argument to compile, because those must all be > numeric scalars or arrays.) Here's one way to do this: Module[ > {f, compiledpart}, compiledpart = Compile[{}, > Do[If[f[i] < 0, Return[{i, f[i]}]], {i, 10}], > {{f[_], _Real}} > ]; findfirstnegative[tempf_] := (compiledpart /. f -> tempf)[] > ] I don't really like this solution because we needed to use two names (f and > tempf). Using two names per argument could get messy if there are several > non-numeric arguments instead of just f. Is this the recommended method for compiling as much of a function as > possible? Note that the following attempt (which doesn't need a tempf) doesn't work: With[{rhs = compiledpart}, findfirstnegative[f_] := rhs] It fails because Mathematica automatically renames the f in the > CompiledFunction in compiledpart to *avoid* the very naming clash I am > trying to create. The With statement effectively creates: findfirstnegative[f$_] := CompiledFunction[{}, > Do[If[f$851[i]<0, Return[{i,f$851[i]}]], {i,10}], > -CompiledCode- > ] What's the neatest, right way to make compiled functions that take > non-numeric arguments? Hi Andrew, What's wrong with simply using the following? fun[f_] = Compile[{}, Do[If[f[i] < 0, Return[{i, f[i]}]], {i, 10}], {{f[_], _Real}}] findfirstnegative[f_Function] := fun[f][] Of course you have to make sure that 'f' is not defined before you issue these definitions, but this is not a problem when you are developing a package. I believe that Module and With weren't meant to be used in this way (i.e. to define new functions *inside* them). When you create packages, use contexts to isolate those symbols which should not be exported. But to be honest, I'm a bit tired now and it is possible that I misunderstood your question ... -- Szabolcs === Subject: Re: ReplaceAll behavour > I do not understand what Mathematica 6 is doing here: a=5 > a/.a->3 gives 3 But... a+2/. a->3 gives 7 Why is that? Use Trance[a /. a->3] or On[] and Off[] to find out how Mathematica evaluates an expression. The following output should explain what happens: In[1]:= On[] During evaluation of In[1]:= On::trace: On[] --> Null. >> In[2]:= a=5 During evaluation of In[2]:= Set::trace: a=5 --> 5. >> Out[2]= 5 In[3]:= a/.a->3 During evaluation of In[3]:= a::trace: a --> 5. >> During evaluation of In[3]:= a::trace: a --> 5. >> During evaluation of In[3]:= Rule::trace: a->3 --> 5->3. >> During evaluation of In[3]:= Rule::trace: 5->3 --> 5->3. >> During evaluation of In[3]:= ReplaceAll::trace: a/.a->3 --> 5/.5->3. >> During evaluation of In[3]:= ReplaceAll::trace: 5/.5->3 --> 3. >> Out[3]= 3 In[4]:= (a+2)/.a->3 During evaluation of In[4]:= a::trace: a --> 5. >> During evaluation of In[4]:= Plus::trace: a+2 --> 5+2. >> During evaluation of In[4]:= Plus::trace: 5+2 --> 7. >> During evaluation of In[4]:= a::trace: a --> 5. >> During evaluation of In[4]:= Rule::trace: a->3 --> 5->3. >> During evaluation of In[4]:= Rule::trace: 5->3 --> 5->3. >> During evaluation of In[4]:= ReplaceAll::trace: a+2/.a->3 --> 7/.5->3. >> During evaluation of In[4]:= ReplaceAll::trace: 7/.5->3 --> 7. >> Out[4]= 7 In[5]:= Off[] Szabolcs P.S. This is why it is a bad idea to do things like sqrt[a_?NumericQ] := x /. FindRoot[x^2 == a, {x, 1}] (Even though this function works correctly almost all the time -- one must come up with a really tricky definition for 'x' to make it fail, like x = Sequence[1]) So use Module[] to localise 'x': sqrt[a_?NumericQ] := Module[{x}, x /. FindRoot[x^2 == a, {x, 1}]] === Subject: Re: Just for fun: Shortest InputForm to achieve a given Kernel error Two more solutions: > I have found 2 answers after some try. For General::ovfl: 9^99! > For $IterationLimit::itlim: #0@# &@1 > >> 1/0 is a string of length 3 which, when interpreted as InputForm (in a >> clean Kernel), generates a Power::infy error: > ToExpression[1/0, InputForm]; >> Power::infy: Infinite expression 1/0 encountered. >> I think this is the shortest string with this property. > Here are some other errors and the lengths of the shortest strings I can >> find to generate them: > $RecursionLimit::reclim: Recursion depth of 256 exceeded. >> Input length: 4 a=2a > General::ovfl: Overflow occurred in computation. >> Input length: 5 > (Kernel running out of memory) >> Input length: 5 >> a=a@a >> General::unfl: Underflow occurred in computation. >> Input length: 6 > $IterationLimit::itlim: Iteration limit of 4096 exceeded. >> Input length: 7 > Can you figure out how to generate those errors with input strings of that >> length? Can you find any *shorter* solutions? >> -- Szabolcs === Subject: InverseFourierTransform strange behaviour Hi all, I am trying to do the InverseFourierTransform on an even and real valued function. because of the real an even properties of the function the IFT should produce a real and even result. but Mathematica 6.0.1.0 gives a even and pure imaginary (erroneous) result: In[1]:= 2 Sqrt[2/Pi] Exp[(w/2)^2] Sin[w]/w; InverseFourierTransform[%, w, x] Out[2]= -I (Erfi[1 - x] + Erfi[1 + x]) trying to FT the (erroneous) result lets Mathematica hang endless in the calculation (until aborted). In[3]:= FourierTransform[%, x, w] Any hints, is this a bug, am I missing something ? thx robert === Subject: Re: Unwanted resize of frontend window I am not sure, but I would guess that window 2 has Inherited as its WindowSize Option. Check Option Inspector under the Format menu, and select the options for Notebook in window 2. Just a guess. WCC W. Craig Carter Professor of Materials Science and Engineering MIT, Dept. of Materials Science and Engineering 13-5018 77 Massachusetts Ave, Cambridge, MA 02139-4307 USA 617-253-6048 ccarter@mit.edu http://pruffle.mit.edu/~ccarter http://pruffle.mit.edu/~ccarter/FAQS/ http://pruffle.mit.edu/~ccarter/I_do_not_use_microsoft.html === > Subject: Unwanted resize of frontend window Suppose I have two frontend windows open; no. 2 is maximized. > When I close frontend window no. 1, > frontend window no. 2 gets automatically resized. > Does anybody know how to stop this strange behaviour? > Ben > Linux, Mathematica 6.0 === Subject: Custom Control of Axes and Plot Labels in 2D and 3D Plots There have been a number of questions concerning the control and placement of axis labels and overall plot labels in graphics. I believe that for 2D graphics there is a complete solution. For 3D graphics it is possible to control the placement of the labels but if the image is rotated it will always be possible to obtain overlaps between axis labels and tick marks. Nevertheless it should be possible to place axis labels for a satisfactory result within range of a recommend viewpoint. For 2D plots, by using PlotRange, PlotRangePadding, ImagePadding and Text statements with Scaled coordinates we can place the various plot labels where we wish. The following is an example where the plot labels and axis labels have been specifically placed: Graphics[ {Circle[], Text[x, Scaled[{0.55, -0.06}]], Text[y, Scaled[{-0.08, 0.55}]], Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.1}]], Text[Placing Our Own Labels, Scaled[{0, 1.02}], {-1, 0}]}, PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {35, 60}}, Frame -> True] For a 3D plot the problem is more difficult because of the possibility of rotating the image. We can place the plot label using Epilog. For short axes labels we can place them just inside the bounding box using Text statements. Inside the box they tend to be disentangled from the tick labels. But it is always possible to select a viewpoint that can cause overlap. The only recourse is to place the axes labels according to the predominate view that is wanted. We should probably also set the AxesEdge option to always keep the axes with the labels. The SphericalRegion and RotationAction options provide a 'jump free' interaction with the mouse. Graphics3D[ {Sphere[], Text[x, Scaled[{0.5, 0.04, 0.04}]], Text[y, Scaled[{0.96, 0.5, 0.04}]], Text[z, Scaled[{0.04, 0.04, 0.5}]]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.2}]], Text[Placing Our Own Labels, Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> Clip] With longer axes labels the problem again becomes more difficult because there is more chance for overlap of the labels and ticks. The following is an attempted solution that works within a selected range of viewpoints. Graphics3D[ {Sphere[], Text[x axis, Scaled[{0.5, 0.04, 0.04}], {-1, 0}], Text[y axis, Scaled[{1.1, 0.5, -0.10}], {-1, 0}], Text[z axis, Scaled[{-0.10, -0.10, 0.5}], {0, 0}, {0, 1}]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.2}]], Text[Placing Our Own Labels, Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> Clip] If we can settle for a fixed viewpoint it is even possible to have the labels parallel to the axes. (However, I don't think that angled text always looks that great on the screen. It may look better printed.) axisstyle[s_] := Style[s, FontSize -> 14, FontWeight -> Bold]; Graphics3D[ {Sphere[], Text[axisstyle[x axis], Scaled[{0.5, 0.04, 0.04}], {0, 0}, {1, -0.4}], Text[axisstyle[y axis], Scaled[{1.1, 0.5, -0.10}], {-1, 0}, {1, 1.7}], Text[axisstyle[z axis], Scaled[{-0.10, -0.10, 0.5}], {0, 0}, {-0.15, 1}]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.2}]], Text[Placing Our Own Labels, Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> Clip] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Lynch Dynamical Systems...Using Mathematica available This is to let folks know that Stephen Lynch's long-awaited book Dynamical Systems with Applications Using Mathematica is now out. I ordered mine back in September 2006 (yes, 6!) when Springer began advertising it. Evidently part of the year's delay was due to the wait for Mathematica 6, which is used for the Mathematica programs. There's some information about the book at http://library.wolfram.com/infocenter/Books/6881/ as well as a downloadable Mathematica 6 notebook with the code (including a tutorial introduction to Mathematica itself). -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > In[1]:= (Count[#1, x_ /; x != 0] & ) /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} Out[1]= {0, 3, 3, 4, 10, 9} Adriano Pascoletti === Subject: Re: [?? Probable Spam] HELP: How to do count to the SUB-LIST {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; Length@# - Count[#, 0] & /@ test {0, 3, 3, 4, 10, 9} /@ is the Map function. Bobby > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} -- DrMajorBob@bigfoot.com === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? I still feel sufficiently provoked by your post to write one more just to make absolutely clear what the point of my first reply (to Bobby Treat) was, since it it appears to me that you have entirely missed it. I will start with my first response to Bobby Treat. Originally I did not intend to join this thread (since I consider this topic to be a horse that was beaten to death on this list a long time ago mostly by yourself). But in his (otherwise correct) reply, Bobby Treat expressed doubts about the correctness of the functions Simplify or D (yes, it was actually D rather than Integrate). Now, I know Simplify to be very reliable; there might have been perhaps one or two cases when it did not work correctly in the whole history of Mathematica. As for D, I would be really shocked to see it return a wrong answer, simply because it uses such a simple algorithm. I don't think it has ever done so. So that claim made interested in this thread and as I was being used incorrectly as this is quite common not just in Mathematica but in any program that performs symbolic definite integration. However, while writing my reply I forgot that the it was D about which doubt had been expressed and mentioned Integrate. Now, while Integrate is quite reliable it is not nearly as reliable as D, for reasons that I will try to explain below. But it is still very reliable in doing what it is supposed to do: finding indefinite integrals. However, it is important to understand what is meant by an indefinite integral in symbolic algebra. The concept of an anti- derivative used in symbolic algebra is purely algebraic and does not depend on the idea of limit or on anything taught in undergraduate calculus. The whole process works over an arbitrary differential fields in the sense of Ritt. Differential fields are just fields with a D operator, that satisfies properties analogous to usual differentiation. If has a subfield of constants k such that D[k]=0, and one can consider algebraic and transcendental extensions in the usual sense. The problem of finding an antiderivative is the following: given an element f of a given differential field F, find an allowable differential extension G = F[x1,x2,...] and an element g in G such that D[g]=f or determine that no such allowable extension exists. If we take F to be just the field of rational functions over the rationals then there are several algorithms, which solve this problem and the extensions that are needed just usual algebraic field extensions of the rationals and transcendental (actually logarithmic) extensions of these. Of course when you think of these objects as the familiar objects from calculus they turn out to have branch cuts and singularities. The Risch algorithm of 1968 solves the algebraic integration problem for a class of functions known as elementary functions (the existence of such a solution was proved much earlier by Liouville). It is exactly what this algorithm computes that is called an indefinite integral or an anti- derivative in the context of symbolic algebra systems. The problem with the Risch algorithm is that it has two different aspects. The easy one is when we are able to confine ourselves to the class of purely transcendental extensions (which turn out to be just logarithmic and exponential). The hard one is when one needs to compute also algebraic extensions. As far as I know no symbolic algebra program implements completely the latter part. Instead some additionalo heuristics is used at some point or perhaps the integratal is returned unevaluated (?) This is why I would not consider Integrate to be nearly as reliable as D. I do not know exactly what exactly is the procedure used by Mathematica's Integrate, but an analogous one used by one of its rivals is described in the book of Geddes, Czapor and Labahn which I mentioned in my earlier post. That is, given a function f whose anti- derivative is supposed to be found, the program first tries a number of heuristic methods, similar to those taught in calculus courses. It also makes use of some look-up tables. When all this fails, the program turns to the Risch algorithm. I am pretty sure Mathematica behaves in the same way. Nowhere, at any stage of this process does any consideration of limits or singularities or branch cuts come into play. These things have nothing to do with the purely algebraic process of indefinite integration. Integrate produces a correct answer unless there is a bug somewhere in its heuristics. Another possibility of course is that the Risch algorithm will take too long and the user aborts. So in view of the above I can't make any sense of you claim that Integrate should be doubted or is not reliable unless what you actually meant was that using the anti-derivative returned by Integrate and the Newton-Leibniz formula is not reliable. This, post. Anyway, this whole belongs to the realm of definite and not indefinite integration. Daniel Lichtblau has already posteda reply to Bobby the same thread (have you looked at it?) where he included a link to a paper of his which explains in detail the difficulties faced by definite integration in this kind of setting. Definite integration still makes use of the Risch algorithm (and hence of derivatives with possible singular points) but it does not simple mindedly use the Newton-Leibniz formula. In fact, with numerical limits it correctly deals with the integral posted by the OP. It is only when the limits are symbolic that it fails to determine correctly the location of the branch cuts. Of course if it could use a purely real formula like yours in the case when definite integrals over an interval are involved, things would become much simpler i9n this particualr case, but this approach does not appear to be algorithmic enough to incorporate it into a general integration procedure. The only way to employ it would seem to be by means of a look-up table of definite integrals, which would deal with some cases but would certainly still leave (probably) infinitely many problematic ones. Andrzej Kozlowski > [Message also posted to: comp.soft-sys.math.mathematica] > Sorry for not having responded sooner; I've been away from >> computer access >> for a week. > So, from that, D and/or Simplify must be wrong. > Must they? Even without any investigation I would say that it is > much > more likely that this integral should not be evaluated by means of > the Leibniz rule (substituting the limits into the anti-derivative > and subtracting). > Of course, the Leibniz rule cannot be used unless one _has_ an >> antiderivative valid on the required interval. Mathematica does >> not supply >> such an antiderivative in this case. > This has been discussed many time before on this list (with your > participation) but since you seem not to be satisfied, here it goes > again, I hope for the last time. > The second fundamental theorem of calculus i.e. the Newton-Leibniz > rule (high school level mathematics) states that if we have a > function with a continuous derivative (a C1 function) on an > interval than it has a continuous anti-derivative on this > interval. However if the original function is not complex > analytic in the complex plane then there will not be a complex > analytic anti-derivative. Instead, there will be anti-derivatives > with singularities, and in unlucky cases they may fall on the > interval of integration. This is exactly what happens in this case. > In fact, it is easy to see what happens in your > special case: > integrand = (r*(r - rho*Cos[alpha - t]))/ > (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + > (z - zeta)^2)^3); > int = integrand /. {r -> 1, rho -> 11/10, > zeta -> 0, alpha -> 0, z -> 12/10} > (1 - (11*Cos[t])/10)/(3*(73/20 - (11*Cos[t])/5)^3) > First, let us compute the integral using Integrate: > Integrate[int, {t, 0, 2*Pi}] > (1772800*Pi)/(11512449*Sqrt[377]) > N[%] > 0.0249156 > Now, let's do it by numerical integration: > NIntegrate[int, {t, 0, 2*Pi}] > 0.024915592618816908 > so far, so good. Now let's compute the indefinte integral: > indef = Integrate[int, t]; > Using the Liebniz rule gives clearly the wrong answer: > indef = Integrate[int, t]; > but why should it give the right answer? > It _must_ give the right answer if indef is actually an >> antiderivative on >> the interval 0 to 2Pi, but it isn't. > It depends on the meaning of anti-derivative. In the meaning that > Mathematica and all other symbolic algebra programs use, a function > can be an an anti-derivative of another function, even if it is > singular or undefined at certain points in the complex plane > provided it is an anti-derivative at almost all points (i.e. a > generic anti-derivative). It is of course completely natural for > Mathematica to use such anti-derivatives since it is precisely this > kind of anti-derivatives that are found by the Risch algorithm. >> The function indef is clearly discontinuous in the interval 0 to 2Pi > True, but that discontinuity is merely an artifact of Mathematica's >> workings. The integrand int is clearly continuous on the interval >> 0 to 2Pi >> and, indeed, on all of R, and so there is an antiderivative on R: > 886400 Sqrt[377]/4340193273 (t - 2 ArcTan[44 Sin[t]/(44 Cos[t] - 3 >> Sqrt[377] - 73)]) + 8800 Sin[t] (1078 Cos[t] - 8009)/(3837483 (44 >> Cos[t] - 73)^2)) > but I don't know how to get Mathematica to produce it. Of course, >> using my >> antiderivative above with Leibniz rule, we get the correct result >> for the >> definite integral. >> Plot[indef, {t, 0, 2 Pi}] > so the Leibniz rule does not apply. There is no reason at all to > suspect the very reliable function Simplify and almost as reliabel > Interate. > There is very good reason to suspect that Integrate, when asked to >> evaluate >> an indefinite integral, might give a result which is not an >> antiderivative >> on some desired interval. This happens fairly often, the subject >> of this >> thread being a case in point. > Mathematica does not even attempt to find anti-derivatives on R in > your sense. Instead of bringing up time and again same points that > are covered in undergraduate calculus course I suggest learning a > little about symbolic algebraic integration. Here are two good > references: > Geddes, Czapor, Labhan Algorithms for Computer Algebra, Kluwer, 1992 > Davenport J. On the Integration of Algebraic Functions, Springer- > Verlag 1981. > If you read one of these you will find that the concept of anti- > derivative that your are using is not considered suitable for > computer algebra (at least at its present stage of development > unless there have been some dramatic developments recently that I > am not aware of ). So, you do not know how to obtain your answer > with Mathematica because it can't be done. Symbolic algebra > programs use known algebraic algorithms. There is no point > demanding that they should do something unless a suitable general > algorithm is known. > Of course, it is possible that you know an algorithmic (in the same > sense that the Risch algorithm is algorithmic) way of computing > such anti-derivatives. If so, I am sure that Wolfram Research will > be very keen to implement it. > But until then this is all there is to this entire issue. > Andrzej Kozlowski Another result which might help Craig, but which I don't know how >> to get >> using Mathematica, is that > Assuming[r > 0 && rho > 0 && Element[zeta, Reals] && Element[z, >> Reals] && >> alpha > 0 && Not[rho == r && zeta == z], Integrate[(r*(r - rho*Cos >> [alpha - >> t]))/ (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + (z - zeta)^2)^3), >> {t, 0, 2 Pi}]] > should be > (2*Pi*r^2*(-2*rho^4 + rho^2*(r^2 - (zeta - z)^2) + (r^2 + (zeta - >> z)^2)^2))/ >> (3*(((rho - r)^2 + (zeta - z)^2)*((rho + r)^2 + (zeta - z)^2))^(5/2)) > Note that the last assumption mentioned above was added by me. >> Without that >> last assumption, there would have been trouble if we had had both >> zeta == z >> and rho == r. But in that special case, the desired definite >> integral is >> easily handled: it's just 0. > David W. Cantrell > Yes, it's an incorrect result. > To paraphrase your post: > integrand = (r*(r - >> rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + (z - zeta)^2 - >> 2*r*rho*Cos[alpha - t])^3); >> assumptions = {r > 0, rho > 0, Element[zeta, Reals], >> Element[z, Reals], alpha >In[15]:= 0}; > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions] > 0 > Plot[integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, >> z -> 1.2}, {t, 0, 2 Pi}, PlotRange -> All] > Visual integration is unconvincing, but you're right, the >> integral isn't >> zero: > NIntegrate[ >> integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, >> z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > Your example violates assumptions (alpha -> 0 vs. alpha > 0), but >> that's >> not the problem: > NIntegrate[ >> integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, >> z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > So, as often happens, you've found a case where Mathematica got a >> general >> solution that isn't correct for some values of the parameters. The >> quadratic formula is another example: > Solve[a x^2 + b x + c == 0, x] > {{x -> (-b - Sqrt[b^2 - 4 a c])/( >> 2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}} > Not true when a == 0, of course. > But let's look further: > indefinite = Integrate[integrand, t, Assumptions -> assumptions]; >> definite = Subtract @@ (indefinite /. {{t -> 2 Pi}, {t -> 0}}); >> Simplify[definite, assumptions] > 0 > Is that a Simplify error, or an Integrate error? > definite /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > -2.05998*10^-18 + 0. [ImaginaryI] > Ah. Simplify may be doing its job just fine (hard to be certain), >> but it >> appears the indefinite integral is incorrect. But look: > D[indefinite, t] == integrand // Simplify > True > and > D[indefinite, t] == integrand // Simplify[#, assumptions] & > True > and also > definite // Together // Numerator // Simplify > 0 > So, from that, D and/or Simplify must be wrong. > If this is correct: > numdefinite // Together // Numerator // TrigFactor > -4 r^2 (r^4 + r^2 rho^2 - 2 rho^4 + 2 r^2 z^2 - rho^2 z^2 + z^4 - >> 4 r^2 z zeta + 2 rho^2 z zeta - 4 z^3 zeta + 2 r^2 zeta^2 - >> rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4) (ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan >> [alpha/ >> 2])/Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - >> ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ >> 1/2 (alpha - 2 [Pi])])/ >> Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]]) >> (r^2 + >> rho^2 + z^2 - 2 z zeta + zeta^2 - 2 r rho Cos[alpha])^2 > The next-to-last factor (the only one that depends on t) is > num[[-2]] > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[alpha/2])/ >> Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - >> ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ >> 1/2 (alpha - 2 [Pi])])/ >> Sqrt[-r^4 + 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta) >> ^2) >> ^2] >> ] > so it all comes down (seemingly) to > Tan[alpha/2] == Tan[1/2 (alpha - 2 [Pi])] // Simplify > True > or > Tan[any] == Tan[any - Pi] > True > BUT... what's likely happening is that Simplify doesn't properly >> take into >> account the branch-cut discontinuities of ArcTanh. In that case, >> there's a >> significant set of parameters for which the integral IS zero, >> such as: > Reduce[Flatten@{num == 0, assumptions}] > ors = (zeta [Element] >> Reals && ((z < zeta && >> rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]) || (z == zeta && rho >> 0 && >> alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]) || (z > zeta && >> rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]))) || ((z | >> zeta) [Element] Reals && alpha > 0 && r > 0 && >> rho > 0) || (C[1] [Element] Integers && z [Element] Reals && >> C[1] >= 1 && alpha == 2 [Pi] C[1] && r > 0 && rho == r && >> zeta == z) > But look: > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > True > Hold on, though... there are a lot of Ors in there. The least >> restrictive >> seems to be > ors[[1, 2, 1]] > z < zeta && rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha >> 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - 4 z^3 >> zeta - >> rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + 2 zeta^2) #1^2 + #1^4 >> &, 2] > But that's a pretty strict condition (on r, especially), and > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > False > SO. Integrate found a set of conditions for which the definite >> integral > was zero; it just didn't tell you what they were! This is supposed >> to be >> the fix for that, I think: > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions, >> GenerateConditions -> True] > 0 > BUT, as you see, that didn't help one bit! > Bobby > > I believe I am getting an incorrect result from a definite > integration: >>> InputForm[integrand] is > (R*(R - rho*Cos[alpha - t]))/(3*(R^2 + rho^2 + (z - zeta)^2 - > 2*R*rho*Cos[alpha - t])^3) >>> InputForm[assumptions] is > {R > 0, L > 0, rho > 0, Element[zeta, Reals], Element[z, Reals], > alpha> 0} >>> Integrate[integrand,{t,0,2Pi},Assumptions->assumptions] > returns 0 >>> But compare this to: > (visually integrate...) > Plot[integrand/.{R -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, z -> 1.2},{t,0,2 Pi},PlotRange->All] >>> (numerically integrate...) > Plot[NIntegrate[integrand/.{{R -> 1, rho -> 1.1, zeta -> 0, > alpha - >> 0, > z -> 1.2},{t,0,tau}],{tau,0,2Pi}, PlotRange->All] >>> Something isn't adding up?? >>>>> -- > DrMajorBob@bigfoot.com >> === Subject: Re: Options in ListContourPlot >> Hello everybody, > I really need somebody to explain to me how the ListContourPlot >> command works. >> I mean, when I use it, the resulting plot has the same colour in the >> region where the scalar field is maximum as in the region where the >> field in minimum. >> So the question is: >> when I have an array of values representing the value of a field at a >> point what does ListContourPlot exactly does? >> Olalla > Bilbao, UPV/EHU > I suspect you're using a version of Mathematica prior to 6, because 6 uses > a default ColorFunction which colors the levels differently for the minimum > and maximum. In previous versions (at least in 5), the default color function > was Hue, which has the dubious advantage of being periodic in the visible > color range. This was my first thought too, but in version 5 the default is GrayLevel, not Hue: http://documents.wolfram.com/mathematica/Built-inFunctions/GraphicsAndSound/ ContourPlots/FurtherExamples/ListContourPlot.html More precisely it is Automatic, but it always gives GrayLevel for me. In[2]:= ColorFunction/.Options[ListContourPlot] Out[2]= Automatic You can change the ColorFunction for your plot by trying something like: ListContourPlot[, ColorFunction -> (Hue[0.73*(1 - #)] &)] > -- Szabolcs === Subject: Re: Options in ListContourPlot > Hello everybody, I really need somebody to explain to me how the ListContourPlot > command works. > I mean, when I use it, the resulting plot has the same colour in the > region where the scalar field is maximum as in the region where the > field in minimum. > So the question is: > when I have an array of values representing the value of a field at a > point what does ListContourPlot exactly does? > Olalla Bilbao, UPV/EHU > Sorry, but I do not understand what the problem is. The minimum and maximum points are always coloured differently for me. Please post a complete (but short) example, and explain how the result you get differs from what you expect. -- Szabolcs === database. The first column is the date, the second column contains the names, and the last column contains the returns. I know that you have to use a loop.The data looks like this: 1/2/01 TBill 0.67 1/3/01 SP 0.78 1/4/01 inv 0.5 1/5/01 inve 0.6 . . . . 1/12/01 Forc 1.2 1/2/02 TBill 0.4 1/3/02 SP 0.2 1/4/02 inv 0.6 1/5/02 inve 0.9 . . . . 1/12/02 Forc 1.6 This patterns continues until 1/6/2007 I need to use DataListPlot to plot the returns of each item. === > database. The first column is the date, the second column contains the > names, and the last column contains the returns. I know that you have > to use a loop. I know I have not to use a loop ;-) The data looks like this: 1/2/01 TBill 0.67 > 1/3/01 SP 0.78 > 1/4/01 inv 0.5 > 1/5/01 inve 0.6 > .. > .. > .. > .. > 1/12/01 Forc 1.2 > 1/2/02 TBill 0.4 > 1/3/02 SP 0.2 > 1/4/02 inv 0.6 > 1/5/02 inve 0.9 > .. > .. > .. > .. > 1/12/02 Forc 1.6 This patterns continues until 1/6/2007 I need to use DataListPlot to plot the returns of each item. Let`s see how the file is read in: In[1]:= tbl = Import[thefile.txt, Table]; have a look at the first line FullForm[tbl[[1]]] Out[2]//FullForm= {1/2/01, TBill, 0.67} We have to convert the string mm/dd/yy to a list {y,m,d}. Additionally I add 2000 to the year: In[3]:= data = Apply[{ToExpression[StringJoin[{, StringReplace[#1, / -> ,], }]][[{3, 1, 2}]] + {2000, 0, 0}, #3} & , tbl, {1}] Out[3]= {{{2001, 1, 2}, 0.67}, {{2001, 1, 3}, 0.78}, {{2001, 1, 4}, 0.5}, {{2001, 1, 5}, 0.6}} I do not have access to Mathematica 6 but according to should work. Peter === Subject: Re: rule based program for Deleting repeated members of a list. > I was wandering why you used b and d as pattern name with a condition on > them rather than b and c, but I realized that when using c as pattern > name in place of d the replacement fails. > In[1]:= s = {a, b, c, c, d, e, e, f, g, g, g, h, a, b}; You probably noticed this by now, but on the following line there should > be {a,b,d} instead of {a,b,d} > s //. {a___, b_, c_, d___} :> {a, b, c} /; b == c > ---------------------------------------^ > Hi Szabolcs, -- Jean-Marc === Subject: Re: Would like to specify Traditional Form in the option inspector > Friends, I would like to specify Traditional Form in the option inspector, so > that I don't need to indicate with each individual evaluation. Could > someone please tell me which parameter to update in the option > inspector? In Mathematica 5, use the menu command Cell -> Default Input/Output FormatType In Mathematica 6, go to Edit -> Preferences -> Evaluation. -- Szabolcs === Subject: Re: Would like to specify Traditional Form in the option inspector > I would like to specify Traditional Form in the option inspector, so > that I don't need to indicate with each individual evaluation. Could > someone please tell me which parameter to update in the option > inspector? The easiest way is menu Edit -> Preferences -> Evaluation -> Input and Output -> Format type of new input cells (and/or Format Type of new output cells) -> select TraditionalForm from the drop-down menu. -- Jean-Marc === Subject: Re: Programming Euler's Method into Mathematica may be it help you: Clear[EulerStep, EulerHeunStep, SimpleNDSolve] EulerStep[y_] := y + h*(f @@ y) EulerHeunStep[y_] := Module[{yast, k1}, k1 = f @@ y; yast = y + h*k1; y + h*((f @@ yast) + k1)/2 ] SimpleNDSolve[eqns : {_Equal ..}, init_, var_List, {t_, t0_, step_, n_Integer}, method_: EulerStep] := Block[{dvar, h = step, f}, dvar = D[#, t] & /@ var; f = First[dvar /. Solve[eqns, dvar]]; f = Function @@ ({var, f} /. a_[t] :> a); Prepend @@@ Transpose[{ NestList[method, init, n], Table[t0 + h*i, {i, 0, n}]}] ] and call it with eusol1 = SimpleNDSolve[{q'[t] == p[t], p'[t] == -q[t]}, {0.0, 1.0}, {q[t], p[t]}, {t, 0, 0.1, 180}, EulerStep]; Jens > I am trying to use Euler's Update Method to Numerically Integrate a > Function (I know how to use NDSolve for this case, but I want to > demonstrate an approximation method as well). For those familiar with > neuroscience, I am trying to model the Hodgkin Huxley Equations. I > have four ordinary differential equations (ODE) that I have written in > discrete form using Euler's Method. I am trying to solve for one of > these discrete equations, V, which is a function of the other three > differential equations (n, m, and h). All four equations are also a > function of time. Essentially, the command for NDSolve for this case > is in the following form: NDSolve[{ODE1, ODE2, ODE3, ODE4, > V[0]==0,n[0]==1, m[0]==2, h[0]==3},{V,n,m,h},{t,0,50},MaxSteps->1000] Instead of the above ODE input, I want to use Euler's Method. (i.e. V(t > +delta_t)=V(t)+delta_t(stuff). Now, the code below works for a > function of x and y. MY QUESTION IS: how would I change this code to > apply to my situation in which I want to solve for V[t] but it is a > function of n[t], m[t], and h[t]. I would appreciate any hints/clues/suggested programs. I know that > Mathematica has a built-in Explicit Euler Method, but I would like > to develop the program myself. I believe I am making a small mistake > that is preventing my success. Tara The following program code works for a function f(x,y): > euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:= Block[{ xold=x0, > yold=y0, > sollist={{x0,y0}}, > x,y,h > }, h=N[(xn-x0)/steps]; Do[ xnew=xold+h; > ynew=yold+h*(f/.{x->xold,y->yold}); > sollist=Append[sollist,{xnew,ynew}]; > xold=xnew; > yold=ynew, > {steps} > ]; Return[sollist] === Subject: Re: Programming Euler's Method into Mathematica The following code, which uses a slightly different programming paradigm, implements Euler's Method for a system: euler[F_, a_, Y0_, b_, n_] := Module[{t, Y, h = (b - a)/n, i}, t[0] = a; Y[0] = Y0; Do[ t[i] = a + i h; Y[i] = Y[i - 1] + h F[t[i - 1], Y[i - 1]], {i, 1, n} ]; Table[{t[i], Y[i]}, {i, 0, n}] ] And the usage messsage is: euler::usage = euler[F, t0, Y0, b, n] gives the numerical solutionn to {Y' == F[t, Y], Y[t0] == Y0} over the intervaln [t0, b] by the n-step Euler's method. The resultn is in the form of a table of {t, Y} pairs.; Note that this function uses an exact increment h rather than converting it explicitly to numeric form using N. Of course you can readily change that or accomplish the corresponding thing by giving an approximate number for one of the endpoints. > I am trying to use Euler's Update Method to Numerically Integrate a > Function (I know how to use NDSolve for this case, but I want to > demonstrate an approximation method as well). For those familiar with > neuroscience, I am trying to model the Hodgkin Huxley Equations. I > have four ordinary differential equations (ODE) that I have written in > discrete form using Euler's Method. I am trying to solve for one of > these discrete equations, V, which is a function of the other three > differential equations (n, m, and h). All four equations are also a > function of time. Essentially, the command for NDSolve for this case > is in the following form: NDSolve[{ODE1, ODE2, ODE3, ODE4, > V[0]==0,n[0]==1, m[0]==2, h[0]==3},{V,n,m,h},{t,0,50},MaxSteps->1000] Instead of the above ODE input, I want to use Euler's Method. (i.e. V(t > +delta_t)=V(t)+delta_t(stuff). Now, the code below works for a > function of x and y. MY QUESTION IS: how would I change this code to > apply to my situation in which I want to solve for V[t] but it is a > function of n[t], m[t], and h[t]. I would appreciate any hints/clues/suggested programs. I know that > Mathematica has a built-in Explicit Euler Method, but I would like > to develop the program myself. I believe I am making a small mistake > that is preventing my success. Tara The following program code works for a function f(x,y): > euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:= Block[{ xold=x0, > yold=y0, > sollist={{x0,y0}}, > x,y,h > }, h=N[(xn-x0)/steps]; Do[ xnew=xold+h; > ynew=yold+h*(f/.{x->xold,y->yold}); > sollist=Append[sollist,{xnew,ynew}]; > xold=xnew; > yold=ynew, > {steps} > ]; Return[sollist] -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: creating a palette of characters Sir, I pasted your code into a new notebook and executed it. I get NotebookObject[] where Untitled-2 is in the square brackets. Somehow I expected to see a grid of buttons. Other responders seemed pleased with the results but I don't understand it. Did I do something wrong or did I just misunderstand what to expect? CreatePalette[Grid[ > {{Button[[, > With[{nb = InputNotebook[]}, NotebookWrite[nb, []]], > Button[], > With[{nb = InputNotebook[]}, NotebookWrite[nb, ]]]]}, > {Button[{, > With[{nb = InputNotebook[]}, NotebookWrite[nb, {]]], > Button[}, > With[{nb = InputNotebook[]}, NotebookWrite[nb, }]]]}, > {Button[(, > With[{nb = InputNotebook[]}, NotebookWrite[nb, (]]], > Button[), > With[{nb = InputNotebook[]}, NotebookWrite[nb, )]]]}}] > ] will make a palette with [,],{,},(,) that are interted into you > active notbook. Jens > >> hi, > i could do this in v5 but not v6. what changed? > i thought i would create a small palette of selected characters for a >> particular nb in v6. > it used to be extremely easy to do. i did the same thing again: > make a table, fill it with symbols, create palette from selection. > looks lovely, but nothing happens when i click on a symbol. > can someone tell me what i have to do differently? or is this change >> documented somewhere that i missed? > vale, >> rip >> === Subject: Implicit plotting issues So I am plotting an implicit function the that has small y values(0 to .5) and large x values(0 to 74). the graph i get is not readable and i can 't resize it using the edges it is lame. So does anyone know how to rescale the the implicit plot so that i could read it. I have included my code, below. I am using Mathematica 5.2 ---------------------------------------------------------------------------- - !(<< Graphics`ImplicitPlot`[IndentingNewLine] (u0 = 76;)n ([Omega] = [Pi]/12;)[IndentingNewLine] (uh = u0*[ExponentialE]^(((-k)*t));)[IndentingNewLine] (up = 7 ((5 - 5 [ExponentialE]^((-k) t) - (1/(k^2 + [Omega] ^2)) ((2 [ExponentialE]^((-k) t) k (((-k) Cos[ 3 [Omega]] + [Omega] Sin[ 3 [Omega]] + [ExponentialE]^(k t) ((k Cos[(((-3) + t)) [Omega]] + [Omega] Sin[(((-3) + t)) [Omega]]))))))));) [IndentingNewLine] (myANS = uh + up;)[IndentingNewLine] (U = myANS ;)n ImplicitPlot[U == 30, {t, 0, 72}, {k, 0.2, 0.48}]n Plot3D[U, {t, 0, 72}, {k, 0.2, 0.48}]) === Subject: Re: Implicit plotting issues > So I am plotting an implicit function the that has small y values(0 > to .5) and large x values(0 to 74). > the graph i get is not readable and i can 't resize it using the edges > it is lame. > So does anyone know how to rescale the the implicit plot so that i > could read it. I have included my code, below. I am using Mathematica > 5.2 > ----------------------------------------------------------------------------- Sorry for the poor text. as a side note what is the best way to copy text form Mathematica every time i try i get a lot of extra stuff???? === Subject: Re: Implicit plotting issues > So I am plotting an implicit function the that has small y values(0 > to .5) and large x values(0 to 74). > the graph i get is not readable and i can 't resize it using the edges > it is lame. > So does anyone know how to rescale the the implicit plot so that i > could read it. I have included my code, below. I am using Mathematica > 5.2 Use ContourPlot rather than ImplicitPlot. << Graphics`ImplicitPlot` u0 = 76; [Omega] = Pi/12; uh = u0/E^(k*t); up = 7*(5 - 5/E^(k*t) - (1/(k^2 + [Omega]^2))* ((2*k*((-k)*Cos[3*[Omega]] + [Omega]*Sin[3*[Omega]] + E^(k*t)*(k*Cos[(-3 + t)*[Omega]] + [Omega]*Sin[(-3 + t)*[Omega]])))/E^(k*t))); myANS = uh + up; U = myANS; ContourPlot[U - 30, {t, 0, 72}, {k, 0.2, 0.48}] Plot3D[U, {t, 0, 72}, {k, 0.2, 0.48}] -- Jean-Marc === Subject: Re: Implicit plotting issues > So I am plotting an implicit function the that has small y values(0 > to .5) and large x values(0 to 74). > the graph i get is not readable and i can 't resize it using the edges > it is lame. > So does anyone know how to rescale the the implicit plot so that i > could read it. I have included my code, below. I am using Mathematica > 5.2 > Could you please post future code snippets as InputForm so that we could read it? << Graphics`ImplicitPlot` u0 = 76; [Omega] = Pi/12; uh = u0/E^(k*t); up = 7*(5 - 5/E^(k*t) - (1/(k^2 + [Omega]^2))* ((2*k*((-k)*Cos[3*[Omega]] + [Omega]*Sin[3*[Omega]] + E^(k*t)*(k*Cos[(-3 + t)*[Omega]] + [Omega]*Sin[(-3 + t)*[Omega]])))/E^(k*t))); myANS = uh + up; U = myANS; If you like the aspect ratio of the (t,k)-plane in your 3d-plot, you should assign that plot to a variable p3d = Plot3D[U, {t, 0, 72}, {k, 0.2, 0.48}]; and extract the option AspectRatio from it: ImplicitPlot[U == 30, {t, 0, 72}, {k, 0.2, 0.48}, AspectRatio -> (AspectRatio /. AbsoluteOptions[p3d])] But you can give any number in AspectRatio->(height/width) hth, Peter === Subject: format mixed integers & floats with text styling (see ) Two years ago in I posed this problem of formatting a table column having a mixture of integers and approximate numbers in such a way that the decimal point on the floats would be vertically aligned with the implied decimal on the integers. For example, here's the data for the table: statNames = {N, Max, Min, Mean, Std.dev., Median}; statNumbers = {40, 103, 2, 56.8, 22.5, 59}; The object was to combine these into a properly formatted table starting from: (* original table *) TableForm[Transpose[{statNames,statNumbers}]] A good solution was proposed by Valeri Astanoff (sorry, I don't have the message reference number): pad[x_Integer]:=PaddedForm[x,3]; pad[x_Real]:=PaddedForm[x,4]; (* aligned table *) TableForm[Transpose[{statNames, pad /@ statNumbers}]] Now I need to complicate the problem by putting everything in a non-default font, by using, e.g., fmtTxt[txt_]:=Style[txt, FontFamily -> Arial,FontSize->12] so that the TableForm expression is changed to: (* formatted table *) TableForm[Transpose[{fmtTxt/@statNames, fmtTxt/@ pad /@ statNumbers}]] Unfortunately, this now breaks the nice vertical alignment. How can the alignment of aligned table be restored but still use such text formatting? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: format mixed integers & floats with text styling (see ) > Two years ago in I posed this problem of formatting a table > column having a mixture of integers and approximate numbers in such a > way that the decimal point on the floats would be vertically aligned > with the implied decimal on the integers. For example, here's the data for the table: statNames = {N, Max, Min, Mean, Std.dev., Median}; > statNumbers = {40, 103, 2, 56.8, 22.5, 59}; The object was to combine these into a properly formatted table starting > from: (* original table *) > TableForm[Transpose[{statNames,statNumbers}]] A good solution was proposed by Valeri Astanoff (sorry, I don't have the > message reference number): pad[x_Integer]:=PaddedForm[x,3]; > pad[x_Real]:=PaddedForm[x,4]; > (* aligned table *) > TableForm[Transpose[{statNames, pad /@ statNumbers}]] Now I need to complicate the problem by putting everything in a > non-default font, by using, e.g., fmtTxt[txt_]:=Style[txt, FontFamily -> Arial,FontSize->12] so that the TableForm expression is changed to: (* formatted table *) > TableForm[Transpose[{fmtTxt/@statNames, fmtTxt/@ pad /@ statNumbers}]] Unfortunately, this now breaks the nice vertical alignment. How can the > alignment of aligned table be restored but still use such text formatting? You cannot use any font *and* keep the table aligned. To do so, you must use monospace fonts such as Courier or LucidaConsole (~~ Monaco on Mac). (Arial has glyphs of variable sizes.) So try fmtTxt[txt_] := Style[txt, FontFamily -> LucidaConsole, FontSize -> 12] to get the desired result. See it in action on Windows at http://homepages.nyu.edu/~jmg336/mathematica/monospacefont.pdf The following web site may be useful: http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html -- Jean-Marc === Subject: Re: format mixed integers & floats with text styling (see ) That's what I was afraid of, especially since the monospacing of LucidaConsole is ugly (to my eyes). >> Two years ago in I posed this problem of formatting a table column >> having a mixture of integers and approximate numbers in such a way >> that the decimal point on the floats would be vertically aligned with >> the implied decimal on the integers. > For example, here's the data for the table: > statNames = {N, Max, Min, Mean, Std.dev., Median}; >> statNumbers = {40, 103, 2, 56.8, 22.5, 59}; > The object was to combine these into a properly formatted table >> starting from: > (* original table *) >> TableForm[Transpose[{statNames,statNumbers}]] > A good solution was proposed by Valeri Astanoff (sorry, I don't have >> the message reference number): > pad[x_Integer]:=PaddedForm[x,3]; >> pad[x_Real]:=PaddedForm[x,4]; >> (* aligned table *) >> TableForm[Transpose[{statNames, pad /@ statNumbers}]] > Now I need to complicate the problem by putting everything in a >> non-default font, by using, e.g., > fmtTxt[txt_]:=Style[txt, FontFamily -> Arial,FontSize->12] > so that the TableForm expression is changed to: > (* formatted table *) >> TableForm[Transpose[{fmtTxt/@statNames, fmtTxt/@ pad /@ statNumbers}]] > Unfortunately, this now breaks the nice vertical alignment. How can >> the alignment of aligned table be restored but still use such text >> formatting? You cannot use any font *and* keep the table aligned. To do so, you must > use monospace fonts such as Courier or LucidaConsole (~~ Monaco on Mac). > (Arial has glyphs of variable sizes.) So try fmtTxt[txt_] := > Style[txt, FontFamily -> LucidaConsole, FontSize -> 12] to get the desired result. See it in action on Windows at http://homepages.nyu.edu/~jmg336/mathematica/monospacefont.pdf The following web site may be useful: http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: format mixed integers & floats with text styling (see ) > Two years ago in I posed this problem of formatting a table > column having a mixture of integers and approximate numbers in such a > way that the decimal point on the floats would be vertically aligned > with the implied decimal on the integers. For example, here's the data for the table: statNames = {N, Max, Min, Mean, Std.dev., Median}; > statNumbers = {40, 103, 2, 56.8, 22.5, 59}; The object was to combine these into a properly formatted table starting > from: (* original table *) > TableForm[Transpose[{statNames,statNumbers}]] A good solution was proposed by Valeri Astanoff (sorry, I don't have the > message reference number): pad[x_Integer]:=PaddedForm[x,3]; > pad[x_Real]:=PaddedForm[x,4]; > (* aligned table *) > TableForm[Transpose[{statNames, pad /@ statNumbers}]] Now I need to complicate the problem by putting everything in a > non-default font, by using, e.g., fmtTxt[txt_]:=Style[txt, FontFamily -> Arial,FontSize->12] so that the TableForm expression is changed to: (* formatted table *) > TableForm[Transpose[{fmtTxt/@statNames, fmtTxt/@ pad /@ statNumbers}]] Unfortunately, this now breaks the nice vertical alignment. How can the > alignment of aligned table be restored but still use such text formatting? Use Grid. Grid[Transpose[{statNames, statNumbers}], Alignment -> {{Left, .}, None}, ItemStyle -> {FontFamily -> Arial, FontSize -> 12}] -- Helen Read University of Vermont === Subject: Background Color for a Panel Why isn't Background an option for Panel? Options[Panel] {Alignment -> {Automatic, Automatic}, Appearance -> Automatic, BaselinePosition -> Automatic, BaseStyle -> {}, DefaultBaseStyle -> Panel, Enabled -> Automatic, FrameMargins -> Automatic, ImageMargins -> 0, ImageSize -> Automatic} Nevertheless, even though the syntax coloring shows it is not allowed, Background does apparently work. Panel[Some text in the panel, Title for Panel, {{Bottom, Left}}, Background -> LightBlue] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone I am new to Mathematica, and I get one problem now, hope to get some > help here I got a list like this: {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: {0,3,3,4,10,9} For non-binary data, you could use one of the following: In[1]:= lst = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; Length /@ (lst /. 0 -> Sequence[]) Length /@ DeleteCases[lst, 0, {2}] Plus @@@ Unitize /@ lst Out[2]= {0, 3, 3, 4, 10, 9} Out[3]= {0, 3, 3, 4, 10, 9} Out[4]= {0, 3, 3, 4, 10, 9} -- Jean-Marc === Subject: Re: HELP: How to do count to the SUB-LIST Try: lst = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; Total/@Unitize[lst] > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > Hello Using Map and Count and your list (which is named lis here) the following code does what you want: (Count[#1, Except[0]] & ) /@ lis An alternative would be: (Length[Select[#1, #1 != 0 & ]] & ) /@ lis or without using pure functions: Clear[x, f1, f2]; f1[x_] := x != 0; f2[x_] := Length[Select[x, f1]]; Map[f2, lis] And so on Norbert Marxer === Subject: Re: HELP: How to do count to the SUB-LIST You'll probably get a lot of answers. This one seems sufficiently general to take care of the different lists you might encounter: Count[#, Except[0]]&/@ list should give you what you want. > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > As a newbie, I would go with the following pattern testing /See Condition in the Help/: In[3]:= (Count[#1, x_ /; x > 0] & ) /@ lst Out[3]= {0, 3, 3, 4, 10, 9} Where lst is your list. Of course if you have negative values you have to adjust the test. J=E1nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} Use Length, Count and Map (see Help for more information) eg: In[1]:= Length[#] - Count[#, 0] & /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} Out[1]= {0, 3, 3, 4, 10, 9} Ssezi === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > Hello Using Map and Count and your list (which is named lis here) the following code does what you want: (Count[#1, Except[0]] & ) /@ lis An alternative would be: (Length[Select[#1, #1 != 0 & ]] & ) /@ lis or without using pure functions: Clear[x, f1, f2]; f1[x_] := x != 0; f2[x_] := Length[Select[x, f1]]; Map[f2, lis] And so on Norbert Marxer === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some >> help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, >> {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, >> {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each >> sub >> list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > There are lots of ways, but one that I think should be pretty fast is: > ls = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, > 0}, {0, 0, > 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, > 3, 4, 2, > 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; > Total[Transpose[UnitStep[ls - 1]]] > {0, 3, 3, 4, 10, 9} > At first I thought that the following (Mathematica 6 only) variant > would be faster > Total[UnitStep[ls - 1], {2}] > {0, 3, 3, 4, 10, 9} > but tests seem to show that this isn't the case. > Andrzej Kozlowski I guess I should add that the above code will only work if (as is your example) all your numbers are non-negative integers. If they are not, you might as well use: Map[Count[#, x_ /; x != 0] &, ls] which is the most obvious way to do this in general, but in the non- negative integer case is much slower than the first method. Andrzej Kozlowski === Subject: Re: dereference variable With, Module, BlockTodd Johnson posted a question at: http://forums.wolfram.com/mathgroup/archive/2007/Oct/msg00395.html The example he provided was convoluted. Instead I will give simple examples that might show how to solve his problem. ------------------------------------ Module creates local variables which are given local values. The local variables take on the specified values only after they evaluate. In the following example Hold prevents the local variable from evaluating, and this is normally not the desired result. In the output below the local variable is (s$5). In[1]:= M1[x_]:= Module[{s=x+3}, Hold[x,s^2] ]; M1[z] Out[2]= Hold[z, s$5+4] With[{s=val},expr] replaces each instances of (s) in (expr) with (val). This replacement is made before (expr) has a chance to evaluate. I think Todd Johnson's problem will be solved if he uses With instead of Module. In[3]:= M2[x_]:= With[{s=x+3}, Hold[x,s^2] ]; M2[z] Out[4]= Hold[z,(3+z)+4] Note: When using With[{s=val}, expr] the value of (s) is (val) inside the With statement and you can't change it inside the With statement. On the other hand when using Module[{x,y}, expr] you can change the values assigned local variables (x,y) as much as you want during evaluation of (expr). ------------------------------------ Then there is Block[{x=0,y=y0}, expr] which evaluates (expr) with temporary values assigned to x, and y. You can also use Block[{x,y}, expr ] to evaluate (expr) with no values assigned to x, and y. Another thing about Block that isn't documented is that it temporarily clears any attributes of the affected symbols. It clears the attributes even if they were Protected (you don't need to Unprotect they symbols first). So for example in the next line the pattern matches. This is because Plus has the attributes Flat and Orderless. These attributes allow the pattern matcher to regard Plus[x,b,z] as Plus[b,Plus[x,z]]. In[5]:= MatchQ[Plus[x,b,z],Plus[b,_]]Out[5]= True In the next line the pattern doesn't match because Block supresses all attributes of Plus. In[6]:= Block[{Plus}, MatchQ[Plus[x,b,z],Plus[b,_]]] Out[6]= False ---------------------------------------- Alos in the next line we give (foo) the Orderless attribute inside Block. You will notice (foo) is only Orderless inside the Block. In[7]:= Block[{foo},Attributes[foo]={Orderless};foo[z,a,x]] Out[7]= foo[a,x,z] ---------------------------------------- For more on this stuff see: http://reference.wolfram.com/mathematica/ref/With.html http://reference.wolfram.com/mathematica/ref/Module.html http://reference.wolfram.com/mathematica/ref/Block.html http://reference.wolfram.com/mathematica/tutorial/ModulesAndLocalVariables.h tml http://reference.wolfram.com/mathematica/tutorial/BlocksComparedWithModules. html ----------------------------------------------------- You could also open my Tricks notebook at http://library.wolfram.com/infocenter/MathSource/4557/ And see my sections on Evaluate and Unevaluated. ------------------------------------------------------ For more on working with unevaluated expressions see the notebook at http://library.wolfram.com/infocenter/Conferences/377/ But beware that the syntax of some features such as ReplacePart is different in Mathematica 6 than it was when that notebook was written. --------------------------------------------- Ted Ersek === Subject: Re: Re: What is the purpose of the Defer Command? > That is, I can integrate one of the output cells in your Defer example by > adding Evaluatable to its properties. That has nothing to do with Defer; you're talking about CellPrint, and I see no advantage to CellPrint over Print. Evaluate the Help example, and now you'll see not five integrals, but 10, and they won't even be in a sensible order (1, 1, 2, 3, 4, 5, 2, 3, 4, 5 at my machine). Evaluate it again and you have 15 output cells, and again they're in no useful order. Using Print, you have 5 outputs no matter how many times you evaluate it, and they're in the proper order. And... changing the properties of a cell is more transparent for newbies than using First to remove Defer or ReleaseHold to remove HoldForm, or simply copy/paste from an earlier line? I don't think so. I also see no reason to involve copy/paste in the use of Defer... no more so than any other wrapper, anyway. First or Defer->Identity removes the wrapper. Use Defer the first time the expression is formed (and save it), and no copy/paste will be required. I'm not sure Defer does anything HoldForm doesn't do... but I can type it faster, and I can type First faster than I can type ReleaseHold. Bobby > Nice. > However, I'll hazard more opinion. > Your first example with HoldForm always requires ReleaseHold to integrate > any of the expressions in the output cells. Your second example with > Defer > can be integrated differently, perhaps in a way more appropriate for a > tutorial or help page, e.g. . . . Perform the computation yourself > before > evaluating the following cells . . .. > That is, I can integrate one of the output cells in your Defer example by > adding Evaluatable to its properties. I cannot do so with your HoldForm > example, which requires ReleaseHold. Both the Evaluatable property and > ReleaseHold can be programmed into document/cell creation, but I think > the > Evaluatable property is more transparent. Someone new to Mathematica > learning about, say, integrals, would probably be distracted by postfix > ReleaseHolds. Moreover, those ReleaseHolds make document creation more > complex (though, since this is software, anything is possible). > Vince Virgilio How about this? > Function[{n}, >> Print[save[n] = HoldForm[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ >> Range[5]; > That gives the same outputs as the Defer example and it allows, for >> instance, > save[3] // ReleaseHold > 6 - 16/[ExponentialE] > We can use Defer almost the same way, however: > Function[{n}, >> Print[save[n] = Defer[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ >> Range[5]; > First@save[3] > 6 - 16/[ExponentialE] > Bobby >>> Still, my question is: What is the purpose of the Defer Command? >>> The only potential purpose that I can see is for didactic purposes, >> to > show > preliminary expressions before they are automatically evaluated. But >> the > only way to get Defer to evaluate is by copying and pasting and then > evaluating, by using Shift-Ctrl-L and then evaluating, or by > evaluating in > place. All of these operations leave no record of the steps taken. >> That > goes > contrary to any didactic purpose. >>> -- > David Park > djmp...@comcast.nethttp://home.comcast.net/~djmpark/ > Have you noticed the example in the documentation (http:// >> reference.wolfram.com/mathematica/ref/Defer.html) that uses Defer to >> create cells with unevaluated contents? That has didactic potential. > Can that example be rewritten without Defer, with similar complexity? > Vince Virgilio >>>> -- >> DrMajorBob@bigfoot.com >> -- DrMajorBob@bigfoot.com === Subject: Re: Re: What is the purpose of the Defer Command? How about this? Function[{n}, Print[save[n] = HoldForm[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ Range[5]; That gives the same outputs as the Defer example and it allows, for instance, save[3] // ReleaseHold 6 - 16/[ExponentialE] We can use Defer almost the same way, however: Function[{n}, Print[save[n] = Defer[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ Range[5]; First@save[3] 6 - 16/[ExponentialE] Bobby >> Still, my question is: What is the purpose of the Defer Command? > The only potential purpose that I can see is for didactic purposes, to >> show >> preliminary expressions before they are automatically evaluated. But the >> only way to get Defer to evaluate is by copying and pasting and then >> evaluating, by using Shift-Ctrl-L and then evaluating, or by >> evaluating in >> place. All of these operations leave no record of the steps taken. That >> goes >> contrary to any didactic purpose. > -- >> David Park >> djmp...@comcast.nethttp://home.comcast.net/~djmpark/ > Have you noticed the example in the documentation (http:// > reference.wolfram.com/mathematica/ref/Defer.html) that uses Defer to > create cells with unevaluated contents? That has didactic potential. > Can that example be rewritten without Defer, with similar complexity? > Vince Virgilio -- DrMajorBob@bigfoot.com === Subject: Re: import function This is a tricky question to answer without the data file in question. I would certainly recommend sending this to Wolfram Technical support (along with the problematic data file). Remember though that Import[....,Table] is a import format tht uses a wide variety of heuristics to figure out what the contents of the file is and then attempts to turn that file's data into the proper formats and types. If you have a much more strucured file, it may make more predictable sense to use a more constrained import format-- rather than Table--to read in the file. Hope that this helps, --David http://scientificarts.com/worklife A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... > I have a question regarding the import function in mathematica 6. > When I import a long array of reals into a table, the function > appears to skip certain array entries, for example the 20230 th row. > This does not occur in mathematica 5.2 using identical code. > Code is below. > In[1]:= > SetDirectory[/Users/elleryames/Research/VoltageStability/Data/ > run0239]; > FileName=run0239; > FileImport=Import[FileName<>.dat,Table]; > Best, > Ellery Ames === Subject: Re: Strange behaviour of Do in Compile Better yet, never use Return at all. I never do. Bobby > Compile[{}, Do[If[i > 10, Return[i + 1]], {i, 10}]][] > On my machine, this returns such values as: > 176792864 > 176795048 > 176797232 > The following slight modification always returns the value 11: > Compile[{}, Do[If[i > 10, Return[i]], {i, 10}]][] > Can anyone explain this behaviour? > Anyway, I guess the moral is: always explicitly return a value from > Compile, > and don't rely on the usual return value properties of flow-control > constructs like Do. -- DrMajorBob@bigfoot.com === Subject: Strange behaviour of Do in Compile Compile[{}, Do[If[i > 10, Return[i + 1]], {i, 10}]][] On my machine, this returns such values as: 176792864 176795048 176797232 The following slight modification always returns the value 11: Compile[{}, Do[If[i > 10, Return[i]], {i, 10}]][] Can anyone explain this behaviour? Anyway, I guess the moral is: always explicitly return a value from Compile, and don't rely on the usual return value properties of flow-control constructs like Do. === Subject: Re: Locator in Manipulate's graphic. > Manipulate[ > Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > (Locator[#,Appearance->Graphics[Circle[#,2]])&}] That has a lot of unmatched brackets, which in general makes it rather hard to unravel what your problem might be. I had already noticed, though, that locators have no options or syntax, to speak of, when used as Manipulator variables. In help it says {u, Locator}, and that's apparently IT, despite the live link from Locator to the more feature-rich Locator used elsewhere. I can find no examples where Locator is used the way you want to use it. (Unfortunately.) Bobby > Can anyone see a way to change the Locator's appearance in > Manipulate. > i.e., from the documentation: > Manipulate[ > Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > Locator}] > I've tried the obvious generalization: > Manipulate[ > Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > (Locator[#,Appearance->Graphics[Circle[#,2]])&}] > without success. Any ideas? W. Craig Carter -- DrMajorBob@bigfoot.com === Subject: Re: Locator in Manipulate's graphic. I believe this is the same issue I once had that was answered in this group by John Fultz . I don't have his direct reply, but here's a response I sent that includes his explanation: I'm still not sure I completely understand.... OK, as I can see, the locator is a large, framed, red rectangle when I use dot=Graphics[{PointSize[Medium],Point[{0,0}]},Background->Red, Frame->True] but why, given the option LocatorAutoCreate->All, don't I then see a bunch of large, framed, red rectangles when I click to create new points? Is it just that the new points are really there but I cannot see them, that I can only see the one point that's on top because I created it last? >> Here's a LocatorPane inside a DynamicModule with a Locator initialized >> >> at the origin and where additional Locator points will be created at >> mouse clicks: >> >> dot=Automatic; >> >> DynamicModule[{pts = {{0, 0}}}, >> LocatorPane[Dynamic[pts], >> Graphics[Point /@ pts], >> Appearance -> dot, >> LocatorAutoCreate -> All] >> ] >> >> This works as expected. (The setting Automatic for Appearance is the >> default.) >> >> Now change the definition of dot to: >> >> dot=Graphics[Disk[],ImageSize->5] >> >> Still OK. But, finally, change the defintion of dot to: >> >> Graphics[{PointSize[Medium],Point[{0,0}]}] >> >> Now it does NOT work as expected: Although the initialized points do >> appear correctly, and a new dot appears at the first click in the >> output, upon each additional click a new dot does not appear but, >> instead, that one new dot moves to the location of the click. >> >> Diagnosis? Cure? > > This is correct behavior. If you change dot to be... > > dot = Graphics[{PointSize[Medium], Point[{0, 0}]}, Background -> Red, > Frame -> True] > > ...and play around with the result, the reason for the behavior should start to > be come obvious. The default size of a Graphics[] object is the size of the > graphic. And the entire graphics object represents the Locator, so all you're > doing is moving the existing Locator (as you should correctly do when clicking > directly on a Locator), rather than creating a new one. The only reason the > Disk[] example worked as you expected is because you set the ImageSize to be so > small, which affected the size of not just the disk, but the Locator itself. > Can anyone see a way to change the Locator's appearance in > Manipulate. i.e., from the documentation: Manipulate[ > Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > Locator}] I've tried the obvious generalization: Manipulate[ > Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > (Locator[#,Appearance->Graphics[Circle[#,2]])&}] without success. Any ideas? > W. Craig Carter -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Locator in Manipulate's graphic. Manipulate[ Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator, Appearance -> (Graphics[Circle[{0, 0}, 0.1], PlotRange -> 2])}] work fine. Jens > Can anyone see a way to change the Locator's appearance in > Manipulate. i.e., from the documentation: Manipulate[ > Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > Locator}] I've tried the obvious generalization: Manipulate[ > Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > (Locator[#,Appearance->Graphics[Circle[#,2]])&}] without success. Any ideas? > W. Craig Carter === Subject: Re: Locator in Manipulate's graphic. Manipulate[ Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator, Appearance -> Graphics[Circle[], ImageSize -> 20]}] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Can anyone see a way to change the Locator's appearance in > Manipulate. > i.e., from the documentation: > Manipulate[ > Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > Locator}] > I've tried the obvious generalization: > Manipulate[ > Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, > (Locator[#,Appearance->Graphics[Circle[#,2]])&}] > without success. Any ideas? W. Craig Carter > === Subject: Locator in Manipulate's graphic. Can anyone see a way to change the Locator's appearance in Manipulate. i.e., from the documentation: Manipulate[ Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator}] I've tried the obvious generalization: Manipulate[ Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, (Locator[#,Appearance->Graphics[Circle[#,2]])&}] without success. Any ideas? W. Craig Carter === Subject: Re: How to do count for sub list????? If all the numbers are 0 or 1, you can Map Total: list = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}; Total /@ list {0, 0, 2, 1, 0, 0, 1, 1} The more general situation can be reduced to that using Unitize: list = RandomInteger[{-1, 1}, {10, 10}] {{-1, 0, 1, 1, 0, 0, 0, 0, -1, 1}, {0, 1, 0, 1, 1, -1, -1, 0, -1, -1}, {-1, 0, 1, 0, 1, -1, -1, -1, 0, 0}, {1, 0, 0, 1, 0, 0, -1, 1, 1, -1}, {0, 1, 0, 1, -1, -1, -1, 1, 0, 0}, {1, 1, 1, 0, 1, 1, -1, 0, -1, 0}, {0, -1, 1, 0, 1, 1, -1, -1, 0, -1}, {1, 0, 1, 0, 0, -1, 0, 1, -1, 1}, {-1, -1, 0, -1, -1, 0, 0, 1, 1, -1}, {0, -1, 1, 0, 0, 1, -1, -1, 1, -1}} Total /@ Unitize@list {5, 7, 6, 6, 6, 7, 7, 6, 7, 7} I suspect this is faster than using Count. This counts non-zeroes by columns: Total@Unitize@list {6, 6, 6, 5, 6, 7, 7, 7, 7, 7} Bobby > name your list: > l = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, > 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, > 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, > 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, > 0}}; > and use > Table[Length[l[[n]]] - Length[Position[l[[n]], 0]], {n, 1, Length[l]}] > or > Length[#] - Length[Position[#, 0]] & /@ l By the way, the result is {0, 0, 2, 1, 0, 0, 1, 1} and not > {0,0,1,1,0,0,1,1= > } > as written in your e-mail. > Ricardo > Hallo, everyone > I am new to Mathematica, and now I have a problem with it, hope to get >> some help from here. > I have a > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { >> 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { >> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { >> 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} >>> I need to get a list which represent the number of NON-zero number in >> each sublist. > I should get a list like: > {0,0,1,1,0,0,1,1} >> -- > ____________________________________ > Ricardo Elgul Samad > tel: (+55 11) 3133-9372 > fax: (+55 11) 3133-9374 > Centro de Lasers e Aplica=E7=F5es > IPEN/CNEN-SP > AV. Prof. Lineu Prestes 2242 > Cidade Universit=E1ria > 05508-000 > S=E3o Paulo - SP > Brazil > ____________________________________ -- DrMajorBob@bigfoot.com === Subject: Re: How to do count for sub list????? > I am new to Mathematica, and now I have a problem with it, hope to get > some help from here. I have a {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} I need to get a list which represent the number of NON-zero number in > each sublist. I should get a list like: {0,0,1,1,0,0,1,1} -------^ I believe that the third entry should be a two rather than a one. Assuming that you want to count the numbers of ones within each sublists, you could use, among many other way, one of the following: In[1]:= lst = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}; Count[#, 1] & /@ lst Total[Transpose@lst] Plus @@@ lst Out[2]= {0, 0, 2, 1, 0, 0, 1, 1} Out[3]= {0, 0, 2, 1, 0, 0, 1, 1} Out[4]= {0, 0, 2, 1, 0, 0, 1, 1} -- Jean-Marc === Subject: Re: How to do count for sub list????? > Hallo, everyone I am new to Mathematica, and now I have a problem with it, hope to get > some help from here. I have a {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} I need to get a list which represent the number of NON-zero number in > each sublist. I should get a list like: {0,0,1,1,0,0,1,1} > In[5]:= (Count[1, x_ /; x != 0] & ) /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} Out[5]= {0, 0, 2, 1, 0, 0, 1, 1} The third list has two non-zero elements. -- Szabolcs === Subject: Re: Re: Strange Manipulate+ContourPlot behavior With a fresh kernel in v6.0.1, none of THOSE results are Indeterminate: e = (b (a - a p + b p))/(2 a b + (a - b)^2 p); rules = {a -> 0, b -> 0, p -> 0}; Fold[ReplaceAll[#1, #2] &, e, #] & /@ Permutations[rules] {1, 1, 0, 0, 1/2, 1/2} $Version 6.0 for Microsoft Windows (32-bit) (June 19, 2007) That's not to say some other evaluation order can't occur, of course. Bobby > I suspect the discrepancy between Manipulate[ContourPlot[e and > Manipulate[ContourPlot[Evaluate[e has to do with automatic > simplification rules. The expression being plotted evaluates to 1, 0, > 1/2 or Indeterminate depending on the order in which replacement rules > are applied. > e = (b (a - a p + b p))/(2 a b + (a - b)^2 p); > rules = {a -> 0, b -> 0, p -> 0}; > Fold[ReplaceAll[#1, #2] &, e, #] & /@ Permutations[rules] > Is it possible to disable automatic simplification rules to prevent > expressions like a / (2 a) simplifying to 1/2? > Not so weird... > In[]:= a = 0; b = 0; p = 0; (b (a - a p + b p))/(-2 a b (-1 + p) + >> a^2 p + b^2 p) > Out[]:= Indeterminate > Syd > Syd Geraghty B.Sc., M.Sc. >> sydgerag...@mac.com >> San Jose, CA >>> Manipulate[ > ContourPlot[( > b (a - a p + b p))/(-2 a b (-1 + p) + a^2 p + b^2 p), {a, 0, 1}, > {b, > 0, 1}], {p, 0, 1}] > That is weird. Sticking in an Evaluate[] around the expression fixes >> the problem -- until the slider is first moved. I guess I'd just >> recommend avoiding p = 0 ... :) > Will -- DrMajorBob@bigfoot.com === Subject: Re: Evaluation question > >> At what point is Unevaluated stripped? > For instance, in the following, unevaluated is stripped even though >> arguments are not evaluated >> a := Unevaluated[2 + 3] > So a:=Unevaluated[2+3] and a=Unevaluated[2+3] seem to work the same >> here >Unevaluated is stripped from an argument of a function before the > function is checked for the Hold attributes. It is easy to see this > with Trace: SetAttributes[f, HoldAll] Trace[f[Unevaluated[x]]] > {HoldForm[f[x]], HoldForm[f[Unevaluated[x]]]} Unevaluated was stripped but then it was restored, as the expression > did not change. On the other hand here Unevaluated is stripped but > this time not restred: Trace[a := Unevaluated[2 + 3]] > {HoldForm[a := 2 + 3], HoldForm[Null]} Normally, Unevaluated that had been stripped from an argument is > restored if no applicable rules were found after it was stripped. In > this case it is, however, not restored, and to tell the truth at the > moment it is not clear to me why. > >> Also, consider > a=Unevaluated[Unevaluated[2+3]] >> OwnValues[a] > OwnValues doesn't show that a has an Unevaluated wrapper, even though >> a /. OwnValues[a] results in Unevaluated[2+3], why is that? Doing a Trace on OwnValues clearly shows evaluation: Attributes[OwnValues] > {HoldAll, Protected} a = Unevaluated[Unevaluated[2 + 3]] Trace[OwnValues[a]] > {HoldForm[OwnValues[a]], HoldForm[{HoldPattern[a] :> Unevaluated[2 + > 3]}], > {HoldForm[HoldPattern[a] :> 2 + 3], > HoldForm[HoldPattern[a] :> 2 + 3]}, > HoldForm[{HoldPattern[a] :> 2 + 3}]} You can clealry see that Unevaluated got stripped during evaluation of: HoldPattern[a] :> Unevaluated[2 + 3] > HoldPattern[a] :> 2 + 3 Just as in the earlier example Unevaluated is stripped but not > restored, and again I find it a bit of a puzzle. Perhaps someone else > can explain this point? > It seems that Rule and RuleDelayed are evaluated to themselves: In[1]:= Trace[1->2+3] Out[1]= {{2+3,5},1->5,1->5} In[2]:= Attributes[f]=Attributes[Rule] Out[2]= {Protected,SequenceHold} In[3]:= Trace[f[1,2+3]] Out[3]= {{2+3,5},f[1,5]} Note the difference between the two completely analogous situations. It seems that Rule is not just a symbol without meaning, but it has some built-in definitions. (BTW, Rule and RuleDelayed also influence scoping, and can interact in strange ways with Module, Function etc.) I did not know that Unevaluated is stripped and then *restored* later. I thought that it works this way: Unevaluated is stripped when the surrounding function is evaluated (more specifically: when the DownValues are applied), but it is left untouched if no DownValues apply. This seems to be consistent with the fact that Rule is evaluated to itself, and that Unevaluated is stripped from Rule. After a little experimentation, I think I understand why Unevaluated is stripped and restored. Consider the following example: In[1]:= f[x_?StringQ] := x In[2]:= f[Unevaluated[1+2]]//Trace Out[2]= {f[1+2],{{1+2,3},StringQ[3],False},f[1+2],f[Unevaluated[1+2]]} However, there are still a few strange things that I do not understand (apart from the behaviour of Rule). For example: In[1]:= NumericQ[Unevaluated[1+2]]//Trace Out[1]= {NumericQ[1+2],False} In[2]:= SetAttributes[f,NumericFunction] In[3]:= NumericQ[f[1,2]]//Trace Out[3]= {NumericQ[f[1,2]],True} In[4]:= NumericQ[Unevaluated[f[1,2]]]//Trace Out[4]= {NumericQ[f[1,2]],False} -- Szabolcs === Subject: Re: Evaluation question > Wihtout evaluation 1+2 is just a symbol and not the number 3 so > NumericQ returns False. I should have been more precise. Unevaluated 1+2 is an expression (rather than a symbol); in fact it is the expression Plus[1,2], which of course is not numeric. It's value is, of course, numeric, but that is obtained only after evaluation. Andrzej Kozlowski > At what point is Unevaluated stripped? > For instance, in the following, unevaluated is stripped even though >> arguments are not evaluated >> a := Unevaluated[2 + 3] > So a:=Unevaluated[2+3] and a=Unevaluated[2+3] seem to work the same >> here >> Unevaluated is stripped from an argument of a function before > the function is checked for the Hold attributes. It is easy to > see this with Trace: > SetAttributes[f, HoldAll] > Trace[f[Unevaluated[x]]] > {HoldForm[f[x]], HoldForm[f[Unevaluated[x]]]} > Unevaluated was stripped but then it was restored, as the > expression did not change. On the other hand here Unevaluated is > stripped but this time not restred: > Trace[a := Unevaluated[2 + 3]] > {HoldForm[a := 2 + 3], HoldForm[Null]} > Normally, Unevaluated that had been stripped from an argument is > restored if no applicable rules were found after it was stripped. > In this case it is, however, not restored, and to tell the truth > at the moment it is not clear to me why. >> Also, consider > a=Unevaluated[Unevaluated[2+3]] >> OwnValues[a] > OwnValues doesn't show that a has an Unevaluated wrapper, even >> though >> a /. OwnValues[a] results in Unevaluated[2+3], why is that? > Doing a Trace on OwnValues clearly shows evaluation: > Attributes[OwnValues] > {HoldAll, Protected} > a = Unevaluated[Unevaluated[2 + 3]] > Trace[OwnValues[a]] > {HoldForm[OwnValues[a]], HoldForm[{HoldPattern[a] :> Unevaluated > [2 + 3]}], > {HoldForm[HoldPattern[a] :> 2 + 3], > HoldForm[HoldPattern[a] :> 2 + 3]}, > HoldForm[{HoldPattern[a] :> 2 + 3}]} > You can clealry see that Unevaluated got stripped during > evaluation of: > HoldPattern[a] :> Unevaluated[2 + 3] > HoldPattern[a] :> 2 + 3 > Just as in the earlier example Unevaluated is stripped but not > restored, and again I find it a bit of a puzzle. Perhaps someone > else can explain this point? > It seems that Rule and RuleDelayed are evaluated to themselves: > In[1]:= Trace[1->2+3] >> Out[1]= {{2+3,5},1->5,1->5} > In[2]:= Attributes[f]=Attributes[Rule] >> Out[2]= {Protected,SequenceHold} > In[3]:= Trace[f[1,2+3]] >> Out[3]= {{2+3,5},f[1,5]} > Note the difference between the two completely analogous >> situations. It seems that Rule is not just a symbol without >> meaning, but it has some built-in definitions. (BTW, Rule and >> RuleDelayed also influence scoping, and can interact in strange >> ways with Module, Function etc.) > It seems that you are right here. I have always thought that Rule > was nothing more than a container but it seems indeed that it has > some sort of rule attatched to it, which causes the doubl > appearance of 1->5 in the above Trace and prevents Unevaluated from > being restored. However, I am still puzzled by this. Evaluates to > itself does not seem to me to explain much. It clearly is doing > something which results in the same output as the input, at least > in this case. But what? I did not know that Unevaluated is stripped and then *restored* >> later. I thought that it works this way: Unevaluated is stripped >> when the surrounding function is evaluated (more specifically: >> when the DownValues are applied), but it is left untouched if no >> DownValues apply. This seems to be consistent with the fact that >> Rule is evaluated to itself, and that Unevaluated is stripped >> from Rule. > The stripping of Unevaluated is described wherever the Mathematica > main evaluation loop is described, which, as far as I know is in > MathSource and perhaps still is), in David Wagner's book Power > Programming with Mathematica. I tis also described in Michael > Trott's Mathematica Guide Books (the Programming section), though > not in as much detail. After a little experimentation, I think I understand why >> Unevaluated is stripped and restored. Consider the following >> example: > In[1]:= f[x_?StringQ] := x > In[2]:= f[Unevaluated[1+2]]//Trace >> Out[2]= {f[1+2],{{1+2,3},StringQ[3],False},f[1+2],f[Unevaluated[1 >> +2]]} > However, there are still a few strange things that I do not >> understand (apart from the behaviour of Rule). For example: > In[1]:= NumericQ[Unevaluated[1+2]]//Trace >> Out[1]= {NumericQ[1+2],False} > In[2]:= SetAttributes[f,NumericFunction] > In[3]:= NumericQ[f[1,2]]//Trace >> Out[3]= {NumericQ[f[1,2]],True} > In[4]:= NumericQ[Unevaluated[f[1,2]]]//Trace >> Out[4]= {NumericQ[f[1,2]],False} > I do not find this surprising. Wihtout evaluation 1+2 is just a > symbol and not the number 3 so NumericQ returns False. > Andrzej Kozlowski > === Subject: Re: Evaluation question I think this involves a rather subtle difference between an expression and its value. (It is sometimes obscured by the fact that soem expressions evaluate to themselves so are their own values). In this case, it is the values of Plus that are considered numerical, but values are obtianed after evaluation. The unevaluated expression Plus[1,2] is not itself numerical. Andrzej Kozlowski > Wihtout evaluation 1+2 is just a symbol and not the number 3 so > NumericQ returns False. >> I should have been more precise. Unevaluated 1+2 is an expression >> (rather than a symbol); in fact it is the expression Plus[1,2], >> which of course is not numeric. It's value is, of course, numeric, = >> but that is obtained only after evaluation. > But Plus has the attribute NumericFunction, therefore it should be > considered numerical whenever all of its arguments are numerical. > For example, see In[2] and In[3] below. f[1,2] stays unevaluated, > but NumericQ[f[1,2]] still returns True because 'f' has the > attribute NumericFunction, and all of its arguments (1 and 2) are > numerical. >> In[1]:= NumericQ[Unevaluated[1+2]]//Trace >> Out[1]= {NumericQ[1+2],False} > In[2]:= SetAttributes[f,NumericFunction] > In[3]:= NumericQ[f[1,2]]//Trace >> Out[3]= {NumericQ[f[1,2]],True} > In[4]:= NumericQ[Unevaluated[f[1,2]]]//Trace >> Out[4]= {NumericQ[f[1,2]],False} > I do not find this surprising. Wihtout evaluation 1+2 is just a > symbol and not the number 3 so NumericQ returns False. -- > Szabolcs === Subject: Re: Evaluation question >> Wihtout evaluation 1+2 is just a symbol and not the number 3 so >> NumericQ returns False. I should have been more precise. Unevaluated 1+2 is an expression > (rather than a symbol); in fact it is the expression Plus[1,2], which > of course is not numeric. It's value is, of course, numeric, but that > is obtained only after evaluation. But Plus has the attribute NumericFunction, therefore it should be considered numerical whenever all of its arguments are numerical. For example, see In[2] and In[3] below. f[1,2] stays unevaluated, but NumericQ[f[1,2]] still returns True because 'f' has the attribute NumericFunction, and all of its arguments (1 and 2) are numerical. > In[1]:= NumericQ[Unevaluated[1+2]]//Trace > Out[1]= {NumericQ[1+2],False} > In[2]:= SetAttributes[f,NumericFunction] > In[3]:= NumericQ[f[1,2]]//Trace > Out[3]= {NumericQ[f[1,2]],True} > In[4]:= NumericQ[Unevaluated[f[1,2]]]//Trace > Out[4]= {NumericQ[f[1,2]],False} > I do not find this surprising. Wihtout evaluation 1+2 is just a >> symbol and not the number 3 so NumericQ returns False. >> -- Szabolcs === Subject: Re: Evaluation question > It seems that Rule and RuleDelayed are evaluated to themselves: In[1]:= Trace[1->2+3] > Out[1]= {{2+3,5},1->5,1->5} In[2]:= Attributes[f]=Attributes[Rule] > Out[2]= {Protected,SequenceHold} In[3]:= Trace[f[1,2+3]] > Out[3]= {{2+3,5},f[1,5]} > Block[] can free Rule from this special behaviour: In[1]:= Block[{Rule},1->Unevaluated[2+3]]//Trace Out[1]= {Block[{Rule},1->Unevaluated[2+3]],{1->2+3,1->Unevaluated[2+3]},1->Unevaluat ed[2+3],1->2+3,1->2+3,{2+3,5},1->5,1->5} -- Szabolcs === Subject: Evaluation in Mathematica: Until no rules apply? Or until the expression The documentation says: As discussed in Principles of Evaluation, Mathematica follows the principle that each expression is evaluated until no further definitions apply. This means that Mathematica must continue re-evaluating results until it gets an expression which remains unchanged through the evaluation procedure. This is not very clear. Does Mathematica evaluate the expression until no rules apply? Or does it stop when application of a rule does not change the expression any more? A few examples: In[1]:= a := a a // Trace Out[2]= {} In[3]:= b[x] := b[x] b[x] // Trace Out[4]= {b[x], b[x]} In[5]:= c[p_] := c[p] c[x] // Trace During evaluation of In[5]:= $IterationLimit::itlim: Iteration limit of 4096 exceeded. >> Out[6]= {c[x],c[x],c[x],c[x],c[x], ... (and so forth) In[7]:= d[x /; True] := d[x] d[x] // Trace Out[8]= {d[x], d[x]} In[9]:= e[x] // Trace Could someone explain how Mathematica decides when to finish the evaluation of an expression? -- Szabolcs === Subject: Re: Format->Magnification does notwork on notebook Sorry; I stand corrected. Bobby > ----- Original Message ----- === > Subject: > Format->Magnification does notwork on notebook >> on the menu doesn't work properly either, it only magnifies the cells >> that are selected, instead of the entire notebook. It works fine on >> Mac >> OS X. The above is BY DESIGN. it works the same on windows. >> Wrong. Not at my WinXP machine, it doesn't! The magnification popup >> affects the entire notebook, whether I have any cells selected or not, >> and >> that has been true in every version I've used. > Bobby > Hello; > He is talking about using the MENU, not the magnification POPUP. > I answered about the MENU part, which only magnifies the cell selected > on my > machine (windows) > Here is a movie showing this: > http://12000.org/tmp/101307/mag.htm > Nasser -- DrMajorBob@bigfoot.com === Subject: Re: Format->Magnification does notwork on notebook ----- Original Message ----- === Subject: Re: Format->Magnification does notwork on notebook > on the menu doesn't work properly either, it only magnifies the cells > that are selected, instead of the entire notebook. It works fine on > Mac > OS X. > The above is BY DESIGN. it works the same on windows. > Wrong. Not at my WinXP machine, it doesn't! The magnification popup > affects the entire notebook, whether I have any cells selected or not, and > that has been true in every version I've used. > Bobby > Hello; He is talking about using the MENU, not the magnification POPUP. I answered about the MENU part, which only magnifies the cell selected on my machine (windows) Here is a movie showing this: http://12000.org/tmp/101307/mag.htm Nasser === Subject: Re: Format->Magnification does notwork on notebook > it only magnifies the cells that are selected, instead of the entire > notebook. > The above is BY DESIGN. it works the same on windows. Wrong. Not at my WinXP machine, it doesn't! The magnification popup affects the entire notebook, whether I have any cells selected or not, and that has been true in every version I've used. Bobby >> I have the same problem, the magnification popup on the bottom right >> doesn't show on linux (ubuntu feisty). The magnification function >> itself >> on the menu doesn't work properly either, it only magnifies the cells >> that are selected, instead of the entire notebook. It works fine on >> Mac >> OS X. > Ramiro > ref this part of what you said: > it only magnifies the cells that are selected, instead of the entire > notebook. > The above is BY DESIGN. it works the same on windows. > Nasser -- DrMajorBob@bigfoot.com === Subject: Re: Format->Magnification NO, not completely correct: In Windows, the magnification hot spot in the bottom-left corner of the notebook window will magnify EVERYTHING in the notebook. What is true is that the menu item Format > Magnification magnifies only what's been selected. >> I have the same problem, the magnification popup on the bottom right >> doesn't show on linux (ubuntu feisty). The magnification function itself >> on the menu doesn't work properly either, it only magnifies the cells >> that are selected, instead of the entire notebook. It works fine on Mac >> OS X. > Ramiro ref this part of what you said: it only magnifies the cells that are selected, instead of the entire > notebook. The above is BY DESIGN. it works the same on windows. Nasser > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Format->Magnification does > ref this part of what you said: > it only magnifies the cells that are selected, instead of the entire > notebook. This is correct, my mistake. However, the magnification on the lower right corner in the status area of the window does apply to the entire notebook in both my mac and windows, but it does not appear on linux. Is there a way I can put it there? Ramiro === Subject: Re: Format->Magnification does not work on notebook > Hi Bhuvanesh, > I am using Mathematica 6.0.0 for Linux. I don't seem to have any popup > menu at the bottom right of the notebook window. > What did you have in mind? > Best, Martin > Do you mean you do NOT see this in your notebook on Linux? see screen shot > below > http://12000.org/tmp/101107/mag.PNG > Nasser Not there in my linux ( 6.0.1.0) version. I'd have to check (at home, later) to see if that shows up in the windows version. -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Format->Magnification does notwork on notebook >I have the same problem, the magnification popup on the bottom right > doesn't show on linux (ubuntu feisty). The magnification function itself > on the menu doesn't work properly either, it only magnifies the cells > that are selected, instead of the entire notebook. It works fine on Mac > OS X. > Ramiro > ref this part of what you said: it only magnifies the cells that are selected, instead of the entire notebook. The above is BY DESIGN. it works the same on windows. Nasser === Subject: Re: Format->Magnification does not I have the same problem, the magnification popup on the bottom right doesn't show on linux (ubuntu feisty). The magnification function itself on the menu doesn't work properly either, it only magnifies the cells that are selected, instead of the entire notebook. It works fine on Mac OS X. Ramiro Quoting Nasser Abbasi : >> Hi Bhuvanesh, >> I am using Mathematica 6.0.0 for Linux. I don't seem to have any popup >> menu at the bottom right of the notebook window. >> What did you have in mind? > Best, Martin > Do you mean you do NOT see this in your notebook on Linux? see screen shot > below > http://12000.org/tmp/101107/mag.PNG > Nasser > === Subject: Re: Re: Hiding Input Cells Nice! But...is it really more efficient to copy and evaluate these definitions in the notebook and evaluate them than to do the equivalent thing manually (by selecting all Input cells with a simple key combination, then use the menu)? > Much of the functionality that you are looking for is contained in the > Tagging palette in A WorkLife FrameWork > (http://scientificarts.com/worklife/). But here is a pair of quick > and dirty functions that will do what you are looking for by > evaluating them in the desired notebook. This is a function that will do what you want (evaluate it in the > notebook whose input cells you are wating to evaluate). ClearAll[EvaluateAndHideInputCells]; EvaluateAndHideInputCells[] := > Module[{nb}, nb = EvaluationNotebook[]; > NotebookFind[nb, Input, All, CellStyle]; > MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[nb, > {toevaluate}]]; SelectionMove[nb, All, EvaluationCell]; > MathLink`CallFrontEnd[ > FrontEnd`SelectionRemoveCellTags[nb, {toevaluate}]]; NotebookFind[nb, toevaluate, All, CellTags]; FrontEndExecute[FrontEndToken[nb, EvaluateCells]]; NotebookFind[nb, toevaluate, All, CellTags]; > MathLink`CallFrontEnd[ > FrontEnd`SelectionRemoveCellTags[nb, {toevaluate}]]; > SetOptions[NotebookSelection[nb], Editable -> True, CellOpen -> False, > ShowCellBracket -> False] ]; And this one will re-show the input cells to see them onece again. > Again evaluate it in the desired notebook. ClearAll[ReopenInputCells]; ReopenInputCells[] := > Module[{nb}, nb = EvaluationNotebook[]; > NotebookFind[nb, Input, All, CellStyle]; > SetOptions[NotebookSelection[nb], Editable -> True, CellOpen -> True, > ShowCellBracket -> True] ] > I hope this helps... --David > http://scientificarts.com/worklife > A WorkLife FrameWork > E x t e n d i n g MATHEMATICA's Reach... >> Is it possible to hide input cells following notebook >> evaluation? I would like to have the output cells visible, but hide the >> input cells, so I can print the output without printing the input cells. >> I'd like this to happen automatically, so I don't have to delete the >> input cells one by one each time. >>> Harvey P. Dale > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Hiding Input Cells Much of the functionality that you are looking for is contained in the Tagging palette in A WorkLife FrameWork (http://scientificarts.com/worklife/). But here is a pair of quick and dirty functions that will do what you are looking for by evaluating them in the desired notebook. This is a function that will do what you want (evaluate it in the notebook whose input cells you are wating to evaluate). ClearAll[EvaluateAndHideInputCells]; EvaluateAndHideInputCells[] := Module[{nb}, nb = EvaluationNotebook[]; NotebookFind[nb, Input, All, CellStyle]; MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[nb, {toevaluate}]]; SelectionMove[nb, All, EvaluationCell]; MathLink`CallFrontEnd[ FrontEnd`SelectionRemoveCellTags[nb, {toevaluate}]]; NotebookFind[nb, toevaluate, All, CellTags]; FrontEndExecute[FrontEndToken[nb, EvaluateCells]]; NotebookFind[nb, toevaluate, All, CellTags]; MathLink`CallFrontEnd[ FrontEnd`SelectionRemoveCellTags[nb, {toevaluate}]]; SetOptions[NotebookSelection[nb], Editable -> True, CellOpen -> False, ShowCellBracket -> False] ]; And this one will re-show the input cells to see them onece again. Again evaluate it in the desired notebook. ClearAll[ReopenInputCells]; ReopenInputCells[] := Module[{nb}, nb = EvaluationNotebook[]; NotebookFind[nb, Input, All, CellStyle]; SetOptions[NotebookSelection[nb], Editable -> True, CellOpen -> True, ShowCellBracket -> True] ] I hope this helps... --David http://scientificarts.com/worklife A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... > Is it possible to hide input cells following notebook > evaluation? I would like to have the output cells visible, but hide the > input cells, so I can print the output without printing the input cells. > I'd like this to happen automatically, so I don't have to delete the > input cells one by one each time. Harvey P. Dale === Subject: Re: Hiding Input Cells Method 1: Select all the input cells by clicking one of their brackets as you press Alt. Then, form Cell menu item, select Cell Properties and uncheck Open. That closes all the input cells. Now print the notebook. Method 2: While holding Alt, click some output cell's bracket. That Selection. This prints just the selected (output) cells. > Is it possible to hide input cells following notebook > evaluation? I would like to have the output cells visible, but hide the > input cells, so I can print the output without printing the input cells. > I'd like this to happen automatically, so I don't have to delete the > input cells one by one each time. Harvey P. Dale > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: ProgressIndicator Questions I would like to use a ProgressIndicator, not to indicate progress in a calculation, but to represent the transmission of information in a given direction. Here is an example from ProgressIndicator Help that indicates the type of display that I want: ProgressIndicator[Dynamic[Clock[Infinity]], Indeterminate] However, I want the ProgressIndicator to be much smaller and, as it would be, I want the information flow in the opposite direction. If I make the ProgressIndicator smaller there is no green portion to indicate a flow at all. ProgressIndicator[Dynamic[Clock[Infinity]], Indeterminate, ImageSize -> {75, 10}] I suspect this may be related to the width of the green portion and the width of the ProgressIndicator. I can obtain a kind of right to left flow with the following construction: ProgressIndicator[Dynamic[2 - Clock[2]], {0, 2}, ImageSize -> {75, 10}] My questions are: 1) Is it possible to change the green and gray colors? 2) Or better, is it possible to specify the width of the ProgressIndicator AND the location and width of the green region independently? Or are there any suggestions for independently constructing a flow indicator, perhaps one that had the kind of shading that the ProgressIndicator has? -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === > 3-vector database. The first column is the date, the second > column contains the names, and the last column contains the > returns. I know that you have to use a loop.The data looks like this: > 1/2/01 TBill 0.67 > 1/3/01 SP 0.78 > 1/4/01 inv 0.5 > 1/5/01 inve 0.6 It's straightforward(ish). Here is one way. 1. Read the file as a Table. data = Rest@Import[d:/Tmpfiles/test.txt, Table] 2. Filter to dates & values date = data[[All, 1]] item = data[[All, 2]] value = data[[All, 3]] cdate[str_, base_: 2000] := Module[ {dy, mo, yr}, {dy, mo, yr} = ToExpression@StringSplit[str, /]; {yr + base, mo, dy} ] 4. Plot your data You can combine steps 1 & 2 as {date, item, value} = Transpose@Rest@Import[d:/Tmpfiles/test.txt, Table] No loops in sight. Dave. === >database. The first column is the date, the second column contains >the names, and the last column contains the returns. I know that you >have to use a loop.The data looks like this: >1/2/01 TBill 0.67 >1/3/01 SP 0.78 >1/4/01 inv 0.5 >1/5/01 inve 0.6 No loop is needed. For example, after putting the data into a Mathematica compatible format, i.e., data = {{1/2/01, TBill, 0.67}, {1/3/01, SP, 0.78}, {1/4/01, inv, 0.5}, {1/5/01, inve, 0.6}}; Simply doing -- To reply via email subtract one hundred and four === Subject: Run notebook so graphs are displayed and not their code I use a Mathematica notebook (Version 6) to create a report (which I then pdf and print off). The notebook has text with code for graphs in between. Once I run a graph I can double click on its bracket, which displays the graph but hides the code. My question is : Can I set up the cells (perhaps as initialisation cells) and be able to run the whole notebook, so that I don't need to go down the notebook (after it is run) and double click on each graph bracket to hide the graph code ? Tom === Subject: Applying Additive Gaussian Noise with standard deviation I am modeling action potentials in Mathematica and need to vary both the mean current and noise amplitude (using additive Gaussian noise with standard deviation). Any suggestions on how to implement these commands in Mathematica? === Subject: Recursion limit: a good idea to ignore? I've written a potentially inefficient algorithm to combine multiple joined polygons into a single one. On large plots I get the warning $RecursionLimit::reclim: Recursion depth of 256 exceeded. and a bunch of errors because of this. Now, should I try and re-write my program (the speed of it is not entirely critical) to avoid recursion or is it okay to locally remove the recursion limit for such code? I'll try and post an actual example of my code once I've tidied it up a little. Will === Subject: Fwd: Compile forgets assigned values inside Do unless they are initialised > In the following example, although var is assigned a value, these are The value is set to late in your example (see below). > forgotten and an error occurs when it is returned as the result of the The value has not been forgotten since it has never been assigned to the symbol. > compiled function: > Compile[{}, > Module[ > {var}, > Do[ > var = 0.;, > {10} > ]; > var > ] > ][] > Compile::initvar: The variable var has not been initialized or has been > initialized to Null. But if var is initialised (to any Real value at all), then all subsequents > assignments to it are remembered: > Compile[{}, > Module[ > {var = 1.}, > Do[ > var = 0.;, > {10} > ]; > var > ] > ][] > 0. > Is this the expected behaviour? Yes. If one wants to compile an expression that uses local symbols, then these local symbols must be initialized at the beginning of the Module (or Block) construct. See ref/message/Compile/initvar. -- Jean-Marc === Subject: Re: Compile forgets assigned values inside Do unless they are initialised > In the following example, although var is assigned a value, these are The value is set to late in your example (see below). > forgotten and an error occurs when it is returned as the result of the The value has not been forgotten since it has never been assigned to the symbol. > compiled function: Compile[{}, > Module[ > {var}, > Do[ > var = 0.;, > {10} > ]; > var > ] > ][] Compile::initvar: The variable var has not been initialized or has been > initialized to Null. > But if var is initialised (to any Real value at all), then all subsequents > assignments to it are remembered: Compile[{}, > Module[ > {var = 1.}, > Do[ > var = 0.;, > {10} > ]; > var > ] > ][] 0. Is this the expected behaviour? Yes. If one wants to compile an expression that uses local symbols, then these local symbols must be initialized at the beginning of the Module (or Block) construct. See ref/message/Compile/initvar. -- Jean-Marc === Subject: Compile forgets assigned values inside Do unless they are initialised In the following example, although var is assigned a value, these are forgotten and an error occurs when it is returned as the result of the compiled function: Compile[{}, Module[ {var}, Do[ var = 0.;, {10} ]; var ] ][] >> Compile::initvar: The variable var has not been initialized or has been initialized to Null. But if var is initialised (to any Real value at all), then all subsequents assignments to it are remembered: Compile[{}, Module[ {var = 1.}, Do[ var = 0.;, {10} ]; var ] ][] >> 0. Is this the expected behaviour? === Subject: Re: Manipulator Import in Powerpoint Sadly there is a misguided belief that Powerpoint is some sort of standard (look, I just have to say this--I HATE Powerpoint and think that it is one of the great misfortunes that has befallen the art of communication...), so IF you can transition to using Mathematica to do your presentations it will open up Vistas (sorry the pun) in presentation possibilities that are Reimann surfaces beyond whatever MS products will ever achieve... OK, that said (and done with emotional rant), I assume that there is no integration of Powerpoint with Flash video (MS really does not do much with moving Powerpoint forward--I suspect that it is the one product that they filed with the least development resources placed upon it). But if Flash were something that Powerpoint could display then, as a stopgap, you could export your Manipulate as a SWF file and embed it in the Powerpoint to at least show some of what the Manipulate can do. Hope that this helps, --David http://scientificarts.com/worklife A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... > Is there a way to import a manipulator object into a Powepoint > presentation? Has anybody created an object plugin? > Alternatively, is there a translator to take a Powerpoint and covert > it to A MAahematica 6.0 presentation? -john michopoulos === Subject: Re: Manipulator Import in Powerpoint and vice versa Craig and all, Actually this brings a refinement/restatement of the problem (I have asked WRI but have not heard back form them yet): 1. Is there a way to automatically import Powerpoint to Mathematica slide show (Inverse statement for intentions related to previous question)? 2. Since there is a plugin to import an Applet into a Powerpoint, is there a way to get the Manipulator Object to Mapped to an Applet? I realize that manipulator uses JLink internally (and therefore it should (maybe) have a Java object incarnation) but I had no had the time to investigate further.... Any thoughts? -john michopoulos That's an interesting idea, and would produce a whole new community of > Mathematica users. But, I doubt that it is possible. Why not use the slideshow feature of mathematica, and forget powerpoint > completely? Just a suggestion... > >> Is there a way to import a manipulator object into a Powepoint >> presentation? Has anybody created an object plugin? > Alternatively, is there a translator to take a Powerpoint and covert >> it to A MAahematica 6.0 presentation? > === Subject: Re: Manipulator Import in Powerpoint That's an interesting idea, and would produce a whole new community of Mathematica users. But, I doubt that it is possible. Why not use the slideshow feature of mathematica, and forget powerpoint completely? Just a suggestion... > Is there a way to import a manipulator object into a Powepoint > presentation? Has anybody created an object plugin? > Alternatively, is there a translator to take a Powerpoint and covert > it to A MAahematica 6.0 presentation? === Subject: Re: JLink Before my last post appeared, I found the answer myself. Change java to javaw in ReinstallJava[CommandLine->C:Program FilesJavajre1.6.0_02bin javaw] However I can claim that I was misled by the page JLink/tutorial/ in the Mathematica 6 Help system, which explicitly suggests using ReinstallJava[CommandLine -> d:fullpathtojava.exe] This should be corrected, I think. John Jowett Mathematica 6 comes with an outdated Java. Therefore, it may be >necessary to use a newer version. A clumsy solution is to change the >Java in the installation. However, there was a better method that worked >before v6: >InstallJava takes an option CommandLine that specifies a command line >to start Java. In version 6 this does no more work correctly. If I say: >InstallJava[CommandLine->name of new java] >the old Java of mathematica is loaded, despite the option. However, if I >prevent mathematica to find the java executable by renaming the >corresponding folder, the correct java is now loaded. >Daniel > Daniel, > Java is now launched at startup time, so when you call > InstallJava[CommandLine->...] J/Link just returns the current Java > link. What you need to do is force Java to restart with your desired options: > ReinstallJava[CommandLine->...] > Incidentally, the pre-launch of Java has been anticipated for a long > time, so the J/Link User Guide has been warning about it for several > years: Programmers should not assume that they have the ability to > control the launch of the Java runtime, as it might already be > running. If for some reason you absolutely must apply options to > control the launch of the Java runtime, useReinstallJavainstead of > InstallJava. > --Todd- Hide quoted text - > - Show quoted text - === Subject: Re: dereference variable > I tried that, and it works OK. But I lose a lot of Mathematica's > knowledge of the properties of Sum, which I would rather not do. You can Replace mySum with Sum whenever you want, though: s=mySum[x,{k,1,20}] s/.mySum->Sum This is another way of Holding the original expression, in effect. Bobby > so that what L actually receives is a value like s$123456. Q, on > the other hand, evaluates s entirely, and arrives at 20*k. You > may wonder, but wait, that is what s evaluates to, why can't your > code deal with that? The simplest answer is that sometimes > Mathematica seems to decide erroneously that the summation can be > turned into multiplication, > It's not erroneous you need to follow the evaluation sequence, >> Mathematica does not operate the way languages like C or Java do, it >> uses a strict read eval loop, it reads an expression checks if there' s >> a rule that can be used to evaluate it and continues doing so until >> there is nothing left to evaluate. For that matter the idea of >> references and passing by value or reference does not map well. >> which leaves me with dummy variables from summations lying around > unbound. > What variables are unbound? I don't see any. I'm sorry, I wasn't very clear. This was a very much stripped > down/faked-up version of the code which has these problems. This code > doesn't have any unbound variables because it's so simple. But sometimes > I'll write something like > Sum[Sum[j,{j, 1, > someweird[nestedexpression[with,i,as,an,argument,somewhere]]}],{i,1,imax}] > and get > imax*Sum[j,{j, 1, > someweird[nestedexpression[with,i,as,an,argument,somewhere]]}] > and now the i in the iterator for the inner loop doesn't have any > meaning. > Although, to be honest, I haven't seen an example of that behavior in a > while, so I can't draw up an example that displays it. > Also, this is a problem at other times, such as when there is an > appreciable difference between x[[i]]-x[[i]] and 0, because I > really mean x[[i]] to stand in for some vector of as-yet-unknown > length, so that it minus itself is a zero vector, which is different > from plain 0. > Again you are fighting the evaluation sequence, if you don't want to >> evaluate x[[i]]-x[[i]] because you are going to define an evaluation >> rule for x later, you shouldn't evaluate that expression until the >> right time. The goal of the bit of code I'm writing is to examine/modify/optimize > some code to be executed later, so it's not really an option to wait > until I have a value for x. > s=mySum[x,{k,1,20}] > L[mySum[x__]]:=Print[here] > I tried that, and it works OK. But I lose a lot of Mathematica's > knowledge of the properties of Sum, which I would rather not do. be done, and I will just have to work around that. >> Ssezi > todd. > -- DrMajorBob@bigfoot.com === Subject: How Import data from Excel and make a list of numbers How I can import in Mathematica 6 data from Excel? More in details, how i can trasform a list of numbers present in one excel columns-> to one list of numbers in Mathematica 6 in the form: {1,2,3,4,5,........} Dino === Subject: Strange behaviour of Do in Compile Compile[{}, Do[If[i > 10, Return[i + 1]], {i, 10}]][] On my machine, this returns such values as: 176792864 176795048 176797232 The following slight modification always returns the value 11: Compile[{}, Do[If[i > 10, Return[i]], {i, 10}]][] Can anyone explain this behaviour? Anyway, I guess the moral is: always explicitly return a value from Compile, and don't rely on the usual return value properties of flow-control constructs like Do. === Subject: Compile forgets assigned values inside Do unless they are initialised In the following example, although var is assigned a value, these are forgotten and an error occurs when it is returned as the result of the compiled function: Compile[{}, Module[ {var}, Do[ var = 0.;, {10} ]; var ] ][] >> Compile::initvar: The variable var has not been initialized or has been initialized to Null. But if var is initialised (to any Real value at all), then all subsequents assignments to it are remembered: Compile[{}, Module[ {var = 1.}, Do[ var = 0.;, {10} ]; var ] ][] >> 0. Is this the expected behaviour? === Subject: Re: Non-numeric arguments to Compile-d functions > Here's a compiled function that does some (made-up) operation on a > real-valued function f: Compile[{}, > Do[If[f[i] < 0, Return[{i, f[i]}]], {i, 10}], > {{f[_], _Real}} > ] (It finds the first integer i such that f[i] is negative.) For the usual reasons of modularity, I would like to make compiled functions > like this not refer to global variables named f. (We can't put f as one of > the elements of the first argument to compile, because those must all be > numeric scalars or arrays.) Here's one way to do this: Module[ > {f, compiledpart}, compiledpart = Compile[{}, > Do[If[f[i] < 0, Return[{i, f[i]}]], {i, 10}], > {{f[_], _Real}} > ]; findfirstnegative[tempf_] := (compiledpart /. f -> tempf)[] > ] I don't really like this solution because we needed to use two names (f and > tempf). Using two names per argument could get messy if there are several > non-numeric arguments instead of just f. Is this the recommended method for compiling as much of a function as > possible? Note that the following attempt (which doesn't need a tempf) doesn't work: With[{rhs = compiledpart}, findfirstnegative[f_] := rhs] It fails because Mathematica automatically renames the f in the > CompiledFunction in compiledpart to *avoid* the very naming clash I am > trying to create. The With statement effectively creates: findfirstnegative[f$_] := CompiledFunction[{}, > Do[If[f$851[i]<0, Return[{i,f$851[i]}]], {i,10}], > -CompiledCode- > ] What's the neatest, right way to make compiled functions that take > non-numeric arguments? Hi Andrew, What's wrong with simply using the following? fun[f_] = Compile[{}, Do[If[f[i] < 0, Return[{i, f[i]}]], {i, 10}], {{f[_], _Real}}] findfirstnegative[f_Function] := fun[f][] Of course you have to make sure that 'f' is not defined before you issue these definitions, but this is not a problem when you are developing a package. I believe that Module and With weren't meant to be used in this way (i.e. to define new functions *inside* them). When you create packages, use contexts to isolate those symbols which should not be exported. But to be honest, I'm a bit tired now and it is possible that I misunderstood your question ... -- Szabolcs === Subject: Re: Hiding Input Cells Method 1: Select all the input cells by clicking one of their brackets as you press Alt. Then, form Cell menu item, select Cell Properties and uncheck Open. That closes all the input cells. Now print the notebook. Method 2: While holding Alt, click some output cell's bracket. That Selection. This prints just the selected (output) cells. > Is it possible to hide input cells following notebook > evaluation? I would like to have the output cells visible, but hide the > input cells, so I can print the output without printing the input cells. > I'd like this to happen automatically, so I don't have to delete the > input cells one by one each time. Harvey P. Dale > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Hiding Input Cells Is it possible to hide input cells following notebook evaluation? I would like to have the output cells visible, but hide the input cells, so I can print the output without printing the input cells. I'd like this to happen automatically, so I don't have to delete the input cells one by one each time. Harvey P. Dale === Subject: Re: ReplaceAll behavour > I do not understand what Mathematica 6 is doing here: a=5 > a/.a->3 gives 3 But... a+2/. a->3 gives 7 Why is that? Use Trance[a /. a->3] or On[] and Off[] to find out how Mathematica evaluates an expression. The following output should explain what happens: In[1]:= On[] During evaluation of In[1]:= On::trace: On[] --> Null. >> In[2]:= a=5 During evaluation of In[2]:= Set::trace: a=5 --> 5. >> Out[2]= 5 In[3]:= a/.a->3 During evaluation of In[3]:= a::trace: a --> 5. >> During evaluation of In[3]:= a::trace: a --> 5. >> During evaluation of In[3]:= Rule::trace: a->3 --> 5->3. >> During evaluation of In[3]:= Rule::trace: 5->3 --> 5->3. >> During evaluation of In[3]:= ReplaceAll::trace: a/.a->3 --> 5/.5->3. >> During evaluation of In[3]:= ReplaceAll::trace: 5/.5->3 --> 3. >> Out[3]= 3 In[4]:= (a+2)/.a->3 During evaluation of In[4]:= a::trace: a --> 5. >> During evaluation of In[4]:= Plus::trace: a+2 --> 5+2. >> During evaluation of In[4]:= Plus::trace: 5+2 --> 7. >> During evaluation of In[4]:= a::trace: a --> 5. >> During evaluation of In[4]:= Rule::trace: a->3 --> 5->3. >> During evaluation of In[4]:= Rule::trace: 5->3 --> 5->3. >> During evaluation of In[4]:= ReplaceAll::trace: a+2/.a->3 --> 7/.5->3. >> During evaluation of In[4]:= ReplaceAll::trace: 7/.5->3 --> 7. >> Out[4]= 7 In[5]:= Off[] Szabolcs P.S. This is why it is a bad idea to do things like sqrt[a_?NumericQ] := x /. FindRoot[x^2 == a, {x, 1}] (Even though this function works correctly almost all the time -- one must come up with a really tricky definition for 'x' to make it fail, like x = Sequence[1]) So use Module[] to localise 'x': sqrt[a_?NumericQ] := Module[{x}, x /. FindRoot[x^2 == a, {x, 1}]] === Subject: Re: Just for fun: Shortest InputForm to achieve a given Kernel error Two more solutions: > I have found 2 answers after some try. For General::ovfl: 9^99! > For $IterationLimit::itlim: #0@# &@1 > >> 1/0 is a string of length 3 which, when interpreted as InputForm (in a >> clean Kernel), generates a Power::infy error: > ToExpression[1/0, InputForm]; >> Power::infy: Infinite expression 1/0 encountered. >> I think this is the shortest string with this property. > Here are some other errors and the lengths of the shortest strings I can >> find to generate them: > $RecursionLimit::reclim: Recursion depth of 256 exceeded. >> Input length: 4 a=2a > General::ovfl: Overflow occurred in computation. >> Input length: 5 > (Kernel running out of memory) >> Input length: 5 >> a=a@a >> General::unfl: Underflow occurred in computation. >> Input length: 6 > $IterationLimit::itlim: Iteration limit of 4096 exceeded. >> Input length: 7 > Can you figure out how to generate those errors with input strings of that >> length? Can you find any *shorter* solutions? >> -- Szabolcs === Subject: Re: Options in ListContourPlot > Hello everybody, I really need somebody to explain to me how the ListContourPlot > command works. > I mean, when I use it, the resulting plot has the same colour in the > region where the scalar field is maximum as in the region where the > field in minimum. > So the question is: > when I have an array of values representing the value of a field at a > point what does ListContourPlot exactly does? > Olalla Bilbao, UPV/EHU > Sorry, but I do not understand what the problem is. The minimum and maximum points are always coloured differently for me. Please post a complete (but short) example, and explain how the result you get differs from what you expect. -- Szabolcs === Subject: Re: Options in ListContourPlot > Hello everybody, > I really need somebody to explain to me how the ListContourPlot > command works. > I mean, when I use it, the resulting plot has the same colour in the > region where the scalar field is maximum as in the region where the > field in minimum. > So the question is: > when I have an array of values representing the value of a field at a > point what does ListContourPlot exactly does? Olalla > Bilbao, UPV/EHU I suspect you're using a version of Mathematica prior to 6, because 6 uses a default ColorFunction which colors the levels differently for the minimum and maximum. In previous versions (at least in 5), the default color function was Hue, which has the dubious advantage of being periodic in the visible color range. You can change the ColorFunction for your plot by trying something like: ListContourPlot[, ColorFunction -> (Hue[0.73*(1 - #)] &)] -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: InverseFourierTransform strange behaviour Hi all, I am trying to do the InverseFourierTransform on an even and real valued function. because of the real an even properties of the function the IFT should produce a real and even result. but Mathematica 6.0.1.0 gives a even and pure imaginary (erroneous) result: In[1]:= 2 Sqrt[2/Pi] Exp[(w/2)^2] Sin[w]/w; InverseFourierTransform[%, w, x] Out[2]= -I (Erfi[1 - x] + Erfi[1 + x]) trying to FT the (erroneous) result lets Mathematica hang endless in the calculation (until aborted). In[3]:= FourierTransform[%, x, w] Any hints, is this a bug, am I missing something ? thx robert === Subject: Re: Unwanted resize of frontend window I am not sure, but I would guess that window 2 has Inherited as its WindowSize Option. Check Option Inspector under the Format menu, and select the options for Notebook in window 2. Just a guess. WCC W. Craig Carter Professor of Materials Science and Engineering MIT, Dept. of Materials Science and Engineering 13-5018 77 Massachusetts Ave, Cambridge, MA 02139-4307 USA 617-253-6048 ccarter@mit.edu http://pruffle.mit.edu/~ccarter http://pruffle.mit.edu/~ccarter/FAQS/ http://pruffle.mit.edu/~ccarter/I_do_not_use_microsoft.html === > Subject: Unwanted resize of frontend window Suppose I have two frontend windows open; no. 2 is maximized. > When I close frontend window no. 1, > frontend window no. 2 gets automatically resized. > Does anybody know how to stop this strange behaviour? > Ben > Linux, Mathematica 6.0 === Subject: Locator in Manipulate's graphic. Can anyone see a way to change the Locator's appearance in Manipulate. i.e., from the documentation: Manipulate[ Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator}] I've tried the obvious generalization: Manipulate[ Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, (Locator[#,Appearance->Graphics[Circle[#,2]])&}] without success. Any ideas? W. Craig Carter === Subject: Custom Control of Axes and Plot Labels in 2D and 3D Plots There have been a number of questions concerning the control and placement of axis labels and overall plot labels in graphics. I believe that for 2D graphics there is a complete solution. For 3D graphics it is possible to control the placement of the labels but if the image is rotated it will always be possible to obtain overlaps between axis labels and tick marks. Nevertheless it should be possible to place axis labels for a satisfactory result within range of a recommend viewpoint. For 2D plots, by using PlotRange, PlotRangePadding, ImagePadding and Text statements with Scaled coordinates we can place the various plot labels where we wish. The following is an example where the plot labels and axis labels have been specifically placed: Graphics[ {Circle[], Text[x, Scaled[{0.55, -0.06}]], Text[y, Scaled[{-0.08, 0.55}]], Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.1}]], Text[Placing Our Own Labels, Scaled[{0, 1.02}], {-1, 0}]}, PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {35, 60}}, Frame -> True] For a 3D plot the problem is more difficult because of the possibility of rotating the image. We can place the plot label using Epilog. For short axes labels we can place them just inside the bounding box using Text statements. Inside the box they tend to be disentangled from the tick labels. But it is always possible to select a viewpoint that can cause overlap. The only recourse is to place the axes labels according to the predominate view that is wanted. We should probably also set the AxesEdge option to always keep the axes with the labels. The SphericalRegion and RotationAction options provide a 'jump free' interaction with the mouse. Graphics3D[ {Sphere[], Text[x, Scaled[{0.5, 0.04, 0.04}]], Text[y, Scaled[{0.96, 0.5, 0.04}]], Text[z, Scaled[{0.04, 0.04, 0.5}]]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.2}]], Text[Placing Our Own Labels, Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> Clip] With longer axes labels the problem again becomes more difficult because there is more chance for overlap of the labels and ticks. The following is an attempted solution that works within a selected range of viewpoints. Graphics3D[ {Sphere[], Text[x axis, Scaled[{0.5, 0.04, 0.04}], {-1, 0}], Text[y axis, Scaled[{1.1, 0.5, -0.10}], {-1, 0}], Text[z axis, Scaled[{-0.10, -0.10, 0.5}], {0, 0}, {0, 1}]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.2}]], Text[Placing Our Own Labels, Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> Clip] If we can settle for a fixed viewpoint it is even possible to have the labels parallel to the axes. (However, I don't think that angled text always looks that great on the screen. It may look better printed.) axisstyle[s_] := Style[s, FontSize -> 14, FontWeight -> Bold]; Graphics3D[ {Sphere[], Text[axisstyle[x axis], Scaled[{0.5, 0.04, 0.04}], {0, 0}, {1, -0.4}], Text[axisstyle[y axis], Scaled[{1.1, 0.5, -0.10}], {-1, 0}, {1, 1.7}], Text[axisstyle[z axis], Scaled[{-0.10, -0.10, 0.5}], {0, 0}, {-0.15, 1}]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style[A Custom Plot, Large], Scaled[{0.5, 1.2}]], Text[Placing Our Own Labels, Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> Clip] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: Format->Magnification does > ref this part of what you said: > it only magnifies the cells that are selected, instead of the entire > notebook. This is correct, my mistake. However, the magnification on the lower right corner in the status area of the window does apply to the entire notebook in both my mac and windows, but it does not appear on linux. Is there a way I can put it there? Ramiro === Subject: Re: Format->Magnification does not work on notebook > Hi Bhuvanesh, > I am using Mathematica 6.0.0 for Linux. I don't seem to have any popup > menu at the bottom right of the notebook window. > What did you have in mind? > Best, Martin > Do you mean you do NOT see this in your notebook on Linux? see screen shot > below > http://12000.org/tmp/101107/mag.PNG > Nasser Not there in my linux ( 6.0.1.0) version. I'd have to check (at home, later) to see if that shows up in the windows version. -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Format->Magnification does notwork on notebook >I have the same problem, the magnification popup on the bottom right > doesn't show on linux (ubuntu feisty). The magnification function itself > on the menu doesn't work properly either, it only magnifies the cells > that are selected, instead of the entire notebook. It works fine on Mac > OS X. > Ramiro > ref this part of what you said: it only magnifies the cells that are selected, instead of the entire notebook. The above is BY DESIGN. it works the same on windows. Nasser === Subject: Re: Format->Magnification does not I have the same problem, the magnification popup on the bottom right doesn't show on linux (ubuntu feisty). The magnification function itself on the menu doesn't work properly either, it only magnifies the cells that are selected, instead of the entire notebook. It works fine on Mac OS X. Ramiro Quoting Nasser Abbasi : >> Hi Bhuvanesh, >> I am using Mathematica 6.0.0 for Linux. I don't seem to have any popup >> menu at the bottom right of the notebook window. >> What did you have in mind? > Best, Martin > Do you mean you do NOT see this in your notebook on Linux? see screen shot > below > http://12000.org/tmp/101107/mag.PNG > Nasser > === Subject: Lynch Dynamical Systems...Using Mathematica available This is to let folks know that Stephen Lynch's long-awaited book Dynamical Systems with Applications Using Mathematica is now out. I ordered mine back in September 2006 (yes, 6!) when Springer began advertising it. Evidently part of the year's delay was due to the wait for Mathematica 6, which is used for the Mathematica programs. There's some information about the book at http://library.wolfram.com/infocenter/Books/6881/ as well as a downloadable Mathematica 6 notebook with the code (including a tutorial introduction to Mathematica itself). -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > In[1]:= (Count[#1, x_ /; x != 0] & ) /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} Out[1]= {0, 3, 3, 4, 10, 9} Adriano Pascoletti === Subject: Re: ReplaceAll behavour > I do not understand what Mathematica 6 is doing here: > a=5 > a/.a->3 > gives 3 > But... > a+2/. a->3 > gives 7 > Why is that? > Being a=5 the statement a+2/. a->3 becomes 7/.5->3. You can check it with Trace: In[5]:= Trace[a + 2 /.a -> 3] Out[5]={{{a,5},5+2,7},{{a,5},5->3,5->3},7/.5->3,7} Adriano Pascoletti === Subject: Would like to specify Traditional Form in the option inspector Friends, I would like to specify Traditional Form in the option inspector, so that I don't need to indicate with each individual evaluation. Could someone please tell me which parameter to update in the option inspector? Diana M. === Subject: Re: Re: What is the purpose of the Defer Command? Nice. However, I'll hazard more opinion. Your first example with HoldForm always requires ReleaseHold to integrate any of the expressions in the output cells. Your second example with Defer can be integrated differently, perhaps in a way more appropriate for a tutorial or help page, e.g. . . . Perform the computation yourself before evaluating the following cells . . .. That is, I can integrate one of the output cells in your Defer example by adding Evaluatable to its properties. I cannot do so with your HoldForm example, which requires ReleaseHold. Both the Evaluatable property and ReleaseHold can be programmed into document/cell creation, but I think the Evaluatable property is more transparent. Someone new to Mathematica learning about, say, integrals, would probably be distracted by postfix ReleaseHolds. Moreover, those ReleaseHolds make document creation more complex (though, since this is software, anything is possible). Vince Virgilio > How about this? > Function[{n}, > Print[save[n] = HoldForm[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ > Range[5]; > That gives the same outputs as the Defer example and it allows, for > instance, > save[3] // ReleaseHold > 6 - 16/[ExponentialE] > We can use Defer almost the same way, however: > Function[{n}, > Print[save[n] = Defer[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ > Range[5]; > First@save[3] > 6 - 16/[ExponentialE] > Bobby > Still, my question is: What is the purpose of the Defer Command? > The only potential purpose that I can see is for didactic purposes, to >> show >> preliminary expressions before they are automatically evaluated. But > the >> only way to get Defer to evaluate is by copying and pasting and then >> evaluating, by using Shift-Ctrl-L and then evaluating, or by >> evaluating in >> place. All of these operations leave no record of the steps taken. That >> goes >> contrary to any didactic purpose. > -- >> David Park >> djmp...@comcast.nethttp://home.comcast.net/~djmpark/ > Have you noticed the example in the documentation (http:// > reference.wolfram.com/mathematica/ref/Defer.html) that uses Defer to > create cells with unevaluated contents? That has didactic potential. > Can that example be rewritten without Defer, with similar complexity? > Vince Virgilio -- > DrMajorBob@bigfoot.com > === Subject: Re: Re: What is the purpose of the Defer Command? How about this? Function[{n}, Print[save[n] = HoldForm[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ Range[5]; That gives the same outputs as the Defer example and it allows, for instance, save[3] // ReleaseHold 6 - 16/[ExponentialE] We can use Defer almost the same way, however: Function[{n}, Print[save[n] = Defer[Integrate[x^n Exp[-x], {x, 0, 1}]]]] /@ Range[5]; First@save[3] 6 - 16/[ExponentialE] Bobby >> Still, my question is: What is the purpose of the Defer Command? > The only potential purpose that I can see is for didactic purposes, to >> show >> preliminary expressions before they are automatically evaluated. But the >> only way to get Defer to evaluate is by copying and pasting and then >> evaluating, by using Shift-Ctrl-L and then evaluating, or by >> evaluating in >> place. All of these operations leave no record of the steps taken. That >> goes >> contrary to any didactic purpose. > -- >> David Park >> djmp...@comcast.nethttp://home.comcast.net/~djmpark/ > Have you noticed the example in the documentation (http:// > reference.wolfram.com/mathematica/ref/Defer.html) that uses Defer to > create cells with unevaluated contents? That has didactic potential. > Can that example be rewritten without Defer, with similar complexity? > Vince Virgilio -- DrMajorBob@bigfoot.com === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > Hi Zhen, The below works : matrixM = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; Table[Count[sd[[g]], _?(# != 0. &)], {g, 1, Length[matrixM]}] Tom. === Subject: Re: HELP: How to do count to the SUB-LIST Try the following: listie = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} Map[Length, DeleteCases[listie, 0, 2]] Output = {0, 3, 3, 4, 10, 9} I presume this is what you want? (I am a bit confused by your other post). Anyway .... Hope this is of use Tom Dowling. > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} === Subject: Re: HELP: How to do count to the SUB-LIST Try: lst = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; Total/@Unitize[lst] > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > Hello Using Map and Count and your list (which is named lis here) the following code does what you want: (Count[#1, Except[0]] & ) /@ lis An alternative would be: (Length[Select[#1, #1 != 0 & ]] & ) /@ lis or without using pure functions: Clear[x, f1, f2]; f1[x_] := x != 0; f2[x_] := Length[Select[x, f1]]; Map[f2, lis] And so on Norbert Marxer === Subject: Re: HELP: How to do count to the SUB-LIST You'll probably get a lot of answers. This one seems sufficiently general to take care of the different lists you might encounter: Count[#, Except[0]]&/@ list should give you what you want. > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > As a newbie, I would go with the following pattern testing /See Condition in the Help/: In[3]:= (Count[#1, x_ /; x > 0] & ) /@ lst Out[3]= {0, 3, 3, 4, 10, 9} Where lst is your list. Of course if you have negative values you have to adjust the test. J=E1nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} Use Length, Count and Map (see Help for more information) eg: In[1]:= Length[#] - Count[#, 0] & /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} Out[1]= {0, 3, 3, 4, 10, 9} Ssezi === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some > help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, > {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, > {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each sub > list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > Hello Using Map and Count and your list (which is named lis here) the following code does what you want: (Count[#1, Except[0]] & ) /@ lis An alternative would be: (Length[Select[#1, #1 != 0 & ]] & ) /@ lis or without using pure functions: Clear[x, f1, f2]; f1[x_] := x != 0; f2[x_] := Length[Select[x, f1]]; Map[f2, lis] And so on Norbert Marxer === Subject: Re: HELP: How to do count to the SUB-LIST > Hallo, everyone > I am new to Mathematica, and I get one problem now, hope to get some >> help here > I got a list like this: > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, >> {0, 0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, >> {1, 3, 3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} > I need to get a list to show the number of non zero number in each >> sub >> list, as to say, I need to get a list like this: > {0,3,3,4,10,9} > There are lots of ways, but one that I think should be pretty fast is: > ls = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, > 0}, {0, 0, > 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, > 3, 4, 2, > 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}}; > Total[Transpose[UnitStep[ls - 1]]] > {0, 3, 3, 4, 10, 9} > At first I thought that the following (Mathematica 6 only) variant > would be faster > Total[UnitStep[ls - 1], {2}] > {0, 3, 3, 4, 10, 9} > but tests seem to show that this isn't the case. > Andrzej Kozlowski I guess I should add that the above code will only work if (as is your example) all your numbers are non-negative integers. If they are not, you might as well use: Map[Count[#, x_ /; x != 0] &, ls] which is the most obvious way to do this in general, but in the non- negative integer case is much slower than the first method. Andrzej Kozlowski === Subject: RE: Quantum Algebra No Fabian, I do Not have a working version of Quantum Algebra. However I think that the power of my new QUANTUM package could be extended so that it can do what Quantum Algebra was able to do. Please check how the Quantum Gates are handled in the Quantum Computing section of QUANTUM, this is somehow similar to Quantum Algebra's functionality: http://homepage.cem.itesm.mx/lgomez/quantum/ I hope it is interesting and useful for you. (you might consider adding your own functions to the QUANTUM package, in order to extend its power to what Quantum Algebra was able to do. Please let me know if you do it) Jose -----Mensaje original----- De: Fabian [mailto:hasslerf@phys.ethz.ch] Enviado el: Mi=E9rcoles, 10 de Octubre de 2007 11:27 p.m. Para: mathgroup@smc.vnet.net Asunto: Quantum Algebra Has anybody a version of the package Quantum Algebra http://library.wolfram.com/infocenter/MathSource/4898/ which is working with Mathematica 6? Fabian === Subject: Re: Evaluation question > At what point is Unevaluated stripped? > For instance, in the following, unevaluated is stripped even though > arguments are not evaluated > a := Unevaluated[2 + 3] > So a:=Unevaluated[2+3] and a=Unevaluated[2+3] seem to work the same > here > Unevaluated is stripped from an argument of a function before the function is checked for the Hold attributes. It is easy to see this with Trace: SetAttributes[f, HoldAll] Trace[f[Unevaluated[x]]] {HoldForm[f[x]], HoldForm[f[Unevaluated[x]]]} Unevaluated was stripped but then it was restored, as the expression did not change. On the other hand here Unevaluated is stripped but this time not restred: Trace[a := Unevaluated[2 + 3]] {HoldForm[a := 2 + 3], HoldForm[Null]} Normally, Unevaluated that had been stripped from an argument is restored if no applicable rules were found after it was stripped. In this case it is, however, not restored, and to tell the truth at the moment it is not clear to me why. > Also, consider > a=Unevaluated[Unevaluated[2+3]] > OwnValues[a] > OwnValues doesn't show that a has an Unevaluated wrapper, even though > a /. OwnValues[a] results in Unevaluated[2+3], why is that? Doing a Trace on OwnValues clearly shows evaluation: Attributes[OwnValues] {HoldAll, Protected} a = Unevaluated[Unevaluated[2 + 3]] Trace[OwnValues[a]] {HoldForm[OwnValues[a]], HoldForm[{HoldPattern[a] :> Unevaluated[2 + 3]}], {HoldForm[HoldPattern[a] :> 2 + 3], HoldForm[HoldPattern[a] :> 2 + 3]}, HoldForm[{HoldPattern[a] :> 2 + 3}]} You can clealry see that Unevaluated got stripped during evaluation of: HoldPattern[a] :> Unevaluated[2 + 3] HoldPattern[a] :> 2 + 3 Just as in the earlier example Unevaluated is stripped but not restored, and again I find it a bit of a puzzle. Perhaps someone else can explain this point? Andrzej Kozlowski > Is there any place that documents at which point OwnValues comes into > evaluation? For instance, setting a high level trap (Robby Villegas' > technique) on Set/OwnValues/Replace/ReplaceAll shows no trace of > OwnValues evaluation. > Is OwnValue application equivalent to > symbol/.ReplaceAll[OwnValues[symbol]]? > === Subject: Evaluation question At what point is Unevaluated stripped? For instance, in the following, unevaluated is stripped even though arguments are not evaluated a := Unevaluated[2 + 3] So a:=Unevaluated[2+3] and a=Unevaluated[2+3] seem to work the same here Also, consider a=Unevaluated[Unevaluated[2+3]] OwnValues[a] OwnValues doesn't show that a has an Unevaluated wrapper, even though a /. OwnValues[a] results in Unevaluated[2+3], why is that? Is there any place that documents at which point OwnValues comes into evaluation? For instance, setting a high level trap (Robby Villegas' technique) on Set/OwnValues/Replace/ReplaceAll shows no trace of OwnValues evaluation. Is OwnValue application equivalent to symbol/.ReplaceAll[OwnValues[symbol]]? === Subject: Re: How to do count for sub list????? name your list: l = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}; and use Table[Length[l[[n]]] - Length[Position[l[[n]], 0]], {n, 1, Length[l]}] or Length[#] - Length[Position[#, 0]] & /@ l By the way, the result is {0, 0, 2, 1, 0, 0, 1, 1} and not {0,0,1,1,0,0,1,1= } as written in your e-mail. Ricardo > Hallo, everyone > I am new to Mathematica, and now I have a problem with it, hope to get > some help from here. > I have a > {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} I need to get a list which represent the number of NON-zero number in > each sublist. > I should get a list like: > {0,0,1,1,0,0,1,1} -- ____________________________________ Ricardo Elgul Samad tel: (+55 11) 3133-9372 fax: (+55 11) 3133-9374 Centro de Lasers e Aplica=E7=F5es IPEN/CNEN-SP AV. Prof. Lineu Prestes 2242 Cidade Universit=E1ria 05508-000 S=E3o Paulo - SP Brazil ____________________________________ === Subject: Re: How to do count for sub list????? > Hallo, everyone I am new to Mathematica, and now I have a problem with it, hope to get > some help from here. I have a {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { > 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} I need to get a list which represent the number of NON-zero number in > each sublist. I should get a list like: {0,0,1,1,0,0,1,1} > In[5]:= (Count[1, x_ /; x != 0] & ) /@ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}} Out[5]= {0, 0, 2, 1, 0, 0, 1, 1} The third list has two non-zero elements. -- Szabolcs === Subject: Re: ReplaceAll behavour >I do not understand what Mathematica 6 is doing here: >a=5 >a/.a->3 >gives 3 >But... >a+2/. a->3 >gives 7 >Why is that? What is happening in each case is evaluation occurs before replacement. =46or a/.a-> evaluation causes this to become 5/.5->3 then the replacement occurs to give the result 3. =46or a+2/.a->3 evaluation gives 5+2/.5->3 Arithmetic operators such as + or - have higher precedence than patter replacement. So, this becomes 7/.5->3. And finally since there is no 5 to replace, the result is 7. You can easily verify this is the way things work by looking at the output from Trace[a/.a->3] and Trace[a+2/.a->3] -- To reply via email subtract one hundred and four === Subject: Re: import function >I have a question regarding the import function in mathematica 6. >When I import a long array of reals into a table, the function >appears to skip certain array entries, for example the 20230 th row. >This does not occur in mathematica 5.2 using identical code. >Code is below. >In[1]:= >SetDirectory[/Users/elleryames/Research/VoltageStability/Data/ >run0239]; FileName=run0239; >FileImport=Import[FileName<>.dat,Table]; There is no way to determine wether the code above is adequate without a sample of the data file you are trying to import. All I can say is the syntax appears correct and if the file has the appropriate format there should be no problem. -- To reply via email subtract one hundred and four === Subject: Re: How Import data from Excel and make a list of numbers >How I can import in Mathematica 6 data from Excel? More in details, >how i can trasform a list of numbers present in one excel columns->to one list of numbers in Mathematica 6 in the form: >{1,2,3,4,5,........} You import Excel files with data = Import[filename, XLS]; Assuming there is one Excel worksheet, you can get a specific column by doing col = data[[All,n]] where n is the column number. Or you could combine these into one line by doing col = Import[[filename][[All,n]]; Note, this assumes all rows in that worksheet have at least n columns. That is if the worksheet has the form comment blank row blank row a1 a2 a3 ... b1 b2 b3 ... ... you will get an error doing Import[filename,XLS][[All,3]] since the first few rows have fewer than three columns. In this case, getting the third column of the data array could be done using col = Cases[Import[filename,XLS],_?(Length>3#)][[All,3]] Of course, if you didn't create the Excel file and don't have something that will display the structure of the file, you have no way to know what that structure will be. What I do in those cases is simply data = Import[filename, XLS]; then use commands like Dimension, Depth, Length etc to determine the structure. Once that is know, it is a simple matter to extract a particular column using Part, Span etc. -- To reply via email subtract one hundred and four === Subject: Re: Hiding Input Cells >Is it possible to hide input cells following notebook >evaluation? I would like to have the output cells visible, but hide >the input cells, so I can print the output without printing the >input cells. This is easily done as follows: Select an input cell by option clicking the bracket to the right of the cell. On a Macintosh this will select all input cells. I don't know the equivalent keys to use with Windows or Linux. Once the desired input cells are selected simply uncheck Cell->Cell Properties->Open. This will close all of the cells doing what you want. >I'd like this to happen automatically, so I don't have >to delete the input cells one by one each time. Note, by option clicking or the equivalent on Windows or Linux, you can select all of the cells of the same type at once and delete them at once. But closing the cells as described above is better in that it will achieve essentially the same for printing purposes but retains the code should further edits be needed in the future. I say essentially the same since a closed cell between two open cells will leave more white space between the open cells than would be the case if they were deleted. This can become important if there are several cells between output cells that need to be closed. -- To reply via email subtract one hundred and four === Subject: Re: HELP: How to do count to the SUB-LIST >I am new to Mathematica, and I get one problem now, hope to get some >help here >I got a list like this: >{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, {0, >0, 0, 0, 1, 1, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0, 0}, {1, 3, >3, 4, 2, 2, 5, 3, 2, 1}, {7, 2, 2, 3, 4, 4, 0, 3, 1, 3}} >I need to get a list to show the number of non zero number in each >sub list, as to say, I need to get a list like this: >{0,3,3,4,10,9} Here are a few different ways: =46irst, noting all of the non-zero values are positive In[10]:= Plus @@@ Sign[data] Out[10]= {0,3,3,4,10,9} or In[11]:= Total[Transpose@Sign@data] Out[11]= {0,3,3,4,10,9} or if there were arbitrary items other than 0 In[12]:= Length[DeleteCases[#, 0]] & /@ data Out[12]= {0,3,3,4,10,9} -- To reply via email subtract one hundred and four === Subject: Programming Euler's Method into Mathematica I am trying to use Euler's Update Method to Numerically Integrate a Function (I know how to use NDSolve for this case, but I want to demonstrate an approximation method as well). For those familiar with neuroscience, I am trying to model the Hodgkin Huxley Equations. I have four ordinary differential equations (ODE) that I have written in discrete form using Euler's Method. I am trying to solve for one of these discrete equations, V, which is a function of the other three differential equations (n, m, and h). All four equations are also a function of time. Essentially, the command for NDSolve for this case is in the following form: NDSolve[{ODE1, ODE2, ODE3, ODE4, V[0]==0,n[0]==1, m[0]==2, h[0]==3},{V,n,m,h},{t,0,50},MaxSteps->1000] Instead of the above ODE input, I want to use Euler's Method. (i.e. V(t +delta_t)=V(t)+delta_t(stuff). Now, the code below works for a function of x and y. MY QUESTION IS: how would I change this code to apply to my situation in which I want to solve for V[t] but it is a function of n[t], m[t], and h[t]. I would appreciate any hints/clues/suggested programs. I know that Mathematica has a built-in Explicit Euler Method, but I would like to develop the program myself. I believe I am making a small mistake that is preventing my success. Tara The following program code works for a function f(x,y): euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:= Block[{txold=x0, yold=y0, sollist={{x0,y0}}, x,y,h }, h=N[(xn-x0)/steps]; Do[ xnew=xold+h; ynew=yold+h*(f/.{x->xold,y->yold}); sollist=Append[sollist,{xnew,ynew}]; xold=xnew; yold=ynew, {steps} ]; Return[sollist] === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? Because of all this hurry I even managed to get the second fundamental theorem of calculus wrong. Of course it states that a continuous function on an interval has a C1-anti-derivative on that interval. Andrzej Kozlowski Sorry for not having responded sooner; I've been away from >> computer access >> for a week. > So, from that, D and/or Simplify must be wrong. > Must they? Even without any investigation I would say that it is > much > more likely that this integral should not be evaluated by means of > the Leibniz rule (substituting the limits into the anti-derivative > and subtracting). > Of course, the Leibniz rule cannot be used unless one _has_ an >> antiderivative valid on the required interval. Mathematica does >> not supply >> such an antiderivative in this case. > This has been discussed many time before on this list (with your > participation) but since you seem not to be satisfied, here it goes > again, I hope for the last time. > The second fundamental theorem of calculus i.e. the Newton-Leibniz > rule (high school level mathematics) states that if we have a > function with a continuous derivative (a C1 function) on an > interval than it has a continuous anti-derivative on this > interval. However if the original function is not complex > analytic in the complex plane then there will not be a complex > analytic anti-derivative. Instead, there will be anti-derivatives > with singularities, and in unlucky cases they may fall on the > interval of integration. This is exactly what happens in this case. > In fact, it is easy to see what happens in your > special case: > integrand = (r*(r - rho*Cos[alpha - t]))/ > (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + > (z - zeta)^2)^3); > int = integrand /. {r -> 1, rho -> 11/10, > zeta -> 0, alpha -> 0, z -> 12/10} > (1 - (11*Cos[t])/10)/(3*(73/20 - (11*Cos[t])/5)^3) > First, let us compute the integral using Integrate: > Integrate[int, {t, 0, 2*Pi}] > (1772800*Pi)/(11512449*Sqrt[377]) > N[%] > 0.0249156 > Now, let's do it by numerical integration: > NIntegrate[int, {t, 0, 2*Pi}] > 0.024915592618816908 > so far, so good. Now let's compute the indefinte integral: > indef = Integrate[int, t]; > Using the Liebniz rule gives clearly the wrong answer: > indef = Integrate[int, t]; > but why should it give the right answer? > It _must_ give the right answer if indef is actually an >> antiderivative on >> the interval 0 to 2Pi, but it isn't. > It depends on the meaning of anti-derivative. In the meaning that > Mathematica and all other symbolic algebra programs use, a function > can be an an anti-derivative of another function, even if it is > singular or undefined at certain points in the complex plane > provided it is an anti-derivative at almost all points (i.e. a > generic anti-derivative). It is of course completely natural for > Mathematica to use such anti-derivatives since it is precisely this > kind of anti-derivatives that are found by the Risch algorithm. >> The function indef is clearly discontinuous in the interval 0 to 2Pi > True, but that discontinuity is merely an artifact of Mathematica's >> workings. The integrand int is clearly continuous on the interval >> 0 to 2Pi >> and, indeed, on all of R, and so there is an antiderivative on R: > 886400 Sqrt[377]/4340193273 (t - 2 ArcTan[44 Sin[t]/(44 Cos[t] - 3 >> Sqrt[377] - 73)]) + 8800 Sin[t] (1078 Cos[t] - 8009)/(3837483 (44 >> Cos[t] - 73)^2)) > but I don't know how to get Mathematica to produce it. Of course, >> using my >> antiderivative above with Leibniz rule, we get the correct result >> for the >> definite integral. >> Plot[indef, {t, 0, 2 Pi}] > so the Leibniz rule does not apply. There is no reason at all to > suspect the very reliable function Simplify and almost as reliabel > Interate. > There is very good reason to suspect that Integrate, when asked to >> evaluate >> an indefinite integral, might give a result which is not an >> antiderivative >> on some desired interval. This happens fairly often, the subject >> of this >> thread being a case in point. > Mathematica does not even attempt to find anti-derivatives on R in > your sense. Instead of bringing up time and again same points that > are covered in undergraduate calculus course I suggest learning a > little about symbolic algebraic integration. Here are two good > references: > Geddes, Czapor, Labhan Algorithms for Computer Algebra, Kluwer, 1992 > Davenport J. On the Integration of Algebraic Functions, Springer- > Verlag 1981. > If you read one of these you will find that the concept of anti- > derivative that your are using is not considered suitable for > computer algebra (at least at its present stage of development > unless there have been some dramatic developments recently that I > am not aware of ). So, you do not know how to obtain your answer > with Mathematica because it can't be done. Symbolic algebra > programs use known algebraic algorithms. There is no point > demanding that they should do something unless a suitable general > algorithm is known. > Of course, it is possible that you know an algorithmic (in the same > sense that the Risch algorithm is algorithmic) way of computing > such anti-derivatives. If so, I am sure that Wolfram Research will > be very keen to implement it. > But until then this is all there is to this entire issue. > Andrzej Kozlowski Another result which might help Craig, but which I don't know how >> to get >> using Mathematica, is that > Assuming[r > 0 && rho > 0 && Element[zeta, Reals] && Element[z, >> Reals] && >> alpha > 0 && Not[rho == r && zeta == z], Integrate[(r*(r - rho*Cos >> [alpha - >> t]))/ (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + (z - zeta)^2)^3), >> {t, 0, 2 Pi}]] > should be > (2*Pi*r^2*(-2*rho^4 + rho^2*(r^2 - (zeta - z)^2) + (r^2 + (zeta - >> z)^2)^2))/ >> (3*(((rho - r)^2 + (zeta - z)^2)*((rho + r)^2 + (zeta - z)^2))^(5/2)) > Note that the last assumption mentioned above was added by me. >> Without that >> last assumption, there would have been trouble if we had had both >> zeta == z >> and rho == r. But in that special case, the desired definite >> integral is >> easily handled: it's just 0. > David W. Cantrell > Yes, it's an incorrect result. > To paraphrase your post: > integrand = (r*(r - >> rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + (z - zeta)^2 - >> 2*r*rho*Cos[alpha - t])^3); >> assumptions = {r > 0, rho > 0, Element[zeta, Reals], >> Element[z, Reals], alpha >In[15]:= 0}; > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions] > 0 > Plot[integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, >> z -> 1.2}, {t, 0, 2 Pi}, PlotRange -> All] > Visual integration is unconvincing, but you're right, the >> integral isn't >> zero: > NIntegrate[ >> integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, >> z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > Your example violates assumptions (alpha -> 0 vs. alpha > 0), but >> that's >> not the problem: > NIntegrate[ >> integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, >> z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > So, as often happens, you've found a case where Mathematica got a >> general >> solution that isn't correct for some values of the parameters. The >> quadratic formula is another example: > Solve[a x^2 + b x + c == 0, x] > {{x -> (-b - Sqrt[b^2 - 4 a c])/( >> 2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}} > Not true when a == 0, of course. > But let's look further: > indefinite = Integrate[integrand, t, Assumptions -> assumptions]; >> definite = Subtract @@ (indefinite /. {{t -> 2 Pi}, {t -> 0}}); >> Simplify[definite, assumptions] > 0 > Is that a Simplify error, or an Integrate error? > definite /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > -2.05998*10^-18 + 0. [ImaginaryI] > Ah. Simplify may be doing its job just fine (hard to be certain), >> but it >> appears the indefinite integral is incorrect. But look: > D[indefinite, t] == integrand // Simplify > True > and > D[indefinite, t] == integrand // Simplify[#, assumptions] & > True > and also > definite // Together // Numerator // Simplify > 0 > So, from that, D and/or Simplify must be wrong. > If this is correct: > numdefinite // Together // Numerator // TrigFactor > -4 r^2 (r^4 + r^2 rho^2 - 2 rho^4 + 2 r^2 z^2 - rho^2 z^2 + z^4 - >> 4 r^2 z zeta + 2 rho^2 z zeta - 4 z^3 zeta + 2 r^2 zeta^2 - >> rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4) (ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan >> [alpha/ >> 2])/Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - >> ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ >> 1/2 (alpha - 2 [Pi])])/ >> Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]]) >> (r^2 + >> rho^2 + z^2 - 2 z zeta + zeta^2 - 2 r rho Cos[alpha])^2 > The next-to-last factor (the only one that depends on t) is > num[[-2]] > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[alpha/2])/ >> Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - >> ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ >> 1/2 (alpha - 2 [Pi])])/ >> Sqrt[-r^4 + 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta) >> ^2) >> ^2] >> ] > so it all comes down (seemingly) to > Tan[alpha/2] == Tan[1/2 (alpha - 2 [Pi])] // Simplify > True > or > Tan[any] == Tan[any - Pi] > True > BUT... what's likely happening is that Simplify doesn't properly >> take into >> account the branch-cut discontinuities of ArcTanh. In that case, >> there's a >> significant set of parameters for which the integral IS zero, >> such as: > Reduce[Flatten@{num == 0, assumptions}] > ors = (zeta [Element] >> Reals && ((z < zeta && >> rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]) || (z == zeta && rho >> 0 && >> alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]) || (z > zeta && >> rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]))) || ((z | >> zeta) [Element] Reals && alpha > 0 && r > 0 && >> rho > 0) || (C[1] [Element] Integers && z [Element] Reals && >> C[1] >= 1 && alpha == 2 [Pi] C[1] && r > 0 && rho == r && >> zeta == z) > But look: > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > True > Hold on, though... there are a lot of Ors in there. The least >> restrictive >> seems to be > ors[[1, 2, 1]] > z < zeta && rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha >> 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - 4 z^3 >> zeta - >> rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + 2 zeta^2) #1^2 + #1^4 >> &, 2] > But that's a pretty strict condition (on r, especially), and > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > False > SO. Integrate found a set of conditions for which the definite >> integral > was zero; it just didn't tell you what they were! This is supposed >> to be >> the fix for that, I think: > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions, >> GenerateConditions -> True] > 0 > BUT, as you see, that didn't help one bit! > Bobby > > I believe I am getting an incorrect result from a definite > integration: >>> InputForm[integrand] is > (R*(R - rho*Cos[alpha - t]))/(3*(R^2 + rho^2 + (z - zeta)^2 - > 2*R*rho*Cos[alpha - t])^3) >>> InputForm[assumptions] is > {R > 0, L > 0, rho > 0, Element[zeta, Reals], Element[z, Reals], > alpha> 0} >>> Integrate[integrand,{t,0,2Pi},Assumptions->assumptions] > returns 0 >>> But compare this to: > (visually integrate...) > Plot[integrand/.{R -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, z -> 1.2},{t,0,2 Pi},PlotRange->All] >>> (numerically integrate...) > Plot[NIntegrate[integrand/.{{R -> 1, rho -> 1.1, zeta -> 0, > alpha - >> 0, > z -> 1.2},{t,0,tau}],{tau,0,2Pi}, PlotRange->All] >>> Something isn't adding up?? >>>>> -- > DrMajorBob@bigfoot.com >> === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? Just to avoid any more disputes ove relementary calculus, a minor correction to the following (which was written in a hurry): > The second fundamental theorem of calculus i.e. the Newton-Leibniz > rule (high school level mathematics) states that if we have a > function with a continuous derivative (a C1 function) on an > interval than it has a continuous anti-derivative on this interval. Actually, the Newton-Leibniz formula is The first fundamental theorem of Calculus and the existence of a continuos anti-derivative of a C1-fucntion on an interval follows from The second fundamental theorem of Calculus. Andrzej Kozlowski > [Message also posted to: comp.soft-sys.math.mathematica] > Sorry for not having responded sooner; I've been away from >> computer access >> for a week. > So, from that, D and/or Simplify must be wrong. > Must they? Even without any investigation I would say that it is > much > more likely that this integral should not be evaluated by means of > the Leibniz rule (substituting the limits into the anti-derivative > and subtracting). > Of course, the Leibniz rule cannot be used unless one _has_ an >> antiderivative valid on the required interval. Mathematica does >> not supply >> such an antiderivative in this case. > This has been discussed many time before on this list (with your > participation) but since you seem not to be satisfied, here it goes > again, I hope for the last time. > The second fundamental theorem of calculus i.e. the Newton-Leibniz > rule (high school level mathematics) states that if we have a > function with a continuous derivative (a C1 function) on an > interval than it has a continuous anti-derivative on this > interval. However if the original function is not complex > analytic in the complex plane then there will not be a complex > analytic anti-derivative. Instead, there will be anti-derivatives > with singularities, and in unlucky cases they may fall on the > interval of integration. This is exactly what happens in this case. > In fact, it is easy to see what happens in your > special case: > integrand = (r*(r - rho*Cos[alpha - t]))/ > (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + > (z - zeta)^2)^3); > int = integrand /. {r -> 1, rho -> 11/10, > zeta -> 0, alpha -> 0, z -> 12/10} > (1 - (11*Cos[t])/10)/(3*(73/20 - (11*Cos[t])/5)^3) > First, let us compute the integral using Integrate: > Integrate[int, {t, 0, 2*Pi}] > (1772800*Pi)/(11512449*Sqrt[377]) > N[%] > 0.0249156 > Now, let's do it by numerical integration: > NIntegrate[int, {t, 0, 2*Pi}] > 0.024915592618816908 > so far, so good. Now let's compute the indefinte integral: > indef = Integrate[int, t]; > Using the Liebniz rule gives clearly the wrong answer: > indef = Integrate[int, t]; > but why should it give the right answer? > It _must_ give the right answer if indef is actually an >> antiderivative on >> the interval 0 to 2Pi, but it isn't. > It depends on the meaning of anti-derivative. In the meaning that > Mathematica and all other symbolic algebra programs use, a function > can be an an anti-derivative of another function, even if it is > singular or undefined at certain points in the complex plane > provided it is an anti-derivative at almost all points (i.e. a > generic anti-derivative). It is of course completely natural for > Mathematica to use such anti-derivatives since it is precisely this > kind of anti-derivatives that are found by the Risch algorithm. >> The function indef is clearly discontinuous in the interval 0 to 2Pi > True, but that discontinuity is merely an artifact of Mathematica's >> workings. The integrand int is clearly continuous on the interval >> 0 to 2Pi >> and, indeed, on all of R, and so there is an antiderivative on R: > 886400 Sqrt[377]/4340193273 (t - 2 ArcTan[44 Sin[t]/(44 Cos[t] - 3 >> Sqrt[377] - 73)]) + 8800 Sin[t] (1078 Cos[t] - 8009)/(3837483 (44 >> Cos[t] - 73)^2)) > but I don't know how to get Mathematica to produce it. Of course, >> using my >> antiderivative above with Leibniz rule, we get the correct result >> for the >> definite integral. >> Plot[indef, {t, 0, 2 Pi}] > so the Leibniz rule does not apply. There is no reason at all to > suspect the very reliable function Simplify and almost as reliabel > Interate. > There is very good reason to suspect that Integrate, when asked to >> evaluate >> an indefinite integral, might give a result which is not an >> antiderivative >> on some desired interval. This happens fairly often, the subject >> of this >> thread being a case in point. > Mathematica does not even attempt to find anti-derivatives on R in > your sense. Instead of bringing up time and again same points that > are covered in undergraduate calculus course I suggest learning a > little about symbolic algebraic integration. Here are two good > references: > Geddes, Czapor, Labhan Algorithms for Computer Algebra, Kluwer, 1992 > Davenport J. On the Integration of Algebraic Functions, Springer- > Verlag 1981. > If you read one of these you will find that the concept of anti- > derivative that your are using is not considered suitable for > computer algebra (at least at its present stage of development > unless there have been some dramatic developments recently that I > am not aware of ). So, you do not know how to obtain your answer > with Mathematica because it can't be done. Symbolic algebra > programs use known algebraic algorithms. There is no point > demanding that they should do something unless a suitable general > algorithm is known. > Of course, it is possible that you know an algorithmic (in the same > sense that the Risch algorithm is algorithmic) way of computing > such anti-derivatives. If so, I am sure that Wolfram Research will > be very keen to implement it. > But until then this is all there is to this entire issue. > Andrzej Kozlowski Another result which might help Craig, but which I don't know how >> to get >> using Mathematica, is that > Assuming[r > 0 && rho > 0 && Element[zeta, Reals] && Element[z, >> Reals] && >> alpha > 0 && Not[rho == r && zeta == z], Integrate[(r*(r - rho*Cos >> [alpha - >> t]))/ (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + (z - zeta)^2)^3), >> {t, 0, 2 Pi}]] > should be > (2*Pi*r^2*(-2*rho^4 + rho^2*(r^2 - (zeta - z)^2) + (r^2 + (zeta - >> z)^2)^2))/ >> (3*(((rho - r)^2 + (zeta - z)^2)*((rho + r)^2 + (zeta - z)^2))^(5/2)) > Note that the last assumption mentioned above was added by me. >> Without that >> last assumption, there would have been trouble if we had had both >> zeta == z >> and rho == r. But in that special case, the desired definite >> integral is >> easily handled: it's just 0. > David W. Cantrell > Yes, it's an incorrect result. > To paraphrase your post: > integrand = (r*(r - >> rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + (z - zeta)^2 - >> 2*r*rho*Cos[alpha - t])^3); >> assumptions = {r > 0, rho > 0, Element[zeta, Reals], >> Element[z, Reals], alpha >In[15]:= 0}; > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions] > 0 > Plot[integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, >> z -> 1.2}, {t, 0, 2 Pi}, PlotRange -> All] > Visual integration is unconvincing, but you're right, the >> integral isn't >> zero: > NIntegrate[ >> integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, >> z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > Your example violates assumptions (alpha -> 0 vs. alpha > 0), but >> that's >> not the problem: > NIntegrate[ >> integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, >> z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > So, as often happens, you've found a case where Mathematica got a >> general >> solution that isn't correct for some values of the parameters. The >> quadratic formula is another example: > Solve[a x^2 + b x + c == 0, x] > {{x -> (-b - Sqrt[b^2 - 4 a c])/( >> 2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}} > Not true when a == 0, of course. > But let's look further: > indefinite = Integrate[integrand, t, Assumptions -> assumptions]; >> definite = Subtract @@ (indefinite /. {{t -> 2 Pi}, {t -> 0}}); >> Simplify[definite, assumptions] > 0 > Is that a Simplify error, or an Integrate error? > definite /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > -2.05998*10^-18 + 0. [ImaginaryI] > Ah. Simplify may be doing its job just fine (hard to be certain), >> but it >> appears the indefinite integral is incorrect. But look: > D[indefinite, t] == integrand // Simplify > True > and > D[indefinite, t] == integrand // Simplify[#, assumptions] & > True > and also > definite // Together // Numerator // Simplify > 0 > So, from that, D and/or Simplify must be wrong. > If this is correct: > numdefinite // Together // Numerator // TrigFactor > -4 r^2 (r^4 + r^2 rho^2 - 2 rho^4 + 2 r^2 z^2 - rho^2 z^2 + z^4 - >> 4 r^2 z zeta + 2 rho^2 z zeta - 4 z^3 zeta + 2 r^2 zeta^2 - >> rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4) (ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan >> [alpha/ >> 2])/Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - >> ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ >> 1/2 (alpha - 2 [Pi])])/ >> Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]]) >> (r^2 + >> rho^2 + z^2 - 2 z zeta + zeta^2 - 2 r rho Cos[alpha])^2 > The next-to-last factor (the only one that depends on t) is > num[[-2]] > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[alpha/2])/ >> Sqrt[-r^4 + >> 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - >> ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ >> 1/2 (alpha - 2 [Pi])])/ >> Sqrt[-r^4 + 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta) >> ^2) >> ^2] >> ] > so it all comes down (seemingly) to > Tan[alpha/2] == Tan[1/2 (alpha - 2 [Pi])] // Simplify > True > or > Tan[any] == Tan[any - Pi] > True > BUT... what's likely happening is that Simplify doesn't properly >> take into >> account the branch-cut discontinuities of ArcTanh. In that case, >> there's a >> significant set of parameters for which the integral IS zero, >> such as: > Reduce[Flatten@{num == 0, assumptions}] > ors = (zeta [Element] >> Reals && ((z < zeta && >> rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]) || (z == zeta && rho >> 0 && >> alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]) || (z > zeta && >> rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - >> 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + >> 2 zeta^2) #1^2 + #1^4 &, 2]))) || ((z | >> zeta) [Element] Reals && alpha > 0 && r > 0 && >> rho > 0) || (C[1] [Element] Integers && z [Element] Reals && >> C[1] >= 1 && alpha == 2 [Pi] C[1] && r > 0 && rho == r && >> zeta == z) > But look: > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > True > Hold on, though... there are a lot of Ors in there. The least >> restrictive >> seems to be > ors[[1, 2, 1]] > z < zeta && rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha >> 0 && >> r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - 4 z^3 >> zeta - >> rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + >> zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + 2 zeta^2) #1^2 + #1^4 >> &, 2] > But that's a pretty strict condition (on r, especially), and > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > False > SO. Integrate found a set of conditions for which the definite >> integral > was zero; it just didn't tell you what they were! This is supposed >> to be >> the fix for that, I think: > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions, >> GenerateConditions -> True] > 0 > BUT, as you see, that didn't help one bit! > Bobby > > I believe I am getting an incorrect result from a definite > integration: >>> InputForm[integrand] is > (R*(R - rho*Cos[alpha - t]))/(3*(R^2 + rho^2 + (z - zeta)^2 - > 2*R*rho*Cos[alpha - t])^3) >>> InputForm[assumptions] is > {R > 0, L > 0, rho > 0, Element[zeta, Reals], Element[z, Reals], > alpha> 0} >>> Integrate[integrand,{t,0,2Pi},Assumptions->assumptions] > returns 0 >>> But compare this to: > (visually integrate...) > Plot[integrand/.{R -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, z -> 1.2},{t,0,2 Pi},PlotRange->All] >>> (numerically integrate...) > Plot[NIntegrate[integrand/.{{R -> 1, rho -> 1.1, zeta -> 0, > alpha - >> 0, > z -> 1.2},{t,0,tau}],{tau,0,2Pi}, PlotRange->All] >>> Something isn't adding up?? >>>>> -- > DrMajorBob@bigfoot.com >> === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? > Sorry for not having responded sooner; I've been away from computer > access > for a week. > So, from that, D and/or Simplify must be wrong. > Must they? Even without any investigation I would say that it is much >> more likely that this integral should not be evaluated by means of >> the Leibniz rule (substituting the limits into the anti-derivative >> and subtracting). > Of course, the Leibniz rule cannot be used unless one _has_ an > antiderivative valid on the required interval. Mathematica does not > supply > such an antiderivative in this case. This has been discussed many time before on this list (with your participation) but since you seem not to be satisfied, here it goes again, I hope for the last time. The second fundamental theorem of calculus i.e. the Newton-Leibniz rule (high school level mathematics) states that if we have a function with a continuous derivative (a C1 function) on an interval than it has a continuous anti-derivative on this interval. However if the original function is not complex analytic in the complex plane then there will not be a complex analytic anti-derivative. Instead, there will be anti-derivatives with singularities, and in unlucky cases they may fall on the interval of integration. This is exactly what happens in this case. >> In fact, it is easy to see what happens in your >> special case: > integrand = (r*(r - rho*Cos[alpha - t]))/ >> (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + >> (z - zeta)^2)^3); >> int = integrand /. {r -> 1, rho -> 11/10, >> zeta -> 0, alpha -> 0, z -> 12/10} >> (1 - (11*Cos[t])/10)/(3*(73/20 - (11*Cos[t])/5)^3) > First, let us compute the integral using Integrate: > Integrate[int, {t, 0, 2*Pi}] >> (1772800*Pi)/(11512449*Sqrt[377]) > N[%] >> 0.0249156 > Now, let's do it by numerical integration: > NIntegrate[int, {t, 0, 2*Pi}] >> 0.024915592618816908 > so far, so good. Now let's compute the indefinte integral: > indef = Integrate[int, t]; > Using the Liebniz rule gives clearly the wrong answer: > indef = Integrate[int, t]; > but why should it give the right answer? > It _must_ give the right answer if indef is actually an > antiderivative on > the interval 0 to 2Pi, but it isn't. It depends on the meaning of anti-derivative. In the meaning that Mathematica and all other symbolic algebra programs use, a function can be an an anti-derivative of another function, even if it is singular or undefined at certain points in the complex plane provided it is an anti-derivative at almost all points (i.e. a generic anti-derivative). It is of course completely natural for Mathematica to use such anti-derivatives since it is precisely this kind of anti-derivatives that are found by the Risch algorithm. >> The function indef is clearly discontinuous in the interval 0 to 2Pi > True, but that discontinuity is merely an artifact of Mathematica's > workings. The integrand int is clearly continuous on the interval 0 > to 2Pi > and, indeed, on all of R, and so there is an antiderivative on R: > 886400 Sqrt[377]/4340193273 (t - 2 ArcTan[44 Sin[t]/(44 Cos[t] - 3 > Sqrt[377] - 73)]) + 8800 Sin[t] (1078 Cos[t] - 8009)/(3837483 (44 > Cos[t] - 73)^2)) > but I don't know how to get Mathematica to produce it. Of course, > using my > antiderivative above with Leibniz rule, we get the correct result > for the > definite integral. >> Plot[indef, {t, 0, 2 Pi}] > so the Leibniz rule does not apply. There is no reason at all to >> suspect the very reliable function Simplify and almost as reliabel >> Interate. > There is very good reason to suspect that Integrate, when asked to > evaluate > an indefinite integral, might give a result which is not an > antiderivative > on some desired interval. This happens fairly often, the subject of > this > thread being a case in point. Mathematica does not even attempt to find anti-derivatives on R in your sense. Instead of bringing up time and again same points that are covered in undergraduate calculus course I suggest learning a little about symbolic algebraic integration. Here are two good references: Geddes, Czapor, Labhan Algorithms for Computer Algebra, Kluwer, 1992 Davenport J. On the Integration of Algebraic Functions, Springer- Verlag 1981. If you read one of these you will find that the concept of anti- derivative that your are using is not considered suitable for computer algebra (at least at its present stage of development unless there have been some dramatic developments recently that I am not aware of ). So, you do not know how to obtain your answer with Mathematica because it can't be done. Symbolic algebra programs use known algebraic algorithms. There is no point demanding that they should do something unless a suitable general algorithm is known. Of course, it is possible that you know an algorithmic (in the same sense that the Risch algorithm is algorithmic) way of computing such anti-derivatives. If so, I am sure that Wolfram Research will be very keen to implement it. But until then this is all there is to this entire issue. Andrzej Kozlowski > Another result which might help Craig, but which I don't know how > to get > using Mathematica, is that > Assuming[r > 0 && rho > 0 && Element[zeta, Reals] && Element[z, > Reals] && > alpha > 0 && Not[rho == r && zeta == z], Integrate[(r*(r - rho*Cos > [alpha - > t]))/ (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + (z - zeta)^2)^3), > {t, 0, 2 Pi}]] > should be > (2*Pi*r^2*(-2*rho^4 + rho^2*(r^2 - (zeta - z)^2) + (r^2 + (zeta - z) > ^2)^2))/ > (3*(((rho - r)^2 + (zeta - z)^2)*((rho + r)^2 + (zeta - z)^2))^(5/2)) > Note that the last assumption mentioned above was added by me. > Without that > last assumption, there would have been trouble if we had had both > zeta == z > and rho == r. But in that special case, the desired definite > integral is > easily handled: it's just 0. > David W. Cantrell > Yes, it's an incorrect result. > To paraphrase your post: > integrand = (r*(r - > rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + (z - zeta)^2 - > 2*r*rho*Cos[alpha - t])^3); > assumptions = {r > 0, rho > 0, Element[zeta, Reals], > Element[z, Reals], alpha >In[15]:= 0}; > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions] > 0 > Plot[integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, > z -> 1.2}, {t, 0, 2 Pi}, PlotRange -> All] > Visual integration is unconvincing, but you're right, the > integral isn't > zero: > NIntegrate[ > integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, > z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > Your example violates assumptions (alpha -> 0 vs. alpha > 0), but > that's > not the problem: > NIntegrate[ > integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, > z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > So, as often happens, you've found a case where Mathematica got a > general > solution that isn't correct for some values of the parameters. The > quadratic formula is another example: > Solve[a x^2 + b x + c == 0, x] > {{x -> (-b - Sqrt[b^2 - 4 a c])/( > 2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}} > Not true when a == 0, of course. > But let's look further: > indefinite = Integrate[integrand, t, Assumptions -> assumptions]; > definite = Subtract @@ (indefinite /. {{t -> 2 Pi}, {t -> 0}}); > Simplify[definite, assumptions] > 0 > Is that a Simplify error, or an Integrate error? > definite /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > -2.05998*10^-18 + 0. [ImaginaryI] > Ah. Simplify may be doing its job just fine (hard to be certain), > but it > appears the indefinite integral is incorrect. But look: > D[indefinite, t] == integrand // Simplify > True > and > D[indefinite, t] == integrand // Simplify[#, assumptions] & > True > and also > definite // Together // Numerator // Simplify > 0 > So, from that, D and/or Simplify must be wrong. > If this is correct: > numdefinite // Together // Numerator // TrigFactor > -4 r^2 (r^4 + r^2 rho^2 - 2 rho^4 + 2 r^2 z^2 - rho^2 z^2 + z^4 - > 4 r^2 z zeta + 2 rho^2 z zeta - 4 z^3 zeta + 2 r^2 zeta^2 - > rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4) (ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan > [alpha/ > 2])/Sqrt[-r^4 + > 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ > 1/2 (alpha - 2 [Pi])])/ > Sqrt[-r^4 + > 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]]) > (r^2 + > rho^2 + z^2 - 2 z zeta + zeta^2 - 2 r rho Cos[alpha])^2 > The next-to-last factor (the only one that depends on t) is > num[[-2]] > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[alpha/2])/ > Sqrt[-r^4 + > 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ > 1/2 (alpha - 2 [Pi])])/ > Sqrt[-r^4 + 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2) > ^2] > ] > so it all comes down (seemingly) to > Tan[alpha/2] == Tan[1/2 (alpha - 2 [Pi])] // Simplify > True > or > Tan[any] == Tan[any - Pi] > True > BUT... what's likely happening is that Simplify doesn't properly > take into > account the branch-cut discontinuities of ArcTanh. In that case, > there's a > significant set of parameters for which the integral IS zero, > such as: > Reduce[Flatten@{num == 0, assumptions}] > ors = (zeta [Element] > Reals && ((z < zeta && > rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - > 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + > 2 zeta^2) #1^2 + #1^4 &, 2]) || (z == zeta && rho > 0 && > alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - > 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + > 2 zeta^2) #1^2 + #1^4 &, 2]) || (z > zeta && > rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - > 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + > 2 zeta^2) #1^2 + #1^4 &, 2]))) || ((z | > zeta) [Element] Reals && alpha > 0 && r > 0 && > rho > 0) || (C[1] [Element] Integers && z [Element] Reals && > C[1] >= 1 && alpha == 2 [Pi] C[1] && r > 0 && rho == r && > zeta == z) > But look: > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > True > Hold on, though... there are a lot of Ors in there. The least > restrictive > seems to be > ors[[1, 2, 1]] > z < zeta && rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - 4 z^3 > zeta - > rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + 2 zeta^2) #1^2 + #1^4 > &, 2] > But that's a pretty strict condition (on r, especially), and > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > False > SO. Integrate found a set of conditions for which the definite > integral > was zero; it just didn't tell you what they were! This is supposed > to be > the fix for that, I think: > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions, > GenerateConditions -> True] > 0 > BUT, as you see, that didn't help one bit! > Bobby > > integration: > InputForm[integrand] is >> (R*(R - rho*Cos[alpha - t]))/(3*(R^2 + rho^2 + (z - zeta)^2 - >> 2*R*rho*Cos[alpha - t])^3) > InputForm[assumptions] is >> {R > 0, L > 0, rho > 0, Element[zeta, Reals], Element[z, Reals], >> alpha> 0} > Integrate[integrand,{t,0,2Pi},Assumptions->assumptions] >> returns 0 > But compare this to: >> (visually integrate...) >> Plot[integrand/.{R -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, z ->> 1.2},{t,0,2 Pi},PlotRange->All] > (numerically integrate...) >> Plot[NIntegrate[integrand/.{{R -> 1, rho -> 1.1, zeta -> 0, alpha - > 0, >> z -> 1.2},{t,0,tau}],{tau,0,2Pi}, PlotRange->All] >> Something isn't adding up?? > > -- > DrMajorBob@bigfoot.com > === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? Sorry for not having responded sooner; I've been away from computer access for a week. > So, from that, D and/or Simplify must be wrong. > Must they? Even without any investigation I would say that it is much > more likely that this integral should not be evaluated by means of > the Leibniz rule (substituting the limits into the anti-derivative > and subtracting). Of course, the Leibniz rule cannot be used unless one _has_ an antiderivative valid on the required interval. Mathematica does not supply such an antiderivative in this case. > In fact, it is easy to see what happens in your > special case: > integrand = (r*(r - rho*Cos[alpha - t]))/ > (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + > (z - zeta)^2)^3); > int = integrand /. {r -> 1, rho -> 11/10, > zeta -> 0, alpha -> 0, z -> 12/10} > (1 - (11*Cos[t])/10)/(3*(73/20 - (11*Cos[t])/5)^3) > First, let us compute the integral using Integrate: > Integrate[int, {t, 0, 2*Pi}] > (1772800*Pi)/(11512449*Sqrt[377]) > N[%] > 0.0249156 > Now, let's do it by numerical integration: > NIntegrate[int, {t, 0, 2*Pi}] > 0.024915592618816908 > so far, so good. Now let's compute the indefinte integral: > indef = Integrate[int, t]; > Using the Liebniz rule gives clearly the wrong answer: > indef = Integrate[int, t]; > but why should it give the right answer? It _must_ give the right answer if indef is actually an antiderivative on the interval 0 to 2Pi, but it isn't. > The function indef is clearly discontinuous in the interval 0 to 2Pi True, but that discontinuity is merely an artifact of Mathematica's workings. The integrand int is clearly continuous on the interval 0 to 2Pi and, indeed, on all of R, and so there is an antiderivative on R: 886400 Sqrt[377]/4340193273 (t - 2 ArcTan[44 Sin[t]/(44 Cos[t] - 3 Sqrt[377] - 73)]) + 8800 Sin[t] (1078 Cos[t] - 8009)/(3837483 (44 Cos[t] - 73)^2)) but I don't know how to get Mathematica to produce it. Of course, using my antiderivative above with Leibniz rule, we get the correct result for the definite integral. > Plot[indef, {t, 0, 2 Pi}] > so the Leibniz rule does not apply. There is no reason at all to > suspect the very reliable function Simplify and almost as reliabel > Interate. There is very good reason to suspect that Integrate, when asked to evaluate an indefinite integral, might give a result which is not an antiderivative on some desired interval. This happens fairly often, the subject of this thread being a case in point. Another result which might help Craig, but which I don't know how to get using Mathematica, is that Assuming[r > 0 && rho > 0 && Element[zeta, Reals] && Element[z, Reals] && alpha > 0 && Not[rho == r && zeta == z], Integrate[(r*(r - rho*Cos[alpha - t]))/ (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + (z - zeta)^2)^3), {t, 0, 2 Pi}]] should be (2*Pi*r^2*(-2*rho^4 + rho^2*(r^2 - (zeta - z)^2) + (r^2 + (zeta - z)^2)^2))/ (3*(((rho - r)^2 + (zeta - z)^2)*((rho + r)^2 + (zeta - z)^2))^(5/2)) Note that the last assumption mentioned above was added by me. Without that last assumption, there would have been trouble if we had had both zeta == z and rho == r. But in that special case, the desired definite integral is easily handled: it's just 0. David W. Cantrell > Yes, it's an incorrect result. > To paraphrase your post: > integrand = (r*(r - > rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + (z - zeta)^2 - > 2*r*rho*Cos[alpha - t])^3); > assumptions = {r > 0, rho > 0, Element[zeta, Reals], > Element[z, Reals], alpha >In[15]:= 0}; > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions] > 0 > Plot[integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, > z -> 1.2}, {t, 0, 2 Pi}, PlotRange -> All] > Visual integration is unconvincing, but you're right, the > integral isn't > zero: > NIntegrate[ > integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, > z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > Your example violates assumptions (alpha -> 0 vs. alpha > 0), but > that's > not the problem: > NIntegrate[ > integrand /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, > z -> 1.2}, {t, 0, 2 Pi}] > 0.0249156 > So, as often happens, you've found a case where Mathematica got a > general > solution that isn't correct for some values of the parameters. The > quadratic formula is another example: > Solve[a x^2 + b x + c == 0, x] > {{x -> (-b - Sqrt[b^2 - 4 a c])/( > 2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}} > Not true when a == 0, of course. > But let's look further: > indefinite = Integrate[integrand, t, Assumptions -> assumptions]; > definite = Subtract @@ (indefinite /. {{t -> 2 Pi}, {t -> 0}}); > Simplify[definite, assumptions] > 0 > Is that a Simplify error, or an Integrate error? > definite /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > -2.05998*10^-18 + 0. [ImaginaryI] > Ah. Simplify may be doing its job just fine (hard to be certain), > but it > appears the indefinite integral is incorrect. But look: > D[indefinite, t] == integrand // Simplify > True > and > D[indefinite, t] == integrand // Simplify[#, assumptions] & > True > and also > definite // Together // Numerator // Simplify > 0 > So, from that, D and/or Simplify must be wrong. > If this is correct: > numdefinite // Together // Numerator // TrigFactor > -4 r^2 (r^4 + r^2 rho^2 - 2 rho^4 + 2 r^2 z^2 - rho^2 z^2 + z^4 - > 4 r^2 z zeta + 2 rho^2 z zeta - 4 z^3 zeta + 2 r^2 zeta^2 - > rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4) (ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan > [alpha/ > 2])/Sqrt[-r^4 + > 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ > 1/2 (alpha - 2 [Pi])])/ > Sqrt[-r^4 + > 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]]) > (r^2 + > rho^2 + z^2 - 2 z zeta + zeta^2 - 2 r rho Cos[alpha])^2 > The next-to-last factor (the only one that depends on t) is > num[[-2]] > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[alpha/2])/ > Sqrt[-r^4 + > 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2)^2]] - > ArcTanh[((r^2 + 2 r rho + rho^2 + (z - zeta)^2) Tan[ > 1/2 (alpha - 2 [Pi])])/ > Sqrt[-r^4 + 2 r^2 (rho^2 - (z - zeta)^2) - (rho^2 + (z - zeta)^2) > ^2] > ] > so it all comes down (seemingly) to > Tan[alpha/2] == Tan[1/2 (alpha - 2 [Pi])] // Simplify > True > or > Tan[any] == Tan[any - Pi] > True > BUT... what's likely happening is that Simplify doesn't properly > take into > account the branch-cut discontinuities of ArcTanh. In that case, > there's a > significant set of parameters for which the integral IS zero, such as: > Reduce[Flatten@{num == 0, assumptions}] > ors = (zeta [Element] > Reals && ((z < zeta && > rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - > 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + > 2 zeta^2) #1^2 + #1^4 &, 2]) || (z == zeta && rho > 0 && > alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - > 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + > 2 zeta^2) #1^2 + #1^4 &, 2]) || (z > zeta && > rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - > 4 z^3 zeta - rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + > 2 zeta^2) #1^2 + #1^4 &, 2]))) || ((z | > zeta) [Element] Reals && alpha > 0 && r > 0 && > rho > 0) || (C[1] [Element] Integers && z [Element] Reals && > C[1] >= 1 && alpha == 2 [Pi] C[1] && r > 0 && rho == r && > zeta == z) > But look: > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > True > Hold on, though... there are a lot of Ors in there. The least > restrictive > seems to be > ors[[1, 2, 1]] > z < zeta && rho > Sqrt[z^2 - 2 z zeta + zeta^2]/Sqrt[2] && alpha > 0 && > r == Root[-2 rho^4 - rho^2 z^2 + z^4 + 2 rho^2 z zeta - 4 z^3 > zeta - > rho^2 zeta^2 + 6 z^2 zeta^2 - 4 z zeta^3 + > zeta^4 + (rho^2 + 2 z^2 - 4 z zeta + 2 zeta^2) #1^2 + #1^4 &, 2] > But that's a pretty strict condition (on r, especially), and > % /. {r -> 1, rho -> 1.1, zeta -> 0, alpha -> 1, z -> 1.2} > False > SO. Integrate found a set of conditions for which the definite > integral > was zero; it just didn't tell you what they were! This is supposed > to be > the fix for that, I think: > Integrate[integrand, {t, 0, 2 Pi}, Assumptions -> assumptions, > GenerateConditions -> True] > 0 > BUT, as you see, that didn't help one bit! > Bobby I believe I am getting an incorrect result from a definite >> integration: > InputForm[integrand] is >> (R*(R - rho*Cos[alpha - t]))/(3*(R^2 + rho^2 + (z - zeta)^2 - >> 2*R*rho*Cos[alpha - t])^3) > InputForm[assumptions] is >> {R > 0, L > 0, rho > 0, Element[zeta, Reals], Element[z, Reals], >> alpha> 0} > Integrate[integrand,{t,0,2Pi},Assumptions->assumptions] >> returns 0 > But compare this to: >> (visually integrate...) >> Plot[integrand/.{R -> 1, rho -> 1.1, zeta -> 0, alpha -> 0, z ->> 1.2},{t,0,2 Pi},PlotRange->All] > (numerically integrate...) >> Plot[NIntegrate[integrand/.{{R -> 1, rho -> 1.1, zeta -> 0, alpha - >> 0, >> z -> 1.2},{t,0,tau}],{tau,0,2Pi}, PlotRange->All] >> Something isn't adding up?? > > -- > DrMajorBob@bigfoot.com > === Subject: Manipulator Import in Powerpoint Is there a way to import a manipulator object into a Powepoint presentation? Has anybody created an object plugin? Alternatively, is there a translator to take a Powerpoint and covert it to A MAahematica 6.0 presentation? -john michopoulos === Subject: Inset a 3D Graphic I find it difficult to Inset a Graphic3D image into Graphics2D and obtain precise size and spacings. In general I want to Inset several graphics into precise spaces with precise spacings between the various Insets. However, as an example I will use a single Inset that I want centered in a Graphics2D image. Here is the Graphics3D to be Inset. plot1 = Graphics3D[Sphere[], ImageSize -> {300, 300}, AspectRatio -> Automatic, Background -> LightBrown] This overall image appears to me to be perfectly square. Now here is an Inset construction that works. The image is 10 x 10 centered in a 12 x 12 plot region. Normally I wouldn't have a Frame, but I include one to make it easy to check the alignment. Graphics[ {Inset[plot1, {6, 6}, {Center, Center}, {10, 10}]}, PlotRange -> {{0, 12}, {0, 12}}, Background -> Orange, Frame -> True, ImageSize -> 400] However, there should be various ways of doing this, and my first attempts involved aligning the lower left corner of the Graphics3D image with the position {1,1} in the 2D graphics. First I tried using ImageScaled to specify the position in the Graphics3D image. Graphics[ {Inset[plot1, {1, 1}, ImageScaled[{0, 0}], {10, 10}]}, PlotRange -> {{0, 12}, {0, 12}}, Background -> Orange, Frame -> True, ImageSize -> 400] That does not work at all. The vertical alignment is correct, but the horizontal alignment is way off. It seems like a bug to me, but maybe I don't understand ImageScaled. So I also tried: Graphics[ {Inset[plot1, {1, 1}, {Left, Bottom}, {10, 10}]}, PlotRange -> {{0, 12}, {0, 12}}, Background -> Orange, Frame -> True, ImageSize -> 400] with the same undesired result. If I try to align on the upper right hand corner the horizontal alignment is again off. Graphics[ {Inset[plot1, {11, 11}, ImageScaled[{1, 1}], {10, 10}]}, PlotRange -> {{0, 12}, {0, 12}}, Background -> Orange, Frame -> True, ImageSize -> 400] Using the center point again with ImageScaled the alignment does work. Graphics[ {Inset[plot1, {6, 6}, ImageScaled[{0.5, 0.5}], {10, 10}]}, PlotRange -> {{0, 12}, {0, 12}}, Background -> Orange, Frame -> True, ImageSize -> 400] It seems that the only reliable point for alignment of a 3D graphic is the center point of the image. One can waste a lot of time trying something else. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: Strange Manipulate+ContourPlot behavior I suspect the discrepancy between Manipulate[ContourPlot[e and Manipulate[ContourPlot[Evaluate[e has to do with automatic simplification rules. The expression being plotted evaluates to 1, 0, 1/2 or Indeterminate depending on the order in which replacement rules are applied. e = (b (a - a p + b p))/(2 a b + (a - b)^2 p); rules = {a -> 0, b -> 0, p -> 0}; Fold[ReplaceAll[#1, #2] &, e, #] & /@ Permutations[rules] Is it possible to disable automatic simplification rules to prevent expressions like a / (2 a) simplifying to 1/2? > Not so weird... > In[]:= a = 0; b = 0; p = 0; (b (a - a p + b p))/(-2 a b (-1 + p) + > a^2 p + b^2 p) > Out[]:= Indeterminate > Syd > Syd Geraghty B.Sc., M.Sc. > sydgerag...@mac.com > San Jose, CA > Manipulate[ >> ContourPlot[( >> b (a - a p + b p))/(-2 a b (-1 + p) + a^2 p + b^2 p), {a, 0, 1}, >> {b, >> 0, 1}], {p, 0, 1}] > That is weird. Sticking in an Evaluate[] around the expression fixes > the problem -- until the slider is first moved. I guess I'd just > recommend avoiding p = 0 ... :) > Will === Subject: Re: Computation does not stop when solving system quadratic eqn > I have two quadratic equations in two unknowns l1 , l2. I try to solve > it using Solve (i could do it by hand but it's quite messy and wanted > to Mathematica to take the trouble). Solve[{32 k l2 r^2 - 16 l2^2 r^2 + > l1^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - > 16 r^2) + > k^2 (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - > 16 r^2) + > l1 (-32 l2 r^2 + > 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - > nyb p0y + p0y^2 - 16 r^2)) == 0, > -d^2 l1^2 + l1 (-2 d^2 k - 2 d^2 l2) + > k^2 (ax^2 + ay^2 - d^2 - 2 ax nxb + nxb^2 - 2 ay nyb + nyb^2) + > l2^2 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) + > 2 k l2 (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - > ay (nyb + p0y)) == 0}, {l1, l2}] However, the calculation does not stop and seems to run for ever. > Could some one please suggest any modifications i need to do? Rewrite temporarily the coefficients of l1 and l2 in a simpler form. In[1]:= rules = {c[1] -> 32 k l2 r^2 - 16 l2^2 r^2, c[2] -> (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2), c[3] -> k^2 (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2), c[4] -> (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)), c[5] -> -d^2, c[6] -> (-2 d^2 k - 2 d^2 l2), c[7] -> k^2 (ax^2 + ay^2 - d^2 - 2 ax nxb + nxb^2 - 2 ay nyb + nyb^2), c[8] -> (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2), c[9] -> 2 k , c[10] -> (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y))}; In[2]:= sols = Solve[{c[1] + l1^2 c[2] + c[3] + l1 c[4] == 0, c[5] l1^2 + l1 c[6] + c[7] + l2^2 c[8] + c[9] l2 c[10] == 0}, {l1, l2}] Out[2]= {{l2 -> (1/( 4 c[2]^2 c[ 8]))(-2 c[2]^2 c[9] c[ 10] - [Sqrt](-8 c[ 2]^2 (-2 c[1] c[2] c[5] - 2 c[2] c[3] c[5] + c[4]^2 c[5] + c[4] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[5] - c[2] c[4] c[6] - c[2] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[6] + 2 c[2]^2 c[7]) c[8] + 4 c[2]^4 c[9]^2 c[10]^2)), l1 -> (-c[4] - Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2])/( 2 c[2])}, {l2 -> (1/( 4 c[2]^2 c[ 8]))(-2 c[2]^2 c[9] c[ 10] + [Sqrt](-8 c[ 2]^2 (-2 c[1] c[2] c[5] - 2 c[2] c[3] c[5] + c[4]^2 c[5] + c[4] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[5] - c[2] c[4] c[6] - c[2] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[6] + 2 c[2]^2 c[7]) c[8] + 4 c[2]^4 c[9]^2 c[10]^2)), l1 -> (-c[4] - Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2])/( 2 c[2])}, {l2 -> (1/( 4 c[2]^2 c[ 8]))(-2 c[2]^2 c[9] c[ 10] - [Sqrt](-8 c[ 2]^2 (-2 c[1] c[2] c[5] - 2 c[2] c[3] c[5] + c[4]^2 c[5] - c[4] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[5] - c[2] c[4] c[6] + c[2] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[6] + 2 c[2]^2 c[7]) c[8] + 4 c[2]^4 c[9]^2 c[10]^2)), l1 -> (-c[4] + Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2])/( 2 c[2])}, {l2 -> (1/( 4 c[2]^2 c[ 8]))(-2 c[2]^2 c[9] c[ 10] + [Sqrt](-8 c[ 2]^2 (-2 c[1] c[2] c[5] - 2 c[2] c[3] c[5] + c[4]^2 c[5] - c[4] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[5] - c[2] c[4] c[6] + c[2] Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2] c[6] + 2 c[2]^2 c[7]) c[8] + 4 c[2]^4 c[9]^2 c[10]^2)), l1 -> (-c[4] + Sqrt[-4 c[1] c[2] - 4 c[2] c[3] + c[4]^2])/( 2 c[2])}} In[3]:= sols /. rules Out[3]= {{l2 -> (-4 k (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y)) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 - [Sqrt](16 k^2 (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y))^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^4 - 8 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 (2 k^2 (ax^2 + ay^2 - d^2 - 2 ax nxb + nxb^2 - 2 ay nyb + nyb^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 + 2 d^2 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) + 2 d^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) - (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) - d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2 - (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2) - d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))))/(4 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2), l1 -> (32 l2 r^2 - 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2) - [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))/(2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2))}, {l2 -> (-4 k (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y)) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 + [Sqrt](16 k^2 (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y))^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^4 - 8 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 (2 k^2 (ax^2 + ay^2 - d^2 - 2 ax nxb + nxb^2 - 2 ay nyb + nyb^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 + 2 d^2 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) + 2 d^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) - (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) - d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2 - (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2) - d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))))/(4 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2), l1 -> (32 l2 r^2 - 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2) - [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))/(2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2))}, {l2 -> (-4 k (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y)) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 - [Sqrt](16 k^2 (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y))^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^4 - 8 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 (2 k^2 (ax^2 + ay^2 - d^2 - 2 ax nxb + nxb^2 - 2 ay nyb + nyb^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 + 2 d^2 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) + 2 d^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) - (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) - d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2 + (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2) + d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))))/(4 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2), l1 -> (32 l2 r^2 - 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2) + [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))/(2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2))}, {l2 -> (-4 k (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y)) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 + [Sqrt](16 k^2 (ax^2 + ay^2 - d^2 + nxb p0x - ax (nxb + p0x) + nyb p0y - ay (nyb + p0y))^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^4 - 8 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 (2 k^2 (ax^2 + ay^2 - d^2 - 2 ax nxb + nxb^2 - 2 ay nyb + nyb^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2 + 2 d^2 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) + 2 d^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) - (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) - d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2 + (-2 d^2 k - 2 d^2 l2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2) + d^2 (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2)) [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))))/(4 (ax^2 + ay^2 - d^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2) (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2)^2), l1 -> (32 l2 r^2 - 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2) + [Sqrt](-4 k^2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (nxb^2 + nyb^2 - 2 nxb p0x + p0x^2 - 2 nyb p0y + p0y^2 - 16 r^2) - 4 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2) (32 k l2 r^2 - 16 l2^2 r^2) + (-32 l2 r^2 + 2 k (ax (nxb - p0x) - nxb p0x + p0x^2 + ay (nyb - p0y) - nyb p0y + p0y^2 - 16 r^2))^2))/(2 (ax^2 + ay^2 - 2 ax p0x + p0x^2 - 2 ay p0y + p0y^2 - 16 r^2))}} -- Jean-Marc === Subject: eigenvectors is taking lot of time Hi all I am trying to calculate eigenvectors of a 30 X 30 matrix. and mathematica is still just running. Is the any way to get the eigenvectors quickly. After 45 mins ,it was still running and displayed a message limit of some number here(4096) exceeded i wanted eigen values and vectors both ..so i tried eigensystem....but tat also took long, so i switched to individualfunctions of eigenvalues and eigenvectors. I aborted it...shud i execute it again and wait for longer? a 30 x 30 matrix?? Vick Al Aisa === Subject: Re: Gradient of a List data = Table[{x + RandomReal[], Sin@x + 0.1 RandomReal[]}, {x, 0, Pi, 0.1}]; f = Interpolation[data, InterpolationOrder -> 3]; {min, max} = data[[Ordering[data][[{1, -1}]], 1]]; Quiet@Plot[f'[x], {x, min, max}, PlotRange -> All] I use Quiet because Plot sometimes samples outside the data range and throws the InterpolatingFunction::dmval message. Notice, however, the result isn't even close to Cos[x], and it changes quite a bit if you change the InterpolationOrder. Bobby > Hi everybody, > Does anybody know how can I get the gradient of a list of points? > My real problem is: > I have a scalar field previously obtained numerically that for a > given point (xi,yi) takes a value f(xi,yi). What I want to do is an > estimation of the gradient of this scalar field BUT I haven't got any > analytical function that expresses my field so I can't use the Grad > function. > How can I solve this using Mathematica? Olalla, Bilbao UPV/EHU > -- DrMajorBob@bigfoot.com === Subject: Re: Gradient of a List Use Interpolation on your data to create an InterpolatingFunction and then you can apply a gradient operator to that. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hi everybody, > Does anybody know how can I get the gradient of a list of points? > My real problem is: > I have a scalar field previously obtained numerically that for a > given point (xi,yi) takes a value f(xi,yi). What I want to do is an > estimation of the gradient of this scalar field BUT I haven't got any > analytical function that expresses my field so I can't use the Grad > function. > How can I solve this using Mathematica? Olalla, Bilbao UPV/EHU > === Subject: Re: Gradient of a List interpolate the data ? and build the gradient of the interpolation. Jens > Hi everybody, Does anybody know how can I get the gradient of a list of points? My real problem is: I have a scalar field previously obtained numerically that for a > given point (xi,yi) takes a value f(xi,yi). What I want to do is an > estimation of the gradient of this scalar field BUT I haven't got any > analytical function that expresses my field so I can't use the Grad > function. How can I solve this using Mathematica? > Olalla, Bilbao UPV/EHU > === Subject: Selecting Rows Where All Columns Satisfy a Condition Hello everyone I've got an Nx4 numeric array called X. I'd like to pull out all rows where -9 does not appear in any of the four columns. I know I can this: Select[X, #[[1]] != -9 && #[[2]] != -9 && #[[3]] != -9 && #[[4]] != -9 &] But is there a more elegant way that applies the not-equal-to condition to each column without having to repeat it? Gregory === Subject: Re: What am I doing wrong with this code? When Plot is giving error messages, the first thing to do is to see what the actual values are, like Table[((1/y - 1)^(1/2)), {y, 0, 5, .1}] A useful trick is to plot both real and imaginary parts on the same graph Plot[#[(1/y - 1)^(1/2)] & /@ {Re, Im} // Evaluate, {y, 0, 5}] Yaroslav > ? Code OK on a Mac using Mathematica 6.0. Do error reoccur after restart? > Tom Dowling > I think I'm having a brain fart. Seriously... > Plot[{1/(1 + y^2), (1/y - 1)^(1/2)}, {y, 0, 5}] > What is wrong with that code? Maybe it's not solvable in mathematica? > I'm trying to plot nullclines of a system of ODEs. and those function > up there are them. I just can't get mathematica to plot them in the > same graph. > I get an error message saying... > (1/y - 1)^(1/2) is not a machine-size real number at y = > 1.0000001666666667`. > Any help is appreciated. > sean === Subject: FullSimplify in functions What is the best/proper way to incorporate FullSimplify[ ] into a function definition in such a way that the FullSimplify[ ] executes only once instead of each time the function is called, i.e. it is compiled, though I'm not sure this is the same thing as the Mathematica Compile[ ] function. Michael Mandelberg === Subject: Re: Converting notebooks to use Mathematica Player >I have just tried to do a trial run of (1) Creating a notebook using > Mathematica 6, (2) Uploading the notebook for Mathematica Player online > conversion (see > http://www.wolfram.com/solutions/interactivedeployment/publish/), (3) > Posting this converted notebook online for others to access (a ZIPped > version is at > http://www.luttrell.org.uk/notebooks/2D%20Ising%20Model.zip). > To check that things worked on a previously clean machine (i.e. without > Mathematica 6 installed) today I downloaded and installed Mathematica > Player > onto an old PC (running Windows XP, but not connected to the internet), > and > tried running the above converted notebook. The notebook opens and the > input > cells display OK, but I can't find any way of executing the notebook, > despite the fact that it proudly announces interactivity enabled at the > top of the notebook, and the output of the Manipulate cell appears only as > a > grey square. On the other hand, if I try to run the converted notebook in > Mathematica itself then it runs OK. > If there is anyone else out there who has a clean machine (i.e. > Mathematica Player, but not Mathematica 6) could they see what happens > when > they try to run the converted notebook in > http://www.luttrell.org.uk/notebooks/2D%20Ising%20Model.zip? It is > important > that this sort of thing should work OK! > -- > Steve Luttrell > West Malvern, UK > I've had the similar problems with the new on-line service to convert my notebooks. This is the email I send to support below. I got a reply that I need to buy service support to get help on these problems. oh well. btw, you should post the link you recived from WRI, not a link to your own downloaded version (and zipped). The link send by WRI remain good for a week. It is a direct link to the converted notebook. -------------------------------------------------------- === Subject: problems using your new on-line player conversion, not secured symbols error Hello; I have been trying your new conversion on-line tool you just announced. Attached is a screen shot of an error I get about unsecured symbols. Sometimes no error happens, but when I download the nbp file, nothing runs (i.e. I no dynamic UI is shown). Sometimes the file is corrupted and not complete. For the case above where I get this unsecured error, I also attach the notebook I have been trying to convert. Could you please let me what is wrong? all these work fine on Mathematica 6.0.1 on windows XP. Nasser ------------------------------------- === Subject: Re: Converting notebooks to use Mathematica Player Hi Steve, I downloaded the file to my son's MacBook which has no version of Mathematica. I downloaded the player. No joy. Your file will not run. When I tried it on my own machine with Mathematica 6 various error messages appeared. Could these be the problem? They are: ArrayPlot::mat : Argument array at position 1 is not a list of lists. ButtonBox[, BaseStyle->Link, ButtonData:>paclet:ref/ArrayPlot, ButtonFrame->None, ButtonNote->ArrayPlot::mat] ArrayPlot::mat : Argument array at position 1 is not a list of lists. ButtonBox[, BaseStyle->Link, ButtonData:>paclet:ref/ArrayPlot, ButtonFrame->None, ButtonNote->ArrayPlot::mat] On clicking your Update button I also get the message Do::iterb : Iterator {nupdate} does not have appropriate bounds. ButtonBox[, BaseStyle->Link, ButtonData:>paclet:ref/message/General/iterb, ButtonFrame->None, ButtonNote->Do::iterb] Hope this helps, Tim Brophy, Ireland > I have just tried to do a trial run of (1) Creating a notebook using > Mathematica 6, (2) Uploading the notebook for Mathematica Player > online > conversion (see > http://www.wolfram.com/solutions/interactivedeployment/publish/), (3) > Posting this converted notebook online for others to access (a ZIPped > version is at http://www.luttrell.org.uk/notebooks/2D%20Ising% > 20Model.zip). > To check that things worked on a previously clean machine (i.e. > without > Mathematica 6 installed) today I downloaded and installed > Mathematica Player > onto an old PC (running Windows XP, but not connected to the > internet), and > tried running the above converted notebook. The notebook opens and > the input > cells display OK, but I can't find any way of executing the notebook, > despite the fact that it proudly announces interactivity enabled > at the > top of the notebook, and the output of the Manipulate cell appears > only as a > grey square. On the other hand, if I try to run the converted > notebook in > Mathematica itself then it runs OK. > If there is anyone else out there who has a clean machine (i.e. > Mathematica Player, but not Mathematica 6) could they see what > happens when > they try to run the converted notebook in > http://www.luttrell.org.uk/notebooks/2D%20Ising%20Model.zip? It is > important > that this sort of thing should work OK! > -- > Steve Luttrell > West Malvern, UK > === Subject: binomial sum bug In: Sum[Binomial[5,2k],{k,0,5}] Out: 16 In: Sum[Binomial[n,2k],{k,0,n}] /. n->5 Out: -16 What the? This has been addressed before about a year ago and a work around was posted but I have two questions: 1. Was it declared a bug by Wolfrram, and 2. In general does Wolfram issue bug fixes, and specifically is there a patch for this problem? Jack Kennedy === Subject: Re: Converting notebooks to use Mathematica Player Mathematica Player does not evaluate Initialization cells. You need to make sure that any Manipulates are completely self-contained, and do not require Shift-Enter evaluations in order to work correctly. The typical way to do this is to add SaveDefinitions->True, which will suck in any definitions required to set up the Manipulate into the dynamic evaluation that sets up the Manipulate output. I took your notebook, added SaveDefinitions->True to the Manipulate, and ran it through the converter. It worked fine for me. You can find it at... http://www.wolfram.com/solutions/interactivedeployment/publish/download.jsp? id=2 171978932&filename=2D+Ising+Model+Fixed.nbp John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Mathematica 6, (2) Uploading the notebook for Mathematica Player online > conversion (see > http://www.wolfram.com/solutions/interactivedeployment/publish/), (3) > Posting this converted notebook online for others to access (a ZIPped > version is at > http://www.luttrell.org.uk/notebooks/2D%20Ising%20Model.zip). > To check that things worked on a previously clean machine (i.e. without > Mathematica 6 installed) today I downloaded and installed Mathematica > Player onto an old PC (running Windows XP, but not connected to the > internet), and tried running the above converted notebook. The notebook > opens and the input cells display OK, but I can't find any way of > executing the notebook, despite the fact that it proudly announces > interactivity enabled at the top of the notebook, and the output of the > Manipulate cell appears only as a grey square. On the other hand, if I > try to run the converted notebook in Mathematica itself then it runs OK. > If there is anyone else out there who has a clean machine (i.e. > Mathematica Player, but not Mathematica 6) could they see what happens > when > they try to run the converted notebook in > http://www.luttrell.org.uk/notebooks/2D%20Ising%20Model.zip? It is > important > that this sort of thing should work OK! === Subject: Re: New LevinIntegrate package for highly oscillatory integration This package can be hooked up to V6.0 NIntegrate using NIntegrate's plug-in mechanism. It would be best if the package is made in such a way that it provides a new integration strategy. (I.e. the plug-in is its ultimate goal.) Below is an example how the hook up can be done just using LevinIntegrate. Note that with that new strategy, LevinOscillatory, piecewise functions are properly integrated. E.g. this works In[21]:= NIntegrate[If[x < 5, Sqrt[x], Exp[I*Cosh[x]]], {x, 0, 10}, Method -> LevinOscillatory] // Timing Out[21]= {0.021987,-0.138718+1.20194 I} but LevinIntegrate gives up: In[23]:= LevinIntegrate[If[x < 5, Sqrt[x], Exp[I*Cosh[x]]], {x, 0, 10}] // Timing During evaluation of In[23]:= LevinIntegrate::unknownoscillator: LevinIntegrate only operates on integrands containing oscillatory factors matching E^_|BesselJ[_Integer,_]|Sin[_]|Cos[_]. If your integrand can still be integrated using a Levin-type method, use GeneralisedLevinIntegrate. Out[23]= {0.001462,Null} Plug-in code: Needs[Moylan`LevinIntegrate`] Clear[LevinOscillatory] LevinOscillatory /: NIntegrate`InitializeIntegrationStrategy[LevinOscillatory, nfs_, ranges_, strOpts_, allOpts_] := Block[{}, LevinOscillatory[{First /@ ranges, strOpts}] ]; LevinOscillatory[{vars_, strOpts_}][Algorithm[regions_, opts___]] := Module[{integrands, ranges, res}, integrands = (#@Integrand)@FunctionExpression & /@ regions; ranges = First@Outer[Prepend[#1, #2] &, #@Boundaries, vars, 1] & /@ regions; res = MapThread[ LevinIntegrate[#1, Sequence @@ #2, Sequence @@ strOpts] &, {integrands, ranges}]; If[FreeQ[res, Null], Total@res, Total@ MapThread[ If[NumberQ[#1], #1, NIntegrate[#2, Sequence @@ #3 // Evaluate, DeleteCases[opts, Method -> _] // Evaluate]] &, {res, integrands, ranges}] ] ]; Anton Antonov, Wolfram Research, Inc. > Hi all, > My LevinIntegrate package, for numerical integration of highly oscillatory > LevinIntegrate is an automatic integrator based on Levin's method for highly > oscillatory integration. It outperformsNIntegrate(and other automatic > integrators) for a variety of irregularly oscillatory functions: > LevinIntegrate[Exp[I*Cosh[x]], {x, 0, 10}] // Timing >> {0.02, -0.138718 + 1.20194 * I} > Compare with: > NIntegrate[Exp[I*Cosh[x]], {x, 0, 10}, MaxRecursion -> 50] // Timing >> (warnings) >> {4.546, -0.138718 + 1.20194 * I} This is an early release of LevinIntegrate; it is still under development. > If you have any comments, suggestions, or problems, please do let me know of > them! > Andrew Moylan === Subject: Zoom2D 4 weeks ago I posted the newest version of Zoom2D adapted to Mahematica 6.0.1. Since I received 2 complaints that the new version is not working because the command BoxForm`ClosingSaveDialog -> False] is marked red by Mathematica's editor. Well, I just made several plots (e.g. Plot[Sin[x],{x,0,10}]) and tried Zoom2D, this worked without problems. Looking at the code, it is true that the above command is flagged red, but this seems rather a bug of the editor than of Zoom2D. If somebody had a problem with Zoom2D, I beg that he sends me an example that I have a chance to look at it. Daniel === Subject: Re: mathematica 6.0 for linux crashes when manipulating plots of I had the same problem using fglrx with an ATI graphics card. Try to run Mathematica with the '-mesa' switch; it forces Mathematica to use its own GL libraries and it should not crash. -Francesco > tutorial, I noticed it ALWAYS crashes when doing the 4th step (Make it > dynamic...). > When running from terminal, the following appears: > Mathematica has received the signal: SIGSEGV and has exited. If > possible, please report this problem to support@wolfram.com describing > in as much detail as possible what you were doing when the problem > occurred. > Segmentation fault (core dumped) > === Subject: Re: Extracting solutions from Solve[] > Hello group: > New guy to Mathematica and I am using the Solve function to find all the roots of a non linear set of equations. > My question is once I have all the solution I am getting rid of all the complex ones and then I need to keep the ones that are within the interval [0,1]. > I have the following nested list after removing complex values: > {{}, {}, {}, {}, {}, {}, {}, {}, { > 1., -0.357968, -0.0366376}, {1., -0.357968, -0.0366376}, {}, {}, {}, {}, > {0.326026, -0.812319, 0.0112833}, {-0.791102, > 0.283189, 0.0113524}, {}, {}, {0.454731, 0.840435, 0.0318799}, {}, {}, > {0.999998, > 1.8482, 1.63961}, {0.999997, 1.8482, 1.63962}, {0.998429, -2.49158, > 3.06313}, {0.999101, -2.49158, 3.06323}} I need to take the solution/group that is within [0,1]. > How do you do this?? > Any help is appreciated....no luck so far... One possible way, using *Cases* and interval arithmetic: In[1]:= sols = {{}, {}, {}, {}, {}, {}, {}, {}, {1., -0.357968, -0.0366376}, {1., -0.357968, -0.0366376}, {}, {}, {}, {}, {0.326026, -0.812319, 0.0112833}, {-0.791102, 0.283189, 0.0113524}, {}, {}, {0.454731, 0.840435, 0.0318799}, {}, {}, {0.999998, 1.8482, 1.63961}, {0.999997, 1.8482, 1.63962}, {0.998429, -2.49158, 3.06313}, {0.999101, -2.49158, 3.06323}}; In[2]:= Cases[sols, {a_, b_, c_} /; IntervalMemberQ[Interval[{0, 1}], a] && IntervalMemberQ[Interval[{0, 1}], b] && IntervalMemberQ[Interval[{0, 1}], c]] Out[2]= {{0.454731, 0.840435, 0.0318799}} -- Jean-Marc === Subject: Re: Extracting solutions from Solve[] On Oct 24, 6:39 pm, Isaac Martinez G. Hello group: > New guy to Mathematica and I am using the Solve function to find all the roots of a non linear set of equations. I do not have a function that selects positive solutions between 0 and 1 But I do have a select positive function. SelectPositive[soln_] := Select[soln, Apply[And,Map[Abs[Part[#, 2]] == Part[#, 2] &, #]] & ] In[4]:= Solve[4 x^2 - 6 x - 9 == 0, x] // SelectPositive Out[4]:= {{x->3/4 (1+Sqrt[5])}} > My question is once I have all the solution I am getting rid of all the complex ones and then I need to keep the ones that are within the interval [0,1]. > I have the following nested list after removing complex values: > {{}, {}, {}, {}, {}, {}, {}, {}, { > 1., -0.357968, -0.0366376}, {1., -0.357968, -0.0366376}, {}, {}, {}, {}, > {0.326026, -0.812319, 0.0112833}, {-0.791102, > 0.283189, 0.0113524}, {}, {}, {0.454731, 0.840435, 0.0318799}, {}, {}, > {0.999998, > 1.8482, 1.63961}, {0.999997, 1.8482, 1.63962}, {0.998429, -2.49158, > 3.06313}, {0.999101, -2.49158, 3.06323}} > I need to take the solution/group that is within [0,1]. > How do you do this?? > Any help is appreciated....no luck so far... === Subject: Re: (x|y) [element] Integers in Reduce function > Consider the following Reduce[x^2 - 2 y^2 == 1 && x>= 0 && y>=0 && (x|y) [element] Integers, > {x,y} ] What does (x|y) [element] Integers mean? Does it mean: (a) x is an Integer AND y is an Integer (b) x is an Integer OR y is an Integer The correct answer is (b). The vertical bar | stands for *Alternatives* in pattern matching (equivalent to the non-exclusive logical OR). See ref/Alternatives and also the tutorial Patterns Involving Alternatives in the documentation center (tutorial/PatternsInvolvingAlternatives). Note that the correct syntax for [element] is [Element] (with a capital 'e'). -- Jean-Marc === Subject: Re: (x|y) [element] Integers in Reduce function Element[x|y, Integers] means that both x and y are integers. http://reference.wolfram.com/mathematica/ref/Element.html Element[patt, dom] asserts that any expression matching the pattern patt is an element of dom. The symbols x and y both match the pattern x|y, so x *and* y are both elements of the specified domain. Bhuvanesh, Wolfram Research === Subject: Re: Integers in Reduce function > Consider the following > Reduce[x^2 - 2 y^2 == 1 && x>= 0 && y>=0 && (x|y) [element] Integers, > {x,y} ] > What does (x|y) [element] Integers mean? > Does it mean: > (a) x is an Integer AND y is an Integer > (b) x is an Integer OR y is an Integer It means AND. The reason is that x|y is a pattern. So what this is saying is that everything that the pattern x|y matches is assumed to be an integer. But what sort of things does the pattern x|y match? Well, it certianly matches x. And it certainly matches y. And it does not match anything else in your formula. So both x and y are assumed to be integers. Andrzej Kozlowski === Subject: Re: remove whitespace > I have a txt file and i want to remove all whitespaces in that file . > I am trying to get a list of all characters in that file ..and it > takes whitespace too,which i wnat to eleminate. I used ReadList which works as I want, but it takes all > whitespaces,.... > How can i overcome this problem. I use Mathematica 5.2 You could use *StringReplace*. In[1]:= data = {The Quick Brown, Fox Jump Over, The Lazy Dog.}; In[2]:= StringReplace[data, Whitespace -> ] Out[2]= {TheQuickBrown, FoxJumpOver, TheLazyDog.} -- Jean-Marc === Subject: Re: Why does Sum return 0 on this series? > In Mathematica 6.0.1 on Mac OS X, Sum returns 0 on this series. > In[1]:= Sum[Log[n]^4/n^2, {n, 2, Infinity}] > Out[1]= 0 > In[2]:= $Version > Out[2]= 6.0 for Mac OS X x86 (32-bit) (June 19, 2007) > Of course that's not right, because the terms are all positive. I > don't expect Sum to always return a correct answer for any series > (that would be unreasonable), OTOH, I think it would be reasonable that Sum should always return a correct answer for any series, assuming that we consider returning the original series unevaluated as being one type of correct answer. > and NSum is the more appropriate > command to investigate this series numerically. But 0 seems like a > very strange answer. Can anyone provide any insight on why > Mathematica is returning 0 for the sum of a positive series? Sorry, I can't do that. However, you might be interested to know that that sum can be expressed in closed form in Mathematica; it's Derivative[4][Zeta][2]. In[2]:= N[Derivative[4][Zeta][2], 11] Out[2]= 24.001486394 In[3]:= NSum[Log[n]^4/n^2, {n, 2, Infinity}, WorkingPrecision->20] Out[3]= 24.001486394 -------------------------- BTW, at least in version 5.2, we can get negative values for some sums of positive terms, related to your original series. For example, In[14]:= Sum[Log[n]^4/n^2, {n, 3, Infinity}] Out[14]= -(1/4)*Log[2]^4 Whether the source of that bug is the same as the source of yours, I don't know. David W. Cantrell === Subject: Re: Why does Sum return 0 on this series? > In Mathematica 6.0.1 on Mac OS X, Sum returns 0 on this series. > In[1]:= Sum[Log[n]^4/n^2, {n, 2, Infinity}] > Out[1]= 0 > In[2]:= $Version > Out[2]= 6.0 for Mac OS X x86 (32-bit) (June 19, 2007) > Of course that's not right, because the terms are all positive. I > don't expect Sum to always return a correct answer for any series > (that would be unreasonable), and NSum is the more appropriate > command to investigate this series numerically. But 0 seems like a > very strange answer. Can anyone provide any insight on why > Mathematica is returning 0 for the sum of a positive series? Adam > ----- > Adam Weyhaupt > Department of Mathematics and Statistics > Southern Illinois University Edwardsville > aweyhau@siue.edu > http://www.siue.edu/~aweyhau/ > Science Building 1316 (618) 650-2220 It's a bug, of course. Bugs happen, even in Mathematica. In fact the answer ought to be: Derivative[4][Zeta][2] Derivative[4][Zeta][2] N[%, 10] 24.001486393736461571`9.999999999999998 This agrees with the answer given by NSum: NSum[Log[n]^4/(n)^2, {n, 2, Infinity}, PrecisionGoal -> 10, WorkingPrecision -> 20] 24.001486394 You can prove this using the first series here: http://functions.wolfram.com/ZetaFunctionsandPolylogarithms/ Zeta2/06/05/01/02/ Andrzej Kozlowski === Subject: Re: Problem with Differential Eq you miss a comma solution = NDSolve[{lpmk1'[ t] == (lpmk10[lpv[t]] - lpmk1[t])*(1/lptaumk1[lpv[t]]), lpmk1[0] == lpmk10[-80]*(1/lptaumk1[-80]), lpv'[t] == -1*(+1*125*(lpmk1[t] 4)*(lpv[t] + 80)), lpv[0] == -80}, {lpv, lpmk1}, {t, 0, 1500}, Method -> Automatic]; ParametricPlot[Evaluate[{t, lpv[t]} /. solution], {t, 0, 1500}, PlotPoints -> 1500, PlotRange -> All] may work. Jens > The following .nb file just won't run!!! I can't see what is wrong as it is > a relativly simple series of self evaluating differential equations. [code] lpmk10[u_] := 1/(1 + Exp[(u + 12.3)/-11.8]); > lptaumk1[u_] := 14.4 - 12.8/(1 + Exp[(u + 28.3)/-19.2]); solution = > NDSolve[{lpmk1'[t] == (lpmk10[lpv[t]] - lpmk1[t])*(1/lptaumk1[lpv[t]]), > lpmk1[0] == lpmk10[-80]*(1/lptaumk1[-80]) > lpv'[t] == > -1*(+1*125*(lpmk1[t]^4)*(lpv[t] + 80)), > lpv[0] == -80}, > {lpv, lpmk1}, {t, 0, 1500}, Method -> Automatic]; > ParametricPlot[Evaluate[{t, lpv[t]} /. solution], {t, 0, 1500}, > PlotPoints -> 1500, PlotRange -> All]; [/code] if any one can shed some light on this it would be great > === Subject: Re: Problem with Differential Eq > The following .nb file just won't run!!! I can't see what is wrong as it is > a relativly simple series of self evaluating differential equations. solution = > NDSolve[{lpmk1'[t] == (lpmk10[lpv[t]] - lpmk1[t])*(1/lptaumk1[lpv[t]]), > lpmk1[0] == lpmk10[-80]*(1/lptaumk1[-80]) ------------------------------------------^^^ A comma is missing here to separate the two equations. > lpv'[t] == -- Jean-Marc === Subject: Re: A riddle: Functions that return unevaluated when they cannot Is this what you are looking for? In[27]:= ClearAll[g] In[28]:= g[x_]:=Module[{res=x+2}, res/;res<10 ] In[29]:= g[15] Out[29]= g[15] In[30]:= g[1] Out[30]= 3 That is, using a conditional on your last expression decides whether or not a return value is returned or the input expression is returned unevaluated. This could of course be a flag which tells whether your calculation succeeded or not. I can't remember where I found this trick, I don't know whether it is documented and how/why it works. But I think it is used in the code of some of the Standard Packages (and probably in the functions you mentioned as well) so should work reliable, but I have no guarantees for that... hth, albert === Subject: Installed new Version 6.1 Add Ons Problem Good Day, I am running versions 5.2 and 6.0 on both 4 core XP Pro 64 bit and 2 core Vista Ultimate 64 bit. In installing Wolfram version 6.1 compatible Ad Ons on the Vista machine it goes to the correct sub directory and is recognized by the 6.1 program. The 5.2 directory with the 5.2 Add Ons is preserved. The document center recognizes new Add Ons. In installing Wolfram version 6.1 compatible Ad Ons on the XP pro 64bit 5.2 Add Ons. The document center recognizes the 5.2 Add Ons. I have reported it to support Ben === Subject: Wald test on mathematica Hello there. I've been trying to make a Wald test, but I got into some problems. Lists are sort of vectors I guess, but they don't always function that way.Here is my ordinary least squares function: ols[x_, y_] := (Inverse[Transpose[x].x]).Transpose[x].y; And my wald test: wald[r_, q_, x_, y_] := (Transpose[(r.ols[x, y]) - q].Inverse[ r.Inverse[Transpose[x].x].Transpose[r]].(r.ols[x, y] - q)*(Part[ Dimensions[x], 1] - Part[Dimensions[xdmda], 2]))/((errors[x, y].errors[x, y])* Part[Dimensions[r], 1]) Where r and q make up the linear restrictions as in rb = q The thing that bothers me is (and it's the same with ols) that I can't use this same function if x is a vector instead of a matrix or if r is a vector, because mathematica will not allow me to transpose a one-dimensional list. What should I do? Should I make a If, then thingy or is there some simpler way I'm not aware of for dealing with this kind of situatitions? === Subject: Re: Help with NMinimize Hello Flavio: Recently I have been studying the numeric capabilities of Mathematica. My attempt at an answer to your question would be: The NXXX, FindXXX routines do use numerical rather than symbolics, but this is mainly for internal calculations. The Mathematica interpreter language processing is separate and inherently symbolic. So understanding patterns, rules, pure functions, et.al. will always be part of making your Mathematica programs work correctly, even with using the NXXX routines. > clear to me which was the problem with my code. Just one last > philosophical question: I know that Mathematica deals with simbolic > calculation, but I though that at least the Nxxx commands (NSolve, > NDSolve,NMinimize, ...) would treat the functions just numerically. > So must I keep in mind that these commands have to be considered > simbolic too? Flavio === Subject: How to create an animation of a rotating rectangle? Using Mathematica, I would appreciate your help on creating the animation of a rectangle rotating about any one of its diagonal, either counterclockwise or clockwise. I would appreciate links to further reading on this topic. Sergio === Subject: Re: Re: why no result & no error from this recursion Yes, and it suddenly quits the kernel -- the command line window that opened when I started the kernel disappears. >> Why does the following recursion produce neither a result nor an error >> message -- nor a system crash? > Block[{$RecursionLimit=50002}, (If[#<1, , . <> #0[# - 1]] &)[50000]] > I even tried setting $RecursionLimit=Infinity, but no change. > I presume this is just bumping up against a hardware/OS limit, so I'm >> surprised to get no error message and no crash. Have you tried running this from the command line? $ MathKernel > Mathematica 5.1 for Linux x86 (64 bit) > -- Motif graphics initialized -- In[1]:= Block[{$RecursionLimit=50002}, (If[#<1, , . <> #0[# - 1]] & > [50000]] > Segmentation fault > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Mathematica Special Interest Group (Northern VA and Washington DC) The Washington D.C. area Mathematica Special Interest Group will meet Friday, 26 October, 7:30 to 9:00 a.m. at the SAIC Enterprise Center building in Tysons Corner (see directions below). Early risers meet before 7:00 in the morning for admission at the front desk, then we have a Dutch treat breakfast downstairs. By about 7:30 we have moved to one of the projector rooms. Meetings consist of a prepared talk, informal discussion about Mathematica programming and applications, general questions, and new business. The two 30-minute talks are: Moving Mathematical Mountains and Surmounting the Challenges of Mathematica, Part II, by D. Vasholz Abstract. Dave continues his talk about wicked mathematical problems and their resolution by Mathematica. Using Group Theory to Compute Tourlength Differences, by B. Colletti Abstract. Bruce computes the difference between the lengths of two tours, each a solution to the multiple asymmetric Traveling Salesman Problem. Big deal! you may say, Just compute each tourlength and subtract. Well, that's the easy but computationally difficult way (when there are thousands of cities). Here we use group theory to compute the difference (WITHOUT computing either tourlength) and to GREATLY reduce processing time. This result is the first of many applications of group theory to tabu search methods of combinatorial optimization conducted by an AFOSR-funded DoD-University Research Consortium (of which Bruce is a co-founder). To inquire about attending, e-mail Dan Martinez (dmartinez@sprintmail.com) or Bruce Colletti (bcolletti@compuserve.com). In your e-mail subject line, please include 'Mathematica SIG.' Turn right onto Westpark Drive (Gosnell Road in the other direction). Turn right at the next light onto Greensboro Drive and then right into the parking lot. Visitor's Parking is adjacent to Westpark Drive. A SIG representative will meet you in the lobby. Please arrive no later than ten minutes to seven if you wish to join us for breakfast, and no later than twenty after seven to attend the meeting only. The desk officer will ask for a driver's license before issuing a visitor's badge. === Subject: Re: determine viewpoint value during V6 3d rotation > In any case, with Version 6 any piece of Graphics3D, > including that produced > by ParametricPlot3D, can be rotated with the mouse. > You can also hold down > the the Ctrl key and zoom in and out with the mouse. > You can also hold down > the shift key and translate the image back and forth > or up and down. Yes, but once you've rotated the image, how can you determine the numerical values of the new settings (so that you can save them for later use)? George === Subject: Problem with Integral in mathematica 5.1 I have three integrals on a volume which normaly gives the same value when I make the integral on a cubic volume (same intervals for the three variables). In the starting functions which all depend on x,y and z, there is just a change in the numerator, it is x^2 for Gxx, y^2 for Gyy, and z^2 for Gzz. I obtain the same results at the end for Gxx and Gzz, but Gyy is different. And I actually don't understand. Below I paste the three different scripts for Gxx,Gyy, and Gzz. If you find something strange, please tell me. Gxx: f[x_, y_, z_] = 1/(4*Pi*yc)*(3* x^2/(Sqrt[x^2 + y^2 + z^2])^5 - 1/( Sqrt[x^2 + y^2 + z^2])^3 + k^2/2*(x^2/(Sqrt[x^2 + y^2 + z^2])^3 + 1/(Sqrt[x^2 + y^2 + z^2]))); g[x_, y_, z_] = Integrate[f[x, y, x], x]; h[y_, z_] = g[x2, y, z] - g[x1, y, z]; i[y_, z_] = Integrate[h[y, z], y]; j[z_] = i[y2, z] - i[y1, z]; l[z_] = Integrate[j[z], z]; res = l[z2] - l[z1] // FortranForm x1 = -0.5; x2 = 0.5; y1 = -0.5; y2 = 0.5; z1 = -0.5; z2 = 0.5; yc = 1 + I*5.56*10^(-11); k = 1.99*10^(-3) - I*1.99^(-3); res Gyy: f[x_, y_, z_] = 1/(4*Pi*yc)*(3* y^2/(Sqrt[x^2 + y^2 + z^2])^5 - 1/( Sqrt[x^2 + y^2 + z^2])^3 + k^2/2*(y^2/(Sqrt[x^2 + y^2 + z^2])^3 + 1/(Sqrt[x^2 + y^2 + z^2]))); g[x_, y_, z_] = Integrate[f[x, y, x], x]; h[y_, z_] = g[x2, y, z] - g[x1, y, z]; i[y_, z_] = Integrate[h[y, z], y]; j[z_] = i[y2, z] - i[y1, z]; l[z_] = Integrate[j[z], z]; res = l[z2] - l[z1] // FortranForm x1 = -0.5; x2 = 0.5; y1 = -0.5; y2 = 0.5; z1 = -0.5; z2 = 0.5; yc = 1 + I*5.56*10^(-11); k = 1.99*10^(-3) - I*1.99^(-3); res Gzz: f[x_, y_, z_] = 1/(4*Pi*yc)*(3* z^2/(Sqrt[x^2 + y^2 + z^2])^5 - 1/( Sqrt[x^2 + y^2 + z^2])^3 + k^2/2*(z^2/(Sqrt[x^2 + y^2 + z^2])^3 + 1/(Sqrt[x^2 + y^2 + z^2]))); g[x_, y_, z_] = Integrate[f[x, y, x], x]; h[y_, z_] = g[x2, y, z] - g[x1, y, z]; i[y_, z_] = Integrate[h[y, z], y]; j[z_] = i[y2, z] - i[y1, z]; l[z_] = Integrate[j[z], z]; res = l[z2] - l[z1] // FortranForm x1 = -0.5; x2 = 0.5; y1 = -0.5; y2 = 0.5; z1 = -0.5; z2 = 0.5; yc = 1 + I*5.56*10^(-11); k = 1.99*10^(-3) - I*1.99^(-3); res === Subject: Re: Returning rules from functions inside a package context >> The following question has been asked and answered in a variety of ways >> in this forum, but I am new to Mathematica and am still not sure what >> is best practice after doing Trace of various trivial statements for >> the past few hours. > For example, I would like f[] below to return {a->1.}, not >> {A`Private`a->1.}. > BeginPackage[A`] >> f::usage = >> Begin[`Private`] > f[] := FindFit[{{0, 0}, {1, 1}}, a x, {a}, x] > End[] > EndPackage[] > The use of Rule[] in different scoping constructs is confusing. >First scope a and x appropriately, as others in this thread have > advised. But then try strings; return the value with the definition f[a] = 1, > or if you need rules, perhaps f[a] = {a -> 1}. I think it's prudent to keep the symbols to a minimum; they too easily > introduce difficult dependencies into larger packages. Vince Virgilio though it took me a while. I am following Jens-Peer's suggestion of defining usage for the each of the returned rule symbols. I am guessing that will be the easiest way for me to stay out of trouble (and giving Capitalized long names to everything). I find, though, that I am parsing the options strings a lot with Cases[opts, Rule[x_, y_]-> something] which may be a bad habit. Art === Subject: Re: Returning rules from functions inside a package context as others have pointed out, there are several possibilities to achieve what you want. I just wanted to strongly recommend not to use the Global`a trick, which will cause all kind of troubles if used in other than the most simple cases. In your case you could simply return just the number, there seems to be no added value in returning the rule at all. Of course if there are more than one parameter in your model, it makes sense to return a list of rules, but then I would recommend to either use strings with meaningful names as others have mentioned or use additional arguments for the symbol names that will be used. This can be achieved like this: BeginPackage[A`] f::usage = Begin[`Private`] f[a_Symbol] := FindFit[{{0, 0}, {1, 1}}, a x, {a}, x] End[] EndPackage[] The function could then be called like: f[c] and returns {c->1.} It is now in the responsibility of the caller to make sure that the symbols used are not set to a value... hth, albert === Subject: Re: WebMathematica and 6.0 problems > >> Probably it is a better idea to install mathematica 5.2 which usually >> runs alright with the license password installed for version 6. I don't think this is true. Actually I don't know whether that is generally true or not, it has always worked for me, though. Sorry if this has caused trouble for anyone... albert === Subject: Re: Hankel transform question > What I get in the development Mathematica kernel is simply an > unevaluated Integrate. > In[12]:= Integrate[s*BesselJ[v,w*s], {s,0,Infinity}, > Assumptions->{v>0,w>0}] > Out[12]= Integrate[s BesselJ[v, s w], {s, 0, Infinity}, > Assumptions -> {v > 0, w > 0}] > But the integral is in fact divergent. To see this, check the series > expansion at infinity. > In[13]:= InputForm[Series[s*BesselJ[v,w*s], {s,Infinity,2}, > Assumptions->{v>0,w>0}]] > Out[13]//InputForm= > Cos[Pi/4 + (Pi*v)/2 - s*w]* > SeriesData[s, Infinity, {Sqrt[2/Pi]/Sqrt[w]}, -1, 3, 2] + > SeriesData[s, Infinity, > {(-1 + 4*v^2)/(4*Sqrt[2*Pi]*w^(3/2))}, 1, 3, 2]* > Sin[Pi/4 + (Pi*v)/2 - s*w] > Notice that the main term is, up to scaling and phase change, of the > form Cos[s]*Sqrt[s]. This diverges in classical integration. > To get a regularized result, you can do as below. > In[14]:= InputForm[Integrate[s*BesselJ[v,w*s], {s,0,Infinity}, > Assumptions->{v>0,w>0}, GenerateConditions->False]] > Out[14]//InputForm= v/w^2 > Offhand I do not see any reason to expect a delta function result. > Certainly DiracDelta[s] would be incorrect, because s is the integral > variable of (definite) integration, hence cannot appear in the result. an integral of f(s) to converge either, with f(s) of the form f(s) = s^a BesselJ(v,w s) (v is the Bessel order, w is a transform variable) if a > 1/2 , since we know that the Bessel function only decays like 1/ sqrt(s) as s goes to infinity. However, it was Mathematica itself (version 5.2) that suggested this integral might make sense, given some sort of regularization (what is this regularization, by the way? Principal Value?) In fact, from the mathworld page http://mathworld.wolfram.com/HankelTransform.html one can see that the delta function Delta[w] can be written as the Hankel Transform of unity (I'm ignoring 2*pi conventions): Delta[w] = Integrate[s BesselJ[0,w s],{s,0,Infinity}] I'm certain that this is simply the analog of the usual representation of the Delta function as a Fourier Transform (the Hankel version is simply in polar coordinates). In any case, it doesn't seem that Mathematica recognizes this variant of the Delta function. J === Subject: Re: Animate with Slider Box Value > I would like to use the following example Animate[Plot[Sin[a x]+Sin[b x],{x,0,10},PlotRange=AE2],{a,1,5},{b,1,5}] But to include only a box with the currnet value of the slider, without the controls (e.g., Pause, etc.). Also, I would like to include a more descriptive name for the slider. How can I this? John C. Erb Maybe this is what you want? Animate[ Plot[Sin[a x] + Sin[b x], {x, 0, 10}, PlotRange -> {-2, 2}], {{a, 1, Parameter 1:}, 1, 5}, {{b, 1, Parameter 2:}, 1, 5}, AnimatorElements -> ProgressSlider ] If you want even more control, you probably can construct the Animate all by yourself, e.g. with something like: Deploy[ DynamicModule[{a = 1, b = 1}, Panel[Column[{Row[{Animator[Dynamic[a], {1, 5}, AppearanceElements -> None], Parameter 1:, Spacer[5], InputField[Dynamic[a]]}], Row[{Animator[Dynamic[b], {1, 5}, AppearanceElements -> None], Parameter 2:, Spacer[5], InputField[Dynamic[b]]}], Panel[ Dynamic[ Plot[Sin[a x] + Sin[b x], {x, 0, 10}, PlotRange -> {-2, 2}]], ImageSize -> 400 ] }] ]] ] hth, albert === Subject: Re: compute distribution > How can i compute the distribution of signals fired from a net . ther > are 26 different signals that can be fired. > which is obtained the form below. > { ammmmmstgretsrdhydtudytyhsdefaweshgffdyhsfdhsgfjsdfdsfhkpgfkjgfjhkjhfdgkbfsdn fjkdsglhdsjfkgndsjgh} i ma confused with how to show the distribution plot. If i compute the > number of times each signal has occured, than how it can be > plotted. (like a appears 12 times, b appears 13 times....than > frequency of appearance can be represented on y axis but what can i > take on x axis. I work on mathematica 5.2 I am not sure at all to have correctly understood what you are looking for; however, I believe that the following should be close enough to help you started. (First in version 5.2, then in version 6.0.1. Graphics have been deleted from this post.) In[1]:= $Version Out[1]= 5.2 for Microsoft Windows (June 20, 2005) In[2]:= myTally[l_List]:=Map[{#,Count[l,#]}&,Union[l]] In[3]:= data=myTally[Characters[ToString[{ ammmmmstgretsrdhydtudytyhsdefaweshgffdyhsfdhsgfjsdfdsfhkpgfkjgfjhkjhfdgkbfsd nf jkdsglhdsjfkgndsjgh}[[1]]]]] Out[3]= {{a,2},{b,1},{d,13},{e,3},{f,13},{g,9},{ h,10},{j,7},{k,6},{l,1},{m,5},{n,2},{p,1},{r,2},{s,12},{t,4},{u,1},{w,1},{y, 4}} In[4]:= data=Sort@Join[data,{#,0}&/@Complement[CharacterRange[a,z],data[[All ,1]]]] Out[4]= {{a,2},{b,1},{ c,0},{d,13},{e,3},{f,13},{g,9},{h,10},{i,0},{j,7},{k,6},{l,1},{m,5},{ n,2},{o,0},{p,1},{q,0},{r,2},{s,12},{t,4},{u,1},{v,0},{w,1},{x,0},{y, 4},{z,0}} In[5]:= < True, Ticks -> {Transpose[{Range[26], CharacterRange[a, z]}], Automatic}] -- Jean-Marc === Subject: Re: compute distribution > Hi ALL > How can i compute the distribution of signals fired from a net . ther > are 26 different signals that can be fired. > which is obtained the form below. > { ammmmmstgretsrdhydtudytyhsdefaweshgffdyhsfdhsgfjsdfdsfhkpgfkjgfjhkjhfdg= kbfs=ADdnfjkdsglhdsjfkgndsjgh} > i ma confused with how to show the distribution plot. If i compute the > number of times each signal has occured, than how it can be > plotted. (like a appears 12 times, b appears 13 times....than > frequency of appearance can be represented on y axis but what can i > take on x axis. > I work on mathematica 5.2 > thnaks > Vick Al Aisa Good day, Here is one way to do it, using character codes : In[1]:=< True] Out[5]=-Graphics- In[6]:=$Version Out[6]=5.1 for Microsoft Windows (January 28, 2005) V=2EAstanoff === Subject: Re: compute distribution $Version 5.2 for Mac OS X (June 20, 2005) Needs[Graphics`]; (* Needs[BarCharts`]; Version 6 *) str=ammmmmstgretsrdhydtudytyhsdefaweshgffdyhsfdhsgfjsdfdsfhkpgfkjgfjhkjhfd gkb fsdnfjkdsglhdsjfkgndsjgh; alpha=CharacterRange[a,z]; data=StringCount[str, #]&/@alpha; BarChart[data, BarLabels->alpha, ImageSize->468] Bob Hanlon > Hi ALL How can i compute the distribution of signals fired from a net . ther > are 26 different signals that can be fired. > which is obtained the form below. > { ammmmmstgretsrdhydtudytyhsdefaweshgffdyhsfdhsgfjsdfdsfhkpgfkjgfjhkjhfdgkbfsdn fjkdsglhdsjfkgndsjgh} i ma confused with how to show the distribution plot. If i compute the > number of times each signal has occured, than how it can be > plotted. (like a appears 12 times, b appears 13 times....than > frequency of appearance can be represented on y axis but what can i > take on x axis. I work on mathematica 5.2 thnaks Vick Al Aisa === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? > I am simply not interested enough in the subject of definite > integration Just in order not to be misunderstood again: I find contour integration in the complex plane a fascinating subject. The same is true about integration on manifolds, topological groups etc. It's only integration on the real line that has no attraction for me whatever so I will try to avoid any future involvement in discussions of this topic. Andrzej Kozlowski === Subject: Re: Can Integrate[expr,{x,a,b}] give an incorrect result? This is clearly a case of a misunderstanding, though I am not sure that I am at fault here. Note that I never try to reply to Craig's original posting and have not even read it carefully. I am simply not interested enough in the subject of definite integration and to tell the truth I can see little point in all the great effort that is being put into definite integration with symbolic limits (I do see a point to definite integration with numerical limits). Personally I would be quite happy if Mathematica returned all definite integrals with symbolic limits unevaluated. So, I only responded to Bobby's assertion that there was something wrong with Simplify or D. I then changed D to Integrate in my response, but even then I only asserted that Integrate is reliable in producing anti-derivatives in the algebraic sense (That is, functions g possibly with branch cuts etc in the complex plane such that D[g]=f for a given f). What I found provocative in your response is that you chose to respond to me rather than to Craig (or Daniel) although nothing in your response is related to any of the assertions that I made in mine. As for the algorithm that is implemented in another CAS, you do not make it clear what exactly it does. If you mean that it can deal with this particular case and with a few similar ones I do not doubt that it can. If, however, you are asserting that it can always find a continuous integrand on an interval whenever it can be proved that it least meant. Andrzej Kozlowski > [Message also posted to: comp.soft-sys.math.mathematica] >> So, from that, D and/or Simplify must be wrong. > Must they? Even without any investigation I would say that it is >> much more likely that this integral should not be evaluated by >> means of the Leibniz rule (substituting the limits into the >> anti-derivative and subtracting). > Of course, the Leibniz rule cannot be used unless one _has_ an > antiderivative valid on the required interval. Mathematica does not > supply such an antiderivative in this case. > This has been discussed many time before on this list (with your >> participation) but since you seem not to be satisfied, here it goes >> again, I hope for the last time. > Unless I've said something false, in which case I would much > appreciate being corrected, it's not clear to me why you took the > trouble to respond this time. >> However >> if the original function is not complex analytic in the complex >> plane then there will not be a complex analytic anti-derivative. >> Instead, there will be anti-derivatives with singularities, and >> in unlucky cases they may fall on the interval of integration. This >> is exactly what happens in this case. > Of course. >> In fact, it is easy to see what happens in your >> special case: > integrand = (r*(r - rho*Cos[alpha - t]))/ >> (3*(r^2 - 2*rho*Cos[alpha - t]*r + rho^2 + >> (z - zeta)^2)^3); >> int = integrand /. {r -> 1, rho -> 11/10, >> zeta -> 0, alpha -> 0, z -> 12/10} >> (1 - (11*Cos[t])/10)/(3*(73/20 - (11*Cos[t])/5)^3) > First, let us compute the integral using Integrate: > Integrate[int, {t, 0, 2*Pi}] >> (1772800*Pi)/(11512449*Sqrt[377]) > N[%] >> 0.0249156 > Now, let's do it by numerical integration: > NIntegrate[int, {t, 0, 2*Pi}] >> 0.024915592618816908 > so far, so good. Now let's compute the indefinte integral: > indef = Integrate[int, t]; > Using the Liebniz rule gives clearly the wrong answer: > indef = Integrate[int, t]; > but why should it give the right answer? > It _must_ give the right answer if indef is actually an > antiderivative on the interval 0 to 2Pi, but it isn't. > It depends on the meaning of anti-derivative. > The meaning of antiderivative in mathematics was well established > prior to the advent of symbolic algebra programs; their advent has not > changed that meaning. No mathematician I know would claim that indef > is an antiderivative on the interval 0 to 2Pi. >> In the meaning that Mathematica and all other symbolic algebra >> programs use, a function can be an an anti-derivative of another >> function, even if it is singular or undefined at certain points in >> the complex plane provided it is an anti-derivative at almost all >> points (i.e. a generic anti-derivative). It is of course completely >> natural for Mathematica to use such anti-derivatives since it is >> precisely this kind of anti-derivatives that are found by the Risch >> algorithm. >> The function indef is clearly discontinuous in the interval 0 to >> 2Pi > True, but that discontinuity is merely an artifact of Mathematica's > workings. The integrand int is clearly continuous on the interval 0 > to 2Pi and, indeed, on all of R, and so there is an antiderivative > on R: > 886400 Sqrt[377]/4340193273 (t - 2 ArcTan[44 Sin[t]/(44 Cos[t] - 3 > Sqrt[377] - 73)]) + 8800 Sin[t] (1078 Cos[t] - 8009)/(3837483 (44 > Cos[t] - 73)^2)) > but I don't know how to get Mathematica to produce it. Of course, > using my antiderivative above with Leibniz rule, we get the correct > result for the definite integral. >> Plot[indef, {t, 0, 2 Pi}] > so the Leibniz rule does not apply. There is no reason at all to >> suspect the very reliable function Simplify and almost as reliabel >> Interate. > There is very good reason to suspect that Integrate, when asked to > evaluate an indefinite integral, might give a result which is not > an antiderivative on some desired interval. This happens fairly > often, the subject of this thread being a case in point. > Mathematica does not even attempt to find anti-derivatives on R in >> your sense. Instead of bringing up time and again same points that >> are covered in undergraduate calculus course I suggest learning a >> little about symbolic algebraic integration. > Here are two good references: > Geddes, Czapor, Labhan Algorithms for Computer Algebra, Kluwer, >> 1992 >> Davenport J. On the Integration of Algebraic Functions, Springer- >> Verlag 1981. > If you read one of these you will find that the concept of anti- >> derivative that your are using is not considered suitable for >> computer algebra (at least at its present stage of development >> unless there have been some dramatic developments recently that I am >> not aware of ). > I'm using the concept of antiderivative as it is ordinarily used in > mathematics. >> So, you do not know how to obtain your answer with Mathematica >> because it can't be done. > Of course, it _could_ be done with Mathematica. I apologize. I > should have > said, more precisely, that I don't know how to get Mathematica to > produce > my antiderivative _easily_. (I would not call having to implement the > appropriate algorithm in Mathematica myself to be an easy way.) >> Symbolic algebra programs use known algebraic algorithms. There is >> no point demanding that they should do something unless a suitable >> general algorithm is known. >> Of course, it is possible that you know an algorithmic (in the same >> sense that the Risch algorithm is algorithmic) way of computing >> such anti-derivatives. If so, I am sure that Wolfram Research will >> be very keen to implement it. > I wouldn't be so sure. A suitable algorithm has been known for > years, and > it is implemented quite successfully in another CAS, the name of > which I > would mention, were we not forbidden to do so in this newgroup. >> But until then this is all there is to this entire issue. > then was some years ago. > ----------------------------------------------------- > Then, in his most recent response, >> I still feel sufficiently provoked by your post to write one more >> reply, > The only reason I can imagine that you would have been provoked by > my previous post is that you failed to understand something I had > said. I certainly had not intended to be provocative. >> just to make absolutely clear what the point of my first reply (to >> Bobby Treat) was, since it it appears to me that you have entirely >> missed it. > No. Rather, I entirely understood it. > So in view of the above I can't make any sense of you claim that >> Integrate should be doubted or is not reliable > There is very good reason to suspect that Integrate, when asked to > evaluate an indefinite integral, might give a result which is not an > antiderivative on some desired interval. This happens fairly often, > the > subject of this thread being a case in point. > Perhaps you overlooked the crucial phrase on some desired interval. >> unless what you >> actually meant was that using the anti-derivative returned by >> Integrate and the Newton-Leibniz formula is not reliable. This, >> post. Anyway, this whole belongs to the realm of definite and not >> indefinite integration. Daniel Lichtblau has already posteda reply >> to Bobby the same thread (have you looked at it?) > Not until you mentioned it. Several of the posts had had their title > changed to give an incorrect result? I had realized that and so had > already looked at them. But somehow, the title of Daniel's post got > further changed, to just give an, causing me to be unaware that he >> where he included a link >> to a paper of his which explains in detail the difficulties faced by >> definite integration in this kind of setting. > I see no link to, or even mention of, a paper in the post by Daniel in > this thread. Am I perhaps overlooking a second post by him here? >> Definite integration still makes use of the Risch algorithm (and >> hence of >> derivatives with possible singular points) but it does not simple >> mindedly use the Newton-Leibniz formula. In fact, with numerical >> limits >> it correctly deals with the integral posted by the OP. > No, it doesn't. Craig, the OP, said that > Integrate[integrand,{t,0,2Pi},Assumptions->assumptions] returns 0 > and Bobby later confirmed that. > That's a definite integral with numerical limits and Mathematica > obviously does not deal with it correctly. The second result I posted > evaluated that definite integral. > (Craig also mentioned use of NIntegrate. That was dealt with > correctly, > but of course NIntegrate is not what we're discussing here.) >> Of course if it could use a purely real formula like >> yours in the case when definite integrals over an interval are >> involved, things would become much simpler i9n this particualr case, > Right, much simpler. Indeed, the main reason that I posted in this > thread > originally is that I thought Craig might find my results to be useful, > despite the fact that I couldn't tell him how to get either of them > with > Mathematica, easily, at that time. But I now have an easy way to > obtain my > second result using Mathematica; see below. >> but this approach does not appear to be algorithmic enough to >> incorporate it into a general integration procedure. > Opinions may vary as to what is or is not algorithmic enough. Since > the approach has already been successfully implemented in another CAS, > I should think that it is algorithmic enough. > ----------------------------------------------------- > Concerning evaluation of the OP's definite integral in Mathematica, > version 5.2: > The integrand was originally given as > (r*(r - rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + (z - zeta)^2 - > 2*r*rho*Cos[alpha - t])^3) > I helped Mathematica by making two trivial replacements: > 1. (z - zeta)^2 by zz > and > 2. alpha - t by t (which is justified since the definite integral > is taken over exactly one cycle). > Then Mathematica has no trouble getting an answer equivalent to the > second result from my previous post. > In[8]:= > Assuming[r > 0 && rho > 0 && zz > 0, > Integrate[(r*(r - rho*Cos[t]))/ (3*(r^2 - 2*r*rho*Cos[t] + > rho^2 + zz)^3), {t, 0, 2 Pi}]] > Out[8]= > (2*Pi*r^2*(r^4 - 2*rho^4 - rho^2*zz + zz^2 + > r^2*(rho^2 + 2*zz)))/(3*(((r - rho)^2 + zz)* > ((r + rho)^2 + zz))^(5/2)) > Unless I've missed something, it seems that _both_ of my simplifying > replacements are needed if Mathematica is to get a correct result > for the > definite integral. > My second replacement is useful because Mathematica does not seem > to be > aware of the fact that the original integral must be independent of > alpha. > The result, 0, below is incorrect. > In[9]:= > Assuming[r > 0 && rho > 0 && zz > 0 && alpha > 0, > Integrate[(r*(r - rho*Cos[alpha - t]))/ (3*(r^2 - 2*r*rho*Cos[alpha > - t] > + rho^2 + zz)^3), {t, 0, 2 Pi}]] > Out[9]= > If[alpha >= 3*Pi || alpha == Pi, 0, > Integrate[(r*(r - rho*Cos[alpha - t]))/(3*(r^2 + rho^2 + zz - > 2*r*rho*Cos[alpha - t])^3), {t, 0, 2*Pi}, Assumptions -> alpha < 3*Pi && Pi != alpha]] > I'm not sure why the first replacement is useful. But without it, > Mathematica produces a different sort of incorrect result for the > definite > integral. Being huge, I will not show the result here, but any > masochist > wishing to duplicate it (perhaps only possible in version 5.2?) can > use > Assuming[r > 0 && rho > 0 && z > zeta, > Integrate[(r*(r - rho*Cos[t]))/ (3*(r^2 - 2*r*rho*Cos[t] + > rho^2 + (z - zeta)^2)^3), {t, 0, 2 Pi}]] > David W. Cantrell === Subject: Re: A riddle: Functions that return unevaluated when they cannot Sin[x] does not evaluate because x is undefined. f[q_?NumberQ]:= q^2 gives with f[x]: f[x] and with f[2.718] 7.38752. Of course, again and again: Clear[f] But, with f[(n_?Positive)?IntegerQ]:=n! f[n_]:= Print[f expects a positive integer argument] Try f[2.4] It is the way some functions are implemented that they do not a should evaluate. with friendly greetings, P_ter === Subject: Re: Satellite Visualization! Andery, I did an extended notebook on this topic ending up with an animation of the earth and a satellite (I called it RSS, Rational Solar Satellite, because it revolves exactly twice for every three orbits of the earth and thus the animation can run smoothly forever.) However, it happens that this is an extended example in my DrawGraphics package, which I sell for $50, from my web site. You may not be interested because of that. The notebook is actually titled 'Mathematica Notebooks as Pedagogical Documents: Derivations of the area swept out by a focal angle in an ellipse' and the abstract is: This notebook presents an example of the Mathematica style for tutorial and student essay notebooks that I advocate. It uses a structured notebook with textual discussion integrated with derivations, calculations and graphics, active calculation of everything and the generation of embedded knowledge. The notebook treats the derivation of an expression for the swept area in an ellipse as a function of focal angle. This result was first presented on the Internet by David W. Cantrell. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hi all, > I have been trying to visualize an artificial satellite moving in its > orbit around the Earth, but I could not success. > I have manly used the command Animate and tried to represent the > orbit as a circle and the satellite as a point moving on that circle. > But I feel the result was so basic while I am looking for something > much professional and I am sure this animation can be achieved by > Mathematica, especially with the new version of it. > My aim is to have an animation for this satellite where I have the > equations of its motion > and the radius (the distance between the satellite and the Earth). > Any help on this would so appreciated, > Andery > === Subject: Re: DSolving(?) for a given tangent Sir, for some reason this does not work on my XP machine using V6. I get the correct answer if I use In[3]:= {x, f[x]} /. First[Quiet[Solve[D[f[x], x] == 1.0, x]]] This gives {6.8824, 4.54545} for output. I'm guessing your Degree is different from mine which is 0.0174533. >> Don't know for sure if this is the right function, so here's the scenario: > f[x_] := E^(0.22 x); >> Plot[f[x], {x, 6, 36}] > Which plots a nice escalating curve. > What I would like to know is: Where is the point {x,f[x]} that has a >> 45-degree tangent line; ie where is this curve's balance point before it >> really starts taking off? In[2]:= f[x_] := E^(0.22*x); > In[3]:= {x, f[x]} /. First[Quiet[Solve[D[f[x], x] == 45*Degree, x]]] Out[3]= {6.882398784680798, 4.545454545454546} Quiet suppresses the warning message: > Solve::ifun:Inverse functions are being > used by Solve, so some solutions may not be found; use Reduce for > complete solution information. >This verifies the result > In[4]:= D[f[x], x]/Degree /. First[Quiet[Solve[D[f[x], x] == > 45*Degree, x]]] Out[4]= 45. Adriano Pascoletti === Subject: mathematica 6.0 for linux crashes when manipulating plots of the tutorial the tutorial, I noticed it ALWAYS crashes when doing the 4th step (Make it dynamic...). When running from terminal, the following appears: Mathematica has received the signal: SIGSEGV and has exited. If possible, please report this problem to support@wolfram.com describing in as much detail as possible what you were doing when the problem occurred. Segmentation fault (core dumped) Does anyone have a hint of how to fix it?