A138 === Subject: Re: put some elements to zero ciao -Luigi- === Subject: Re: sparsearray bug? This seems indeed to be a bug. Here is what I think is the reason. In[1] = SparseArray[{1}] // FullForm Out[1] = SparseArray[Automatic,List[1],0,List[1,List[List[0,1],List[List[1]]],List[1] ]] Look at the third element (zero). This is a default element, which is filled for any position missed in explicit rules (when SparseArray is defined from a set of rules position->value). Now, in that latter case (when at least one default element is present), it makes sense to apply whatever Listable operation is applied to an entire array (Power[x,-1] in this case) also to the default element - but this should not be done in cases when all elements are indicated explicitly (and so the default element substitution does not actually take place). Let us change a default element to 1 in the FullForm: In[2] = SparseArray[Automatic,List[1],1,List[1,List[List[0,1],List[List[1]]],List[1] ]] Out[2] = SparseArray[<1>,{1},1] In this case, no error message: In[3] = 1/SparseArray[Automatic,List[1],1,List[1,List[List[0,1],List[List[1]]],List[ 1]]] Out[3] = SparseArray[<1>,{1},1] In[4] = Normal[%] Out[4] ={1} Now, we can convince ourselves that the bug is indeed related to applying an inverse (in this case, but this may be a more general problem) to the default element: In[5]:= Normal[1/SparseArray[{1->1,2->2,4->5}]] During evaluation of In[5]:= Power::infy: Infinite expression 1/0 encountered. >> Out[5]= {1,1/2,ComplexInfinity,1/5} Here the behavior was correct, since the default is present. However, I would bet that the actual place where this message was generated isn't correct - I am almost certain that it was generated before default element substitution actually took place (but this only WRI could confirm). Now: In[6]:= Normal[1/SparseArray[{1->1,2->2,3->4,4->5}]] During evaluation of In[6]:= Power::infy: Infinite expression 1/0 encountered. >> Out[6]= {1,1/2,1/4,1/5} Here it was incorrect (in terms of error message generation at least), since the default wasn't ever used. Now we change the default to 1: In[7]:= Normal[1/SparseArray[{1->1,2->2,3->4,4->5,{_}->1}]] Out[7]= {1,1/2,1/4,1/5} and get no error message. Here also the default wasn't actually used. This seems to support my conjecture. Hope this helps. Leonid > In[494]:= SparseArray[{1}]/SparseArray[{1}] During evaluation of In[494]:= Power::infy: Infinite expression 1/0 > encountered. >During evaluation of In[494]:= [Infinity]::indet: Indeterminate expression > 0 ComplexInfinity encountered. >> Out[494]= SparseArray[<1>,{1},Indeterminate] > > === Subject: 2dFFT & image processing hi everybody, I need to perform a high-pass filter on some images. I know I can get a high pass filter doing a convolution of the image with a predefined kernel, but for various reasons (and my learning too) I wanted to follow the sequence: 1) fft 2) cut away central region (with a smooth edge) 3) fft again but, due to my ignorance, I'm unable to accomplish the process: given the image in a, I put: f = Fourier[a[[1]]]; af = Abs@f; Dimensions[f] {500,500} and I can check the fft with Graphics[Raster[255*af/Max[af]]] I then create the hole and apply it to the fft and invert again: k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. s -> 1000.; holed = af*k; fholed = Abs[Fourier[holed]]; since the reconstructed image Graphics[Raster[255*fholed/Max[fholed]]] is strongly fuzzed, whichever value I choose for the parameter s above, I wanted to ask you if I completely misunderstood the process! thank you, alessandro === Subject: Re: Installation errors on Solaris with Mathematica 6. G'day, Exact steps on your installation procedure would help. For example, did you install Mathematica as root? The messages below look like what cp would silently return if it didn't have permission to write. Yas > I downloaded a trial of Mathematica 7 for Solaris from the Wolfram > Reserach site, after requesting one. I attempted to install this on a Sun Blade 2000, but get a large > number of installation errors. These are recorded in the file: /usr/local/Wolfram/Mathematica/7.0/InstallErrors - see below for > contents I have contacted Wolfram Research about this, but thought someone on > the Mathematica news group might know the answer. $ uname -a > SunOS ws2 5.10 Generic_139555-08 sun4u sparc SUNW,Sun-Blade-1000 $ cat /etc/release > Solaris 10 10/08 s10s_u6wos_07b SPARC > Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. > Use is subject to license terms. > Assembled 27 October 2008 The machine has one 1200 MHz CPU. . Can you suggest how to resolve this? > > cp: cannot create /usr/share/icons/blueprint/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/blueprint/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/blueprint/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/blueprint/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/blueprint/128x128/apps: No such > file or directory > cp: cannot create /usr/share/icons/blueprint/128x128/apps: No such > file or directory > cp: cannot create /usr/share/icons/gnome/64x64/apps: No such file or > directory > cp: cannot create /usr/share/icons/gnome/64x64/apps: No such file or > directory > cp: cannot create /usr/share/icons/gnome/128x128/apps: No such file or > directory > cp: cannot create /usr/share/icons/gnome/128x128/apps: No such file or > directory > cp: cannot create /usr/share/icons/handhelds/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/handhelds/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/handhelds/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/handhelds/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/handhelds/128x128/apps: No such > file or directory > cp: cannot create /usr/share/icons/handhelds/128x128/apps: No such > file or directory > cp: cannot create /usr/share/icons/now/32x32/apps: No such file or > directory > cp: cannot create /usr/share/icons/now/32x32/apps: No such file or > directory > cp: cannot create /usr/share/icons/now/64x64/apps: No such file or > directory > cp: cannot create /usr/share/icons/now/64x64/apps: No such file or > directory > cp: cannot create /usr/share/icons/now/128x128/apps: No such file or > directory > cp: cannot create /usr/share/icons/now/128x128/apps: No such file or > directory > cp: cannot create /usr/share/icons/redglass/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/redglass/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/redglass/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/redglass/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/redglass/128x128/apps: No such file > or directory > cp: cannot create /usr/share/icons/redglass/128x128/apps: No such file > or directory > cp: cannot create /usr/share/icons/whiteglass/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/whiteglass/32x32/apps: No such file > or directory > cp: cannot create /usr/share/icons/whiteglass/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/whiteglass/64x64/apps: No such file > or directory > cp: cannot create /usr/share/icons/whiteglass/128x128/apps: No such > file or directory > cp: cannot create /usr/share/icons/whiteglass/128x128/apps: No such > file or directory > > === Subject: Re: RecurrenceTable can't finish Hi Ian, consider your first recurrence relation:a[i] ..==a[i] .. + d[i+1] a[i+1] If i=n: d[i+1] becomes zero and the recursion fails. Daniel > I have a RecurrenceTable that works for all but the last element, at which it stumbles across a ComplexInfinity that does not occur when I do the final calculation myself. Here is self-contained (if not explained) code. Runs fine when the nspec for RecurrenceTable is {i,1,n-1} (as below), but gives the error when nspec is {i,1,n}. I can use the recurrence equation to calculate the last value (for n) without problems, but RecurrenceTable can't. > > n = 20; > Guess = 7*10^-5; > b[i_] := Piecewise[{{0, i == 0 || i == n}}, 3/10]; > d[i_] := Piecewise[{{0, i == 0 || i == n + 1}}, 5/10 i/n]; > > q = RecurrenceTable[{a[i] (1 - d[1] q1) == > b[i - 1] a[i - 1] + (1 - b[i] - d[i]) a[i] + d[i + 1] a[i + 1], q1 (1 - d[1] q1) == (1 - b[1] - d[1]) q1 + d[2] a[2], a[1] == Guess}, a, {i, 1, n-1}]]; > > That the solution is right for a[1] through a[n-1] can be confirmed with the following code. > > k = 10; (* Initial Population Size *) > p0 = Table[1/k! D[x^k, {x, i}], {i, 0, n}] /. x -> 0; > P = Table[1/(j + 1)! D[b[j] x^(j + 1), {x, i}] + 1/(j - 1)! D[d[j] x^(j - 1), {x, i}] + 1/(j)! D[(1 - (b[j] + d[j])) x^j, {x, i}], {i, 0, n}, {j, 0, n}] /. x -> 0; > p[t_] := MatrixPower[N[P], t, p0]; > qGood = p[5000][[2 ;; n + 1]]/(1 - p[5000][[1]]); > Show[ListLinePlot[qGood], ListPlot[q]] > > === Subject: op_eye_ifs.gif (GIF Image, 997x997 pixels) - Scaled (91%) http://www.geocities.com/rlbagulatftn/op_eye_ifs.gif Another of the nested ellipse types that I found yesterday. A very simple op art type tiling of a circle: Clear[f, dlst, pt, cr, ptlst, x, y] dlst = Table[ Random[Integer, {1, 2}], {n, 250000}]; f[1, {x_, y_}] := N[{-x/2 - y/2, x/2 - y/2 + 7/24}]; f[2, {x_, y_}] := N[ {2*x*y/(x2 + y2) , (x2 - y2)/(y2 + x2)}]; pt = {0.5, 0.75}; cr[n_] := If[n - 1 == 0, RGBColor[0, 0, 1], If[n - 2 == 0, RGBColor[0, 0, 0], If[n - 3 == 0, RGBColor[1, 0, 0], RGBColor[0, 1, 0]]]] ptlst = Table[{cr[dlst[[j]]], Point[pt = f[dlst[[j]], Sequence[pt]]]}, {j, Length[dlst]}]; Show[Graphics[Join[{PointSize[.001]}, ptlst]], AspectRatio -> Automatic, PlotRange -> All] === Subject: Re: logical simplification problem > > Hi mathematica community, > > if it does not exist as predefined function in mathematica, how to > > define a rule that illustrate this logical property: if p implies q > > then p || q is simplified into q and p&&q is simplified into p? Possibly you are looking for BooleanMinimize. In[15]:= BooleanMinimize[{p || q, p && q}, DNF, Implies[p, q]] Out[15]= {q, p} Daniel Lichtblau > Wolfram Research one who take the time to answer my question. In fact, The function BooleanMinimize seems to do what I want but the problem now is that Implies doesn't test if p implies q is really true or false . I want to use something like ImpliesQ (which unfortunately become obsolete) in order to test the implication and so if it is true the expression is minimized and if it is false it stills in the same form. Any suggestion? === Subject: Re: matrix equation Hi Haibo, here is a simpler example that shows the essentials. Daniel f[t_] := {{t , t^2}, {t^2, 3 t}}; eq = {f[t] == a[t] .f'[t], a[0] == {{0, 0}, {0, 0}}}; y = a /. NDSolve[eq, a, {t, 0, 0.5}][[1]]; Plot[y[t], {t, 0, .5}] > Suppose T is a inversible matrix, and its elements are functions of t. > Consequently, we may denote this matrix as T[t], and its first and second > derivative is denoted as T'[t] and T''[t]. > I want to solve a equation as follows: > (A+B)T+T'==(a+b)T+2T', (A+B)T'+aBT==aT'+(ab+b)T+T''; > where a,b are known constants, and A,B is what I want to get. > How to express it in matrix form and solve it? > > === Subject: Re: Animate parametric plot of two lists? I'm not certain which is better, to store a large number of complete plots, or to generate each one. Generating each of the plots, which seems to be rapid enough for me, could be done as follows. f[t_] := Cos[t] g[t_] := Sin[t] list1 = Table[f[t], {t, 0, 2 Pi, .1}]; list2 = Table[g[t], {t, 0, 2 Pi, .1}]; n = Length[list1]; plotdat = Thread[{list1, list2}]; Animate[ Show[ ListPlot[Take[plotdat, k], Joined -> True, PlotStyle -> {Red, Dashed}, AspectRatio -> Automatic, PlotRange -> 1.2], ListPlot[Take[plotdat, k], PlotMarkers -> {Automatic, 12}, AspectRatio -> Automatic, PlotRange -> 1.2] ], {k, 1, n, 1}] But not (for some reason that I don't understand) as follows: Animate[ Show[ ListPlot[Take[plotdat, k], PlotMarkers -> {Automatic, 12}, AspectRatio -> Automatic, PlotRange -> 1.2], ListPlot[Take[plotdat, k], Joined -> True, PlotStyle -> {Red, Dashed}, AspectRatio -> Automatic, PlotRange -> 1.2] ], {k, 1, n, 1}] But, as usual, I find it easier to do it with Presentations where the various uses of the options are untangled and the order doesn't matter. Needs[Presentations`Master`] Animate[ Draw2D[ {ListDraw[Take[plotdat, k], PlotMarkers -> {Automatic, 12}], ListDraw[Take[plotdat, k], Joined -> True, PlotStyle -> {Red, Dashed}]}, Axes -> True, PlotRange -> 1.2], {k, 1, n, 1}] If you wanted to pre-compute all of the frames, you could just pre-compute the primitives without generating the entire plots. Clear[frame] frame[k_]:={ListDraw[Take[plotdat,k], PlotMarkers->{Automatic,12}], ListDraw[Take[plotdat,k], Joined->True, PlotStyle->{Red,Dashed}]}; framelist=Table[frame[k],{k,1,n}]; Animate[ Draw2D[ {framelist[[k]]}, PlotRange -> 1.2, Axes -> True], {k, 1, n, 1}] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ When I have explicit formulas for two functions of time, it's simple to animate the parametric plot of them by using ParametricPlot inside Animate. I'd like to create a similar animation now, but using two lists of numbers. Apparently there is no function such as ListParametricPlot. Below a roundabout way I found (I want to show both a dashed line and a point tracing out the curve in time). Is there a better way to do this? I'd like to be able to include many more frames, and this method seems inefficient. Any suggestion/help is appreciated. Porscha (*Animate a parametric plot from two lists*) In[1]:= f[t_] := Cos[t] In[2]:= g[t_] := Sin[t] In[27]:= list1 = Table[f[t], {t, 0, 2 Pi, .1}]; In[28]:= list2 = Table[g[t], {t, 0, 2 Pi, .1}]; In[29]:= n = Length[list1]; In[30]:= plotdat = Thread[{list1, list2}]; In[31]:= frame = ConstantArray[0.0, n]; In[32]:= Do[ frame[[j]] = Show[ListLinePlot[plotdat[[1 ;; j]], PlotStyle -> {Red, Dashed}, PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}], ListPlot[plotdat[[1 ;; j]], PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}, PlotMarkers -> {Automatic, 12}]], {j, 1, n}] In[33]:= ListAnimate[frame] === Subject: Re: Animate parametric plot of two lists? When I have explicit formulas for two functions of time, it's simple > to animate the parametric plot of them by using ParametricPlot inside > Animate. I'd like to create a similar animation now, but using two lists of > numbers. Apparently there is no function such as ListParametricPlot. Below a roundabout way I found (I want to show both a dashed line and > a point tracing out the curve in time). Is there a better way to do > this? I'd like to be able to include many more frames, and this method > seems inefficient. Any suggestion/help is appreciated. Porscha > > (*Animate a parametric plot from two lists*) > In[1]:= f[t_] := Cos[t] > In[2]:= g[t_] := Sin[t] In[27]:= list1 = Table[f[t], {t, 0, 2 Pi, .1}]; > In[28]:= list2 = Table[g[t], {t, 0, 2 Pi, .1}]; In[29]:= n = Length[list1]; > In[30]:= plotdat = Thread[{list1, list2}]; > In[31]:= frame = ConstantArray[0.0, n]; In[32]:= Do[ > frame[[j]] = > Show[ListLinePlot[plotdat[[1 ;; j]], PlotStyle -> {Red, Dashed}, > PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}], > ListPlot[plotdat[[1 ;; j]], > PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}, > PlotMarkers -> {Automatic, 12}]], {j, 1, n}] In[33]:= ListAnimate[frame] > You can interpolate data and use ParametricPlot (not sure it is more efficient than yours though). {f1, f2} = ListInterpolation[#, {{0, 2 Pi}}] & /@ {list1, list2} Animate[ParametricPlot[{f1[t], f2[t]}, {t, 0, max}, PlotRange -> {-1.2, 1.2}, AspectRatio -> 1/GoldenRatio, Mesh -> {Range[0, 2 Pi, .1]}, PlotStyle -> Red, MeshStyle -> Directive[PointSize[Large], Blue]], {max, 0.1, 2 Pi}] Jay === Subject: Re: Fast calculation of pair correlation function Very interesting, I didn't know the HierarchicalClustering package until now. The DistanceMatrix function does exactly what I wanted to do. But, unfortunately, a list of 10^4 elements seems to be the maximum that this function can handle before the Kernel shuts down, telling me No more memory available. I think it would be good to have the DistanceMatrix function in the Mathematica kernel, because it's a very time and memory consuming calculation. === Subject: GeoDistance and transformation from WGS84 to WGS84 Hi all, Anyone an idea why the following doesn't work? It calculates the distance between two points on the earth with given latlong coordinates. WGS84 is the datum used for GPS, if I'm not mistaken. In[86]:= GeoDistance[GeoPosition[{1, 0}, WGS84], GeoPosition[{0, 0}, WGS84]] During evaluation of In[86]:= GeoDistance::datum: No direct transformation between datums WGS84 and WGS84 is available. >> Out[86]= GeoDistance[GeoPosition[{1, 0}, WGS84], GeoPosition[{0, 0}, WGS84]] The More Information box of GeoPosition specifically states that WGS84 is one of the allowed datums. However, GeodesyData[Datum] and GeodesyData[ReferenceEllipsoid] make clear that WGS84 is not a datum, but a reference ellipsoid (WGS72 seems to be both). === Subject: Jens-Peer Kuska We are all very saddened to hear of the sudden death of Jens-Peer Kuska. In particular it must be very difficult for his family. Based at the University of Leipzig in the Bioinformatics Department Jens had many interests including medical image processing, and computer visualization. For a very long time he had been a Mathematica enthusiast and was well known to many of the developers of Mathematica here at Wolfram Research. He worked on many Mathematica development projects including MathGL3D -- an OpenGL rendering system for Mathematica and a set of virtual TeX fonts to use the Mathematica typesetting fonts with TeX (later supported by TeXSave). Recently he had been developing a suite of image processing functionality to complement his work. He published a book on using Mathematica and C to solve theoretical physics problems: 'Mathematica und C in der modernen Theoretischen Physik'. On MathGroup he was a continuous contributor, making frequent posts and comments. Always giving sensible, practical and useful advice. He would always see to the heart of the matter, people who followed his advice would not only learn how to solve their problem, but would increase their understanding of how Mathematica works. He was a frequent and enthusiastic attendee at many Mathematica conferences and symposia. I remember him well in Avignon for IMS 2006 and Maastricht for IMS 2008. He also took part in many conferences and training sessions in Germany. I last saw him at a Mathematica Day at the Weierstrass Institute in Berlin in November. As ever he was a strong contributor, asking questions and giving his own perspective and opinions. Afterwards several of us continued our discussions at a very enjoyable meal. Jens was a completely unique character, warm and friendly, very knowledgeable about Mathematica, as well as mathematics, physics and programming in general. He was incisive and questioning -- but realistic with a fine sense of what was practical and useful. This was bundled with a lovely sardonic and dry sense of humour. He certainly knew how to get the best out of Mathematica. He always liked to see what was in upcoming versions, and was very free with praise, advice and suggestions so that we could all make the most of what was to come. Sadly, this is not to be any more. He will be missed. Tom Wickham-Jones Director of Kernel Technology Wolfram Research === Subject: BarChart and ChartStyle How can I use the ChartStyle option to get the second bar to be LightGreen? This doesn't work: BarChart[{{16, 8}, {5, 3}}, BarSpacing -> -.5, ChartStyle -> {{LightGray, LightGreen}, {LightGray, LightRed}}] and this doesn't work BarChart[{{16, 8}, {5, 3}}, BarSpacing -> -.5, ChartStyle -> {LightGray, LightGreen, LightGray, LightRed}] === Subject: Re: Simplifying with KroneckerDelta sub = expr_* KroneckerDelta[c_, d_] :> Simplify[expr, c == d] * KroneckerDelta[c, d]; Exp[a - b] KroneckerDelta[a, b] /. sub KroneckerDelta[a, b] Bob Hanlon That helps, but maybe I should have been more specfic because I actually have long and more involved expressions. What would be really useful for me in this case would be a replacement rule like this: krule = f[b_] KroneckerDelta[a_, b_] -> f[a] KroneckerDelta[a, b] where f[ ] is any function. For example, if I had an expression like: Exp[a-b] KroneckerDelta[a,b] I would like Mathematica to give me Exp[0] KroneckerDelta[a,b] which after simplifying of course it's just KroneckerDelta[a,b] Is there anyway I can do this? I tried some ways but they didn't work (maybe writing f[b_] is not the right way?) -Francsico > Why not use a rule? krule = b_ KroneckerDelta[a_, b_] -> a KroneckerDelta[a, b] (m + n) KroneckerDelta[k, m + n] /. Krule > k KroneckerDelta[k, m + n] But the real work might be if you have a sum before the KroneckerDelta that > only includes m + n as sub-terms. You could write a routine that collected > on the KroneckerDelta forms, then wrapped Hold around the m+n sub-terms > (both places), then applied the rule and released the Hold. > David Park > djmpark@comcast.net > http://home.comcast.net/~djmpark/ > > > > Does anybody know how to tell mathematica to use the KroneckerDelta in > order > to simplify expressions? For example, it would be great if it could receive > something like this: (m+n) KroneckerDelta[k,m+n] and give k KroneckerDelta[k,m+n] Of course this is simple example, but I have an expression which is about > 200 terms long, so if it could use the delta to simplify things by itself, > that would be great. Francisco > -- > View this message in context: http://www.nabble.com/Simplifying-with-KroneckerDelta-tp24362541p24362541.ht > ml: > Why is this unavailable? CityData[{Austin, Texas, UnitedStates}, TimeZone] Missing[NotAvailable] Bobby -- > DrMajorBob@bigfoot.com > > -- Peter Lindsay === Subject: Re: TimeZones It doesn't seem to be available for any city in the US: In[51]:= DeleteCases[ CityData[#, TimeZone] & /@ CityData[{All, UnitedStates}], Missing[NotAvailable]] // Length Out[51]= 0 Not so for the Netherlands: In[52]:= DeleteCases[ CityData[#, TimeZone] & /@ CityData[{All, Netherlands}], Missing[NotAvailable]] // Length Out[52]= 482 It's a sign of the times. > Why is this unavailable? CityData[{Austin, Texas, UnitedStates}, TimeZone] Missing[NotAvailable] Bobby -- > DrMajor...@bigfoot.com === Subject: Add syntax highlighting to own command I was missing a scoping construct like 'With' but where the local variables get assigned linearly. E. g. In[1] := LinearWith[ { b = a <> there! }, Print[ b ] ] I'm fairly new to Mathematica, but I know some Lisp, and somehow I got it. I called my new construct Let and defined it as: Let[ vars_, expr_ ] := If[ Length[ Unevaluated[ vars ] ] == 1, With[ vars, expr ], (* else *) Unevaluated[ vars ] /. { a_, b__ } :> With[ { a }, Let[ { b }, expr ] ] ] SetAttributes[ Let, HoldAll ] It seems to work fine so far. Now, I would like to have this construct load always when I start Mathematica and I don't want to get it cleared when I use 'Clear[Global`*]'. So I put it in the System` context and also added wonder where to put it that it gets read automatically at each startup of Mathematica. However, my first question: Is it a bad idea to add things to the System` context? And if not, where to put my file? And if, what would be better? Second, my main question: Is it somehow possible to add this nice syntax highlighting to the Let construct like with the With construct, where the local variables appear in green? Third: Can I somehow add a help page? I have already the Let::usage. And last: Does anybody know how to make the construct better? Is there something like syntax transformation rules in Mathematica? Bastian === Subject: Re: Selecting Rows Based on Column Values Select[tester, #[[3]] == 1 &] Cases[tester, _?(#[[3]] == 1 &)] Select[tester, Last[#] == 1 &] Cases[tester, _?(Last[#] == 1 &)] Cases[tester, {_, _, 1}] DeleteCases[tester, {_, _, Except[1]}] tester /. {_, _, Except[1]} -> Sequence[] Bob Hanlon I've been trying to use the Select Command to select only the rows that have the a specific value in a specific column. I have, for example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. === Subject: Re: Selecting Rows Based on Column Values #[[All,3]] means the third column of an array, and your triples are one-dimensional objects...Use #[[3]]: In[2]:= Select[tester, #[[3]] == 1 &] Out[2]= {{1, 3, 1}, {4, 2, 1}} Another approach In[3]:= Cases[tester, {_, _, 1}] Out[3]= {{1, 3, 1}, {4, 2, 1}} Adriano Pascoletti 2009/7/8 cynthia wu that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > > > === Subject: Re: Selecting Rows Based on Column Values G'day, Something like the following maybe.. tester = {{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} numberSelected = 1; col = 3; Part[tester, Flatten[Position[tester[[All, col]], numberSelected]]] Yas > I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > > > === Subject: Re: Selecting Rows Based on Column Values > I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > > Cynthia, You might use a pattern instead: Cases[tester,{__,1}] Out= {{1, 3, 1}, {4, 2, 1}} -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Selecting Rows Based on Column Values Hi Cynthia, you were just a step away. Here is the right syntax: In[1] = tester = {{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}}; In[2] = Select[tester, #[[3]] == 1 &] Out[2] = {{1, 3, 1}, {4, 2, 1}} Just keep in mind that you have to use square brackets, not parentheses, to call functions in Mathematica. Leonid > I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > > > === Subject: Re: Selecting Rows Based on Column Values > I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > Select[tester, #[[3]] == 1 &] You don't want All because you are applying the test to *each* 3 element list. eg. {1, 3, 1}[[ 3]] etc. Mike === Subject: Re: Selecting Rows Based on Column Values Cynthia, tester = {{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} Select[tester, #[[3]] == 1 &] {{1, 3, 1}, {4, 2, 1}} 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 > I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > > === Subject: Re: Selecting Rows Based on Column Values The correct syntax is In[2]:= Select[tester=2C#[[3]]==1&] Out[2]= {{1=2C3=2C1}=2C{4=2C2=2C1}} You're using #[[All=2C 3]]=2C which refers to a 2d element. Tomas I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have=2C for > example=2C the following matrix (4x3): tester={{1=2C 3=2C 1}=2C {3=2C 1=2C 0}=2C {4=2C 2=2C 1}=2C {5=2C 6=2C 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester=2C #[[All=2C3]]==1&)=2C but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1=2C3=2C1}=2C {4=2C2=2C1}}. > > === Subject: Re: Selecting Rows Based on Column Values Select[tester, Part[#, 3] == 1 &] or Select[tester, #[[3]] == 1 &] Another possibility is to use Cases Cases[tester, {x_, y_, z_} /; z == 1] Good luck Tom Dowling > I've been trying to use the Select Command to select only the rows > that have the a specific value in a specific column. I have, for > example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. > I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my > request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. > > > === Subject: Re: Selecting Rows Based on Column Values Select[tester, Part[#, 3] == 1 &] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I've been trying to use the Select Command to select only the rows that have the a specific value in a specific column. I have, for example, the following matrix (4x3): tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} I want to select the rows that have values ==1 in the 3rd column. I've tried: select(tester, #[[All,3]]==1&), but I get an error saying that my request violates the matrix boundaries. The desired output should be: {{1,3,1}, {4,2,1}}. === Subject: Jens Jens was a beacon of learning for Mathematica. Benedetto Bongiorno CPA CRE Cell 214-707-6546 Land 972-470-9138 Fax 972-470-9748 bongiob@sbcglobal.net This Email is covered by the Electronic Communications Privacy Act, 18 U.S.C. Sections 2510-2521 and is legally privileged. The information contained in this Email is intended only for the use of the individual or entity named above. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distributions or copying of this communication is strictly prohibited. If you have received this communication in error, please notify sender. === Subject: Re: Jens-Peer Kuska passed away I think it was a shock for all the people who knew him, I met him several time during mathematica meetings, he is very thoughtful, helpful and friendly person. I think we all will miss him, a very kindly person!. O. Kullie Quoting Kevin J. McCann : > He will be missed by us all, but especially his family and colleagues. Kevin > > === Subject: Re: Jens-Peer Kuska passed away Of course I only met Jens thru Mathgroup...if ever there was a person with unique style, etc. it was him........ I always checked his Mathgroup contribution to see what I could learn from him....not only for his Mathematica insight but to find out how he was going to tease us that day.....A man of Intelligence and Wit....not a bad combination.... Jerry Blimbaum === Subject: Re: Jens-Peer Kuska passed away Our salute goes out to him, our condolences to his family and friends. He will be missed. fjm ----- Original Message ----- === Subject: Re: Jens-Peer Kuska passed away > This is indeed a very tragic and sad news. The MathGroup will never be > the same again. I would like to add just a few words from myself. I have known Jens-Peer through the MathGroup since I started to > participate in in in 1998. At that time I was a newbie and he one of > the most active and most knowledgeable contributors. There seemed to > be no area of computer science, physics or other science Jens-Peer did > not know about. He was a brilliant C programmer, and expert in many > other computer languages but it was clear (and he often stated it) > that he loved Mathematica above all others. This made him sometimes > impatient with people who criticized without understanding it, but > even when he seemed to be annoyed he always gave practical and useful > advice. Around the 2001 I started teaching geometry of polyhedra at the > university (in Japan) where I worked as a professor. I wanted to use a > 3D viewer but found RealTime3D - (and Open GL based hack used by > Mathematica before version 6 as a stop-gap measure) unsatisfactory. > However, I remembered that I had seen a MathGroup post by Russel Towle > in which he praised MathGL 3d - an Open GL and MathLink based program > as being ideal for the purpose I had in mind. > Jens-Peer asking him about a Mac version and he replied that he had no > access to Macs but WRI was going to send him an i-Mac and he would let > me know when a Mac version becomes available. > So, while waiting for that, I run MathGl3d slowly under emulation on > my Mac and while my students used much faster Windows version. It > would take a long time to describe how impressive this program was at > that time. It's enough to say that many of its capabilities are still > unmatched by Mathematica in version 7. In particular, what I found > particularly useful was the superb function MVContourPlot3D, which is > still much faster and more accurate than ContourPlot3D in Mathematica > 7. In any many of my students became quite expert at using this > part of her graduation thesis. I met Jens-Peer personally just once, during the IMS at Imperial > processing and after that I had a chance to exchange a few words with > him. The memory of his wit and intelligence remains with me to this > day. I reminded him about this promised Mac version of Math GL 3d, and > he told me that he was having more problems than he had expected due > to bugs in Apple's implementation of Open GL. Two more years past and assumed that Jens-Peer had forgotten all about > this. But then in 2005 unexpectedly I got an e-mail from him with a > link from which I was able to download a working version for Mac OS X. > I was very pleased and immediately started using it in my lectures (by > that time at a different university and on a different topic). Soon > after that an announcement from WRI appeared in the MathGroup to the > effect that MathGL3d was now a commercial (and not very cheap) package > sold by Wolfram Research. In effect I got a fairy expensive present, > which I would never had asked for if I had known about it. In fact this was very typical of Jens-Peer - he helped people in such > a unpretentious and undemanding way that one often did not appreciate > that there was a cost in it for him. Jens-Peer was, by the way, a research professor at the University of > Lepipzig, one of the oldest universities in Europe located in the city > of Johann Sebastian Bach. His manner was, however, so direct and > unpretentious that probably only a few of the many MathGroup users > whose questions he answered ever realized it. Andrzej Kozlowski > > > > >> >> I am sorry to inform you that Jens-Peer Kuska passed away last week. >> He was 45 years old. >> >> I have known Jens-Peer since the early 80s when we both studied >> physics >> at the Humboldt University in Berlin. Our departments were on opposite >> sides of the first floor hallway. >> >> After Germany's reunification and the availability of more computers >> and software, Jens-Peer's favorite program soon become Mathematica. >> And he evolved to be a true expert of it. >> >> His broad and detailed mathematics and physics knowledge allowed >> Jens to cover new areas in computer graphics with his OpenGL viewer >> and in his work on medical image processing. >> >> Most of the Mathgroup readers know Jens-Peer from his short, to the >> point, >> helpful, stimulating contributions to Mathgroup, where he >> contributed so >> many times for more than 10 years. >> >> >> >> And the German-speaking Mathematica user knew him additionally from >> his >> many contribution to the German Mathematica user group: >> >> +site:www.mathematica.ch&hl=en&fp=1&cad=b >> >> Jens-Peer was a brilliant Mathematica (and in general) programmer who >> was able to code complicated algorithms efficiently and elegantly. His >> reservoir of ideas what to implement, calculate, investigate, or >> visualize was virtually unlimited. >> >> For the ones that were fortunate to know him in person and discuss >> Mathematica, mathematics, physics, or image-processing issues with >> him, >> know the value of his deep, critical, and constructive opinions and >> contributions. >> He loved to discuss so many different topics, ranging from >> Fullform[]s of >> Mathematica graphics expressions to shape-characteristics of averaged >> Wigner functions of quantum systems and the use of partial >> differential >> equations to image processing tasks. >> We all will miss such discussions with him in the future. >> >> Jens-Peer will be missed by the Mathematica community, his university >> department >> (http://www.izbi.uni-leipzig.de/englisch/izbi/mitarbeiter/kuska.php), >> his former students, his friends, and of course, his family. >> >> Michael Trott >> Wolfram Research > > === Subject: Re: Jens-Peer Kuska passed away Jens-Peer death is a big loss, unimaginable for his family, hard to realize for his friends and colleauges. He was a clear person. Unpretending in his outer appearence (I saw him only once with a tie, when we were asking project-money from some state investment bank, and he immediately took it off when we were finished), but always with a sharp intellect and great humor. I met him first in 1996 in Berlin, while touring Germany together with Michael Trott in the MathMobile. Since then we met often, mostly professionally, but also privately. We for the european commision, met at conferences and workshops and he also helped me once with a difficult economic consulting project for the Office of Fair Trade. I always enjoyed meeting, working and talking with him. Maybe it is not too personal to mention in this group that I was most impressed by the way he interacted with his son. So I hope he will cope as well as possible with this hard loss. He truly can be proud of his father. I am glad I knew Jens-Peer and I will always remember his very special way of being. Rolf Mertig GluonVision GmbH, Berlin, Germany === Subject: Re: Jens-Peer Kuska passed away I am terribly sorry to hear about this. I am writing a book where Mathematica plays an important role. Kuska's name, among others regulars here, did come across my mind when I think about Acknowledgement. He was always among the first who helped. Jens-Peer will be sorely missed. Michuco === Subject: Re: Jens-Peer Kuska passed away I too am very shocked to hear of the tragic news of Jens-Peer Kuska. I benefited a lot from his posts, in particular when I began using Mathematica first. Often, my idiosyncratic questions would produce just a single reply, that being from Jens-Peer. His responses were without exception insightful and to the point, and always enriched my understanding of Mathematica. He seemed to have the knack of knowing exactly where you were at with Mathematica, and of telling you exactly what you needed to know. Thomas Dowling I am sorry to inform you that Jens-Peer Kuska passed away last week. > He was 45 years old. I have known Jens-Peer since the early 80s when we both studied physics > at the Humboldt University in Berlin. Our departments were on opposite > sides of the first floor hallway. After Germany's reunification and the availability of more computers > and software, Jens-Peer's favorite program soon become Mathematica. > And he evolved to be a true expert of it. His broad and detailed mathematics and physics knowledge allowed > Jens to cover new areas in computer graphics with his OpenGL viewer > and in his work on medical image processing. Most of the Mathgroup readers know Jens-Peer from his short, to the point, > helpful, stimulating contributions to Mathgroup, where he contributed so > many times for more than 10 years. > > And the German-speaking Mathematica user knew him additionally from his > many contribution to the German Mathematica user group: > > Jens-Peer was a brilliant Mathematica (and in general) programmer who > was able to code complicated algorithms efficiently and elegantly. His > reservoir of ideas what to implement, calculate, investigate, or > visualize was virtually unlimited. For the ones that were fortunate to know him in person and discuss > Mathematica, mathematics, physics, or image-processing issues with him, > know the value of his deep, critical, and constructive opinions and > contributions. > He loved to discuss so many different topics, ranging from Fullform[]s of > Mathematica graphics expressions to shape-characteristics of averaged > Wigner functions of quantum systems and the use of partial differential > equations to image processing tasks. > We all will miss such discussions with him in the future. Jens-Peer will be missed by the Mathematica community, his university > department > (http://www.izbi.uni-leipzig.de/englisch/izbi/mitarbeiter/kuska.php), > his former students, his friends, and of course, his family. Michael Trott > Wolfram Research > === Subject: Re: Jens-Peer Kuska passed away Returning to the group after a couple of days off, I read this shocking and rather unexpected news. If there would be one constant factor in life, it would be Jens-Peer's presence here. I'll miss his typical reply template: ... and doesn't work ?? My condoleances and thoughts go to his family and friends. Sjoerd I am sorry to inform you that Jens-Peer Kuska passed away last week. > He was 45 years old. I have known Jens-Peer since the early 80s when we both studied physics > at the Humboldt University in Berlin. Our departments were on opposite > sides of the first floor hallway. After Germany's reunification and the availability of more computers > and software, Jens-Peer's favorite program soon become Mathematica. > And he evolved to be a true expert of it. His broad and detailed mathematics and physics knowledge allowed > Jens to cover new areas in computer graphics with his OpenGL viewer > and in his work on medical image processing. Most of the Mathgroup readers know Jens-Peer from his short, to the point= , > helpful, stimulating contributions to Mathgroup, where he contributed so > many times for more than 10 years. > . And the German-speaking Mathematica user knew him additionally from his > many contribution to the German Mathematica user group: > ... Jens-Peer was a brilliant Mathematica (and in general) programmer who > was able to code complicated algorithms efficiently and elegantly. His > reservoir of ideas what to implement, calculate, investigate, or > visualize was virtually unlimited. For the ones that were fortunate to know him in person and discuss > Mathematica, mathematics, physics, or image-processing issues with him, > know the value of his deep, critical, and constructive opinions and > contributions. > He loved to discuss so many different topics, ranging from Fullform[]s of > Mathematica graphics expressions to shape-characteristics of averaged > Wigner functions of quantum systems and the use of partial differentia= l > equations to image processing tasks. > We all will miss such discussions with him in the future. Jens-Peer will be missed by the Mathematica community, his university > department > (http://www.izbi.uni-leipzig.de/englisch/izbi/mitarbeiter/kuska.php), > his former students, his friends, and of course, his family. Michael Trott > Wolfram Research === Subject: Re: Manipulating list Kosal, First, let's change your second list to use small case letters. Mathematica always uses an initial capital for its own symbols and by starting our symbols with small case letters we know we won't inadvertently use a built-in Mathematica symbol. Specifically, in Mathematica I stands for the unit imaginary number. list1 = {{a, b, c}, {d, e, f}, {g, h, i}}; list2 = {{1, 2}, {3, 4}, {5, 6}}; Then we can combine your two list by the following: MapThread[Prepend[#2, Last[#1]] &, {list1, list2}] {{c, 1, 2}, {f, 3, 4}, {i, 5, 6}} MapThread is a functional programming command. If you haven't seen these before they are a little difficult at first but well worth learning because they are so nice. MapThread generates elements of a new list by working itself through the two lists by pairs. Look it up in Help. Prepend[#2, Last[#1]] & is a pure function (Look up Function in Help) that instructs Mathematica how to combine the elements of the two lists. #1 stands for an element from the first list, {a,b,c} say, and #2 stands for an element from the second list, {1,2} say. So Prepend[{1,2},Last[{a,b,c}] gives {c,1,2} etc. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal === Subject: Re: Manipulating list In[6]:= Transpose[{list1, list2}] /. {{__, x_}, {y__}} :> {x, y} Out[6]= {{C, 1, 2}, {F, 3, 4}, {I, 5, 6}} In[7]:= MapThread[{Last[#1], Sequence @@ #2} & , {list1, list2}] Out[7]= {{C, 1, 2}, {F, 3, 4}, {I, 5, 6}} Adriano Pascoletti 2009/7/8 kosal lee to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, > C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal > > === Subject: Re: Manipulating list > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like > you to help me. Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 > (that is, C,F,I) to appear in the first position in each member list > in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal > This should work: Flatten /@ Thread[{list1[[All, 3]], list2}] -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Manipulating list MapThread[Prepend, {list2, list1[[All, 3]]}] or Flatten /@ Transpose[{list1[[All, 3]], list2}] or Module[{copy = list1}, copy[[All, {1, 2}]] = list2; RotateRight[copy, {0, 1}]]] will do what you want. There are also many other ways of course. Note that on (very) large lists, the last solution is by far the most efficient of those I listed (20 - 25 x faster on lists of length 100000 according to my tests). Leonid > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you > to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, > C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal > > === Subject: Re: Manipulating list list1 = {{A, B, C}, {D, E, F}, {G, H, I}}; list2 = {{1, 2}, {3, 4}, {5, 6}}; MapThread[Prepend[#2, Last@#1] &, {list1, list2}] {{C, 1, 2}, {F, 3, 4}, {I, 5, 6}} or Prepend @@@ Transpose@{list2, list1[[All, -1]]} {{C, 1, 2}, {F, 3, 4}, {I, 5, 6}} Bobby > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like > you to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that > is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal > -- DrMajorBob@bigfoot.com === Subject: Re: Manipulating list > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal MapThread[Flatten[[{#1[[3]],#2}&,{list1,list2}] is one way. {list1[[All, 3]], list2[[All, 1]], list2[[All, 2]]} // Transpose is another Mike === Subject: Re: Manipulating list Many possibilities here, but Join[List /@ list1[[All, 3]], list2, 2] will do the trick. /@ is shorthand infix notation for Map and list1 [[All, 3]] means the set of 3rd elements of all rows. By the way. All of the Mathematica reserved words and symbols start with an uppercase letter. In your example the C, D, E, and I are reserved. > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal === Subject: Re: Manipulating list There are many ways to do that, but I thought it might be instructive to try something using functional programming, which is essential for a sound understanding of the power of Mathematica: In[1]:= MapThread[Prepend,{list2,Last/@list1}] Out[1]= {{C,1,2},{F,3,4},{I,5,6}} Tomas Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal > === Subject: Re: Manipulating list > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal Kosal, Refrain from using capital variables; some of them are reserved (C,D,E,I are reserved!). This very specific example could be solved in the following way: myfunc[a_, b_] := Prepend[b, a[[-1]]] list1 = {{a, b, c}, {d, e, f}, {g, h, i}}; list2 = {{1, 2}, {3, 4}, {5, 6}}; MapThread[myfunc, {list1, list2}] Sander === Subject: Re: Manipulating list > Hello Mathematica users I am new to Mathematica and I have one particular problem I would like yo= u to help me. > Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} > list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that i= s, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal Here is one solution (I've changed to lower case as some capital case letters are variables in Mathematica e.g. I for imaginary part) list1 = {{a, b, c}, {d, e, f}, {e, h, i}}; list2 = {{1, 2}, {3, 4}, {5, 6}}; Flatten /@ Thread@List[list1[[All, 3]], list2[[All, 1 ;; 2]]] Mac === Subject: Re: Manipulating list That's what you have: list1 = {{A, B, C}, {D, E, F}, {G, H, II}} list2 = {{1, 2}, {3, 4}, {5, 6}} This gives you the list of last elements of the first list (II instead of I, since I is the imaginary unity): In[29]:= Last /@ list1 Out[29]= {C, F, II} Then this solves your problem: In[28]:= MapThread[Append, {list2, Last /@ list1}] Out[28]= {{1, 2, C}, {3, 4, F}, {5, 6, II}} Have fun, Alexei Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal -- 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: Selecting Rows Based on Column Values On Jul 9, 1:58 am, Adriano Pascoletti > #[[All,3]] means the thirdcolumnof an array, and your triples are > one-dimensional objects...Use #[[3]]: In[2]:= Select[tester, #[[3]] == 1 &] > Out[2]= {{1, 3, 1}, {4, 2, 1}} Another approach In[3]:= Cases[tester, {_, _, 1}] > Out[3]= {{1, 3, 1}, {4, 2, 1}} Adriano Pascoletti 2009/7/8 cynthia wu > I've been trying to use the Select Command to select only therows > > that have the a specific value in a specificcolumn. I have, for > > example, the following matrix (4x3): > tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} > I want to select therowsthat havevalues==1 in the 3rdcolumn. > > I've tried: > select(tester, #[[All,3]]==1&), but I get an error saying that my > > request violates the matrix boundaries. > The desired output should be: {{1,3,1}, {4,2,1}}. > === Subject: Re: Selecting Rows Based on Column Values >I've been trying to use the Select Command to select only the rows >that have the a specific value in a specific column. I have, for >example, the following matrix (4x3): >tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}} >I want to select the rows that have values ==1 in the 3rd column. >I've tried: >select(tester, #[[All,3]]==1&), but I get an error saying that my >request violates the matrix boundaries. >The desired output should be: {{1,3,1}, {4,2,1}}. You are close. What the selector operates on is an individual row of your matrix. So instead of #[[All,3]]==1& all you need is #[[3]]==1& Any of the following do what you want In[2]:= Select[tester, #[[3]] == 1 &] Out[2]= {{1, 3, 1}, {4, 2, 1}} In[3]:= Select[tester, Last[#] == 1 &] Out[3]= {{1, 3, 1}, {4, 2, 1}} In[4]:= Cases[tester, {__, 1}] Out[4]= {{1, 3, 1}, {4, 2, 1}} === Subject: Re: GeoDistance and transformation from WGS84 to WGS84 On Jul 9, 12:55 am, Sjoerd C. de Vries distance between two points on the earth with given latlong > coordinates. WGS84 is the datum used for GPS, if I'm not mistaken. In[86]:= GeoDistance[GeoPosition[{1, 0}, WGS84], GeoPosition[{0, > 0}, WGS84]] During evaluation of In[86]:= GeoDistance::datum: No direct > transformation between datums WGS84 and WGS84 is available. >> Out[86]= GeoDistance[GeoPosition[{1, 0}, WGS84], > GeoPosition[{0, 0}, WGS84]] The More Information box of GeoPosition specifically states that > WGS84 is one of the allowed datums. However, GeodesyData[Datum] and > GeodesyData[ReferenceEllipsoid] make clear that WGS84 is not a > datum, but a reference ellipsoid (WGS72 seems to be both). I don't know *why* it doesn't work, but if you change WGS84 to WGS84Original it does work: In[255]:= GeoDistance[GeoPosition[{1, 0}, WGS84Original], GeoPosition[{0, 0}, WGS84Original]] Out[255]= 110574. -Rob === Subject: Re: Jens-Peer Kuska-> honor his memory too! Better to honor them while they are alive: two who post answers here who are the best programmers that I know: Daniel Lichtbau Bob Hanlon === Subject: Symbolic summation Hello all, I have a problem, I've to compute a symbolic summation, which takes a very long time if I have to do it by hand. I have to write the terms of the Volterra series, related to the associated linear equation of a system. The problem is that I'm not really confident with mathematica, I've tried to use symbolic calculations with sums, but I think that in my case is not so easy. The problem is that I want a solution of this form: x1+x2+x3+x4+x5... Where the 1, 2, 3 and 4 and 5 are the summation subscripts... My summation is not infinite, I have to stop it. If I write something like this: n = 3; Sum[kl, {l, 2, n}] I obtain 2kl, instead I want to obtain k2+k3. Is it possible with mathematica? === Subject: Re: TimeZones I reported this as a bug some while ago... It's in the WRI bugs system. Best, David > Why is this unavailable? CityData[{Austin, Texas, UnitedStates}, TimeZone] Missing[NotAvailable] Bobby -- > DrMajor...@bigfoot.com === Subject: Re: Is it possible to impose a condition on an iterator Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] - Sum[a^2 - 3 a/(4 a^2), {a, 7, 11}] 69209343871/28217280 Sum[a^2 - 3 a/(4 a^2), {a, Drop[Range[1, 20], {7, 11}]}] 69209343871/28217280 % == %% True Bob Hanlon I would like to perform a summation of this type, Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] excluding however some values of the iteratore, I would for instance like to exclude the values than to greater of 6 and inferior to 12. Is it possible? === Subject: Re: Jens-Peer Kuska passed away I checked my email archives and see that I have been corresponding with Jens for well over a decade. In every note a friendly and appreciative manner. It is a pleasure to reread them, especially those where he corrects mistakes of mine. My warm condolences go out to his family and personal friends. --David === Subject: Wolfram alpha official demo! LOL Checking the official W/A blog I found the following video http://www.youtube.com/watch?v=pvngZAx1-PU&eurl=http%3A%2F%2Fblog.wolframalp ha.com%2F&feature=player_embedded (the link is to You Tube, but I got there from W/A Blog) It is funny, because it is supposed to show off what W/A is capable of finding, but it turns out to show off what W/A is NOT capable of! === Subject: Export to Excel without the brackets {} getting the brackets {} around the data inside of each Excel cell? === Subject: Re: stirring chocolate pudding backwards: identifying coordinates > I think I need to better illustrate my problem. Let's try this: values = Array[v## &, {3, 3}]; > values = MatrixForm[values] The above generates: 3 time intervals in 3 dimensions. > values is a times series. Time runs down the matrix. samples = Array[s## &, {4, 3}]; > samples = MatrixForm[samples] The above generates 4 sample points in 3 dimensions. > samples is not a time series. Each of the numbers in each row of the samples matrix > represents a percent as well as a coordinate. The total of > each row in samples always equals 1. In the real world > they could represent proportions of 3 fluids in a mixture > or perhaps percentages of 3 assets in a portfolio. Each of the numbers in values represents an amount relative > to some original value. They are independent measurements and > must be >=0. The number of columns in each of the two matrices needs to > correspond. The number of rows does not. In its planned application, I might sample 1,000 or even 1,000,000 > coordinates to better get an approximation of the weighted average > of the sample space. Next we generate a time series (corresponding to the time > increments in values) of weighted averages of the samples > where the weights stand in proportion to the measurements > in each column at each interval in the time series values: values.Mean[samples] Still, so far so good (and much speeded up from my original code Now, back to my original representation of the space from which > I select samples: sampleSimplex[sampleSize_, dimensions_] := Normalize[#, Total]& /@ > RandomReal[ExponentialDistribution[2], {sampleSize, dimensions}] The following graphs the coordinates of the samples > so you can see what the sampleSimplex[] function does: Graphics3D[Point /@ sampleSimplex[1000, 3, 0, 1], > ImageSize -> 250, ViewPoint -> {Pi, Pi/2, 2}] Instead of trying to calculate from the entire simplex (the > triangle defined by coordinates: {{1,0,0},{0,1,0},{0,0,1}}), > I sample from a finite set of points. The entire simplex would > represent all possible mixtures. An aside, I wonder if Mathematica has a way for me to do this > continuously rather than messing around with sampling? I still > have a lot to learn. Using my original post's example: samples = {{0.375153,0.412505,0.212342}, > {0.470678,0.360788,0.168533}, > {0.0510186,0.828575,0.120407}, > {0.24481,0.00851303,0.746677}} values = {{0.518072,0.490701,0.813364}, > {0.404083,0.356724,0.362498}, > {0.507292,0.436016,0.247148}} values.Mean[samples] {0.599181, 0.372042, 0.397434} I want to identify the coordinates on the plane (from which I > select samples) for each of these three weighted averages. > The plane has an infinite number of points so at least one must > have the same individual value as the weighted average of the > sample. More generally, this point should vary, over time, across > the plane (especially as, in its projected application, I'll have > values for thousands of time increments and they may have far > greater variance than my simple example). Also, it seems like it > wouldn't have to correspond to any specific point in the list of > samples. I hope this makes the problem clearer. > For any set of values, the weighting scheme you describe will always give an average that would be observed at the mean (centroid) of the simplex. If this is counter-intuitive then perhaps you should reconsider the weighting. === Subject: Re: Manipulate not working What do you mean when you say that Manipulate is choking on the Manipulate? I tried this with Mathematica 7.0.1 on a PC with a 3 GHz I evaluated the Input cell, I could open the output's play controls, click the Play button, and have the graphics cycle through all the values of k in approximately 5 seconds. > > Manipulate[f[z_] := z^2 - 4*z + k; > rpts = Graphics3D[{PointSize[0.02], Red, > Point @@ {({Re[#1], Im[#1], 0} & ) /@ > (z /. Solve[f[z] == 0, z])}}]; > p1 = ParametricPlot3D[{Re[z], Im[z], Re[f[z]]} /. z -> x, > {x, 0, 4}, PlotStyle -> {Thickness[0.008], Yellow}]; > p2 = Plot3D[Re[f[z]] /. z -> x + I*y, {x, 0, 4}, > {y, -4, 4}, PlotRange -> {{0, 4}, {-2, 2}, {-5, 5}}, > PlotStyle -> {LightPurple}]; > cp1 = ContourPlot[Re[f[x + I*y]] == 0, {x, 0, 4}, > {y, -2, 2}]; lns = Cases[Normal[First[cp1]], > Line[pts_] :> ({#1[[1]], #1[[2]], 0} & ) /@ pts, > {0, Infinity}]; realcontour = > Show[Graphics3D[{Thickness[0.008], Purple, > Line @@ {lns}}], PlotRange -> {{0, 4}, {-2, 2}, > {-5, 5}}]; cp2 = ContourPlot[Im[f[x + I*y]] == 0, > {x, 0, 4}, {y, -2, 2}]; lns = Cases[Normal[First[cp2]], > Line[pts_] :> ({#1[[1]], #1[[2]], 0} & ) /@ pts, > {0, Infinity}]; imagcontour = > Show[Graphics3D[{Thickness[0.008], Green, > Line @@ {lns}}], PlotRange -> {{0, 4}, {-2, 2}, > {-5, 5}}]; realdiagram = > Show[{p2, p1, realcontour, imagcontour, rpts}, > PlotRange -> {{0, 4}, {-2, 2}, {-5, 5}}, > Lighting -> Neutral, BoxRatios -> {1, 1, 1}, > AxesLabel -> {Style[x, 20], Style[y, 20], > Style[Re, 20]}, AxesEdge -> {{-1, -1}, {1, -1}, > {1, 1}}, ImageSize -> {500, 500}], {k, -5, 5, 1}] > -- 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: Is it possible to impose a condition on an iterator of the summation ? >I would like to perform a summation of this type, >Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] >excluding however some values of the iteratore, I would for instance >like to exclude the values than to greater of 6 and inferior to 12. >Is it possible? I sounds like you want to do the sum for a = 7 to 11 which is easily done as: Sum[a^2 - 3 a/(4 a^2), {a, 7, 11}] But since this seems so obvious, perhaps I've misunderstood your issue. === Subject: Re: Add syntax highlighting to own command Hi Bastian, While I won't be able to authoritatively answer most of your questions, I would not place your function into a System` context. What I would do is to place your function into a separate package with its own context, and make that package autoloadable. I am not a big expert on this, I am pretty sure you will get great advice from other people here. As for the highlighting, I would also very much like to learn if this can be extended to user-defined functions. Regarding your code, I think it is a very clever piece. I don't know why you would want to improve it - it seems quite a piece of art to me. I was first somewhat surprised that it works. I think it very cleverly uses the fact that RuleDelayed, being a scoping construct, does not respect the possible colliding variables in inner scoping constructs (like With here) and in this respect is different from other scoping constructs such as Module, Block, With, or Function (thus your substitution works as intended, instead of internal variables simply being renamed). Sorry if I wasn't exactly helpful. Leonid > I was missing a scoping construct like 'With' but where the local > variables get assigned linearly. E. g. In[1] := LinearWith[ { > b = a <> there! }, > Print[ b ] ] > I'm fairly new to Mathematica, but I know some Lisp, and somehow I got > it. I called my new construct Let and defined it as: Let[ vars_, expr_ ] := > If[ Length[ Unevaluated[ vars ] ] == 1, > With[ vars, expr ], > (* else *) > Unevaluated[ vars ] /. > { a_, b__ } : With[ { a }, > Let[ { b }, expr ] ] ] SetAttributes[ Let, HoldAll ] It seems to work fine so far. Now, I would like to have this construct load always when I start > Mathematica and I don't want to get it cleared when I use > 'Clear[Global`*]'. So I put it in the System` context and also added > wonder where to put it that it gets read automatically at each startup > of Mathematica. However, my first question: Is it a bad idea to add things to the > System` context? And if not, where to put my file? And if, what would > be better? Second, my main question: Is it somehow possible to add this nice syntax > highlighting to the Let construct like with the With construct, where > the local variables appear in green? Third: Can I somehow add a help page? I have already the Let::usage. And last: Does anybody know how to make the construct better? Is there > something like syntax transformation rules in Mathematica? Bastian > > === Subject: Re: matrix equation Daniel, thank you for your suggestion! Haibo Hi Haibo, > here is a simpler example that shows the essentials. > Daniel > f[t_] := {{t , t^2}, {t^2, 3 t}}; > eq = {f[t] == a[t] .f'[t], a[0] == {{0, 0}, {0, 0}}}; > y = a /. NDSolve[eq, a, {t, 0, 0.5}][[1]]; > Plot[y[t], {t, 0, .5}] > > >> Suppose T is a inversible matrix, and its elements are functions of t. >> Consequently, we may denote this matrix as T[t], and its first and second >> derivative is denoted as T'[t] and T''[t]. >> I want to solve a equation as follows: >> (A+B)T+T'==(a+b)T+2T', (A+B)T'+aBT==aT'+(ab+b)T+T''; >> where a,b are known constants, and A,B is what I want to get. >> How to express it in matrix form and solve it? >> >> >> > > === Subject: Re: Manipulating list To all who answered my question about manipulating list. I want to say thank you very much. Kosal ________________________________ === Subject: Re: Manipulating list MapThread[Prepend, {list2, Last /@ list1}] Prepend @@@ Thread[{list2, Last /@ list1}] Flatten /@ Thread[{Last /@ list1, list2}] Bob Hanlon Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal === Subject: Re: Manipulating list > MapThread[Prepend, {list2, list1[[All, 3]]}] > > or > > Flatten /@ Transpose[{list1[[All, 3]], list2}] > > or > > Module[{copy = list1}, copy[[All, {1, 2}]] = list2; RotateRight[copy, {0, > 1}]]] > > will do what you want. There are also many other ways of course. Note > that on (very) large lists, the last solution is by far the most efficient > of those > I listed (20 - 25 x faster on lists of length 100000 according to my tests). Even faster: Transpose[ Prepend[ Transpose[ list2 ], list1[[ All, 3 ]] ] ] Bastian === Subject: Re: Manipulating list >I am new to Mathematica and I have one particular problem I would >like you to help me. Suppose I have two lists: >list1 = {{A,B,C},{D,E,F},{G,H,I}} list2 = {{1,2},{3,4},{5,6}} >I want to have the third elements in each of member list in list1 >(that is, C,F,I) to appear in the first position in each member list >in list2 >that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Here are a couple of ways to accomplish what you want In[1]:= list1 = {{a, b, c}, {d, e, f}, {g, h, i}}; list2 = {{1, 2}, {3, 4}, {5, 6}}; In[4]:= MapThread[Join[{Last@#1}, #2] &, {list1, list2}] Out[4]= {{c, 1, 2}, {f, 3, 4}, {i, 5, 6}} In[6]:= ArrayFlatten@{{List /@ list1[[All, 3]], list2}} Out[6]= {{c, 1, 2}, {f, 3, 4}, {i, 5, 6}} Note, I changed the variable names from uppercase to lowercase. In general, it is not a good idea to use single uppercase letters as variable names since will often conflict with built-in symbols. Specifically, both E and I have built-in meaning. If you make a habit of naming your functions and variables so that the first letter is lower case, you are guaranteed not to have a conflict with built-in objects. === Subject: Shortcut for Power Hi! what do i have to press if i want lets say x^2? i mean in want to have the 2 as superscript and not the ^. I use MacOS btw... === Subject: Re: Calculate n in binomial distribution Hi Peter, I think there is a bug in Minimize for the Integer domain. Consider: Minimize[(x - 6.1)^2, x, Integers] giving: {1.21, {x -> 5}} Minimize[(x - 6.)^2, x, Integers] giving: {1., {x -> 5}} Minimize[(x - 6)^2, x, Integers] giving: {0, {x -> 6}} Minimize seems to have problems mixing integers and reals. I think you should report this to Wolfram. Daniel > Suppose I have the following distribution: > > cf[n_,p_,k_]=CDF[BinomialDistribution[n,p],k] > > Now I want to calculate n so that the biggest n such that e.g. > > cf[n,0.2,7]<0.3 > > I made a ListPlot > > ListPlot[Abs[cf[#,0.2,7]-0.3]&/@Range[60]], where I see, that a value of > about n=46 gives an approximation nearest to 0.3 > > To get this value of n I tried > > Minimize[{Abs[cf[n,0.2,7]-0.3],n>7},n,Integers] > > Out: {0.699765, {n->11}} > > which is obviously wrong. > > Why? > > Is it, because Abs isn't differentiable at the peak? > > I tried other ways too, like Reduce NMinimize, FindMinimum, but no success. > === Subject: Re: BarChart and ChartStyle Hi Don, > How can I use the ChartStyle option to get the second bar to be LightGreen? This doesn't work: BarChart[{{16, 8}, {5, 3}}, BarSpacing -> -.5, > ChartStyle -> {{LightGray, LightGreen}, {LightGray, LightRed}}] and this doesn't work BarChart[{{16, 8}, {5, 3}}, BarSpacing -> -.5, > ChartStyle -> {LightGray, LightGreen, LightGray, LightRed}] > > > BarChart[{{16, 8}, {5, 3}}, ChartStyle -> {LightGray, LightGreen}] or BarChart[{{16, 8}, {5, 3}}, ChartStyle -> {{LightGray, LightGreen}, None}] or BarChart[{{16, Style[8, LightGreen]}, {5, 3}}, ChartStyle -> LightGray ] Oliver === Subject: Jens Obviously all comments on the death of Jens-Peer indicate his helping hands. I can affirm this also. When the learning software M@th Desktop was in its beta stadium Jens offered his advice to improve the software. I met him personally on the IMS 08 in Maastricht. He was a very friendly and talkative person. When we went by bus to the dinner for the celebration of the 20th birthday of Mathematica, he gave me hints how to convert help browser files to the new paclet structure. Jens told nice stories about his family especially his son. He liked him so miuch. I would like to express my sincere condolences for his family. Personally I will pray for him and offer a holy mass, simply to say thank you for the services he offered to us. -Reinhard -- ******************************************** Dr. Reinhard Simonovits Handelsakademie | Karl Franzens University Math Department | Inst. for Mathematics Grazbachgasse 71 | Heinrichstrasse 36 A-8010 Graz, Austria Email: Reinhard.Simonovits@uni-graz.at ********************************************* === Subject: Re: about Implication I think ImpliesQ uses CylindricalDecomposition and quantifier elimination to test the implication between two statements involving polynomial expressions in the same variables. Thus everything it can do can also be done with Reduce. Let's take trivial example: Experimental`ImpliesQ[x>3,x>2] During evaluation of In[9]:= Experimental`ImpliesQ::obs: Experimental`ImpliesQ has been superseded by Refine, and is now obsolete. It will not be included in Mathematica version 8. >> True This could be done with Reduce: Reduce[Not[x > 2] && x > 3] False However, Reduce will attempt to use many more methods than InpliesQ and therefore will tend to be slower. But, as we can see, Mathematica 7 itself tells you the answer to your question (how come you did not see it?): use Refine. So, the above examples can be done as follows: Refine[Not[x > 2], x > 3] False Actually, the above example belongs to ImpliesRealQ, a more specialized version of ImpliesQ. The following is an example that won't be done by ImpliesRealQ: In[3]:= Experimental`ImpliesQ[Element[x, Reals], Element[x, Complexes]] During evaluation of In[3]:= Experimental`ImpliesQ::obs:Experimental`ImpliesQ has been superseded by Refine, and is now obsolete. It will not be included in Mathematica version 8. >> Out[3]= True So ImpliesRealQ is also obsolete and indeed Refine is an equally efficient way to do this example: Refine[Element[x, Complexes], Element[x, Reals]] True Of course Simplify will also work but, just as Reduce, it is less efficient. Andrzej Kozlowski > Hi mathematica community, > when trying to use the function ImpliesQ (that tests if exp1 implies > exp2 or not) mathematica show me a message telling that this function > becomes obsolete and will disappear in mathematica8, could you tell me > why? and by which function it is replaced. > NB:Implies doesnt do the same thing as ImpliesQ. > thank you. > === Subject: Re: about Implication >Hi mathematica community, when trying to use the function ImpliesQ >(that tests if exp1 implies exp2 or not) mathematica show me a >message telling that this function becomes obsolete and will >disappear in mathematica8, could you tell me why? and by which >function it is replaced. NB:Implies doesnt do the same thing as >ImpliesQ. thank you. In the current release version of Mathematica that runs on Mac OS X, In[2]:= $Version Out[2]= 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) there is no built-in function named ImpliesQ. And I strongly suspect anyone who posts here that has actual knowledge of what future versions of Mathematica will look like is not free to post those details here. === Subject: Re: Manipulating list MapThread[Prepend, {list2, Last /@ list1}] Prepend @@@ Thread[{list2, Last /@ list1}] Flatten /@ Thread[{Last /@ list1, list2}] Bob Hanlon Hello Mathematica users I am new to Mathematica and I have one particular problem I would like you to help me. Suppose I have two lists: list1 = {{A,B,C},{D,E,F},{G,H,I}} list2 = {{1,2},{3,4},{5,6}} I want to have the third elements in each of member list in list1 (that is, C,F,I) to appear in the first position in each member list in list2 that is, i want to have list ={{C,1,2},{F,3,4},{I,5,6}} Kosal === Subject: Re: sparsearray bug? >In[494]:= SparseArray[{1}]/SparseArray[{1}] >During evaluation of In[494]:= Power::infy: Infinite expression 1/0 >encountered. >> During evaluation of In[494]:= [Infinity]::indet: >Indeterminate expression 0 ComplexInfinity encountered. >> >Out[494]= SparseArray[<1>,{1},Indeterminate] What were you expecting and why would you ever divide one sparse array by another? Consider for normal arrays the following: In[3]:= x = RandomReal[1, {2, 2}] Out[3]= {{0.980046, 0.324877}, {0.587326, 0.387608}} In[4]:= y = RandomReal[1, {2, 2}] Out[4]= {{0.554456, 0.960964}, {0.162428, 0.976886}} In[5]:= x/y Out[5]= {{1.76758, 0.338074}, {3.61592, 0.396779}} Since the divide operation does an element by element divide you should expect the same behavior when dividing a sparse array by another sparse array. But by definition a sparse array has a great many elements with value 0. So, an element by element divide will inevitably mean dividing by 0. Admittedly, this explanation doesn't totally explain your result above since SparseArray[{1}] is the one element array {1}. Possibly the code that does the element by element divide does not look to see that SparseArray[{1}] isn't really a sparse array in the since there are no zero elements. But even if this is a bug (meaning the results are different than intended) it still leaves the question of why would you be doing this kind of division? === Subject: arbitrary size kernel while I understand a bit the logic behind filtering in the frequency domain, I have a problem with filtering by convolution. I'd like to understand how to construct arbitrary-size kernels: which are the requirements? Specifically, I need to build the kernel of a high-pass filter able to filter everything below some freq f_0. My problem is that all the descriptions I found are usually for kernels in the 3x3 form, e.g. ((0.0, -1.0, 0.0),(-1.0, 5.0, -1.0),(0.0, -1.0, 0.0)) What I cannot understand is: which is the relationship between the cutoff frequency and a given kernel shape? The kernel size? The step between central element and side elements? alessandro === Subject: Re: Is it possible to impose a condition on an iterator of In[6]:= r1 = Sum[a^2 - 3*(a/(4*a^2)), {a, {1, 2, 3, 4, 5, 13, 14, 15, 16, 17, 18, 19, 20}}]; In[7]:= r2 = Sum[a^2 - 3*(a/(4*a^2)), {a, DeleteCases[Range[20], i_ /; i >= 6 && i <= 12]}]; In[8]:= r3 = Sum[If[a >= 6 && a <= 12, 0, a^2 - 3*(a/(4*a^2))], {a, 1, 20}]; Out[9]= True In[10]:= r1 Out[10]= 64135524211/28217280 Adriano Pascoletti 2009/7/9 Mauro like to exclude the values than to greater of 6 and inferior to 12. Is > it possible? > > > === Subject: Re: Is it possible to impose a condition on an iterator Hello Mauro, > I would like to perform a summation of this type, Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] excluding however some values of the iteratore, I would for instance > like to exclude the values than to greater of 6 and inferior to 12. Is > it possible? > > > how about: f[a_] := If[6 <= a <= 12, 0, a^2 - 3 a/(4 a^2)] Sum[a^2 - 3 a/(4 a^2), {a, 1, 5}] + Sum[a^2 - 3 a/(4 a^2), {a, 13, 20}] Oliver === Subject: Re: Is it possible to impose a condition on an iterator of A follow - up to my previous post (particularly the conditionalSum function): there is of course a much simpler and much faster solution: ClearAll[conditionalSumAlt]; SetAttributes[conditionalSumAlt, HoldAll]; conditionalSumAlt[expr_, test_, iterators__] := Sum[expr*If[test, 1, 0], iterators]; Perhaps, I have been playing too much with introspection recently. Sorry if that was confusing. Best, Leonid > I would like to perform a summation of this type, Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] excluding however some values of the iteratore, I would for instance > like to exclude the values than to greater of 6 and inferior to 12. Is > it possible? > > > === Subject: Re: Is it possible to impose a condition on an iterator of Hi Mauro, You can use the particular syntax of Sum which allows to supply a list of values to be summed over: In[1] = With[{iterlist = Select[Range[1, 20] , # <= 6 || # >= 12 &]}, Sum[a^2 - 3 a/(4 a^2), {a, iterlist}]] Out[1] = 69209343871/28217280 This is however not very general. What if, for instance, you need to do a multi-dimensional sum and exclude some points according to the test that mixes different coordinates (iteration variables). Here is my attempt to implement a function with such additional functionality but with the standard iterator syntax of Sum: In[2] = ClearAll[conditionalSum]; SetAttributes[conditionalSum, HoldAll]; conditionalSum[expr_, test_, iterators__] := With[{heldVars = Replace[Hold[iterators], {var_, __} :> var, 1]}, Block @@ Append[Replace[heldVars, Hold[vars___] :> Hold[{vars}], {0}], Unevaluated[ With[{itervalues = Flatten[Table[ If[TrueQ[test], List @@ heldVars, Sequence @@ {}], iterators], Length[Hold[iterators]] - 1]}, Total@Map[expr /. Thread[List @@ heldVars -> #] &, itervalues]]]]]; This uses the fact that Table has the same iterator syntax as Sum and can be used to generate expression values and filter out points on which does not give True. It also uses Block to localize iteration variables, so it won't suffer from possible global values set for the iterator variables. So: In[3] = a = 1; conditionalSum[a^2 - 3 a/(4 a^2), a <= 6 || a >= 12, {a, 1, 20}] Out[3] = 69209343871/28217280 (I gave a global value to deliberately). This will sum over 3 coordinates, with all 3 iterators using different iterator sematics: In[4] = conditionalSum[i + j + k, i + j + k < 8, {i, 3}, {j, 1, 4, 1}, {k, {1, 3, 4, 6}}] Out[4] = 116 It can also handle cases when the limits of the outer variables depend on inner variables: In[5] = conditionalSum[i + j + k, i + j + k < 8, {i, 3}, {j, 1, i, 1}, {k, {1, 3, 4, 6}}] Out[5] = 68 I did a few more tests indicating that this works correctly, but I don't exclude the possibility of some subtle bugs that I failed to spot. I did not supply type-checks for the input parameters (iterators in particular) and error messages (this can be done easily). Also, I don't know which cool features of the standard Sum I am missing with this approach - perhaps there are lots of symbolic simplifications or built-in rules associated with Sum, also it is certainly faster. But for some simple things conditionalSum may be convenient. Hope this helps. Leonid > I would like to perform a summation of this type, Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] excluding however some values of the iteratore, I would for instance > like to exclude the values than to greater of 6 and inferior to 12. Is > it possible? > > > === Subject: Re: Is it possible to impose a condition on an iterator In any looping function, the iterator may take the form {i, lis}, where lis is an explicit list of values. So in your situation you need only construct that list, for example: avals = Complement[Range[20], Range[7, 11]]; Then: Sum[a^2 - 3 a/(4 a^2), {a, avals}] Of course you can do the entire thing at once by putting the Complement expression that constructs the list directly into the Sum expression: Sum[a^2 - 3 a/(4 a^2), {a, Complement[Range[20], Range[7, 11]]}] > I would like to perform a summation of this type, > > Sum[a^2 - 3 a/(4 a^2), {a, 1, 20}] > > excluding however some values of the iteratore, I would for instance > like to exclude the values than to greater of 6 and inferior to 12. Is > it possible? > > -- 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: Is it possible to impose a condition on an iterator Quite possible. The straightforward approach would be to take b = Table[{a=2Ca^2-3 a/(4 a^2)}=2C{a=2C1=2C20}] and then Plus@@ (#[[2]]&/@Select[b=2C[Not[6<#[[1]]<12]&])//N (btw=2C if you wish to sum the elements of a table I suggest you use Plus t= ogether with Apply - it is much nicer to take advantage of the beauties of = functional programming) . The above expression has //N at the end in order = to convert the resulting fraction to a more readable form. Alternatively=2C c = Table[a^2-3 a/(4 a^2)=2C{a=2C1=2C20}] d = Flatten[Position[Range[20]=2C x_/=3Bx<=6||x>=12]] Plus@@c[[d]]//N The result in both cases is 2452.73 Tomas I would like to perform a summation of this type=2C Sum[a^2 - 3 a/(4 a^2)=2C {a=2C 1=2C 20}] excluding however some values of the iteratore=2C I would for instance > like to exclude the values than to greater of 6 and inferior to 12. Is > it possible? > > === Subject: Re: Problem with fitting Hi Chris, it looks like your expression does not depend on the parameter. Try e.g.: FindFit[Table[i, {i, 8}], x, {{a, 3}}, x] and you get the message you describe. Daniel > Hi there, > > I encounter the following problem when fitting a complicated function using FindFit: when running > > BBWorigin = > FindFit[Data2, {CHFSorigin[x] /. ABWorigin /. ABW /. BBW /. CBW /. > DBW /. FGW} , {{COorigin, 4.3}}, {x}, MaxIterations -> 1000] > > > where I previously defined the function CHFSorigin and where the rules ABWorigin, ABW, BBW, CBW, DBW and FGW were also defined, I obtain the following output by mathematica: > > {COorigin -> 4.3} > FindFit::fmgz: Encountered a gradient that is effectively zero. The > result returned may not be a minimum; it may be a maximum or a saddle > point. > > My first reaction was to change COorigin to a different value, but that did not change the result, i.e. the fit always stopped at the initial value. Does anybody have > any ideas about how to progress from here? > > > Christian > === Subject: Re: 2dFFT & image processing Oops, I made a small mistake here. The DC term is only in one cormer of the FFT. So the line should read: k[[1, 1]] = 1; On Jul 9, 7:51 am, alexxx.ma...@gmail.com I need to perform a high-pass filter on some images. I know I can get a high pass filter doing a convolution of the image > with a predefined kernel, but for various reasons (and my learning > too) I wanted to follow the sequence: > 1) fft > 2) cut away central region (with a smooth edge) > 3) fft again but, due to my ignorance, I'm unable to accomplish the process: given the image in a, I put: f = Fourier[a[[1]]]; > af = Abs@f; > Dimensions[f] > {500,500} and I can check the fft with Graphics[Raster[255*af/Max[af]]] I then create the hole and apply it to the fft and invert again: k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. > s -> 1000.; > holed = af*k; > fholed = Abs[Fourier[holed]]; since the reconstructed image Graphics[Raster[255*fholed/Max[fholed]]] > is strongly fuzzed, whichever value I choose for the parameter s > above, I wanted to ask you if I completely misunderstood the process! thank you, alessandro === Subject: Re: 2dFFT & image processing Hi Allesandro, Your problem lies in the assumption that the low frequency components are in the middle of the Fourier output. In fact, that's the spot with the highest frequencies, so cutting them away blurs your picture. Also, you seem to forget that you have to do an InverseFourier to get back to the picture domain. Check these lines of code: (* Import an example image*) pic = ImageData[ ImageCrop[ExampleData[{TestImage, TruckAndAPC}], {500, 500}]]; (* Show it *) Image[pic] (* Fourier transform *) picf = Fourier[pic]; (* Check to see that inverse Fourier brings back the picture *) Image[Abs[InverseFourier[picf]]] (* Same for this version where amplitude and phase components are used *) Image[Abs[InverseFourier[Abs[picf] Exp[I Arg[picf]]]]] (* Filter LOW frequency components; DC component in the corners is retained *) k = Table[If[x^2 + y^2 < 320^2, 1, 0], {x, -249, 250}, {y, -249, 250}]; k[[1, 1]] = k[[1, -1]] = k[[-1, -1]] = k[[-1, 1]] = 1; Image[Abs[InverseFourier[k Abs[picf] Exp[I Arg[picf]]]]] (* Filter HIGH frequency components; DC component in the corners is retained *) k = Table[If[x^2 + y^2 < 320^2, 0, 1], {x, -249, 250}, {y, -249, 250}]; k[[1, 1]] = k[[1, -1]] = k[[-1, -1]] = k[[-1, 1]] = 1; Image[Abs[InverseFourier[k Abs[picf] Exp[I Arg[picf]]]]] On Jul 9, 7:51 am, alexxx.ma...@gmail.com I need to perform a high-pass filter on some images. I know I can get a high pass filter doing a convolution of the image > with a predefined kernel, but for various reasons (and my learning > too) I wanted to follow the sequence: > 1) fft > 2) cut away central region (with a smooth edge) > 3) fft again but, due to my ignorance, I'm unable to accomplish the process: given the image in a, I put: f = Fourier[a[[1]]]; > af = Abs@f; > Dimensions[f] > {500,500} and I can check the fft with Graphics[Raster[255*af/Max[af]]] I then create the hole and apply it to the fft and invert again: k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. > s -> 1000.; > holed = af*k; > fholed = Abs[Fourier[holed]]; since the reconstructed image Graphics[Raster[255*fholed/Max[fholed]]] > is strongly fuzzed, whichever value I choose for the parameter s > above, I wanted to ask you if I completely misunderstood the process! thank you, alessandro === Subject: Re: 2dFFT & image processing > hi everybody, > I need to perform a high-pass filter on some images. I know I can get a high pass filter doing a convolution of the image > with a predefined kernel, but for various reasons (and my learning > too) I wanted to follow the sequence: > 1) fft > 2) cut away central region (with a smooth edge) > 3) fft again but, due to my ignorance, I'm unable to accomplish the process: given the image in a, I put: f = Fourier[a[[1]]]; > af = Abs@f; Why are you taking the absolute value here? You can't recover the image from this data anymore. > Dimensions[f] > {500,500} and I can check the fft with Graphics[Raster[255*af/Max[af]]] I then create the hole and apply it to the fft and invert again: k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. > s -> 1000.; > holed = af*k; The indices are incorrect, the frequency (0,0) is not in the center of the spectrum, it's actually the very first point in the lower left hand corner of the plot. You have two options: shift the spectrum after Fourier, or shift the filter. So I'd define k as: k = Table[1 - Exp[-(If[x>249,x-500,x]^2 + If[y>249,y-500,y]^2)/s],{x, 0,500},(y,0,500}]/.s->1000.; > fholed = Abs[Fourier[holed]]; InverseFourier is the Inverse Fourier transform, so given the new k I'd use: fholed=InverseFourier[f*k] Sseziwa Mukasa === Subject: Re: 2dFFT & image processing Alessandro, > hi everybody, > I need to perform a high-pass filter on some images. > > I know I can get a high pass filter doing a convolution of the image > with a predefined kernel, but for various reasons (and my learning > too) I wanted to follow the sequence: > 1) fft > 2) cut away central region (with a smooth edge) > 3) fft again > You got the idea right, except in 3) you want the inverse fft Moreover: > but, due to my ignorance, I'm unable to accomplish the process: > > given the image in a, I put: > > f = Fourier[a[[1]]]; > af = Abs@f; > Dimensions[f] > {500,500} > > and I can check the fft with Graphics[Raster[255*af/Max[af]]] > and now you see that Fourier does not put the low frequencies at the center as you expected, but at the four corners. > I then create the hole and apply it to the fft and invert again: > > k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. > s -> 1000.; > holed = af*k; > fholed = Abs[Fourier[holed]]; > There's a couple of problems here: 1. Your mask is centered, hence won't match the corners 2. Don't throw away the phase (argument) of the FFT or you won't be able to reconstruct the image 3. You should use InverseFourier to perform the inverse FFT. If you forgive my obfuscated cornering, this works as expected: k2 = ArrayFlatten[Reverse /@ Reverse[Partition[k, {250, 250}]]]; holed = f*k2; fholed = Abs[InverseFourier[holed]]; Compare Image[fholed, Byte] with ImageConvolve[a, CrossMatrix[0, 21] - GaussianMatrix[10]] Matthias Odisio Wolfram Research > since the reconstructed image Graphics[Raster[255*fholed/Max[fholed]]] > is strongly fuzzed, whichever value I choose for the parameter s > above, I wanted to ask you if I completely misunderstood the process! > > thank you, > > > alessandro === Subject: Re: 2dFFT & image processing On 9 Lug, 07:51, alexxx.ma...@gmail.com I need to perform a high-pass filter on some images. I know I can get a high pass filter doing a convolution of the image > with a predefined kernel, but for various reasons (and my learning > too) I wanted to follow the sequence: > 1) fft > 2) cut away central region (with a smooth edge) > 3) fft again but, due to my ignorance, I'm unable to accomplish the process: given the image in a, I put: f = Fourier[a[[1]]]; > af = Abs@f; > Dimensions[f] > {500,500} and I can check the fft with Graphics[Raster[255*af/Max[af]]] I then create the hole and apply it to the fft and invert again: k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. > s -> 1000.; > holed = af*k; > fholed = Abs[Fourier[holed]]; since the reconstructed image Graphics[Raster[255*fholed/Max[fholed]]] > is strongly fuzzed, whichever value I choose for the parameter s > above, I wanted to ask you if I completely misunderstood the process! thank you, alessandro I beg your pardon, I found my error: I used Abs[] on the FFT's for display purpose, and I made the mistake of cutting the hole on the Abs [FFT] instead of the whole FFT: k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. s -> 1000.; holed = f*k; and: Grid[{{ MatrixPlot[Abs[Fourier[f]], FrameTicks -> None, DataReversed -> {True, True}, MatrixPlot[Fourier[holed], FrameTicks -> None, DataReversed -> {True, True}}}] works ok. What I have yet to find is the corresponding way to do it with convolution on a kernel: I cannot understand how the cutoff frequency here (corresponding to the hole size) is related to the kernel of the convolution... alessandro === Subject: fractal_teardrops.gif (GIF Image, 658x1009 pixels) - Scaled (90%) http://www.geocities.com/rlbagulatftn/fractal_teardrops.gif I was wondering if I could do the self-similar trick with othher figures besides ellipses and circles and I remembered the teardrop or piriform shape: Clear[f, dlst, pt, cr, ptlst, x, y] RandomSeed[]; dlst = Table[ Random[Integer, {1, 2}], {n, 250000}]; f[1, {x_, y_}] := N[ {(( x^2 - y^2)/(y^2 + x^2))^2*2*x*y/(x^2 + y^2) , (x^2 - y^2)/( y^2 + x^2)}]; f[2, {x_, y_}] := N[{7/24 - x/2 - y/2, x/2 - y/2}]; pt = {0.5, 0.75}; cr[n_] := If[n - 2 == 0, RGBColor[0, 0, 1], If[n - 3 == 0, RGBColor[0, 1, 0], If[n - 1 == 0, RGBColor[1, 0, 0], RGBColor[0, 0, 0]]]] ptlst = Table[{cr[dlst[[j]]], Point[pt = f[dlst[[j]], Sequence[pt]]]}, {j, Length[dlst]}]; Show[Graphics[Join[{PointSize[.001]}, ptlst]], AspectRatio -> Automatic, PlotRange -> All] > === Subject: Re: Strange Solve result after previous bad input On Jun 18, 6:19 am, Alain Cochard [...] > Here, there is '=' instead of '==' in the 2nd eq: > In[2]:= Solve[{a==x + y, b=-x + y},{x,y}] > Solve::eqf: -x + y is not a well-formed equation. [...] > Is this normal? Yes. Here, because you used = where you meant to use ==, you've assigned the value -x + y to the variable b. > If so, is there a cure (some resetting procedure), apart from > quiting Mathematica and entering back? Yes, Unset b, like so: b = . Pillsy === Subject: Re: Two questions about modification of a matrix. mat = Table[RandomReal[{-1, 1}], {7}, {5}] mat2 = mat*Table[If[i*j > 6, 0, 1], {i, Length[mat]}, {j, Length[mat[[1]]]}] mat3 = Map[Max[0, #] &, a, {2}] Bob Hanlon Suppose there is a N*N matrix. 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j is position of this element, as in mat[[i,j]]) 2. How can I change all negative elements in that matrix to 0 ? I know a for loop can be used, I just wonder if there is any more concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' function as in another system which conveniently returns indice of elements that satisfy a certain condition) === Subject: Re: exporting coordinate triplets out of plt = ParametricPlot3D[{Cos[u], Sin[u] + Cos[v], Sin[v]}, {u, 0, 2 Pi}, {v, -Pi, Pi}] pts = Cases[plt, {_?NumericQ, _?NumericQ, _?NumericQ}, Infinity]; However, you can generate exact values for points that fit the model using the model directly pts2 = Flatten[ Table[{Cos[u], Sin[u] + Cos[v], Sin[v]}, {u, 0, 2 Pi, Pi/50}, {v, -Pi, Pi, Pi/50}], 1]; Bob Hanlon I have some physical models constructed with ParametricPlot3D... Now, I'd love to Export these to a file for further analysis...the preferred format is the {x,y,z} coordinate style. How is this done? TIA, C. === Subject: Re: laptop recommendation to run mathematica fast? Most people wouldn't consider the Eee PC a laptop. Wikipedia lists it as a subnotebook/netbook. If you were looking for speed first and portability second, you're at the wrong end of the hardware scale. The design of netbooks factors portability and battery life as strong primary and secondary goals, withperformance as a distant tertiary goal. I have an Eee PC, too, which serves me very well. I have Mathematica and a couple of other CPU-sucking applications on it. But I understand that, if I expect to use them, I'm going to be engaged in some thumb-twiddling. That's the price I pay for a six hour battery life in a two pound package. On the other hand, there's a lot more variety in laptops. Some laptops favor portability strongly, some favor performance strongly, and some attempt to balance the two (this is a gross simplification...there are other factors, too, but you get the idea). I don't follow laptops on a regular basis, so I couldn't give you any helpful suggestions for what's on the market now. But I replace my own laptop about every three years, and I never have trouble finding something in the $2500-$3300 range with a nice large screen, decent sized hard drive, and reasonably fast CPU. Such laptops are available from all of the major vendors (e.g., Dell, Lenovo, Apple). And in the modern day and age, dual core is standard even in many of the cheaper laptops. Good luck in your shopping. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > hello, perhaps someone can recommend me a laptop to run Mathematica fast? i bought a asus eee pc 901 recently, which tho very cute pink and quiet, > (when the fan is off anyway!) it does return a rather disappointing > internal benchmark of around 0.32 for both Mathematica v7 and v5.2 with > windows XP. what with Moore's law and all that i had vaguely reckoned that in 2009 a > new machine should be running a lot faster than that since i have a circa > that benchmarks Mathematica 5.2 at 0.27 under windows ME, so that the > small increase in speed that i do see could be wholly put down to the > intel atom N270 in the asus running that little bit faster at 1.6 GHz. anyway, i am looking to buy a somewhat bigger screened laptop in the next > few weeks, so if you have, or know, of something that will run the > internal Mathematica v7.0 benchmark at, well, lets say, 3.0 or more?, > i.e. about ten times faster than what i have now, i would be very > interested to know what make and model it is, as i have had little luck > so far trawling the web for such info, and tho the wolfram benchmark > report mentions various intel xeons running at speeds of 3.75 or more i > cant say ive ever seen a laptop with one of these chipsets inside it, and > no mention whatever is made of these ubiquitous intel core 2 duo things, > quadcore or not, or what i could expect from them. > thankyou f.c (oh, i would just add that since i will be using the machine for other > things besides mathematica it would be best for me to continue with > windows a while longer, but if you get a nice turn of speed under > linux or mac OS please feel free to say so!) === Subject: Re: laptop recommendation to run mathematica fast? > Most people wouldn't consider the Eee PC a laptop. Wikipedia lists it as a > subnotebook/netbook. If you were looking for speed first and portability > second, you're at the wrong end of the hardware scale. The design of netbooks > factors portability and battery life as strong primary and secondary goals, withperformance as a distant tertiary goal. I have an Eee PC, too, which serves me > very well. I have Mathematica and a couple of other CPU-sucking applications > on it. But I understand that, if I expect to use them, I'm going to be > engaged in some thumb-twiddling. That's the price I pay for a six hour > battery life in a two pound package. On the other hand, there's a lot more variety in laptops. Some laptops favor > portability strongly, some favor performance strongly, and some attempt to > balance the two (this is a gross simplification...there are other factors, too, > but you get the idea). I don't follow laptops on a regular basis, so I > couldn't give you any helpful suggestions for what's on the market now. > But I replace my own laptop about every three years, and I never have > trouble finding something in the $2500-$3300 range with a nice large screen, > decent sized hard drive, and reasonably fast CPU. Such laptops are > available from all of the major vendors (e.g., Dell, Lenovo, Apple). > And in the modern day and age, dual core is standard even in many of > the cheaper laptops. Good luck in your shopping. > John Fultz > jfu...@wolfram.com > User Interface Group > Wolfram Research, Inc. hello, perhaps someone can recommend me a laptop to run Mathematica fast? i bought a asus eee pc 901 recently, which tho very cute pink and quiet, > (when the fan is off anyway!) it does return a rather disappointing > internal benchmark of around 0.32 for both Mathematica v7 and v5.2 with > windows XP. what with Moore's law and all that i had vaguely reckoned that in 2009 a > new machine should be running a lot faster than that since i have a circa > that benchmarks Mathematica 5.2 at 0.27 under windows ME, so that the > small increase in speed that i do see could be wholly put down to the > intel atom N270 in the asus running that little bit faster at 1.6 GHz. anyway, i am looking to buy a somewhat bigger screened laptop in the next > few weeks, so if you have, or know, of something that will run the > internal Mathematica v7.0 benchmark at, well, lets say, 3.0 or more?, > i.e. about ten times faster than what i have now, i would be very > interested to know what make and model it is, as i have had little luck > so far trawling the web for such info, and tho the wolfram benchmark > report mentions various intel xeons running at speeds of 3.75 or more i > cant say ive ever seen a laptop with one of these chipsets inside it, and > no mention whatever is made of these ubiquitous intel core 2 duo things , > quadcore or not, or what i could expect from them. thankyou f.c (oh, i would just add that since i will be using the machine for other > things besides mathematica it would be best for me to continue with > windows a while longer, but if you get a nice turn of speed under > linux or mac OS please feel free to say so!) Try Dell's XPS series for a large screen large format fast laptop. === Subject: Re: 2 plots in the same Manipulate Manipulate[ Row[{your ListLinePlot stuff, your PieChart stuff}, {Manipulate variables} ] > Hi > I've made one Maniipulate showing a ListLinePlot where i can vary a > couple of different parameters. > the ListLinePlot. I want this PieChart to be manipulated at the same > time, showing just next to my ListLinePlot. How is this done? I've > been trying a bit with Grid but found nothing that works. === Subject: Re: 2 plots in the same Manipulate Manipulate[ GraphicsRow[{ListLinePlot[pnts], BarChart[pnts]}], {{pnts, Table[i^1, {i, 6}]}}] ? Jens > Hi > I've made one Maniipulate showing a ListLinePlot where i can vary a > couple of different parameters. > the ListLinePlot. I want this PieChart to be manipulated at the same > time, showing just next to my ListLinePlot. How is this done? I've > been trying a bit with Grid but found nothing that works. > === Subject: Re: 2 plots in the same Manipulate Have you tried GraphicsGrid inside your manipulate command? Porscha Quoting Lobotomy : > Hi > I've made one Maniipulate showing a ListLinePlot where i can vary a > couple of different parameters. > the ListLinePlot. I want this PieChart to be manipulated at the same > time, showing just next to my ListLinePlot. How is this done? I've > been trying a bit with Grid but found nothing that works. > > > > === Subject: Using fractions in axis labels I can't seem to get my axis labels formatted correctly in Mathematica 7. I would like to have a string expression followed by a fraction in parentheses, but the string expression appears in the numerator, instead of in front of the fraction. Here is my expression for SetOptions: SetOptions[ListLinePlot,AxesLabel -> {Wavelength ([Mu]m), Solar Irradiance !( W / !(*SuperscriptBox[m, 2])[Mu]m)}] I have also tried the frontend graphics interface to enter fractions, with the same result. Jeff === Subject: Re: Using fractions in axis labels I'm not quite certain what your y axis label is to be, but you could use a Row construction to format the label. Plot[x, {x, 0, 1}, AxesLabel -> {Wavelength ([Mu]m), Row[{Solar Irradiance , W/(m^2), [Mu]m}]}] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I can't seem to get my axis labels formatted correctly in Mathematica 7. I would like to have a string expression followed by a fraction in parentheses, but the string expression appears in the numerator, instead of in front of the fraction. Here is my expression for SetOptions: SetOptions[ListLinePlot,AxesLabel -> {Wavelength ([Mu]m), Solar Irradiance !( W / !(*SuperscriptBox[m, 2])[Mu]m)}] I have also tried the frontend graphics interface to enter fractions, with the same result. Jeff === Subject: Re: Using fractions in axis labels The second label isn't a string. Try: ListLinePlot[{{0, 0}, {1, 1}}, AxesLabel -> {Wavelength ([Mu]m), Solar Irradiance (!(*FractionBox[W, RowBox[{SuperscriptBox[m, 2], , [Mu]m}]]))}] > I can't seem to get my axis labels formatted correctly in Mathematica 7. I would like to have a string expression followed by a fraction in parentheses, but the string expression appears in the numerator, instead of in front of the fraction. Here is my expression for SetOptions: SetOptions[ListLinePlot,AxesLabel -> {Wavelength ([Mu]m), > Solar Irradiance !( > W / !(*SuperscriptBox[m, 2])[Mu]m)}] I have also tried the frontend graphics interface to enter fractions, with the same result. Jeff === Subject: Re: Using fractions in axis labels > I can't seem to get my axis labels formatted correctly in Mathematica 7. = I would like to have a string expression followed by a fraction in paren= theses, but the string expression appears in the numerator, instead of in f= ront of the fraction. Here is my expression for SetOptions: SetOptions[ListLinePlot,AxesLabel -> {Wavelength ([Mu]m), > Solar Irradiance !( > W / !(*SuperscriptBox[m, 2])[Mu]m)}] I have also tried the frontend graphics interface to enter fractions, wit= h the same result. Use StringForm: SetOptions[ListLinePlot, AxesLabel -> {Wavelength ([Mu]m), StringForm[Solar Irradiance (`1`), m/2]}] Pillsy === Subject: Publishing the an interactive calculator on the web Hi I'm doing this interactive calculator and i want to put it on my webpage. Though, I've heard, the current version of webmathematica cannot handle manipulate, the 3.0 version can, but it is not out yet. Is there any other way of publishing it on the web (like easy way, not requiring to reprogramme my mathematica code into another language) I know there is a way to translate the code into JAVA when using another system. (My JAVA programming sucks (as my mathematica programming does as well) but I couldn't make the same calculator in JAVA =) === Subject: Re: exporting coordinate triplets out of ParametricPlot3D hsphere = ParametricPlot3D[{Cos[phi]*Sin[th], Sin[phi]*Sin[th], Cos[th]}, {th, 0, Pi}, {phi, 0, Pi}]; Export[somefilename, hsphere /. Graphics3D[ GraphicsComplex[pnts_, ___], ___] :> pnts,Table] Jens > > I have some physical models constructed with ParametricPlot3D... Now, > I'd love to Export these to a file for further analysis...the > preferred format is the {x,y,z} coordinate style. > > How is this done? > > TIA, > > C. > === Subject: Re: Number format maybe that's where Lehman bros went wrong ? 2009/6/22 Murray Eisenberg : > You could try AccountingForm, although that represents negative numbers > in parentheses and with no negative sign. > >> Hi >> i dont want my outbput to be presented using 10^n. I just want it to >> print the the entire sum like 10000000 rather than 1*10^7 >> How do i fix it? Ive experimented with NumberForm but i can't find the >> solution >> -- > Murray Eisenberg murray@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 > > -- Peter Lindsay === Subject: Re: Needs[], BeginPackage[], filename Hi Scot, May be I miss some sources where alternatives are shown, but your suggested workaround is exactly what Roman Maeder also suggests as a possible solution to this very problem in his Programming in Mathematica 3-rd edition (p. 50) So, unless things changed significantly in the package system since 1997, this is probably it. You can, of course, add your own definition to BeginPackage, which will itself execute Needs and then call the standard BeginPackage, Something like this: With[{filepattern = (Rule | RuleDelayed)[_String, _String]}, Unprotect[BeginPackage]; Clear[BeginPackage]; BeginPackage[context_String, dependson : {(_String | filepattern) ..}] /; MemberQ[dependson, filepattern] := With[{filesAndContexts = Cases[dependson, filepattern]}, Needs[#2, #1] & @@@ filesAndContexts; BeginPackage[context, dependson /. (Rule | RuleDelayed)[file_String, cont_String] :> cont]]; Protect[BeginPackage] ]; This adds a new syntax that allows you to intersperse the context names with rules that tell BeginPackage which file names to associate with which context. Example of use (insert your own context names): BeginPackage[ TestContext`, {OptionPipe`, AttributesOfPureFunctions.m :> AttributesOfPureFunctions`, NbToHTML`, CheckOptions.m -> CheckOptions`}]; EndPackage[] But, a disclaimer :) - I can not guarantee that this will always work properly. I tried a few simple cases and it seems to work for me, but I hope I won't be flamed for this :) Hope this helps. Leonid > Needs[] allows the context and filename to be specified. BeginPackage[] allows a context and not a file name. Then, my packages require two steps, as in the following example: ** start ** Needs[sizedistribution`, size functions.m] BeginPackage[tandemdma`, {sizedistribution`}] ** stop ** Are two steps really necessary or am I missing something very simple? My goal would be to just forego Needs[] and handle everything in one step > with BeginPackage, but I cannot figure out a way to feed the filename to > BeginPackage[]. I had a search on the MathArchives, but I did not succed in locating any > material addressing this question. > > > > > === Subject: Re: Needs[], BeginPackage[], filename ContextToFileName[context] gives the string specifying the file name that is by convention associated with a particular context. and you can overwrite it for your package. Or just name the package as suggested by the Mathematica conventions. Jens > Needs[] allows the context and filename to be specified. > > BeginPackage[] allows a context and not a file name. > > Then, my packages require two steps, as in the following example: > > ** start ** > > Needs[sizedistribution`, size functions.m] > > BeginPackage[tandemdma`, {sizedistribution`}] > > ** stop ** > > Are two steps really necessary or am I missing something very simple? > > My goal would be to just forego Needs[] and handle everything in one step > with BeginPackage, but I cannot figure out a way to feed the filename to > BeginPackage[]. > > I had a search on the MathArchives, but I did not succed in locating any > material addressing this question. > > > > > > === Subject: Re: Needs[], BeginPackage[], filename Hi Scott, > Needs[] allows the context and filename to be specified. > > BeginPackage[] allows a context and not a file name. > > Then, my packages require two steps, as in the following example: > > ** start ** > > Needs[sizedistribution`, size functions.m] > > BeginPackage[tandemdma`, {sizedistribution`}] > > ** stop ** > > Are two steps really necessary or am I missing something very simple? Two steps are not necessary. > My goal would be to just forego Needs[] and handle everything > in one step with BeginPackage, but I cannot figure out a way > to feed the filename to BeginPackage[]. > > I had a search on the MathArchives, but I did not succed in > locating any material addressing this question. This question has been answered before. The answer is in the online help. Search for BeginPackage and you will find that BeginPackage[YourContext, {Packages`You`Need`}] will call Needs[Packages`You`Need`] Another way to see this is to look in the supplied packages. They are only text files and there's a wealth of information there. D. === Subject: Re: Needs[], BeginPackage[], filename 1) Create a folder MyApplication (say) in your private Mathematica/Applications folder. (Evaluate $UserBaseDirectory to find this.) 2) Write a notebook called MyPackage.nb (say) that contains all your package code. Make all the cells Initialization cells. Make the BeginPackage statement: BeginPackage[MyApplication`MyPackage`] 3) Save MyPackage.nb in the MyApplication folder and when you first save it choose Save as Autogenerated Package. This will create the MyPackage.m file in the same folder. Every time you change and save the MyPackage.nb notebook the MyPackage.m package file will also be automatically updated. You should normally never have to look at the MyPackage.m file. 4) Load the package with: Needs[MyApplication`MyPackage`] The Presentations package has a simple example of developing a package and a sample package notebook that spells everything out in more detail. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Needs[] allows the context and filename to be specified. BeginPackage[] allows a context and not a file name. Then, my packages require two steps, as in the following example: ** start ** Needs[sizedistribution`, size functions.m] BeginPackage[tandemdma`, {sizedistribution`}] ** stop ** Are two steps really necessary or am I missing something very simple? My goal would be to just forego Needs[] and handle everything in one step with BeginPackage, but I cannot figure out a way to feed the filename to BeginPackage[]. I had a search on the MathArchives, but I did not succed in locating any material addressing this question. === Subject: Re: Slow performance gathering property data from fitted and Timing[rsquares2 = (#[RSquared]) & /@ models;] is 10% faster than Timing[rsquares = Through[models@RSquared];] though arguably less elegant. > Did you do something equivalent to this? data := Table[{3 + i + RandomReal[{-3, 7}], > i + RandomReal[{-2, 5}]}, {i, 1, 20}] Timing[models = Array[LinearModelFit[data, x, x] &, 70000];] {90.2283, Null} Timing[rsquares = Through[models@RSquared];] {40.3059, Null} ListPlot@rsquares Notice, the RSquare values came out faster than the model fitting. Bobby > > > > > Hi All, During some recent research I asked Mathematica to calculate 70, 000 > simple linear regression fits to 70,000 small datasets. This worked > well and resulted in a list of 70,000 fitted model objects being > finished in under 5 minutes. My next step was to collect the RSquared property for each of the > 70,000 fits contained in the list, and Mathematica took over 3 hours to > accomplish this. This seems horrendously slow simply to gather values > from a list. Has anyone ran into a similar problem? Any suggestions > how I might be able to significantly speed the gathering of properties > from large lists of fitted model objects? The snippet of code I was using to gather the RSquared values is below: piedlrRsquared = > Table[piedlrmodels[[i]][RSquared], {i, 1, Length[piedlrmodels]}] // > Timing; > Todd -- > DrMajor...@bigfoot.com === Subject: Re: extract coefficients > Hello all, I have an expression that is nonlinear with respect to variables q > [i]. > I need to transform it into equation with respect to unknown q[]. > Multipliers near each of such combination of q[] are functions that > must be extracted for integration. I'm having problem with Coefficient > [] because it does not allow extract multipliers near q[i] of just 1- > order, combination of the type q[i]q[j] or near q[i]q[j]q[k] > Please, help Below there is an example of the expression. I need to transform it > into equation with respect to unknown q[1], q[4] and q[7]. > w1,v1,u1 are functions of polynomial type that must be integrated > numerically to perform a coefficients at q[]. > Everything else is numbers in reality. -((EE*h*q[7]*w1[x, y]*Derivative[0, 1][v1][x, y])/(b*R*(-1 + [Nu] > ^2))) - (EE*h*[Nu]*q[4]*w1[x, y]*Derivative[1, 0][u1][x, y])/(b*R*(-1 > + [Nu]^2)) - > (3*q[1]^2*(EE*h*w1[x, y]*Derivative[0, 1][w1][x, y]^2 + EE*h*[Nu]*w1 > [x, y]*Derivative[1, 0][w1][x, y]^2))/(2*b^2*R*(-1 + [Nu]^2)) + > (q[1]^3*((-EE)*h*Derivative[0, 1][w1][x, y]^4 - 2*EE*h*Derivative[0, > 1][w1][x, y]^2*Derivative[1, 0][w1][x, y]^2 - EE*h*Derivative[1, 0][w1] > [x, y]^4))/ > (2*b^4*(-1 + [Nu]^2)) + q[1]*((q[7]*((-EE)*h*Derivative[0, 1][v1] > [x, y]*Derivative[0, 1][w1][x, y]^2 - EE*h*Derivative[0, 1][w1][x, y] > *Derivative[1, 0][v1][x, y]* > Derivative[1, 0][w1][x, y] + EE*h*[Nu]*Derivative[0, 1][= w1] > [x, y]*Derivative[1, 0][v1][x, y]*Derivative[1, 0][w1][x, y] - > EE*h*[Nu]*Derivative[0, 1][v1][x, y]*Derivative[1, 0][w1]= [x, y] > ^2))/(b^3*(-1 + [Nu]^2)) + > (q[4]*((-EE)*h*[Nu]*Derivative[0, 1][w1][x, y]^2*Derivative[1, 0= ] > [u1][x, y] - EE*h*Derivative[0, 1][u1][x, y]*Derivative[0, 1][w1][x, y] > *Derivative[1, 0][w1][x, y] + > EE*h*[Nu]*Derivative[0, 1][u1][x, y]*Derivative[0, 1][w1]= [x, y] > *Derivative[1, 0][w1][x, y] - EE*h*Derivative[1, 0][u1][x, y] > *Derivative[1, 0][w1][x, y]^2))/ > (b^3*(-1 + [Nu]^2)) + (-12*b^4*EE*h*w1[x, y]^2 - > EE*h^3*R^2*Derivative[0, 2][w1][x, y]^2 - 2*EE*h^3*R^2*Derivative[1, 1] > [w1][x, y]^2 + > 2*EE*h^3*R^2*[Nu]*Derivative[1, 1][w1][x, y]^2 - 2*EE*h^3*R^= 2* > [Nu]*Derivative[0, 2][w1][x, y]*Derivative[2, 0][w1][x, y] - > EE*h^3*R^2*Derivative[2, 0][w1][x, y]^2)/ > (12*b^4*R^2*(-1 + [Nu]^2))) > Hello Galina, suppose expr is your expression, then you can get it collected like this: col = Collect[expr, {q[_], q[a_]*q[b_],q[a_]*q[b_]*q[c_]}, mycoeff [Factor[#1]] & ]; (*This will extract a list of the q's : *) qs = List @@ col /. mycoeff[_] -> 1; (* And this the correspondiong coefficients: *) cf = Cases[List @@ col, _mycoeff, -1] /. mycoeff -> Identity; (* this gives 0, as it should *) Expand[qs . cf - tmp2 /. mycoeff -> Identity] Rolf Mertig GluonVision GmbH, Berlin, Germany http://www.gluonvision.com === Subject: Re: from the list select >from this list select the person who has P in the third position >namedata = {{Aardsma, David, P},{Bay, Jason, OF}} In[2]:= Cases[namedata, {_, _, P}] Out[2]= {{Aardsma, David, P}} === Subject: Re: Needs[], BeginPackage[], filename >Needs[] allows the context and filename to be specified. >BeginPackage[] allows a context and not a file name. >Then, my packages require two steps, as in the following example: >** start ** >Needs[sizedistribution`, size functions.m] >BeginPackage[tandemdma`, {sizedistribution`}] >** stop ** >Are two steps really necessary or am I missing something very >simple? Have you looked at the online documentation for BeginPackage in the Documentation Center? There is a comment immediately following the second syntax example that states Needs will be called for each of the items in the second argument. To do this in one step, this should work BeginPackage[tandemdma`, {sizedistribution`,size functions`}] This assumes the files to be loaded are both in a directory contained in the list returned by $Path. === Subject: palette creation I never - up to now - needed to create a custom palette, but now I urgently need to do it, to quickly write a long document containing often-repeated pieces/symbols/formulas. I tried on the net and found at http://documents.wolfram.com/mathematica/book/section-1.10.12 a sequence of steps that - though aimed at V5.2 - seemed easy and direct. Yet they're clearly unsupported in V7, since I obtain a palette, true, but not working. CreatePalette, and use PasteButton[] at each button: I'm surprised that the old method which was so direct and wysiwyg has been unsupported. Or am I wrong? alessandro === Subject: Almost finished - my first calculator! Hello My first Calculator is soon finished, though there are some problems still with it which I have not been able to solve. There's one bigger problem and a few smaller: Big problem: The Target amount is not working so well. The point with this is when you want to know how long time it takes until this amount is accumulated. All other parameters is the same except the time parameter of course. The idea is then when target amount is set to more than initial deposit it should calculate the time (i know how to do that) and then adjust the time parameter to that value, showing that plot in the same way when not using target amount with another Plotlabel. A perhaps easier alternative is when using target amount, fuck the plot and just present the amount of years required, but even this i dont know how to do. When changing another parameter after the target amount is set the target amount should be set to 0 again. otherwise it fucks up! Try it yourself, this is hard to explain. Smaller problems: *i want the PieChart showing % in the legend *I want the piechart and the listlineplot to be closer together *I want the Accumulated amount to be before the amount, not after! *I dont want the number to be presented without any decimals. *Is there any way to remove the sliders? My computer is anyway to slow. I just want to keep the boxes below where i can enter the numbers It would be nice if someone could help me solve this now when I've come so close to finishing my first masterpiece!THX Here's the code, try it! everything but the target amount works well Manipulate[ GraphicsColumn[{ ListLinePlot[#, DataRange -> {0, [Psi]}, PlotRange -> All, GridLines -> Automatic, Frame -> {True, True, False, True}, AxesOrigin -> {0, 0}, Filling -> Axis, ImageSize -> {400}, ColorFunction -> BlueGreenYellow, FillingStyle -> {Opacity[ 0.2, Blue]}, PlotStyle -> Thick, Mesh -> All, MeshStyle -> Directive[Blue, PointSize[0.01]], PlotLabel -> Accumulated amount: NumberForm[Last[#], ExponentFunction -> (If[Abs[#] <= 15, Null, #] &)] ] &@(Table[ If[[CapitalOmega] > [Lambda], {[Psi] = Log[([Alpha] [Zeta] + E^[Delta] [CapitalOmega] - E^[Mu] [CapitalOmega])/([Alpha] [Zeta] + E^[Delta] [Lambda] - E^[Mu] [Lambda])]/([Zeta] Log[ 1 + (E^[Delta] - E^[Mu])/[Zeta]]), f, PlotLabel -> Years NumberForm[[Psi], 2]}, If[[Delta] == [Mu], [Lambda] + [Alpha]*x*[Zeta], f = #5 (1 + ((E^#2 - 1) - (E^#6 - 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 - 1))/#3))^(#3*#4) - 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[[Alpha], [Delta], [Zeta], x, [Lambda], [Mu]]]], {x, 0, [Psi], 1}]), PieChart3D[{[Alpha]*[Zeta]*[Psi], [Lambda], f - [Alpha]*[Zeta]*[Psi] - [Lambda]}, ChartStyle -> DarkRainbow, ChartElementFunction -> ProfileSector3D, ChartLegends -> {Added Contributions, Initial Investment, Growth, Target Amount}]}], {{[Zeta], 1, Frequency of Contributions}, {1 -> Annually, 4 -> Quarterly, 12 -> Monthly}}, Delimiter, {{[Lambda], 5000, Initial Deposit}, 0, 1000000, 1000, Appearance -> {Open, Labeled}}, {{[Alpha], 1543, Added Contributions}, 0, 50000, 1000, Appearance -> {Open, Labeled}}, {{[Delta], 0.073, Growth(%/100)}, 0, 0.5, 0.01, Appearance -> {Open, Labeled}}, {{[Mu], 0.03, Inflation(%/100)}, 0, [Delta], 0.01, Appearance -> {Open, Labeled}}, {{[Psi], 8, Years}, 0, 100, 1, Appearance -> {Open, Labeled}}, {{[CapitalOmega], 0, Target amount}, 0, 10000000, 10000, Appearance -> {Open, Labeled}}] === Subject: Re: For loops with mathematica.... comments!!! Julien Table[i^2, {i, Flatten[{Range[20, 200, 30], Range[300, 400, 25]}]}] Do[y = i^2; Print[y]; > Print[i == Sqrt[y]], {i, > Flatten[{Range[20, 200, 30], Range[300, 400, 25]}]}] > Bob Hanlon > Hey guys, I am totally new to mathematica. > I want to use a simple loop for but with many arguments in the loop... > the help says to do Do[ thingstodo, {i,8}] i will go from 1 to 8 to do thingstodo. First question: what if I want i to go from 20 then 200 then 300 > then 400, (can we give a sequence as argument?) Second question: I have a lot of line to do in things to do. should > I separate everything with a ; (doesn t seem to work, or use a > procedure or something?) > THanks a lot for your help!!! Julien > > === Subject: For loops with mathematica.... Hey guys, I am totally new to mathematica. I want to use a simple loop for but with many arguments in the loop... the help says to do Do[ thingstodo, {i,8}] i will go from 1 to 8 to do thingstodo. First question: what if I want i to go from 20 then 200 then 300 then 400, (can we give a sequence as argument?) Second question: I have a lot of line to do in things to do. should I separate everything with a ; (doesn t seem to work, or use a procedure or something?) THanks a lot for your help!!! Julien === Subject: Re: For loops with mathematica.... > Hey guys, I am totally new to mathematica. > I want to use a simple loop for but with many arguments in the loop... > the help says to do Do[ thingstodo, {i,8}] i will go from 1 to 8 to do thingstodo. First question: what if I want i to go from 20 then 200 then 300 then 400= , (can we give a sequence as argument?) Second question: I have a lot of line to do in things to do. should I sep= arate everything with a ; (doesn t seem to work, or use a procedure or some= thing?) THanks a lot for your help!!! Julien Hey dude, you seem to be totally new to a lot of things. First question: what if you had a quick look at the core language (online help) or a basic introduction to Mathematica? Second question: wasn't the first question helpful enough? THanks a lot for your help!!! === Subject: Re: For loops with mathematica.... Hi Julien, > > I am totally new to mathematica. > I want to use a simple loop for but with many arguments in the loop... > the help says to do > > Do[ thingstodo, {i,8}] > > i will go from 1 to 8 to do thingstodo. > > First question: what if I want i to go from 20 then 200 then > 300 then 400, (can we give a sequence as argument?) You can do this. Try Do[ PrintTemporary[ji], {ji, {Range[20], Range[200, 300], 400}} ] or crange = Join[Range[20], Range[200, 300], {400}]; Do[ PrintTemporary[ji], {ji, crange} ] > Second question: I have a lot of line to do in things to do. > should I separate everything with a ; (doesn t seem to work, > or use a procedure or something?) Multiple statements inside a loop have to be separated using ;. As an example, Do[ a = Sin[ji Degree]; b = Cos[ji Degree]; Print[ji, t, a, t, b], {ji, 0, 90, 45} ] As with any programming language, you'll want to put stuff in Module[]'s as readability diminishes D. === Subject: Re: For loops with mathematica.... The form (i, end} for an iterator is essentially an abbreviation for {i, 1, end}. And that is a special case of {i, start, end}. That, in turn, is a special case of {i, start, end, increment}. But you're asking about a more complicated set of values for i than any single iterator of that form will provide. Fortunately, in the current version of Mathematica, there is a more general iterator construction yet, {i, valueList}, which iterates over the values given in the list valueList. For example, Do[expr,{i,{3,8,12,291}}] will evaluate expr at each of i = 3, 8, 12, 291. So your problem now reduces to constructing the list of values you want, and that's straightforward: Join[Range[1,20], Range[300,400]] You are correct that if you want to do several things -- that is, evaluate several individual expressions during each iteration, then you separate them by semicolons, in other words, form from them a compound expression. For example: Do[Print[i^2];Print[i^3], {i,{3,8,12,291}}] You say that separating expressions with a semicolon in the first argument of Do doesn't seem to work, but you didn't explain in what way it doesn't work. Finally, you might do some more reading of Mathematica documentation to learn more of the basics. And also to see whether you really need a Do loop at all, or any other kind of explicitly constructed iterative construct. You may find that Nest can nicely automate the entire process for you. Or that you can use whole-array processing, functional programming, or pattern-matching instead of an explicitly coded loop. And you might find that such an alternative procedure is much simpler to code and read and even more efficient than an explicitly coded loop. > Hey guys, > > I am totally new to mathematica. > I want to use a simple loop for but with many arguments in the loop... > the help says to do > > Do[ thingstodo, {i,8}] > > i will go from 1 to 8 to do thingstodo. > > First question: what if I want i to go from 20 then 200 then 300 then 400, (can we give a sequence as argument?) > > Second question: I have a lot of line to do in things to do. should I separate everything with a ; (doesn t seem to work, or use a procedure or something?) > > > THanks a lot for your help!!! > > Julien > -- 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: For loops with mathematica.... It would help if you could give us more of a specific simple example. If you are completely new to Mathematica you probably have to build up from simpler problems. If you look at Table you will see that in one form you can specify a specific list of iterator values: {i,{20,200,300}} gives those three values. You might want to write a function with parameters that uses a Module to build up a calculation. For example, maybe something like this is what you want: f[p1_, p2_][i_] := Module[{work}, work = i + p1; work^2 + p2] Table[f[1, 2][i], {i, {20, 200, 300}}] {443, 40403, 90603} David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hey guys, I am totally new to mathematica. I want to use a simple loop for but with many arguments in the loop... the help says to do Do[ thingstodo, {i,8}] i will go from 1 to 8 to do thingstodo. First question: what if I want i to go from 20 then 200 then 300 then 400, (can we give a sequence as argument?) Second question: I have a lot of line to do in things to do. should I separate everything with a ; (doesn t seem to work, or use a procedure or something?) THanks a lot for your help!!! Julien === Subject: Re: For loops with mathematica.... Do[ thingstodo, {i,{20,200,300,400}}] will cycle i through the values 20,200,300,400. You should separate statements in the Do loop with ; It works just fine. If you want output, use Print. If you want to deliver more complex result you might consider lists. May I offer the advice to start reading some introductory texts that Mathematica offers in its Documentation centre? Or are you planning to learn everything by guessing and asking random questions in this group? > Hey guys, I am totally new to mathematica. > I want to use a simple loop for but with many arguments in the loop... > the help says to do Do[ thingstodo, {i,8}] i will go from 1 to 8 to do thingstodo. First question: what if I want i to go from 20 then 200 then 300 then 400= , (can we give a sequence as argument?) Second question: I have a lot of line to do in things to do. should I sep= arate everything with a ; (doesn t seem to work, or use a procedure or some= thing?) THanks a lot for your help!!! Julien === Subject: Re: Two questions about modification of a Carl, Andrzej, Best, Leonid > >> >> Assuming that you store your matrix in a variable , here is the >> code: >> >> 1. >> >> MapIndexed[If[Times @@ #2 > Length[matr], 0, #1] &, matr, {2}] >> >> 2. >> >> matr /. _?Negative :> 0 >> >> As usual in Mathematica, in both cases above the original matrix has not >> been changed. Rather a new copy of the matrix is created as a result. >> >> If your matrix is large, you can implement the 1. much more efficiently. >> Here is the previous implementation: >> >> In[1] = >> nullify[matr_?MatrixQ] := >> MapIndexed[If[Times @@ #2 > Length[matr], 0, #1] &, matr, {2}] >> >> >> Here is an alternative one using SparseArrays: >> >> In[2] = >> nullifyFast[matr_?MatrixQ] := >> Normal[SparseArray[Thread[# -> Extract[matr, #]]]] &[ >> Flatten[Thread[{#, Range[IntegerPart[Length[matr]/#]]}] & /@ >> Range[Length[matr]], 1]]; >> >> Here is a test matrix: >> >> In[3] = >> largeTestMatr = RandomInteger[{-20, 20}, {400, 400}]; >> >> Compare performance: >> >> In[4] = >> (res1 = nullifyFast[largeTestMatr]); // Timing >> >> Out[4] = >> {0.03, Null} >> >> In[5] = >> (res2 = nullify[largeTestMatr]); // Timing >> >> Out[5] = >> {2.073, Null} >> >> In[6] = >> res1 == res2 >> >> Out[6] = >> true >> >> The solutions have such a dramatic difference in performance (for large >> matrices), since the condition i*j>N is very strong and we only need to >> keep >> a very small (comparing to a total number of matrix elements) subset of >> elements non - zero, and thus in the second solution we can utilize >> efficient built-in Mathematica facilities such as SparseArrays, while the >> first solution is very general and does not utilize the resulting matrix >> structure. >> >> For the second problem, probably the easiest way to speed up code in case >> of large matrices is to use Compile: >> >> nullifyNegativeCompiled = >> Compile[{{matr, _Real, 2}}, >> Module[{i = 1, j = 1, new = matr}, >> For[i = 1, i <= Length[matr], i++, >> For[j = 1, j <= Length[matr], j++, >> If[matr[[i, j]] < 0, new[[i, j]] = 0]]]; >> new]]; >> >> My benchmarks indicate 3-fold speed - up on , with respect >> to >> a rule-based solution. >> >A much simpler (and faster) solution is to use Clip: Clip[matrix, {0, Infinity}] Carl Woll > Wolfram Research > >> Leonid >> >> >> >> >> >>> Suppose there is a N*N matrix. >>> >>> 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j >>> is position of this element, as in mat[[i,j]]) >>> >>> 2. How can I change all negative elements in that matrix to 0 ? >>> >>> I know a for loop can be used, I just wonder if there is any more >>> concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' >>> function as in another system which conveniently returns indice of >>> elements >>> that satisfy a certain condition) >>> === Subject: Re: Two questions about modification of a matrix. For the second problem, probably the easiest way to speed up code in > case > of large matrices is to use Compile: nullifyNegativeCompiled = > Compile[{{matr, _Real, 2}}, > Module[{i = 1, j = 1, new = matr}, > For[i = 1, i <= Length[matr], i++, > For[j = 1, j <= Length[matr], j++, > If[matr[[i, j]] < 0, new[[i, j]] = 0]]]; > new]]; My benchmarks indicate 3-fold speed - up on , with > respect to > a rule-based solution. In my tests the following is both simpler and much faster : ClipNullify[mat_] := Clip[#, {0, Infinity}] & /@ mat For example: mat = RandomInteger[{-100, 100}, {1000, 1000}]; (m1 = nullifyNegativeCompiled[mat]); // Timing {0.320822, Null} (m2 = ClipNullify[mat]); // Timing {0.013523, Null} m1 == m2 True Andrzej Kozlowski === Subject: Re: Two questions about modification of Assuming that you store your matrix in a variable , here is the code: 1. MapIndexed[If[Times @@ #2 > Length[matr], 0, #1] &, matr, {2}] 2. matr /. _?Negative :> 0 As usual in Mathematica, in both cases above the original matrix has not > been changed. Rather a new copy of the matrix is created as a result. If your matrix is large, you can implement the 1. much more efficiently. > Here is the previous implementation: In[1] = > nullify[matr_?MatrixQ] := > MapIndexed[If[Times @@ #2 > Length[matr], 0, #1] &, matr, {2}] > Here is an alternative one using SparseArrays: In[2] = > nullifyFast[matr_?MatrixQ] := > Normal[SparseArray[Thread[# -> Extract[matr, #]]]] &[ > Flatten[Thread[{#, Range[IntegerPart[Length[matr]/#]]}] & /@ > Range[Length[matr]], 1]]; Here is a test matrix: In[3] = > largeTestMatr = RandomInteger[{-20, 20}, {400, 400}]; Compare performance: In[4] = > (res1 = nullifyFast[largeTestMatr]); // Timing Out[4] = > {0.03, Null} In[5] = > (res2 = nullify[largeTestMatr]); // Timing Out[5] = > {2.073, Null} In[6] = > res1 == res2 Out[6] = > true The solutions have such a dramatic difference in performance (for large > matrices), since the condition i*j>N is very strong and we only need to keep > a very small (comparing to a total number of matrix elements) subset of > elements non - zero, and thus in the second solution we can utilize > efficient built-in Mathematica facilities such as SparseArrays, while the > first solution is very general and does not utilize the resulting matrix > structure. For the second problem, probably the easiest way to speed up code in case > of large matrices is to use Compile: nullifyNegativeCompiled = > Compile[{{matr, _Real, 2}}, > Module[{i = 1, j = 1, new = matr}, > For[i = 1, i <= Length[matr], i++, > For[j = 1, j <= Length[matr], j++, > If[matr[[i, j]] < 0, new[[i, j]] = 0]]]; > new]]; My benchmarks indicate 3-fold speed - up on , with respect to > a rule-based solution. > A much simpler (and faster) solution is to use Clip: Clip[matrix, {0, Infinity}] Carl Woll Wolfram Research > Leonid > > >> Suppose there is a N*N matrix. >> >> 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j >> is position of this element, as in mat[[i,j]]) >> >> 2. How can I change all negative elements in that matrix to 0 ? >> >> I know a for loop can be used, I just wonder if there is any more >> concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' >> function as in another system which conveniently returns indice of elements >> that satisfy a certain condition) >> >> >> > === Subject: Re: Two questions about modification of a matrix. HI, 1) With[{[ScriptCapitalN] = 4}, MapIndexed[If[Times @@ #2 > [ScriptCapitalN], 0, #1] &, matrix, {2}] ] 2) Map[If[# < 0, 0, #] &, matrix, {2}] Jens > Suppose there is a N*N matrix. > > 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j > is position of this element, as in mat[[i,j]]) > > 2. How can I change all negative elements in that matrix to 0 ? > > I know a for loop can be used, I just wonder if there is any more > concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' > function as in another system which conveniently returns indice of elements > that satisfy a certain condition) > === Subject: Re: Two questions about modification of a matrix. ways for that. >> I know a for loop can be used, I just wonder if there is any more > concise and beautiful ways. You're right about Mathematica. Stop thinking about loops. Think about Map > and Pattern. Here are some example solutions to the problems you posed. 1. n = 3; MapIndexed[(If[Times @@ #2 > n, 0, #1]) &, mat, {2}] 2. mat /. {_?Negative->0} (*This ? is known as a PatternTest[]*) > > -----Original Message----- === > Subject: Two questions about modification of a matrix. Suppose there is a N*N matrix. 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j > is position of this element, as in mat[[i,j]]) 2. How can I change all negative elements in that matrix to 0 ? I know a for loop can be used, I just wonder if there is any more > concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' > function as in another system which conveniently returns indice of elements > that satisfy a certain condition) > > > === Subject: Re: Two questions about modification of a matrix. There must be 100s of ways to do this. Here's my version: n = 5; m = RandomReal[{-5, 5}, {n, n}] 1: MapIndexed[If[Times @@ #2 > n, 0, #1] &, m, {2}] 2: Map[If[# < 0, 0, #] &, m, {2}] A slightly more beginner-friendly formatted version of 1 would be: MapIndexed[ Function[{entry, indices}, If[Apply[Times, indices] > n, 0, entry] ], m, {2}] > Suppose there is a N*N matrix. 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j > is position of this element, as in mat[[i,j]]) 2. How can I change all negative elements in that matrix to 0 ? I know a for loop can be used, I just wonder if there is any more > concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' > function as in another system which conveniently returns indice of elemen= ts > that satisfy a certain condition) === Subject: Re: Two questions about modification of a matrix. >> I know a for loop can be used, I just wonder if there is any more concise and beautiful ways. You're right about Mathematica. Stop thinking about loops. Think about Map and Pattern. Here are some example solutions to the problems you posed. 1. n = 3; MapIndexed[(If[Times @@ #2 > n, 0, #1]) &, mat, {2}] 2. mat /. {_?Negative->0} (*This ? is known as a PatternTest[]*) -----Original Message----- === Subject: Two questions about modification of a matrix. Suppose there is a N*N matrix. 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j is position of this element, as in mat[[i,j]]) 2. How can I change all negative elements in that matrix to 0 ? I know a for loop can be used, I just wonder if there is any more concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' function as in another system which conveniently returns indice of elements that satisfy a certain condition) === Subject: Re: Two questions about modification of a matrix. > Suppose there is a N*N matrix. 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j > is position of this element, as in mat[[i,j]]) 2. How can I change all negative elements in that matrix to 0 ? I know a for loop can be used, I just wonder if there is any more > concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' > function as in another system which conveniently returns indice of elements > that satisfy a certain condition) > Try this: For your condition i*j>N: A = Array[Subscript[a, ##] &, {4, 4}]; MapIndexed[If[Greater[Times @@ #2, 4], 0, #1] &, A, {2}] // MatrixForm to replace negatives with 0: (B = RandomInteger[{-5, 5}, {4, 4}]) // MatrixForm Map[If[# < 0, 0, #] &, B, {2}] // MatrixForm -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Two questions about modification of a matrix. Assuming that you store your matrix in a variable , here is the code: 1. MapIndexed[If[Times @@ #2 > Length[matr], 0, #1] &, matr, {2}] 2. matr /. _?Negative :> 0 As usual in Mathematica, in both cases above the original matrix has not been changed. Rather a new copy of the matrix is created as a result. If your matrix is large, you can implement the 1. much more efficiently. Here is the previous implementation: In[1] = nullify[matr_?MatrixQ] := MapIndexed[If[Times @@ #2 > Length[matr], 0, #1] &, matr, {2}] Here is an alternative one using SparseArrays: In[2] = nullifyFast[matr_?MatrixQ] := Normal[SparseArray[Thread[# -> Extract[matr, #]]]] &[ Flatten[Thread[{#, Range[IntegerPart[Length[matr]/#]]}] & /@ Range[Length[matr]], 1]]; Here is a test matrix: In[3] = largeTestMatr = RandomInteger[{-20, 20}, {400, 400}]; Compare performance: In[4] = (res1 = nullifyFast[largeTestMatr]); // Timing Out[4] = {0.03, Null} In[5] = (res2 = nullify[largeTestMatr]); // Timing Out[5] = {2.073, Null} In[6] = res1 == res2 Out[6] = true The solutions have such a dramatic difference in performance (for large matrices), since the condition i*j>N is very strong and we only need to keep a very small (comparing to a total number of matrix elements) subset of elements non - zero, and thus in the second solution we can utilize efficient built-in Mathematica facilities such as SparseArrays, while the first solution is very general and does not utilize the resulting matrix structure. For the second problem, probably the easiest way to speed up code in case of large matrices is to use Compile: nullifyNegativeCompiled = Compile[{{matr, _Real, 2}}, Module[{i = 1, j = 1, new = matr}, For[i = 1, i <= Length[matr], i++, For[j = 1, j <= Length[matr], j++, If[matr[[i, j]] < 0, new[[i, j]] = 0]]]; new]]; My benchmarks indicate 3-fold speed - up on , with respect to a rule-based solution. Leonid > Suppose there is a N*N matrix. 1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j > is position of this element, as in mat[[i,j]]) 2. How can I change all negative elements in that matrix to 0 ? I know a for loop can be used, I just wonder if there is any more > concise and beautiful ways. (I doubt Mathematica doesn't have a 'find' > function as in another system which conveniently returns indice of elements > that satisfy a certain condition) > > === Subject: Re: from the list select Sorry, but I beg to differ: pattern-matching and pure functions are NOT what complete novices are likely to think of. Or, even if they find them in the documentation, may find them such unfamiliar ideas as to be reluctant to try them. > > namedata = {{Aardsma, David, P},{Bay, Jason, OF}} > > Solutions: > > Cases[namedata, {_, _, P}] > > > Next time consider reading the documentation first before posting your > question - this one is simple enough to be figured out even by a complete > novice. > > Leonid > > > >> from this list select the person who has P in the third position >> >> >> namedata = {{Aardsma, David, P},{Bay, Jason, OF}} >> > -- 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: from the list select namedata = {{Aardsma, David, P},{Bay, Jason, OF}} Solutions: Cases[namedata, {_, _, P}] Next time consider reading the documentation first before posting your question - this one is simple enough to be figured out even by a complete novice. Leonid > from this list select the person who has P in the third position > namedata = {{Aardsma, David, P},{Bay, Jason, OF}} > > === Subject: Re: from the list select or or Cases[namedata, {__, P}] or namedata /. {_, _, c : Except[P]} :> Sequence[] or Part[namedata, Sequence @@ Position[namedata, {__, P}]] and several more possibilities. Jens > from this list select the person who has P in the third position > > > namedata = {{Aardsma, David, P},{Bay, Jason, OF}} > === Subject: Re: from the list select > from this list select the person who has P in the third position > namedata = {{Aardsma, David, P},{Bay, Jason, OF}} > If you want the exactly P at the third position use: Cases[namedata,{_,_,P}] If you want any string with a P in it at the third position of the sublists use: Cases[namedata,{_,_,_?(StringMatch[#,*P*]&)}] -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: from the list select Brute force: where = First@Flatten@Position[Part[#, 3] & /@ namedata, P]; namedata[[where]] Pattern-matching: Cases[namedata, {_,_,P}] > from this list select the person who has P in the third position > > > namedata = {{Aardsma, David, P},{Bay, Jason, OF}} > -- 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: from the list select namedata = {{Aardsma, David, P}, {Bay, Jason, OF}}; Select[namedata, #[[3]] == P &] {{Aardsma, David, P}} Cases[namedata, _?(#[[3]] == P &)] {{Aardsma, David, P}} Select[namedata, Last[#] == P &] {{Aardsma, David, P}} Cases[namedata, _?(Last[#] == P &)] {{Aardsma, David, P}} Cases[namedata, {_, _, P}] {{Aardsma, David, P}} Cases[namedata, {__, P}] {{Aardsma, David, P}} from this list select the person who has P in the third position namedata = {{Aardsma, David, P},{Bay, Jason, OF}} === Subject: Re: Putting an If in my function Hi Porscha, Set (=) evaluates the right hand side immediately. At that time the truth of the condition g==w cannot be determined as these are still unknown parameters. You must use SetDelayed (:=) so that the condition will be evaluated at the time the function is called with known parameters. > -----Original Message----- > Cc: mathgroup@smc.vnet.net === > Subject: Re: Re: Putting an If in my function > > > I'm also interested in adding a special case to a function. Using > what's written below works fine: > > myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w > > But why doesn't the same work when the myFun is defined using = > instead of:=? i.e., > > myFun[a_, g_, f_, x_, d_, w_] = (d + a f x) /; g == w > ln[5]:=myFun[a, w, f, x, d, w] > Out[5]=d + a f x /; w == w > > Porscha > > > Quoting Sjoerd C. de Vries : > Nomen est omen, the old Romans used to say. And they were often > right. I'm not sure what you are trying to do here, with your function in an > unneccessary, overly complex, pure function notation. Why not write: myFun[a_, g_, f_, x_, d_, w_] := d (1 + (E^g - E^w)/f)^(f x) + (a (-1 > + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w) which is much more readable (at least in Mathematica)? In[31]:= Limit[myFun[a, g, f, x, d, w], g -> w] Out[31]= d + a f x You use the undefined 'n' in d + a n. I guess this must be f x... You can add a definition for myFun for this special case like this > (no > If[ ] necessary): myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w In[36]:= myFun[a, w, f, x, d, w] Out[36]= d + a f x If you want to use an If in the definition this would be something > like: x) > + (a (-1 + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w),d + a f x] > > >> >> #5 (1 + ((E^#2 - 1) - (E^#6 - >> 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 = > - >> 1))/#3))^(#3*#4) - >> 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] >> >> in the case when w==g the denominator equals zero. >> >> in this case i would like to rewrite the formula above to the much >> simpler >> d+a*n. How is this done? I've tried >> >> If[w == g, % = d + a*n], but this is not working. Another thing is >> where to put the If > > > > > === Subject: Re: Putting an If in my function I'm also interested in adding a special case to a function. Using what's written below works fine: myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w But why doesn't the same work when the myFun is defined using = instead of:=? i.e., myFun[a_, g_, f_, x_, d_, w_] = (d + a f x) /; g == w ln[5]:=myFun[a, w, f, x, d, w] Out[5]=d + a f x /; w == w Porscha Quoting Sjoerd C. de Vries : Nomen est omen, the old Romans used to say. And they were often > right. I'm not sure what you are trying to do here, with your function in an > unneccessary, overly complex, pure function notation. Why not write: myFun[a_, g_, f_, x_, d_, w_] := d (1 + (E^g - E^w)/f)^(f x) + (a (-1 > + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w) which is much more readable (at least in Mathematica)? In[31]:= Limit[myFun[a, g, f, x, d, w], g -> w] Out[31]= d + a f x You use the undefined 'n' in d + a n. I guess this must be f x... You can add a definition for myFun for this special case like this (no > If[ ] necessary): myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w In[36]:= myFun[a, w, f, x, d, w] Out[36]= d + a f x If you want to use an If in the definition this would be something > like: > f= > x) > + (a (-1 + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w),d + a f x] > > >> >> #5 (1 + ((E^#2 - 1) - (E^#6 - >> 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 = > - >> 1))/#3))^(#3*#4) - >> 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] >> >> in the case when w==g the denominator equals zero. >> >> in this case i would like to rewrite the formula above to the much >> simpler >> d+a*n. How is this done? I've tried >> >> If[w == g, % = d + a*n], but this is not working. Another thing is >> where to put the If > > > > > === Subject: Re: Putting an If in my function Nomen est omen, the old Romans used to say. And they were often right. I'm not sure what you are trying to do here, with your function in an unneccessary, overly complex, pure function notation. Why not write: myFun[a_, g_, f_, x_, d_, w_] := d (1 + (E^g - E^w)/f)^(f x) + (a (-1 + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w) which is much more readable (at least in Mathematica)? In[31]:= Limit[myFun[a, g, f, x, d, w], g -> w] Out[31]= d + a f x You use the undefined 'n' in d + a n. I guess this must be f x... You can add a definition for myFun for this special case like this (no If[ ] necessary): myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w In[36]:= myFun[a, w, f, x, d, w] Out[36]= d + a f x If you want to use an If in the definition this would be something like: x) + (a (-1 + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w),d + a f x] #5 (1 + ((E^#2 - 1) - (E^#6 - > 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 = - > 1))/#3))^(#3*#4) - > 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] in the case when w==g the denominator equals zero. in this case i would like to rewrite the formula above to the much > simpler > d+a*n. How is this done? I've tried If[w == g, % = d + a*n], but this is not working. Another thing is > where to put the If === Subject: Re: Putting an If in my function Function[{a, g, f, x, d, w}, If[g == w, d + a*f*x, d (1 + (E^g - E^w)/f)^(f x) + ( a (-1 + (1 + (E^g - E^w)/f)^(f x)) f)/(E^g - E^w)]] ? Jens > > #5 (1 + ((E^#2 - 1) - (E^#6 - > 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 - > 1))/#3))^(#3*#4) - > 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] > > > in the case when w==g the denominator equals zero. > > in this case i would like to rewrite the formula above to the much > simpler > d+a*n. How is this done? I've tried > > If[w == g, % = d + a*n], but this is not working. Another thing is > where to put the If > === Subject: Re: Putting an If in my function I would suggest that you use pattern - matching instead of If: Clear[fn]; fn[a_,g_,f_,x_,d_,w_]/;w==g:=d+a*f*x; fn[a_,g_,f_,x_,d_,w_]:= d (1+(Exp[g]-Exp[w])/f)^(f x)+(a (-1+(1+(Exp[g]-Exp[w])/f)^(f x)) f)/(Exp[g]-Exp[w]); Leonid #5 (1 + ((E^#2 - 1) - (E^#6 - > 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 - > 1))/#3))^(#3*#4) - > 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] > in the case when w==g the denominator equals zero. in this case i would like to rewrite the formula above to the much > simpler > d+a*n. How is this done? I've tried If[w == g, % = d + a*n], but this is not working. Another thing is > where to put the If > > === Subject: Re: Putting an If in my function f[a_, g_, f_, x_, d_, w_] = #5 (1 + ((E^#2 - 1) - (E^#6 - 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 - 1))/#3))^(#3*#4) - 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w]; f[a_, g_, f_, x_, d_, g_] = Limit[f[a, g, f, x, d, w], w -> g] a f x+d ?? f Bob Hanlon #5 (1 + ((E^#2 - 1) - (E^#6 - 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 - 1))/#3))^(#3*#4) - 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] in the case when w==g the denominator equals zero. in this case i would like to rewrite the formula above to the much simpler d+a*n. How is this done? I've tried If[w == g, % = d + a*n], but this is not working. Another thing is where to put the If === Subject: Re: Seeking a Porter Stemmer done in Mathematica Like a lot of stuff I look for in Mathematica .....It is already built- in.....check http://reference.wolfram.com/mathematica/ref/WordData.html under More Information HTH. Roger Williams Franklin Laboratory Has any one written and is willing to share it a Porter Stemmer in > Mathematica? > === Subject: Plot contour regions over a globe I'm in need of some advice and any help would be appreciated. I'm trying to use Mathematica to plot a representation of coverage areas on top of a representation of a globe. But I would like to have countries outlined on the sphere. I tried the new Geo plot toolbox and to show all the countries uses a enormous amount of resources. This is not quite the solution I am hoping for. The contour regions plotted over the globe will be inputted as latitude and longitude which brings me to another missing piece of Mathematica. There doesn't seem to be a tool to plot coordinates in 3D. I believe these were all new features in v7 so I hope for many more features to come in the future. -Mike === Subject: Possible bug in Mathematica 7 using ColorFunction Problem: use of ColorFunction affects spacing of Greek characters in Frame label. Here is a simple example of the problem: SetOptions[Plot, Frame -> True, FrameLabel -> Wavelength ([Mu]m)] Plot[y = x, {x, 1, 1000}, ColorFunction -> (ColorData[VisibleSpectrum][#] &), ColorFunctionScaling -> False, Filling -> Axis] Notice the space between the Greek character [Mu] and the m, causing the m to overlap the right parantheses. The space disappears if you remove the ColorFunction gradient from the plot parameters. Also, if you change [Mu] to a standard character like m, the formatting looks perfectly acceptable. To be honest, I don't really understand the reason for the [#] & following the ColorData tag, but the gradient doesn't seem to work properly without it. Is my syntax correct? === Subject: Re: Green's Function for Fresnel Reflection? > Can anyone point to a two-dimensional Green's Function for the classical > Fresnel reflection problem of a linearly polarized infinite plane wave > striking the planar interface between two unbounded half-spaces with > different refractive indices? [This is admittedly a math-and-physics rather than Mathematica question; > but there's an incredible level of mathematical smarts on this group, > and I'd like to implement the answer in some extended Mathematica > calculations.] Specific case of interest can be described as a y-polarized E field with > k vector in the x,z plane; interface in the x,y (or y,z) plane; with > wave going from higher to lower index half space so that TIR occurs > above a critical angle, as treated using plane-wave analysis in every > elementary optics or e-m theory text. A closed-form or special-function Green's function solution for a point > source instead of an infinite plane wave would be extremely useful; and > digging into Helmholtz/Weyl decomposition to derive something like this > looks like very heavy going. Extension to point source located in higher-index planar slab between > two lower-index half spaces (aka a planar waveguide) would be truly > great. I do not think the closed-form formula for the Green's tensor exist in half-plane geometry, except for long range asymptotics. The integral expression via plane wave expansion can be found in Maradudin and Mills, PRB 11(4) 1392 (1975). Very recently G. Panasyuk et al obtained a short distance expansion for G(r,r'), works like a charm: J. Phys. A: Math. Theor. 42 No 27 (10 July 2009) 275203. This is suitable for a point source within a surface proximity. The Fortran code can be found at http://whale.seas.upenn.edu/CODES This code can also find G numerically via direct integration for, virtually, any distances. Hope this will be helpful. === Subject: Re: Matrix construction >Array, but I want to construct a matrix from other matrices, how to >do it? For example, suppose I would like to construct a matrix M >which is composed of four matrices, A,B,C,D. The element >corresponding to the first row and the first column is A, the first >row and second column is B... I used the M={{A,B},{C,D}} and =46or version 6 and later the most direct way to do this would be to use ArrayFlatten. For example, In[1]:= a = RandomInteger[1, {2, 2}]; b = RandomInteger[2, {2, 2}]; c = RandomInteger[3, {2, 2}]; d = RandomInteger[4, {2, 2}]; In[5]:= ArrayFlatten@{{a, b}, {c, d}} Out[5]= {{1, 0, 0, 1}, {0, 1, 2, 0}, {2, 2, 4, 3}, {3, 3, 3, 2}} With earlier versions of Mathematica the same result can be obtained using Flatten as follows: In[6]:= Flatten[{{a, b}, {c, d}}, {{1, 3}, {2, 4}}] Out[6]= {{1, 0, 0, 1}, {0, 1, 2, 0}, {2, 2, 4, 3}, {3, 3, 3, 2}} === Subject: Re: Undocumented functions for working with graphics times for using it I must launch Mathematica with -cleanStart key for clearing the dump. But for Image`ToGraphicsRaster I can not get your clear code. My result contains unknown functions like Image`ImageDump`list with no attributes: In[1]:= ClearAttributes[Image`ToGraphicsRaster, {Protected, ReadProtected}] ?Image`ToGraphicsRaster Output: Image`ToGraphicsRaster[Image`ImageDump`list:{_? Image`ValidImageQ..}]:=Image`ToGraphicsRaster/@Image`ImageDump`list Image`ToGraphicsRaster[Image`ImageDump`img_?Image`ValidImageQ]:=Module [{Image`ImageDump`width,Image`ImageDump`height,Image`ImageDump`range,Image`= ImageDump`cf,Image`ImageDump`data,Image`ImageDump`interleaving,Image`ImageD= ump`imsize}, {{Image`ImageDump`width,Image`ImageDump`height},Image`ImageDump`range,Image= `ImageDump`cf} =ImageData[Image`ImageDump`img, {ImageDimensions,DataRange,ColorFunction}]; {Image`ImageDump`interleaving,Image`ImageDump`imsize}= {Interleaving,ImageSize}/.Options[Image`ImageDump`img]/.Options [Image];If [ImageData[Image`ImageDump`img,Interleaving- >True]],Image`ImageDump`data=Reverse[First [Image`ImageDump`img]]];Graphics[Raster[Image`ImageDump`data,{{0,0}, {Image`ImageDump`width,Image`ImageDump`height}},Image`ImageDump`range,Color= Function- {Image`ImageDump`width,Image`ImageDump`height},ImageSize- >Image`ImageDump`imsize],PlotRange->{{0,Image`ImageDump`width}, {0,Image`ImageDump`height}}]] How did you get your clear code? > ...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 an= d > 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: Take away the sliders Hi I just want to use the boxes below the sliders to enter the parameter values. I dont want to use the sliders or the other functions coming with Manipulate. Is there another commando i can use than manipulate, or just a way to remove the sliders? === Subject: how to make .nbp? Hi I want to make my .nb to a .nbp so that people that dont have mathematica can download mathematica player and use it. How to do it? === Subject: Re: Ansatz? Somewhere I've picked up the idea that ansatz can also be used to > indicate the form or the approach -- more specifically, something > like the choice of coordinates and variables and equations -- the > geometry and notation so to speak -- in which one sets up a problem o= r > a calculation. I would say, that this is the common understanding of ansatz in > science (at least for a native german speaker). An example would be the > german word Loesungsansatz, meaning the initial choice of how to approach > (and solve) a given problem, > e.g. the starting point of a mathematical proof or the set of initial > assumptions. Wolfram MathWorld says: An ansatz is an assumed form for a mathematical statement > that is not based on any underlying theory or principle. SEE ALSO: Conjecture, Hypothesis, Principle, Proposition So, to assume something without any prior derivation could be an > ansatz, but > usually an ansatz would be based on some reasonable assumptions or > additional > knowledge, so not based on ANY underlying theory or principle sounds > too > much like a crystal ball. > Markus I agree with Markus. An Ansatz is an assumption, that is a statement which is considered (at least temporarily) true. The description given in wikipedia not based on ANY underlying theory or principle sounds to me more like the definition of Axiom, which is a statement considered true permanently (at least within a given theory) During the course of a demonstration an Ansatz could turn out to be self-contradictory and therefore false (this happens in reductio ad absurdum proofs), while an Axion should never turn out self- contradictory (unless your theory is incoherent). === Subject: Re: Ansatz? > > Somewhere I've picked up the idea that ansatz can also be used to > indicate the form or the approach -- more specifically, something > like the choice of coordinates and variables and equations -- the > geometry and notation so to speak -- in which one sets up a problem or > a calculation. > > I would say, that this is the common understanding of ansatz in > science (at least for a native german speaker). An example would be the > german word Loesungsansatz, meaning the initial choice of how to approach > (and solve) a given problem, > e.g. the starting point of a mathematical proof or the set of initial > assumptions. English, but by a native German author. === Subject: Re: Ansatz? > So, to assume something without any prior derivation could be an > ansatz, but > usually an ansatz would be based on some reasonable assumptions or > additional > knowledge, so not based on ANY underlying theory or principle sounds > too > much like a crystal ball. Actually, in almost all cases known to me Ansatz refers to a principle or a form of a solution that is known to work but at the stage when it is introduced it is magically pulled out of a hat (like a rabbit) without any justification except that the magicians knowledge that it will give the right answer. sometimes refers to a method of solving certain kind of problems that has actually been proved; in other words, it's a kind of theorem. One example that comes to my mind is the so called Sinai-Chemov Ansatz in ergodic theory of billiards. Andrzej Kozlowski === Subject: Re: Ansatz? > Wolfram MathWorld says: An ansatz is an assumed form for a mathematical statement > that is not based on any underlying theory or principle. SEE ALSO: Conjecture, Hypothesis, Principle, Proposition Somewhere I've picked up the idea that ansatz can also be used to > indicate the form or the approach -- more specifically, something > like the choice of coordinates and variables and equations -- the > geometry and notation so to speak -- in which one sets up a > problem or > a calculation. The underlying theory or principles in my interpretation can be > perfectly clear, and no Conjectures or Hypotheses need be > involved. > One is simply setting up the calculation using this ansatz, in order > to > calculate certain consequences or numerical results (a calculation > which > one, of course, carries out using Mathematica). Is my interpretation of this term off the mark? (Wikipedia's > explanation of the term seems to me considerably closer to my > understanding than to Wolfram's definition.) Although I forgot almost all German I ever learned, it still looks to me that Ansatz == Beginning :) So looks to me an ansatz is created when a mathematician, or any other human being, hits his/her stomach and belches out something formulated into words. J=E1nos= === Subject: Re: For loops with mathematica.... Table[i^2, {i, Flatten[{Range[20, 200, 30], Range[300, 400, 25]}]}] Do[y = i^2; Print[y]; Print[i == Sqrt[y]], {i, Flatten[{Range[20, 200, 30], Range[300, 400, 25]}]}] Bob Hanlon Hey guys, I am totally new to mathematica. I want to use a simple loop for but with many arguments in the loop... the help says to do Do[ thingstodo, {i,8}] i will go from 1 to 8 to do thingstodo. First question: what if I want i to go from 20 then 200 then 300 then 400, (can we give a sequence as argument?) Second question: I have a lot of line to do in things to do. should I separate everything with a ; (doesn t seem to work, or use a procedure or something?) THanks a lot for your help!!! Julien === Subject: Re: Matrix construction joining, for instance, {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}, {{9, 10}, {11, 12}}, {{13, 14}, {15, 16}}} we have to get {{1, 2, 5, 6}, {3, 4, 7, 8}, {9, 10, 13, 14}, {11, 12, 15, 16}} A possible solution: In[1] = joinBlocks[matrixOfMatrices_?(MatrixQ[#,MatrixQ]&)] := Flatten[Map[ Join @@@ Transpose[#] &, matrixOfMatrices], 1]; For example, {{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},{{13,14},{15,16}}}}//Matrix Form (output suppressed), In[2]= joinBlocks[{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},{{13,14},{15,16}} }}] Out[2]= {{1,2,5,6},{3,4,7,8},{9,10,13,14},{11,12,15,16}} This works on more general matrices as well. For example, on Fold[Partition, Range[48], {2, 2, 3}] // MatrixForm (output suppressed) In[3] = joinBlocks[Fold[Partition, Range[48], {2, 2, 3}]] Out[3] = {{1, 2, 5, 6, 9, 10}, {3, 4, 7, 8, 11, 12}, {13, 14, 17, 18, 21, 22}, {15, 16, 19, 20, 23, 24}, {25, 26, 29, 30, 33, 34}, {27, 28, 31, 32, 35, 36}, {37, 38, 41, 42, 45, 46}, {39, 40, 43, 44, 47, 48}} Hope this helps. Leonid > I know that matrix can be constructed via Table or Array, but I want to > construct a matrix from other matrices, how to do it? > For example, suppose I would like to construct a matrix M which is composed > of four matrices, A,B,C,D. The element corresponding to the first row and > the first column is A, the first row and second column is B... > I used the M={{A,B},{C,D}} and M={A,B,C,D}, but both of them didn't work. > How? Haibo > > > === Subject: Re: Matrix construction Haibo > A = Array[a, {3, 2}]; B = Array[b, {3, 4}]; > G = Array[g, {3, 2}]; H = Array[h, {3, 4}]; (* brute force joining *) > Join[Join[A, G], Join[B, H], 2] (* using a more specialized function *) > ArrayFlatten[{{A,B},{G,H}}] > > > >> >> I know that matrix can be constructed via Table or Array, but I want to >> construct a matrix from other matrices, how to do it? >> For example, suppose I would like to construct a matrix M which is >> composed >> of four matrices, A,B,C,D. The element corresponding to the first row and >> the first column is A, the first row and second column is B... >> I used the M={{A,B},{C,D}} and M={A,B,C,D}, but both of them didn't work. >> How? >> -- > 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: Matrix construction At first, it is a little difficult to pick it out in Help, but what you want is the Version 6 routine ArrayFlatten. amat = Array[a[#1, #2] &, {2, 2}]; bmat = Array[b[#1, #2] &, {2, 3}]; cmat = Array[c[#1, #2] &, {3, 2}]; dmat = Array[d[#1, #2] &, {3, 3}]; {{amat, bmat}, {cmat, dmat}} // ArrayFlatten // MatrixForm David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I know that matrix can be constructed via Table or Array, but I want to construct a matrix from other matrices, how to do it? For example, suppose I would like to construct a matrix M which is composed of four matrices, A,B,C,D. The element corresponding to the first row and the first column is A, the first row and second column is B... I used the M={{A,B},{C,D}} and M={A,B,C,D}, but both of them didn't work. How? Haibo === Subject: Re: Matrix construction A = Array[a, {3, 2}]; B = Array[b, {3, 4}]; G = Array[g, {3, 2}]; H = Array[h, {3, 4}]; (* brute force joining *) Join[Join[A, G], Join[B, H], 2] (* using a more specialized function *) ArrayFlatten[{{A,B},{G,H}}] I know that matrix can be constructed via Table or Array, but I want to > construct a matrix from other matrices, how to do it? > For example, suppose I would like to construct a matrix M which is composed > of four matrices, A,B,C,D. The element corresponding to the first row and > the first column is A, the first row and second column is B... > I used the M={{A,B},{C,D}} and M={A,B,C,D}, but both of them didn't work. > How? -- 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: Matrix construction I know that matrix can be constructed via Table or Array, but I want to construct a matrix from other matrices, how to do it? For example, suppose I would like to construct a matrix M which is composed of four matrices, A,B,C,D. The element corresponding to the first row and the first column is A, the first row and second column is B... I used the M={{A,B},{C,D}} and M={A,B,C,D}, but both of them didn't work. How? Haibo === Subject: Re: Matrix construction I'm not really sure whether this meets your requirements, but you might give ArrayFlatten a try. > I know that matrix can be constructed via Table or Array, but I want to > construct a matrix from other matrices, how to do it? > For example, suppose I would like to construct a matrix M which is composed > of four matrices, A,B,C,D. The element corresponding to the first row and > the first column is A, the first row and second column is B... > I used the M={{A,B},{C,D}} and M={A,B,C,D}, but both of them didn't work. > How? Haibo === Subject: *slowing down* a Mathematica process (Dynamic/Refresh question) I hope to use Mathematica as an interface to an outside process, in which it periodically polls an outside data source and performs calculations on the data. The problem is, the loop is quick and Mathematica polls the outside datasource too often. UpdateInterval does not help (I think it effects how often the updated results are displayed, but the polling continues as quickly as Mathematica can do it). Adding a call to Pause[] doesn't help either, as it causes the entire session to freeze and become unusable. I have tried this a variety of ways, getting the same behavior each time. A schematic of one version of the code appears below DynamicModule[{holder}, Dynamic[Refresh[FinishDynamic[]; holder = callToOutsideDataFeed[], UpdateInterval -> 1]] Are there any Dynamic/Refresh gurus out there who can help? Michael Stern === Subject: Re: For loops with mathematica.... >I am totally new to mathematica. I want to use a simple loop for but >with many arguments in the loop... the help says to do >Do[ thingstodo, {i,8}] >i will go from 1 to 8 to do thingstodo. >First question: what if I want i to go from 20 then 200 then 300 >then 400, (can we give a sequence as argument?) Usually, there are better methods to get a particular result in Mathematica than using explicit loops. For example consider the following: In[1]:= m = 10^6; In[2]:= Timing[sum = 0; n = 1; Do[sum += n; n++, {m}]; sum] Out[2]= {2.47955,500000500000} In[3]:= Timing[For[n = 1; sum = 0, n <= m, n++, sum += n]; sum] Out[3]= {2.62515,500000500000} In[4]:= Timing[Plus @@ Range[m]] Out[4]= {0.285061,500000500000} In[5]:= Timing[Total@Range[m]] Out[5]= {0.233266,500000500000} In[6]:= Timing[Sum[n, {n, m}]] Out[6]= {0.250216,500000500000} In[7]:= Timing[Sum[n, {n, k}] /. k -> m] Out[7]= {0.098365,500000500000} Each method give exactly the same result but there is a very significant difference in the amount of time required for each to return an answer. Notice, methods using explicit loops are the slowest. A very large number of the functions built into Mathematica have the attribute LIstable. In these cases, a list of values can be given and a list of results will be returned. For example, In[8]:= x = Range[5]; x^2 Out[9]= {1,4,9,16,25} So, it is likely you can do f[Join[Range[20,200],Range[300,400]]] to get f[x] for x running from 20 to 200 and then from 300 to 400. In cases where the function you want does not have the attribute Listable, you can use Map to map the function to each element of a list. The syntax to do this would be Map[f, Join[Range[20,200],Range[300,400]]] or f/@Join[Range[20,200],Range[300,400]] Other methods are also possible. >Second question: I have a lot of line to do in things to do. should >I separate everything with a ; (doesn t seem to work, or use a >procedure or something?) The syntax expr1;expr2 represents a compound expression. When Mathematica encounters this syntax, each of the expri are executed in turn but only the result from the last expression is returned. The syntax expr; is the compound expression expr;Null. Mathematica executes expr but returns nothing since the last expression Null returns nothing. My guess is when you say things didn't seem to work is you used the form expr; and on not seeing a result returned you assumed things didn't work. But to answer your question, use of a semicolon depends on the results you want. There is no general rule that will always do what you want. For questions like this, it is always better to post what you tried, what you got and what you wanted. That will result in an answer more specific to your particular problem === Subject: Re: FindInstance over Integers I hope you realize that as there are no general algorithms for solving such problems you really have to rely on luck and hope. However, if you have to rely on luck and hope your best bet is probably NMinimize, which at least will try to solve almost any problem that can be formulated as one of minimalization, that is, it will never tell you that the methods available to it are insufficient (even though they probably are ;-)) Actually, in this particular case they are sufficient: NMinimize[{1, x == 2^y && x > 2 && Element[x | y, Integers]}, {x, y}] {1., {x -> 4, y -> 2}} Andrzej Kozlowski > Hello -- I'm working on a project which requires the program to determine > whether a given set of equalities and inequalities is satisfiable over > the integers. Of course, this problem is not decidable in general. > But I just need a good enough function that will at least report > that a set of constraints is satisfiable only if it actually is, and > work across some fairly easy cases. FindInstance is the obvious > function to use, but it seems to fail for constraints that are very > easy to satisfy. The simplest example I can come up with is this: FindInstance[x == 2^y && x > 2, {x, y}, Integers] Clearly, {x->4, y->2} would satisfy these constraints, but Mathematica > reports that the methods available to FindInstance are > insufficient.... It may be relevant that if I change x > 2 to x > 1, then > Mathematica has no problem finding a solution. Are there any workarounds or alternatives to this approach? -Zac > === Subject: Re: FindInstance over Integers I meant: even though they probably aren't Andrzej Kozlowski > that is, it will never tell you that the methods available to it > are insufficient (even though they probably are ;-))