> It is astonishing that debates like this keep coming up. To anyone who > disagrees with the notion that 1^Infinity is indeterminate, I suggest > that you write something called a new kind of calculus. But you might > want to learn the old kind first. I taught calculus for many years. Unless I've misunderstood Ted, his question has nothing to do with calculus. (If I have misunderstood you, Ted, please let me know!) What you're thinking about, Selwyn, cannot be debated -- at least not by reasonable people: Certain _limit_ forms, such as 1^oo and 0^0, are indeterminate. That is simply a fact. It cannot be altered (unless we were to change the power function x^y substantially, which surely we don't want to do). But, when we say that a certain limit form is indeterminate, it is important to know not only what that _does_ mean, but also what it does _not_ mean! Let's take the limit form 0^0 as an example. Saying that it is indeterminate means that, as x and y approach 0, x^y may approach any of many different possible values (or the limit may not exist). [The word indeterminate is appropriate in that, merely knowing that both base and power approach 0, we do not have enough information to be able to determine the limit, if it exists.] This indeterminacy is due to the fact that f(x,y) = x^y has an essential singularity at (0,0). But saying that the limit form 0^0 is indeterminate does _not_ mean that the simple arithmetic expression 0^0 need be undefined. In the arithmetic expression 0^0, both base and power _are_ 0, they are constant. No limits are involved. Whether the arithmetic expression 0^0 should be defined as 1, as many prominent mathematicians (including Euler, Knuth, Graham, and Kahan) have suggested, or should be undefined, is apparently still open to debate by reasonable people. Now the OP had asked about 1^Infinity. If he was asking about the limit form 1^Infinity, then, just as for 0^0, there can be no reasonable debate. That limit form is indeterminate, period. But, since he mentioned no limits, I had naturally assumed that he had in mind the simple arithmetic expression 1^Infinity, in which the base does not merely approach 1, but rather _is_ 1, and the power does not merely approach Infinity, by rather _is_ Infinity. Both base and power are constants. (In case you're balking at the notion of the power being the constant Infinity: Of course, there is no such constant in the real number system. But such a constant does exist in an extension of the reals.) Just as for the arithmetic expression 0^0, whether the arithmetic expression 1^Infinity should be defined as 1, or be undefined, is still open to debate by reasonable people. Note: Of course, defining the arithmetic expressions 0^0 and 1^Infinity to be 1 would in no way alter the fact that f(x,y) = x^y has essential singularities at (0,0) and (1,Infinity), and so would in no way alter the fact that the limit forms 0^0 and 1^Infinity are indeterminate. ==== Okay, finally I get it. I apologize for thinking you're all nitwits. :^) So the question is whether 1^Infinity (and related forms) could/should be assigned some value in a non-limit sense. Thinking back on a previous life (FORTRAN) I see that there may be systems in which it would make sense to have 1^Infinity = 1 while 1.^Infinity = Indeterminant. But in a system that contains rationals as well as integers, it seems to me that having 1^Infinity = 1 is just as wrong as 1.^Infinity = 1. (The wrongness of 1.^Infinity = 1, by the way, must be understood in terms of limits, not machine arithmetic, since 1. is a machine number.) As usual, Mathematica does the right thing, defering to generality and consistency with traditional mathematics. --- Selwyn Hollis > [Message also posted to: comp.soft-sys.math.mathematica] >>It is astonishing that debates like this keep coming up. To anyone who >>disagrees with the notion that 1^Infinity is indeterminate, I suggest >>that you write something called a new kind of calculus. But you might >>want to learn the old kind first. > I taught calculus for many years. Unless I've misunderstood Ted, his > question has nothing to do with calculus. (If I have misunderstood you, > Ted, please let me know!) What you're thinking about, Selwyn, cannot be debated -- at least not > by reasonable people: Certain _limit_ forms, such as 1^oo and 0^0, are indeterminate. > expression 1^Infinity should be defined as 1, or be undefined, is still > open to debate by reasonable people. Note: Of course, defining the arithmetic expressions 0^0 and 1^Infinity > to be 1 would in no way alter the fact that f(x,y) = x^y has essential > singularities at (0,0) and (1,Infinity), and so would in no way alter > the fact that the limit forms 0^0 and 1^Infinity are indeterminate. > ==== toSphere[{x_, y_, z_}] := {Sqrt[x^2 + y^2 + z^2], ArcCos[z/Sqrt[x^2 + y^2 + z^2]], ArcTan[x, y]} SphereCurve[p1_, p2_] := Module[{sp1, sp2, ip, t}, sp1 = toSphere[p1]; sp2 = toSphere[p2]; ip = (1 - t)*sp1 + t*sp2; ParametricPlot3D[Evaluate[ #1{Cos[#3]*Sin[#2], Sin[#3]*Sin[#2], Cos[#2]} & @@ ip], {t, 0, 1}] ] SphereCurve[pt1, pt2] may help. > I have the following problem. Given two random points on a sphere, I would > like to connect them with a curve that goes 'approximately' on the sufrace > line segments. Connecting the points with a straigh line is achived by Line[{pt1,pt2}]. I am failing to get good ideas on how to approach the problem, would > appreciate any hint / trick / tip. ==== If you're willing to use a less primitive approach... First let's assume the radius is 1 and define p[t_] := (1 - t)*p1 + t*p2 and curve[p1_,p2_] := ParametricPlot3D[Evaluate[Flatten[{p[t]/Sqrt[p[t].p[t]], Thickness[0.01]}]], {t, 0, 1}, DisplayFunction->Identity] This generates random points for testing: randompoint := Module[{u=2*Pi*Random[], v=Pi*Random[]}, {Cos[u]Sin[v], Sin[u]Sin[v], Cos[v]}] Now, <like to connect them with a curve that goes 'approximately' on the sufrace >line segments. Connecting the points with a straigh line is achived by Line[{pt1,pt2}]. I am failing to get good ideas on how to approach the problem, would >appreciate any hint / trick / tip. > ==== Here is a routine that will generate two different random points on a unit sphere. twoPoints := With[ {phi1 = Random[Real, {0, Pi/2}], phi2 = Random[Real, {Pi/2 + 0.01, Pi}], theta1 = Random[Real, {0, 2Pi}], theta2 = Random[Real, {0, 2Pi}]}, {{Cos[theta1]Sin[phi1], Sin[theta1]Sin[phi1], Cos[phi1]}, {Cos[theta2]Sin[phi2], Sin[theta2]Sin[phi2], Cos[phi2]}} ] The following routine generates the parametrization in t for a great circle going through the two points and an interator giving the short great circle arc between the two points. greatCircleArc[{pt1_, pt2_}] := Module[{n, e1, e2, t1, t2}, n = pt1[Cross]pt2; {e1, e2} = (NullSpace[{N[n]}]) // Chop; t1 = ArcTan @@ (pt1.# & /@ {e1, e2}); t2 = ArcTan @@ (pt2.# & /@ {e1, e2}); {t1, t2} = Sort[{t1, t2}]; {t1, t2} = Which[ t2 - t1 <= Pi, {t1, t2}, t2 - t1 > Pi, {t2, 2Pi + t1}]; {Cos[t]e1 + Sin[t]e2, {t, t1, t2}}] You can use that to plot the arc in a 3D plot. Since I want to combine a number of elements in the plot I find it much easier to use my DrawGraphics package from my web site. Here is the code for a plot that draws a wire frame sphere, the two points, the short arc and the complete great circle. Needs[DrawGraphics`DrawingMaster`] pts = twoPoints; plotargs = greatCircleArc[pts]; Draw3DItems[ {(* Draw WireFrame sphere *) ColorMix[Cobalt, Gray][0.5], ParametricDraw3D[{Cos[t]Sin[p], Sin[t]Sin[p], Cos[p]}, {p, 0, Pi}, {t, 0, 2Pi}, PlotPoints -> {15, 31}] // UseWireFrame, (* Draw entire great circle *) PermanentGreen, ParametricDraw3D[First[plotargs] // Evaluate, {t, 0, 2Pi}], (* Draw short great circle arc *) AbsoluteThickness[2], EnglishRed, ParametricDraw3D @@ plotargs, (* Plot the two points *) AbsolutePointSize[6], Black, Point /@ pts}, BoxStyle -> LightGray, Background -> Linen, ImageSize -> 450]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ ==== > I have the following problem. Given two random points on a sphere, I would > like to connect them with a curve that goes 'approximately' on the sufrace > line segments. Connecting the points with a straigh line is achived by Line[{pt1,pt2}]. I am failing to get good ideas on how to approach the problem, would > appreciate any hint / trick / tip. see this example (needs Java): http://wwwvis.informatik.uni-stuttgart.de/~kraus/LiveGraphics3D/examples/par ametrized/greatcircle.html -- Kraus, Visualization and Interactive Systems Group (VIS) http://wwwvis.informatik.uni-stuttgart.de/~kraus/ -- Who does not move, cannot get lost. (Alfred Werner) ==== your example does work if you put << Graphics`MultipleListPlot` into a seperate cell of its own and evaluate it first of all. Matthias Bode. -----UrsprÌ.b9ngliche Nachricht----- Gesendet: Dienstag, 10. Dezember 2002 10:11 An: mathgroup@smc.vnet.net Betreff: MultipleListPlot not working I can't get this function to do anything. I read it in with Needs[Graphics`MultipleListPlot`]; and no error messages appear, and the file IS present in this directory: C:Program FilesWolfram ResearchMathematica4.1 (2)AddOnsStandardPackagesGraphics'MultipleListPlot.m but when I do an example right out of Help such as << Graphics`MultipleListPlot` (list1 = Table[{x, Sin[2 Pi x]}, {x, 0, 1, 0.1}]; list2 = Table[{x, Cos[2 Pi x]}, {x, 0, 1, 0.1}]); MultipleListPlot[list1, list2] , nothing appears (no plot shows) except this text !(MultipleListPlot[{{0, 0}, {0.1`, 0.5877852522924731`}, {0.2`, 0.9510565162951535`}, {0.30000000000000004`, 0.9510565162951535`}, {0.4`, 0.5877852522924732`}, {0.5`, 1.2246063538223773`*^-16}, {0.6000000000000001`, (-0.5877852522924734`)}, {0.7000000000000001`, (-0.9510565162951535`)}, {0.8`, (-0.9510565162951536`)}, {0.9`, (-0.5877852522924734`)}, {1.`, (-2.4492127076447545`*^-16)}}, {{0, 1}, {0.1`, 0.8090169943749475`}, {0.2`, 0.30901699437494745`}, {0.30000000000000004`, (-0.30901699437494756` )}, {0.4`, (-0.8090169943749473`)}, {0.5`, (-1.`)}, {0.6000000000000001`, (-0.8090169943749472`)}, {0.7000000000000001`, (-0.30901699437494756`)}, {0.8`, 0.30901699437494723`}, {0.9`, 0.8090169943749473`}, {1.`, 1.`}}]) ==== Steven, With a highly oscillatory function like that you need to increase the number of PlotPoints. Otherwise Mathematica begins to miss some of the features of the curve. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ STH Hatton's Law: There is only One inviolable Law. ==== Steven, observe: In[2]:= Options[Plot, PlotPoints] Out[2]= {PlotPoints -> 25} As you used the default, 25 plot points are not only not enough to reasonably display the rapidly oscillating function, they are also too few starting points for the adaptive sampling algorithm. Just increase, e.g. Plot[x Sin[x], {x, -100, 100}, PlotPoints -> 333] is quite pleasing to the eye, even if enlarged. -- >-----Original Message----- >To: mathgroup@smc.vnet.net >{-100,100}] and >disvovered that the portion of the plot between,9.5Pi and 11Pi >is displayed >as a line segment joining the points {9.5 , 9.5 Sin[9.5]} and {11 , 11 >Sin[11]}. I've also found that the plot from x=-100 to >x=99.99 is incorrect. >The plot over the range [-100,99] is correct. What is >happening here? Does >this happen on other systems? >-- ==== I'm trying to do a 2 dimensional convolution of the Airy disk with the image of an extended source in an optical system, using the Digital Image Processing package. Does anyone have an example routine for doing this? ==== Many thanks for all the suggestions from Allan, Harmut, Daniel. In my original post I did not specify why I was interested in the sorting algorithm. The purpose was to generate what are called DNA dot plots which can be used to compare two DNA sequences. For eaxmple, consider the following sequences myDNA1 = TCTGCTTTCTTCCAAATTGATGCTGGATAGAGGTGTTTATTTCTATTCTCATATTCCTAA GTAAAACAGATAACTGCCTCTCAACTATATCAAGTAGACTAAAATATTGTGCGTCCTGAACCTCTAAGTATGCGTC CTGAACCTCTAAGTATCATATTCCTAAGTAAAACAGATAACTGCCTCTCAACTATATCAAGTAGACTAAAATATTGT CGGGTGCCTGTAGTCCCAGCTACTCGGGAGGCTGAGGCAGGAGAATGGCGTGAACCTGGAAGGCAGAGCTGCAGTGA GCAGAGATCG; myDNA2 = ACAAGAAGGCTGCTGCCACCAGCCTGTGAAGCAAGGTTAAGGTGAGAAGGCTGGAGGTGAGATTCTGGGCAGGTA GGTACTGGAAGCCGGGGCAAGGTGCAGAAAGGCAGAAAGTGTTTCTGAAAGAGGGATTAGCCCGTTGTCTTACACAT ATTCCTAAGTAAAACAGATAACTGCCTCTCAACTATATCAAGTAGACTAAAATATTGTGCGTCCTGAACCTCTAAGT ATGCGTCCTGAACCTCTAAGTATCATATTCCTAAGTAAAACAGATAACTGCCTCTCAACTATATCAAGTAGACTAAA ATATTGTTAGTCTGACTTTGCACCTGCTCTGTGATTATGACTATCCCACAGTCTCCTA; These sequences were engineered to have several common blocks of DNA. Using the following program a plot is generated that shows the alignment of the DNA blocks ( I have used one of Allan's algorithms (Matchings7) for searching for common DNA blocks dotPlot1[dna1_, dna2_, BlockSize_, offset_] := Module[{st, pt, sp, s1, s2, s, rr}, s1 = MapIndexed[List[#, (First[#2] - 1)offset + 1] &, Map[StringJoin[#] &, Partition[Characters[dna1], BlockSize, offset], 1]]; s2 = MapIndexed[List[#, (First[#2] - 1)offset + 1] &, Map[StringJoin[#] &, Partition[Characters[dna2], BlockSize, offset], 1]]; s = {s1, s2}; st = #[[Ordering[#[[All, 1]]]]] & /@ s; sp = Split[#, #1[[1]] === #2[[1]] &] & /@ st; pt = (Alternatives @@ (Intersection @@ st[[All, All, 1]])); rr = Transpose[Cases[#, {{pt, _}, ___}] & /@ sp]; ListPlot[ Flatten[Apply[Outer[List, ##, 1] &, rr, {1}], 2] /. {{a_String, x1_}, {b_String, y1_}} -> {x1, y1}, AspectRatio -> 1, PlotStyle -> {RGBColor[0, 0, 1]}, Frame -> True, FrameLabel -> {DNA 1, DNA 2}, RotateLabel -> False, Axes -> False]] dotPlot1[myDNA1, myDNA2, 6, 1] One of the reasons Allan's code is so efficient is the use of patterns in Cases and Intersection. The question then arises how would one proceed if the test is not the equality of blocks, but some other measure. For example 2 blocks of 8 nucleotides are equal if at least 6 of the eight bases match , e,g, newTest:=Count[Characters[#1]-Characters[#2],0]>6& I have attempted a search using such a test but my code cannnot compete with Allan's or the various variants that have been suggested. The bottleneck is in Cases or Intersection. I did find that if my test used StringMatchQ[block1, block2, SpellingCorrection-> True], I got quite good performance, though this test is not precise, and I was not able to extend it. Would be nice to be able to modify the criteria used in SpellingCorrection so that it gives True for user defined criteria. Brian > I give below some further speed-ups. > The improvement, at least on the data I used, is due to using > Split[Sort[_]] right at the start to parcel the data - it probably depends > on there being a lot of repetition of the first term of the entries in the > data. > The code for Matchings6 below is faster than Daniel Lichblau's recently > posted code - though he suggests that this might be speeded up by > substituting numbers for strings and compiling. Data Random[Integer, {1, 2000}]}, {6000}]; > Random[Integer, {1, 2000}]}, {12000}]; Get the members of s1 with the same first entry as some member of s2. Previous code (preserves order) Matched1[s1_,s2_]:= > Cases[ s1,{Alternatives@@Union[s2[[All,1]]],_}] Matched1[s1,s2];//Timing {3.4 Second,Null} New code (does not preserve order) - note the use of s1[[Ordering[s1[[All, > 1]]]]] to save on ordering with respect to the second entries Matched4[s1_,s2_]:= > Cases[Split[s1[[Ordering[s1[[All,1]]]]], #1[[1]]===#2[[1]]&], > {{Alternatives@@Union[s2[[All,1]]],_},___}] Matched4[s1,s2];//Timing {1.6 Second,Null} > Get the full matchings (this code will work on {s1,s2 ,....,sn}, as well as > just {s1, s2}) Matchings7[s_]:= > Module[{st,pt,sp}, > st = #[[Ordering[#[[All,1]]]]]&/@s; > sp=Split[#,#1[[1]]===#2[[1]]&]&/@st; > pt= (Alternatives@@(Intersection@@ st[[All,All,1]])); > Transpose[Cases[#,{{pt,_},___}]&/@sp] > ]; (ms7=Matchings7[{s1,s2}]);//Timing {3.46 Second,Null} > Daniel Lichtblau (gives essentially the same information as Matchings7) myTest[l1_, l2_] := > Module[{s1, s2, m = Length[l1], n = Length[l2], j, k, res = {}, ord }, > s1 = Sort[l1]; s2 = Sort[l2]; > For[j = 1; k = 1, j <= m && k <= n, Null, > ord = Order[s1[[j,1]], s2[[k,1]]]; > If[ord == 1, j++; Continue[]]; > If[ord == -1, k++; Continue[]]; > res = {res, {s1[[j]], s2[[k]]}}; > j++; k++; > ]; > Partition[Partition[Flatten[res], 2], 2] > ] myTest[s1,s2];//Timing {7.47 Second,Null} > -- ==== >-----Original Message----- I give below some further speed-ups. >The improvement, at least on the data I used, is due to using >Split[Sort[_]] right at the start to parcel the data - it probably depends >on there being a lot of repetition of the first term of the entries in the >data. Yes, the idea is, to exploit all work already done, and Composition[Split,Sort] appears to be a fundamental design pattern for the language! >The code for Matchings7 below is faster than Daniel Lichblau's recently >posted code - though he suggests that this might be speeded up by >substituting numbers for strings and compiling. Data Random[Integer, {1, 2000}]}, {6000}]; > Random[Integer, {1, 2000}]}, {12000}]; Get the members of s1 with the same first entry as some member of s2. Previous code (preserves order) Matched1[s1_,s2_]:= > Cases[ s1,{Alternatives@@Union[s2[[All,1]]],_}] Matched1[s1,s2];//Timing {3.4 Second,Null} New code (does not preserve order) - note the use of >s1[[Ordering[s1[[All, 1]]]]] to save on ordering with respect to the second entries Matched4[s1_,s2_]:= > Cases[Split[s1[[Ordering[s1[[All,1]]]]], #1[[1]]===#2[[1]]&], > {{Alternatives@@Union[s2[[All,1]]],_},___}] Matched4[s1,s2];//Timing {1.6 Second,Null} > This is very pleasing, and a general pattern if I understand Union[s2[[All,1]]] as the sorted list of keys searched. A slight improvement is still possible though. We suffer from a performance penalty imposed by the test function for Split. I had already published how to overcome this, here now recalled in a procedure: Attributes[SortSplit1] = {HoldFirst}; SortSplit1[s_] := Module[{ord = Ordering[s[[All, 1]]], secs}, secs = FoldList[Plus, 0, Length /@ Split[s[[ord, 1]] ]]; s[[Take[ord, #]]] & /@ Transpose[{Drop[secs + 1, -1], Drop[secs, 1]}]] ssb = SortSplit1[s1]; // Timing {0.271 Second, Null} whereas ssa = Split[s1[[Ordering[s1[[All, 1]]]]], #1[[1]] === #2[[1]] &]; // Timing {0.571 Second, Null} In[19]:= ssa == ssb Out[19]= True The Hold-Attribute for SortSplit1 is essential for its performance! If you don't want to give that, you alternatively may make a local copy of the argument as in SortSplit1x[s1_] := Module[{s = s1}, Module[{ord = Ordering[s[[All, 1]]]}, s[[Take[ord, #]]] & /@ With[{secs = FoldList[Plus, 0, Length /@ Split[s[[ord, 1]] ]]}, Transpose[{Drop[secs + 1, -1], Drop[secs, 1]}]]]] ssx = SortSplit1x[s1]; // Timing {0.301 Second, Null} In[56]:= ssx == ssa Out[56]= True I observe this, yet my understanding of Mathematica is not deep enough to explain it, let alone use this to deduce, so to speek, improved coding. Such I have to store it in my brain as an ad-hoc rule of surmise. I would be very pleased to have that clarified. With this we now may tweak Matched4 a bit further: Attributes[Matched4bis] = {HoldAll}; Matched4bis[s1_, s2_] := Cases[SortSplit1[s1], {{Alternatives @@ Union[s2[[All, 1]]], _}, ___}] (The need to Hold propagates! Not for SortSplit1x of course) Matched4x[s1_, s2_] := Cases[SortSplit1x[s1], {{Alternatives @@ Union[s2[[All, 1]]], _}, ___}] In[58]:= Matched4[s1, s2]; // Timing Out[58]= {1.061 Second, Null} In[59]:= Matched4bis[s1, s2]; // Timing Out[59]= {0.761 Second, Null} In[60]:= Matched4x[s1, s2]; // Timing Out[60]= {0.781 Second, Null} Get the full matchings (this code will work on {s1,s2,....,sn}, as well as >just {s1, s2}) Matchings7[s_]:= > Module[{st,pt,sp}, > st = #[[Ordering[#[[All,1]]]]]&/@s; > sp=Split[#,#1[[1]]===#2[[1]]&]&/@st; > pt= (Alternatives@@(Intersection@@ st[[All,All,1]])); > Transpose[Cases[#,{{pt,_},___}]&/@sp] > ]; (ms7=Matchings7[{s1,s2}]);//Timing {3.46 Second,Null} > I didn't manage to introduce SortSplit1 into Matchings7 (the Hold mechanisms seems to break down when Mapping SortSplit1 over the argument), however it works with SortSplit1x: Matchings7x[s_] := Module[{pt, sp}, sp = SortSplit1x /@ s; pt = (Alternatives @@ (Intersection @@ s[[All, All, 1]])); Transpose[Cases[#, {{pt, _}, ___}] & /@ sp]]; In[173]:= ms7x = Matchings7x[{s1, s2}]; // Timing Out[173]= {1.652 Second, Null} In[174]:= ms7 = Matchings7[{s1, s2}]; // Timing Out[174]= {2.364 Second, Null} In[175]:= ms7ax == ms7 Out[175]= True Well, I just made it (writing calls upon thinking): Attributes[Matchings7a] = {HoldAll}; Matchings7a[s_] := Module[{pt, sp}, sp = SortSplit1 /@ Unevaluated[s]; pt = (Alternatives @@ (Intersection @@ s[[All, All, 1]])); Transpose[Cases[#, {{pt, _}, ___}] & /@ sp]]; In[227]:= ms7a = Matchings7a[{s1, s2}]; // Timing Out[227]= {1.572 Second, Null} Daniel Lichtblau (gives essentially the same information as Matchings7) myTest[l1_, l2_] := > Module[{s1, s2, m = Length[l1], n = Length[l2], j, k, res = {}, ord }, > s1 = Sort[l1]; s2 = Sort[l2]; > For[j = 1; k = 1, j <= m && k <= n, Null, > ord = Order[s1[[j,1]], s2[[k,1]]]; > If[ord == 1, j++; Continue[]]; > If[ord == -1, k++; Continue[]]; > res = {res, {s1[[j]], s2[[k]]}}; > j++; k++; > ]; > Partition[Partition[Flatten[res], 2], 2] > ] myTest[s1,s2];//Timing {7.47 Second,Null} > I do not agree, as to this containing the same information, see: In[239]:= my = myTest[s1, s2]; // Timing Out[239]= {5.578 Second, Null} In[242]:= Length /@ {my, ms7} Out[242]= {5944, 625} In[243]:= Composition[Length, Union, Flatten] /@ {my, ms7} Out[243]= {2592, 2624} In[244]:= Length /@ {my, Flatten[ms7, 1]} Out[244]= {5944, 1250} Or compare In[248]:= ms7[[1]] Out[248]= {{{AAAA, 747}, {AAAA, 1580}, {AAAA, 1929}, {AAAA, 1277}}, {{AAAA, 1241}, {AAAA, 658}, {AAAA, 141}, {AAAA, 1567}, {AAAA, 371}, {AAAA, 861}, {AAAA, 1963}, {AAAA, 1607}, {AAAA, 316}, {AAAA, 1674}, {AAAA, 1501}, {AAAA, 1749}, {AAAA, 1777}, {AAAA, 172}, {AAAA, 568}, {AAAA, 1752}}} In[250]:= Take[my, 10] Out[250]= {{{AAAA, 747}, {AAAA, 141}}, {{AAAA, 1277}, {AAAA, 172}}, {{AAAA, 1580}, {AAAA, 316}}, {{AAAA, 1929}, {AAAA, 371}}, {{AAAB, 417}, {AAAB, 18}}, {{AAAB, 1521}, {AAAB, 332}}, {{AAAB, 1526}, {AAAB, 396}}, {{AAAB, 1693}, {AAAB, 525}}, {{AAAB, 1961}, {AAAB, 664}}, {{AAAB, 1976}, {AAAB, 827}}} Quite a lot is missing here! This is caused by the fact that at match, when Order[...] == 0, both pointers j, k are incremented, such elements from the longer sequence at this (matching) key will disappear. I had already communicated a procedural solution, here adapted to your form of output: myMatch4[s1_, s2_] := Module[{ss1 = Sort[s1], ss2 = Sort[s2], keys, rr1, rr2}, keys = Intersection[ss1[[All, 1]], ss2[[All, 1]]]; rr1 = getLabelled[ss1, keys]; rr2 = getLabelled[ss2, keys]; Transpose[{rr1, rr2}]] In[266]:= my4 = myMatch4[s1, s2]; // Timing Out[266]= {5.748 Second, Null} In[267]:= Map[Sort, ms7, {2}] === my4 Out[267]= True One might obtain Brian's form just by Apply'ing Outer[List,##,1]& at level {1} to get all matching pairs. -- > Here now a better procedural solution, combining Daniel's ansatz with observations made so far: myMatch5[s1_, s2_] := Module[{ss1 = SortSplit1[s1], ss2 = SortSplit1[s2], acc}, Module[{u1 = ss1[[All, 1, 1]], u2 = ss2[[All, 1, 1]], j = 1, jx = Length[ss1], k = 1, kx = Length[ss2], res = acc[]}, While[j <= jx && k <= kx, Switch[Order[u1[[j]], u2[[k]]], 1, ++j, -1, ++k, 0, (res = acc[res, {ss1[[j]], ss2[[k]]}]; ++j; ++k)] ]; List @@ Flatten[res, Infinity, acc]]] In[277]:= my5 = myMatch5[s1, s2]; // Timing Out[277]= {2.313 Second, Null} In[278]:= my5 === ms7 Out[278]= True Effectively this is a prototype of a Sort-Merge procedure, pairing subsequences of equal keys. Although Mathematica has a most performant Sort procedure, there is nothing comparable for the merge step. Having this one (or something similar) in the kernel, certainly would add value to the product. SortSplit1 may be considered too. Hartmut ==== A correspondent has sent me the following problem. I want to calculate the intersection of an ellipse ((x-c)^2/b^2 + (y-d)^2/a^2 ==1) with centre at the point (c,d) and a circle (x^2 + y^2 == 1) with centre at(0,0). What are the formal point solutions?. ellipse = (x - c)^2/b^2 + (y - d)^2/a^2 == 1; circ = x^2 + y^2 == 1; sol = Solve[{ellipse, circ}, {x, y}]; The output comes out immediately as a rather long expression. However, when trying to obtain numerical values for given values of a, b, c, and d, I get complex numbers, and even in the case where their imaginary part is close to 0, the real part doesn't correspond at all to the solution (as seen in an implicit plot of the two figures). I'm at a loss! What's going on? Tomas Garza Mexico City ==== I have the following in mathematica : x[z_]:=1000Log[10]-ProductLog[z] I would like to be able to execute this from a shell or C code. CForm just outputs : CForm[1000Log[10] - ProductLog[z]] 1000*Log(10) - ProductLog(z) Is it possible to compile 'ProductLog' to a C library or even an executable which I can then use in C code ? thanks Matt -- http://mffm.darktech.org WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/ FFTw C++ : http://mffmfftwrapper.sourceforge.net/ Vector Bass : http://mffmvectorbass.sourceforge.net/ Multimedia Time Code : http://mffmtimecode.sourceforge.net/ ==== I have found the example 'factor.c'. Unfortunatly there are problems with running the program ... something to do with 'MLOpenArgv' ... when the program is run it requests : 'Create link:' thanks MAtt > I have the following in mathematica : > x[z_]:=1000Log[10]-ProductLog[z] I would like to be able to execute this from a shell or C code. CForm > just outputs : > CForm[1000Log[10] - ProductLog[z]] > 1000*Log(10) - ProductLog(z) Is it possible to compile 'ProductLog' to a C library or even an > executable which I can then use in C code ? thanks > Matt > -- > http://mffm.darktech.org WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/ > FFTw C++ : http://mffmfftwrapper.sourceforge.net/ > Vector Bass : http://mffmvectorbass.sourceforge.net/ > Multimedia Time Code : http://mffmtimecode.sourceforge.net/ -- http://mffm.darktech.org WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/ FFTw C++ : http://mffmfftwrapper.sourceforge.net/ Vector Bass : http://mffmvectorbass.sourceforge.net/ Multimedia Time Code : http://mffmtimecode.sourceforge.net/ ==== I have found the arguments to start with under Unix : lp=MLOpenString(ep, -linkname math -mathlink, &err); problem solved. thanks Matt > I have found the example 'factor.c'. Unfortunatly there are problems with running the program ... something > to do with 'MLOpenArgv' ... when the program is run it requests : > 'Create link:' thanks > MAtt > I have the following in mathematica : > x[z_]:=1000Log[10]-ProductLog[z] > I would like to be able to execute this from a shell or C code. CForm > just outputs : > CForm[1000Log[10] - ProductLog[z]] > 1000*Log(10) - ProductLog(z) > Is it possible to compile 'ProductLog' to a C library or even an > executable which I can then use in C code ? > thanks > Matt > -- > http://mffm.darktech.org > WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/ > FFTw C++ : http://mffmfftwrapper.sourceforge.net/ > Vector Bass : http://mffmvectorbass.sourceforge.net/ > Multimedia Time Code : http://mffmtimecode.sourceforge.net/ -- > http://mffm.darktech.org WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/ > FFTw C++ : http://mffmfftwrapper.sourceforge.net/ > Vector Bass : http://mffmvectorbass.sourceforge.net/ > Multimedia Time Code : http://mffmtimecode.sourceforge.net/ -- http://mffm.darktech.org WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/ FFTw C++ : http://mffmfftwrapper.sourceforge.net/ Vector Bass : http://mffmvectorbass.sourceforge.net/ Multimedia Time Code : http://mffmtimecode.sourceforge.net/ ==== just a small question. I export my graph by Export[file.eps, %, EPS]. All works well exept axes labels. In my .ps file there is no ratio sign / or a horizontal line between y and y0 while they are available on a Mathematica graph. Ok, I tried x:x0 and it works, but it looks not so elegant (to my mind, but I keep it as a default now). Is it possible to do something? It's not very crucial but nevertheless... ==== Gentlemen; We are a research group on mineral processing of INGEOMINAS; which is a geological institute here in Colombia and are interested in knowing if could use this software to solve kinetics expression like the following: t= C1g(X)+C2p(X) Where g(x) = 1- ( 1-X)^1/3 and p(X) = 1- 3(1-X)^2/3 +2( 1-X); t=time(min); X = extent of reaction % ; According with bibliography ,through the method of Nedler and Mead (Flexible Polyhedron search method)C1 and C2 can be obtained from minimization of the function. We would greateful if you could give us an orientation to solve our experimental problem. I would ask you an special collaboration to develop one example with the correct syntax using the experimental results sent in the attachment file. [contact the author to obtain collaboration and orientation. Carlos Espitia Georecursos Area INGEOMINAS Diagonal 53 # 34 ö 53 Bogota ö Colombia ==== >Good day, > I have a question about the utilization of FITS format. I have >Mathematica 4.2 for Students and I'm trying to display and analyze those >images. Since 4.2 is suppose to have added the FITS format to the list of >recognized formats how come I cannot use the standard functions to view and >manipulate them? > I use > image=Import[m22.fits]; > Then > Show[image] >It does not display anything! >I bought the add-on Digital Image Processing (1.1) and again I cannot use >any of the functions in that package. In a nut shell: I thought that FITS format could be used the same way a JPEG >format or any image (pic) format is used (displayed,manipulated,analyzed). Am I doing something wrong or maybe I did not understand something about >this new feature in Mathematica 4.2? Robert Pigeon While many people think of FITS as an image format, it is actually a data format. So the output of Import is data. In[1]:= data=Import[cb.fits]; The data is a list of matrices. The length of the data will tell you how many matrices there are: In[2]:= Length[data] Out[2]= 1 The data in each matrix usually represents an intensity. You can then use a variety of functions to plot one of the matrices. ListDensityPlot is what you see in many FITS viewers. In[3]:= ListDensityPlot[First[data], Mesh->False] -DensityGraphics- In[4]:= ListContourPlot[First[data]] Out[4]= -ContourGraphics- In[5]:= ListPlot3D[First[data], Mesh->False] Out[5]= -SurfaceGraphics- -Dale ==== [Gianluca - I have reset your question a little - Allan] I am confused by this result: Module[{a},a=x;g[x_]=a] x g[y] x ?g Global`g g[x$_] = x Somehow I would expect the same output as Module[{},a=x;g[x_]=a] x g[y] y ?g Global`g g[x_] = x The difference is a dollar sign. | > | Italy | > +---------------------------------+ > | Ph.: (39) 0432-558422 | > | http://www.dimi.uniud.it/~gorni | > +---------------------------------+ EXPLANATION FIRST EXAMPLE: Module[{a},a=x;g[x_]=a] In Module 1) the occurences of variable a are renamed to a$n (standard evaluation of Module); 2) because the a in g[x_]= a is in the target of the x in x_ , and in the target of the a in {a}, the x is changed to x$ (standard scoping renaming to avoid clashes - not specific to Module); giving Module[{a$n},a$n=x;g[x$_]=a$n] The body of Module, a$n=x; g[x$_]=a$n, is now evaluated. The rule for g[x$_] = x is stored. The output from Module is x SECOND EXAMPLE: Module[{},a=x;g[x_]=a];g[y] There is no renaming When the body of Module is evaluated the rule for g[x_]=x is stored. We can follow the evaluations with TracePrint. ==== of scoping is so poor. My rule-of-thumb for making Module[] was to start off without local variables, for example: Module[{}, num = x^2; den = 1 + x^2; h[x_] = num/den; h'[1]] so that I can debug easily. When I finally get it to work I add the list of the local variables: Module[{num, x, den, h}, num = x^2; den = 1 + x^2; h[x_] = num/den; h'[1]] But now it is broken! I wish to be enlightened on this issue: How can I safely write a function definition inside a Module? Gianluca Gorni > To: gorni@dimi.uniud.it > >> I am confused by this result: >> >> In: Module[{a}, a = x; g[x_] = a]; g[y] >> >> Out: x >> >> Somehow I would expect the same output as >> >> In: Module[{}, a = x; g[x_] = a]; g[y] >> >> Out: y >> >> In the first case ?g gives g[x$_] = x, >> while in the second it gives g[x_] = x. >> The difference is a dollar sign. >> >> Can anyone explain why the dollar is inserted in one case >> but not in the other? The x was not a local variable >> in either case. Since the names of named patterns in rules and definitions > are treated as local variables, the x in the definition of > g[x_] is a local variable in these examples (section 2.6.4 > in The Mathematica Book). Module[{a}, a = x; g[x_] = a] > therefore contains nested scoping constructs, so the local > symbol x in g[x_] = a is renamed to prevent a potential > conflict with the variable a from the enclosing Module. In Module[{}, a = x; g[x_] = a], where there are no conflicting > variables from the nested scoping constructs, the definition of > g is evaluated as if the Module was not present. Since this > definition is an immediate assignment, the right side of the > assignment is not held unevaluated, and will be affected by > definitions (such as the now global definition of a) that are > present when the assignment is evaluated. If you use a delayed assignment for the definition of g > then both inputs will show the same result: In[1]:= Module[{a},a=x;g[x_]:=a];g[y] Out[1]= x In[2]:= Module[{},a=x;g[x_]:=a];g[y] Out[2]= x The only fundamentally troublesome issue here is that immediate > assignments are treated as scoping constructs even though they > do not hold their arguments unevaluated. ==== Anto Ü«é.91ì.9eì[Cent ]Üåë.81:at4clf$es3$1@smc.vnet.net... > Can i make mathematica 4 show me the whole procedure it does before spitting > out the result? Try to use the function: Trace[ ] Trace[expr] generates a list of all expressions used in the evaluation of expr. Trace[expr, form] includes only those expressions which match form. Trace[expr, s] includes all evaluations which use transformation rules associated with the symbol. ------------ Andy£¬in Chinese called ê.9b.85£ñÇ£© bachelor of science Xi'an Jiaotong University Xi'an,ShaanXi,710049 P.R.China http://wangzhengyao.xiloo.com ==== in general no. You can try Trace[] or On[functionName] Can i make mathematica 4 show me the whole procedure it does before spitting > out the result? ==== Anto, This is the kind of question that is very difficult to answer because you give very little information. Which procedure? What kind of problem? What do you mean by the whole procudure? Nor is the subject title of the posting very helpful for people searching the archives. Many of the high level routines in Mathematica such as Solve, Integrate, etc., are written in C-code and employ advanced algorithms that are probably very difficult to follow and not at all educational or enlightening. So, you can't see and probably don't want to see everything that is going on. However, for purposes of learning methods you don't have to use all of Mathematica's advanced routines. You can program Mathematica to do the steps and see how some procedure you are trying to learn can be implemented. For example, at my web site I have an introductory notebook that shows how to solve equations without using the Solve routine, but doing it step by step. On the other hand if you have a question about how some advanced routine works, you will have to take it up with WRI and may not find them all that forthcoming. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator ==== Try to use the function: Trace[ ] Trace[expr] generates a list of all expressions used in the evaluation of expr. Trace[expr, form] includes only those expressions which match form. Trace[expr, s] includes all evaluations which use transformation rules associated with the symbol ------------ Andy£¬in Chinese called ê.9b.85£ñÇ£© bachelor of science Xi'an Jiaotong University Xi'an,ShaanXi,710049 P.R.China http://wangzhengyao.xiloo.com ==== With default settings, apparently Mathematica plots curves with precision limited by typical printers. I need to export these plots to Corel Draw and view them under very high magnification. But viewed this way many of the close-together points in my plots coincide, whereas I know they don't in reality. Is there a way to get these plots with much greater precision? (The export process using Enhanced Metafile otherwise works very well; even the object grouping is what I want.) Or is there another way, for example writing an Excel file and plotting there? (I'm an Excel user but no expert and I doubt that it can make high precision plots.) ==== Users with HP PA-RISC1.1 processor can use Mathematica 4.2 but without graphics: $ file mathematica/4.2/SystemFiles/Graphics/Binaries/HP-RISC/* makepsres: PA-RISC1.1 shared executable motifps: PA-RISC2.0 shared executable dynamically linked psrender: PA-RISC1.1 shared executable fortunately Could you, please, consider recompiling motifps for HP PA-RISC1.1 processor and puting it on the web? -- Pavel Pokorny Math Dept, Prague Institute of Chemical Technology http://staffold.vscht.cz/mat/Pavel.Pokorny ==== Have no idea why it is doing this but interesting to note that if you replace d by a specific value you always seem to get Pi rather than 0 as an answer. Also, you might want to look at the integals from 0 to Infinity and -Infinity to 0 (the latter is especially messy for a specific value of d). Maybe a clue there. > Using version 4.1, Integral[Sin[x+d]/(x+d),{x,-Infinity,Infinity}] yields 0 . This is, of course, incorrect. (Does version 4.2 make this error also?) Mathematica does Integral[Sin[x]/x,{x,-Infinity,Infinity}] correctly > however, yielding Pi, which should also be the answer for the original > integral (regardless of the value of d). Does anyone have an idea why Mathematica gets the original integral wrong? > ==== and have found another entirely separate curious behavior which I do not understand. First, if we ask Mathematica (version 4.1) to Integrate[Sin[x+d]/(x+d), {x, -Infinity, 0}] we get, incorrectly, -Pi/2 + SineIntegral[d]. A correct result would have been +Pi/2 + SineIntegral[d]. The incorrect behavior above presumably explains, in some sense, what I had noted in my previous post: Integrate[Sin[x+d]/(x+d), {x, -Infinity, Infinity}] incorrectly yields 0. Second, it seems that Mathematica does get correct answers for such integrals if d is given as a specific value. But sometimes the answer is quite needlessly complicated. For example, Integrate[Sin[x+Pi]/(x+Pi), {x, -Infinity, 0}] yields the messy result (Pi*(-2 + Sqrt[2]*BesselJ[1/2, Pi])*Log[2])/2 - (Pi*(-2 + Sqrt[2]*BesselJ[1/2, Pi])*Log[4])/4 + (I/2)*(I*Pi + 2*Pi^2 - (2*I)*Pi*Log[Pi]) - ((-2 + Sqrt[2]*BesselJ[1/2, Pi])*(EulerGamma*Pi^(3/2) - I*Pi^(5/2) - Pi^(3/2)*Log[Pi]))/(2*Sqrt[Pi]) + (Pi^(3/2)*(-(((-2 + Sqrt[2]*BesselJ[1/2, Pi])*Log[2])/ Sqrt[Pi]) - (EulerGamma*Pi - 2*SinIntegral[Pi] + SinIntegral[2*Pi])/Pi^(3/2) - (-4*Sqrt[Pi] + 2*EulerGamma*Sqrt[Pi] + 2*Sqrt[Pi]*Log[4] - Sqrt[2*Pi]* Derivative[1, 0][BesselJ][1/2, Pi])/(2*Pi)))/2 But Pi/2 + SineIntegral[Pi] is a much simpler correct answer! BTW, asking for a numerical approximation of the messy answer above, we get correctly 3.42273 + 1.77635*10^-15*I . (Of course, the precise answer is purely real. The very small imaginary component in the approximation is an understandable artifact.) Now here's the new behavior I can't understand: Suppose that we ask Mathematica to Simplify the messy result above, hoping that it will be smart enough to give us something like Pi/2 + SineIntegral[Pi] . Instead, we get Indeterminate preceded by the comment !(Power::indet ((:)( )) Indeterminate expression !(0``68.9889^0) encountered.) Now it's bad enough that Mathematica thinks the result is Indeterminate, but what I really can't grasp is how floating-point values could possibly be involved in this matter: The messy expression to be simplified was _precise_! Floating-point values should have nothing to do with its simplification. Curiously, ==== >Allan > > I type primitives in the Master Index and get section 2.9.1, which does > not > have a list of all the primitives. Yes, of course I found it sooner or > later. > But that's not a good index. > All I can say is that, when someone asks me about Mathematica, I'll say it > is > hard to use for many reasons, and one of them is the poor documentation. > Dave Golber I agree that the documentation is extensive, but at the same time it's inadequate. For example try to find out how to delimit a function (subroutine) definition without using Module[{x}, . Or try to find how to put several statements together in one branch of an If statement. Or try to find a clear and complete explanation of exactly how to increase the precision of all computations in a notebook. The first two I guessed at and have answers for. The last one I still don't know. I may be unusual in that I work alone, have no one to ask questions of verbally, and will not pay over $1000 for a 2-day course. ==== > So today I'm doing some graphics. Oh: there are _options_ and _directives_. > So I try to find out what are all the graphics primatives? > When you look in the index of the 1500 page book, or type Graphics Primatives > in the on-line Help, you don't find it. You have to look under Graphics or > Graphics3D. In the book, it's in the appendix. > And the entry in the appendix is not quite complete: > It says Graphics[primatives, options] represents a two-dimensional graphical > image. > It should say returns a graphis object The reason is that the appendix is > the place for the complete and formal description of the functions and all > their arguments and returns. No longer the place for chatty-teachy. > (represents is chatty-teachy) > To understand the system, I need to be able to trace the sequence > Line[...] is a graphics _primative_ > Graphics[ ... graphics primatives ....] is a graphics _object_ > Show [... graphics object...] puts a picture on the screen. > I don't know if this sounds dumb on my part, but I do know that I have just > wasted a bunch of time on this, and that having to go back and forth just to > find out the type of the return of a function (to use old fashioned > nomenclature) .... which people knew thirty years ago was part of documenting a > system .... seems pretty dumb on the part of Mathematica. > Dave Golber GRAY: Here again I agree. All the different kinds of graphic-related entities are quite confusing. The only way I cope is to copy a working graphic sequence and change it bit by bit until it does what I want. This usually works but is very slow. I have wasted hours on this. I expect better from documentation of an expensive professional product. Another thing that bothers me is that the error messages tell me nowhere near enough to help find the error easily. And so far as I know most of these messages are not documented anywhere. There are about 12 entries under error in the book but there should be a place where you can just look up anything that appears in the microscopic blue print. ==== I observed the same thing, except I was computing closures on a large number of graphs, again using combinatorica. I examined the combinatorica code and couldn't find any place where it was holding on to references internally, but none the less I fixed it by modifying their algorithms for my purposes. What I did, in particular, was instead of maintaining the several representations of the graph that combinatorica passes around, I just used adjacency list. I never did prove what's going on, but my guess is that there is some results caching in Mathematica (that is suggested by the graph of MemoryInUse[] as I did repeated closures: it had a distinct sawtooth superimposed on it). Perhaps Mathematica doesn't clear the cache aggressively enough, maybe having a long chain of references causes it to loose track of the actual size of something, or it doesn't examine the whole chain each time is does a cache sweep, or ... Dearest group Has anyone noticed this before? I would like to use KSubsets and > RandomKSubsets a few million times in a proggy, but after executing it a few > thousand times Mathematica crashes, running out of memory. Watching my Taskman (Win > 2K, Mathematica 4.1) we see a constant increase in memory used, until its all soaked > up. I have this problem with both the Combinatorica.m that shipped with > Mathematica, and the new one that has been written, which I believe is now the one > in Mathematica 4.2. I am not really sure what it means to 'leak memory', but this > seems to fit the bill. Here is a crashing-demo. Executing memorySwallower[3,100], for example, > repeatedly just soaks up more and more memory. Pourquoi? I believe the > same thing happens if I use KSubsets also. In[1]:= > MemoryInUse[] > Get[DiscreteMath`Combinatorica`] > MemoryInUse[] > Out[1]= > 1398624 > Out[3]= > 1956536 memorySwallower[S_,n_]:= > Module[{data,subsamples},Print[ToString[MemoryInUse[]]]; > Table[data=Table[{i,j},{i,1000},{j,1+m}]; > subsamples=Table[RandomKSubset[data,S],{100}],{m,n}]; > Print[ToString[MemoryInUse[]]]] memorySwallower[3,100] 15497936 > 29833672 B > _____________________________ ==== > Interesting optimization problem: > Given a list of n-dimensional points, find a point that minimizes the > average distance to all the given points. For example, here are 4 points in 3-space: points = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; Here's the formula for euclidean distance: d[p1_, p2_] := Sqrt[Tr[(p1 - p2)^2]] Now we want to find the point where all the partial derivatives are 0: eq[i_] := D[Tr[d[Array[z, 3], #] & /@ points], z[i]] eqs = (eq[#] == 0 & /@ Range[3]) Solve[eqs, {z[1], z[2], z[3]}] But Mathematica chokes on that... Any ideas for a better algorithm to find the total-distance minimizing > point (this should work for any dimensions; 16 in my case)? Daniel -- > Daniel Reeves -- http://ai.eecs.umich.edu/people/dreeves/ Humans are genes' way of making more genes. -- Richard Dawkins search terms: Euclidean 1-median problem Fermat-Weber problem Rob Pratt Department of Operations Research http://www.unc.edu/~rpratt/ ==== > Given a list of n-dimensional points, find a point that minimizes the > average distance to all the given points. ... Solve[eqs, {z[1], z[2], z[3]}] But Mathematica chokes on that... Any ideas for a better algorithm to find the total-distance minimizing > point (this should work for any dimensions; 16 in my case)? Well, I happen to know the answer in three dimensions: In[15]:= centroid = Plus@@points/Length[points] Out[15]= 11 13 15 {--, --, --} 2 2 2 In[16]:= eqs /. Thread[Array[z,3]->centroid] Out[16]= {True, True, True} Maybe you can extend this to n dimensions. I cannot do so, at least not trivially. However, FindRoot worked nicely in the 16-dimensional examples I tried. Tom Burton ==== I copied your code as follows: In[1]:= << Graphics`MultipleListPlot`; In[2]:= (list1 = Table[{x, Sin[2*Pi*x]}, {x, 0, 1, 0.1}]; list2 = Table[{x, Cos[2*Pi*x]}, {x, 0, 1, 0.1}]); In[3]:= MultipleListPlot[list1, list2]; It works as it should. Tomas Garza Mexico City ----- Original Message ----- > but when I do an example right out of Help such as << Graphics`MultipleListPlot` > (list1 = Table[{x, Sin[2 Pi x]}, {x, 0, 1, 0.1}]; > list2 = Table[{x, Cos[2 Pi x]}, {x, 0, 1, 0.1}]); MultipleListPlot[list1, list2] , nothing appears (no plot shows) except this text !(MultipleListPlot[{{0, 0}, {0.1`, 0.5877852522924731`}, {0.2`, > 0.9510565162951535`}, {0.30000000000000004`, > 0.9510565162951535`}, {0.4`, 0.5877852522924732`}, {0.5`, > 1.2246063538223773`*^-16}, {0.6000000000000001`, > (-0.5877852522924734`)}, {0.7000000000000001`, > (-0.9510565162951535`)}, > {0.8`, (-0.9510565162951536`)}, {0.9`, (-0.5877852522924734`)}, > {1.`, > (-2.4492127076447545`*^-16)}}, {{0, 1}, {0.1`, 0.8090169943749475`}, > {0.2`, > 0.30901699437494745`}, {0.30000000000000004`, > (-0.30901699437494756` > )}, {0.4`, (-0.8090169943749473`)}, {0.5`, (-1.`)}, > {0.6000000000000001`, (-0.8090169943749472`)}, {0.7000000000000001`, > > (-0.30901699437494756`)}, {0.8`, 0.30901699437494723`}, {0.9`, > 0.8090169943749473`}, {1.`, 1.`}}]) In-reply-To: <200212100910.EAA14854@smc.vnet.net> ==== SG> I can't get this function to do anything. I read it in with SG> Needs[Graphics`MultipleListPlot`]; SG> and no error messages appear, and the file IS present in SG> this directory: SG> C:Program FilesWolfram ResearchMathematica4.1 SG> (2)AddOnsStandardPackagesGraphics'MultipleListPlot.m SG> but when I do an example right out of Help such as SG> << Graphics`MultipleListPlot` SG> (list1 = Table[{x, Sin[2 Pi x]}, {x, 0, 1, 0.1}]; SG> list2 = Table[{x, Cos[2 Pi x]}, {x, 0, 1, 0.1}]); SG> MultipleListPlot[list1, list2] SG> , nothing appears (no plot shows) except this text SG> !(MultipleListPlot[{{0, 0}, {0.1`, 0.5877852522924731`}, {0.2`, SG> 0.9510565162951535`}, {0.30000000000000004`, [SKIPPED] I cannot reproduce this behavior in the following versions 4.2 for Microsoft Windows (June 5, 2002) 4.2 for Microsoft Windows (February 28, 2002) 4.1 for Microsoft Windows (November 2, 2000) 4.0 for Microsoft Windows (April 21, 1999) Microsoft Windows 3.0 (April 25, 1997) I can reproduce the behavior you had quoted in such a way. 1. Do NOT load MultipleListPlot via Needs[Graphics`MultipleListPlot`]; 2. Input (list1 = Table[{x, Sin[2 Pi x]}, {x, 0, 1, 0.1}]; list2 = Table[{x, Cos[2 Pi x]}, {x, 0, 1, 0.1}]); 3. Input MultipleListPlot[list1, list2] SG> !(MultipleListPlot[{{0, 0}, {0.1`, 0.5877852522924731`}, {0.2`, SG> 0.9510565162951535`}, {0.30000000000000004`, etc !(MultipleListPlot[{{0, 0}, {0.1`, 0.5877852522924731`}, {0.2`, 0.9510565162951535`}, {0.30000000000000004`, 0.9510565162951535`}, {0.4`, 0.5877852522924732`}, {0.5`, 1.2246063538223773`*^-16}, {0.6000000000000001`, (-0.5877852522924734`)}, {0.7000000000000001`, (-0.9510565162951535`)}, {0.8`, (-0.9510565162951536`)}, {0.9`, (-0.5877852522924734`)}, {1.`, (-2.4492127076447545`*^-16)}}, {{0, 1}, {0.1`, 0.8090169943749475`}, {0.2`, 0.30901699437494745`}, {0.30000000000000004`, (-0.30901699437494756` )}, {0.4`, (-0.8090169943749473`)}, {0.5`, (-1.`)}, {0.6000000000000001`, (-0.8090169943749472`)}, {0.7000000000000001`, (-0.30901699437494756`)}, {0.8`, 0.30901699437494723`}, {0.9`, 0.8090169943749473`}, {1.`, 1.`}}]) Over years, I gradually came to the final conclusion that it is best to load the proper package prior to using a function call from it ;-) Best wishes, Vladimir Bondarenko Mathematical and Production Director Symbolic Testing Group http://www.CAS-testing.org/ GEMM Project (98% ready) Mail : 76 Zalesskaya Str, Simferopol, Crimea, Ukraine P.S. A remark for our Moderator only. See at last how good I am ;) ==== regarding the package Statistics'NonlinearFit' is it possible to fit an array of data with a function defined by NIntegrate? Example: f[r_,a_] := NIntegrate[x/(x^2+a^2) Exp[-x^2] BesselJ[0,x r],{x,0,Infinity}] BestFitParameters /. NonlinearRegress[data,f[r,a],r,{a},RegressionReport -> BestFitParameters] I mean, I know it's not possible because I tried and it doesn't work, but I was wondering if there is some way to do that. Any suggestion is more than welcome. Hyper ==== Math friends, If I program Mathematica to calculate a Cayley Table for A_5, for example, and it displays on the screen in the notebook, I have not been able to figure out how to paste the values into Excel without all the extra formatting, such as quote marks. Has someone worked this out? For example, the Cayley Table for A_5 copies as follows into Excel... !(* TagBox[GridBox[{ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, {2, 3, 1, 7, 9, 8, 10, 12, 11, 4, 5, 6, 14, 15, 13, 19, 21, 20, 22, 24, 23, 16, 17, 18, 37, 39, 38, 40, 42, 41, 46, 47, 48, 43, 44, 45, 49, 51, 50, 52, 54, 53, 58, 59, 60, 55, 56, 57, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}, {3, 1, 2, 10, 11, 12, 4, 6, 5, 7, 9, 8, 15, 13, 14, 22, 23, 24, 16, 18, 17, 19, 21, 20, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 25, 27, 26, 28, 30, 29, 34, 35, 36, 31, 32, 33, 37, 39, 38, 40, 42, 41, 46, 47, 48, 43, 44, 45}, {4, 6, 5, 1, 3, 2, 11, 10, 12, 8, 7, 9, 25, 27, 26, 28, 30, 29, 34, 35, 36, 31, 32, 33, 13, 15, 14, 16, 18, 17, 22, 23, 24, 19, 20, 21, 50, 49, 51, 55, 56, 57, 52, 53, 54, 58, 60, 59, 38, 37, 39, 43, 44, 45, 40, 41, 42, 46, 48, 47}, {5, 4, 6, 8, 7, 9, 1, 2, 3, 11, 12, 10, 26, 25, 27, 31, 32, 33, 28, 29, 30, 34, 36, 35, 38, 37, 39, 43, 44, 45, 40, 41, 42, 46, 48, 47, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 50, 51, 49, 55, 57, 56, 58, 60, 59, 52, 53, 54}, and so on... ==== set the PlotPoints option to a value that resolve the oscillations and Plot[x Sin[x], {x, -100, 100}, PlotPoints -> 66] will work fine. disvovered that the portion of the plot between,9.5Pi and 11Pi is displayed > as a line segment joining the points {9.5 , 9.5 Sin[9.5]} and {11 , 11 > Sin[11]}. I've also found that the plot from x=-100 to x=99.99 is incorrect. > The plot over the range [-100,99] is correct. What is happening here? Does > this happen on other systems? > -- > STH > Hatton's Law: > There is only One inviolable Law. ==== > disvovered that the portion of the plot between,9.5Pi and 11Pi is displayed > as a line segment joining the points {9.5 , 9.5 Sin[9.5]} and {11 , 11 > Sin[11]}. I've also found that the plot from x=-100 to x=99.99 is incorrect. > The plot over the range [-100,99] is correct. What is happening here? Does > this happen on other systems? > -- Although Mathematica attempts to refine the plot recursively as needed to produce an accurate plot, you can fool the algorithm. One way is to provide a function with more oscillations than the initial number of PlotPoints. On my system (4.2 on Mac), the default initial number of PlotPoints is 25. Your function oscillates about 32 times over the domain. Increase the number of PlotPoints to 50. The problem goes away. As you have seen, fewer PlotPoints may work, depending upon the initial distribution of points. Plot your examples with PlotDivision->1 to see that small adjustments in the domain change the number of oscillations captured by the initial set of points. Tom Burton ==== A similar problem occurs with Mathematica 4.2 for Windows, but the range over which it occurs is somewhere in the range x=30 to x=40 (I haven't checked precisely). You can fix the problem by using a larger number of PlotPoints, which ensures that the oscillating function you want to plot doesn't fool the plotting algorithm. In this case the following works: Plot[x Sin[x], {x, -100, 100}, PlotPoints -> 100]; Steve Luttrell and > disvovered that the portion of the plot between,9.5Pi and 11Pi is displayed > as a line segment joining the points {9.5 , 9.5 Sin[9.5]} and {11 , 11 > Sin[11]}. I've also found that the plot from x=-100 to x=99.99 is incorrect. > The plot over the range [-100,99] is correct. What is happening here? Does > this happen on other systems? > -- > STH > Hatton's Law: > There is only One inviolable Law. ==== > disvovered that the portion of the plot between,9.5Pi and 11Pi is displayed > as a line segment joining the points {9.5 , 9.5 Sin[9.5]} and {11 , 11 > Sin[11]}. I've also found that the plot from x=-100 to x=99.99 is incorrect. > The plot over the range [-100,99] is correct. What is happening here? Does > this happen on other systems? I tried this in 4.0 and saw the same thing. If you add the directive PlotPoints->100, it fixes it. ==== How can I get Mathematica 4.2 to do simple multipliction thru PlusMinus operators? For example, suppose I have a 3-dimensional vector with component tolerances specified: In[4]:= va = {{4.10 ± 0.057}, {-3.16 ± 0.796}, {5.09 ± .250}} Out[4]:= {{4.1[PlusMinus]0.057},{-3.16[PlusMinus]0.796},{5.09[PlusMinus]0.25}} In[5]:= FullForm[va] Out[5]://FullForm= List[List[PlusMinus[4.1`,0.057`]],List[PlusMinus[-3.16`,0.796`]], List[PlusMinus[5.09`,0.25`]]] In[6]:= 5.2*va Out[6]:= {{5.2 (4.1[PlusMinus]0.057)},{5.2 (-3.16[PlusMinus]0.796)},{5.2 (5.09 [PlusMinus]0.25)}} However, what I want is (for the first component of the vector, va) is 5.2*4.1 ± (5.2*0.057) or, equivalently 21.32 ± 0.2964 Is there a standard package to do this? I wasn't able to find anything of help in Section 1.10 or 3.10 of the Wolfram Reference. How does one assign meaning to the PlusMinus operator to do simple arithmetic calculations as shown above? Many thanks to all who may respond! ....Terry H ==== Can Mathematica do the following? (I provided answers that I did by hand). 1. Find the GCD of f[x_] := x^5 + 4x^4 + 6x^3 + 6x^2 + 5x +2, g[x_] := x^4 + 3x^2 + 3x +6 Answer: gcd (f(x), g(x)) = x^3 + 4x^2 + 5x + 2 over the field Z7? (I think the answer is easy and is yes). 2. Write the GCD above as a linear combination of the given polynomials? Answer: 5*(x^5 + 4x^4 + 6x^3 + 6x^2 + 5x +2) + (2x + 1)*(x^4 + 3x^2 + 3x +6) This one I am not sure about (I guess we can do it piece-meal, but is there a slick function to do it?). ==== I don't quite get it about precision. If I do $MaxPrecision=$MinPrecision=50, does that mean that all computations following that in the whole notebook will be done to 50 decimal places? (Assuming that the precision is not changed explicitly after that.) If that doesn't do it, how can I make that happen? Do I have to put lots of zeroes in every constant I enter? (The exact value of these doesn't matter but once they are entered, the computation itself must be very exact. This computation is to verify an extremely complicated identity.) It's probable that my computations are being limited by insufficient precision and the easiest thing to do is just up it drastically everywhere in the notebook. ==== One of the things I'm having some trouble with in my math class is determining the partial fraction for a simple constant fraction like this: -5Pi ----- 12 One possibility is: -Pi Pi --- - --- 6 4 I'm having difficulty intuiting how to do this, and I wind up doing tons of trial and error, which sometimes takes too long. Besides some advice on the right way to do this, I'd also like to know how to achieve this in Mathematica. If it weren't for the Mathematica part, I'd have put this in alt.math.moderated. -- Steven Hodgen steven@twitch.net ==== I'm new to Mathematica, and I have a question to which I've found no answers in the archives. Can you help? The issue is: how do I create a pure recursive function? Normally when creating a recursive function I use the name of the function to perform the recursive call: fact[n_] := If[n == 1, 1, n fact[n - 1]] However this has the disadvantage that the symbol fact is now global. The logical step to make the name of the function local is something like: Function[factl, factl[5]] @@ {Function[n, If[n == 0, 1, n factl[n - 1]]]} or maybe: With[{fact = Function[n, If[n == 0, 1, n fact[n - 1]]]}, fact[5]] However both of these solutions steadfastly return the value 5 fact[4]. I assume the problem is that the variables initialised in Function[] and With[] must be symbols, and cannot be patterns. But a recursion requires a pattern (n_ in the first, global, solution above). What do I do to get factorial to work _without_ making the symbol fact global? I'd be grateful for any help. Niall. ==== I think the best way is to use cost representatives rather than cosets to construct your table. First define Z4Z12 in your way: In[2]:= Z4Z12 = Flatten[Outer[List, Range[0, 3], Range[0, 11]], 1] Out[2]= {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {1, 10}, {1, 11}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, {2, 9}, {2, 10}, {2, 11}, {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, {3, 9}, {3, 10}, {3, 11}} In[3]:= multZ4Z12[{a_, b_}, {c_, d_}] := {Mod[a + c, 4], Mod[b + d, 12]} Next we cpnstruct the subroup generated by {2,2} (your Coset1): In[4]:= H = NestWhileList[multZ4Z12[#1, {2, 2}] & , {2, 2}, #1 != {0, 0} & ] Out[4]= {{2, 2}, {0, 4}, {2, 6}, {0, 8}, {2, 10}, {0, 0}} Now we can use Union with a suitable SameTest function to obtian a set of coste representatives: In[7]:= cosetReps = Union[Z4Z12, SameTest -> (MemberQ[H, multZ4Z12[#1, -#2]] & )] Out[7]= {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 1}, {1, 2}, {1, 3}} We only need to generate a multiplication table for the coset representatives, so we defiea new multiplication: In[8]:= multF[{a_, b_}, {c_, d_}] := Select[cosetReps, MemberQ[H, multZ4Z12[{a, b}, {c, d}] - #1] & ] You cna check that it wrks the right way. Now it is easy to generate the multiplication table. Not e that I have paid no attention to efficiency here. This method works nicely for examples of your size. For much larger ones it would be necessary to carefully consider the question of efficiency and the code would almost certainly become less compact. > Math friends, I am trying to create a multiplication table for the factor groups, (Z_4 (+) Z_12)/<(2,2) > I understand how to list the elements of (Z_4 (+) Z_12). This is done > with: Z4Z12 = Flatten[Outer[List, Range[0, 3], Range[0, 11]], 1] I would like to be able to figure out how to list the eight factor > groups > with a calculation with (2,2). This would be in modulo 4,12 arithmetic. As a workaround, I defined (Z_4 (+) Z_12)/<(2,2)> as the eight cosets > defined below: multZ4Z12[{a_, b_}, {c_, d_}] := {Mod[a + c, 4], Mod[b + d, 12]} Multiplication[Z4Z12, multZ4Z12] // TableForm; Coset1 = {Z4Z12[[1]], Z4Z12[[27]], Z4Z12[[5]], Z4Z12[[31]], Z4Z12[[9]], > Z4Z12[[35]]} Coset2 = {Z4Z12[[2]], Z4Z12[[28]], Z4Z12[[6]], Z4Z12[[32]], > Z4Z12[[10]], > Z4Z12[[36]]} Coset3 = {Z4Z12[[3]], Z4Z12[[29]], Z4Z12[[7]], Z4Z12[[33]], > Z4Z12[[11]], > Z4Z12[[25]]} Coset4 = {Z4Z12[[4]], Z4Z12[[30]], Z4Z12[[8]], Z4Z12[[34]], > Z4Z12[[12]], > Z4Z12[[26]]} Coset5 = {Z4Z12[[37]], Z4Z12[[15]], Z4Z12[[41]], Z4Z12[[19]], > Z4Z12[[45]], > Z4Z12[[23]]} Coset6 = {Z4Z12[[38]], Z4Z12[[16]], Z4Z12[[42]], Z4Z12[[20]], > Z4Z12[[46]], > Z4Z12[[24]]} Coset7 = {Z4Z12[[39]], Z4Z12[[17]], Z4Z12[[43]], Z4Z12[[21]], > Z4Z12[[47]], > Z4Z12[[13]]} Coset8 = {Z4Z12[[40]], Z4Z12[[18]], Z4Z12[[44]], Z4Z12[[22]], > Z4Z12[[48]], > Z4Z12[[14]]} I was not able to figure a way to create a multiplication table with > these > eight elements, because of the multiple part modulo addition. There must be a way to multiply <(2,2)> by different elements of the > external direct product, and a way to compute the multiplication table > of > the factor groups. Can someone help? > Diana ===================================================== > God made the integers, all else is the work of man. > L. Kronecker, Jahresber. DMV 2, S. 19. > ==== Andrzej, I am not sure that I am getting the desired final multiplication table output. The output I get for the multiplication table: MultiplicationTable[cosetReps, multZ4Z12] // TableForm has zeros in it. (Perhaps I have not used the right equation to calculate the multiplication table.) I am not sure that the code is understanding that the result might not be an exact match of the original coset, but might have bits and pieces of the original coset. For example, manually multiplying (element for element) the coset represented by (3,0) and (3,2) gives: {(2,2), (2,6), (2,10), (2,2), (2,6), (2,10)}, when the actual coset represented by the identity is: {{0, 0}, {2, 2}, {0, 4}, {2, 6}, {0, 8}, {2, 10}} I have listed the representative element, such as {0, 0}, first. I greatly appreciate you help with this. The concept of being able to do this with Mathematica is very exciting. Diana M. ==== Andrzej, I used the wrong equation for multiplication. MultiplicationTable[cosetReps, multF] // TableForm also gives a table entirely of zeros. Diana > Math friends, I am trying to create a multiplication table for the factor groups, (Z_4 (+) Z_12)/<(2,2) > I understand how to list the elements of (Z_4 (+) Z_12). This is done with: Z4Z12 = Flatten[Outer[List, Range[0, 3], Range[0, 11]], 1] I would like to be able to figure out how to list the eight factor groups > with a calculation with (2,2). This would be in modulo 4,12 arithmetic. As a workaround, I defined (Z_4 (+) Z_12)/<(2,2)> as the eight cosets > defined below: multZ4Z12[{a_, b_}, {c_, d_}] := {Mod[a + c, 4], Mod[b + d, 12]} Multiplication[Z4Z12, multZ4Z12] // TableForm; Coset1 = {Z4Z12[[1]], Z4Z12[[27]], Z4Z12[[5]], Z4Z12[[31]], Z4Z12[[9]], > Z4Z12[[35]]} Coset2 = {Z4Z12[[2]], Z4Z12[[28]], Z4Z12[[6]], Z4Z12[[32]], Z4Z12[[10]], > Z4Z12[[36]]} Coset3 = {Z4Z12[[3]], Z4Z12[[29]], Z4Z12[[7]], Z4Z12[[33]], Z4Z12[[11]], > Z4Z12[[25]]} Coset4 = {Z4Z12[[4]], Z4Z12[[30]], Z4Z12[[8]], Z4Z12[[34]], Z4Z12[[12]], > Z4Z12[[26]]} Coset5 = {Z4Z12[[37]], Z4Z12[[15]], Z4Z12[[41]], Z4Z12[[19]], Z4Z12[[45]], > Z4Z12[[23]]} Coset6 = {Z4Z12[[38]], Z4Z12[[16]], Z4Z12[[42]], Z4Z12[[20]], Z4Z12[[46]], > Z4Z12[[24]]} Coset7 = {Z4Z12[[39]], Z4Z12[[17]], Z4Z12[[43]], Z4Z12[[21]], Z4Z12[[47]], > Z4Z12[[13]]} Coset8 = {Z4Z12[[40]], Z4Z12[[18]], Z4Z12[[44]], Z4Z12[[22]], Z4Z12[[48]], > Z4Z12[[14]]} I was not able to figure a way to create a multiplication table with these > eight elements, because of the multiple part modulo addition. There must be a way to multiply <(2,2)> by different elements of the > external direct product, and a way to compute the multiplication table of > the factor groups. Can someone help? > Diana ===================================================== > God made the integers, all else is the work of man. > L. Kronecker, Jahresber. DMV 2, S. 19. > ==== Here is the correct code, I hope. First load the Combinatorica package: In[1]:= << DiscreteMath`Combinatorica` Next define the group elements In[2]:= Z4Z12 = Flatten[Outer[List, Range[0, 3], Range[0, 11]], 1] Out[2]= {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {1, 10}, {1, 11}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, {2, 9}, {2, 10}, {2, 11}, {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, {3, 9}, {3, 10}, {3, 11}} Next,t he group multiplication: In[3]:= multZ4Z12[{a_, b_}, {c_, d_}] := {Mod[a + c, 4], Mod[b + d, 12]} THe generated subgroup: In[4]:= H = NestWhileList[multZ4Z12[#1, {2, 2}] & , {2, 2}, #1 != {0, 0} & ] Out[4]= {{2, 2}, {0, 4}, {2, 6}, {0, 8}, {2, 10}, {0, 0}} The coset representatives: In[5]:= cosetReps = Union[Z4Z12, SameTest -> (MemberQ[H, multZ4Z12[#1, -#2]] & )] Out[5]= {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 1}, {1, 2}, {1, 3}} Now (this is different from the previous version), the multiplication of the coset representatives: In[6]:= multF[{a_, b_}, {c_, d_}] := First[Select[cosetReps, MemberQ[H, multZ4Z12[multZ4Z12[{a, b}, {c, d}], -#1]] & ]] And here is the multiplication table: In[7]:= TableForm[MultiplicationTable[cosetReps, multF]] Out[7]//TableForm= TableForm[{{1, 2, 3, 4, 5, 6, 7, 8}, {2, 3, 4, 1, 6, 7, 8, 5}, {3, 4, 1, 2, 7, 8, 5, 6}, {4, 1, 2, 3, 8, 5, 6, 7}, {5, 6, 7, 8, 3, 4, 1, 2}, {6, 7, 8, 5, 4, 1, 2, 3}, {7, 8, 5, 6, 1, 2, 3, 4}, {8, 5, 6, 7, 2, 3, 4, 1}}] I hope this is now O.K. Andrzej > Andrzej, > I am not sure that I am getting the desired final multiplication table > output. The output I get for the multiplication table: MultiplicationTable[cosetReps, multZ4Z12] // TableForm has zeros in it. (Perhaps I have not used the right equation to > calculate > the multiplication table.) I am not sure that the code is > understanding that > the result might not be an exact match of the original coset, but > might have > bits and pieces of the original coset. For example, manually multiplying (element for element) the coset > represented by (3,0) and (3,2) gives: {(2,2), (2,6), (2,10), (2,2), (2,6), (2,10)}, when the actual coset > represented by the identity is: {{0, 0}, {2, 2}, {0, 4}, {2, 6}, {0, 8}, {2, 10}} I have listed the representative element, such as {0, 0}, first. I greatly appreciate you help with this. The concept of being able to > do > this with Mathematica is very exciting. Diana M. -----Original Message----- > To: Diana > Cc: mathgroup@smc.vnet.net; Andrzej Kozlowski > I think the best way is to use cost representatives rather than cosets > to construct your table. First define Z4Z12 in your way: In[2]:= > Z4Z12 = Flatten[Outer[List, Range[0, 3], Range[0, 11]], 1] Out[2]= > {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, > {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, {1, 0}, {1, 1}, > {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, > {1, 9}, {1, 10}, {1, 11}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, > {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, {2, 9}, {2, 10}, > {2, 11}, {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, > {3, 6}, {3, 7}, {3, 8}, {3, 9}, {3, 10}, {3, 11}} In[3]:= > multZ4Z12[{a_, b_}, {c_, d_}] := {Mod[a + c, 4], > Mod[b + d, 12]} > Next we cpnstruct the subroup generated by {2,2} (your Coset1): In[4]:= > H = NestWhileList[multZ4Z12[#1, {2, 2}] & , {2, 2}, > #1 != {0, 0} & ] Out[4]= > {{2, 2}, {0, 4}, {2, 6}, {0, 8}, {2, 10}, {0, 0}} Now we can use Union with a suitable SameTest function to obtian a set > of coste representatives: > In[7]:= > cosetReps = Union[Z4Z12, SameTest - (MemberQ[H, multZ4Z12[#1, -#2]] & )] Out[7]= > {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 1}, {1, 2}, > {1, 3}} We only need to generate a multiplication table for the coset > representatives, so we defiea new multiplication: In[8]:= > multF[{a_, b_}, {c_, d_}] := Select[cosetReps, > MemberQ[H, multZ4Z12[{a, b}, {c, d}] - #1] & ] You cna check that it wrks the right way. Now it is easy to generate > the multiplication table. Not e that I have paid no attention to efficiency here. This method > works nicely for examples of your size. For much larger ones it would > be necessary to carefully consider the question of efficiency and the > code would almost certainly become less compact. Andrzej Kozlowski > Yokohama, Japan > Math friends, >> I am trying to create a multiplication table for the factor groups, >> (Z_4 (+) Z_12)/<(2,2)> I understand how to list the elements of (Z_4 (+) Z_12). This is done >> with: >> Z4Z12 = Flatten[Outer[List, Range[0, 3], Range[0, 11]], 1] >> I would like to be able to figure out how to list the eight factor >> groups >> with a calculation with (2,2). This would be in modulo 4,12 >> arithmetic. >> As a workaround, I defined (Z_4 (+) Z_12)/<(2,2)> as the eight cosets >> defined below: >> multZ4Z12[{a_, b_}, {c_, d_}] := {Mod[a + c, 4], Mod[b + d, 12]} >> Multiplication[Z4Z12, multZ4Z12] // TableForm; >> Coset1 = {Z4Z12[[1]], Z4Z12[[27]], Z4Z12[[5]], Z4Z12[[31]], >> Z4Z12[[9]], >> Z4Z12[[35]]} >> Coset2 = {Z4Z12[[2]], Z4Z12[[28]], Z4Z12[[6]], Z4Z12[[32]], >> Z4Z12[[10]], >> Z4Z12[[36]]} >> Coset3 = {Z4Z12[[3]], Z4Z12[[29]], Z4Z12[[7]], Z4Z12[[33]], >> Z4Z12[[11]], >> Z4Z12[[25]]} >> Coset4 = {Z4Z12[[4]], Z4Z12[[30]], Z4Z12[[8]], Z4Z12[[34]], >> Z4Z12[[12]], >> Z4Z12[[26]]} >> Coset5 = {Z4Z12[[37]], Z4Z12[[15]], Z4Z12[[41]], Z4Z12[[19]], >> Z4Z12[[45]], >> Z4Z12[[23]]} >> Coset6 = {Z4Z12[[38]], Z4Z12[[16]], Z4Z12[[42]], Z4Z12[[20]], >> Z4Z12[[46]], >> Z4Z12[[24]]} >> Coset7 = {Z4Z12[[39]], Z4Z12[[17]], Z4Z12[[43]], Z4Z12[[21]], >> Z4Z12[[47]], >> Z4Z12[[13]]} >> Coset8 = {Z4Z12[[40]], Z4Z12[[18]], Z4Z12[[44]], Z4Z12[[22]], >> Z4Z12[[48]], >> Z4Z12[[14]]} >> I was not able to figure a way to create a multiplication table with >> these >> eight elements, because of the multiple part modulo addition. >> There must be a way to multiply <(2,2)> by different elements of the >> external direct product, and a way to compute the multiplication table >> of >> the factor groups. Can someone help? >> Diana >> ===================================================== >> God made the integers, all else is the work of man. >> L. Kronecker, Jahresber. DMV 2, S. 19. > http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ ==== -----Mensagem original----- Enviada em: ter.8da-feira, 10 de dezembro de 2002 06:11 Para: mathgroup@smc.vnet.net Assunto: Re: Levemberg im sure if you try a search engine like google or yahoo you'll find it. just type in the keywords in what your looking for. RAyRAy Hmmm... Already tried that, before posting this msg. All I got was a dozen links of software that uses this algorithm for something, but no theory at all. Just some books about it. Tks anyway. ==== http://www.library.cornell.edu/nr/bookcpdf/c15-5.pdf page 683 ----------------------- Saved my life! :-) Luiz ==== please find the documentation how to install the fonts and style files. It should be in $TopDirectory/SysmteFiles/IncludeFiles/TeX/texmf/doc/wolfram and is called msymdoc.pdf You have to add the $TopDirectory/SysmteFiles/IncludeFiles/TeX/texmf/ to the texmf trees that teTeX search and eventual edit the buggy font name data base. Mail me direct if you have still problems. I need some help, here. I'm using Mathematica 4.2 on OS X and I'd > like to save a notebook so that I can include it in a LaTeX file. > According to the Wolfram site, Mathematica has a convenient save as > option just for this sort of task. Unfortunately, I can't get it to > work for the life of me. The notebook saves, but it won't compile. I use TeXShop, a very standard LaTeX environment for OS X that's > built (I believe) on top of teTeX. Per the 'request' of my LaTeX > compiler, I've located copies of notebook2e.sty and wrisym.sty, but > this doesn't help; the fatal error is something like '! LaTeX Error: > This NFSS system isn't set up properly.' Does anybody out there have a slick solution to my problem? It seems > to me that Wolfram should have made this process work out-of-the-box > with standard installations of Mathematica 4.2 and standard > installation of LaTeX utilities. Perhaps I'm missing something. I hope somebody out there can give me a hand with this. (FWIW, I > have access to latex and Mathematics 4.2 on linux and NT platforms, > too.) -- > Jason Miller, Ph.D. > Division of Mathematics and Computer Science > Truman State University > 100 East Normal St. > Kirksville, MO 63501 > http://vh216801.truman.edu > 660.785.7430 ==== As I understand it, I can write a Complex java class with a public constructor method of the form: public Complex(double Re, double Im) and mehtods re() and im() of the form: public double re(); public double im(); If I place this class file in a directory on the JavaClassPath and execute SetComplexPath[Complex], I should then be able to pass complex numbers from Mathematica to any java method accepting objects of type Complex. Has anyone had any luck with this? I haven't been able to get it to work in Mac OS 9 or Mac OS X. Mark McClure Dept. of Mathematics University of North Carolina at Asheville http://www.unca.edu/~mcmcclur/ ==== a small example sol = Solve[{0 == x^2 + y, -1 == x + y}, {x, y}]; and Select[sol, (x /. #) > 0 &] will return the solution with positive x. I am trying to solve 3 equations on 3 variables --- which is solveable. > After that I want to use only the positive solutions of the three > variables for further calculations. I tried to use the Select command in > connection with the Solve command, but I get only an empty list. Could you help by recommend commands? Angela Birk -- > Angela Birk > University of Hamburg > HWWA > Economics > 20347 Hamburg, Germany > +49 40 42834 - 478 ==== Angela, The fact that you have 3 eqns and 3 unknowns does not guarantee you that the system is solvable. If there are linearly dependent columns or rows in your matrix, the system is ill-conditioned. So, I suggest you to start from checking if the matrix is non-singular. Good luck. > I am trying to solve 3 equations on 3 variables --- which is solveable. > After that I want to use only the positive solutions of the three > variables for further calculations. I tried to use the Select command in > connection with the Solve command, but I get only an empty list. Could you help by recommend commands? Angela Birk ==== > I am trying to solve 3 equations on 3 variables --- which is solveable. > After that I want to use only the positive solutions of the three > variables for further calculations. I tried to use the Select command in > connection with the Solve command, but I get only an empty list. [...] Try Cases[sol, {(_ -> _?Positive) ..}] where 'sol' is the result of Solve. Rainer ==== If you study the following sequence you«ll understand how to obtain what you want: In[1]:= sol = Solve[{3*x + y + z == -1, 2*x + y + z == -3, x - y + z == -3}, {x, y, z}] Out[1]= {{x -> 2, y -> -1, z -> -6}} In[2]:= pos = Cases[sol[[1]], w_ /; w[[2]] > 0] Out[2]= {x -> 2} In[3]:= pos[[1,2]] Out[3]= 2 Bear in mind that the solution to a set of simultaneous equations comes out as a sequence of rules. Then Cases will help you get the rule or rules where the second part is positive. Tomas Garza Mexico City ----- Original Message ----- Angela Birk -- > Angela Birk > University of Hamburg > HWWA > Economics > 20347 Hamburg, Germany > +49 40 42834 - 478 ==== > Can anyone explain the following results? In[8]:= > r[t_]:=4-3Sin[t] In[9]:= > !(NIntegrate[Sqrt[r[t]^2 + (r')[t]^2], {t, 0, 2 [Pi]}]) Out[9]= > 28.8142 This is correct. > In[10]:= > !(Integrate[Sqrt[r[t]^2 + (r')[t]^2], {t, 0, 2 [Pi]}] // N) Out[10]= > -18.9606 This is wrong. The exact (incorrect) result of this integration in my version 4.1 is, after simplification, 2*(EllipticE[Pi/4, -48] + EllipticE[(3*Pi)/4, -48] - 25*(EllipticF[Pi/4, -48] + EllipticF[(3*Pi)/4, -48])). The last two terms, involving incomplete elliptic integrals of the first kind, are spurious. Omitting them, the answer would then be correct. However, there is a simplification which I'm surprised that Mathematica doesn't know: 2*(EllipticE[Pi/4, -48] + EllipticE[(3*Pi)/4, -48]) should simplify to an expression with just a _single complete_ elliptic integral of the second kind, namely (#) 4*EllipticE[-48], a much nicer form of the exact (correct) answer. But there's more of interest here! Note that the radicand of the integrand simplifies to just 25 - 24*Sin[t]. So what do we get if we ask Mathematica to Integrate[Sqrt[25 - 24*Sin[t]], {t, 0, 2*Pi}]? We find yet another error! We get 2*EllipticE[Pi/4, -48] + 2*EllipticE[(3*Pi)/4, -48] + 4*EllipticF[I*ArcSinh[1/(4*Sqrt[3])], -48] the last term of which is spurious (but, being imaginary, is different from the spurious terms mentioned previously). Next, let's see what we get if we ask for an indefinite integral: Integrate[Sqrt[25 - 24*Sin[t]], t] yields -2*EllipticE[(Pi/2 - t)/2, -48]. Hooray! If we now use the Fundamental Theorem _ourselves_, we do get a correct exact answer (finally!), albeit not in the simplified form of (#). So I must now wonder why Mathematica got a spurious imaginary term when it did the corresponding definite integral. Finally, let's see what happens if we first transform the integral ourselves using the standard substitution u = Sin[t]: We get 2*Integrate[Sqrt[(25-24u)/(1-u^2)], {u, -1, 1}]. For this, Mathematica then gives (28*I)*(EllipticE[1/49] - EllipticE[ArcSin[7], 1/49] + EllipticF[ArcSin[7], 1/49] - EllipticK[1/49]) which, although messy (and looking as though it might be complex, when it is in fact purely real), does happen to be correct! Hooray again! In summary, correct exact results can -- at least, sometimes -- be obtained by assisting Mathematica ourselves, although these are not as simple as (#). But we should not have to lead Mathematica by the hand, so to speak. I will be very happy when such matters concerning elliptic integrals are corrected. ==== > Respected Sir/Madam, > I want to super impose(add) two curves of > different ranges-one is -5ms to 15 ms and other one > is 0ms to 20ms of different amplitude. > So kindly suggest me -- > With best wishes.............. > SISIR KUMAR NAYAK > ELECTRICAL SCIENCE > U-79,STUDENT HOSTEL > IISC, BANGALORE. > PH:3942624(080) One way: gr1 = Plot[Sin[x], {x, 0, 7}, PlotStyle -> {Hue[0], Thickness[0.01]}]; gr2 = Plot[Sin[2*x], {x, 2, 5}, PlotStyle -> {Hue[0.7], Dashing[{0.01, 0.02}]}]; Show[gr1, gr2, PlotRange -> All]; PlotRange ->All is to protect against Mathematica restricting the display to what it calculated is interesting - not actually needed here. You could also set the plot numerically: here PlotRange-> {{0,7},{-1,1}} would be suitable. We may not want to show the separate curves, only the combination: here are three ways to do this 1) gr1 = Plot[Sin[x], {x, 0, 7}, PlotStyle -> {Hue[0], Thickness[0.01]}, DisplayFunction -> Identity]; gr2 = Plot[Sin[2*x], {x, 2, 5}, PlotStyle -> {Hue[0.7], Dashing[{0.01, 0.02}]}, DisplayFunction -> Identity]; Show[gr1, gr2, PlotRange -> All, DisplayFunction -> $DisplayFunction]; 2) Show[Plot[Sin[x], {x, 0, 7}, PlotStyle -> {Hue[0], Thickness[0.01]}, DisplayFunction -> Identity], Plot[Sin[2*x], {x, 2, 5}, PlotStyle -> {Hue[0.7], Dashing[{0.01, 0.02}]}, DisplayFunction -> Identity], DisplayFunction -> $DisplayFunction, PlotRange -> All] 3) Show[Block[{$DisplayFunction = Identity}, {Plot[Sin[x], {x, 0, 7}, PlotStyle -> {Hue[0], Thickness[0.01]}], Plot[Sin[2*x], {x, 2, 5}, PlotStyle -> {Hue[0.7], Dashing[{0.01, 0.02}]}]}], PlotRange -> All]; -- ==== For example (if I understand well what you want): In[7]:= p1=Plot[Sin[x/5[Pi]],{x,-5,15},PlotRange->{{-5,20},{-2,2}}, PlotStyle->RGBColor[1,0,0]]; In[9]:= p2=Plot[2Sin[2x/5[Pi]],{x,0,20},PlotStyle->RGBColor[0,0,1]]; In[10]:= Show[p1,p2] Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : mar., 10. d.8ecembre 2002 10:10 Ë : mathgroup@smc.vnet.net Objet : superimpose to curves Respected Sir/Madam, I want to super impose(add) two curves of different ranges-one is -5ms to 15 ms and other one is 0ms to 20ms of different amplitude. So kindly suggest me -- With best wishes.............. SISIR KUMAR NAYAK ELECTRICAL SCIENCE U-79,STUDENT HOSTEL IISC, BANGALORE. PH:3942624(080) ==== Sisir, Make the separate plots and suppress the display. Then combine the two plots with a Show statement. As a little extra I put color on the two curves. The Block statement temporarily sets the system display function to Identity, which suppresses the extra display of the separate curves. Needs[Graphics`Colors`] Block[{$DisplayFunction = Identity}, plot1 = Plot[Sin[x], {x, 0, Pi}, PlotStyle -> Blue]; plot2 = Plot[2Sin[x], {x, Pi/4, 5Pi/4}, PlotStyle -> Red];] Show[{plot1, plot2}]; Using the DrawGraphics package from my web site it can be done in a slightly more natural and direct manner. Needs[DrawGraphics`DrawingMaster`] Draw2D[ {Blue, Draw[Sin[x], {x, 0, Pi}], Red, Draw[2Sin[x], {x, Pi/4, 5Pi/4}]}, Axes -> True]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ U-79,STUDENT HOSTEL IISC, BANGALORE. PH:3942624(080) ==== I don't think there is a simple expression in a conventional sense, but you can give a simple formula in terms of a generating power series: f[k_, m_] := SeriesCoefficient[Series[1/(1 - x)^k, {x, 0, m - k}], m - k] http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ I was wondering if there was a simple expression (as a function of m > and k ) > to compute > the total number of solutions to the integer programming problem: n_1 + n_2 + n_3 + ... + n_k = m where m > k, each ni >= 1. Basically, I am trying to figure out the number of ways of partitioning > a set with m unique elements into k non-empty disjoint subsets. For example, if k = 2, then the number of solutions to n_1 + n_2 = m is (m-1) = M_2(m) (say) if k = 3, then the number of solutions to n_1 + n_2 + n_3 = m is M_3(m) = sum_{i=1}^{m-2} (m-i-1) = > sum_{i=1}^{m-2} M_2(m-i) I can think of a recursive solutions wherein M_2(m) = (m-1) and > M_k(m) = sum_{i=1}^{m-k+1} M_(k-1)(m-i), k > 2 Kumar > ==== i am trying to do a poincare map. i generate x[t] and x'[t]. i write z2 = Table[Evaluate[{x[t] , x'[t]} /. %], {t, 0, 10, .005}] ListPlot[z2] and i get a set of values that looks like {{0.517671, 9.75893}}, {{0.562696, 8.33465}}, {{0.601599, 7.26733}}, {{0.635675, 6.38612}},.... the problem is when i use ListPlot[z2] i get the dreaded is not a list of numbers error. if i remove the extra parenthesis by hand it works, but thats a tedious business several hundred points. i am sure this is a simple thing to fix. i would appreciate any help. mario ==== Is there a way to construct a graphical map of a Mathematica source file? - D. ==== Strange, indeed... I tried the RootSearch package from Ted Ersek... It works fine on your example ! In[11]:= RootSearch[f'[x]==0,{x,3,3.2}] {{x -> 3.141592653589793}} Florian Jaccard -----Message d'origine----- Envoy.8e : mar., 10. d.8ecembre 2002 10:17 Ë : mathgroup@smc.vnet.net Objet : Why can't Mathematica find this root? Regard this function: f[x_] := Sin[x]^3 * Cos[x] And then try this: Solve[f'[x] == 0, x] and you'll get a list of all roots but one. I wonder why. By regarding f'[x] one can directly see that x = pi is a root, yet, Mathematica fails to see it... V.8anligen Konrad ------------------- ==== > Regard this function: f[x_] := Sin[x]^3 * Cos[x] And then try this: Solve[f'[x] == 0, x] and you'll get a list of all roots but one. No, you don't. There are infinitely many roots, of which Mathematica gives you only three: -Pi/2, 0, and Pi/2. > I wonder why. Didn't you notice Mathematica's comment that, since inverse functions were being used, some solutions might not be found? That's the explanation. > By regarding f'[x] one can directly see that x = pi is a root, yet, Mathematica fails to see it... More basically, just try Solve[Sin[x] == 0, x]. The only solution you'll get is 0, the _principal_ value of the inverse sine of 0. David ==== f'[x] is a periodic function, hence it has an infinity of roots. Mathematica tries to sample at least one period of this function; in this case it returns roots contained in the (-Pi,Pi) interval. Since the period of the function is Pi, it can be deduced that x->0 also corresponds to x->Pi (actually x->k*Pi, with k in the Integers). Since Solve produces a relevant message, I think its overall behaviour is consistent in this case. Orestis Vantzos > Regard this function: f[x_] := Sin[x]^3 * Cos[x] And then try this: Solve[f'[x] == 0, x] and you'll get a list of all roots but one. I wonder why. By regarding f'[x] one can directly see that x = pi is a root, yet, Mathematica fails to see it... > ------------------- ==== I believe the reason may be that it expects the result to be interpreted as a repeating result. The root Pi, is simply the root 0, which it does find, in the next period of the function. So, if you view it like this: roots = 0 + k*Pi (k=+-1, +-2, +-3,...) in this case where k = 1, you get your root. I'm not 100% certain, but this may be what it assumes. --Steven > Regard this function: f[x_] := Sin[x]^3 * Cos[x] And then try this: Solve[f'[x] == 0, x] and you'll get a list of all roots but one. I wonder why. By regarding f'[x] one can directly see that x = pi is a root, yet, Mathematica fails to see it... > ------------------- >