1696 === Subject: Re: Partitioned matrix operations you may symbolically invert your matrix: Inverse[M] giving: {{0, 1/C}, {1/B, -(A/(B C))}} Now it is up to you to ensure that C,B and B C are invertible. Daniel > Here's a Mathematica newbie question. Say I have a matrix, M, defined as, M = {{A, B}, {C, 0}} where A is nxn, B is nxm, C is mxn, and the zero sum matrix is mxm. I would > like to perform an operation on the matrix M without fully defining A, B, > and C and get a result in terms of A, B, and C. For example, if I wanted to > determine the matrix inverse of M in terms of A, B, and C. Is this possible in Mathematica? I've unfortunately not found anything in > the docs that indicates that this is possible. Thx. === Subject: Re: Problem with GraphicsColumn Use the ImagePadding option and make it the same in both plots, or at least the horizontal portion. You will need enough padding on the left to accommodate the longer y tick values in the top plot and that will leave extra space on the left in the bottom plot. But that is what is necessary for alignment of the two plots. GraphicsColumn[ {Plot[10^4 Sin@x, {x, 0, 10}, Frame -> True, ImagePadding -> {{40, 5}, {30, 10}}], Plot[Cos@x, {x, 0, 10}, Frame -> True, ImagePadding -> {{40, 5}, {30, 10}}]}] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Actually, the two figures I drew are the same x-axis range but different y-axis range like: GraphicsColumn[{Plot[10^4 Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}] Because of the length of the number of y-axis label in Plot@Sin is longer than Plot@Cos, the figure moves to right hand side. If I want to solve this, I have to add some items like the first and the second cases above. However more problems are encountered. === Subject: problem with Sum Hi mathematica community, I have this input: Sum[a[k], {k, 1, j}] - Sum[a[k], {k, 1, i+j-n}] How it is possible to let mathematica gives as output: Sum[a[k], {k, i+j-n+1, j}] if i+j-nj thank you very much. === Subject: Re: Looking for a Column,Row, and Grid interactive Lab Find it in the usual sort of way to find such documentation: In the Documentation Center, search for Grid. At the bottom of the reference page about Grid, you'll find a Tutorials section. Go to the tutorial Grids, Rows, and Columns in Mathematica. Like all the tutorial and other pages of the Documentation Center, this is a notebook, so it's fully interactive: you can change and reevaluate any Input cell there (without altering the permanent copy of the notebook. In learning Column, Row, and Grid, I am seeking an interactive guide > to study those features of Mathematica. Even a partial one would do to Andrew > -- 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: Slow/jerky animations inside manipulate (more details) As several people have kindly pointed out, my first post was a bit too vague (my first time with Mathgroup). I am adding more specific ------Original post: Slow/jerky animations inside manipulate --------- I have an Animate command (I'm using GraphicsRow to show two side-by-side synchronized animations) inside of Manipulate. The resulting animations play very fast and are jerky. I can adjust the play speed using AnimationRate, but it must be slowed down by a ridiculous amount in order to look smooth. I've tried adjusting the RefreshRate, as wellas making time a slider variable and animating from within the Manipulate control panel,both with little success. How can I create smooth animations, appropriate for class demonstrations? ------------------------------------------------------------------------- -----Additional Comments------------------------------------------------- My plots are actually simple. I am, however, solving an ODE inside of the Manipulate/Animate commands. I've played around with the NDSolve options thinking it might make things faster, but again no success. Basically I just want two sliders to choose initial conditions for the ODEs, then animate the results. Inside Manipulate, I solve the following ODEs, where the initial conditions q0,p0 are the slider variables: sols = First@NDSolve[{q'[t] == p[t], p'[t] == 2 A De (Exp[-2 A (q[t] - xe)] - Exp[-A (q[t] - xe)]), q[0] == q0, p[0] == p0}, {q, p}, {t,0, 100}]; Inside Animate, I have two plots (tp is the animation variable): 1. Plot solution q(tp) vs. tp, as well as a circle that moves along as the curve is being traced out: p1 = Graphics[{ Point[{tp, Evaluate[q[tp] /. sols]}]}]; p2 = Quiet@Plot[Evaluate[q[T1] /. sols], {T1, 0, tp}, PerformanceGoal->Speed]; FIRSTplot = Show[p1, p2]; 2. Plot a static background curve Staticplot (computed outside Animate), with a circle moving on it. The equation for the background curve is: f(q)=De(1+Exp[-2 A (q-xe)]-2 Exp[-A (q-xe)]) The coordinates for Point below are {q,f(q)}. p7 = Graphics[{Point[{Evaluate[q[tp] /. sols], De (1 + Exp[-2 A (Evaluate[q[tp] /. sols] - xe)] - 2 Exp[-A (Evaluate[q[tp] /. sols] - xe)]) }] }]; SECONDplot=Show[Staticplot,p7]; ------------------------------------------------------------------------- === Subject: Re: Parallelize and Symbolic computation > Hi All, I apologies if this is an idiotic question. Essentially, I've a complex > Taylor series expansion that keeps running out of memory and as I've > upgraded to Mathematica 7 of late, and we've a few machines idling away, I > was wondering if the parallel stuff could help. The documentation for Parallel Tools hints that it's only applicable for > numeric problems, but doesn't state that symbolic is out of the question. At a recent Mathematica demo I went to recently it was suggested that the > parallel architecture didn't exclude all symbolic calculations. Has anyone > seen any documentation on this? Or have any experience of it? > JHatt The parallelize mechanism in 7, works by starting extra kernels, that can each do any calculation they want, but I can't quite see how that will help you with your calculation. It might be an idea to post the problem, because if there is a way round your difficulty, someone here will suggest it! Memory problems can be greatly eased by moving to a 64-bit architecture. Many modern computers are already 64-bit capable, and in that case, all that is needed is to change to a 64-bit operating system and re-install Mathematica. However, I'd start by posting your actual problem if possible. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Parallelize and Symbolic computation a) you will probably need more memory with parallel execution b) no it work for any algorithm, but you should have a problem with few input data, few output data and a huge number of operations on it c) with computers you have in many cases the choice speed xor memory. Since parallel computing is for speed, you need probably more memory Jens > Hi All, I apologies if this is an idiotic question. Essentially, I've a complex > Taylor series expansion that keeps running out of memory and as I've > upgraded to Mathematica 7 of late, and we've a few machines idling away, I > was wondering if the parallel stuff could help. The documentation for Parallel Tools hints that it's only applicable for > numeric problems, but doesn't state that symbolic is out of the question. At a recent Mathematica demo I went to recently it was suggested that the > parallel architecture didn't exclude all symbolic calculations. Has anyone > seen any documentation on this? Or have any experience of it? === Subject: Re: Polygon Union I need to make a couple of corrections to my post from yesterday. >> I've also been thinking about this problem. I use the continental maps >> that are available through CountryData[], and I'd rather have a continent >> without an internal political boundaries shown. I've been surprised that >> this possibility is not a built-in option. See last remark below. I meant was the stuff beginning with For the case of internal boundaries. >>> I am looking for a Mathematica function which generates the union of >>> two (not necessarily convex) polygons. I found a package on the web >>> (the Imtek library, I believe) which includes a convex polygon >>> intersection function, but not a polygon *union* function. Does >>> anyone know if such a function is available or, if not, can anyone >>> suggest an algorithm to implement in Mathematica? >>> David Skulsky Consider a pair of polygons p1 and p2. For the case where boundaries > might transversally intersect, a reasonable tactic is to iterate over > vertices of p2 to see which lie in p1, and vice versa. Then look at > neighbors of such points (that are not themselves inside one and > bounding the other) to find intersecting segments. This will allow to > recast as one polygon. Reasonably efficient code for doing the inside/ > outside tests can be found in the MathGroup archives: http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00519.html For the case of internal boundaries, you can look for segments that > get repeated. This should usually work, unless you have, say, Ohio and > Kentucky both claiming a river right up to the land boundary on the > other state's side (in that case, instead of looking for segments you > might look for militias. Actually you can treat this as the > transversal intersection case.) A related issue is when you try to merge polygons that have common > boundaries, but vertices disagree due to small numeric error. In such > cases it is useful to do comparisons at precision lower than that used > in specifying the boundary vertices. Daniel Lichtblau > Wolfram Research The handling of transversal intersections is not in general correct. If we have a pair of neighboring points of p2, say, that both lie in p1, that does not mean the entire connecting segment lies inside p1. If you are dealing with country boundaries, where individual segments tend to be small, this will usually be the case, but for general nonconvex polygons it does not necessarily hold. Likewise for neighbors of p2 that both lie outside p1: their connecting segment might still intersect the boundary of p1. And of course if the edge between a pair of neighbors in p2 crosses the p1 boundary, it might be in multiple places. I do not know what is regarded as best prectice for handling this. An approach that strikes me as sensible is related to the inside/outside test (URL above) from February. It should work reasonably well if individual segments are small relative to dimensions of the polygons (as is usually the case with, say, map boundaries. And if this property does not hold, one can subdivide segments so it will.) Anyway, the idea is simply to bin segments in p1 by endpoints, in such a way that it is easy to locate all possible p1 segments crossed by any given edge in p2. Then test each possible crossing. The reason for binning is of course to avoid having to test every p1 segment against every p2 segment. If there are m vertices in p1 and n in p2, then the complexity of the preprocessing is O(m+n), and if we assume all bins have a small number of segments, the processing complexity is also O(m+n). For reasonable polygons (ones that do not require substantial refinement to make edges small), this should be in the ballpark of optimal. That is, there might be methods that are t times faster, but such that t increases with vertex counts. Daniel Lichtblau Wolfram Research === Subject: AnimationDirection when Exporting Suppose I want to export an animation (using Animate or Manipulate) so that the exported animation runs once in the forward direction and stops. Here's a little example, of a circle moving from left to right along the anim = Animate[ ParametricPlot[{Cos[t] + k, Sin[t]}, {t, 0, 2 Pi}, PlotRange -> 10], {k, -12, 12}] Export[anim.avi,anim] In the resulting AVI, the circle moves from left to right (the desired Forward direction), and then it runs Backward, from right to left. One would think that setting AnimationDirection->Forward would fix this. So try exporting this: Animate[ ParametricPlot[{Cos[t] + k, Sin[t]}, {t, 0, 2 Pi}, PlotRange -> 10], {k, -12, 12},AnimationDirection -> Forward] It still runs once Forward, then once Backward. I've also tried specifying the direction within Export. Export[anim.avi,anim,AnimationDirection -> Forward] Still no joy. Is there any way to get the exported animation to run once in the Forward direction only? This has been a nagging issue for me for quite some time. -- Helen Read University of Vermont === Subject: perturbation methods example from stephen lynch's book? Hello group, This message is a bit long. I was reading Stephen Lynch's dynamical systems with applications using mathematica and noticed he's using asymptotics and perturbation methods in chapter 4, section 4 perturbation methods. Except he's only showing the code for linstedt-poincare methods which fails for the example given in the book. (van der pol equation) (*See Example 8:The Lindstedt-Poincare technique.*) SetAttributes[{w1, epsilon}, Constant] x = x0 + epsilon*x1 + epsilon=882*x2; Collect[(1 + 2 epsilon w1 + epsilon=882 (w1=882 + 2 w2)) Dt[x, {t, 2}] + x - epsilon x=883, epsilon]; (*The O (1) equation.*) DSolve[{x0''[t] + x0[t] == 0, x0[0] == 1, x0'[0] == 0}, x0[t], t] (*The O (epsilon) equation.*) DSolve[{x1''[t] + x1[t] == Cos[t] =883 + 2 w1 Cos[t], x1[0] == 0, x1'[0] == 0}, x1[t], t]; Simplify[%] He then discusses method of multiple scales to approximate the solutions to van der pol equation (x'' + x = epsilon (1 - x^2) x', given x=a, and x'=0) I was wondering if anyone worked out that example. (example 10 in chapter 4). If so, can someone kindly share the codes for it? ie. 1. solution to PDEs, O(1) and O(epsilon), that results from changing the time scales, 2. using TrigReduce to simplify, 3. remove the secular terms, 4. impose ICs and approximate the one term O(epsilon) solution, x_ms I might be asking a lot, but I was hoping someone has the codes for it. === Subject: Re: Slow/jerky animations inside manipulate What is the nature of your two plots? They must be 3D plots with a lot of detail. 1) You could use the PerformanceGoal -> Speed option to speed up the rendering while the slider is being moved. 2) You could try to simplify your plots. Note that the way to obtain adequate detail is to use the MaxRecursion option and NOT increase the PlotPoints. You may even be able to decrease the PlotPoints. To speed things up you could use Mesh -> None, and don't use Opacity. 3) You could pre-compute a set of displays, display[i] 1 <= I <= n, and then display them in a sequence with the slider. If most of the elements in the plots are fixed you could pre-compute them. 4) Make certain you have the same PlotRange in all plots in the animation, i.e., specify it explicitly. Letting Mathematica automatically determine the PlotRange for each frame is the principal cause of jerkiness. 5) In some situations, because of the slowness, straight animation just might not be the best solution to a presentation. You might be able to use multiple plots and a much simplified animation that abstracts the relevant change. Not every topic can be adequately or easily presented in a single display. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I am using Mathematica v. 6.0.2.1. I have an Animate command (I'm using GraphicsRow to show two side-by-side synchronized animations) inside of Manipulate. The resulting animations play very fast and are jerky. I can adjust the play speed using AnimationRate, but it must be slowed down by a ridiculous amount in order to look smooth. I've tried adjusting the RefreshRate, as well as making time a slider variable and animating from within the Manipulate control panel, both with little success. How can I create smooth animations, appropriate for class demonstrations? === Subject: Re: Slow/jerky animations inside manipulate I am using Mathematica v. 6.0.2.1. I have an Animate command (I'm using GraphicsRow to show two > side-by-side synchronized animations) inside of Manipulate. The > resulting animations play very fast and are jerky. I can adjust the > play speed using AnimationRate, but it must be slowed down by a > ridiculous amount in order to look smooth. I've tried adjusting the > RefreshRate, as well as making time a slider variable and animating > from within the Manipulate control panel, both with little success. How can I create smooth animations, appropriate for class demonstrations? > PerformanceGoal->Quality (which is an option for the various plotting functions) -- Helen Read University of Vermont === Subject: Re: Slow/jerky animations inside manipulate I am using Mathematica v. 6.0.2.1. I have an Animate command (I'm using GraphicsRow to show two > side-by-side synchronized animations) inside of Manipulate. The > resulting animations play very fast and are jerky. I can adjust the > play speed using AnimationRate, but it must be slowed down by a > ridiculous amount in order to look smooth. I've tried adjusting the > RefreshRate, as well as making time a slider variable and animating > from within the Manipulate control panel, both with little success. How can I create smooth animations, appropriate for class demonstrations? > You shouldn't be focusing on Animate[] as the source of the problem. It almost certainly isn't. Animate[] can only refresh as quickly as it can compute its contents. Since you didn't include the graphics being computed, it's impossible for anyone here to make targeted, useful comments about how to speed things up. But here are a few generic ideas... * See if anything can be precomputed outside of the animation. If the animation is a looping animation, you wish to pre-compute each and every frame of the loop, and use ListAnimate to animate the results (the downside is that this will probably create a very large notebook file). Or you might be able to get some benefit from implementing memoization in the function being plotted (look up memoization in the documentation for more information). Or there may be other steps which you can pull out of the Animate to front load more of the computation. * Try some of the standard methods for speeding up graphics visualization. Reduce PlotPoints and MaxRecursion. Remove uses of transparency. * Examine the code for any algorithms which can be rewritten to be more efficient. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. === Subject: Graphics3D not visible under X11 (was: Compositing, 3D graphics, and KDE 4.2) >> I have version 7.0.0 running on a 32-bit linux system, in KDE 4.2 >> (radeonhd driver). Now, most of the stuff is esoteric, and I'm quite >> happy to have gotten everything running fast and stably and prettily, >> including Mathematica looking great. However, I've just noticed today >> that if I produce any 3D graphics (using Plot3D, or >> Graphics3D[Cylinder[{{0, 0, 0}, {0, 1, 0}}]], for example) that the 3D >> object shows up only if I'm actively rotating it or resizing it with >> the mouse. Otherwise, it disappears and looks like just a big blank >> space on the screen. I might try updating to 7.0.2 just in case that >> fixes things. >> I have tested this on 64bit KDE 4.2.2 with kwin compositing and Mathematica >> 7.0.1 on two different machines, one using the proprietary Nvidia drivers, >> the other the Intel graphics drivers. In either case, 3D graphs worked >> without actively manipulating them. >> Therefore this might be an issue with you ATI drivers. I have no idea >> whether this will help, but you might try different drivers, e.g. the >> proprietary ATI driver (Catalyst 9.4 for Linux has been released recently, >> IIRC). I have the same issue with the intel driver, no matter if compiz is > enabled or not. So it seems that this problem is not specific to the > ATI driver. Richard, were you able to find a solution to this? For me, adding Option AccelMethod uxa to /etc/X11/xorg.conf (Device section) fixed the problem. Best, -Nikolaus -- =C2=BBTime flies like an arrow, fruit flies like a Banana.=C2=AB PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: Re: perturbation methods example from stephen lynch's book? I just realized that the codes I posted isn't complete. Not sure what Lynch is doing in his notebook, but his Collect[] line doesn't seem to work. It's probably because he's using Dt[x, {t, 2}] on just x not x[t] epsilon=epsilon; SetAttributes[{w1,epsilon},Constant] x=x0+epsilon*x1+epsilon^2*x2; Collect[(1+2 epsilon w1+epsilon^2 (w1^2+2 w2))Dt[x,{t,2}]+x-epsilon x^3,epsilon] DSolve[{x0''[t]+x0[t]==0,x0[0]==1,x0'[0]==0},x0[t],t] DSolve[{x1''[t]+x1[t]==Cos[t]^3+2 w1 Cos[t],x1[0]==0,x1'[0]==0},x1[t],t] Simplify[%] === > Subject: perturbation methods example from stephen lynch's book? > Hello group, This message is a it long. I was reading Stephen Lynch's dynamical systems with > applications > using mathematica and noticed he's using asymptotics and > perturbation > methods in chapter 4, section 4 perturbation methods. Except he's only showing the code for linstedt-poincare > methods which > fails for the example given in the book. (van der pol > equation) (*See Example 8:The Lindstedt-Poincare technique.*) > SetAttributes[{w1, epsilon}, Constant] x = x0 + epsilon*x1 + epsilonèº2*x2; Collect[(1 + 2 epsilon w1 + epsilonèº2 (w1èº2 + 2 w2)) > Dt[x, {t, 2}] + x > - epsilon xèº3, epsilon]; (*The O (1) equation.*) > DSolve[{x0''[t] + x0[t] == 0, x0[0] == 1, x0'[0] == 0}, > x0[t], t] (*The O (epsilon) equation.*) > DSolve[{x1''[t] + x1[t] == Cos[t] èº3 + 2 w1 Cos[t], x1[0] > == 0, x1'[0] > == 0}, x1[t], t]; > Simplify[%] He then discusses method of multiple scales to approximate > the > solutions to van der pol equation (x'' + x =åÊ epsilon > (1 - x^2) x', > given x=a, and x'=0) I was wondering if anyone worked out that example. (example > 10 in > chapter 4). If so, can someone kindly share the codes for > it? > ie. > 1. solution to PDEs, O(1) and O(epsilon), that results from > changing > the time scales, > 2. using TrigReduce to simplify, > 3. remove the secular terms, > 4. impose ICs and approximate the one term O(epsilon) > solution, x_ms I might be asking a lot, but I was hoping someone has the > codes for > it. > Sean === Subject: ListDensityPlot how to define colors for specific range of values can i define specific color for specific range of values? is there any way to define this in Mathamatica? your comments are highly appreciated . prageeth -- Software Engineer, Axiohelix Co, Okinawa Industry Support Center 1831-1 Oroku, Naha-shi, Okinawa, 901-0152 Japan. === Subject: Re: directionfields from StreamPlot Just to clarify slightly more, if you purchase the package you can download both versions, and if you are working in Mathematica 5 or earlier you could download the earlier DrawGraphics version and when you update to Mathematica 7 you could freely download the Presentations version. And also, so far at least, I have been giving free updates. The latest update was in 19 May 2009. Sometimes purchasers change their email address and if you didn't receive a notice please contact me. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Just to clarify, Presentations isn't a second package; it is the up-to-date DrawGraphics. You wouldn't need to buy both. Bobby > At the end of your message (below), you ask about visualizing Poincare > maps. I recommend you look at Gianluca Gorni's notebook PoincareMaps.nb > (which includes the code for a corresponding package). There's a version > for old versions of Mathematica at Gorni's web site: http://sole.dimi.uniud.it/~gianluca.gorni/ I've done much of the revision of that notebook so that it will work > with Mathematica 7, but there's still some work to do about which I've > written directly to Prof. Gorni. If you're interested, I can send you a > copy of what I have so far. However, to run Gorni's functions, you'll also need a copy of David > Park's non-free but marvelous and useful Presentations package, which > handles much of the underlying graphics. You can obtain the package > from Park's site: http://home.comcast.net/~djmpark/DrawGraphicsPage.html The posted copy of Gorni's package uses Park's older DrawGraphics > package, which like Presentations is not free and is available from the > same site of David's. > k1 and k2 are pseudo first order reaction rate constants. It can range >> from 10^-3 to 10^7 or so. (for diffusion limited process) h range >> from 0 to 1. >> The [original] system ...is kinda simplified... The system below >> behaves a bit >> more interestingly. (Let's say...k1=3, k2=7, t=50 and then...) >> Manipulate[ >> StreamPlot[{va - k1 (t^-h) a - k2 ( t^-h ) b, k1 (t^-h ) a - db}, >> {a, -10, 10}, {b, -10, 10}], {k1, 0.01,10}, {k2, 0.01, 10}, {t, 0.1, >> 50}, {h, 0, 1}, {va, 0.1, 10}, {db, 0.1, 10}] >> As you vary va, db, and h, you will see the center of stable attractor >> shifts. >> This is entirely a different post, but if I wanted to see a poincare >> section of that system, will that be doable in mathematica? Seems >> Like Stephen Lynch's book uses 3 different CAs to generate the >> figures. And Mathematica version doesn't have the codes for poincare >> section shown in fig 8.11 b.... > -- DrMajorBob@bigfoot.com === Subject: Re: directionfields from StreamPlot looks Correction. I just realized that Lynch does have the codes for doing the Poincare section. It's in the notebook on Mathematica website under his book page. (no method of multiple scales though.) > question. That system was a simpler version other systems I was > working on. What you're doing with Manipulate[] is more or less what I've been > doing except I wasn't sure if I was doing it right or not. (And as > seen with the previous example I gave, I was getting confused about > StreamPlot in general) I was taking the RHS of the two ODEs and using the StreamPlot to get > an idea of what the solutions look like. Not much unlike plotting > solutions in phase space (is that acceptable? based on your post, it > seems like it is...) Except now the trajectories in that space represent the a' and b' > instead of a and b as the normal phase portraits should be(?) Is this ok? (Does this give an hint as to the actual solutions of the > system?) k1 and k2 are pseudo first order reaction rate constants. It can range > from 10^-3 to 10^7 or so. (for diffusion limited process) h range > from 0 to 1. The system above is kinda simplified... The system below behaves a bit > more interestingly. (Let's say...k1=3, k2=7, t=50 and then...) Manipulate[ > StreamPlot[{va - k1 (t^-h) a - k2 ( t^-h ) b, k1 (t^-h ) a - db}, > {a, -10, 10}, {b, -10, 10}], {k1, 0.01,10}, {k2, 0.01, 10}, {t, 0.1, > 50}, {h, 0, 1}, {va, 0.1, 10}, {db, 0.1, 10}] As you vary va, db, and h, you will see the center of stable attractor > shifts. This is entirely a different post, but if I wanted to see a poincare > section of that system, will that be doable in mathematica? Seems > Like Stephen Lynch's book uses 3 different CAs to generate the > figures. And Mathematica version doesn't have the codes for poincare > section shown in fig 8.11 b. I'll probably start another post about it. Sometime this week... > What are k1, k2, and h? Once you have fixed values for those, then you have a non-autonomous > system of two first order differential equations. So you're asking h= er= > e > about a time-dependent vector field in the (a,b)-plane: F[t_, a_, b_] := {-k1 t^-h a - k2 t^-h b, k1 t^-h a} Actually, this is not defined at time t=0. There are (at least) two methods for visualizing that. Method 1: For particular individual values of t, form an ordinary 2D > StreamPlot or VectorPlot. Here, let's take: k1=10;k2=2;h=1; And the time-dependent vector field will be given by: F[t_,a_,b_]={-k1 t^-h a-k2 t^-h b,k1 t^-h a}; Then form a grid of snapshots of the vector field at different times: Grid[Partition[ > Table[ > StreamPlot[F[t,a,b], {a,-10,10}, {b,-10,10}], {t, 0.1, 2= 4,= > 2}], > 4]] Or, better yet, use Manipulate so that you can dynamically change the > time and hence the value of the field: Manipulate[ > StreamPlot[F[t, a, b], {a, -10, 10}, {b, -10, 10}], > {t, 0.1, 24, 2}] For the values of k1, k2, and h I picked, and on the {a,b} domain and > the t range, there does not seem to be much change in the field. Method 2: Represent the time-varying field F as a function on {t,a,b} > space. Then you could do something like: G[t_, a_, b_] = Flatten[{1, F[t, a, b]}] VectorPlot3D[G[t, a, b], {t, 0.1, 24}, {a, -10, 10}, {b, -10, 10= }] Hi Murray, > How would you use StreamPlot for the following system? a'[t] == - k1 (t ^-h) a[t] - k2 (t ^-h) b[t], > b'[t] == k1 (t ^-h) a[t] === >> Subject: Re: directionfields from StreamPlot looks different f= > rom solution >> You're not. For the direction >> field of a 1-dimensional ordinary differential equation y' >> == f[t, y], the vector field you want to plot is {1, >> f[t,y]}. So... > streams = >> StreamPlot[{1, t^2 - y}, {t, -4, 4}, {y, -2, 10}, >> StreamStyle -> Directive[Orange]]; >> sol = Table[NDSolve[{y'[t] == t^2 - y[t], y[0] == >> y0}, y[t], >> {t, -4, 4}], >> {y0, 0, 6, 0.5}]; >> solutionCurves = >> Plot[y[t] /. sol, {t, -4, 4}, >> PlotRange -> {{-4, 4}, {-2, 10}}]; >> Show[{solutionCurves, streams} > Note that you do not need any parentheses around t^2. And >> in the current version of Mathematica, you no longer need to >> wrap y[t]/.sol with Evaluate -- unless you would like the >> curves automatically to be given different colors. > sean_inc...@yahoo.com >>> I don't think I'm using StreamPlot properly. >> Consider the following non-autonomous ODE >> y'[t] == (t^2) - y[t] >> Solutions for various ICs can be viewed by the >> following. >>> sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == >> y0}, y[t], {t, -4, >>> 4}], {y0, 0, 6, 0.5}]; >> Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange >> -> {{-4, 4}, {-2, >>> 10}}] >> Shouldn't Vector fields be similar to the solutions >> above? If I plot t >>> on x-axis vs. t^2-y on y axis... >> VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] >> StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] >> I don't get similar results... >> What is the reason for this? >>> Sean > -- Murray Eisenberg >> mur...@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 >> =0A=0A=0A -- > Murray Eisenberg mur...@math.um= as= > s.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: Generic nested menus implementation Hi all, since already two people asked for this feature, and I got interested myself, I assume that this topic may be of general interest, and this is my reason to start a separate thread. Here I present my first attempt at generic multilevel menu implementation. The code is probably full of bugs, and also perhaps many parts could be done easier but I just did not figure it out, so I will appreciate any feedback. The examples of use follow. THE CODE ---------------------------------------------------------------------------- ------------------------------------------- (* checking recursive pattern *) Clear[menuTreeValidQ]; menuTreeValidQ[{_String, {___String}}] := True; menuTreeValidQ[item_] := MatchQ[item, {_String, {___?menuTreeValidQ} ..}]; (* This can probably be done much better *) Clear[localMaxPositions]; localMaxPositions[ls_List] := Module[{n = 0, pos, part}, pos = Position[part = Split[Partition[ls, 3, 1], Last[#1] == First[#2] &], x_ /; MatchQ[x, {{s_, t_, u_}} /; s <= t && u <= t] || MatchQ[x, {{s_, t_, _}, ___, {_, u_, p_}} /; s <= t && u >= p]]; List /@ Flatten[Fold[ Function[{plist, num}, n++; Join[plist[[1 ;; n - 1]], Range[plist[[n]], plist[[n]] + num - 1], plist[[n + 1 ;;]] + num - 1]], pos, Length /@ Extract[part, pos]] + 1]]; (* By leaves I here mean, for every branch, those with locally largest distance from the stem. Level would not do *) Clear[leafPositions]; leafPositions[tree_] := Extract[#, localMaxPositions[Length /@ #]] &@ Reap[MapIndexed[Sow[#2] &, tree , Infinity]][[2, 1]]; Clear[mapOnLeaves]; mapOnLeaves[f_, tree_] := MapAt[f, tree, leafPositions[tree]]; Clear[replaceByEvaluated]; replaceByEvaluated[expr_, patt_] := With[{pos = Position[expr, patt]}, With[{newpos = Split[Sort[pos, Length[#1] > Length[#2] &], Length[#1] == Length[#2] &]}, Fold[ReplacePart[#1, Extract[#1, #2], #2, List /@ Range[Length[#2]]] &, expr, newpos]]]; (* converts initial string-based menu tree into more complex expression suitable for menu construction *) Clear[menuItemsConvertAlt]; menuItemsConvertAlt[menuitemTree_, menuMakers : {(_Symbol | _Function) ..}, actionF_, representF_: (# &), representLeavesF_: (# &)] := Module[{g, actionAdded, interm, maxdepth, actF}, actionAdded = &, menuitemTree]; interm = MapIndexed[ Replace[#, {x_String, y : ({({_RuleDelayed} | _RuleDelayed) ..})} :> representF[x, {Length[#2]/2}] :> g[Length[#2]/2][x, Flatten@y], 1] &, {actionAdded}, Infinity]; interm = Fold[replaceByEvaluated, interm, {_Replace, HoldPattern[# &[__]], HoldPattern[Length[{___}]], HoldPattern[Times[_Integer, Power[_Integer, -1]]], _Flatten}][[1, 2]]; maxdepth = Max[Cases[interm, g[x_] :> x, Infinity, Heads -> True]]; With[{fns = menuMakers}, replaceByEvaluated[interm /. g[n_Integer] :> menuMakers[[n]], HoldPattern[fns[[_Integer]]]] /. actF :> actionF ] /; maxdepth <= Length[menuMakers]] (* main menu-building function *) Clear[createNestedMenu]; createNestedMenu::invld = The supplied menu tree structure is not valid; createNestedMenu[menuItemTree_, ___] /; Not[menuTreeValidQ[menuItemTree]] := never happens /; Message[createNestedMenu::invld]; createNestedMenu[menuItemTree_?menuTreeValidQ, menuCategories_, actionF_, representF_: (# &), representLeavesF_: (# &)] := Module[ {menuVars, menuNames, menuDepth = Depth[Last@menuItemTree]/2, setHeld, setDelayedHeld, heldPart, subBack, subBackAll, makeSubmenu, addSpaces, menuCategs = menuCategories, standardCategory = Choose }, Options[makeSubmenu] = {Appearance -> Button, FieldSize -> {{1, 8}, {1, 4}}, Background -> Lighter[Yellow, 0.8], BaseStyle -> {FontFamily -> Helvetica, FontColor -> Brown, FontWeight -> Plain}}; menuCategs = PadRight[menuCategs, menuDepth + 1, standardCategory]; (* Make variables to store menu names and values *) Block[{var, name}, {menuVars, menuNames} = Apply[ Hold, Evaluate[Table[Unique[#], {menuDepth}]]] & /@ {var, name}]; (* Functions to set/extract held variables *) setHeld[Hold[var_], rhs_] := var = rhs; setDelayedHeld[Hold[var_], rhs_] := var := rhs; heldPart[seq_Hold, n_] := First[Extract[seq, {{n}}, Hold]]; (* Functions to close the given menu/submenus*) subBack[depth_Integer] := (If[depth =!= menuDepth + 1, setHeld[heldPart[menuVars, depth], ]]; setHeld[heldPart[menuNames, depth - 1], menuCategs[[depth - 1]]]); subBackAll[depth_Integer] := subBack /@ Range[menuDepth + 1, depth, -1]; (* Function to create a (sub)menu at a given level *) makeSubmenu[depth_] := Function[{nm, actions}, subBackAll[depth + 1];(* remove lower menus if they are open *) If[depth =!= 1, setHeld[heldPart[menuNames, depth - 1], nm]]; setDelayedHeld[heldPart[menuVars, depth], Dynamic@ ActionMenu[menuNames[[depth]], Prepend[actions, Back :> subBackAll[depth]]], AutoAction -> True, Sequence @@ Options[makeSubmenu]]]]; (* Function to help with a layout *) addSpaces[x_List, spaceLength : (_Integer?Positive) : 10] := With[{space = StringJoin @@ Table[ , {spaceLength}]}, MapIndexed[ReplacePart[Table[space, {Length[x]}], ##] &, x]]; (* Initialization code *) subBackAll[2]; menuItemsConvertAlt[ {menuNames[[1]], {menuItemTree}}, makeSubmenu /@ Range[menuDepth], actionF, representF, representLeavesF][[1, 2]]; (* Display the menus *) Dynamic[ Function[Null, Grid[addSpaces[{##}, 5], Frame -> True, FrameStyle -> Thick, Background -> Lighter[Pink, 0.8]], HoldAll] @@ menuVars] ]; (* End Module *) ---------------------------------------------------------------------------- ------------------------------- So, the input for a menu should be a tree structure like this: In[1] = menuItems = {Continents, {{Africa, {{Algeria, {Algiers, Oran}}, {Angola, {Luanda, Huambo}}}}, {North America, {{United States, {New York, Washington}}, {Canada, {Toronto, Montreal}}}}}}; The root of the tree (Continents in this case) is not used later (but needed for consistency), so can be any string. The second necessary ingredient is a list of categories (strings) of the length equal to the depth of the menu to be constructed, or less (in which case some subcategories will be shown with a standard header Choose). The last mandatory ingredient is a function representing the action to be taken upon clicking on the lowest-level menu item (leaf). This is how we create the menu: In[1] = createNestedMenu[menuItems, {Continent, Country , City }, Print] In this case, all categories are given explicilty, and when we click on an atomic menu element (not representing further menu sub-levels), it is printed. You can also omit some sub-categories, they will be substituted by Choose In[2] = createNestedMenu[menuItems, {Continent}, Print] There are additional optional parameters, which allow us to represent different submenu items in different way - functions representF and representLeavesF. The first one governs the appearance of the non-atomic submenu elements and takes the level of a submenu as a second argument. The second governs the appearance of atomic menu elements (leaves). For example: In[3] = createNestedMenu[menuItems, {Continent, Country , City }, Print, (Style[#, FontColor -> Switch[#2, {1}, Brown, {2}, Blue, {3}, Green, _True, Orange], #]) &, Style[#, Red] &] I went through some pains to ensure that the menu will work also on less regular menu trees, where leaves may have different distance from the stem, like here: In[4] = menuTreeValidQ@ (compMenuItems = {Company, {{Services, {Training, Development}}, {Products, {{OS tools, {}}, {Application software, {}} }}, {News, {{Press releases, {}}, {Media coverage, {}} }}, {Company, {{Vacancies, {{Developer, {Requirements}}, {Tester, {}}}}, {Structure, {}}} } }}) Out[4] = True We create the menu as before: In[5] = createNestedMenu[compMenuItems, {Main}, Print] where I omitted sub-categories. Notice that the syntax I chose is such that, whenever the submenu contains only atomic elements, they can either all be represented by just strings, or wrapped in lists as {element,{}}, but not mixed. But if menu contains a mix of atomic and non-atomic elements, atomic elements must be wrapped in lists as above. For example, the more politically correct way to represent the first example structrure is this: {Continents, {{Africa, {{Algeria, {{Algiers, {}}, {Oran, {}}}}, {Angola, {{Luanda, {}}, {Huambo, {}}}}}}, {North America, {{United States, {{New York, {}}, {Washington, {}}}}, {Canada, {{Toronto, {}}, {Montreal, {}}}}}}}} The menuTreeValidQ predicate can be used to test if the structure is valid or not. Hope that I don't waste everyone's time and bandwidth. All feedback is greatly appreciated. Leonid === Subject: Re: changing variables in differential equations Hi Andre, you start out with one independent variable x. Then after the variable transformation you have 2 (u,v)! Therefore, this can not be a regular transformation. Daniel > Given an ordinary differential equation of order n, H(x,y,y',y'',...)=0 > Given the change of variables : x=x(u,v) and y=y(u,v) > How to calculate (hopefully recursively) y', y'', and so on as functions > of say : u, v', v'' In other words how to translate automatically the differential equation > in terms of the new variables ? === Subject: Re: changing variables in differential equations Hi Andre, having clearified that v= V[u] is to be considered the new dependent variable there is still the question if the dependent variable remains essentially the same or not: x=X[u,v[u]] y=Y[u,v[u]]= V[u] = v Anyway, we can define the i-derivative of y with respect to x by y[i] (note: lower case= variables, upper case= functions): Clear[x,X,y,Y]; x[0] = X[u, v[u]]; y[0] = Y[u, v[u]]; y[i_] := Dt[y[i - 1]]/Dt[x[0]] here is a simple example where the transformation only depends on u: X[u_, v_] := u^2; Y[u_, v_] := X[u, v] + X[u, v]^2 y[1]//Simplify Daniel > Given an ordinary differential equation of order n, H(x,y,y',y'',...)=0 > Given the change of variables : x=x(u,v) and y=y(u,v) > How to calculate (hopefully recursively) y', y'', and so on as functions > of say : u, v', v'' In other words how to translate automatically the differential equation > in terms of the new variables ? === Subject: Re: mathematica tutor for NYC high school student > Hello We are wondering if you can help us with this. We live in Manhattan (NYC) and are seriously considering withdrawing > our 15 yr old son (presently in 9th grade) from the school system and > give him homeschooling that is creative, adventurous and > non-competing. 2 out of three is good. He will need some competitiveness, it will help > drive him. > The more you son learns, the more confidence he will attain. > Home schooling is good for some things, but terrible for others. > Try instead to get your child into a better school district. If money is > tight or that option is not available, the supplement his education > yourself. > Go to a nearby university and ask a professor there if he may audit a > course. Most professors will be glad to accept him if he will not cause > trouble. Naturally, for Math we are thinking of Mathematica so all his high > school > math curriculum can be done visually but with mathematical rigor. Depending on the level he is at, shelve Mathematica for a while. Let him > grind the math by hand. Some explorations are augmented by mathmatica, > but only in later stages after one has learned the fundamentals. > You don't want him to be someone who has to go to the computer when it > comes time to integrate and simplify an expression. Question: Do you know some group/program/person in NYC so we can find > a > Mathematica tutor for our son so he gets excited about the > inherent beauty of Math and covers the basic knowledge he needs ? Your son needs to attain the exitement of math through his expereince > with people that he innitiates. Don't rely on others to get him > exited. > The best thing you can do is expose him to math indirectly. Talk with > him about your experiences with math. Get lots of good PBS and discovery > channel programs on math and science. He needs to cover Geometry, Trig, Algebra and Calculus at the high > school level (grades 9-12). It is a long shot, but I am placed in Architecture and need to look > outside my field for guidance. So the web becomes my first stop. At > some point I will walk over to Courant Inst and see if they can help. > Prof. H. Lalvani, PhD If you are a prof at a university or college, you can have your son > audit courses. I agree totally. Homeschooling is something I wish my parents did not put me through. The social interaction would have been nice (in some cases). As for auditing classes, that is a great way to learn things! I had a chance to learn college level algebra by sitting in on a class. Calculus I and II were done with some books I found in a throw out bin on campus, but I did take calculus III by sitting in on a class at a local college. And odd as it may seem, being inspired about math may come from unexpected sources. Mine came from a combination of watching a show called Numb3rs, and reading Jurassic Park. === Subject: a graph problem-> heptagon analog to the dodecahedron The construction of an two heptagon 28 vertex graph using an adjacency matrix isn't easy. The problem I had was getting all the errors out. The true answer is: http://www.geocities.com/rlbagulatftn/m28_7_14_7_rt3d.gif Edges=42 Vertices=28 Faces=16 In my original effort I had not one, but two mistakes in the adjacency matrix. So I present it as a problem for solution ( the almost adjacency matrix) find the errors: Mathematica: m28 = {{0, 1, 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}, {1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 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, 0, 1, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0}} CharacteristicPolynomial[m28, x] NSolve[CharacteristicPolynomial[m28, x] == 0, x] GraphPlot3D[m28] 3 BipartiteMatching[.89ª°Graph:<[InvisibleSpace]43[Invisib leSpace], [InvisibleSpace]28[InvisibleSpace], [InvisibleSpace]Undirected [InvisibleSpace]>.89ª°] 43 28 17 === Subject: Re: difference between HeavisidePi and UnitBox My typical application has been a 4F imaging system -- FourierTransform [rect[x]], then multiply by the pupil function, another rect, then InverseFourierTransform back into space domain. I've tried using both HeavisidePi and the UnitBox to represent the rect, both seem to have problems I start having severe problems when I use multiple scaled HeavisidePi. As a matter of fact, as soon as I shift and scale it, FourierTransform cannot calculate a result. With the UnitBox as the object, the results are a bit better, but then I cannot use a sum expression to represent the 5-bar pattern, I have to specify them explicitly. Not a big deal, and in the end things seem to work out. That is until I add an off-axis source, or defocus into the system. With an off-axis source the input is UnitBox[x] E^(I x s) -- and here the most curious thing happens. In this form everything is fine, but when I use UnitBox[x] E^(-I x s) I get two extra DiracDeltas in the FourierTransform with different signs. But I am side-tracked. For this kind of application, FourierTransform[UnitBox], multiply by UnitBox, InverseFourierTransform, am I using the right function? Should I spend more time with HeavisidePi? === Subject: What should be a simple task.... Hi :) I am an analyst (applied physics and math) who has to present all of my work in Power Point briefings, sometimes on paper, sometimes electronically. I vastly prefer working in Mathematica to another system; however, I'm currently ham strung by my inability to transfer simple plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right clicking on the plot in Mathematica and Paste Special: Metafile in Power Point, and all would be well (Ok, I had to tweak line thickness settings and fonts in my plots to make them survive the transfer, but that was fine). Now, I have select the whole cell rather than just the plot to get the Copy As: metafile option, and I have to go all the way to the menu bar to do it (no longer an option on the right click). Fine, I can deal with that, but I can't deal with the fact that my simple plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. I've played with the PlotPoints option-no effect. I've exported into different form ats with varying ImageResolution and imported; Either the fonts get screwed up or it looks even worse or there's ugly aliasing or no effect on the stair stepping. I've exported to PDF and snapshot-copied from there; The curves look good, but now the whole image is just a little bit blurry/soft, a little too much to pass muster with my supervisors and sponsors. I'm really getting frustrated now, have spent way too much time on what *was* a solved problem before my upgrades, and beginning to suspect that the problem is some import or paste/display setting in Power Point that I can't reach. I really don't want to have two different briefings for electronic vs. paper presentation, but I'm a little concerned that's where this is heading, or I'm going to have to use the other system to make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. This is one of those stupid simple problems that also happens to be quite fundamental to the ability to make good use of Mathematica. -Kristin === Subject: Re: Correction to Fundamental Theorem of It works on my version too (Mathematica 6 for OS X, 32 bit) g[x_] := Integrate[Exp[-t^2], {t, 0, x}] D[g[x], x] Out[9]:= E^(-x^2) 2009/6/12 Bob Hanlon Bob Hanlon I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all > works well. Can someone explain the odd behavior? > Len -- Por favor eviten enviarme archivos adjuntos de Word o Powerpoint ( http://www.gnu.org/philosophy/no-word-attachments.es.html ) === Subject: Problem of NUMERICAL constraints (Ndsolve) with Nminimize Hello everybody, I have to optimize an function with numerical constraints using Nminimize. To construct the constraints, i have to solve a system of ODEs (type): Sol=NDSolve[{{B'[ t] == -(t6 + t13) B[t] -(t7 + t15 + t14*t11) F[ t] +(1/2)*(B[t] B[t] + t11*F[t] F[t] + t12*GG[t] GG[t]) - t2, F'[t] == -t8*F[t] - t3, GG'[t] == -(t9 + t16) F[t] - (t10 + t17) GG[t] - t4, A'[t] == t5 B[t] +((t5*t7/t6) - t14) F[ t] +(1/2)*(F[t] F[t] + GG[t] GG[t]) - t1}, {B[0] == F[0] == GG[0] == A[0] == 0}}, {B, F, GG, A}, {t, 0, 10}][[1]] where t1,...,t17 are parameters to obtain. and then i have to use A,B,F,GG and my data to construct this constraints. So i use WITH (or Block) commend for it: f[t1_?NumericQ, t2_?NumericQ, t3_?NumericQ, t4_?NumericQ, t5_?NumericQ, t6_?NumericQ, t7_?NumericQ, t8_?NumericQ, t9_?NumericQ, t10_?NumericQ, t11_?NumericQ, t12_?NumericQ, t13_?NumericQ, t14_?NumericQ, t15_?NumericQ, t16_?NumericQ, t17_?NumericQ] := With[{...}, C] Here C are constraints to put on Nminimize optimization. I don't know how to deal with this, if C is only one constraint i have no problem with, but here C is a list. For Mathematica, f1[t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17] is only one element and not a List. I think to another way to solve this problem which is to get A,B,F,GG by defining functions directly with Ndsolve (then construct constraints with Data without using WITH) but i have to evaluate a lot of time NDSOLVE on my procedure, and it take a much of time. That will be great if someone could give an idea. === Subject: mergeSort with ReplaceRepeated Hi I'm writing an implementation of mergesort using replacerepeated. This is actually the code: merge[{a1, arest___}, b : {b1, ___}] /; a1 >= b1 //. {merge[a1, arest, b1] :> merge[b1, a1, arest] }; but it doesn't work, and I don't know why, because I'm really new to Mathematica. Any clue? -- Luca Bedogni === Subject: Re: Presentation quick with grid and pasted There's a step missing below: how to save the palette after using Palettes->Generate Palette from Selection ! This issue has arisen before in MathGroup. I know there's an answer, and I could probably again reconstruct it or find it by a search, but the difficulty indicates that there's a design gap in Mathematica in such situations. It just should not be that non-obvious. ... evaluate this code to make a button, click on a > cell insertion point, and click the button: Button[Insert Text+Math Grid, > NotebookWrite[InputNotebook[], > Cell[BoxData[ > FormBox[GridBox[{{Cell[text], [Placeholder]}}], > TraditionalForm]], Text]]] You could turn this button into a palette (Palettes->Generate Palette > from Selection) and install it (Palettes->Install Palette...) and use > it later (Palettes->) as well. -- 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: Correction to Fundamental Theorem of Calculus and g[x_] := Integrate[E^(-t^2), {t, 0, x}] False Trace[D[g[x], x]] {{HoldForm[g[x]], HoldForm[Integrate[E^(-t^2), {t, 0, x}]], HoldForm[(1/2)*Sqrt[Pi]* Erf[x]]}, HoldForm[ D[(1/2)*Sqrt[Pi]*Erf[x], x]], HoldForm[E^(-x^2)]} Trace[g'[x]] {{HoldForm[Derivative[1][g]], {HoldForm[g[#1]], HoldForm[ Integrate[E^(-t^2), {t, 0, #1}]], HoldForm[(1/2)*Sqrt[Pi]*Erf[3]]}, HoldForm[0 & ]}, HoldForm[(0 & )[x]], HoldForm[0]} This appears to be the problem Integrate[Exp[-t^2], {t, 0, #1}] (1/2)*Sqrt[Pi]*Erf[3] g[x_] := Evaluate[Integrate[E^(-t^2), {t, 0, x}]] True g[x_] = Integrate[E^(-t^2), {t, 0, x}]; True Bob Hanlon Hi Bob: Mine works as well using the D notation for derivative. But why will it not work using the prime notation? See below. In[1]:= g[x_] := Integrate[E^(-t^2), {t, 0, x}] In[2]:= g'[x] Out[2]= 0 In[3]:= D[g[x], x] Out[3]= E^(-x^2) Len > Works in my version. $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) f[x_] := Integrate[Sin[t^2], {t, 0, x}] D[f[x], x] Sin[x^2] g[x_] := Integrate[Exp[-t^2], {t, 0, x}] D[g[x], x] E^(-x^2) > Bob Hanlon I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all > works well. Can someone explain the odd behavior? > Len > === Subject: Re: Correction to Fundamental Theorem of Calculus and Hi Bob, The trace does indeed show the problem, but I don't understand why the Gaussian integral returns the error function evaluated at 3... The other example that Len gave works ok -- the Integral[Sin[t^2],{t, 0,#1}] returns Sqrt[Pi/2]*FresnelS[Sqrt[2/Pi]*#1] as expected... or a simpler case: f[x_] := Integrate[Sin[t], {t, 0, x}] f'[x] // Trace // InputForm {{HoldForm[Derivative[1][f]], {HoldForm[f[#1]], HoldForm[Integrate[Sin [t], {t, 0, #1}]], HoldForm[1 - Cos[#1]]}, HoldForm[Sin[#1] & ]}, HoldForm[(Sin[#1] & )[x]], HoldForm[Sin[x]]} Do you (or anyone else here) know why Mathematica behaving this way when given the Gaussian? Is it a known bug? Simon === Subject: Re: Creating Matrix from vectors specific issue. >am getting vectors from my program which is of the form v1 = >{{1},{2},{3}}; v2 = {{4},{5},{6}}; BUT NOT v1 = {1,2,3} and v2 = >{4,5,6} >Now if i use A = {v1,v2} and then Transpose[A] i am getting the >required matrix only in the 2nd case i.e when v1 = {1,2,3} and >similarly v2. However when i use the same A = {v1,v2} in the 1st >case and then Transpose[] i.e when v1 = {{1},{2},{3}} and similarly >v2, i am not getting the required matrix. If anyone would help me >with this specific point it will be helpful. >I have also seen that the dimension in case 1 is {3,1} while that in >case 2 is {3}. If there is any way to interchange the two .. that >also will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that >will also suffice. You really ought to read the tutorials on working with lists in Mathematica. To convert any multi-dimensional list to a 1D list, use Flatten. For example, In[1]:= v1 = {{1}, {2}, {3}}; v2 = {{4}, {5}, {6}}; In[3]:= Flatten[v1] Out[3]= {1,2,3} So, the desired result can be obtained with Transpose as follows: In[4]:= Transpose[Flatten /@ {v1, v2}] Out[4]= {{1, 4}, {2, 5}, {3, 6}} Or even more directly with ArrayFlatten as follows: In[5]:= ArrayFlatten@{{v1, v2}} Out[5]= {{1, 4}, {2, 5}, {3, 6}} === Subject: Re: Correction to Fundamental Theorem of Calculus and Mathematica I define a function (using f[x_]:=) as the definite integral (from 0 to x) of sin(t^2). When I differentiate using Mathematica I get the correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all works well. Can someone explain the odd behavior? Len I tried and this is the result: In[3]:= g[x_] := Integrate[Exp[-t^2], {t, 0, x}] In[4]:= D[g[x], x] Out[4]= [ExponentialE]^-x^2 Sorry, Alexei -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: Solving simultaneous integral equation >I have a problem of the form >Integrate[f[s],{s,(b-e)/c,(b+e)/c] >I am trying to solve for c and e (b is known). f[s] cannot be >integrated algebraicly, only by by setting values for e and c and >using NIntegrate. >I also have a supplimentary equation linking b and c, which cannot >be inverted using solve to give a relationship between e and c. >I am trying to use NSolve or FindRoot to solve the system of >equations, but I keep getting errors saying that algebraic limits >are invalid for NIntegrate. The obvious way to get around this particular error message would be to use say x and y for the limits of integration then solve for b and e using Solve or NSolve. That is, use FindRoot with NIntegrate[f[s], {s, x, y}] to find suitable values for x and y. Then b will be c(x+y)/2 and e will be c(y-x)/2. However, I am not sure this will be all that useful. My guess is there are an infinite number of pairs for any given f[s] that will cause the definite integral to have a specific value. This is clearly true for the simple f[s]:= 1 since the integral becomes simply the difference between the integration limits. === Subject: Re: perturbation methods example from stephen lynch's book? Hi Simon, Actually I've found some resources on wolfram website. http://library.wolfram.com/infocenter/MathSource/5269/ It seems like an excellent resource for those who wants to learn and use asymptotics in mathematica. Only problem is that it uses mathematica 3... And Lynch's example 7 and typos come from his duffing equation. Instead of x''+x+eps x^3 =0, he uses x''+x =eps x^3 Differences show in O(e) eqn. o1 = DSolve[{x0[t] + x0''[t] == 0, x0'[0] == 0, x0[0] == 1 }, x0[t], t] [[1, 1]] DSolve[{x0[t]^3 + x1[t] + x1''[t] == 0 /. {x0[t] -> Cos[t]}, x1'[0] == 0, x1[0] == 0 }, x1[t], t][[1, 1]] oe = % // Simplify // Expand x~xp= o1[[2]] + [Epsilon] (oe)[[2]] % // TraditionalForm vs. o1 = DSolve[{x0[t] + x0''[t] == 0, x0'[0] == 0, x0[0] == 1 }, x0[t], t] [[1, 1]] DSolve[{-x0[t]^3 + x1[t] + x1''[t] == 0 /. {x0[t] -> Cos[t]}, x1'[0] == 0, x1[0] == 0 }, x1[t], t][[1, 1]] oe = % // Simplify // Expand x~xp= o1[[2]] + [Epsilon] (oe)[[2]] % // TraditionalForm === Subject: Re: Creating Matrix from vectors specific issue. and Flatten[] or ArrayFlatten[] does not help ? Jens > My exact problem is as follows.. > I am getting vectors from my program which is of the form > v1 = {{1},{2},{3}}; > v2 = {{4},{5},{6}}; > BUT NOT v1 = {1,2,3} and v2 = {4,5,6} Now if i use A = {v1,v2} and then Transpose[A] i am getting the > required matrix only in the 2nd case i.e when v1 = {1,2,3} and > similarly v2. > However when i use the same A = {v1,v2} in the 1st case and then > Transpose[] i.e when v1 = > {{1},{2},{3}} and similarly v2, i am not getting the required matrix. > If anyone would help me with this specific point it will be helpful. I have also seen that the dimension in case 1 is {3,1} while that in > case 2 is {3}. If there is any way to interchange the two .. that also > will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will > also suffice. Please help. > === Subject: Re: Creating Matrix from vectors specific issue. Did you look carefully at the result of the following? v1 = {{1},{2},{3}}; v2 = {{4},{5},{6}}; A = {v1,v2} You get: {{{1}, {2}, {3}}, {{4}, {5}, {6}}} What you have is a list of two 3-element lists, with each of those individual elements itself being a 1-element list. That is, A has ArrayDepth of 3 (and a Depth of 4) whereas to have a list of lists that represents a matrix, you want an ArrayDepth of 2 (and a Depth of 3). So all you need to do to reduce your 1st case to your 2nd case is to Flatten each vector: B = {Flatten[v1],Flatten[v2]} {{1,2,3},{4,5,6}} And now you have a list of two 3-element lists, where each individual element is a number (and no longer a 1-element list holding a number). So it can represent a matrix in the conventional meaning of the term, and you can make what are the rows into the columns by using Transpose, as you did in your 2nd case. For a whole bunch of vectors of the form list v1, v2, you can Map the function Flatten onto the whole list of vectors at once rather than evaluating Flatten separately upon each. In the case of your two two: v1 = {{1},{2},{3}}; v2 = {{4},{5},{6}}; Flatten /@ {v1,v2} I do recommend you study the Documentation Center tutorials Lists and VectorsAndMatrices. Learning more of the fundamentals will eventually save you a lot of time. > My exact problem is as follows.. > I am getting vectors from my program which is of the form > v1 = {{1},{2},{3}}; > v2 = {{4},{5},{6}}; > BUT NOT v1 = {1,2,3} and v2 = {4,5,6} Now if i use A = {v1,v2} and then Transpose[A] i am getting the > required matrix only in the 2nd case i.e when v1 = {1,2,3} and > similarly v2. > However when i use the same A = {v1,v2} in the 1st case and then > Transpose[] i.e when v1 = > {{1},{2},{3}} and similarly v2, i am not getting the required matrix. > If anyone would help me with this specific point it will be helpful. I have also seen that the dimension in case 1 is {3,1} while that in > case 2 is {3}. If there is any way to interchange the two .. that also > will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will > also suffice. Please help. > -- 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 Matrix from vectors specific issue. Here is the royal road to knowledge answer: Flatten[{{1},{2},{3}}] yields {1,2,3} However, you would be better served in the long term by looking typing howto/WorkWithLists in the search box of the Documentation Center. === Subject: Re: Creating Matrix from vectors specific issue. In[7]:= v1 = {{1}, {2}, {3}}; v2 = {{4}, {5}, {6}}; Transpose[Flatten /@ {v1, v2}] Out[8]= {{1, 4}, {2, 5}, {3, 6}} In[9]:= MapThread[Join, {v1, v2}] Out[9]= {{1, 4}, {2, 5}, {3, 6}} Adriano Pascoletti 2009/6/12 Kinu I am getting vectors from my program which is of the form > v1 = {{1},{2},{3}}; > v2 = {{4},{5},{6}}; > BUT NOT v1 = {1,2,3} and v2 = {4,5,6} Now if i use A = {v1,v2} and then Transpose[A] i am getting the > required matrix only in the 2nd case i.e when v1 = {1,2,3} and > similarly v2. > However when i use the same A = {v1,v2} in the 1st case and then > Transpose[] i.e when v1 = > {{1},{2},{3}} and similarly v2, i am not getting the required matrix. > If anyone would help me with this specific point it will be helpful. I have also seen that the dimension in case 1 is {3,1} while that in > case 2 is {3}. If there is any way to interchange the two .. that also > will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will > also suffice. Please help. === Subject: Re: Creating Matrix from vectors specific issue. > My exact problem is as follows.. > I am getting vectors from my program which is of the form > v1 = {{1},{2},{3}}; > v2 = {{4},{5},{6}}; > BUT NOT v1 = {1,2,3} and v2 = {4,5,6} Now if i use A = {v1,v2} and then Transpose[A] i am getting the > required matrix only in the 2nd case i.e when v1 = {1,2,3} and > similarly v2. > However when i use the same A = {v1,v2} in the 1st case and then > Transpose[] i.e when v1 = > {{1},{2},{3}} and similarly v2, i am not getting the required matrix. > If anyone would help me with this specific point it will be helpful. I have also seen that the dimension in case 1 is {3,1} while that in > case 2 is {3}. If there is any way to interchange the two .. that also > will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will > also suffice. A = Transpose[{Flatten[v1],Flatten[v2]}] Mathematica makes a distinction between a matrix (tensor of rank 2) which has two dimensions, and a vector (tensor of rank 1), the function ArrayDepth can be used to determine the rank of a structure. Flatten can be used to modify rank. Ssezi === Subject: Re: keybord problem with version 7 and altgr > { }), a blank is inserted in front of [ or {. > This seems to happen with some flavours of Linux. A workaround is: Make a copy of the File /Mathematica/SystemFiles/.../KeyTranslations.tr (this is needed, because if you make an error editing this file, Mathematica will not work) open this file with your editor. Add the following to the list of KeyEvents: Item[KeyEvent[ISO_Level3_Shift], FrontEndExecute[{FrontEnd`NotebookWrite[ FrontEnd`InputNotebook[],Sequence[],After]}]] This makes Mathematica to insert a Sequence[] at Cursor position when pressing AltGr. But Sequence[] is nothing. Save the edited file and restart Mathematica. I found this workaround in this group, if I remember correctly. -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: keybord problem with version 7 and altgr if you use a Linux system, than it is a known problem and WRI has a patch for it and the actual 7.0.1 version should no show it. Jens > { }), a blank is inserted in front of [ or {. > === Subject: Re: Creating Matrix from vectors specific issue. a = Map[List, Array[s, {3, 5}], {2}] {{{s[1, 1]}, {s[1, 2]}, {s[1, 3]}, {s[1, 4]}, {s[1, 5]}}, {{s[2, 1]}, {s[2, 2]}, {s[2, 3]}, {s[2, 4]}, {s[2, 5]}}, {{s[3, 1]}, {s[3, 2]}, {s[3, 3]}, {s[3, 4]}, {s[3, 5]}}} Transpose[Apply[Sequence, a, {2}]] {{s[1, 1], s[2, 1], s[3, 1]}, {s[1, 2], s[2, 2], s[3, 2]}, {s[1, 3], s[2, 3], s[3, 3]}, {s[1, 4], s[2, 4], s[3, 4]}, {s[1, 5], s[2, 5], s[3, 5]}} Bob Hanlon My exact problem is as follows.. I am getting vectors from my program which is of the form v1 = {{1},{2},{3}}; v2 = {{4},{5},{6}}; BUT NOT v1 = {1,2,3} and v2 = {4,5,6} Now if i use A = {v1,v2} and then Transpose[A] i am getting the required matrix only in the 2nd case i.e when v1 = {1,2,3} and similarly v2. However when i use the same A = {v1,v2} in the 1st case and then Transpose[] i.e when v1 = {{1},{2},{3}} and similarly v2, i am not getting the required matrix. If anyone would help me with this specific point it will be helpful. I have also seen that the dimension in case 1 is {3,1} while that in case 2 is {3}. If there is any way to interchange the two .. that also will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will also suffice. Please help. === Subject: Re: RandomReal gets stuck >> And Mathematica does not recognizes >> input Subscript[a,i] as equivalent to a[i]. You mean something like zero doesn't come from a[1] - Subscript[a, 1] for instance? and > False That's true, but when using this trick I never actually type or use the > subscripted form; I only see it. So there's no chance the conflict can > occur for me. Subscripts also disappear if you assign values, such as in a[2] = 3; a[2] 3 a[j] displays subscripted for any j where a[j] is undefined. Maybe you won't find it useful, but maybe you will. I don't know. Bobby > The issue is, that subFunction makes not Subscript[a,i] but SubscriptBox[a,i], so if you enter (I use LaTeX form here to mark the subscripted a) True It's really great! -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Correction to Fundamental Theorem of Calculus and Mathematica this is nonsens. f[x_] := Integrate[Sin[t^2], {t, 0, x}] g[x_] := Integrate[Exp[-t^2], {t, 0, x}] D[#, x] & /@ {g[x], f[x]} gives {E^(-x^2), Sin[x^2]} That is why it is useful to post your full input and not a verbal description. Jens I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all > works well. Can someone explain the odd behavior? > Len > === Subject: Re: Correction to Fundamental Theorem of Calculus and Mathematica Hi Simon: Interesting! Like you, I get correct results when differentiating using D. But when I differentiate using the prime sign (g'[x] ) I get the incorrect answer of 0. Len > Hi Len, Running both 6.0.3 and 7.0.1, I don't seem to get that problem: In[1]:= f[x_]:=Integrate[Sin[t^2],{t,0,x}] In[2]:= D[f[x],x] > Out[2]= Sin[x^2] In[3]:= g[x_]:=Integrate[Exp[-t^2],{t,0,x}] In[4]:= D[g[x],x] > Out[4]= E^-x^2 Simon === Subject: Re: Correction to Fundamental Theorem of Calculus and Mathematica > Interesting! Like you, I get correct results when differentiating > using D. But when I differentiate using the prime sign (g'[x] ) I > get the incorrect answer of 0. I think this is a case where Trace is useful, and when looking at the output of Trace it seems clear that this is why it goes wrong for g': In[14]:= Integrate[Exp[-t^2], {t, 0, #}] Out[14]= 1/2 Sqrt[[Pi]] Erf[3] In[15]:= Integrate[Sin[t], {t, 0, #}] Out[15]= 1 - Cos[#1] I think Out[14] clearly is a bug, because whatever # may be, it is not 3 in almost all cases :-) hth, albert === Subject: Re: Correction to Fundamental Theorem of Calculus and Mathematica I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all > works well. Can someone explain the odd behavior? > Len > My guess is that you had been doing things with Mathematica prior to that, and as a result, g had some sort of definition. If the problem happens again, try typing ??g If you get a strange result, it is often useful to kill the kernel so that you start with a clean slate. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Correction to Fundamental Theorem of Calculus Yes. However, with those definitions of f and g: f'[x] Sin[x^2] g'[x] 0 I believe that's the discrepancy to which the original poster refers. And this originates from what you'll see if you use the FullForm, the FullForm of h'[x] being Derivative[1][h][x]: Derivative[1][f] (FresnelS^[Prime])[Sqrt[2/[Pi]] #1]& Derivative[1][g] 0& The latter arises from: g[x] 1/2 Sqrt[[Pi]] Erf[x] So I don't understand why the derivative of g is the constantly 0 function. After all, Mathematica DOES know: Derivative[1][Erf] (2 E^-#1^2)/Sqrt[[Pi]]& And that surely is not the zero function! > Hi Len, Running both 6.0.3 and 7.0.1, I don't seem to get that problem: In[1]:= f[x_]:=Integrate[Sin[t^2],{t,0,x}] In[2]:= D[f[x],x] > Out[2]= Sin[x^2] In[3]:= g[x_]:=Integrate[Exp[-t^2],{t,0,x}] In[4]:= D[g[x],x] > Out[4]= E^-x^2 Simon > -- 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: polynomial of 7th order, some structure hi, I have an equation i have been trying to solve, but no amount of Solve, Reduce or ToRadical seems to produce an answer. x(1+x^2)^3 == a x^4 +b x^3 +...+e I know that it has one or three real roots, depending on combinations of coefficients, with only one root at x>0. That is the one that I want, the root that is > 0. Does anyone have any ideas what I can do? I can plot the Root[] results, and I can see that it is usually the same one root from the list, for most coefficient combinations. Any way i can get the formula without plugging in the values? your question is not about Mathematica, but about mathematics. My excuses to moderator. Are n't you aware of the Galois theorem stating that algebraic equation of a general form only then have solution in radicals (that is what you are looking for) when its power is below or equal to 5? You have equation of the power 7 with 5 arbitrary constants, do you hope that it may belong to exceptions of this theorem? Then you should have good reasons for that, and these reasons should most probably go beyond the form of the equation itself. For example, they may be in the physical (chemical, etc.) nature of the phenomenon that gave rise to this equation. I met such situations. If I am right and no such reasons exist, the only thing you can reasonably look for in this case may be conditions imposed on the coefficients a, b ... at which such a (positive) root appears and disappears. You may also look for an approximate solution for x>0 in the close vicinity of such a bifurcation point. But this again more the mathematical question, of how to look for such a bifurcation point. If it is formulated correctly, simple Mathematica tools will be applicable. Good lack, Alexei -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: How to use R within Mathematica I stumbled upon your question. On Windows, it is easy to use R from within Mathematica. You just have to download and install the statconnDCOM server (free for noncommerial use) from rcom.univie.ac.at The following piece of code shows how you than can use R from within Mathematica. Needs[NETLink`] myR = CreateCOMObject[RCOMServerLib.StatConnector] myR@Init[R] myR@SetSymbol[xxx,12321] result1=myR@GetSymbol[xxx] myR@EvaluateNoReturn[randmat<-matrix(rnorm(100),10)] rmat=myR@GetSymbol[randmat] result2=myR@Evaluate[solve(matrix(1:4,2))] > I would like to use functions from some R libraries within Mathametica. I have seen that there exists a software called RLink but it is not readily available. Is the way to go to use the R functionaly in C/C++ and then use MathLink to call the C/C++ functions? === Subject: Re: How to use R within Mathematica On Jun 13, 6:07 am, Erich Neuwirth On Windows, it is easy to use R from within Mathematica. > You just have to download and install the > statconnDCOM server (free for noncommerial use) > from rcom.univie.ac.at The following piece of code shows how you than > can use R from within Mathematica. Needs[NETLink`] > myR = CreateCOMObject[RCOMServerLib.StatConnector] > myR@Init[R] > myR@SetSymbol[xxx,12321] > result1=myR@GetSymbol[xxx] > myR@EvaluateNoReturn[randmat<-matrix(rnorm(100),10)] > rmat=myR@GetSymbol[randmat] > result2=myR@Evaluate[solve(matrix(1:4,2))] I would like to use functions from some R libraries within Mathametica.= I have seen that there exists a software called RLink but it is not readil= y available. Is the way to go to use the R functionaly in C/C++ and t= hen use MathLink to call the C/C++ functions? > Very interesting. I just downloading and installed RAndFriends from rcom.univie.ac.at, which installs R, rcom, rscproxy, statconnDCOM, and I order to run your code, I had to modify it as follows: myR = CreateCOMObject[StatConnectorSrv.StatConnector] You example illustrates a number of methods, such as SetSymbol, Evaluate, etc. I was able to infer myR@Close[] (and then use ReleaseCOMObject[myR]). Do know where I might find the full set of methods? --Mark === Subject: Re: How to use R within Mathematica On Jun 13, 5:07 am, Erich Neuwirth On Windows, it is easy to use R from within Mathematica. > You just have to download and install the > statconnDCOM server (free for noncommerial use) > from rcom.univie.ac.at The following piece of code shows how you than > can use R from within Mathematica. Needs[NETLink`] > myR = CreateCOMObject[RCOMServerLib.StatConnector] It seems like the actual COM object should be different. I had success with myR = CreateCOMObject[StatConnectorSrv.StatConnector] --Sasha > myR@Init[R] > myR@SetSymbol[xxx,12321] > result1=myR@GetSymbol[xxx] > myR@EvaluateNoReturn[randmat<-matrix(rnorm(100),10)] > rmat=myR@GetSymbol[randmat] > result2=myR@Evaluate[solve(matrix(1:4,2))] I would like to use functions from some R libraries within Mathametica.= I have seen that there exists a software called RLink but it is not readil= y available. Is the way to go to use the R functionaly in C/C++ and t= hen use MathLink to call the C/C++ functions? > === Subject: Combined Set, SetDelayed This may be a silly question but I have not found an answer to it yet in the Documentation Centre. In dynamic programming the following construct f [ x_, y_] := f [x,y] = ...... is used, unless I am mistaken. I'd like to know if there are other situations where we must write a function definition in the above format. Sid. === Subject: Re: Combined Set, SetDelayed Hi Sid, if you check the grouping of the expression it is f[x_,y_] := ( f[x, y] = ... ) thus if f[x,y] is not in the downvalues of f for the particular x and y it will do the calculation. If it is in the downvalues, it simply returns the value it knows. ( NB this is dangerous if you change your definition of f, but do not clear all the previously calculated specific values ) it can be used whenever the calculation of f[x,y] is computationally expensive (and memory isn't too much of a problem)... the famous example (I think given in the documentation centre) is that of the Fibonacci numbers - a naive recursive definition f[0]=f[1]=1; f[n_Integer?Positive]:=f[n-1]+f[n-2] becomes unusable for relatively small values of n. Simon === Subject: Re: Combined Set, SetDelayed it has nothing to do with dynamic programming -- do it, always when you have a computation that need a lot of time and that you call more than once. Jens This may be a silly question but I have not found an answer to it yet > in the Documentation Centre. In dynamic programming the following construct > f [ x_, y_] := f [x,y] = ...... is used, unless I am mistaken. I'd like to know if there are other situations where we must write a > function definition in the above format. Sid. > === Subject: Re: Combined Set, SetDelayed This may be a silly question but I have not found an answer to it yet > in the Documentation Centre. In dynamic programming the following construct > f [ x_, y_] := f [x,y] = ...... is used, unless I am mistaken. I'd like to know if there are other situations where we must write a > function definition in the above format. The idea is that the function is not evaluated when it is defined, but once it is evaluated, it remembers values that have been computed. This is extremely useful when defining a function recursively. Try this: a[0] = 1; a[1] = 2; a[n_] := a[n - 1] - a[n - 2] Table[a[n], {n, 0, 25}] // Timing And compare with this: b[0] = 1; b[1] = 2; b[n_] := b[n] = b[n - 1] - b[n - 2] Table[b[n], {n, 0, 25}] // Timing On my system, the first table, where it has to start over every time and run through the entire (longer and longer as you go) recursion, took 0.811 seconds. The second version, using the function that remembers values, took only 1.87003*10^-15 seconds. And if the table requires more steps than the recursion limit (the default is 255), it won't even work unless the function is defined to remember values. -- Helen Read University of Vermont === Subject: Re: Avoid printing leading zero On 6/11/09 at 9:47 PM, lorenzana.jose@gmail.com (Jos=C3=A9 Lorenzana) >How do you avoid printing the leading zero in -0.03? I need to >construct the string -.03 . >Something like this does not work: >ToString@NumberForm[-0.3, {0, 2}] Since you want a string result, it seems the most straight forward way of doing this would be In[13]:= StringReplace[ToString[-.03], 0. -> .] Out[13]= -.03 === Subject: Re: Presentation quick with grid and pasted There is no missing step. Palettes->Install Palette..., which I mention below, installs a copy of the palette into the right location so that it will be found in the Palettes menu. It does so by saving a copy of the palette in the right directory with the name you specify, and then immediately regenerating the menus so that you don't have to quit/restart to see the results. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > There's a step missing below: how to save the palette after using > Palettes->Generate Palette from Selection ! This issue has arisen before in MathGroup. I know there's an answer, and > I could probably again reconstruct it or find it by a search, but the > difficulty indicates that there's a design gap in Mathematica in such > situations. It just should not be that non-obvious. > ... evaluate this code to make a button, click on a >> cell insertion point, and click the button: >> Button[Insert Text+Math Grid, >> NotebookWrite[InputNotebook[], >> Cell[BoxData[ >> FormBox[GridBox[{{Cell[text], [Placeholder]}}], >> TraditionalForm]], Text]]] >> You could turn this button into a palette (Palettes->Generate Palette >> from Selection) and install it (Palettes->Install Palette...) and use >> it later (Palettes->) as well. === Subject: Re: need a help Contact support@wolfram.com --david > hi! > I got an error code: 557 I tried to reinstall again my copy: no result 1-mathematica basically v6 upgraded to v7 > 2-platform :W Vista the info that I get is: there was a syntax error in the LinkSetup file > c:users packard appData Roaming Mathematica FrontEnd init.m what to do? > dr albert haccoun > france === Subject: Re: Avoid printing leading zero > How do you avoid printing the leading zero in -0.03? > I need to construct the string -.03 . Something like this does not work: > ToString@NumberForm[-0.3, {0, 2}] I have thie following two routines in my init.m file. 'myform' suppresses exponential notation and substitutes a blank space for the non-significant leading zero that precedes a fraction in PaddedForm output: 0.xyz -> .xyz, and -0.xyz -> -.xyz. The number of characters does not change. This is a quick-&-dirty implementation. There are no checks for out-of-range values, special cases, non-numbers, etc, so there may be error messages, more than w+2 characters, or other anomalies. myform[x__] := StringReplace[ToString@PaddedForm[x, ExponentFunction->(Null&)],{ 0.0-> .0, 0.1-> .1, 0.2-> .2, 0.3-> .3, 0.4-> .4, 0.5-> .5, 0.6-> .6, 0.7-> .7, 0.8-> .8, 0.9-> .9, -0.0-> -.0, -0.1-> -.1, -0.2-> -.2, -0.3-> -.3, -0.4-> -.4, -0.5-> -.5, -0.6-> -.6, -0.7-> -.7, -0.8-> -.8, -0.9-> -.9}]; 'mform' is like 'myform', but in positive numbers the non-significant zero is simply deleted, not replaced by a blank space, and the string is one character shorter. mform[x__] := StringReplace[ToString@PaddedForm[x, ExponentFunction->(Null&)],{ 0.0-> .0, 0.1-> .1, 0.2-> .2, 0.3-> .3, 0.4-> .4, 0.5-> .5, 0.6-> .6, 0.7-> .7, 0.8-> .8, 0.9-> .9, -0.0-> -.0, -0.1-> -.1, -0.2-> -.2, -0.3-> -.3, -0.4-> -.4, -0.5-> -.5, -0.6-> -.6, -0.7-> -.7, -0.8-> -.8, -0.9-> -.9}]; === Subject: Re: Avoid printing leading zero Use StringDrop In[16]:= StringDrop[-0.03, {2, 2}] Out[16]= -.03 > How do you avoid printing the leading zero in -0.03? > I need to construct the string -.03 . Something like this does not work: > ToString@NumberForm[-0.3, {0, 2}] > Jos=E9 === Subject: Re: Inverse / Laplace Transform Halved Mathematica 7.0.1: InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t]// Simplify // InputForm Piecewise[{{BesselI[1, t]/2, s > 1}, {-DiracDelta[t], s < 1}}, 0] LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]],s,t],t,s] // InputForm s/E^(a*Sqrt[s]) I am currently using Version 6 and have found that InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t] yields, after tidying up, 1/2 BesselI[1,t]. > Also, LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], > t,s] gives ((1/2)*s)/E^(a*Sqrt[s]) . > Do members have the same problem with Version 7 ? Is it I who am missing something here ? -- 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: Inverse / Laplace Transform Halved Mathematica 7.01 with MacOS 10.5.7 produces the following: In[78]:= InverseLaplaceTransform[LaplaceTransform[BesselI[1, t], t, s], s, t] Out[78]= Sqrt[=CF=80] InverseLaplaceTransform[=E2=89=A5 { {-(s/Sqrt[=CF=80]), s < 1}, {((s (-1 + s/Sqrt[-1 + s^2]))/Sqrt[=CF=80]), s > 1}, {0, TagBox[True, PiecewiseDefault, AutoDelete->False, DeletionWarning->True] } }/s, s, t] In[91]:= LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], t, s] Out[91]= E^(-a Sqrt[s]) s The second is the exact function in the argument. The first does not process the three conditions of the LT of BesselI[1,t]. HTH, Raul Martinez I am currently using Version 6 and have found that InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t] yields, after tidying up, 1/2 BesselI[1,t]. > Also, LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], > t,s] gives ((1/2)*s)/E^(a*Sqrt[s]) . > Do members have the same problem with Version 7 ? Is it I who am missing something here ? > Sid > === Subject: Inverse / Laplace Transform Halved I am currently using Version 6 and have found that InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t] yields, after tidying up, 1/2 BesselI[1,t]. Also, LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], t,s] gives ((1/2)*s)/E^(a*Sqrt[s]) . Do members have the same problem with Version 7 ? Is it I who am missing something here ? Sid === Subject: Re: Inverse / Laplace Transform Halved I am currently using Version 6 and have found that InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t] yields, after tidying up, 1/2 BesselI[1,t]. > Also, LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], > t,s] gives ((1/2)*s)/E^(a*Sqrt[s]) . > Do members have the same problem with Version 7 ? > I have version 7.0.1 Mac OS X 10.15.7 (PPC). The Transformation of BesselI[1,t] gives me an additional 1/2, as you got, whereas s*Exp[-a Sqrt[s]] returns itself. -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Inverse / Laplace Transform Halved In[5]:= InverseLaplaceTransform[ LaplaceTransform[BesselI[1, t], t, s, Assumptions -> {s > 1}], s, t] Out[5]= -DiracDelta[t] + 1/2 (BesselI[1, t] + 2 DiracDelta[t]) In[6]:= $Version Out[6]= 7.0 for Linux x86 (64-bit) (February 18, 2009) -Francesco I am currently using Version 6 and have found that InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t] yields, after tidying up, 1/2 BesselI[1,t]. > Also, LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], > t,s] gives ((1/2)*s)/E^(a*Sqrt[s]) . > Do members have the same problem with Version 7 ? Is it I who am missing something here ? > Sid > === Subject: Re: Inverse / Laplace Transform Halved $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) InverseLaplaceTransform[ LaplaceTransform[ BesselI[1, t], t, s] // Simplify, s, t] // Simplify Piecewise[{{BesselI[1, t]/2, s > 1}, {-DiracDelta[t], s < 1}}] However, LaplaceTransform[ InverseLaplaceTransform[ BesselI[1, t], t, s], s, t] BesselI[1, t] No problem with second example LaplaceTransform[ InverseLaplaceTransform[ s*Exp[(-a)*Sqrt[s]], s, t], t, s] s/E^(a*Sqrt[s]) Bob Hanlon I am currently using Version 6 and have found that InverseLaplaceTransform[LaplaceTransform[BesselI[1,t],t,s],s,t] yields, after tidying up, 1/2 BesselI[1,t]. Also, LaplaceTransform[InverseLaplaceTransform[s*Exp[(-a)*Sqrt[s]], s, t], t,s] gives ((1/2)*s)/E^(a*Sqrt[s]) . Do members have the same problem with Version 7 ? Is it I who am missing something here ? Sid === Subject: Re: differentiation operator Lim Cheung, When I bring up the Classroom Assistant palette, go to the Calculator Advanced tab, and press the 2nd button in the 5th row it pastes the partial differential form in my notebook. This has the partial symbol with var as a subscript and another box to enter the expr. If I fill x into the var box, and x^2 into the expr box, and then press Shift-Enter, the entire expression will evaluate to obtain 2x. If you type x^2, select it, and then press the palette button, it will paste the differential operator on the x^2. You will then still have to fill in the x and use Shift-Enter. Does this not evaluate properly for you? If not, there is some bug in your installation and you should contact WRI. True, this form does not look exactly like 'd/dx' but I would think it would be good enough. Or, perhaps you want a restricted paste button that already has the x filled in. If so, you could use the following expression to create the button in your notebook: Defer@PasteButton[!( *SubscriptBox[([PartialD]), (x)][SelectionPlaceholder])] You can create this statement by writing Defer@PasteButton[]. Then click in the partial expression from the Classroom Assistant. Then fill var with x, and fill expr with a selection placeholder (esc spl esc). When you evaluate that you will obtain a button that will paste the operator onto any selected expression. You could make your own palette with the button by using CreatePalette. Otherwise, I don't really understand what your objective or problem is. You could also try out the Notation package. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi David Park Calculus textbooks) in the Classroom Assistant palette but it seems to be for display only. (Am i missing something here?) I guess the solution is to format it to behave like a differentiation operator. Any ideas on that? We would like d(f[x])/dx to function in the same way as D[f[x],x]. Mr. Chee Inactive hide details for David Park David Park David Park 10/06/2009 23:32 To 'Chee Lim Cheung' , cc Subject RE: differentiation operator I don't see why you say that the differential operator on the palette doesn't work. If you paste it in a notebook and then fill in x and the expression and then evaluate, it will work. Otherwise, you could do something like: d[x_] = Function[expr, D[expr, x]]; d[x][x^2] 2 x David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi All My students have asked me whether it is possible to define the operator df[x]/dx for differentiation rather than D[f[x],x]. The operator is available in a palette but it does not seem to do anything other than for display only. Example: d/dx(x^2)=2x rather than D[x^2,x]=2x. Am I missing something? Mr. Chee === Subject: Re: Presentation quick with Of course! When I selected Install Palette, the pop-up dialog asked for a source, and I forgot that the source file could be an open notebook and not necessarily a notebook previously saved. The issue remains, however, about saving a palette once you create it with Generate Palette from Selection. It just seems to me that one should not have to go through all the fuss of seeing the list of values of Notebooks[], picking the relevant one nb, and finally using NotebookSave[nb]. What is the rationale for the design decision not to allow, by default, using File->Save or File->Save As directly upon such a created palette? > There is no missing step. Palettes->Install Palette..., which I mention below, > installs a copy of the palette into the right location so that it will be found > in the Palettes menu. It does so by saving a copy of the palette in the right > directory with the name you specify, and then immediately regenerating the menus > so that you don't have to quit/restart to see the results. > > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. >> There's a step missing below: how to save the palette after using >> Palettes->Generate Palette from Selection ! >> This issue has arisen before in MathGroup. I know there's an answer, and >> I could probably again reconstruct it or find it by a search, but the >> difficulty indicates that there's a design gap in Mathematica in such >> situations. It just should not be that non-obvious. >>> ... evaluate this code to make a button, click on a >>> cell insertion point, and click the button: >>>> Button[Insert Text+Math Grid, >>> NotebookWrite[InputNotebook[], >>> Cell[BoxData[ >>> FormBox[GridBox[{{Cell[text], [Placeholder]}}], >>> TraditionalForm]], Text]]] >>>> You could turn this button into a palette (Palettes->Generate Palette >>> from Selection) and install it (Palettes->Install Palette...) and use >>> it later (Palettes->) as well. > -- 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: weird escaping problem with StringPattern inside Module[] Hello MathGroup: I am having a strange problem where my code works fine in a Notebook session but acts strangely inside a Module[]. I presume that this is some scoping problem that is currently beyond me. I know how Module[] takes local variables and adds $nnn or something to the variable. It is doing a similar thing to my string pattern and I have no idea how to escape this and disable this behavior. Any help you can provide is greatly appreciated. This code works as expected: parseVars = {abc, def}; text0 = the rain in spain stays mainly...; parsePattern = the ~~ abc__ ~~ in ~~ def__ ~~ stays main -> parseVars; Flatten@StringCases[text0, parsePattern] > {rain, spain} Print[patt=, parsePattern] > patt=the ~~abc__~~ in ~~def__~~ stays main->{abc,def} This is the module containing the exact same logic: getWeather[inputStr_String] := Module[ {parseVars, parsePattern} , parseVars = {abc, def}; parsePattern = the ~~ abc__ ~~ in ~~ def__ ~~ stays main - > parseVars; Print[patt=, parsePattern]; Flatten@StringCases[inputStr, parsePattern] ] This shows the symptom. Notice how the pattern vars are suffixed and hence do not match those in the rhs of StringCases[] with the result being all are no match!?!?! getWeather[text0] > patt=the ~~abc$__~~ in ~~def$__~~ stays main->{abc,def} > {abc, def} TIA. Roger Williams Franklin Laboratory === Subject: Re: ParallelTable[ ] ParallelTable[] take longer, because parallel computing take usual longer than serial one. Since the data must be distributed to the processors and the results must be collected additional to the original work, it must take longer ! You can't do more and expect it will be faster. Jens > Just started looking at the parallel computing. This seems a very good > option for me because any long calculations I have are usually tied to > list manipulation. For background,$ProcessorCount returns 2 on my machine. I tried this command: AbsoluteTiming[ParallelTable[i^2, {i, 1000000}]] The required time was 9.28 s. I followed with this command: AbsoluteTiming[Table[i^2, {i, 1000000}]] The requied time was 0.86 s. So, you can imagine my confusion. Can anyone explain why parallel table > generation took 10 times as long? [Incidentally and perhaps related, the command of Timing[ParallelTable[i^2, > {i, 1000000}]] takes 0.078 s. This leaves me very confused because the > computer obviously take much longer to execute, i.e., I am sitting at my > console for closer to 9.28 s than 0.078 s. The command of Timing[Table[i^2, > {i, 1000000}]] takes 0.875 s. What gives?] Looking forward to everyone's insights! > === Subject: Re: Correction to Fundamental Theorem of Calculus and In[1]:= f[x_]:=Integrate[Sin[t^2],{t,0,x}] In[2]:= D[f[x],x] Out[2]= Sin[x^2] In[3]:= g[x_]:=Integrate[Exp[-t^2],{t,0,x}] In[4]:= D[g[x],x] Out[4]= E^-x^2 In[9]:= $Version Out[9]= 7.0 for Mac OS X x86 (32-bit) (February 18, 2009) 2009/6/12 Len : I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, al= l > works well. Can someone explain the odd behavior? > Len -- Peter Lindsay === Subject: Re: Correction to Fundamental Theorem of Calculus and As Bob Hanlon points out, there is a bug with: Clear[g] g[x_] := Integrate[E^-t^2, {t, 0, x}] g'[x] // Trace I think someone left off the &! But since this is a theorem about functions, we might use Function in the first place: g := Function[x, Integrate[E^-t^2, {t, 0, x}]] g'[x] // Trace which now works. Also, Mathematica can handle the following purely symbolic expression. Implies[F[x] == Integrate[f[t], {t, 0, x}], !(*SuperscriptBox[F, [Prime], MultilineFunction->None])[x] == f[x]] MapAt[D[#, x] &, %, 1] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi Bob: For some reason Mathematica doesn't like the prime notation. (See below). The prime notation does work for the sin (t^2) example. Do you know why this is the case? Len In[1]:= g[x_] := Integrate[E^(-t^2), {t, 0, x}] In[2]:= g'[x] Out[2]= 0 In[3]:= D[g[x], x] Out[3]= E^-x^2 > Works in my version. $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) f[x_] := Integrate[Sin[t^2], {t, 0, x}] D[f[x], x] Sin[x^2] g[x_] := Integrate[Exp[-t^2], {t, 0, x}] D[g[x], x] E^(-x^2) Bob Hanlon I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, al= l > works well. Can someone explain the odd behavior? > Len === Subject: Re: Correction to Fundamental Theorem of Calculus and Hi Bob: For some reason Mathematica doesn't like the prime notation. (See below). The prime notation does work for the sin (t^2) example. Do you know why this is the case? Len In[1]:= g[x_] := Integrate[E^(-t^2), {t, 0, x}] In[2]:= g'[x] Out[2]= 0 In[3]:= D[g[x], x] Out[3]= E^-x^2 > Works in my version. $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) f[x_] := Integrate[Sin[t^2], {t, 0, x}] D[f[x], x] Sin[x^2] g[x_] := Integrate[Exp[-t^2], {t, 0, x}] D[g[x], x] E^(-x^2) Bob Hanlon I define a function (using f[x_]:=) as the definite integral (from 0 > to x) of sin(t^2). When I differentiate using Mathematica I get the > correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral > (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect > answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, al= l > works well. Can someone explain the odd behavior? > Len === Subject: double pentagon bridge graph polygons The idea of adding two more rows of pentagons occurred to me. Vertex types: {n, 2*n, 4*n, 2*n, n} {2, 4, 8, 4, 2}, {3, 6, 12, 6, 3}, {4, 8, 16, 8, 4}, {5, 10, 20, 10, 5}, all pentagons {6, 12, 24, 12, 6}, somewhat like the Buckyball {7, 14, 28, 14, 7}, {8, 16, 32, 16, 8}, {9, 18, 36, 18, 9}, {10, 20, 40, 20, 10} The Euler data are in general: {V,E,F}={10*n, 16*n, 6*n + 2} {30, 48, 20}, {40, 64, 26}, {50, 80, 32}, {60, 96, 38}, {70, 112, 44}, {80, 128, 50}, {90, 144, 56}, {100, 160, 62} I did the Schlegel diagrams for 2 and 3 and they appear to work at least as graphs. The one of immediate interest is {V,E,F}={50, 80, 32} {5, 10, 20, 10, 5}, all pentagons http://www.geocities.com/rlbagulatftn/5_10_20_10_5graph.gif {5, 10, 20, 10, 5} {V,E,F}={50, 80, 32} Not all the pentagons are flat as faces ( so it isn't an ideal Platonic solid), but it exists as a graph. http://www.geocities.com/rlbagulatftn/3_6_12_6_3graph.gif Just like in the Schlegel diagram: {3,6,12,6,3} {V,E,F}={30,48,20} So two of the cases work fine. All the graphs of the pentagon bridge type are here ( single and double): http://www.flickr.com/photos/fractalmusic/sets/72157619727734302/ Mathematica:{30, 48, 20}/{3, 6, 12, 6, 3} << DiscreteMath`GraphPlot`; << DiscreteMath`ComputationalGeometry` << DiscreteMath`Combinatorica` m24 = {{0, 1, 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}, {1, 0, 1, 0, 0, 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}, {1, 1, 0, 0, 0, 0, 0, 1, 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, 1, 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, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 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, 0, 1, 0, 1, 0, 0, 1, 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, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, {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, 1, 0, 0, 1, 0, 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, 1, 1, 1, 0}}; CharacteristicPolynomial[m24, x] NSolve[CharacteristicPolynomial[m24, x] == 0, x] GraphPlot3D[m24] 3 48 30 20 Mathematica:{V,E,F}={50, 80, 32} {5, 10, 20, 10, 5}; << DiscreteMath`GraphPlot`; << DiscreteMath`ComputationalGeometry` << DiscreteMath`Combinatorica` m24 = {{0, 1, 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, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 0, 0, 0, 0, 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, 0, 0, 0}, {0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 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, 0}, {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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}, {1, 0, 0, 0, 0, 0, 1, 0, 0, 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, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 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, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 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, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0}}; CharacteristicPolynomial[m24, x] NSolve[CharacteristicPolynomial[m24, x] == 0, x] GraphPlot3D[m24] 3 80 50 32 === Subject: Re: Evaluating notebooks from other notebooks 1) Cells in the xyz.nb must be mark as InitializationCell (i.e. InitializationCell -> True) 2) In the root.nb: Import[xyz.nb, Initialization] === Subject: Re: Inverse / Laplace Transform Halved Sir, I see that the LT* LT^-1 thing worked but why can't one get just the inverse transform itself? I ask this because I can't get M7 to produce anything other than very simple inverse transforms. In your example: InverseLaplaceTransform[E^(-a Sqrt[s]) s, s, t] just comes back unevaluated. For a while I thought one needed some kind of package loaded but now I think not; I'm now thinking it just doesn't work very well. Am I missing something? Rob === Subject: Trig identity for linear combination of sines Hi: I have a function which is a linear combination of sines, of the form y = a*sin(x+q) + b*sin(x+r) + c*sin(x+t) and I am looking for a trignometric identity that would reduce the above to the form y = A*sin(x+Z) I would also like to find out how to implement this rule in Mathematica. Chelly === Subject: Re: Trig identity for linear combination of sines > Hi: I have a function which is a linear combination of sines, of the form y = a*sin(x+q) + b*sin(x+r) + c*sin(x+t) and I am looking for a trignometric identity that would reduce the > above to the form y = A*sin(x+Z) I would also like to find out how to implement this rule in > Mathematica. Chelly > I do not know of any such trigonometric identity, and I think it would have to be pretty complicated. However, you can use Mathematica to find A and Z. First consider the functions ff[x_] := a Sin[x + q] + b Sin[x + r] + c Sin[x + t] and gg[x_] := A Sin[x + Z] where a,b,c, q,r,t, A Z are some real numbers. Both of these are analytic functions. Suppose, for given a,b,c, q,r,t we find A and Z such that these two equations hold: eq1 = ff[0] == gg[0] a*Sin[q] + b*Sin[r] + c*Sin[t] == A*Sin[Z] and eq2 = ff'[0] == gg'[0] a*Cos[q] + b*Cos[r] + c*Cos[t] == A*Cos[Z] You can easily convince yourself that in this case the n-th derivative of ff at 0 must equal the n-th derivative of gg at 0, since the derivatives of order (n+2) are simply the derivatives of order n, or - derivatives of order n. So as long as eq1 and eq2 hold the functions will have equal derivatives of all orders at 0. But since both ff and gg are analytic functions everywhere in the complex plane they are determined by their derivatives at 0, and so they must be equal. So we only need to solve eq1 and eq 2. Reduce[{eq1, eq2}, {A, Z}] will now give you a complete solution (which is not unique). You can get a simpler looking (but complete) answer by using; Simplify[{A, Z} /. Last[Solve[{eq1, eq2}, {A, Z}]]] {(Sqrt[a^2 + 2*a*b*Cos[q - r] + 2*a*c*Cos[q - t] + b^2 + 2*b*c*Cos[r - t] + c^2]* Sqrt[(a*Cos[q] + b*Cos[r] + c*Cos[t])^2])/(a*Cos[q] + b*Cos[r] + c*Cos[t]), ArcCos[Sqrt[(a*Cos[q] + b*Cos[r] + c*Cos[t])^2]/ Sqrt[ a^2 + 2*a*b*Cos[q - r] + 2*a*c*Cos[q - t] + b^2 + 2*b*c*Cos[r - t] + c^2]]} Note that some conditions need to be satisfied for these to be valid. Reduce gives you all the conditions. Andrzej Kozlowski === Subject: Re: Trig identity for linear combination of sines > Hi: I have a function which is a linear combination of sines, of the form y = a*sin(x+q) + b*sin(x+r) + c*sin(x+t) and I am looking for a trignometric identity > that would reduce the above to the form y = A*sin(x+Z) I would also like to find out how to implement this rule in Mathematica. Chelly Collect[TrigExpand[ a*Sin[x+q] + b*Sin[x+r] + c*Sin[x+t] ], {Cos[x], Sin[x]} ] /. Sin[x]*A_ + Cos[x]*B_ -> Sqrt[A^2 + B^2] * Sin[x + ArcTan[A,B]] Sqrt[(a*Cos[q] + b*Cos[r] + c*Cos[t])^2 + (a*Sin[q] + b*Sin[r] + c*Sin[t])^2] * Sin[x + ArcTan[a*Cos[q] + b*Cos[r] + c*Cos[t], a*Sin[q] + b*Sin[r] + c*Sin[t]]] === Subject: Re: ParallelTable[ ] Jens, into any attempts at parallel computing. I was imagining that ParallelTable[i^2, {i, 1000000}]] might be broken down to two processors, e.g., one processor takes items 1 to 500000 and the other processor takes items 500001 to 1000000. I am thinking that the overall computation should therefore be roughly twice as fast (after taking into account some time costs associated with reconstructing a unified list when the two processors report back, plus some general inefficiency in distribution of the problem (i.e., probably not best to put 500000 on each processor for an i^2 problem)). I think you're saying in the email below that the overhead from reconstructing a unified list exceeds the gain from distribution across two processors. So, if a seemingly straightforward divide-and-conquer problem does not speed up, what are the kinds of problems that ParrallelTable is good at and helps with? Scot ParallelTable[] take longer, because parallel computing take > usual longer than serial one. Since the data must be distributed > to the processors and the results must be collected additional > to the original work, it must take longer ! You can't do more > and expect it will be faster. Jens > Just started looking at the parallel computing. This seems a very good >> option for me because any long calculations I have are usually tied to >> list manipulation. >> For background,$ProcessorCount returns 2 on my machine. >> I tried this command: >> AbsoluteTiming[ParallelTable[i^2, {i, 1000000}]] >> The required time was 9.28 s. >> I followed with this command: >> AbsoluteTiming[Table[i^2, {i, 1000000}]] >> The requied time was 0.86 s. >> So, you can imagine my confusion. Can anyone explain why parallel table >> generation took 10 times as long? >> [Incidentally and perhaps related, the command of Timing[ParallelTable[i^2, >> {i, 1000000}]] takes 0.078 s. This leaves me very confused because the >> computer obviously take much longer to execute, i.e., I am sitting at my >> console for closer to 9.28 s than 0.078 s. The command of Timing[Table[i^2, >> {i, 1000000}]] takes 0.875 s. What gives?] >> Looking forward to everyone's insights! > > === Subject: Re: ParallelTable[ ] Can't check it now since I am currently working a single core laptop which uses 1.7 and 1.6 seconds for these calculations, respectively. Since parallel computing will have some overhead for interprocess communication (initialisation, data transport etc.) you will need a computation that takes really long so that the overhead is small compared to that. Try to increase the length of the table by a factor of 100. Actually, I think you'll gain most if every computational step takes longer than just the evaluation of i^2. Try something like an integration or a simplication of something non-trivial. Some time is spend in generating the output (and suppressing it, as it is too long). This is the reason between the Timing and AbsoluteTiming timings. Timing just gives you the amount of CPU time spend by the kernel in actual calculations whereas AbsoluteTiming also takes into account the time the frontend spends in displaying stuff. > Just started looking at the parallel computing. This seems a very good > option for me because any long calculations I have are usually tied to > list manipulation. For background,$ProcessorCount returns 2 on my machine. I tried this command: AbsoluteTiming[ParallelTable[i^2, {i, 1000000}]] The required time was 9.28 s. I followed with this command: AbsoluteTiming[Table[i^2, {i, 1000000}]] The requied time was 0.86 s. So, you can imagine my confusion. Can anyone explain why parallel table > generation took 10 times as long? [Incidentally and perhaps related, the command of Timing[ParallelTable[i^= 2, > {i, 1000000}]] takes 0.078 s. This leaves me very confused because the > computer obviously take much longer to execute, i.e., I am sitting at my > console for closer to 9.28 s than 0.078 s. The command of Timing[Table[i^= 2, > {i, 1000000}]] takes 0.875 s. What gives?] Looking forward to everyone's insights! === Subject: Re: Combined Set, SetDelayed > 0.811 seconds. The second version, using the function that remembers > values, took only 1.87003*10^-15 seconds. The frequency of visible light is around 3*10^14 Hz, so that's around one period of a visible light wave. Is there maybe a typo here? === Subject: Re: Combined Set, SetDelayed > Helen Read > 0.811 seconds. The second version, using the function that remembers >> values, took only 1.87003*10^-15 seconds. The frequency of visible light is around 3*10^14 Hz, so that's around > one period of a visible light wave. Is there maybe a typo here? No, no typo. Not sure what your point is. -- Helen Read University of Vermont === Subject: Re: need a help I wonder what you mean with mathematica basically v6 upgraded to v7. As far as I know new versions of Mathematica are never installed as an update to a previous version (in the sense of patching existing code). So, did you merge v6 and v7 files or so? > hi! > I got an error code: 557 I tried to reinstall again my copy: no result 1-mathematica basically v6 upgraded to v7 > 2-platform :W Vista the info that I get is: there was a syntax error in the LinkSetup file > c:users packard appData Roaming Mathematica FrontEnd init.m what to do? > dr albert haccoun > france === Subject: Re: RandomReal gets stuck >> The issue is, that subFunction makes not Subscript[a,i] but >> SubscriptBox[a,i], so if you enter (I use LaTeX form here to mark the >> subscripted a) >> True >> It's really great! > I do not understand what you mean. Your code gives > Out[5]= False Forgive me. I used LaTeX form. a_1 meant: type a then Ctrl- then 1. I apologize for misusing Blank. -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: a graph problem-> heptagon analog to the dodecahedron http://www.flickr.com/photos/fractalmusic/sets/72157619727734302/ Mathematica: << DiscreteMath`GraphPlot`; << DiscreteMath`ComputationalGeometry` << DiscreteMath`Combinatorica` m28 = {{0, 1, 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}, {1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0}, { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 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, 0, 1, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0}} CharacteristicPolynomial[m28, x] NSolve[CharacteristicPolynomial[m28, x] == 0, x] GraphPlot3D[m28] .89ª°Graph:<[InvisibleSpace]42[InvisibleSpace], [InvisibleSpace]28[InvisibleSpace], [InvisibleSpace] Undirected[InvisibleSpace]>.89ª° .89ª°Graphics.89ª° 3 42 28 16 === Subject: Re: Presentation quick with If menu commands worked on palettes, then there would constant confusion when you're using the palette. Which menu commands work on palettes and which don't? What if typing went to one notebook but the File->Save menu command worked on a completely different notebooK? Should File->Print be allowed to print palettes...if so, how much frustration and wasted paper would it cause, and if not, why should it be different from File->Save? Or what if you could get yourself into a mode where typing and many menu commands didn't work at all (i.e. because palettes aren't generally editable)? The current system isn't the most convenient for developers of palettes. But it greatly reduces confusion for users of palettes, and there are many more palette users than palette developers. For palette users, the current system is very consistent. The only menu commands which work directly on palettes are geared directly toward palettes...for example, Generate Notebook from Palette. When I develop palettes, incidentally, I never use Generate Palette from Selection. CreatePalette[] returns a notebook expression which I can operate with directly. Since I create palettes that I might want to be able to alter slightly in the future, it's much more reproducible to create an entire program which, from start to finish, creates the palette and deploys it (saving it in the process when I so wish). This makes it very easy to reliably make small changes without accidental fumbling producing spoiled palettes which need to be redone. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > Of course! When I selected Install Palette, the pop-up dialog asked for > a source, and I forgot that the source file could be an open notebook > and not necessarily a notebook previously saved. The issue remains, however, about saving a palette once you create it > with Generate Palette from Selection. It just seems to me that one > should not have to go through all the fuss of seeing the list of values > of Notebooks[], picking the relevant one nb, and finally using > NotebookSave[nb]. What is the rationale for the design decision not to allow, by default, > using File->Save or File->Save As directly upon such a created palette? > There is no missing step. Palettes->Install Palette..., which I >> mention below, >> installs a copy of the palette into the right location so that it will >> be found >> in the Palettes menu. It does so by saving a copy of the palette in >> the right >> directory with the name you specify, and then immediately regenerating >> the menus >> so that you don't have to quit/restart to see the results. >> John Fultz >> jfultz@wolfram.com >> User Interface Group >> Wolfram Research, Inc. >>> There's a step missing below: how to save the palette after using >>> Palettes->Generate Palette from Selection ! >>>> This issue has arisen before in MathGroup. I know there's an answer, >>> and >>> I could probably again reconstruct it or find it by a search, but the >>> difficulty indicates that there's a design gap in Mathematica in such >>> situations. It just should not be that non-obvious. >>>>>>> ... evaluate this code to make a button, click on a >>>> cell insertion point, and click the button: >>>>>> Button[Insert Text+Math Grid, >>>> NotebookWrite[InputNotebook[], >>>> Cell[BoxData[ >>>> FormBox[GridBox[{{Cell[text], [Placeholder]}}], >>>> TraditionalForm]], Text]]] >>>>>> You could turn this button into a palette (Palettes->Generate >>>> Palette >>>> from Selection) and install it (Palettes->Install Palette...) and >>>> use >>>> it later (Palettes->) as well. === Subject: FITS format and Mathematica 6 I am very puzzled by the way Mathematica imports and exports data in FITS format, I hope that somebody could give some guidance here. I work with data in FITS format. For some reason, in the first release of Math 6 apparently there were no way of getting the full header of an image. This was fixed in the 6.0.2 version which I have now (I=B4m not sure about the numeration) with the Metadata option in Import, option that it is documentated only in the webpage, not in my Documentation Center. Well, whatever, going to my question: How can I write a fits file with my own header? This does not work: header=Import[file1.fits,Metadata]; data=Table[0.,{10},{10}]; Export[test.fits,data,Metadata->header] where the variable header is the Metadata of another fits file Actually, I can not export any fits file with a header different respect to the default one. (You can examine the header of a fits file in a text editor) Maybe Metadata is not an Element of the file..?? but: Import[file1.fits,Elements] {Airmass, Author, BitDepth, ColorSpace, Comments, Data, DataType, Declination, Device, Equinox, ExposureTime, Graphics, History, HourAngle, ImageSize, Metadata, Range, RawData, Reference, RightAscension, SiderealTime, TableData, TableHeaders, TableUnits, Telescope} Atte. Andres Guzman $Version 6.0 for Microsoft Windows (32-bit) (February 7, 2008) $System ps. by the way, these features where handled (not very neatly, but effectively) in version 5.2 with ConversionOptions->{Verbose->True} ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. === Subject: Re: How to use R within Mathematica For my own personal use, or for non-commercial academic use, I do not find the listed cost of RLink as very reasonable -- especially given that some of its crucial functionality can be achieved for free using the sort of code that Eric Neuwirth posted in this group (). > RLink is readily available at http://www.scienceops.com/Rlink2.asp However it is not a free application.... though its cost is very > reasonable.... Hope this helps. --David http://scientificarts.com/worklife -- 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: Extracting contour values from ContourPlot After trying for a while to get the contour line 1 to be shown for 0 lbl ? Jens === Subject: Re: Extracting contour values from ContourPlot You can use the option ContourLabels -> All to label the contours. A legend such as in multiple-line plots doesn't make sense for contour plots as it would require every contour line to be distinct (with varying colors and/or dashing) which woulde be dead ugly. > I have spent an hour researching this group and online, with no > definitive answer. The problem: I have an nxm matrix of z values that I want to plot with > List(Contour|Density)Plot together with a legend that shows the > *actual* values of the contours used in the plot. (Seems like a pretty > basic thing to me....). I know how to draw a nice legend, that's not > the problem. I have found a way to do it: I can specify the contours and plot range > explicitly. But what I really want is not to have to do this, and rely > on the semi-intelligent mechanism of Mathematica to pick an appropriate n= umber > of contours and their values, THEN use those to draw the legend. It seems that there is no way to do this. That is, there is no way to > extract the actual contour values used in the plot. I found a > ColorBarPlot package which however does not work in Mathematica 7: > Is it really not possible to do > this? === Subject: Re: Extracting contour values from ContourPlot On Jun 14, 4:08 pm, Sjoerd C. de Vries All to label the contours. A > legend such as in multiple-line plots doesn't make sense for contour > plots as it would require every contour line to be distinct (with > varying colors and/or dashing) which woulde be dead ugly. > No. Because of the shading of the contours, it is easy to identify each contour line, they do not need to be distinct. Perhaps I wasn't very clear in my OP. I know I can label the contour lines WITHIN the plot. That's NOT what I want. (The reason is that the plot I want to make gets then transformed into a ring). What I want is a separate legend with the contour values. === Subject: Re: Extracting contour values from ContourPlot plt = ContourPlot[Cos[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}]; and Cases[plt, _Tooltip, Infinity] /. Tooltip[_, lbl_] :> lbl ? Jens > I have spent an hour researching this group and online, with no > definitive answer. The problem: I have an nxm matrix of z values that I want to plot with > List(Contour|Density)Plot together with a legend that shows the > *actual* values of the contours used in the plot. (Seems like a pretty > basic thing to me....). I know how to draw a nice legend, that's not > the problem. I have found a way to do it: I can specify the contours and plot range > explicitly. But what I really want is not to have to do this, and rely > on the semi-intelligent mechanism of Mathematica to pick an appropriate number > of contours and their values, THEN use those to draw the legend. It seems that there is no way to do this. That is, there is no way to > extract the actual contour values used in the plot. I found a > ColorBarPlot package which however does not work in Mathematica 7: > Is it really not possible to do > this? > === Subject: Re: Extracting contour values from ContourPlot On Jun 14, 4:06 pm, Jens-Peer Kuska plt = ContourPlot[Cos[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}]; and Cases[plt, _Tooltip, Infinity] /. Tooltip[_, lbl_] :> lbl ? Jens > Perhaps I wasn't very clear. I know I can label the lines inside the plot. That's not what I want. I want a separate legend. === Subject: Re: weird escaping problem with StringPattern inside Module[] I would use a RegularExpression, which is not relying on any variables. But, staying in your approach, this works as you expect: getWeather[inputStr_String]:= Module[{parseVars,parsePattern,abc,def}, parseVars={abc,def}; parsePattern=the ~~ Pattern[Evaluate[parseVars[[1]]],BlankSequence[]]~~ in ~~ Pattern[Evaluate[parseVars[[2]]],BlankSequence[]]~~ stays mainly -> parseVars; Print[patt=,parsePattern]; Flatten@StringCases[inputStr,parsePattern] ] It is not very clean, but I hope it may help. ADL > Hello MathGroup: I am having a strange problem where my code works fine in a Notebook > session but acts strangely inside a Module[]. I presume that this is > some scoping problem that is currently beyond me. I know how Module[] takes local variables and adds $nnn or something > to the variable. It is doing a similar thing to my string pattern and > I have no idea how to escape this and disable this behavior. Any help you can provide is greatly appreciated. > ... > Roger Williams > Franklin Laboratory === Subject: Re: weird escaping problem with StringPattern inside Module[] try getWeather[inputStr_String] := Block[{parseVars, parsePattern}, parseVars = {abc, def}; parsePattern = the ~~ abc__ ~~ in ~~ def__ ~~ stays main -> parseVars; Print[patt=, parsePattern]; Flatten@StringCases[inputStr, parsePattern]] Jens > Hello MathGroup: I am having a strange problem where my code works fine in a Notebook > session but acts strangely inside a Module[]. I presume that this is > some scoping problem that is currently beyond me. I know how Module[] takes local variables and adds $nnn or something > to the variable. It is doing a similar thing to my string pattern and > I have no idea how to escape this and disable this behavior. Any help you can provide is greatly appreciated. This code works as expected: parseVars = {abc, def}; > text0 = the rain in spain stays mainly...; > parsePattern = the ~~ abc__ ~~ in ~~ def__ ~~ stays main - parseVars; > Flatten@StringCases[text0, parsePattern] >> {rain, spain} > Print[patt=, parsePattern] >> patt=the ~~abc__~~ in ~~def__~~ stays main->{abc,def} > This is the module containing the exact same logic: getWeather[inputStr_String] := Module[ > {parseVars, parsePattern} > , parseVars = {abc, def}; > parsePattern = the ~~ abc__ ~~ in ~~ def__ ~~ stays main - >> parseVars; > Print[patt=, parsePattern]; > Flatten@StringCases[inputStr, parsePattern] > ] This shows the symptom. Notice how the pattern vars are suffixed and > hence do not match those in the rhs of StringCases[] with the result > being all are no match!?!?! getWeather[text0] >> patt=the ~~abc$__~~ in ~~def$__~~ stays main->{abc,def} >> {abc, def} TIA. > Roger Williams > Franklin Laboratory > === Subject: Re: Extracting contour values from ContourPlot data = Table[Sin[i + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}]; Select[Options[ListContourPlot], ! StringFreeQ[ToString[#], Labels] &] {ContourLabels -> Automatic} ListContourPlot[data, ContourLabels -> True] Bob Hanlon I have spent an hour researching this group and online, with no definitive answer. The problem: I have an nxm matrix of z values that I want to plot with List(Contour|Density)Plot together with a legend that shows the *actual* values of the contours used in the plot. (Seems like a pretty basic thing to me....). I know how to draw a nice legend, that's not the problem. I have found a way to do it: I can specify the contours and plot range explicitly. But what I really want is not to have to do this, and rely on the semi-intelligent mechanism of Mathematica to pick an appropriate number of contours and their values, THEN use those to draw the legend. It seems that there is no way to do this. That is, there is no way to extract the actual contour values used in the plot. I found a ColorBarPlot package which however does not work in Mathematica 7: Is it really not possible to do this? === Subject: Re: mergeSort with ReplaceRepeated Well, it is not really an homework. I'm trying to understand Mathematica, and now I want to learn the replacerepeated mechanism. Googling around, I found some exercises, and one is to make a mergesort function using replacerepeated, and that was my question. -- Luca Bedogni 2009/6/15 Sjoerd C. de Vries I guess that given the code below you haven't learned enough of the > Mathematica language to come even close to solving it. Since it is not the goal of this group to make your homework, I can > only advise you to learn the basics using the documentation included > with Mathematica before you endeavour in the more complicated stuff. The code below doesn't work for one thing because it doesn't contain > an actual function definition. This is usually done using Set (=) or > SetDelayed (:=). Look them up in the documentation. > Hi > I'm writing an implementation of mergesort using replacerepeated. > This is actually the code: > merge[{a1, arest___}, b : {b1, ___}] /; a1 >= b1 //. {merge[a1, arest, = > b1] > :> merge[b1, a1, arest] }; > but it doesn't work, and I don't know why, because I'm really new to > Mathematica. Any clue? -- > Luca Bedogni > === Subject: Re: mergeSort with ReplaceRepeated Judging from your June 6 post, this is a homework assignment of yours. I guess that given the code below you haven't learned enough of the Mathematica language to come even close to solving it. Since it is not the goal of this group to make your homework, I can only advise you to learn the basics using the documentation included with Mathematica before you endeavour in the more complicated stuff. The code below doesn't work for one thing because it doesn't contain an actual function definition. This is usually done using Set (=) or SetDelayed (:=). Look them up in the documentation. > Hi > I'm writing an implementation of mergesort using replacerepeated. > This is actually the code: > merge[{a1, arest___}, b : {b1, ___}] /; a1 >= b1 //. {merge[a1, arest, = b1] > :> merge[b1, a1, arest] }; > but it doesn't work, and I don't know why, because I'm really new to > Mathematica. Any clue? -- > Luca Bedogni === Subject: Re: Presentation quick with grid and pasted I understand the larger point here. But there's just one part of the rationale I don't understand: Shouldn't File->Save save the currently selected notebook, even if it's a palette? > If menu commands worked on palettes, then there would constant confusion > when you're using the palette. Which menu commands work on palettes and > which don't? What if typing went to one notebook but the File->Save menu > command worked on a completely different notebooK? Should File->Print be > allowed to print palettes...if so, how much frustration and wasted paper > would it cause, and if not, why should it be different from File->Save? > Or what if you could get yourself into a mode where typing and many > menu commands didn't work at all (i.e. because palettes aren't generally > editable)? The current system isn't the most convenient for developers of > palettes. But it greatly reduces confusion for users of palettes, and > there are many more palette users than palette developers. For palette users, the current system is very consistent. The only > menu commands which work directly on palettes are geared directly toward > palettes...for example, Generate Notebook from Palette. When I develop palettes, incidentally, I never use Generate Palette > from Selection. CreatePalette[] returns a notebook expression which I > can operate with directly. Since I create palettes that I might want to > be able to alter slightly in the future, it's much more reproducible to > create an entire program which, from start to finish, creates the palette > and deploys it (saving it in the process when I so wish). This makes > it very easy to reliably make small changes without accidental fumbling > producing spoiled palettes which need to be redone. > John Fultz > jfultz@wolfram.com > User Interface Group > Wolfram Research, Inc. >> Of course! When I selected Install Palette, the pop-up dialog asked for >> a source, and I forgot that the source file could be an open notebook >> and not necessarily a notebook previously saved. >> The issue remains, however, about saving a palette once you create it >> with Generate Palette from Selection. It just seems to me that one >> should not have to go through all the fuss of seeing the list of values >> of Notebooks[], picking the relevant one nb, and finally using >> NotebookSave[nb]. >> What is the rationale for the design decision not to allow, by default, >> using File->Save or File->Save As directly upon such a created palette? >>> There is no missing step. Palettes->Install Palette..., which I >>> mention below, >>> installs a copy of the palette into the right location so that it will >>> be found >>> in the Palettes menu. It does so by saving a copy of the palette in >>> the right >>> directory with the name you specify, and then immediately regenerating >>> the menus >>> so that you don't have to quit/restart to see the results. >>>>>> John Fultz >>> jfultz@wolfram.com >>> User Interface Group >>> Wolfram Research, Inc. >>>>>> There's a step missing below: how to save the palette after using >>>> Palettes->Generate Palette from Selection ! >>>>>> This issue has arisen before in MathGroup. I know there's an answer, >>>> and >>>> I could probably again reconstruct it or find it by a search, but the >>>> difficulty indicates that there's a design gap in Mathematica in such >>>> situations. It just should not be that non-obvious. >>>>>>>>>>> ... evaluate this code to make a button, click on a >>>>> cell insertion point, and click the button: >>>>>>>> Button[Insert Text+Math Grid, >>>>> NotebookWrite[InputNotebook[], >>>>> Cell[BoxData[ >>>>> FormBox[GridBox[{{Cell[text], [Placeholder]}}], >>>>> TraditionalForm]], Text]]] >>>>>>>> You could turn this button into a palette (Palettes->Generate >>>>> Palette >>>>> from Selection) and install it (Palettes->Install Palette...) and >>>>> use >>>>> it later (Palettes->) as well. -- 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: Parallelize and Symbolic computation Jens, I'm not sure I agree with your statements; whilst parallel computing does introduce over head, in terms of process communication, depending on how the problem is split, multiple machines should surely offer increased resource for memory and CPU. Returning the result to a single process is an interesting problem though, but without knowing how the Parallel arch works in Mathematica I've really no idea. This is however a little to abstract for me. The documentation of parallelize says expressions like Parallelize[Integrate[1/(x - 1), x]] cannot be 'parallelized', so I'm guessing D[] is also out. David, the 64-bit isn't an approach I can use at the moment due to licensing, but I'll try and break down the problem, see if the group can point out the error of my ways. Essentially, I've a system of ODEs (12 states in all) I'm only observing (measuring) a single state so have a single output (y(t)) that I'd like to produce a Taylor series expansion of (for those that are interested I'm trying to determine the identifiability of the system parameters) My normal way of getting the Taylor series co-effs is brute force, e.g. given a system S1'[t_]:=-p2*S1[t]*S2[t]+p1*S1[t] ... S2'[t_]:= p2*S1[t]*S2[t]-p2*S1[t] ... ... Send'[t] := -k7*Send[t]*S1[t] ... Define the output y[t_] := {Send[t]} Then trundle along getting the derivatives y[0] yDer=D[y[t],t] yDer2=D[yDer,t] ... For the problem I'm currently working with, the 12 state-system, this runs out of memory by the 5th Taylor series coeff and I need a few more. I hope this makes sense, any help or suggestions would be much appreciated. John -----Original Message----- === Subject: Re: Parallelize and Symbolic computation > Hi All, I apologies if this is an idiotic question. Essentially, I've a complex > Taylor series expansion that keeps running out of memory and as I've > upgraded to Mathematica 7 of late, and we've a few machines idling away, I > was wondering if the parallel stuff could help. The documentation for Parallel Tools hints that it's only applicable for > numeric problems, but doesn't state that symbolic is out of the question. At a recent Mathematica demo I went to recently it was suggested that the > parallel architecture didn't exclude all symbolic calculations. Has anyone > seen any documentation on this? Or have any experience of it? > JHatt The parallelize mechanism in 7, works by starting extra kernels, that can each do any calculation they want, but I can't quite see how that will help you with your calculation. It might be an idea to post the problem, because if there is a way round your difficulty, someone here will suggest it! Memory problems can be greatly eased by moving to a 64-bit architecture. Many modern computers are already 64-bit capable, and in that case, all that is needed is to change to a 64-bit operating system and re-install Mathematica. However, I'd start by posting your actual problem if possible. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Generic nested menus implementation I have played around with your initial idea also, and appended is what I came up with... hth, albert (* START OF CODE *) (* just a little helper *) ClearAll@toLabel; toLabel[s_String] := s; toLabel[s_String -> l_List] := s; toLabel[s_String :> _] := s; (* the heart of the code: recursive definition of the action menues *) ClearAll@createNextLevel; SetAttributes[createNextLevel, HoldFirst]; Options[createNextLevel] = Flatten[{ Options[ActionMenu], AppearanceWrapper -> Row, DefaultLabels -> {} }]; createNextLevel[{levels_, stack_}, label_String, action_, opts : OptionsPattern[]] := ( Do[levels[i] =., {i, Length[stack] + 1, Max[DownValues[levels][[All, 1, 1, 1]]]}]; action[stack] ); createNextLevel[{levels_, stack_}, label_String :> myaction_, action_, opts : OptionsPattern[]] := ( Do[levels[i] =., {i, Length[stack] + 1, Max[DownValues[levels][[All, 1, 1, 1]]]}]; myaction ); createNextLevel[{levels_, stack_}, label_String -> items_List, action_, opts : OptionsPattern[]] := With[{ defaultlabel = Function[ Which[ Length[#] >= Length[stack] + 1, #[[Length[stack] + 1]], Length[#] > 0, Last[#], True, Choose ] ][OptionValue[DefaultLabels]] }, Do[levels[i] =., {i, Length[stack] + 1, Max[DownValues[levels][[All, 1, 1, 1]]]}]; levels[Length[stack]] = With[{i = Length[stack] + 1}, ActionMenu[ Dynamic[ If[Length[stack] >= i, stack[[i]], defaultlabel] ], Map[ toLabel[#] :> ( stack = Append[Take[stack, i - 1], toLabel[#]]; createNextLevel[{levels, stack}, #, action, opts]; ) &, items ], FilterRules[Flatten@{opts}, Options[ActionMenu]] ] ] ]; (* main function to call *) ClearAll@nestedActionMenu Options[nestedActionMenu] = Flatten[{ AppearanceWrapper -> Row, DefaultLabels -> {}, Options[ActionMenu] }]; nestedActionMenu[items_List, action_: None, opts : OptionsPattern[]] := With[{ defaultlabel = Function[If[Length[#] > 0, #[[1]], Choose]][ OptionValue[DefaultLabels]] }, DynamicModule[{ levels, stack = {} }, levels[0] = ActionMenu[ Dynamic[If[Length[stack] > 0, stack[[1]], defaultlabel]], Map[ toLabel[#] :> ( stack = {toLabel[#]}; createNextLevel[{levels, stack}, #, action, opts]) &, items ], FilterRules[Flatten@{opts}, Options[ActionMenu]] ]; Column[{ Dynamic[OptionValue[AppearanceWrapper][ Table[ levels[i], {i, 0, Max[DownValues[levels][[All, 1, 1, 1]]]}] ]] }] ] ]; (* END OF CODE *) (* simple example usage, with the default there are no actions! *) nestedActionMenu[{ Africa -> { Algeria -> {Algiers, Oran}, Angola -> {Luanda, Huambo} }, North America -> { United States -> {New York, Washington}, Canada -> {Toronto, Montreal} } } ] (* example with actions, they can be given globaly or locally for each entry *) Deploy@nestedActionMenu[{ Africa -> { Algeria -> {Algiers, Oran}, Angola -> {Luanda, Huambo} }, North America -> { United States -> {New York, Washington}, Canada -> {Toronto, Montreal :> Print[Monteral is special!]} } }, Print, DefaultLabels -> {Continent, Country, City} ] (* somewhat more involved example,menu definition is created programmatically from CountryData and CityData, watch out,this will not work well when ContryData and CityData are not yet initialized and will take a while to finish *) menuDefinition = Map[ Function[cont, cont -> Map[ # -> CountryData[#, LargestCities][[All, 1]] &, CountryData[cont] ] ], DeleteCases[CountryData[Continents], Antarctica] ]; (* example for a more interesting global action *) cityinfo[{continent___, country_, city_}] := CreateDialog[{ Grid[{ {Style[city, Section], Show[CountryData[country, Flag], ImageSize -> 50]}, {continent, country}, {Population, CityData[city, Population]}, {Elevation, CityData[city, Elevation]} }, Alignment -> {{Left, Right}, Automatic}], DefaultButton[] }] (* check that the global action works: *) cityinfo[{Europe, Switzerland, Zurich}] (* now we are ready to install the nested action menu in a menu bar, we use the option AppearanceWrapper for further formatting... *) SetOptions[EvaluationNotebook[], DockedCells -> { Cell[BoxData[ToBoxes[Button[City Information, CreateDialog[{ExpressionCell[Panel[ nestedActionMenu[ menuDefinition, (DialogReturn[]; cityinfo[#]) &, Appearance -> None, AppearanceWrapper -> Function[ Grid[{#}, Alignment -> Left, Dividers -> All, FrameStyle -> LightGray, ItemSize -> {10, 1}]], DefaultLabels -> {Continent, Country, City} ], ImageMargins -> 0, FrameMargins -> 0 ], CellMargins -> {{0, 0}, {0, 0}} ]}, WindowMargins -> { {MousePosition[ScreenAbsolute][[1]], Automatic}, {Automatic, MousePosition[ScreenAbsolute][[2]] - 40}}, WindowFrame -> Frameless, CellMargins -> 0, CellFrameMargins -> 0, WindowSize -> FitAll ], Appearance -> None ] ]], DockedCell ] } ] === Subject: Re: Generic nested menus implementation Hi all, a quick follow - up: There is a bug in the function that returns the positions of the locally maximal numbers in a list. Here is a better (and hopefully correct) version: Clear[localMaxPositions]; localMaxPositions[lst_List] := Part[#, All, 2] &@ ReplaceList[ MapIndexed[List, lst], {___, {x_, _}, y : {t_, _} .., {z_, _}, ___} /; x < t && z < t :> y]; Sorry for this. Leonid > Hi all, since already two people asked for this feature, and I got interested > myself, I assume that this topic may be of general interest, and this is my > reason to start a separate thread. Here I present my first attempt at > generic multilevel menu implementation. The code is probably full of bugs, > and also perhaps many parts could be done easier but I just did not figure > it out, so I will appreciate any feedback. The examples of use follow. THE CODE > ----------------------------------------------------------------------------- ------------------------------------------ (* checking recursive pattern *) Clear[menuTreeValidQ]; > menuTreeValidQ[{_String, {___String}}] := True; > menuTreeValidQ[item_] := MatchQ[item, {_String, {___?menuTreeValidQ} ..}]; (* This can probably be done much better *) Clear[localMaxPositions]; > localMaxPositions[ls_List] := > Module[{n = 0, pos, part}, > pos = Position[part = Split[Partition[ls, 3, 1], Last[#1] == First[#2] > &], > x_ /; MatchQ[x, {{s_, t_, u_}} /; s <= t && u <= t] || > MatchQ[x, {{s_, t_, _}, ___, {_, u_, p_}} /; s <= t && u >= p]]; > List /@ Flatten[Fold[ > Function[{plist, num}, n++; > Join[plist[[1 ;; n - 1]], Range[plist[[n]], plist[[n]] + num - 1], > plist[[n + 1 ;;]] + num - 1]], pos, Length /@ Extract[part, pos]] + 1]]; > (* By leaves I here mean, for every branch, those with locally > largest distance from the stem. Level would not do *) Clear[leafPositions]; > leafPositions[tree_] := > Extract[#, localMaxPositions[Length /@ #]] &@ > Reap[MapIndexed[Sow[#2] &, tree , Infinity]][[2, 1]]; > Clear[mapOnLeaves]; > mapOnLeaves[f_, tree_] := MapAt[f, tree, leafPositions[tree]]; > Clear[replaceByEvaluated]; > replaceByEvaluated[expr_, patt_] := > With[{pos = Position[expr, patt]}, > With[{newpos = > Split[Sort[pos, Length[#1] > Length[#2] &], > Length[#1] == Length[#2] &]}, > Fold[ReplacePart[#1, Extract[#1, #2], #2, List /@ Range[Length[#2]]] &, > expr, newpos]]]; > (* converts initial string-based menu tree into more complex expression > suitable for menu construction *) Clear[menuItemsConvertAlt]; > menuItemsConvertAlt[menuitemTree_, menuMakers : {(_Symbol | _Function) ..}, > actionF_, representF_: (# &), representLeavesF_: (# &)] := > Module[{g, actionAdded, interm, maxdepth, actF}, > actionAdded = > &, > menuitemTree]; > interm = > MapIndexed[ > Replace[#, {x_String, y : ({({_RuleDelayed} | _RuleDelayed) ..})} : representF[x, {Length[#2]/2}] :> g[Length[#2]/2][x, Flatten@y], > 1] &, {actionAdded}, Infinity]; > interm = > Fold[replaceByEvaluated, > interm, {_Replace, HoldPattern[# &[__]], HoldPattern[Length[{___}]], > HoldPattern[Times[_Integer, Power[_Integer, -1]]], _Flatten}][[1, 2]]; > maxdepth = Max[Cases[interm, g[x_] :> x, Infinity, Heads -> True]]; > With[{fns = menuMakers}, > replaceByEvaluated[interm /. g[n_Integer] :> menuMakers[[n]], > HoldPattern[fns[[_Integer]]]] /. actF :> actionF > ] /; maxdepth <= Length[menuMakers]] > (* main menu-building function *) Clear[createNestedMenu]; > createNestedMenu::invld = The supplied menu tree structure is not valid; createNestedMenu[menuItemTree_, ___] /; Not[menuTreeValidQ[menuItemTree]] > := never happens /; Message[createNestedMenu::invld]; createNestedMenu[menuItemTree_?menuTreeValidQ, menuCategories_, actionF_, > representF_: (# &), representLeavesF_: (# &)] := Module[ > {menuVars, menuNames, menuDepth = Depth[Last@menuItemTree]/2, > setHeld, setDelayedHeld, heldPart, subBack, subBackAll, makeSubmenu, > addSpaces, menuCategs = menuCategories, standardCategory = Choose > }, Options[makeSubmenu] = {Appearance -> Button, > FieldSize -> {{1, 8}, {1, 4}}, Background -> Lighter[Yellow, 0.8], > BaseStyle -> {FontFamily -> Helvetica, FontColor -> Brown, > FontWeight -> Plain}}; menuCategs = PadRight[menuCategs, menuDepth + 1, standardCategory]; (* Make variables to store menu names and values *) > Block[{var, name}, {menuVars, menuNames} = > Apply[ Hold, Evaluate[Table[Unique[#], {menuDepth}]]] & /@ {var, > name}]; (* Functions to set/extract held variables *) > setHeld[Hold[var_], rhs_] := var = rhs; > setDelayedHeld[Hold[var_], rhs_] := var := rhs; > heldPart[seq_Hold, n_] := First[Extract[seq, {{n}}, Hold]]; (* Functions to close the given menu/submenus*) > subBack[depth_Integer] := > (If[depth =!= menuDepth + 1, setHeld[heldPart[menuVars, depth], ]]; > setHeld[heldPart[menuNames, depth - 1], menuCategs[[depth - 1]]]); > subBackAll[depth_Integer] := subBack /@ Range[menuDepth + 1, depth, -1]; (* Function to create a (sub)menu at a given level *) > makeSubmenu[depth_] := > Function[{nm, actions}, > subBackAll[depth + 1];(* remove lower menus if they are open *) > If[depth =!= 1, setHeld[heldPart[menuNames, depth - 1], nm]]; > setDelayedHeld[heldPart[menuVars, depth], > Dynamic@ > ActionMenu[menuNames[[depth]], > Prepend[actions, Back :> subBackAll[depth]]], AutoAction -> True, Sequence @@ Options[makeSubmenu]]]]; (* Function to help with a layout *) > addSpaces[x_List, spaceLength : (_Integer?Positive) : 10] := > With[{space = StringJoin @@ Table[ , {spaceLength}]}, > MapIndexed[ReplacePart[Table[space, {Length[x]}], ##] &, x]]; (* Initialization code *) > subBackAll[2]; > menuItemsConvertAlt[ > {menuNames[[1]], {menuItemTree}}, makeSubmenu /@ Range[menuDepth], > actionF, representF, representLeavesF][[1, 2]]; (* Display the menus *) > Dynamic[ > Function[Null, > Grid[addSpaces[{##}, 5], Frame -> True, FrameStyle -> Thick, > Background -> Lighter[Pink, 0.8]], HoldAll] @@ menuVars] > ]; (* End Module *) ----------------------------------------------------------------------------- ------------------------------ > So, the input for a menu should be a tree structure like this: In[1] = menuItems = {Continents, {{Africa, {{Algeria, {Algiers, > Oran}}, {Angola, {Luanda, > Huambo}}}}, {North America, {{United States, {New > York, Washington}}, {Canada, {Toronto, Montreal}}}}}}; The root of the tree (Continents in this case) is not used later (but > needed for consistency), so can be any string. > The second necessary ingredient is a list of categories (strings) of the > length equal to the depth of the menu to be constructed, or less (in which > case some subcategories will be shown with a standard header Choose). The > last mandatory ingredient is a function representing the action to be taken > upon clicking on the lowest-level menu item (leaf). This is how we create the menu: In[1] = createNestedMenu[menuItems, {Continent, Country , City > }, Print] In this case, all categories are given explicilty, and when we click on an > atomic menu element (not representing further menu sub-levels), it is > printed. You can also omit some sub-categories, they will be substituted by > Choose In[2] = createNestedMenu[menuItems, {Continent}, Print] There are additional optional parameters, which allow us to represent > different submenu items in different way - functions > representF and representLeavesF. The first one governs the appearance of > the non-atomic submenu elements and takes the level of a submenu as a > second > argument. The second governs the appearance of atomic menu elements > (leaves). For example: In[3] = > createNestedMenu[menuItems, {Continent, Country , > City }, Print, (Style[#, FontColor - Switch[#2, {1}, Brown, {2}, Blue, {3}, Green, _True, > Orange], #]) &, Style[#, Red] &] I went through some pains to ensure that the menu will work also on less > regular menu trees, where leaves may have different distance from the stem, > like here: In[4] = > menuTreeValidQ@ > (compMenuItems = {Company, > {{Services, > {Training, Development}}, > {Products, > {{OS tools, {}}, > {Application software, {}} > }}, > {News, > {{Press releases, {}}, > {Media coverage, {}} > }}, > {Company, > {{Vacancies, {{Developer, {Requirements}}, {Tester, > {}}}}, > {Structure, {}}} > } > }}) Out[4] = True We create the menu as before: In[5] = createNestedMenu[compMenuItems, {Main}, Print] where I omitted sub-categories. Notice that the syntax I chose is such that, whenever the submenu contains > only atomic elements, they can either all be represented by just strings, > or > wrapped in lists as {element,{}}, but not mixed. But if menu contains a mix > of atomic and non-atomic elements, atomic elements must be wrapped in lists > as above. For example, the more politically correct > way to represent the first example structrure is this: {Continents, {{Africa, {{Algeria, {{Algiers, {}}, {Oran, > {}}}}, {Angola, {{Luanda, {}}, {Huambo, {}}}}}}, {North > America, {{United States, {{New York, {}}, {Washington, {}}}}, > {Canada, {{Toronto, {}}, {Montreal, {}}}}}}}} The menuTreeValidQ predicate can be used to test if the structure is valid > or not. Hope that I don't waste everyone's time and bandwidth. > All feedback is greatly appreciated. Leonid > === Subject: Re: Looking for a Column,Row, and Grid interactive Lab Yes, I am working through the tutorials now. Whew a lot! What I meant was a manipulate sort a thing to study all the options and settings interactively not having to type so much. === Subject: Re: problem with Sum try e.g.: Sum[a[k], {k, Min[i + j - n, j] + 1, Max[i + j - n, j]}] Daniel > Hi mathematica community, I have this input: Sum[a[k], {k, 1, j}] - Sum[a[k], {k, 1, i+j-n}] > How it is possible to let mathematica gives as output: > Sum[a[k], {k, i+j-n+1, j}] if i+j-n and Sum[a[k], {k, j+1, i+j-n}] if i+j-n>j thank you very much. > === Subject: Re: Integrate Bug > I am trying to calculate this integral that should be positive.But the > answer is 0. In: Integrate[(1)/(z^2 + b^2 + a^2 - 2 z b Sin[[Theta]] - > 2 a b Cos[[Theta]])^(1/2), {[Theta], 0, 2 [Pi]}, > Assumptions -> {a > 0, b > 0, z > 0}] Out:0 Anybody have notice a situation like that? My platform is MacOSX 10.4 and Mathematica 7. Best wishes, Good day, Here is the most compact form of the integral, due to Dr. Andreas Dieckmann, who e-mailed me he used transformations (17.4.3), (17.4.11) and (17.4.15) given in Abramowitz/Stegun : 4*EllipticK[(4*b*Sqrt[a^2 + z^2])/(b + Sqrt[a^2 + z^2])^2]/(b + Sqrt [a^2 + z^2]) -- Valeri Astanoff p.s. I'm a bit disappointed FullSimplify couldn't do the same... === Subject: Re: ListDensityPlot how to define colors for specific range of values data = Table[Sin[x*y], {x, -Pi, Pi, Pi/32}, {y, -Pi, Pi, Pi/32}] // N; myColorFunction[x_] /; x < 0 := ColorData[AvocadoColors][Abs[x]] myColorFunction[x_] /; x >= 0 := ColorData[SunsetColors][Abs[x]] and ListPlot3D[data, ColorFunction -> myColorFunction, ColorFunctionScaling -> False] The trick is to use ColorFunctionScaling -> False to get the true z values as argument of the color function. Jens > can i define specific color for specific range of values? is there any way > to define this in Mathamatica? your comments are highly appreciated . prageeth > === Subject: Re: ListDensityPlot how to define colors for specific range of values All you have to do is to define a function that returns a color given the z-value as argument (or a value between 0 and 1, depending on the setting of the option ColorFunctionScaling) For example (with the default ColorFunctionScaling->True): Continuous blend: DensityPlot[Sin[x y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> (Blend[{Red, White, Blue}, #] &), PlotPoints -> 100] Dicrete colours: DensityPlot[Sin[x y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> ([Piecewise] { {White, # < 0.1}, {Red, 0.1 <= # <= 0.5}, {Blue, 0.5 < # < 0.8}, {Green, 0.8 <= #} } &), PlotPoints -> 100] On Jun 10, 11:33 am, prageeth saraka wimalaweera > can i define specific color for specific range of values? is there any way > to define this in Mathamatica? your comments are highly appreciated . prageeth -- > Software Engineer, > Axiohelix Co, > Okinawa Industry Support Center 1831-1 Oroku, > Naha-shi, > Okinawa, > 901-0152 Japan. === Subject: Re: differentiation operator !( *SubscriptBox[([PartialD]), (x, x)] (f[x])) does not what you want ? Jens > Hi All My students have asked me whether it is possible to define the operator > df[x]/dx for differentiation rather than D[f[x],x]. The operator is > available in a palette but it does not seem to do anything other than for > display only. Example: d/dx(x^2)=2x rather than D[x^2,x]=2x. Am I missing something? Mr. Chee > === Subject: Re: differentiation operator I don't see why you say that the differential operator on the palette doesn't work. If you paste it in a notebook and then fill in x and the expression and then evaluate, it will work. Otherwise, you could do something like: d[x_] = Function[expr, D[expr, x]]; d[x][x^2] 2 x David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi All My students have asked me whether it is possible to define the operator df[x]/dx for differentiation rather than D[f[x],x]. The operator is available in a palette but it does not seem to do anything other than for display only. Example: d/dx(x^2)=2x rather than D[x^2,x]=2x. Am I missing something? Mr. Chee === Subject: Re: differentiation operator Hi Chee, I did not thoroughly test it, but if you define: $Pre = # /. Times[ d expr_ Power[dx, -1]] :> D[expr, x] & the following examples work: d/dx x^2 -> 2x d/dx Sin[x] -> Cos[x] d/dx (x-x^3) -> 1-3x^2 e.t.c Daniel > Hi All My students have asked me whether it is possible to define the operator > df[x]/dx for differentiation rather than D[f[x],x]. The operator is > available in a palette but it does not seem to do anything other than for > display only. Example: d/dx(x^2)=2x rather than D[x^2,x]=2x. Am I missing something? Mr. Chee > === Subject: Re: Partitioned matrix operations Hi Joe, As far as I know Mathematica doesn't have the possibility to declare a variable to be a matrix, especially not with undefined dimensions. Of course, you can define a matrix containing nxm symbolic elements (with n,m known and defined) and work with that, but I don't think that's what you want. You might want to take a look at http://www.math.washington.edu/~lee/Ricci/ > Here's a Mathematica newbie question. Say I have a matrix, M, defined as, M = {{A, B}, {C, 0}} where A is nxn, B is nxm, C is mxn, and the zero sum matrix is mxm. I wou= ld > like to perform an operation on the matrix M without fully defining A, B, > and C and get a result in terms of A, B, and C. For example, if I wanted = to > determine the matrix inverse of M in terms of A, B, and C. Is this possible in Mathematica? I've unfortunately not found anything in > the docs that indicates that this is possible. Thx. === Subject: Re: Partitioned matrix operations Your proposed use of Inverse works only if A, B and C commute (where appropriate). You can verify that your proposed inverse is not correct by premultiplying it by the original matrix thus: {{A, B}, {C, 0}} . {{0, C^(-1)}, {B^(-1), -A (B C)^(-1)}} When you expand this out the upper right element is A C^(-1) - B A (B C)^(-1) which does not simplify to 0 (as you would have liked) when A, B and C don't commute (where appropriate). Anyway, back to the original problem. Since it is only a 2x2 block matrix you can solve it manually thus: {{A,B},{C,0}} . {{U,V},{W,X}} = {{1,0},{0,1}} where you have to solve for the matrices U, V, W, X, and the 1 and 0 symbols on the r.h.s. stand for the appropriate matrices. I won't say any more in case this is a homework problem. -- Stephen Luttrell West Malvern, UK you may symbolically invert your matrix: Inverse[M] giving: {{0, 1/C}, {1/B, -(A/(B C))}} Now it is up to you to ensure that C,B and B C are invertible. Daniel > Here's a Mathematica newbie question. Say I have a matrix, M, defined as, >> M = {{A, B}, {C, 0}} >> where A is nxn, B is nxm, C is mxn, and the zero sum matrix is mxm. I >> would > like to perform an operation on the matrix M without fully defining A, B, > and C and get a result in terms of A, B, and C. For example, if I wanted >> to > determine the matrix inverse of M in terms of A, B, and C. >> Is this possible in Mathematica? I've unfortunately not found anything in > the docs that indicates that this is possible. >> Thx. > === Subject: Re: Slow/jerky animations inside manipulate (more details) You have to distinguish between global and localized version of a variable. Here I cleand up tp and T1. After this the following runs pretty smooth. A = 1; De = 1; xe = 0; tp = 10; Animate[ sols = NDSolve[{q'[t] == p[t], p'[t] == 2 A De (Exp[-2 A (q[t] - xe)] - Exp[-A (q[t] - xe)]), q[0] == q0, p[0] == p0}, {q, p}, {t, 0, 100}][[1]]; p1 = Graphics[{Point[{tp, Evaluate[q /. sols][tp]}]}]; p2 = Quiet@ Plot[Evaluate[q /. sols][T1], {T1, 0, tp}, PerformanceGoal -> Speed]; FIRSTplot = Show[p1, p2] , {q0, .1, 1}, {p0, .1, 1}] Daniel > As several people have kindly pointed out, my first post was a bit too > vague (my first time with Mathgroup). I am adding more specific ------Original post: Slow/jerky animations inside manipulate --------- > I have an Animate command (I'm using GraphicsRow to show two > side-by-side synchronized animations) inside of Manipulate. The > resulting animations play very fast and are jerky. I can adjust the > play speed using AnimationRate, but it must be slowed down by a > ridiculous amount in order to look smooth. I've tried adjusting the > RefreshRate, as wellas making time a slider variable and animating > from within the Manipulate control panel,both with little success. > How can I create smooth animations, appropriate for class demonstrations? > ------------------------------------------------------------------------- > -----Additional Comments------------------------------------------------- > My plots are actually simple. I am, however, solving an ODE inside of the > Manipulate/Animate commands. I've played around with the NDSolve > options thinking it might make things faster, but again no success. > Basically I just want two sliders to choose initial conditions for the > ODEs, then animate the results. Inside Manipulate, I solve the following ODEs, where the initial > conditions q0,p0 are the slider variables: sols = First@NDSolve[{q'[t] == p[t], p'[t] == 2 A De (Exp[-2 A (q[t] - xe)] - > Exp[-A (q[t] - xe)]), q[0] == q0, p[0] == p0}, {q, p}, {t,0, 100}]; Inside Animate, I have two plots (tp is the animation variable): 1. Plot solution q(tp) vs. tp, as well as a circle that moves along > as the curve is being traced out: p1 = Graphics[{ Point[{tp, Evaluate[q[tp] /. sols]}]}]; > p2 = Quiet@Plot[Evaluate[q[T1] /. sols], {T1, 0, tp}, > PerformanceGoal->Speed]; > FIRSTplot = Show[p1, p2]; 2. Plot a static background curve Staticplot (computed outside > Animate), with a circle moving on it. The equation for the background > curve is: f(q)=De(1+Exp[-2 A (q-xe)]-2 Exp[-A (q-xe)]) The coordinates for Point below are {q,f(q)}. p7 = Graphics[{Point[{Evaluate[q[tp] /. sols], > De (1 + Exp[-2 A (Evaluate[q[tp] /. sols] - xe)] - > 2 Exp[-A (Evaluate[q[tp] /. sols] - xe)]) }] }]; > SECONDplot=Show[Staticplot,p7]; > ------------------------------------------------------------------------- > === Subject: Strange problem with ImageApply on byte images when Interleaving is Hello everyone, ImageApply seems to act strange when using imported images (Byte image rather than Real) , when Interleaving is true. I use version 7.0.1. a = ImageResize[Import[ExampleData/lena.tif], {4, 4}]; (* Resizing is only to make it notebook friendly *) Reap[ImageApply[(Sow[#]; #) &, a, Interleaving -> True]]//InputForm will output something like: {Image[{{{172, 96, 58}, {185, 130, 108}, {192, 163, 149}, {134, 101, 85}}, {{169, 99, 63}, {138, 96, 86}, {163, 135, 126}, {153, 121, 101}}, {{137, 90, 76}, {116, 80, 76}, {161, 106, 89}, {175, 145, 111}}, {{114, 87, 80}, {97, 69, 67}, {169, 120, 97}, {174, 142, 106}}}, Byte, ColorSpace -> RGB, Interleaving -> True, Magnification -> Automatic], {{{0.6745098039215687, 0.3764705882352941, 0.22745098039215686}, {0.6745098039215687, 0.3764705882352941, 0.22745098039215686}, {Image`LocalProcessingDump`x[1], Image`LocalProcessingDump`x[2], Image`LocalProcessingDump`x[3]}, Image`LocalProcessingDump`x[1], Image`LocalProcessingDump`x[ 2], Image`LocalProcessingDump`x[3], 0.6745098039215687, 0.3764705882352941, 0.22745098039215686, 0.7254901960784313, 0.5098039215686274, 0.4235294117647059, 0.7529411764705882, 0.6392156862745098, 0.5843137254901961, 0.5254901960784314, 0.396078431372549, 0.3333333333333333, 0.6627450980392157, 0.38823529411764707, 0.24705882352941178, 0.5411764705882353, 0.33725490196078434, 0.5294117647058824, 0.49411764705882355, 0.6, 0.4745098039215686, 0.5372549019607843, 0.35294117647058826, 0.2980392156862745, 0.4549019607843137, 0.3137254901960784, 0.6313725490196078, 0.41568627450980394, 0.34901960784313724, 0.6862745098039216, 0.5686274509803921, 0.43529411764705883, 0.4470588235294118, 0.3411764705882353, 0.3803921568627451, 0.27058823529411763, 0.2627450980392157, 0.47058823529411764, 0.6823529411764706, 0.5568627450980392}}} What are these LocalProcessingDump things? Any idea? It creates a lot of problems. If you say: b=Image[ImageData[a]]; Reap[ImageApply[(Sow[#]; #) &, a, Interleaving -> True]]//InputForm you get the expected result: {Image[{{{0.6745098039215687, 0.3764705882352941, 0.22745098039215686}, {0.7254901960784313, 0.5098039215686274, 0.4235294117647059}, {0.7529411764705882, 0.6392156862745098, 0.5843137254901961}, {0.5254901960784314, 0.396078431372549, 0.3333333333333333}}, {{0.6627450980392157, 0.38823529411764707, 0.24705882352941178}, {0.5411764705882353, 0.3764705882352941, 0.33725490196078434}, {0.6392156862745098, 0.5294117647058824, 0.49411764705882355}, {0.6, 0.4745098039215686, 0.396078431372549}}, {{0.5372549019607843, 0.35294117647058826, 0.2980392156862745}, {0.4549019607843137, 0.3137254901960784, 0.2980392156862745}, {0.6313725490196078, 0.41568627450980394, 0.34901960784313724}, {0.6862745098039216, 0.5686274509803921, 0.43529411764705883}}, {{0.4470588235294118, 0.3411764705882353, 0.3137254901960784}, {0.3803921568627451, 0.27058823529411763, 0.2627450980392157}, {0.6627450980392157, 0.47058823529411764, 0.3803921568627451}, {0.6823529411764706, 0.5568627450980392, 0.41568627450980394}}}, Real, ColorSpace -> Automatic, Interleaving -> True], {{{0.6745098039215687, 0.3764705882352941, 0.22745098039215686}, {0.6745098039215687, 0.3764705882352941, 0.22745098039215686}, {0.7254901960784313, 0.5098039215686274, 0.4235294117647059}, {0.7529411764705882, 0.6392156862745098, 0.5843137254901961}, {0.5254901960784314, 0.396078431372549, 0.3333333333333333}, {0.6627450980392157, 0.38823529411764707, 0.24705882352941178}, {0.5411764705882353, 0.3764705882352941, 0.33725490196078434}, {0.6392156862745098, 0.5294117647058824, 0.49411764705882355}, {0.6, 0.4745098039215686, 0.396078431372549}, {0.5372549019607843, 0.35294117647058826, 0.2980392156862745}, {0.4549019607843137, 0.3137254901960784, 0.2980392156862745}, {0.6313725490196078, 0.41568627450980394, 0.34901960784313724}, {0.6862745098039216, 0.5686274509803921, 0.43529411764705883}, {0.4470588235294118, 0.3411764705882353, 0.3137254901960784}, {0.3803921568627451, 0.27058823529411763, 0.2627450980392157}, {0.6627450980392157, 0.47058823529411764, 0.3803921568627451}, {0.6823529411764706, 0.5568627450980392, 0.41568627450980394}}}} What is going on? Any idea? Sebastien === Subject: Re: Error importing Excel data into Mathematica 7 > I have a number of programs that were originally written in V6 that import > data from .xls files such as: path=C:UsersErinDesktop; > data=Import[datafile.xls,{Data,1},Path->path]; > This series of commands has never failed to import the data just fine into > version 6. Running the exact same code in version 7, though, results in the > following error: Get::path: Join[C:UsersErinDesktop,{C:Documents and > SettingsJM27373Application > DataMathematicaSystemFilesKernelSystemResources,C:Documents and > SettingsJM27373Application > DataMathematicaSystemFilesKernelSystemResourcesWindows,C:Docume nts > and SettingsAll UsersApplication > DataMathematicaSystemFilesKernelSystemResources,C:Documents and > SettingsAll UsersApplication > DataMathematicaSystemFilesKernelSystemResourcesWindows,C:Progra m > FilesWolfram > ResearchMathematica7.0SystemFilesKernelSystemResources,C:Progra m > FilesWolfram > ResearchMathematica7.0SystemFilesKernelSystemResourcesWindows}] in > $Path is not a string. >> from the error message one can guess that Path->{path} could work and it does indeed. > It also states something about Data not being present in importing XLS > files. this also happened for me after I tried your code. It goes away when you restart Mathematica and try the above with the enclosing {}. Looks like the Join-bug messes up the whole import function once it is triggerd... hth, albert === Subject: Presentation quick with grid and pasted graphic I trying to create a presentation (slide show) using Mathematica 7.0.1 on Mac OS X 10.4.11 for the first time. I am using the default stylesheet. On the first slide, I inserted a 1x2 grid (using the classroom assistant palette). On the left hand side of the grid I typed some text. When I do so, the background of the grid turns beige. On the right hand side of the grid I copied and pasted a 3D rotatable graphic (a cube obtained from PolyhedronData [Cube]). Again, the background is beige. When I click somewhere else not on the grid, the background turns white. Then, when I view the slide in slideshow mode, the grid background is white. However, if I rotate the graphic, the background of the grid becomes beige, and I am unable to return it to white by clicking off the grid. Clicking somewhere else returns only the text side to white but not the graphic side. The result is a poor looking presentation. Do any of you have any suggestions for avoiding this behavior? Is there a preferred method for placing text and graphics side by side? Adam === Subject: Re: manipulate contourplot question Use the PerformanceGoal option. Manipulate[ ContourPlot[ a x^2 + 2 b x y + c y^2 + 2 d x + 2 f y + g == 0 /. {a -> 1, c -> 3, d -> 0, f -> 0, g -> -1} // Evaluate, {x, -5, 5}, {y, -5, 5}, PerformanceGoal -> Quality, PlotPoints -> 10], {{b, 0}, -5, 5}] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ The following produces a smooth function. But when I hold and move the slider the function appears jagged and is only fully drawn when I release the slider. I know this is done to show an initial result very fast. Is there a method to influence this behavior? Manipulate[ ContourPlot[ a x^2 + 2 b x y + c y^2 + 2 d x + 2 f y + g == 0 /. {a -> 1, c -> 3, d -> 0, f -> 0, g -> -1} // Evaluate, {x, -5, 5}, {y, -5, 5}, PlotPoints -> 10], {{b, 0}, -5, 5}] Maarten === Subject: manipulate contourplot question The following produces a smooth function. But when I hold and move the slider the function appears jagged and is only fully drawn when I release the slider. I know this is done to show an initial result very fast. Is there a method to influence this behavior? Manipulate[ ContourPlot[ a x^2 + 2 b x y + c y^2 + 2 d x + 2 f y + g == 0 /. {a -> 1, c -> 3, d -> 0, f -> 0, g -> -1} // Evaluate, {x, -5, 5}, {y, -5, 5}, PlotPoints -> 10], {{b, 0}, -5, 5}] Maarten === Subject: Re: manipulate contourplot question The following produces a smooth function. But when I hold and move the > slider the function appears jagged and is only fully drawn when I > release the slider. I know this is done to show an initial result very fast. Is there a > method to influence this behavior? Manipulate[ ContourPlot[ a x^2 + 2 b x y + c y^2 + 2 d x + 2 f y + g == 0 /. {a -> 1, c -> 3, d -> 0, f -> 0, g -> -1} // Evaluate, {x, -5, 5}, {y, -5, 5}, PlotPoints -> 10], {{b, 0}, -5, 5}] Include the option PerformanceGoal -> Quality within the ContourPlot. -- Helen Read University of Vermont === Subject: Re: differentiation operator Hi David Park Calculus textbooks) in the Classroom Assistant palette but it seems to be for display only. (Am i missing something here?) I guess the solution is to format it to behave like a differentiation operator. Any ideas on that? We would like d(f[x])/dx to function in the same way as D[f[x],x]. Mr. Chee David Park I don't see why you say that the differential operator on the palette doesn't work. If you paste it in a notebook and then fill in x and the expression and then evaluate, it will work. Otherwise, you could do something like: d[x_] = Function[expr, D[expr, x]]; d[x][x^2] 2 x David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi All My students have asked me whether it is possible to define the operator= df[x]/dx for differentiation rather than D[f[x],x]. The operator is available in a palette but it does not seem to do anything other than f= or display only. Example: d/dx(x^2)=2x rather than D[x^2,x]=2x. Am I missing something? Mr. Chee === Subject: Re: Draw a 3D surface g[y_] := y^2 - 2 Plot3D[Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, RegionFunction -> Function[{x, y, z}, x < g[y]]] ? Jens > I intend to draw a 3D surface, which is defined in a tricky way. Given > function f(x, y), the values of f are known but the range is > determined by a function of y, g(y). I need to plot x as a function of > y and f within the range determined by g(y). Can anybody help? > Appreciate! Jun Lin > === Subject: Re: Draw a 3D surface I intend to draw a 3D surface, which is defined in a tricky way. Given function f(x, y), the values of f are known but the range is determined by a function of y, g(y). I need to plot x as a function of y and f within the range determined by g(y). Can anybody help? Appreciate! Jun Lin I do not really understand, what do you mean with range determined with g(y). You should probably explain it in more details. Concerning the first part of your question, here is the most simple answer: draw the f=f(x,y)surface using say, Plot3D, and then rotate the graph with the mouse such that the Ox axis is directed upwards. ?? Or rotate it programmatically using Rotate function. If you need it upwards at once (this may be useful for example, if you need to programmatically include some other graphics together with this plot), the following may help: ParametricPlot3D[{y, Sin[x*y], x}, {x, -1, 1}, {y, -1, 1}, AxesLabel -> {y, f, x}] I took here the function f=sin(xy) to be concrete. Have success, Alexei -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: problem with Sum >I have this input: Sum[a[k], {k, 1, j}] - Sum[a[k], {k, 1, i+j-n}] >How it is possible to let mathematica gives as output: Sum[a[k], {k, >i+j-n+1, j}] if i+j-nj Have you looked at the documentation for If? Specifically, If[i i + j - n Out[10]= Sum[a[k], {k, 1, i + j - n}] === Subject: Re: RandomReal gets stuck > If you want to use subscripted variables, it might help to use this code: subFunction::usage = subFunction[a] causes inputting a[i] or > !(*SubscriptBox[a, i]) to be synonymous, while always > displaying the latter in outputs. subFunction[a] causes inputting a[i] or !(*SubscriptBox[a, > i]) to be synonymous, while always displaying the latter in > outputs. subFunction[a_Symbol]:=Block[{aa=ToString[a]},MakeExpression[Subscrip= tBox[ToString@a,i_],f_]:=MakeExpression[RowBox[{ToString@a,[,i,]}]]; MakeBoxes[a[i_],f_]:=SubscriptBox[MakeBoxes[a,f],MakeBoxes[i,f]]] The result is that you can refer to a[i] or Subscript[a,i] > interchangeably, but it always displays in the subscripted form. I find it > much easier to use a[i] while typing formulas, so I'm getting the best of > both worlds. Not sure if that addresses everything brought up on the thread, of course. Bobby It is very interesting, thank you. But as I understand the definition aa=ToString[a] inside Block is not necessary. And Mathematica does not recognizes input Subscript[a,i] as equivalent to a[i]. There seems to be some errors in the code. === Subject: Re: AnimationDirection when Exporting > Suppose I want to export an animation (using Animate or Manipulate) so > that the exported animation runs once in the forward direction and > stops. You can gain more control of animations by exporting individual frames as .gif or .png files with serial file names. Then use Thorsten Lemke's Macintosh app Graphic Converter [or QuickTime Pro (a $35 upgrade to the free QuickTime) if you're stuck in the Windoze environment] to paste them together into a .mov file. The drawback, if it is one, is that you get QuickTime animations instead of .avi ones. See for a few dozen animations constructed in this way. --Lou Talman Department of Mathematical and Computer Sciences Metropolitan State College of Denver === Subject: Re: What should be a simple task.... I think the subject of this discussion has been somewhat misstated (or at least I hope so). What I am objecting to is essentially the use of the word should. If should is interpreted literally then, in my opinion, the discussion becomes absurd. Everyone should use Mathematica in the way that he or she finds most convenient and there are almost as many different situations as there are users. As an obvious example I will mention there is no point telling people to stay inside Mathematica if they want to submit a paper to a journal which only accepts submissions written in TeX or Word or whatever. The other should (that one should use Mathematica only for calculation) is even more absurd - there is absolutely no point telling me that I should use Illustrator when Mathematica produces perfectly acceptable results (and besides, I try to boycott Adobe's products on principle, as much as possible of course...). I think the real issue is the direction of Mathematica's development by WRI, not how it is actually used by users, which should be up to them (which does not mean that one should not try to inform them about all the possibilities, which I take to be what David Park's reply is really about). To me it seems obvious that Mathematica should be developed as a self-contained tool for two reasons. One is that only such a development makes possible fantastic projects such as the Demonstrations Project and Wolfram Alpha. Both of these can exist only both have no real competitors and the reason is that there is no other tool today that can compete with Mathematica in respect of this integration. AES's argument has always been that Wolfram should do basically the same thing as many other programs do, I know of at least a dozen commercial and free programs that do rather well exactly what he argues Mathematica should be doing. I think if AES hopes that he can persuade Wolfram that the best way to success is becoming a part of a crowd, I think he hasn't been paying any attention during the last 20 years. One can say many things about Stephen Wolfram but that he likes to be a part of a crowd is not one of them. Of course, although I believe Mathematica should be developed exactly the way it is now, as a basically integrated and self contained tool, I also think that making sure that it has up to date and extensive export abilities is essential. This obviously follows from what I Mathematica in a way that is most convenient for them. Andrzej Kozlowski > Kristin, I want to apologize at the start because I am not directly answering > your > problem (I hope you will get a simple effective solution, probably > from one > of my favorite guys at WRI.), and what I say may sound a little > critical - > but I hope not of you. There has been a long-time running discussion, mainly between me and > AES, > on MathGroup concerning how Mathematica should be used. I think that > Mathematica should be used not only for calculations but also as a > communications medium. One should stay in Mathematica all the way. AES > believes one should only do basic mathematical calculations and > plots in > Mathematica (which it would specialize in) and export everything to > other > media for publication or communication. And, in fact, I suspect that > most > users do it his way. But there are quite a few complaints about problems in exporting > Mathematica > output to other media that appear in this newsgroup. This process > actually > takes quite a bit of special knowledge. We even see such problems > posted by > people we know to be quite sophisticated users of Mathematica. So why not stay in Mathematica in the first place? It's capabilities > for > presenting technical information are immensely superior to any > static or > semi-static medium such as PowerPoint. Why not convince the > recipients of > your information that it is better to spend your time on the technical > problems, than on the problems of converting to a vastly inferior > medium > that serves their interests less well? If one of the reasons is that they don't have Mathematica then it is > all the > more reason that WRI and everyone else would benefit from a free and > easily > obtained Mathematica PlayerPro. > David Park > djmpark@comcast.net > http://home.comcast.net/~djmpark/ Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another > system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks > decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my > simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either > the > fonts get screwed up or it looks even worse or there's ugly aliasing > or > no effect on the stair stepping. I've exported to PDF and snapshot- > copied > from there; The curves look good, but now the whole image is just a > little > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on > what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power > Point > that I can't reach. I really don't want to have two different > briefings > for electronic vs. paper presentation, but I'm a little concerned > that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin > === Subject: Re: What should be a simple task.... Hi Kristin, I agree that many graphs copied as metafile appear with jaggies and other artefacts when presented in Powerpoint. I usually do a copy as bitmap and (in Powerpoint) a copy special as PNG. I scale the figure in Mathematica to the size it should appear in Powerpoint since resizing a bitmap tends to make the figure look blurry. > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-copied > from there; The curves look good, but now the whole image is just a little > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefings > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin === Subject: Re: What should be a simple task.... Kristin, I want to apologize at the start because I am not directly answering your problem (I hope you will get a simple effective solution, probably from one of my favorite guys at WRI.), and what I say may sound a little critical - but I hope not of you. There has been a long-time running discussion, mainly between me and AES, on MathGroup concerning how Mathematica should be used. I think that Mathematica should be used not only for calculations but also as a communications medium. One should stay in Mathematica all the way. AES believes one should only do basic mathematical calculations and plots in Mathematica (which it would specialize in) and export everything to other media for publication or communication. And, in fact, I suspect that most users do it his way. But there are quite a few complaints about problems in exporting Mathematica output to other media that appear in this newsgroup. This process actually takes quite a bit of special knowledge. We even see such problems posted by people we know to be quite sophisticated users of Mathematica. So why not stay in Mathematica in the first place? It's capabilities for presenting technical information are immensely superior to any static or semi-static medium such as PowerPoint. Why not convince the recipients of your information that it is better to spend your time on the technical problems, than on the problems of converting to a vastly inferior medium that serves their interests less well? If one of the reasons is that they don't have Mathematica then it is all the more reason that WRI and everyone else would benefit from a free and easily obtained Mathematica PlayerPro. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi :) I am an analyst (applied physics and math) who has to present all of my work in Power Point briefings, sometimes on paper, sometimes electronically. I vastly prefer working in Mathematica to another system; however, I'm currently ham strung by my inability to transfer simple plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right clicking on the plot in Mathematica and Paste Special: Metafile in Power Point, and all would be well (Ok, I had to tweak line thickness settings and fonts in my plots to make them survive the transfer, but that was fine). Now, I have select the whole cell rather than just the plot to get the Copy As: metafile option, and I have to go all the way to the menu bar to do it (no longer an option on the right click). Fine, I can deal with that, but I can't deal with the fact that my simple plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. I've played with the PlotPoints option-no effect. I've exported into different form ats with varying ImageResolution and imported; Either the fonts get screwed up or it looks even worse or there's ugly aliasing or no effect on the stair stepping. I've exported to PDF and snapshot-copied from there; The curves look good, but now the whole image is just a little bit blurry/soft, a little too much to pass muster with my supervisors and sponsors. I'm really getting frustrated now, have spent way too much time on what *was* a solved problem before my upgrades, and beginning to suspect that the problem is some import or paste/display setting in Power Point that I can't reach. I really don't want to have two different briefings for electronic vs. paper presentation, but I'm a little concerned that's where this is heading, or I'm going to have to use the other system to make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. This is one of those stupid simple problems that also happens to be quite fundamental to the ability to make good use of Mathematica. -Kristin === Subject: Re: What should be a simple task.... > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-cop= ied > from there; The curves look good, but now the whole image is just a littl= e > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefing= s > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin I confirmed some quality problems Kristin is talking about. I tried copying and pasting the Plot[x,{x,0,1}] graphic from Mathematica 7 to Experiment #1: First I selected the graphic (not cell) then right- clicked to Copy Graphic. Next, I pasted to a slide and noticed some poor quality in the pasted graphic. Experiment #2: First I selected the cell of the graphic -- converted it to Metafile. I noticed that the converted graphic in Mathematica looks the same as the pasted Powerpoint graphic from Experiment #1. Experiment #3: Repeated Experiment #2 except that I converted the graphic to Bitmap. Much better quality in the pasted graphic except for some clipping at margins of the graphic. I think the Metafile conversion utility (Powerpoint/Mathematica) has some quality issues. Can someone recommend a command to extend the margins of the graphics to avoid clipping something important when the graphic is pasted? Lawrence === Subject: Re: What should be a simple task.... > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-cop= ied > from there; The curves look good, but now the whole image is just a littl= e > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefing= s > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin I've had problems with this too. Exporting Mathematica graphics into Office 2007 programs in a vector format is kind of a pain. The best way to keep the graphics looking good is to keep them in Mathematica. Depending on your needs you may be able to give your presentations using Mathematica's built in presentation functionality. It lacks flashy trasitions and other stuff that makes presentations pretty which may be a priority but it does let you make really clean looking presentations with raw mathematica graphics. you can even use commands like Manipulate to support dynamic figures. If that is not an option for whatever reason you might try using a raster format like PNG for your graphics. They are fixed resolution but they will look good with minimal tweeking of options. its not ideal but I dont know of any other way to get antialiased graphics from Mathematica to Word 2007. a simple general form that i use for the export command in these situations is : Export[ SystemDialogInput[FileSave], (* graphics go here *), ImageResolution->(*some number to specify dpi*)] I'm sorry if I don't really answer your questions but this is as close to a solution as I have. === Subject: Re: What should be a simple task.... The following seems to work: 1) click on the graph (not the cell bracket) 2) Right click and choose Save Graphic As...} 3) Save the result as an EPS then, in Excel do 4) In the Insert menu choose Picture 5) Choose the eps file that you saved from Mathematica 6) The eps is inserted I did this with success using MS Office 2008 on a Mac. Hope this helps... --David > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-cop= ied > from there; The curves look good, but now the whole image is just a littl= e > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefing= s > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin === Subject: Re: What should be a simple task.... > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. The following may, or may not, be relevant . . . I had an experience some time back in which I was placing (pasting, inserting) PDF files (Mathematic-prepared or otherwise prepared) into PowerPoint slides, and discovering that they all looked lousy (jaggies) the instant I resized them in any way. Eventually concluded that PowerPoint was apparently only displaying the preview/thumbnail associated with the PDF files. The full Postscript code for the PDFs was apparently stored in the PowerPoint slides, because they printed flawlessly direct from PowerPoint; but the onscreen rendering or projection (even in Full Screen mode) was apparently only using the thumbnail. Being paranoid, I concluded that this was just good old Microsoft, deliberately making non-MS formats look bad for anticompetitive reasons; so ever since then I've done _all_ my slide preparation, storage, and presentation using PDF formats and Adobe or other non-MS products only (Reader or Acrobat are great slide show presentation apps), and ditched all MS products. But, as noted at the start, this was some years back. === Subject: Re: What should be a simple task.... > In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). I don't have to select the whole cell in order to get the Copy As... Metafile option in Mathematica 7. I do have to go all the way to the menu bar to get the option, but it's available if I just click on the plot to select it without selecting the whole cell. (Enhanced Metafile), so the problem may be on the PowerPoint 2007 end of things. Sorry I can't be more helpful, Pillsy === Subject: Getting histogram information All, I have used the Histogram[] function many times. It works well and has lots of options but seems to lack transparency. Specifically, if I don't specify a bin width and let the function compute it, I want to know exactly what bin width the function used. Obviously, with some additional work I can infer the bin width from the resulting histogram. It would be better, however, to know precisely the bin width that the function actually used. I consulted Wolfram support about this and they were helpful, providing me with a bit of clever but rather obscure code that returns the populated histogram bins. But this still requires additional work to infer the bin width. The code provided by Wolfram support is listed after the signature. Can anyone figure out how to get the bin width directly from the Histogram[] function? Raul Martinez Code: data1=RandomReal[NormalDistribution[0,1],100]; h = Reap @Histogram[data1,Automatic,Function[{xbins,counts},Sow[counts];counts]] h[[2]] h[[2,1,1]] (*This will give the number of bins.*) h[[2,1,1]]//Length === Subject: Creating Matrix from vectors Suppose i have a n number of vectors say s1, s2,... sn. I want to create a matrix such that these n vectors are the n columns of the matrix. I tried using A = {s1,s2,..,sn}; however this keep the vectors intact and stacks them one below the other. How can i make a matrix from these?? Can anyone please help me with this. === Subject: Undocumented functions for working with graphics Does anyone know where such functions as Image`ToGraphicsRaster and Image`PossibleImageQ are documented. Are there other such built-in functions? At this moment I even can't imagine from where (except this group) I could learn that functions mentioned exist... === Subject: Out of memory errors I'm operating on some largish problems in which I'm making a graph, using MakeGraph from the Combinatorica package. When I exceed a certain size, the thing runs for a bit and then gives an out of memory error and then the kernel shuts down. I'm running Vista on a dual core I've tracked down the problem, I think. Mathematica runs the operation is why doesn't it build a pagefile like most windows applications? Then I could run anything that didn't actually use up the free disk space. === Subject: Re: AnimationDirection when Exporting > >> Suppose I want to export an animation (using Animate or Manipulate) so >> that the exported animation runs once in the forward direction and >> stops. You can gain more control of animations by exporting individual frames > as .gif or .png files with serial file names. Yes, I know that. That's the way one used to do animations, back in the olden days. My point is that I want to use Animate or Manipulate, and export an animation that runs once in the forward direction only, not forward then backward. Is there no way to do it? I'll be teaching a group of (extremely) bright high school students to make animations in Mathematica at the (Vermont) Governor's Institute in Mathematical Sciences in a few weeks. The kids have never seen Mathematica before, and I'll only have them for a single session of an hour or so. We will use Animate to make animations, and use the Classroom Assistant or Basic Math Input palette to help with input, so that I won't have to spend a lot of time teaching them Mathematica syntax. There won't be time to mess around with making tables of individual frames; I need the simplest, quickest way for them to make an animation, which is Animate. -- Helen Read University of Vermont === Subject: Re: Getting histogram information > All, I have used the Histogram[] function many times. It works well and has > lots of options but seems to lack transparency. Specifically, if I don't specify a bin width and let the function > compute it, I want to know exactly what bin width the function used. > Obviously, with some additional work I can infer the bin width from > the resulting histogram. It would be better, however, to know > precisely the bin width that the function actually used. I consulted Wolfram support about this and they were helpful, > providing me with a bit of clever but rather obscure code that returns > the populated histogram bins. But this still requires additional work > to infer the bin width. The code provided by Wolfram support is listed > after the signature. Can anyone figure out how to get the bin width directly from the > Histogram[] function? > It's not possible. If you need a *simple* approach, and don't want to use the code you were given, just specify the bin width yourself. If you look under more information, you'll find a list of methods that Mathematica can use to automatically find a bin width that produces a smooth histogram. You can look up the methods, and implement them yourself (some of them are pretty simple). Then you'll have both automatic bin width calculation *and* and the exact bin width. Of course the ideal situation would be if Mathematica provided access to the binning functions it uses for these methods, so we wouldn't have to implement them ourselves. So I poked around inside Histogram (in v7) and found the following binning functions: Histogram`HistogramBayesianBinning Histogram`HistogramFreedmanDiaconisBinning Histogram`HistogramScottBinning Histogram`HistogramSturgesBinning Histogram`HistogramWandBinning At least some of these functions take an argument, which is a function they use to transform again the bin width they calculate. I don't know what histogram uses for this transformation function, but we can just use Identity. So, here's the simplest way to have both automatic bin width calculation and know the exact bin width: Histogram[data, Histogram`HistogramWandBinning[Identity]] gives the histogram and Histogram`HistogramWandBinning[Identity][data] gives the exact bin specification. (Use Differences to get the bin width) === Subject: Re: Getting histogram information BinCounts[] is your friend .. Jens > All, I have used the Histogram[] function many times. It works well and has > lots of options but seems to lack transparency. Specifically, if I don't specify a bin width and let the function > compute it, I want to know exactly what bin width the function used. > Obviously, with some additional work I can infer the bin width from > the resulting histogram. It would be better, however, to know > precisely the bin width that the function actually used. I consulted Wolfram support about this and they were helpful, > providing me with a bit of clever but rather obscure code that returns > the populated histogram bins. But this still requires additional work > to infer the bin width. The code provided by Wolfram support is listed > after the signature. Can anyone figure out how to get the bin width directly from the > Histogram[] function? > Raul Martinez Code: data1=RandomReal[NormalDistribution[0,1],100]; h > = > Reap > @Histogram[data1,Automatic,Function[{xbins,counts},Sow[counts];counts]] h[[2]] h[[2,1,1]] (*This will give the number of bins.*) > h[[2,1,1]]//Length === Subject: Re: Undocumented functions for working with graphics Does anyone know where such functions as Image`ToGraphicsRaster and > Image`PossibleImageQ are documented. They are not documented. This means that they are not supported and may not work in future versions. > Are there other such built-in > functions? Lots of them. They are used internally by Mathematica and are not meant to be used by users. But sometimes we dig them out and use them anyway. > At this moment I even can't imagine from where (except this > group) I could learn that functions mentioned exist... > === Subject: Re: Undocumented functions for working with graphics ...just following up on the method for reverse engineering of my previous post, here is part of the code for ToGraphicsRaster obtained using that approach: Image`ToGraphicsRaster[img_?Image`ValidImageQ] := Module[{width, height, range, cf, data, interleaving, imsize}, {{width, height}, range, cf} = ImageData[ img, {ImageDimensions, DataRange, ColorFunction}]; {interleaving, imsize} = {Interleaving, ImageSize} /. Options[img] /. Options[Image]; data = Reverse[ImageData[img, Interleaving -> True]], data = Reverse[First[img]]]; Graphics[ Raster[data, {{0, 0}, {width, height}}, range, ColorFunction -> cf], ImageSize -> {width, height}, ImageSize -> imsize], PlotRange -> {{0, width}, {0, height}}]] Does anyone know where such functions as Image`ToGraphicsRaster and > Image`PossibleImageQ are documented. Are there other such built-in > functions? At this moment I even can't imagine from where (except this > group) I could learn that functions mentioned exist... === Subject: Re: Undocumented functions for working with graphics HI, Functions that are not documented are likely to be ephemeral, or to be ones that may have their specifications/design changed without notice. If they do not have a usage message then they are not likely to be documented anywhere. However, you can try to look in code that uses them to reverse engineer how they are called. The rest simply requires experimentation. Here is one way to go about this reverse engineering.... If the given function has the attribute ReadProtected, then it generally will be something that is written in top level Mathematica code. So, if you Unprotect that function and then remove the ReadProtected attrubute, you can then see the function's Mathematica code by executing ??functionname the function is called and how it is likely to work. I hope this helps a bit... --David http://scientificarts.com/worklife Does anyone know where such functions as Image`ToGraphicsRaster and > Image`PossibleImageQ are documented. Are there other such built-in > functions? At this moment I even can't imagine from where (except this > group) I could learn that functions mentioned exist... === Subject: Re: differentiation operator That works reasonable well. For example, all the following forms work OK (in the last form I simulate the Mathematica 2D standard form): d/dx Sin[x] (d/dx) Sin[x] (d Sin[x])/dx d -- Sin[x] dx However, what does NOT work as one might hope is... d Sin[x]/x ...even though that is a perfectly acceptable, traditional (with a small t) mathematical form for the same derivative. Of course the use of the d/dx ties everything to a particular variable. Change from x to y or t or something else, and it's dead. > Hi Chee, I did not thoroughly test it, but if you define: $Pre = # /. Times[ d expr_ Power[dx, -1]] :> D[expr, x] & the following examples work: d/dx x^2 -> 2x d/dx Sin[x] -> Cos[x] d/dx (x-x^3) -> 1-3x^2 e.t.c Daniel >> Hi All >> My students have asked me whether it is possible to define the operator > >> df[x]/dx for differentiation rather than D[f[x],x]. The operator is > >> available in a palette but it does not seem to do anything other than for > >> display only. >> Example: d/dx(x^2)=2x rather than D[x^2,x]=2x. >> Am I missing something? > >> Mr. Chee -- 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: Generic nested menus implementation @ albert, Oh yes!, this is what I needed 3 months ago. Some tweaks requested/ questions: 1. how do I set options for the visual aspects (ie, imagesize, color, fontsize etc.) of the ActionMenu in the code. Its hard to figure that out somewhat. Or, did you take over any ability to set those options. 2. I would like to set visual options per level (ie, Level1->Blue, Level2->Red, etc.) like this (similer to how grid works): {1->Blue,2- >Red}, or via name of each level. Or, allow use of BaseStyle for whole shabang. 3. The choose' part be given options of color, fontsize etc. or even another word, Pick, even a symbol character. 4. Set up the code so it can live/work after the kernel is off. See J. Fultz's really cool and informative notebooks on dynamic stuff. number of Gui problems for me. :-) andrew === Subject: Magnification inconsistency On the Mac, with version 7.0.0 There are three different ways to change the magnification at which a current notebook is displayed on screen: (a) Preferences > Advanced > Formatting Options > Font Options > Magnification (b) Window > Magnification (c) The view magnification indicator at the bottom right of the window. With a notebook containing some text, try using (a) to change the magnification to 300% and watch the indicator (c) - it does not get updated. Then, with 300% magnification already in effect from (a), use method (b) to change the magnification to 300% again (it still should say 100%). This has no visible effect. Finally, after doing all the above, use (c) to change to 300% magnification. Now you have a 900% magnified display even though the indicator (c) reads 300%. I don't have 7.0.1 yet so I don't know if this bug is still there - if yes, I'll file a report. Jens === Subject: Re: Presentation quick with grid and pasted graphic The short explanation is that Mathematica has two modes of entry -- a text mode and a math mode. The text mode formats things as a word processor would. Math mode, on the other hand, wants to fiddle with the spacing and the visual styles to be appropriate for math. You can embed one in another, and when you do and you're editing in the embedded mode, you see the beige background you describe. I'm just going to give you a recipe for doing what you want. Ideally, the steps of this recipe would be condensed and on the Classroom Assistant palette, but they're not (I'll follow up internally on this, and we'll consider a few modifications for a future version). * Click some place between cells, so that you have the long horizontal line which serves as the cell insertion point. * Click the 1x2 palette button that you did before. * Choose the menu item Cell->Convert To->TraditionalForm Display. * Select the first placeholder in the grid again and choose Insert->Typesetting->New Inline Cell (Ctrl+9). * The cell is still an input cell and will be bold. To get rid of that, select the cell bracket and choose Format->Style->Text (Cmd+7). Or, somewhat easier, evaluate this code to make a button, click on a cell insertion point, and click the button: Button[Insert Text+Math Grid, NotebookWrite[InputNotebook[], Cell[BoxData[ FormBox[GridBox[{{Cell[text], [Placeholder]}}], TraditionalForm]], Text]]] You could turn this button into a palette (Palettes->Generate Palette from Selection) and install it (Palettes->Install Palette...) and use it later (Palettes->) as well. Note that with this solution, you'll still get beige when editing your text, but only around the text, and it'll go away if you click anyplace else. You will not get beige on the right-hand element if you, for example, copy and paste a graphic into it. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > I trying to create a presentation (slide show) using Mathematica > 7.0.1 on Mac OS X 10.4.11 for the first time. I am using the default stylesheet. On the first slide, I inserted a > 1x2 grid (using the classroom assistant palette). On the left hand > side of the grid I typed some text. When I do so, the background of > the grid turns beige. On the right hand side of the grid I copied > and pasted a 3D rotatable graphic (a cube obtained from PolyhedronData > [Cube]). Again, the background is beige. When I click somewhere > else not on the grid, the background turns white. Then, when I view > the slide in slideshow mode, the grid background is white. However, > if I rotate the graphic, the background of the grid becomes beige, > and I am unable to return it to white by clicking off the grid. > Clicking somewhere else returns only the text side to white but not > the graphic side. The result is a poor looking presentation. Do any of you have any > suggestions for avoiding this behavior? Is there a preferred method > for placing text and graphics side by side? > Adam === Subject: Re: What should be a simple task.... Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another syste= m; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent= . In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simp= le > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either th= e > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-c= op= > ied > from there; The curves look good, but now the whole image is just a lit= tl= > e > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefi= ng= > s > for electronic vs. paper presentation, but I'm a little concerned that'= s > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin I confirmed some quality problems Kristin is talking about. I tried > copying and pasting the Plot[x,{x,0,1}] graphic from Mathematica 7 to Experiment #1: First I selected the graphic (not cell) then right- > clicked to Copy Graphic. Next, I pasted to a slide and noticed some > poor quality in the pasted graphic. > Experiment #2: First I selected the cell of the graphic -- converted > it to Metafile. I noticed that the converted graphic in Mathematica > looks the same as the pasted Powerpoint graphic from Experiment #1. > Experiment #3: Repeated Experiment #2 except that I converted the > graphic to Bitmap. Much better quality in the pasted graphic except > for some clipping at margins of the graphic. I think the Metafile conversion utility (Powerpoint/Mathematica) has > some quality issues. Can someone recommend a command to extend the margins of the graphics > to avoid clipping something important when the graphic is pasted? Lawrence- Hide quoted text - - Show quoted text - format) when pasting. Use Edit > Paste Special and select Enhanced Metafile. Windows/Enhanced Metafiles do not support antialiased drawing. To illustrate this, evaluate Plot[Sin[x], {x, 0, 2 [Pi]}, PlotStyle -> {Antialiasing -> False}]. It looks the same as the metafile. So, if you would like a metafile to look better in print, try this before copying/saving the graphic: FE`Evaluate@FEPrivate`SetMetafileConversionQuality[High] This will create the metafile based on a higher resolution device, and will consequently take longer to load. This setting presists throughout the session and is *NOT* restored when a new session is started. Use Normal to return to the default setting. Ian === Subject: Re: What should be a simple task.... > Can someone recommend a command to extend the margins of the graphics > to avoid clipping something important when the graphic is pasted? > I've found a way: I used the ImagePadding option to extend the margin around the image to avoid clipping after pasting. Plot[x,{x,0,1},ImagePadding->20] === Subject: Re: What should be a simple task.... > I've had problems with this too. Exporting Mathematica graphics into > Office 2007 programs in a vector format is kind of a pain. The best > way to keep the graphics looking good is to keep them in Mathematica. I'd again put in a strong plug for putting them into PDF, then organizing, editing, *and presenting* them using nothing but Adobe applications. I've had a few troubles (eventually solved) getting graphics out of Mathematica and into PDF -- but never _any_ troubles using, modifying, and re-purposing these graphics further using Acrobat, Illustrator and Photoshop Elements (and iView MediaPro as my basic organizing and cataloging tool). === Subject: Re: What should be a simple task.... my views about this issue are aligned with those of AES who has just posted. I would perhaps add that my instincts would be to write the graphic to disk as png or pdf [ depending on the OS you use ] then use that graphic file in LaTeX or if you really have to , in powerpoint. 2009/6/10 Nelson-Patel, Kristin : > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-cop= ied > from there; The curves look good, but now the whole image is just a littl= e > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefing= s > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin -- Peter Lindsay === Subject: Re: What should be a simple task.... Oh, and on extending the margins... The ImagePadding option needs to be tweaked to give more points on the left to avoid cutting off the frame tick labels. The Automatic algorithm doesn't seem to properly sense where the content is ending. ImagePadding -> {{40, 10}, {20, 10}} seems to work well. -Kristin -----Original Message----- === Subject: Re: What should be a simple task.... > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-copied > from there; The curves look good, but now the whole image is just a little > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefings > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin I confirmed some quality problems Kristin is talking about. I tried copying and pasting the Plot[x,{x,0,1}] graphic from Mathematica 7 to Experiment #1: First I selected the graphic (not cell) then right- clicked to Copy Graphic. Next, I pasted to a slide and noticed some poor quality in the pasted graphic. Experiment #2: First I selected the cell of the graphic -- converted it to Metafile. I noticed that the converted graphic in Mathematica looks the same as the pasted Powerpoint graphic from Experiment #1. Experiment #3: Repeated Experiment #2 except that I converted the graphic to Bitmap. Much better quality in the pasted graphic except for some clipping at margins of the graphic. I think the Metafile conversion utility (Powerpoint/Mathematica) has some quality issues. Can someone recommend a command to extend the margins of the graphics to avoid clipping something important when the graphic is pasted? Lawrence === Subject: Re: What should be a simple task.... maybe Power Point will render the data layer instead of the preview layer. I independently reached the conclusion that the problem is in fact Power Point 2007 by noting that printing looks just fine. I haven't had a chance to try this technique, but will. Someone also made the suggestion that I should just do all of my presentations within Mathematica on principle. Trust me, nothing would make me happier; but I'm not an island and my entire organization and all of the people who pay us to do our work, use Power Point and want their products in Power Point. No one here is going to figure out how to make my organization's chart templates and logos in Mathematica for me, and being a full-time working mom of two toddlers, I'm not flush with the personal time to do this at home either. I actually like my workflow between the two programs, where I draw quick cartoons in Power Point to illustrate rough geometries, cut and paste into mathematica, do all of the technical development, modeling and analysis, and documentation in Mathematica, and then move the results plots back into Power Point where I can then tell the story. Maybe that was more justification than was required, but I just don't think it's realistic to impose a Mathematica-only workflow on the customer base. The beauty of Mathematica is it's incredible flexibility and power-- people can apply it to literally anything they want in any way they want. That should be honored in the way the company handles interface issues, or the brand is undermined. One reason I haven't gone to bitmaps, as others have suggested, is that my organization really likes us to put our briefings through a team of graphics people who work in Illustrator to make nit-picky graphics changes. Those graphics people need (or at least say they need) vector-based formats. Metafiles seem to work fine. I think they'd prefer EPS, but that really never worked well out of Mathematica. Oftentimes, our management takes our briefings on the road and don't want to have to come to us to fiddle around with our plots, so they want the graphics people to be able to edit colors, thicknesses, etc, without wasting technical person-hours on it unless they need a real substantive change. It's all in the details! -Kristin -----Original Message----- === Subject: Re: What should be a simple task.... > Hi :) I am an analyst (applied physics and math) who has to present all > of my work in Power Point briefings, sometimes on paper, sometimes > electronically. I vastly prefer working in Mathematica to another system; > however, I'm currently ham strung by my inability to transfer simple > plots from Mathematica 7 to Power Point 2007 in a way that looks decent. In previous versions of both, I was able to Copy As: Metafile by right > clicking on the plot in Mathematica and Paste Special: Metafile in > Power Point, and all would be well (Ok, I had to tweak line thickness > settings and fonts in my plots to make them survive the transfer, but > that was fine). Now, I have select the whole cell rather than just > the plot to get the Copy As: metafile option, and I have to go all the > way to the menu bar to do it (no longer an option on the right click). > Fine, I can deal with that, but I can't deal with the fact that my simple > plots look completely ratty now upon pasting into Power Point. There's all this stair stepping in curves which should be smooth. > I've played with the PlotPoints option-no effect. I've exported into > different form ats with varying ImageResolution and imported; Either the > fonts get screwed up or it looks even worse or there's ugly aliasing or > no effect on the stair stepping. I've exported to PDF and snapshot-copied > from there; The curves look good, but now the whole image is just a littl > bit blurry/soft, a little too much to pass muster with my supervisors > and sponsors. I'm really getting frustrated now, have spent way too much time on what > *was* a solved problem before my upgrades, and beginning to suspect > that the problem is some import or paste/display setting in Power Point > that I can't reach. I really don't want to have two different briefings > for electronic vs. paper presentation, but I'm a little concerned that's > where this is heading, or I'm going to have to use the other system to > make my plots. Which would bea shame. Has anyone figured this one out yet? Help, please-I'm crying uncle. > This is one of those stupid simple problems that also happens to be > quite fundamental to the ability to make good use of Mathematica. -Kristin I confirmed some quality problems Kristin is talking about. I tried copying and pasting the Plot[x,{x,0,1}] graphic from Mathematica 7 to Experiment #1: First I selected the graphic (not cell) then right- clicked to Copy Graphic. Next, I pasted to a slide and noticed some poor quality in the pasted graphic. Experiment #2: First I selected the cell of the graphic -- converted it to Metafile. I noticed that the converted graphic in Mathematica looks the same as the pasted Powerpoint graphic from Experiment #1. Experiment #3: Repeated Experiment #2 except that I converted the graphic to Bitmap. Much better quality in the pasted graphic except for some clipping at margins of the graphic. I think the Metafile conversion utility (Powerpoint/Mathematica) has some quality issues. Can someone recommend a command to extend the margins of the graphics to avoid clipping something important when the graphic is pasted? Lawrence === Subject: Re: What should be a simple task.... Hands down, PDF is the best way to exchange graphics between programs if both programs support it. Unfortunately, Powerpoint does not natively support PDF. It uses a filter that converts PDF's to a bitmap (defeating all the advantages of the vector format), and its default settings yield the really poor images you are complaining about. On a Mac, I create my presentations on Keynote, which handles PDF's natively. If I must for compatibility reasons, I export the Keynote to Powerpoint when I am done. The export filter in Keynote does a much better job of creating readable bitmaps for Powerpoint than Powerpoint itself does. On a PC, your best bet is using the PNG format. Select the graphic, right click, Save As..., and select PNG as the file format (I've only used a Mac since upgrading to 7; your mileage may vary but I remember this working on a PC). It's a little blurry, but acceptable at the resolutions usually available on a projector. I feel your pain. One does not always get to choose the medium one uses to communicate, but we do the best with what is imposed upon us. Daniel === Subject: keybord problem with version 7 and altgr { }), a blank is inserted in front of [ or {. === Subject: Correction to Fundamental Theorem of Calculus and Mathematica I define a function (using f[x_]:=) as the definite integral (from 0 to x) of sin(t^2). When I differentiate using Mathematica I get the correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all works well. Can someone explain the odd behavior? Len === Subject: Re: RandomReal gets stuck > And Mathematica does not recognizes > input Subscript[a,i] as equivalent to a[i]. You mean something like zero doesn't come from a[1] - Subscript[a, 1] for instance? and False That's true, but when using this trick I never actually type or use the subscripted form; I only see it. So there's no chance the conflict can occur for me. Subscripts also disappear if you assign values, such as in a[2] = 3; a[2] 3 a[j] displays subscripted for any j where a[j] is undefined. Maybe you won't find it useful, but maybe you will. I don't know. Bobby >> If you want to use subscripted variables, it might help to use this >> code: >> subFunction::usage = subFunction[a] causes inputting a[i] or >> !(*SubscriptBox[a, i]) to be synonymous, while always >> displaying the latter in outputs. >> subFunction[a] causes inputting a[i] or !(*SubscriptBox[a, >> i]) to be synonymous, while always displaying the latter in >> outputs. >> subFunction[a_Symbol]:=Block[{aa=ToString[a]},MakeExpression[Subscrip= > tBox[ToString@a,i_],f_]:=MakeExpression[RowBox[{ToString@a,[,i,]}]];M akeBoxes[a[i_],f_]:=SubscriptBox[MakeBoxes[a,f],MakeBoxes[i,f]]] >> The result is that you can refer to a[i] or Subscript[a,i] >> interchangeably, but it always displays in the subscripted form. I find >> it >> much easier to use a[i] while typing formulas, so I'm getting the best >> of >> both worlds. >> Not sure if that addresses everything brought up on the thread, of >> course. >> Bobby > It is very interesting, thank you. But as I understand the definition > aa=ToString[a] > inside Block is not necessary. And Mathematica does not recognizes > input Subscript[a,i] as equivalent to a[i]. There seems to be some > errors in the code. > -- DrMajorBob@bigfoot.com === Subject: Re: RandomReal gets stuck You're correct that Block and aa=ToString@a are unnecessary; it's a very long time since I looked at the code. But it works just fine, as it is or with those removed; I just neglected to tell you how to use it. For instance, subFunction[ a_Symbol] := (MakeExpression[SubscriptBox[ToString@a, i_], f_] := MakeExpression[RowBox[{ToString@a, [, i, ]}]]; MakeBoxes[a[i_], f_] := SubscriptBox[MakeBoxes[a, f], MakeBoxes[i, f]]) Now enter subFunction[a] then Array[a, 10] Array[Subscript[a, #] &, 10] and observe. Both outputs are the same. Or enter a[j] whose output is Subscript[a,j] (But looking like a subscripted variable, of course.) It only affects the symbol a, which you've set up using subFunction[a]. Bobby >> If you want to use subscripted variables, it might help to use this >> code: >> subFunction::usage = subFunction[a] causes inputting a[i] or >> !(*SubscriptBox[a, i]) to be synonymous, while always >> displaying the latter in outputs. >> subFunction[a] causes inputting a[i] or !(*SubscriptBox[a, >> i]) to be synonymous, while always displaying the latter in >> outputs. >> subFunction[a_Symbol]:=Block[{aa=ToString[a]},MakeExpression[Subscrip= > tBox[ToString@a,i_],f_]:=MakeExpression[RowBox[{ToString@a,[,i,]}]];M akeBoxes[a[i_],f_]:=SubscriptBox[MakeBoxes[a,f],MakeBoxes[i,f]]] >> The result is that you can refer to a[i] or Subscript[a,i] >> interchangeably, but it always displays in the subscripted form. I find >> it >> much easier to use a[i] while typing formulas, so I'm getting the best >> of >> both worlds. >> Not sure if that addresses everything brought up on the thread, of >> course. >> Bobby > It is very interesting, thank you. But as I understand the definition > aa=ToString[a] > inside Block is not necessary. And Mathematica does not recognizes > input Subscript[a,i] as equivalent to a[i]. There seems to be some > errors in the code. > -- DrMajorBob@bigfoot.com === Subject: Solving simultaneous integral equation Hello I have a problem of the form Integrate[f[s],{s,(b-e)/c,(b+e)/c] I am trying to solve for c and e (b is known). f[s] cannot be integrated algebraicly, only by by setting values for e and c and using NIntegrate. I also have a supplimentary equation linking b and c, which cannot be inverted using solve to give a relationship between e and c. I am trying to use NSolve or FindRoot to solve the system of equations, but I keep getting errors saying that algebraic limits are invalid for NIntegrate. Any help or advice would be greatly appreciated. Mat === Subject: Re: Creating Matrix from vectors Use Transpose a = Array[s, {3, 5}] {{s[1, 1], s[1, 2], s[1, 3], s[1, 4], s[1, 5]}, {s[2, 1], s[2, 2], s[2, 3], s[2, 4], s[2, 5]}, {s[3, 1], s[3, 2], s[3, 3], s[3, 4], s[3, 5]}} Transpose[a] {{s[1, 1], s[2, 1], s[3, 1]}, {s[1, 2], s[2, 2], s[3, 2]}, {s[1, 3], s[2, 3], s[3, 3]}, {s[1, 4], s[2, 4], s[3, 4]}, {s[1, 5], s[2, 5], s[3, 5]}} Bob Hanlon Suppose i have a n number of vectors say s1, s2,... sn. I want to create a matrix such that these n vectors are the n columns of the matrix. I tried using A = {s1,s2,..,sn}; however this keep the vectors intact and stacks them one below the other. How can i make a matrix from these?? Can anyone please help me with this. === Subject: Re: Getting histogram information data = RandomReal[ NormalDistribution[0, 5*RandomReal[]], {RandomInteger[{100, 500}]}]; h = Histogram[data] Binwidth bw = Cases[h, RectangleBox[c1_, c2_] -> c2 - c1, Infinity][[1, 1]] Bob Hanlon All, I have used the Histogram[] function many times. It works well and has lots of options but seems to lack transparency. Specifically, if I don't specify a bin width and let the function compute it, I want to know exactly what bin width the function used. Obviously, with some additional work I can infer the bin width from the resulting histogram. It would be better, however, to know precisely the bin width that the function actually used. I consulted Wolfram support about this and they were helpful, providing me with a bit of clever but rather obscure code that returns the populated histogram bins. But this still requires additional work to infer the bin width. The code provided by Wolfram support is listed after the signature. Can anyone figure out how to get the bin width directly from the Histogram[] function? Raul Martinez Code: data1=RandomReal[NormalDistribution[0,1],100]; h = Reap @Histogram[data1,Automatic,Function[{xbins,counts},Sow[counts];counts]] h[[2]] h[[2,1,1]] (*This will give the number of bins.*) h[[2,1,1]]//Length === Subject: Re: Seeking the Eliza source file Eliza.m Here is the URL for MathSource: http://library.wolfram.com/infocenter/MathSource/1818/ george > The code for Matthew Markerts Mathematica version of Eliza is > MathSource item pub/Applications/Other/0204-635-0011, entitled > Eliza.m. Submitted to MathSource in October 1992. > === Subject: Re: Seeking the Eliza source file Eliza.m the bottom part of the window was hidden so I didn't see that there was a download. that teach me to not browse at 7am with little sleep. ;-) lol === Subject: Re: Seeking the Eliza source file Eliza.m > The code for Matthew Markerts Mathematica version of Eliza is > MathSource item pub/Applications/Other/0204-635-0011, entitled > Eliza.m. Submitted to MathSource in October 1992. > Have you tried Google? It's the second hit. http://library.wolfram.com/infocenter/MathSource/1818/ === Subject: Re: Seeking the Eliza source file Eliza.m http://library.wolfram.com/infocenter/MathSource/1818/ ? (Google search: Eliza Mathematica) Ingolf Dahl -----Original Message----- === Subject: Seeking the Eliza source file Eliza.m The code for Matthew Markerts Mathematica version of Eliza is MathSource item pub/Applications/Other/0204-635-0011, entitled Eliza.m. Submitted to MathSource in October 1992. === Subject: Avoid printing leading zero How do you avoid printing the leading zero in -0.03? I need to construct the string -.03 . Something like this does not work: ToString@NumberForm[-0.3, {0, 2}] JosÌ© === Subject: Re: perturbation methods example from stephen lynch's book? Hi Sean, recently for Poincare-Lindstedt expansions, so I thought I'd give it a go. My P-L program was completely automatic and could, in theory, go to arbitrary order. Automating the method of multiple time scales is a harder proposition (even in the simplified version discussed by Lynch), as I had to hold Mathematica's hand through some of the steps. Also, in Lynch's book, he only goes to order x(t)~x0(t, eps t)+O(eps) -- the removal of the secular terms at O(eps) is used to fix the coefficients in x0 This is the general DE he was investigating -- init. cond's are x(0) =a, x'(0)=0: DE[x_, t_, eps_, f_] := x''[t] + x[t] - eps f[x[t], x'[t]] Produce the DEs up to O(eps)^2: DE[x, t, eps, (1 - #1^2) #2 &] /. {x[t] -> x0[t, eps t] + eps x1[t, eps t], Derivative[n_][x][t] :> D[x0[t, eps t] + eps x1[t, eps t], {t, n}]}; ser = Series[% /. f_[t, eps t] :> f[t0, t1], {eps, 0, 1}] // Simplify Solve the zero'th order DE: DSolve[ser[[3]][[1]] == 0, x0, {t0, t1}] The result is equivalent to: x0Soln = x0 -> (R[#2] Cos[#1 + th[#2]] &); Only the R(0) and th(0) terms are fixed by the initial conditions -- giving R(0)=a, th(0)=0. (note that Lych said R(0)=a/2... I'm not sure why) The derivatives of R and th are fixed by the removal of secular terms. Here's the DE of order eps: Collect[ser[[3]][[2]] /. x0 :> (R[#2] Cos[#1 + th[#2]] &) // TrigReduce, {Sin[_], Cos[_]}, Simplify] The resonant terms are removed from the DE by setting the coefficients of the linear trigonometric terms to zero: thsoln = DSolve[th'[t1] == 0 && th[0] == 0, th, t1] Rsoln = DSolve[4 R[t1] - R[t1]^3 - 8 R'[t1] == 0 && R[0] == a, R, t1] [[2]] // FullSimplify Then we get Lynch's final result for x0: x0[t1, t2] /. x0Soln /. Rsoln /. thsoln I'm sorry I haven't got anything more elegant for this... Simon PS I think there are a couple of typos in the examples 7 and 9... did you also spot them? PPS Lynch's code for example 8 works fine. Dt is a total derivative... it assumes everything is a dependent variable unless told otherwise - thus his earlier declaration SetAttributes[{w1,epsilon},Constant]. === Subject: polynomial of 7th order, some structure hi, I have an equation i have been trying to solve, but no amount of Solve, Reduce or ToRadical seems to produce an answer. x(1+x^2)^3 == a x^4 +b x^3 +...+e I know that it has one or three real roots, depending on combinations of coefficients, with only one root at x>0. That is the one that I want, the root that is > 0. Does anyone have any ideas what I can do? I can plot the Root[] results, and I can see that it is usually the same one root from the list, for most coefficient combinations. Any way i can get the formula without plugging in the values? === Subject: Re: Creating Matrix from vectors Transpose[] There is no native matrix in Mathematica. The only data native data structure is List[] (what you usually see and input between braces {...}.) However, List is infinitely nestable, and there are functions that understand that if you apply them to a list of lists all of equal length, the outer list is treated as a matrix (for example, Det[] or Dot[] or MatrixForm[]). This is hugely flexible, because these same functions treat any level of nesting of lists (of the right structure) as a high order tensor. === Subject: Re: Creating Matrix from vectors > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the > matrix. > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. > A = Transpose[{s1,s2,...,sn}] === Subject: Re: Creating Matrix from vectors > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the matrix= . > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. What you tried actually creates a matrix with the vectors as rows; to get them as columns simply transpose this: columnMatrix = Transpose[{s1,s2,...,sn}] Peter. === Subject: Re: Creating Matrix from vectors Transpose the matrix you give in your example using the Transpose[ ] function (or put esc-tr-esc behind the last curly bracket. > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the matrix= . > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. === Subject: Re: Creating Matrix from vectors If I understand correctly, you should just Transpose the matrix: s1 = {a, b, c}; s2 = {d, e, f}; s3 = {g, h, i}; A = Transpose[{s1, s2, s3}] A // MatrixForm 2009/6/11 Kinu create a matrix such that these n vectors are the n columns of the matrix. > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. -- Por favor eviten enviarme archivos adjuntos de Word o Powerpoint ( http://www.gnu.org/philosophy/no-word-attachments.es.html ) === Subject: Re: Creating Matrix from vectors Hello Kinu: Please try: v01 = {a, b, c} v02 = {d, e, f} v03 = {g, h, i} MatrixForm[Transpose[{v01, v02, v03}]] MATTHIAS BODE Las Lomas de Aranjuez S 17.35775¡, W 066.14577¡ LVSABA@HOTMAIL.COM -------------------------------------------------- === Subject: Creating Matrix from vectors > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the matrix. > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. === Subject: Creating Matrix from vectors Specific issue > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the matrix= . > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. My exact problem is as follows.. I am getting vectors from my program which is of the form v1 = {{1},{2},{3}}; v2 = {{4},{5},{6}}; BUT NOT v1 = {1,2,3} and v2 = {4,5,6} Now if i use A = {v1,v2} and then Transpose[A] i am getting the required matrix only in the 2nd case i.e when v1 = {1,2,3} and similarly v2. However when i use the same A = {v1,v2} in the 1st case i.e when v1 = {{1},{2},{3}} and similarly v2, i am not getting the required matrix. If anyone would help me with this specific point it will be helpful. I have also seen that the dimension in case 1 is {3,1} while that in case 2 is {3}. If there is any way to interchange the two .. that also will suffice. i.e if i can change {{1},{2},{3}} to {1,2,3} that will also suffice. Please help. === Subject: Re: Creating Matrix from vectors Mathematica does not have matrix as a built-on primitive type of data structure. To Mathematica a matrix is just a list of lists, with the individual lists being its rows. For example, v1 = {1, 2, 3}; v2 = {4, 5, 6}; m = {v1, v2} {{1,2,3},{4,5,6}} And if you want to display such a list of lists to look like a conventional matrix, wrap it in MatrixForm: MatrixForm[m] If you want to interchange rows with columns, you may use Transpose: Transpose[m] {{1,4},{2,5},{3,6}} And now if you wrap that with MatrixForm, you'll see the sort of display you want, where the original vectors v1 and v2 appear as the columns. > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the matrix. > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. > -- 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 Matrix from vectors Assuming that the s1, s2,... are defined as equal length lists, then why can't you just use: A = Transpose[{s1,s2,..,sn}]; David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Suppose i have a n number of vectors say s1, s2,... sn. I want to create a matrix such that these n vectors are the n columns of the matrix. I tried using A = {s1,s2,..,sn}; however this keep the vectors intact and stacks them one below the other. How can i make a matrix from these?? Can anyone please help me with this. === Subject: Re: Creating Matrix from vectors Just add Transpose. For instance In[1]:= s1 = {1, 3, 2}; s2 = {10, 20, 30}; A = Transpose[{s1, s2}] Out[1]= {{1, 10}, {3, 20}, {2, 30}} This is a 3 by 2 matrix: evaluate MatrixForm[A] to see it in the usual form. Adriano Pascoletti 2009/6/11 Kinu create a matrix such that these n vectors are the n columns of the matrix. > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. === Subject: Re: Creating Matrix from vectors and a matrix is not a list of vectors ? But v1 = {1, 2, 3}; v2 = {3, 4, 5}; v3 = {6, 7, 8}; A = {v1, v2, v3}; MatrixQ[A] gives True .. Jens > Suppose i have a n number of vectors say s1, s2,... sn. I want to > create a matrix such that these n vectors are the n columns of the matrix. > I tried using A = {s1,s2,..,sn}; > however this keep the vectors intact and stacks them one below the > other. How can i make a matrix from these?? > Can anyone please help me with this. > === Subject: Operations on InterpolatingFunction Solving a simple differential equation: ifun = First[ u /. NDSolve[{u''[t] + u[t] == 0, u[0] == 0, u'[0] == 1}, u, {t, 0, [Pi]}]] returns the InterpolationFunction object, as expected. I can integrate this function (and obtain another InterpolatingFunction to be plotted, etc.) by: Integrate[ifun[t], t] 1. Why doesn't the following produce an InterpolatingFunction in the same way? Integrate[ifun[t]^2, t] 2. How can I normalize the solutions found using NDSolve? Norm[ifunt[t]] doesn't work... === Subject: Re: Locator as a button No idea, anyone? Istvan === Subject: Re: Dependent dynamic controls pretty simple, I should have fiddled a bit more with the code. Istvan I think you can understand what happens when using some extra prints: Module[{sw = True, a, b, c, n, assign}, assign[switch_, x_] := If[switch, > a = x; c = f@x; n = Position[aSet, x][[1, 1]], > b = x; c = g@x; n = Position[bSet, x][[1, 1]] > ]; assign[sw, First@If[sw, aSet, bSet]]; > Print[{a, b, c, n}]; > Panel@Column@{ > Dynamic@Column@{sw, If[sw, a, b], c, n}, > Grid[{{ > a, > RadioButton[Dynamic[sw, (sw = #; assign[#, First@aSet]) = &], > True], > PopupMenu[Dynamic[a, assign[sw, #] &], aSet, > Enabled -> Dynamic[sw]] > }, { > b, > RadioButton[Dynamic[sw, (sw = #; assign[#, First@bSet]) = &], > False], > PopupMenu[Dynamic[b, (Print[{sw, #}]; assign[sw, #]) &], b= Set, > Enabled -> Dynamic[! sw]] > }}] > } ] so what we learn is that actually everything works as intended, but then > in the end the initialization of the PopupMenu calls the setter function > once because b has no value yet. Whether this is what one should expect > or not I don't know, maybe you can find something in the documentation. > It is very easy to correct, though, by initializing b (in case sw is > initialized to False you might want to also initialize a): Module[{sw = True, a = aSet[[1]], b = bSet[[1]], c, n, assign}, assign[switch_, x_] := If[switch, > a = x; c = f@x; n = Position[aSet, x][[1, 1]], > b = x; c = g@x; n = Position[bSet, x][[1, 1]] > ]; assign[sw, First@If[sw, aSet, bSet]]; Panel@Column@{ > Dynamic@Column@{sw, If[sw, a, b], c, n}, > Grid[{{ > a, > RadioButton[Dynamic[sw, (sw = #; assign[#, First@aSet]) = &], > True], > PopupMenu[Dynamic[a, assign[sw, #] &], aSet, > Enabled -> Dynamic[sw]] > }, { > b, > RadioButton[Dynamic[sw, (sw = #; assign[#, First@bSet]) = &], > False], > PopupMenu[Dynamic[b, assign[sw, #] &], bSet, > Enabled -> Dynamic[! sw]] > }}] > } ] I have also rearranged some Dynamics since the controls need not be > recreated every time one of the variables changes. > Another suggestion would be to use DynamicModule instead of just Module, > but that depends also on what you really try to achieve. With Module you > will create a set of variables at each call, and they will persist for > the rest of the session. hth, albert === Subject: Re: Draw a 3D surface This is a question inspired by Jens's use of RegionFunction below. In the documentation for RegionFunction there is an example where RegionFunction isa pure function is called with a slot number: SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#6 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]] Here I was perplexed to know what #6 was (and still cannot figure it out). How do I get to see what #6 is? I then tried different values for the slot number: {SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#1 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]], SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#2 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]], SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#3 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]], SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#4 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]], SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#5 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]], SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (#6 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]]} and the result was an interesting sequence of 3D objects (note that there are only 6 slots valid - #7 fails) As a further enquiry I tried a Table version of the above: Table[SphericalPlot3D[1 + Sin[5 =CE=B8] Sin[5 =CF=86]/5, {=CE=B8, 0, Pi}, {=CF=86, 0, 2 Pi}, Mesh -> None, RegionFunction -> (# i > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]], {i, 1, 6, 1}] To my surprise the resulting 3D objects were different after #1. I would appreciate any enlightenment here regarding slots and valid Table increments for slots. Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com Mathematica 7.0.1 for Mac OS X x86 (64 - bit) (18th February 2009) MacOS X V 10.5.6 g[y_] := y^2 - 2 Plot3D[Exp[-x^2 - y^2], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, > RegionFunction -> Function[{x, y, z}, x < g[y]]] > ? Jens > I intend to draw a 3D surface, which is defined in a tricky way. >> Given >> function f(x, y), the values of f are known but the range is >> determined by a function of y, g(y). I need to plot x as a function >> of >> y and f within the range determined by g(y). Can anybody help? >> Appreciate! >> Jun Lin > === Subject: Re: Creating Matrix from vectors >Suppose i have a n number of vectors say s1, s2,... sn. I want to >create a matrix such that these n vectors are the n columns of the >matrix. I tried using A = {s1,s2,..,sn}; however this keep the >vectors intact and stacks them one below the other. How can i make a >matrix from these?? Can anyone please help me with this. Use Transpose. That is, A = Transpose@{s1,s2,..,sn}; will be what you want. === Subject: Re: Correction to Fundamental Theorem of Calculus and Works in my version. $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) f[x_] := Integrate[Sin[t^2], {t, 0, x}] D[f[x], x] Sin[x^2] g[x_] := Integrate[Exp[-t^2], {t, 0, x}] D[g[x], x] E^(-x^2) Bob Hanlon I define a function (using f[x_]:=) as the definite integral (from 0 to x) of sin(t^2). When I differentiate using Mathematica I get the correct answer of sin(x^2). But when I define a function (using g[x_]:=) as the definite integral (from 0 to x) of e^(-t^2) and differentiate, I get the incorrect answer of 0. (The correct answer is e^(-x^2).) Why the inconsistency? Oddly, if I define the function g above using = instead of :=, all works well. Can someone explain the odd behavior? Len === Subject: AT&T Usenet Netnews Service Shutting Down Distributrion: internal Please note that on or around July 15, 2009, AT&T will no longer be offering access to the Usenet netnews service. If you wish to continue reading Usenet newsgroups, access is available through third-party vendors. === === === Subject: A Joint Fourier - Laplace Inversion I am trying to work out numerically the inverse Fourier - Laplace transform of a function , F[q,s], (where q & s are the Fourier and Laplace parameters respectively), for various given values of x & t. f (x, t) is the joint inverse of F[q, s]. I already have the code for doing the numerical inversion of a Laplace transform; it needs to be fed a function of s and a t value. Hence I first carry out the Fourier inversion numerically with NIntegrate, hoping to get the function of s to feed into the Laplace inversion routine (InvLap) This is my attempt IFL[F_, x_?NumericQ, t_?NumericQ]:= Module[ {g}, g[s_?NumericQ]:= 1/(2Pi) NIntegrate[F*Exp[I q x],{q,-Infinity, Infinity}] InvLap[g,t] ] I 'd like IFL[F[q,s], 3.5, 2.1] to give me f (3.5, 2.1), but it doesn't ! I can't suss out how to get the g[s] function. Sid === Subject: Re: Integrate Bug > I am trying to calculate this integral that should be positive.But th= e > answer is 0. In: Integrate[(1)/(z^2 + b^2 + a^2 - 2 z b Sin[[Theta]] - > 2 a b Cos[[Theta]])^(1/2), {[Theta], 0, 2 [Pi]}, > Assumptions -> {a > 0, b > 0, z > 0}] Out:0 Anybody have notice a situation like that? My platform is MacOSX 10.4 and Mathematica 7. Best wishes, Further to my previous post, seems that one single formula suffices : F[a_, b_, z_] := > (4 Sqrt[a^2 + b^2 + z^2 + 2 b Sqrt[a^2 + z^2]]* > Abs[Im[EllipticK[(a^4 + b^4 + 6 b^2 z^2 + z^4 + > 4 b^3 Sqrt[a^2 + z^2] + 4 b z^2 Sqrt[a^2 + z^2] + > 2 a^2 (3 b^2 + z^2 + 2 b Sqrt[a^2 + z^2]))/ > (a^2 - b^2 + z^2)^2]]])/Abs[a^2 - b^2 + z^2] -- > V.Astanoff 2009/6/6 Andreas Dieckmann further simplified to: (4/Sqrt[a^2 + b^2 + z^2 + 2*b*Sqrt[a^2 + z^2]]) EllipticK[(4*b* > Sqrt[a^2 + z^2])/(a^2 + b^2 + z^2 + 2*b*Sqrt[a^2 + z^2])] > Andreas- Masquer le texte des messages pr=E9c=E9dents - - Afficher le texte des messages pr=E9c=E9dents - Congratulations : you crunched and squeezed my awful formula more then can FullSimplify ! Could you please spare a few moments to explain (for those like me who are not very familiar with EllipticK) the way you did it ? -- Valeri Astanoff === Subject: Re: 60Mb dataset > I'm having a problem with Mathematica and I want to see if there's any > help for it. > Specifically, I'm operating on a 60Mb dataset. I can load it and do > minor operations, but when I try to do a more complex task, it tries > doesn't Mathematica page to disk? Or is the problem that I don't know > how to make it do so? It is not Mathematica that swaps data to disk, but the operating system. However, a 32-bit system cannot address more memory that 4 GB (and, at least on Windows, a single program can only use at most 2GB). === Subject: Exploring Baseball with Retrosheet and Mathematica A new version (2.5) of a Retrosheet-enabled baseball package for Mathematica users is available at http://homepage.mac.com/klevasseur/erm New functions have been added to extract hits of various types from a game and a function, PitchCalls, which tabulates the number of strikes, balls and other pitches in a game. See http://homepage.mac.com/klevasseur/erm/2007_pitchcalls/2007_pitchcalls.html for an example of its use. Documentation and the beginning phase of system of palettes are included. This package is totally free! Ken Levasseur UMass Lowell === Subject: Re: Coding for Mathematica The results here are: f[x_] := x^2 - 2 x[1] = 1.0 For[n = 1, n < 10, n++, {x[n + 1] = x[n] - f[x[n]]/f'[x[n]]; Print[n + 1, , N[x[n + 1], 10]];}] Plot[f[x], {x, 0, 2}] 1. 2 1.5 3 1.41667 4 1.41422 5 1.41421 6 1.41421 7 1.41421 8 1.41421 9 1.41421 10 1.41421 (plus the graph) And that's exactly what your code asked for. Other code options include: Solve[f@x == 0, x] {{x -> -Sqrt[2]}, {x -> Sqrt[2]}} NSolve[f@x == 0, x] {{x -> -1.4142135623730951`}, {x -> 1.414213562373095`}} FindRoot[f@x, {x, 1}] {x -> 1.41421} FixedPointList[# - f[#]/f'[#] &, 1.] {1., 1.5, 1.41667, 1.41422, 1.41421, 1.41421, 1.41421} but not this, which doesn't terminate: FixedPointList[# - f[#]/f'[#] &, 1] That's because starting with 1, and EXACT number, causes all the iterations to use exact arithmetic as well, so the stopping rule never activates. A different sort of failure SOMETIMES occurs if you start with an arbitrary precision version of 1, if precision is lost at each iteration. To illustrate what happens, I'll limit the number of iterations: FixedPointList[# - f[#]/f'[#] &, 1, 7] {1, 3/2, 17/12, 577/408, 665857/470832, 886731088897/627013566048, 1572584048032918633353217/1111984844349868137938112, 4946041176255201878775086487573351061418968498177/ 3497379255757941172020851852070562919437964212608} or Precision /@ FixedPointList[# - f[#]/f'[#] &, SetPrecision[1., 10]] {10., 9.77815, 9.4404, 9.13824, 8.83721, 8.53618} Loss of precision wasn't severe enough to prevent convergence, in this case. Bobby > Im a first time user of Mathematica. So im trying to put in a command > related to Newton's Method. I would just like to know if once im done > typing this command in am i suppose to see the results immediately or do > i have go to something in the program to see the results of my command. > Here is the Code please can anyone tell me what im doing wrong i will be > really grateful: In[1] :=(*your name,06/06/09*) > In[2] :=(*Newton's Method*) > In[3] := f[x_] := x^2 - 2 > In[4] := x[1] = 1.0 > In[5] := For[n = 1, n < 10, n++, > {x[n + 1] = x[n] - f[x[n]]/f'[x[n]]; > Print[n + 1, , N[x[n + 1], 10]];}] > In[6] := Plot[f[x], {x, 0, 2}] > -- DrMajorBob@bigfoot.com === Subject: Re: Coding for Mathematica I think that the problem may be that you typed in the In[1]:= portion of the statements. Mathematica generates that, you don't need to type it. Copy and paste the following into your notebook, evaluate, and you will see the results immediately. (Each statement begins on a new line, but they can all be in one cell and evaluated all at once.) (* David Park, 06/08/09 *) (* Newton's Method *) f[x_] := x^2 - 2 x[1] = 1.0 For[n = 1, n < 10, n++, {x[n + 1] = x[n] - f[x[n]]/f'[x[n]]; Print[n + 1, , N[x[n + 1], 10]];}] Plot[f[x], {x, 0, 2}] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Im a first time user of Mathematica. So im trying to put in a command related to Newton's Method. I would just like to know if once im done typing this command in am i suppose to see the results immediately or do i have go to something in the program to see the results of my command. Here is the Code please can anyone tell me what im doing wrong i will be really grateful: In[1] :=(*your name,06/06/09*) In[2] :=(*Newton's Method*) In[3] := f[x_] := x^2 - 2 In[4] := x[1] = 1.0 In[5] := For[n = 1, n < 10, n++, {x[n + 1] = x[n] - f[x[n]]/f'[x[n]]; Print[n + 1, , N[x[n + 1], 10]];}] In[6] := Plot[f[x], {x, 0, 2}] === Subject: Re: Coding for Mathematica One could write an essay about Mathematica programming styles based upon the example of Newton's Method. (Indeed, I've done essentially that in one conference paper and in some materials for classes in years past.) Please, no offense intended in saying this: your programming style does betray somebody coming to Mathematica with, perhaps, too much exposure to classical programming languages where the only option was to take a one-step-at-a-time procedural approach. In the example at hand, there's no reason to manufacture a loop explicitly as you did. Instead, you could do the following, which exploits Mathematica's NestList functional programming approach: f[x_] := x^2 - 2 g[x_] = x - f[x]/f'[x]; iterates = NestList[g, 1., 9]; formatNumber[t_]:=NumberForm[t,10] Transpose[{Range[10], formatNumber /@ iterates}] // TableForm This may look longer than what you have below, but I purposely set it up so that it could readily be adapted so as to make a function that does the whole thing as a chunk. And so as to separate out the formatting aspect from the computational aspect. (I didn't include anything about plotting the original function f, since that does not seem directly related to what you asked.) One thing in your procedural code is not going to do what you expect, namely, to display each iterate to 10 decimal digits. Instead of N[#,10], which still by default displays to only 6 digits, you need NumberForm[#,10], which changes the number of displayed digits to what the 2nd argument specifies. Actually, Newton's method converges so rapidly that you won't see any difference in the iterates after the first 5, even if you asked to display 15 or 16 decimal digits. Now to answer what you explicitly asked: Yes, the result of evaluating each of the Input cells In[3] through In[5] will be to print a two-column table with second column the successive iterates. > Im a first time user of Mathematica. So im trying to put in a command > related to Newton's Method. I would just like to know if once im done > typing this command in am i suppose to see the results immediately > or do i have go to something in the program to see the results of my > command. Here is the Code please can anyone tell me what im doing wrong > i will be really grateful: In[1] :=(*your name,06/06/09*) > In[2] :=(*Newton's Method*) > In[3] := f[x_] := x^2 - 2 > In[4] := x[1] = 1.0 > In[5] := For[n = 1, n < 10, n++, > {x[n + 1] = x[n] - f[x[n]]/f'[x[n]]; > Print[n + 1, , N[x[n + 1], 10]];}] > In[6] := Plot[f[x], {x, 0, 2}] > -- 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: directionfields from StreamPlot Just to clarify, Presentations isn't a second package; it is the up-to-date DrawGraphics. You wouldn't need to buy both. Bobby > At the end of your message (below), you ask about visualizing Poincare > maps. I recommend you look at Gianluca Gorni's notebook PoincareMaps.nb > (which includes the code for a corresponding package). There's a version > for old versions of Mathematica at Gorni's web site: http://sole.dimi.uniud.it/~gianluca.gorni/ I've done much of the revision of that notebook so that it will work > with Mathematica 7, but there's still some work to do about which I've > written directly to Prof. Gorni. If you're interested, I can send you a > copy of what I have so far. However, to run Gorni's functions, you'll also need a copy of David > Park's non-free but marvelous and useful Presentations package, which > handles much of the underlying graphics. You can obtain the package > from Park's site: http://home.comcast.net/~djmpark/DrawGraphicsPage.html The posted copy of Gorni's package uses Park's older DrawGraphics > package, which like Presentations is not free and is available from the > same site of David's. > k1 and k2 are pseudo first order reaction rate constants. It can range >> from 10^-3 to 10^7 or so. (for diffusion limited process) h range >> from 0 to 1. >> The [original] system ...is kinda simplified... The system below >> behaves a bit >> more interestingly. (Let's say...k1=3, k2=7, t=50 and then...) >> Manipulate[ >> StreamPlot[{va - k1 (t^-h) a - k2 ( t^-h ) b, k1 (t^-h ) a - db}, >> {a, -10, 10}, {b, -10, 10}], {k1, 0.01,10}, {k2, 0.01, 10}, {t, 0.1, >> 50}, {h, 0, 1}, {va, 0.1, 10}, {db, 0.1, 10}] >> As you vary va, db, and h, you will see the center of stable attractor >> shifts. >> This is entirely a different post, but if I wanted to see a poincare >> section of that system, will that be doable in mathematica? Seems >> Like Stephen Lynch's book uses 3 different CAs to generate the >> figures. And Mathematica version doesn't have the codes for poincare >> section shown in fig 8.11 b.... > -- DrMajorBob@bigfoot.com === Subject: Re: directionfields from StreamPlot To clarify one point: when one updates Gorni's PoincareMaps.nb so as to work with Mathematica 7, one then replaces Park's DrawGraphics with Park's Presentations package. > At the end of your message (below), you ask about visualizing Poincare > maps. I recommend you look at Gianluca Gorni's notebook PoincareMaps.nb > (which includes the code for a corresponding package). There's a version > for old versions of Mathematica at Gorni's web site: http://sole.dimi.uniud.it/~gianluca.gorni/ I've done much of the revision of that notebook so that it will work > with Mathematica 7, but there's still some work to do about which I've > written directly to Prof. Gorni. If you're interested, I can send you a > copy of what I have so far. However, to run Gorni's functions, you'll also need a copy of David > Park's non-free but marvelous and useful Presentations package, which > handles much of the underlying graphics. You can obtain the package > from Park's site: http://home.comcast.net/~djmpark/DrawGraphicsPage.html The posted copy of Gorni's package uses Park's older DrawGraphics > package, which like Presentations is not free and is available from the > same site of David's. > >> k1 and k2 are pseudo first order reaction rate constants. It can range >> from 10^-3 to 10^7 or so. (for diffusion limited process) h range >> from 0 to 1. >> The [original] system ...is kinda simplified... The system below behaves a bit >> more interestingly. (Let's say...k1=3, k2=7, t=50 and then...) >> Manipulate[ >> StreamPlot[{va - k1 (t^-h) a - k2 ( t^-h ) b, k1 (t^-h ) a - db}, >> {a, -10, 10}, {b, -10, 10}], {k1, 0.01,10}, {k2, 0.01, 10}, {t, 0.1, >> 50}, {h, 0, 1}, {va, 0.1, 10}, {db, 0.1, 10}] >> As you vary va, db, and h, you will see the center of stable attractor >> shifts. >> This is entirely a different post, but if I wanted to see a poincare >> section of that system, will that be doable in mathematica? Seems >> Like Stephen Lynch's book uses 3 different CAs to generate the >> figures. And Mathematica version doesn't have the codes for poincare >> section shown in fig 8.11 b.... > -- 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: performance // Re: Re: Why Comparing apples to apples: Clear[fn, fn1]; fn[This is my test function][x_, y_] := x*y; fn1[x_, y_] := x*y; MapThread[ fn[This is my test function], {Range[100000], Range[100000]}]; // Timing MapThread[fn1, {Range[100000], Range[100000]}]; // Timing {0.11964, Null} {0.108061, Null} MapThread[ fn[This is my test function], {Range[100000], Range[100000]}]; // Timing MapThread[fn1, {Range[100000], Range[100000]}]; // Timing {0.108755, Null} {0.11406, Null} Or, as you see... no difference. I'd never use f[##]&, when f is the same thing in less keystrokes (and less time as well, apparently). Bobby > Hi Scot, The main source of overhead I see here is that myfunction[yourstring] is > first computed during evaluation, and the global rule base is searched > (hopefully with no match found:) ) for anything matching > since the head of any expression is evaluated > first. Consider this simple benchmark: In[1]:= Clear[fn,fn1]; > fn[This is my test function][x_,y_]:=x*y; > fn1[x_,y_]:=x*y; In[2]:= MapThread[fn[This is my test > function][##]&,{Range[100000],Range[100000]}];//Timing Out[2]= {0.911,Null} In[3]:= MapThread[fn1[##]&,{Range[100000],Range[100000]}];//Timing Out[3]= {0.771,Null} In[4]:= MapThread[fn1,{Range[100000],Range[100000]}];//Timing Out[4]= {0.561,Null} In the latter case, a small speed-up is because we can avoid an extra > parameter-passing stage [##]&, which we can not in your construction. > This > tells us about another possible source of overhead: when used in > higher-order functions such as Map, your construction can not be used by > name but needs an extra stage of constructing a pure function from it. > This > test shows about 50% slowdown, but the above test function does not > really > do much - for any realistic computation these effects will not probably > be > noticable since the main time will be spent in computing the r.h.s of the > function. I did not do more systematic benchmarks, but I would not expect much of a > performance hit, unless you have a single function name and > a > huge number of different definitions stored (which is unlikely). Of > course, > this depends on whether or not SubValues lookup is implemented as > efficiently as DownValues, which I assume is true. Again, if the body of > your is any computationally demanding, you probably > shouldn't > notice any overhead. Let me add that with this approach, your other > limitation is that you won't be able to set the Attributes of myfunction > such that they will affect the manipulations with var1,var2, etc. > Leonid >> On the general topic of performance, I'd be interested to know if anyone >> can comment on the following. In an effort to keep my codes as >> reasonable >> as possible, I use a lot of sentence variables. What I mean is that >> I'll >> write: >> myfunction[further explanation][var1_,var2_]:= .... >> I add that extra string in naming the function. This helps me immensely >> to >> remember what I'm doing and make my code accessible to me again in six >> months. I have often wondered, however, if I slow down Mathematica by >> using these long function names. >> Does anyone know? >> [For most of my applications, the limiting aspect on overall >> implementation time is my slow human CPU, so I have ample computer >> cycles >> and memory. However, there are a few applications that cause me to leave >> my computer running overnight, so I'm wondering somewhat about the >> performance of the code and if these long variable names are having an >> effect.] >> -- DrMajorBob@bigfoot.com === Subject: Re: performance // Re: Re: Why is recursion so The performance hit is miniscule. Even if x could take on millions of values in f[x][y], table lookup time for the strings is log-linear in the number of strings, I think. Bobby > On the general topic of performance, I'd be interested to know if anyone > can comment on the following. In an effort to keep my codes as reasonable > as possible, I use a lot of sentence variables. What I mean is that > I'll > write: myfunction[further explanation][var1_,var2_]:= .... I add that extra string in naming the function. This helps me immensely > to > remember what I'm doing and make my code accessible to me again in six > months. I have often wondered, however, if I slow down Mathematica by > using these long function names. Does anyone know? [For most of my applications, the limiting aspect on overall > implementation time is my slow human CPU, so I have ample computer cycles > and memory. However, there are a few applications that cause me to leave > my computer running overnight, so I'm wondering somewhat about the > performance of the code and if these long variable names are having an > effect.] > Daniel, >> Let me tell you straight away that you won't get efficiency of OCaml >> in Mathematica, >> the latter really being a CAS, research and prototyping tool, but not >> an efficiency-oriented production language. >> Regarding your question, the short answer is that recursion is slow >> because lists are implemented as arrays in Mathematica. When you >> pattern-match, the whole array is copied every time. This >> explains both the slowdown - the time becomes effectively quadratic >> (assuming that the complexity of array copying is linear), and the >> (stack) memory use explosion. >> So, IMO, indeed Mathematica is unfortunately less suited for the >> straightforward recursive solutions like yours. The closest thing you >> can probably do to stay in the recursive mindset is to use linked >> lists. Here is an implementation that does just that: >> Clear[myselectAux]; >> myselectAux[{}, predicate_] = {}; >> myselectAux[{head_, tail_List}, predicate_] := >> If[predicate[head], {head, myselectAux[tail, predicate]}, >> myselectAux[tail, predicate]]; >> Clear[toLinkedList]; >> toLinkedList[x_List] := Fold[{#2, #1} &, {}, Reverse[x]]; >> Clear[mySelectLL]; >> mySelectLL[x_List, predicate_] := >> Flatten@myselectAux[toLinkedList[x], predicate]; >> You can find more info on linked lists in Mathematica in the book of >> David Wagner, >> in the notes by Daniel Lichtblau (see Wolfram library archive, should >> be named >> something like efficient data structures in Mathematica), and also >> in my book >> (http://www.mathprogramming-intro.org/book/node525.html). >> For example: >> In[1] = test = RandomInteger[{1, 10}, 10] >> Out[1] = {6, 10, 1, 9, 4, 6, 1, 9, 10, 4} >> In[2] = toLinkedList@test >> Out[2] = {6, {10, {1, {9, {4, {6, {1, {9, {10, {4, {}}}}}}}}}}} >> In[3] = mySelectLL[test, # > 5 &] >> Out[3] = {6, 10, 9, 6, 9, 10} >> Now, the benchmarks: I use yours, on my 5 years old 1.8 GHz P IV, and >> I get: >> In[4] = >> data = Table[Random[], {20000}]; >> Block[{$RecursionLimit = Infinity}, >> Timing[data2 = mySelectLL[data, # > 0.5 &];]] >> Out[4] = {0.2, Null} >> Now, this is not the most efficient implementation. David Wagner in >> his excellent book >> discussed in great detail this sort of problems with the mergesort >> algorithm as an archetypal example. I believe that you can squeeze >> another factor of 2-5 by further optimizing the implementation >> (keeping it recursive) with several performance-tuning techniques >> available in Mathematica. >> By the way, I tested the above code with larger lists and it seems to >> continue be linear complexity up to 100 000 elements, but the kernel >> (v.6) just crashes after that - this >> behavior I can not explain, since the memory usage seems quite decent. >> So, to summarize my opinion: if you prefer to stay in a recursive >> mode, you *can* use recursion in Mathematica rather efficiently by >> switching to linked lists (and this will require some extra work but >> not so much of it). This may be enough to move you from the domain of >> toy problems to that of reasonably complex prototypes. But don't >> expect efficiency of the highly optimized production language with a >> native-code compiler (or even byte code interpreter) from a rewrite >> system such as Mathematica. Also, I'd say that other programming >> styles such as structural operations (APL - like) will bring you >> closer to efficiency of Ocaml etc. since then you can leverage the >> highly-optimized vectorized operations built in Mathematica. >> Hope this helps. >> Leonid >>> This post is about functional programming in Mathematica versus other >>> functional languages such as OCaml, SML or Haskell. At least a naive >>> use of functional constructs in Mathematica is horrendously slow. Am I >>> doing something wrong? Or isn't Mathematica really suitable for >>> functional programming beyond toy programs? Couldn't the Wolfram team >>> make a more efficient implementation for recursion, as other >>> functional languages has done? (Instead of the naive C-like behavior >>> for recursively defined functions.) >>>> as below >>>> myselect[{}, predicate_] = {} >>> myselect[{head_, tail___}, predicate_] := If[predicate[head], >>> Join[{head}, myselect[{tail}, predicate]], >>> myselect[{tail}, predicate] >>> ] >>>> Then I tried this function on a 20.000 element vector with machine >>> size floats: >>>> data = Table[Random[], {20000}]; >>> $RecursionLimit = 100000; >>> Timing[data2 = myselect[data, # > 0.5 &];] >>>> The result is {7.05644, Null}, and hundreds of MB of system memory are >>> 20.000 floats! It's just a megabyte! >>>> The following OCaml program executes in apparently no-time. It is not >>> compiled and does the same thing as the above Mathematica code. After >>> increasing the list by a factor of ten to 200.000 elements, it still >>> executes in a blink. (But with 2.000.000 elements my OCaml interpreter >>> says Stack overflow.) >>>> let rec randlist n = if n=0 then [] else Random.float(1.0) :: randlis= >> t >>> (n-1);; >>>> let rec myselect = function >>> [],predicate -> [] >>> | x::xs,predicate -> if predicate(x) then x::myselect(xs,predicate= >> ) >>> else myselect(xs,predicate);; >>>> let mypred x = x>0.5;; >>>> let l=randlist(20000);; >>> let l2=myselect(l,mypred);; (* lightning-fast compared to Mathematic= >> a >>> *) > -- DrMajorBob@bigfoot.com === Subject: Re: Why is recursion so slow in Mathematica? Bobby, I am not in favor of writing things in assembler. In fact, with a JIT- compiler high-level code is sometimes *faster* than compiled code in practical circumstances. The reason is that the compilation can be optimized for the machine at hand in stand of precompiled for all x86 platforms or whatever you have. Anyways, OCaml is definately a high-level language too so anyone sticking with that should not feel like a fossil. All the best, Daniel > As Szabolcs demonstrated in this case, using the right algorithms and > structures makes Mathematica far more competitive with compiled languages= > like OCaml. But the difference in speed between languages is also overwhelmed by time= > itself. IBM Assembler was my first favorite language (1971 or so), and I hauled = > around card decks a tenth the size of my classmates; I was good at it. Bu= t > there's no way I'd go back to that, just to get more speed in trivial > calculations. Mathematica today is a hundred times faster (or more) than = > Assembler in 1971, and it does a thousand times more FOR me. If I had spent 40 years writing Assembler code, I'd have very little to = > show for it. I hope that doesn't become anyone's experience with OCaml. Bobby === Subject: Re: bandmatrix Looks like homework. Do yourself a favor and try to solve it yourself. You will learn much more in the process. > reduce the band of a sparse matrix (100 x 100 ) with 10% approximately > of ones. > I known that Mathematica has a implementation to do this.(see the > code) > Needs[GraphUtilities`] > ma=Table[ If[n==m,1,If[RandomInteger[100]<90,0,1]],{n,1,100},{m, > 1,100}]; > {r,c}=MinimumBandwidthOrdering[ma,Method->RCM]; > (* Show Matrices *) > MatrixPlot[ma,ColorFunction->Monochrome] > MatrixPlot[ma[[r,c]],ColorFunction->Monochrome] > But the problem is: reduce the band of a sparse matrix (about 10% of > ones) using simulated annealing process, without using RCM method or > Sloam method. > Implement a program using Mathematica. > Can someone help me? === Subject: Re: Polygon Union It is usually not too difficult to translate existing C code to Mathematica (as long as it doesn't use pointers). Making it efficient, functional programming, code is an entirely different matter. Your question provoked my interest and I've been looking into this polygon union stuff, but it's pretty complicated stuff. Not something you'd write in a few lines of Mathematica code alas... > Hmmm... I was hoping to avoid using a function external to > Mathematica (I've never used MathLink), but this may be inevitable. > David Skulsky On Jun 6, 12:49 am, Sjoerd C. de Vries http://www.cs.man.ac.uk/~toby/alan/software/hasC code to perform a > set of polygon operations, among which the polygon union. I am looking for a Mathematica function which generates the union of > two (not necessarily convex) polygons. I found a package on the we= b > (the Imtek library, I believe) which includes a convex polygon > intersection function, but not a polygon *union* function. Does > anyone know if such a function is available or, if not, can anyone > suggest an algorithm to implement in Mathematica? > David Skulsky === Subject: Re: Polygon Union > I've also been thinking about this problem. I use the continental maps > that are available through CountryData[], and I'd rather have a continent > without an internal political boundaries shown. I've been surprised that > this possibility is not a built-in option. See last remark below. > I am looking for a Mathematica function which generates the union of > two (not necessarily convex) polygons. I found a package on the web > (the Imtek library, I believe) which includes a convex polygon > intersection function, but not a polygon *union* function. Does > anyone know if such a function is available or, if not, can anyone > suggest an algorithm to implement in Mathematica? > David Skulsky Consider a pair of polygons p1 and p2. For the case where boundaries might transversally intersect, a reasonable tactic is to iterate over vertices of p2 to see which lie in p1, and vice versa. Then look at neighbors of such points (that are not themselves inside one and bounding the other) to find intersecting segments. This will allow to recast as one polygon. Reasonably efficient code for doing the inside/ outside tests can be found in the MathGroup archives: http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00519.html For the case of internal boundaries, you can look for segments that get repeated. This should usually work, unless you have, say, Ohio and Kentucky both claiming a river right up to the land boundary on the other state's side (in that case, instead of looking for segments you might look for militias. Actually you can treat this as the transversal intersection case.) A related issue is when you try to merge polygons that have common boundaries, but vertices disagree due to small numeric error. In such cases it is useful to do comparisons at precision lower than that used in specifying the boundary vertices. Daniel Lichtblau Wolfram Research === Subject: Re: Documentation Methods and Efficiencies David, Leonid, SyntaxInformation[], and I'm just reading through this command now for the attention. Actually, my case of documentation is even worse than outlined below, mostly reflecting my incapacity to remember anything about today when tomorrow comes. That is, I make heavy use of f::usage to write a paragraph about f[phrase]. Then, I use f[phrase] in the code itself so that I can follow the code without having to refer to my usage. I also richly pepper everything with title cells and text cells. I probably spend about as much time on all of this as I actually do on the coding of the problem. All of this is great for me because I can pick up on my work in the future, although I don't know if it helps anyone else to look at my untidy f[phrase] formulations. I have also found f[phrase] to be a very useful way to make a family of related functions. That is, I will have f[phrase1] and f[phrase2] that are related. This also helps me keep everything organized in my head. I also like to do this with variables, e.g., data[from instrument 1] and data[from instrument 2]. With SyntaxInformation[], now my functions can have paragraphs, phrases, and grammar. :-) Boy, I love Mathematica. Scot > I'm starting this as a new thread because I'm shifting the topic even > further. I'm not certain of the general effect of string comments, or regular > comments, (* *), or even the use of longer descriptive variable names on > efficiency. We can do some tests as below. Maybe somebody can provide more > information about this. I am pretty much in Scot's camp in wanting and > needing documentation for routines that I write. There are many ways to produce documentation. One way is to always write a > usage message. It's easy to be lazy but usage messages are really useful, > not only because they provide information, but they also provide command > completion. Another way is to always write a SyntaxInformation statement. > These are again very useful when using the routines. If the routine has > options then it also pays to define them and include an OptionsPattern in > the SyntaxInformation. WRI has provided all these facilities, and except for > one thing, they are well designed. It will be more productive to use the WRI > documentationn facilities than design our own, and if the routines are > passed on to other users it will be easier for them. Let's look at some cases: f1::usage = f1[x] returns x^2 + 1; > SyntaxInformation[f1] = {ArgumentsPattern -> {_}}; > f1[x_] := > Module[{work}, > (* Square x *) > work = x^2; > (* Add one and return *) > work + 1] Timing[Do[f1[RandomReal[]], {100000}]] > {0.951, Null} But if we copy the f1 definition cell and then use Shift-Ctrl-I or > Shift-Ctrl-N or Shift-Ctrl-T to convert it to any of the various forms, we > lose the comments. I think this is an ill-designed feature of Mathematica. > It can catch a developer, who has carefully commented his code, by surprise. > (A developer might do this to clean up a much modified routine and restore > automatic indentation.) So one idea might be to replace the (* *) comments by strings that do > nothing. They won't disappear if one changes the cell format. They appear to > have only a slight effect on efficiency. f2::usage = f2[x] returns x^2 + 1; > SyntaxInformation[f2] = {ArgumentsPattern -> {_}}; > f2[x_] := > Module[{work}, > Square of x; > work = x^2; > Add one and return; > work + 1] Timing[Do[f2[RandomReal[]], {100000}]] > {0.967, Null} Then we come to Scot's method. f3::usage = f3[Take the square and add one][x] returns x^2 + 1; > f3[Take the square and add one][x_] := > Module[{work}, > work = x^2; > work + 1] Timing[Do[f3[Take the square and add one][RandomReal[]], {100000}]] > {0.952, Null} There doesn't appear to be a significant efficiency effect between these > methods. But the last method has disadvantages. We can't define > SyntaxInformation for the x portion of the definition. And will we have to > type in the information string every time we use the routine? Maybe we can > use command completion. But that doesn't work. Try it. I believe that Mathematica could be improved if both the SyntaxInformation > and usage statement command completion allowed for subvalues. Subvalues are > very useful in separating parameters from variables. I don't see why there > should be an insuperable obstacle here. Now we come back to more general documentation. In many applications it > would be good practice to not only write usage messages and > SyntaxInformation statements, and also use OptionsPattern when appropriate, > but also to actually incorporate many routines in packages and write Version > 6 documentation pages for them using Workbench. Well, not for everything, > but for any routine that you might use in the future, or others might use; > for routines that are part of a major research project, or used in > courseware or in an electronic book. The function page has a place for > extensive notes on the usage. One could also include many test cases there, > and also extensive textual discussion and even developmental material. It > could certainly go beyond the standard WRI Function Help page. The advantage > is that one has a fixed and recognized place to place and obtain all the > information on a function. One doesn't have to search through old notebooks. > And what better time to set up the documentation than shortly after a > routine has been developed when the material is at hand? If the substance of > the work is being done anyway, then it makes sense to get it into the > standard documentation. It's not that much extra work, once we learn how to > use Workbench, and once WRI is willing to put a little more effort into it > and make Workbench convenient for something more than their internal > documentation. > David Park > djmpark@comcast.net > http://home.comcast.net/~djmpark/ On the general topic of performance, I'd be interested to know if anyone > can comment on the following. In an effort to keep my codes as reasonable > as possible, I use a lot of sentence variables. What I mean is that I'll > write: myfunction[further explanation][var1_,var2_]:= .... I add that extra string in naming the function. This helps me immensely to > remember what I'm doing and make my code accessible to me again in six > months. I have often wondered, however, if I slow down Mathematica by > using these long function names. Does anyone know? [For most of my applications, the limiting aspect on overall > implementation time is my slow human CPU, so I have ample computer cycles > and memory. However, there are a few applications that cause me to leave > my computer running overnight, so I'm wondering somewhat about the > performance of the code and if these long variable names are having an > effect.] === Subject: Documentation Methods and Efficiencies I'm starting this as a new thread because I'm shifting the topic even further. I'm not certain of the general effect of string comments, or regular comments, (* *), or even the use of longer descriptive variable names on efficiency. We can do some tests as below. Maybe somebody can provide more information about this. I am pretty much in Scot's camp in wanting and needing documentation for routines that I write. There are many ways to produce documentation. One way is to always write a usage message. It's easy to be lazy but usage messages are really useful, not only because they provide information, but they also provide command completion. Another way is to always write a SyntaxInformation statement. These are again very useful when using the routines. If the routine has options then it also pays to define them and include an OptionsPattern in the SyntaxInformation. WRI has provided all these facilities, and except for one thing, they are well designed. It will be more productive to use the WRI documentationn facilities than design our own, and if the routines are passed on to other users it will be easier for them. Let's look at some cases: f1::usage = f1[x] returns x^2 + 1; SyntaxInformation[f1] = {ArgumentsPattern -> {_}}; f1[x_] := Module[{work}, (* Square x *) work = x^2; (* Add one and return *) work + 1] Timing[Do[f1[RandomReal[]], {100000}]] {0.951, Null} But if we copy the f1 definition cell and then use Shift-Ctrl-I or Shift-Ctrl-N or Shift-Ctrl-T to convert it to any of the various forms, we lose the comments. I think this is an ill-designed feature of Mathematica. It can catch a developer, who has carefully commented his code, by surprise. (A developer might do this to clean up a much modified routine and restore automatic indentation.) So one idea might be to replace the (* *) comments by strings that do nothing. They won't disappear if one changes the cell format. They appear to have only a slight effect on efficiency. f2::usage = f2[x] returns x^2 + 1; SyntaxInformation[f2] = {ArgumentsPattern -> {_}}; f2[x_] := Module[{work}, Square of x; work = x^2; Add one and return; work + 1] Timing[Do[f2[RandomReal[]], {100000}]] {0.967, Null} Then we come to Scot's method. f3::usage = f3[Take the square and add one][x] returns x^2 + 1; f3[Take the square and add one][x_] := Module[{work}, work = x^2; work + 1] Timing[Do[f3[Take the square and add one][RandomReal[]], {100000}]] {0.952, Null} There doesn't appear to be a significant efficiency effect between these methods. But the last method has disadvantages. We can't define SyntaxInformation for the x portion of the definition. And will we have to type in the information string every time we use the routine? Maybe we can use command completion. But that doesn't work. Try it. I believe that Mathematica could be improved if both the SyntaxInformation and usage statement command completion allowed for subvalues. Subvalues are very useful in separating parameters from variables. I don't see why there should be an insuperable obstacle here. Now we come back to more general documentation. In many applications it would be good practice to not only write usage messages and SyntaxInformation statements, and also use OptionsPattern when appropriate, but also to actually incorporate many routines in packages and write Version 6 documentation pages for them using Workbench. Well, not for everything, but for any routine that you might use in the future, or others might use; for routines that are part of a major research project, or used in courseware or in an electronic book. The function page has a place for extensive notes on the usage. One could also include many test cases there, and also extensive textual discussion and even developmental material. It could certainly go beyond the standard WRI Function Help page. The advantage is that one has a fixed and recognized place to place and obtain all the information on a function. One doesn't have to search through old notebooks. And what better time to set up the documentation than shortly after a routine has been developed when the material is at hand? If the substance of the work is being done anyway, then it makes sense to get it into the standard documentation. It's not that much extra work, once we learn how to use Workbench, and once WRI is willing to put a little more effort into it and make Workbench convenient for something more than their internal documentation. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ On the general topic of performance, I'd be interested to know if anyone can comment on the following. In an effort to keep my codes as reasonable as possible, I use a lot of sentence variables. What I mean is that I'll write: myfunction[further explanation][var1_,var2_]:= .... I add that extra string in naming the function. This helps me immensely to remember what I'm doing and make my code accessible to me again in six months. I have often wondered, however, if I slow down Mathematica by using these long function names. Does anyone know? [For most of my applications, the limiting aspect on overall implementation time is my slow human CPU, so I have ample computer cycles and memory. However, there are a few applications that cause me to leave my computer running overnight, so I'm wondering somewhat about the performance of the code and if these long variable names are having an effect.] === Subject: changing variables in differential equations Given an ordinary differential equation of order n, H(x,y,y',y'',...)=0 Given the change of variables : x=x(u,v) and y=y(u,v) How to calculate (hopefully recursively) y', y'', and so on as functions of say : u, v', v'' In other words how to translate automatically the differential equation in terms of the new variables ? === Subject: Looking for a Column,Row, and Grid interactive Lab In learning Column, Row, and Grid, I am seeking an interactive guide to study those features of Mathematica. Even a partial one would do to Andrew === Subject: Re: Dependent dynamic controls It would be nice if anyone could comment on this. Istvan === Subject: Slow/jerky animations inside manipulate I am using Mathematica v. 6.0.2.1. I have an Animate command (I'm using GraphicsRow to show two side-by-side synchronized animations) inside of Manipulate. The resulting animations play very fast and are jerky. I can adjust the play speed using AnimationRate, but it must be slowed down by a ridiculous amount in order to look smooth. I've tried adjusting the RefreshRate, as well as making time a slider variable and animating from within the Manipulate control panel, both with little success. How can I create smooth animations, appropriate for class demonstrations? === Subject: Re: MemoryInUse and Print the output is as follows (with fresh kernel, in one cell): $HistoryLength = 0; Print[Share[]; MemoryInUse[]]; Print[Share[]; MemoryInUse[]]; Print[Share[]; MemoryInUse[]]; Print[Share[]; MemoryInUse[]]; Print[Share[]; MemoryInUse[]]; 9128664 9127856 9127128 9126392 9125560 Is memory leaking? O there's somehting I'm missing here. Istvan On May 21, 6:00 am, Jens-Peer Kuska on my system I get a constant memory decrease with $HistoryLength = 0; Print[Share[]; MemoryInUse[]]; > Print[Share[]; MemoryInUse[]]; > Print[Share[]; MemoryInUse[]]; > Print[Share[]; MemoryInUse[]]; > Print[Share[]; MemoryInUse[]]; Jens No idea? Any comment? Istvan === Subject: Re: Future for Mathematica on Solaris > I was interested in purchasing a copy of Mathematica forSolaris, but have seen various things on the net suggesting theSolaris(and to a > lesser extent linux) versions are more buggy than the Windows version. Looking on the Wolfram web site where one can request a trial http://www.wolfram.com/products/mathematica/experience/request.cgi I find one can't request a trail onSolarisfrom the web site. So I contacted Wolfram Research directly by email and asked about a > 14-day save-disabled trail. I received a reply in a couple of days, > telling me no trial version of Mathematica exists forSolaris. Given theSolarisversion is more expensive than the windows one, > there are various reports of bugs onSolaris, and one can't even get a > trail version, it does beg the question whether Wolfram Research are > serious about the future of Mathematica onSolaris. Peter I'm sure that somebody has already (or will very soon) contacted you, Pet= er. > But for anybody else who might have been following this, there's a bit mo= re to > say here. The person you spoke to correctly pointed out that there is = no trial > version forSolaris, but didn't realize there was another option which wou= ld > have accomplished your goal. If you're talking to a representative of = our salesteam, they can grant a temporary evaluation license. We're spreading the word internally to make sure that anybody who might b= e > fielding questions such as this will be aware of the option in the future= . been > aware of the oversight. > John Fultz > jfu...@wolfram.com > User Interface Group > Wolfram Research, Inc. Just to reply to John Fultz's comment. I have indeed been contacted by a very helpful lady at Wolfram Research on this matter, who has offered to put me in touch with an 'Account Executive' to arrange a trial. Quite why it should be necessary to jump through so many hoops to get a trial for Solaris, when it's much easier for other platforms is not a good sign. It's can't be too difficult to make an trial download for Solaris, given one can purchase a Solaris version to download from the Wolfram Reserach web site. But I feel it is only fair to say, although there was clearly some communication issues internally to Wolfram Reserach initially, both John Fultz and the other lady (whose name I will not post online), have both been very helpful. Peter === Subject: Re: Problem with GraphicsColumn What about: GraphicsColumn[{Plot[Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}] Maybe there is another problem that you haven't mentioned and that doesn't appear with the example? David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I encounter a problem below: My aim is to obtain a graphicscolumn for my paper to be submited: GraphicsColumn[{Plot[Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}, Alignment -> Right, ImageSize -> 500, Spacings -> Scaled[-.1]] However I find the right part of the outcome contains blank space. If I add two items: GraphicsColumn[{Plot[Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}, Alignment -> Right, ImageSize -> 500, Spacings -> Scaled[-.1], Frame -> All, FrameStyle -> Opacity[0]] it works. However when I Export[FIG1.EPS,%,EPS] , it inevitably contains the Frame. === Subject: Re: Problem with GraphicsColumn Actually, the two figures I drew are the same x-axis range but different y-axis range like: GraphicsColumn[{Plot[10^4 Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}] Because of the length of the number of y-axis label in Plot@Sin is longer than Plot@Cos, the figure moves to right hand side. If I want to solve this, I have to add some items like the first and the second cases above. However more problems are encountered. === Subject: Re: 1GB Kernel Memory Limit/ Out of memory errors I was out of email contact for the weekend, and while going through the weekend's MathGroup load, I noticed the following two similar posts, from Friday night and Sunday night. The Friday one doesn't seem to have had any public responders, so I thought I'd respond to both in one shot. First, let me say categorically that Mathematica does not have a 1 gigabyte limit, and it has no limitation based solely on the amount there, Mathematica does not manage its own paging file or its own memory limitations. It merely allocates memory using Microsoft's implementation of the C 'malloc' function, which is subject to the standard limitations imposed by the operating system. On a Win32 system, these limitations impose a per-process limitation of 2G of addressable space to the process, or 3Gb if booted using the /3GB switch and if the application is compiled appropriately to use the 3Gb, which Mathematica is. This addressable space is backed by virtual memory, which is the collection of physical Practically, you're never going to see anything very close to that limitation being used by MemoryInUse[]. Some of the memory which is addressable is not going to be directly available for use by Mathematica for several reasons. But, in practice, I've been able to get a Mathematica kernel to use around 1.85Gb (if memory serves me correctly...it's been a while since I've done this) on a 2Gb system. However, there are several legitimate reasons why a Mathematica kernel could issue an out of memory message when MemoryInUse[] is displaying a much lower number. Without seeing your programs, I could only speculate, but here are some possibilities. * Mathematica failed in the middle of making a very large memory allocation because the memory just wasn't available. The math just doesn't work. * Mathematica failed to make a smaller (but probably still in the tens of megabytes) allocation because of memory fragmentation. Since there are only 2Gb (or 3Gb) of addressable space, the pattern of past memory allocations and frees may leave the currently allocated memory so fragmented that no really large blocks of contiguous memory are left. A single, 50Mb request for memory will fail if there are no contiguous 50Mb chunks of addressable space, regardless of how much memory is in use. * Much less commonly, it's possible to exhaust other, much more limited, memory-based resources. This includes stack space, which could affect highly recursive calculations, and limitations on the number of handles, which might come into play if accessing an extremely large number of files without subsequently closing their streams. A note about the memory fragmentation issue. If this were the problem, then quite possibly you could run your evaluations on a 64-bit version larger addressable space is available means that getting a contiguous block of memory isn't a problem. But only the allocated blocks need to be backed by virtual memory, no matter what their addresses are. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. ------------------------------- I'm currently working on a problem that requires a whole lot of memory > to complete. Sometimes, depending on the specific parameters being > used, I will receive the dreaded, No more memory available, message. > Doing my best to track memory usage with MemoryInUse[], MaxMemoryUsed > [] and the Windows Task Manager, I find that the kernel quits when it > hits a limit of around one gigabyte. I'm using Version 7.0 on 32-bit Windows XP without the /3GB switch > active; neither switching to a 64 bit OS nor activating the /3GB > switch are possibilities. However, I was under the distinct impression > that even without the /3GB switch active I should have a per-process > memory limit of 2GB, not 1GB. Is there some other reason the kernel > might quit, due to either Mathematica settings or OS settings? As for modifying my program I've done obvious things like setting > $HistoryLength 0, Clear[]ing things that are no longer needed, and > none of them have done the trick in all cases I've needed to deal > with. I've also done an array of not-so-obvious things that haven't > worked either. Any suggestions would be greatly appreciated. Pillsy ---------------------------- > I'm operating on some largish problems in which I'm making a graph, > using MakeGraph from the Combinatorica package. When I exceed a > certain size, the thing runs for a bit and then gives an out of memory > error and then the kernel shuts down. I'm running Vista on a dual core > I've tracked down the problem, I think. Mathematica runs the operation > is why doesn't it build a pagefile like most windows applications? > Then I could run anything that didn't actually use up the free disk > space. === Subject: Multidimensional optimization problem solved with mathematica Hello everybody, === Subject: Re: Multi-level Menu (ActionMenu) Hi Chris, Below is the closest analog I found (I am not a UI person and you will probably get better solutions from others, but still) : suppose your menu data is in such a structure: In[1] = menuItems = {{Africa, {{Algeria, {Algiers, Oran}}, {Angola, {Luanda, Huambo}}} }, {North America, {{United States, {New York, Washington}}, {Canada, {Toronto, Montreal}}} }}; The first auxiliary function adds actions to the lower-level menu items: In[2] = Clear[addLowestItemActions]; addLowestItemActions[menuItemTree_, f_] := Map[# :> f[#] &, menuItemTree, {Depth[menuItemTree] - 1}]; Example: In[3] = Clear[h]; addLowestItemActions[menuItems, h] Out[3] = {{Africa, {{Algeria, {Algiers :> h[Algiers], Oran :> h[Oran]}}, {Angola, {Luanda :> h[Luanda], Huambo :> h[Huambo]}}}}, {North America, {{United States, {New York :> h[New York], Washington :> h[Washington]}}, {Canada, {Toronto :> h[Toronto], Montreal :> h[Montreal]}}}}} Another auxilliary function will transform the structure as needed in ActionMenu: In[4] = Clear[menuItemsConvert]; menuItemsConvert[itemsAndActions_, menuDepth_Integer, submenuConstructionFnames_List] /; Length[submenuConstructionFnames] == menuDepth - 1 := Fold[Function[{expr, fandlevel}, With[{fn = fandlevel[[1]]}, Apply[# :> fn[##] &, expr, fandlevel[[2]]]]], itemsAndActions, Transpose[{submenuConstructionFnames, List /@ Range[2*menuDepth - 3, 1, -2]}]]; Example: In[5] = Clear[f,g]; menuItemsConvert[addLowesItemActions[menuItems, h], 3, {f, g}] Out[5] = {Africa :> g[Africa, {Algeria :> f[Algeria, {Algiers :> h[Algiers], Oran :> h[Oran]}], Angola :> f[Angola, {Luanda :> h[Luanda], Huambo :> h[Huambo]}]}], North America :> g[North America, {United States :> f[United States, {New York :> h[New York], Washington :> h[Washington]}], Canada :> f[Canada, {Toronto :> h[Toronto], Montreal :> h[Montreal]}]}]} Finally, the main menu-building function: Clear[createDepth3CountryDataMenu]; createDepth3CountryDataMenu[menuItemTree_, actionF_] := With[{menudepth = 3}, Module[{name , subname, sub, subsub, subBack, makeSub, subsubBack, makeSubSub, subsubname = Cities}, subBack[] := (sub = ; name = Continent); subsubBack[] := (subsub = ; subname = Country); subsubBack[]; subBack[]; makeSub[nm_String, actions_List] := (name = nm; sub := ActionMenu[subname, Prepend[actions, Back :> (subsubBack[]; subBack[])]]); makeSubSub[nm_String, actions_List] := (subname = nm; subsub := ActionMenu[subsubname, Prepend[actions, Back :> subsubBack[]]]); With[{menuContent = menuItemsConvert[ addLowestItemActions[menuItemTree, actionF], menudepth, {makeSubSub, makeSub}]}, Dynamic[Row[{ActionMenu[name, menuContent], sub, subsub}]]]]] It is less generic than the previous two. It is possible to write it in a more generic way to allow it to automatically adjust to the input menu structure, but the code will look more complex. It will however then become more elegant and robust. In particular, it is possible to generate functions like makeSub, makeSubSub automatically, as well as variables , . Note that all functions rely on a particular list data structure used to store the menu items. The usage (for example): createDepth3CountryDataMenu[menuItems , Print[The city you chose is , #] &] Hope this helps. Leonid http://www.cafewebmaster.com/demo/css-menu/css-dhtml-menu.png === Subject: Re: directionfields from StreamPlot looks different from solution Hi Sean, VectorPlot and StreamPlot do not show the same. VectorPlot obviously plots a vector field, showing vector of different length. StreamPlot on the other hand does not bother about the size of the vectors (velocity), it only gives directions. Nevertheless, you must feed StreamPlot with vectors (velocities). Daniel > I don't think I'm using StreamPlot properly. Consider the following non-autonomous ODE y'[t] == (t^2) - y[t] Solutions for various ICs can be viewed by the following. sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == y0}, y[t], {t, -4, > 4}], {y0, 0, 6, 0.5}]; Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange -> {{-4, 4}, {-2, > 10}}] Shouldn't Vector fields be similar to the solutions above? If I plot t > on x-axis vs. t^2-y on y axis... VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] I don't get similar results... What is the reason for this? > Sean === Subject: Parallelize and Symbolic computation Hi All, I apologies if this is an idiotic question. Essentially, I've a complex Taylor series expansion that keeps running out of memory and as I've upgraded to Mathematica 7 of late, and we've a few machines idling away, I was wondering if the parallel stuff could help. The documentation for Parallel Tools hints that it's only applicable for numeric problems, but doesn't state that symbolic is out of the question. At a recent Mathematica demo I went to recently it was suggested that the parallel architecture didn't exclude all symbolic calculations. Has anyone seen any documentation on this? Or have any experience of it? JHatt === Subject: Re: Problem with plotting and simplifying a function simply write: Sum[Cos[2 Pi k t], {k, -n, n}] this gives: -1 + 2 Cos[n [Pi] t] Csc[[Pi] t] Sin[(1 + n) [Pi] t] Further, note that the Sin part is zero because Sin is an odd function. Daniel > I have a question that troubles me , and I'll appreciate your advices. > Given Sum of : X_N(t) =Sum [ Exp(j2*Pi*k*t) ] with lower limit -N and upper limit +N , -2<= t <= 2 > I need to calculate x(t) ,so I used Euler : > X_N(t) = Sum e^(j2*pi*k*t) = Sum [ cos(2pi*k*t) + j*sin (2pi*k*t) ]. Now ,if I'm mistaken the sinus part becom equal to zero , because the cycle > of sinus is PI . But I have a problem with the Cosinus part , how can I > simplify it ? the t parameter interrupts with the simplifying ...... > maybe separating it to conditions ? N=2R ------> even , N=2R+1 --> odd ? === Subject: what is my error? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: Re: what is my error? > eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, > {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater > than zero -- > There are many solutions. mr mp m=13 fr fp f=19 r=15 p=17 n=32 Block[{m = 13, f = 19, r = 15, p = 17, n = 32}, Table[{mr, m-mr, r-mr, f-(r-mr)},{mr,1,m-1}]] {{ 1,12,14, 5}, { 2,11,13, 6}, { 3,10,12, 7}, { 4, 9,11, 8}, { 5, 8,10, 9}, { 6, 7, 9,10}, { 7, 6, 8,11}, { 8, 5, 7,12}, { 9, 4, 6,13}, {10, 3, 5,14}, {11, 2, 4,15}, {12, 1, 3,16}} === Subject: what is my error? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: what is my error? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: what is my error? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: Rasterize off by one pixel I'm trying to make a 100x100 pixel image using Rasterize, as follows, where n=100 Rasterize[ Graphics[Rectangle[{0,0}, {1,1}], PlotRange->{{0,2},{0,2}}], Image, RasterSize->{n,n} ] when I check the resulting image using ImageDimensions, the size is 100x101. If I say size {n,n/2}, then the image is 100x51 instead of 100x50. === Subject: Re: Rasterize off by one pixel With[{n = 100}, img = Rasterize[ Graphics[Rectangle[{0, 0}, {1, 1}], PlotRange -> {{0, 2}, {0, 2}}, PlotRangePadding -> None, AspectRatio -> Automatic, ImagePadding -> None], Image, ImageSize -> {n, n}] ] ? Jens > I'm trying to make a 100x100 pixel image using Rasterize, as follows, > where n=100 Rasterize[ > Graphics[Rectangle[{0,0}, {1,1}], > PlotRange->{{0,2},{0,2}}], > Image, > RasterSize->{n,n} > ] when I check the resulting image using ImageDimensions, the size is > 100x101. If I say size {n,n/2}, then the image is 100x51 instead of > 100x50. === Subject: creating an array in a loop I am new to Mathematica programming I have the following question. How to create an array in a loop? I have the code Neps0; Nlmbd=10; Array[SOL,{10,20}] deps0=0.1; eps0=0.0; For[lmbd=0; ieps0=1;, lmbd<=Nlmbd-1; ieps0 <= Neps;, lmbd=lmbd+1; ieps0=ieps0+1;, eps0=deps0*(ieps-1); SOL[[lmbd+1,ieps]]=Func[lmbd,eps0]; ] SOL (where Func[a,b] is some function) What is wrong with it, why this does not work? === Subject: two questions Fg === Subject: Learning Trace more.... I am seeking a deeper fuller tutorial on Trace function. Links, notebooks or examples are welcomed. Btw, I have found doing this idiom useful: Trace[(exprToStudy) , TraceOriginal -> True , TraceBackward -> All , TraceForward -> All , TraceAbove -> True] // Flatten // Column Any problems doing so? Enhancements? Andrew === Subject: directionfields from StreamPlot looks different from solution I don't think I'm using StreamPlot properly. Consider the following non-autonomous ODE y'[t] == (t^2) - y[t] Solutions for various ICs can be viewed by the following. sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == y0}, y[t], {t, -4, 4}], {y0, 0, 6, 0.5}]; Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange -> {{-4, 4}, {-2, 10}}] Shouldn't Vector fields be similar to the solutions above? If I plot t on x-axis vs. t^2-y on y axis... VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] I don't get similar results... What is the reason for this? Sean === Subject: Re: Tube in ParametricPlot3D with too many details >> I'm using the following code to get a tube around a homoclinic loop >> hloop = ParametricPlot3D[{-2 Sech[ u], u - 2 Tanh[ u], 0 }, {u, -5, >> 5}, PlotStyle -> {Tube[0.1], Red}, Axes -> None] >> The only issue is that, if I try to export it as a pdf, I get too many >> details which results in (too) big pdf. >> Is there anyway to have Mathematica producing a plot with less >> Giovanni Lanzani >> This problem came up with version 6 for graphics rendered using >> GraphicsComplex. It has been discussed in this group. The best solution >> is to use File->PrintSelection. In the printer menu chose save to >> print to a pdf. >> The drawback is, the picture takes a whole page, so you have to open it >> in a graphics program like GraphicsConverter (on Mac) to adjust the regio= > n. >> -- >> _________________________________________________________________ >> Peter Breitfeld, Bad Saulgau, Germany --http://www.pBreitfeld.de > this did the trick. > It has been discussed in this group. The best solution >> is to use File->PrintSelection. Would it be possible to point me the discussions where the others > solutions are explained? > Giovanni, I don't remember exactly the messages where this was discussed. You may 'FixPolygons' on http://library.wolfram.com/infocenter/MathSource/7029/. After applying FixPolygons onto your graphic, you can export it the usual way, giving smooth pdfs of moderate size. But the .eps files are still huge. The processing of FixPolygons needs some time (about 5 to 10 minutes on my G5) -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Integrate Bug > I am trying to calculate this integral that should be positive.But the > answer is 0. In: Integrate[(1)/(z^2 + b^2 + a^2 - 2 z b Sin[[Theta]] - > 2 a b Cos[[Theta]])^(1/2), {[Theta], 0, 2 [Pi]}, > Assumptions -> {a > 0, b > 0, z > 0}] Out:0 Anybody have notice a situation like that? My platform is MacOSX 10.4 and Mathematica 7. Best wishes, Further to my previous post, seems that one single formula suffices : F[a_, b_, z_] := (4 Sqrt[a^2 + b^2 + z^2 + 2 b Sqrt[a^2 + z^2]]* Abs[Im[EllipticK[(a^4 + b^4 + 6 b^2 z^2 + z^4 + 4 b^3 Sqrt[a^2 + z^2] + 4 b z^2 Sqrt[a^2 + z^2] + 2 a^2 (3 b^2 + z^2 + 2 b Sqrt[a^2 + z^2]))/ (a^2 - b^2 + z^2)^2]]])/Abs[a^2 - b^2 + z^2] -- === Subject: Re: Integrate Bug > I am trying to calculate this integral that should be positive.But the > answer is 0. In:Integrate[(1)/(z^2 + b^2 + a^2 - 2 z b Sin[[Theta]] - > 2 a b Cos[[Theta]])^(1/2), {[Theta], 0, 2 [Pi]}, > Assumptions -> {a > 0, b > 0, z > 0}] Out:0 Anybody have notice a situation like that? My platform is MacOSX 10.4 and Mathematica 7. Best wishes, Good day, A half-manual half-guessed tentative solution to get around the bug : In[1]:= f[a_, b_, z_, t_] = 1/Sqrt[a^2 + b^2 + z^2 - 2a*b*Cos[t] - 2b*z*Sin[t]]; In[2]:= F[a_, b_, z_] /; b < a || b < z := -((4 Sqrt[a^2 + b^2 + z^2 + 2b Sqrt[a^2 + z^2]]* Im[EllipticK[(a^4 + b^4 + 6b^2*z^2 + z^4 + 4b^3*Sqrt[a^2 + z^2] + 4b*z^2Sqrt[a^2 + z^2] + 2a^2*(3*b^2 + z^2 + 2b*Sqrt[a^2 + z^2]))/ (a^2 - b^2 + z^2)^2]])/(a^2 - b^2 + z^2)); F[a_, b_, z_] /; b > a && b > z := 4 Sqrt[a^2 + b^2 + z^2 + 2b Sqrt[a^2 + z^2]]* Im[EllipticK[(a^4 + b^4 + 6b^2 z^2 + z^4 + 4b^3*Sqrt[a^2 + z^2] + 4b*z^2Sqrt[a^2 + z^2] + 2a^2*(3*b^2 + z^2 + 2b*Sqrt[a^2 + z^2]))/ (a^2 - b^2 + z^2)^2]/(a^2 - b^2 + z^2)]; Numeric check : In[4]:= F[2, 3, 4] Out[4]= (-(4/11))*Sqrt[29 + 12Sqrt[5]]* Im[EllipticK[(1/121)*(1217 + 600 Sqrt[5] + 8*(43 + 12 Sqrt[5]))]] In[5]:= % // N Out[5]= 1.62239 In[6]:= NIntegrate[f[2, 3, 4, t], {t, 0, 2 Pi}] Out[6]= 1.62239 In[7]:= F[2, 5, 4] Out[7]= 4 Sqrt[45 + 20 Sqrt[5]]* Im[(-(1/5))* EllipticK[(1/25)*(3297 + 1640 Sqrt[5] + 8*(91 + 20 Sqrt[5]))]] In[8]:= % // N Out[8]= 1.80576 In[9]:= NIntegrate[f[2, 5, 4, t], {t, 0, 2 Pi}] Out[9]= 1.80576 -- === Subject: Automatically adding bottom frame line to cells without output? Some of he style sheets that come with Mathematica, such as the Creative and Report versions, put frames around the input and output cells, but leave off the bottom line from input cells. This makes sense for those input cells that have output, but when there is no output, such as for a function definition, it looks ugly. Is there a way to automatically add a bottom cell frame line in that case? I also looked at adding a private style (Input 2) to a notebook, so I could set function definitions to that and have the bottom line appear, but I couldn't see how to add a style in the Private Style Definitions notebook. Is that possible? I want to have it be a private style so that it goes with the notebook when I give it to someone. In the end, I manually selected the cells without bottom lines and used the option inspector to add them. Rather annoying. === Subject: Debugger, um, tutorial on it?? Nearly every IDE I ever used had a full tutorial on debugging using their debugger. Where is Mathematica's? I am hoping something can be officially released about how and when and why debugging long before Andrew === Subject: Re: Debugger, um, tutorial on it?? Oh Yes! I am downloading it now. Give me some time to kick the tires, I work slow but intense. I suspect it wont be till Mathematica 8 some real docs for the debugger will be given; so, your posting is really timely. === Subject: Documentation What is the canonical way to author documentation in Mathematica 7 ? -- ---------------------------------------- Informatique technique et scientifique http://www.dxdydz.net Jean-Marie Thomas +33 (0)1 75 57 60 75 +33 (0)6 37 18 86 63 === Subject: Re: Documentation I have written a notebook that discusses some of the internals (which I learned through reverse engineering existing Documentation Center content) for creating Documentation in Mathematica 6 and greater. That notebook is located here: http://scientificarts.com/worklife/notebooks/index.html under the title Documentation Center Notes. Also it is located here: http://www.scientificarts.com/mathematicatools/blog/BE3448096684/BE34480966= 84.html My application A WorkLife FrameWork in its current version (beta, but it is the shipping version, and compatible with Mathematica 7), contains a tool for transforming a set of notebooks into Documentation Center material. It's what I used to transform my original version 5 documentation to version 6+ documentation for that application. --David > What is the canonical way to author documentation in Mathematica 7 ? > -- > ---------------------------------------- > Informatique technique et scientifique > http://www.dxdydz.net Jean-Marie Thomas +33 (0)1 75 57 60 75 > +33 (0)6 37 18 86 63 === Subject: Series Expansion Hi every body, I have the following function fm which is a rational between to series : fm1 = 1 + Sum[a_n*x^n, {n, 1, M}] fm2 = 1 + Sum[b_n*x^n, {n, 1, M + 2}] fm = (fm1/fm2) // Expand Now I want to have aseries exansion of fm to some order: Series[fm, {x, 0, 5}] // Expand But I get the input nothing else? can somebody there give me some hit 1/(1 + !( *UnderoverscriptBox[([Sum]), (n = 1), (2 + M)]( *SuperscriptBox[(x), (n)] b_n))) + !( *UnderoverscriptBox[([Sum]), (n = 1), (M)]( *SuperscriptBox[(x), (n)] a_n))/(1 + !( *UnderoverscriptBox[([Sum]), (n = 1), (2 + M)]( *SuperscriptBox[(x), (n)] b_n))) O. Kullie === Subject: Re: Problem with a plot in Mathematica just a crazy off-the-wall idea here, but maybe you should try looking at some of the online documentation pages for using Mathematica ? 2009/6/4 dmirab : > Hi there I have a function to plot in Mathematica but i am keeping getting some mistake of sintax. this is the function: C=(25/2*3.14*7*vary*varz)*exp(-y^2/2*vary^2)*exp(-38^2/2*varz^2) and vary=0.22*(1+0.0004x)-0.5 > varz=0.20*(1+0.0001x)-0.5 it shoud be a 3d but i put z=38 so it's a 2D now. How do you type it in Mathematica? Just to get what's my mistake any help is very much appreciated > -- Peter Lindsay === Subject: Problem with a plot in Mathematica Hi there I have a function to plot in Mathematica but i am keeping getting some mistake of sintax. this is the function: C=(25/2*3.14*7*vary*varz)*exp(-y^2/2*vary^2)*exp(-38^2/2*varz^2) and vary=0.22*(1+0.0004x)-0.5 varz=0.20*(1+0.0001x)-0.5 it shoud be a 3d but i put z=38 so it's a 2D now. How do you type it in Mathematica? Just to get what's my mistake any help is very much appreciated === Subject: LocatorPane gets invisible inside GraphicsRow (bug?) Code of misbehaving Locator is below. The locator does not show up before the background if the list of LocatorPane and a string is wrapped into GraphicsRow. Sometimes it does show up, but just temporarily, or partially, that is: as it is moved, it gets behind some invisible rectangle, that is randomly placed on the plot. But with a fresh kernel the Locator object simply does not show up (Mathematica 7.0.1). Still the invisible Locator can be moved, and the 'pt' variable is dynamically updated. pt = {0, 0}; GraphicsRow@{LocatorPane[Dynamic@pt, Plot[Sin@x, {x, -[Pi], [Pi]}]], N/A} Row@{LocatorPane[Dynamic@pt, Plot[Sin@x, {x, -[Pi], [Pi]}]], N/A} Is it a bug? Istvan Zachar === Subject: Re: problem writing debugging utility function Stonewall, The Function command must obey the general rules of Mathematica evaluation. When we indicate HoldAll as an explicit attribute, this tells Function how to pass the arguments to its body - to evaluate them first or not. But the HoldAll attribute implicit for Function is always there, and that just assures that Function is at all able to do its work, such as variable binding and name conflict resolution (Function is a lexical scoping construct). Consider an example: In[1] = x = 10; Function[x, x^2] /@ Range[5] Out[1] = {1, 4, 9, 16, 25} The inside a function has nothing to do with a global , exactly due to the HoldAll attribute of Function: it allows Function to analyze its arguments (I mean, the body - x and x^2 in this case) and do the name collision resolution before using the arguments. (there is a slight confusion in terminology here because Function is a SubValues-based construct: Function[body][args], so when I mean arguments, I mostly mean body :), because that's what is affected by the attributes of Function). So, in a sense, the confusion arises because this is the case when Function itself is a subject to the same logic. Now, removing the HoldAll attribute from Function is equivalent to using Evaluate on all its arguments: In[2] = Function[Evaluate[x],Evaluate[x^2]]/@Range[5] During evaluation of In[2]:= Function::flpar: Parameter specification 10 in Function[10,100] should be a symbol or a list of symbols. >> ... Out[2]= {Function[10,100][1],Function[10,100][2],Function[10,100][3],Function[10,100 ][4],Function[10,100][5]} The error messages are because the first argument of Function must be variable name, or a list of variable names (for named variables), but now evaluates to its global value, and the action of Function[10,100] on any argument is undefined and thus the expression is just returned (note by the way that if we would know/be able to see the system (built-in) global rules/definitions for Function, they would be SubValues, not DownValues). In the following case: In[3] = Clear[y]; Function[Evaluate[y], Evaluate[x^2]] /@ Range[5] Out[3] = {100, 100, 100, 100, 100} It at least understands what to do since has no global value and is a symbol. In the latter case, formally the result would be the same if we make a normal call: In[4] = Function[y, x^2] /@ Range[5] Out[4] = {100, 100, 100, 100, 100} Tracing shows the difference in evaluation however: In[5] = Function[Evaluate[y], Evaluate[x^2]][1] // Trace Out[5] = {{{{x,10},10^2,100},Function[y,100]},Function[y,100][1],100} In[6] = Function[y, x^2][1] // Trace Out[6] = {Function[y,x^2][1],x^2,{x,10},10^2,100} By the way, sometimes we may want to force the first (or both) of the arguments of the Function (the variable name or list of names) to be evaluated. This happens when we want to force Function perform the variable binding with the exact variable names that we provide. One such case happens when we have a list of variables (and possibly the rhs) separately: In[7] = Clear[x1,x2,x3] vars = {x1,x2,x3}; expr = x1*x2*x3; In[8] = {#, #[1, 2, 3]} &@Function[vars, expr] Out[8] = {Function[vars, expr], x1 x2 x3} In[9] = {#, #[1, 2, 3]} &@Function[Evaluate[vars], expr] Out[9] = {Function[{x1, x2, x3}, expr], x1 x2 x3} In[10] = {#, #[1, 2, 3]} &@Function[Evaluate[vars], Evaluate[expr]] Out[10] = {Function[{x1, x2, x3}, x1 x2 x3], 6} We see that in the latter case, we achieved the correct binding. I have to add however that separating variables and body in such a manner can be error prone and probably should be avoided in favor of safer techniques to achieve the same goal. For example, if x1,x2,x3 would have global values, we are in trouble: In[11] =x1 = 1; x2 = 2; x3 = 3; In[12]:= Function[Evaluate[vars],Evaluate[expr]] During evaluation of In[100]:= Function::flpar: Parameter specification {1,2,3} in Function[{1,2,3},6] should be a symbol or a list of symbols. >> Out[12]= Function[{1,2,3},6] One way to make this safer in this case is to wrap everything in Block: In[13] = x1 = 1; x2 = 2; x3 = 3; Block[{x1, x2, x3}, {#, #[1, 2, 3]} &@ Function[Evaluate[vars], Evaluate[expr]]] Out[13] = {Function[{x1, x2, x3}, x1 x2 x3], 6} But this wouldn't save us if x1,x2,x3 would have global values at the moment when we defined and . So it is best to avoid globals. In[14] = Clear[x1,x2,x3]; Another class of situations where we may want to do this is when we want to prevent variable renaming that normally happens during the name collision resolution in nested scoping constructs. Here is a (rather contrived) example from the top of my head: In[15] = Module[{x}, Function[x, x^2]] // FullForm Out[15] = Function[x,Power[x,2]] In[16] = Module[{x}, Function[Evaluate[x], x^2]] // FullForm Out[16] = Function[x$246,Power[x$246,2]] We see that Function in the first case protects its variable which remains just (as a symbol name), while in the second it is given a name generated by Module. When can this ever be useful? Well, if you use introspection in your code (such as writing macros that analyze/transform your code), then the second case can protect the code from what is called in Lisp a variable capture - when several instances of belonging to different lexical scopes would mistakingly be considered by a macro to be the same x, or similar problems. Probably all these examples are appropriate to be categorized as advanced techniques, so normally you don't want to play with Function in this manner. But I think they clarify the role of internal (implicit) HoldAll that the Function possesses. To summarize: this internal HoldAll has nothing to do with the arguments passed to the function Function[body][arguments] (and, by the way, never could, because in expression f[x][y], only the processing of is affected by the attributes of ), but with the passed to the function itself, and is needed for the correct operation of the Function itself. OTOH, correct processing of according to the attributes given explicitly in the of Function is a task of Function's implementation. Hope this helps. Leonid > Leonid, This is a really good explanation of evaluation. I'm still struggling > to internalize this, even after using Mathematica for years. I'm > curious about one point you raised. In this example: > In[7] = Function[y, (Print[Just before calling f]; f[y]), > HoldAll][Print[*]] > Just before calling f > * > Out[7]= {Hold[Null],Symbol} the result is different than when leaving off the explicit HoldAll: In[32]:= Function[y, (Print[Just before calling f]; f[y])][ > Print[*]] During evaluation of In[32]:= * During evaluation of In[32]:= Just before calling f Out[32]= f[Null] Yet the documentation for Function says: > Function has attribute HoldAll. The function body is evaluated only > after the formal parameters have been replaced by arguments. How is the explicit HoldAll attribute different from the inherent > HoldAll? Why doesn't Function normally act as with the explicit > HoldAll? > === Subject: Re: problem writing debugging utility function Leonid, This is a really good explanation of evaluation. I'm still struggling to internalize this, even after using Mathematica for years. I'm curious about one point you raised. In this example: > In[7] = Function[y, (Print[Just before calling f]; f[y]), > HoldAll][Print[*]] Just before calling f * Out[7]= {Hold[Null],Symbol} the result is different than when leaving off the explicit HoldAll: In[32]:= Function[y, (Print[Just before calling f]; f[y])][ Print[*]] During evaluation of In[32]:= * During evaluation of In[32]:= Just before calling f Out[32]= f[Null] Yet the documentation for Function says: Function has attribute HoldAll. The function body is evaluated only after the formal parameters have been replaced by arguments. How is the explicit HoldAll attribute different from the inherent HoldAll? Why doesn't Function normally act as with the explicit HoldAll? === Subject: ContourPlot3D and NIntegrate I don't understand what goes wrong in this sequence: * In[1]:=VV[x_,y_,z_]:= Module[{u,phi},NIntegrate[(x^2+y^2+z^2)^(-3)*u*phi,{u,0,1},{phi,0,2Pi}] ] In[2]:= ContourPlot3D[VV[x,y,z],{x,1,2},{y,1,2},{z,1,2}], AND THEN: NIntegrate::inumr: The integrand [NoBreak](phi$12637167 u$12637167)/(x^2+y^2+z^2)3[NoBreak] has evaluated to non-numerical values for all sampling points in the region with boundaries [NoBreak]{{0,1},{0,6.28319}}[NoBreak]. =87 Can anybody help? Henning Heiberg-Andersen === Subject: Re: ContourPlot3D and NIntegrate Hello Henning, I don't understand what goes wrong in this sequence: * In[1]:=VV[x_,y_,z_]:= Module[{u,phi},NIntegrate[(x^2+y^2+z^2)^(-3)*u*phi,{u,0,1},{phi,0,2Pi}] ] > this forces numerical evaluation: VV[x_?NumericQ, y_?NumericQ, z_?NumericQ] := Module[{u, phi}, NIntegrate[(x^2 + y^2 + z^2)^(-3)*u*phi, {u, 0, 1}, {phi, 0, 2 Pi}]] However, I suggest a different route: we can pre-evaluate the integral f = Integrate[(x^2 + y^2 + z^2)^(-3)*u*phi, {u, 0, 1}, {phi, 0, 2 Pi}] and then ContourPlot3D[f, {x, 1, 2}, {y, 1, 2}, {z, 1, 2}] which is faster. Should this not be possible you could start by looking into MaxRecursion and/or PlotPoints. Hth, Oliver > In[2]:= ContourPlot3D[VV[x,y,z],{x,1,2},{y,1,2},{z,1,2}], AND THEN: NIntegrate::inumr: The integrand [NoBreak](phi$12637167 > u$12637167)/(x^2+y^2+z^2)3[NoBreak] has evaluated to non-numerical values > for all sampling points in the region with boundaries > [NoBreak]{{0,1},{0,6.28319}}[NoBreak]. > =87 Can anybody help? > Henning Heiberg-Andersen === Subject: Re: ContourPlot3D and NIntegrate will the quenstions of that kind never end ? VV[x_?NumericQ, y_?NumericQ, z_?NumericQ] := Module[{u, phi}, NIntegrate[(x^2 + y^2 + z^2)^(-3)*u*phi, {u, 0, 1}, {phi, 0, 2 Pi}]] ContourPlot3D[VV[x, y, z], {x, 1, 2}, {y, 1, 2}, {z, 1, 2}] will work after a very long time .. Jens I don't understand what goes wrong in this sequence: * In[1]:=VV[x_,y_,z_]:= Module[{u,phi},NIntegrate[(x^2+y^2+z^2)^(-3)*u*phi,{u,0,1},{phi,0,2Pi}] ] In[2]:= ContourPlot3D[VV[x,y,z],{x,1,2},{y,1,2},{z,1,2}], AND THEN: NIntegrate::inumr: The integrand [NoBreak](phi$12637167 > u$12637167)/(x^2+y^2+z^2)3[NoBreak] has evaluated to non-numerical values > for all sampling points in the region with boundaries > [NoBreak]{{0,1},{0,6.28319}}[NoBreak]. > =87 Can anybody help? > Henning Heiberg-Andersen > === Subject: Re: directionfields from StreamPlot looks different from You're not. For the direction field of a 1-dimensional ordinary differential equation y' == f[t, y], the vector field you want to plot is {1, f[t,y]}. So... streams = StreamPlot[{1, t^2 - y}, {t, -4, 4}, {y, -2, 10}, StreamStyle -> Directive[Orange]]; sol = Table[NDSolve[{y'[t] == t^2 - y[t], y[0] == y0}, y[t], {t, -4, 4}], {y0, 0, 6, 0.5}]; solutionCurves = Plot[y[t] /. sol, {t, -4, 4}, PlotRange -> {{-4, 4}, {-2, 10}}]; Show[{solutionCurves, streams} Note that you do not need any parentheses around t^2. And in the current version of Mathematica, you no longer need to wrap y[t]/.sol with Evaluate -- unless you would like the curves automatically to be given different colors. > I don't think I'm using StreamPlot properly. Consider the following non-autonomous ODE y'[t] == (t^2) - y[t] Solutions for various ICs can be viewed by the following. sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == y0}, y[t], {t, -4, > 4}], {y0, 0, 6, 0.5}]; Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange -> {{-4, 4}, {-2, > 10}}] Shouldn't Vector fields be similar to the solutions above? If I plot t > on x-axis vs. t^2-y on y axis... VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] I don't get similar results... What is the reason for this? > Sean -- 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 an array in a loop Not clear what you are trying to do. Try something closer to this. Func[lmbd_, eps0_] := lmbd + 1 + eps0 Neps = 20; Nlmbd = 10; SOL = Table[0, {Nlmbd}, {Neps}]; deps0 = 0.1; For[lmbd = 0; ieps0 = 1, lmbd <= Nlmbd - 1 && ieps0 <= Neps, lmbd++; ieps0++, eps0 = deps0*(ieps0 - 1); SOL[[lmbd + 1, ieps0]] = Func[lmbd, eps0]] SOL Bob Hanlon I am new to Mathematica programming I have the following question. How to create an array in a loop? I have the code Neps0; Nlmbd=10; Array[SOL,{10,20}] deps0=0.1; eps0=0.0; For[lmbd=0; ieps0=1;, lmbd<=Nlmbd-1; ieps0 <= Neps;, lmbd=lmbd+1; ieps0=ieps0+1;, eps0=deps0*(ieps-1); SOL[[lmbd+1,ieps]]=Func[lmbd,eps0]; ] SOL (where Func[a,b] is some function) What is wrong with it, why this does not work? -- Bob Hanlon === Subject: Re: How to handle Units of Measure You could try the Accelerator`ConstantsUnits` package, I have mentioned in previous posts: http://jowett.home.cern.ch/jowett/Accelerator/ConstantsUnits.html Then a numerical version of your example (choosing unusual frequency units just to demonstrate the power) is Z = R + I*w*L /. {R -> 10.*Ohm, w -> 300000./Day, L -> 5.*Henry} Convert[Z,Ohm] which returns (10. + 17.3611 I) Ohm A symbolic version would be Z = R + I*w*L /. {R -> rO*Ohm, w -> wD/Day, L -> lH*Henry} Convert[Z, Ohm] returning Ohm*(rO + (I*lH*wD)/86400) It all looks better in a notebook of course. John Jowett > In this very simple example if I write > R+iwL > where R is measured in Ohms, w in s^-1, L in H, I expect that the > result is given in Ohms. > Why it doesn't happen in Mathematica ? Ho can I do to handle in a > simple way those conversions ? I do it this way, simple enough: In[30]:= R := x*Ohm; > w := z*Hz; > L := y*H; > H = Ohm/Hz; > R + w*L // Simplify Out[34]= Ohm (x + y z) -- > Alexei Boulbitch, Dr., habil. > Senior Scientist IEE S.A. > ZAE Weiergewan > 11, rue Edmond Reuter > L-5326 Contern > Luxembourg Phone: +352 2454 2566 > Fax: +352 2454 3566 Website:www.iee.lu This e-mail may contain trade secrets or privileged, undisclosed or other= wise confidential information. If you are not the intended recipient and ha= ve received this e-mail in error, you are hereby notified that any review, = copying or distribution of it is strictly prohibited. Please inform us imme= r your co-operation. === Subject: Re: Speeding up code DH always has great ideas into how to speed up and optimize code. I thought of him and this question when I came across this insight into the general question: Kas Thomas recounts the following advice he got early in his career on how to write fast code at his blog: http://asserttrue.blogspot.com/2009/03/how-to-write-fast-code.html A short snippet of a conversation between Kas and his mentor follows: 'The CPU,' he said, 'runs at a certain speed. It can execute a fixed number of instructions per second, and no more. There is a finite limit to how many instructions per second it can execute. Right?' 'Right,' I said. 'So there is no way, really, to make code go faster, because there is no way to make instructions execute faster. There is only such a thing as making the machine do less.' He paused for emphasis. 'To go fast,' he said slowly, 'do less.' To go fast, do less. Do less; go fast. Yes, of course. It makes perfect sense. There's no other way to make a program run faster except to make it do less. Me again -- All of these almost magical things Mathematica does with optimizing list operations and functional programming constructs, all of them, let run code faster because it lets it do less. Simple and elegant, the haiku form of programming languages. Best, A === Subject: Re: Problem with a plot in Mathematica C is reserved. Use a lower case c exp( _ ) should be Exp[ _ ] c[y_, vary_, varz_] = (25/2*3.14*7*vary*varz)*Exp[-y^2/2*vary^2]* Exp[-38^2/2*varz^2]; vary[x_] = 0.22*(1 + 0.0004 x) - 0.5; varz[x_] = 0.20*(1 + 0.0001 x) - 0.5; Plot3D[c[y, vary[x], varz[x]], {x, 0, 10}, {y, 0, 5}] Bob Hanlon Hi there I have a function to plot in Mathematica but i am keeping getting some mistake of sintax. this is the function: C=(25/2*3.14*7*vary*varz)*exp(-y^2/2*vary^2)*exp(-38^2/2*varz^2) and vary=0.22*(1+0.0004x)-0.5 varz=0.20*(1+0.0001x)-0.5 it shoud be a 3d but i put z=38 so it's a 2D now. How do you type it in Mathematica? Just to get what's my mistake any help is very much appreciated === Subject: Re: what is my error? There are multiple solutions eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17} {mp + mr == 13, fp + fr == 19, fr + mr == 15, fp + mp == 17} soln[fp_] = Quiet[Solve[eqns, {mr, mp, fr, fp}][[1]]] {mr -> fp - 4, mp -> 17 - fp, fr -> 19 - fp} solns1 = Table[Join[{fp -> fpi}, soln[fpi]], {fpi, 5, 16}] {{fp -> 5, mr -> 1, mp -> 12, fr -> 14}, {fp -> 6, mr -> 2, mp -> 11, fr -> 13}, {fp -> 7, mr -> 3, mp -> 10, fr -> 12}, {fp -> 8, mr -> 4, mp -> 9, fr -> 11}, {fp -> 9, mr -> 5, mp -> 8, fr -> 10}, {fp -> 10, mr -> 6, mp -> 7, fr -> 9}, {fp -> 11, mr -> 7, mp -> 6, fr -> 8}, {fp -> 12, mr -> 8, mp -> 5, fr -> 7}, {fp -> 13, mr -> 9, mp -> 4, fr -> 6}, {fp -> 14, mr -> 10, mp -> 3, fr -> 5}, {fp -> 15, mr -> 11, mp -> 2, fr -> 4}, {fp -> 16, mr -> 12, mp -> 1, fr -> 3}} And @@ (eqns /. solns1 // Flatten) True Reduce[Join[eqns, Thread[{mr, mp, fr, fp} > 0]], {mr, mp, fr, fp}] 0 < mr < 13 && mp == 13 - mr && fr == 15 - mr && fp == 19 - fr Restricting the domain to Integers solns2 = {Reduce[Join[eqns, Thread[{mr, mp, fr, fp} > 0]], {mr, mp, fr, fp}, Integers] // ToRules} {{mr -> 1, mp -> 12, fr -> 14, fp -> 5}, {mr -> 2, mp -> 11, fr -> 13, fp -> 6}, {mr -> 3, mp -> 10, fr -> 12, fp -> 7}, {mr -> 4, mp -> 9, fr -> 11, fp -> 8}, {mr -> 5, mp -> 8, fr -> 10, fp -> 9}, {mr -> 6, mp -> 7, fr -> 9, fp -> 10}, {mr -> 7, mp -> 6, fr -> 8, fp -> 11}, {mr -> 8, mp -> 5, fr -> 7, fp -> 12}, {mr -> 9, mp -> 4, fr -> 6, fp -> 13}, {mr -> 10, mp -> 3, fr -> 5, fp -> 14}, {mr -> 11, mp -> 2, fr -> 4, fp -> 15}, {mr -> 12, mp -> 1, fr -> 3, fp -> 16}} And @@ (eqns /. solns2 // Flatten) True Bob Hanlon eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: Re: Series Expansion It won't work with arbitrary series coefficients (also, would need to be a[n] vice a_n and b[n] vice b_n). Using simple examples, fm1[a_, x_] = 1 + Sum[a^n*x^n, {n, 1, M}] // Simplify (a^(M + 1)*x^(M + 1) - 1)/(a*x - 1) fm2[b_, x_] = 1 + Sum[b^n*x^n, {n, 1, M + 2}] // Simplify (b^(M + 3)*x^(M + 3) - 1)/(b*x - 1) fm[a_, b_, x_] = (fm1[a, x]/fm2[b, x]) ((b*x - 1)*(a^(M + 1)*x^(M + 1) - 1))/((a*x - 1)*(b^(M + 3)*x^(M + 3) - 1)) Series[fm[a, b, x], {x, 0, 5}] // Normal // Simplify ((a^5*x^5 + a^4*(x^4 - b*x^5) + a^3*(x^3 - b*x^4) + a^2*(x^2 - b*x^3) + a*(x - b*x^2) - b*x + 1)*(a^(M + 1)*x^(M + 1) - 1))/ (b^(M + 3)*x^(M + 3) - 1) Bob Hanlon Hi every body, I have the following function fm which is a rational between to series : fm1 = 1 + Sum[a_n*x^n, {n, 1, M}] fm2 = 1 + Sum[b_n*x^n, {n, 1, M + 2}] fm = (fm1/fm2) // Expand Now I want to have aseries exansion of fm to some order: Series[fm, {x, 0, 5}] // Expand But I get the input nothing else? can somebody there give me some hit 1/(1 + !( *UnderoverscriptBox[([Sum]), (n = 1), (2 + M)]( *SuperscriptBox[(x), (n)] b_n))) + !( *UnderoverscriptBox[([Sum]), (n = 1), (M)]( *SuperscriptBox[(x), (n)] a_n))/(1 + !( *UnderoverscriptBox[([Sum]), (n = 1), (2 + M)]( *SuperscriptBox[(x), (n)] b_n))) O. Kullie === Subject: Problem with plotting and simplifying a function I have a question that troubles me , and I'll appreciate your advices. Given Sum of : X_N(t) =Sum [ Exp(j2*Pi*k*t) ] with lower limit -N and upper limit +N , -2<= t <= 2 I need to calculate x(t) ,so I used Euler : X_N(t) = Sum e^(j2*pi*k*t) = Sum [ cos(2pi*k*t) + j*sin (2pi*k*t) ]. Now ,if I'm mistaken the sinus part becom equal to zero , because the cycle of sinus is PI . But I have a problem with the Cosinus part , how can I simplify it ? the t parameter interrupts with the simplifying ...... maybe separating it to conditions ? N=2R ------> even , N=2R+1 --> odd ? === Subject: Re: Problem with plotting and simplifying a function I doubt whether this is about Mathematica. It looks more like a math question. Given that this is a Mathematica newsgroup a few remarks from this point of view, just in case: Your syntax is not even close to that of the Mathematica language. -Underscores are not allowed in variable r function names (they are part of the pattern match syntax). -Use square brackets for the Exp function (and all other functions for that matter) -Lower case e does not equal the base of the natural log; that's written as either E or esc-ee-esc. -cosine and sine are written as Cos and Sin (starting with a capital letter as does any function in Mathematica) -You don't specify over which variable you're summing. Is it j2, k or t? -You use a lowercase j to indicate the square root of -1. In Mathematica you either use capital I, or esc-ii-esc or esc-jj-esc. For the Eulerian expression to be true j2 must be I as well, or does it have a deeper meaning? Now to the math: -You state that the cycle (I prefer the term 'period') of the sine is Pi. That's not true. It's 2Pi. Its zeros are spaced Pi apart, but that's not the same. -You state that sin (2pi*k*t) is zero. That's not generally true, only for integer values of of 2 k t. You never say that they are integer. -However, assuming 2 k t is integer (since you seem sure the sin equals zero), cos(2pi*k*t) equals 1, and your summation is 2N+1. > I have a question that troubles me , and I'll appreciate your advices. > Given Sum of : X_N(t) =Sum [ Exp(j2*Pi*k*t) ] with lower limit -N and upper limit +N , -2<= t <= 2 > I need to calculate x(t) ,so I used Euler : > X_N(t) = Sum e^(j2*pi*k*t) = Sum [ cos(2pi*k*t) + j*sin (2pi*k*t) ]. Now ,if I'm mistaken the sinus part becom equal to zero , because the cycle > of sinus is PI . But I have a problem with the Cosinus part , how can I > simplify it ? the t parameter interrupts with the simplifying ...... > maybe separating it to conditions ? N=2R ------> even , N=2R+1 --> od= d ? > === Subject: Re: Problem with plotting and simplifying a function what do you want to simplify with 1+2 Sum[Cos[2*Pi*k*t],{k,1,n}] ? Jens > I have a question that troubles me , and I'll appreciate your advices. > Given Sum of : X_N(t) =Sum [ Exp(j2*Pi*k*t) ] with lower limit -N and upper limit +N , -2<= t <= 2 > I need to calculate x(t) ,so I used Euler : > X_N(t) = Sum e^(j2*pi*k*t) = Sum [ cos(2pi*k*t) + j*sin (2pi*k*t) ]. Now ,if I'm mistaken the sinus part becom equal to zero , because the cycle > of sinus is PI . But I have a problem with the Cosinus part , how can I > simplify it ? the t parameter interrupts with the simplifying ...... > maybe separating it to conditions ? N=2R ------> even , N=2R+1 --> odd ? === Subject: 1GB Kernel Memory Limit I'm currently working on a problem that requires a whole lot of memory to complete. Sometimes, depending on the specific parameters being used, I will receive the dreaded, No more memory available, message. Doing my best to track memory usage with MemoryInUse[], MaxMemoryUsed [] and the Windows Task Manager, I find that the kernel quits when it hits a limit of around one gigabyte. I'm using Version 7.0 on 32-bit Windows XP without the /3GB switch active; neither switching to a 64 bit OS nor activating the /3GB switch are possibilities. However, I was under the distinct impression that even without the /3GB switch active I should have a per-process memory limit of 2GB, not 1GB. Is there some other reason the kernel might quit, due to either Mathematica settings or OS settings? As for modifying my program I've done obvious things like setting $HistoryLength = 0, Clear[]ing things that are no longer needed, and none of them have done the trick in all cases I've needed to deal with. I've also done an array of not-so-obvious things that haven't worked either. Any suggestions would be greatly appreciated. Pillsy === Subject: Re: 1GB Kernel Memory Limit I'm currently working on a problem that requires a whole lot of memory > to complete. Sometimes, depending on the specific parameters being > used, I will receive the dreaded, No more memory available, message. > Doing my best to track memory usage with MemoryInUse[], MaxMemoryUsed > [] and the Windows Task Manager, I find that the kernel quits when it > hits a limit of around one gigabyte. I'm using Version 7.0 on 32-bit Windows XP without the /3GB switch > active; neither switching to a 64 bit OS nor activating the /3GB > switch are possibilities. However, I was under the distinct impression > that even without the /3GB switch active I should have a per-process > memory limit of 2GB, not 1GB. Is there some other reason the kernel > might quit, due to either Mathematica settings or OS settings? As for modifying my program I've done obvious things like setting > $HistoryLength = 0, Clear[]ing things that are no longer needed, and > none of them have done the trick in all cases I've needed to deal > with. I've also done an array of not-so-obvious things that haven't > worked either. Any suggestions would be greatly appreciated. Well, I guess the first question, is if there is reason to expect to be able to run your code in the space available. You do not give enough information to decide that. Assuming most of the memory is consumed in large arrays, have you tested these to ensure they are packed using Developer`PackedArrayQ. A common reason for arrays to fail to pack, is if you have the odd integer mixed with an array of Real's - all the data must have the same type in order to pack. Not all software takes advantage of the 3GB switch - I don't know if MathKernel does or not. Under 32-bit Windows, you can't ever get a contiguous block of memory of even 2GB - even if you use the 3GB switch - so if Mathematica requests its memory as one chunk, that could explain what you find. Of course, you have supplied the real answer already - install 64-bit Windows and sufficient memory. This is my configuration, and it works beautifully David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: 1GB Kernel Memory Limit MacOS X Snow Leopard Windows XP 64 Bit, Windows Vista 64 Bit, Linux 64 Bit are 4 possible options ... Jens I'm currently working on a problem that requires a whole lot of memory > to complete. Sometimes, depending on the specific parameters being > used, I will receive the dreaded, No more memory available, message. > Doing my best to track memory usage with MemoryInUse[], MaxMemoryUsed > [] and the Windows Task Manager, I find that the kernel quits when it > hits a limit of around one gigabyte. I'm using Version 7.0 on 32-bit Windows XP without the /3GB switch > active; neither switching to a 64 bit OS nor activating the /3GB > switch are possibilities. However, I was under the distinct impression > that even without the /3GB switch active I should have a per-process > memory limit of 2GB, not 1GB. Is there some other reason the kernel > might quit, due to either Mathematica settings or OS settings? As for modifying my program I've done obvious things like setting > $HistoryLength = 0, Clear[]ing things that are no longer needed, and > none of them have done the trick in all cases I've needed to deal > with. I've also done an array of not-so-obvious things that haven't > worked either. Any suggestions would be greatly appreciated. Pillsy > === Subject: Repositioning AxesLabel position I have been trying to create a visually appealing data graphing template, something that might come close to the looks of an Origin or SigmaPlot graph. It seems that one of the weakness is the inability to reposition and rotate the axis labels. They are always at the end of each x and y axis and horizontal. Does anyone know of a method to transpose and rotate the text? Charles Koehler ______________________________________________________________________ This e-mail has been scanned by Verizon Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on Verizon Managed Email Content Service, visit: http://www.verizonbusiness.com/us/security/email/ CONFIDENTIALITY NOTICE: The information in this electronic mail is intended only for the named recipient. It is confidential and may be privileged. If you are not the intended recipient, please delete this electronic mail and all attachments immediately. Any unauthorized copying, distribution, disclosure or other action based upon these electronically transmitted materials is prohibited. ______________________________________________________________________ === Subject: Re: Problem with a plot in Mathematica >Hi there I have a function to plot in Mathematica but i am keeping >getting some mistake of sintax. >this is the function: >C=(25/2*3.14*7*vary*varz)*exp(-y^2/2*vary^2)*exp(-38^2/2*varz^2) >and >vary=0.22*(1+0.0004x)-0.5 varz=0.20*(1+0.0001x)-0.5 >it shoud be a 3d but i put z=38 so it's a 2D now. How do you type it >in Mathematica? To make effective use of any software, it is a good idea to read the documentation. And for software as complex as Mathematica, this is essential. A couple of key points. All built-in functions and symbols used by Mathematica start with a capital letter. Consequently, anything that does not begin with a capital letter is something you created and must be defined by you. Second, computer software generally doesn't do context interpretation well. Meaning, you simply cannot use parenthesis pairs as both indicating grouping for multiplication and delimiting function arguments. In fact, given both functions and variables can have arbitrary names, I doubt there is any way to create software that could allow such overloading. To overcome this, square brackets are used by Mathematica to delimit function arguments. So, your function needs to be written as: C=(25/2*3.14*7*vary*varz)*Exp[-y^2/2*vary^2]*Exp[-38^2/2*varz^2] === Subject: Re: creating an array in a loop >I am new to Mathematica programming I have the following question. >How to create an array in a loop? I have the code >Neps0; Nlmbd=10; >Array[SOL,{10,20}] >deps0=0.1; eps0=0.0; >For[lmbd=0; ieps0=1;, >lmbd<=Nlmbd-1; ieps0 <= Neps;, >lmbd=lmbd+1; ieps0=ieps0+1;, >eps0=deps0*(ieps-1); >SOL[[lmbd+1,ieps]]=Func[lmbd,eps0]; >] SOL >(where Func[a,b] is some function) >What is wrong with it, why this does not work? I am guessing you intended to have two criteria for determining when the loop ends. Specifically, lmbd =E2=89=A4 Nlmbd-1 and ieps0 =E2=89= =A4 Neps0. But you have used a complex expression to join these two criteria. Mathematica will only see the result from the last. That is your exit criteria written as: lmbd<=Nlmbd-1; ieps0 <= Neps0; will not never output either a True or False value. That is you cannot use a semicolon to join test criteria. Nor can you use it to terminate your test criteria. Assuming I have correctly interpreted your intent, the loop test needs to be either lmbd =E2=89=A4 Nlmbd-1 && ieps0 =E2=89=A4 Neps or And[lmbd =E2=89=A4 Nlmbd-1, iesp0 =E2=89=A4 Neps0] It looks like you may have typos in the loop code. You have variables in your loop named similar to loop counters but not identical. Possibly, this is correct and you have these variable defined elsewhere or perhaps this is an error. I can't determine which is the case for certain. =46inally, while it is possible to do what you want using For loops, this tends to be very inefficient in Mathematica. Other constructs generally execute far faster than For loops while still generating the same result. For example consider the following: In[2]:= Timing[For[n = 0; sum = 0, n < 10^6, n++; sum += n]; sum] Out[2]= {3.41602,500000500000} In[3]:= Timing[Plus @@ Range[10^6]] Out[3]= {0.284018,500000500000} In[4]:= Timing[Total[Range[10^6]]] Out[4]= {0.235723,500000500000} In[5]:= Timing[Sum[n, {n, 10^6}]] Out[5]= {0.242449,500000500000} In[6]:= Timing[Sum[k, {k, m}] /. m -> 10^6] Out[6]= {0.000392,500000500000} All produce exactly the same result. But there is a vast difference in execution time with the For loop being the slowest. === Subject: Re: directionfields from StreamPlot looks different from solution Hi Murray, How would you use StreamPlot for the following system? a'[t] == - k1 (t ^-h) a[t] - k2 (t ^-h) b[t], b'[t] == k1 (t ^-h) a[t] === > Subject: Re: directionfields from StreamPlot looks different f= rom solution > You're not. For the direction > field of a 1-dimensional ordinary differential equation y' > == f[t, y], the vector field you want to plot is {1, > f[t,y]}. So... streams = > StreamPlot[{1, t^2 - y}, {t, -4, 4}, {y, -2, 10}, > StreamStyle - Directive[Orange]]; > sol = Table[NDSolve[{y'[t] == t^2 - y[t], y[0] == > y0}, y[t], > {t, -4, 4}], > {y0, 0, 6, 0.5}]; > solutionCurves = > Plot[y[t] /. sol, {t, -4, 4}, > PlotRange -> {{-4, 4}, {-2, 10}}]; > Show[{solutionCurves, streams} Note that you do not need any parentheses around t^2. And > in the current version of Mathematica, you no longer need to > wrap y[t]/.sol with Evaluate -- unless you would like the > curves automatically to be given different colors. sean_incali@yahoo.com > I don't think I'm using StreamPlot properly. > Consider the following non-autonomous ODE > y'[t] == (t^2) - y[t] > Solutions for various ICs can be viewed by the > following. > sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == > y0}, y[t], {t, -4, > 4}], {y0, 0, 6, 0.5}]; > Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange > -> {{-4, 4}, {-2, > 10}}] > Shouldn't Vector fields be similar to the solutions > above? If I plot t > on x-axis vs. t^2-y on y axis... > VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] > StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] > I don't get similar results... > What is the reason for this? > > Sean > > -- 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 > =0A=0A=0A === Subject: Re: Psychrometric chart Bob, you might have to make your own graphics function. Since you're familiar with a psychrometric plot, you're probably also familiar with a Roses wind diagram. I have a .nb file I made for a Roses wind diagram. I'd be happy to send that to you, and you could see what I did. Then you could think about making your own graphics function. Advice: I would say you need to have medium-level capacity with Mathematica for your effort to end in success rather than frustration. Best, Scot > Hi Bob, you must not assume that people know special words from very narrow topics, you must explain what you want. I know faintly that a Mollier map shows some dependence between entropy, enthalpy and temperature. But you will have to explain. > Please could someone help me to plot the Mollier (i-x) psychrometric chart. === Subject: Re: Psychrometric chart I just checked and I have a fairly old .nb which plots the chart. I see it doesn't have complete labeling, etc but I think it has all the significant curves plotted. Let me know if you don't find something elsewhere and I could send you a copy. Rob === Subject: Re: what is my error? You all pointed out to me to think for a minute before I posted. Noticed all! > eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == > 17}NSolve[eqns, > {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater > than zero -- > > -- Home 508 877-3862 Cell 508 982-7266 === Subject: Re: what is my error? Richard, eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}; These equations are not all independent so if we use NSolve or Solve or Reduce we do not obtain a complete solution. Reduce[eqns] mp == 13 - mr && fr == 15 - mr && fp == 4 + mr We can see this by setting up the matrix and rhs to use LinearSolve: m = ( { {1, 1, 0, 0}, {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} } ); b = {13, 19, 15, 17}; Det[m] 0 But, LinearSolve will obtain a solution as long as the rhs is linearly dependent in the same way as the rows of the matrix are. lsols0 = LinearSolve[mat, {13, 19, 15, 17}] lsols1 = {mr, mp, fr, fp} -> lsols0 // Thread {-4, 17, 19, 0} {mr -> -4, mp -> 17, fr -> 19, fp -> 0} eqns /. lsols1 {True, True, True, True} David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: Re: what is my error? > eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == > 17}NSolve[eqns, > {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are > greater > than zero -- > What makes you think so? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}; sols = FindInstance[ And @@ eqns && mr > 0 && mp > 0 && fr > 0 && fp > 0, {mr, mp, fr, fp}] {{mr -> 13/2, mp -> 13/2, fr -> 17/2, fp -> 21/2}} eqns /. sols {{True, True, True, True}} ???? Actually, even if you only want positive integer solutions you will find more than the one you gave: {mr, mp, fr, fp} /. {ToRules[Reduce[ And @@ eqns && mr > 0 && mp > 0 && fr > 0 && fp > 0, {mr, mp, fr, fp}, Integers]]} {{1, 12, 14, 5}, {2, 11, 13, 6}, {3, 10, 12, 7}, {4, 9, 11, 8}, {5, 8, 10, 9}, {6, 7, 9, 10}, {7, 6, 8, 11}, {8, 5, 7, 12}, {9, 4, 6, 13}, {10, 3, 5, 14}, {11, 2, 4, 15}, {12, 1, 3, 16}} Andrzej Kozlowski === Subject: what is my error? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- === Subject: question on passing arguments in a function within BarChart I am trying to use the ChartElementFunction within BarChart to draw some special error bars. The following is a step in the right direction and it works: g[{{xmin_, xmax_}, {ymin_, ymax_}}, values_, meta_] := {Polygon[{{xmin, ymin}, {xmax, ymin}, {xmax, ymax}, {xmin, ymax}}], {Thickness[0.005], Black, Line[{{(xmin + xmax)/2, ymin}, {(xmin + xmax)/2, ymax}}]}} BarChart[{1, 2, 3}, ChartElementFunction -> g] I am not sure where g is getting the coordinates from but it does, but now I would like to include the metadata: the actual values that I will use for the error bars, however, I am not sure how to pass that argument (i.e. ChartElementFunction->g[???] ) . Any suggestions? Ramiro === Subject: Re: question on passing arguments in a function within BarChart Hi Ramiro, The meta information is passed together with the input as a set of rules. Example follows: g[{{xmin_, xmax_}, {ymin_, ymax_}}, values_, meta_] := {Polygon[{{xmin, ymin}, {xmax, ymin}, {xmax, ymax}, {xmin, ymax}}], {Thickness[0.005], Black, Line[{{(xmin + xmax)/2, ymax + meta[[1]]}, {(xmin + xmax)/2, ymax - meta[[1]]}}]}} BarChart[{1 -> 0.3, 2 -> 0.5, 3 -> 0.2}, ChartElementFunction -> g] BarChart generates the input to g based on its input. Meta data is explained in the last line of the More Information section of the doc page of ChartElementFunction. I am trying to use the ChartElementFunction within BarChart to draw > some special error bars. The following is a step in the right direction and it works: g[{{xmin_, xmax_}, {ymin_, ymax_}}, values_, > meta_] := {Polygon[{{xmin, ymin}, {xmax, ymin}, {xmax, ymax}, {xmin, > ymax}}], {Thickness[0.005], Black, > Line[{{(xmin + xmax)/2, ymin}, {(xmin + xmax)/2, ymax}}]}} > BarChart[{1, 2, 3}, ChartElementFunction -> g] I am not sure where g is getting the coordinates from but it does, but > now I would like to include the metadata: the actual values that I > will use for the error bars, however, I am not sure how to pass that > argument (i.e. ChartElementFunction->g[???] ) . Any suggestions? Ramiro === Subject: Re: difference between HeavisidePi and UnitBox Andrzej, I agree with what you say here, but as a user of this functionality let me amplify a bit. > It depends on your purpose. For some simple purposes they are > equivalent but there is a huge difference when you try to do calculus > with them. The basic issue is that function, derivative, and integral mean different things in different mathematical contexts. For the benefit of those who haven't encountered this, start at page 255 of: for a fine overview of these issues. > You can perform most natural operations such as > differentiation or integration on generalized functions: D[HeavisidePi[x], x] > 2*DiracDelta[2*x + 1] - 2*DiracDelta[2*x - 1] which is a well behaved generalized function while D[UnitBox[x], x] Piecewise[{{Indeterminate, x == 1/2 || x == -(1/2)}}, 0] is the zero function with two undefined values at 1/2 and -1/2, > basically a useless object. UnitBox has the unfortunate property that it doesn't have derivatives at the important points. On the other side, HeavisideTheta isn't numeric at those points, so it would be troublesome in numerical analysis. Which one you should choose depends on what you're going to do with them. Now, this isn't really much of a problem when using the math to solve an scientific or engineering problem by hand: the physical nature of the problem determines the interpretation of the mathematical symbols. Most scientists and engineers aren't even aware of the issues here, and those of us who are rarely worry about them when scribbling on the back of the envelope. But Mathematica only sees the symbols, not the reality (if any) behind them. > So, for example: Integrate[D[HeavisidePi[x], x], {x, -Infinity, 0}] > 1 while naturally Integrate[D[UnitBox[x], x], {x, -Infinity, 0}] > 0 I came up with these examples just off hand so they may look a bit > artificial but it is easy to find ones that arise in serious problems. Not so artificial when you realize that Mathematica is likely to evaluate such expressions as it breaks down more realistic problems. I suspect this is exactly the kind of thing behind the difficulties Mathematica used to have when given calculations that required generalized functions: http://forums.wolfram.com/mathgroup/archive/2000/Apr/msg00043.html In the early days, Wolfram apparently believed that these issues could be finessed by heuristics similar to the way we do applied math by hand. So, the only explicit generalized function was DiracDelta, and UnitStep's treatment depended on the undocumented heuristics. That didn't work very well. In recent versions, since the introduction of the distinction between the Heaviside generalized functions and their numerical counterparts, Mathematica's behavior in this area has been much better. For me, the main application here is in analyzing noises, such as white and flicker noise: http://www.nr.com/whp/Flicker_Noise_1978.pdf For some purposes here, it's very handy to do symbolic calculations using generalized functions, rather than numerical simulations. >> I understand that it doesn't matter. There's even some discussion >> here about it http://mathworld.wolfram.com/RectangleFunction.html >> My question is regarding The piecewise version of the rectangle >> function is implemented in Mathematica as UnitBox[x], while the >> generalized function version is implemented as HeavisidePi[x]. >> why do we need both? I find the integral transforms (I use mostly >> FourierTransform) actually work much better with the piecewise UnitBox >> for 5-bar patterns that I like to use. >> Does anyone have a thorough explanation of when generalized functions >> are better than piecewise and vice versa? > ... -- John Doty, Noqsi Aerospace, Ltd. http://www.noqsi.com/ -- The axiomatic method of mathematics is one of the great achievements of our culture. However, it is only a method. Whereas the facts of mathematics once discovered will never change, the method by which these facts are verified has changed many times in the past, and it would be foolhardy to expect that changes will not occur again at some future date. - Gian-Carlo Rota === Subject: Re: RandomReal gets stuck Apparently there is more to it than meets the eye, but section 2.5.5 in the (old) mathematica book discusses the use of indexed objects. Bas > Sorry, in the meantime I found the entry for this in the documentation which > explains precisely when and how this kind of notation can be useful. A.B. > >> By the way, is the use of indexed variable names in the form x[i] encouraged >> in Mathematica ? It doesn't make sense in mathematical notation (as far as I >> am aware) and is not coherent with the use of brackets in Mathematica. >> A.B. >> The code above uses Maximize in a non-sensical way, particularly >> when the function y hasn't been defined. This usage asks >> Mathematica to find the maximize the sum of n things with >> respect to each of the n things. It appears there is an attempt >> to use the notation y[n] to mean an array indexed by n rather >> than a function of n. So, Maximize correctly generates error >> messages. What is unexpected is poor input to Maximize appears >> to cause a problem for RandomReal. > Bill, >> I don't think you understood what I was trying to do. I merely > simplified Bas' code to something that had the same effects on random > number generation. The use of y[i] was taken from Bas' example. I > don't think he meant to index an array. You can use y[1], y[2] etc. > just as any other variable. >> The error message in Maximize is not material to the problem. I ask > Mathematica to maximize an unbounded sum of variables. It's a > perfectly legal (though unsolvable) problem. That it responds with an > error message doesn't matter (I can -and have- come up with more > elaborate functions that have the same problem with random numbers but > don't cause Maximize to generate a warning). The problem is that > Maximize with 31 or more variables resets the random number generator. > In the mean time, Wolfram has confirmed this is indeed the case and it > will be fixed in a new realease. > I can confirm this bug. > Executing an even simpler version, namely > Maximize[Plus @@ Table[y[i], {i, 31}], Table[y[i], {i, 31}]]; > will also set the random generator to a fixed starting point. The > number 31 is crucial, as lower values do not appear to cause the > bug, while higher values do. Changing Plus to Times appears to > prevent the bug. > In[394]:= Table[ > Maximize[Plus @@ Table[y[i], {i, 31}], Table[y[i], {i, 31}]]; > RandomReal[], {20} > ] >> When I execute the code above, I do get the same result as you >> report. Clearly, there is a problem here somewhere. But it isn't >> clear the issue is with RandomReal. >> The code above uses Maximize in a non-sensical way, particularly >> when the function y hasn't been defined. This usage asks >> Mathematica to find the maximize the sum of n things with >> respect to each of the n things. It appears there is an attempt >> to use the notation y[n] to mean an array indexed by n rather >> than a function of n. So, Maximize correctly generates error >> messages. What is unexpected is poor input to Maximize appears >> to cause a problem for RandomReal. >> On my system, changing Plus to Times eliminates the effect on >> RandomReal even though there is still a non-sensical input to >> Maximize. Alternatively, defining y then executing the code does >> In[5]:= y[n_] := n^2 - n >> In[6]:= Table[ >> Maximize[Plus @@ Table[y[i], {i, 31}], Table[y[i], {i, 31}]]; >> RandomReal[], {20}] >> During evaluation of In[6]:= Maximize::ivar: 0 is not a valid >> variable. >> During evaluation of In[6]:= Maximize::ivar: 0 is not a valid >> variable. >> During evaluation of In[6]:= Maximize::ivar: 0 is not a valid >> variable. >> During evaluation of In[6]:= General::stop: Further output of >> Maximize::ivar will be suppressed during this calculation. >> Out[6]= {0.877054,0.833103,0.703786,0.0482118,0.226066,0.230746,0.07380= > 72= >> ,0.680963,0.53264,0.989333,0.418793,0.951114,0.963168,0.870439,0.926361,0= > .267113,0.195084,0.810066,0.875896,0.579076} > This is very nasty, as a lot of people critically depend on random > functions to be random. I would urge you to report this to wolfram > support. >> I agree many people including myself depend on the random >> functions to be random. And I would also like Mathematica to >> fail gracefully when given non-sensical input and provide useful >> error messages. But I am never surprised when software does >> something other than fail gracefully given non-sensical input or >> provides less than useful error messages. >> Entering >> Table[ >> Maximize[Plus @@ Table[y[i], {i, 31}], Table[y[i], {i, 31}]]; >> RandomReal[], >> {20} >> ] >> into a new session and expecting useful output simply isn't a >> reasonable expectation. >> Note, this in no way says what the original poster was doing is >> unreasonable or non-sensical. The rest of the information needed >> to determine whether what the original poster was attempting is >> sensible hasn't been provided. I would also note, that sending a >> bug report to Wolfram without the additional information is >> probably pointless. > === Subject: Re: RandomReal gets stuck > could > have consequences on subsequent computations. > Defining y[1]=10 simply creates a value rule for a DownValue for y. > In this > case y itself has no particular value. Setting x=5 gives an OwnValue > to x. Any thoughts from the experts on the safety of using the notation > y[i] for > subscripted variables ? A.B. > It's much safer than using Subscripted variables for subscripted variables. Andrzej Kozlowski > I agree many people including myself depend on the random functions >> to be random. And I would also like Mathematica to fail gracefully >> when given non-sensical input and provide useful error messages. >> But I am never surprised when software does something other than >> fail gracefully given non-sensical input or provides less than >> useful error messages. > This was perfectly good input. There is nothing wrong with it. It > asks the minimum of the sum of 31 variables (which of course does > not exist, but this doesn't mean that the question is mathematically > incorrect, or that the input is syntactically wrong). >> I disagree. The code asked for the minimum of 31 *functions* not >> 31 variables. Variables are not functions. >> While I agree it is often convenient to think of y[1] as either >> a subscripted variable or the first value of an array, it is >> neither. There is a clear difference in behavior when it comes >> to assignments. Assignments to symbols used as variables result >> in the symbol having an OwnValue not a DownValue. That is: >> In[1]:= x = 1 >> Out[1]= 1 >> In[2]:= OwnValues[x] >> Out[2]= {HoldPattern[x]:>1} >> In[3]:= DownValues[x] >> Out[3]= {} >> This is just opposite of what happens with assignments made to >> functions. That is: >> In[4]:= y[1] = 3 >> Out[4]= 3 >> In[5]:= OwnValues[y] >> Out[5]= {} >> In[6]:= DownValues[y] >> Out[6]= {HoldPattern[y(1)]:>3} >> There is a clear difference that will cause differences when >> these are used in other computations. Simply stated the syntax >> y[1] is not a variable and should only be used as a variable >> with a great deal of care and understanding. > However, the validity of this input has absolutely nothing to do > with the seriousness of this bug. This is the kind of bug that is > very hard to forgive because it's completely unexpected. >> You seem to be missing my point here. Invalid input simply is >> not guaranteed to have predictable results. Until the problem >> with the input is fixed, it isn't possible to say whether the >> result is a bug or not. >> In any case, the code used by the original poster did not >> include definitions of functions being used. And without those >> definitions, there was no way to verify the code he was using >> was valid. And that lack means there is no way to clearly know >> whether his result was due to a bug in Mathematica or his code. === Subject: Re: RandomReal gets stuck have consequences on subsequent computations. Defining y[1]=10 simply creates a value rule for a DownValue for y. In this case y itself has no particular value. Setting x=5 gives an OwnValue to x. Any thoughts from the experts on the safety of using the notation y[i] for subscripted variables ? A.B. > I agree many people including myself depend on the random functions > to be random. And I would also like Mathematica to fail gracefully > when given non-sensical input and provide useful error messages. > But I am never surprised when software does something other than > fail gracefully given non-sensical input or provides less than > useful error messages. > >> This was perfectly good input. There is nothing wrong with it. It >> asks the minimum of the sum of 31 variables (which of course does >> not exist, but this doesn't mean that the question is mathematically >> incorrect, or that the input is syntactically wrong). I disagree. The code asked for the minimum of 31 *functions* not > 31 variables. Variables are not functions. While I agree it is often convenient to think of y[1] as either > a subscripted variable or the first value of an array, it is > neither. There is a clear difference in behavior when it comes > to assignments. Assignments to symbols used as variables result > in the symbol having an OwnValue not a DownValue. That is: In[1]:= x = 1 Out[1]= 1 In[2]:= OwnValues[x] Out[2]= {HoldPattern[x]:>1} In[3]:= DownValues[x] Out[3]= {} This is just opposite of what happens with assignments made to > functions. That is: In[4]:= y[1] = 3 Out[4]= 3 In[5]:= OwnValues[y] Out[5]= {} In[6]:= DownValues[y] Out[6]= {HoldPattern[y(1)]:>3} There is a clear difference that will cause differences when > these are used in other computations. Simply stated the syntax > y[1] is not a variable and should only be used as a variable > with a great deal of care and understanding. > >> However, the validity of this input has absolutely nothing to do >> with the seriousness of this bug. This is the kind of bug that is >> very hard to forgive because it's completely unexpected. You seem to be missing my point here. Invalid input simply is > not guaranteed to have predictable results. Until the problem > with the input is fixed, it isn't possible to say whether the > result is a bug or not. In any case, the code used by the original poster did not > include definitions of functions being used. And without those > definitions, there was no way to verify the code he was using > was valid. And that lack means there is no way to clearly know > whether his result was due to a bug in Mathematica or his code. === Subject: How to change the font size in legend I came across this thread this morning. The solution is: PlotLegend -> {Style[Exact PDF, FontSize -> 20], Style[ Normal Approx, FontSize -> 20]} Chiara === Subject: Re: How can I get the previous Fibonacci calculated number in a specific > How can I get a previous Fibonacci calculated number in a specific > range? > I tested it with 13 and got 8.034441857 .....so that works Hi. Not sure if this is what you want, but this uses the Newton Method to arrive at a solution. You will want to just use FixedPoint, and remove the Print Statement. pf[n_] := Module[{equ, close, sol}, close = Log[(10*n)/(5 + Sqrt[5])]/ArcCsch[2.`40.]; equ = #1 - (Sqrt[5]* GoldenRatio^(1 + #1)*(Fibonacci[1 + #1] - n))/ (GoldenRatio^(2*(1 + #1))*ArcCsch[2] - ArcCsch[2]*Cos[#1*Pi] - Pi*Sin[#1*Pi]) & ; sol = FixedPointList[equ, close, 30]; Print[sol]; Fibonacci[Last[sol]] ] pf[13] {6.002463651555561729480380118647684161094, 6.00000138968405635542723303991757514756, 6.00000000000044224613952819926819019849, 6.0000000000000000000000000447878323424, 6.000000000000000000000000000000000000, 6.000000000000000000000000000000000000} 8.00000000000000000000000000000000000 At larger input values, the initial guess gets closer to the actual value, so there are less loops. pf[2343400000000] // Round {59.86164431800891991967444158220990866255, 59.8616443180089199196744415135639364713, 59.8616443180089199196744415135639364713} 1448300849237 As a side note, your phi1 variable is the GoldenRatio (1 + Sqrt[5])/2 == GoldenRatio True = = = = = = HTH Dana DeLouis > > How can I get a previous Fibonacci calculated number in a specific > range. I can calculate the previous number of phi see below > > phi1 =(1+sqrt(5))/2 > > 13/phi1 > > I tested it with 13 and got 8.034441857 .....so that works > > but how can I get only the previous numbers of Fibonacci in a > specified range from 20 to 20000 if I input a large number like > 234.34e10 > > tia sal2 > === Subject: Re: Series Expansion Hi every body, I have the following function fm which is a rational between to series : fm1 = 1 + Sum[a_n*x^n, {n, 1, M}] fm2 = 1 + Sum[b_n*x^n, {n, 1, M + 2}] fm = (fm1/fm2) // Expand Now I want to have aseries exansion of fm to some order: Series[fm, {x, 0, 5}] // Expand But I get the input nothing else? can somebody there give me some hit 1/(1 + !( *UnderoverscriptBox[([Sum]), (n = 1), (2 + M)]( *SuperscriptBox[(x), (n)] b_n))) + !( *UnderoverscriptBox[([Sum]), (n = 1), (M)]( *SuperscriptBox[(x), (n)] a_n))/(1 + !( *UnderoverscriptBox[([Sum]), (n = 1), (2 + M)]( *SuperscriptBox[(x), (n)] b_n))) O. Kullie For one thing the notation like a_n in Mathematica means not what you want to express. You should chose another one, like for example, a[n] or somewhat else. For another thing, I also did not succeed to expand your expression in its general form. This is not unexpected, since the form of the expansion too strongly depends upon M. However, if you ultimately want to have the expansion up to the 5th order, you need terms higher than the 5th order neither in the numerator nor in the denominator. Higher terms do not contribute. So your problem is not in Mathematica, but in mathematics. Anyway, try this: In[45]:= Clear[fm, fm1, fm2]; fm1 = 1 + Sum[a[n]*x^n, {n, 1, 5}] fm2 = 1 + Sum[b[n]*x^n, {n, 1, 3 + 2}] fm = (fm1/fm2) // Expand Series[fm, {x, 0, 5}] // Simplify Out[46]= 1 + x a[1] + x^2 a[2] + x^3 a[3] + x^4 a[4] + x^5 a[5] Out[47]= 1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5] Out[48]= 1/( 1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5]) + (x a[1])/( 1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5]) + ( x^2 a[2])/( 1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5]) + ( x^3 a[3])/( 1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5]) + ( x^4 a[4])/( 1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5]) + ( x^5 a[5])/(1 + x b[1] + x^2 b[2] + x^3 b[3] + x^4 b[4] + x^5 b[5]) Out[49]= (SeriesData[$CellContext`x, 0, { 1, $CellContext`a[1] - $CellContext`b[ 1], $CellContext`a[2] - $CellContext`a[1] $CellContext`b[ 1] + $CellContext`b[1]^2 - $CellContext`b[ 2], $CellContext`a[3] - $CellContext`a[2] $CellContext`b[ 1] + $CellContext`a[1] $CellContext`b[1]^2 - $CellContext`b[ 1]^3 - $CellContext`a[1] $CellContext`b[ 2] + 2 $CellContext`b[1] $CellContext`b[2] - $CellContext`b[ 3], $CellContext`a[4] - $CellContext`a[3] $CellContext`b[ 1] + $CellContext`a[2] $CellContext`b[1]^2 - $CellContext`a[ 1] $CellContext`b[1]^3 + $CellContext`b[1]^4 - $CellContext`a[ 2] $CellContext`b[ 2] + 2 $CellContext`a[1] $CellContext`b[1] $CellContext`b[ 2] - 3 $CellContext`b[1]^2 $CellContext`b[ 2] + $CellContext`b[2]^2 - $CellContext`a[1] $CellContext`b[ 3] + 2 $CellContext`b[1] $CellContext`b[3] - $CellContext`b[ 4], $CellContext`a[5] - $CellContext`a[4] $CellContext`b[ 1] + $CellContext`a[3] $CellContext`b[1]^2 - $CellContext`a[ 2] $CellContext`b[1]^3 + $CellContext`a[ 1] $CellContext`b[1]^4 - $CellContext`b[1]^5 - $CellContext`a[ 3] $CellContext`b[ 2] + 2 $CellContext`a[2] $CellContext`b[1] $CellContext`b[ 2] - 3 $CellContext`a[1] $CellContext`b[1]^2 $CellContext`b[ 2] + 4 $CellContext`b[1]^3 $CellContext`b[2] + $CellContext`a[ 1] $CellContext`b[2]^2 - 3 $CellContext`b[ 1] $CellContext`b[2]^2 - $CellContext`a[2] $CellContext`b[ 3] + 2 $CellContext`a[1] $CellContext`b[1] $CellContext`b[ 3] - 3 $CellContext`b[1]^2 $CellContext`b[ 3] + 2 $CellContext`b[2] $CellContext`b[3] - $CellContext`a[ 1] $CellContext`b[ 4] + 2 $CellContext`b[1] $CellContext`b[4] - $CellContext`b[ 5]}, 0, 6, 1]) -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: ContourPlot3D and NIntegrate Since VV uses numerical techniques (i.e., NIntegrate), you must restrict it to numerical arguments. VV[x_?NumericQ, y_?NumericQ, z_?NumericQ] := Module[{u, phi}, NIntegrate[(x^2 + y^2 + z^2)^(-3)*u*phi, {u, 0, 1}, {phi, 0, 2 Pi}]] However, use Integrate Clear[VV]; VV[x_, y_, z_] = Integrate[(x^2 + y^2 + z^2)^(-3)*u*phi, {u, 0, 1}, {phi, 0, 2 Pi}] Pi^2/(x^2 + y^2 + z^2)^3 ContourPlot3D[VV[x, y, z], {x, 1, 2}, {y, 1, 2}, {z, 1, 2}] Bob Hanlon I don't understand what goes wrong in this sequence: * In[1]:=VV[x_,y_,z_]:= Module[{u,phi},NIntegrate[(x^2+y^2+z^2)^(-3)*u*phi,{u,0,1},{phi,0,2Pi}] ] In[2]:= ContourPlot3D[VV[x,y,z],{x,1,2},{y,1,2},{z,1,2}], AND THEN: NIntegrate::inumr: The integrand [NoBreak](phi$12637167 u$12637167)/(x^2+y^2+z^2)3[NoBreak] has evaluated to non-numerical values for all sampling points in the region with boundaries [NoBreak]{{0,1},{0,6.28319}}[NoBreak]. =87 Can anybody help? Henning Heiberg-Andersen === Subject: interfacing odd usb device to mathematica Hi All -- I am fed up with the cheesy software that comes with my biofeedback USB device, and I'd like to interface it to Mathematica. It is a LightStone device from the Wild Divine project. The trouble is that it does not show up on ControllerInformation[], although it does show up on my Mac's USBProbe software. I am using Mac OSX, version 4.11 and Mathematica 7. USBProbe gives me the following information about the device: Descriptor Version Number: 0x0110 Device Class: 0 (Composite) Device Subclass: 0 Device Protocol: 0 Device MaxPacketSize: 8 Device VendorID/ProductID: 0x14FA/0x0001 (unknown vendor) Device Version Number: 0x2441 Number of Configurations: 1 Manufacturer String: 3 Wild Divine Product String: 1 ST7 RS232 USB BIOFBK Serial Number String: 0 (none) The only solution I can think of now is to try to write a separate program to stream output from the device and then read that output into Mathematica. But if there's some way to get Mathematica to recognize the device itself, that would obviously be much better. -Zac === Subject: A puzzle with Compile Hi everyone, I stumbled upon a strange behavior for which I have no good explanation. Consider the following perverse way to imitate Range: In[1] = Module[{i = 0}, Function[x, Table[x, {10}], HoldAll][++i]] Out[1] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Now I attempt to speed it up with Compile: In[2] = Compile[{{n, _Integer}}, Module[{i = 0}, Function[x, Table[x, {n}], HoldAll][++i]]][10] Out[2] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1} Now, I am not a Compile expert, but to me it looks like it does not respect the Hold attribute I have given to the Function inside (this can also be confirmed by using something like (Print[i];++i) instead of (++i)) - printing occurs just once. Note by the way that Table is not a culprit either - it is HoldAll, and we may use explicit list in its place and get the same results. In[3] = Module[{i = 0}, Function[x, {x, x, x, x, x}, HoldAll][++i]] Out[3] = {1, 2, 3, 4, 5} In[4] = Compile[{{n, _Integer}}, Module[{i = 0}, Function[x, {x, x, x, x, x}, HoldAll][++i]]][1] Out[4] = {1, 1, 1, 1, 1} where in this case the dependence is at all spurious, and the whole structure is known at compile-time (unlike the previous one where the length of the list was a parameter to the function). It looks like Compile's treatment of this kind of code is not consistent with the general principles of Mathematica evaluation / attributes mechanics. Note that it is not like Compile can not handle held arguments at all: In[5] = Compile[{{n, _Integer}}, Module[{i = 0}, Table[++i, {n}]]][5] Out[5] = {1, 2, 3, 4, 5} in which case ++i is held by Table. We can go even further: In[6] = Module[{i = 0}, {++i, ++i, ++i}] Out[6]= {1, 2, 3} In[7] = Compile[{{n, _Integer}}, Module[{i = 0}, {++i, ++i, ++i}]][5] Out[7] = {3, 3, 3} where again, in the last example, there is no real n-dependence. My own guess is that this sort of problems occur when Hold attributes are used to make a function act like a macro in some sense - that is, when effectively some code expansion must happen (to get correct results) before the code is executed (like the above examples). But the In[5] example, which is treated correctly, is different only in Table being a built-in rather than user-defined, with HoldAll also, so I am still puzzled. Besides, for the very last example I have no explanation whatsoever - this one just looks like a plain bug. Anyone having better ideas / explanation? Leonid === Subject: Re: Replacing expressions with smaller atoms The first of those solutions (with Simplify) looks brilliant, but I don't think I've ever seen that sort of form anywhere in the Mathematica documentation. I've used the second argument(s) to Simplify often, but didn't know it'd work like that. Is there some obvious way to see that substitutions will work that way, or did you figure it out some other way. C.O. > M = x + (x (x^2 + x + 1))^(1/2); Simplify[M, L == x^2 + x + 1] Sqrt[L*x] + x M /. x^2 + x + 1 -> L Sqrt[L*x] + x > Bob Hanlon > If I define an atom eg L=x^2+x+1, is there a way to rewrite an > expression with these atoms? For example: L=x^2+x+1 > M=x+(x(x^2+x+1))^(1/2) I would like some way to express this as x+(xL)^(1/2). Is this possible? -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 === Subject: Re: Replacing expressions with smaller atoms M = x + (x (x^2 + x + 1))^(1/2); Simplify[M, L == x^2 + x + 1] Sqrt[L*x] + x M /. x^2 + x + 1 -> L Sqrt[L*x] + x Bob Hanlon If I define an atom eg L=x^2+x+1, is there a way to rewrite an expression with these atoms? For example: L=x^2+x+1 M=x+(x(x^2+x+1))^(1/2) I would like some way to express this as x+(xL)^(1/2). Is this possible? === Subject: Re: Possible bug in Eigenvalues[ ] ??? > I'm using Mathematica v.6.0.1.0 under Windows. > I was using the Eigenvalues function to find the eigenvalues of some > complex matrices when I found a very strange behaviour. > Cutting the problem down to the bone, consider the 2x2 matrices > mat = {{11/3, -(1/3)}, {-(1/3), -7}} > pert={{-1 + [ImaginaryI], 1/2 + [ImaginaryI]/2}, {-1, 0}} I'm interested in the trajectories on the complex plane of the > eigenvalues of A(lambda)= mat + lambda*pert as a function of the > strength lambda. I calculated these trajectories in two ways and I get > different results (one of which is the correct one). --> 1st way > expr = Eigenvalues[mat + [Lambda] pert]; > traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; --> 2nd way > traj2 = Table[Eigenvalues[mat + [Lambda] pert], {[Lambda], 0, 10, 0.1}]; The resulting lists traj1 and traj2 are NOT the same! > A small notebook showing this problem can be found here: > http://www.homepages.ucl.ac.uk/~ucapllo/test.eig.nb Any thoughts? Is this behaviour normal? Lorenzo Yes, normal. The symbolic eigenvalues might correspond to a different ordering once substitutions with number take place. To get a viable comparison, sort the numeric values. In[12]:= diff = Map[Sort,traj1]-Map[Sort,traj2]; In[13]:= Max[Abs[diff]] -15 Out[13]= 6.40475 10 Daniel Lichtblau Wolfram Research === Subject: Re: Possible bug in Eigenvalues[ ] ??? Lorenzo, This comes about because of the non-standard evaluation of Table and the fact that it has the attribute HoldAll. In one case it is obtaining a symbolic expression for the eigenvalues and then substituting into that, and in the other case it is solving the Eigenvalues problem each time. In both cases your solutions are undergoing a switch somewhere in the lambda domain, which corresponds to crossing a branch line. The Presentations package at my web site ($50) has a multifunctions capability that will provide continuous solutions for each of the branches of the solutions. For your example this takes the following form: Needs[Presentations`Master`] eigenvalues = Eigenvalues[mat + [Lambda] pert] {(-(1/6) + I/6) ((5 + 5 I) + 3 [Lambda] - Sqrt[ 514 I - (93 + 93 I) [Lambda] + (18 - 9 I) [Lambda]^2]), (-(1/ 6) + I/6) ((5 + 5 I) + 3 [Lambda] + Sqrt[ 514 I - (93 + 93 I) [Lambda] + (18 - 9 I) [Lambda]^2])} Then we use the Multivalues routine to initialize the evaluation and the CalculateMultivalues routine to calculate successive values. This does not work properly with Table, but works if we map the table functions onto the list of data points. Here we show the value of lambda, the two complex values, and the order of the two values in terms of the two functions above. I used wider steps just to shorten the posted output. You will notice that the order of the solutions switched between lambda = 3.5 and lambda = 4.0 and the two sets of solutions give continuous paths. eigendata = Multivalues[Null, eigenvalues, [Lambda]]; {#, CalculateMultivalues[eigendata][#]} & /@ Range[0, 10, .5] {{0., {{3.67707 + 0. I, -7.01041 + 0. I}, {1, 2}}}, {0.5, {{3.17252 + 0.479244 I, -7.00585 + 0.0207556 I}, {1, 2}}}, {1., {{2.63718 + 0.93368 I, -6.97052 + 0.06632 I}, {1, 2}}}, {1.5, {{2.0619 + 1.36404 I, -6.89524 + 0.135965 I}, {1, 2}}}, {2., {{1.43436 + 1.77216 I, -6.7677 + 0.227837 I}, {1, 2}}}, {2.5, {{0.736607 + 2.16242 I, -6.56994 + 0.337576 I}, {1, 2}}}, {3., {{-0.0602051 + 2.54621 I, -6.27313 + 0.453794 I}, {1, 2}}}, {3.5, {{-1.00604 + 2.95992 I, -5.82729 + 0.54008 I}, {1, 2}}}, {4., {{-2.15722 + 3.54582 I, -5.17612 + 0.454183 I}, {2, 1}}}, {4.5, {{-3.2619 + 4.54089 I, -4.57143 - 0.0408875 I}, {2, 1}}}, {5., {{-4.03354 + 5.62978 I, -4.2998 - 0.629777 I}, {2, 1}}}, {5.5, {{-4.65302 + 6.6284 I, -4.18031 - 1.1284 I}, {2, 1}}}, {6., {{-5.21554 + 7.55475 I, -4.11779 - 1.55475 I}, {2, 1}}}, {6.5, {{-5.75291 + 8.4319 I, -4.08042 - 1.9319 I}, {2, 1}}}, {7., {{-6.27786 + 9.27459 I, -4.05548 - 2.27459 I}, {2, 1}}}, {7.5, {{-6.79632 + 10.0922 I, -4.03701 - 2.59215 I}, {2, 1}}}, {8., {{-7.31138 + 10.8908 I, -4.02196 - 2.89078 I}, {2, 1}}}, {8.5, {{-7.8247 + 11.6747 I, -4.00863 - 3.17474 I}, {2, 1}}}, {9., {{-8.33728 + 12.4471 I, -3.99606 - 3.44707 I}, {2, 1}}}, {9.5, {{-8.84967 + 13.21 I, -3.98366 - 3.71004 I}, {2, 1}}}, {10., {{-9.36223 + 13.9653 I, -3.9711 - 3.96533 I}, {2, 1}}}} The routines work by remembering the last set of multivalues and using a linear programming assignment problem to reassign the multivalues at each step. This has many uses, and one of the most interesting is to drag a locator around a Riemann surface. We can attach an arrow to the locator to represent the value of the complex multifunction, and also display the numerical value. Although we don't directly 'see' the Riemann surface itself, we do see that the function is single valued and continuous as we move the locator around, and as we circle around various branch points we recover all of the values. There are no discontinuous branch line artifacts - just as Riemann promised. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I'm using Mathematica v.6.0.1.0 under Windows. I was using the Eigenvalues function to find the eigenvalues of some complex matrices when I found a very strange behaviour. Cutting the problem down to the bone, consider the 2x2 matrices mat = {{11/3, -(1/3)}, {-(1/3), -7}} pert={{-1 + [ImaginaryI], 1/2 + [ImaginaryI]/2}, {-1, 0}} I'm interested in the trajectories on the complex plane of the eigenvalues of A(lambda)= mat + lambda*pert as a function of the strength lambda. I calculated these trajectories in two ways and I get different results (one of which is the correct one). --> 1st way expr = Eigenvalues[mat + [Lambda] pert]; traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; --> 2nd way traj2 = Table[Eigenvalues[mat + [Lambda] pert], {[Lambda], 0, 10, 0.1}]; The resulting lists traj1 and traj2 are NOT the same! A small notebook showing this problem can be found here: http://www.homepages.ucl.ac.uk/~ucapllo/test.eig.nb Any thoughts? Is this behaviour normal? Lorenzo === Subject: Possible bug in Eigenvalues[ ] ??? I'm using Mathematica v.6.0.1.0 under Windows. I was using the Eigenvalues function to find the eigenvalues of some complex matrices when I found a very strange behaviour. Cutting the problem down to the bone, consider the 2x2 matrices mat = {{11/3, -(1/3)}, {-(1/3), -7}} pert={{-1 + [ImaginaryI], 1/2 + [ImaginaryI]/2}, {-1, 0}} I'm interested in the trajectories on the complex plane of the eigenvalues of A(lambda)= mat + lambda*pert as a function of the strength lambda. I calculated these trajectories in two ways and I get different results (one of which is the correct one). --> 1st way expr = Eigenvalues[mat + [Lambda] pert]; traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; --> 2nd way traj2 = Table[Eigenvalues[mat + [Lambda] pert], {[Lambda], 0, 10, 0.1}]; The resulting lists traj1 and traj2 are NOT the same! A small notebook showing this problem can be found here: http://www.homepages.ucl.ac.uk/~ucapllo/test.eig.nb Any thoughts? Is this behaviour normal? Lorenzo === Subject: Re: Possible bug in Eigenvalues[ ] ??? atleast in Mathematica 7.0.1 mat = {{11/3, -(1/3)}, {-(1/3), -7}} pert = {{-1 + I, 1/2 + I/2}, {-1, 0}}; traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; traj2 = Table[ Eigenvalues[mat + [Lambda] pert], {[Lambda], 0, 10, 0.1}]; Graphics[ {{Line[{Re[#], Im[#]} & /@ #] & /@ Transpose[traj1]}, {RGBColor[1, 0, 0], {Line[{Re[#], Im[#]} & /@ #] & /@ Transpose[traj2]}}} ] the lines match, except the crossover position. Jens > I'm using Mathematica v.6.0.1.0 under Windows. > I was using the Eigenvalues function to find the eigenvalues of some > complex matrices when I found a very strange behaviour. > Cutting the problem down to the bone, consider the 2x2 matrices > mat = {{11/3, -(1/3)}, {-(1/3), -7}} > pert={{-1 + [ImaginaryI], 1/2 + [ImaginaryI]/2}, {-1, 0}} I'm interested in the trajectories on the complex plane of the > eigenvalues of A(lambda)= mat + lambda*pert as a function of the > strength lambda. I calculated these trajectories in two ways and I get > different results (one of which is the correct one). --> 1st way > expr = Eigenvalues[mat + [Lambda] pert]; > traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; --> 2nd way > traj2 = Table[Eigenvalues[mat + [Lambda] pert], {[Lambda], 0, 10, 0.1}]; The resulting lists traj1 and traj2 are NOT the same! > A small notebook showing this problem can be found here: > http://www.homepages.ucl.ac.uk/~ucapllo/test.eig.nb > Any thoughts? Is this behaviour normal? > Lorenzo > === Subject: Struggling to figure out the correct coding for a multiple I am trying to figure out how to write the code to solve the following equation (the capital E will represent the Sigma symbol and the character immediately following will represent the summation subscript...forgive me for not knowing the correct term for this). x = Ei ci + Ei Ej (Bi + Bj)/2 * ci * cj + Ei Ej Ek (Ci Cj Ck)^(1/3) ci * cj * ck I want to have a list of values for the B terms, C terms, and c terms and refer to that list in the coding (please see below). I have not been able to figure out how to correctly make the pair of summations in the second term work (likewise for the triple sum in term 3). I have been playing around with trying to break up the second and third terms and then multiply each section with the corresponding section (again, please see the code below), but there must be a correct way to do this all together...but darned if I have not spend days trying to figure out how). Any and all help is greatly appreciated. Sorry, I know this is probably simple, but I am not a mathematician and pretty new to Mathematica. (* my code so far *) c1 = {c2, c3} B1 = {B2, B3} C1 = {C2, C3} term1 = Sum[i, {i, c1}]; term2 = Sum[((i + j)/2) , {i, B1}, {j, C1}] trem2a = Sum[k l, {k, B1}, {l, c1}] term3 = Sum[(i j k)^(1/3) l m n, {i, C1}, {j, C1}, {k, C1}, {l, c1}, {m, c1}, {n, c1}]; x = term1 + term2 + term3; === Subject: Re: Learning Trace more I am seeking a deeper fuller tutorial on Trace function. Links, notebooks or examples are welcomed. Btw, I have found doing this idiom useful: Trace[(exprToStudy) , TraceOriginal -> True , TraceBackward -> All , TraceForward -> All , TraceAbove -> True] // Flatten // Column Any problems doing so? Enhancements? Andrew Few months ago Leonid Shifrin placed here a message where he offered his textbook on Math programming. You can read it online or download it.There you will find descriptions and examples on Trace along with many other useful things. Hope that helps, Alexei -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: ReplaceAll and BlankNullSequence I keep getting {1} when I try to do a simple replacement with this code: {kevinbacon, iscool} /. {x___, iscool} -> {x} Why doesn't the output show {kevinbacon} ??? I am so confused... === Subject: Re: Replacing expressions with smaller atoms > M = x + (x (x^2 + x + 1))^(1/2); Simplify[M, L == x^2 + x + 1] Sqrt[L*x] + x M /. x^2 + x + 1 -> L Sqrt[L*x] + x > Bob Hanlon > If I define an atom eg L=x^2+x+1, is there a way to rewrite an > expression with these atoms? For example: L=x^2+x+1 > M=x+(x(x^2+x+1))^(1/2) I would like some way to express this as x+(xL)^(1/2). Is this possible? > === Subject: Re: Replacing expressions with smaller atoms Ben, one way would be to use a local rule like L:>(x^2+x+1). Your L then does not have a global value, you use it in your expression until you want to substitute it with x^2+x+1, then you just use (your expression)/.L:>(x^2+x+1) It would be easier to answer your question if you'd provide more information about your problem/goals. Leonid > If I define an atom eg L=x^2+x+1, is there a way to rewrite an > expression with these atoms? For example: L=x^2+x+1 > M=x+(x(x^2+x+1))^(1/2) I would like some way to express this as x+(xL)^(1/2). Is this possible? > === Subject: Replacing expressions with smaller atoms If I define an atom eg L=x^2+x+1, is there a way to rewrite an expression with these atoms? For example: L=x^2+x+1 M=x+(x(x^2+x+1))^(1/2) I would like some way to express this as x+(xL)^(1/2). Is this possible? === Subject: Re: Replacing expressions with smaller The documentation for Simplify states: Assumptions can consist of equations, inequalities, domain specifications such as x[Element]Integers, and logical combinations of these. I used an equation. Bob Hanlon The first of those solutions (with Simplify) looks brilliant, but I don't think I've ever seen that sort of form anywhere in the Mathematica documentation. I've used the second argument(s) to Simplify often, but didn't know it'd work like that. Is there some obvious way to see that substitutions will work that way, or did you figure it out some other way. C.O. > M = x + (x (x^2 + x + 1))^(1/2); Simplify[M, L == x^2 + x + 1] Sqrt[L*x] + x M /. x^2 + x + 1 -> L Sqrt[L*x] + x > Bob Hanlon > If I define an atom eg L=x^2+x+1, is there a way to rewrite an > expression with these atoms? For example: L=x^2+x+1 > M=x+(x(x^2+x+1))^(1/2) I would like some way to express this as x+(xL)^(1/2). Is this possible? -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 === Subject: Re: directionfields from StreamPlot looks What are k1, k2, and h? Once you have fixed values for those, then you have a non-autonomous system of two first order differential equations. So you're asking here about a time-dependent vector field in the (a,b)-plane: F[t_, a_, b_] := {-k1 t^-h a - k2 t^-h b, k1 t^-h a} Actually, this is not defined at time t=0. There are (at least) two methods for visualizing that. Method 1: For particular individual values of t, form an ordinary 2D StreamPlot or VectorPlot. Here, let's take: k1=10;k2=2;h=1; And the time-dependent vector field will be given by: F[t_,a_,b_]={-k1 t^-h a-k2 t^-h b,k1 t^-h a}; Then form a grid of snapshots of the vector field at different times: Grid[Partition[ Table[ StreamPlot[F[t,a,b], {a,-10,10}, {b,-10,10}], {t, 0.1, 24, 2}], 4]] Or, better yet, use Manipulate so that you can dynamically change the time and hence the value of the field: Manipulate[ StreamPlot[F[t, a, b], {a, -10, 10}, {b, -10, 10}], {t, 0.1, 24, 2}] For the values of k1, k2, and h I picked, and on the {a,b} domain and the t range, there does not seem to be much change in the field. Method 2: Represent the time-varying field F as a function on {t,a,b} space. Then you could do something like: G[t_, a_, b_] = Flatten[{1, F[t, a, b]}] VectorPlot3D[G[t, a, b], {t, 0.1, 24}, {a, -10, 10}, {b, -10, 10}] > Hi Murray, > How would you use StreamPlot for the following system? a'[t] == - k1 (t ^-h) a[t] - k2 (t ^-h) b[t], > b'[t] == k1 (t ^-h) a[t] === >> Subject: Re: directionfields from StreamPlot looks different f= > rom solution >> You're not. For the direction >> field of a 1-dimensional ordinary differential equation y' >> == f[t, y], the vector field you want to plot is {1, >> f[t,y]}. So... >> streams = >> StreamPlot[{1, t^2 - y}, {t, -4, 4}, {y, -2, 10}, >> StreamStyle -> Directive[Orange]]; >> sol = Table[NDSolve[{y'[t] == t^2 - y[t], y[0] == >> y0}, y[t], >> {t, -4, 4}], >> {y0, 0, 6, 0.5}]; >> solutionCurves = >> Plot[y[t] /. sol, {t, -4, 4}, >> PlotRange -> {{-4, 4}, {-2, 10}}]; >> Show[{solutionCurves, streams} >> Note that you do not need any parentheses around t^2. And >> in the current version of Mathematica, you no longer need to >> wrap y[t]/.sol with Evaluate -- unless you would like the >> curves automatically to be given different colors. >> sean_incali@yahoo.com > I don't think I'm using StreamPlot properly. >> Consider the following non-autonomous ODE >> y'[t] == (t^2) - y[t] >> Solutions for various ICs can be viewed by the >> following. > sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == >> y0}, y[t], {t, -4, > 4}], {y0, 0, 6, 0.5}]; >> Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange >> -> {{-4, 4}, {-2, > 10}}] >> Shouldn't Vector fields be similar to the solutions >> above? If I plot t > on x-axis vs. t^2-y on y axis... >> VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] >> StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] >> I don't get similar results... >> What is the reason for this? > Sean >> -- 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 >> =0A=0A=0A > -- 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: directionfields from StreamPlot looks question. That system was a simpler version other systems I was working on. What you're doing with Manipulate[] is more or less what I've been doing except I wasn't sure if I was doing it right or not. (And as seen with the previous example I gave, I was getting confused about StreamPlot in general) I was taking the RHS of the two ODEs and using the StreamPlot to get an idea of what the solutions look like. Not much unlike plotting solutions in phase space (is that acceptable? based on your post, it seems like it is...) Except now the trajectories in that space represent the a' and b' instead of a and b as the normal phase portraits should be(?) Is this ok? (Does this give an hint as to the actual solutions of the system?) k1 and k2 are pseudo first order reaction rate constants. It can range from 10^-3 to 10^7 or so. (for diffusion limited process) h range from 0 to 1. The system above is kinda simplified... The system below behaves a bit more interestingly. (Let's say...k1=3, k2=7, t=50 and then...) Manipulate[ StreamPlot[{va - k1 (t^-h) a - k2 ( t^-h ) b, k1 (t^-h ) a - db}, {a, -10, 10}, {b, -10, 10}], {k1, 0.01,10}, {k2, 0.01, 10}, {t, 0.1, 50}, {h, 0, 1}, {va, 0.1, 10}, {db, 0.1, 10}] As you vary va, db, and h, you will see the center of stable attractor shifts. This is entirely a different post, but if I wanted to see a poincare section of that system, will that be doable in mathematica? Seems Like Stephen Lynch's book uses 3 different CAs to generate the figures. And Mathematica version doesn't have the codes for poincare section shown in fig 8.11 b. I'll probably start another post about it. Sometime this week... > What are k1, k2, and h? Once you have fixed values for those, then you have a non-autonomous > system of two first order differential equations. So you're asking her= e > about a time-dependent vector field in the (a,b)-plane: F[t_, a_, b_] := {-k1 t^-h a - k2 t^-h b, k1 t^-h a} Actually, this is not defined at time t=0. There are (at least) two methods for visualizing that. Method 1: For particular individual values of t, form an ordinary 2D > StreamPlot or VectorPlot. Here, let's take: k1=10;k2=2;h=1; And the time-dependent vector field will be given by: F[t_,a_,b_]={-k1 t^-h a-k2 t^-h b,k1 t^-h a}; Then form a grid of snapshots of the vector field at different times: Grid[Partition[ > Table[ > StreamPlot[F[t,a,b], {a,-10,10}, {b,-10,10}], {t, 0.1, 24,= 2}], > 4]] Or, better yet, use Manipulate so that you can dynamically change the > time and hence the value of the field: Manipulate[ > StreamPlot[F[t, a, b], {a, -10, 10}, {b, -10, 10}], > {t, 0.1, 24, 2}] For the values of k1, k2, and h I picked, and on the {a,b} domain and > the t range, there does not seem to be much change in the field. Method 2: Represent the time-varying field F as a function on {t,a,b} > space. Then you could do something like: G[t_, a_, b_] = Flatten[{1, F[t, a, b]}] VectorPlot3D[G[t, a, b], {t, 0.1, 24}, {a, -10, 10}, {b, -10, 10}] > Hi Murray, > How would you use StreamPlot for the following system? > a'[t] == - k1 (t ^-h) a[t] - k2 (t ^-h) b[t], > b'[t] == k1 (t ^-h) a[t] === >> Subject: Re: directionfields from StreamPlot looks different f= > rom solution >> You're not. For the direction >> field of a 1-dimensional ordinary differential equation y' >> == f[t, y], the vector field you want to plot is {1, >> f[t,y]}. So... >> streams = >> StreamPlot[{1, t^2 - y}, {t, -4, 4}, {y, -2, 10}, >> StreamStyle - >> Directive[Orange]]; >> sol = Table[NDSolve[{y'[t] == t^2 - y[t], y[0] == >> y0}, y[t], >> {t, -4, 4}], >> {y0, 0, 6, 0.5}]; >> solutionCurves = >> Plot[y[t] /. sol, {t, -4, 4}, >> PlotRange -> {{-4, 4}, {-2, 10}}]; >> Show[{solutionCurves, streams} >> Note that you do not need any parentheses around t^2. And >> in the current version of Mathematica, you no longer need to >> wrap y[t]/.sol with Evaluate -- unless you would like the >> curves automatically to be given different colors. >> sean_inc...@yahoo.com > I don't think I'm using StreamPlot properly. > Consider the following non-autonomous ODE > y'[t] == (t^2) - y[t] > Solutions for various ICs can be viewed by the >> following. > sol= Table[NDSolve[{y'[t] == (t^2) - y[t], y[0] == >> y0}, y[t], {t, -4, > 4}], {y0, 0, 6, 0.5}]; > Plot[Evaluate[y[t] /. sol], {t, -4, 4}, PlotRange >> -> {{-4, 4}, {-2, > 10}}] > Shouldn't Vector fields be similar to the solutions >> above? If I plot t > on x-axis vs. t^2-y on y axis... > VectorPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] > StreamPlot[{t, (t^2) - y}, {t, -4, 4}, {y, -2, 10}] > I don't get similar results... > What is the reason for this? > Sean >> -- Murray Eisenberg >> mur...@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 >> =0A=0A=0A -- > Murray Eisenberg mur...@math.umas= s.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: Polygon Union http://www.cs.man.ac.uk/~toby/alan/software/ has C code to perform a set of polygon operations, among which the polygon union. > I am looking for a Mathematica function which generates the union of > two (not necessarily convex) polygons. I found a package on the web > (the Imtek library, I believe) which includes a convex polygon > intersection function, but not a polygon *union* function. Does > anyone know if such a function is available or, if not, can anyone > suggest an algorithm to implement in Mathematica? > David Skulsky === Subject: Re: Polygon Union I've also been thinking about this problem. I use the continental maps that are available through CountryData[], and I'd rather have a continent without an internal political boundaries shown. I've been surprised that this possibility is not a built-in option. > I am looking for a Mathematica function which generates the union of > two (not necessarily convex) polygons. I found a package on the web > (the Imtek library, I believe) which includes a convex polygon > intersection function, but not a polygon *union* function. Does > anyone know if such a function is available or, if not, can anyone > suggest an algorithm to implement in Mathematica? > David Skulsky === Subject: Re: what is my error? eqns = {mr + mp == 13, fr + fp == 19, mr + fr == 15, mp + fp == 17}NSolve[eqns, {mr, mp, fr, fp}] gives {{mr->-4.+1. fp,mp->17.-1. fp,fr->19.-1. fp}} The solution is {mr->8, mp->5, fr->7, fp->12} if mr,mp,fr,fp are greater than zero -- your error is that you should think on mathematical nature of the problem before starting to write Mathematica code. In the case of a linear system like yours algebra teaches us to first check the determinant of the matrix in the lhp: In[63]:= matrix = {{1, 1, 0, 0}, {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1}}; matrix // MatrixForm Det[matrix] Out[64]//MatrixForm= !(* TagBox[ RowBox[{(, [NoBreak], GridBox[{ {1, 1, 0, 0}, {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 0, 1} }, GridBoxAlignment->{ Columns -> {{Left}}, ColumnsIndexed -> {}, Rows -> {{Baseline}}, RowsIndexed -> {}}, GridBoxSpacings->{Columns -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, ColumnsIndexed -> {}, Rows -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, RowsIndexed -> {}}], [NoBreak], )}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]) Out[65]= 0 So, the determinant is zero. Then you may have either no solutions at all, or may have solutions, if the rhp is degenerated. In the latter case it is also easy to get correct solutions, but not as straightforward as in the non-degenerated case. I propose that you first look into any popular algebra textbook. Have success, Alexei -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: setting selection via char positions and setting its background Ok, I have figured out this much: Button[Hilite, Higlite[] := ( FrontEndExecute[FrontEndToken[SelectionSetFind]]; FrontEndExecute[{FrontEnd`NotebookFind[FrontEnd`InputNotebook[], Automatic, Next]}]; FrontEndExecute[ {FrontEndToken[FrontEnd`InputNotebook[], Background, Yellow]}] ); Higlite[]] What I want next is to apply this highlighting to all cells without having to click the button repeatedly. Btw, anyone has access to the code of the find/replace dialog? Perhaps it might be helpful to me. === Subject: Re: setting selection via char positions and setting its background Another version: Button[ StyleBox[=E2=97=8A,nFontColor->RGBColor[1, 1, 0]] , hit = Background /. Options[NotebookSelection[], Background]; SetOptions[NotebookSelection[], Background -> pt]] As for the find/replace, I been told its all in C code. So how does one select text going cell to cell and within the cell via code?? === Subject: Help with optimization problem in Mathematica multidimensional, multicriteria with more than one decision variables ?? Can you give me some references about the topic and if you have some examples? === Subject: Re: Repositioning AxesLabel position Use a Frame f[x_] := x^2; Plot[f[x], {x, 0, 1}, Axes -> False, Frame -> {True, True, False, False}, FrameLabel -> {x-label, y-label}] Plot[f[x], {x, 0, 1}, Axes -> False, Frame -> {True, False, False, True}, FrameTicks -> All, FrameLabel -> {x-label, None, None, y-label}] Plot[f[x], {x, 0, 1}, Axes -> False, Frame -> {False, False, True, True}, FrameTicks -> All, FrameLabel -> {None, None, x-label, y-label}] Bob Hanlon I have been trying to create a visually appealing data graphing template, something that might come close to the looks of an Origin or SigmaPlot graph. It seems that one of the weakness is the inability to reposition and rotate the axis labels. They are always at the end of each x and y axis and horizontal. Does anyone know of a method to transpose and rotate the text? Charles Koehler ______________________________________________________________________ This e-mail has been scanned by Verizon Managed Email Content Service, using Skeptic(tm) technology powered by MessageLabs. For more information on Verizon Managed Email Content Service, visit: http://www.verizonbusiness.com/us/security/email/ CONFIDENTIALITY NOTICE: The information in this electronic mail is intended only for the named recipient. It is confidential and may be privileged. If you are not the intended recipient, please delete this electronic mail and all attachments immediately. Any unauthorized copying, distribution, disclosure or other action based upon these electronically transmitted materials is prohibited. ______________________________________________________________________ === Subject: Re: Possible bug in Eigenvalues[ ] ??? mat = {{11/3, -(1/3)}, {-(1/3), -7}}; pert = {{-1 + I, 1/2 + I/2}, {-1, 0}}; expr = Eigenvalues[mat + lambda * pert]; traj1 = Table[expr, {lambda, 0, 10, 0.1}]; plt11 = ParametricPlot[{Re[expr], Im[expr]}, {lambda, 0, 10}, AspectRatio -> 1/GoldenRatio] plt12 = ListPlot[{Re[#], Im[#]} & /@ traj1] traj2 = Table[ Eigenvalues[mat + lambda * pert], {lambda, 0, 10, 0.1}]; traj1 == traj2 False traj3 = Table[ Evaluate[Eigenvalues[mat + lambda * pert]], {lambda, 0, 10, 0.1}]; traj1 == traj3 True Attributes[Table] {HoldAll,Protected} Bob Hanlon I'm using Mathematica v.6.0.1.0 under Windows. I was using the Eigenvalues function to find the eigenvalues of some complex matrices when I found a very strange behaviour. Cutting the problem down to the bone, consider the 2x2 matrices mat = {{11/3, -(1/3)}, {-(1/3), -7}} pert={{-1 + [ImaginaryI], 1/2 + [ImaginaryI]/2}, {-1, 0}} I'm interested in the trajectories on the complex plane of the eigenvalues of A(lambda)= mat + lambda*pert as a function of the strength lambda. I calculated these trajectories in two ways and I get different results (one of which is the correct one). --> 1st way expr = Eigenvalues[mat + [Lambda] pert]; traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; --> 2nd way traj2 = Table[Eigenvalues[mat + [Lambda] pert], {[Lambda], 0, 10, 0.1}]; The resulting lists traj1 and traj2 are NOT the same! A small notebook showing this problem can be found here: http://www.homepages.ucl.ac.uk/~ucapllo/test.eig.nb Any thoughts? Is this behaviour normal? Lorenzo === Subject: Re: RandomReal gets stuck >Apparently there is more to it than meets the eye, but section 2.5.5 >in the (old) mathematica book discusses the use of indexed objects. In the fourth edition of the Mathematica Book, it is section 2.4.5 titled Making Definitions for Indexed Objects *briefly* discusses using the syntax y[[0] etc as a subscripted variable. Basically, this section shows an example where it is more convenient to use this syntax over a list and has the following statement: You can think of the expression a[i] as being like an indexed or subscripted variable. None of what I've said really contradicts this. What I've done is simply point out being like is not the same as being. That is, there are similarities between a subscripted variable and the syntax a[i] but there is not an identity relationship. === Subject: performance // Re: Why is recursion so slow in On the general topic of performance, I'd be interested to know if anyone can comment on the following. In an effort to keep my codes as reasonable as possible, I use a lot of sentence variables. What I mean is that I'll write: myfunction[further explanation][var1_,var2_]:= .... I add that extra string in naming the function. This helps me immensely to remember what I'm doing and make my code accessible to me again in six months. I have often wondered, however, if I slow down Mathematica by using these long function names. Does anyone know? [For most of my applications, the limiting aspect on overall implementation time is my slow human CPU, so I have ample computer cycles and memory. However, there are a few applications that cause me to leave my computer running overnight, so I'm wondering somewhat about the performance of the code and if these long variable names are having an effect.] > Daniel, Let me tell you straight away that you won't get efficiency of OCaml > in Mathematica, > the latter really being a CAS, research and prototyping tool, but not > an efficiency-oriented production language. Regarding your question, the short answer is that recursion is slow > because lists are implemented as arrays in Mathematica. When you > pattern-match, the whole array is copied every time. This > explains both the slowdown - the time becomes effectively quadratic > (assuming that the complexity of array copying is linear), and the > (stack) memory use explosion. So, IMO, indeed Mathematica is unfortunately less suited for the > straightforward recursive solutions like yours. The closest thing you > can probably do to stay in the recursive mindset is to use linked > lists. Here is an implementation that does just that: Clear[myselectAux]; > myselectAux[{}, predicate_] = {}; > myselectAux[{head_, tail_List}, predicate_] := > If[predicate[head], {head, myselectAux[tail, predicate]}, > myselectAux[tail, predicate]]; Clear[toLinkedList]; > toLinkedList[x_List] := Fold[{#2, #1} &, {}, Reverse[x]]; Clear[mySelectLL]; > mySelectLL[x_List, predicate_] := > Flatten@myselectAux[toLinkedList[x], predicate]; You can find more info on linked lists in Mathematica in the book of > David Wagner, > in the notes by Daniel Lichtblau (see Wolfram library archive, should > be named > something like efficient data structures in Mathematica), and also > in my book > (http://www.mathprogramming-intro.org/book/node525.html). For example: In[1] = test = RandomInteger[{1, 10}, 10] Out[1] = {6, 10, 1, 9, 4, 6, 1, 9, 10, 4} In[2] = toLinkedList@test Out[2] = {6, {10, {1, {9, {4, {6, {1, {9, {10, {4, {}}}}}}}}}}} In[3] = mySelectLL[test, # > 5 &] Out[3] = {6, 10, 9, 6, 9, 10} Now, the benchmarks: I use yours, on my 5 years old 1.8 GHz P IV, and > I get: In[4] = > data = Table[Random[], {20000}]; > Block[{$RecursionLimit = Infinity}, > Timing[data2 = mySelectLL[data, # > 0.5 &];]] Out[4] = {0.2, Null} Now, this is not the most efficient implementation. David Wagner in > his excellent book > discussed in great detail this sort of problems with the mergesort > algorithm as an archetypal example. I believe that you can squeeze > another factor of 2-5 by further optimizing the implementation > (keeping it recursive) with several performance-tuning techniques > available in Mathematica. By the way, I tested the above code with larger lists and it seems to > continue be linear complexity up to 100 000 elements, but the kernel > (v.6) just crashes after that - this > behavior I can not explain, since the memory usage seems quite decent. So, to summarize my opinion: if you prefer to stay in a recursive > mode, you *can* use recursion in Mathematica rather efficiently by > switching to linked lists (and this will require some extra work but > not so much of it). This may be enough to move you from the domain of > toy problems to that of reasonably complex prototypes. But don't > expect efficiency of the highly optimized production language with a > native-code compiler (or even byte code interpreter) from a rewrite > system such as Mathematica. Also, I'd say that other programming > styles such as structural operations (APL - like) will bring you > closer to efficiency of Ocaml etc. since then you can leverage the > highly-optimized vectorized operations built in Mathematica. >> This post is about functional programming in Mathematica versus other >> functional languages such as OCaml, SML or Haskell. At least a naive >> use of functional constructs in Mathematica is horrendously slow. Am I >> doing something wrong? Or isn't Mathematica really suitable for >> functional programming beyond toy programs? Couldn't the Wolfram team >> make a more efficient implementation for recursion, as other >> functional languages has done? (Instead of the naive C-like behavior >> for recursively defined functions.) >> as below >> myselect[{}, predicate_] = {} >> myselect[{head_, tail___}, predicate_] := If[predicate[head], >> Join[{head}, myselect[{tail}, predicate]], >> myselect[{tail}, predicate] >> ] >> Then I tried this function on a 20.000 element vector with machine >> size floats: >> data = Table[Random[], {20000}]; >> $RecursionLimit = 100000; >> Timing[data2 = myselect[data, # > 0.5 &];] >> The result is {7.05644, Null}, and hundreds of MB of system memory are >> 20.000 floats! It's just a megabyte! >> The following OCaml program executes in apparently no-time. It is not >> compiled and does the same thing as the above Mathematica code. After >> increasing the list by a factor of ten to 200.000 elements, it still >> executes in a blink. (But with 2.000.000 elements my OCaml interpreter >> says Stack overflow.) >> let rec randlist n = if n=0 then [] else Random.float(1.0) :: randlis= > t >> (n-1);; >> let rec myselect = function >> [],predicate -> [] >> | x::xs,predicate -> if predicate(x) then x::myselect(xs,predicate= > ) >> else myselect(xs,predicate);; >> let mypred x = x>0.5;; >> let l=randlist(20000);; >> let l2=myselect(l,mypred);; (* lightning-fast compared to Mathematic= > a >> *) === Subject: Re: Struggling to figure out the correct coding for a multiple > I am trying to figure out how to write the code to solve the > following equation (the capital E will represent the Sigma > symbol and the character immediately following will represent > the summation subscript...forgive me for not knowing the correct > term for this). x = Ei ci + Ei Ej (Bi + Bj)/2 * ci * cj + > Ei Ej Ek (Ci Cj Ck)^(1/3) ci * cj * ck I want to have a list of values for the B terms, C terms, and > c terms and refer to that list in the coding (please see below). Let c = {c1, c2, ...}. Then c1 + c2 + ... = Total[c]. Let B = {B1, B2, ...}. Then second term factors into the product of two sums, the first of which is a sum of products: B.c * Total[c]. The single-letter symbols C, D, E, I, K, N, O are all Protected, so let Cx = {C1, C2, ...}. Then the third term factors into the cube of a sum of products: (c.Cx^(1/3))^3 Finally, x = Total[c]*(1 + B.c) + (c.Cx^(1/3))^3 I have not been able to figure out how to correctly make the pair > of summations in the second term work (likewise for the triple > sum in term 3). I have been playing around with trying to break > up the second and third terms and then multiply each section with > the corresponding section (again, please see the code below), but > there must be a correct way to do this all together...but darned > if I have not spend days trying to figure out how). Any and all help is greatly appreciated. Sorry, I know this is > probably simple, but I am not a mathematician and pretty new to > Mathematica. (* my code so far *) c1 = {c2, c3} > B1 = {B2, B3} > C1 = {C2, C3} term1 = Sum[i, {i, c1}]; term2 = Sum[((i + j)/2) , {i, B1}, {j, C1}] > trem2a = Sum[k l, {k, B1}, {l, c1}] > term3 = Sum[(i j k)^(1/3) l m n, {i, C1}, {j, C1}, {k, C1}, > {l, c1}, {m, c1}, {n, c1}]; > x = term1 + term2 + term3; === Subject: Re: Rasterize off by one pixel For n<15 this has still problems. See this plot: DiscretePlot[ img = Rasterize[ Graphics[Rectangle[{0, 0}, {1, 1}], PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> None, AspectRatio -> Automatic, ImagePadding -> None], Image, ImageSize -> {n, n}] // ImageDimensions, {n, 100}] On Jun 6, 9:48 am, Jens-Peer Kuska With[{n = 100}, > img = Rasterize[ > Graphics[Rectangle[{0, 0}, {1, 1}], PlotRange -> {{0, 2}, {0, 2}}= , > PlotRangePadding -> None, AspectRatio -> Automatic, > ImagePadding -> None], Image, ImageSize -> {n, n}] > ] > I'm trying to make a 100x100 pixel image using Rasterize, as follows, > where n=100 Rasterize[ > Graphics[Rectangle[{0,0}, {1,1}], > PlotRange->{{0,2},{0,2}}], > Image, > RasterSize->{n,n} > ] when I check the resulting image using ImageDimensions, the size is > 100x101. If I say size {n,n/2}, then the image is 100x51 instead of > 100x50. > === Subject: Re: mathematica tutor for NYC high school student > Hello We are wondering if you can help us with this. We live in Manhattan (NYC) and are seriously considering withdrawing > our 15 yr old son (presently in 9th grade) from the school system and > give him homeschooling that is creative, adventurous and > non-competing. 2 out of three is good. He will need some competitiveness, it will help drive him. The more you son learns, the more confidence he will attain. Home schooling is good for some things, but terrible for others. Try instead to get your child into a better school district. If money is tight or that option is not available, the supplement his education yourself. Go to a nearby university and ask a professor there if he may audit a course. Most professors will be glad to accept him if he will not cause trouble. > Naturally, for Math we are thinking of Mathematica so all his high > school > math curriculum can be done visually but with mathematical rigor. Depending on the level he is at, shelve Mathematica for a while. Let him grind the math by hand. Some explorations are augmented by mathmatica, but only in later stages after one has learned the fundamentals. You don't want him to be someone who has to go to the computer when it comes time to integrate and simplify an expression. > Question: Do you know some group/program/person in NYC so we can find > a > Mathematica tutor for our son so he gets excited about the > inherent beauty of Math and covers the basic knowledge he needs ? Your son needs to attain the exitement of math through his expereince with people that he innitiates. Don't rely on others to get him exited. The best thing you can do is expose him to math indirectly. Talk with him about your experiences with math. Get lots of good PBS and discovery channel programs on math and science. > He needs to cover Geometry, Trig, Algebra and Calculus at the high > school level (grades 9-12). It is a long shot, but I am placed in Architecture and need to look > outside my field for guidance. So the web becomes my first stop. At > some point I will walk over to Courant Inst and see if they can help. > Prof. H. Lalvani, PhD If you are a prof at a university or college, you can have your son audit courses. === Subject: Re: Mathematica bug?? >{{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, >0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse >gives >{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ >r}} >with no warnings. This is a *diagonal* matrix that should be >trivially invertible. >Does anyone know why Inverse has catastrophically failed here? Here, I get: In[4]:= {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse Out[4]= {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/r}} In[5]:= $Version Out[5]= 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) Perhaps there is a version or platform issue. === Subject: Locator as a button is there any way to use a button (e.g. RadioButton, Checkbox, Button, etc.) as the appearance of a locator (as Locator, or in LocatorPane), to preserve both the movability and the clickability of the object? I've tried several methods with no success: either I can move the locator, but the button won't respond to my clicks, or vice versa. Istvan === Subject: Re: directionfields from StreamPlot looks At the end of your message (below), you ask about visualizing Poincare maps. I recommend you look at Gianluca Gorni's notebook PoincareMaps.nb (which includes the code for a corresponding package). There's a version for old versions of Mathematica at Gorni's web site: http://sole.dimi.uniud.it/~gianluca.gorni/ I've done much of the revision of that notebook so that it will work with Mathematica 7, but there's still some work to do about which I've written directly to Prof. Gorni. If you're interested, I can send you a copy of what I have so far. However, to run Gorni's functions, you'll also need a copy of David Park's non-free but marvelous and useful Presentations package, which handles much of the underlying graphics. You can obtain the package from Park's site: http://home.comcast.net/~djmpark/DrawGraphicsPage.html The posted copy of Gorni's package uses Park's older DrawGraphics package, which like Presentations is not free and is available from the same site of David's. k1 and k2 are pseudo first order reaction rate constants. It can range > from 10^-3 to 10^7 or so. (for diffusion limited process) h range > from 0 to 1. The [original] system ...is kinda simplified... The system below behaves a bit > more interestingly. (Let's say...k1=3, k2=7, t=50 and then...) Manipulate[ > StreamPlot[{va - k1 (t^-h) a - k2 ( t^-h ) b, k1 (t^-h ) a - db}, > {a, -10, 10}, {b, -10, 10}], {k1, 0.01,10}, {k2, 0.01, 10}, {t, 0.1, > 50}, {h, 0, 1}, {va, 0.1, 10}, {db, 0.1, 10}] > As you vary va, db, and h, you will see the center of stable attractor > shifts. This is entirely a different post, but if I wanted to see a poincare > section of that system, will that be doable in mathematica? Seems > Like Stephen Lynch's book uses 3 different CAs to generate the > figures. And Mathematica version doesn't have the codes for poincare > section shown in fig 8.11 b.... -- 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: Setting GridLines style for major and minor grid lines To draw only the major y-grid lines this simple option works great: LogLogPlot[x, {x, 1, 10^6}, GridLines -> {None, 10^Range[10]}] Indeed, I don't think Mathematica does have a major/minor grid specification, but it's really, really easy to generate yourself (plus this mechanism gives you much more flexibility): LogLogPlot[x, {x, 1, 10^6}, GridLines -> {None, Flatten[Table[{i 10^j, If[i == 1, GrayLevel[0], GrayLevel[0.9]]}, {j, 0, 6}, {i, 9}], 1]}] > I am drawing a log plot. Because it spans many decades, the grid lines > look horrible in the default setting (they completely overwhelm the > plot). What I want is to only draw the grid lines for the major grid > (for the y axis). I was looking at a way to specify the style of the > gridlines separately for major and minor grid WITHOUT having to > generate all the gridline locations myself. Unfortunately is seems > that in Mathematica 7 GridLinesStyle->{xstyle,ystyle} is the only availab= le > option. It would be SOOOO MUCH BETTER if Mathematica would have: GridLinesStyle->{{xMajorStyle,xMinorStyle},{yMajorStyle,yMinorStyle}} Any other easy way to achieve this? I find that Mathematica still has many irritating limitations with plots. > This is only one I have run into. TIA === Subject: Re: Setting GridLines style for major and minor grid lines I don't know if having two different styles for major and minor grid lines is a good idea because it will tend to confuse the viewer. Better is to have fewer grid lines and to make them as light as possible, what Edward Tufte calls the minimum effective difference. Here is a LogLog example from GridLines help where, just for illustration, I use a full set of grid lines vertically, but a restricted set horizontally. LogLogPlot[1/x, {x, 1, 10000}, Frame -> True, GridLines -> {Table[10^n, {n, 0, 4}], Automatic}, GridLinesStyle -> GrayLevel[.85]] The Presentations package has a CustomGridLines (and also a CustomTicks) command and a different paradigm that makes it easier to construct custom graphics with elements from different plot types. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I am drawing a log plot. Because it spans many decades, the grid lines look horrible in the default setting (they completely overwhelm the plot). What I want is to only draw the grid lines for the major grid (for the y axis). I was looking at a way to specify the style of the gridlines separately for major and minor grid WITHOUT having to generate all the gridline locations myself. Unfortunately is seems that in Mathematica 7 GridLinesStyle->{xstyle,ystyle} is the only available option. It would be SOOOO MUCH BETTER if Mathematica would have: GridLinesStyle->{{xMajorStyle,xMinorStyle},{yMajorStyle,yMinorStyle}} Any other easy way to achieve this? I find that Mathematica still has many irritating limitations with plots. This is only one I have run into. TIA === Subject: Mathematica Special Interest Group (Washington DC Area) Mathematica SIG (http://web.mac.com/hrbishop.pmsi/DCSIG.m/DCSIG.html) MEETING Note the location!!! 12 June 2009, 8:00-9:30am Northern Virginia Community College (Alexandria Campus) Room AA377 (Bisdorf Building) 3001 N. Beauregard St Alexandria VA 22311 Agenda 1. Prepared Talks Google Maps, by Harry Bishop - Abstract. Harry will discuss his recent work involving Google Maps. - Aerostat Dynamics Modeling Using Mathematica, by Pramud Rawat Abstract. An aerostat dynamics model uses Mathematica to derive the differential equation set for generalized coordinates using Lagrangian theory. Thereafter, Matlab-Simulink simulates the nonlinear behavior of the tethered balloon in a gust. Simulation outputs are pumped to Mathematica for animation. This analysis was recently published in an AIAA paper. 2. Mathematica Gems and Discoveries - Sharing of Mathematica programming oddities - Applications of Mathematica to some areas of science - Something recently read and worth sharing 3. Mathematica Questions, Possible Approaches and Discussion 4. New Business Select next meeting presentation, time and place Directions to the NVCC-Alexandria campus: Beauregard (light), Echols (light), Fillmore, Dover, turn right on Dawes (light), and then pass the Coca Cola bottling plant. Park curbside along Dawes Ave for free (there should be few cars present, but make sure to park on the garage-side of the road). However, if there's no space, then park in the metered lot located past the flashing traffic light. Enter the outside doors of the Bisdorf Building (behind flagpoles): - For breakfast (7:30-8:00am), go downstairs to the cafeteria - To go to room AA377 (from where you first entered the building, which is on Level 2), climb one flight of stairs to the third floor, turn left, walk down the long hall to the room. Please arrive by 7:30am if you wish to join us for breakfast. The meeting starts at 8:00. === Subject: Re: Polygon Union Hmmm... I was hoping to avoid using a function external to Mathematica (I've never used MathLink), but this may be inevitable. David Skulsky On Jun 6, 12:49 am, Sjoerd C. de Vries set of polygon operations, among which the polygon union. I am looking for a Mathematica function which generates the union of > two (not necessarily convex) polygons. I found a package on the web > (the Imtek library, I believe) which includes a convex polygon > intersection function, but not a polygon *union* function. Does > anyone know if such a function is available or, if not, can anyone > suggest an algorithm to implement in Mathematica? > David Skulsky === Subject: Problem with GraphicsColumn I encounter a problem below: My aim is to obtain a graphicscolumn for my paper to be submited: GraphicsColumn[{Plot[Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}, Alignment -> Right, ImageSize -> 500, Spacings -> Scaled[-.1]] However I find the right part of the outcome contains blank space. If I add two items: GraphicsColumn[{Plot[Sin@x, {x, 0, 10}, Frame -> True], Plot[Cos@x, {x, 0, 10}, Frame -> True]}, Alignment -> Right, ImageSize -> 500, Spacings -> Scaled[-.1], Frame -> All, FrameStyle -> Opacity[0]] it works. However when I Export[FIG1.EPS,%,EPS] , it inevitably contains the Frame. === Subject: Coding for Mathematica Im a first time user of Mathematica. So im trying to put in a command related to Newton's Method. I would just like to know if once im done typing this command in am i suppose to see the results immediately or do i have go to something in the program to see the results of my command. Here is the Code please can anyone tell me what im doing wrong i will be really grateful: In[1] :=(*your name,06/06/09*) In[2] :=(*Newton's Method*) In[3] := f[x_] := x^2 - 2 In[4] := x[1] = 1.0 In[5] := For[n = 1, n < 10, n++, {x[n + 1] = x[n] - f[x[n]]/f'[x[n]]; Print[n + 1, , N[x[n + 1], 10]];}] In[6] := Plot[f[x], {x, 0, 2}] === Subject: Re: Why is recursion so slow in Mathematica? As Szabolcs demonstrated in this case, using the right algorithms and structures makes Mathematica far more competitive with compiled languages like OCaml. But the difference in speed between languages is also overwhelmed by time itself. IBM Assembler was my first favorite language (1971 or so), and I hauled around card decks a tenth the size of my classmates; I was good at it. But there's no way I'd go back to that, just to get more speed in trivial calculations. Mathematica today is a hundred times faster (or more) than Assembler in 1971, and it does a thousand times more FOR me. If I had spent 40 years writing Assembler code, I'd have very little to show for it. I hope that doesn't become anyone's experience with OCaml. Bobby >> This post is about functional programming in Mathematica versus other >> functional languages such as OCaml, SML or Haskell. At least a naive >> use of functional constructs in Mathematica is horrendously slow. Am I >> doing something wrong? Or isn't Mathematica really suitable for >> functional programming beyond toy programs? Couldn't the Wolfram team >> make a more efficient implementation for recursion, as other >> functional languages has done? (Instead of the naive C-like behavior >> for recursively defined functions.) >> as below >> myselect[{}, predicate_] = {} >> myselect[{head_, tail___}, predicate_] := If[predicate[head], >> Join[{head}, myselect[{tail}, predicate]], >> myselect[{tail}, predicate] >> ] >> Then I tried this function on a 20.000 element vector with machine >> size floats: >> data = Table[Random[], {20000}]; >> $RecursionLimit = 100000; >> Timing[data2 = myselect[data, # > 0.5 &];] >> The result is {7.05644, Null}, and hundreds of MB of system memory are >> 20.000 floats! It's just a megabyte! >> The following OCaml program executes in apparently no-time. It is not >> compiled and does the same thing as the above Mathematica code. After >> increasing the list by a factor of ten to 200.000 elements, it still >> executes in a blink. (But with 2.000.000 elements my OCaml interpreter >> says Stack overflow.) >> let rec randlist n = if n=0 then [] else Random.float(1.0) :: randlist >> (n-1);; >> let rec myselect = function >> [],predicate -> [] >> | x::xs,predicate -> if predicate(x) then x::myselect(xs,predicate) >> else myselect(xs,predicate);; >> let mypred x = x>0.5;; >> let l=randlist(20000);; >> let l2=myselect(l,mypred);; (* lightning-fast compared to Mathematica >> *) So you discovered that appending to arrays is slow while appending to > linked lists is fast :) Actually you are not comparing the exact same algorithms. The data > structure you used in those languages was a linked list. Removing or > appending elements takes a constant time for linked lists. > Mathematica's List is a vector-type data structure, so > removing/appending elements takes a time proportional to the vector's > length. One data structure is not better than the other, of course, they're just > useful for different purposes. For example, a linked list is unsuitable > for applications where the elements need to be accessed randomly instead > of sequentially. Random access is often needed for numerical > computations/simulations. For a fair comparison, use a linked list in Mathematica too. This could > look like {1,{2,{3,{}}}} myselect[{}, test_] = {}; > myselect[{head_, tail_}, test_] := > If[test[head], {head, myselect[tail, test]}, myselect[tail, test]] toLinkedList[list_List] := Fold[{#2, #1} &, {}, list] data = toLinkedList@Table[Random[], {20000}]; Block[{$RecursionLimit = [Infinity]}, > Timing[myselect[data, # > 0.5 &];]] This runs in 0.2 sec on my (not very fast) system. And you can check that the function works correctly: Block[{$RecursionLimit = [Infinity]}, > Select[Flatten[data], # > 0.5 &]] About the thing that you call naive C-like behavior: you probably mean > that Mathematica doesn't automatically perform the tail-call > optimization. That is correct, you need to transform your recursions > explicitly. Here's an example: myselect2[dest_, {head_, tail_}, test_] := > If[test[head], > myselect2[{head, dest}, tail, test], > myselect2[dest, tail, test]] myselect2[dest_, {}, test_] := dest Note that it is $IterationLimit that we need to increase now and this > version doesn't fill up the evaluation stack. Also note that this produces the result in the reverse order: Block[{$IterationLimit = [Infinity]}, > Select[Flatten[data], # > 0.5 &]] We could produce the result in the same order, but reverse linking (like > {{{{},1},2},3}). I couldn't do any better than this using a singly-linked list. It looks > like OCaml (which I don't know BTW) uses a singly linked list too, and > can't do the tail-call optimization, so its stack gets filled up. One more thing: even when using the same data structure and same > algorithm, it is of course expected that a very high level interpreted > language like Mathematica is not going to perform nearly as well as a > low level compiled language like OCaml. In high level languages the > usual solution to this performance problem is built-in functions: don't > implement Select in Mathematica itself. Use the built-in one, which is > written in C and much faster than a Mathematica implementation could > ever be. Hope this helps, > Szabolcs > -- DrMajorBob@bigfoot.com === Subject: Re: Why is recursion so slow in Mathematica? > This post is about functional programming in Mathematica versus other > functional languages such as OCaml, SML or Haskell. At least a naive > use of functional constructs in Mathematica is horrendously slow. Am I > doing something wrong? Or isn't Mathematica really suitable for > functional programming beyond toy programs? Couldn't the Wolfram team > make a more efficient implementation for recursion, as other > functional languages has done? (Instead of the naive C-like behavior > for recursively defined functions.) as below myselect[{}, predicate_] = {} > myselect[{head_, tail___}, predicate_] := If[predicate[head], > Join[{head}, myselect[{tail}, predicate]], > myselect[{tail}, predicate] > ] Then I tried this function on a 20.000 element vector with machine > size floats: data = Table[Random[], {20000}]; > $RecursionLimit = 100000; > Timing[data2 = myselect[data, # > 0.5 &];] The result is {7.05644, Null}, and hundreds of MB of system memory are > 20.000 floats! It's just a megabyte! The following OCaml program executes in apparently no-time. It is not > compiled and does the same thing as the above Mathematica code. After > increasing the list by a factor of ten to 200.000 elements, it still > executes in a blink. (But with 2.000.000 elements my OCaml interpreter > says Stack overflow.) let rec randlist n = if n=0 then [] else Random.float(1.0) :: randlist > (n-1);; let rec myselect = function > [],predicate -> [] > | x::xs,predicate -> if predicate(x) then x::myselect(xs,predicate) > else myselect(xs,predicate);; let mypred x = x>0.5;; let l=randlist(20000);; > let l2=myselect(l,mypred);; (* lightning-fast compared to Mathematica > *) > You can't really take a programming style that is optimised for one language and expect it to be optimal in another! Clearly, OCaml does tail recursion optimisation, and represents lists in memory, in a way that makes it easy to take the tail of a long list - perhaps lists in OCaml are represented as linked lists. However, representing a list as a linked list, has a downside. Extracting the N'th element of a long list and large N, is an expensive operation. Since lists in Mathematica are often used as vectors, a representation using linked lists would have been a BAD choice overall. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Why is recursion so slow in Mathematica? Leonid, Programming in Mathematica) is out of print, too bad! But your book seems to be interesting as well. I will definately read it the whole thing; the section on why you think Mathematica is so good was interesting. I guess I need to learn about reap/sow as well... I do understand that Mathematica is what it is and is not supposed to compete with low-level languages on speed. All the best, Daniel > Daniel, Let me tell you straight away that you won't get efficiency of OCaml > in Mathematica, > the latter really being a CAS, research and prototyping tool, but not > an efficiency-oriented production language. Regarding your question, the short answer is that recursion is slow > because lists are implemented as arrays in Mathematica. When you > pattern-match, the whole array is copied every time. This > explains both the slowdown - the time becomes effectively quadratic > (assuming that the complexity of array copying is linear), and the > (stack) memory use explosion. So, IMO, indeed Mathematica is unfortunately less suited for the > straightforward recursive solutions like yours. The closest thing you > can probably do to stay in the recursive mindset is to use linked > lists. Here is an implementation that does just that: Clear[myselectAux]; > myselectAux[{}, predicate_] = {}; > myselectAux[{head_, tail_List}, predicate_] := > If[predicate[head], {head, myselectAux[tail, predicate]}, > myselectAux[tail, predicate]]; Clear[toLinkedList]; > toLinkedList[x_List] := Fold[{#2, #1} &, {}, Reverse[x]]; Clear[mySelectLL]; > mySelectLL[x_List, predicate_] := > Flatten@myselectAux[toLinkedList[x], predicate]; You can find more info on linked lists in Mathematica in the book of > David Wagner, > in the notes by Daniel Lichtblau (see Wolfram library archive, should > be named > something like efficient data structures in Mathematica), and also > in my book > (http://www.mathprogramming-intro.org/book/node525.html). For example: In[1] = test = RandomInteger[{1, 10}, 10] Out[1] = {6, 10, 1, 9, 4, 6, 1, 9, 10, 4} In[2] = toLinkedList@test Out[2] = {6, {10, {1, {9, {4, {6, {1, {9, {10, {4, {}}}}}}}}}}} In[3] = mySelectLL[test, # > 5 &] Out[3] = {6, 10, 9, 6, 9, 10} Now, the benchmarks: I use yours, on my 5 years old 1.8 GHz P IV, and > I get: In[4] = > data = Table[Random[], {20000}]; > Block[{$RecursionLimit = Infinity}, > Timing[data2 = mySelectLL[data, # > 0.5 &];]] Out[4] = {0.2, Null} Now, this is not the most efficient implementation. David Wagner in > his excellent book > discussed in great detail this sort of problems with the mergesort > algorithm as an archetypal example. I believe that you can squeeze > another factor of 2-5 by further optimizing the implementation > (keeping it recursive) with several performance-tuning techniques > available in Mathematica. By the way, I tested the above code with larger lists and it seems to > continue be linear complexity up to 100 000 elements, but the kernel > (v.6) just crashes after that - this > behavior I can not explain, since the memory usage seems quite decent. So, to summarize my opinion: if you prefer to stay in a recursive > mode, you *can* use recursion in Mathematica rather efficiently by > switching to linked lists (and this will require some extra work but > not so much of it). This may be enough to move you from the domain of > toy problems to that of reasonably complex prototypes. But don't > expect efficiency of the highly optimized production language with a > native-code compiler (or even byte code interpreter) from a rewrite > system such as Mathematica. Also, I'd say that other programming > styles such as structural operations (APL - like) will bring you > closer to efficiency of Ocaml etc. since then you can leverage the > highly-optimized vectorized operations built in Mathematica. Hope this helps. Leonid > This post is about functional programming in Mathematica versus other > functional languages such as OCaml, SML or Haskell. At least a naive > use of functional constructs in Mathematica is horrendously slow. Am I > doing something wrong? Or isn't Mathematica really suitable for > functional programming beyond toy programs? Couldn't the Wolfram team > make a more efficient implementation for recursion, as other > functional languages has done? (Instead of the naive C-like behavior > for recursively defined functions.) as below myselect[{}, predicate_] = {} > myselect[{head_, tail___}, predicate_] := If[predicate[head], > Join[{head}, myselect[{tail}, predicate]], > myselect[{tail}, predicate] > ] Then I tried this function on a 20.000 element vector with machine > size floats: data = Table[Random[], {20000}]; > $RecursionLimit = 100000; > Timing[data2 = myselect[data, # > 0.5 &];] The result is {7.05644, Null}, and hundreds of MB of system memory are > 20.000 floats! It's just a megabyte! The following OCaml program executes in apparently no-time. It is not > compiled and does the same thing as the above Mathematica code. After > increasing the list by a factor of ten to 200.000 elements, it still > executes in a blink. (But with 2.000.000 elements my OCaml interpreter > says Stack overflow.) let rec randlist n = if n=0 then [] else Random.float(1.0) :: randl= is= > t > (n-1);; let rec myselect = function > [],predicate -> [] > | x::xs,predicate -> if predicate(x) then x::myselect(xs,predica= te= > ) > else myselect(xs,predicate);; let mypred x = x>0.5;; let l=randlist(20000);; > let l2=myselect(l,mypred);; (* lightning-fast compared to Mathemat= ic= > a > *) === Subject: Re: Why is recursion so slow in Mathematica? > This post is about functional programming in Mathematica versus other > functional languages such as OCaml, SML or Haskell. At least a naive > use of functional constructs in Mathematica is horrendously slow. Am I > doing something wrong? Or isn't Mathematica really suitable for > functional programming beyond toy programs? Couldn't the Wolfram team > make a more efficient implementation for recursion, as other > functional languages has done? (Instead of the naive C-like behavior > for recursively defined functions.) as below myselect[{}, predicate_] = {} > myselect[{head_, tail___}, predicate_] := If[predicate[head], > Join[{head}, myselect[{tail}, predicate]], > myselect[{tail}, predicate] > ] Then I tried this function on a 20.000 element vector with machine > size floats: data = Table[Random[], {20000}]; > $RecursionLimit = 100000; > Timing[data2 = myselect[data, # > 0.5 &];] The result is {7.05644, Null}, and hundreds of MB of system memory are > 20.000 floats! It's just a megabyte! The following OCaml program executes in apparently no-time. It is not > compiled and does the same thing as the above Mathematica code. After > increasing the list by a factor of ten to 200.000 elements, it still > executes in a blink. (But with 2.000.000 elements my OCaml interpreter > says Stack overflow.) let rec randlist n = if n=0 then [] else Random.float(1.0) :: randl= ist > (n-1);; let rec myselect = function > [],predicate -> [] > | x::xs,predicate -> if predicate(x) then x::myselect(xs,predica= te) > else myselect(xs,predicate);; let mypred x = x>0.5;; let l=randlist(20000);; > let l2=myselect(l,mypred);; (* lightning-fast compared to Mathemat= ica > *) So you discovered that appending to arrays is slow while appending to > linked lists is fast :) Actually you are not comparing the exact same algorithms. The data > structure you used in those languages was a linked list. Removing or > appending elements takes a constant time for linked lists. > Mathematica's List is a vector-type data structure, so > removing/appending elements takes a time proportional to the vector's > length. One data structure is not better than the other, of course, they're just > useful for different purposes. For example, a linked list is unsuitabl= e > for applications where the elements need to be accessed randomly instead > of sequentially. Random access is often needed for numerical > computations/simulations. For a fair comparison, use a linked list in Mathematica too. This coul= d > look like {1,{2,{3,{}}}} myselect[{}, test_] = {}; > myselect[{head_, tail_}, test_] := > If[test[head], {head, myselect[tail, test]}, myselect[tail, test]] toLinkedList[list_List] := Fold[{#2, #1} &, {}, list] data = toLinkedList@Table[Random[], {20000}]; Block[{$RecursionLimit = [Infinity]}, > Timing[myselect[data, # > 0.5 &];]] This runs in 0.2 sec on my (not very fast) system. And you can check that the function works correctly: Block[{$RecursionLimit = [Infinity]}, > Select[Flatten[data], # > 0.5 &]] About the thing that you call naive C-like behavior: you probably mean > that Mathematica doesn't automatically perform the tail-call > optimization. That is correct, you need to transform your recursions > explicitly. Here's an example: myselect2[dest_, {head_, tail_}, test_] := > If[test[head], > myselect2[{head, dest}, tail, test], > myselect2[dest, tail, test]] myselect2[dest_, {}, test_] := dest Note that it is $IterationLimit that we need to increase now and this > version doesn't fill up the evaluation stack. Also note that this produces the result in the reverse order: Block[{$IterationLimit = [Infinity]}, > Select[Flatten[data], # > 0.5 &]] We could produce the result in the same order, but reverse linking (like > {{{{},1},2},3}). I couldn't do any better than this using a singly-linked list. It look= s > like OCaml (which I don't know BTW) uses a singly linked list too, and > can't do the tail-call optimization, so its stack gets filled up. One more thing: even when using the same data structure and same > algorithm, it is of course expected that a very high level interpreted > language like Mathematica is not going to perform nearly as well as a > low level compiled language like OCaml. In high level languages the > usual solution to this performance problem is built-in functions: don't > implement Select in Mathematica itself. Use the built-in one, which is > written in C and much faster than a Mathematica implementation could ever= be. Hope this helps, > Szabolcs Oh, so they are arrays! Does that mean Mathematica has to reallocate memory to fit in new elements? Just a check, what's the space requirment for your representations of linked list? ByteCount[Fold[{#2,#1}&,{},Table[RandomReal[],{1000}]] 48024 bytes for 1000 eight-byte doubles. Same byte count for RandomInteger, BTW! In C I guess it would be something like 8*1000 bytes for the data plus 4*1000 bytes for the pointers to the next list elment. The Mathematica overhead seems reasonably ok to me, and it seems to be linear with the number of elements. a tail-recursive version of the standard list implementation of myselect (i.e. using arrays). The time performance is almost the same, but the tail-recursive versions doesn't eat memory like a monster. In summary, with your help I feel confident to continue my journey into Mathematica land :) I hope one day I will be able to contribute back to this group and the community. Daniel === Subject: Re: interfacing odd usb device to mathematica I have wondered why Mathematica does not support my i/o capabilities that can be readily used with a wider range of hardware. My specific application is the kind of things that are typically done with LabView. Mathemaica's built-in Java would seem to be the streamlined way to gain access to these i/o capabilities. You might already have a better MathLink idea in mind if you're big into C, etc., but if not, I think the way to start is to use Java and the i/o packages that are available for it. Not 100% sure since I haven't done this---I have only thought about doing it---I'd be interested if others have more efficient suggestions. >> I am fed up with the cheesy software that comes with my biofeedback >> USB device, and I'd like to interface it to Mathematica. It is a >> LightStone device from the Wild Divine project. The trouble is that >> it does not show up on ControllerInformation[], although it does show >> up on my Mac's USBProbe software. I am using Mac OSX, version 4.11 >> and Mathematica 7. USBProbe gives me the following information about >> the device: >> Descriptor Version Number: 0x0110 >> Device Class: 0 (Composite) >> Device Subclass: 0 >> Device Protocol: 0 >> Device MaxPacketSize: 8 >> Device VendorID/ProductID: 0x14FA/0x0001 (unknown= > vendor) >> Device Version Number: 0x2441 >> Number of Configurations: 1 >> Manufacturer String: 3 Wild Divine >> Product String: 1 ST7 RS232 USB BIOFBK >> Serial Number String: 0 (none) >> The only solution I can think of now is to try to write a separate >> program to stream output from the device and then read that output >> into Mathematica. But if there's some way to get Mathematica to >> recognize the device itself, that would obviously be much better. The only USB devices supported by Mathematica via the ControllerState > [] function on Mac OS X are those which conform to the USB HID (human > interface device) specification. Other (custom) USB devices cannot be > supported in the same general way. I think your only option to get > data from this device into Mathematica would be to write a custom > MathLink application. -Rob === Subject: Re: interfacing odd usb device to mathematica I have written some C code that uses a USB library to read in a data stream from an OCZ EEG if you are interested. It's set up to run in OS X but would work in linux without too many changes I believe. The main issue is knowing how the data is sent from the device and how to translate it into useable numbers. I was also not able to get mathematica to read it in a very good way, other than making a loop that reads in data for a predetermined amount of time while a plot is dynamically updated. Exam week starts monday and so I don't think I would have time to get it all collected together for a week or so though but if you're still interested I can post it on my website with instructions on how to get it all set up and use it. Adam Simpson >> I am fed up with the cheesy software that comes with my biofeedback >> USB device, and I'd like to interface it to Mathematica. It is a >> LightStone device from the Wild Divine project. The trouble is >> that >> it does not show up on ControllerInformation[], although it does show >> up on my Mac's USBProbe software. I am using Mac OSX, version 4.11 >> and Mathematica 7. USBProbe gives me the following information about >> the device: >> Descriptor Version Number: 0x0110 >> Device Class: 0 (Composite) >> Device Subclass: 0 >> Device Protocol: 0 >> Device MaxPacketSize: 8 >> Device VendorID/ProductID: 0x14FA/0x0001 (unknown= > vendor) >> Device Version Number: 0x2441 >> Number of Configurations: 1 >> Manufacturer String: 3 Wild Divine >> Product String: 1 ST7 RS232 USB BIOFBK >> Serial Number String: 0 (none) >> The only solution I can think of now is to try to write a separate >> program to stream output from the device and then read that output >> into Mathematica. But if there's some way to get Mathematica to >> recognize the device itself, that would obviously be much better. The only USB devices supported by Mathematica via the ControllerState > [] function on Mac OS X are those which conform to the USB HID (human > interface device) specification. Other (custom) USB devices cannot be > supported in the same general way. I think your only option to get > data from this device into Mathematica would be to write a custom > MathLink application. -Rob > === Subject: Help with FindMinimum I'm trying to write a code to solve an heterogeneous kinetics problem where the effective mass transferr coefficient (Deff), the reaction order (n) and the reaction rate (kRQ) ares simultaneously solved. In doing that an non linear equation should be solved inside a FindMinimum rotine where the values of Deff, kRQ and n are fitted to the experimental data. The problem code is presented below but it is not working. Does anyone konw how to sort it out? R0 = Sqrt[45*37]/2.0*10^-6 [Rho] = 2.500 (* Kg/m^3 *) ConNaOH = 6000. (* moles/m^3 *) extra=E7=E3o = ReadList[silicato NaOH-80oC.txt, Number, RecordLists -> True]; pontos = ListPlot[extra=E7=E3o, PlotStyle -> PointSize[0.012]] X[t_] = k1*t^2 + k2 *t + k3 ajuste1 = !( *UnderoverscriptBox[([Sum]), (i = 1), (Length[extra=E7=E3o])] *SuperscriptBox[((X[extra=E7=E3o[[i, 1]]] - extra=E7=E3o[[i, 2]])), (2)]); d1 = FindMinimum[ajuste1, {k1, k2, k3}] {minimo1, argumento1} = d1 argumento1 XE = X[t] /. argumento1 extra=E7=E3o1 = extra=E7=E3o deriv = D[XE, t] For[j = 1, j <= Length[extra=E7=E3o], j++, extra=E7=E3o1[[j, 2]] = XE /. t -> extra=E7=E3o[[j, 1]]] modelo1 = ListPlot[extra=E7=E3o1, PlotStyle -> PointSize[0.015], Joined -> True] Show[pontos, modelo1] F = Fa = extra=E7=E3o; For[j = 1, j <= Length[extra=E7=E3o], j++, Fa[[j, 2]] = -4/3*[Pi]*R0^3*[Rho]*deriv /. t -> extra=E7=E3o[[j, 1]] ] Print[Fa] alfa = Table[0, {i, 1, Length[extra=E7=E3o]}] [Alpha]1 = Table[(1 - extra=E7=E3o[[i, 2]])^(2/3), {i, 1, Length[extra=E7=E3o]}] [Alpha]2 = Table[(1 - extra=E7=E3o[[i, 2]])^(1/3), {i, 1, Length[extra=E7=E3o]}] dados = Table[Fa[[i, 2]], {i, 1, Length[extra=E7=E3o]}] [Sigma] = Table[FindRoot[[Theta]/( 4 [Pi]*kRQ*[Alpha]1[[i]]) + (ConNaOH + [Theta]/(4[Pi]*Deff* [Alpha]1[[i]]))^n == 0, {[Theta], 1}], {i, 1, Length[extra=E7=E3o]}] Print[[Sigma]] alfa = [Theta] /. [Sigma] ajuste2 = !( *UnderoverscriptBox[([Sum]), (i = 1), (Length[extra=E7=E3o])] *SuperscriptBox[((alfa[[i]] - dados[[i]])), (2)]); d2 = FindMinimum[ajuste2, {kRQ, 10, 20}, {Deff, 1*10^-9, 1}, {n, 1., 2}] === Subject: Seeking a Porter Stemmer done in Mathematica Has any one written and is willing to share it a Porter Stemmer in Mathematica? === Subject: manipulate problem with symboltrack hi all, first code here: Manipulate[ (*chord elements generation*) result = select[opt]; sn1 = result[[1]]; sn2 = result[[2]]; key = result[[3]]; chord = playChord[sn1, sn2, key, opt, instr]; (*locators generation*) locators = locatorsDB[[opt]]; Grid[{{ (*EmitSound@chord,*)chord }, {Which[ (*time < 0.01, counter=0,*) counter == 0, counter++, counter == Length[sn2c], Null (* do nothing *), time > sn2c[[counter]], counter++; EmitSound[Sound[SoundNote[sn1[[counter]], sn2[[counter]]]]] ]; i = counter; l = Length@locators; If[Mod[i, l] == 0, k = Quotient[i, l] - 1, k = Quotient[i, l]]; i = counter - 15*k; dancer[1, i, locators]} }] , {{opt, 1, Style}, {1 -> Happy, 2 -> Calm, 3 -> Sad, 4 -> Heart-broken}, ControlType -> PopupMenu}, {{instr, Piano, Instrument}, instrDB, ControlType -> PopupMenu}, {{time, 0, Trigger}, 0, Last[sn2c], 1, ControlType -> Trigger},(**) {{counter, 0}, ControlType -> None}, ] I'm quite puzzled with the problem: how to keep variable opt without being updated while changing other variables? === Subject: Re: Mathematica bug?? > Apologies ... this was a side effect of redefining 'Power' / the infix > operator ^ to do wedge products for differential forms. Apparently > Inverse calls Power during this inversion, at least for some of the > terms (?). Hence the bug. was. But mathematica changes since then make this old kludge fail. As a coincidence, I've been learning more about differential forms lately. Which particular package for dealing with differential forms were you using? (Note that there is a way around this, either way; use [Wedge] instead of ^: In[1]:= a^b // FullForm Out[1]//FullForm= Power[a, b] In[2]:= a [Wedge] b // FullForm Out[2]//FullForm= Wedge[a, b] -- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis We'll have to make our own luck from now on. -- Louis Wu === Subject: Re: Mathematica bug?? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? Perhaps this is a bug from a previous version. It works fine for me in 7.0 on Windows: In[25]:= $Version Out[25]= 7.0 for Microsoft Windows (32-bit) (February 18, 2009) In[26]:= mat = DiagonalMatrix[{Sqrt[1-2/r], 1/Sqrt[1-2/r], r, r Sin[ [Theta]]}] Out[26]= {{Sqrt[1-2/r],0,0,0},{0,1/Sqrt[1-2/r],0,0},{0,0,r,0},{0,0,0,r Sin[[Theta]]}} In[27]:= minv = Inverse[mat] Out[27]= {{1/Sqrt[1-2/r],0,0,0},{0,Sqrt[1-2/r],0,0},{0,0,1/r,0}, {0,0,0,Csc[[Theta]]/r}} In[28]:= mat.minv == IdentityMatrix[Length[mat]] Out[28]= True === Subject: Re: Mathematica bug?? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? For what it's worth, it works properly here: In[8]:= {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse Out[8]= {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/r}} In[9]:= $Version Out[9]= 7.0 for Linux x86 (32-bit) (January 30, 2009) -- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis If you are afraid of loneliness, do not marry. -- Anton Chekhov === Subject: Re: Mathematica bug?? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > =9A =9A0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > =9A r}} with no warnings. =9AThis is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? I can not reproduce this behavior with Mathematica 7.01 on WinXP SP3: In[26]:= {{Sqrt[1-2/r],0,0,0},{0,1/Sqrt[1-2/r],0,0},{0,0,r,0},{0,0,0,r Sin[[Theta]]}}//Inverse Out[26]= {{1/Sqrt[1-2/r],0,0,0},{0,Sqrt[1-2/r],0,0},{0,0,1/r,0}, {0,0,0,Csc[[Theta]]/r}} === Subject: Re: Mathematica bug?? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? > I get the result: {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/r}} which seems to be correct. Maybe you have set Values to some of your variables. -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Mathematica bug?? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? > This gives the expected result with 7.0.1 on 64-bit Windows. What version of Mathematica are you using? David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Mathematica bug?? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. > Works for me. I get: {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/r}} What version are you using? Have you cleared any variables? Try rebooting the kernal. === Subject: Re: Mathematica bug?? I get a different answer: {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/r}} This is the correct answer. What version of Mathematica were you using? Have you tried this on a fresh kernel? > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? === Subject: Re: Mathematica bug?? It works fine here: {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/r}} $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) Bobby > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? > -- DrMajorBob@bigfoot.com === Subject: Re: Mathematica bug?? First, you should be very cautious about categorically, and so dramatically, entitling a post as Mathematica bug. Second, such a title is so general as to be unhelpful to potential readers. Third, you don't say which version of Mathematica you're using. I tried this in Mathematica 7.0.1 and got the correct inverse: {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse // InputForm {{1/Sqrt[1 - 2/r], 0, 0, 0}, {0, Sqrt[1 - 2/r], 0, 0}, {0, 0, r^(-1), 0}, {0, 0, 0, Csc[[Theta]]/r}} But then I also tried it in Mathematica 5.2, and still I got the correct inverse. I suspect you had already assigned a value to r or Theta somewhere earlier in the evaluation steps. Or else just mistyped something. > {{Sqrt[1 - 2/r], 0, 0, 0}, {0, 1/Sqrt[1 - 2/r], 0, 0}, {0, 0, r, > 0}, {0, 0, 0, r Sin[[Theta]]}} // Inverse gives {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1/r, 0}, {0, 0, 0, Csc[[Theta]]/ > r}} with no warnings. This is a *diagonal* matrix that should be > trivially invertible. Does anyone know why Inverse has catastrophically failed here? > -- 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: Mathematica bug?? > First, you should be very cautious about categorically, and so > dramatically, entitling a post as Mathematica bug. Second, such a title is so general as to be unhelpful to potential reader= s. Wow! oshaughn - a relatively Mathfroup newcomer (just 5 posts so far) - cries Bug! and he gets 14 (self?) reassuring replies within a few hours, mostly from Mathgroup oldtimers. Looks like everybody is on hedge here :-) Relax, Mathematica 7.x certainly has bugs, but they probably are not so obvious anymore and probably only concern the newest functions. (my grand father was a great lawyer and taught me that if you sprinkle your sentences with probably, you never get in trouble. Well...you - probably - never get into trouble :-) I certainly share Murray's wise opinions expressed above. Perhaps I would have expressed them more, shall we say, colorfully :-) Your apologies are very appreciated. oshaughn: if you think that form matters (differentiable or otherwise) and you enjoy admiring event horizons from a safe Mathematica shore, I would suggest you look into David Park's Tensorial package at http://home.comcast.net/~djmpark/TensorialPage.html Put your XX century antique code to a deserved rest and enjoy: early XXI century Mathematica code V.6 compatible 2D output and.... first class support directly from David. (OOPS...just slipped into my marketing mode again. I must have been exposed to too much WRI product descriptions lately :-) ) Anyway, check it out. It's well worth its reasonable price. === Subject: Re: Integrate Bug I am trying to calculate this integral that should be positive.But the > answer is 0. In: Integrate[(1)/(z^2 + b^2 + a^2 - 2 z b Sin[[Theta]] - > 2 a b Cos[[Theta]])^(1/2), {[Theta], 0, 2 [Pi]}, > Assumptions -> {a > 0, b > 0, z > 0}] Out:0 Anybody have notice a situation like that? My platform is MacOSX 10.4 and Mathematica 7. Best wishes, Further to my previous post, seems that one single formula suffices : F[a_, b_, z_] := > (4 Sqrt[a^2 + b^2 + z^2 + 2 b Sqrt[a^2 + z^2]]* > Abs[Im[EllipticK[(a^4 + b^4 + 6 b^2 z^2 + z^4 + > 4 b^3 Sqrt[a^2 + z^2] + 4 b z^2 Sqrt[a^2 + z^2] + > 2 a^2 (3 b^2 + z^2 + 2 b Sqrt[a^2 + z^2]))/ > (a^2 - b^2 + z^2)^2]]])/Abs[a^2 - b^2 + z^2] -- > 2009/6/6 Andreas Dieckmann your expression with the complex EllipticK for the integral can be further simplified to: (4/Sqrt[a^2 + b^2 + z^2 + 2*b*Sqrt[a^2 + z^2]]) EllipticK[(4*b* Sqrt[a^2 + z^2])/(a^2 + b^2 + z^2 + 2*b*Sqrt[a^2 + z^2])] Andreas === Subject: Re: performance // Re: Re: Why is recursion so Hi Scot, The main source of overhead I see here is that myfunction[yourstring] is first computed during evaluation, and the global rule base is searched (hopefully with no match found:) ) for anything matching since the head of any expression is evaluated first. Consider this simple benchmark: In[1]:= Clear[fn,fn1]; fn[This is my test function][x_,y_]:=x*y; fn1[x_,y_]:=x*y; In[2]:= MapThread[fn[This is my test function][##]&,{Range[100000],Range[100000]}];//Timing Out[2]= {0.911,Null} In[3]:= MapThread[fn1[##]&,{Range[100000],Range[100000]}];//Timing Out[3]= {0.771,Null} In[4]:= MapThread[fn1,{Range[100000],Range[100000]}];//Timing Out[4]= {0.561,Null} In the latter case, a small speed-up is because we can avoid an extra parameter-passing stage [##]&, which we can not in your construction. This tells us about another possible source of overhead: when used in higher-order functions such as Map, your construction can not be used by name but needs an extra stage of constructing a pure function from it. This test shows about 50% slowdown, but the above test function does not really do much - for any realistic computation these effects will not probably be noticable since the main time will be spent in computing the r.h.s of the function. I did not do more systematic benchmarks, but I would not expect much of a performance hit, unless you have a single function name and a huge number of different definitions stored (which is unlikely). Of course, this depends on whether or not SubValues lookup is implemented as efficiently as DownValues, which I assume is true. Again, if the body of your is any computationally demanding, you probably shouldn't notice any overhead. Let me add that with this approach, your other limitation is that you won't be able to set the Attributes of myfunction such that they will affect the manipulations with var1,var2, etc. Leonid > On the general topic of performance, I'd be interested to know if anyone > can comment on the following. In an effort to keep my codes as reasonable > as possible, I use a lot of sentence variables. What I mean is that I'll > write: myfunction[further explanation][var1_,var2_]:= .... I add that extra string in naming the function. This helps me immensely to > remember what I'm doing and make my code accessible to me again in six > months. I have often wondered, however, if I slow down Mathematica by > using these long function names. Does anyone know? [For most of my applications, the limiting aspect on overall > implementation time is my slow human CPU, so I have ample computer cycles > and memory. However, there are a few applications that cause me to leave > my computer running overnight, so I'm wondering somewhat about the > performance of the code and if these long variable names are having an > effect.] === Subject: Multi-level Menu (ActionMenu) http://www.cafewebmaster.com/demo/css-menu/css-dhtml-menu.png === Subject: mathematica tutor for NYC high school student Hello We are wondering if you can help us with this. We live in Manhattan (NYC) and are seriously considering withdrawing our 15 yr old son (presently in 9th grade) from the school system and give him homeschooling that is creative, adventurous and non-competing. Naturally, for Math we are thinking of Mathematica so all his high school math curriculum can be done visually but with mathematical rigor. Question: Do you know some group/program/person in NYC so we can find a Mathematica tutor for our son so he gets excited about the inherent beauty of Math and covers the basic knowledge he needs ? He needs to cover Geometry, Trig, Algebra and Calculus at the high school level (grades 9-12). It is a long shot, but I am placed in Architecture and need to look outside my field for guidance. So the web becomes my first stop. At some point I will walk over to Courant Inst and see if they can help. Prof. H. Lalvani, PhD === Subject: Re: RandomReal gets stuck If you want to use subscripted variables, it might help to use this code: subFunction::usage = subFunction[a] causes inputting a[i] or !(*SubscriptBox[a, i]) to be synonymous, while always displaying the latter in outputs. subFunction[a] causes inputting a[i] or !(*SubscriptBox[a, i]) to be synonymous, while always displaying the latter in outputs. subFunction[a_Symbol]:=Block[{aa=ToString[a]},MakeExpression[SubscriptBox[To String@a,i_],f_]:=MakeExpression[RowBox[{ToString@a,[,i,]}]];MakeBoxe s[a[i_],f_]:=SubscriptBox[MakeBoxes[a,f],MakeBoxes[i,f]]] The result is that you can refer to a[i] or Subscript[a,i] interchangeably, but it always displays in the subscripted form. I find it much easier to use a[i] while typing formulas, so I'm getting the best of both worlds. Not sure if that addresses everything brought up on the thread, of course. Bobby > Apparently there is more to it than meets the eye, but section 2.5.5 >> in the (old) mathematica book discusses the use of indexed objects. In the fourth edition of the Mathematica Book, it is section > 2.4.5 titled Making Definitions for Indexed Objects *briefly* > discusses using the syntax y[[0] etc as a subscripted > variable. Basically, this section shows an example where it is > more convenient to use this syntax over a list and has the > following statement: You can think of the expression a[i] as being like an indexed > or subscripted variable. None of what I've said really contradicts this. What I've done > is simply point out being like is not the same as being. > That is, there are similarities between a subscripted variable > and the syntax a[i] but there is not an identity relationship. > -- DrMajorBob@bigfoot.com === Subject: Re: Possible bug in Eigenvalues[ ] ??? Lorenzo, This comes about because of the non-standard evaluation of Table and the fact that it has the attribute HoldAll. In one case it is obtaining a symbolic expression for the eigenvalues and then substituting into that, and in the other case it is solving the Eigenvalues problem each time. In both cases your solutions are undergoing a switch somewhere in the lambda domain, which corresponds to crossing a branch line. The Presentations package at my web site ($50) has a multifunctions capability that will provide continuous solutions for each of the branches of the solutions. For your example this takes the following form: Needs[Presentations`Master`] eigenvalues = Eigenvalues[mat + [Lambda] pert] {(-(1/6) + I/6) ((5 + 5 I) + 3 [Lambda] - Sqrt[ 514 I - (93 + 93 I) [Lambda] + (18 - 9 I) [Lambda]^2]), (-(1/ 6) + I/6) ((5 + 5 I) + 3 [Lambda] + Sqrt[ 514 I - (93 + 93 I) [Lambda] + (18 - 9 I) [Lambda]^2])} Then we use the Multivalues routine to initialize the evaluation and the CalculateMultivalues routine to calculate successive values. This does not work properly with Table, but works if we map the table functions onto the list of data points. Here we show the value of lambda, the two complex values, and the order of the two values in terms of the two functions above. I used wider steps just to shorten the posted output. You will notice that the order of the solutions switched between lambda = 3.5 and lambda = 4.0 and the two sets of solutions give continuous paths. eigendata = Multivalues[Null, eigenvalues, [Lambda]]; {#, CalculateMultivalues[eigendata][#]} & /@ Range[0, 10, .5] {{0., {{3.67707 + 0. I, -7.01041 + 0. I}, {1, 2}}}, {0.5, {{3.17252 + 0.479244 I, -7.00585 + 0.0207556 I}, {1, 2}}}, {1., {{2.63718 + 0.93368 I, -6.97052 + 0.06632 I}, {1, 2}}}, {1.5, {{2.0619 + 1.36404 I, -6.89524 + 0.135965 I}, {1, 2}}}, {2., {{1.43436 + 1.77216 I, -6.7677 + 0.227837 I}, {1, 2}}}, {2.5, {{0.736607 + 2.16242 I, -6.56994 + 0.337576 I}, {1, 2}}}, {3., {{-0.0602051 + 2.54621 I, -6.27313 + 0.453794 I}, {1, 2}}}, {3.5, {{-1.00604 + 2.95992 I, -5.82729 + 0.54008 I}, {1, 2}}}, {4., {{-2.15722 + 3.54582 I, -5.17612 + 0.454183 I}, {2, 1}}}, {4.5, {{-3.2619 + 4.54089 I, -4.57143 - 0.0408875 I}, {2, 1}}}, {5., {{-4.03354 + 5.62978 I, -4.2998 - 0.629777 I}, {2, 1}}}, {5.5, {{-4.65302 + 6.6284 I, -4.18031 - 1.1284 I}, {2, 1}}}, {6., {{-5.21554 + 7.55475 I, -4.11779 - 1.55475 I}, {2, 1}}}, {6.5, {{-5.75291 + 8.4319 I, -4.08042 - 1.9319 I}, {2, 1}}}, {7., {{-6.27786 + 9.27459 I, -4.05548 - 2.27459 I}, {2, 1}}}, {7.5, {{-6.79632 + 10.0922 I, -4.03701 - 2.59215 I}, {2, 1}}}, {8., {{-7.31138 + 10.8908 I, -4.02196 - 2.89078 I}, {2, 1}}}, {8.5, {{-7.8247 + 11.6747 I, -4.00863 - 3.17474 I}, {2, 1}}}, {9., {{-8.33728 + 12.4471 I, -3.99606 - 3.44707 I}, {2, 1}}}, {9.5, {{-8.84967 + 13.21 I, -3.98366 - 3.71004 I}, {2, 1}}}, {10., {{-9.36223 + 13.9653 I, -3.9711 - 3.96533 I}, {2, 1}}}} The routines work by remembering the last set of multivalues and using a linear programming assignment problem to reassign the multivalues at each step. This has many uses, and one of the most interesting is to drag a locator around a Riemann surface. We can attach an arrow to the locator to represent the value of the complex multifunction, and also display the numerical value. Although we don't directly 'see' the Riemann surface itself, we do see that the function is single valued and continuous as we move the locator around, and as we circle around various branch points we recover all of the values. There are no discontinuous branch line artifacts - just as Riemann promised. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I'm using Mathematica v.6.0.1.0 under Windows. I was using the Eigenvalues function to find the eigenvalues of some complex matrices when I found a very strange behaviour. Cutting the problem down to the bone, consider the 2x2 matrices mat = {{11/3, -(1/3)}, {-(1/3), -7}} pert={{-1 + [ImaginaryI], 1/2 + [ImaginaryI]/2}, {-1, 0}} I'm interested in the trajectories on the complex plane of the eigenvalues of A(lambda)= mat + lambda*pert as a function of the strength lambda. I calculated these trajectories in two ways and I get different results (one of which is the correct one). --> 1st way expr = Eigenvalues[mat + [Lambda] pert]; traj1 = Table[expr, {[Lambda], 0, 10, 0.1}]; --> 2nd way traj2 = Table[Eigenvalues[mat + [Lambda] pert], {[Lambda], 0,