D-99 === Subject: Reduce and Indeterminate If a complex number appears in an inequality, Reduce issues a warning: Reduce[I > 0] This is useful (to avoid mistakes). But if Indeterminate appears in an inequality, Reduce will immediately say False: Reduce[Indeterminate > 0] While it is debatable what is the correct thing to do mathematically, I naively believe that it would be useful if Reduce at least gave a warning. It is true that it is not a good idea to manipulate expressions completely blindly (without paying attention to what they contain), but some functions may return very large expressions ... and the main advantage of using computers is that they can do large and tedious calculations quickly. What do MathGroup readers think about this? Here's a somewhat artificial example: In[1]:= Integrate[1/x, {x, a, b}] Out[1]= If[(-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0), -Log[a] + Log[b], Integrate[1/x, {x, a, b}, Assumptions -> ! ((-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0))]] In[2]:= First[%] Out[2]= (-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0) In[3]:= Reduce[% && (a | b) [Element] Reals] Out[3]= False Note that unlike Reduce, FullSimplify gives a warning: In[4]:= FullSimplify[%%, (a | b) [Element] Reals] During evaluation of In[4]:= FullSimplify::infd: Expression (-Im[b] Re[a]+Im[a] Re[b])/(Im[a]-Im[b]) simplified to Indeterminate. >> Out[4]= Indeterminate >= 0 && (Im[a/(-a + b)] != 0 || Re[a/(a - b)] >= 1 || (a/(a - b) != 0 && Re[a/(-a + b)] >= 0)) In[5]:= Reduce[Rest[%] && (a | b) [Element] Reals, {a, b}] Out[5]= (a < 0 && (b < a || a < b <= 0)) || (a > 0 && (0 <= b < a || b > a)) === Subject: Re: Reduce and Indeterminate Yes, a statement can be true, it can be false, or it might not make any sense. If it does not make sense, then considering it false is just as bad as considering it true. > Hi Szabolcs, > it would certainly be nice and consistent if a message about a invalid > comparison is produced. But we must ask if real harm can be produced from > this result and I think this is possible. Although all arthmetic operations > on Indeterminate give Indeterminate, it is not hard to come up with a simple > example where things go wrong: > f[x_]:=If[Reduce[x>0],pos,neg,ind]; > Therefore, I think a warning is a must. > Daniel > If a complex number appears in an inequality, Reduce issues a warning: > Reduce[I > 0] > This is useful (to avoid mistakes). But if Indeterminate appears in an > inequality, Reduce will immediately say False: > Reduce[Indeterminate > 0] > While it is debatable what is the correct thing to do mathematically, I > naively believe that it would be useful if Reduce at least gave a warning. > It is true that it is not a good idea to manipulate expressions completely > blindly (without paying attention to what they contain), but some functions > may return very large expressions ... and the main advantage of using > computers is that they can do large and tedious calculations quickly. > What do MathGroup readers think about this? > Here's a somewhat artificial example: > In[1]:= Integrate[1/x, {x, a, b}] > Out[1]= If[(-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0), -Log[a] + Log[b], > Integrate[1/x, {x, a, b}, > Assumptions -> ! ((-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0))]] > In[2]:= First[%] > Out[2]= (-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0) > In[3]:= Reduce[% && (a | b) [Element] Reals] > Out[3]= False > Note that unlike Reduce, FullSimplify gives a warning: > In[4]:= FullSimplify[%%, (a | b) [Element] Reals] > During evaluation of In[4]:= FullSimplify::infd: Expression (-Im[b] > Re[a]+Im[a] Re[b])/(Im[a]-Im[b]) simplified to Indeterminate. > Out[4]= Indeterminate >= > 0 && (Im[a/(-a + b)] != 0 || > Re[a/(a - b)] >= 1 || (a/(a - b) != 0 && Re[a/(-a + b)] >= 0)) > In[5]:= Reduce[Rest[%] && (a | b) [Element] Reals, {a, b}] > Out[5]= (a < 0 && (b < a || a < b <= 0)) || (a > 0 && (0 <= b < a || b > a)) > > 1 === Subject: Re: Reduce and Indeterminate Hi Szabolcs, it would certainly be nice and consistent if a message about a invalid comparison is produced. But we must ask if real harm can be produced from this result and I think this is possible. Although all arthmetic operations on Indeterminate give Indeterminate, it is not hard to come up with a simple example where things go wrong: f[x_]:=If[Reduce[x>0],pos,neg,ind]; Therefore, I think a warning is a must. Daniel > If a complex number appears in an inequality, Reduce issues a warning: Reduce[I > 0] This is useful (to avoid mistakes). But if Indeterminate appears in an > inequality, Reduce will immediately say False: Reduce[Indeterminate > 0] While it is debatable what is the correct thing to do mathematically, I > naively believe that it would be useful if Reduce at least gave a > warning. It is true that it is not a good idea to manipulate > expressions completely blindly (without paying attention to what they > contain), but some functions may return very large expressions ... and > the main advantage of using computers is that they can do large and > tedious calculations quickly. What do MathGroup readers think about this? Here's a somewhat artificial example: In[1]:= Integrate[1/x, {x, a, b}] Out[1]= If[(-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0), -Log[a] + Log[b], > Integrate[1/x, {x, a, b}, > Assumptions -> ! ((-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0))]] In[2]:= First[%] Out[2]= (-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0) In[3]:= Reduce[% && (a | b) [Element] Reals] Out[3]= False Note that unlike Reduce, FullSimplify gives a warning: In[4]:= FullSimplify[%%, (a | b) [Element] Reals] During evaluation of In[4]:= FullSimplify::infd: Expression (-Im[b] > Re[a]+Im[a] Re[b])/(Im[a]-Im[b]) simplified to Indeterminate. Out[4]= Indeterminate >= > 0 && (Im[a/(-a + b)] != 0 || > Re[a/(a - b)] >= 1 || (a/(a - b) != 0 && Re[a/(-a + b)] >= 0)) In[5]:= Reduce[Rest[%] && (a | b) [Element] Reals, {a, b}] Out[5]= (a < 0 && (b < a || a < b <= 0)) || (a 0 && (0 <= b < a || b > a)) === Subject: Re: Dynamic (more) Hi Luca, Dynamic does only evaluate its arguments for display. Convince yourself by: Dynamic[Print[asas];1] this gives a message Dynamic[Print[asas];1]; this gives no message therefore, the statement:q = p + 1 in Dynamic[q = p + 1]; is never executed. Further, q=1;Dynamic[q] does return Dynamic[q] and not 1. Try: q=1;Dynamic[q]//FullForm This is then further evaluated for display to give 1. hope this helps, Daniel > Hi! The following gives the (expected?) result 1: p = 0; > q = 0; > Dynamic[q = p + 1]; > Dynamic[q] This one gives {1, 1}, also as I would expect: DynamicModule[{p, q}, > p = 0; > q = 0; > {Dynamic[q = p + 1], > Dynamic[q]}] > Can anybody explain why the next gives 0? DynamicModule[{p, q}, > p = 0; > q = 0; > Dynamic[q = p + 1]; > Dynamic[q] > ] > Try the following pair too: DynamicModule[{p = 0, q}, {Dynamic[q = p + 1], Dynamic[q]}] DynamicModule[{p = 0, q}, Dynamic[q = p + 1]; Dynamic[q]] Luca === Subject: Re: EdgeRenderingFunction to produce edge labels in >DeleteCases[ >Thread[Range[Length[vertices]] -> (VertexLabel /. >vertices[[All,2 ;;]])], >_ -> VertexLabel >]; >I am just curious. Why the DeleteCases? In this simple example DeleteCases does nothing. In what kind of graph would it have a function? >with friendly greetings, >P_ter I wanted my code to handle the case where some or all vertex labels are unspecified. For example, without the DeleteCases you would obtain the following for Cycle[3]: g=Cycle[3] Graph[{{{1, 2}}, {{2, 3}}, {{1, 3}}}, {{{-0.4999999999999998, 0.8660254037844387}}, {{-0.5000000000000004, -0.8660254037844384}}, {{1., 0}}}] vertices = g[[2]]; Thread[Range[Length[vertices]] -> (VertexLabel /. vertices[[All, 2;;]])] {1->VertexLabel,2->VertexLabel,3->VertexLabel} Obviously, I don't want to perform these replacement rules on the list of vertices. Carl Woll Wolfram Research === Subject: Re: List re-arrangement question > I'm trying to do something like the following: > Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, > {b1, b2, b3}}}, {3, 1, 2}] expecting to get: > {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, > b3}}} However, it looks like Transpose doesn't work with ragged > arrays...so what is the recommended Mathematica style to do the above > transformation? Here are some possible ways: rag={{{a1,a2,a3},{a1},{a1,a2,a3}},{{b1,b2,b3},{b1},{b1,b2,b3}}}; Thread /@ Thread@rag MapThread[Thread[{##}] &, rag] MapThread[Transpose[{##}] &, rag] {{{a1,b1},{a2,b2},{a3,b3}},{{a1,b1}},{{a1,b1},{a2,b2},{a3,b3}}} {{{a1,b1},{a2,b2},{a3,b3}},{{a1,b1}},{{a1,b1},{a2,b2},{a3,b3}}} {{{a1,b1},{a2,b2},{a3,b3}},{{a1,b1}},{{a1,b1},{a2,b2},{a3,b3}}} -- Jean-Marc === Subject: Re: List re-arrangement question >I'm trying to do something like the following: >Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, >{b1, b2, b3}}}, {3, 1, 2}] expecting to get: >{{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, >b3}}} However, it looks like Transpose doesn't work with ragged >arrays...so what is the recommended Mathematica style to do the above >transformation? In version 6, you can use Flatten: Flatten[ {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1},{b1, b2, b3}}}, {{2}, {3}, {1}} ] {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, b3}}} Carl Woll Wolfram Research === Subject: Re: Coordinates of vertices Steve, For version 5.2 I could do the following. I assume this will also work for 5.1. <List,2]//Union) ScatterPlot3D[vtc] Maarten King, Peter R ial.ac.uk> cc: === Subject: RE: Coordinates of vertices 16/04/2008 16:00 I forgot to mention that I was using version 5.1 so I don't think I have access to that. My fault. Any other suggestions? > -----Original Message----- > Cc: mathgroup@smc.vnet.net === > Subject: Re: Coordinates of vertices > Peter, The vertices are in the graphics object. > Just use [[ ]] to get them out. tc=Truncate[PolyhedronData[Cube]] > vertices=ph[[1,1]]//N > ListPointPlot3D[vertices ,BoxRatios->Automatic] Hope this helps, maarten > King, Peter R > mathgroup@smc.vnet.net ial.ac.uk> cc: === > Subject: > Coordinates of vertices 16/04/2008 11:02 > I am sure I have done this before but I can't for the life of me > remember how, and I can't find it in the manual. Some help > would be much > appreciated. I'd like to find the coordinates of the vertices of a > truncated cube. Whilst Vertices[cube] correctly gives me the coordinates of a cube > Vertices[Truncate[Polyhedron[Cube]]] doesn't do what I want because > Truncate[Polyhedron[... is a graphics object not a polyhedron > object. So > can I convert the graphics object into a polyhedron and use > vertices, or > work out the vertices some other way (for a cube this is trivial to do > but for more complicated shapes this is much more tedious) > Peter > === Subject: Re: PolarPlot Hi Helen, just saw your reply. A coordinate system as you propose would assign more than one coordinate tuple to any point. Although I can see aplications in graphics (cycloids...), I do not think that this makes life easier for calculations. There are enough problems with unique maps, no need to make artificial ones. Daniel >> Hi Bruce, >> the radius in polar coordinates has to be real and positive. Therefore, Actually, no. In polar coordinates r is a *directed* distance, which may > be positive or negative. > >> r=Sqrt[Cos[phi]] can not be the correct formula, we would get imaginary >> values. To prevent this, we may e.g. write: r=Sqrt[Abs[Cos[phi]] what >> gives the plot you are looking for. >> hope this helps, Daniel > === Subject: Re: Directory of Mathematica Add-Ons > On Apr 13, 3:32 am, David Bailey > Contact the Wolfram Partnerships group... >>>http://partnerships.wolfram.com/ >> I don't think that would cover the many Mathematica packages - free and >> otherwise - published independently of Wolfram. Correct. it includes only those that have negotiated a partnership > agreement with Wolfram. What does that negotiation entail? -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u === Subject: Re: Select from list One possible way: In[46]:= Flatten@ Position[(MemberQ[#, 2] && MemberQ[#, 3] &) /@ ptX, True] Out[46]= {1, 2, 5} > I have a list like this: ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Select from list Hi Steve, simply use Position: Position[ptX,{___,2,___,3,___}|{___,3,___,2,___}] hope this helps, Daniel > I have a list like this: ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray > === Subject: Re: Select from list > I have a list like this: ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray Hi Steve, This approach is using a trick from Carl Woll to get non-zero positions in a list: NonzeroPositions[data_] := SparseArray[data] /. SparseArray[_, _, _, x_] :> Flatten[x[[2, 2]]] With that: findTwo[ptX_,va_,vb_]:= NonzeroPositions[Total[-Unitize[ptX - va] + 1, {2}]*Total[-Unitize[ptX - vb] + 1, {2}]] Here, -Unitize[ptX - va] + 1 replaces each occurance of va with 1, others are 0. Total[...,{2}] then adds up the values (i.e. you get 0 if va is not there) With list = Table[RandomSample[Range[9], 4], {10^6}]; We get In[10]:= Timing[findTwo[list, 2, 3] ;][[1]] Out[10]= 0.641 and some other approaches: In[11]:= Timing[ Flatten[Position[(Map[Cases[#1, 2] &, list] /. {} -> {0})*(Map[ Cases[#1, 3] &, list] /. {} -> {0}), {2*3}]];][[1]] Out[11]= 12.063 === Subject: Re: Select from list >I have a list like this: ptX= >{{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both >a 2 and a 3. In this example I would get {1,2,5}. The best solution I >have, with more generality, is: va = 2; >vb = 3; >za = Map[Cases[#1, va]&, ptX] /. {} -> {0} >zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} >Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} >{{3}, {3}, {0}, {3}, {3}} >{1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray If you are interested in the fastest possible method for doing this, then I would do the following: First, a helper function: NonzeroPosition[data_]:=SparseArray[data] /. HoldPattern[SparseArray[__, {_,{_,x_},_}]]:>x Now, I'll use Clip to convert the input into a 1D list which is 1 if the a sublist has 2 and 0 if it doesn't, and similarly, for 3. twos = Unitize @ Total[ Clip[ ptX, {2,2}, {0,0}], {2}]; threes = Unitize @ Total[ Clip[ ptX, {3,3}, {0,0}], {2}]; both 2 and 3, and 0 otherwise: twothree = BitAnd[twos, threes]; To convert this 1D list into a list of positions, use NonzeroPosition: Flatten@NonzeroPosition[twothree]; Putting the above together, we have: Flatten @ NonzeroPosition @ BitAnd[ Unitize @ Total[ Clip[ ptX, {2,2}, {0,0}], {2}], Unitize @ Total[ Clip[ ptX, {3,3}, {0,0}], {2}] ] As an example, here is a list of length 10^6, and a timing example: data = RandomReal[5, {10^6, 5}]; Flatten @ NonzeroPosition @ BitAnd[ Unitize @ Total[ Clip[ data, {2,2}, {0,0}], {2}], Unitize @ Total[ Clip[ data, {3,3}, {0,0}], {2}] ]; //Timing {0.391,Null} Carl Woll Wolfram Research === Subject: Re: transformation rule (some [cut] : If you are not averse to using a global flag variable, you can do it as : follows. : Unprotect[Integrate]; : globalIntegrateFlag = True; : Integrate[args__] := Block[ : {globalIntegrateFlag=False, res}, : res = Integrate[args]; : If [FreeQ[res,EllipticF], res, HoldForm[Integrate[args]]] : Examples: : In[7]:= InputForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] : Out[7]//InputForm= HoldForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] : In[8]:= Integrate[1/Sqrt[1 - phi^2], phi] : Out[8]= ArcSin[phi] Tom. -- Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill, Egham, Surrey, TW20 0EX, England. Email: T.Crane at rhul dot ac dot uk Fax: +44 (0) 1784 472794 === Subject: Re: A Problem with Simplify > [...] >>Capitalization notwithstanding, it need not do any such thing. Integrate >>should give a generic result that behaves sensibly in the limit as a->1 > >>from whatever path is specified to Limit. This is similar to the > >>situation of >>In[18]:= InputForm[solns = x /. Solve[a*x^2 + x == 1, x]] >>Out[18]//InputForm= {(-1 - Sqrt[1 + 4*a])/(2*a), >> (-1 + Sqrt[1 + 4*a])/(2*a)} >>In[20]:= Limit[solns, a->0] >>Out[20]= {-Infinity, 1} >>Note that a blind substitution of a->0 will not give nice results. > Well. But how I can get the partial answer for the case a=1 with > Limit? > I have tried the foolowing code: > In[1]:= Limit[Integrate[Cos[a*z]/Sin[z],z],a->1] > Out[1]= [Infinity] > In[2]:= Limit[Integrate[Exp[a*z]*Sinh[z],z],a->1] > Out[2]= -[Infinity] > In[3]:= Limit[Integrate[Exp[z]*Sinh[a z],z],a->1] > Out[3]= E^z DirectedInfinity[E^(-I*Im[z])] > In[4]:= Limit[Integrate[Exp[(a-1)*x],x],a->1] > Out[4]= [Infinity] > All results are incorrect! > As I understand, Integrate does not give a generic result that behaves > sensibly in the limit as a->1! Sorry, I should have stated the situation more clearly. Yes, the antiderivatives you see have singularities at the parameter value in question (in all cases, when a is 1). Hence the results you show above. What I should have said is that one can get these obtain definite integrals a la Newton-Leibniz. Here is a standard simple example (modified slightly so as to have a->1 as the bad value). In[22]:= InputForm[i1 = Integrate[x^(-a),x]] Out[22]//InputForm= x^(1 - a)/(1 - a) Certainly it blows up as a->1. In[23]:= Limit[i1, a->1] Out[23]= -Infinity In[24]:= Limit[i1, a->1, Direction->1] Out[24]= Infinity But if we take a pair of values for x, say 2 and 3, to evaluate the definite integral, we in fact get the expected/desired logarithm result in the limit as a->1 (and independent of direction). In[27]:= InputForm[Limit[(i1/.x->3)-(i1/.x->2), a->1]] Out[27]//InputForm= Log[3/2] In[28]:= InputForm[Limit[(i1/.x->3)-(i1/.x->2), a->1, Direction->1]] Out[28]//InputForm= Log[3/2] To see that this really is reproducing the Fundamental Theorem of Calculus result (or at least doing a heckuva job to fool me), I'll show this instead as a definite integral from x0 to x. In[29]:= InputForm[Limit[i1 - (i1/.x->x0), a->1]] Out[29]//InputForm= Log[x] - Log[x0] I believe most of your examples will also behave fine when processed in this way. The Cos[a*z]/Sin[z] integrand might be an exception, but that indicates a limitation of Limit rather than a bug in Integrate. Depending on whether you give symbolic (z,z0) or exact numeric (3,2) input to Limit it either returns a complicated, but seemingly correct result, or else unevaluated. Daniel Lichtblau Wolfram Research === Subject: Re: A kernel, multiple notebooks, and Global? > I just wanted to mention this for the case that the OP asked this > question because he is trying to track down a problem related to this. to say that, unless you do something to deliberately manipulate contexts, a group of several simultaneously open notebooks can generally be used as if they were all parts of one big notebook with one overall global context. I didn't raise this question because of any problems I've encountered, but rather to flush out any problems that might arise in the packages without Packages approach that I'd like to start implementing for my particular Mathematica style of use (and it looks like there needn't be any such problems). This approach says, in essence, that I'm often working on 3 or 4 different physical problems, with the currently active projects changing from time to time (and old projects reviving from time to time). So, I'd like to keep all the materials associated with any given project -- notes, references, other memos, graphics and artwork, materials for publications resulting from the project == and, especially, all the Mathematica notebooks for that project -- in a separate master folder for that project. Moreover, I'd like to have all the Mathematica accessories -- like any packages or modules that do some major computational or display tasks for that project -- be right there, in that same subfolder with the primary notebooks for the project. A typical project -- a study of optical fiber propagation, let's say -- generally has a limited and consistent set or glossary of primary parameters and variables, set by the physics of the problem and the conventional notation in the field, and thus easy to remember. So, those quantities might as well all be global variables, used with the same meaning in all the project notebooks. Suppose then that we might at different times want to do calculations and display results on the modes of these optical fibers, or on their propagation characteristics, or their thermal behavior, or on a perturbation aspect of their behavior, or whatever. Rather than have one large, unwieldy notebook to do all these tasks, we might better have a number of separate much smaller task notebooks that are appropriately named (OpticalFiberModes.nb, etc) and that each do one limited part of the overall project -- and then one modules notebook (OpticalFiberModules.nb) that contains various common basic function and equation definitions for the project, plus individual display modules that create certain graphics or tabular displays of results, plus computational modules that do some complicated iterative numerical calculations -- in other words, any stuff that's lengthy or that might go into a Package in other circumstances. At a given time, one might have only one or two task notebooks open, plus the modules notebook (no real problem on a modern computer screen). If you're polishing up a certain graphic display routine, you edit this routine (probably as a Module[]) in the modules notebook; execute the modules notebook to refresh it (which is very fast, since this notebook does nothing but definitions); then jump to and run the task notebook that calls it, and back again if further editing is needed. What are the virtues of this approach? * Each task notebook can be comparatively short and free of long module definitions -- and thus can be navigated through quickly. * The modules notebook may be longer -- but if too long can be split into setup modules, display modules, computational modules. * **You never have to learn how to create/edit/modify/store away Packages! -- a great virtue, from what the questions I've seen repeatedly posed in this group. * Maybe more important, you don't have to **remember** any of this knowledge on how to work with Packages, nor do you have to remember how you defined a Package, or how to use it, over possibly long interim periods between active periods of a given project. All that knowledge is right there at hand, in the modules notebook, if you go back later to that project. * If you need one part of a project's modules notebook in another project, you just copy it over into that project's modules notebook. I'm not attacking Packages here. It's just that they're necessarily pretty sophisticated constructs (and have to be, if they're going to function in the full Mathematica environment). Hence they have a significant learning curve (and a significant 'evaporation rate' if one moves away from them for any period of time). The above approach seems like it may work for me, and give me one fewer messy construct in Mathematica to worry about. I don't see any serious downsides to this approach, although if any are pointed out by readers -- if any -- of this lengthy screed, I'll certainly have to learn from them. === Subject: Re: A kernel, multiple notebooks, and Global? > to say that, unless you do something to deliberately manipulate > contexts, a group of several simultaneously open notebooks can generally > be used as if they were all parts of one big notebook with one overall > global context. That's true AFAIK... > I didn't raise this question because of any problems I've encountered, > but rather to flush out any problems that might arise in the packages > ... other than that I think if you feel comfortable to work the way you have decribed there is technically no reason to not go for it. The advantage of packages comes in when you want/need encapsulate parts of your code so that different modules don't interfere. This could bite you if you are not careful, but you could cure that by using separate namespaces for them by using BeginPackage and EndPackage statements within your modules notebooks. This you could do without creating *.m files, which is probably what makes you think packages are complicated. Another aspect where package files make sense is when you want to give away code for others to use. If you don't plan to do that I don't see much further advantages for you to dive into packages, although they might be by far not as complicated as you think :-). Also it wouldn't be much work to convert your modules notebooks to genuine packages whenever you think it makes sense... hth, albert === Subject: Re: Any One have an idea? > Does anyone have any idea how to do or come up with the knight's tour problem. > Please give me some idea how to do it! (* Ver 6.01 *) Needs[Combinatorica`] g = KnightsTourGraph[8, 8]; path = Partition[HamiltonianCycle[g], 2, 1]; ShowGraph[Highlight[g, {path}, HighlightedEdgeColors -> Red]] - - HTH :>) Dana DeLouis ----- Original Message ----- === Subject: Any One have an idea? Does anyone have any idea how to do or come up with the knight's tour problem. Please give me some idea how to do it! The program is used a random number to select a starting position for the knight, and select the next position by selecting one of the available positions at random. When the knight reaches a position from which the number of the last possible available positions, the tour is finished. > Anna SJ. > === Subject: Fourier Trasform of a Bessel Function I try to make the following > FourierTransform[BesselJ[n, x], x, w]; > % /. n -> 0 I try > FourierTransform[BesselJ[0, x], x, w] I obtain another result. Why? Vlad === Subject: Re: Extending Integrate[] Hi Szabolcs, it looks like mathematica does not automatically distribute your rule over Plus. This comes a bit as a surprise. But you can teach it. If you additionally give the following rule: Integrate[a_+b_,x_]:=Integrate[a,x]+Integrate[b,x] then your example works. Of course you also need linearity. hope this helps, Daniel > According to the documentation it is possible to extend Integrate[] with > new rules: http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCannotBe Done.html The specific example that is given is: Unprotect[Integrate] Integrate[Sin[Sin[a_. + b_. x_]], x_] := Jones[a, x]/b Now Integrate[Sin[Sin[3x]], x] will return Jones[0, x]/3 But if I try an integrand that is just slightly more complicated, > Mathematica returns it unevaluated: In[21]:= Integrate[a + Sin[Sin[x]], x] > Out[21]= Integrate[a + Sin[Sin[x]], x] My question is: Is it really possible to extend Integrate in an > intelligent way? The above example seems to be just simple pattern > matching. It would work with any function, not just Integrate[]. There > is nothing new or surprising about it. But is it *really* possible to extend Integrate[] with new definitions > in a way that Mathematica will use these rules when calculating more > complicated Integrals? If (as I suspect) it is not possible to do this, then the documentation > is a bit misleading ... > === Subject: Re: Extending Integrate[] > Hi Szabolcs, > it looks like mathematica does not automatically distribute your rule over > Plus. This comes a bit as a surprise. But you can teach it. If you > additionally give the following rule: > Integrate[a_+b_,x_]:=Integrate[a,x]+Integrate[b,x] > then your example works. Of course you also need linearity. Hi Daniel, The problem with this approach is that it will prevent Integrate from working correctly in certain cases. Here's an example: In[1]:= expr = D[x*f[x], x] Out[1]= f[x] + x*f'[x] In[2]:= Integrate[expr, x] Out[2]= x*f[x] In[3]:= Unprotect[Integrate] Out[3]= {Integrate} In[4]:= Integrate[a_ + b_, x_] := Integrate[a, x] + Integrate[b, x] In[5]:= Integrate[expr, x] Out[5]= Integrate[f[x], x] + Integrate[x*f'[x], x] Jens's suggestion, i.e. Integrate[d_. + c_.*Sin[Sin[a_. + b_. x_]], x_] := c*Jones[a, x]/b + Integrate[d, x] /; FreeQ[c, x] appears to be reliable, but everything it does is still fully implemented with plain old pattern matching. So my original suspicion, that the internal algorithms of Integrate[] cannot use these new definitions in any way, seems to be true. Szabolcs === Subject: Re: Mathematica Player Pro! I'm glad to see that people here are excited about Player Pro. We certainly are, too, and we put it together as a direct response to many requests we got directly from the user community. And feedback from users, including your remarks made here about Player Pro, has been and will continue to be followed with interest at the highest levels within Wolfram Research. I know that many of you are aware of this, but I'll remind people that there is a free alternative right now, which is the Publish-for-Player website in combination with the freely available Mathematica Player... http://www.wolfram.com/solutions/interactivedeployment/publish/ It has a few more limitations than Player Pro, but quite a lot can be accomplished with it. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. > David, I haven't tried Player Pro yet but I have long wished for > something like the vision you outline. For me, the greatest advantage of live Mathematica notebooks, as > opposed to traditional formats for scientific and mathematical > exposition, is the ease with which readers can assimilate new material > to greater depth. This is true, not only of research work but also of > pedagogical material. There could also be a (long overdue!) > educational revolution here. I hope that Wolfram Research will make Player Pro free. John Jowett >> I don't know if this falls within the purview of MathGroup because it >> has to do with the Mathematica business model, but it also is vitally >> important to how Mathematica is used and its range and scope. >> Anybody who knows me knows that I am a tremendous enthusiast for >> Mathematica. I believe it is a truly revolutionary new medium and even >> in twenty years the technical community has not come fully to grips with >> it. >> Mathematica Player Pro is as great an advance as Version 6 is, perhaps >> even greater! You can write a notebook in the normal manner and ANYONE >> who has Player Pro can read it and get all the interactivity. And >> anyone who has commercial packages can distribute free Player Pro >> versions so that anyone can also read and interact with any notebooks >> David Reiss for reminding me of the requirement for making packages work >> in Player Pro. Encode them.) >> There is only one problem: 'ANYONE who has Player Pro' is still not very >> many people. WRI is allowing Premier subscribers to give away two free >> copies. But why not go all the way and provide free copies of Player Pro >> to everyone? (And junk Player and all its little restrictions and >> convolutions.) Why not go even further and try to convince Dell and >> Apple, and any other OEM, to sell the computers with Mathematica Player >> Pro preloaded, just as they now come preloaded with Acrobat Reader? >> Huge numbers of people buy the Adobe Acrobat software because they know >> for a certainty that absolutely everybody can read the documents. >> Everything from IRS tax forms, restaurant menus to scientific papers on >> quantum gravity are available as pdf files. >> I have long believed that all scientific papers and technical reports >> should be written as Mathematica notebooks. But, in practice, this is >> very little done. Rather I think that most users use Mathematica as a >> super calculator or programming language and then export some of the >> results, or copy out by hand, to the actual paper or report that is >> either written in Word or as a Postscript file using Latex, and then >> often converting to pdf. The main reason they do this is because they >> know very well that most people can't read Mathematica notebooks. >> A static printed scientific document, or a pdf document, is to a >> Mathematica notebook as an ox cart is to a Lear jet. And that vastly >> understates it. Active Mathematica notebooks, written in the style of a >> research paper or textbook have huge advantages. One, of many, of these >> advantages is that they are largely self-proofing. When active >> definitions are used to carry out derivations and make graphics and >> dynamic displays there is a tremendous amount of cross-checking that >> goes on. When I mentioned this to a scientist friend he perked up - but >> only for a moment. >> I think some time ago I read that Mathematica notebooks would be >> accepted as documents on the physics and mathematical arXives. But I >> have never seem one there and if any exist they are vanishingly few. >> Everything is Postscript or pdf. Mathematica notebooks would be far >> superior except for the available readership. >> Providing Mathematica Player Pro free to everyone would unleash a >> torrent of Mathematica use that would eclipse its present reach. More >> people would write and distribute Mathematica notebooks because they >> would know that everybody could read them. More people would read them >> (and how could they help but be impressed!) and decide they wanted to >> write notebooks also. It would be the second revolution. I believe it is >> by far the superior business model. I just cross my fingers and hope the >> folks at WRI will come to the same conclusion. >> -- >> David Park >> djmp...@comcast.nethttp://home.comcast.net/~djmpark/ === Subject: Re: Possible bug in WAV export The results I get in your Table of 20 do vary; the spectra and the sounds differ - but a quick look thru identified only about 4 obvious variants. === Subject: Re: Documentation Center Tutorial On Apr 16, 5:07 am, Dr. David Kirkby ...as promised I have created a notebook with a set of notes on some > aspects of how to prepare material for the Mathematica Documentation > Center. > You can find this notebook at (its the only one on this page at the > moment): >http://www.scientificarts.com/worklife/notebooks/ > The material described there will allow you to create material for the > mathematica Documentation Center by hand. And it will not have the > full set of bells and whistles; but, it may provide just the starting > point and a subset of the tricks needed to get folks going on this. > When version 3.0 of A WorkLife FrameWork is released it will contain a > variety of tools for doing all of this automatically. > rather quickly... > I hope that this helps... Just a suggestion. Why not remove all the stuff at the top about not > reproducing it (except in full), not for commercial use, plus other > restrictions. Instead, stick it on a wiki of some sort where others can > edit it? Sadly I have no time to do this. I have run it by some folks that I know at WRI and will make changes as they come in. Also it's part of the documentation for my product and so I need to keep track of it for that purpose. But anyone who wants to take the core of the methods described and put it up on a wiki is welcome to do so. And, of course they can contact me directly for permission to use the document in full if it seems like a good idea. The copyright stuff is just to make sure that questions for use go through me first.... BEst, --David My guess is that perhaps someone from Wolfram Research might make some > changes. http://www.mathematica-users.org has not been a wonderful successful it must said, and there might be > better places, but this documentation issue is the sort of item that > could be put in an FAQ http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageNam... === Subject: Re: Package to 'graft' Lists onto Matrices Yes, that works. Indeed, it was exactly the sort of thing I got used to doing years ago with the array-processing language APL (but no longer had to do once Ken Iverson invented the idea of rank of a verb). Still, the method seems excessive and perhaps even sneaky to me -- transposing twice. And it might be rather inefficient as the matrix size grows (although I haven't tested timings). In[19]:= m = Partition[Range[9], 3]; ... if I wanted to add a column I could do In[22]:= Transpose@Join[Transpose@m, {data}] Out[22]= {{1, 2, 3, 2}, {4, 5, 6, 0}, {7, 8, 9, 0}} -- 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: heat equation through different media/problem with constant flux at 2008/4/16 Luigi B : > I am trying to solve the heat conduction problem in a sequence of > three media with different properties. For that I am using NDSolve > However, i still do not get a satisfactory result. Probably because I > am not including the condition that at the interface between two media > the heat flux is constant. How can I do this? I suspect your hypothesis is correct. I've never tried including a a constant flux condition (kleft D[u[x],x]/.x->a == kright D[u[x],x]/.x->a) into NDSolve. I'll be interested to see if someone has a method. But, why not solve the equations in each of the three domains using DSolve, and then enforce continuity of u and continuity of flux with Solve to determine the solution symboilicaly. If the thermal conductivity is uniform in each sublayer, this should be fairly straightforward---I think you'll end up matching Fourier coefficients at the interfaces. -- W. Craig Carter === Subject: heat equation through different media/problem with constant flux at Äåáò Áìì¬ am trying to solve the heat conduction problem in a sequence of ôèòåmedia with different properties. For that I am using NDSolve ÷éôè íù ï÷grid. The code (without the 'tedious' definition of the ôéíå äå[Eth]åîäåîboundar y conditions) is: ܡܨΠÄÓïìö[ARin g]Û$B_(B_t u[x, ô[CapitalYAcute] .bd.bd áìæáÛø[CapitalYAcute]ª ¤Â¢ß¨ÂÜ ßûø2}u[x, t], u[ ø¬ °[CapitalYAcute] .bd.bd ÔáöÓÉî[ OHat]Û°[CapitalYAcute] (TavRInt[0] - TavSInt[0])/L* ø¬ õÛ°¬ ô[CapitalYAcute] .bd.bd ÔáöÓÉî[ OHat]Û ô[CapitalYAcute]([L, t]) == TavRInt[ ô[CapitalYAcute]£¿ õ¬ ûø0, L}, {t, 0, tmax}, MaxSteps -> 50000, Method - û¢Ü.bcÍåô[EGrav e]ïäÏæÌ[EAcute ]îåóÜ.be¢ -> { ¢Ü.bcÔåîó[IDoub leDot]ò[CapitalEth]òïäõ[ATi lde]ôÇòéä[CapitalUDoubleD ot].be¢¬ ¢Ü.bcÃïï[OG rave]äéîáôåó[CapitalU DoubleDot].be-> {mygrid}}}]) Èï÷åöåò ¬ still do not get a satisfactory result. Probably because I áí îïincluding the condition that at the interface between two media ôèheat flux is constant. How can I do this? Ôèáîëó Ìõéç === Subject: Re: heat equation through different media/problem with constant flux Luigi, > I am trying to solve the heat conduction problem in a sequence of > three media with different properties. For that I am using NDSolve > with my own grid. The code (without the 'tedious' definition of the > time dependent boundary conditions) is: !(NDSolve[{=A2=DF_t u[x, > t] == alfa[x]*=A2=DF_{x, 2}u[x, t], u[ > x, 0] == TavSInt[0] + (TavRInt[0] - TavSInt[0])/L* > x, u[0, t] == TavSInt[ > t], ([L, t]) == TavRInt[ > t]}, u, {x, 0, L}, {t, 0, tmax}, MaxSteps -> 50000, Method - >{, -> { > , -> {mygrid}}}]) > However, i still do not get a satisfactory result. Probably because I > am not including the condition that at the interface between two media > the heat flux is constant. How can I do this? The thing is here, that you have a jump condition between the two materials. A crude workaround would be to refine the mesh at the interface. Another option would be to smooth out the interface. Jose LLuis G=C3=B3mez-Mu=C3=B1osome time a ago did a finite element version of a similar problem. You can find it as part of the IMTEK Mathematica Supplement. http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/imsTOC/Applic ation%20Examples/Finite%20Element%20Method/CompositeMaterialsDocu.html There is also a 3D version of it. http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/imsTOC/Applic ation%20Examples/Finite%20Element%20Method/CompositeMaterials3DDocu.html hth, Oliver Oliver Ruebenkoenig, === Subject: Re: Help with minimization of Eigenvalues > > > > > > > Eig[p_, q_] := Eigenvalues[N@{m, s} /. a -> p /. b -> q] // First > Eig[1, 2] > > Yes, I have tried that before writing to the newsgroup. This seems to work, > however when I call > > > I still get the same error > > > Eigenvalues::gfargs: > Generalized Eigenvalues > arguments accept only matrices with machine real > and complex elements. More.89¥Ï > > > > > Moreover, though I am not sure to have fully understood what you tried to > achieved, you might be interested in using the function > CharacteristicPolynomial[] to compute the eigenvalues in a symbolic form and > use these results to solve or minimize them. > > I am trying to optimize the parameters of a matrix in order to minimize the > second (or n-th ) eigenvalue. > The matrices in general are of much higher order, say 6x6 or 10x10, and > the eigenvalues cannot in g eneral be computed in symbolic form > unfortunately. Hi Dario, The following definitions make certain that the parameters a and b are passed systematically to both matrices m and s. Indeed, the matrices m and s are defined as functions of a and b, and we force Mathematica to express them in machine-size arithmetic. Also, the function Eig[] is defined to ensure that it will be called only if both arguments are numeric. This is required, actually, to guarantee a correct behavior with FindNimimum[]. Clear[Eig, m, s] m[a_, b_] := N[{{a, b}, {b, -a + 1}}] s[a_, b_] := N[{{1, 0}, {0, 3*a}}] Eig[(a_)?NumericQ, (b_)?NumericQ] := First[Eigenvalues[{m[a, b], s[a, b]}]] Eig[1, 2] FindMinimum[Eig[a, b], {a, 1, 2}, {b, 1, 2}] 1.75831 {0.434259, {a -> 0.434259, b -> 2.14762*10^-10}} Hope this helps, -- Jean-Marc -- Jean-Marc === Subject: Re: Help with minimization of Eigenvalues On Apr 16, 1:14 pm, Jens-Peer Kuska s = {{1, 0}, {0, 3 a}}}, > Eigenvalues[N[{m, s}]] // First > ] may help. function Eig, and if I write Eig[a_?NumericQ, b_?NumericQ] := With[{m1 = m, s1 = s}, Eigenvalues[N[{m1, s1}]] // First] trying to assign the global matrices m and s to the local m1 and s1 still does not work. I do not understand the logic. What is happening? Dario === Subject: Re: Help with minimization of Eigenvalues > I am trying to minimize a particular eigenvalue of a generalized > eigenvalue problem that depends on a few parameters. I have the > following problem: Suppose we have two matrices s and m like these (the real matrices are > much more complicated) m = {{a, b}, {b, -a + 1}} s = {{1, 0}, {0, 3a}} If I define the function Eig Eig[a_, b_] := Eigenvalues[{m, s}]//First And use it with the FindMinimum function it does not work. > Infact just calling Eig[1,2] gives the error Eigenvalues::gfargs: > Generalized Eigenvalues > arguments accept only matrices with machine real > and complex elements. More... Even inserting Evaluate[] into the Eigenvalues function does not work. > What am I doing wrong? Your function Eig[a, b] does *not* use or pass its arguments to the matrices m and s. (In other words, the values a and b on the LHS are not used on the RHS: the matrices still hold the symbols a and b.) The following is one possible way to modify the value of a and b within the matrices m and s. In[29]:= m = {{a, b}, {b, -a + 1}}; s = {{1, 0}, {0, 3 a}}; Eig[p_, q_] := Eigenvalues[N@{m, s} /. a -> p /. b -> q] // First Eig[1, 2] Out[32]= 1.75831 Moreover, though I am not sure to have fully understood what you tried to achieved, you might be interested in using the function CharacteristicPolynomial[] to compute the eigenvalues in a symbolic form and use these results to solve or minimize them. In[46]:= CharacteristicPolynomial[{m, s}, x] Out[46]= a - a^2 - b^2 - x + a x - 3 a^2 x + 3 a x^2 In[51]:= Reduce[CharacteristicPolynomial[{m, s}, x] == 0] Out[51]= (x == -(1/3) && a == 1/3 (-1 + 3 b^2)) || (1 + 3 x != 0 && (a == ( 1 + x + 3 x^2 - Sqrt[-4 (b^2 + x) (1 + 3 x) + (-1 - x - 3 x^2)^2])/( 2 (1 + 3 x)) || a == (1 + x + 3 x^2 + Sqrt[-4 (b^2 + x) (1 + 3 x) + (-1 - x - 3 x^2)^2])/( 2 (1 + 3 x)))) -- Jean-Marc === Subject: Re: Help with minimization of Eigenvalues > I am trying to minimize a particular eigenvalue of a generalized > eigenvalue problem that depends on a few parameters. I have the > following problem: Suppose we have two matrices s and m like these (the real matrices are > much more complicated) m = {{a, b}, {b, -a + 1}} s = {{1, 0}, {0, 3a}} If I define the function Eig Eig[a_, b_] := Eigenvalues[{m, s}]//First And use it with the FindMinimum function it does not work. > Infact just calling Eig[1,2] gives the error Eigenvalues::gfargs: > Generalized Eigenvalues > arguments accept only matrices with machine real > and complex elements. More... Even inserting Evaluate[] into the Eigenvalues function does not work. > What am I doing wrong? Your function Eig[a, b] does *not* use or pass its arguments to the matrices m and s. (In other words, the values a and b on the LHS are not used on the RHS: the matrices still hold the symbols a and b.) The following is one possible way to modify the value of a and b within the matrices m and s. In[29]:= m = {{a, b}, {b, -a + 1}}; s = {{1, 0}, {0, 3 a}}; Eig[p_, q_] := Eigenvalues[N@{m, s} /. a -> p /. b -> q] // First Eig[1, 2] Out[32]= 1.75831 Moreover, though I am not sure to have fully understood what you tried to achieved, you might be interested in using the function CharacteristicPolynomial[] to compute the eigenvalues in a symbolic form and use these results to solve or minimize them. In[46]:= CharacteristicPolynomial[{m, s}, x] Out[46]= a - a^2 - b^2 - x + a x - 3 a^2 x + 3 a x^2 In[51]:= Reduce[CharacteristicPolynomial[{m, s}, x] == 0] Out[51]= (x == -(1/3) && a == 1/3 (-1 + 3 b^2)) || (1 + 3 x != 0 && (a == ( 1 + x + 3 x^2 - Sqrt[-4 (b^2 + x) (1 + 3 x) + (-1 - x - 3 x^2)^2])/( 2 (1 + 3 x)) || a == (1 + x + 3 x^2 + Sqrt[-4 (b^2 + x) (1 + 3 x) + (-1 - x - 3 x^2)^2])/( 2 (1 + 3 x)))) -- Jean-Marc === Subject: Re: List concatenation - two more methods, one truly fast > As follow up, the following tests are more realistic in that p > is similar to the Graphics objects produced during a mesh > plot. The last method (table entry substitution) is about 2 orders > of magnitude faster. Unfortunately in actual plot generation I > dont known n (number of objects) in advance, so that one is out. ClearAll[poly,p,n]; poly={}; n=5000; SetRandom[1234]; > p[arg_]:= {Graphics[RGBColor[Random[],Random[],Random[]]], > Graphics[Polygon[{{Random[],Random[]}, > {Random[],Random[]},{Random[],Random[]}}]]}; > Print[Timing[Do[AppendTo[poly,p[i]],{i,1,n}]][[1]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Append[poly,p[i]],{i,1,n}]][[1]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly=Join[poly,{p[i]}],{i,1,n}]][[1]]]; > ClearAll[poly]; poly={}; > Print[Timing[Do[poly={poly,p[i]},{i,1,n}];poly=Flatten[poly]][[1]]]; > ClearAll[poly]; poly=Table[0,{n}]; > Print[Timing[Do[poly[[i]]=p[i],{i,1,n}]][[1]]; > 11.3361 Second > 11.3306 Second > 11.7123 Second > 7.24559 Second > 0.061505 Second Observation: timing of the first 4 methods is roughly O(n^2). > That would suggest that Mathematica does not implement a true > list processor in the kernel, since building a list should be O(n). This result is fascinating - it is reasonable that all the solutions based on appending lists work O(n^2), but the nested list approach should not behave this way. If you repeat the timing, but without defining p: n = 5000; poly = Table[0, {n}]; Print[Timing[Do[poly = {poly, p[i]}, {i, 1, n}]; poly = Flatten[poly]][[1]]]; I get 0.02 seconds rather than 11 seconds (I obviously have a slightly slower machine. This means that the time depends crucially on what you are accumulating. Consider the semantics of the operation: poly = {poly, p[i]} This will only be efficient if Mathematica 'knows' that the old value of poly is already fully evaluated. As I understand it, Mathematica does this using a hashing method, and my guess is that in this case the hash table overflows and the ever growing expression gets repeatedly evaluated - hence O(n^2). It would be nice if someone from Wolfram could comment on these timing results. Incidentally, the following method works efficiently without requiring the array size to be known in advance: n = 5000; poly = Table[0, {n}]; Print[Timing[poly = Reap[Do[Sow[p[i]], {i, 1, n}]][[2, 1]]][[1]]]; David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Coordinates of vertices > I forgot to mention that I was using version 5.1 so I don't think I have > access to that. My fault. Any other suggestions? I have an old version of my course notes for when I was teaching with 5.0, and I wanted to do transformations on polyhedra. The number of vertices were small enough that you can visibly extract them via: < === Subject: Re: Coordinates of vertices I forgot to mention that I was using version 5.1 so I don't think I have access to that. My fault. Any other suggestions? > -----Original Message----- > Cc: mathgroup@smc.vnet.net === > Subject: Re: Coordinates of vertices > Peter, The vertices are in the graphics object. > Just use [[ ]] to get them out. tc=Truncate[PolyhedronData[Cube]] > vertices=ph[[1,1]]//N > ListPointPlot3D[vertices ,BoxRatios->Automatic] Hope this helps, maarten > > > King, Peter R > > > mathgroup@smc.vnet.net > > ial.ac.uk> cc: > > === > Subject: > Coordinates of vertices > > 16/04/2008 11:02 > > > > > > > > > I am sure I have done this before but I can't for the life of me > remember how, and I can't find it in the manual. Some help > would be much > appreciated. I'd like to find the coordinates of the vertices of a > truncated cube. Whilst Vertices[cube] correctly gives me the coordinates of a cube > Vertices[Truncate[Polyhedron[Cube]]] doesn't do what I want because > Truncate[Polyhedron[... is a graphics object not a polyhedron > object. So > can I convert the graphics object into a polyhedron and use > vertices, or > work out the vertices some other way (for a cube this is trivial to do > but for more complicated shapes this is much more tedious) > Peter > === Subject: Basic algebraic identities 1. Which basic algebraic identities does Mathematica know? For example, it does not appear to know the orthogonality relation for Legendre polynomials: Integrate[ LegendreP[m, x] LegendreP[n, x], {x,-1,1}] - 2/(2 n+1) KroneckerDelta[n,m] = 0 When I try this out, I find that the left hand side does not evaluate to zero - even if I add assumptions about n & m being positive integers. Yet a similar check shows that it does know about Cos[x]^2 + Sin[x]^2] - 1 = 0 (although one does need to use Simplify[%] before it reveals its knowledge). 2. If it really does not know the orthogonality relation for Legendre polys, how would I teach it? === Subject: Re: ListPlot & lots 'o dots. it is definitly a bug Wolfram should fix. Daniel Apparently ListPlot has a quirk on my systems (XP SP2/3, 6.0.2) With test data test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], > [Pi]/50}]; ListPlot[test] produces a plot with lots 'o dots as expected. It's > easy to see which dots correspond to which frequency by connecting > points in each data set ListPlot[test, Joined->True] We can correct the ordinate scale using ListPlot[test, Joined->True, DataRange->{-[Pi], [Pi]}], and for > lots 'o plots this looks messy. Using SetOptions, we can set ListPlot up so that we don't need to > specify Joined & a data range every time we use ListPlot using SetOptions[ListPlot, DataRange -> {-[Pi], [Pi]}, Joined - True ]; We can confirm ListPlot's new settings either by removing the ; or > using Options@ListPlot. For me this is where the problem starts. After an appropriate SetOptions (like above), ListPlot[test] should > give me a plots that is joined & has the correct ordinate scale. For > me it doesn't, despite Joined->True and DataRange, ListPlot[test] gets > ma a plot with lots 'o dots and the wrong scale. I know there's a > point to SetOptions since I can set (eg) a PlotRange and FrameLabels. > It's just that ListPlot (apparently) ignores DataRange & Joined so > that I have to specify them each time I use ListPlot. I'd like to know if this problem restricted to my system. In the > event that it can be reproduced, I'll report it as a bug. Tests. > test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], [Pi]/ > 50}]; (* generate test data *) > ListPlot[test] (* plot w/ lots o dots *) > ListPlot[test, Joined -> True, DataRange -> {-[Pi], [Pi]}] (* > desired plot *) > SetOptions[ListPlot, DataRange -> {-[Pi], [Pi]}, Joined -> True, > FrameLabel -> {Hi, Lo}, PlotRange -> {0, [Pi]/2}]; (* set default > options for ListPlot *) > ListPlot[test] (* dotty plot, incorrect ordinate but correct abscissa > & labels -- WTF? *) Dave. === Subject: Re: ListPlot & lots 'o dots. Apparently ListPlot has a quirk on my systems (XP SP2/3, 6.0.2) With test data test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], > [Pi]/50}]; ListPlot[test] produces a plot with lots 'o dots as expected. It's > easy to see which dots correspond to which frequency by connecting > points in each data set ListPlot[test, Joined->True] We can correct the ordinate scale using ListPlot[test, Joined->True, DataRange->{-[Pi], [Pi]}], and for > lots 'o plots this looks messy. Using SetOptions, we can set ListPlot up so that we don't need to > specify Joined & a data range every time we use ListPlot using SetOptions[ListPlot, DataRange -> {-[Pi], [Pi]}, Joined - True ]; We can confirm ListPlot's new settings either by removing the ; or > using Options@ListPlot. For me this is where the problem starts. After an appropriate SetOptions (like above), ListPlot[test] should > give me a plots that is joined & has the correct ordinate scale. For > me it doesn't, despite Joined->True and DataRange, ListPlot[test] gets > ma a plot with lots 'o dots and the wrong scale. I know there's a > point to SetOptions since I can set (eg) a PlotRange and FrameLabels. > It's just that ListPlot (apparently) ignores DataRange & Joined so > that I have to specify them each time I use ListPlot. I'd like to know if this problem restricted to my system. In the > event that it can be reproduced, I'll report it as a bug. Tests. > test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], [Pi]/ > 50}]; (* generate test data *) > ListPlot[test] (* plot w/ lots o dots *) > ListPlot[test, Joined -> True, DataRange -> {-[Pi], [Pi]}] (* > desired plot *) > SetOptions[ListPlot, DataRange -> {-[Pi], [Pi]}, Joined -> True, > FrameLabel -> {Hi, Lo}, PlotRange -> {0, [Pi]/2}]; (* set default > options for ListPlot *) > ListPlot[test] (* dotty plot, incorrect ordinate but correct abscissa > & labels -- WTF? *) Dave. It would seem that ListPlot is not responding to changed options! Although this is a bug, I would not recommend setting the options of built-in functions because it can cause confusion over time. A better approach is to define your own plotting function which calls ListPlot with the required options. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: ListPlot & lots 'o dots. Hello David, I am not sure I understand your question accurately, but if I do understand, then this may be a preferable solution to your problem: (*fresh kernel*) test = Table[{x, Sin[n Pi x]}, {n, 1, 5, 1}, {x, -Pi, Pi, Pi/50}]; (* supply x and y explicitly *) ListPlot[test] ListPlot[test, Joined -> True] ListLinePlot[test] This is a lovely example by the way---I am going to use it as a problem for students to calculate fourier coefficients from data: give 'em the points randomly, extract the coefficients, plot separate curves... Craig Carter > With test data > test = Table[N@Sin[n [Pi] x], {n, 1, 5, 1}, {x, -[Pi], [Pi], > [Pi]/50}]; > We can correct the ordinate scale using ListPlot[test, Joined->True, DataRange->{-[Pi], [Pi]}], and for > lots 'o plots this looks messy. : : > ListPlot[test] (* dotty plot, incorrect ordinate but correct abscissa > & labels -- WTF? *) > === Subject: Re: If Integrate returns no result, can we conclude that no closed-form >> The documentation says: >> In the most convenient cases, integrals can be done purely in >> terms of elementary functions such as exponentials, logarithms and >> trigonometric functions. In fact, if you give an integrand that >> involves only such elementary functions, then one of the important >> capabilities of Integrate is that if the corresponding integral >> can be expressed in terms of elementary functions, then Integrate >> will essentially always succeed in finding it. >> = http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCanno= tBeDone.html >> How precise is this? Can one rely on this information? >> I suppose that depends on the definition of essentially. ;-) >>> Is it really >> true that if Mathematica cannot integrate an expression made up of >> elementary functions, then no closed-form result exists? > No. Consider, for example, >> In[9]:= Integrate[D[x Sin[x^ArcSin[x]], x], x] >> Out[9]= Integrate[x^(1 + ArcSin[x])*Cos[x^ArcSin[x]]*(ArcSin[x]/x = + > Log[x]/Sqrt[1 - x^2]) + Sin[x^ArcSin[x]], x] >> which was done in Versionn 6.0.2 under Windows XP. > This is not an elementary function (as far as the Risch algorithm >> is concerned). >> The class of elementary functions consists of rational functions, >> exponentials, logarithms, trigonometric, inverse trigonometric, >> hyperbolic, and inverse hyperbolic functions, the solutions of a >> polynomial equation whose coefficients are elementary functions) and >> any finite nesting (composition) of elementary functions. It does >> not include the power of an elementary function to another >> elementary function so your example actually shows the opposite of >> what you seem to claim, namely that Mathematica has correctly >> concluded (by using the Risch algorithm) that the integral cannot be >> expressed in terms of elementary functions. Are you claiming that, for the purpose of the Risch algorithm, > Exp[Log[x] ArcSin[x]] is not considered to be an elementary function? I find that hard to believe! David > I think both of us are (partly) right. Well, you are right that this is an elementary function in the sense that I stated earlier (composites of elementary functions are elementary) but it is certainly not an elementary transcendental function as in the easy case of the Risch algorithm (e.g. see p. 529 of Geddes, Czapor, Labahn Algorithms for computer algebra). Elementary transcendental functions are just functions generated over the ground field by exponential and logs. However your function is an object that lives in a mixed tower of algebraic and transcendental extensions. Algebraic extensions are needed to convert ArcSin to Log, which is required by the Risch algorithm, and you obviously need to consider two transcendental extensions because of the composition of transcendental functions in your formula. So we have a so called mixed tower of extensions. However, the original Risch algorithm did not apply to such cases. This case was solved only in 1987 in a PhD thesis of Bronstein (Risch's paper appeared in 1968) and as far as I know it has never been implemented. Its certainly not implemented in Mathematica and moreover it seems it is not even considered as an unimplemented part of the Risch algorithm (see Bhuvanesh's post in the same thread, which only mentions the purely algebraic case as unimplemented). So, if this is correct (and I am only an amateur in this area) then, although your function is indeed elementary in the wide sense of Bronstein's algorithm it is not elementary in the sense of the original Risch algorithm. Andrzej Kozlowski Andrzej Kozlowski === Subject: Re: If Integrate returns no result, can we conclude that no closed-form > The documentation says: >> In the most convenient cases, integrals can be done purely in > terms of elementary functions such as exponentials, logarithms and > trigonometric functions. In fact, if you give an integrand that > involves only such elementary functions, then one of the important > capabilities of Integrate is that if the corresponding integral > can be expressed in terms of elementary functions, then Integrate > will essentially always succeed in finding it. >> http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCannotBe Done.html >> How precise is this? Can one rely on this information? >> I suppose that depends on the definition of essentially. ;-) > Is it really > true that if Mathematica cannot integrate an expression made up of > elementary functions, then no closed-form result exists? > No. Consider, for example, >> In[9]:= Integrate[D[x Sin[x^ArcSin[x]], x], x] >> Out[9]= Integrate[x^(1 + ArcSin[x])*Cos[x^ArcSin[x]]*(ArcSin[x]/x + >> Log[x]/Sqrt[1 - x^2]) + Sin[x^ArcSin[x]], x] >> which was done in Versionn 6.0.2 under Windows XP. > This is not an elementary function (as far as the Risch algorithm > is concerned). The class of elementary functions consists of rational functions, > exponentials, logarithms, trigonometric, inverse trigonometric, > hyperbolic, and inverse hyperbolic functions, the solutions of a > polynomial equation whose coefficients are elementary functions) and > any finite nesting (composition) of elementary functions. It does > not include the power of an elementary function to another > elementary function so your example actually shows the opposite of > what you seem to claim, namely that Mathematica has correctly > concluded (by using the Risch algorithm) that the integral cannot be > expressed in terms of elementary functions. Are you claiming that, for the purpose of the Risch algorithm, Exp[Log[x] ArcSin[x]] is not considered to be an elementary function? I find that hard to believe! David === Subject: Re: If Integrate returns no result, can we conclude that no closed-form >> The documentation says: >> In the most convenient cases, integrals can be done purely in >> terms of >> elementary functions such as exponentials, logarithms and >> trigonometric >> functions. In fact, if you give an integrand that involves only such >> elementary functions, then one of the important capabilities of >> Integrate is that if the corresponding integral can be expressed in >> terms of elementary functions, then Integrate will essentially always >> succeed in finding it. >> = http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCann >> otBeDone.html >> How precise is this? Can one rely on this information? I suppose that depends on the definition of essentially. ;-) > Is it really >> true that if Mathematica cannot integrate an expression made up of >> elementary functions, then no closed-form result exists? No. Consider, for example, In[9]:= Integrate[D[x Sin[x^ArcSin[x]], x], x] Out[9]= Integrate[x^(1 + ArcSin[x])*Cos[x^ArcSin[x]]*(ArcSin[x]/x + > Log[x]/Sqrt[1 - x^2]) + Sin[x^ArcSin[x]], x] which was done in Versionn 6.0.2 under Windows XP. This is not an elementary function (as far as the Risch algorithm is concerned). The class of elementary functions consists of rational functions, exponentials, logarithms, trigonometric, inverse trigonometric, hyperbolic, and inverse hyperbolic functions, the solutions of a polynomial equation whose coefficients are elementary functions) and any finite nesting (composition) of elementary functions. It does not include the power of an elementary function to another elementary function so your example actually shows the opposite of what you seem to claim, namely that Mathematica has correctly concluded (by using the Risch algorithm) that the integral cannot be expressed in terms of elementary functions. Andrzej Kozlowski === Subject: Re: If Integrate returns no result, can we conclude that no closed-form .. > A completely implemented Risch algorithm will either return an > explicit answer for an integral that can be evaluated in terms of > elementary functions or determine that no such answer can be given. ... > Andrzej Kozlowski Is this a theorem? Matthias Bode. === Subject: Re: If Integrate returns no result, can we conclude that no closed-form You are right that all computer algebra systems that perform indefinite integration use the Risch algorithm (arguably misnamed since Risch's original work in 1968 dealt chiefly with the easier part of the algorithm, and others such as Liouville, Hermite, Hardy and Ritt earlier and Davenport, Trager and others later, contributed at least as much). A completely implemented Risch algorithm will either return an explicit answer for an integral that can be evaluated in terms of elementary functions or determine that no such answer can be given. The Risch algorithm consists of two parts. The first deals with so called transcendental elementary functions. This is the easy part and is very similar to the Hermite's method of integrating arbitrary rational functions (a part of which is taught in calculus courses). However, the second part, which deals with algebraic functions is much harder and uses some quite advanced computational algebraic geometry. As far as there is no complete implementation of the Risch algorithm in any CAS. Anyway, this was sure about 10 years ago and I doubt that anything has changed since then (but would not stake my life on that). The problem lies, of course, with the part involving computational algebraic geometry. Algorithms in computational algebraic geometry are often very hard to implement (and the number of people who understand them and can program at the professional level and also have the time that would be needed for this is surely rather limited). As a result I believe there are certain branches of the Risch algorithm where some kind of heuristics are used instead of the algorithm itself. I have no idea will happen if the Mathematica implementation gets into one of such branches. One possibility,of course, it that the heuristic method will work anyway and you will get an answer (possible a wrong one;-)). Or the thing may just run for ever. I doubt that it will just admit defeat and return the integral unevaluated. I think it is fairly safe to assume that if an indefinite integral is returned unevaluated than it can't be integrated in terms of elementary functions. But this, of course, is only mere speculation. Andrzej Kozlowski The documentation says: In the most convenient cases, integrals can be done purely in terms > of > elementary functions such as exponentials, logarithms and > trigonometric > functions. In fact, if you give an integrand that involves only such > elementary functions, then one of the important capabilities of > Integrate is that if the corresponding integral can be expressed in > terms of elementary functions, then Integrate will essentially always > succeed in finding it. http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCannotBe Done.html How precise is this? Can one rely on this information? Is it really > true that if Mathematica cannot integrate an expression made up of > elementary functions, then no closed-form result exists? Szabolcs (P.S. I do not know how Integrate works. I heard that CASs use a > so-called Risch-alogrithm, but there is relatively little > information > about this on the web (except in academic papers, most of which expect > the reader to be familiar with the topic).) > === Subject: Re: If Integrate returns no result, can we conclude that no > The documentation says: In the most convenient cases, integrals can be done purely in terms of > elementary functions such as exponentials, logarithms and trigonometric > functions. In fact, if you give an integrand that involves only such > elementary functions, then one of the important capabilities of > Integrate is that if the corresponding integral can be expressed in > terms of elementary functions, then Integrate will essentially always > succeed in finding it. http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAnd... How precise is this? Can one rely on this information? Is it really > true that if Mathematica cannot integrate an expression made up of > elementary functions, then no closed-form result exists? Szabolcs (P.S. I do not know how Integrate works. I heard that CASs use a > so-called Risch-alogrithm, but there is relatively little information > about this on the web (except in academic papers, most of which expect > the reader to be familiar with the topic).) No, just the fact that Integrate cannot do an integral doesn't mean no closed form in elementary functions exists. Here's one example that Integrate cannot currently do but can be done in closed form (in terms of elementary functions): Integrate[(1 - x^2 - 5*x^4 + 9*x^5 - 5*x^6 + 5*x^9)/(Sqrt[-1 + x + x^5]*(-1 + x - x^2 + x^5)), x] Integrate does not currently have a full implementation of the algebraic case of the Risch algorithm, for instance, although we still do pretty well using substitutions and elliptic integration code for such inputs. Bhuvanesh, Wolfram Research === Subject: Re: If Integrate returns no result, can we conclude that no closed-form > The documentation says: In the most convenient cases, integrals can be done purely in terms of > elementary functions such as exponentials, logarithms and trigonometric > functions. In fact, if you give an integrand that involves only such > elementary functions, then one of the important capabilities of > Integrate is that if the corresponding integral can be expressed in > terms of elementary functions, then Integrate will essentially always > succeed in finding it. http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCann > otBeDone.html How precise is this? Can one rely on this information? I suppose that depends on the definition of essentially. ;-) > Is it really > true that if Mathematica cannot integrate an expression made up of > elementary functions, then no closed-form result exists? No. Consider, for example, In[9]:= Integrate[D[x Sin[x^ArcSin[x]], x], x] Out[9]= Integrate[x^(1 + ArcSin[x])*Cos[x^ArcSin[x]]*(ArcSin[x]/x + Log[x]/Sqrt[1 - x^2]) + Sin[x^ArcSin[x]], x] which was done in Versionn 6.0.2 under Windows XP. > Szabolcs (P.S. I do not know how Integrate works. I heard that CASs use a > so-called Risch-alogrithm, but there is relatively little information > about this on the web (except in academic papers, most of which expect > the reader to be familiar with the topic).) People who work for WRI can answer better than I, but if I understand correctly, Mathematica's implementation of the Risch algorithm is incomplete. Furthermore, I suspect that there is no current CAS having a complete implementation of it. David === Subject: Re: mx files this means, the utilities for dealing with contexts and packages which work automatically for .m files (BeginPackage[.., {..}], Needs after Begin[`Private`] etc.) have to be modified for .mx files .. ?! I have a large number of packages in my Applications directory. Many of them depend on each other. If I follow your advice, there will be a lot of redundancy: For the example below, the definitions of OtherPackage will be stored in OtherPackage.mx (for users calling Needs[OtherPackage`] but also in SomePackage.mx (for users calling Needs[SomePackage`]. It seems, for creating SomePackage.mx I have to include also all packages which appear in $Packages after starting the kernel and executing SomePackage.nb. Is that the correct approach? Hannes Kessler On 16 Apr., 13:20, Jens-Peer Kuska DumpSave[ SomePackage.mx, {SomePackage`,OtherPackage`}] ?? Jens > What about the following example? > BeginPackage[SomePackage`, {OtherPackage`}] > ... > EndPackage[] > DumpSave[ SomePackage.mx, SomePackage`] > Quit[] > Needs[SomePackage`] > The context OtherPackage` is not in $ContextPath as it should be. > Hannes Kessler > On 15 Apr., 12:49, Jens-Peer Kuska > DumpSave[] will do it. >> Jens > what is the preferred method to create packages in .mx files analogous > to the initialization cell method in notebooks to maintain packages in > the .m format? > Hannes Kessler === Subject: Re: The FinancialData Function I share your concerns, but hold more hope that Wolfram realise that charging ~$2500 for a license and $500 for Premier Service results in some obligations to their customers. That said, I was disappointed that their Tech Support didn't follow up on the concerns I expressed about 6mths ago - is their statement that FinancialData is 'experimental' a caveat intended to warn us all that it's not to be used for serious work? I hope not. We are all now pretty used to the fact that Mathematica is well written, and that QA/QC is exceptionally good (despite those who think they or others can do better). Given this, I am sure they have fully understood just how powerful the curated data facilities can be for the user. Renegging in the FD function would not be acceptable to me and I suspect many others. Now, you mention the data paclets could be at risk and that Yahoo could suddenly start charging WRI (if they are not already). The solution would be simple, however, since I know there are many financal data providers out there who could fill the gap - at a cost. I would like to hear from WRI about this since its a key issue. I've never heard of this function, but have one immediate strong reaction/question: Is there -- or will there soon be -- a fully open, officially standardized, fully and openly specified, widely and near universally accepted, stable, long-term, NON-proprietary set of **formats** for the data and information that is to be transmitted back and forth between data providers and data users in this system? [Something akin to the more or less open, universal and stable graphics standards that have emerged over time.] Lacking that, I wouldn't personally go near this kind of financial data distribution system and related tools like FinancialData for building anything that was of any real and continuing importance to me. Think of mapping data, GPS and topographic data, or satellite imagery and related software tools as an analogous system. I play with some of this data, plan journeys using MapQuest, hiking trips using Google Earth (an incredible tool), etc -- but if someone suddenly decided to change all the standards for this data, I could still use all my old stored data and tools -- or just do without. (There would of course be many important commercial enterprises that would be much more seriously impacted.) But then suppose people get important, continuing personal or business activities deeply involved in an information system that uses tools like FinancialData; the data providers and Wolfram somehow get cross-wise commercially; and the data providers threaten to change their formats just enough to screw Wolfram (and all FinancialData users). Or, suppose the data providers decide to throw digital rights management complexities all over their data, as is the case now with music, films, video -- and the deep pockets financial data providers manage to bribe Congress to require that all computer tools like FinancialData contain provisions to enforce these DRM complexities. This may all come across as paranoid fears, and maybe it is -- but look what has actually happened in other areas of widely distributed electronic information distribution . . . Robert Prince-Wright Houston TX, 77006 USA === Subject: Re: The FinancialData Function On Apr 1, 10:19 am, robert prince-wright > I share your concerns, but hold more hope that Wolfram realise that charging ~$2500 for a license and $500 for Premier Service results in some obligations to their customers. That said, I was disappointed that their Tech Support didn't follow up on the concerns I expressed about 6mths ago - is their statement that FinancialData is 'experimental' a caveat intended to warn us all that it's not to be used for serious work? I hope not. We are all now pretty used to the fact that Mathematica is well written, and that QA/QC is exceptionally good (despite those who think they or others can do better). Given this, I am sure they have fully understood just how powerful the curated data facilities can be for the user. Renegging in the FD function would not be acceptable to me and I suspect many others. Now, you mention the data paclets could be at risk and that Yahoo could suddenly start charging WRI (if they are not already). The solution would be simple, however, since I know there are many financal data providers out there who could fill the gap - at a cost. I would like to hear from WRI about this since its a key issue. > I've never heard of this function, but have one immediate strong > reaction/question: Is there -- or will there soon be -- a fully open, officially > standardized, fully and openly specified, widely and near universally > accepted, stable, long-term, NON-proprietary set of **formats** > for the data and information that is to be transmitted back > and forth between data providers and data users in this > system? [Something akin to the more or less open, universal and stable graphics > standards that have emerged over time.] Lacking that, I wouldn't personally go near this kind of financial data > distribution system and related tools like FinancialData for building > anything that was of any real and continuing importance to me. Think of mapping data, GPS and topographic data, or satellite imagery > and related software tools as an analogous system. I play with some of > this data, plan journeys using MapQuest, hiking trips using Google Earth > (an incredible tool), etc -- but if someone suddenly decided to change > all the standards for this data, I could still use all my old stored > data and tools -- or just do without. (There would of course be many > important commercial enterprises that would be much more seriously > impacted.) > Financial data come in many shapes and colors. Some data are public domain, but not real time (for ex. 20 min.- delayed stock prices), other data is not free, but real time (eg. real time stock prices). Some data is real time and still free (eg. forex prices). I am sure WRI complies with all the legal requirements when distributing financial data. Things may change in the future, like everything else. > But then suppose people get important, continuing personal or business > activities deeply involved in an information system that uses tools like > FinancialData; the data providers and Wolfram somehow get cross-wise > commercially; and the data providers threaten to change their formats > just enough to screw Wolfram (and all FinancialData users). Or, suppose the data providers decide to throw digital rights management > complexities all over their data, as is the case now with music, films, > video -- and the deep pockets financial data providers manage to bribe > Congress to require that all computer tools like FinancialData contain > provisions to enforce these DRM complexities. This may all come across as paranoid fears, and maybe it is -- but look > what has actually happened in other areas of widely distributed > electronic information distribution . . . Robert Prince-Wright > Houston > TX, 77006 > USA === Subject: Re: Legend with ListDensityPlot > Equivalent functionality to colorbar in Mathematica? I'm an author of a package to do this for DensityPlot, ContourPlot, and Plot3D: I'd be interested in any helped to extend it to work with List- plots as well. I haven't got around to it, 'coz I haven't need it yet. You could always use an interpolating function with the list data as input to a ContourPlot, I suppose. Will === Subject: Re: Number of monominals I was installed today upgrade to ver. 6.02 and all working correct now. My Mathematica first process run during 2 weeks and I was working on 2 process. ARTUR Alexey Popkov pisze: > >> According to the documentation, the function Length[expr] gives the >> number of elements in expr. >> Also The length of a symbol is 0. >> You have to write it as a list, if you want the expression to be counted. >> Length[{f[1]}] >> The other inputs are working, because Length counts the elements of the >> function Plus: >> In[1]:=Length[Plus[f[1],f[2],f[3]]] >> Out[1]:=3 >> OK! >> In[2]:=Length[Plus[f[1],f[2]]] >> Out[2]:=2 >> In[3]:=Length[f[1]] >> Out[3]:=0 >> I hope, that I could answer your question. >> Patrick >> I can not reproduce such behavour in Mathematica 5.2 and 6.02. How do > you do that? > In[1]:= Length[f[1]] > Out[1]= 1 > __________ NOD32 Informacje 2701 (20071204) __________ Wiadomosc zostala sprawdzona przez System Antywirusowy NOD32 > http://www.nod32.com lub http://www.nod32.pl === Subject: Something very simple..... 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, {{ 7.18, -1.86, -8.19}, 98.02}, {{26.71, -9.30, -6.85}, 111.27}, {{ 0, 0, 0}, 100.00}, {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], Sphere[{{26.71, -9.30, -6.85}, 111.27}], Sphere[{{ 0, 0, 0}, 100.00}], Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. What simple thing am I missing to remove the extra braces? (I know I can use Table but isn't there a one-step method?) Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. I want the elements of lsta that do NOT correspond to elements of lstb, in this case everything from lsta except elements 1,3, and 4: result={b,e,f}. (lstb won't have entries larger than Length[lsta]). Steve Gray === Subject: Re: Something very simple..... > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} Here is a more complicated pattern match approach, (Apply seems to be the easiest) sphlst /. {x : (List[{z__}, n_]) -> Sphere[{z}, n]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Using the range and complement could be one way In[113]:= Extract[lsta, #] & /@ (Complement[Range[Length[lsta]], lstb]) Out[113]= {b, e, f} Hope this is helpful Pratik Desai Wolfram Research Steve Gray > -- === Subject: Re: Something very simple..... > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray Here is a newbie approach for 1: > In[26]:= > (Sphere[Sequence[First[#1], > Last[#1]]] & ) /@ sphlst > Out[26]= > {Sphere[{5.11, 0.76, -0.32}, > 100.39], Sphere[ > {7.18, -1.86, -8.19}, > 98.02], Sphere[{26.71, > -9.3, -6.85}, 111.27], > Sphere[{0, 0, 0}, 100.], > Sphere[{8.65, 4.28, -3.81}, > 103.87]} Here is a more newbie approach for 2: > In[19]:= > Flatten[Extract[lsta, > Complement[ > (Position[lsta, > #1] & ) /@ lsta, > ({{#1}} & ) /@ lstb]]] > Out[19]= > {b, e, f} I hope it helps. J=E1nos ------ ..because Annushka has already bought sunflower oil, and not only bought it, but spilled it too. Bulgakov: Master and Margarita === Subject: Re: Something very simple..... 1. A pretty ugly solution (explicitly taking the arguments to Sphere and doing a pattern match), but you get the expected blastomere plot: In[6]:= g = Sphere /@ sphlst /. {Sphere[{{a__}, b_}] -> Sphere[{a}, b]} Out[6]= {Sphere[{5.11, 0.76, -0.32}, 100.39], Sphere[{7.18, -1.86, -8.19}, 98.02], Sphere[{26.71, -9.3, -6.85}, 111.27], Sphere[{0, 0, 0}, 100.], Sphere[{8.65, 4.28, -3.81}, 103.87]} In[7]:= Graphics3D[g] Out[7]= Graphics3D[{Sphere[{5.11, 0.76, -0.32}, 100.39], Sphere[{7.18, -1.86, -8.19}, 98.02], Sphere[{26.71, -9.3, -6.85}, 111.27], Sphere[{0, 0, 0}, 100.], Sphere[{8.65, 4.28, -3.81}, 103.87]}, ImageSize -> {360., 380.88094545077234}, ViewPoint -> {2.6859783732354505, -2.033988326753927, -0.31370633583051105}, ViewVertical -> {0.4842555587883932, -0.47728721617137, 0.7967257012534106}] your 1D example lists (for example it checks to make sure that removalList is shorter or of equal length to list). But it works for your case (others' code will almost certainly be much more efficient): deleteElements[list_ /; Length[Dimensions[list]] == 1, removalList_] := Delete[list, Partition[removalList,1]]/; (Length[removalList]<=Length[list] && Length[Dimensions[removalList]] == 1 && First@Union@(Positive@removalList) && First@Union@(IntegerQ /@ removalList)) In[14]:= deleteElements[{a, b, c, d, e, f}, {1, 3, 4}] Out[14]= {b, e, f} Good luck! > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray === Subject: Re: Something very simple..... There are some good answers that have been posted. Here is a more compact option: Delete[lsta, List/@lstb] Januk > 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray === Subject: Re: Something very simple..... I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). The following will do it: Pick[lsta, If[MemberQ[lstb, #], False, True] & /@ Range@Length@lsta] Here is how it works: lsta = {a, b, c, d, e, f} ; lstb = {1, 3, 4}; (* We build a list of same length as lsta since Pick expects two list of same length. *) Range@Length@lsta {1, 2, 3, 4, 5, 6} (* We mark what elements must be taken. *) If[MemberQ[lstb, #], False, True] & /@ Range@Length@lsta {False, True, False, False, True, True} (* The final expression is *) Pick[lsta, If[MemberQ[lstb, #], False, True] & /@ Range@Length@lsta] {b, e, f} -- Jean-Marc === Subject: Re: Something very simple..... Sphere @@@ sphlst ?? Jens > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray > === Subject: Re: Something very simple..... > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. The following will do it: Map[Sphere[Sequence @@ #] &, sphlst] For instance, In[1]:= sphlst = {{{5.11, 0.76, -0.32}, 100.39}, {{7.18, -1.86, -8.19}, 98.02}, {{26.71, -9.30, -6.85}, 111.27}, {{0, 0, 0}, 100.00}, {{8.65, 4.28, -3.81}, 103.87}}; Map[Sphere[Sequence @@ #] &, sphlst] Graphics3D@% Out[2]= {Sphere[{5.11, 0.76, -0.32}, 100.39], Sphere[{7.18, -1.86, -8.19}, 98.02], Sphere[{26.71, -9.3, -6.85}, 111.27], Sphere[{0, 0, 0}, 100.], Sphere[{8.65, 4.28, -3.81}, 103.87]} [... graphic deleted ...] -- Jean-Marc === Subject: Re: Something very simple..... Just use Apply with level specification {1}: Apply[Sphere, sphlst, {1}] {Sphere[{5.11, 0.76, -0.32}, 100.39], Sphere[{7.18, -1.86, -8.19}, 98.02], Sphere[{26.71, -9.3, -6.85}, 111.27], Sphere[{0, 0, 0}, 100.], Sphere[{8.65, 4.28, -3.81}, 103.87]} Andrzej Kozlowski > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray > === Subject: Re: Something very simple..... Hi Steve, > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. > Sphere @@@ sphlst > 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). lsta[[ Complement[Range[Length[lsta]], lstb] ]] hope this helps, Oliver Steve Gray Oliver Ruebenkoenig, === Subject: Re: Something very simple..... Hi Steve, > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], Sphere[{{ 7.18, > -1.86, -8.19}, 98.02}], Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. Apply[Sphere, sphlst, 1] does the trick. > 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to > elements of lstb, in this case everything from lsta except > elements 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). For this, I'd use lstc = lsta[[#]] & /@ lstb lstd = Complement[lsta, lstc] but there are undoubtedly other ways. Dave. No virus found in this outgoing message. Checked by AVG. 05:38 === Subject: Re: Something very simple..... Hi Steve, 1) you must use Map together with Apply: Map[Sphere@@#&,sphlst] 2) here we the complement of the indices and then use Part: lsta[[ Complement[Range[Length[lsta]],lstb]] ] hope this helps, Daniel > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray > === Subject: Re: conversion of sin to cos you may simply replace all Sin[x] -> Cos[x-Pi/2] hope this helps, Daniel > Hello all, Here is my problem. I have a very long product of cosines with > arguments of the form k*Pi, k being integers. > I want to convert this expression to a sum of cosines. TrigReduce > works fine, except that it converts cos to sin. > So, I want all the sin (after the TrigReduce) to be converted to cos > and the arguments be of the form p*Pi, p being rational of course. > It has something to do with Hold or HoldAll, but I don't know the > details. Or perhaps the TrigReduce can be overridden > somehow. > Can someone help? > === Subject: Combinatorica`ShowGraph HeadCenter option In whatever version of Mathematica was current 5 years ago, the following code displayed a directed graph with the arrows located half-way along each edge: < True]; ShowGraph[g, HeadCenter -> 0.5] In Mathematica 6.0.2 (with Combinatorica` instead of DiscreteMath`Combinatorica`, of course), the option HeadCenter seems to be unrecognized, and the arrows remain at their target ends -- in other words, they appear where they are hardest to see! Has this change been documented? There is nothing whatsoever about this in Compatibility/tutorial/DiscreteMath/Combinatorica. Except that this compatibility guide states, All of the functionality in DiscreteMath`Combinatorica` is available in the newly created Combinatorica Package. Plainly that is not the case in so far as HeadCenter is concerned. How can one still locate the arrows on the displayed directed graph -- using ShowGraph (which has been generally much simpler to use, especially for students, in contrast with the newer GraphPlot. -- 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: Combinatorica`ShowGraph HeadCenter option Hi Murray, here is a work around: g=ShowGraph[Cycle[3,Type->Directed]]; g=g/. x:Arrow[__]->{Arrowheads[{{Automatic,0.5}}],x} hope this helps, Daniel > In whatever version of Mathematica was current 5 years ago, the > following code displayed a directed graph with the arrows located > half-way along each edge: < g = SetGraphOptions[Cykcle[3], EdgeDirection -> True]; > ShowGraph[g, HeadCenter -> 0.5] In Mathematica 6.0.2 (with Combinatorica` instead of > DiscreteMath`Combinatorica`, of course), the option HeadCenter seems to > be unrecognized, and the arrows remain at their target ends -- in other > words, they appear where they are hardest to see! Has this change been documented? There is nothing whatsoever about this > in Compatibility/tutorial/DiscreteMath/Combinatorica. Except that this > compatibility guide states, All of the functionality in > DiscreteMath`Combinatorica` is available in the newly created > Combinatorica Package. Plainly that is not the case in so far as > HeadCenter is concerned. How can one still locate the arrows on the displayed directed graph -- > using ShowGraph (which has been generally much simpler to use, > especially for students, in contrast with the newer GraphPlot. > === Subject: Symbolic Quantum Operators for Dirac Notation in Mathematica About Quantum for Mathematica ( http://homepage.cem.itesm.mx/lgomez/quantum/index.htm ) Now you can define Symbolic Quantum Operators for Dirac Notation in Mathematica, please see this link: http://homepage.cem.itesm.mx/lgomez/quantum/defope/defope.html Before this improvement operators could be defined only through the explicit Dirac representation of their =93matrix elements=94 ket-on-bra. Now operators can be defined trough their operation on a ket. For example, rising (creation) and lowering (annihilation) operators of the harmonic oscillator are easily defined and used at the end of the document in this link http://homepage.cem.itesm.mx/lgomez/quantum/defope/defope.html Now the Quantum Random Walk is solved in the documentation by three different methods, which have different advantages and disadvantages. The last of these three methods uses the new feature of definition of symbolic quantum operators: FIRST: Q. Random Walker: Dirac Notation Approach: beautiful but slow: http://homepage.cem.itesm.mx/lgomez/quantum/qrwnaive/qrwnaive.html SECOND: Q. Random Waker: Mathematica Syntax Approach: Fastest but too specialized: http://homepage.cem.itesm.mx/lgomez/quantum/qrwefficient/qrwefficient.html THIRD: Q. Random Walker: Defining-operators approach: beautiful enough and fast enough, a good compromise: http://homepage.cem.itesm.mx/lgomez/quantum/qrwbest/qrwbest.html A colleague, Rub=E9n Dario, is already implementing new exciting Quantum Mechanics calculations (molecular collisions) using these new features. To have the new features, you must download the new Quantum.zip http://homepage.cem.itesm.mx/lgomez/quantum/Quantum.zip and install this new version according to the instructions in http://homepage.cem.itesm.mx/lgomez/quantum/installation/installation.html Enjoy it! Jose Luis Gomez-Munoz http://homepage.cem.itesm.mx/lgomez/ === Subject: Graphics3D, missing part I am trying to use Mathematica 5.1 to make a fractal tree. I get no problem for Show[G1,G2,G3], but when I do Show[G, G1, G2, G3], the problem part of the graph is missing. Have I done something wrong? Any help is much appreciated. wshun coneF = Function[{x, y, z, r, h, t}, {{x + 0.6h*Cos[t], y + 0.6h*Sin[t], z + 0.6h, 0.4r, 0.4h, t}, {x + 0.6h*Cos[t], y + 0.6h*Sin[t], z + 0.6h, 0.4r, 0.6h, Mod[t + 2Pi/3, 2Pi]}, {x + 0.6h*Cos[t], y + 0.6h*Sin[t], z + 0.6h, 0.4r, 0.6h, Mod[t + 4Pi/3, 2Pi]}}] coneG = Function[A, Flatten[Table[coneF[ Extract[A, {k, 1}], Extract[A, {k, 2}], Extract[A, {k, 3}], Extract[A, {k, 4}], Extract[A, {k, 5}], Extract[A, {k, 6}]], {k, Length[A]}], 1]] DrawCone = Function[A, Table[ParametricPlot3D[{Extract[A, {k, 1}], Extract[A, {k, 2}], Extract[A, {k, 3}]} + Extract[A, {k, 4}]*(1 - h/ Extract[A, {k, 5}])*{Cos[t], Sin[t], 0} + h*{Cos[Extract[A, {k, 6}]], Sin[Extract[A, {k, 6}]], 1}, {h, 0, Extract[A, {k, 5}]}, {t, 0, 2Pi}], {k, Length[A]}]] A = {{0, 0, 0, 1, 6, 0}}; A1 = coneG[A]; A2 = coneG[A1]; A3 = coneG[A2]; G = DrawCone[A]; G1 = DrawCone[A1]; G2 = DrawCone[A2]; G3 = DrawCone[A3] Show[G, G1, G2, G3] === Subject: Re: Graphics3D, missing part > I am trying to use Mathematica 5.1 to make a fractal tree. I get no > problem for Show[G1,G2,G3], but when I do Show[G, G1, G2, G3], the > problem part of the graph is missing. Have I done something wrong? Note sure what you get with 5.1, but on my system (6.0.2 Mac OS X Intel) both commands display only a partial graph. Setting the option PlotRange to All allows Mathematica to draw both plots completely. Show[G1, G2, G3, PlotRange -> All] Show[G, G1, G2, G3, PlotRange -> All] You can see the differences at http://homepages.nyu.edu/~jmg336/mathematica/graphics3dmissingpart.jpg HTH, -- Jean-Marc $Version 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) coneF = Function[{x, y, z, r, h, t}, {{x + 0.6 h*Cos[t], y + 0.6 h*Sin[t], z + 0.6 h, 0.4 r, 0.4 h, t}, {x + 0.6 h*Cos[t], y + 0.6 h*Sin[t], z + 0.6 h, 0.4 r, 0.6 h, Mod[t + 2 Pi/3, 2 Pi]}, {x + 0.6 h*Cos[t], y + 0.6 h*Sin[t], z + 0.6 h, 0.4 r, 0.6 h, Mod[t + 4 Pi/3, 2 Pi]}}] coneG = Function[A, Flatten[Table[ coneF[Extract[A, {k, 1}], Extract[A, {k, 2}], Extract[A, {k, 3}], Extract[A, {k, 4}], Extract[A, {k, 5}], Extract[A, {k, 6}]], {k, Length[A]}], 1]] DrawCone = Function[A, Table[ParametricPlot3D[{Extract[A, {k, 1}], Extract[A, {k, 2}], Extract[A, {k, 3}]} + Extract[A, {k, 4}]*(1 - h/Extract[A, {k, 5}])*{Cos[t], Sin[t], 0} + h*{Cos[Extract[A, {k, 6}]], Sin[Extract[A, {k, 6}]], 1}, {h, 0, Extract[A, {k, 5}]}, {t, 0, 2 Pi}], {k, Length[A]}]] A = {{0, 0, 0, 1, 6, 0}}; A1 = coneG[A]; A2 = coneG[A1]; A3 = coneG[A2]; G = DrawCone[A]; G1 = DrawCone[A1]; G2 = DrawCone[A2]; G3 = DrawCone[A3] Show[G, G1, G2, G3] Show[G, G1, G2, G3, PlotRange -> All] Show[G1, G2, G3] Show[G1, G2, G3, PlotRange -> All] === Subject: Re: Graphics3D, missing part Show[G, G1, G2, G3, PlotRange -> All] ?? Jens > I am trying to use Mathematica 5.1 to make a fractal tree. I get no > problem for Show[G1,G2,G3], but when I do Show[G, G1, G2, G3], the > problem part of the graph is missing. Have I done something wrong? Any help is much appreciated. wshun coneF = Function[{x, y, z, r, h, t}, {{x + 0.6h*Cos[t], y + > 0.6h*Sin[t], z + 0.6h, 0.4r, 0.4h, t}, {x + 0.6h*Cos[t], y + > 0.6h*Sin[t], z + 0.6h, 0.4r, 0.6h, Mod[t + 2Pi/3, 2Pi]}, {x + > 0.6h*Cos[t], y + 0.6h*Sin[t], z + 0.6h, 0.4r, 0.6h, Mod[t + 4Pi/3, > 2Pi]}}] coneG = Function[A, Flatten[Table[coneF[ Extract[A, {k, 1}], > Extract[A, {k, 2}], Extract[A, {k, 3}], Extract[A, {k, 4}], > Extract[A, {k, 5}], Extract[A, {k, 6}]], {k, Length[A]}], 1]] DrawCone = Function[A, Table[ParametricPlot3D[{Extract[A, {k, 1}], > Extract[A, {k, 2}], Extract[A, {k, 3}]} + Extract[A, {k, 4}]*(1 - h/ > Extract[A, {k, 5}])*{Cos[t], Sin[t], 0} + h*{Cos[Extract[A, {k, 6}]], > Sin[Extract[A, {k, 6}]], 1}, {h, 0, Extract[A, {k, 5}]}, {t, 0, 2Pi}], > {k, Length[A]}]] A = {{0, 0, 0, 1, 6, 0}}; A1 = coneG[A]; A2 = coneG[A1]; A3 = > coneG[A2]; G = DrawCone[A]; G1 = DrawCone[A1]; G2 = DrawCone[A2]; G3 = > DrawCone[A3] Show[G, G1, G2, G3] > === Subject: Re: Graphics3D, missing part wshun On Apr 1, 6:39 pm, Jens-Peer Kuska Show[G, G1, G2, G3, PlotRange -> All] ?? Jens > === Subject: Re: Problems with differentiating Piecewise functions >> If I set up a piecewise function and differentiate it: >> In[112]:= pw1 = Piecewise[{{x^2, x <= 0}, {x, x > 0}}] >> Out[112]= [Piecewise] { >> {x^2, x <= 0}, >> {x, x > 0} >> } >> In[113]:= pw1 /. x -> 0 >> Out[113]= 0 >> In[114]:= pw1d = D[pw1, x] >> Out[114]= [Piecewise] { >> {2 x, x < 0}, >> {1, x > 0}, >> {Indeterminate, !(* >> TagBox[True, >> PiecewiseDefault, >> AutoDelete->False, >> DeletionWarning->True])} >> } >> In[115]:= pw1d /. x -> 0 >> Out[115]= Indeterminate >> Then at the joins between the pieces I get Indeterminate values, >> because the limit x <= 0 has become x < 0 after differentiation. >> Does >> anyone know a solution to this problem? >> Howard. > What do you mean by a solution to this problem? You have a > function that is not differentiable at 0 and you would like it's > derivative to have a value there? You can't expect a solution to a > problem when you do not tell us what is the problem (except the > fact > that not all functions are differentiable - but that's life). > Note that is your pieceise function is actually differentiable than > the derivative is defined everywhere: > pw2 = Piecewise[{{x^2, x <= 0}, {x^3, x > 0}}]; > pw2d = D[pw2, x] > Piecewise[{{2*x, x < 0}, {0, x == 0}}, 3*x^2] > This is also as it should be. What else would you expect? > Andrzej Kozlowski >> example that I posted (I simplified my problem by cutting and pasting >> an example from the help file to keep the post short). I am actually >> fitting cubic splines and the functions are continuous up to the >> second derivative (at least to the accuracy of machine precision). A >> better example is: >> In[54]:= pw[x_] := >> Piecewise[{{0.+ 0.007508378277320685 x + 7.561460342471517*10^-7 x^3, >> x < 50}, {-4.8729206849430454*10^-6 (-125.76959597633721 + >> x) (1148.1044516606876- 47.50636365246156 x + x^2), 50 <= x}}] >> In[55]:= pw[x] >> Out[55]= [Piecewise] { >> {0.+ 0.00750838 x + 7.56146*10^-7 x^3, x < 50}, >> {-4.87292*10^-6 (-125.77 + x) (1148.1- 47.5064 x + x^2), 50 <= x} >> } >> In[56]:= pw[50] >> Out[56]= 0.469937 >> In[57]:= pw[50 + 10^-30] >> Out[57]= 0.469937 >> In[58]:= pw[50 - 10^-30] >> Out[58]= 0.469937 >> In[60]:= pw'[x] >> Out[60]= [Piecewise] { >> {0.00750838+ 2.26844*10^-6 x^2, x < 50}, >> {-4.87292*10^-6 (-125.77 + x) (-47.5064 + 2 x) - >> 4.87292*10^-6 (1148.1- 47.5064 x + x^2), x > 50}, >> {Indeterminate, !(* >> TagBox[True, >> PiecewiseDefault, >> AutoDelete->False, >> DeletionWarning->True])} >> } >> In[61]:= pw'[50] >> Out[61]= Indeterminate >> In[62]:= pw'[50 + 10^-30] >> Out[62]= 0.0131795 >> In[63]:= pw'[50 - 10^-30] >> Out[63]= 0.0131795 >> Also if you Plot pw or pw' you get an annoying gap in the plot at the >> join (but strangely not pw''). My guess is that Mathematica is too >> pedantic about machine precision and is treating each piece as an >> algebraic equation. However this does not explain why Plot behaves >> funnily and doesn't help if you are trying to do numerical analysis. > You are violating one of the most fundamental principles of computer > algebra: do not mix approximate numbers with symbolic computation. > More correctly, such mixing requires a great deal of care and > symbolic algebraic techniques that can deal with approximate numbers > (and even more so with machine precision input) are still in their > infancy. (In fact Mathematica is one of the few systems that make it > to some extent possible). In your case the symbolic technique you > are using is differentiation of a piecewise function, and this > cannot be reliably combined with numerical precision input. > The answer to your problem is simple. Switch from using a mixture of > symbolic methods and approximate input to a purely numeric setting. > The best way to do this, I think, is by using FunctionInterpolation. > So what you need to do is this: > pw[x_] := > Piecewise[{{0. + 0.007508378277320685 x + 7.561460342471517*10^-7 x^3, > x < 50}, {-4.8729206849430454*10^-6 (-125.76959597633721 + > x) (1148.1044516606876 - 47.50636365246156 x + x^2), 50 <= x}}] > f = FunctionInterpolation[pw[x], {x, 0, 80}]; > Plot[f[x], {x, 40, 60}] > shows a continuous curve > Plot[f'[x], {x, 40, 60}] > shows an almost smooth curve, with a slight kink at the break > point. One could probably play with the options to > FunctionInterpolation to smoothen it. > Andrzej Kozlowski Actually, you can get a smooth looking derivative by using a higher > interpolation order: f = FunctionInterpolation[pw[x], {x, 0, 80}, InterpolationOrder -> 10]; Plot[f'[x], {x, 40, 60}] looks very smooth and so does: Plot[f''[x], {x, 40, 60}] Andrzej Kozlowski FunctionInterpolation but I actually wanted to plot my splines not an approximation to them. I guess I am asking too much since Piecewise takes algebraic expressions, unlike FunctionInterpolation, and therefore must evaluate symbolically. === Subject: how change color of directed edges for GraphPlot I have a directed graph to display using GraphPlot: a=RotateVertices[EmptyGraph[4],-([Pi]/4)]; a=SetGraphOptions[a,EdgeDirection->True]; a=AddEdges[a,{{1,2},{2,3},{2,4},{3,1},{4,1},{4,3}}]; I want to display it using GraphPlot... GraphPlot[a, Method -> None, DirectedEdges -> True, VertexRenderingFunction -> ({Black, Disk[#1, 0.02]} &)] ... but I want the edges and the arrows to be Black and not the default brown. How can one do this WITHOUT having to completely rewrite what the default EdgeRenderingFunction->Automatic option does; that is, I still want the arrows with their heads in the default position (it looks something like 2/3 the way along each arrow). -- 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: changing style of vertices for ShowGraph But I want to reproduce with GraphPlot some of the old behavior of DiscreteMath`Combinatorica`ShowGraph (since some other of its behavior seems to have disappeared in Mathematica 6). Namely, to show the vertex labels not AT the vertices but rather near the vertices, so that I can still use solid disks for the vertices. If I do something like this... GraphPlot[Cycle[3],Method->Automatic, VertexLabeling->True, VertexRenderingFunction->({Black,Disk[#1,0.02],Black,Text[#2,#1]}&)] ... then I get the disks but no labels, because evidently one of the arguments of Text[#2,#1] -- which one?? (this doesn't seem to be documented?) -- is giving the location to be AT the vertices. With some experimentation, I discover that it's argument #1 that gives the coordinates of the vertex, so I can use something like: GraphPlot[Cycle[3],Method->Automatic, VertexLabeling->True, VertexRenderingFunction-> ({Black,Disk[#1,0.02],Black,Text[#2,#1+{0.05,0.05}]}&)] But this is SO much work for something that was SO simple with ShowGraph! > Setting the option VertexLabeling->True has no effect when a custom > definition is provided for VertexRenderingFunction, as VertexLabeling > only affects how the default rendering function draws the vertices. > If you want vertex labels provided you need to include that in the > definition of the custom rendering function. Look up the documentation for VertexRenderingFunction and > EdgeRenderingFunction to see what additional arguments are provided. > The first argument for VertexRenderingFunction is the position of the > vertex. The second argument is the label. So the following works: GraphPlot[Cycle[3], Method -> Automatic, VertexLabeling -> True, > EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} &), > VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}], > Yellow, > Disk[#1, 0.04], Black, Text[#2, #1]} &)] You can drop the option settings for VertexLabeling and EdgeLabeling > and get the same effect. As for whether GraphPlot plays well with the Combinatorica graph > structure, it does handle vertex labels correctly but not edge labels, > as the following example illustrates. I was personally surprised to > find that the edge labels were not passed to EdgeRenderingFunction. I > think this might be a bug. GraphPlot[ > Graph[{{{1, 2}, EdgeLabel -> e1}, {{2, 3}, EdgeLabel -> e2}, > {{3, 1}, > EdgeLabel -> e3}}, > {{{-0.5, 0.866}, VertexLabel -> a}, > {{-0.5, -0.866}, VertexLabel -> b}, > {{1., 0}, VertexLabel -> c}}], > EdgeRenderingFunction -> ({Black, Line[#1], > Text[#3, Mean[#1]] > } &), > VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}], > Yellow, > Disk[#1, 0.04], Black, Text[#2, #1]} &)] > Jason >> Yes, GraphPlot seems to permit making nice vertices (or edges), but >> then >> the labeling -- either with a Graph object from Combinatorica or just >> the kind of graph described by the GraphPlot reference page -- does >> not >> seem to admit vertex labels or edge labels, at least so far as I can >> see. For example, neither of the following displays either vertex >> labels or edge labels: >> GraphPlot[Cycle[3], Method -> Automatic, VertexLabeling -> True, >> EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} &), >> VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}], >> Yellow, Disk[#1, 0.04]} &)] >> GraphPlot[{{v1 -> v2, a}, {v2 -> v3, b}, {v3 -> v1, c}}, >> Method -> Automatic, VertexLabeling -> True, EdgeLabeling -> True, >> EdgeRenderingFunction -> ({Black, Line[#1]} &), >> VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}], >> Yellow, Disk[#1, 0.04]} &)] >> On the other hand, if I remove he VertexRenderingFunction option, I do >> see vertex labels on the default (yellow boxes) vertex shapes: >> GraphPlot[{v1 -> v2, a}, {v2 -> v3, b}, {v3 -> v1, c}}, >> Method -> Automatic, VertexLabeling -> True, >> EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} >> &)] >> GraphPlot[Cycle[3], Method -> Automatic, VertexLabeling -> True, >> EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} &)] >> Of course this now defeats the purpose of using GraphPlot so as to get >> exactly the kind of vertex shapes that VertexRenderingFunction, above, >> provides. >> Similarly with EdgeRenderingFunction. >> The kernel function GraphPlot doesn't seem to mesh very well with >> Combinatorica's graph functions. This all still seems only half- >> baked. > Take a look at GraphPlot, the graph rendering function that is built > into the Mathematica kernel. I switched from using ShowGraph to > GraphPlot after realising that it was (a) faster and (b) easier to > customise. Here's what you want: >> GraphPlot[ > Cycle[3], > Method -> None, > EdgeRenderingFunction -> ({Black, Line[#1]} &), > VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}], > Yellow, > Disk[#1, 0.04]} &) > ] >> You need to specify Method->None, otherwise GraphPlot will override > the > specified positions of the vertices in the graph and use its own > default > vertex positioning algorithm. >> VertexRenderingFunction is what you need to define in order to > customise > the appearance of the vertices. >> I provided a definition of EdgeRenderingFunction just so that the > edges > are rendered in the same way as ShowGraph. >>> Jason >> -- > J. McKenzie Alexander > Department of Philosophy, Logic and Scientific Method > London School of Economics and Political Science > Houghton Street, London WC2A 2AE >>> With Mathematica 6, I can change the default style (medium black >> disk) >> for rendering the vertices of a Combinatorica Graph like this: >> Needs[Combinatorica`] >> g = Cycle[3]; >> ShowGraph[g, VertexStyle -> Disk[Large], VertexColor -> Red] >> But how can I, for example, change the vertex style so it is, say, a >> large yellow disk with a thick red boundary? Or even just change >> it to >> be a circle? I tried obvious things like the following, but they >> cause errors: >> ShowGraph[g, VertexStyle -> Graphics[Circle[], ImageSize -> 20]] >> -- >> 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 >>>> Please access the attached hyperlink for an important electronic > communications disclaimer: > http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm > -- >> 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 -- > Dr J. McKenzie Alexander > Department of Philosophy, Logic and Scientific Method > London School of Economics and Political Science > Houghton Street, London WC2A 2AE > Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm > -- 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: Something very simple..... Steve, Try, Sphere@@#&/@sphlst and, Complement[lsta,lsta[[lstb]]] maarten Steve Gray unner.com> cc: === Subject: Something very simple..... 01/04/2008 10:19 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, {{ 7.18, -1.86, -8.19}, 98.02}, {{26.71, -9.30, -6.85}, 111.27}, {{ 0, 0, 0}, 100.00}, {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], Sphere[{{26.71, -9.30, -6.85}, 111.27}], Sphere[{{ 0, 0, 0}, 100.00}], Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. What simple thing am I missing to remove the extra braces? (I know I can use Table but isn't there a one-step method?) Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. I want the elements of lsta that do NOT correspond to elements of lstb, in this case everything from lsta except elements 1,3, and 4: result={b,e,f}. (lstb won't have entries larger than Length[lsta]). Steve Gray === Subject: Defining a Play[] function for Drawbar Organ Emulation Although I have no problem PLOTing such a function as this, I cannot get it to work with the Play[] function. Can anyone help? This is based on the 11-drawbar organ stops used on some hammond organs (such as the X-66 model) which I am trying to emulate for additive synthesis output in a future Demonstration Project (I am using Mathematica 6). ElevenDrawbars[f_, d_String] := Module[{d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, h10, d11, h11, z}, d = StringTake[d, {1}] <> StringTake[d, {2}] <> StringTake[d, {4}] <> StringTake[d, {5}] <> StringTake[d, {6}] <> StringTake[d, {7}] <> StringTake[d, {9}] <> StringTake[d, {10}] <> StringTake[d, {11}] <> StringTake[d, {13}] <> StringTake[d, {14}]; d1 = ToExpression[StringTake[d, {1}]]; d2 = ToExpression[StringTake[d, {2}]]; d3 = ToExpression[StringTake[d, {3}]]; d4 = ToExpression[StringTake[d, {4}]]; d5 = ToExpression[StringTake[d, {5}]]; d6 = ToExpression[StringTake[d, {6}]]; d7 = ToExpression[StringTake[d, {7}]]; d8 = ToExpression[StringTake[d, {8}]]; d9 = ToExpression[StringTake[d, {9}]]; d10 = ToExpression[StringTake[d, {10}]]; h10 = d11/2; d11 = ToExpression[StringTake[d, {11}]]; h11 = d11/2; z = N[2 Pi]; Play[d1 Sin[1/2 f x z] + d2 Sin[3/2 f x z] + d3 Sin[f x z] + d4 Sin[2 f x z] + d5 Sin[3 f x z] + d6 Sin[4 f x z] + d7 Sin[5 f x z] + d8 Sin[6 f x z] + d9 Sin[8 f x z] + d10 Sin[7 f x z] + h10 Sin[9 f x z] + d11 Sin[10 f x z] + h11 Sin[12 f x z], {x, 0, z}, SampleDepth -> 16, SampleRate -> 44100]] I get the following error statements: In[30]:= ElevenDrawbars[440, 00 8845 041 00] During evaluation of In[30]:= Set::setraw: Cannot assign to raw object 00 8845 041 00. >> During evaluation of In[30]:= Sound::ssnm: A good PlayRange could not be found since most of the samples are not evaluating to machine-size real numbers. >> Out[30]= Sound[SampledSoundFunction[!(* TagBox[ RowBox[{CompiledFunction, [, RowBox[{ RowBox[{{, Play`Time7, }}], ,, RowBox[{Block, [, RowBox[{ RowBox[{{, RowBox[{x, =, RowBox[{0.`, , +, RowBox[{0.000022675736961451248`, , Play`Time7}]}]}], }}], ,, RowBox[{ RowBox[{(, RowBox[{ RowBox[{(, RowBox[{ RowBox[{d1$2049, , RowBox[{Sin, [, FractionBox[ RowBox[{440, , x, , z$2049}], 2], ]}]}], +, RowBox[{d2$2049, , RowBox[{Sin, [, FractionBox[ RowBox[{3, , 440, , x, , z$2049}], 2], ]}]}], +, RowBox[{d3$2049, , RowBox[{Sin, [, RowBox[{440, , x, , z$2049}], ]}]}], +, RowBox[{d4$2049, , RowBox[{Sin, [, RowBox[{2, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d5$2049, , RowBox[{Sin, [, RowBox[{3, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d6$2049, , RowBox[{Sin, [, RowBox[{4, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d7$2049, , RowBox[{Sin, [, RowBox[{5, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d8$2049, , RowBox[{Sin, [, RowBox[{6, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d9$2049, , RowBox[{Sin, [, RowBox[{8, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d10$2049, , RowBox[{Sin, [, RowBox[{7, , 440, , x, , z$2049}], ]}]}], +, RowBox[{h10$2049, , RowBox[{Sin, [, RowBox[{9, , 440, , x, , z$2049}], ]}]}], +, RowBox[{d11$2049, , RowBox[{Sin, [, RowBox[{10, , 440, , x, , z$2049}], ]}]}], +, RowBox[{h11$2049, , RowBox[{Sin, [, RowBox[{12, , 440, , x, , z$2049}], ]}]}]}], )}], +, 0.`}], )}], , 1.`}]}], ]}], ,, <-CompiledCode->}], ]}], False, Editable->False]), 277088, {44100, 16}]] Can ANYONE help correct my ElevenDrawbars function to avoid this problem? Benjamin Tubb brtubb@pdmusic.org === Subject: Mixed Numerical Derivatives How can I come up with the Hessian of a function, at a particular point, which can only be evaluated numerically? If I had a symbolic function, I could do something like In[123]:= D[x^3 + z*y^-1 + z^(1/2), {{x, y, z}, 2}] /. {x -> 3, y -> 5, z -> 12} Out[123]= {{18, 0, 0}, {0, 24/ 125, -1/25}, {0, -1/25, -1/(96 Sqrt[3])}} The function I'm interested in, though, can only be calculated numerically. Using ND, I can find the diagonal elements of the Hessian: In[92]:= rules = Last[ FindMaximum[{Total[logPr[vdt, ddt, var, #] & /@ testData], ddt > 0, var > 0}, {{vdt, .9}, {ddt, 120}, {var, 90}}]] Out[92]= {vdt -> 0.95945, ddt -> 151.097, var -> 103.255} In[111]:= Needs[NumericalCalculus`] In[124]:= ND[ Total[logPr[vdtp, ddt, var, #] & /@ testData] /. rules, {vdtp, 2}, Evaluate[vdt /. rules]] Out[124]= -64.4011 But what about the off diagonal elements? === Subject: Obscure limitation of shorthand f' notation for Derivative The shorthand f' notation for Derivative: f'''' >> Derivative[4][f] Equivalently, ToExpression[f <> Table[', {4}]] >> Derivative[4][f] Now, Derivative can represent derivatives of high order: Derivative[32768][f] >> Derivative[32768][f] But, ToExpression[f <> Table[', {32767}]] >> Derivative[32767][f] ToExpression[f <> Table[', {32768}]] >> Derivative[-32768][f] Evidently a short int is overflowing somewhere. === Subject: PysankyEasterEggsP.nbp $Aborted Michael Trott's PysankyEasterEggsP.nbp downloaded from www.mathematicaguidebooks.org shows $Aborted when loaded into Mathematica. No hint was given as to why. Using SetOptions[Dynamic,SynchronousUpdating->False] as suggested in tutorial/IntroductionToDynamic if you have something slow in a Dynamic did not help. The Dynamic Timeout note of 21-Nov-2007 in this newsgroup the explained how to set DynamicEvaluationTimeout whereas the online documentation did not. AbsoluteOptions[$FrontEnd,DynamicEvaluationTimeout] reports {DynamicEvaluationTimeout->6.} Using SetOptions[$FrontEnd,DynamicEvaluationTimeout->60] (a 60 second timeout) allowed the demo to load properly. Note that the FrontEnd's init.m file stores this value so the value will remain even after restarting Mathematica. It would have been very helpful if a message had been issued stating that a timeout had occurred and what to do about it. DynamicEvaluationTimeout can also be set by choosing the Edit menu's Preferences... dialog and clicking the [Open Option Inspector] button under the |Advanced| tab. Expand [+] Cell Options and click on Evaluation Options. DynamicEvaluationTimeout appears near the bottom. Click on the value and enter 60 to make the same change shown above. Click on the X on the left to remove the setting and restore the default. Note that this is all done with Show option values at the top of the dialog set to [Global Preferences]. It is also possible to select just that cell or PysankyEasterEggsP.nbp so that the DynamicEvaluationTimeout setting only applies there. To do that: 1) Disable Dynamic Updating Enabled in the Evaluation menu. 2) Load PysankyEasterEggsP.nbp, select the cell. 3) Choose the Format menu's Options Inspector... 4) Set DynamicEvaluationTimeout to 60 as stated above. 5) Enable Dynamic Updating Enabled in the Evaluation menu. It does not seem not possible to re-evaluate the cell once it has displayed $Aborted. Q.E.D. === Subject: Write documentation for 6.0 under Solaris There seems to be very little documentation about how to write documentation for 6.0. I found this http://homepage.cem.itesm.mx/lgomez/createMathematica6AddOn/createMathematic a6AddOn.html but it did not seem to work for me. I found something quite recently added to the Wolfram site recently which was an example added in the last month or so I think. It had a link to an alpha version of Workbench 1.2, but the link did not work. But that was only for Windows/Mac. Are there any plans to make it possible to write documentation if one uses Solaris - or for that matter, HP-UX or similar? I thought Mathematica was supposed to be multi-platform, but some of the add-on packages and workbench do not support all platforms. I would think the ability to write documentation needs to be in the front end and mutli-platform and should not need other packages such as workbench which only run on a subset of platforms. === Subject: Re: Problem with FourierParameters Am 1. Apr 2008 um 00:55 schrieb Devendra Kapadia: >I get a wrong result using FourierParameters: FourierTransform[f, x, w] > InverseFourierTransform[%, w, x] gives 1/2 Sqrt[[Pi]/2] (Sign[1 - w] + Sign[1 + w]) > Sin[x]/x which is what I expected. But with the setting of FourierParameters: FourierTransform[f, x, w, FourierParameters -> {1, -1}] > InverseFourierTransform[%, w, x, FourierParameters -> {1, -1}] gives 1/2 [Pi] Sign[1 - w] + 1/2 [Pi] Sign[1 + w] <--- This is OK > 0 <--- Bug? Other functions e.g. f=1/(1+x^2) transform correctly in both cases. Gruss Peter > >> Hello Peter, >> >> The answer given by InverseFourierTransform for your example with >> FourierParameters -> {1, -1} is indeed incorrect. >> >> We use symbolic integration for computing the inverse transform >> in both the cases given above. The incorrect answer appears to >> be caused by the fact that the output from FourierTransform in >> the second case is not in factored form. Hence, a partial >> workaround for the problem is to use Factor in the call >> to InverseFourierTransform, as shown below: >> >> >> In[2]:= FourierTransform[Sin[x]/x, x, w, FourierParameters -> {1, -1}] >> Pi Sign[1 - w] Pi Sign[1 + w] >> Out[2]= -------------- + -------------- >> 2 2 >> >> In[3]:= InverseFourierTransform[Factor[%], w, x, >> FourierParameters -> {1, -1}] >> Sin[x] >> Out[3]= ------ >> x >> >> >> caused by it. >> >> >> Devendra Kapadia, >> Wolfram Research, Inc. > I experimented a bit with different FourierParameters and it seems that the > wrong answer always comes up, if the first parameter (a) ist not 0. Can you > confirm this? Sincerly, Peter Breitfeld > -- > ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== > Peter Breitfeld | http://www.pBreitfeld.de > Kreuzgasse 4, 88348 Bad Saulgau | PGP/GPG Key gibt's hier Yes, the problem is also seen with other numerical values of 'a' in FourierParameters -> {a,b}, but the example seems to work fine if we allow 'a' to remain symbolic as shown below: In[2]:= FourierTransform[Sin[x]/x, x, w, FourierParameters -> {a, -1}] -1 + a Pi Sqrt[(2 Pi) ] (Sign[1 - w] + Sign[1 + w]) Out[2]= ------------------------------------------------- 2 In[3]:= Simplify[InverseFourierTransform[%, w, x, FourierParameters -> {a, -1}], Im[a] == 0] Sin[x] Out[3]= ------ x -Devendra === Subject: Re: Problem with FourierParameters Am 1. Apr 2008 um 00:55 schrieb Devendra Kapadia: > I get a wrong result using FourierParameters: >> FourierTransform[f, x, w] >> InverseFourierTransform[%, w, x] >> gives >> 1/2 Sqrt[[Pi]/2] (Sign[1 - w] + Sign[1 + w]) >> Sin[x]/x >> which is what I expected. But with the setting of FourierParameters: >> FourierTransform[f, x, w, FourierParameters -> {1, -1}] >> InverseFourierTransform[%, w, x, FourierParameters -> {1, -1}] >> gives >> 1/2 [Pi] Sign[1 - w] + 1/2 [Pi] Sign[1 + w] <--- This is OK >> 0 <--- Bug? >> Other functions e.g. f=1/(1+x^2) transform correctly in both cases. >> Gruss Peter > Hello Peter, The answer given by InverseFourierTransform for your example with > FourierParameters -> {1, -1} is indeed incorrect. We use symbolic integration for computing the inverse transform > in both the cases given above. The incorrect answer appears to > be caused by the fact that the output from FourierTransform in > the second case is not in factored form. Hence, a partial > workaround for the problem is to use Factor in the call > to InverseFourierTransform, as shown below: > In[2]:= FourierTransform[Sin[x]/x, x, w, FourierParameters -> {1, -1}] Pi Sign[1 - w] Pi Sign[1 + w] > Out[2]= -------------- + -------------- > 2 2 In[3]:= InverseFourierTransform[Factor[%], w, x, > FourierParameters -> {1, -1}] Sin[x] > Out[3]= ------ > x > inconvenience > caused by it. > Devendra Kapadia, > Wolfram Research, Inc. I experimented a bit with different FourierParameters and it seems that the wrong answer always comes up, if the first parameter (a) ist not 0. Can you confirm this? Sincerly, Peter Breitfeld -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld | http://www.pBreitfeld.de Kreuzgasse 4, 88348 Bad Saulgau | PGP/GPG Key gibt's hier === Subject: Re: Problem with FourierParameters Am 1. Apr 2008 um 00:55 schrieb Devendra Kapadia: > I get a wrong result using FourierParameters: >> FourierTransform[f, x, w] > InverseFourierTransform[%, w, x] >> gives >> 1/2 Sqrt[[Pi]/2] (Sign[1 - w] + Sign[1 + w]) > Sin[x]/x >> which is what I expected. But with the setting of FourierParameters: >> FourierTransform[f, x, w, FourierParameters -> {1, -1}] > InverseFourierTransform[%, w, x, FourierParameters -> {1, -1}] >> gives >> 1/2 [Pi] Sign[1 - w] + 1/2 [Pi] Sign[1 + w] <--- This is OK > 0 <--- Bug? >> Other functions e.g. f=1/(1+x^2) transform correctly in both cases. >> Gruss Peter > Hello Peter, >> The answer given by InverseFourierTransform for your example with >> FourierParameters -> {1, -1} is indeed incorrect. >> We use symbolic integration for computing the inverse transform >> in both the cases given above. The incorrect answer appears to >> be caused by the fact that the output from FourierTransform in >> the second case is not in factored form. Hence, a partial >> workaround for the problem is to use Factor in the call >> to InverseFourierTransform, as shown below: >> In[2]:= FourierTransform[Sin[x]/x, x, w, FourierParameters -> {1, -1}] >> Pi Sign[1 - w] Pi Sign[1 + w] >> Out[2]= -------------- + -------------- >> 2 2 >> In[3]:= InverseFourierTransform[Factor[%], w, x, >> FourierParameters -> {1, -1}] >> Sin[x] >> Out[3]= ------ >> x >> inconvenience >> caused by it. >> Devendra Kapadia, >> Wolfram Research, Inc. The real problem comes about that Mathematica does not InverseFourierTransform Sign[1-w] correctly!!! It seams that internally a rule is defined to InverseFourierTransform Sign[1+w]+Sign[1-w] such that one need to factor out the rest before. If instead Mathematica where able to InverseFourierTransform Sign[1-w] no such rules would be necessary at all!!! I'm confused by the idea to implement special rules before the more elementary ones work -- this lead to bugs which appear almost at random. Here two distinct bugs: (I) In[1]=InverseFourierTransform[Sign[w],w,x,FourierParameters->{1,-1}] Out[1]=I/(Pi*x) + DiracDelta[x] - 2*Pi*DiracDelta[x] should be I/(Pi*x) [actually the principal value of it] why the 2*Pi in the last term [otherwise the two DiracDelta would the next bug I show with the standard FourierParameters, it is also present with FourierParameters->{1, -1} but then it is Qobscured by bug(I) (II) In[2]=InverseFourierTransform[Sign[1 - w], w, x] Out[2]=((2*I)*Cos[x] - 2*Sin[x])/(Sqrt[2*Pi]*x) should be ((2*I)*Cos[x] + 2*Sin[x])/(Sqrt[2*Pi]*x) These bugs (I)&(II) where already present in 5.2. They are quite severe as Fourier transforms of this type appear quite often in many applications. Fabian === Subject: Re: Problem with FourierParameters > I get a wrong result using FourierParameters: FourierTransform[f, x, w] > InverseFourierTransform[%, w, x] gives 1/2 Sqrt[[Pi]/2] (Sign[1 - w] + Sign[1 + w]) > Sin[x]/x which is what I expected. But with the setting of FourierParameters: FourierTransform[f, x, w, FourierParameters -> {1, -1}] > InverseFourierTransform[%, w, x, FourierParameters -> {1, -1}] gives 1/2 [Pi] Sign[1 - w] + 1/2 [Pi] Sign[1 + w] <--- This is OK > 0 <--- Bug? Other functions e.g. f=1/(1+x^2) transform correctly in both cases. Gruss Peter > Hello Peter, The answer given by InverseFourierTransform for your example with FourierParameters -> {1, -1} is indeed incorrect. We use symbolic integration for computing the inverse transform in both the cases given above. The incorrect answer appears to be caused by the fact that the output from FourierTransform in the second case is not in factored form. Hence, a partial workaround for the problem is to use Factor in the call to InverseFourierTransform, as shown below: In[2]:= FourierTransform[Sin[x]/x, x, w, FourierParameters -> {1, -1}] Pi Sign[1 - w] Pi Sign[1 + w] Out[2]= -------------- + -------------- 2 2 In[3]:= InverseFourierTransform[Factor[%], w, x, FourierParameters -> {1, -1}] Sin[x] Out[3]= ------ x caused by it. Devendra Kapadia, Wolfram Research, Inc. === Subject: Re: Mathematica notebooks the best method I agree with everything below but to tell the truth I can't see what is supposed to be the point of this entire thread. If one wants to write a research paper using Mathematica and submit it to a print or on-line journal one needs only to convert it to pdf and it should then be acceptable in many cases it would be (assuming of course that the contents are good enough). If one wants in addition to provide people who are able to use Mathematica with live calculations one can put a Mathematica notebook for download on a web page. I can't see why anyone should wish for more or argue against this. The rest seems to me a complete waste of time and effort and some of what I have read I actually found quite funny (comical) though I assume it was meant to be serious. A completely different issue is whether academic institutions should provide their students with the opportunity to discover the (in my opinion) very remarkable possibilities offered by the latest version of Mathematica. That's all that my own response was concerned with. This is a real issue while a discussion of publishing standards is a waste of time. I should like to repeat that I have yet to meet a student who would complain about the lack of a printed manual and I think using that as an argument against Mathematica is a perfect example of the sort of academic attitude I referred to in my first response. Andrzej Kozlowski > djvu vs. pdf: no big deal. Tex vs. Mathematica: BIG deal! With djvu and pdf, it's merely a matter of the final format in which > the > document appears and is disseminated. With (La)TeX and Mathematica, there's a crucial difference in the > entire > authoring process. Among other things: (1) (La)TeX concentrates upon the logical structure of the document, > whereas Mathematica from the start involves the actual appearance of > the > document. (2) Typing math markup is typically quicker in (La)TeX than in > Mathematica, as it avoids Control-key sequences (unless one is using > an > editor where such sequences are used as shortcuts) or at least uses > shorter keystroke-only sequences. (3) Mathematica allows live calculations in the document itself, > whereas TeX does not (except of the most primitive kind). > Exception: a > specialized TeX+CAS system. (4) Mathematica creates graphics of all sorts directly in the > document, whereas with the exception of a limited number of native or > package add-on graphics types, graphics must be imported into a TeX > document from an external source (such as Mathematica)! There are two other another differences: (5) One can have an entire TeX document preparation system -- > editor, > TeX engine plus packages, viewer, and converter (dvi to ps or pdf, > e.g.) > -- for free. Needless to say, Mathematica is not free. (6) The source code for TeX and many or most of the supporting > utilities is open source; this is certainly not the case for > Mathematica. >> ...I would like to point out that publishing standards are not >> set in stone. For several years I have witnessed PDF visibly loosing >> ground to djvu in the mathematical preprint area. I like with many >> other things I learned about it first form students, who quickly >> understood its technical superiority over PDF (most of all, much >> smaller file size). Now I see that a number of on-line mathematics >> journals are offering djvu as an alternative to pdf. -- > Murray Eisenberg murray@math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street fax 413 545-1801 > Amherst, MA 01003-9305 > === Subject: Re: Mathematica notebooks the best method for technical Mathematica notebooks are the best method there is for technical communications This statement is certainly true as it stands. Journals or some universities may not adopt it as a standard for some valid reasons, but notebooks are certainly superior to any type of non-live technical document . I think David Park was thinking more at private technical communications. As long as both parties use mathematica, exchanging notebooks is by far the best way to communicate. As far as journal publication is concerned, probably the best strategy would be: publish using the accpted standards (latex, pdf,ect) but mention in the paper that a notebook with the relevant calculations is available online somewhere. === Subject: Re: Mathematica notebooks the best method for technical On 1 Apr, 09:20, Mariano Su=E1rez-Alvarez > Indeed. I would not be able to describe such an effort > with any other term apart from misguided. Very misguided. > Essentially > proprietary formats cannot possibly be considered as a > the simple fact that Mathematica, say, is absurdly expensive > for most of the world, to rather more complicated issues > (for example, one can never tell when the whimsical ires > of whatever be the superpower of the day, any day, may decide > to forbid selling, say, Mathematica to country X in order > to `fight Y' for whatever value X has at the time---terrorists, > peadophiles, and so on.), to so many other issues... It simply cannot withstand any analysis. -- m The only way I could see this happening is if Wolfram Research released the front end under the GPL or similar. Then it might, but even then it is far from clear it would and I personally doubt it would. === Subject: Re: Mathematica notebooks the best method for technical > Mathematica notebooks are the best method there is for > technical communications Would this were true. It's not. Making Mathematica notebooks become the primary method for both > preparing *and communicating* technical communications (broadly > interpreted to include teaching, writing, presentations, and > publications) in both the academic and professional worlds might be a > laudable goal, and a number of people (David Park very much included) > have put sincere and laudable efforts into trying to make it be the case. Sorry, it's _not_ going to happen. Wolfram is partly to blame for this -- very much including the currently > ongoing version 6 documentation disaster. But there are also very major and fundamental reasons why this goal very > possibly should not happen, or should not be attempted, or simply could > never happen in any case. To focus on just one aspect of this topic (out of many), I would point > out that major professional societies have (since Isaaac Newton's time!) > carried the burden of developing two of the major worldwide channels of > technical and scientific communications, namely scientific and technical > journals (and archives), and scientific and technical meetings And, these societies are struggling to adapt, and in many ways > successfully adapting, today to the Internet, electronic technologies, > open access, and other emerging complexities of information > transmission and communication. It's an expensive and > resource-consuming struggle The primary communication methods or formats for user input of > technical material to essentially all such journals and meetings today > -- user input being of course the primary source for all such material > -- are TeX (or LaTeX), PDF, and (unfortunately, but it's the reality) MS > Word. I've been heavily involved with a couple of these societies, and a close > observer at least, if not a major contributor, to the major and > stressful evolution of professional society publication and meeting > activities and methods in recent years. I've also been a heavy personal > user of Mathematica since I heard Steven Wolfram introduce version 1 to > an overflowing auditorium at my university several decades ago. I can only say that I would be a vehement opponent of any proposal > within these societies to divert resources to an effort to add > Mathematica notebooks to the format list above. [And, given the current situation, I'd be a vehement opponent of any > efforts within my university to spend university resources on making > Mathematica a *preferred* and heavily university-supported computational > and communications technology within my university.] Indeed. I would not be able to describe such an effort with any other term apart from misguided. Essentially proprietary formats cannot possibly be considered as a the simple fact that Mathematica, say, is absurdly expensive for most of the world, to rather more complicated issues (for example, one can never tell when the whimsical ires of whatever be the superpower of the day, any day, may decide to forbid selling, say, Mathematica to country X in order to `fight Y' for whatever value X has at the time---terrorists, peadophiles, and so on.), to so many other issues... It simply cannot withstand any analysis. -- m === Subject: Re: Something very simple..... For the first question, use any one of these: Sphere @@@ sphlst Sphere @@ # & /@ sphlst Apply[Sphere, sphlst, 1] For the second question: lsta = {a, b, c, d, e, f}; lstb = {1, 3, 4}; lsta[[Complement[Range[Length[lsta]], lstb]]] {b,e,f} Assuming that lstb is sorted as shown Fold[Delete[#1, #2] &, lsta, Reverse[lstb]] {b,e,f} Fold[Drop[#1, {#2}] &, lsta, Reverse[lstb]] {b,e,f} Bob Hanlon > 1. I have a list of sphere centers and radii like this: sphlst={{{ 5.11, 0.76, -0.32}, 100.39}, > {{ 7.18, -1.86, -8.19}, 98.02}, > {{26.71, -9.30, -6.85}, 111.27}, > {{ 0, 0, 0}, 100.00}, > {{ 8.65, 4.28, -3.81}, 103.87}}. If I do Map[Sphere,sphlst] I get too many braces, like this: {Sphere[{{ 5.11, 0.76, -0.32}, 100.39}], > Sphere[{{ 7.18, -1.86, -8.19}, 98.02}], > Sphere[{{26.71, -9.30, -6.85}, 111.27}], > Sphere[{{ 0, 0, 0}, 100.00}], > Sphere[{{ 8.65, 4.28, -3.81}, 103.87}]} and Sphere needs for example Sphere[{1.11, 2.22, 3.33},4.5]. > What simple thing am I missing to remove the extra braces? > (I know I can use Table but isn't there a one-step method?) > Flatten doesn't seem to be useful here, or I'm using it wrong. 2. I have two lists, lsta={a,b,c,d,e,f} and lstb={1,3,4}. > I want the elements of lsta that do NOT correspond to elements > of lstb, in this case everything from lsta except elements > 1,3, and 4: result={b,e,f}. > (lstb won't have entries larger than Length[lsta]). > Steve Gray > === Subject: Re: Factorial equations > Who know how is possible with use Mathematica solving equations > involving factorials e.g > Solve[n! + n == 726, n] My difficult problem to solving is > x=n > y=n! find function f(x,y) such > f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, > f[6,6!]=1103, f[7,7!]=5247 > values are generated by procedure > ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; > m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I > will > be greatfull ! > Best wishes > ARTUR In this particular case you can find all the solutions using FindInstance: FindInstance[n! + n == 726 && Element[n, Integers] && n > 0, {n}] {{n -> 6}} and FindInstance[n! + n == 726 && Element[n, Integers] && n > 0 && n != 6, {n}] {} which means that 6 is a solution and there is no other positive integer solution. Now about your probem. First, your procedure does not make sense. Your function f is a function of two variables but it your procedure you have an f[n]. Secondly, the problem as stated is trivial for Mathematica and one does not need any procedures. This will do: f[x_, y_] = Together[InterpolatingPolynomial[{{{1, 1!}, 1}, {{2, 2!}, 2}, {{3, 3!}, 5}, {{4, 4!}, 59}, {{5, 5!}, 246}, {{6, 6!}, 1103}, {{7, 7!}, 5247}}, {x, y}]] (1/141478298898)*(1235040757839*x^3 - 6971716404999*x^2 + 135058984529*y*x + 12699232479546*x - 27342188*y^2 - 692985197547*y - 6263124978282) Now you can check that Apply[f[##1] & , Table[{n, n!}, {n, 1, 6}], {1}] {1, 2, 5, 59, 246, 1103} Andrzej Kozlowski === Subject: Re: Factorial equations Just as Solve will tell you, there IS no algebraic solution to problems like that. We can do pretty well with numerical methods, though: Clear[f] f[s_] := FindRoot[n + Gamma[n + 1] == s, {n, 3}] f[726] {n -> 6.} f[600] {n -> 5.89694} Bobby > Who know how is possible with use Mathematica solving equations > involving factorials e.g > Solve[n! + n == 726, n] My difficult problem to solving is > x=n > y=n! find function f(x,y) such > f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]== 246, > f[6,6!]=1103, f[7,7!]=5247 > values are generated by procedure > ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; > m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I will > be greatfull ! > Best wishes > ARTUR > -- DrMajorBob@longhorns.com === Subject: Re: Factorial equations > Who know how is possible with use Mathematica solving equations > involving factorials e.g > Solve[n! + n == 726, n] My difficult problem to solving is > x=n > y=n! find function f(x,y) such > f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, > f[6,6!]=1103, f[7,7!]=5247 > values are generated by procedure > ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; > m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I will > be greatfull ! > Best wishes > ARTUR > This is all quite confusing. It is not hard to write a solver for equations of the form, say, n+n!==constant. To get an idea of how you might go about it, see (for example) But this will not help with what I believe is your goal, to find a closed form for terms in your sequence A007878 from the OEIS. I've no idea as to whether there is a concise closed form for this sequence. I also do not see why you have a function of two variables, since you only use one. That is, it is not clear why you work with f(n,n!) rather then just f(n). There may be a good reason, but if so you did not show it. Also you left out a term in your sequence: the fourth one is actually 16. As for computing it faster, the time is pretty much all spent in the discriminants. Some trial and error lead me to use the Bezout matrix formulation, as that seems fastest. Note that I also explicitly expand, since there is no guarantee these will be computed in expanded form. Timing[aa = Table[ k = Array[f,s+1,0].x^Range[0,s]; m = Discriminant[k, x, Method->SylvesterMatrix]; Length[Expand[m]], {s,1,8}]] Out[20]= {24.11, {0, 2, 5, 16, 59, 246, 1103, 5247}} The zero for the first term is because the discriminant of f[0] + x*f[1] is 1, and 1, being an atom in Mathematica, has length of zero. This may be related to ome recent questions you posted to the news group. Finally I will say that there might be better/faster ways to compute these discriminants (say, faster determinant code than what Mathematica now has). Daniel Lichtblau Wolfram Research === Subject: Re: Factorial equations >> Who know how is possible with use Mathematica solving equations >> involving factorials e.g >> Solve[n! + n == 726, n] >> My difficult problem to solving is >> x=n >> y=n! >> find function f(x,y) such >> f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, >> f[6,6!]=1103, f[7,7!]=5247 >> values are generated by procedure >> ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; >> m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a >> Who can help in find formula or do above procedure much quickest I >> will >> be greatfull ! >> Best wishes >> ARTUR In this particular case you can find all the solutions using > FindInstance: FindInstance[n! + n == 726 && Element[n, Integers] && n > 0, {n}] > {{n -> 6}} and > FindInstance[n! + n == 726 && Element[n, Integers] && n > 0 && n != > 6, {n}] > {} which means that 6 is a solution and there is no other positive > integer solution. Actually, this can be done more simply by using Reduce: Reduce[n! + n == 726 && Element[n, Integers] && n > 0, {n}] n==6 As for the second half, it now seems to me that by function you probably mean a polynomial with integer coefficients (?), in which case the polynomial below is not a satisfactory answer. However, since I still have no idea what your actual problem is (or why you believe that such a polynomial with integer coefficients exists) I will leave this problem to others. Andrzej Kozlowski > Now about your probem. First, your procedure does not make sense. > Your function f is a function of two variables but it your procedure > you have an f[n]. Secondly, the problem as stated is trivial for > Mathematica and one does not need any procedures. This will do: f[x_, y_] = > Together[InterpolatingPolynomial[{{{1, 1!}, 1}, {{2, 2!}, 2}, {{3, > 3!}, 5}, > {{4, 4!}, 59}, {{5, 5!}, 246}, {{6, 6!}, 1103}, {{7, 7!}, > 5247}}, {x, y}]] > (1/141478298898)*(1235040757839*x^3 - 6971716404999*x^2 + > 135058984529*y*x + 12699232479546*x - 27342188*y^2 - > 692985197547*y - > 6263124978282) Now you can check that Apply[f[##1] & , Table[{n, n!}, {n, 1, 6}], {1}] > {1, 2, 5, 59, 246, 1103} > Andrzej Kozlowski === Subject: Re: Factorial equations As for the first question (solving equations with factorials), Ted Ersek's RootSearch function works wonders: In[11]:= RootSearch[n! + n == 726, {n, 2, 10}] Out[11]= {{n -> 6.}} The package is available here: http://library.wolfram.com/infocenter/MathSource/4482/ Hope that helps a bit! > Who know how is possible with use Mathematica solving equations > involving factorials e.g > Solve[n! + n == 726, n] My difficult problem to solving is > x=n > y=n! find function f(x,y) such > f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, > f[6,6!]=1103, f[7,7!]=5247 > values are generated by procedure > ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; > m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I will > be greatfull ! > Best wishes > ARTUR -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Factorial equations Who know how is possible with use Mathematica solving equations involving factorials e.g Solve[n! + n == 726, n] My difficult problem to solving is x=n y=n! find function f(x,y) such f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, f[6,6!]=1103, f[7,7!]=5247 values are generated by procedure ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I will be greatfull ! Best wishes ARTUR === Subject: Re: Factorial equations > My difficult problem to solving is > x=n > y=n! find function f(x,y) such > f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, > f[6,6!]=1103, f[7,7!]=5247 > values are generated by procedure > ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; > m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I will > be greatfull ! Though I am not sure to have fully grasped what you try to achieve, the following approach for computing the coefficients is about 10 times faster that the expression above (and clearer). Clear[f, g] g[0] = f[0]; g[n_Integer?Positive] := g[n] = g[n - 1] + f[n] x^n myFun[n_Integer?Positive] := Length@Resultant[g[n], D[g[n], x], x, Method -> BezoutMatrix] Table[myFun[n], {n, 1, 8}] {1, 2, 5, 16, 59, 246, 1103, 5247} We use a recursive definition with memoization (i.e. the intermediate results are saved, avoiding to be computed again after their first computation) to compute the polynomials. Also, most of the CPU time is spent computing *Resultant*, so we use the method *BezoutMatrix*, method which seems to be the fastest for this problem. For instance, 1103 (n = 7) is computed in 1.1337 second (vs 4.95693 seconds for the Automatic method) 5247 (n = 8) is computed in 15.8515 second (vs 136.098 seconds for the Automatic method) Below, you will find some timings that show where the CPU spend its time among the different part of the expression and also a speed comparison among the different algorithms available to compute *Resultant*. In[6]:= Clear[f, g] g[0] = f[0]; g[n_Integer?Positive] := g[n] = g[n - 1] + f[n] x^n myFun[n_Integer?Positive] := Length@Resultant[g[n], D[g[n], x], x] Table[{g[n] // Timing // First, D[g[n], x] // Timing // First, Resultant[g[n], D[g[n], x], x] // Timing // First, myFun[n] // Timing}, {n, 1, 8}] Out[10]= {{0.000037, 0.000016, 0.000045, {0.00003, 1}}, {0.000021, 0.00001, 0.000199, {0.000169, 2}}, {0.000024, 0.000012, 0.000666, {0.000644, 5}}, {0.000025, 0.000012, 0.003941, {0.003926, 16}}, {0.000033, 0.000016, 0.037161, {0.036293, 59}}, {0.000044, 0.000022, 0.309441, {0.318596, 246}}, {0.000051, 0.000026, 4.89827, {4.95693, 1103}}, {0.000053, 0.000029, 122.954, {136.098, 5247}}} In[11]:= Table[ Timing[Length@ Resultant[g[n], D[g[n], x], x, Method -> #]] & /@ {Automatic, Modular , Subresultants, BezoutMatrix, SylvesterMatrix}, {n, 1, 5}] Out[11]= {{{0.000072, 1}, {0.000029, 1}, {0.000027, 1}, {0.000026, 1}, {0.000026, 1}}, {{0.000186, 2}, {0.005394, 2}, {0.000147, 2}, {0.000523, 2}, {0.00017, 2}}, {{0.000655, 5}, {0.009401, 5}, {0.000249, 5}, {0.001269, 5}, {0.000657, 5}}, {{0.004164, 16}, {0.375798, 16}, {0.000979, 16}, {0.003623, 16}, {0.003861, 16}}, {{0.039217, 59}, {17.702, 59}, {0.020984, 59}, {0.016298, 59}, {0.038365, 59}}} In[12]:= Table[ Timing@Length@ Resultant[g[n], D[g[n], x], x, Method -> BezoutMatrix], {n, 1, 8}] Out[12]= {{0.000087, 1}, {0.000568, 2}, {0.001319, 5}, {0.003843, 16}, {0.016913, 59}, {0.106776, 246}, {1.1337, 1103}, {15.8515, 5247}} Hope this helps, -- Jean-Marc === Subject: Re: Factorial equations Hi Artur, here is a somewhat faster method where we use Discriminant with the option Method-> BezoutMatrix: n=7; poly=Plus@@Table[Symbol[c<>ToString[i]] x^i,{i,0,n}]; Length@Discriminant[poly,x,Method-> BezoutMatrix] hope this helps, Daniel > Who know how is possible with use Mathematica solving equations > involving factorials e.g > Solve[n! + n == 726, n] My difficult problem to solving is > x=n > y=n! find function f(x,y) such > f[1,1!]==1, f[2,2!]==2, f[3,3!]==5, f[4,4!]=59,f[5,5!]=246, > f[6,6!]=1103, f[7,7!]=5247 > values are generated by procedure > ClearAll[f]; a = {}; Do[k = 0; Do[k = k + f[n] x^n, {n, 0, s}]; > m = Resultant[k, D[k, x], x]; AppendTo[a, Length[m]], {s, 1, 8}]; a Who can help in find formula or do above procedure much quickest I will > be greatfull ! > Best wishes > ARTUR === Subject: Re: Factorial equations > Who know how is possible with use Mathematica solving equations > involving factorials e.g > Solve[n! + n == 726, n] You could use *Reduce* and tell Mathematica that n is a positive integer. For instance, In[1]:= Reduce[n! + n == 726 && n >= 0, n, Integers] Out[1]= n == 6 (* We check this is the correct result, indeed. *) In[2]:= n! + n == 726 /. ToRules@% Out[2]= True HTH, -- Jean-Marc === Subject: Re: same color above a treshold > in ArrayPlot or ContourPlot, I need to color the points exceeding a > certain treshold with the same color (say red). > I guess that could be done defining an appropriate ColorFunction... > but I cannot work it out. Here is several possibilities among many others, using replacement rule, ColorFunction, and ColorRules. data = {{1, 0.5, 0, 0.3}, {1, 1, 0.2, 0.3}, {1, 0, 1, 0.7}}; ArrayPlot[data] (* default colors for comparison *) ArrayPlot[data /. _?(# > 0.5 &) -> Orange] ArrayPlot[data, ColorFunction -> (Hue[Clip[#, {0, 0.5}]] &)] ArrayPlot[data, ColorRules -> {_?(# > .5 &) -> Orange, _ -> Green}] ArrayPlot[data, ColorRules -> {_?(# > .5 &) -> Orange}] HTH, -- Jean-Marc === Subject: Re: Any body can help me solve the equation with piecewise function > I have a problem to solve, but it seems not easy because of the piecewise function involved. I am wondering how we should deal with piecewise function when solving an equation or doing optimization. > > To give you an simple example, the piecewise function is f(x)= 3x if x<0; f(x)= 0 if x>=0. And I want to solve the equation f(x)+6=0. > > I actually define the piecewise function at first using Which and then try to use NSolve to solve it. However, NSolve doesn't work through. > > Anybody know how should I solve this kind of problem generally in Mathematica? Of course, for this simple example, we can divide it into two cases and then compare the solutions after solving the two cases. Yet my problem is more general and involves more than 3 piecewise functions, thus a lot of possible cases to deal with. So any command or function to deal with this kind of general problem? First, note that there exists several obvious ways to define a piecewise function in Mathematica such as *Piecewise*, *Which*, *Switch*, *If*, etc., and some less obvious ways such as *Boole*, *UnitStep*, *Clip*, *InterpolatingFunction* to name a few. Which one to choose depends on the version of Mathematica you are using, the familiarity you have with them, what you try to achieve, and also evaluation speed. Therefore, it is hard to tell what in general one should use without taking in account the problem to be solved and its context. Second, note that some solvers are designed to deal specifically with piecewise and piecewise-related function (*Reduce*, *Simplify*, *Minimize*, to name a few) whereas some others are not (*Solve* for instance). Third, note that there exists two classes of solvers --- symbolic (Solve, Reduce, DSolve, Minimize. ...) and numeric (NSolve, NSolve, NMinimize, ...) ---, each type using different algorithms and yielding exact or approximate solutions, respectively. Finally, here is an example using the function you gave in your post (the output from Mathematica have been commented out (**)). Clear[f] f[x_] := Piecewise[{{3 x, x < 0}, {0, x >= 0}}] Reduce[f[x] + 6 == 0, x] (* x == -2 *) f[x] + 6 == 0 /. ToRules@% (* True *) Solve[f[x] + 6 == 0, x] (* During evaluation of In[4]:= Solve::eqf: x<0 is not a well-formed equation. >> Solve[6 + [Piecewise] { {3 x, x < 0} } == 0, x] *) Simplify[f[x] + 6 == 0] (* 2 + x == 0 *) Solve[%, x] (* {{x -> -2}} *) Plot[f[x] + 6, {x, -10, 10}] (* ... discarded plot ... *) -- Jean-Marc -- Jean-Marc === Subject: Re: Any body can help me solve the equation with piecewise function >I have a problem to solve, but it seems not easy because of the >piecewise function involved. I am wondering how we should deal with >piecewise function when solving an equation or doing optimization. >To give you an simple example, the piecewise function is f(x)= 3x if >x<0; f(x)= 0 if x>=0. And I want to solve the equation f(x)+6=0. >I actually define the piecewise function at first using Which and >then try to use NSolve to solve it. However, NSolve doesn't work >through. >Anybody know how should I solve this kind of problem generally in >Mathematica? How about using Reduce? For example, In[1]:= f[x_] = Piecewise[{{3 x, x < 0}, {0, x >= 0}}]; In[2]:= Reduce[f[x] + 6 == 0, x] Out[2]= x == -2 === Subject: How to put text on a curved surface? I would like to put Mathematica on a curved surface, e.g. a torus. Can anyone help here? with friendly greetings, P_ter === Subject: optimization I'm quite new to mathematica, and I am not sure how to optimize following algorithm (see .nb in link below). Simulation generates 2 time series, and takes quite a long time to generate series for w>1000 even if you try to run the code with w0, it takes few minutes) http://staff.utia.cas.cz/barunik/optimization.nb My question is, if it is possible somehow to optimize the algorithm so Jozef === Subject: setting elements of an array based on a condition I have one array, W, which for testing purposes has 25 rows and 50 columns. There are two more things I want to accomplish with this: 1) I want to set all elements of W which are smaller than zero to zero. 2) Then I want to calculate the sum of the elements in each column of W. How can I do this? The code below shows how I get to W. Claus X = RandomReal[{0, 1}, 50]; Y = RandomReal[{0, 1}, 50]; BinWidth = 0.2; Radius = 0.2; xyzVals2 = Table[ {i/(1/BinWidth) + (BinWidth/2) , j/(1/BinWidth) + (BinWidth/2) } , {i, 0, (1/BinWidth) - 1} , {j, 0, (1/BinWidth) - 1}]; RasterPtsVals = Partition[Flatten[xyzVals2], 2] RasterX = RasterPtsVals[[All, 1]] RasterY = RasterPtsVals[[All, 2]] XDiffSq = (RasterX - a /. a -> X)^2; YDiffSq = (RasterY - b /. b -> Y)^2; Dist = Sqrt[(XDiffSq + YDiffSq)]; W = 1 - (Dist/Radius) === Subject: Re: Mathematica Player Pro! >I hope that Wolfram Research will make Player Pro free. I can't see Wolfram doing this although I would like to be wrong. Mathematica packages and notebooks are text. If the player could properly display any valid Mathematica code and allow for interactivity, making the player free would be tantamount to making Mathematica free since I could use any text editor to create the package/notebook. Admittedly, this would not be nearly as convenient or pleasant as using the front end. But it seems like it would work. === Subject: function not evaluating question tia sal2 function not evaluating question tia sal2 I trying to evaluate this function to a numerical value but it doesn;t seem to work I replace the expression with t sin t and it works what am I doing wrong? In[240]:= f = Function[{t}, 0.680232 Cos 6.28319 [t]] Out[240]:= Function[{t}, 0.680232 Cos 6.28319[t]] In[241]:= Evaluate [f[2.5]] Out[241]:= 0.680232 Cos 6.28319[2.5] Why am I not getting a numerical value? tia sal2 === Subject: Re: function not evaluating question tia sal2 > I trying to evaluate this function to a numerical value but it doesn;t > seem to work I replace the expression with t sin t and it works what > am I doing wrong? In[240]:= f = Function[{t}, 0.680232 Cos 6.28319 [t]] > Out[240]:= Function[{t}, 0.680232 Cos 6.28319[t]] f = Function[{t}, 0.680232 Cos [6.28319 t]] f[2.5] yields -0.680232 I suspect you may want: f2 = Function[{t}, 0.680232 Cos [2 Pi t]] f2[2.5] also yields -0.680232 but is not numerically = to f[2.5] === Subject: Re: function not evaluating question tia sal2 you should try to read the manual and learn to set the brackets on the right positions: f = Function[{t}, 0.680232 Cos[ 6.28319 t]] Jens > function not evaluating question tia sal2 > I trying to evaluate this function to a numerical value but it doesn;t > seem to work I replace the expression with t sin t and it works what > am I doing wrong? In[240]:= f = Function[{t}, 0.680232 Cos 6.28319 [t]] > Out[240]:= Function[{t}, 0.680232 Cos 6.28319[t]] > In[241]:= Evaluate [f[2.5]] > Out[241]:= 0.680232 Cos 6.28319[2.5] Why am I not getting a numerical value? tia sal2 > === Subject: Re: function not evaluating question tia sal2 > function not evaluating question tia sal2 > I trying to evaluate this function to a numerical value but it doesn;t > seem to work I replace the expression with t sin t and it works what > am I doing wrong? In[240]:= f = Function[{t}, 0.680232 Cos 6.28319 [t]] > Out[240]:= Function[{t}, 0.680232 Cos 6.28319[t]] > In[241]:= Evaluate [f[2.5]] > Out[241]:= 0.680232 Cos 6.28319[2.5] Why am I not getting a numerical value? tia sal2 > It seems you have misplaced a square bracket. (Note that Evaluate is not required here.) In[1]:= f = Function[{t}, 0.680232 Cos[6.28319 t]]; f[2.5] Out[2]= -0.680232 -- Jean-Marc === Subject: Sorting 3 points Simple question, but documentation is no help. I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function === Subject: Re: Sorting 3 points correctly under versions 4 and 5 (that is important for code to be downloaded for my remote course offerings) is #1[[3]] <= #2[[3] & Last[] changed syntax under 6.0. === Subject: Re: Sorting 3 points Last[] changed syntax under 6.0. > No, it did not. According to the docs it hasn't changed since version 1 (though I have not used earlier versions than 4, so I have no first hand experience with them). === Subject: Re: Sorting 3 points > Simple question, but documentation is no help. > I have three coordinate triplets: =9AP1={x1,y1,z1} =9A =9A =9AP2={x2,y2,z2} =9A =9A =9AP3={x3,y3,z3} where all entries are numeric. I wont to sort them into =9AP1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command =9A =9A{P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function The simplest solution is to use SortBy {P1s,P2s,P3s}=SortBy[{P1,P2,P3},#[[3]]&] or {P1s,P2s,P3s}=SortBy[{P1,P2,P3},Last] === Subject: Re: Sorting 3 points > Simple question, but documentation is no help. > I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function Well, this is pretty simple if you read what an ordering function is ... Sort[list, Last[#1] < Last[#2] &] (Or if you have Mathematica 6, just use SortBy[list, Last]) Perhaps the missing piece was constructing anonymous functions? Read the doc page of Function for an explanation (#1, #2 are the first and second arguments of the function). === Subject: Re: Sorting 3 points Sort[{P1,P2,P3}, Last[#1] Simple question, but documentation is no help. > I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function > === Subject: Re: Sorting 3 points > Simple question, but documentation is no help. > I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function The pure function (Last@#2 > Last@#1) & seems to be a good candidate. For instance, P1 = {1, 2, 3}; P2 = {3, 1, 2}; P3 = {2, 3, 1}; Sort[{P1, P2, P3}, (Last@#2 > Last@#1) &] (* Any Version *) SortBy[{P1, P2, P3}, Last] (* Version 6.0 and above *) {{2, 3, 1}, {3, 1, 2}, {1, 2, 3}} {{2, 3, 1}, {3, 1, 2}, {1, 2, 3}} -- Jean-Marc === Subject: Re: ? Hello AES, I believe mathematica is doing something sensible here. It has scaled your graphics so that your print statement produces objects of about the same size. I believe this is true in 5.0 as well. To get what you want with Print, you could specify that you want a large graphics object, viz: p = Plot[Sin[x], {x, 0, Pi}, ImageSize -> Large] Print[text, p] (*should also work in 5.0*) However, I believe what you might want would be better if you used Grid (6.0), or used Inset(6.0), or used FrameLabel->text in your plot (5.0) > Print[Plot[---]]; > Print[Some textn, Plot[---]]; > * This is documented --or better, warned about -- where? (since it looks like I'll have to, once again, step aside from > attempting to accomplish anything useful with 6.0 and > burn up more time digging into its arcane documentation, > trying to understand this. Apologies for the sarcasm -- > but that's the way it feels.) -- W. Craig Carter === Subject: Re: DifferenitalD vs CapitalDifferenitalD > After applying Jens correction, I was hoping to be able to use the > DifferentialD with x, etc. and then use the 'dx' , where 'd' here is > DifferentialD (just dont know how to add it here in the email), so it > would be a Symbol....but this didnt work....I realize I can use the > straight forward dx , etc. symbol but I want to highlight the > Differential....any way to 'fix' this?....when I type in DifferentialD > , from the Palette, and then add x to it and perform //Head on it , it > just returns DifferentialD thank you....jerry blimbaum > [DifferentialD]x cannot be used as a symbol because [DifferentialD] is treated as an operator. A symbol name must start with a letter. But why do you want to use [DifferentialD]x as a symbol anyway? I cannot imagine any reasonable application for this. If you explained your motivation for wanting to have a symbol with this name, perhaps we could say something more useful ... === Subject: Re: DifferenitalD vs CapitalDifferenitalD > After applying Jens correction, I was hoping to be able to use the = > DifferentialD with x, etc. and then use the 'dx' , where 'd' here is = > DifferentialD (just dont know how to add it here in the email), so it = > would be a Symbol....but this didnt work....I realize I can use the = > straight forward dx , etc. symbol but I want to highlight the = > Differential....any way to 'fix' this?....when I type in DifferentialD = > , from the Palette, and then add x to it and perform //Head on it , it = > just returns DifferentialD Hi Jerry, The behavior you have noticed is perfectly normal since the built-in function *DifferentialD[]*, which can also be entered as |esc|dd|esc| (i.e. the escape key followed by the character lowercase d twice followed by the escape key again), is a *compound operator with built-in meaning*. The full form of a complete expression with *DifferentialD[]* is DifferentialD[some_expression] (one argument is required). For instance, say we enter the expression |esc|dd|esc|z Its full form is And its head is Thus, one cannot manipulate double struck lowercase d independently. Now, if you are interested by the above character without built-in meaning, you can get it with the following sequence of keys: |esc|dsd|dsd| Note that dsd stands for double struck lowercase d. Similarly, you can get a double struck capital C by entering |esc|dsC|esc| Finally, enter and evaluate the following sequences of keystrokes: |esc|int|esc|z |esc|dsd|esc|z |esc|int|esc|z |esc|dd|esc|z They look the same. However, the first expression generates an error message, while the second returns the expected definite integral. -- Jean-Marc === Subject: Mathematica SIG (Washington DC Area) The Washington D.C. area Mathematica Special Interest Group will meet Friday, 25 April, 7:30 to 9:00 a.m. at the SAIC Enterprise Center building in Tysons Corner (see directions below). Early risers meet before 7:00 in the morning for admission at the front desk, then we have a Dutch treat breakfast downstairs. By about 7:30 we have moved to one of the classrooms. Meetings consist of prepared talks, informal discussion about Mathematica programming and applications, general questions, and new business. Here are the prepared talks: Speaker #1. Mel Friedman will discuss five mini-topics: a. Tradeoffs Between Calculating With Real and Exact Numbers b. Analytical Convolution Integral, Analytical Fourier Transform and Inverse Fourier Transform c. Fourier and Inverse Fourier Transforms With Delta Functions d. Numerical Integration of a Discretely Sampled Function e. Least Squares Fit of Discretely Sampled Function Speaker #2. Harry Bishop will discuss our evolving MathSIG group site (and what else we might do with it) and the present static (DC-SIG) site. Speaker #3. Dan Martinez may present another (as he calls it) harangue about Manipulate. If that's haranguing, then we need more of it! To inquire about attending, e-mail Dan Martinez (dmartinez@sprintmail.com) or Bruce Colletti (bcolletti@compuserve.com). In your e-mail subject line, please include 'Mathematica SIG.' A SIG representative will meet you in the lobby. Please arrive no later than ten minutes to seven if you wish to join us for breakfast, and no later than twenty after seven to attend the meeting only. The desk officer will ask for a driver's license before issuing a visitor's badge. === Subject: Re: Mathematica Player Pro! >Why not go even further and try to convince Dell and Apple, > and any other OEM, to sell the computers with Mathematica Player Pro > preloaded, just as they now come preloaded with Acrobat Reader? > hi David; I mentioned the same exact idea on here on may 9 2007 around when the free player came out . http://forums.wolfram.com/mathgroup/archive/2007/May/msg00268.html If Wolfram research can make a deal with the likes of Dell/Compaq, etc... to have the MathPlayer preinstalled in new PC's sold, then the problem with the large size of the player will no longer exist. I noticed that a new PC's from DELL nowadays, that it has adobe reader already installed on the desktop. So, I agree, it is a good idea :) Nasser === Subject: Wolfram User Interface Research? My understanding is that at least some vendors of larger software apps do a substantial amount of research into how users interact with their products -- e.g., they set up experiments in test rooms where they observe, record, and/or videotape how ordinary users perform various typical tasks using their products -- how they approach them, what mistakes they frequently make -- and try to interpret from these observations what mental constructs these users seem to be working under, why they make the mistakes they make and so on. A curiosity based question along this line for Wolfram: If one examined a bunch of notebooks generated by some representative set of users, I particularly wonder what would be the relative frequency of use for all of the numerous non-alphabetic operators in Mathematica? -- that is, all the innumerable codings like . . @ -> & @ @@ @@@ * << % and on. Which of these are frequently used, which are very seldom used, by different classes of users? (And which are most frequently misused or lead to errors when used?) One might of course ask the same thing about many of the alphabetically named computational and display commands in Mathematica (There are more than 1000 of these, is that not so?) Seems like data like this could not only improve the product but provide some really useful guidance for what to focus on in the development of manuals, tutorials, and other documentation for new or less experienced users (assuming, of course, that Wolfram will ever again have any interest in providing this kind of documentation) (sorry, couldn't resist that jab). === Subject: Re: Wolfram User Interface Research? On 2008-04-21 16:53:24 +0930, AES said: > If one examined a bunch of notebooks generated by some representative > set of users, I particularly wonder what would be the relative frequenc= y > of use for all of the numerous non-alphabetic operators in Mathematica? > -- that is, all the innumerable codings like . . @ -> & = @ > @@ @@@ * << % and on. When I started learning Mathematica, I was a little confused about how to start with all of these. I really liked the conciseness they give to expressions, but it can be tempting to chain inscrutiably long commands together and create an unreadable mess --- but of course, if you did exactly the same thing with the FullForm equivalents then the result would be just as hard to read, if not more so. One of the biggest things I've noticed is that I like using @ a lot more than I thought I would. At first, I thought that consistency would be better and everything should be nested brackets: Sort[Flatten[OptionValue[myopt]]] or whatever. But Sort@Flatten@OptionValue@myopt is much easier to type and removes the need to count brackets. And I've loved being able to tack on a //N (or whatever) to the end of expressions from the first time I saw Mathematica's postfix notation. Just a couple of thoughts :) Will === Subject: Re: Wolfram User Interface Research? This comment about APL is quite wrong: nothing compelled you to write inscrutable single line programs (except maybe in the earliest days, when one was sending single lines over a telephone line to a mainframe, then waiting for your instruction's turn to get its slice of time and have the result sent back and typed at your terminal). With APL then, and with IBM's APL2 now, you MAY, if you wish, write overly condensed one-liners. And indeed some APL programmers aimed to write as concise a program, all in one line, as they could possibly do. But what some folks regard as inscrutable, others read with ease. It's like saying that if one doesn't understand Chinese, then a couple of pictograms form an inscrutable text, whereas somebody who does understand Chinese finds it wholly scrutable. What's more, many of the combinations of symbols in APL were instantly recongnizable to any APL programmer as so-called idioms. The delight of APL was, and is, that many very complicated things can, in fact, be expressed quite concisely, in a way that the suggestive graphic symbols of APL help one understand. In fact, one could maintain that, despite the power of its pattern-matching, functional programming constructs, and list-handling abilities, Mathematica programs can be MUCH more difficult to understand than corresponding APL program -- because the Mathematica programs use all those, often long, words, and because they force one to pay close attention to order of precedence and to insert nested brackets. It's really all a matter of what one has learned, and how well, and how accustomed one is to the language. As just one rather simple-minded example, suppose you want to form the running cumulative sum of a list (in APL-speak, a vector) of numbers. In APL, this is given by + vec (and generalizes from to other binary operations). In Mathematica 5 and earlier, Rest[FoldList[Plus,0,vec]] (also generalizable) and in Mathematica 6, Accumulate[vec] (a special function that's no longer generalizable). The APL notation is related to the APL notation for summing a list, +/vec (which is also generalizable); the Mathematica analog is, of course: Plus @@ vec I think one would have a hard time proving that +/vec is more difficult to read, especially at a glance, than Plus @@ vec -- or even Total[vec]. When I see +/vec, I immediately think, add up the entries in vec. I cannot speak knowledgeably of the current situation with APL2, but for many years APL programmers were incredibly productive compared with those programming in just about all other standard computer languages. It's not for no good reason that, for example, major financial analysis systems and reservations systems were written in APL (and some still are, or at least in offshoots from the APL trunk). > >> it can be tempting to chain inscrutiably long commands >> together and create an unreadable mess --- As was the case, oldtimers will recall, with IBM's APL (A Programming > Language), which allowed you -- in fact, more or less compelled you -- > to write incredibly powerful, but totally inscrutable single line > programs, leading to the now classic phrase Write once -- read never, > since one day later even the original coder couldn't figure out how his > or her code worked. >> together and create an unreadable mess --- but of course, if you did >> exactly the same thing with the FullForm equivalents then the result >> would be just as hard to read, if not more so. Don't agree with you on this -- but nonetheless will take your further > comment to heart and go off and finally learn how to use @ . > -- 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: Wolfram User Interface Research? > it can be tempting to chain inscrutiably long commands > together and create an unreadable mess --- As was the case, oldtimers will recall, with IBM's APL (A Programming Language), which allowed you -- in fact, more or less compelled you -- to write incredibly powerful, but totally inscrutable single line programs, leading to the now classic phrase Write once -- read never, since one day later even the original coder couldn't figure out how his or her code worked. > together and create an unreadable mess --- but of course, if you did > exactly the same thing with the FullForm equivalents then the result > would be just as hard to read, if not more so. Don't agree with you on this -- but nonetheless will take your further comment to heart and go off and finally learn how to use @ . === Subject: Re: Wolfram User Interface Research? On 2008-04-22 04:08:34 +0930, AES said: >> together and create an unreadable mess --- but of course, if you did >> exactly the same thing with the FullForm equivalents then the result >> would be just as hard to read, if not more so. Don't agree with you on this -- but nonetheless will take your further > comment to heart and go off and finally learn how to use @ . Oh, I just meant to say that you're better off splitting things up into chunks and commenting each part if it doesn't make any sense. Here's some code of which I'm not particularly proud but which, kind of, demonstrates this idea: ListCombinations[in_List, AND_, NOT_] := Module[{s, x},=E2=80=A8 s == Tuples[{# &, NOT[#] &}, Length@in];=E2=80=A8 s = Thread[MyApply[#, i= n]] & /@ s /. MyApply[x_, y_] -> x[y];=E2=80=A8 s = AND @@ # & /@ s;=E2=80=A8= Most@s (* Last element is NOT all -- we're not using that one *)=E2=80=A8 ] ListCombinations[{a, b, c}, And, Not] If I'd chained all those s= into a single statement (which is probably that second line is pretty messy), regardless of whether those @@ and & and /. were Apply[], Function[], Replace[], and so on. Will === Subject: Re: Parallel Computing Toolkit with ssh tunnels Hi Art, in order for SSH tunneling to work for your configuration, you have to use active MathLink connections that use standard input and output as MathLink transport, i.e., LaunchSlave[remotehost,ssh `1` math -mathlink, ConnectionType- >LinkLaunch] Also see http://documents.wolfram.com/applications/parallel/Configuration/Un= ix.html Sascha > I would like to create a poor man's parallel cluster using PCT to work > through ssh tunnels due circumvent firewall restrictions. I have 3 slave and 1 master linux machines with sshd running on port > 22 and no other ports open. Assume each machine is additionally behind > a physical firewall and has a local IP and the firewall port forwards > 22 to this machine. Authentication is set up without a password so > that the following works: me@master: ssh slave1 math > Mathematica 6.0 for Linux x86 (64-bit) > Copyright 1988-2008 Wolfram Research, Inc. In[1]:= I haven't been able to get LaunchSlave[] to work with this setup with > various combinations of LinkName, LinkHost and for example, 'ssh -R > port1:127.0.0.1:port1 -R port2:127.0.0.1:port2' as replacement for > $RemoteCommand. It seems for each launch, the master listens on two new random ports > for each slave and instructs the slave to connect to these ports on a > specific IP. I think I have both an issue with the firewall and the > fact that meaningless local IPs are passed to the slaves rather than > the IP of the firewall. Even when I hand set the ports and open them > on the firewalls, I have problems. I am guessing the mathlink connection protocol is the same as > launching a remote kernel on a slave from the master, which I also > haven't been able to get to work with these firewalls and port > restrictions. I have been able to get it to work with all machines in > one local network and with no firewall restrictions. I have also been > able to use gdb to debug mathlink code using the similar two port > communication. I was wondering if anyone has gotten either PCT or remote kernel > launching through ssh tunnels to work. There are prior posts on this > forum and help on a wiki page:http://tinyurl.com/5ano5tbut I haven't > been able to get them to work either. I am using 6.0.2 on 64-bit > Ubuntu 7.10 with PCT 2.1. Art. === Subject: Re: Polygon cutter what is wrong with ContourPlot[] to reinvent the weel? Except the good old numeric code, nobody would use code from 1966 that has not updated over the time. And what is wrong with the good old Which[] function of Mathematica ? Jens > A programming style question. The code fragments below come > from conversion to Mathematica (they must work on versions >=4.0) of an ancient Fortran IV contourplot program written > in 1966 for my thesis. They are key part of the inner loop > polygon cutter. > ----------------------------------------------------------- > Version 1. Straight translation from Fortran: p={Null}; > If [tb>0&&tb==tt, p={P1,P2,P4,P3}]; > If [tb==1&&tt==2, p={Pc2,P1,P2,P4,P3}]; > If [tb==-1&&tt==-1,p={}]; > If [tb==-1&&tt==0, p={Pc1,Pc2,Pc3}]; > If [tb==-1&&tt==1, p={Pc1,P4,P3}]; > If [tb==-1&&tt==2, p={Pc1,Pc2,P3,P4}]; > If [tb==0&&tt==0, p={}]; > If [tb==1&&tt==0, p={Pc3,Pc2,P1,P2}]; > If [tb==2&&tt==0, p={Pc3,P1,P2}]; > poly=Graphics[Polygon[p]]; V1 was actually a separate subroutine, with a RETURN after > each match, but in Mathematica it goes inline. > tb (tag-bottom) and tt (tag-top) are integers in range > -1 through 2 whereas P1, ... etc, are point coordinates. > ----------------------------------------------------------- > Version 2. Table driven variant of above: p={{{},{Pc1,Pc2,Pc3},{Pc1,P4,P3},{Pc1,Pc2,P3,P4}}, > {{Null},{},{Null},{Null}}, > {{Null},{Pc3,Pc2,P1,P2},{P1,P2,P4,P3},{Pc2,P1,P2,P4,P3}}, > {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]]; > poly=Graphics[Polygon[p]]; Impossible (tb,tt) combinations return {Null}. V2 was > actually that implemented when V1 was later converted to > Univac 1110 machine language. > ---------------------------------------------------------- > Question: which version is preferable in Mathematica, or is > there a better one? Both run roughly at the same speed > (about 25 microsec under 5.2 on an Intel MacBook Pro). > Since this loop is traversed once for each polygon, > efficiency is important. > === Subject: Re: Polygon cutter Carlos, > Well, tell me how ContourPlot can be used for an arbitrary finite > element mesh, > which may have arbitrary geometry, topology and element type > combinations, > when the data is only known at the nodes (or at Gauss points). > the function imsUnstructuredContourPlot[ co, inc, val ] co = coordinates inc = incidences val = values at the nodes which you can get here : http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/imsTOC/Utliti es/Graphics/UnstructuredPlotDocu.html can do it. hth, oliver > Last I heard, ContourPlot only works for a rectangular region and the function > must be provided as, well, a function. It has its uses, but not in FEM plotting. Oliver Ruebenkoenig, === Subject: Re: Polygon cutter Well, tell me how ContourPlot can be used for an arbitrary finite element mesh, which may have arbitrary geometry, topology and element type combinations, when the data is only known at the nodes (or at Gauss points). Last I heard, ContourPlot only works for a rectangular region and the function must be provided as, well, a function. It has its uses, but not in FEM plotting. === Subject: Re: Polygon cutter a) in version 6.0 ContourPlot[] will work with data in any position as to see from ListContourPlot[Table[Random[], {5}, {3}]] b) and for higer finite elements you have to write the correct interpolation routine. But it may be sufficient, to compute the function on a triangular mesh and feed it into ListContourPlot[] Jens > Well, tell me how ContourPlot can be used for an arbitrary finite element mesh, > which may have arbitrary geometry, topology and element type combinations, > when the data is only known at the nodes (or at Gauss points). Last I heard, ContourPlot only works for a rectangular region and the function > must be provided as, well, a function. It has its uses, but not in FEM plotting. > === Subject: Re: Polygon cutter Hello Carlos, I believe the interpretation of good style is a bit like ethics--it's easy to agree in extreme cases, but the in-between cases are subjective. I think this depends on whether you intend to modify the code in the future. I believe V1 is easier to read, and if you think that someone else may wish to modify it, then I recommend sticking with that. However,Which will probably be more efficient, and rank the order of tests with decreasing frequency. V2 looks cool--some people like that. There is probably a way to improve the coolness even more, and remove the need to return the impossible Nulls. Creating V2 probably hones your skills and is more interesting to do, which is similarly important; but probably has a direct impact on a broader interpretation of efficiency. > A programming style question. The code fragments below come > Version 1. Straight translation from Fortran: p={Null}; > If [tb>0&&tb==tt, p={P1,P2,P4,P3}]; : : > poly=Graphics[Polygon[p]]; Version 2. Table driven variant of above: p={{{},{Pc1,Pc2,Pc3},{Pc1,P4,P3},{Pc1,Pc2,P3,P4}}, > {{Null},{},{Null},{Null}}, > {{Null},{Pc3,Pc2,P1,P2},{P1,P2,P4,P3},{Pc2,P1,P2,P4,P3}}, > {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]]; > poly=Graphics[Polygon[p]]; Question: which version is preferable in Mathematica, or is > there a better one? Both run roughly at the same speed > (about 25 microsec under 5.2 on an Intel MacBook Pro). > Since this loop is traversed once for each polygon, > efficiency is important. -- W. Craig Carter === Subject: Re: Polygon cutter > Hello Carlos, > I believe the interpretation of good style is a bit like ethics--it's > easy to agree in extreme cases, but the in-between cases are > subjective. > I think this depends on whether you intend to modify the code in the > future. I believe V1 is easier to read, and if you think that someone > else may wish to modify it, then I recommend sticking with that. > However,Which will probably be more efficient, and rank the order of= > tests with decreasing frequency. > V2 looks cool--some people like that. There is probably a way to= > improve the coolness even more, and remove the need to return the > impossible Nulls. Creating V2 probably hones your skills and is > more interesting to do, which is similarly important; but probably has= > a direct impact on a broader interpretation of efficiency. > A programming style question. The code fragments below come > Version 1. Straight translation from Fortran: > p={Null}; > If [tb>0&&tb==tt, p={P1,P2,P4,P3}]; > : > : > poly=Graphics[Polygon[p]]; > Version 2. Table driven variant of above: > p={{{},{Pc1,Pc2,Pc3},{Pc1,P4,P3},{Pc1,Pc2,P3,P4}}, > {{Null},{},{Null},{Null}}, > {{Null},{Pc3,Pc2,P1,P2},{P1,P2,P4,P3},{Pc2,P1,P2,P4,P3}}, > {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]]; > poly=Graphics[Polygon[p]]; > Question: which version is preferable in Mathematica, or is > there a better one? Both run roughly at the same speed > (about 25 microsec under 5.2 on an Intel MacBook Pro). > Since this loop is traversed once for each polygon, > efficiency is important. > -- > W. Craig Carter > Your suggestion of looking at the Which construct was an interesting > one - > didn't know it existed. So I tried it as > p={Null}; > Which [tb>0&&tb==tt, p={P1,P2,P4,P3}, tb==1&&tt==2,= > p={Pc2,P1,P2,P4,P3}, > tb==-1&&tt==-1,p={}, = tb==-1&&tt==0= > , > p={Pc1,Pc2,Pc3}, > tb==-1&&tt==1, p={Pc1,P4,P3}, t= b==-1&&tt==2, > p={Pc1,Pc2,P3,P4}, > tb==0&&tt==0, p={}, = tb==1&&tt==0, > p={Pc3,Pc2,P1,P2}, > tb==2&&tt==0, p={Pc3,P1,P2}]; > poly=Graphics[Polygon[p]]; > The two most common cases are the first two. I expected this to be > quicker than V1 > but it wasnt. On a MacBook Pro under 5.2: > V1 25 microsec/polygon > V2 24 > Which 30 > Similar rankings for 4.1 and 4.2. Havent tested it on 6.0. How about using Switch? switchfun[{tb_, tt_}]:= > Switch[{tb, tt}, > {tb, tb} /; tb > 0, {P1, P2, P4, P3}, > {1, 2}, {Pc2, P1, P2, P4, P3}, > {-1, 0}, {Pc1, Pc2, Pc3}, > {-1, 1}, {Pc1, P4, P3}, > {-1, 2}, {Pc1, Pc2, P3, P4}, > {1, 0}, {Pc3, Pc2, P1, P2}, > {2, 0}, {Pc3, P1, P2}, > {_, _}, {} > ] Graphics@Polygon@switchfun@{tb,tt} Note, in V6 Graphics[Polygon[{}]] is OK but Graphics[Polygon[{Null}]] > produces an error. And the same is true for Graphics3D. --Mark {Null} IS intended to trigger an error, since those tag combinations, in the famous Unix phrase, cant happen === Subject: Re: Polygon cutter The two most common cases are the first two. I expected this to be > quicker than V1 > but it wasnt. On a MacBook Pro under 5.2: V1 25 microsec/polygon > V2 24 > Which 30 Similar rankings for 4.1 and 4.2. Havent tested it on 6.0. I am glad to know it, surprised, but glad to know. Strange, because you are evaluating ifs even though it has determined to be true beforehand. So, let me suggest an (possible) improvement of V1: findpoly[tb_,tt_]:= Module[{}, If [tb>0&&tb==tt, Return[Graphics[Polygon[{P1,P2,P4,P3}]]; : : If [tb==2&&tt==0, Return[Graphics[Polygon[{Pc3,P1,P2}]]]; ] This is more like your older subroutine... -- W. Craig Carter === Subject: Re: Polygon cutter > Hello Carlos, > I believe the interpretation of good style is a bit like ethics--it's > easy to agree in extreme cases, but the in-between cases are > subjective. > I think this depends on whether you intend to modify the code in the > future. I believe V1 is easier to read, and if you think that someone > else may wish to modify it, then I recommend sticking with that. > However,Which will probably be more efficient, and rank the order of > tests with decreasing frequency. > V2 looks cool--some people like that. There is probably a way to > improve the coolness even more, and remove the need to return the > impossible Nulls. Creating V2 probably hones your skills and is > more interesting to do, which is similarly important; but probably has > a direct impact on a broader interpretation of efficiency. > A programming style question. The code fragments below come > Version 1. Straight translation from Fortran: > p={Null}; > If [tb>0&&tb==tt, p={P1,P2,P4,P3}]; > : > : > poly=Graphics[Polygon[p]]; > Version 2. Table driven variant of above: > p={{{},{Pc1,Pc2,Pc3},{Pc1,P4,P3},{Pc1,Pc2,P3,P4}}, > {{Null},{},{Null},{Null}}, > {{Null},{Pc3,Pc2,P1,P2},{P1,P2,P4,P3},{Pc2,P1,P2,P4,P3}}, > {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]]; > poly=Graphics[Polygon[p]]; > Question: which version is preferable in Mathematica, or is > there a better one? Both run roughly at the same speed > (about 25 microsec under 5.2 on an Intel MacBook Pro). > Since this loop is traversed once for each polygon, > efficiency is important. > -- > W. Craig Carter Your suggestion of looking at the Which construct was an interesting > one - > didn't know it existed. So I tried it as p={Null}; > Which [tb>0&&tb==tt, p={P1,P2,P4,P3}, tb==1&&tt==2, > p={Pc2,P1,P2,P4,P3}, > tb==-1&&tt==-1,p={}, tb==-1&&tt==0= > , > p={Pc1,Pc2,Pc3}, > tb==-1&&tt==1, p={Pc1,P4,P3}, tb==-1&&tt==2, > p={Pc1,Pc2,P3,P4}, > tb==0&&tt==0, p={}, tb==1&&tt==0, > p={Pc3,Pc2,P1,P2}, > tb==2&&tt==0, p={Pc3,P1,P2}]; > poly=Graphics[Polygon[p]]; The two most common cases are the first two. I expected this to be > quicker than V1 > but it wasnt. On a MacBook Pro under 5.2: V1 25 microsec/polygon > V2 24 > Which 30 Similar rankings for 4.1 and 4.2. Havent tested it on 6.0. How about using Switch? switchfun[{tb_, tt_}]:= Switch[{tb, tt}, {tb, tb} /; tb > 0, {P1, P2, P4, P3}, {1, 2}, {Pc2, P1, P2, P4, P3}, {-1, 0}, {Pc1, Pc2, Pc3}, {-1, 1}, {Pc1, P4, P3}, {-1, 2}, {Pc1, Pc2, P3, P4}, {1, 0}, {Pc3, Pc2, P1, P2}, {2, 0}, {Pc3, P1, P2}, {_, _}, {} ] Graphics@Polygon@switchfun@{tb,tt} Note, in V6 Graphics[Polygon[{}]] is OK but Graphics[Polygon[{Null}]] produces an error. And the same is true for Graphics3D. --Mark === Subject: Re: Polygon cutter > Hello Carlos, > I believe the interpretation of good style is a bit like ethics--it's > easy to agree in extreme cases, but the in-between cases are > subjective. I think this depends on whether you intend to modify the code in the > future. I believe V1 is easier to read, and if you think that someone > else may wish to modify it, then I recommend sticking with that. > However,Which will probably be more efficient, and rank the order of > tests with decreasing frequency. V2 looks cool--some people like that. There is probably a way to > improve the coolness even more, and remove the need to return the > impossible Nulls. Creating V2 probably hones your skills and is > more interesting to do, which is similarly important; but probably has > a direct impact on a broader interpretation of efficiency. > A programming style question. The code fragments below come > Version 1. Straight translation from Fortran: > p={Null}; > If [tb>0&&tb==tt, p={P1,P2,P4,P3}]; : > : > poly=Graphics[Polygon[p]]; > Version 2. Table driven variant of above: > p={{{},{Pc1,Pc2,Pc3},{Pc1,P4,P3},{Pc1,Pc2,P3,P4}}, > {{Null},{},{Null},{Null}}, > {{Null},{Pc3,Pc2,P1,P2},{P1,P2,P4,P3},{Pc2,P1,P2,P4,P3}}, > {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]]; > poly=Graphics[Polygon[p]]; > Question: which version is preferable in Mathematica, or is > there a better one? Both run roughly at the same speed > (about 25 microsec under 5.2 on an Intel MacBook Pro). > Since this loop is traversed once for each polygon, > efficiency is important. -- > W. Craig Carter Your suggestion of looking at the Which construct was an interesting one - didn't know it existed. So I tried it as p={Null}; Which [tb>0&&tb==tt, p={P1,P2,P4,P3}, tb==1&&tt==2, p={Pc2,P1,P2,P4,P3}, tb==-1&&tt==-1,p={}, tb==-1&&tt==0= , p={Pc1,Pc2,Pc3}, tb==-1&&tt==1, p={Pc1,P4,P3}, tb==-1&&tt==2, p={Pc1,Pc2,P3,P4}, tb==0&&tt==0, p={}, tb==1&&tt==0, p={Pc3,Pc2,P1,P2}, tb==2&&tt==0, p={Pc3,P1,P2}]; poly=Graphics[Polygon[p]]; The two most common cases are the first two. I expected this to be quicker than V1 but it wasnt. On a MacBook Pro under 5.2: V1 25 microsec/polygon V2 24 Which 30 Similar rankings for 4.1 and 4.2. Havent tested it on 6.0. === Subject: returning inverse Hessian from FindMinimum I am using Method -> QuasiNewton with FindMinimum. I specify the Gradient but not the Hessian. Can I have FindMinimum return the inverse Hessian it has accumulated when it completes its optimization? The implementation notes indicated BFGS is used for QuasiNewton. I would like to use the inverse Hessian to get an idea of how stable the fitted parameters are around the minimum. I would also like to use it to fudge together the minima from running FindMinimum[] in batch across several machines using the parallel computing toolkit. I don't think this is possible or desirable - I'm just messing around. I looked through the docs and the source for Optimization`UnconstrainedProblems` and didn't find anything, well, other than some good programming pointers. Any suggestions or general guidance would be cool. Sam === Subject: New Presentations Version I have released an updated version of Presentations. Existing purchasers should have received notices and a download link. If you are a purchaser and have not received the notice, please contact me and supply a working email address. Others may purchase the package for $50 through my web site below. Presentations is a package that extends Mathematica to make it easier for students, teachers and researchers to work with textbooks, tutorials and research papers. The core portion implements an easier paradigm for producing custom graphics, geometric diagrams and displays. Among other features there are routines for 3D Text that rotates with the image and hides behind surfaces, 3D arrows, custom ticks and grids, and complex function and complex number graphics. Beyond graphics there is an Indefinite Sequence section that allows the writing, some manipulations, and conversion to normal Mathematica expressions of expressions with ellipses to indicated skipped terms. New features in Presentations are: 3D Text can now be done with most ordinary fonts on your computer and you can even create block characters. A new References section allows the maintenance of lists of references or notes with user specified styles. The references can be inserted into Text cells using Tooltips, OpenerViews or Buttons with pop-up windows. A Key Equations section allows the maintenance of a list of key equations for a notebook. The equations can be numbered and the numbers are dynamically updated. There is complete control of the style and format for the equations, their labels and their references. A Student's Integral section helps students to learn and use standard integration techniques. An integrate command mimics Integrate but holds the integral unevaluated. There are then commands to operate on the integrand, use a change of variable, use integration by parts, use trigonometric substitution and do linear breakouts. The integrals can then be turned over to a BasicIntegralTable such as a student might use, to custom integral tables such as a researcher might use in special cases, or to the Mathematica Integrate or NIntegrate commands. A Manipulations section contains routines for performing common manipulations of expressions that Mathematica seems to have overlooked. CompleteTheSquare does what you might expect. FactorOut will pull an arbitrary subexpression out of an expression (such as a matrix) and apply functions such as HoldForm or CreateSubexpression to the parts. MultiplyByOne will multiply the numerator and denominator of an expression will breakout specified function patterns on specified 'vectors'. PushOnto will push a set of arguments onto specified patterns. It overcomes the severe shortcomings of the Through command. HoldOp will hold an operation, but evaluate the arguments. CreateSubexpression and ReleaseSubexpressions will wrap subexpressions in a Tooltip. A Tooltip works just as well as HoldForm in shielding expressions. (Shielding subexpressions prevents routines such as Simplify from breaking them apart.) MapLevelParts and MapLevelPatterns allows an operation to be mapped onto a subset of level parts (as a single entity) in an expression. The most common usage would be to operate on a subset of terms in a sum. SymbolsToPatterns will convert a list of symbols in an expression to named patterns. This is useful in converting derived results into general rules. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ === Subject: Re: NDSolve and vector functions HI, thank's a lot for the replies. I think the most practicable way is the solution due to Carl. He packs all vector valued constants into functions that only evaluate if the argument is numeric. I will play around with this to check if there are no surprises. thank's again, Daniel > Hello all, does anybody know a way to compute a vector valued function using NDSolve without explicitely specifying all vector components. Here is a simple example: Although NDSolve[{p'[t]==p[t],p[0]=={1,0}},p,{t,0,1}] works, NDSolve[{p'[t]==p[t]+{1,1},p[0]=={1,0}},p,{t,0,1}] does not work because p[t] in p[t]+{1,1} is treated as a scalar and the expression is evaluated to {1+p[t],1+p[t]} what is clearly not intended. Even in IdentityMatrix[2].p[t]+{1,1} IdentityMatrix[2].p[t] is treated like a scalar and added to the components of {1,1}. do I miss something??? Daniel > === Subject: Hamiltonian System with NDSolve So I'm trying to solve the following Hamiltonian system using Mathematica. solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, p'[t] == I*(2 + 1/2)(I*x[t])^(1 + 1/2), p[0] == 1-2*I}, {x, p}, {t,0,10}, MaxSteps -> Infinity][[1]]; I'm letting E=1, so at all points t, it should be that (p[t]/.solution)^2-(I*x[t]/.solution)^(2+1/2)=1. That is the case until the function crosses a branch cut on the complex x-plane that runs from 0 to i*(Infinity). Once the function crosses the branch cut, the system no longer preserves E and the value changes to something around 1.3. How can I go about fixing this problem? I've already tried working with the precision and accuracy goals, and that didn't work. I'm not sure what else to consider. Any help would be appreciated. Alex === Subject: Re: Hamiltonian System with NDSolve you need a symplectic method and NDSolve[] has implemente one as Method ->{SymplecticPartitionedRungeKutta, ..} Jens > So I'm trying to solve the following Hamiltonian system using Mathematica. solution = NDSolve[{x'[t] == 2p[t], x[0] == 2, > p'[t] == I*(2 + 1/2)(I*x[t])^(1 + 1/2), p[0] == 1-2*I}, {x, p}, {t,0,10}, MaxSteps -> Infinity][[1]]; I'm letting E=1, so at all points t, it should be that > (p[t]/.solution)^2-(I*x[t]/.solution)^(2+1/2)=1. That is the case until the function crosses a branch cut on the complex x-plane that runs from 0 to i*(Infinity). Once the function crosses the branch cut, the system no longer preserves E and the value changes to something around 1.3. How can I go about fixing this problem? I've already tried working with the precision and accuracy goals, and that didn't work. I'm not sure what else to consider. Any help would be appreciated. Alex > === Subject: Column Product of a Matrix of zeros and 1's I have a matrix of zero's and ones: myGlobalMatrix; also a set called thisSet with the columns of myGlobalMatrix which have to be multiplied (e.g. column 1,3,4). I would like to know the positions of the 1's. I do this as follows: Flatten[Position[Product[myGlobalMatrix[[All,i]],{i, thisSet}],1]] But this is to general. It does not use that the matrix consists of zeros and ones. Can this be taken into account? with friendly greetings, P_ter === Subject: Re: Very Long Wait for the Kernel after Reboot > I'm running v6.0.1 of Mathematica under Mac OS X v10.4.11 with 1 GB > time I try to evaluate a Mathematica instruction after rebooting the > computer, it takes a very long time to load the kernel (I once timed > it at five minutes, and it seems to be getting longer, but I haven't > timed it again so that might just be frustration). Subsequent > sessions with Mathematica don't require nearly as long (though it > still seems unreasonably long) to get the kernel up and running---as > long as I haven't rebooted. Is this normal for my configuration? Does anyone have an explanation? One thing to check is your anti-virus software. Try temporarily disabling it and see if that fixed the problem. If it does, turn the anti-virus software back on and try adding the Mathematica installation directory to the anti-virus exclusions. -- Helen Read University of Vermont === Subject: Re: Very Long Wait for the Kernel after Reboot > I experience the same problem with my mac, and I have two workarounds. > 1) Start the kernel explicity under the evaluation menu. > 2) Abort the stalled first evaluation and then re-evaluate. --Lou Talman Department of Mathematical and Computer Sciences Metropolitan State College of Denver === Subject: Re: Very Long Wait for the Kernel after Reboot Hello Louis, This thread has come up before, and I didn't see a subsequent explanation. I experience the same problem with my mac, and I have two workarounds. 1) Start the kernel explicity under the evaluation menu. 2) Abort the stalled first evaluation and then re-evaluate. I suspect the problem lies in multiple threading, and the separate processes of the Frontend and the Kernel. But, I am out of my depth here. Craig > I'm running v6.0.1 of Mathematica under Mac OS X v10.4.11 with 1 GB > computer, it takes a very long time to load the kernel (I once timed > it at five minutes, and it seems to be getting longer, but I haven't > Is this normal for my configuration? Does anyone have an explanation? > === Subject: Re: problem accessing notebooks ... > what you do with SetDirectory[] is irrelevant for the package search. ... This is not true for version 5.2. I've put an empty package pack.m into my desktop-directory and another one (pp.m) in a subdirectory named sub: In[1]:= $Version Out[1]= 5.2 for Linux x86 (64 bit) (June 20, 2005) In[2]:= !!~/Desktop/pack.m BeginPackage[pack`,{sub`pp`}]; EndPackage[]; In[3]:= !!~/Desktop/sub/pp.m BeginPackage[sub`pp`]; Print[Verzeichnis gefunden!]; EndPackage[]; In[4]:= <<~/Desktop/pack.m Get::noopen : Cannot open sub`pp`. More... Needs::nocont : Context sub`pp` was not created when Needs was evaluated. More... In[5]:= SetDirectory[~/Desktop]; In[6]:= < ... >> what you do with SetDirectory[] is irrelevant for the package search. > ... This is not true for version 5.2. > I've put an empty package pack.m into my desktop-directory and another one > (pp.m) in a subdirectory named sub: In[1]:= > $Version > Out[1]= > 5.2 for Linux x86 (64 bit) (June 20, 2005) > In[2]:= > !!~/Desktop/pack.m > BeginPackage[pack`,{sub`pp`}]; > EndPackage[]; > In[3]:= > !!~/Desktop/sub/pp.m > BeginPackage[sub`pp`]; > Print[Verzeichnis gefunden!]; > EndPackage[]; > In[4]:= > <<~/Desktop/pack.m > Get::noopen : Cannot open sub`pp`. More... > Needs::nocont : Context sub`pp` was not created when Needs was evaluated. More... > In[5]:= > SetDirectory[~/Desktop]; > In[6]:= > < Verzeichnis gefunden! > === Subject: Re: problem accessing notebooks > ... >> what you do with SetDirectory[] is irrelevant for the package search. > ... This is not true for version 5.2. It is true for every version of mathematica that I know of. But with the default settings ., representing the current directory, is contained within $Path. So if that entry isn't deleted, SetDirectory will help, as you have observed. If you delete . from $Path, SetDirectory will not help at all. Try your tests after doing this to see yourself: $Path = DeleteCases[$Path, .] hth, albert === Subject: Re: A Problem with Simplify >> Indeed. However, there would be two problems. First, >> someone would >> have to devise suitable algorithms and implement >> them. This may not be >> totally impossible, but it would certainly take a lot >> of effort. But >> then, we would see the second problem. This ideal >> integrate would >> run for ever on almost any non-trivial problem. You >> would get nice >> mathematical answers to trivial ones, which would >> make you feel >> good, and no answers to non-trivial ones, which would >> probably make >> you a annoyed enough to complain (to the MathGroup?). >> Would that be a good way to use the time and effort >> of programmers and >> your own money? >> As for Reduce - you should try it a little more on >> harder problems >> than the one you have just presented. It uses some >> very beautiful and >> powerful algorithms like Cylindrical Algebraic >> Decomposition but they >> have exponential or in this case double exponential >> complexity (in >> the number of variables) so if you it try on >> something with more than >> 3 variables involved you will see what I mean. Given >> the choice >> between a program that does everything in the spirit >> of true >> mathematics but can only sole trivial problems that >> can be done by >> hand and one that gives only generic solutions but >> can deal with >> cases that would take you a hundred years to do by >> hand, which one >> would you choose? >> Andrzej Kozlowski I do not see the reason why in the case of Integrate keeping track > for the conditions will take more time than in the case of Reduce. > As I understand it is just the same or something like. > No, because the formulas that Integrate deals with are very often the kind Reduce cannot deal at all with (Reduce can basically only manage algebraic equations and inequalities and those reducible to algebraic ones. Integrate often deals with transcendental functions or, what's worse, composites of transcendental and algebraic ones). If you wanted Integrate to keep track of all conditions, it would have to try to solve equations to check for zeros in the denominator, common zeros in the numerator and the denominator and such like, and it would have to do it not just in the simple cases (like your example) but in all cases. But in the vast majority of cases it can't do anything of the sort. As an illustration, just take one of your examples: p = Integrate[Sin[a x]/Cos[x], x]; Reduce[Numerator[p]==0,a] Reduce[Numerator[p] == 0, a] This system cannot be solved with the methods available to Reduce. Reduce[(-(a + 1))*Hypergeometric2F1[1/2 - a/2, 1, 3/2 - a/2, -E^(2*I*x)] - (a - 1)*E^(2*I*a*x)* Hypergeometric2F1[(a + 1)/2, 1, (a + 3)/2, -E^(2*I*x)] == 0, a] And even in the purely algebraic cases Reduce can easily take for ever. Or consider this: Reduce[x^3 + Sin[x] == 0, x] During evaluation of In[34]:= Reduce::nsmet : This system cannot be solved with the methods available to Reduce even though anyone can easily see that 0 is a solution (but Reduce is not allowed to return an incomplete solution). The problems with you kind of Integrate would involve all the above and worse. Adnrzej Kozlowski === Subject: Re: ? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) Result from first line is expected plot; result from second line is a > miniaturized plot about 1/4 the size of the first one. * This is sensible or useful? * This is what a novice user should expect as consistent > and reasonable behavior from the above commands? (Print[Plot] doesn't do the same thing with a given Plot > as does Print[----, Plot[], ----] ???) * This is documented --or better, warned about -- where? (since it looks like I'll have to, once again, step aside from > attempting to accomplish anything useful with 6.0 and > burn up more time digging into its arcane documentation, > trying to understand this. Apologies for the sarcasm -- > but that's the way it feels.) > Graphics with ImageSize->Automatic are rendered smaller when they appear > in lists or grids, and even smaller when they appear in text-like > constructs. If you like the default size, you can specify ImageSize->Medium in your plots. The reason for this behavior is that since, in v6, graphics are now first class output objects rather than mere side effects, changing the automatic size based upon context can make it easier to work with them. Imagine, for example, outputting a list or a grid of default-sized graphics and trying to get an idea for the totality of the output while each graphic is still big enough to compete for a standalone-sized portion of the screen. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. === Subject: Re: FrontEnd and JLink I tried the following using Math.EXE, which is much the same as driving the kernel from Java: $FrontEndLaunchCommand=$InstallationDirectory<>Mathematica -mathlink; UseFrontEnd[NotebookCreate[]] I guess you need to wrap all relevant commands in UseFrontEnd. An examination of the JLink source indicates that the default FE launch command uses a -nogui option - so using the default launch command the above command seems to create an invisible notebook object. The only problem with this (depending on your applicatio) is that you get an unnecessary menu bar at the top. Also, you should give it a good test to ensure there are no strange 'features', since I don't suppose many people have used this! Unless you have already written a compled Java GUI, you may like to consider using my Super Widget Package (available free from my site, which creates a Java GUI in a very easy way, and supports a lot of Java features - such as, for example the MDI interface. David Bailey http://www.dbaileyconsultancy.co.uk > I want to create Mathematica graphical objects (notebook with cells, > palettes, plots, etc) from a Java Gui using JLink calls > Apparently, this is not possible until you don't use the > Mathematica.exe frontend > (no way to initialize a frontend from a java gui) hereafter a Java example > Any helps ? laurent > ----------------------------------------------------------------------------- ------- > import com.wolfram.jlink.*; > class Exemple_FrontEnd { > public static void main (String[] args){ try { > KernelLink ml = MathLinkFactory.createKernelLink(-linkmode launch - > linkname MathKernel); > ml.evaluateToInputForm(Needs[ + KernelLink.PACKAGE_CONTEXT + > ],0); > ml.evaluateToInputForm(ConnectToFrontEnd[], 0); > setVisible(True); > ml.evaluate(UseFrontEnd[NotebookCreate[]]); } catch (MathLinkException e) { > e.printStackTrace(); > } > } > } > === Subject: problem during polygon deletion (* I have a bug in my Mathematica program destined for the Wolfram Demonstration Project. Can anyone please give me a hint what I do wrong. The following Mathematica notebook allows the use to create, store and delete polygons. When I hit the delete last vertex button or the delete last polygon button, it works, but I get strange error messages. Any help would be very much appreciated, please send any answers to k a r l s c h e r e r 3 @ y a h o o . c o . n z (without the gaps). Even someone's email address of a person who could help me would be great. Getting desparate. OK, here is the code: *) ClearAll[Global`*]; (* -------------- define the orthogonal grid :---------------- *) lx =30; ly=30;(*size of lattice *) rx=Range[lx]; ry=Range[ly]; (* Tuples[list,n] Cell[TextData[{ generate all possible , Cell[BoxData[ StyleBox[n, TI]], InlineFormula], -tuples of elements from , Cell[BoxData[ StyleBox[list, TI]], InlineFormula] }], TableText] *)lattice = Point[Tuples [{rx,ry}]]; (* -------------- define the isometric grid :---------------- *) d=1 ;(*horizontal grid spacing *) h=Sqrt[3]/2; (* height of triangles*) lx ; ly=10;(*size of lattice *) rx1= Range[0,lx]; ry1 = 2*h* Range[0,ly]; (* Cell[generate all possible pairs of elements from these lists:, TableText] *) lattice1 = Tuples [{rx1,ry1}]; (* lattice 1 *) rx2 = .5 +rx1; ry2= h+ry1; lattice2 = Tuples [{rx2,ry2}]; (* lattice2 *) isolattice = Point[Join[lattice1, lattice2]]; (* -------------- define snap to ortho and isometric grid :---------------- *) osnap[{x_,y_}]:={Floor[x +.5],Floor[y +.5]} isosnap[{p_,q_}]:= With[ {d=Floor[Floor[q+h/2,2 h]-Floor[q+h/2, h]]}, {Floor[p+ (1-d)/2]+d/2,Floor[q+h/2, h]} ] snap[p_]:= If[gridsnap, If[ortho,osnap[p],isosnap[p]], p ] (* --------------manipulate--------------------*) Manipulate[ ClickPane[ Graphics[ { (* ------- draw grid ---------------- *) LightGray, If[grid, If[ortho,lattice,isolattice] ,{} ], (* ------- draw text ---------------- *) Black, {Text[Style[Number of stored polygons:,12],{4,-1}]}, {Text[Style[Length[pols],12],{8.6,-1}]}, {Text[Style[Stored polygons shown:,12],{13.5,-1}]}, {Text[Style[Floor[1/2+ showpols*Length[pols]],12],{17.6,-1}]}, (* -------store a new polygon ---------------- *) If[store, {store=False, If[Length[pts]>0, {pols=AppendTo[pols, pts], polcols=AppendTo[polcols, col1], pts={} }, {}] },{} ], (* ------- draw new points ---------------- *) Black,PointSize[pointsize], Point[pts], (* draw points *) (* ------- draw next polygon ---------------- *) FaceForm[col1], EdgeForm[If[outline,Thin,None]], Opacity[opacity],Polygon[pts], (* ------- draw stored polygons ---------------- *) Table[ If[showpols=B3(i-.5)/Length[pols], {FaceForm[polcols[[i]]],Polygon[pols[[i]]]} ,{}], {i,Length[pols]} ] , (* -------delete current polygon ---------------- *) If[delnew, {delnew=False, pts={} },{} ], (* -------delete all stored polygons ---------------- *) If[delall, {delall=False, pols={},polcols={} },{} ], (* -------delete last vertex of new polygon ---------------- *) If[delvertex, {delvertex=False, If[Length[pts]>0, pts=Delete[pts,-1] ,{}] } ,{}] (* -------delete last shown polygon ---------------- *) If[delmax, {delmax=False, If[Length[pols]>0, With[ {i=Floor[1/2+ showpols*Length[pols]]}, {pols=Delete[pols,i],polcols=Delete[polcols,i]} ],{}] },{}] }, PlotRange=AE{{-.2,18.2},{-2.2, 18.2}} ], (* end graphics *) ( { (* here we act on the mouseclicks (we are in a ClickPane !) *) pts=AppendTo[pts,snap[#]] (* store next vertex *) } )& ], (* end clickpane *) Style[Grid Controls,Bold], {{grid,True,Style[show grid]},{True,False}}, {{ortho,False,Style[ortho grid]},{True,False}}, {{gridsnap,True,Style[snap to gridn]},{True,False}}, Style[Global Polygon Controls,Bold], {{outline,True,Style[outline]},{True,False}}, {{opacity,.7,Style[opacityn]},0,1,ImageSize=AESmall}, Style[Controls For New Polygon,Bold], {{col1,Cyan,Style[face colour]},Red,ControlType=AEColorSlider,ImageSize=AESmall}, {{pointsize,.02,Style[pointsize new polygon,Black]}, 0,.03,ControlType=AESlider,ImageSize=AESmall}, {{delvertex,False,Style[delete last vertex]},{True,False}}, {{delnew,False,Style[delete new polygon]},{True,False}}, {{store,False,Style[store new polygonn,Blue,Bold]},{True,False}}, Style[Controls For Stored Polygons,Bold], {{showpols,1,Style[show stored polygons]},0,1,ImageSize=AESmall}, {{delmax,False,Style[delete last shown]},{True,False}}, {{delall,False,Style[delete all stored]},{True,False}}, {{pols,{}},ControlType=AENone}, {{pts,{}},ControlType=AENone}, {{polcols,{}},ControlType=AENone}, ControlPlacement=AELeft, SaveDefinitions=AETrue ] Manipulate[ ClickPane[ Graphics[ { (* ------- draw grid ---------------- *) LightGray, If[grid, If[ortho,lattice,isolattice] ,{} ], (* ------- draw text ---------------- *) Black, {Text[Style[Number of stored polygons:,12],{4,-1}]}, {Text[Style[Length[pols],12],{8.6,-1}]}, {Text[Style[Stored polygons shown:,12],{13.5,-1}]}, {Text[Style[Floor[1/2+ showpols*Length[pols]],12],{17.6,-1}]}, (* -------store a new polygon ---------------- *) If[store, {store=False, If[Length[pts]>0, {pols=AppendTo[pols, pts], polcols=AppendTo[polcols, col1], pts={} }, {}] },{} ], (* ------- draw new points ---------------- *) Black,PointSize[pointsize], Point[pts], (* draw points *) (* ------- draw next polygon ---------------- *) FaceForm[col1], EdgeForm[If[outline,Thin,None]], Opacity[opacity],Polygon[pts], (* ------- draw stored polygons ---------------- *) Table[ If[showpols=B3(i-.5)/Length[pols], {FaceForm[polcols[[i]]],Polygon[pols[[i]]]} ,{}], {i,Length[pols]} ] , (* -------delete current polygon ---------------- *) If[delnew, {delnew=False, pts={} },{} ], (* -------delete all stored polygons ---------------- *) If[delall, {delall=False, pols={},polcols={} },{} ], (* -------delete last vertex of new polygon ---------------- *) If[delvertex, {delvertex=False, If[Length[pts]>0, pts=Delete[pts,-1] ,{}] } ,{}] (* -------delete last shown polygon ---------------- *) If[delmax, {delmax=False, If[Length[pols]>0, With[ {i=Floor[1/2+ showpols*Length[pols]]}, {pols=Delete[pols,i],polcols=Delete[polcols,i]} ],{}] },{}] }, PlotRange=AE{{-.2,18.2},{-2.2, 18.2}} ], (* end graphics *) ( { (* here we act on the mouseclicks (we are in a ClickPane !) *) pts=AppendTo[pts,snap[#]] (* store next vertex *) } )& ], (* end clickpane *) Style[Grid Controls,Bold], {{grid,True,Style[show grid]},{True,False}}, {{ortho,False,Style[ortho grid]},{True,False}}, {{gridsnap,True,Style[snap to gridn]},{True,False}}, Style[Global Polygon Controls,Bold], {{outline,True,Style[outline]},{True,False}}, {{opacity,.7,Style[opacityn]},0,1,ImageSize=AESmall}, Style[Controls For New Polygon,Bold], {{col1,Cyan,Style[face colour]},Red,ControlType=AEColorSlider,ImageSize=AESmall}, {{pointsize,.02,Style[pointsize new polygon,Black]}, 0,.03,ControlType=AESlider,ImageSize=AESmall}, {{delvertex,False,Style[delete last vertex]},{True,False}}, {{delnew,False,Style[delete new polygon]},{True,False}}, {{store,False,Style[store new polygonn,Blue,Bold]},{True,False}}, Style[Controls For Stored Polygons,Bold], {{showpols,1,Style[show stored polygons]},0,1,ImageSize=AESmall}, {{delmax,False,Style[delete last shown]},{True,False}}, {{delall,False,Style[delete all stored]},{True,False}}, {{pols,{}},ControlType=AENone}, {{pts,{}},ControlType=AENone}, {{polcols,{}},ControlType=AENone}, ControlPlacement=AELeft, SaveDefinitions=AETrue ] === Subject: Re: How to remove unneeded constraints > The problem I am working on is a pretty large problem, which I am solving by dividing it into a lot of subproblems. As such, I have a large list of constraints that apply to the entire problem, but are not relevant for each individual subproblem. This becomes a problem when I use Refine, as it takes a very long time when you have a lot of conditions, even though the conditions don't pertain to the problem. Example: > In[25]:= Table[Timing@Refine[p>q,Map[Subscript[x,#]>0&,Range[i]]],{i,1000,5000,1000}] > Out[25]= {{0.547,p>q},{1.797,p>q},{3.875,p>q},{8.594,p>q},{10.468,p>q}} And it only gets worse. However, for each individual call to Refine I make, I only need a small subset of the total constraints. So what I want to do is something like this: > expr = some expression of n different variables; > cond = DeleteCases[totalConstraints, all cases which do not contain a variable from expr]; > result = Refine[expr,cond]; I have no idea how to construct a pattern powerful enough to do what is required for the DeleteCases call, though. All of the variables are of the form Subscript[s,_,_,_] or Subscript[b,_,_] and the conditions can also contain expressions of several variables. > here is a toy problem I used to test the code below, hope it isn't to simple: expr = Total@ Table[Random[]*ToExpression[x <> ToString[i]]^i, {i, 1, 100, 5}] conditions = Table[ToExpression[x <> ToString[i - 1]] < Random[] < ToExpression[x <> ToString[i]], {i, 1, 100}] This will construct a pattern that matches all variables in expr (maybe you need some fine tuning to extract only those symbols which represent variables in your problem): varpattern = Alternatives @@ Cases[expr, _Symbol,Infinity] Now you can use that pattern to extract the relevant conditions: DeleteCases[conditions, _?(FreeQ[#, varpattern] &)] If you haven't seen this kind of pattern yet, search for PatternTest in the documentation. In cases where a pattern where such a PatternTest using a pure function is necessary, I usually prefere to use Select instead of DeleteCases/Cases, but in this case it isn't much clearer or shorter: Select[conditions, MemberQ[#, varpattern, Infinity] &] hth, albert === Subject: Re: How to remove unneeded constraints > The problem I am working on is a pretty large problem, which I am solving by dividing it into a lot of subproblems. As such, I have a large list of constraints that apply to the entire problem, but are not relevant for each individual subproblem. This becomes a problem when I use Refine, as it takes a very long time when you have a lot of conditions, even though the conditions don't pertain to the problem. Example: > In[25]:= Table[Timing@Refine[p>q,Map[Subscript[x,#]>0&,Range[i]]],{i,1000,5000,1000}] > Out[25]= {{0.547,p>q},{1.797,p>q},{3.875,p>q},{8.594,p>q},{10.468,p>q}} And it only gets worse. However, for each individual call to Refine I make, I only need a small subset of the total constraints. So what I want to do is something like this: > expr = some expression of n different variables; > cond = DeleteCases[totalConstraints, all cases which do not contain a variable from expr]; > result = Refine[expr,cond]; I have no idea how to construct a pattern powerful enough to do what is required for the DeleteCases call, though. All of the variables are of the form Subscript[s,_,_,_] or Subscript[b,_,_] and the conditions can also contain expressions of several variables. Hi Kristian, A possible solution that I would recommend uses *FreeQ[]* for pattern matching and *Pick[]* to build the list of constraints that do not contains the unneeded variables. In[1]:= (* We make an arbitrary list of constraints *) conds = {E^(Subscript[s, 1, 1, 2] + Subscript[b, 3, 1]) > 1, E^(Subscript[s, 1, 1, 3] + Subscript[b, 3, 1])/+Subscript[b, 2, 2] <= 100, Abs[Log[Subscript[s, 1, 1, 3]^Sin[Subscript[b, 1, 2] Pi]]] <= 2}; (* We look for any expression that does not have a variable s for which the third index is 3 *) FreeQ[#, Subscript[s, _, _, 3] ] & /@ conds (*We look for any expression that does not have the variable b with first index equal to 3 *) FreeQ[#, Subscript[b, 3, _] ] & /@ conds (* The returned list does not contain any expression that contains the variable s for which its third index is 3 *) Pick[conds, FreeQ[#, Subscript[s, _, _, 3] ] & /@ conds] (* The following examples should be self-explanatory by now *) Pick[#, FreeQ[#, Subscript[b, ___, 3, ___] ] & /@ #] &@conds Pick[#, FreeQ[#, Subscript[_, 1, 2, ___] ] & /@ #] &@conds Pick[#, FreeQ[#, Subscript[b, 1, 2] | Subscript[s, 1, _, 2]] & /@ #] &@conds Out[2]= {True, False, False} Out[3]= {False, False, True} Out[4]= b + s 3,1 1,1,2 {E > 1} Out[5]= Sin[Pi b ] 1,2 {Abs[Log[s ]] <= 2} 1,1,3 Out[6]= b + s b + s 3,1 1,1,3 3,1 1,1,2 E {E > 1, -------------- <= 100} b 2,2 Out[7]= b + s 3,1 1,1,3 E {-------------- <= 100} b 2,2 -- Jean-Marc === Subject: Re: How to remove unneeded constraints > Hello The problem I am working on is a pretty large problem, which I am solving by dividing it into a lot of subproblems. As such, I have a large list of constraints that apply to the entire problem, but are not relevant for each individual subproblem. This becomes a problem when I use Refine, as it takes a very long time when you have a lot of conditions, even though the conditions don't pertain to the problem. Example: > In[25]:= Table[Timing@Refine[p>q,Map[Subscript[x,#]>0&,Range[i]]],{i,1000,5000,1000}] > Out[25]= {{0.547,p>q},{1.797,p>q},{3.875,p>q},{8.594,p>q},{10.468,p>q}} And it only gets worse. However, for each individual call to Refine I make, I only need a small subset of the total constraints. So what I want to do is something like this: > expr = some expression of n different variables; > cond = DeleteCases[totalConstraints, all cases which do not contain a variable from expr]; > result = Refine[expr,cond]; I have no idea how to construct a pattern powerful enough to do what is required for the DeleteCases call, though. All of the variables are of the form Subscript[s,_,_,_] or Subscript[b,_,_] and the conditions can also contain expressions of several variables. The following should work if the constraints are just a linear concatenation of equations/inequalities: In[1]:= expr = Subscript[a, 1] + Subscript[a, 2] Subscript[a, 3] Out[1]= Subscript[a, 1] + Subscript[a, 2] Subscript[a, 3] In[2]:= constraints = And @@ (Subscript[a, #] > 0 & /@ Range[5000]); In[3]:= Timing[ filteredConstraints = With[ {relevantVariables = Union@Cases[expr, Subscript[__], Infinity]}, Select[constraints, ! FreeQ[#, Alternatives @@ relevantVariables] &] ] ] Out[3]= {0.047, Subscript[a, 1] > 0 && Subscript[a, 2] > 0 && Subscript[a, 3] > 0} In[4]:= Refine[expr > 0, filteredConstraints] // Timing Out[4]= {0., True} In[5]:= Refine[expr > 0, constraints] // Timing Out[5]= {10.797, True} === Subject: Exclusions I'm having a little trouble with the use of Exclusions for plotting. If I use Exclusions -> Automatic in the following, Plot3D finds no exclusions. pdfN[{x_, y_} := PDF[MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}], {x, y}]; grayColors = Function[{x, y, z}, (Lighter[Gray, #] &)[z]]; Plot3D[ pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, Exclusions -> Automatic, ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, AxesLabel -> {x, y}] However, if I try to exclude a cross-section through the mean of the distribution asin the following, as well as my defined Exclusions, I get an exclusion drawn at {y == 0, x < 0}, even though I have used inequalities to exclude y == 0 from my Exclusions. Plot3D[ pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, Exclusions -> {{ArcTan[x, y] == 0.5, x > 0 && y > 0}, {ArcTan[x, y] == -Pi + 0.5, x < 0 &7 y < 0}}, ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, AxesLabel -> x, y}] Can anyone see a way that I can avoid this? === Subject: Re: Exclusions > I'm having a little trouble with the use of Exclusions for plotting. If I use Exclusions -> Automatic in the following, Plot3D finds no > exclusions. pdfN[{x_, y_} := PDF[MultinormalDistribution[{0, 0}, {{1, 0}, {0, Syntax error: a square bracket is missing. ------------------------------------------ > 1}}], {x, y}]; grayColors = Function[{x, y, z}, (Lighter[Gray, #] &)[z]]; Plot3D[ pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, > Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, > Exclusions -> Automatic, > ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, > AxesLabel -> {x, y}] However, if I try to exclude a cross-section through the mean of the > distribution asin the following, as well as my defined Exclusions, I > get an exclusion drawn at {y == 0, x < 0}, even though I have used > inequalities to exclude y == 0 from my Exclusions. Plot3D[ pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, > Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, > Exclusions -> {{ArcTan[x, y] == 0.5, x > 0 && y > 0}, {ArcTan[x, y] > == -Pi + 0.5, x < 0 &7 y < 0}}, Very likely typo: should be double ampersand sign if logical AND is intended. As written, you check whether the product of a pure function by seven times y is less than zero. ---------------------------------------------------------------------- > ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, > AxesLabel -> x, y}] Syntax error: a curly bracket is missing. ----------------------------------------- > Can anyone see a way that I can avoid this? > Exclusions -> Automatic excludes subregions associated with discontinuities. Since the function you posted is continuous, why do you expect to get any exclusion with this setting? Anyway, you may be more interested in the option *RegionFunction*, which specifies the region to include in the plot drawn. You will find below a syntacticly correct version of your code. Needs[MultivariateStatistics`] pdfN[{x_, y_}] := PDF[MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}], {x, y}]; Plot3D[pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}] grayColors = Function[{x, y, z}, (Lighter[Gray, #] &)[z]]; Plot3D[pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, Exclusions -> Automatic, ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, AxesLabel -> {x, y}] Plot3D[pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, Exclusions -> {{ArcTan[x, y] == 0.5, x > 0 && y > 0}, {ArcTan[x, y] == -Pi + 0.5, x < 0 && y < 0}}, ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, AxesLabel -> {x, y}] -- Jean-Marc === Subject: Re: Exclusions On Apr 22, 2:39 am, Jean-Marc Gulliet My first post here - I have discovered the limitations of copying and pasting. In my notebook, the syntax is correct. I don't expect an automatic exclusion, but I do get an additional (unwanted) exclusion at y==0 && x<0 when I use the following command: Plot3D[ pdfN[{x, y}], {x, -3, 3}, {y, -3, 3}, PlotRange -> Full, Mesh -> 30, ColorFunction -> grayColors, PlotPoints -> 50, ClippingStyle -> None, Exclusions -> { {ArcTan[x, y] == 0.5, x > 0 && y > 0}, {ArcTan[x, y] == -Pi + 0.5, x < 0 && y < 0}}, ExclusionsStyle -> {None, Directive[Thick, Red]}, MaxRecursion -> 0, AxesLabel -> {x, y}] === Subject: Re: Sorting 3 points p = {P1,P2,P3}; Sort[p, #1[[3]] < #2[[3]] &] Sort[p, Last[#1] < Last[#2] &] Bob Hanlon > Simple question, but documentation is no help. > I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function > === Subject: Re: Hamiltonian System with NDSolve I already tried that, and the problem still remains. Any other thoughts? === Subject: Re: Tilted decimals - Mathematica 6 Perhaps David Park has replied directly to you, but in case not... Point your browser to his Mathematica Page: http://home.comcast.net/~djmpark/Mathematica.html Scroll down to the section Packages for Sale. Click the link Presentations/DrawGraphics. At the bottom of the target page, click the link Purchase Presentations/DrawGraphics Package. It will take you to kagi.com, where you can place your order. The package you want is the first one, confusingly listed as DrawGraphics Mathematica Package. But if you order that, then you can download either the Mathematica 6.0-compatible Presentations package or else the earlier DrawGraphics package. (Kagi is similar to PayPal. You pay kagi.com by credit card, etc. You do NOT need any prior kind of account on kagi.com) I would like to send the following mail directly to you > ( djmpark@comcast.net, since Monday 14 April) > but I get always the following Message: Mailbox disabled for this recipient. Could you kindly tell me how to reach you ? Gianfranco Zosi > Dip. Fisica Generale > Universita di Torino I am ready to transfer 50 $ to you, but the link to Wolfram is not > clear at all, i.e., I have not seen any instruction for > Purchase Presentations Package. > Can I send them directly to you, through my Visa Card ? > Gianfranco PS I do not see in your exmaple, at least explicitly, the angle alpha Pi/6. > Here is one solution using the CustomTicks function from the Presentations > package. We also need to use NumberForm to extend the display precision, > otherwise all the numbers will be the same. Needs[Presentations`Master`] With[ > {xticks = CustomTicks[Identity, {123.45678, 123.45679, .000002, 5}, > CTNumberFunction - (Graphics[ > Text[Style[NumberForm[#, {9, 6}], 12], {0, 0}, {-1, 0}, {0, > 1}], > AspectRatio -> 6, > ImageSize -> {10, 60}] &)], > yticks = CustomTicks[Identity, {123.45678, 123.45679, .000002, 5}, > CTNumberFunction -> (NumberForm[#, {9, 6}] &)]}, > Draw2D[ > {Draw[x, {x, 123.45678, 123.45679}]}, > AspectRatio -> 1/GoldenRatio, > Frame -> True, > FrameTicks -> {{yticks, Automatic}, {xticks, > xticks // NoTickLabels}}, > FrameLabel -> {x, y}, > BaseStyle -> {FontSize -> 12}] > ] However, that rather violates the principle: Maximize the information, > minimize the ink. 123.45678 is repeated 12 times! In technical publication > the tick labels themselves are usually simplified and the functional > relation between the tick values and the quantity is put in the frame > labels. Here the tick labels go from 0 to 1 on the x and y axes. With[ > {ticks = CustomTicks[#/105 + 123.45678 &, {0, 1, .2, 5}]}, > Draw2D[ > {Draw[x, {x, 123.45678, 123.45679}]}, > AspectRatio -> 1/GoldenRatio, > Frame -> True, > FrameTicks -> {{ticks, ticks // NoTickLabels}, {ticks, > ticks // NoTickLabels}}, > FrameLabel -> {(x-123.45678)!(*SuperscriptBox[10, 5]), > (y-123.45678)!(*SuperscriptBox[10, 5])}, > BaseStyle -> {FontSize -> 12}] > ] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >> How can I see all the decimals on the x-axis **and** avoid overlapping ? >> Trivial example: Plot[x, {x, 123.45678, 123.45679}] >> I would like to rotate clockwise by an angle alpha (e.g.,Pi/6, or >> Pi/2+Pi/6) >> the values on the x-axis and translate them in order to see the starting >> point, >> i.e., the 1 of 123.45678 should be near to the relevant tick. >> Note: I cannot use the usual Options to reduce the **size** of the >> figures or >> increase the size of the image. >> Any hint ? >> PS The nice suggestion by Ruskeepaa (pag. 271) seems not applicable in >> this case. >> Gianfranco Zosi >> Dip. Fisica Generale >> Universita di Torino > -- 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: Tilted decimals - Mathematica 6 I would like to send the following mail directly to you ( djmpark@comcast.net, since Monday 14 April) but I get always the following Message: Mailbox disabled for this recipient. Could you kindly tell me how to reach you ? Gianfranco Zosi Dip. Fisica Generale Universita di Torino I am ready to transfer 50 $ to you, but the link to Wolfram is not clear at all, i.e., I have not seen any instruction for Purchase Presentations Package. Can I send them directly to you, through my Visa Card ? Gianfranco PS I do not see in your exmaple, at least explicitly, the angle alpha Pi/6. Here is one solution using the CustomTicks function from the Presentations package. We also need to use NumberForm to extend the display precision, otherwise all the numbers will be the same. Needs[Presentations`Master`] With[ {xticks = CustomTicks[Identity, {123.45678, 123.45679, .000002, 5}, CTNumberFunction -> (Graphics[ Text[Style[NumberForm[#, {9, 6}], 12], {0, 0}, {-1, 0}, {0, 1}], AspectRatio -> 6, ImageSize -> {10, 60}] &)], yticks = CustomTicks[Identity, {123.45678, 123.45679, .000002, 5}, CTNumberFunction -> (NumberForm[#, {9, 6}] &)]}, Draw2D[ {Draw[x, {x, 123.45678, 123.45679}]}, AspectRatio -> 1/GoldenRatio, Frame -> True, FrameTicks -> {{yticks, Automatic}, {xticks, xticks // NoTickLabels}}, FrameLabel -> {x, y}, BaseStyle -> {FontSize -> 12}] ] However, that rather violates the principle: Maximize the information, minimize the ink. 123.45678 is repeated 12 times! In technical publication the tick labels themselves are usually simplified and the functional relation between the tick values and the quantity is put in the frame labels. Here the tick labels go from 0 to 1 on the x and y axes. With[ {ticks = CustomTicks[#/105 + 123.45678 &, {0, 1, .2, 5}]}, Draw2D[ {Draw[x, {x, 123.45678, 123.45679}]}, AspectRatio -> 1/GoldenRatio, Frame -> True, FrameTicks -> {{ticks, ticks // NoTickLabels}, {ticks, ticks // NoTickLabels}}, FrameLabel -> {(x-123.45678)!(*SuperscriptBox[10, 5]), (y-123.45678)!(*SuperscriptBox[10, 5])}, BaseStyle -> {FontSize -> 12}] ] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >> >> How can I see all the decimals on the x-axis **and** avoid overlapping ? >> >> Trivial example: Plot[x, {x, 123.45678, 123.45679}] >> >> I would like to rotate clockwise by an angle alpha (e.g.,Pi/6, or >> Pi/2+Pi/6) >> the values on the x-axis and translate them in order to see the starting >> point, >> i.e., the 1 of 123.45678 should be near to the relevant tick. >> >> Note: I cannot use the usual Options to reduce the **size** of the >> figures or >> increase the size of the image. >> >> Any hint ? >> >> PS The nice suggestion by Ruskeepaa (pag. 271) seems not applicable in >> this case. >> >> Gianfranco Zosi >> Dip. Fisica Generale >> Universita di Torino >> === Subject: Re: DifferenitalD vs CapitalDifferenitalD After applying Jens correction, I was hoping to be able to use the DifferentialD with x, etc. and then use the 'dx' , where 'd' here is DifferentialD (just dont know how to add it here in the email), so it would be a Symbol....but this didnt work....I realize I can use the straight forward dx , etc. symbol but I want to highlight the Differential....any way to 'fix' this?....when I type in DifferentialD , from the Palette, and then add x to it and perform //Head on it , it just returns DifferentialD thank you....jerry blimbaum ----- Original Message ----- === Subject: Re: DifferenitalD vs CapitalDifferenitalD this is a bug, add MakeBoxes[DifferentialD[x_], fmt_] := RowBox[{[DifferentialD], ToBoxes[x, fmt]}] Jens > The documentation for DifferenitalD states: DifferenitalD[x] displays as dx , where instead of d appears the > smybol entered as esc dd esc (without the spaces). Yet when I > enter DifferentialD[x] and evaluate I get back DifferenitalD[x] (not > esc dd esc x ). The documentation for CapitalDifferentialD seems identical to that for > DifferentialD. Yet when I enter CapitalDifferentialD[x] I get Dx > where D is the symbol entered as esc DD esc. Moreover, esc dd esc x evaluates to DifferenitalD[x] but esc DD esc > x evaluates to esc DD esc x. It is all so confusing I feel like giving up on Mathematica > typesetting altogether. Can anyone explain what is going on here? This is with $Version > 6.0 for Mac OS X x86 (64-bit) (March 13, 2008) > $ReleaseNumber > 2 Andrzej Kozlowski > === Subject: Vector valued differential equations I lately asked if it is possible to write differential equations of vector valued functions without having to explicitely write all components. For the following cases it can be done very easily: Assume we are looking for a vector valued function y[t]={y1[t],y2[t]..,ym[t]}. To begin with, assume further that we have a first order differential equations that can be written explicitly as: y1'= f1[t,y]; y2'=f2[t,y],..,fm[t,y] then with F[t_,y_?VectorQ]:={f1[t,y],f12[t,y],..} where VectorQ ensure that the function is not called with symbolic arguments. With initial conditions y0={y10,y20,..} we can write the DE like: eq={y'[t]==F[t,y[t]], y[0]==y0}; NDSolve[eq,y[t],{t,0,tend}] If we have a n-th order DE, we may use the same trick. We now have: y1'= f11[t,y,y'..]; y2'=f21[..];..;ym'=fm1[..]; y1''=f12[..];..;ym''=fm2[..]; .... y1((n-1) derivative))= f1(n-1)[..];..;ym((n-1)derivative)=fm(n-1)[..] instead of y we have: f={y1,y2,..,y1',y2',..,(n-1)derivative of y1,..} with F and initial conditions f0: F[t_,f_?VectorQ]:={f11,f21,..,fm1,f21,f22,..,fm2,..,f1(n-1)} f0={y1[0],..,ym[0],y1'[0],..,(n-1)drivative of fm[0]} the DE can be written: eq={f'[t]==F[t,f[t]], f[0]==f0}; NDSolve[eq,y[t],{t,0,tend}] Here is a simple example, the 2-dim Kepler problem: f0={10,0,0,0.18};(*{x,y,vx,vy}*) tend=80; F[p_?VectorQ]:=({p[[3]],p[[4]],-p[[1]]/(p[[1]]^2+p[[2]]^2)^(3/2),-p[[2]]/(p[ [1]]^2+p[[2]]^2)^(3/2)}); eq={f'[t]==F[f[t]],f[0]==f0}; sol4=f[t]/.NDSolve[eq,f[t],{t,0,tend}][[1]]; ParametricPlot[{sol4[[1]],sol4[[2]]},{t,0,tend},Mesh->True] Daniel === Subject: Re: Comments on the .m file editor > I don't see the advantages of writing package with the .m file editor. > Normally I don't even look at the .m file. I would be interested in hearing > comments from some of the sophisticated users about when writing .m files > directly might be advantagous. Normally a routine should be written and debugged in a regular Mathematica > ..nb notebook. A debugging method that works for almost all cases and is very > easy to use is just to insert temporary Print statements into the routine. When a routine is debugged, and a usage message and SyntaxInformation are > written it can just be moved to a package.nb notebook with Initialization > cells that has been saved as an Auto Generated Package. That is by far the easiest method. You can put (* comments *) anywhere in a Mathematica expression but one very > negative feature of Mathematica is that if one uses Shift-Ctrl-N or > Shift-Ctrl-I to convert and reformat a cell it strips out all the comments. > I think comments should be considered a permanent part of an expression and > never stripped out by such reformating. > I find there are lots of advantages to having computer code in a simple text file. It makes it easy to use utilities like grep and file comparators, or to create your own utilities - such as a code indenter that works to your personal whim! The ability to skip to a particular function or section is also convenient. The time I must have wasted debugging AutoGenetated Page's in which one cell was accidentally not marked as Initialisation - editing one file is so much nicer. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Comments on the .m file editor > Since the .m is in plaintext (let's not go into how a .nb is > also plaintext), it is easier to run commands like unix's diff on > the code tree to see what changed. In order for this to work right, > the .m file must be indented in a way that promotes readability... That reminds me: the .m file editor doesn't have any sort of indenting features! At the very very least, padding out a newline with the same leading spaces as the previous line would make life so much easier. Also, if people don't want constructions like [alpha] cluttering up their diffs, they are more than free to use basic ascii for their code. The reason that I started using the .m file editor to write packages is because the documentation lead me there. I've heard of initialisation cells and auto-generated packages, but it all seemed (at the time) like black magic compared to opening up the package and editing it. > I don't see the advantages of writing package with the .m file editor. > Normally I don't even look at the .m file. Can you use the interactive debugger with notebooks? The only reason I want to stick with the .m file editor is that you can insert outline comments anywhere in the code. This allows much more flexible code commenting. Actually, I'm considering writing my Mathematica code in LaTeX's docstrip format, but it would lack some of the niceties of doing everything within Mathematica's frontend. You wouldn't want to look in an auto-generated .m file. It's not a pretty sight. But a handwritten one is as easy to read as a notebook, modulo the nice symbols and typesetting=85 Will === Subject: Re: Problems to find the local extrema of an InterpolatingFunction As an unexperienced mathematica user, now I am just wondering how I can get full information on the explicit form of piecewise polynomials generated by Interpolation[] from a given set of points. What kind of algorithm does Interpolation use? I know e.g. that the default interpolation order is 3, but I'd like to know if it's a natural spline or what exactly is the default output. === Subject: Converting Power terms to Times terms I am using Dolfin/FFC for solving finite element problems. I want to use Mathematica for generating the linear and bilinear terms of the weak equation. After computing the terms, I use the InputForm, and then give the results to FFC compiler. The problem is that FFC does not accept power function. Therefore, terms such as a^2 must be written as a*a. Because there are many terms in the weak form of my problem, manual conversion of power terms takes a long time (and probably is subject to errors). Is there any way to disable power function, or stop times function to be simplified in the power form? Any other solution? Reza === Subject: Re: Converting Power terms to Times terms no, but you can redefine the output of Power[], so that it look like a*a*a, i.e. Unprotect[Power] Format[Power[a_, n_Integer], FortranForm] := (HoldForm @@ {Table[a, {n}]}) /. List -> Times Protect[Power] and FortranForm[a*b^4*Sin[w^2]] gives a*(b*b*b*b)*Sin(w*w) Jens I am using Dolfin/FFC for solving finite element problems. I want to use Mathematica for generating the linear and bilinear terms of the weak equation. After computing the terms, I use the InputForm, and then give the results to FFC compiler. The problem is that FFC does not accept power function. Therefore, terms such as a^2 must be written as a*a. Because there are many terms in the weak form of my problem, manual conversion of power terms takes a long time (and probably is subject to errors). Is there any way to disable power function, or stop times function to be simplified in the power form? Any other solution? Reza === Subject: Re: Converting Power terms to Times terms Hello Reza, Perhaps CForm or FortranForm may get you close? I don't know what dolfin/fcc syntax looks like. I used to solve problems like this by doing fancy editing tricks on the output. But that was Math version 1. Best Wishes, Craig I am using Dolfin/FFC for solving finite element problems. I want to use Mathematica Is there any way to disable power function, or stop times function to be simplified in the power form? -- W. Craig Carter === Subject: Re: Converting Power terms to Times terms Hi Reza, we may prevent Power to gobble up terms by e.g. converting the terms into a string. If you then copy the resulting expression to the clipboard as plain text the quotes are not copied. Here is an example: (1+a)^3+(1-a)^5/.Power[x_,n_Integer]:>Nest[#<>*(<>ToString[x]<>)&, 1,n] there is an superfluous 1* that will not hurt. hope this helps, Daniel I am using Dolfin/FFC for solving finite element problems. I want to use Mathematica for generating the linear and bilinear terms of the weak equation. After computing the terms, I use the InputForm, and then give the results to FFC compiler. The problem is that FFC does not accept power function. Therefore, terms such as a^2 must be written as a*a. Because there are many terms in the weak form of my problem, manual conversion of power terms takes a long time (and probably is subject to errors). Is there any way to disable power function, or stop times function to be simplified in the power form? Any other solution? Reza === Subject: Re: problem accessing notebooks Dietmar === Subject: need help with Plot I have the following situation. f[z_,t_]=some function sol=Solve[f[z,t]==0,{z}] This returns {{z->sol1[t]},{z->sol2[t]},{z->sol3[t]},{z->sol4[t]}} I want to plot Plot[Select[{sol1[t],sol2[t],sol3[t],sol4[t]},#>t&] But it doesn't plot correctly. Depending on t, Select returns either 2 or 4 values. Plot correctly plots only the sections for which Select returns 2 values (it plots two curves), and doesn't plot anything for the interval for t, in which Select returns 4 values. Can anyone help to fix this? I should also mention, that if I restrict t to only the interval where Select returns 4 values, Plot correctly plots 4 curves. === Subject: Re: need help with Plot Plot can not deal with a varying number of functions. But as a work around you may define new functions that are zero where you do not want them to draw. As dirty trick, you may instead of returning zero, you may return a symbol. In version 6, this has the effect, that this part is not drawn. Here an example with zero: sol=4 t{Sin[2Pi t],1.2 Sin[ 2.2 Pi t],1.4Sin[ 2.4Pi t], Sin[2.6Pi t]}; {sol1[t_],sol2[t_],sol3[t_],sol4[t_]}=If[# sol=Solve[f[z,t]==0,{z}] > This returns > {{z->sol1[t]},{z->sol2[t]},{z->sol3[t]},{z->sol4[t]}} > I want to plot > Plot[Select[{sol1[t],sol2[t],sol3[t],sol4[t]},#>t&] > But it doesn't plot correctly. Depending on t, Select returns either 2 or 4 values. Plot correctly plots only the sections for which Select returns 2 values (it plots two curves), and doesn't plot anything for the interval for t, in which Select returns 4 values. > Can anyone help to fix this? I should also mention, that if I restrict t to only the interval where Select returns 4 values, Plot correctly plots 4 curves. === Subject: Re: DifferenitalD vs CapitalDifferenitalD The way this started was an Instructor friend is teaching a course in Fields. He asked me why I use Mathematica rather then another product. I explained and told him I would show him some examples. One example I chose was to determine the Directional Derivative. Well, this involves differentials. I merely wanted to 'highlight' the differential visually. I wasnt trying to use DifferentialD as an operator. Of course, I have seen DifferentialD often enough in integrals. I was 'hoping' I could also use it this other way. for example, the element of path length , ds = Sqrt[dx^2 + dy^2 ] I would have preferred that I could type all the 'd's here as DifferentialD and, of, course solve for DifferentialDs if I knew the other differentials. But that was exactly what I couldnt do....In principle there is nothing 'wrong' with simply ds, dx, etc...I just wanted a different 'visual' on the screen. > After applying Jens correction, I was hoping to be able to use the > DifferentialD with x, etc. and then use the 'dx' , where 'd' here is > DifferentialD (just dont know how to add it here in the email), so it > would be a Symbol....but this didnt work....I realize I can use the > straight forward dx , etc. symbol but I want to highlight the > Differential....any way to 'fix' this?....when I type in DifferentialD > , from the Palette, and then add x to it and perform //Head on it , it > just returns DifferentialD thank you....jerry blimbaum > [DifferentialD]x cannot be used as a symbol because [DifferentialD] is treated as an operator. A symbol name must start with a letter. But why do you want to use [DifferentialD]x as a symbol anyway? I cannot imagine any reasonable application for this. If you explained your motivation for wanting to have a symbol with this name, perhaps we could say something more useful ... === Subject: Re: Sorting 3 points > Simple question, but documentation is no help. > I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function > Sort[{P1,P2,P3},#1[[3]]<#2[[3]]&] Ssezi === Subject: Re: Sorting 3 points Three possible solutions: In[1]:= Reverse[SortBy[{{2, 3, 1}, {3, 5, 8}, {5, 1, 6}}, Last]] Out[1]= {{3, 5, 8}, {5, 1, 6}, {2, 3, 1}} In[2]:= SortBy[{{2, 3, 1}, {3, 5, 8}, {5, 1, 6}}, Last[-#1] & ] Out[2]= {{3, 5, 8}, {5, 1, 6}, {2, 3, 1}} In[3]:= Sort[{{2, 3, 1}, {3, 5, 8}, {5, 1, 6}}, #1[[3]] > #2[[3]] & ] Out[3]= {{3, 5, 8}, {5, 1, 6}, {2, 3, 1}} Adriano Pascoletti > Simple question, but documentation is no help. > I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function === Subject: Re: Sorting 3 points Carlos, This is the last of the 'basic examples' from the Help on Sort: In: Sort[{{a,2},{c,1},{d,3}},#1[[2]]<#2[[2]]&] Out: {{c,1},{a,2},{d,3}} The sorting function is #1[[2]]<#2[[2]]& It should be easy to work out from this what you have to modify in this sorting function to achieve the results you want. Maarten carlos@Colora cc: === 21/04/2008 Subject: Sorting 3 points 09:21 Simple question, but documentation is no help. I have three coordinate triplets: P1={x1,y1,z1} P2={x2,y2,z2} P3={x3,y3,z3} where all entries are numeric. I wont to sort them into P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3} so that zs3>=zs2>=zs1, with one command {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function] Is that possible and if so, which Ordering Function === Subject: Dynamic: feature? I have a cell containing this: Dynamic[f[a, b]] Then I do this: a /: f[a, b] = 12 and the dynamic cell updates to 12, as I would expect. When I do this: b /: f[a, b] = 45 The dynamic cell does *not* update for some reason. It seems as though it does not realize an update has occurred when it is associated with b. Does anyone know why this is? Chris === Subject: Re: axis alignment of 3D plots with ListContourPlot3D I'd say that in a closer-to-ideal world, you *would* be limited to the options listed in the Documentation Centre. /snark CO > Hi Jean-Marc and Craig, mathematica newbie I didn't know the Options command to view all options, > and thought I was limited to the options you see for each command in the Jess > === Subject: Re: axis alignment of 3D plots with ListContourPlot3D Hi Jean-Marc and Craig, mathematica newbie I didn't know the Options command to view all options, and thought I was limited to the options you see for each command in the Jess > Hello Jess, > This will work, it is not efficient, but fairly straightforward to > modify for you own purposes: data = Table[{Sin[RandomReal[{-x, x}]], Cos[RandomReal[{-x, x}]], > Cos[ x]}, {x, 0, 1, .01}]; plot = ListPlot3D[data] Show[myplot, > ViewPoint -> r {Cos[theta] Sin[phi], Sin[theta] Sin[phi], Cos[phi]}] > (*here I use spherical coordinates, but the choice is yours) (* > You can also program your own flight trajectory and speed > *) > Can anyone tell me how I can manually the view angle of a > ListContourPlot3D? Mathematica seems to automatically set the view > angle according to the data distribution. I need to do this because I > am generating a series of 3D graphics with ListContourPlot3D, which I > then animate into a AVI movie using the export command. As the > distribution changes shape significantly in each image, Mathematica > automaitcally shifts the view angle substantially, which unfortunately > makes the resulting animation appear to shake as the view angle > changes. > Jess > > -- > W. Craig Carter > === Subject: installing Player Pro killed using Mathematica itself: BEWARE! With an existing installation of Mathematica 6.0.2 under Windows, I just installed Player Pro. The result: if I start Mathematica itself and open a new notebook there, I am prohibited from typing any and all input. This sort of thing is intolerable! An utterly time-frittering aggravation. I suspect that the scenario involved here was not tested by WRI: My mathpass for Mathematica itself is in the Licensing subdirectory of my USERBASE directory, which is the same as my BASE directory (both set by Windows environment variables MATHEMATICA_BASE and MATHEMATICA_USERBASE). This is hardly the first time I have run into trouble with multiple passwords from multiple Wolfram Research products. It is something they have just not yet gotten right. Beware! What I did as a temporary fix was to use my Windows backup program to restore my pre-existing mathpass file. Now regular Mathematica works. But of course Player Pro does not. -- 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: Column Product of a Matrix of zeros and 1's >I have a matrix of zero's and ones: myGlobalMatrix; also a set >called thisSet with the columns of myGlobalMatrix which have to be >multiplied (e.g. column 1,3,4). I would like to know the positions >of the 1's. I do this as follows: >Flatten[Position[Product[myGlobalMatrix[[All,i]],{i, thisSet}],1]] >But this is to general. It does not use that the matrix consists of >zeros and ones. Can this be taken into account? with friendly I am unclear as to what you are trying to accomplish. If myGloblMatrix consists of just ones and zeros, then probably the fastest way to locate all of the ones would be Most@ArrayRules@SparseArray@myGlobalMatricx It looks like the code you have above locates all rows of myGlobalMatrix where the first thisSet columns are 1 If this is what you want, then one way would be Position[Clip[Total/@(myGlobalMatrix[[All,;;thisSet]]),{thisSet,thisSet},{0= ,1}],1] Here, I assume you are using verision 6.x === Subject: waveform I'm new to the audio functions of Mathematica, and I'd like to create a waveform that is a sine wave of whose frequency increasing linearly over time. Does anybody know a way to do this? Jack === Subject: Re: Print[Plot] vs Print[text,Plot]? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) Result from first line is expected plot; result from second line is a > miniaturized plot about 1/4 the size of the first one. * This is sensible or useful? * This is what a novice user should expect as consistent > and reasonable behavior from the above commands? (Print[Plot] doesn't do the same thing with a given Plot > as does Print[----, Plot[], ----] ???) * This is documented --or better, warned about -- where? (since it looks like I'll have to, once again, step aside from > attempting to accomplish anything useful with 6.0 and > burn up more time digging into its arcane documentation, > trying to understand this. Apologies for the sarcasm -- > but that's the way it feels.) This is controlled by the option ImageSizeMultipliers, which can be changed at different levels if you want to. E.g., SetOptions[EvaluationNotebook[], ImageSizeMultipliers -> {1, 1}] {Plot[x, {x, 0, 1}], xxx} Maxim Rytin m.r@inbox.ru === Subject: Re: Print[Plot] vs Print[text,Plot]? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) Result from first line is expected plot; result from second line is a > miniaturized plot about 1/4 the size of the first one. * This is sensible or useful? the default for ImageSize is Automatic, so I think it is sensible that the ImageSize is determined automatically, depending on what is to be shown. Whether or not the size in the second case is too small or not is a rather useless discussion. If you want a definite size for your plot use ImageSize to set it. > * This is what a novice user should expect as consistent > and reasonable behavior from the above commands? (Print[Plot] doesn't do the same thing with a given Plot > as does Print[----, Plot[], ----] ???) There are plenty of cases where mathematica does things automagically, so I think it is something that even a novice user will get used to and probably even appreciates. Just think about the automatic choosing of plotranges, plotstyles, ... I, for my part, am quite happy that I only have to mess around with these if the automatisms don't work well enough... > * This is documented --or better, warned about -- where? (since it looks like I'll have to, once again, step aside from > attempting to accomplish anything useful with 6.0 and > burn up more time digging into its arcane documentation, > trying to understand this. Apologies for the sarcasm -- > but that's the way it feels.) Specifications for both width and height can be any of the following: * Automatic determined by location or other dimension (default) * Tiny, Small, Medium, Large pre-defined absolute sizes ... I have never felt the need to read this in the documetation. Maybe you should just take the advantage that mathematica lets you work interactivley: try things out and accept that things are like they are. If you don't like the program or some of it's features, don't use them. There are alternatives and the old versions, and what you could do with them mostly still works with version 6. hth, albert === Subject: Re: Print[Plot] vs Print[text,Plot]? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) Result from first line is expected plot; result from second line is a > miniaturized plot about 1/4 the size of the first one. * This is sensible or useful? * This is what a novice user should expect as consistent > and reasonable behavior from the above commands? (Print[Plot] doesn't do the same thing with a given Plot > as does Print[----, Plot[], ----] ???) * This is documented --or better, warned about -- where? (since it looks like I'll have to, once again, step aside from > attempting to accomplish anything useful with 6.0 and > burn up more time digging into its arcane documentation, > trying to understand this. Apologies for the sarcasm -- > but that's the way it feels.) I am agree absolutely. And the solution is not so obvious as one can expect. To change this behavour you need to modify the option ImageSize inside Plot[] command. This option specifies the width of the image in pixels when only one numerical argument is passed: plot = Plot[Sin[x], {x, 0, 6 Pi}, ImageSize -> 300]; And you can not control the size of the image with Graphics[Plot[], ImageSize -> 300]. This does not work. http://mathforum.org/kb/message.jspa?messageID=6184854&tstart=15 === Subject: Re: Print[Plot] vs Print[text,Plot]? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) You do not need print for this. Here are some ways to do it using PlotLabel or Labeled, and GraphicsRow, GraphicsColumn, or GraphicsRid. Plot[Sin[x], {x, 0, 2 [Pi]}, PlotLabel -> Some text] Labeled[Plot[Sin[x], {x, 0, 2 [Pi]}], Some text, Top] Labeled[Plot[Sin[x], {x, 0, 2 [Pi]}], Some text, Bottom] GraphicsRow[{Plot[Sin[x], {x, 0, 2 [Pi]}, PlotLabel -> Plot 1], Plot[Cos[x], {x, 0, 2 [Pi]}, PlotLabel -> Plot 2]}] Labeled[GraphicsGrid[{{Plot[Sin[x], {x, 0, 2 [Pi]}, PlotLabel -> Plot 1], Plot[Cos[x], {x, 0, 2 [Pi]}, PlotLabel -> Plot 2]}, {Plot[Tan[x], {x, 0, 2 [Pi]}, PlotLabel -> Plot 3], Plot[Cot[x], {x, 0, 2 [Pi]}, PlotLabel -> Plot 4]}}], My plots, Top] Incidentally, you will usually get better answers here if you post specific Mathematica code that others can copy/paste into a notebook and execute, so that they don't have to make up examples for you. -- Helen Read University of Vermont === Subject: Re: Print[Plot] vs Print[text,Plot]? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) Getting precise control of the size and position of graphics objects -- such as Column, Row, GraphicsRow, GraphicsColumn, Inset, etc. For instance, the above example can be written Column[{Some text, Plot[Sin[x], {x, 0, 10}]}] The output should be more of your liking. (Note that we have not use any of the available options.) Print is of really use when one wants to display some information within a loop or block structure. Do[Print[Column[{Some text, Plot[Sin[x], {x, 0, 10}]}]]; Print[Some other text], {3}] -- Jean-Marc === Subject: Re: Print[Plot] vs Print[text,Plot]? > I've just executed a test cell containing Print[Plot[---]]; > Print[Some textn, Plot[---]]; (same simple plot in both lines; objective of 2nd line being to get the > text and the plot -- eventually several plots -- into the same output > cell) Result from first line is expected plot; result from second line is a > miniaturized plot about 1/4 the size of the first one. * This is sensible or useful? Yes, I think that it is useful that Mathematica descreases the size of graphics inlined in text. The same thing happens when you start typing in a cell that already contains a single graphic. In my subjective opinion, it would be really annyoing if the size weren't decreased automatically. * This is what a novice user should expect as consistent > and reasonable behavior from the above commands? (Print[Plot] doesn't do the same thing with a given Plot > as does Print[----, Plot[], ----] ???) * This is documented --or better, warned about -- where? (since it looks like I'll have to, once again, step aside from > attempting to accomplish anything useful with 6.0 and > burn up more time digging into its arcane documentation, > trying to understand this. Apologies for the sarcasm -- > but that's the way it feels.) Why don't you just use separate Print[] commands instead, to create separate cells? Or even better: avoid Print[] entirely, if possible. (Yes, I know that Print[]ing graphics is useful sometimes, but if all you need is an output with multiple plots, use Column instead.) === Subject: Re: Defining derivatives > Derivative[1][f1] = f2; What can one _do_ with this construction? > Can one then plot or evaluate f1, without further ado? Fun, amusement, education, research, profit, ego... Here is an example that satisfies 4/6. (*caveat pedants, this is intended as a pedagogical exercise, lifted from my course notes, flames ignored*) GraphFunction[x_, y_] := ((x - y) (x + y))/(1 + (x + y)^2) (*simple graph f(x,y) ) $Assumptions = {x [Element] Reals, y [Element] Reals}; (*give simplify a hint *) CurvatureOfGraph[f_, x_, y_] := (*def. of curvature of f(x,y)*) FullSimplify[ (*silly to call simplify each time the function is called? not always*) Module[{dfdx = D[f[x, y], x], dfdy = D[f[x, y], y], d2fdx2 = D[f[x, y], {x, 2}], d2fdy2 = D[f[x, y], {y, 2}], d2fdxdy = D[f[x, y], x, y]} , Return[((1 + dfdx^2) d2fdx2 - 2 dfdx dfdy d2fdxdy + (1 + dfdy^2) d2fdy2)/ Sqrt[1 + dfdx^2 + dfdy^2]]]] CurvFunc = (*mysterious function definition for out particular surface*) Function[{x, y}, Evaluate[CurvatureOfGraph[GraphFunction, x, y]]] (*enigmatic defintions for partials on our surface*) dfdx = Function[{x, y}, Evaluate[FullSimplify[D[GraphFunction[x, y], x]]]] dfdy = Function[{x, y}, Evaluate[FullSimplify[D[GraphFunction[x, y], y]]]] angle[x_] := ((Pi/2 + ArcTan[x])/Pi) (*plot of function showing height, curvature, and normals, all in one go*) plotcurvature = Plot3D[GraphFunction[x, y], {x, -3, 3}, {y, 3, -3}, MeshFunctions -> (CurvFunc[#1, #2] &), MeshStyle -> Thick, PlotLabel -> Curvatures(level sets) and Normals(color variation), ColorFunction -> (Glow[ RGBColor[angle[dfdx[#1, #2]], angle[dfdy[#1, #2]], 0.75]] &),ColorFunctionScaling -> False, Lighting -> None] (*I think that's something*) -- W. Craig Carter === Subject: Re: Defining derivatives thank's a lot for the replies. Here is a short summary of what I just learned: - expressions with the form: f[..][..] are called SubValues of f. Documentation of this is non existent, but mathematica knows about it. - the best way to define derivatives is: Derivative[1][f]= f2 however, what is still not clear to me is why the following does not work: Derivative[1][f][x_]= f2[x] thank's again, Daniel > Hello All, does anybody know how to define symbolic derivatives. E.g.: f[x_]:=f1[x]; f'[x_]:=f2[x]; this does not work because f on the lefthand side is evaluated. To prevent this (do not forget to remove f before redefining it): f[x_]:=f1[x]; HoldPattern[f'[x_]]:=f2[x]; this gives no message, but f'[x] returns f1[x] instead of f2[x]. The same thinhg happens when you change the sequence of definitions: f'[x_]:=f2[x]; f[x_]:=f1[x]; Further, where is the information about derivatives stored? thank's a lot, Daniel > === Subject: Re: Defining derivatives Hi Jean-Marc, is this a typo?: f'[x] ^:= f2[x] this would only worj for the variable x. Daniel >> Hello All, >> does anybody know how to define symbolic derivatives. E.g.: >> f[x_]:=f1[x]; >> f'[x_]:=f2[x]; >> this does not work because f on the lefthand side is evaluated. To >> prevent this (do not forget to remove f before redefining it): >> f[x_]:=f1[x]; >> HoldPattern[f'[x_]]:=f2[x]; >> this gives no message, but f'[x] returns f1[x] instead of f2[x]. >> The same thinhg happens when you change the sequence of definitions: >> f'[x_]:=f2[x]; >> f[x_]:=f1[x]; Daniel, *UpSetDelayed[]*. For instance, In[1]:= Remove[f] > f[x_] := f1[x] > f'[x] ^:= f2[x] > f'[x] Out[4]= f2[x] -- Jean-Marc > === Subject: Re: Defining derivatives > Hi Jean-Marc, is this a typo?: f'[x] ^:= f2[x] this would only worj for the variable x. Daniel Hi Daniel, Wow, that's hurt! You are right, of course. I apologize for the confusion that may have resulted. The correct expression is f' ^:= f2; Nevertheless, this approach is less generic than Carl Woll's solution Derivative[1][f1] = f2; (Note that f' = f2 is also less generic than the above.) (* Using up values *) Remove[Global`*] f[x_] := f1[x] f' ^:= f2 f'[x] D[f[x], x] f'[c] D[f[c], c] Out[4]= f2[x] Out[5]= f1'[x] Out[6]= f2[c] Out[7]= f1'[c] {* Carl Woll's solution *} Remove[Global`*] f[x_] := f1[x] Derivative[1][f1] = f2; f'[x] D[f[x], x] f'[c] D[f[c], c] Out[11]= f2[x] Out[12]= f2[x] Out[13]= f2[c] Out[14]= f2[c] (* Another possibility, but less generic *) Remove[Global`*] f[x_] := f1[x] f' = f2; f'[x] D[f[x], x] f'[c] D[f[c], c] Out[18]= f2[x] Out[19]= f1'[x] Out[20]= f2[c] Out[21]= f1'[c] -- Jean-Marc > Hello All, > does anybody know how to define symbolic derivatives. E.g.: > f[x_]:=f1[x]; > f'[x_]:=f2[x]; > this does not work because f on the lefthand side is evaluated. To > prevent this (do not forget to remove f before redefining it): > f[x_]:=f1[x]; > HoldPattern[f'[x_]]:=f2[x]; > this gives no message, but f'[x] returns f1[x] instead of f2[x]. > The same thinhg happens when you change the sequence of definitions: > f'[x_]:=f2[x]; > f[x_]:=f1[x]; >> >> Daniel, > >> *UpSetDelayed[]*. For instance, >> In[1]:= Remove[f] > >> f[x_] := f1[x] > >> f'[x] ^:= f2[x] > >> f'[x] >> Out[4]= f2[x] > >> -- Jean-Marc === Subject: Re: Defining derivatives > Nevertheless, this approach is less generic than Carl Woll's solution Derivative[1][f1] = f2; > What can one _do_ with this construction? Presumably it's executed in situations where f2 is already defined, and f1 isn't --- ?? --- and when executed creates f1 (to within a constant of integration)? Can one then plot or evaluate f1, without further ado? === Subject: Re: Player Pro and Packages Of course my comment was a bit sarcastic. Seriously. What I meant was that it is very difficult to protect and claim ownership for clear text file formats, like the Mathematica notebook format or the PDF format. Evidently the Adobe people have understood that for their case. I feel it a bit illogical to have a high price for the notebook editing part (Mathematica) and a low part for the calculation engine (Player Pro), since the notebook editing part to me seems as the simpler part. And I feel a bit concerned: of course I would also prefer a Mathematica free for all, but at the same time I would like the Wolfram people well paid and working, improving their product further. Hopefully Wolfram finds some new business concept to make the money roll in. Maybe they could sell Mathematica as engine for more specialized products? There are some indications that they are thinking this way. Then they would benefit from having as many Mathematica developers as possible in the community of Mathematica users. Maybe it is up to us Mathematica enthusiasts to show the world why we are enthusiastic to create resources to make Mathematica free. Ingolf Dahl > -----Original Message----- === > Subject: Re: Player Pro and Packages Maybe Wolfram should ask Adobe for an advice, how to ensure that > behind the content created for Adobe Reader is a genuine > Adobe Acrobat > license. The problems involved seem to be quite equivalent. ;-) I do hope this comment was sarcastic or sardonic, rather than serious? Is not the great virtue of PDF that it's a more or less fully > _open_, fully specified, and widely distributed format or > standard, made openly available by Adobe so that anyone with > adequate coding skills can create documents or display > documents in that format _without_ having an Adobe license at > either end. I understand that Adobe does retain some kind of ownership > over it, and they certainly sell tools that third parties can > purchase to create or read PDFS. And, there are security > links and password protections that document creators can put > into PDF documents to limit what recipients can do with a document. But my understanding was that the second paragraph above was > nonetheless more or less true (except for some unfortunate > garbage related to embedded fonts). Is this not the case? === Subject: Re: Player Pro and Packages > The PDF specification was first published when Adobe Acrobat was > introduced in 1993. Since then, updated versions of the PDF Reference > have been made available from Adobe via the Web. A significant number of= > developers and systems integrators offer customized enhancements and > extensions to Adobe's core family of products. Adobe publishes the PDF > specification to foster the creation of an ecosystem around the PDF > format. The PDF Reference provides a description of the Portable > Document Format and is intended for application developers wishing to > develop applications that create PDF files directly, as well as read or > modify PDF document content. >http://www.adobe.com/devnet/pdf/pdf_reference.html > (Note that this is why open source as well as non-Adobe commercial > software can legally read and create, and even add goodies to, PDF > files. To name a few: OpenOffice, PDFCreator, Mac OS X, ...) Mathematica notebooks as a widespread publication or communication > format, should seriously ponder the middle sentence Adobe publishes the PDF specification to foster the creation of an= > ecosystem around the PDF format. --- an ecosystem, note, which does not directly require anyone, authors > OR readers, to purchase any Adobe products. Perhaps I am missing something here... but the notebook specification is fully published by Wolfram. Also, Mathematica Player is free... it is only the intermediate product that has a cost associated with it. Perhaps the question is whether it is permitted to write a competitor to Player... that of course is a different intellectual property question. --David === Subject: Re: Player Pro and Packages > Maybe Wolfram should ask Adobe for an advice, how to ensure that behind the > content created for Adobe Reader is a genuine Adobe Acrobat license. The > problems involved seem to be quite equivalent. ;-) I do hope this comment was sarcastic or sardonic, rather than serious? Is not the great virtue of PDF that it's a more or less fully _open_, fully specified, and widely distributed format or standard, made openly available by Adobe so that anyone with adequate coding skills can create documents or display documents in that format _without_ having an Adobe license at either end. I understand that Adobe does retain some kind of ownership over it, and they certainly sell tools that third parties can purchase to create or read PDFS. And, there are security links and password protections that document creators can put into PDF documents to limit what recipients can do with a document. But my understanding was that the second paragraph above was nonetheless more or less true (except for some unfortunate garbage related to embedded fonts). Is this not the case? === Subject: Re: Player Pro and Packages >> Maybe Wolfram should ask Adobe for an advice, how to ensure that behind the >> content created for Adobe Reader is a genuine Adobe Acrobat license. The >> problems involved seem to be quite equivalent. ;-) I do hope this comment was sarcastic or sardonic, rather than serious? Is not the great virtue of PDF that it's a more or less fully _open_, > fully specified, and widely distributed format or standard, made openly > available by Adobe so that anyone with adequate coding skills can create > documents or display documents in that format _without_ having an Adobe > license at either end. I understand that Adobe does retain some kind of ownership over it, and > they certainly sell tools that third parties can purchase to create or > read PDFS. And, there are security links and password protections that > document creators can put into PDF documents to limit what recipients > can do with a document. But my understanding was that the second paragraph above was nonetheless > more or less true (except for some unfortunate garbage related to > embedded fonts). Is this not the case? The PDF specification was first published when Adobe Acrobat was introduced in 1993. Since then, updated versions of the PDF Reference have been made available from Adobe via the Web. A significant number of developers and systems integrators offer customized enhancements and extensions to Adobe's core family of products. Adobe publishes the PDF specification to foster the creation of an ecosystem around the PDF format. The PDF Reference provides a description of the Portable Document Format and is intended for application developers wishing to develop applications that create PDF files directly, as well as read or modify PDF document content. http://www.adobe.com/devnet/pdf/pdf_reference.html (Note that this is why open source as well as non-Adobe commercial software can legally read and create, and even add goodies to, PDF files. To name a few: OpenOffice, PDFCreator, Mac OS X, ...) -- Jean-Marc === Subject: Re: Player Pro and Packages The PDF specification was first published when Adobe Acrobat was > introduced in 1993. Since then, updated versions of the PDF Reference > have been made available from Adobe via the Web. A significant number of > developers and systems integrators offer customized enhancements and > extensions to Adobe's core family of products. Adobe publishes the PDF > specification to foster the creation of an ecosystem around the PDF > format. The PDF Reference provides a description of the Portable > Document Format and is intended for application developers wishing to > develop applications that create PDF files directly, as well as read or > modify PDF document content. http://www.adobe.com/devnet/pdf/pdf_reference.html (Note that this is why open source as well as non-Adobe commercial > software can legally read and create, and even add goodies to, PDF > files. To name a few: OpenOffice, PDFCreator, Mac OS X, ...) Mathematica notebooks as a widespread publication or communication format, should seriously ponder the middle sentence Adobe publishes the PDF specification to foster the creation of an ecosystem around the PDF format. --- an ecosystem, note, which does not directly require anyone, authors OR readers, to purchase any Adobe products. === Subject: Changing TextStyle within Show I have often used TextStyle as a global option in Show, for example TextStyle->{FontFamily->Times,FontSlant->Italic,FontSize->9} to render all text in a plot. Is there a way to use it as a Graphics instruction so that font size, etc. is changed for subsequent Text objects as the plot is processed? The Graphics documentation (I am looking at 5.2 on my laptop) says yes, but gives no specific format or examples. I would expect a function like Graphics[TextStyle[ arguments ]] to be available but cant find a description. === Subject: Problem with RegionFunction any idea what is the problem with the output of this Manipulate? Manipulate[ Plot3D[Sin[x]*Cos[y],{x,1,10},{y,2,10},RegionFunction->Function[{x,y}, 45<=(y^x)]] ,{dummy,{True,False}}] Interestingly none of the following codes produces errors: Plot3D[Sin[x]*Cos[y], {x, 1, 10}, {y, 1, 10}, RegionFunction -> Function[{x, y}, 45 <= (y^x)]] Manipulate[ Plot3D[Sin[x]*Cos[y], {x, 1, 10}, {y, 1, 10}, RegionFunction -> If[region, All, Function[{x, y}, 45 <= (y^x)]]] , {region, {True, False}}] Any suggestion would be appreciated. Istvan Zachar === Subject: Defining output formats On the doc page tutorial/DefiningOutputFormats there is an example: This specifies the TeXForm for the symbol x. In[1]:= Format[x, TeXForm] := {bf x} The output format for x that you specified is now used whenever the TeX form is needed. In[2]:= TeXForm[1 + x^2] Out[2]//TeXForm= x^2+1 Quite obviously, this does not work in the way the documentation suggests. I would have expected {bf x}^2 + 1. Let's try another example: In[3]:= TeXForm[x] Out[3]//TeXForm= text{${backslash backslash $bf x$}$} So is there a way to tell Mathematica that x should always be formatted in bold in TeXForm? === Subject: Re: Product In the following link of Wolfram Blog, Mark Sofroniou makes some comments about the efficient algorithms for multiplications included in Mathematica. http://blog.wolfram.com/2007/09/25/arithmetic-is-hard-to-get-right/ Jose Mexico -----Mensaje original----- De: Jose Luis Gomez [mailto:jose.luis.gomez@itesm.mx] Enviado el: Viernes, 11 de Abril de 2008 11:24 a.m. Para: 'Steven'; 'mathgroup@smc.vnet.net' Asunto: RE: Product (* Steven *) (* I think it is an interesting question *) (* See what happens when we compare total with other ways to add many small integers *) (* First a test list:*) In[1]:= mytestlist = Table[RandomInteger[{1, 9}], {1000000}]; (* add all the numbers in the list, and also report the computer time used to calculate:*) In[2]:= Timing[Plus @@ mytestlist] Out[2]= {0.266, 5003966} (* AGAIN add all the numbers in the list, BUT THIS TIME USING TOTAL and also report the computer time used to calculate:*) In[3]:= Timing[Total[mytestlist]] Out[3]= {0.031, 5003966} (* As you can see, for small integers, Total has a special algorithm that that adds ten times faster than just add all the numbers in order*) (* Therefore your question is equivalent to ask if there is an improved algorithm to multiply numbers, and if that algorithm is implemented in a special command in Mathematica, equivalent to Total*) (* I do not know the answer, while someone else answers this, you can multiply the following way:*) In[4]:= Times @@ mytestlist (* large result deleted *) (* The following link might be interesting for you:*) (* http://homepage.cem.itesm.mx/lgomez/matecmatica/fp/fp.html *) (* http://homepage.cem.itesm.mx/lgomez/matecmatica/funcionalprog.nb *) (* Hope that helps *) (* Jose *) (* Mexico *) -----Mensaje original----- De: Steven [mailto:steven_504@telenet.be] Enviado el: Viernes, 11 de Abril de 2008 12:43 a.m. Para: mathgroup@smc.vnet.net Asunto: Product Silly beginner's question: is there a function to multiply all elements of a list, like Total does for addition? 'fraid I can't find it. TIA === Subject: Re: bar charts, frame ticks, and error bars easiest option. :) dan went through a lot of gyrations on formatting of charts, hate to say it, but I simply went back to MS Excel. > Hello all, > I've found a number of posts that deal with either using frames with > bar charts or error bars with bar charts, but I've been having > difficulty implementing those previous suggestions when it comes to a > bar chart showing multiple sets of data. Take for example the > following: > BarChart[{{10, 20, 30, 40}, {5, 15, 25, 35}}, > Frame -> {True, True, None, None}, > FrameTicks -> {{{1, A}, {2, B}, {3, C}, {4, D}}, Automatic, > None, None}] > The problem with the result is that the ticks show up under the first > bar of each set, when I would hope that the ticks would be at the > center of each set. I haven't even tried to use error bars yet. Does > anyone have any suggestions on how to make this work? And maybe, how > to implement a plot legend with these multiple set bar charts? > Dan === Subject: Re: Timing >Who know how change bellow procedure to received reasonable timing? Part: >Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - >1))/(4 Sqrt[2])]/(2^n - 1) >is every time integer Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - >>2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], >> Print[n]], {n, 1, 17}]] >> >I will be greatfull for any help! (Mayby some N[] or Floor[N[]] or >Int[N[]] will be quickest Best wishes >Artur You should review Fibonacci numbers and difference equations. Anyway, one can prove that ((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2]) is an integer. Then notice: In[166]:= 3 - 2 Sqrt[2] // N Out[166]= 0.171573 As n gets larger, this term disappears. Therefore, all you need to do is: f[n_] := Round[(3 + 2 Sqrt[2])^(2^(n-1)-1)/(4 Sqrt[2])] Of course, the number of digits doubles every time, so on my computer things become very slow at f[23] (which is an integer with ~3.2 million digits). So, you might want to experiment with recurrence relations (a la Fibonacci). This might allow you to incorporate the 2^n-1 denominator and keep things from blowing quite so quickly. For example, if g[n_] := ((3 + 2 Sqrt[2])^n - (3 - 2 Sqrt[2])^n)/(4 Sqrt[2]) then (from the quadratic satisfied by 3 +/- 2 Sqrt[2]): g[n+2] == 6 g[n+1] - g[n] g[0]==0 g[1]==1 {g[n+1], g[n]} == {{6, -1}, {1, 0}} . {g[n], g[n-1]} or MatrixPower[{{6, -1}, {1,0}}, n] == {{g[n+1], -g[n]}, {g[n], g[n-1]}} etc. Carl Woll Wolfram Research === Subject: Re: Timing It is easy to prove that expr is an integer. Let A=(3 + 2 Sqrt[2]) and B=3 -2 Sqrt[2]. Then A and B are the roots of x^2 - (A + B) x + A B == 0 // Expand = x^2 - 6 x + 1 == 0 with A+B = 6 and A*B=1. Note also that A-B=4Sqrt[2]. expr is (A^m-B^m)/(4*Sqrt[2])= (A-B)*(A^(m-1) + A^(m-2) B + A^(m-3)B^2+ ...A*B^(m-2)+B^(m-1))/(4 Sqrt[2]) = A^(m-1) + A^(m-2) B + A^(m-3)B^2+ ...A*B^(m-2)+B^(m-1) = (A^(m-1)+B^(m-1)) + (A^(m-2)*B+ A*B^(m-2))+...= (A^(m-1)+B^(m-1) + (A^(m-3)+B^(m-3) + ....) + 1 Here m is 2^(n-1)-1.The 1 is present because A*B // Simplify 1 so the product of the same powers o A and B is 1. So expr clearly an integer since any sum of power A^k+B^k can be expresses as polynomial with integer coefficients in the symmetric functions of A and B. So this does not require any use of Mathematica. The question when this is divisible by 2^n-1 is far from clear. One could try to use something like this: f[n_] := Module[ {prec = Log[10, ((2*Sqrt[2] + 3)^ (2^(n - 1) - 1) - (3 - 2*Sqrt[2])^ (2^(n - 1) - 1))/ ((4*Sqrt[2])*(2^n - 1))], p}, p = N[((2*Sqrt[2] + 3)^ (2^(n - 1) - 1) - (3 - 2*Sqrt[2])^ (2^(n - 1) - 1))/ ((4*Sqrt[2])*(2^n - 1)), prec + $MachinePrecision]; p == Round[p]] Table[f[n], {n, 2, 20}] // Timing {11.4016, {False, True, False, True, False, True, False, False, False, False, False, True, False, False, False, True, False, True, False}} This is at least vastly faster than the OP's version. Andrzej Kozlowski > The previous method should work (in a very weak interpretation of > work) if you replace the expr with; expr = Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - > 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])] Note: FullSimplify[Together[expr], Element[n, Integers]] is considerably simpler ((3 + 2*Sqrt[2])^2^(-1 + n)*(-4 + 3*Sqrt[2]) - > (3 - 2*Sqrt[2])^2^(-1 + n)*(4 + 3*Sqrt[2]))/8 I can't immediately see that this result should be integer, but I am > getting integers for the first 10 t = Table[nexpr /. n -> i, {i, 1, 10}] // Expand > Map[IntegerQ, t] > In general, Do is slow compared to Table, but it is the size of the > expression that is the limiting factor here. > My problem is find such numbers n that expression >> ((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/ >> (4 >> Sqrt[2]) >> is divisable by (2^n - 1) >> or another words (2^n - 1) is divisor of ((3 + 2 Sqrt[2])^(2^(n - >> 1) - 1) - >> (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2]) >> My procedure Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - >> 1) - (3 - >> 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], Print[n]], >> {n, 1, >> 17}] >> is extremaly slow (probably Expand function do that as aslowly but >> without >> Expand we don't have integers. I don't have idea how improove them. >> Best wishes >> Artur >> W_Craig Carter pisze: > Hello Artur, > I am not sure I understand your question: >> Are you asking for > Member[expr,Integers] && Element[n,Integers] > for 1 <= n <= 17 ? >> If so, this may be a hint, although it does not exactly check the > above: >> Map[Element[Rationalize[#, .00000001], Integers] & , > Table[expr /. n -> i, {i, 1, 30}]] >> and it is reasonably fast. This approximate method gets worse for > large n; so I don't trust the result except for n=1,3,5 >> Note, that > Map[Element[Rationalize[Expand[#], .00000001], Integers] & , > Table[expr /. n -> i, {i, 1, 10}]] >> Gives a different result and is much slower, thus emphasizing the > result for large n. >> I am curious to see the better solutions.... >>> Who know how change bellow procedure to received reasonable timing? >> Part: >> Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - >> 1) - >> 1))/(4 Sqrt[2])]/(2^n - 1) >> is every time integer >>> Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - >>> (3 - >>> 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], >>> Print[n]], {n, 1, 17}]] >>> I will be greatfull for any help! (Mayby some N[] or Floor[N[]] or >> Int[N[]] will be quickest >> Best wishes >> Artur >>>>>> > -- > W. Craig Carter > === Subject: Re: Timing The previous method should work (in a very weak interpretation of work) if you replace the expr with; expr = Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])] Note: FullSimplify[Together[expr], Element[n, Integers]] is considerably simpler ((3 + 2*Sqrt[2])^2^(-1 + n)*(-4 + 3*Sqrt[2]) - (3 - 2*Sqrt[2])^2^(-1 + n)*(4 + 3*Sqrt[2]))/8 I can't immediately see that this result should be integer, but I am getting integers for the first 10 t = Table[nexpr /. n -> i, {i, 1, 10}] // Expand Map[IntegerQ, t] In general, Do is slow compared to Table, but it is the size of the expression that is the limiting factor here. > My problem is find such numbers n that expression > ((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 > Sqrt[2]) > is divisable by (2^n - 1) or another words (2^n - 1) is divisor of ((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - > (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2]) My procedure Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - > 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], Print[n]], {n, 1, > 17}] is extremaly slow (probably Expand function do that as aslowly but without > Expand we don't have integers. I don't have idea how improove them. > Best wishes > Artur W_Craig Carter pisze: > Hello Artur, > I am not sure I understand your question: > Are you asking for > Member[expr,Integers] && Element[n,Integers] > for 1 <= n <= 17 ? > If so, this may be a hint, although it does not exactly check the above: > Map[Element[Rationalize[#, .00000001], Integers] & , > Table[expr /. n -> i, {i, 1, 30}]] > and it is reasonably fast. This approximate method gets worse for > large n; so I don't trust the result except for n=1,3,5 > Note, that > Map[Element[Rationalize[Expand[#], .00000001], Integers] & , > Table[expr /. n -> i, {i, 1, 10}]] > Gives a different result and is much slower, thus emphasizing the > result for large n. > I am curious to see the better solutions.... > > Who know how change bellow procedure to received reasonable timing? > Part: > Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - > 1))/(4 Sqrt[2])]/(2^n - 1) > is every time integer > Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - > 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], > Print[n]], {n, 1, 17}]] > > I will be greatfull for any help! (Mayby some N[] or Floor[N[]] or > Int[N[]] will be quickest > Best wishes > Artur > -- W. Craig Carter === Subject: Re: Timing My problem is find such numbers n that expression ((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2]) is divisable by (2^n - 1) or another words (2^n - 1) is divisor of ((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2]) My procedure Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], Print[n]], {n, 1, 17}] is extremaly slow (probably Expand function do that as aslowly but without Expand we don't have integers. I don't have idea how improove them. Best wishes Artur W_Craig Carter pisze: > Hello Artur, > I am not sure I understand your question: Are you asking for > Member[expr,Integers] && Element[n,Integers] > for 1 <= n <= 17 ? If so, this may be a hint, although it does not exactly check the above: Map[Element[Rationalize[#, .00000001], Integers] & , > Table[expr /. n -> i, {i, 1, 30}]] and it is reasonably fast. This approximate method gets worse for > large n; so I don't trust the result except for n=1,3,5 Note, that > Map[Element[Rationalize[Expand[#], .00000001], Integers] & , > Table[expr /. n -> i, {i, 1, 10}]] Gives a different result and is much slower, thus emphasizing the > result for large n. I am curious to see the better solutions.... >> Who know how change bellow procedure to received reasonable timing? >> Part: >> Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - >> 1))/(4 Sqrt[2])]/(2^n - 1) >> is every time integer >> Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - >> 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], >> Print[n]], {n, 1, 17}]] >> I will be greatfull for any help! (Mayby some N[] or Floor[N[]] or >> Int[N[]] will be quickest >> Best wishes >> Artur >> === Subject: Re: Timing Hello Artur, I am not sure I understand your question: Are you asking for Member[expr,Integers] && Element[n,Integers] for 1 <= n <= 17 ? If so, this may be a hint, although it does not exactly check the above: Map[Element[Rationalize[#, .00000001], Integers] & , Table[expr /. n -> i, {i, 1, 30}]] and it is reasonably fast. This approximate method gets worse for large n; so I don't trust the result except for n=1,3,5 Note, that Map[Element[Rationalize[Expand[#], .00000001], Integers] & , Table[expr /. n -> i, {i, 1, 10}]] Gives a different result and is much slower, thus emphasizing the result for large n. I am curious to see the better solutions.... > Who know how change bellow procedure to received reasonable timing? Part: > Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - > 1))/(4 Sqrt[2])]/(2^n - 1) > is every time integer > Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - > 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], > Print[n]], {n, 1, 17}]] > I will be greatfull for any help! (Mayby some N[] or Floor[N[]] or > Int[N[]] will be quickest Best wishes > Artur -- W. Craig Carter === Subject: Re: Timing Who know how change bellow procedure to received reasonable timing? Part: Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1) is every time integer > Timing[Do[ If[IntegerQ[Expand[((3 + 2 Sqrt[2])^(2^(n - 1) - 1) - (3 - > 2 Sqrt[2])^(2^(n - 1) - 1))/(4 Sqrt[2])]/(2^n - 1)], > Print[n]], {n, 1, 17}]] > I will be greatfull for any help! (Mayby some N[] or Floor[N[]] or Int[N[]] will be quickest Best wishes Artur === Subject: matrix of vectors - super slow I have an matrix of vectors where each element has to go through various transformations, that is each element has to be multiplied by a few different matrices. Is there a more efficient way of doing that from what I am currently doing? n = 128*1; m = 128*1; R = 1; BeamIn = Table[( { {Sqrt[2]/2}, {Sqrt[2]/2} } ), {i, n}, {j, m}]; PBeam = Table[0, {i, n}, {j, m}]; SBeam = Table[0, {i, n}, {j, m}]; PInt = Table[0, {i, n}, {j, m}]; SInt = Table[0, {i, n}, {j, m}]; HalfWave[[Theta]_] = ( { {Cos[-[Theta]], Sin[-[Theta]]}, {-Sin[-[Theta]], Cos[-[Theta]]} } ).( { {1, 0}, {0, Exp[-I [Pi]]} } ).( { {Cos[[Theta]], Sin[[Theta]]}, {-Sin[[Theta]], Cos[[Theta]]} } ); QuarterWave[[Theta]_] = ( { {Cos[-[Theta]], Sin[-[Theta]]}, {-Sin[-[Theta]], Cos[-[Theta]]} } ).( { {1, 0}, {0, Exp[-I [Pi]/2]} } ).( { {Cos[[Theta]], Sin[[Theta]]}, {-Sin[[Theta]], Cos[[Theta]]} } ); PPol = ( { {1, 0}, {0, 0} } ); SPol = ( { {0, 0}, {0, 1} } ); LaserRod[TT_, [Theta]_, Q_] = ( { {Cos[-[Theta]], Sin[-[Theta]]}, {-Sin[-[Theta]], Cos[-[Theta]]} } ).( { {Exp[-I *2.8 *TT^2*Q], 0}, {0, Exp[I *0.4 *TT^2* Q]} } ).( { {Cos[[Theta]], Sin[[Theta]]}, {-Sin[[Theta]], Cos[[Theta]]} } ); For[i = 1, i <= n, i++, For[j = 1, j <= m, j++, x = R ((2 i - n) - 1); y = R ((2 j - m) - 1); r = Sqrt[x^2 + y^2]; [Theta] = ArcTan[y/x]; PBeam[[i, j]] = PPol.LaserRod[r, [Theta], 1*10^-3].QuarterWave[[Pi]/ 2].LaserRod[r, [Theta], 1*10^-3].PPol.BeamIn[[i, j]]; SBeam[[i, j]] = SPol.LaserRod[r, [Theta], 1*10^-3].QuarterWave[[Pi]/ 2].LaserRod[r, [Theta], 1*10^-3].PPol.BeamIn[[i, j]]; PInt[[i, j]] = Norm[PBeam[[i, j]][[1, 1]]]^2; SInt[[i, j]] = Norm[SBeam[[i, j]][[2, 1]]]^2; ]; ]; ListDensityPlot[PInt] ListDensityPlot[SInt] === Subject: Re: Mathematica notebooks There does not seem to be any such restriction for the Semester Edition, the Annual Edition, or the regular unlimited-time edition. Here is the entirety of the Product Summary for the Semester Edition; the language for the other two editions is similar: Mathematica for Students: Semester Edition is available for immediate download. It is a convenient and affordable option for students who may need the capabilities of Mathematica for only one or two prerequisite or elective classes. This time-limited version of Mathematica for Students is activated upon registration and expires six months later. A 12-month Annual Edition is also available. For those needing Mathematica for Students for more than one or two classes, the standard version is available. Note: Mathematica for Students is intended for students enrolled in accredited academic institutions and is for use on a student's own personal computer. Valid proof of student status is required prior to purchasing Mathematica for Students. > I htink the last time I checked they were only available to students at > institutions that have Mathematica site licenses. > If this has changed I am very glad to hear of it. Andrzej Kozlowski > >> Of course there IS a time-limited, cheap student version of Mathematica >> available. In fact, two such: a 6-month version and a 12-month version. > .... A time limited cheap student version > available to any student, whether at an institution that has a site > license or not, would make an enormous contribution to the adoption of > Mathematica, >> -- >> 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 > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Mathematica notebooks the best method I think the last time I checked they were only available to students at institutions that have Mathematica site licenses. If this has changed I am very glad to hear of it. Andrzej Kozlowski > Of course there IS a time-limited, cheap student version of > Mathematica > available. In fact, two such: a 6-month version and a 12-month > version. >> .... A time limited cheap student version >> available to any student, whether at an institution that has a site >> license or not, would make an enormous contribution to the adoption >> of >> Mathematica, -- > 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: Rotate axes label in 3D graphics I plotted two 3D surface figures, g1 and g2, and compined them using Show[] as the following: Show[ g1, g2, AxesLabel->{x, y, intensity} ] How can I rotate the label on the third axes? Alternatively I tried using Epilog->{ Rotate[ {Text[StyleForm[intensity],{ } ] ,Pi/2 } but got error message Graphics::gprim: <.....omit> was encountered where a Graphics primitive or directive was expected Can anyone tell me how to solve this problem? === Subject: Re: Rotate axes label in 3D graphics Plot3D[x*Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, AxesLabel -> {x, y, }, PlotRangePadding -> 0.25] /. Graphics3D[dta_, opts___] :> Graphics3D[{dta, Text[intensity, {-2.4, -2.4, 1}, {0, 0}, {0, 1}]}, opts] Jens I plotted two 3D surface figures, g1 and g2, and compined them using > Show[] as the following: Show[ g1, g2, AxesLabel->{x, y, intensity} ] How can I rotate the label on the third axes? > Alternatively I tried using Epilog->{ Rotate[ {Text[StyleForm[intensity],{ coord> } ] ,Pi/2 } but got error message Graphics::gprim: <.....omit was encountered where a Graphics primitive or directive was expected > Can anyone tell me how to solve this problem? > === Subject: same color above a treshold in ArrayPlot or ContourPlot, I need to color the points exceeding a certain treshold with the same color (say red). I guess that could be done defining an appropriate ColorFunction... but I cannot work it out. Could anyone help me? Luigi === Subject: Re: same color above a treshold ContourPlot[x*Exp[-x^2 - y^2], {x, -2, 2}, {y, -2, 2}, PlotRange -> All, ColorFunctionScaling -> False, ColorFunction -> (If[Abs[#] > 0.25, RGBColor[1, 0, 0], RGBColor[0, 2 # + 1, 0]] &)] for z-values < 1/4 Jens > in ArrayPlot or ContourPlot, I need to color the points exceeding a > certain treshold with the same color (say red). > I guess that could be done defining an appropriate ColorFunction... > but I cannot work it out. > Could anyone help me? Luigi > === Subject: Re: The FinancialData Function I've never heard of this function, but have one immediate strong reaction/question: Is there -- or will there soon be -- a fully open, officially standardized, fully and openly specified, widely and near universally accepted, stable, long-term, NON-proprietary set of **formats** for the data and information that is to be transmitted back and forth between data providers and data users in this system? [Something akin to the more or less open, universal and stable graphics standards that have emerged over time.] Lacking that, I wouldn't personally go near this kind of financial data distribution system and related tools like FinancialData for building anything that was of any real and continuing importance to me. Think of mapping data, GPS and topographic data, or satellite imagery and related software tools as an analogous system. I play with some of this data, plan journeys using MapQuest, hiking trips using Google Earth (an incredible tool), etc -- but if someone suddenly decided to change all the standards for this data, I could still use all my old stored data and tools -- or just do without. (There would of course be many important commercial enterprises that would be much more seriously impacted.) But then suppose people get important, continuing personal or business activities deeply involved in an information system that uses tools like FinancialData; the data providers and Wolfram somehow get cross-wise commercially; and the data providers threaten to change their formats just enough to screw Wolfram (and all FinancialData users). Or, suppose the data providers decide to throw digital rights management complexities all over their data, as is the case now with music, films, video -- and the deep pockets financial data providers manage to bribe Congress to require that all computer tools like FinancialData contain provisions to enforce these DRM complexities. This may all come across as paranoid fears, and maybe it is -- but look what has actually happened in other areas of widely distributed electronic information distribution . . . === Subject: Re: The FinancialData Function > I've never heard of this function, but have one immediate strong > reaction/question: Is there -- or will there soon be -- a fully open, officially > standardized, fully and openly specified, widely and near universally > accepted, stable, long-term, NON-proprietary set of **formats** > for the data and information that is to be transmitted back > and forth between data providers and data users in this > system? [Something akin to the more or less open, universal and stable graphics > standards that have emerged over time.] Lacking that, I wouldn't personally go near this kind of financial data > distribution system and related tools like FinancialData for building > anything that was of any real and continuing importance to me. Why? You can export to any format you like (for archiving). FinancialData has nothing to do with data exchange formats. It simply gives you the requested data as a Mathematica expression. It spares you the trouble of having to import the data manually to Mathematica. === Subject: Re: finding positions of elements in a list > Having a few problems here with what I think should be a simple operation. I have a list as shown: mylist={{20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106}, {21, 107},...} It's a list of {x,y} co-ordinates of some data points I'm analysing. I want to create a new list which contains only those data points whose y co-ordinate is greater than 80 ie. mylist[[n,2]]>80. Problem is, I can't work out how to use Select to do this when each element in the list has an x and a y co-ordinate. If I split the list into x and y co-ordinates and searched for those y values greater than 80, I would have a list of those y-values but would not know the corresponding x-values. I also tried Position but it wasn't clear to me if a pattern can be used for this. FWIW, Here is a summary of most of the post with some new solutions and some benchmarking to get you inspired by the versatility of Mathematica programming language. In[1]:= myList = {{20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106}, {21, 107}} myList /. {x_, y_ /; y <= 107} -> Sequence[] Cases[myList, {x_, y_ /; y > 107}] DeleteCases[myList, {x_, y_ /; y <= 107}] Select[myList, Last@# > 107 &] Pick[myList, Thread[myList[[All, 2]] > 107]] myList[[Flatten@Position[myList, {_, y_ /; y > 107}]]] Table[If[myList[[j]][[2]] > 107, myList[[j]]], {j, Length[myList]}] /. Null -> Sequence[] If[#[[2]] > 107, #] & /@ myList /. Null -> Sequence[] Out[1]= {{20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106}, {21, 107}} Out[2]= {{20, 109}, {20, 110}, {20, 111}} Out[3]= {{20, 109}, {20, 110}, {20, 111}} Out[4]= {{20, 109}, {20, 110}, {20, 111}} Out[5]= {{20, 109}, {20, 110}, {20, 111}} Out[6]= {{20, 109}, {20, 110}, {20, 111}} Out[7]= {{20, 109}, {20, 110}, {20, 111}} Out[8]= {{20, 109}, {20, 110}, {20, 111}} Out[9]= {{20, 109}, {20, 110}, {20, 111}} In[10]:= myList = Table[Sequence @@ myList, {20000}]; myList /. {x_, y_ /; y <= 107} -> Sequence[] // Timing // First Cases[myList, {x_, y_ /; y > 107}] // Timing // First DeleteCases[myList, {x_, y_ /; y <= 107}] // Timing // First Select[myList, Last@# > 107 &] // Timing // First Pick[myList, Thread[myList[[All, 2]] > 107]] // Timing // First myList[[Flatten@Position[myList, {_, y_ /; y > 107}]]] // Timing // First Table[If[myList[[j]][[2]] > 107, myList[[j]]], {j, Length[myList]}] /. Null -> Sequence[] // Timing // First If[#[[2]] > 107, #] & /@ myList /. Null -> Sequence[] // Timing // First Out[11]= 0.147246 Out[12]= 0.098208 Out[13]= 0.113085 Out[14]= 0.15736 Out[15]= 0.084279 Out[16]= 0.230995 Out[17]= 0.342529 Out[18]= 0.295696 In[19]:= $Version Out[19]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) -- Jean-Marc === Subject: Separate input/output files A typical Mathematica notebook contains input and output together. With the objective of separating input and output for convenience and also eliminating repeated input commands and statements, I like to write two separate smaller files somewhat as under: ------ Harmonic.in Constant [{yi,ydi,w,tmax} = { 1.,.2, 1.,8.}]; NDSolve[{Y''[t]+w^2 Y[t]==0, Y[0]==yi,Y'[0]==ydi},Y,{t,0,tmax}]; y[t_]= Y[t] /.First[%] ; (* above two lines to be labelled ODE *) Plot[y'[t],{t,0,tmax}]; (* above line to be labelled PLT*) yi=2.; w=7. ; tmax= 4 ; Table[ {t,y[t],y'[t]}, {t,0,tmax,tmax/15.}]//ColumnForm (* above line to be labelled TABL*) Plot[y[t],{t,0,tmax}]; (* Only tmax = 4 takes effect but not yi and w, the quantities inside NDSolve curly barckets, do not take effect *) ------------ Harmonic.run yi = 1.6; w = 2; tmax= 4.; ODE PLT ydi = 2.; w = 1.2; tmax= 2.5 ; ODE PLT TABL --------------- Harmonic.out (* Contains output for ODE, PLT,TAB for changed input parameters, Harmonic.run lines echoed before respective outputs *) ------------- How to make such a file separation possible? Such separation I believe is convenient for dynamical simulation exercises. Narasimham === Subject: Re: Separate input/output files > A typical Mathematica notebook contains input and output together. > With the objective of separating input and output for convenience and > also eliminating repeated input commands and statements, I like to > write two separate smaller files somewhat as under: Take a look at the Splice[] command and the following program: http://ai.eecs.umich.edu/people/dreeves/mash/ === Subject: Re: floating point issue > K = Rationalize[{111.5, 10.5, 1.5}, 0]; > g = Rationalize[{-0.7071068, 0., -0.7071068}, 0]; K.Cross[K, g] 0 FWIW, On my system v6.0.2 Mac Os X 1.5.2 64-bit, g = Rationalize[{-0.7071068, 0., -0.7071068}] returns the list unevaluated. To get a list of nice/exact numbers, I must use *RootApproximant* (and of course K must be rationalized as well). Only then I can get the value of zero for the dot-cross product. In[1]:= $Version K = Rationalize@{111.5, 10.5, 1.5} g = RootApproximant@{-0.7071068, 0., -0.7071068} K.Cross[K, g] Out[1]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) Out[2]= {223/2, 21/2, 3/2} Out[3]= {-(1/Sqrt[2]), 0, -(1/Sqrt[2])} Out[4]= 0 In[5]:= K = Rationalize@{111.5, 10.5, 1.5} g = Rationalize@{-0.7071068, 0., -0.7071068} K.Cross[K, g] Out[5]= {223/2, 21/2, 3/2} Out[6]= {-0.707107, 0, -0.707107} Out[7]= 3.19744*10^-14 In[8]:= K = {111.5, 10.5, 1.5} g = {-0.7071068, 0., -0.7071068} K.Cross[K, g] Out[8]= {111.5, 10.5, 1.5} Out[9]= {-0.707107, 0., -0.707107} Out[10]= 3.19744*10^-14 -- Jean-Marc === Subject: Re: floating point issue As shown previously, use 0 as the tolerance (dx) to force rational. g = Rationalize[{-0.7071068, 0., -0.7071068}, 0] Bob Hanlon K = Rationalize[{111.5, 10.5, 1.5}, 0]; > g = Rationalize[{-0.7071068, 0., -0.7071068}, 0]; K.Cross[K, g] 0 FWIW, On my system v6.0.2 Mac Os X 1.5.2 64-bit, g = Rationalize[{-0.7071068, 0., -0.7071068}] returns the list unevaluated. To get a list of nice/exact numbers, I > must use *RootApproximant* (and of course K must be rationalized as > well). Only then I can get the value of zero for the dot-cross product. > In[1]:= $Version > K = Rationalize@{111.5, 10.5, 1.5} > g = RootApproximant@{-0.7071068, 0., -0.7071068} > K.Cross[K, g] Out[1]= 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) Out[2]= {223/2, 21/2, 3/2} Out[3]= {-(1/Sqrt[2]), 0, -(1/Sqrt[2])} Out[4]= 0 In[5]:= K = Rationalize@{111.5, 10.5, 1.5} > g = Rationalize@{-0.7071068, 0., -0.7071068} > K.Cross[K, g] Out[5]= {223/2, 21/2, 3/2} Out[6]= {-0.707107, 0, -0.707107} Out[7]= 3.19744*10^-14 In[8]:= K = {111.5, 10.5, 1.5} > g = {-0.7071068, 0., -0.7071068} > K.Cross[K, g] Out[8]= {111.5, 10.5, 1.5} Out[9]= {-0.707107, 0., -0.707107} Out[10]= 3.19744*10^-14 > -- > Jean-Marc > === Subject: Re: Mathlink: How do I pass arbitrary data from Mathematica to C? > I am trying to write some code to interface Mathematica to a closed- > source library written in C. I'm using Mathlink for this, which is > typically used to interface Mathematica to external functions - see > for example > http://reference.wolfram.com/mathematica/tutorial/SettingUpExternalFu... > For example, if the library has a function 'f' with the following > prototype: > int f(int x, int y); > the following in a Mathlink template (.tm file) will allow me to call > this function from Mathematica by the name Foo, if I link to the > library., create an > executable, then install that executable in Mathematica with > Install[]. > :Begin: > :Function: f > :Pattern: Foo[x_Integer, y_Integer] > :Arguments: {x, y} > :ArgumentTypes: {Integer, Integer} > :ReturnType: Integer > :End: > (There is no need for me to write the function f, as that has been > done. I just need to link to the library containing the function f, in > much the same way you use the 'pow' function in C without writing it - > you would just link to the maths library.). > I have no problem with the above - it all works as expected. > The problem occurs with a function 'g', which instead of having only > integer arguments, takes a pointer to some data. The format of the > data is not specified - the C function just needs to know where in > memory the data is, and how many bytes there are. The C prototype is > int g(const void *data, long nbytes); > Does anyone know how I can write a Mathematica template so when I link > with the function 'g', I can pass the data properly? Note, that since > the library is closed-source, I am not able to change the calling > method in any way. But I expect it should be possible to write an > interface in C, such that data is passed from Mathematica in a form > compatible with Mathematica, and then converts it to a from the C > library accepts. But I am stuck as how to do this. > If its not possible to do this with a template, can it be done by > writing it all in C? If so, how? > I don't want Mathematica to try to interpret the data in any way - > just to pass an address of where the data is in memory, and also the > number of bytes of data. Than the library function g will return an > integer, which I want to pass back to Mathematica. > Someone suggested that I might look at the C code generated by mcc to > work out how to do this, (perhaps making use of MLPutInteger), but I > can't work out how to do this. > Does that make sense? Any ideas how to pass arbitrary data to a C > program? > I have a similar issue in trying to get arbitrary data from C to > Mathematica, but that is another story. >> When you pass data over MathLink, you are communicating between two >> processes - so no pointers can be passed. It certainly sounds as though >> you need to write an interface routine in C - as you suggest. Presumably >> you know the structure of this data, so perhaps you could transmit it >> from Mathematica in pieces and assemble it in the required format in the >> interface routine. >> Perhaps you should tell us the structure of this data, and how big it is. >> David Baileyhttp://www.dbaileyconsultancy.co.uk The data will be passed to some hardware via a library routine written > in C. For example, the first bit of data might bea command like RESET, the > next might be LOADFILE The next bit of data might be a binary file. > Hence I need to find a way of passing an arbitrary collection of > bytes. It might be one byte, two bytes, three bytes ... up to a couple > MB or so. I will know the exact length. It it was a file I wanted to send, then I assume something like > data=BinaryReadList[filenane.dat,Character8] would be suitable to read it, then I would need to send the contents > of 'data' But equally the data might just be a bit of text. > I think the easiest answer is to write a few little C routines which take data items of the various types and append them to a data structure (presumably a char[]). You will also need one C routine to initialise the array, and one to send the end result to its destination. The only problem with this scheme might be if it is too slow for your requirements (because of the number of MathLink calls), but I would certainly start with that approach. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Any body can help me solve the equation with piecewise function I have a problem to solve, but it seems not easy because of the piecewise function involved. I am wondering how we should deal with piecewise function when solving an equation or doing optimization. To give you an simple example, the piecewise function is f(x)= 3x if x<0; f(x)= 0 if x>=0. And I want to solve the equation f(x)+6=0. I actually define the piecewise function at first using Which and then try to use NSolve to solve it. However, NSolve doesn't work through. Anybody know how should I solve this kind of problem generally in Mathematica? Of course, for this simple example, we can divide it into two cases and then compare the solutions after solving the two cases. Yet my problem is more general and involves more than 3 piecewise functions, thus a lot of possible cases to deal with. So any command or function to deal with this kind of general problem? === Subject: Minimum width of Button[.] on different platforms Manipulate[Button[Null, ImageSize -> w], {w, 1, 100}] On my Windows XP PC, Button[.]s are always at least 8 pixels wide. On my friend's Mac, they are always at least 68 pixels wide. 68 seems a lot. Is there any way for Mathematica to force buttons on Mac OS X to render smaller than that? === Subject: Minimum width of Button[.] on different platforms A related curiosity: Button[Null, ImageSize -> 0] Button[Null, ImageSize -> 1] Button[Null, ImageSize -> 2] On my Windows XP PC, the actual apparent width of these buttons are: 10 pixels 9 pixels 8 pixels -----Original Message----- === Subject: Minimum width of Button[.] on different platforms Manipulate[Button[Null, ImageSize -> w], {w, 1, 100}] On my Windows XP PC, Button[.]s are always at least 8 pixels wide. On my friend's Mac, they are always at least 68 pixels wide. 68 seems a lot. Is there any way for Mathematica to force buttons on Mac OS X to render smaller than that? === Subject: Re: Operate on Heads I would like to thank to all respondents to my posted questions on this, as well as on previous topics. I would try to explain some of my desires? on a rather simple example related to some natural events I have a number of Modules (subroutines, functions, or whatever one prefer to call it) With (subject, object(s), event(s), action(s)) structure. For example, a subject is an Earth based location triad, Objects are Sun and Moon, Events are Rise and Set, ... Based on interrelations of all of above, Some unique action, based on the state of the system, should be described/specified, and executed One way to solve this problem is to have all logic in the main program and have a possibly large number of small modules, Each describing a unique but simple action. The logic could, in principle, be implemented via combination of If,Then,Else,Switch; And,Or,... ; (pattern construction) Alternatives; or something better ? In this simple example we have (hidden/protected possibly someone else or even Mathematica own) commands such as Set (possibly the same name for two completely different commands), Rise, but also commands (modules, or whatever) SunRise, SunSet, MoonRise, MoonSet, which name (Head) is a composite word. I have dealt with such situations along the lines described by Januk, tnx, and via fun[A,B,C][a,b,c][t] Polygon @@ Line Type of structures. The last line Apply approach actually just replaces the Head name. In principal no problem when I have my own relatively simple structures, however, ... Some of my Modules are to often inside some loops (Table, Plot). In complex interrelations between a larger number of objects and events, logic is becoming cumbersome and all things are getting to slow. Thus my imperative in those situations is getting under the hood, if I can and if I have enough time, And speed things up. Now comes Mathematica's sentence Operate is essentially a generalization of Apply, which allows you to apply an operator to the head of an expression, rather than simply to replace the head What this really means? This is what stimulated me, since I smell (possibilities toward) a number of better, more elegant, more efficient, solutions to my problems ... Of course there might be some Pandora Boxes in between ... (non)technical issues, etc. C pointers and list of all lists, the machine code list, and its 1:1 twin called assembler are coming to mind ... -----Original Message----- === Subject: Re: Operate on Heads Hi Andy, A basic approach would be to convert everything to strings, use Mathematica's string manipulation commands to create the expression you'd like evaluated, then convert back to an expression. See below for a simple example. f[something_, x__] := Module[{strArgs, strHeads}, strHeads = ToString[something]; strArgs = Riffle[ToString /@ {x}, ,]; (* Manipulate your heads here *) strHeads = StringReplace[strHeads, p -> P]; StringJoin[strHeads, [, strArgs, ] ] // ToExpression ] f[plus, 2, 3] Hope that helps, Januk On Mar 16, 6:49 am, Dr Andy D Kucar P2EE4 www.radio4u.com > I would like to be able to pass a composite name Head, e.g., > FirstSecondThird to a Module, > and then, inside the module, use FirstSecondThird, First, Second, Third Heads, and/or make other Operate ions on Heads How could this be accomplished? > === Subject: Re: Fast way to select those elements from a list that are in another > Unfortunately, Pick[a, Thread[a == b]] doesn't perform the same task. In > subsequently evaluates to true: >> SameQ[s1,s2,Sequence[]] >> SameQ[s1,s2] >> True This brings up an interesting quirk: you can only use SameQ to verify that > two things are identical if you can be sure that none of them is Sequence[]! You are right, of course. Sorry about my silly post! (I totally missed the point). -- Jean-Marc === Subject: Re: Fast way to select those elements from a list that are in another Unfortunately, Pick[a, Thread[a == b]] doesn't perform the same task. In subsequently evaluates to true: >> SameQ[s1,s2,Sequence[]] >> SameQ[s1,s2] >> True This brings up an interesting quirk: you can only use SameQ to verify that two things are identical if you can be sure that none of them is Sequence[]! -----Original Message----- === Subject: Re: Fast way to select those elements from a list that are in another > Two lists of integers: {a, b} = Table[RandomInteger[10000, 1000], {2}]; Which elements from a are in b? Select[a, MemberQ[b, #] &]; // Timing > {0.351, Null} It takes about 0.351 seconds (on my slow laptop). Specialised > functions for related tasks, such as Intersection[a, b], are much > faster: Intersection[a, b]; // Timing > {0., Null} Using Intersection, here's a somewhat faster way to select those > elements from a that are in b: With[ > {c = Intersection[a, b]}, > Select[a, MemberQ[c, #] &] > ]; // Timing > {0.09, Null} Is there a better, faster way to do this? Andrew, I have came up with the following, which is, I believe, the fastest among all solutions that have been posted (as of today): Pick[a, Thread[a == b]] For instance, {a, b} = Table[RandomInteger[10000, 1000], {2}]; s1 = Select[a, MemberQ[b, #] &]; // Timing // First s2 = With[{c = Intersection[a, b]}, Select[a, MemberQ[c, #] &]]; // Timing // First s3 = Pick[a, Thread[a == b]]; // Timing // First (* 0.127442 0.01327 0.000111 True *) -- Jean-Marc === Subject: Re: Fast way to select those elements from a list that are in another > Two lists of integers: {a, b} = Table[RandomInteger[10000, 1000], {2}]; Which elements from a are in b? Select[a, MemberQ[b, #] &]; // Timing > {0.351, Null} It takes about 0.351 seconds (on my slow laptop). Specialised > functions for related tasks, such as Intersection[a, b], are much > faster: Intersection[a, b]; // Timing > {0., Null} Using Intersection, here's a somewhat faster way to select those > elements from a that are in b: With[ > {c = Intersection[a, b]}, > Select[a, MemberQ[c, #] &] > ]; // Timing > {0.09, Null} Is there a better, faster way to do this? Andrew, I have came up with the following, which is, I believe, the fastest among all solutions that have been posted (as of today): Pick[a, Thread[a == b]] For instance, {a, b} = Table[RandomInteger[10000, 1000], {2}]; s1 = Select[a, MemberQ[b, #] &]; // Timing // First s2 = With[{c = Intersection[a, b]}, Select[a, MemberQ[c, #] &]]; // Timing // First s3 = Pick[a, Thread[a == b]]; // Timing // First (* 0.127442 0.01327 0.000111 True *) -- Jean-Marc === Subject: Re: IsIntegerOrFloat for comparison, IIOF1[list_]:=With[{ll=Flatten@list}, If[Length[ll]==Length[Cases[ll,_Real|_Integer]], True,False]]; (* Peter Breitfeld *) (* Szabolcs Horvat *) IIOF3[expr_]:=Cases[expr, {False}->False/.{}->True; (* Jean-Marc Gulliet *) IIOF4[expr_]:=VectorQ[expr,NumberQ[#]&&(Head[#]=!=Rational)&& (Head[#]=!=Complex)&]; (* Andrzej Kozlowski *) (* Albert Retey's submission not tested since it wasnt wrapped as function *) A timing test on a random-float list of 10^6 items gives (version 5.2 on MacBook Pro laptop running Mac OS X 10.4.11, dual 2.3GHz Intel processors) IIOF1 0.396629 Second IIOF2 2.47186 Second IIOF3 2.81298 Second II0F4 2.9122 Second I have no idea why IIOF1 is about 6 times faster than the others. === Subject: Re: IsIntegerOrFloat > (* Albert Retey's submission not tested since it wasnt > wrapped as function *) I just wanted to mention that it is just as good wrapped as a function as the others, it just makes definitions for more than one kind of arguments: IIOF5[n_Real] := True IIOF5[n_Integer] := True IIOF5[lst_List] := And @@ (IIOF5/@ lst) IIOF5[___] := False You can use IIOF5 just as any function with just one definition. I think this i a very common and useful technique in mathematica, especially for functions like this, which shall return either True or False for any kind of argument given (in mathematica, these usually end with Q for Question). If speed matters - as you have indicated with your comparisons - IIOF5 comes out as second best only, so you might also consider this: IIOF6[expr_List] := Union[Union[data[[All, 0]]], {Real, Integer}] == Union[{Integer, Real}] timings: {#, Timing[#[data];][[1]]} & /@ {IIOF1, IIOF2, IIOF3, IIOF4, IIOF5, IIOF6} { {IIOF1, 0.641}, {IIOF2, 3.593}, {IIOF3, 4.079}, {IIOF4, 4.156}, {IIOF5, 1.094}, {IIOF6, 0.265} } > I have no idea why IIOF1 is about 6 times faster than the others. In general things like this are not always easy to explain. In this case it looks like the use of pattern matching vs. extraction of heads seams to be crucial to improve speed. This was also what made me come up with IIOF6... hth, albert === Subject: Re: IsIntegerOrFloat One possibility is IsIntegerOrFloat[list_List] := VectorQ[list, MemberQ[{Real,Integer}, Head[#]]&] Bhuvanesh, Wolfram Research === Subject: Re: Number of monomials > To count the number of terms in a sum, use e.g. > Length[{ Sequence@@sum }] Sorry, this is incorrect. I think that the only reliable way to count the number of terms in a sum is to explicitly check if there is only one or more terms. numOfTerms[terms_Plus] := Length[terms] numOfTerms[term_] := 1 === Subject: Re: Global setting of Graphics options for plot, listplot, listlogplot... > Has anyone any experience (v6) with setting global graphics options. > What I want to do is fairly simple. I want all my graphics to have a > frame, automatic gridlines of a particular colour and the same font > etc. Fonts are easy, I can set those as in Option Inspector (Formatting > Options/Expression Formatting/Graphics Box Options/GraphicsBoxOptions) > in BaseStyle and DefaultBaseStyle. Setting Frame and GridLinesStyles here is not a good plan though as > plot legends and graphics Grid use invisible graphics boxes to > position things. Adding frames and grids lines to all graphics boxes > will corrupt these place holder boxes. I can, in my init.m file introduce altered values for Options[Plot] > with Frame->True etc but I have to do this for Plot, ListPlot, > LogPlot, ListLogPlot etc of which there are quite a few. Question is can anyone think of a better way? > I believe that there is no better way. You must set options explicitly for all plotting functions that you wish to alter. However, this can be done with a single SetOptions command: SetOptions[{Plot, ListPlot, ParametricPlot, ...}, Frame -> True, Axes -> False] But note that several of the graphics options have different default settings between these functions. === Subject: Re: Global setting of Graphics options for plot, listplot, listlogplot... I would recommend against spending too much time trying to make a 'universal plot format'. You can certainly do it if you are producing repetitive plots of a specific type, say weather data plotted each day or a number of experimental data runs whose results were quite similar. But the average technical person is going to have a range of graphics requirements. Each set of data or each mathematical idea will require its own style of presentation if the message is going to be conveyed with maximum effectiveness. What this come down to is that graphics is work if you really want to convey the clearest message and each graphic requires its individual treatment. Nevertheless, there are things you can do for a number of similar plots. One approach is to create your own Show statement with the desired options: MyShow[plot_] := Show[plot, Frame -> True, GridLinesStyle -> GrayLevel[0.8], GridLines -> Automatic, BaseStyle -> {FontSize -> 12}, ImageSize -> 450] This works fairly well for simple linear scale plots. MyShow[Plot[Sin[x], {x, 0, 6 [Pi]}]] data = Table[{x, x Cos[x]}, {x, 0, 6 [Pi], 6 [Pi]/100}]; MyShow[ListPlot[data]] But not for Log plots because there the grid has to be generated within the Log plot. MyShow[LogPlot[x!/(1 + x^2), {x, 0, 3}]] So you could make a second Show statement that did not set the GridLines so you could inherit them from the Log plot. MyLogShow[plot_] := Show[plot, Frame -> True, GridLinesStyle -> GrayLevel[0.8], BaseStyle -> {FontSize -> 12}, ImageSize -> 450] MyLogShow[LogPlot[x!/(1 + x^2), {x, 0, 3}, GridLines -> Automatic]] But then, do you really like Mathematics's choice of GridLines there? So trying to create a universal plot format or style will only tend to divert you from the much more interesting issues that have to do with your individual plots and probably won't save you much time in the long run. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Has anyone any experience (v6) with setting global graphics options. > What I want to do is fairly simple. I want all my graphics to have a > frame, automatic gridlines of a particular colour and the same font > etc. Fonts are easy, I can set those as in Option Inspector (Formatting > Options/Expression Formatting/Graphics Box Options/GraphicsBoxOptions) > in BaseStyle and DefaultBaseStyle. Setting Frame and GridLinesStyles here is not a good plan though as > plot legends and graphics Grid use invisible graphics boxes to > position things. Adding frames and grids lines to all graphics boxes > will corrupt these place holder boxes. I can, in my init.m file introduce altered values for Options[Plot] > with Frame->True etc but I have to do this for Plot, ListPlot, > LogPlot, ListLogPlot etc of which there are quite a few. Question is can anyone think of a better way? > ZSG > === Subject: Re: Dynamic and J/Link > I'm using Java to do some agent-based modeling and am wondering what > the best way is to create a dynamic graphic that will update > automatically whenever the state of the simulation changes. Suppose - for sake of argument - that the simulation is a single Java > object saved in a Mathematica variable called model. Suppose that > calling the Java method step() advances the simulation one iteration > and that calling the Java method getState() returns a rectangular 2D > array of 0s and 1s. Now, one easy way of representing the state of > the model is by using Raster, so the following gives a basic graphic > representation: Graphics[ Raster[model@getState[]] ] Suppose, now, that we wrap that statement with Dynamic as follows: Dynamic[ > Graphics[ Raster[ model@getState[] ] ] > ] If I then evaluate the following, the displayed graphic doesn't change > at all, even though (intuitively, at least) it should: model@step[]; > Update[ model ] For some reason, calling Update on the variable model doesn't cause > the Dynamic object in the notebook to recognize that it needs to > refresh the displayed graphic. Why is that? Now, the only way I've found to solve this problem is the draw the > display using a second variable which contains a local copy of the > state of the Java object. First, set up the initial display in the > notebook as follows: array = model@getState[]; > Dynamic[ > Graphics[ Raster[ array ] ] > ] then manually update the variable array each time the simulation > changes: model@step[]; > array = model@getState[]; (* This triggers a redisplay *) The two irritations about this are that it (a) it requires polluting > the current Mathematica's session namespace with another variable that > doesn't do anything except hold a value which could be easily obtained > by calling model@getState[], and (b) it requires some (minor) > additional code to configure each display. Those aren't real worries, > but it does suggest that I'm not doing this the most efficient way. Is the above solution the best (or, indeed, only) way to get Dynamic > to recognize state changes of J/Link objects? Does anyone else have My experience is also that Update is, unlike stated in the documentation, not really causing Dynamic to realize changes, even in other circumstances. Others have given hints about workarounds, another thing that probably helps is the UpdateInterval option of Dynamic. Of course it doesn't do the same thing, but in many cases where external processes are involved in my opinion it is an even better approach. Other than that I have also used global variables that just indicate the changing of something that otherwise wouldn't be recognized by Dynamic. To make your code more clean and robust, it is probably a good idea to encapsulate this in an extra function as David Bailey has suggested. hth, albert === Subject: Re: conversion of sin to cos > Hello all, Here is my problem. I have a very long product of cosines with > arguments of the form k*Pi, k being integers. > I want to convert this expression to a sum of cosines. TrigReduce > works fine, except that it converts cos to sin. > So, I want all the sin (after the TrigReduce) to be converted to cos > and the arguments be of the form p*Pi, p being rational of course. > It has something to do with Hold or HoldAll, but I don't know the > details. Or perhaps the TrigReduce can be overridden > somehow. > Can someone help? > Hi Glenn, you don't need a CAS for this. I'll just use Mathematica syntax here: For integer k: Cos[k*Pi]==(-1)^k. If your product is Product[Cos[k[i]*Pi],{i,1,n}], then it can be written as (-1)^Mod[Sum[k[i],{i,1,n}],2] or if you insist on cosines: Cos[Mod[Sum[k[i],{i,1,n}],2]*Pi]. Peter === Subject: Re: conversion of sin to cos > Hello all, Here is my problem. I have a very long product of cosines with > arguments of the form k*Pi, k being integers. Cos[k*Pi] == (-1)^k, so your expression is probably a bit more complicated than that :-) > I want to convert this expression to a sum of cosines. TrigReduce > works fine, except that it converts cos to sin. > So, I want all the sin (after the TrigReduce) to be converted to cos > and the arguments be of the form p*Pi, p being rational of course. Have you tried expression /. Sin[a_] :> Cos[a - Pi/2] or expression /. Sin[a_] :> Cos[Collect[a - Pi/2, Pi]] or expression /. Sin[a_] :> Cos[Collect[a - Pi/2, Pi, Together]] ? It would be easier to answer if you posted a short sample of a Sin-expression that you need converted to a Cos-expression. > It has something to do with Hold or HoldAll, but I don't know the > details. Hold[] just prevents evaluation of its arguments. HoldAll is not a function, but an attribute. It is the attribute that gives Hold[] its magic. > Or perhaps the TrigReduce can be overridden > somehow. > Can someone help? > === Subject: Re: conversion of sin to cos > Here is my problem. I have a very long product of cosines with > arguments of the form k*Pi, k being integers. > I want to convert this expression to a sum of cosines. TrigReduce > works fine, except that it converts cos to sin. > So, I want all the sin (after the TrigReduce) to be converted to cos > and the arguments be of the form p*Pi, p being rational of course. > It has something to do with Hold or HoldAll, but I don't know the > details. Or perhaps the TrigReduce can be overridden > somehow. Hi Glenn, Please, could you post an actual (short) example of such a product as well as what you get having trigreduced it? Meanwhile, Simplify/FullSimplify with the option ComplexityFunction might be what you are looking for. -- Jean-Marc === Subject: Re: conversion of sin to cos > Hello all, Here is my problem. I have a very long product of cosines with > arguments of the form k*Pi, k being integers. > I want to convert this expression to a sum of cosines. TrigReduce > works fine, except that it converts cos to sin. > So, I want all the sin (after the TrigReduce) to be converted to cos > and the arguments be of the form p*Pi, p being rational of course. > It has something to do with Hold or HoldAll, but I don't know the > details. Or perhaps the TrigReduce can be overridden > somehow. > Can someone help? > It might be helpful to give a small actual example of what you want to achieve. As you have described it, I would have thought the answer would reduce to +1 or -1. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: conversion of sin to cos > Hello all, Here is my problem. I have a very long product of cosines with > arguments of the form k*Pi, k being integers. > I want to convert this expression to a sum of cosines. TrigReduce > works fine, except that it converts cos to sin. > So, I want all the sin (after the TrigReduce) to be converted to cos > and the arguments be of the form p*Pi, p being rational of course. > It has something to do with Hold or HoldAll, but I don't know the > details. Or perhaps the TrigReduce can be overridden > somehow. > Can someone help? Cos[J Pi] is + or - depending on whether J is respy even/odd . If there are m odd Pis and n even Pis, then J = m alone decides the sign, - for odd m and + for even m. HTH === Subject: Re: variance of product of 2 independent variables Hi Rudy, obvioulsy the equation - ^2^2 = v(a) +v(b) + v(a)v(b) is wrong. You can see this easily by considering the units. This also gives a hint how to correct: - ^2^2 = v(a)^2 +v(b)^2 + v(a)v(b) hope this helps, Daniel > Hello Ben - I have a question about the subject matter. To review, you sent Frank > Brand the following: < correlations among them), > then you can compute the variance of their product quite easily v(ab) := < a^2b^2 > - < ab >^2 = - ^2^2 = v(a) + > v(b) + v(a)v(b); > v(a)=-^2, v(b)=-^2 here v(.) denotes variance, <.> denotes mean. > Note that we do not have to assume normal distributions for a and b, > essential is that their are uncorrelated, hence the means of products > factor into products of means.If = 1000 and = 0.001, and v(a) = 100 and v(b) = 1e-10 (in other > words, both a and b have 1% standard deviations), then I compute v(ab) = > 100*0.001 + 1e-10*1000 + 100*1e-10 ~ 0.1 > which is obviously wrong ( = 1.000 and std deviation would be > sqrt(0.1) = 0.31. Help! Da stimmt was nicht! Rudy dankwort > Phoenix AZ USA >