> Is there a Mathematica package (other than NMinimize) that solves MINLP and > MILP optimization problems ? > Etienne I purchased the commercial Mathematica package Operations Research 2.0, and it offers a mixed-integer linear programming (MILP) solver. It accepts any combination of real, integer, and binary variables. It also offers a specialized solver for binary-only variables. There is also the commercial package Industrial Optimization that may offer this as well, although the price for the latter is much greater than the former. For MINLP, perhaps Industrial Opt offers this (check Wolfram's website), but you may also benefit from the Global Optimization 4.0 Mathematica package by Loehle Associates (which I own and am happy with). ==== I am creating bar charts for values that have fairly long names. The default > BarLabels option depicts the labels horizontally, causing the labels to over > run eachother and make the chart unreadable. Is there a way to alter the > orientation of the bar labels to veritical? The solution I prefer is to turn the bars horizontal, so the long labels appear left of the abscissa and can be easily read. Do this: BarChart[stuff, BarOrientation -> Horizontal] Depending upon your operating system, you may need to add RotateLabel->False. On Mac OSX I don't have to, because the Mac version cannot rotate text anyway :( Hope this helps. Tom Burton PS Still running 4.1.5. ==== I am working on a linear programming problem. Does anybody know how to check for multiple optima with the linear programming tools in Mathematica (LinearProgramming ConstrainedMin, ConstrainedMax)? In case of multiple optima, what will be the answer of mathematica? Many thanks ----------- Giacomo Calzolari University of Bologna, Department of Economics Piazza Scaravilli 2 40126, Bologna, Italy Web http://www.dse.unibo.it/calzolari/ ----------- ==== What you want is a change of variables: expr = x + y + z/(x + y) + e^(x + y) + (w*x) + y; expr /. x -> z - y /. z -> x 1 + e^x + x + w*(x - y) + y Treat -----Original Message----- >I have an expression: x+y+z/(x+y)+e^(x+y)+w*x+y.... I want to replace >any (x+y) term by x noer how the expression looks like. I tried >/.command. However, it does not work properly. Is there any simple way >of doing this? Use ReplaceRepeated x+y+z/(x+y)+e^(x+y)+w*(x+y) //. x+y->x e^x + w*x + x + z/x > Bob Hanlon > Chantilly, VA USA : ==== Actually, she wants a change of variables: expr/.x->z-y/.z->x. -----Original Message----- x + y + z/(x + y) + e^(x + y) + w*(x + y) //. x + y -> x e^x + x + w*x + z/x David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator : ==== Just a small change: insertx[str_] := Module[{foo = str, vars, n, pos}, foo = StringReplace[foo, {)( -> foo = StringReplace[foo, {) -> ], ( -> Cross[}]; n = Length[StringPosition[foo, .]]; Do[pos = StringPosition[foo, .][[1]]; foo = StringReplacePart[foo, ToString[Slot[i]], pos] (*Print[foo]*), {i, n}]; ToExpression[foo <> &]] (* put & here *) insertx[str1] insertx[str1][j, k, i, k, k, i] (* not here *) Treat -----Original Message----- travelling and cannot subscribe to the mathgroup right now - it would Silvia ******************************** i = {1, 0, 0}; j = {0, 1, 0}; k = {0, 0, 1}; zero = {0, 0, 0}; a = {i, j, k} str1 = (((..)(..))(..)) The function insertx is to convert this string of parentheses and dots into a cross product, where each dot represents a different variable, and the parentheses indicate the groupings of the cross product. insertx[str_] := Module[{foo = str, vars, n, pos}, foo = StringReplace[ foo, {)( -> ),(, .( -> .,(, ). -> ),., .. -> .,.}]; foo = StringReplace[foo, {) -> ], ( -> Cross[}]; n = Length[StringPosition[foo, .]]; Do[pos = StringPosition[foo, .][[1]]; foo = StringReplacePart[foo, ToString[Slot[i]], pos] (*Print[foo]*) , {i, n}]; ToExpression[foo]] The function properly converts the string into the associated cross product, but does not evaluate correctly. Checking whether what is returned by the function is still a string gives a false, and it should, as the function should return an expression. (the output is indented) insertx[str1] ((#1[Cross]#2)[Cross](#3[Cross]#4))[Cross](#5[Cross]#6) insertx[str1] &[j, k, i, k, k, i] ((#1[Cross]#2)[Cross](#3[Cross]#4))[Cross](#5[Cross]#6) StringQ[insertx[str1]] False Typing in the corresponding cross product by hand and evaluating it returns the correct result. Cross[Cross[Cross[#1, #2], Cross[#3, #4]], Cross[#5, #6]] &[j, k, i, k, k, i] {1, 0, 0} What is wrong??? I have spent many hours on trying to understand this, so either I am completely off or there is a bug. ==== Below is a simple-minded implementation that delivers the factor of 10 I previously suggested in private. It's only first order, but you could improve it as needed easily. Tom Burton > I've tracked down the slow operation of my Mathematica simulation code to > lie in the ListIntegrate command: G[n_] := ListIntegrate[xsec Phi[n], 1] where both xsec and Phi[n] are 400 values long. Is there a way to speed up ListIntegrate via Compile or a similar technique? > In[2]:= < Any ideas on how to solve for the periodic solution of this equation A(t)=S(t+P)-(ln(2)/halflife)*A(t) S(t+P) = S(t) if t1 S(t+P) = 0 otherwise where P is the period of the system > t is the time at which a sample is taken > t1 is the beginning of a discontinuity > t2 is the end of a discontinuity > A(t) is the abundance at time t I want to fit data to the resulting equation and find t1 and t2 Sincerely, Tom > ==== I am using Mathematica 4. I am attempting to solve simultaneously a set of 6 first order conditions for six unknowns. I have successfully used the FindRoot command to solve for actual numerical values for the six unknowns when all other variables in the six equations are assigned to numeric values. However, I would now like to solve for the same six unknowns, this time solving them for expressions including the other variables (not solving for numeric values). I have been trying to use the Solve command to do this but with no success. Mathematica comes to a stop when it reaches this line of the code and, even after running for several hours, gives no result. Am I attempting the impossible? The six first order conditions are fairly complicated. Here is an example: ******* so1 = Exp[ a1*v1 - b1*v1^2/2 - c*r1]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) so2 = Exp[ a2*v1 - b2*v2^2/2 - c*r2]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) so3 = Exp[ a3*v3 - b3*v3^2/2 - c*r3]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) so0 = 1 - so1 - so2 - so3 x1 = (a1 - b1*v1)/c x2 = (a2 - b2*v2)/c x3 = (a3 - b3*v3)/c t1 = so1*(r1 - f1 - df1 + (v1 - k1 - dm1)*x1) t2 = so2*(r2 - f2 - df2 + (v2 - k2 - dm2)*x2) t3 = so3*(r3 - f3 - df3 + (v3 - k3 - dm3)*x3) foc1v = D[t1, v1] foc2v = D[t2, v2] foc3v = D[t3, v3] foc1r = D[t1, r1] foc2r = D[t2, r2] foc3r = D[t3, r3] Solve[{foc1v == 0, foc2v == 0, foc3v == 0, foc1r == 0, foc2r == 0, foc3r == 0}, {v1,v2,v3,r1,r2,r3}] ******* Here I am hoping to solve {v1,v2,v3,r1,r2,r3} in terms of the f's and k's. Any suggestions? Is Solve the correct command to use? ==== I think Solve is correct to be used, but, having non-linear equations, probably analitically unsolvable. I did something much similar but much simpler, and the resulting formula was so big that the notebook was larger than 73MB! I am using Mathematica 4. I am attempting to solve simultaneously a > set of 6 first order conditions for six unknowns. I have successfully > used the FindRoot command to solve for actual numerical values for the > six unknowns when all other variables in the six equations are > assigned to numeric values. However, I would now like to solve for > the same six unknowns, this time solving them for expressions > including the other variables (not solving for numeric values). I > have been trying to use the Solve command to do this but with no > success. Mathematica comes to a stop when it reaches this line of the > code and, even after running for several hours, gives no result. Am I > attempting the impossible? The six first order conditions are fairly > complicated. > Here is an example: ******* so1 = Exp[ > a1*v1 - b1*v1^2/2 - c*r1]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + > Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) > so2 = Exp[ > a2*v1 - b2*v2^2/2 - c*r2]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + > Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) > so3 = Exp[ > a3*v3 - b3*v3^2/2 - c*r3]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + > Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) > so0 = 1 - so1 - so2 - so3 > x1 = (a1 - b1*v1)/c > x2 = (a2 - b2*v2)/c > x3 = (a3 - b3*v3)/c > t1 = so1*(r1 - f1 - df1 + (v1 - k1 - dm1)*x1) > t2 = so2*(r2 - f2 - df2 + (v2 - k2 - dm2)*x2) > t3 = so3*(r3 - f3 - df3 + (v3 - k3 - dm3)*x3) > foc1v = D[t1, v1] > foc2v = D[t2, v2] > foc3v = D[t3, v3] > foc1r = D[t1, r1] > foc2r = D[t2, r2] > foc3r = D[t3, r3] > Solve[{foc1v == 0, foc2v == 0, foc3v == 0, foc1r == 0, foc2r == 0, > foc3r == 0}, {v1,v2,v3,r1,r2,r3}] ******* Here I am hoping to solve {v1,v2,v3,r1,r2,r3} in terms of the f's and > k's. Any suggestions? Is Solve the correct command to use? > ==== I have a list of expressions. Some of them include radicals. When the radical exponent is even, and the expression inside the radical is not a number, the corresponding element will not be defined if the expression inside the radical is negative. In such cases, I want to replace the original element by a list of elements which includes the element itself, and the expressions contained in such radicals. I found a way to do this for the parcial case in which there is only one radical of that kind in an element. I tried to do it using ReplaceAll, but did not succeed. So I used this LONG way. In[] v1 = {Sqrt[3]*x + 4, 5*x + x^2, 1 + Sqrt[2 + 5*x], (6*x - 1)^(1/5) + 2, 3*x - (2*x - 1)^(1/6), (2 + x^3)^(1/8)} Out[] {4 + Sqrt[3]*x, 5*x + x^2, 1 + Sqrt[2 + 5*x], 2 + (-1 + 6*x)^(1/5), 3*x - (-1 + 2*x)^(1/6), (2 + x^3)^(1/8)} In[] = p1=Position[v1,Power[a_,Rational[1,b_]]/;EvenQ[b]/;NumberQ[a]==True] Out[] {{3,2},{5,2,2},{6}} In[] p1f=p1/.{a_Integer,___}=AEa Out[] {3,5,6} In[] vv1[{a__}]:=v1[[a]] In[] = new1=Table[{v1[[p1f[[i]]]],vv1[p1[[i]]]},{i,Length[p1]}]/.{a_,Power[b_, Rational[1,_]]}=AE{a,b} Out[] {{1 + Sqrt[2 + 5*x], 2 + 5*x}, {3*x - (-1 + 2*x)^(1/6), -1 + 2*x}, {(2 + x^3)^(1/8), 2 + x^3}} In[] s1=ReplacePart[v1,new1,Split[p1f],Split[Range[Length[p1]]]] Out[] {4 + Sqrt[3]*x, 5*x + x^2, {1 + Sqrt[2 + 5*x], 2 + 5*x}, 2 + (-1 + 6*x)^(1/5), {3*x - (-1 + 2*x)^(1/6), -1 + 2*x}, {(2 + x^3)^(1/8), 2 + x^3}} When more than one of these situation occur in an element, this method does not work. In[] v3 = {Sqrt[3]*x + 4, 5*x + x^2, 1 + Sqrt[2 - (x^3 - 3*x - 8)^(1/4) + 5*x], (6*x - 1)^(1/5) + 2, 3*x - (2*x - 1)^(1/6), (2*x^(1/4) + x^3*(4*x^2 - 3)^(1/10))^(1/8)} {4 + Sqrt[3]*x, 5*x + x^2, 1 + Sqrt[2 + 5*x - (-8 - 3*x + x^3)^(1/4)], 2 + (-1 + 6*x)^(1/5), 3*x - (-1 + 2*x)^(1/6), (2*x^(1/4) + x^3*(-3 + 4*x^2)^(1/10))^(1/8)} What I want to get is In[] sol3 = {Sqrt[3]*x + 4, 5*x + x^2, {1 + Sqrt[2 - (x^3 - 3*x - 8)^(1/4) + 5*x], 2 - (x^3 - 3*x - 8)^(1/4) + 5*x, x^3 - 3*x - 8}, (6*x - 1)^(1/5) + 2, {3*x - (2*x - 1)^(1/6), 2*x - 1}, {(2*x^(1/4) + x^3*(4*x^2 - 3)^(1/10))^(1/8), 2*x^(1/4) + x^3*(4*x^2 - 3)^(1/10), x, 4*x^2 - 3}} I don=B4t see how I can use ReplacePart in this situation, because the new elements will have different lengths. In[] = p3=Position[v3,Power[a_,Rational[1,b_]]/;EvenQ[b]/;NumberQ[a]==True] Out[] {{3,2,1,3,2},{3,2},{5,2,2},{6,1,1,2},{6,1,2,2},{6}} I could do it step by step. But, since I do not know in advance the number of occurrences, I would have to change the formulas every time the input changes. Julio ==== I should have checked before: Compile doesn't make any difference on my machine. (Used too; old habits die hard;) So roughly as fast and simpler is li[y_,d_]:=Tr[(#[[1]]+#[[2]])d/2&/@Partition[y,2,1]] Tom Burton ------ Forwarded Message > I've tracked down the slow operation of my Mathematica simulation code to > lie in the ListIntegrate command: G[n_] := ListIntegrate[xsec Phi[n], 1] where both xsec and Phi[n] are 400 values long. Is there a way to speed up ListIntegrate via Compile or a similar technique? > In[2]:= < New Cell Defaults > CommonDefaultFormatTypes. Is Input set to StandardForm? I wouldn't fret too long over this before reinstalling Mathematica. That should definitely cure the problem. --- Selwyn Hollis slhollis@mac.com http://www.math.armstrong.edu/faculty/hollis > I recently began using Mathematica 4.1 on Mac OS X, upgrading from 4.0 > running > on Mac OS 9. One of the nice features of the OS 9 version (and the > a lot of nice editor functionality. It would highlight unmatched > braces, it would auto-indent code in a pleasant manner, and so on. > However, these features don't seem to be working in the OS X > version--I feel like I'm editing Mathematica in Notepad. Is there some option I can use to turn these features on? Pillsbury -- > Pillsbury > pillsy@mac.com > ==== All, Has anyone been able to get Mathematica on a mac to connect to a remote kernel by SSH? --- ==== Here's what I have: F[a_, b_, c_, d_, e_, f_, X_] := (a + b X + c X^2 + d X^3 + e X^4 + f X^5)* Exp[-(((X - m)/sd)^2)/2]/(Sqrt[2Pi]sd) The strange thing, and I'd appreciate someone shedding some light on this, is that this: !(Integrate[ F[p_0, p_1, p_2, p_3, p_4, p_5, X]*((((X - m))/sd))^5, {X, (-Infinity), Infinity}, Assumptions -> {sd > 0}]) (I cut and pasted that it looks like it works) Anyway, THAT gives me an answer really quickly... (within 5 minutes on my box) JUST changing it from p0..5 to a,b,c,d,e,f like so: Integrate[F[a, b, c, d, e, f, X]*((X - m)/sd)^5, {X, -Infinity, Infinity}, Assumptions -> {sd > 0}] Causes mathematica to go into an infinite loop (seemingly after 6 hours). This ... sucks. How am I to know if a certain equation is solvable, if only I choose the right variables?? Binesh Bannerjee -- For in much wisdom is much grief, and he that increaseth knowledge increaseth sorrow. -- Ecclesiastes 1:18 SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub ==== Since Mathgroup had so much fun with the recent problem of counting occurences of ...,1,0,... in a list of zeros and ones, I thought I'd try to bring the collective intelligence to bear on the following: Given a matrix M of real numbers and a pair of real numbers a and b, what is the most efficient way to achieve the effect of applying the function Max[Min[#,b],a]& to each number in M? ---- Selwyn Hollis slhollis@mac.com : Hui Zou ==== I'm looking for some cad tools for control design & analysis in mathematica. ==== I think, the JLink User Guide of Tod Gayley is good and contains some examples. Mathematica interactively over the Internet and also makes it possible to invocate Java from the Mathematica session. So I used JLink in both directions. You can read about my Application Server under www.schmitther.de The invocation of Java from the Mathematica session is not yet described in these web pages. Hermann Schmitt ----- Original Message ----- > Antonio Garcia > Berkeley Physics (and RAND Corporation, at times...) ==== > Is anyone here familiar with J/Link, the new and promising (if at the > moment totally maddening) interface between Mathematica and java? It seems > few sample programs have been written, there are no debugging features, > and little real documentation. er... the 100+ pages JLink UserGuide (available as NB and PDF File) is not enough for you? I actually cannot think of many things that are not in there... I don't know what version you use, or how you got J/Link, but I guess, the UserGuide was supplied... if not, get it from the J/Link site: http://www.wolfram.com/solutions/mathlink/jlink/ or use this link here for directly fetching the NB of the UserGuide: http://www.wolfram.com/solutions/mathlink/jlink/documentation/JLinkUserGuide .nb > If so, I have a number of questions for you... Well ... bring them on: murphee ==== (http://www.smartpsread.com/mathematica.php) using J/Link and have had no problem using the javadoc. We are specifically calling mathematica from Java. What exactly are your questions? Is anyone here familiar with J/Link, the new and promising (if at the > moment totally maddening) interface between Mathematica and java? It seems > few sample programs have been written, there are no debugging features, > and little real documentation. If so, I have a number of questions for you... Antonio Garcia > Berkeley Physics (and RAND Corporation, at times...) > ==== I have the following program: oo`newContext[ctxp_] := ( BeginPackage[ctxp[[1]]]; ) oo`resumeContext[] := ( EndPackage[]; $ContextPath = Drop[$ContextPath, 1]; ) oo`new11[x_] := ( Print[Begin new11]; klassnam = x; ctx = klassnam <> `; oo`newContext[{ctx}]; ); oo`new12[] := ( Print[Name klasse - Begin]; Print[$Context: , $Context]; ToExpression[klasse]; Print[Context of klasse: , Context[klasse]]; oo`resumeContext[]; Print[Name klasse - End]; ); Print[Begin Programm:]; Print[$Context: , $Context]; oo`new11[Rechteck]; oo`new12[]; Print[after new12:]; Print[$Context: , $Context]; I get the following results: Begin Programm: $Context: Global` Begin new11 Name klasse - Begin $Context: Rechteck` klasse klasse::shdw: Symbol klasse appears in multiple contexts {Rechteck`, Global`} ; definitions in context Rechteck` may shadow or be shadowed by other definitions.Context of klasse: Global` Name klasse - End after new12: $Context: Global` In[14]:= My question is: Why is the variable klasse also defined in the context Global? Hermann Schmitt ==== I have a new program: oo`hfield = klasse1; oo`newContext[ctxp_] := ( $ContextPath = Join[ctxp, $ContextPath]; BeginPackage[ctxp[[1]]]; If[Length[ctxp]>1, $ContextPath = Join[ctxp, Rest[$ContextPath]]; ] ) oo`resumeContext[] := ( EndPackage[]; $ContextPath = Drop[$ContextPath, 1]; ) oo`new11[x_] := ( Print[Anfang new11]; klassnam = x; tsx = ToString[klassnam]; oo`dat = D:Math_OOclasses <> tsx <> .cl; ctx = klassnam <> `; oo`newContext[{ctx}]; ) oo`new12[] := ( Print[Name klasse - Anfang]; Print[$Context: , $Context]; ToExpression[oo`hfield]; Print[Context von klasse: , Context[klasse]]; oo`resumeContext[]; Print[Name klasse - Ende]; ); Print[Anfang Programm:]; Print[$Context: , $Context]; oo`new11[Rechteck]; Print[nach new11:]; Print[$Context: , $Context]; oo`hfield = klasse; oo`new12[]; Print[nach new12:]; Print[$Context: , $Context]; and the results: Anfang Programm: $Context: Global` Anfang new11 nach new11: $Context: Rechteck` Name klasse - Anfang $Context: Rechteck` klasse klasse::shdw: Symbol klasse appears in multiple contexts {Rechteck`, Global`} ; definitions in context Rechteck` may shadow or be shadowed by other definitions.Context von klasse: Global` Name klasse - Ende nach new12: $Context: Global` In[19]:= According your theory, I think, klasse1 should be defined in Global` and klasse only in Rechteck But this is not the case. Therefore - excuse me - I doubt, that your theory is correct. Hermann Schmitt ----- Original Message ----- > Print[$Context: , $Context]; > ToExpression[klasse]; > Print[Context of klasse: , Context[klasse]]; > oo`resumeContext[]; > Print[Name klasse - End];) is converted into internal form (with contexted symbols) prior to > evaluation. This is before > oo`new11[Rechteck]; > is evaluated -- > ------ > Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > I have the following program: > > oo`newContext[ctxp_] := ( > BeginPackage[ctxp[[1]]]; > ) > oo`resumeContext[] := ( > EndPackage[]; > $ContextPath = Drop[$ContextPath, 1]; > ) > oo`new11[x_] := ( > Print[Begin new11]; > klassnam = x; > ctx = klassnam <> `; > oo`newContext[{ctx}]; > ); > oo`new12[] := ( > Print[Name klasse - Begin]; > Print[$Context: , $Context]; > ToExpression[klasse]; > Print[Context of klasse: , Context[klasse]]; > oo`resumeContext[]; > Print[Name klasse - End]; > ); > Print[Begin Programm:]; > Print[$Context: , $Context]; > oo`new11[Rechteck]; > oo`new12[]; > Print[after new12:]; > Print[$Context: , $Context]; > > I get the following results: > > Begin Programm: > $Context: Global` > Begin new11 > Name klasse - Begin > $Context: Rechteck` > klasse > klasse::shdw: Symbol klasse appears in multiple contexts {Rechteck`, > Global`} > ; definitions in context Rechteck` > may shadow or be shadowed by other definitions.Context of klasse: > Global` > Name klasse - End > after new12: > $Context: Global` > In[14]:= > > My question is: > Why is the variable klasse also defined in the context Global? > > Hermann Schmitt ==== the variable klasse becomes defined when you give the definition for oo`new21[] Just try it out and evaluate only the oo`* defintions and Names[Global`*] will list {ctx, ctxp, klasse, klassnam} The problem is, that you use Print[Context of klasse: , Context[klasse]]; in your definition and this will create the klasse symbol when oo`new21[] is defined. Jens I have the following program: oo`newContext[ctxp_] := ( > BeginPackage[ctxp[[1]]]; > ) > oo`resumeContext[] := ( > EndPackage[]; > $ContextPath = Drop[$ContextPath, 1]; > ) > oo`new11[x_] := ( > Print[Begin new11]; > klassnam = x; > ctx = klassnam <> `; > oo`newContext[{ctx}]; > ); > oo`new12[] := ( > Print[Name klasse - Begin]; > Print[$Context: , $Context]; > ToExpression[klasse]; > Print[Context of klasse: , Context[klasse]]; > oo`resumeContext[]; > Print[Name klasse - End]; > ); > Print[Begin Programm:]; > Print[$Context: , $Context]; > oo`new11[Rechteck]; > oo`new12[]; > Print[after new12:]; > Print[$Context: , $Context]; I get the following results: Begin Programm: > $Context: Global` > Begin new11 > Name klasse - Begin > $Context: Rechteck` > klasse > klasse::shdw: Symbol klasse appears in multiple contexts {Rechteck`, > Global`} > ; definitions in context Rechteck` > may shadow or be shadowed by other definitions.Context of klasse: > Global` > Name klasse - End > after new12: > $Context: Global` > In[14]:= My question is: > Why is the variable klasse also defined in the context Global? Hermann Schmitt ==== Hermann, > My question is: > Why is the variable klasse also defined in the context Global? klasse is created in the context Global` when the assignment oo`new12[] := (Print[Name klasse - Begin]; Print[$Context: , $Context]; ToExpression[klasse]; Print[Context of klasse: , Context[klasse]]; oo`resumeContext[]; Print[Name klasse - End];) is converted into internal form (with contexted symbols) prior to evaluation. This is before oo`new11[Rechteck]; is evaluated -- ------ Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > I have the following program: oo`newContext[ctxp_] := ( > BeginPackage[ctxp[[1]]]; > ) > oo`resumeContext[] := ( > EndPackage[]; > $ContextPath = Drop[$ContextPath, 1]; > ) > oo`new11[x_] := ( > Print[Begin new11]; > klassnam = x; > ctx = klassnam <> `; > oo`newContext[{ctx}]; > ); > oo`new12[] := ( > Print[Name klasse - Begin]; > Print[$Context: , $Context]; > ToExpression[klasse]; > Print[Context of klasse: , Context[klasse]]; > oo`resumeContext[]; > Print[Name klasse - End]; > ); > Print[Begin Programm:]; > Print[$Context: , $Context]; > oo`new11[Rechteck]; > oo`new12[]; > Print[after new12:]; > Print[$Context: , $Context]; I get the following results: Begin Programm: > $Context: Global` > Begin new11 > Name klasse - Begin > $Context: Rechteck` > klasse > klasse::shdw: Symbol klasse appears in multiple contexts {Rechteck`, > Global`} > ; definitions in context Rechteck` > may shadow or be shadowed by other definitions.Context of klasse: > Global` > Name klasse - End > after new12: > $Context: Global` > In[14]:= My question is: > Why is the variable klasse also defined in the context Global? Hermann Schmitt > ==== The problem is that the assumption {x+y==x} is exactly the same as {y==0} ,e.g. : Simplify[y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] e^x + w*x + z/x which presumably is not what was wanted (if it was than it is much simpler just to substitute y -> 0}? Quite frankly, the original request does not make any mathematical sense at all, at least to me. For a start, it is hard to imagine under what conditions it is reasonable to substitute x for x+y if y is not 0! In addition, what does it mean to say there is still one more term if we rewrite the answer? If x+2y contains x+y because it can be rewritten as (x+y) + y than so does x+1/2 y since that can be re-written as (x+y)-1/2y and so does any expression. The kind of magic that seems to asked for cannot be achieved either by syntactic pattern matching (because of the need to interpret contains) or by Simplify which uses wll defined mathematical rules (and in this case the only well defined rule is y==0). Actually on second thoughts I began to suspect that this question is related to another one posted by Heather, concerning simplifying expressions in which x is much larger than y. I am not at all sure if a sensible calculus of this kind can be developed but obviously Simplify will not do this. Moreover, it seems to me that under any sensible interpretation of much larger than, if x+y is approximately x, than so is x+2y, and so on. In other words, x is essentially Infinity in relation to y. If so, there is no reason then why a single y should be left int the answer and x+ (any numeric quantity) y ought to be replaced by just x (without at the same time assuming that y is zero). This sort of thing may perhaps be achieved with the following rule: x + y + z/(x + y) + e^(x + y) + e^y + w*x + y//. x + (k:(_?NumericQ):1)*y -> x e^x + e^y + x + w*x + z/x Andrzej Kozlowski >> I tried ReplaceRepeated, however, I got the following answer: >> x+y+z/(x+y)+e^(x+y)+(w*x)+y//. x+y->x >> e^x+x+(w*x)+2y+z/x >> In fact, there is still one more (x+y) term if we rewritten the answer. > That Heather, Use Simplify with the assumption x+y=x: Simplify[x + y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] e^x + x + w*x + z/x In other circumstances we may have to give more help Simplify (or > FullSimplify). > Please check possiblities in the Help Browser. > ------ > Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== > I tried ReplaceRepeated, however, I got the following answer: > x+y+z/(x+y)+e^(x+y)+(w*x)+y//. x+y->x e^x+x+(w*x)+2y+z/x In fact, there is still one more (x+y) term if we rewritten the answer. > That Heather, Use Simplify with the assumption x+y=x: Simplify[x + y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] e^x + x + w*x + z/x In other circumstances we may have to give more help Simplify (or > FullSimplify). > Please check possiblities in the Help Browser. > ------ > Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 > The problem is that the assumption {x+y==x} is exactly the same as {y==0} ,e.g. : Simplify[y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] e^x + w*x + z/x which presumably is not what was wanted (if it was than it is much simpler just to substitute y -> 0}? Quite frankly, the original request does not make any mathematical sense at all, at least to me. For a start, it is hard to imagine under what conditions it is reasonable to substitute x for x+y if y is not 0! In addition, what does it mean to say there is still one more term if we rewrite the answer? If x+2y contains x+y because it can be rewritten as (x+y) + y than so does x+1/2 y since that can be re-written as (x+y)-1/2y and so does any expression. The kind of magic that seems to asked for cannot be achieved either by syntactic pattern matching (because of the need to interpret contains) or by Simplify which uses wll defined mathematical rules (and in this case the only well defined rule is y==0). Actually on second thoughts I began to suspect that this question is related to another one posted by Heather, concerning simplifying expressions in which x is much larger than y. I am not at all sure if a sensible calculus of this kind can be developed but obviously Simplify will not do this. Moreover, it seems to me that under any sensible interpretation of much larger than, if x+y is approximately x, then so is x+2y, and so on. In other words, x is essentially Infinity in relation to y. If so, there is no reason then why a single y should be left int the answer and x+ (any numeric quantity) y ought to be replaced by just x (without at the same time assuming that y is zero). This sort of thing may perhaps be achieved with the following rule: x + y + z/(x + y) + e^(x + y) + e^y + w*x + y//. x + (k:(_?NumericQ):1)*y -> x e^x + e^y + x + w*x + z/x Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== First, thank you for all the response. In fact, my second question about replace do relate to the first question about simplification with much less assumptions. It is an Engineering problem. I have circuits with different parasitic capacitors and resistors. The transfer function of the circuit in frequency domain (S domain) is very complicated. I need to simplify the frequency response under certain assumptions. Then, it will be easier for me to find the dominant poles and zeros of the transfer function. Previously I do the simplification by hand. Sometimes it is time-consuming and very easy to make mistakes. Since I started using Mathematica recently, I am trying to figure out whether Mathematica can easily help me in simplifying transfer functions. For example, a transfer function in S domain is as follows: TF(s) = gm1* (gds2+gm2+A*gm2 +cbd2*s)/((gds1*(gds2+(cbd2+cload)*s)+s*(cload*(gds2+gm2+A*gm2+cbd2*s)+c1*(g ds2+(cbd2+cload)*s)))....(Eqn.1) Where gds1 is much less than gm1 (Assumption 1), gds2 is much less than gm2 (Assumption 2) , cbd2 is much less than cload (Assum. 3) and A is much larger than 1 (Assum. 4). s=j*w where w refers to the frequency. Here s is a variable. It ranges from 0 to infinity. When s=0, we can get the DC gain as TF(0)=gm1*(gds2+gm2+A*gm2)/(gds1*gds2)........(Eqn. 2), which can be approximated as gm1*A*gm2/(gds1*gds2) under the assumptions. All the parameters in the above equations are positive. Please note that Assum. 1,2,3 and 4 are the only assumptions we have. There is no other relationship definitions between different parameters. For example, we do not know whether gds1 is larger than gds2 or not. Or gm1 is larger than gm2 or not and so on and so forth. Obviously, when simplifying TF(s), we can not simply assume gds2->0, gds1->0 and cbd2->0. If we redefine gds1/gm1 as x, gds2/gm2 as y, cbd2/cload as z, TF(s) becomes a function of {x, y, z, gm1,gm2,cload,c1,A}as shown below, TF(s)=gm1*(gm2+A*gm2+gm2*y+cload*s*z))/(cload*gm2*s+A*cload*gm2*s+c1*cload*s ^2+cload*gm1*s*x+c1*gm2*s*y +cload*gm2*s*y+gm1*gm2*x*y+c1*cload*s^2*z+cload2*s2*z+cload*gm1*s*x*z)...... .....(Eqn.3) After using Limit function on TF with x->0 & y->0 & z->0, TF(s) will be (1+A)*gm1*gm2/(cload*s*(gm2+A*gm2+c1*s))......(Eqn.4) At the first glance, the answer seems simple enough. However, if we verify the answer, we find it is totally wrong because now TF(0) becomes infinite other than what we shown in Eqn. (2). Furthermore, the location of poles and zero of TF(s) are changed. One reason causing this error is that Mathematica removes any terms that have x, y or z . For example, cload*s*z term is being deleted by Mathematica by mistake after Limit function. In fact, the value of cload*s*z is undefined although z is close to zero. cload*s*z can be very large if s and cload are both very large compared with z. I also found some other methods such as using Series & Normal or using MachineEpsilon & chop are not practical for my case. In order to avoid deleting some terms mistakenly as what happened in Limit function, I think the only way is to go back to Eqn. (1) and just let Mathematica to replace (gm1+gds1) by gm1, (gm2+gds2) by gm2 and (cbd2+cload) by cload. By doing this, we can guarantee that gds1 will be neglected only when gm1 and gds1 have common coefficients. For example, cload*gm2+cload*gds2 will be replace by cload*gm2. But cload*gm2+c1*gds2 will not be changed since gm2 and gds2 do not have common coefficients. To speak frankly, after trying all the above methods, I found simplying TF by hand is comparably straight forward. Anyone who have comments, better suggestions are quite welcome. Anyone who have similar experience on circuit analysis, please let me know whether you have better simplification method or not. I am looking forward to hearing Heather ----- Original Message ----- which, if I remember correctly the original posting (I did not keep it) > was not wanted. But hen we are just guessing what's in another persons > mind. > She's looking for a change of variables. Nothing mysterious about it. > > Expr/.x->z-y/.z->x > > > > -----Original Message----- > Sent: Saturday, July 27, 2002 9:42 AM > Cc: mathgroup@smc.vnet.net > Replace > > I tried ReplaceRepeated, however, I got the following answer: >> x+y+z/(x+y)+e^(x+y)+(w*x)+y//. x+y->x > e^x+x+(w*x)+2y+z/x > In fact, there is still one more (x+y) term if we rewritten the > answer. > Simplify[x + y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] >> That > Heather, > Use Simplify with the assumption x+y=x: > e^x + x + w*x + z/x > In other circumstances we may have to give more help Simplify (or >> FullSimplify). >> Please check possiblities in the Help Browser. ------ >> Hayes >> Mathematica Training and Consulting >> Leicester UK >> www.haystack.demon.co.uk >> hay@haystack.demon.co.uk >> Voice: +44 (0)116 271 4198 > > The problem is that the assumption {x+y==x} is exactly the same as > {y==0} ,e.g. : > > Simplify[y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] > > e^x + w*x + z/x > > which presumably is not what was wanted (if it was than it is much > simpler just to substitute y -> 0}? Quite frankly, the original request > does not make any mathematical sense at all, at least to me. For a > start, it is hard to imagine under what conditions it is reasonable to > substitute x for x+y if y is not 0! In addition, what does it mean to > say there is still one more term if we rewrite the answer? If x+2y > contains x+y because it can be rewritten as (x+y) + y than so does > x+1/2 y since that can be re-written as (x+y)-1/2y and so does any > expression. The kind of magic that seems to asked for cannot be achieved > > either by syntactic pattern matching (because of the need to interpret > contains) or by Simplify which uses wll defined mathematical rules > (and in this case the only well defined rule is y==0). > > Actually on second thoughts I began to suspect that this question is > related to another one posted by Heather, concerning simplifying > expressions in which x is much larger than y. I am not at all sure if > a sensible calculus of this kind can be developed but obviously Simplify > > will not do this. Moreover, it seems to me that under any sensible > interpretation of much larger than, if x+y is approximately x, then > so is x+2y, and so on. In other words, x is essentially Infinity in > relation to y. If so, there is no reason then why a single y should be > left int the answer and x+ (any numeric quantity) y ought to be > replaced by just x (without at the same time assuming that y is zero). > This sort of thing may perhaps be achieved with the following rule: > > x + y + z/(x + y) + e^(x + y) + e^y + w*x + y//. > x + (k:(_?NumericQ):1)*y -> x > > e^x + e^y + x + w*x + z/x > Andrzej Kozlowski > Toyama International University > JAPAN > http://platon.c.u-tokyo.ac.jp/andrzej/ > ==== > Actually on second thoughts I began to suspect that this question is > related to another one posted by Heather, concerning simplifying > expressions in which x is much larger than y. I am not at all sure if > a sensible calculus of this kind can be developed but obviously Simplify > will not do this. It seems to me that this is essentially a (capital-C) Calculus problem, and unless a simple /.y->0 is what's wanted, the correct tool is Limit[]. Berkeley's critique of 18th century Calculus applies here: while it was essentially antiscientific, his reasoning was flawless and should warn us against trying to solve this sort of problem by mindless algebra. Of course, Limit[] is a tricky and somewhat unreliable power tool, requiring caution. This reflects the mathematical subtlety of this kind of problem. It is generally essential to formulate the problem in such a way that the direction of the approach to the limit is unambiguous. -- | John Doty You can't confuse me, that's my job. | Home: jpd@w-d.org | Work: jpd@space.mit.edu ==== I want to convert long sequences of Mathematica graphics cells (conventional plots, with some Text on them) to a steppable slide show or movie after they're created. I've done this using the Edit>Save Selection as QuickTime menu command to get a QuickTime movie, then playing the movie back with the QuickTime movie player, and it works OK. But what's the *best/simplest/easiest/most effective* way to do a lot of these? (best way to export initially, preferably under Notebook control, best export format, best way to play back) (on a Mac, OS 9.1, Mathematica 4.0.1) Criteria: * Full screen or near full screen playback * Pretty good image quality -- minimal jaggies * Single-frame step forward and back using arrow keys ==== I have created a palette using placeholders, but every time I apply the functions in the palette to expression in a notebook, the font size of the palette resets the cell's font size in the notebook. How can I stop this from happening? : ==== Try algebra: Solve[A[t] == S[t + P] - Log[2]/halflife*A[t], A[t]] {{A[t] -> S[P + t]/ (1 + Log[2]/halflife)}} That works noer what values S takes on, so your one equation won't let you solve for S between t1 and t2. If A is known and you're solving for S, it's still algebra, but A would have to satisfy the boundary conditions. Treat -----Original Message----- t is the time at which a sample is taken t1 is the beginning of a discontinuity t2 is the end of a discontinuity A(t) is the abundance at time t I want to fit data to the resulting equation and find t1 and t2 Sincerely, Tom ==== I want to make some simple packages. Not even much worried about contexts or protection, since all symbols likely to be global anyway. But I would like to put multiple cells including notebook type header cells in these packages -- primarily, I suppose, because this makes the code so much easier to edit and more readable, for me anyway, than using (* *) style comments. 1) All the package demos and templates I've seen seem to be single cells (though that's not always very clearly stated). Do packages have to be single cells? Or can they have multiple cells, including header cells? 2) How come compound expressions in these single-cell packages don't seem to need semicolons between the expressions? 3) As an alternative to a package, suppose I just want a cell in notebook A to execute the entirely of another notebook B, again with no context concerns, all symbols global, and notebooks A and B both open on the desktop. What exactly do I need to put in notebook A to do this? (I can read all about the NotebookCreate, NotebookWrite, NotebookFind commands -- I just can't find a NotebookRun or NotebookExecute command.) Mac PB G3, OS 9.1, Mathematica 4.0. : kuska@informatik.uni-leipzig.de ==== you want to preprare a package with the notebook frontend ? *and* you have not read http://support.wolfram.com/mathematica/packages/writing/make.html especial item 2 of the url above will help you. Jens I want to make some simple packages. Not even much worried about > contexts or protection, since all symbols likely to be global anyway. But I would like to put multiple cells including notebook type header > cells in these packages -- primarily, I suppose, because this makes the > code so much easier to edit and more readable, for me anyway, than using > (* *) style comments. 1) All the package demos and templates I've seen seem to be single > cells (though that's not always very clearly stated). Do packages have > to be single cells? Or can they have multiple cells, including header > cells? 2) How come compound expressions in these single-cell packages don't > seem to need semicolons between the expressions? 3) As an alternative to a package, suppose I just want a cell in > notebook A to execute the entirely of another notebook B, again with no > context concerns, all symbols global, and notebooks A and B both open on > the desktop. > > What exactly do I need to put in notebook A to do this? (I can read all > about the NotebookCreate, NotebookWrite, NotebookFind commands -- I just > can't find a NotebookRun or NotebookExecute command.) Mac PB G3, OS 9.1, Mathematica 4.0. : ==== The trapezoidal rule is equivalent to an appropriate Dot product. Here are four methods compared: ListIntegrate, Integrate[Interpolation] with interpolation order descending from 3 to 1, and a Dot product. The weight vector for the Dot product can be pre-computed, so this will save a LOT of time. For the random data below there's no significant difference in accuracy, but high-order interpolation may be important for other data. I'd compare answers for the Dot product and third-order interpolation, and then decide if the difference is worth the extra time. (I doubt it.) << NumericalMath`ListIntegrate` n = 100000; h = 1/n; data = Transpose[{Range[0, n]/n, Random[] & /@ Range[0, n]}]; ListIntegrate[data] // Timing Integrate[Interpolation[data, InterpolationOrder -> 3][ x], {x, 0, 1}] // Timing Integrate[Interpolation[data, InterpolationOrder -> 2][x], {x, 0, 1}] // Timing Integrate[Interpolation[data, InterpolationOrder -> 1][x], {x, 0, 1}] // Timing wts = {h/2}~Join~(h & /@ Range[n - 1])~Join~{h/2}; wts.data[[All, 2]] // Timing {2.6559999999999997*Second, 0.49906638684786364} {2.6719999999999997*Second, 0.49906638684786364} {2.187000000000001*Second, 0.49887608638890346} {1.8130000000000006*Second, 0.4990676925038021} {0.10999999999999943*Second, 0.4990724913628793} Treat -----Original Message----- {x,0,100}]//Timing {4.56 Second,13.768} Trapezium rule with equal steps: #[[1]]+#[[-1]]+ 2 Tr[Take[#,{2,-2}]]&[data[[All,2]]] 0.01/2//Timing {0.22 Second,13.768} Trapezium rule with possibly unequal steps (Drop[#1,1] - Drop[#1,-1]).(Drop[#2,-1] + Drop[#2,1])&[ data[[All,1]], data[[All,2]]]/2//Timing {0.83 Second,13.768} -- ------ Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > I've tracked down the slow operation of my Mathematica simulation code to > lie in the ListIntegrate command: G[n_] := ListIntegrate[xsec Phi[n], 1] where both xsec and Phi[n] are 400 values long. Is there a way to speed up ListIntegrate via Compile or a similar technique? > > --- >hew Rosen > Harvard-Smithsonian Center for Astrophysics > Mail Stop 59 > 60 Garden Street > Cambridge, MA 02138 e: mrosen@cfa.harvard.edu > o: (617) 496-7614 > : ==== Emily, First of all, you want DSolve, not Solve. Secondly, if you were using Solve, its second argument is the list of variables you want to solve for, and I don't think that's what you've listed below... aren't those the parameters you want to solve in terms of? -----Original Message----- have been trying to use the Solve command to do this but with no success. Mathematica comes to a stop when it reaches this line of the code and, even after running for several hours, gives no result. Am I attempting the impossible? The six first order conditions are fairly complicated. Here is an example: ******* so1 = Exp[ a1*v1 - b1*v1^2/2 - c*r1]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) so2 = Exp[ a2*v1 - b2*v2^2/2 - c*r2]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) so3 = Exp[ a3*v3 - b3*v3^2/2 - c*r3]/(1 + Exp[a1*v1 - b1*v1^2/2 - c*r1] + Exp[a2*v2 - b2*v2^2/2 - c*r2] + Exp[a3*v3 - b3*v3^2/2 - c*r3]) so0 = 1 - so1 - so2 - so3 x1 = (a1 - b1*v1)/c x2 = (a2 - b2*v2)/c x3 = (a3 - b3*v3)/c t1 = so1*(r1 - f1 - df1 + (v1 - k1 - dm1)*x1) t2 = so2*(r2 - f2 - df2 + (v2 - k2 - dm2)*x2) t3 = so3*(r3 - f3 - df3 + (v3 - k3 - dm3)*x3) foc1v = D[t1, v1] foc2v = D[t2, v2] foc3v = D[t3, v3] foc1r = D[t1, r1] foc2r = D[t2, r2] foc3r = D[t3, r3] Solve[{foc1v == 0, foc2v == 0, foc3v == 0, foc1r == 0, foc2r == 0, foc3r == 0}, {v1,v2,v3,r1,r2,r3}] ******* Here I am hoping to solve {v1,v2,v3,r1,r2,r3} in terms of the f's and k's. Any suggestions? Is Solve the correct command to use? : ==== We can do even better, by using a Dot product to replace whatever order of Interpolation we choose, as follows. We could compute the weight vector from theory, but I'll just discover it by differentiation -- particularly useful if the step-size isn't constant. For 3rd-order, the weight vector is 'wts2' below. If we want an even higher (or lower) order fit, replace ListIntegrate with Integrate and Interpolation as before. e[i_, n_] := Array[{0, Boole[i + 1 == #]} &, n] d[i_, data_] := ListIntegrate[data + e[i, Length[ data]]] - ListIntegrate[data] wts2 = d[#, data] & /@ Range[0, n]; -----Original Message----- time. (I doubt it.) << NumericalMath`ListIntegrate` n = 100000; h = 1/n; data = Transpose[{Range[0, n]/n, Random[] & /@ Range[0, n]}]; ListIntegrate[data] // Timing Integrate[Interpolation[data, InterpolationOrder -> 3][ x], {x, 0, 1}] // Timing Integrate[Interpolation[data, InterpolationOrder -> 2][x], {x, 0, 1}] // Timing Integrate[Interpolation[data, InterpolationOrder -> 1][x], {x, 0, 1}] // Timing wts = {h/2}~Join~(h & /@ Range[n - 1])~Join~{h/2}; wts.data[[All, 2]] // Timing {2.6559999999999997*Second, 0.49906638684786364} {2.6719999999999997*Second, 0.49906638684786364} {2.187000000000001*Second, 0.49887608638890346} {1.8130000000000006*Second, 0.4990676925038021} {0.10999999999999943*Second, 0.4990724913628793} Treat -----Original Message----- {x,0,100}]//Timing {4.56 Second,13.768} Trapezium rule with equal steps: #[[1]]+#[[-1]]+ 2 Tr[Take[#,{2,-2}]]&[data[[All,2]]] 0.01/2//Timing {0.22 Second,13.768} Trapezium rule with possibly unequal steps (Drop[#1,1] - Drop[#1,-1]).(Drop[#2,-1] + Drop[#2,1])&[ data[[All,1]], data[[All,2]]]/2//Timing {0.83 Second,13.768} -- ------ Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 > I've tracked down the slow operation of my Mathematica simulation code to > lie in the ListIntegrate command: G[n_] := ListIntegrate[xsec Phi[n], 1] where both xsec and Phi[n] are 400 values long. Is there a way to speed up ListIntegrate via Compile or a similar technique? > > --- >hew Rosen > Harvard-Smithsonian Center for Astrophysics > Mail Stop 59 > 60 Garden Street > Cambridge, MA 02138 e: mrosen@cfa.harvard.edu > o: (617) 496-7614 > : ==== h is the step-size, and n+1 is the number of points. In computing the wts vector for equal step-sizes, those are all that count. X~Join~y is the same as Join[x,y], and h&/Range[n-1] is a vector of n-1 h values. I was working from 's starting point, so the data matrix is a set of {x,y} pairs, but that needn't be where you start. Just Dot wts with the argument of ListIntegrate in your problem. As I mentioned before, you can precompute wts*xsec and then Dot that with Phi[n], to eliminate multiplying two 400-long vectors at each computation of G, along with eliminating ListIntegrate. I just sent another post that shows how to replace Integrate & Interpolation with Dot at any order of interpolation. Hence, if you want seventh- or twentieth-order interpolation, you can get that at almost no extra cost. My machine is a Gateway 700XL Pentium 4, 2.2GHz with 1024 MB RDRAM. I bought too soon at that (February); the new 700XL has a 2.53GHz chip for the same price. That just makes me mad! -----Original Message----- --On Saturday, July 27, 2002 3:10 PM -0500 DrBob are four methods compared: ListIntegrate, Integrate[Interpolation] with > interpolation order descending from 3 to 1, and a Dot product. The > weight vector for the Dot product can be pre-computed, so this will save > a LOT of time. For the random data below there's no significant > difference in accuracy, but high-order interpolation may be important > for other data. I'd compare answers for the Dot product and third-order > interpolation, and then decide if the difference is worth the extra > time. (I doubt it.) << NumericalMath`ListIntegrate` > n = 100000; > h = 1/n; > data = Transpose[{Range[0, n]/n, Random[] & /@ Range[0, n]}]; > ListIntegrate[data] // Timing > Integrate[Interpolation[data, InterpolationOrder -> 3][ > x], {x, 0, 1}] // Timing > Integrate[Interpolation[data, InterpolationOrder -> 2][x], {x, 0, 1}] // > > Timing > Integrate[Interpolation[data, InterpolationOrder -> 1][x], {x, 0, 1}] // > > Timing > wts = {h/2}~Join~(h & /@ Range[n - 1])~Join~{h/2}; > wts.data[[All, 2]] // Timing {2.6559999999999997*Second, 0.49906638684786364} > {2.6719999999999997*Second, 0.49906638684786364} > {2.187000000000001*Second, 0.49887608638890346} > {1.8130000000000006*Second, 0.4990676925038021} > {0.10999999999999943*Second, 0.4990724913628793} Treat -----Original Message----- > Sent: Saturday, July 27, 2002 5:44 AM > To: mathgroup@smc.vnet.net Mathew, Some possibilities < Integrate[ > Interpolation[data, InterpolationOrder[Rule]1][x], > {x,0,100}]//Timing {4.56 Second,13.768} Trapezium rule with equal steps: #[[1]]+#[[-1]]+ 2 Tr[Take[#,{2,-2}]]&[data[[All,2]]] 0.01/2//Timing {0.22 Second,13.768} Trapezium rule with possibly unequal steps (Drop[#1,1] - Drop[#1,-1]).(Drop[#2,-1] + Drop[#2,1])&[ > data[[All,1]], data[[All,2]]]/2//Timing {0.83 Second,13.768} -- > ------ > Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 >> I've tracked down the slow operation of my Mathematica simulation > code to >> lie in the ListIntegrate command: >> G[n_] := ListIntegrate[xsec Phi[n], 1] >> where both xsec and Phi[n] are 400 values long. >> Is there a way to speed up ListIntegrate via Compile or a similar > technique? >> >> --- >>hew Rosen >> Harvard-Smithsonian Center for Astrophysics >> Mail Stop 59 >> 60 Garden Street >> Cambridge, MA 02138 >> e: mrosen@cfa.harvard.edu >> o: (617) 496-7614 --- ==== Oh yeah, the weight vectors don't actually depend on the data. It's fine to use a random vector of the right length for computing weights. -----Original Message----- along with eliminating ListIntegrate. I just sent another post that shows how to replace Integrate & Interpolation with Dot at any order of interpolation. Hence, if you want seventh- or twentieth-order interpolation, you can get that at almost no extra cost. My machine is a Gateway 700XL Pentium 4, 2.2GHz with 1024 MB RDRAM. I bought too soon at that (February); the new 700XL has a 2.53GHz chip for the same price. That just makes me mad! -----Original Message----- --On Saturday, July 27, 2002 3:10 PM -0500 DrBob are four methods compared: ListIntegrate, Integrate[Interpolation] with > interpolation order descending from 3 to 1, and a Dot product. The > weight vector for the Dot product can be pre-computed, so this will save > a LOT of time. For the random data below there's no significant > difference in accuracy, but high-order interpolation may be important > for other data. I'd compare answers for the Dot product and third-order > interpolation, and then decide if the difference is worth the extra > time. (I doubt it.) << NumericalMath`ListIntegrate` > n = 100000; > h = 1/n; > data = Transpose[{Range[0, n]/n, Random[] & /@ Range[0, n]}]; > ListIntegrate[data] // Timing > Integrate[Interpolation[data, InterpolationOrder -> 3][ > x], {x, 0, 1}] // Timing > Integrate[Interpolation[data, InterpolationOrder -> 2][x], {x, 0, 1}] // > > Timing > Integrate[Interpolation[data, InterpolationOrder -> 1][x], {x, 0, 1}] // > > Timing > wts = {h/2}~Join~(h & /@ Range[n - 1])~Join~{h/2}; > wts.data[[All, 2]] // Timing {2.6559999999999997*Second, 0.49906638684786364} > {2.6719999999999997*Second, 0.49906638684786364} > {2.187000000000001*Second, 0.49887608638890346} > {1.8130000000000006*Second, 0.4990676925038021} > {0.10999999999999943*Second, 0.4990724913628793} Treat -----Original Message----- > Sent: Saturday, July 27, 2002 5:44 AM > To: mathgroup@smc.vnet.net Mathew, Some possibilities < Integrate[ > Interpolation[data, InterpolationOrder[Rule]1][x], > {x,0,100}]//Timing {4.56 Second,13.768} Trapezium rule with equal steps: #[[1]]+#[[-1]]+ 2 Tr[Take[#,{2,-2}]]&[data[[All,2]]] 0.01/2//Timing {0.22 Second,13.768} Trapezium rule with possibly unequal steps (Drop[#1,1] - Drop[#1,-1]).(Drop[#2,-1] + Drop[#2,1])&[ > data[[All,1]], data[[All,2]]]/2//Timing {0.83 Second,13.768} -- > ------ > Hayes > Mathematica Training and Consulting > Leicester UK > www.haystack.demon.co.uk > hay@haystack.demon.co.uk > Voice: +44 (0)116 271 4198 >> I've tracked down the slow operation of my Mathematica simulation > code to >> lie in the ListIntegrate command: >> G[n_] := ListIntegrate[xsec Phi[n], 1] >> where both xsec and Phi[n] are 400 values long. >> Is there a way to speed up ListIntegrate via Compile or a similar > technique? >> >> --- >>hew Rosen >> Harvard-Smithsonian Center for Astrophysics >> Mail Stop 59 >> 60 Garden Street >> Cambridge, MA 02138 >> e: mrosen@cfa.harvard.edu >> o: (617) 496-7614 --- Matthew Rosen Harvard-Smithsonian Center for Astrophysics Mail Stop 59 60 Garden Street Cambridge, MA 02138 e: mrosen@cfa.harvard.edu o: (617) 496-7614 ==== It seems that compilation might be useful, at least for the trapezium rule: datay = Table[100Sin[x], {x, 0, 100, .001}]; TrapeziumRule[{a_, r___, b_}, h_] := (a + b + 2Tr[{r}])/2 h TrapeziumRule[datay,.001]//Timing {1.37 Second,13.7681} TrapeziumRuleCmp = Compile[ {{data, _Real, 1}, h}, #[[1]] + #[[-1]] + 2 Tr[Take[#, {2, -2}]] &[data] h/2 ]; TrapeziumRuleCmp[datay,.001]//Timing {0.44 Second,13.7681} -- ------ Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 : ==== Sorry; one more tweak. For large datasets, the previous method involves too many integrations to compute a weight vector, so here's a fix for that, and details of how to compute the vector for any desired order: f[data_, order_] := Integrate[Interpolation[data, InterpolationOrder -> order][x], {x, 0, 1}] d[i_, data_, order_] := f[data + e[i, Length[data]], order] - f[data, order] order = 7; begin = d[#, data, order] & /@ Range[0, order + 1] wts3 = begin~Join~Array[begin[[-1]] &, n - 3 - 2order]~Join~Reverse[begin]; All the weights are the same, except the first and last 'order + 1' of them, so we only have to compute the first 'order + 2'. This wouldn't be so simple, of course, if the step-size isn't constant. In that case, either figure out the formula or do the integrations. -----Original Message----- is the same as Join[x,y], and h&/Range[n-1] is a vector of n-1 h values. I was working from 's starting point, so the data matrix is a set of {x,y} pairs, but that needn't be where you start. Just Dot wts with the argument of ListIntegrate in your problem. As I mentioned before, you can precompute wts*xsec and then Dot that with Phi[n], to eliminate multiplying two 400-long vectors at each computation of G, along with eliminating ListIntegrate. I just sent another post that shows how to replace Integrate & Interpolation with Dot at any order of interpolation. Hence, if you want seventh- or twentieth-order interpolation, you can get that at almost no extra cost. My machine is a Gateway 700XL Pentium 4, 2.2GHz with 1024 MB RDRAM. I bought too soon at that (February); the new 700XL has a 2.53GHz chip for the same price. That just makes me mad! -----Original Message----- --On Saturday, July 27, 2002 3:10 PM -0500 DrBob are four methods compared: ListIntegrate, Integrate[Interpolation] with > interpolation order descending from 3 to 1, and a Dot product. The > weight vector for the Dot product can be pre-computed, so this will save > a LOT of time. For the random data below there's no significant > difference in accuracy, but high-order interpolation may be important > for other data. I'd compare answers for the Dot product and third-order > interpolation, and then decide if the difference is worth the extra > time. (I doubt it.) << NumericalMath`ListIntegrate` > n = 100000; > h = 1/n; > data = Transpose[{Range[0, n]/n, Random[] & /@ Range[0, n]}]; > ListIntegrate[data] // Timing > Integrate[Interpolation[data, InterpolationOrder -> 3][ > x], {x, 0, 1}] // Timing > Integrate[Interpolation[data, InterpolationOrder -> 2][x], {x, 0, 1}] // > > Timing > Integrate[Interpolation[data, InterpolationOrder -> 1][x], {x, 0, 1}] // > > Timing > wts = {h/2}~Join~(h & /@ Range[n - 1])~Join~{h/2}; > wts.data[[All, 2]] // Timing {2.6559999999999997*Second, 0.49906638684786364} > {2.6719999999999997*Second, 0.49906638684786364} > {2.187000000000001*Second, 0.49887608638890346} > {1.8130000000000006*Second, 0.4990676925038021} > {0.10999999999999943*Second, 0.4990724913628793} Treat -----Original Message----- Mathew, Some possibilities < Integrate[ > Interpolation[data, InterpolationOrder[Rule]1][x], > {x,0,100}]//Timing {4.56 Second,13.768} Trapezium rule with equal steps: #[[1]]+#[[-1]]+ 2 Tr[Take[#,{2,-2}]]&[data[[All,2]]] 0.01/2//Timing {0.22 Second,13.768} Trapezium rule with possibly unequal steps (Drop[#1,1] - Drop[#1,-1]).(Drop[#2,-1] + Drop[#2,1])&[ > data[[All,1]], data[[All,2]]]/2//Timing {0.83 Second,13.768} -- >> I've tracked down the slow operation of my Mathematica simulation > code to >> lie in the ListIntegrate command: >> G[n_] := ListIntegrate[xsec Phi[n], 1] >> where both xsec and Phi[n] are 400 values long. >> Is there a way to speed up ListIntegrate via Compile or a similar > technique? >> >> --- >>hew Rosen >> Harvard-Smithsonian Center for Astrophysics >> Mail Stop 59 >> 60 Garden Street >> Cambridge, MA 02138 >> e: mrosen@cfa.harvard.edu >> o: (617) 496-7614 --- Matthew Rosen Harvard-Smithsonian Center for Astrophysics Mail Stop 59 60 Garden Street Cambridge, MA 02138 e: mrosen@cfa.harvard.edu o: (617) 496-7614 ==== There does sem to be a bug here, but it is not quite what you think. It's the first answer that you get that is probably wrong. On the other hand, in the second case it is very unlikely that Mathematica enters an infinite loop, rather it is still trying to arrive at the answer and there is no guarantee that it will reach one after, say a week or a month. As for first case, the reason why the answer is probably this. Evaluate the formula: formula=Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - m)/sd)^5, {X, -Infinity, Infinity}] Now set Evaluate[Table[Subscript[p, i], {i, 1, 5}]] = Table[Random[], {5}] and also sd = Random[]; m = Random[]; Now evaluate again Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - m)/sd)^5, {X, -Infinity, Infinity}] and formula You will almost certainly get different answers, while they clearly ought to be the same. It seems that it is nto the fact that the names you are suing are different that leads to different results in both of your integrals but the fact that the names of the parameters in the first case are not symbols. Officially there is no reason why they should be, but in practice using non-symbols in formulas makes them more complicated and is more likely to result in errors. The really bad news as far as your problem is concerned is that it is the 6 hour fruitless computation that appears to be the correct one ... Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > Here's what I have: F[a_, b_, c_, d_, e_, f_, X_] := (a + b X + c X^2 + d X^3 + e X^4 + f > X^5)* > Exp[-(((X - m)/sd)^2)/2]/(Sqrt[2Pi]sd) The strange thing, and I'd appreciate someone shedding some light on > this, > is that this: !(Integrate[ > F[p_0, p_1, p_2, p_3, p_4, p_5, > X]*((((X - m))/sd))^5, {X, (-Infinity), Infinity}, > Assumptions -> {sd > 0}]) (I cut and pasted that it looks like it works) Anyway, THAT gives me an answer really quickly... (within 5 minutes on > my box) JUST changing it from p0..5 to a,b,c,d,e,f like so: Integrate[F[a, b, c, d, e, f, X]*((X - m)/sd)^5, {X, -Infinity, > Infinity}, > Assumptions -> {sd > 0}] Causes mathematica to go into an infinite loop (seemingly after 6 > hours). This ... sucks. How am I to know if a certain equation is solvable, if > only I choose the right variables?? Binesh Bannerjee -- > For in much wisdom is much grief, and he that increaseth knowledge > increaseth sorrow. -- Ecclesiastes 1:18 SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub > SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub > OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub > ==== : There does sem to be a bug here, but it is not quite what you think. : It's the first answer that you get that is probably wrong. On the other : hand, in the second case it is very unlikely that Mathematica enters an : infinite loop, rather it is still trying to arrive at the answer and : there is no guarantee that it will reach one after, say a week or a : month. : As for first case, the reason why the answer is probably this. Evaluate : the formula: to put in a dated address on the post! Hmmm... I'm not so sure... (I cut and pasted from your post, just so it will all be directly cut and pastable in Mathematica) F[a_,b_,c_,d_,e_,f_,X_] := (a + b X + c X^2 + d X^3 + e X^4 + f X^5) * (Exp[-(((X-m)/sd)^2)/2]/(Sqrt[2Pi]sd)) (* Your formula *) formula=Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - m)/sd)^5, {X, -Infinity, Infinity}] (* I assume you do {i,1,5} instead of {i,0,5} because the result of * the calculation above doesn't include p sub zero *) Evaluate[Table[Subscript[p, i], {i, 1, 5}]] = Table[Random[], {5}] sd = Random[]; m = Random[]; Andrzej = Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - m)/sd)^5, {X, -Infinity, Infinity}] Chop[Andrzej] formula This yields for me: p = {0.76938, 0.670623, 0.624459, 0.386326, 0.773623} Andrzej = 26.036 * (2.08162+(1.66533*10^-16)p0) Chop[Andrzej] = 54.1961 formula = 54.1961 If you just ExpandAll[Andrzej] , you get 54.1961-(4.3358*10^-15)p0 So, I think it's doing the right thing with the p array, it just goes off into some loop with the a,b,c,d,e,f... Is that reasoning sound, or am I missing something? Perhaps I'm missing a point, and they shouldn't be different _at all_... I dunno... Is that safely negligible as machine precision error? Binesh : You will almost certainly get different answers, while they clearly : ought to be the same. It seems that it is nto the fact that the names : you are suing are different that leads to different results in both of : your integrals but the fact that the names of the parameters in the : first case are not symbols. Officially there is no reason why they : should be, but in practice using non-symbols in formulas makes them more : complicated and is more likely to result in errors. : The really bad news as far as your problem is concerned is that it is : the 6 hour fruitless computation that appears to be the correct one ... :> Here's what I have: F[a_, b_, c_, d_, e_, f_, X_] := (a + b X + c X^2 + d X^3 + e X^4 + f :> X^5)* :> Exp[-(((X - m)/sd)^2)/2]/(Sqrt[2Pi]sd) The strange thing, and I'd appreciate someone shedding some light on :> this, :> is that this: !(Integrate[ :> F[p_0, p_1, p_2, p_3, p_4, p_5, :> X]*((((X - m))/sd))^5, {X, (-Infinity), Infinity}, :> Assumptions -> {sd > 0}]) (I cut and pasted that it looks like it works) Anyway, THAT gives me an answer really quickly... (within 5 minutes on :> my box) JUST changing it from p0..5 to a,b,c,d,e,f like so: Integrate[F[a, b, c, d, e, f, X]*((X - m)/sd)^5, {X, -Infinity, :> Infinity}, :> Assumptions -> {sd > 0}] Causes mathematica to go into an infinite loop (seemingly after 6 :> hours). This ... sucks. How am I to know if a certain equation is solvable, if :> only I choose the right variables?? Binesh Bannerjee -- :> For in much wisdom is much grief, and he that increaseth knowledge :> increaseth sorrow. -- Ecclesiastes 1:18 SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub :> SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub :> OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub -- 'One of the cultural barriers that separates computer scientists from regular scientists and engineers is ... the practical scientist is trying to solve tomorrow's problem with yesterday's computer; the computer scientist, we think, often has it the other way around.' -- Numerical Recipes in C SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub ==== Okay, here is my first attempt. Here is what I take to be the test function: funct1[a_, b_, mat_] := Map[Max[Min[#, b], a] &, mat, {2}]; here is my challenger: funct2[a_, b_, mat_] := If[b <= a, Array[a & , Dimensions[mat]], Map[Which[#1 <= a, a, #1 <= b, #1, True, b] & , mat, {2}]] We create a random matrix of entries: In[3]:= mat = Array[Random[] & , {100, 100}]; I shall test separately two cases, when ab: In[4]:= a = 0.3; b = 0.5; In[5]:= Timing[p = funct1[a, b, mat]; ] Out[5]= {0.35 Second,Null} In[6]:= Timing[q = funct2[a, b, mat]; ] Out[6]= {0.02 Second,Null} In[7]:= p == q Out[7]= True Now when a>b In[8]:= a = 0.5; b = 0.3; In[9]:= Timing[p = funct1[a, b, mat]; ] Out[9]= {0.3 Second,Null} In[10]:= Timing[q = funct2[a, b, mat]; ] Out[10]= {0.05 Second,Null} In[11]:= p == q Out[11]= True Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > Since Mathgroup had so much fun with the recent problem of counting > occurences of ...,1,0,... in a list of zeros and ones, I thought I'd try > to bring the collective intelligence to bear on the following: Given a matrix M of real numbers and a pair of real numbers a and b, > what is the most efficient way to achieve the effect of applying the > function Max[Min[#,b],a]& to each number in M? ==== Here is an improved version of funct2 which considerably speeds up the case b<=a: funct2[a_, b_, mat_] := If[b <= a, Map[a&,mat,{2}], Map[Which[#1 <= a, a, #1 <= b, #1, True, b] & , mat, {2}]] Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > Okay, here is my first attempt. Here is what I take to be the test function: funct1[a_, b_, mat_] := Map[Max[Min[#, b], a] &, mat, {2}]; here is my challenger: funct2[a_, b_, mat_] := If[b <= a, > Array[a & , Dimensions[mat]], > Map[Which[#1 <= a, a, #1 <= b, #1, True, b] & , mat, {2}]] We create a random matrix of entries: In[3]:= > mat = Array[Random[] & , {100, 100}]; > I shall test separately two cases, when ab: In[4]:= > a = 0.3; b = 0.5; In[5]:= > Timing[p = funct1[a, b, mat]; ] Out[5]= > {0.35 Second,Null} In[6]:= > Timing[q = funct2[a, b, mat]; ] Out[6]= > {0.02 Second,Null} In[7]:= > p == q Out[7]= > True Now when a>b In[8]:= > a = 0.5; b = 0.3; In[9]:= > Timing[p = funct1[a, b, mat]; ] Out[9]= > {0.3 Second,Null} In[10]:= > Timing[q = funct2[a, b, mat]; ] Out[10]= > {0.05 Second,Null} In[11]:= > p == q Out[11]= > True > Since Mathgroup had so much fun with the recent problem of counting >> occurences of ...,1,0,... in a list of zeros and ones, I thought I'd >> try >> to bring the collective intelligence to bear on the following: >> Given a matrix M of real numbers and a pair of real numbers a and b, >> what is the most efficient way to achieve the effect of applying the >> function Max[Min[#,b],a]& to each number in M? >> ---- >> Selwyn Hollis >> slhollis@mac.com > ==== I've been warned by others in the past that there is some serious flaw in Mathematica's PostScript rendering of 3D graphics, and now I'm running into it in a big way. I'm making a series of, in essence, 3D bar charts using Graphics3D and Show to display vertical towers (Line[]s) of varying heights rising vertically from different points in a base plane; and some of the towers just aren't there -- just don't draw -- randomly as far as I can tell. A given tower will be there in one plot of a sequence, missing in the next one (when its height has changed somewhat), reappear a few plots later, and so on -- typically only one such tower in a given sequence of plots. This is causing me trouble big time. Is there a workaround? Specific commands or options I should avoid? Two add'l notes: 1) As a work-around I replaced all the thick Line[]s in the graphics with long skinny Cuboid[]s, and did not observe any of those to be randomly missing in any case I've tried to date. 2) I also realized that certain other Line[]s in my graphic were long enough to extend outside the PlotRange I had set in the Show[] command. After I corrected this, the randomly missing Line[] problem seemed to go away even when using Line[]s. That was a programming error on my part, but I think nonetheless also still a bug in Mathematica's rendering code: * PlotRange is essentially a windowing or masking command -- it's supposed to let you generate graphic elements that extend outside the plot range, then just not display them, right? (At least it does in many other cases.) * The Line[]s that randomly disappeared were not the Line[]s that ran outside the plotting range, and had no direct connection to them -- and they only disappeared in certain plots, while the overlength Line[]s were present in all the plots. ==== First, let me show how the rule I sent last time can be used to somewhat simplify the manual operations you have been making. We define a rather simple-minded much smaller function by: MuchSmaller[y_, x_][expr_] := expr //. HoldPattern[x + (k : (_?NumericQ) : 1)*y] :> x all it does is try to replace expressions like x+k*y by just plain x when y is much smaller than x. k is any numeric quantity. Now let's consider your case: In[2]:= TF[s_]= gm1* (gds2+gm2+A*gm2 +cbd2*s)/(gds1*(gds2+(cbd2+cload)*s)+s*(cload*(gds2+gm2+A*gm2+cbd2*s)+c1* (g ds2+(cbd2+cload)*s))); In[3]:= TF[0] (gm1*(gds2 + gm2 + A*gm2))/(gds1*gds2) We know that gds2 is much smaller than gm2 so: In[4]:= MuchSmaller[gds2,gm2][%] (gm1*(gm2 + A*gm2))/(gds1*gds2) next we would like to use the fact that A is much smaller than 1. However, the problem with using pattern matching to do this sort of thing is that you first have to transform the expression in such a way that the pattern you are trying to match is explicitly visible. In this case we only need to apply: In[5]:= MuchSmaller[A,1][Factor[%]] (gm1*gm2)/(gds1*gds2) It would not have worked without Factor. One could refine the MuchSmaller function to consider a number of rules at the same time and to try simplifying before using rules, but in the end manual control will always be necessary. With some effort it might indeed be possible to write a sensible set of rules for simplifying expressions using muchsmaller assumptions, although one has to be careful because many usual laws of arithmetic will break down (e.g. suppose we know that x is much smaller than y but we know nothing about a. In that case you do not wish to reduce a + x to just a. However, applying usual laws of aritmetic we get a + x == (a-y) + (y + x) == a-y + y == a). > First, thank you for all the response. In fact, my second question about replace do relate to the first > question > about simplification with much less assumptions. It is an Engineering > problem. I have circuits with different parasitic capacitors and > resistors. > The transfer function of the circuit in frequency domain (S domain) is > very > complicated. I need to simplify the frequency response under certain > assumptions. Then, it will be easier for me to find the dominant poles > and > zeros of the transfer function. Previously I do the simplification by > hand. > Sometimes it is time-consuming and very easy to make mistakes. Since I > started using Mathematica recently, I am trying to figure out whether > Mathematica can easily help me in simplifying transfer functions. For example, a transfer function in S domain is as follows: TF(s) = gm1* (gds2+gm2+A*gm2 > +cbd2*s)/((gds1*(gds2+(cbd2+cload)*s)+s*(cload*(gds2+gm2+A*gm2+cbd2*s)+c1* > (g > ds2+(cbd2+cload)*s)))....(Eqn.1) Where gds1 is much less than gm1 (Assumption 1), gds2 is much less than > gm2 > (Assumption 2) , cbd2 is much less than cload (Assum. 3) and A is much > larger than 1 (Assum. 4). > s=j*w where w refers to the frequency. Here s is a variable. It ranges > from > 0 to infinity. When s=0, we can get the DC gain as TF(0)=gm1*(gds2+gm2+A*gm2)/(gds1*gds2)........(Eqn. 2), which can be approximated as gm1*A*gm2/(gds1*gds2) under the > assumptions. All the parameters in the above equations are positive. Please note that Assum. 1,2,3 and 4 are the only assumptions we have. > There > is no other relationship definitions between different parameters. For > example, we do not know whether gds1 is larger than gds2 or not. Or gm1 > is > larger than gm2 or not and so on and so forth. Obviously, when > simplifying > TF(s), we can not simply assume gds2->0, gds1->0 and cbd2->0. > If we redefine gds1/gm1 as x, gds2/gm2 as y, cbd2/cload as z, TF(s) > becomes > a function of {x, y, z, gm1,gm2,cload,c1,A}as shown below, TF(s)=gm1*(gm2+A*gm2+gm2*y+cload*s*z))/(cload*gm2*s+A*cload*gm2*s+c1*cload* > s > ^2+cload*gm1*s*x+c1*gm2*s*y > +cload*gm2*s*y+gm1*gm2*x*y+c1*cload*s^2*z+cload2*s2*z+cload*gm1*s*x*z)... > ... > .....(Eqn.3) After using Limit function on TF with x->0 & y->0 & z->0, TF(s) will > be > (1+A)*gm1*gm2/(cload*s*(gm2+A*gm2+c1*s))......(Eqn.4) At the first glance, the answer seems simple enough. However, if we > verify > the answer, we find it is totally wrong because now TF(0) becomes > infinite > other than what we shown in Eqn. (2). Furthermore, the location of > poles and > zero of TF(s) are changed. One reason causing this error is that > Mathematica > removes any terms that have x, y or z . For example, cload*s*z term is > being > deleted by Mathematica by mistake after Limit function. In fact, the > value > of cload*s*z is undefined although z is close to zero. cload*s*z can be > very > large if s and cload are both very large compared with z. I also found some other methods such as using Series & Normal or > using > MachineEpsilon & chop are not practical for my case. In order to avoid deleting some terms mistakenly as what happened in > Limit > function, I think the only way is to go back to Eqn. (1) and just let > Mathematica to replace (gm1+gds1) by gm1, (gm2+gds2) by gm2 and > (cbd2+cload) > by cload. By doing this, we can guarantee that gds1 will be neglected > only > when gm1 and gds1 have common coefficients. For example, > cload*gm2+cload*gds2 will be replace by cload*gm2. But cload*gm2+c1*gds2 > will not be changed since gm2 and gds2 do not have common coefficients. To speak frankly, after trying all the above methods, I found simplying > TF > by hand is comparably straight forward. Anyone who have comments, better suggestions are quite welcome. Anyone > who > have similar experience on circuit analysis, please let me know whether > you > have better simplification method or not. I am looking forward to > hearing ----- Original Message ----- > Replace >> Seems to me that this is quite obviously *not* what was asked for as >> it >> will do things like: >> In[15]:= >> e^x /. x -> z - y /. z -> x >> Out[15]= >> e^(x - y) >> which, if I remember correctly the original posting (I did not keep it) >> was not wanted. But hen we are just guessing what's in another persons >> mind. > She's looking for a change of variables. Nothing mysterious about it. > Expr/.x->z-y/.z->x > > -----Original Message----- > Sent: Saturday, July 27, 2002 9:42 AM > Cc: mathgroup@smc.vnet.net > Replace > I tried ReplaceRepeated, however, I got the following answer: > x+y+z/(x+y)+e^(x+y)+(w*x)+y//. x+y->x > e^x+x+(w*x)+2y+z/x > In fact, there is still one more (x+y) term if we rewritten the > answer. > That > Heather, > Use Simplify with the assumption x+y=x: > Simplify[x + y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] > e^x + x + w*x + z/x > In other circumstances we may have to give more help Simplify (or > FullSimplify). > Please check possiblities in the Help Browser. > The problem is that the assumption {x+y==x} is exactly the same as > {y==0} ,e.g. : >> Simplify[y + z/(x + y) + e^(x + y) + w*x + y, {x + y == x}] >> e^x + w*x + z/x > which presumably is not what was wanted (if it was than it is much > simpler just to substitute y -> 0}? Quite frankly, the original > request > does not make any mathematical sense at all, at least to me. For a > start, it is hard to imagine under what conditions it is reasonable to > substitute x for x+y if y is not 0! In addition, what does it mean to > say there is still one more term if we rewrite the answer? If x+2y > contains x+y because it can be rewritten as (x+y) + y than so does > x+1/2 y since that can be re-written as (x+y)-1/2y and so does any > expression. The kind of magic that seems to asked for cannot be > achieved > either by syntactic pattern matching (because of the need to interpret > contains) or by Simplify which uses wll defined mathematical rules > (and in this case the only well defined rule is y==0). > Actually on second thoughts I began to suspect that this question is > related to another one posted by Heather, concerning simplifying > expressions in which x is much larger than y. I am not at all sure > if > a sensible calculus of this kind can be developed but obviously > Simplify > will not do this. Moreover, it seems to me that under any sensible > interpretation of much larger than, if x+y is approximately x, then > so is x+2y, and so on. In other words, x is essentially Infinity in > relation to y. If so, there is no reason then why a single y should be > left int the answer and x+ (any numeric quantity) y ought to be > replaced by just x (without at the same time assuming that y is zero). > This sort of thing may perhaps be achieved with the following rule: >> x + y + z/(x + y) + e^(x + y) + e^y + w*x + y//. > x + (k:(_?NumericQ):1)*y -> x >> e^x + e^y + x + w*x + z/x ==== While Berkeley's critique of 18th century Calculus was right at the time, Abraham Robinson showed that ultimately that the intuition behind the sort of thing that Leibnitz and others did was right and could be completely formalized and turned into a very powerful tool. It certainly would be nice to implement non-standard analysis in Mathematica (perhaps someone has already done this?). Indeed one can in this way turn calculus into algebra (getting rid of the concept of Limit) and it may well be the most natural approach to calculus via symbolic algebra. (For more see Abraham Robinson, Non-standard Analysis, Princeton Landmarks in Mathematics, 1996). > Actually on second thoughts I began to suspect that this question is >> related to another one posted by Heather, concerning simplifying >> expressions in which x is much larger than y. I am not at all sure if >> a sensible calculus of this kind can be developed but obviously >> Simplify >> will not do this. It seems to me that this is essentially a (capital-C) Calculus > problem, > and unless a simple /.y->0 is what's wanted, the correct tool is > Limit[]. > Berkeley's critique of 18th century Calculus applies here: while it was > essentially antiscientific, his reasoning was flawless and should warn > us > against trying to solve this sort of problem by mindless algebra. Of course, Limit[] is a tricky and somewhat unreliable power tool, > requiring caution. This reflects the mathematical subtlety of this kind > of problem. It is generally essential to formulate the problem in such a > way that the direction of the approach to the limit is unambiguous. -- ==== That should have been Leibniz, of course. > While Berkeley's critique of 18th century Calculus was right at the > time, Abraham Robinson showed that ultimately that the intuition > behind the sort of thing that Leibnitz and others did was right and > could be completely formalized and turned into a very powerful tool. It > certainly would be nice to implement non-standard analysis in > Mathematica (perhaps someone has already done this?). Indeed one can in > this way turn calculus into algebra (getting rid of the concept of > Limit) and it may well be the most natural approach to calculus via > symbolic algebra. (For more see Abraham Robinson, Non-standard Analysis, Princeton > Landmarks in Mathematics, 1996). > Andrzej Kozlowski Toyama International University > JAPAN > http://platon.c.u-tokyo.ac.jp/andrzej/ > Actually on second thoughts I began to suspect that this question is > related to another one posted by Heather, concerning simplifying > expressions in which x is much larger than y. I am not at all sure > if > a sensible calculus of this kind can be developed but obviously > Simplify > will not do this. >> It seems to me that this is essentially a (capital-C) Calculus >> problem, >> and unless a simple /.y->0 is what's wanted, the correct tool is >> Limit[]. >> Berkeley's critique of 18th century Calculus applies here: while it was >> essentially antiscientific, his reasoning was flawless and should warn >> us >> against trying to solve this sort of problem by mindless algebra. >> Of course, Limit[] is a tricky and somewhat unreliable power tool, >> requiring caution. This reflects the mathematical subtlety of this kind >> of problem. It is generally essential to formulate the problem in >> such a >> way that the direction of the approach to the limit is unambiguous. ==== I would assume that you are looking for the following definitions (rules) to handle Much smaller relations in order to cancel negligible small Terms from an expression. s << L s/L << 1 1 << L/s from that, one can define a ruleset like these below: (a is an arbitrary Object) a+L+s -> a+L a+s -> a+s a+L/s (if Abs(a)>=1) -> L/s , otherwise -> a+L/s a+s/L (if Abs(a)>=1) -> a , otherwise -> a+s/L (L+s)/L ->> 1 1/s+1/L -> 1/s s+a*L (if Abs(a) >=1) ->> a*L , otherwise ->> s+a/L ... s^2+s^1 -> s^1 if L=1 => s<<1 L^2+L^1 -> L^2 if s=1 => L 1 side effects are s^n << s if n =1 and L=1 and so on (Power adds considerable complexity to this ruleset) your example is F()+1+x^2 with 1>>x replacing the desired Objects (1 -> L, x -> s) according the rules above, we get F()+L+s^2 -> F()+L+s^1 -> F()+L restoring the original Objects (L -> 1,s -> x) = F()+1 where x^2 is removed and all other Terms remains unaffected. You need a new function for Plus[] looking for L and s Objects and applying their respective Rules. A problem is to set all possible rule-templates in order to catch all possible terms with symbolic and positive as well as negative numbers as coefficients. This is why a Limit with s or s/L -> 0 will fail as MuchSmallerAssumption a*s+a*L -> a*L but b*s+a*L -> b*s+a*L because we haven't said anyhing about a and b, but a simple (s, s/L)->0 will remove factor b. ==== I get the same answer both ways, to as many places as you see here: 1.8430622009642987*Integrate[ (-0.9025328739879791 + X)^5* F[Subscript[p, 0], 0.2856264419666387, 0.04012528894153399, 0.2662836604257217, 0.7959934248376723, 0.15354837805257518, X], {X, -Infinity, Infinity}] -----Original Message----- formula=Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - m)/sd)^5, {X, -Infinity, Infinity}] Now set Evaluate[Table[Subscript[p, i], {i, 1, 5}]] = Table[Random[], {5}] and also sd = Random[]; m = Random[]; Now evaluate again Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - m)/sd)^5, {X, -Infinity, Infinity}] and formula You will almost certainly get different answers, while they clearly ought to be the same. It seems that it is nto the fact that the names you are suing are different that leads to different results in both of your integrals but the fact that the names of the parameters in the first case are not symbols. Officially there is no reason why they should be, but in practice using non-symbols in formulas makes them more complicated and is more likely to result in errors. The really bad news as far as your problem is concerned is that it is the 6 hour fruitless computation that appears to be the correct one ... > Here's what I have: F[a_, b_, c_, d_, e_, f_, X_] := (a + b X + c X^2 + d X^3 + e X^4 + f > X^5)* > Exp[-(((X - m)/sd)^2)/2]/(Sqrt[2Pi]sd) The strange thing, and I'd appreciate someone shedding some light on > this, > is that this: !(Integrate[ > F[p_0, p_1, p_2, p_3, p_4, p_5, > X]*((((X - m))/sd))^5, {X, (-Infinity), Infinity}, > Assumptions -> {sd > 0}]) (I cut and pasted that it looks like it works) Anyway, THAT gives me an answer really quickly... (within 5 minutes on > my box) JUST changing it from p0..5 to a,b,c,d,e,f like so: Integrate[F[a, b, c, d, e, f, X]*((X - m)/sd)^5, {X, -Infinity, > Infinity}, > Assumptions -> {sd > 0}] Causes mathematica to go into an infinite loop (seemingly after 6 > hours). This ... sucks. How am I to know if a certain equation is solvable, if > only I choose the right variables?? Binesh Bannerjee -- > For in much wisdom is much grief, and he that increaseth knowledge > increaseth sorrow. -- Ecclesiastes 1:18 SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub > SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub > OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub > ==== It seems that you have not evaluated Binesh's defintion of F. You should be getting a numerical answer, not a formula involving F, Integrate etc. Andrzej > I get the same answer both ways, to as many places as you see here: 1.8430622009642987*Integrate[ > (-0.9025328739879791 + X)^5* > F[Subscript[p, 0], > 0.2856264419666387, > 0.04012528894153399, > 0.2662836604257217, > 0.7959934248376723, > 0.15354837805257518, X], > {X, -Infinity, Infinity}] > -----Original Message----- > Sent: Monday, July 29, 2002 2:13 AM There does sem to be a bug here, but it is not quite what you think. > It's the first answer that you get that is probably wrong. On the other > hand, in the second case it is very unlikely that Mathematica enters an > infinite loop, rather it is still trying to arrive at the answer and > there is no guarantee that it will reach one after, say a week or a > month. As for first case, the reason why the answer is probably this. Evaluate > the formula: > formula=Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], > Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - > m)/sd)^5, > {X, -Infinity, Infinity}] Now set > Evaluate[Table[Subscript[p, i], {i, 1, 5}]] = Table[Random[], {5}] and also sd = Random[]; m = Random[]; Now evaluate again > Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], > Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - > m)/sd)^5, > {X, -Infinity, Infinity}] and formula You will almost certainly get different answers, while they clearly > ought to be the same. It seems that it is nto the fact that the names > you are suing are different that leads to different results in both of > your integrals but the fact that the names of the parameters in the > first case are not symbols. Officially there is no reason why they > should be, but in practice using non-symbols in formulas makes them more complicated and is more likely to result in errors. The really bad news as far as your problem is concerned is that it is > the 6 hour fruitless computation that appears to be the correct one ... > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ >> Here's what I have: >> F[a_, b_, c_, d_, e_, f_, X_] := (a + b X + c X^2 + d X^3 + e X^4 + f >> X^5)* >> Exp[-(((X - m)/sd)^2)/2]/(Sqrt[2Pi]sd) >> The strange thing, and I'd appreciate someone shedding some light on >> this, >> is that this: >> !(Integrate[ >> F[p_0, p_1, p_2, p_3, p_4, p_5, >> X]*((((X - m))/sd))^5, {X, (-Infinity), Infinity}, >> Assumptions -> {sd > 0}]) >> (I cut and pasted that it looks like it works) >> Anyway, THAT gives me an answer really quickly... (within 5 minutes on > my box) >> JUST changing it from p0..5 to a,b,c,d,e,f like so: >> Integrate[F[a, b, c, d, e, f, X]*((X - m)/sd)^5, {X, -Infinity, >> Infinity}, >> Assumptions -> {sd > 0}] >> Causes mathematica to go into an infinite loop (seemingly after 6 >> hours). >> This ... sucks. How am I to know if a certain equation is solvable, if >> only I choose the right variables?? >> Binesh Bannerjee >> -- >> For in much wisdom is much grief, and he that increaseth knowledge >> increaseth sorrow. -- Ecclesiastes 1:18 >> SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub >> SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub >> OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub ==== AES, I am just going to answer your first question. Yes, it is possible to write packages with cell grouping and headers and with text cell exposition. In my opinion, that it the way it should be done. Many package writers, even many who are extremely good at Mathematica, take an arcane approach to writing packages. Many even recommend writing packages in a text editor outside of Mathematica! (There is also the question of where to put packages. Many writers will put them anywhere except the ExtraPackages folder, which is where they should be if you want them to behave like standard packages.) I think all of this confusion arises because the fundamentals of package writing are poorly documented. To write a package just start with a standard Default Mathematica notebook. Write your BeginPackage statement, usage statements, function definitions, etc., in the normal way. As much as possible, put each statement in a separate cell. Make all the Input cells Initialization cells. When you save the notebook choose the option Create AutoSave Package. The .m package file will automatically be created, and it will be automatically updated everytime you change and save the .nb file. YOU SHOULD NEVER HAVE TO DIRECTLY EDIT OR EVEN LOOK AT A .m FILE. (The only reason to look at a .m file is to look at somebody else's code, if they haven't provided you with the .nb file. If you want other people to have direct access to your package code, give them the .nb file.) You can do all your work in the .nb file. Then you can use all the normal FrontEnd facilities. This means that you can use cell grouping with group headers and text cells. These are automatically excluded when the .m file is created. I often use an Annotation Section and an Implementation Section. I use SubSections for the Usage Statements and Package Code. I use SubSubSections for each routine and sometimes for each usage statement. So it is possible to group and organize the package code in just the way you desire. I will send you a sample package notebook if you wish. ==== >I'd like to change the default settings of the File>Printing Settingsthe header in all future notebooks. I know how to do this in individual notebooks, so I opened Default.nb, >made this change, and Quit and re-Opened Mathematica. The change seems to >stick >in Default.nb, but still doesn't seem to show up in new notebooks. ??? http://support.wolfram.com/mathematica/interface/print/globalheadandfoot.htm l -Dale ==== I'm trying to create some ButtonFunctions that modify cell margins. I >have something that works very well, so long as the CellMargins option >appears explicity in every cell---as, e.g., in Cell[abc,Text, CellMargins->{{10,0},{0,6}}]. But with something like Cell[abc,Text] or Cell[abc,Text, >CellMargins->{{Inherited,Inherited},{0,Inherited}}], >I'm stuck. The only thing I can think of is to provide the default >values from the style sheet ``manually. Is it possible to determine the value of an inherited cell option? If >one could somehow force inherited cell options to appear explicitly, >that would provide a solution. Any ideas? Selwyn Hollis slhollis@mac.com >http://www.armstrong.edu/faculty/hollis You want AbsoluteOptions. For example, in one notebook do the following In[1]:= nbk=EvaluationNotebook[]; And create a text cell which you then select. In another notebook, do In[2]:= Options[NotebookSelection[nbk], CellMargins] Out[2]= {CellMargins->{{Inherited,Inherited},{Inherited,Inherited}}} In[2]:= AbsoluteOptions[NotebookSelection[nbk], CellMargins] Out[3]= {CellMargins->{{12.,10.},{7.,7.}}} -- http://www.wz.com/internet/Mathematica.html ==== I am writing my thesis using ArticleModern style sheet in Mathematica 4.1. >I have problems as below : 1) I wish to make it show the page break just like the MS Excel and MS Word > do. I tried by selecting the Show Page Breaks from the menu, but nothing > was seen on the screen. What should i do? Assuming that you have more than one page, you should see a dashed line between cells at the location of the page breaks. >2) I type my text in the cell in text form. When i click Full Right Justify > Selection button, all the words at the end of each line will break into >two parts and go to next line. >It looks like this, example : Programming becomes Programm- (initial line) > ing (following line). >Anybody knows how to make the words not breaking aparts showed as above? Turn off hyphenation. 1) Select the cell 2) Choose the menu item Format>Option Inspector 3) In the Lookup field put hyphenation. The hit enter. 4) At the Hyphenation->True option uncheck the checkbox. If it is a common problem, you should set the hyphenation in the style sheet. >Any helps and suggestions would be highly appreciated. Shz Shz ======= of the individual or entity to which they are addressed. Any disclosure, >copying, >distribution and diversion contrary to the applicable export control laws and >regulations including US Export Administration Regulations is strictly >prohibited. and do not disclose it to others. Please notify the >postmaster@hitachi.com.my >of the delivery error by replying to this message and then delete it from your ======= > -- http://www.wz.com/internet/Mathematica.html ==== >Dear MathGroup Members, >Tracing functions from Packages generates very long >and confusing output, since long context names are >printed. To give a short example, consider the following >command sequence: DiscreteMath`Tree` t=MakeTree[Range[5]] Trace[TreeFind[t,3]] generates very long output. A simple strategy to strip >it would be to use Trace[command, form] which only reports >expressions matching form. >But this does not alleviate the problem that package >variable names are very long, since all package symbols >have a long context. For example >the private package variables 'm' and 'found' are printed as DiscreteMath`Tree`Private`m and >DiscreteMath`Tree`Private`found This makes Trace output almost unreadable. Can anyone suggest a simple idea how to remove the long >context names in Trace output? I defined a function which cuts the context from >symbols, but this seems awkward an application of >the function to the output is not trivial. Johannes Ludsteck Which symbols are available via short names is controlled by $ContextPath. If you reset $ContextPath to include DiscreteMath`Tree`Private` then the variables in that context will be returned by short name. The problem with doing that is that you've make those private symbols and functions accessible. To minimize that problem, use a Block. Block[{$ContextPath = Append[$ContextPath, DiscreteMath`Tree`Private`]}, Print@Trace[TreeFind[t, 3]] ] Inside the Block short names are used. Outside the Block full names are used. -- Omega Consulting The final answer to your Mathematica needs Spend less time searching and more time finding. http://www.wz.com/internet/Mathematica.html ==== There is some real weirdness with Random[Integer, j] for some large values of j but not others (for both 4.1 and 4.2 versions). <> The other failure only is apparent in very large big >> integers, and I do not know exactly how to categorize it. I just find this very troubling. --Mark. ==== I am using StoppingTest in NDSolve, as a consequence the terminal value of the independent variable is unknown prior to NDSolve finishing. How does one extract this number from the Interpolation object? ==== Treat has shown convincingly that the formula returned by Mathematica is correct. Moreover, repeating my numerical test I now get the same answer (up to infinitesimals) in both cases which suggests that I was nto careful enough when first performing this test. This seems to have a very weird implications. It appears that we are dealing with a bug of a most unusual kind, whose effects are somehow removed by using subscripts. Although it would appear very unlikely unlikely it does look look as if subscripts were used in at least some of the code of Integrade and it somehow became subscript dependent. It certainly seems to merit an inversitgation by WRI. Andrzej Kozlowski > There does sem to be a bug here, but it is not quite what you think. > It's the first answer that you get that is probably wrong. On the other > hand, in the second case it is very unlikely that Mathematica enters an > infinite loop, rather it is still trying to arrive at the answer and > there is no guarantee that it will reach one after, say a week or a > month. As for first case, the reason why the answer is probably this. Evaluate > the formula: > formula=Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], > Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - > m)/sd)^5, > {X, -Infinity, Infinity}] Now set > Evaluate[Table[Subscript[p, i], {i, 1, 5}]] = Table[Random[], {5}] and also sd = Random[]; m = Random[]; Now evaluate again > Integrate[F[Subscript[p, 0], Subscript[p, 1], Subscript[p, 2], > Subscript[p, 3], Subscript[p, 4], Subscript[p, 5], X]*((X - > m)/sd)^5, > {X, -Infinity, Infinity}] and formula You will almost certainly get different answers, while they clearly > ought to be the same. It seems that it is nto the fact that the names > you are suing are different that leads to different results in both of > your integrals but the fact that the names of the parameters in the > first case are not symbols. Officially there is no reason why they > should be, but in practice using non-symbols in formulas makes them more > complicated and is more likely to result in errors. The really bad news as far as your problem is concerned is that it is > the 6 hour fruitless computation that appears to be the correct one ... > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ >> Here's what I have: >> F[a_, b_, c_, d_, e_, f_, X_] := (a + b X + c X^2 + d X^3 + e X^4 + f >> X^5)* >> Exp[-(((X - m)/sd)^2)/2]/(Sqrt[2Pi]sd) >> The strange thing, and I'd appreciate someone shedding some light on >> this, >> is that this: >> !(Integrate[ >> F[p_0, p_1, p_2, p_3, p_4, p_5, >> X]*((((X - m))/sd))^5, {X, (-Infinity), Infinity}, >> Assumptions -> {sd > 0}]) >> (I cut and pasted that it looks like it works) >> Anyway, THAT gives me an answer really quickly... (within 5 minutes on >> my box) >> JUST changing it from p0..5 to a,b,c,d,e,f like so: >> Integrate[F[a, b, c, d, e, f, X]*((X - m)/sd)^5, {X, -Infinity, >> Infinity}, >> Assumptions -> {sd > 0}] >> Causes mathematica to go into an infinite loop (seemingly after 6 >> hours). >> This ... sucks. How am I to know if a certain equation is solvable, if >> only I choose the right variables?? >> Binesh Bannerjee >> -- >> For in much wisdom is much grief, and he that increaseth knowledge >> increaseth sorrow. -- Ecclesiastes 1:18 >> SSH2 Key: http://www.hex21.com/~binesh/binesh-ssh2.pub >> SSH1 Key: http://www.hex21.com/~binesh/binesh-ssh1.pub >> OpenSSH Key: http://www.hex21.com/~binesh/binesh-openssh.pub > ==== My overall objective is to create and store on HD a sizable number of medium-length animations -- maybe 50 or more such animations, with maybe 100 frames each, each frame consisting of a not too complex GraphicArray. These are intended for later playback or projection as a full screen (or near full screen) slide show on a Mac (OS 9.1, Mathematica 4.1), with forward and backward single-stepping under arrow key control and ability to restart from the first frame being important. I'm lookng for advice on the best strategy for doing this. 1) I can generate each of the individual animations by hand -- run a notebook containing a module that's iterated 100 times to generate the 100 frames, select the 100 graphics cells by hand, use the Save Selection as QuickTime menu option to save to a QT movie, play this move back later as a QT movie. This is tedious, however, and I'm not that fond of the QT Movie Player (can't get rid of the surrounding frame for example, at least AFAIK). 2) I can just save the notebook after evaluation -- presumably with Editable->False for all Cells -- then use ^A and ^Y to animate the graphics, and the up/down arrow keys to step forward and back through them. A not so minor annoyance, however, is that the animation starts off running and you have to use the up/down arrow keys to stop it, then step frame by frame back to the first frame. In addition, AnimationDirection seems not to work as advertised, and as a result restarting the animation from the beginning if you're up somewhere around the 90th frame is a problem. Inputting ?AnimationDirection yields Forward. Stepping forward using the arrow keys or the > button on the control strip at the bottom takes you to the end of the animation, but then stops and does not loop around to the first frame (and the >> and << buttons on the control strip are grayed out). If you move backward too rapidly by holding down the back arrow or < button, however, you can overshoot the first frame and jump again to the end. Any better ideas for all this? ==== > time, Abraham Robinson showed that ultimately that the intuition > behind the sort of thing that Leibnitz and others did was right and > could be completely formalized and turned into a very powerful tool. It > certainly would be nice to implement non-standard analysis in > Mathematica (perhaps someone has already done this?). Yes, that would be a nice way. However, I'm not aware of such a package, and Mathematica is so firmly rooted in standard complex analysis that I mean Robinson's approach. When I see a package with NonStandardExpand[], and SameMonadQ[], I'll want to give it a spin... ==== Re a longer post I submitted recently: Execute the following as the only (or final) contents of a notebook Do[Plot[x^k, {x,0,1}, PlotRange->{{0,1}, {0,1}}], {k,1,4}] Then Select All cells (cmd-A); Animate (cmd-Y); and hit the up or down arrow keys a few times or click the vertical bars in the control strip to pause the animation. Single-stepping the animation backward using the up/down? arrow key will now take you down to the k=1 plot, then loop back up to the k=4 plot. Single-stepping the animation forward using the down/up? arrow key will take you up to the k=4 plot, but will NOT loop back down to the k=1 plot (although the free-running animation does seem to loop around OK). Adding another cell (even a header or text cell) at the end of the notebook, however, so that there is another cell after the k=4 plot, will enable cyclic single-step looping in either direction around the loop. [Mac PB G3, OS 9.1, Mathematica 4.1]