A117 === Subject: Re: RenderBadPicture error while running Mathematica 6 on Linux Try mathematica -defaultvisual instead. Ugly fonts though. === Subject: Re: Testing TOC sidebar palette Hello Yuri, Yes, the links are working fine now. I have downloaded both packages. Tom Dowling > Could you check the links again? > Do they work now? > 2008/5/14, Thomas Dowling : > Me too. Same error message. > Tom Dowling > murray@math.umass.edu > > Did you forget to make those files public? I'm getting a 404 Not > Found > > error when I try the URLs. > > Hi group, > > > > Sometimes ago there was question about creating TOC of the notebook. > > David Reiss gave a hint of using CellID for these purposes. Based on > > this idea I have developed a sidebar TOC palette where I also > include > > several tasks typical for my work. Could you please inform me if it > is > > convenient to use it and what kind of extra tasks should be added to > > the palette? > > > > Main properties of palette include: > > - Generation of Table of Contents for any currently selected > notebook > > - Additional selection instrument for extra tasks. Current version > > supports locking/unlocking cells to block cells from accidental > > editing and deleting > > - Tracing graphics coordinates. (It also launches an additional tool > > GraphicsCoordinates. Note, the Graphics object must be selected to > > activate this button) > > - Tracing evaluation time > > - Running everyday notebooks in save mode (with cell options > > Delatable and Editable set to False) > > - Few additional actions: comparing two cells in the notebook, > > evaluating the whole section etc. > > > > The files can be downloaded from: > > http://www.spinalgebra.com/sidebar/graphicscoordinates.zip > > http://www.spinalgebra.com/sidebar/sidebar.zip > > > > > -- > > Murray Eisenberg murray@math.umass.edu > > Mathematics & Statistics Dept. > > Lederle Graduate Research Tower phone 413 549-1020 (H) > > University of Massachusetts 413 545-2859 (W) > > 710 North Pleasant Street fax 413 545-1801 > > Amherst, MA 01003-9305 > > -- > Yuri Kandrashkin, PhD > http://spinalgebra.com - Mathematica based applications: > - Magnetic Resonance with SpinAlgebra > - Work with systems of Units > - Interactive tools: ViewPoint selector, Options explorer, etc > === Subject: Re: DSolve question >Below is the code that works. Clearly Mathematica recognizes output >in curly braces { } differently than that without. Did it seem surprising to you Mathematica sees things in curly braces differently that without them? If so, it shouldn't. Mathematica uses curly braces to denote a List. If no curly braces are present, then whatever expression you have is not a List. Since lists are different than say symbols, numbers, general expressions and other objects, Mathematica treats them differently as should be expected. If it truly was surprising to you output in curly braces was different than without curly braces you should review the material that can be found by selecting Help->Documentation Center then clicking on the second item (Lists) under Core Language paying particular attention to the information in the tutorials listed at the bottom of the page that comes up after clicking. Lists are a very fundamental construct in Mathematica. You will undoubtedly have difficulties getting Mathematica to perform as you want without having a fairly good grasp of lists. === Subject: Re: Expression manipulation Just for the record. Mathematica is much powerful than it appears to be. (Anyway, I hope J. Harrison is working to make notation manipulation easier.) http://www.gregosetroianos.mat.br/playEquation/index.html I used it to teach algebraic manipulation, first and second order equations and more. It worked extremely well for teaching. Extremely well. Believe-me: extremely well!! (1) You start with the equation 3x-7==14 on input cell in your notebook. (2) To solve the equation, you can add 7 to both members, or subtract -7 from both members. Suppose you wants the later. Then you just select -7 and press the button *-* buttom on the control palette. (3) This is what happens in sucession: * the pressed button is highlighted; * a nice short beep is emited; * the user selection (-7) goes to an input field and stays selected; * the notebooks sizes (control palette and user notebook) are automatically adjusted to fit on the vertical according to the height of the selection (-7); * a cell Subtracting -7 is pasted below your input cell; * and for a brief moment (1.5 seconds) the program shows another cell with a freezed intermediate step before evaluation):(3x-7)-(-7)==14-(-7) * the freezed cell is then evaluated to 3x==21. Finally you must divide by 3. So you select 3 and press the divide button. As before, the program beeps, the pressed button is marked, the user selection (3) goes to the input field, etc., and for a brief moment (1.5 seconds) the program shows 3x/3==21/3 (in TraditionalForm) and then this: x==7. Instead of selecting, you could also just type 1/3 in the input field and press the times button. In order to solve a second degree equation/inequality, the user: selects the variable to solve for, unless there is only one, in which case the program automatically identifies the variable. (In any case, the variable goes to the input field.) However, this is not a mere Solve-like command. Instead, as in a normal class, the user will have to put his equation (by using the other buttons) in one of the following traditional forms: x^2==k a x^2+b x+c==0. Only then the solve button will print the result carefully formatted as the user would see it in a traditional book. You could also solve equations with radicals, inequalities, do some algebraic replacements of variables, customize your interface, create you own operations, etc. Unfortunately, I stopped there. The package was not updated to Mathematica 5.2 or 6. Cordialmente, Carlos C.8esar de Ara.9cjo Gregos & Troianos Educacional http://www.gregosetroianos.mat.br Belo Horizonte, MG, Brasil (31) 3283-1122 === Subject: Re: Problem with cell brackets and Manipulate At least on linux 32-bit, 6.0.1.0, this problem does not occur. Perhaps it's OS-dependent? Curtis > Here is some code: > conGrade[bias_, sd_, sm_, tea_, maxBias_] := > Module[{grade}, > grade = 103. - 33.*(Sqrt[(bias/maxBias)^2 + (sm*sd)^2]/tea); > If[grade > 100., grade = 100.]; If[grade < 0., grade = 0.]; > grade]; Manipulate[ > conGrade[bias, sd, sigMult, TEa, maxBias], {{bias, 0}, -10, 10, > Appearance -> Labeled}, {{sd, 1.0}, 0, 10, > Appearance -> Labeled}, {{sigMult, 2.5}, 1.65, 3.0, > Appearance -> Labeled}, {{TEa, 8.0}, 5, 10, > Appearance -> Labeled}, {{maxBias, 0.85}, 0.75, 1.0, > Appearance -> Labeled}] > The code works fine. However, when I select the bracket to the right > of the manipulate to collapse the code, most of the sliders move to > the end of their range. As long as the bracket is highlighted, the > sliders will move to the pegged positions. As soon as the highlight is removed -- collapsing the code part does > not matter -- the sliders work properly. Using Mathematica 6.0.2.1, OS X 10.5 2 Any help would be appreciated. george woodrow -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Asking NonlinearRegression I should have added to my previous post that the following is an example of a function that gives a reasonable fit, but perhaps it is not acceptable? fun2 = base + max/(1 + E^((xo - x)/r)); A fit may be obtained as follows: In[479]= rules2 = FindFit[Partition[d1, 2], fun2 , {{base, .2}, {max, 1}, {xo, 50}, {r, 8}}, x] Out[479]= {base -> -0.00839687, max -> 1.14459, xo -> 81.5014, r -> 10.5337} Plotting .... In[489]= plot2 = Plot[fun2 /. rules2, {x, 0, 105}]; In[487]= listplot = ListPlot[Partition[d1, 2], PlotRange -> {-.05, 1.1}, PlotStyle -> {Green, PointSize[Large]}]; In[490]= Show[plot2, listplot] Tom Dowling Are you sure about this? Proceeding as you outlined ... In[375]:= d1 = {1, 0.00, 2, 0.00, 3, 0.00, 4, 0.00, 5, 0.00, 6, 0.00, 7, > 0.00, > 8, 0.00, 9, 0.00, 10, 0.00, 11, 0.00, 12, 0.00, 13, 0.00, 14, 0.00, > 15, 0.00, 16, 0.00, 17, 0.00, 18, 0.00, 19, 0.00, 20, 0.00, 21, > 0.00, 22, 0.00, 23, 0.00, 24, 0.00, 25, 0.00, 26, 0.00, 27, 0.00, > 28, 0.00, 29, 0.00, 30, 0.00, 31, 0.00, 32, 0.00, 33, 0.00, 34, > 0.00, 35, 0.00, 36, 0.00, 37, 0.00, 38, 0.00, 39, 0.00, 40, 0.00, > 42, 0.00, 44, 0.00, 46, 0.00, 48, 0.00, 50, 0.00, 52, 0.04, 54, > 0.06, 56, 0.08, 58, 0.09, 60, 0.16, 65, 0.24, 70, 0.32, 75, 0.43, > 80, 0.49, 85, 0.58, 90, 0.80, 95, 0.91, 100, 1.00, 105, 1}; In[376]:= fun = Exp[(1 - Exp[a*(1 - Exp[-b*x])])*(Exp[-b*x])/(1 - > Exp[-b*x])]; In[412]:= paramrules = FindFit[d1, fun, {a, b}, x] Out[412]= {a -> 0.648266, b -> 1.02124} If I now plot the (partitioned) data and the fitted function, as follows: In[419]= plot = Plot[fun /. paramrules, {x, 0, 105}, AxesOrigin -> {0, > 0}]; > listplot = ListPlot[Partition[d1, 2], PlotRange -> {-.05, 1.1 > }, PlotStyle -> {Green, PointSize[Large]}]; > Show[plot, listplot] This does not seem to be a reasonable fit to me. Furthermore, the following gives an overflow error message. Are you sure > you > are trying to fit to an appropriate function? > In[422]= FindFit[Partition[d1, 2], fun, {a, b}, x] > IGeneral::ovfl: Overflow occurred in computation. General::ovfl: Overflow occurred in computation. General::ovfl: Overflow occurred in computation. General::stop: Further output of General::ovfl will be suppressed > during this calculation. FindFit::nrlnum: The function value <<1>> is not a list of real > numbers with dimensions {59} at {a,b} = {-1.80801,-5.23877}. Out[422]= {a -> -1.80801, b -> -5.23877} I have not been able to obtain a reasonable fit to your data even using > 'manual' values for 'a' and 'b' in 'fun'. Maybe fit to > a different function? Tom Dowling >> Hi Navri, >> NonlinearRegression as well as FindFit (should be used instead of the >> older NonlinearFit) seem to work as expected: >> fun=Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])]; >> d1={1,0.00,2,0.00,3,0.00,4,0.00,5,0.00,6,0.00,7,0.00,8,0.00,9,0.00,10,0.00,11 ,0.00,12,0.00,13,0.00,14,0.00,15,0.00,16,0.00,17,0.00,18,0.00,19,0.00,20,0.00 ,21,0.00,22,0.00,23,0.00,24,0.00,25,0.00,26,0.00,27,0.00,28,0.00,29,0.00,30,0 .00,31,0.00,32,0.00,33,0.00,34,0.00,35,0.00,36,0.00,37,0.00,38,0.00,39,0.00,4 0,0.00,42,0.00,44,0.00,46,0.00,48,0.00,50,0.00,52,0.04,54,0.06,56,0.08,58,0.0 9,60,0.16,65,0.24,70,0.32,75,0.43,80,0.49,85,0.58,90,0.80,95,0.91,100,1.00,10 5,1}; >> FindFit[d1,fun,{a,b},x] >> NonlinearRegress[d1, fun, {a, b}, x] >> Could it bee that you had a syntax error? >> hope this helps, Daniel >> I have a problem with nonlinear regression in Mathematica. I want to fit >> my data (below) to this following equation: >> y = Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])] >> and I would like to find a and b values and also determined r-squared >> value. >> I try to use NonlinearRegression/NonlinearFit code, but its not working, >> I hope someone could help me >> DATA: >> x y >> 1 0.00 >> 2 0.00 >> 3 0.00 >> 4 0.00 >> 5 0.00 >> 6 0.00 >> 7 0.00 >> 8 0.00 >> 9 0.00 >> 10 0.00 >> 11 0.00 >> 12 0.00 >> 13 0.00 >> 14 0.00 >> 15 0.00 >> 16 0.00 >> 17 0.00 >> 18 0.00 >> 19 0.00 >> 20 0.00 >> 21 0.00 >> 22 0.00 >> 23 0.00 >> 24 0.00 >> 25 0.00 >> 26 0.00 >> 27 0.00 >> 28 0.00 >> 29 0.00 >> 30 0.00 >> 31 0.00 >> 32 0.00 >> 33 0.00 >> 34 0.00 >> 35 0.00 >> 36 0.00 >> 37 0.00 >> 38 0.00 >> 39 0.00 >> 40 0.00 >> 42 0.00 >> 44 0.00 >> 46 0.00 >> 48 0.00 >> 50 0.00 >> 52 0.04 >> 54 0.06 >> 56 0.08 >> 58 0.09 >> 60 0.16 >> 65 0.24 >> 70 0.32 >> 75 0.43 >> 80 0.49 >> 85 0.58 >> 90 0.80 >> 95 0.91 >> 100 1.00 >> 105 1 >> Rgds, >> Navri >> === Subject: Re: Asking NonlinearRegression Are you sure about this? Proceeding as you outlined ... In[375]:= d1 = {1, 0.00, 2, 0.00, 3, 0.00, 4, 0.00, 5, 0.00, 6, 0.00, 7, 0.00, 8, 0.00, 9, 0.00, 10, 0.00, 11, 0.00, 12, 0.00, 13, 0.00, 14, 0.00, 15, 0.00, 16, 0.00, 17, 0.00, 18, 0.00, 19, 0.00, 20, 0.00, 21, 0.00, 22, 0.00, 23, 0.00, 24, 0.00, 25, 0.00, 26, 0.00, 27, 0.00, 28, 0.00, 29, 0.00, 30, 0.00, 31, 0.00, 32, 0.00, 33, 0.00, 34, 0.00, 35, 0.00, 36, 0.00, 37, 0.00, 38, 0.00, 39, 0.00, 40, 0.00, 42, 0.00, 44, 0.00, 46, 0.00, 48, 0.00, 50, 0.00, 52, 0.04, 54, 0.06, 56, 0.08, 58, 0.09, 60, 0.16, 65, 0.24, 70, 0.32, 75, 0.43, 80, 0.49, 85, 0.58, 90, 0.80, 95, 0.91, 100, 1.00, 105, 1}; In[376]:= fun = Exp[(1 - Exp[a*(1 - Exp[-b*x])])*(Exp[-b*x])/(1 - Exp[-b*x])]; In[412]:= paramrules = FindFit[d1, fun, {a, b}, x] Out[412]= {a -> 0.648266, b -> 1.02124} If I now plot the (partitioned) data and the fitted function, as follows: In[419]= plot = Plot[fun /. paramrules, {x, 0, 105}, AxesOrigin -> {0, 0}]; listplot = ListPlot[Partition[d1, 2], PlotRange -> {-.05, 1.1 }, PlotStyle -> {Green, PointSize[Large]}]; Show[plot, listplot] This does not seem to be a reasonable fit to me. Furthermore, the following gives an overflow error message. Are you sure you are trying to fit to an appropriate function? In[422]= FindFit[Partition[d1, 2], fun, {a, b}, x] IGeneral::ovfl: Overflow occurred in computation. >> General::ovfl: Overflow occurred in computation. >> General::ovfl: Overflow occurred in computation. >> General::stop: Further output of General::ovfl will be suppressed during this calculation. >> FindFit::nrlnum: The function value <<1>> is not a list of real numbers with dimensions {59} at {a,b} = {-1.80801,-5.23877}. Out[422]= {a -> -1.80801, b -> -5.23877} I have not been able to obtain a reasonable fit to your data even using 'manual' values for 'a' and 'b' in 'fun'. Maybe fit to a different function? Tom Dowling > Hi Navri, NonlinearRegression as well as FindFit (should be used instead of the older NonlinearFit) seem to work as expected: fun=Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])]; > d1={1,0.00,2,0.00,3,0.00,4,0.00,5,0.00,6,0.00,7,0.00,8,0.00,9,0.00,10,0.00,11 ,0.00,12,0.00,13,0.00,14,0.00,15,0.00,16,0.00,17,0.00,18,0.00,19,0.00,20,0.00 ,21,0.00,22,0.00,23,0.00,24,0.00,25,0.00,26,0.00,27,0.00,28,0.00,29,0.00,30,0 .00,31,0.00,32,0.00,33,0.00,34,0.00,35,0.00,36,0.00,37,0.00,38,0.00,39,0.00,4 0,0.00,42,0.00,44,0.00,46,0.00,48,0.00,50,0.00,52,0.04,54,0.06,56,0.08,58,0.0 9,60,0.16,65,0.24,70,0.32,75,0.43,80,0.49,85,0.58,90,0.80,95,0.91,100,1.00,10 5,1}; FindFit[d1,fun,{a,b},x] NonlinearRegress[d1, fun, {a, b}, x] Could it bee that you had a syntax error? hope this helps, Daniel > I have a problem with nonlinear regression in Mathematica. I want to fit > my data (below) to this following equation: > y = Exp[(1-Exp[a*(1-Exp[-b*x])])*(Exp[-b*x])/(1-Exp[-b*x])] > and I would like to find a and b values and also determined r-squared > value. > I try to use NonlinearRegression/NonlinearFit code, but its not working, > I hope someone could help me > DATA: > x y > 1 0.00 > 2 0.00 > 3 0.00 > 4 0.00 > 5 0.00 > 6 0.00 > 7 0.00 > 8 0.00 > 9 0.00 > 10 0.00 > 11 0.00 > 12 0.00 > 13 0.00 > 14 0.00 > 15 0.00 > 16 0.00 > 17 0.00 > 18 0.00 > 19 0.00 > 20 0.00 > 21 0.00 > 22 0.00 > 23 0.00 > 24 0.00 > 25 0.00 > 26 0.00 > 27 0.00 > 28 0.00 > 29 0.00 > 30 0.00 > 31 0.00 > 32 0.00 > 33 0.00 > 34 0.00 > 35 0.00 > 36 0.00 > 37 0.00 > 38 0.00 > 39 0.00 > 40 0.00 > 42 0.00 > 44 0.00 > 46 0.00 > 48 0.00 > 50 0.00 > 52 0.04 > 54 0.06 > 56 0.08 > 58 0.09 > 60 0.16 > 65 0.24 > 70 0.32 > 75 0.43 > 80 0.49 > 85 0.58 > 90 0.80 > 95 0.91 > 100 1.00 > 105 1 > > Rgds, > Navri > > > > > === Subject: overloading times operator I do a simple calculation like Expand[(e_{1} + e_{3})(e_{1} - e_{3})] and get the wrong answer. (On the first try.) If I then re-execute the code that defines the multiplication, I repeat the calculation and get correct output. Alternatively, if I execute e=Symbol[e] before loading the procedure, I get correct output on the first try. More troubling is that after getting correct output, if I perform calculations of a different kind (e.g. matrix multiplication), when I repeat my original calculation, I start getting incorrect output again. (Until I re-execute the code that defines the multiplication.) It's frustrating to repeat a calculation and get different sets of output depending on what other calculations are done in between. Does anyone have suggestions? === Subject: Re: overloading times operator it's frustrating to repeat, that we can only answer a question when we get the full code and *not* a mixture of Mathematica and TeX and not a description like because the problem is probably in that procedure to define the non-commutative product and we can't help you if you don't write how this procedure to define the non-commutative product is defined. Jens > > I do a simple calculation like > > Expand[(e_{1} + e_{3})(e_{1} - e_{3})] > > and get the wrong answer. (On the first try.) > > If I then re-execute the code that defines the multiplication, I repeat the calculation and get correct output. > > Alternatively, if I execute > > e=Symbol[e] > > before loading the procedure, I get correct output on the first try. > > More troubling is that after getting correct output, if I perform calculations of a different kind (e.g. matrix multiplication), when I repeat my original calculation, I start getting incorrect output again. (Until I re-execute the code that defines the multiplication.) > > It's frustrating to repeat a calculation and get different sets of output depending on what other calculations are done in between. > > Does anyone have suggestions? > === Subject: Re: overloading times operator I really recommend to use NonCommutativeMultiply[] for a non- commutative product and give it the desired properties (or any other operator without built-in properties). Overloading Times[] is potentially breaking Mathematica internals, which is probably the reason for your strange results. But I cannot further comment on your problem until you give a precise definition of your non-commutative product. (In any case, if you use NonCommutativeMultiply for your produvt, you also must define NonCommutativeExpand separately.) Michael Weyrauch > > I do a simple calculation like > > Expand[(e_{1} + e_{3})(e_{1} - e_{3})] > > and get the wrong answer. (On the first try.) > > If I then re-execute the code that defines the multiplication, I repeat the calculation and get correct output. > > Alternatively, if I execute > > e=Symbol[e] > > before loading the procedure, I get correct output on the first try. > > More troubling is that after getting correct output, if I perform calculations of a different kind (e.g. matrix multiplication), when I repeat my original calculation, I start getting incorrect output again. (Until I re-execute the code that defines the multiplication.) > > It's frustrating to repeat a calculation and get different sets of output depending on what other calculations are done in between. > > Does anyone have suggestions? > === Subject: Re: overloading times operator > of the form e_X e_Y, where X and Y are multi-indices. I do this using Times. The usual way to do this is to with NonCummutativeMulitply, which can also be entered as a**b. There are a number of examples of it's use in the documentation for NonCummutativeMultiply. Mark === Subject: Re: overloading times operator > > I do a simple calculation like > > Expand[(e_{1} + e_{3})(e_{1} - e_{3})] > > and get the wrong answer. (On the first try.) > > If I then re-execute the code that defines the multiplication, I repeat the calculation and get correct output. > > Alternatively, if I execute > > e=Symbol[e] > > before loading the procedure, I get correct output on the first try. > > More troubling is that after getting correct output, if I perform calculations of a different kind (e.g. matrix multiplication), when I repeat my original calculation, I start getting incorrect output again. (Until I re-execute the code that defines the multiplication.) > > It's frustrating to repeat a calculation and get different sets of output depending on what other calculations are done in between. > > Does anyone have suggestions? > You don't actually give your procedure, but the first step is not to try to do non commutative algebra using Times. Even though you can, in principle, use ClearAttributes[Times,Orderless] (to make Times non commutative), re-defining the basic arithmetic operators in this way will not produce consistent results, and can break a lot of other code. You should represent your non commutative multiplication using ** or [CircleTimes] (the latter is much more elegant to view) and define operations involving these operators as you see fit. For example: SetAttributes[CircleTimes, Flat] CircleTimes[a_, b_] := -CircleTimes[b, a] /; (! OrderedQ[{a, b}]) This will use anticommutation to reduce expressions such as b[CirceTimes]a to a standard order (alphabetical order, as written, but you can obviously devise other orderings to suit your needs. Note that you have to be a bit careful how you formulate the test in the above to avoid an infinite series of replacements. Although defining expressions involving CircleTimes explicitly in this way is the most direct way to do noncommutative algebra, I think it is better to leave expressions such as a[CircleTimes]b inert and define functions that operate on such expressions to produce various transformations. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: overloading times operator You didn't show us the procedure. In any case, it is probably risky to overload Times for this purpose. Why not use NonCommutativeMultiply or CircleTimes? -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >of the form e_X e_Y, where X and Y are multi-indices. I do this using >Times. I do a simple calculation like Expand[(e_{1} + e_{3})(e_{1} - e_{3})] and get the wrong answer. (On the first try.) If I then re-execute the code that defines the multiplication, I repeat > the calculation and get correct output. Alternatively, if I execute e=Symbol[e] before loading the procedure, I get correct output on the first try. More troubling is that after getting correct output, if I perform > calculations of a different kind (e.g. matrix multiplication), when I > repeat my original calculation, I start getting incorrect output again. > (Until I re-execute the code that defines the multiplication.) It's frustrating to repeat a calculation and get different sets of output > depending on what other calculations are done in between. Does anyone have suggestions? > === Subject: Re: Traditional Ordering of Equations > - Is there a way to prevent Mathematica from reordering a function to its standard order upon evaluation? There is just at this time another active thread about that topic and the complications of it, check todays posts or the archive... > - I want to list all resulting functions in one cell, as can be done using the Print and Fortranform commands. I want the list to look like this: > > > FunctionName1 = Function1 > FunctionName2 = Function2 > FunctionName3 = Function3 > etc. > > All these functions were defined earlier in the notebook using the following syntax: > > FunctionName1 = Function1 > > I tried writing a new Mathematica function to do this: > > FortranFormulas[ff_] := > Print[HoldForm[ff] = FortranForm[ff]] > FunctionNameList = {NO3inYt, NO3outYt} > Scan[FortranFormulas, FunctionNameList] > > However, this generates an output like: > = Function1inFortranForm Function1 > = Function2inFortranForm Function2 > > The alternative: > FortranFormulas[ff_] := > Print[ff] = FortranForm[Release[ff]]] > FunctionNameList = {HoldForm[NO3inYt], HoldForm[NO3outYt]} > Scan[FortranFormulas, FunctionNameList] > > generates an output like: > = FunctionName1 FunctionName1 > = FunctionName2 FunctionName2 > > Both are incorrect and in the wrong order. As others have mentioned in other threads, it is always a good idea to present a minimal but complete example of code that shows your problem, otherwise people who spend the valuable time to help you have to even think about examples themselfs. In this case you are lucky, because an example was easy to make up :-) This is how I would do it: Expr1Name=a^2+b^3; Expr2Name=5a-b^3+c; fortrancode=StringJoin[ToString/@Flatten[Map[ {#,=,FortranForm[#[[1]]],n}&, {HoldForm[Expr1Name],HoldForm[Expr2Name]} ]] ] You can copy and paste from the output cell or use something like (be careful to not overwrite an existing file when executing this!): Export[ ToFileName[{$HomeDirectory, Desktop}, formulas.f], fortrancode, Text ] to create a fortranf source file containing the code. hth, albert === Subject: Re: Traditional Ordering of Equations > As a beginner in Mathematica I am using Mathematica 6.0 for integration and simplification of a number of functions which I subsequently use in a Fortran program. Now I have two questions which I cannot find the answer to in the documentation or forums: > > - Is there a way to prevent Mathematica from reordering a function to its standard order upon evaluation? > > - I want to list all resulting functions in one cell, as can be done using the Print and Fortranform commands. I want the list to look like this: > > > FunctionName1 = Function1 > FunctionName2 = Function2 > FunctionName3 = Function3 > etc. > > All these functions were defined earlier in the notebook using the following syntax: > > FunctionName1 = Function1 > > I tried writing a new Mathematica function to do this: > > FortranFormulas[ff_] := This line, > Print[HoldForm[ff] = FortranForm[ff]] is equivalent to Print[ HoldForm[ff] * = * FortranForm[ff] ]. Multiplication is commutative, so Mathematica will automatically sort the three terms. You probably meant Print[HoldForm[ff], =, FortranForm[ff]] instead. > FunctionNameList = {NO3inYt, NO3outYt} > Scan[FortranFormulas, FunctionNameList] > > However, this generates an output like: > = Function1inFortranForm Function1 > = Function2inFortranForm Function2 > > The alternative: > FortranFormulas[ff_] := > Print[ff] = FortranForm[Release[ff]]] Again, the syntax appears to be incorrect here ... > FunctionNameList = {HoldForm[NO3inYt], HoldForm[NO3outYt]} > Scan[FortranFormulas, FunctionNameList] > > generates an output like: > = FunctionName1 FunctionName1 > = FunctionName2 FunctionName2 > > Both are incorrect and in the wrong order. > > Here's a way to do this: First, let's produce some pretty formulae to experiment with: y = HornerForm[LegendreP[6, x]] z = TrigExpand[Cos[6 x]] The key is to set the attribute HoldAll on the function: ClearAll[fortranFormulas] SetAttributes[fortranFormulas, HoldAll] fortranFormulas[ff_] := Print[HoldForm[ff], = , FortranForm[ff]] Now one way to use the function on a list is to wrap all symbols in Hold, as you did: fortranFormulas @@@ {Hold[y], Hold[z]} But it may be more convenient (less typing with long lists) to just use strings: Scan[ToExpression[#, InputForm, fortranFormulas] &, {y, z}] === Subject: NthSubset function of Combinatorica package Hello all: Do you know how the function NthSubset of the Combinatorica package works? If you can point me to a description of the algorithm, that would be very helpful. Roman. === Subject: Re: NthSubset function of Combinatorica package >> Certainly you mean that it does NOT make use of the latter (just a >> typo). :-) Yes, looking back at my posts I often see that some things that I > meant to be there are missing, or that some things that I did not > mean to be there are present. Very rarely everything is perfectly in > order but then the post itself is missing ;-) > I am quite confused about the subset-related functions of >> Combinatorica. >> There are several functions for generating the nth subset for >> different orderings. The doc page of NthSubset uses the expression >> canonical order, and this is what the function produces: >> Table[NthSubset[i, {1, 2, 3}], {i, 0, 2^3 - 1}] >> {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}} This is the standard length-lexicographic ordering. That means: > first subsets are ordered by length, then, among those of equal > length the lexicographic order is used. >> The doc page of NextSubset also mentions canonical order, but it >> generates subsets in a different order: >> NestList[NextSubset[{1, 2, 3}, #] &, {}, 2^3 - 1] >> {{}, {3}, {2}, {2, 3}, {1}, {1, 3}, {1, 2}, {1, 2, 3}} Here it seems that subsets are ordered lexicographically according > to the elements they do not contain - those that do not contain 1 > come before those that do, if both contain (or both do not contain) > 1, then those that do not contain 2 come earlier, and so on. >> The doc page of UnrankSubset says some canonical order: >> Table[UnrankSubset[i, {1, 2, 3}], {i, 0, 2^3 - 1}] >> {{}, {3}, {2, 3}, {2}, {1, 2}, {1, 2, 3}, {1, 3}, {1}} This one seems more complicated, or at least I can only see a fairly > complicated way of describing it. First, subsets that do not contain > 1 come before those that do. Next, among those that do not contain > 1, those that contain 2 come after those that don't and among those > that do contain 1, those that contain 2 are come before those that > do not. This alternation is then continued inductively. (there > maybe a much easier way to describe this ordering but I can't see > it right now). I assume that this somewhat strange ordering is used > because of better performance (?) > This is the standard length-lexicographic ordering. That means, > first subsets are ordered by length. Then, among those of equal > length the lexicographic order is used. This last paragraph, of course, should have been erased before posting. It provided a completely unintended illustration of what I Andrzej === Subject: Re: NthSubset function of Combinatorica package Hello all: Do you know how the function NthSubset of the Combinatorica package > works? If you can point me to a description of the algorithm, that > would be very helpful. > You can read the source code of all standard packages. Go to >> $InstallationDirectory/AddOns/Packages/Combinatorica, and search for >> NthSubset in Combinatorica.m. You will find that it just calls the >> built-in Subsets function. >> Subsets[] is built-in, so we cannot see its implementation. But there >> are several subset-related functions in Combinatorica, such as KSubsets, >> whose code is available. You can check those. >> Or just search the web. Here's the first hit I got for generating >> subsets: >> http://compprog.wordpress.com/2007/10/10/generating-subsets/ >> And a Mathematica implementation of this algorithm (for generating all >> subsets): >> subsets[l_List] := >> Table[Pick[l, IntegerDigits[k, 2, Length[l]], 1], >> {k, 0, 2^Length[l] - 1}] > However, note that Subsets[Range[1000], All, {1100}] ( {{1, 100}} ) returns the answer immediately while Subsets[Range[1000], All] gives a rather different answer ... so the former certianly does make use of > the latter. > Certainly you mean that it does NOT make use of the latter (just a typo). :-) I am quite confused about the subset-related functions of Combinatorica. There are several functions for generating the nth subset for different orderings. The doc page of NthSubset uses the expression canonical order, and this is what the function produces: Table[NthSubset[i, {1, 2, 3}], {i, 0, 2^3 - 1}] {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}} The doc page of NextSubset also mentions canonical order, but it generates subsets in a different order: NestList[NextSubset[{1, 2, 3}, #] &, {}, 2^3 - 1] {{}, {3}, {2}, {2, 3}, {1}, {1, 3}, {1, 2}, {1, 2, 3}} The doc page of UnrankSubset says some canonical order: Table[UnrankSubset[i, {1, 2, 3}], {i, 0, 2^3 - 1}] {{}, {3}, {2, 3}, {2}, {1, 2}, {1, 2, 3}, {1, 3}, {1}} So it seems that canonical order can mean many different things in Combinatorica ... There are some other functions, too, with precise definitions of the order, such as UnrankGrayCodeSubset, UnrankBinarySubset, and NextLexicographicSubset. It seems that the relevant function (with accessible source code) for the OP is UnrankKSubset, because it generates subsets in the same order as NthSubset/Subset: Join @@ Table[ UnrankKSubset[m - 1, k, {1, 2, 3, 4}], {k, 0, 4}, {m, Binomial[4, k]}] {{}, {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}} UnrankKSubset is also a good example of why it is a very bad idea to use $RecursionLimit = Infinity. On the doc page it is not explained that UnrankKSubset's first argument starts from 0 (and not from 1), and UnrankKSubset[1, 0, {1, 2, 3}] (which one might expect to return {}) simply crashes the kernel, causing the kernel state to be lost. I really hope that WRI will include proper stack overflow protection in future versions of Mathematica ... (and perhaps a Front End dialogue box that would alert the user that the kernel has crashed ... the only indication is a beep and I am sure that many users will not notice immediately what happened.) === Subject: Re: NthSubset function of Combinatorica package >> Hello all: >> Do you know how the function NthSubset of the Combinatorica >> package >> works? If you can point me to a description of the algorithm, that >> would be very helpful. You can read the source code of all standard packages. Go to > $InstallationDirectory/AddOns/Packages/Combinatorica, and search for > NthSubset in Combinatorica.m. You will find that it just calls the > built-in Subsets function. Subsets[] is built-in, so we cannot see its implementation. But > there > are several subset-related functions in Combinatorica, such as > KSubsets, > whose code is available. You can check those. Or just search the web. Here's the first hit I got for generating > subsets: http://compprog.wordpress.com/2007/10/10/generating-subsets/ And a Mathematica implementation of this algorithm (for generating = > all > subsets): subsets[l_List] := > Table[Pick[l, IntegerDigits[k, 2, Length[l]], 1], > {k, 0, 2^Length[l] - 1}] > However, note that >> Subsets[Range[1000], All, {1100}] >> ( {{1, 100}} ) >> returns the answer immediately while >> Subsets[Range[1000], All] >> gives a rather different answer ... so the former certianly does >> make use of >> the latter. Certainly you mean that it does NOT make use of the latter (just a > typo). :-) Yes, looking back at my posts I often see that some things that I meant to be there are missing, or that some things that I did not mean to be there are present. Very rarely everything is perfectly in order but then the post itself is missing ;-) > I am quite confused about the subset-related functions of > Combinatorica. There are several functions for generating the nth subset for > different orderings. The doc page of NthSubset uses the expression > canonical order, and this is what the function produces: Table[NthSubset[i, {1, 2, 3}], {i, 0, 2^3 - 1}] {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}} This is the standard length-lexicographic ordering. That means: first subsets are ordered by length, then, among those of equal length the lexicographic order is used. > The doc page of NextSubset also mentions canonical order, but it > generates subsets in a different order: NestList[NextSubset[{1, 2, 3}, #] &, {}, 2^3 - 1] {{}, {3}, {2}, {2, 3}, {1}, {1, 3}, {1, 2}, {1, 2, 3}} Here it seems that subsets are ordered lexicographically according to the elements they do not contain - those that do not contain 1 come before those that do, if both contain (or both do not contain) 1, then those that do not contain 2 come earlier, and so on. > The doc page of UnrankSubset says some canonical order: Table[UnrankSubset[i, {1, 2, 3}], {i, 0, 2^3 - 1}] {{}, {3}, {2, 3}, {2}, {1, 2}, {1, 2, 3}, {1, 3}, {1}} This one seems more complicated, or at least I can only see a fairly complicated way of describing it. First, subsets that do not contain 1 come before those that do. Next, among those that do not contain 1, those that contain 2 come after those that don't and among those that do contain 1, those that contain 2 are come before those that do not. This alternation is then continued inductively. (there maybe a much easier way to describe this ordering but I can't see it right now). I assume that this somewhat strange ordering is used because of better performance (?) This is the standard length-lexicographic ordering. That means, first subsets are ordered by length. Then, among those of equal length the lexicographic order is used. Andrzej Kozlowski > So it seems that canonical order can mean many different things in > Combinatorica ... There are some other functions, too, with precise definitions of the > order, such as UnrankGrayCodeSubset, UnrankBinarySubset, and > NextLexicographicSubset. It seems that the relevant function (with accessible source code) for > the OP is UnrankKSubset, because it generates subsets in the same > order as NthSubset/Subset: Join @@ Table[ > UnrankKSubset[m - 1, k, {1, 2, 3, 4}], {k, 0, 4}, {m, Binomial[4, > k]}] {{}, {1}, {2}, {3}, {4}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, > {3, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}} > UnrankKSubset is also a good example of why it is a very bad idea to > use $RecursionLimit = Infinity. On the doc page it is not explained > that UnrankKSubset's first argument starts from 0 (and not from 1), > and UnrankKSubset[1, 0, {1, 2, 3}] (which one might expect to return > {}) simply crashes the kernel, causing the kernel state to be lost. I really hope that WRI will include proper stack overflow protection > in future versions of Mathematica ... (and perhaps a Front End > dialogue box that would alert the user that the kernel has crashed ... > the only indication is a beep and I am sure that many users will not > notice immediately what happened.) === Subject: Re: NthSubset function of Combinatorica package >> Hello all: >> Do you know how the function NthSubset of the Combinatorica package >> works? If you can point me to a description of the algorithm, that >> would be very helpful. You can read the source code of all standard packages. Go to > $InstallationDirectory/AddOns/Packages/Combinatorica, and search for > NthSubset in Combinatorica.m. You will find that it just calls the > built-in Subsets function. Subsets[] is built-in, so we cannot see its implementation. But there > are several subset-related functions in Combinatorica, such as > KSubsets, > whose code is available. You can check those. Or just search the web. Here's the first hit I got for generating > subsets: http://compprog.wordpress.com/2007/10/10/generating-subsets/ And a Mathematica implementation of this algorithm (for generating all > subsets): subsets[l_List] := > Table[Pick[l, IntegerDigits[k, 2, Length[l]], 1], > {k, 0, 2^Length[l] - 1}] > However, note that Subsets[Range[1000], All, {1100}] ( {{1, 100}} ) returns the answer immediately while Subsets[Range[1000], All] gives a rather different answer ... so the former certianly does make use of the latter. Andrzej Kozlowski === Subject: Re: NthSubset function of Combinatorica package > Hello all: > > Do you know how the function NthSubset of the Combinatorica package > works? If you can point me to a description of the algorithm, that > would be very helpful. > You can read the source code of all standard packages. Go to $InstallationDirectory/AddOns/Packages/Combinatorica, and search for NthSubset in Combinatorica.m. You will find that it just calls the built-in Subsets function. Subsets[] is built-in, so we cannot see its implementation. But there are several subset-related functions in Combinatorica, such as KSubsets, whose code is available. You can check those. Or just search the web. Here's the first hit I got for generating subsets: http://compprog.wordpress.com/2007/10/10/generating-subsets/ And a Mathematica implementation of this algorithm (for generating all subsets): subsets[l_List] := Table[Pick[l, IntegerDigits[k, 2, Length[l]], 1], {k, 0, 2^Length[l] - 1}] === Subject: Re: Range of Use of Mathematica I think David's right on! His Derivations sub-package is phenomenal, and I only wish I had more occasions to use it. Bobby > For some years now 'AES' (actually Professor Anthony E. Siegman, McMurty > Professor of Engineering Emeritus at Stanford University) and I have > engaged > in a running dialog on the extent of Mathematica's usefulness in > preparing > research material for publication. I believe that AES's basic position is > that Mathematica is fine for doing computer algebra (traditional CAS > operations), numerical calculations and generating starting graphics for > publications. But then he advocates using outside programs for perfecting > the graphics, doing typesetting and preparing the final publication. He > thinks that ..even attempting (to combine these functions in > Mathematica) . > is inherently a bad idea. > I suspect that this is, in fact, the procedure employed by most > Mathematica > users involved in research and publication. Not being myself extremely > prolific in publishable ideas, and in recent years only publishing a few > Mathematica papers, which were in notebook form, I'm not in a position > to be > too critical of AES's position and I do respect his experience and > knowledge > in these matters. > What I have been interested in is using Mathematica to study various > textbooks and subjects to attempt to learn some modern mathematics and > physics. In doing this I have always wanted to produce notebooks that > looked > like textbooks or research papers. Not having publication as a primary > objective, I have been willing to stay with Mathematica all the way. > What I > have learned is that with Mathematica I can produce notebooks that look > like > regular publications. I have to admit that this does require extra > effort in > the way of writing convenience routines that define and format various > objects one may be dealing with. But it does not involve more work that > buying additional, often expensive, applications and learning their > installation, syntax and operation, and how to export Mathematica > results to > these programs. If one already has and knows well these additional > applications, before coming to Mathematica, then AES's approach is the > natural one. For those who come to Mathematica first, I think it would be > far easier to work in Mathematica as far as possible. I don't see why one > couldn't write an entire paper in Mathematica and then print it as a PDF > document. > Even if one uses Mathematica strictly for CAS work and numerical > calculations, it is still necessary to write definitions and routines for > processing the objects one deals with. I do not see why there should be > an > artificial line between extra routines that calculate and extra routines > that format. And, in any case, having nice presentations of objects is > often > an integral part of calculating with them and understanding the theory. > Having this preference for Mathematica notebooks, and looking at many > textbooks and papers, I will go one step further, many will say right off > the edge! Mathematica notebooks are inherently FAR SUPERIOR to static > printed documents. They are so superior that I can't understand why > anyone > would want to transform to printed documents. A Mathematica notebook is > to a > printed document as the Parthenon is to its floor plan. Forget that > static > printed papers are the standard of today. They won't be in the future. > I'll give two examples where printed documents fall short. The first is > the > general matter of presenting mathematical proofs in textbooks. I find > proofs > difficult and the limitations of the printed page do not make them any > easier. Proofs usually have structure, but in books and especially with > poor > typographic layout, they often look like a run-on paragraph. Proofs often > need commentary and sometimes extended examples or subparts. Putting > these > in the middle of a proof disrupts the structure of the proof and putting > them before or after disconnects them. So I take it as something of a > challenge to learn how to better present proofs using the active > features of > Mathematica. I've written a Derivation container that can contain comment > and command expressions. The comments can be used to annotate the steps > of a > proof or derivation. A command gives evaluated results of a Mathematica > statement, with a Tooltip of the generating statement. I've also designed > Sidebars, which are notebooks embedded within the main notebook that can > be > launched by a button. These provide methods to clarify proofs and > derivations but there may be other and better methods, such as using > TabView > for various sections of a proof. Every proof may require its own style of > presentation. I think there is much that can be done with Mathematica to > make the presentation of proofs clearer, more elegant and easier for > students and readers than anything possible in printed documents. If we > always think in terms of static printed documents we won't even take up > this > challenge. > As a second example, my wife and I are reading 'King of Infinite Space: > Donald Coxeter, the Man Who Saved Geometry' by Siobhan Roberts. Excellent > book! There, in discussing methods to visualize four dimensional space > Coxeter used the idea of slicing, and slicing from 3-dimensional space to > 2-dimensional space as practice. So there were pictures of sequences of > parallel sections slicing the Icosahedron (vertex first, edge first and > face > first) and Dodecahedron. But these are very difficult to follow on a > static > page. I could partially follow them and my wife was rather lost. How much > better to see these in a Manipulate statement where one could set the > normal > to the slicing plane and slowly move through a regular polyhedron. It > would > be especially nice if we could get the 3D slicing picture in one pane and > the 2D outline in a second pane. It sent me to the Demonstrations > project to > see if this had been done but I couldn't find it, and I suspect it might > be > somewhat difficult. But I did find some nice animations demonstrating > Euclidean solid geometry theorems by Isidor Hafner! > Still, I have some reservations about the Demonstrations Project, as > popular > as it is. If forcing everything onto a static printed page is one > restrictive mode or presenting material, then forcing everything into a > Manipulate statement is another restrictive mode. Generally the > Demonstration projects are lacking in textual discussion, derivations, > methods of calculation, and because of that, generally difficult to > actually > follow and learn from. The lesson to me is that we should not > artificially > restrict Mathematica but use its full powers to present topics in > notebooks > that follow a classical style of writing but employ the active > capabilities > of Mathematica. David Park djmpark@comcast.net http://home.comcast.net/~djmpark > -- DrMajorBob@longhorns.com === Subject: Range of Use of Mathematica For some years now 'AES' (actually Professor Anthony E. Siegman, McMurty Professor of Engineering Emeritus at Stanford University) and I have engaged in a running dialog on the extent of Mathematica's usefulness in preparing research material for publication. I believe that AES's basic position is that Mathematica is fine for doing computer algebra (traditional CAS operations), numerical calculations and generating starting graphics for publications. But then he advocates using outside programs for perfecting the graphics, doing typesetting and preparing the final publication. He thinks that ..even attempting (to combine these functions in Mathematica) . is inherently a bad idea. I suspect that this is, in fact, the procedure employed by most Mathematica users involved in research and publication. Not being myself extremely prolific in publishable ideas, and in recent years only publishing a few Mathematica papers, which were in notebook form, I'm not in a position to be too critical of AES's position and I do respect his experience and knowledge in these matters. What I have been interested in is using Mathematica to study various textbooks and subjects to attempt to learn some modern mathematics and physics. In doing this I have always wanted to produce notebooks that looked like textbooks or research papers. Not having publication as a primary objective, I have been willing to stay with Mathematica all the way. What I have learned is that with Mathematica I can produce notebooks that look like regular publications. I have to admit that this does require extra effort in the way of writing convenience routines that define and format various objects one may be dealing with. But it does not involve more work that buying additional, often expensive, applications and learning their installation, syntax and operation, and how to export Mathematica results to these programs. If one already has and knows well these additional applications, before coming to Mathematica, then AES's approach is the natural one. For those who come to Mathematica first, I think it would be far easier to work in Mathematica as far as possible. I don't see why one couldn't write an entire paper in Mathematica and then print it as a PDF document. Even if one uses Mathematica strictly for CAS work and numerical calculations, it is still necessary to write definitions and routines for processing the objects one deals with. I do not see why there should be an artificial line between extra routines that calculate and extra routines that format. And, in any case, having nice presentations of objects is often an integral part of calculating with them and understanding the theory. Having this preference for Mathematica notebooks, and looking at many textbooks and papers, I will go one step further, many will say right off the edge! Mathematica notebooks are inherently FAR SUPERIOR to static printed documents. They are so superior that I can't understand why anyone would want to transform to printed documents. A Mathematica notebook is to a printed document as the Parthenon is to its floor plan. Forget that static printed papers are the standard of today. They won't be in the future. I'll give two examples where printed documents fall short. The first is the general matter of presenting mathematical proofs in textbooks. I find proofs difficult and the limitations of the printed page do not make them any easier. Proofs usually have structure, but in books and especially with poor typographic layout, they often look like a run-on paragraph. Proofs often need commentary and sometimes extended examples or subparts. Putting these in the middle of a proof disrupts the structure of the proof and putting them before or after disconnects them. So I take it as something of a challenge to learn how to better present proofs using the active features of Mathematica. I've written a Derivation container that can contain comment and command expressions. The comments can be used to annotate the steps of a proof or derivation. A command gives evaluated results of a Mathematica statement, with a Tooltip of the generating statement. I've also designed Sidebars, which are notebooks embedded within the main notebook that can be launched by a button. These provide methods to clarify proofs and derivations but there may be other and better methods, such as using TabView for various sections of a proof. Every proof may require its own style of presentation. I think there is much that can be done with Mathematica to make the presentation of proofs clearer, more elegant and easier for students and readers than anything possible in printed documents. If we always think in terms of static printed documents we won't even take up this challenge. As a second example, my wife and I are reading 'King of Infinite Space: Donald Coxeter, the Man Who Saved Geometry' by Siobhan Roberts. Excellent book! There, in discussing methods to visualize four dimensional space Coxeter used the idea of slicing, and slicing from 3-dimensional space to 2-dimensional space as practice. So there were pictures of sequences of parallel sections slicing the Icosahedron (vertex first, edge first and face first) and Dodecahedron. But these are very difficult to follow on a static page. I could partially follow them and my wife was rather lost. How much better to see these in a Manipulate statement where one could set the normal to the slicing plane and slowly move through a regular polyhedron. It would be especially nice if we could get the 3D slicing picture in one pane and the 2D outline in a second pane. It sent me to the Demonstrations project to see if this had been done but I couldn't find it, and I suspect it might be somewhat difficult. But I did find some nice animations demonstrating Euclidean solid geometry theorems by Isidor Hafner! Still, I have some reservations about the Demonstrations Project, as popular as it is. If forcing everything onto a static printed page is one restrictive mode or presenting material, then forcing everything into a Manipulate statement is another restrictive mode. Generally the Demonstration projects are lacking in textual discussion, derivations, methods of calculation, and because of that, generally difficult to actually follow and learn from. The lesson to me is that we should not artificially restrict Mathematica but use its full powers to present topics in notebooks that follow a classical style of writing but employ the active capabilities of Mathematica. David Park djmpark@comcast.net http://home.comcast.net/~djmpark === Subject: Re: Range of Use of Mathematica > For some years now 'AES' (actually Professor Anthony E. Siegman, McMurty > Professor of Engineering Emeritus at Stanford University) and I have engaged > in a running dialog on the extent of Mathematica's usefulness in preparing > research material for publication. I believe that AES's basic position is > that Mathematica is fine for doing computer algebra (traditional CAS > operations), numerical calculations and generating starting graphics for > publications. But then he advocates using outside programs for perfecting > the graphics, doing typesetting and preparing the final publication. He > thinks that ..even attempting (to combine these functions in Mathematica) . > is inherently a bad idea. > > [Remainder of post snipped] > I appreciate David Park's setting out this outline of our respective views and differences. I believe he's given a fair and accurate summary of these views and differences, and also that there is a quite sizable amount of agreement, but also some definite and persistent areas of disagreement, in our views. And, I also believe there are some additional factors and arguments that also need to be brought out on these issues. I'd like to respond on all these aspects (although I suspect there are others on this group who may feel that I've posted more than enough already), and I hope to respond eventually; but this may not happen for a while because of pressure of other commitments on my side (and very likely on his also). Others may of course also want to add other comments. One response I'd make immediately is that the issues here seem to me to be quite a broader than just the range of ways in which Mathematica can be used. The real underlying issue is (even if phrasing it this way may sound a bit pretentious): What is, or what could be, or should be, the _strategic vision_ for Mathematica, as a system or as a product line or as a useful tool or even as a communications standard? And then, as a necessary of this strategic vision, what is really the target market or audience for Mathematica? And then, if there's any agreement on this strategic vision, and on the market for it, how do those choices influence the way that Mathematica should be designed, and developed, and marketed, and documented, and delivered, and priced? --- including especially, what should it's interface look like? Those are all questions that can, of course, be argued and discussed at immense length --- and such discussions, while providing lots of grist for entertaining comments and flame wars, may come to very little beyond that, if Wolfram Inc already has its strategic vision, thank you, and is not inclined to open this vision up very much to outside knowledge or input. And finally, my pretty strong personal impressions (for what little they're worth) are that if Wolfram Inc. (or Wolfram, person?) really has a clear strategic vision for Mathematica, it's certainly not clear to me what it really is; and secondarily, despite the obvious levels of skill and ability and dedication in those who create and maintain Mathematica, there are a lot of ways in which Walfram is seriously missing the boat in building a product to occupy and serve a larger user environment, with user documentation being the most obvious area for this kind of criticism. === Subject: Re: DSolve question My second post was made immediately after the first but ended up much further down the chain. === Subject: Re: RenderBadPicture error while running Kishan and Peter, Setting the environment variable XLIB_SKIP_ARGB_VISUALS to 1 before starting Mathematica may correct this problem. env XLIB_SKIP_ARGB_VISUALS=1 mathematica Chris Hill Wolfram Research >Hi dear group, I get hundreds of these messages since I upgraded to Fedora Linux 9 (for >x86_64 - architecture). Additionally the fonts are only partally shown >in the Frontend (FontPaths are set in xorg.conf and xset q confirms they >are recognized). Mathematica 6 worked well with Fedora 8. The same messages and symptoms ('special' characters like brackets and >'+' display but letters and digits do not) on Ubuntu 8.04 x86_64. Mathematica 5 works fine in both cases. openSuse 10.3 + Mathematica 6 works perfectly, but I did a fresh >install on a small partition and do not want to migrate from Fedora to >openSuse (but maybe I will do. Fedora 9 came without 3D-support (at >least for my ATI-Radeon based card); unbelievable these days, isn't it?). I really can not figure out, why this happens and any idea is welcome. >TIA, >Peter > Hi all, > > I am getting an error while running Mathematica 6 on my Linux machine. > The details of the error is as follows. Please help me out if you know > the solution. > > X Error of failed request: RenderBadPicture (invalid Picture > parameter) > Major opcode of failed request: 154 (RENDER) > Minor opcode of failed request: 7 (RenderFreePicture) > Picture id in failed request: 0x2a09632 > Serial number of failed request: 382906 > Current serial number in output stream: 382909 > > X Error of failed request: BadMatch (invalid parameter attributes) > Major opcode of failed request: 154 (RENDER) > Minor opcode of failed request: 4 (RenderCreatePicture) > Serial number of failed request: 383763 > Current serial number in output stream: 383766 > > Kishan. > === Subject: Re: overloading times operator >elements of the form e_X e_Y, where X and Y are multi-indices. I do >this using Times. >I do a simple calculation like >Expand[(e_{1} + e_{3})(e_{1} - e_{3})] >and get the wrong answer. (On the first try.) >If I then re-execute the code that defines the multiplication, I >repeat the calculation and get correct output. >Alternatively, if I execute >e=Symbol[e] >before loading the procedure, I get correct output on the first try. >More troubling is that after getting correct output, if I perform >calculations of a different kind (e.g. matrix multiplication), when >I repeat my original calculation, I start getting incorrect output >again. (Until I re-execute the code that defines the >multiplication.) >It's frustrating to repeat a calculation and get different sets of >output depending on what other calculations are done in between. >Does anyone have suggestions? overload Times. So, I don't see a way to determine precisely why things work the way you describe. But, having said that there are two obvious things to look at: Second, is the issue of overloading a commonly used function such as Times. It is inherently risky to overload operations that are likely to be used throughout Mathematica. Possibly, there is some internal code that is designed to temporarily overload Times which restores the default behavior to clean up after itself. Assuming no errors in your code, this would explain the behavior you see. But this is entirely speculation on my part. Rather than overload Times, I would define one of the operators without built in meanings such as CircleTimes to have the behavior you want. This would ensure your code will not interact in some unintended way with other built in functions. See tutorial/OperatorsWithoutBuiltInMeanings. === Subject: Re: Replace non-numeric values in a list Here's yet another variation, that is slightly faster on my machine (we can negate the pattern instead of the test): In[7]:= Replace[bigriffledlist, Except[_?NumericQ] -> 0, 1]; // Timing Out[7]= {7.86, Null} In[8]:= Replace[bigriffledlist, {x_?NumericQ -> x, x_ -> 0}, 1]; // Timing (* Bobby's version *) Out[8]= {9.765, Null} > Hi Adel et al, There were a lot of interesting replies to this question. I thought you might be interested in speed of some of them on a big list. Bobby was fastest followed by Szabolcs. bigriffledlist = Riffle[RandomInteger[{1, 5}, 5000000], {x, y, z}]; newlistbob = Replace[bigriffledlist, {x_?NumericQ -> x, x_ -> 0}, 1]; // > Timing (* DrMajorBob *) {5.81391, Null} newlistszabolcs = Replace[bigriffledlist, x_ /; ! NumericQ[x] -> 0, 1]; // > Timing (*Szabolcs Horvat*) {8.11852, Null} > newlistszabolcs == newlistbob // Timing {0.090427, True} Other notables were. newlist = Map[(If[NumericQ[#], #, 0] &), bigriffledlist]; // Timing (*Bob > Hanlon*) {10.2462, Null} newlist = Replace[bigriffledlist, _?(Not[NumericQ[#]] &) -> 0, 1]; // > Timing (*Bob Hanlon*) {11.9771, Null} > Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) > MacOS X V 10.5.2 > list = {a, 1, 2, b, 3}; >> Replace[list, {x_?NumericQ -> x, x_ -> 0}, 1] >> {0, 1, 2, 0, 3} >> or >> Replace[list, x_ /; ! NumericQ[x] -> 0, 1] >> {0, 1, 2, 0, 3} >> Bobby I have a list that contains numeric and non-numeric values > list = { a, 1, 2, b, 3}; > How can I replace non-numeric values with zeros? > -- >> DrMajorBob@longhorns.com === Subject: Re: Replace non-numeric values in a list > Hi Adel, > > a really straightforward method would be (assuming your list > explicitly contains letters and numbers only as in your example) > > In[1]= list = {a, 1, 2, b, 3}; > > In[2]= isletter[a_] := If[LetterQ[ToString[a]], True, False] > > In[3]= newlist = Table[If[isletter[list[[i]]], 0, list[[i]]], {i, > Length[list]}] > > Out[4]= {0, 1, 2, 0, 3} > It is not a very good idea to rely on ugly hacks like this ... For example, this will fail for {1, 2, Pi} ... === Subject: Re: Replace non-numeric values in a list Hi Adel et al, There were a lot of interesting replies to this question. I thought you might be interested in speed of some of them on a big list. Bobby was fastest followed by Szabolcs. bigriffledlist = Riffle[RandomInteger[{1, 5}, 5000000], {x, y, z}]; newlistbob = Replace[bigriffledlist, {x_?NumericQ -> x, x_ -> 0}, 1]; // Timing (* DrMajorBob *) {5.81391, Null} newlistszabolcs = Replace[bigriffledlist, x_ /; ! NumericQ[x] -> 0, 1]; // Timing (*Szabolcs Horvat*) {8.11852, Null} newlistszabolcs == newlistbob // Timing {0.090427, True} Other notables were. newlist = Map[(If[NumericQ[#], #, 0] &), bigriffledlist]; // Timing (*Bob Hanlon*) {10.2462, Null} newlist = Replace[bigriffledlist, _?(Not[NumericQ[#]] &) -> 0, 1]; // Timing (*Bob Hanlon*) {11.9771, Null} Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) MacOS X V 10.5.2 > list = {a, 1, 2, b, 3}; > Replace[list, {x_?NumericQ -> x, x_ -> 0}, 1] {0, 1, 2, 0, 3} or Replace[list, x_ /; ! NumericQ[x] -> 0, 1] {0, 1, 2, 0, 3} Bobby >> I have a list that contains numeric and non-numeric values >> list = { a, 1, 2, b, 3}; >> How can I replace non-numeric values with zeros? > > -- DrMajorBob@longhorns.com > === Subject: Re: Replace non-numeric values in a list >> I have a list that contains numeric and non-numeric values >> list = { a, 1, 2, b, 3}; >> How can I replace non-numeric values with zeros? >> -- >> Adel Elsabbaghhttp://www.svlab-asu.com/aelsabbagh.html Surprisingly the script below fails. Anyone want to comment? list = { a, 1, 2, b, 3}; newlist2 = list /. v_?(Not[NumericQ[#]] &) -> 0 Not really surprising. list itself is not numeric so it matches the pattern. Search for pattern in ReplaceAll beigns at the bottom level and stops if a match is found so list is the first and only match. One way to avoid this is: newlist2 = Replace[list, v_?(Not[NumericQ[#]] &) -> 0, {1}] {0, 1, 2, 0, 3} Andrzej Kozlowski === Subject: An Elegant way of plotting the Pole-Zero diagram Hi to All: Would anyone care to provide an elegant way of plotting the pole-zero diagram of a transfer function H[s], using the conventional symbols, namely, x for poles and 0 for zeros. Mathematica does not have a built-in function to draw those symbols---like Point[] and PointSize[]. Your help will be appreciated Lemiel === Subject: Re: An Elegant way of plotting the Pole-Zero diagram and poles = {0.45 + I*0.45, -0.45 - I*0.45}; zeros = {1, -1}; Graphics[{{Dashing[Tiny], GrayLevel[0.25], Circle[{0, 0}, 1]}, {RGBColor[1, 0, 0], Text[[Times], {Re[#], Im[#]}] & /@ poles, Text[[EmptyCircle], {Re[#], Im[#]}] & /@ zeros}}, Axes -> True, AspectRatio -> 1 ] does not help ? Jens > Hi to All: > > Would anyone care to provide an elegant way of plotting the pole-zero > diagram of a transfer function H[s], using the conventional symbols, > namely, x for poles and 0 for zeros. Mathematica does not have a > built-in function to draw those symbols---like Point[] and > PointSize[]. > Your help will be appreciated > Lemiel > === Subject: Re: An Elegant way of plotting the Pole-Zero diagram > Hi to All: > > Would anyone care to provide an elegant way of plotting the pole-zero > diagram of a transfer function H[s], using the conventional symbols, > namely, x for poles and 0 for zeros. Mathematica does not have a > built-in function to draw those symbols---like Point[] and > PointSize[]. Here are two functions for those symbols: zero[pt_, size_: 10] := Circle[pt, Offset[size/2 {1, 1}]] pole[pt_, size_: 10] := Line[Map[Offset[size/2 #, pt] &, {{{1, 1}, {-1, -1}}, {{-1, 1}, {1, -1}}}, {2}]] The size is specified in printer's points, i.e. it stays constant while resizing the plot. === Subject: Filtering a list of list for certain elements that are neighbours I have a list of lists mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} I want to filter out all lists that have a being a neighbor to b. I am looking for the following result. {{a,c,b},{b,c,a}} For this toy example, I can probably do it by hand but my real problem has 120 lists in a list. And I need to filter out various combination of letters like s cannot be next to d , s cannot be next to j , c cannot be next to j , h cannot be next to d and h cannot be next to s. === Subject: Re: Filtering a list of list for certain elements that are neighbours Cases[mylist, {a, ___, b} | {b, ___, a}] if this is equivalent to a being a neighbor to b what ever this mean. Jens > I have a list of lists > > mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} > > I want to filter out all lists that have a being a neighbor to b. > > I am looking for the following result. > > {{a,c,b},{b,c,a}} > > > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. > === Subject: Re: Filtering a list of list for certain elements that are neighbours > I have a list of lists > > mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} > > I want to filter out all lists that have a being a neighbor to b. > > I am looking for the following result. > > {{a,c,b},{b,c,a}} > > > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. > Cases[mylist, Except[{___, a, b, ___} | {___, b, a, ___}]] === Subject: Re: Filtering a list of list for certain elements that are neighbours Hi Steve, try e.g.: DeleteCases[mylist,{___,a,b,___}|{___,b,a,___}] hope this helps, Daniel > I have a list of lists > > mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} > > I want to filter out all lists that have a being a neighbor to b. > > I am looking for the following result. > > {{a,c,b},{b,c,a}} > > > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. > === Subject: Re: Filtering a list of list for certain elements that are neighbours > I have a list of lists > > mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} > > I want to filter out all lists that have a being a neighbor to b. > > I am looking for the following result. > > {{a,c,b},{b,c,a}} I think this is the most straightforward way to achieve what you want: DeleteCases[mylist, {___, a, b, ___} | {___, b, a, ___}] > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. There might be more efficient solutions than the above, but for 120 lists I think there is no reason to waste your time to save CPU time. You might want to write a filter function which can handle arbitrary pairs, like: filter[l_,a_,b_]:=DeleteCases[l, {___, a, b, ___} | {___, b, a, ___}] then use it like: filter[mylist,s,d] filter[mylist,s,j] ... hth, albert === Subject: Framed[3, FrameStyle -> None] fails It seems that the option FrameStyle -> None to Framed does not work. Framed[3, FrameStyle -> None] returns a framed 3 with a black border around it in Mathematica version 6.0 on WinXP. The documentation states that, The option setting FrameStyle->None draws no explicit frame. Chris === Subject: Re: Filtering a list of list for certain elements that are neighbours >I have a list of lists >mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} >I want to filter out all lists that have a being a neighbor to b. >I am looking for the following result. >{{a,c,b},{b,c,a}} Here is one way In[13]:= Fold[ DeleteCases[#1, #2] &, mylist, {{___, a, b, ___}, {___, b, a, ___}}] Out[13]= {{a, c, b}, {b, c, a}} === Subject: Re: An Elegant way of plotting the Pole-Zero diagram Probably not elegant The PlotMarkers for ListPlot doesn't work properly if the second list of points (zeros in this case) has only one point. For a single zero, the single point is duplicated to make the list seem to have two points. Clear[poleZeroPlot]; The PlotMarkers for ListPlot doesn't work properly if the second list of points (zeros in this case) has only one point. For a single zero, the single point is duplicated to make the list seem to have two points. poleZeroPlot[transferFunction_, s_: s] := Module[{denom, num, poles, zeros, pz, axStyle}, denom = Denominator[transferFunction]; num = Numerator[transferFunction]; poles = If[FreeQ[denom, s], {}, ({Re[#], Im[#]} & /@ (s /. Solve[denom == 0, s]))]; zeros = If[FreeQ[num, s], {}, ({Re[#], Im[#]} & /@ (s /. Solve[num == 0, s]))]; pz = Join[poles, zeros]; zeros = If[Length[zeros] == 1, Join[zeros, zeros], zeros]; axStyle = {Blue, AbsoluteDashing[{5, 5}]}; ListPlot[{poles, zeros} /. {} -> Sequence[], PlotMarkers -> (Style[#, {Bold, Red, 16}] & /@ If[Length[poles] == 0, {O}, If[Length[zeros] == 0, {X}, {X, O}]]), Frame -> True, Axes -> True, AxesStyle -> {axStyle, axStyle}, PlotRange -> 1.1 { {Min[-1, Min[pz[[All, 1]]]], Max[1, Max[pz[[All, 1]]]]}, {Min[-1, Min[pz[[All, 2]]]], Max[1, Max[pz[[All, 2]]]]}}, Epilog -> Append[axStyle, Circle[{0, 0}, 1]], AspectRatio -> Automatic]] poleZeroPlot[(s + 2)/(s^2 + 1/4)] poleZeroPlot[(s^2 + 1/4)/(s + 2)] poleZeroPlot[s^2 + 1/4] poleZeroPlot[1/(z^2 + 1/4), z] Bob Hanlon > Hi to All: > > Would anyone care to provide an elegant way of plotting the pole-zero > diagram of a transfer function H[s], using the conventional symbols, > namely, x for poles and 0 for zeros. Mathematica does not have a > built-in function to draw those symbols---like Point[] and > PointSize[]. > Your help will be appreciated > Lemiel > === Subject: CurrentValue[EventKey] fails? To all, I am unable to create an expression that reports what key has been pressed. It seems that CurrentValue[EventKey] always returns None. Here is the code: EventHandler[a string, KeyDown :> Print[CurrentValue[EventKey]]] I get similar results with: EventHandler[Dynamic[key], KeyDown :> (key = CurrentValue[EventKey])] Chris === Subject: Re: Labeling points (* Custom LabeledListPlot *) LabeledListPlot[data_] := Show[Graphics[{PointSize[Last[#]/50], Point[Take[#, 2]], Text[ToString[Round[100 Last[#]]] <> %, Take[#, 2], {-1.5, 0}]} & /@ data], Axes -> True, AxesOrigin -> {0, 0}, AspectRatio -> 1, AxesLabel -> {Shots, Damage}]; (* Data supplied by other routines *) data = {{1, 1, 0.5`1.9999999999999998}, {2, 1, 0.75`2.0000000000000004}, {2, 2, 0.25`1.9999999999999998}, {3, 1, 0.875`2.0000000000000013}, {3, 2, 0.5`1.9999999999999998}, {3, 3, 0.125`1.9999999999999998}, {4, 1, 0.9375`2.0000000000000004}, {4, 2, 0.6875`2.}, {4, 3, 0.3125`1.9999999999999998}, {4, 4, 0.0625`1.9999999999999998}, {5, 1, 0.96875`1.9999999999999991}, {5, 2, 0.8125`2.000000000000002}, {5, 3, 0.5`1.9999999999999998}, {5, 4, 0.1875`2.0000000000000004}, {5, 5, 0.03125`1.9999999999999998}, {6, 1, 0.984375`2.0000000000000004}, {6, 2, 0.890625`2.0000000000000004}, {6, 3, 0.65625`1.9999999999999998}, {6, 4, 0.34375`2.}, {6, 5, 0.109375`2.0000000000000013}, {6, 6, 0.015625`1.9999999999999998}}; LabeledListPlot[data] === Subject: Re: Labeling points >> Here's a graphic I created for a discussion on game theory: >> http://home.comcast.net/~anglewyrm/thread/dps.png >> I put the text next to the points in as a post-processing step by >> hand in >> PhotoShop. >> Is there a way to get mathematica to display such information? > You can post-process plot output to add the information you want. For > example, here is a ListPlot: plot = ListPlot[Table[{x, y}, {x, 1, 4}, {y, 1, x}], AxesOrigin -> {0, > 0}] That first reply was truncated somehow. Here's the rest... To add labels the the ListPlot output, I (1) replace Point objects in the output with labeled Points, (2) wrap the result with Show[..., PlotRangeClipping->False], which prevents labels that fall outside of the plot range from being clipped. Show[ plot /. Point[pts_] :> ({Point[#], Black, Text[Row[{IntegerPart[100 #[[2]]/5], %}], #, {-1.5, -1}]} & /@ pts), PlotRangeClipping -> False] Christopher Carlson User Interface Group Wolfram Research, Inc === Subject: Re: Multiple threads using Mathlink Hello Steve, correctly. However, my problem remains unresolved. I've done some experiments to track down the issue. Apparently, the problem is related to the Mathlink.close() method (I'm using Java). Here are the results: 1/ when I reuse the same Mathlink object to perform all computations, without closing it, everything works fine 2/ when I create a separate object in every webservice invocation, but don't use the close() method, it also works. In this case, I kill the kernel after it completes the computations (with Unix killall command). I'm forced to do this, because otherwise the webservice thread doesn't end (it's waiting for the child - Mathlink - process to complete) 3/ when I create a separate object in every webservice invocation and invoke the close() method, the application server crashes mysteriously afterwards (sometimes during a webservice invocation which doesn't use Mathlink at all). In cases 2/ and 3/, I use synchronize clauses to protect pieces of code which open and close the link. This is probably not needed, as the java Mathlink wrapper already does it (using, for instance, the environmentLock object in NativeLink.java). The schema of my Mathlink invocations is as follows: synchronized(lock) { ml.connect(); ml.discardAnswer(); } ml.evaluate(<< + scriptFile); ml.discardAnswer(); ml.evaluate(expression); ml.waitForAnswer(); ml.getXYZ(); // for instance: getDouble() synchronized(lock) { ml.close(); } I'm still not sure if the issue lies in Mathlink, my usage of it, or the webservice framework I'm using (Tomcat & Axis2). Pawel Banasik > Pawel, Generally speaking it is safe to use MathLink with threads. Here are > the relevant stipulations: 1. Do not concurrently access the same MLENV object from more than > one thread at a time. This means that you do not want multiple > threads invoking any of the MLOpen* functions using the same MLENV > object simultaneously. You will need to protect access to the MLENV > object with a thread locking mechanism. 2. Do not concurrently access the same MLINK object from more than > one thread at a time. You will need to protect access to the MLINK > object with a thread locking mechanism. To answer your question about MathLink and Kernels, you should > understand the following about MathLink. MathLink does not > specifically create Kernel processes. MathLink creates a > communication link between one process and another process. MathLink > supports the ability to start the other process, but fundamentally > what you are dealing with is a full duplex communication link between > two processes. MathLink links function in a one-to-one paradigm, > thus one link can start and communicate with one process. Steve > Senior Network/System Protocol Developer > Wolfram Research Inc. > I have a question regarding multithreaded access to Mathematica via > MathLink. > > I'm developing a set of webservices for use with the Taverna Workbench > (taverna.sourceforge.net), a computational biology tool. These > webservices > call Mathematica to perform some computations. Obviously, each > webservice > invocation creates a new thread. As I'd like the Mathematica > environments > belonging to different threads to be completely separated one from > another, > I've implemented a mechanism which creates a new MathLink object for > every > thread. Unfortunately, this leads to serious problems, including an > application service crash, occuring from time to time. Apparently, > this is > some kind of a concurrent access problem - it doesn't happen when I > run only > one thread at a time, with subsequent invocations separated by a few > seconds. > > Perhaps there is a problem with my understanding of the relation > between > MathLink and Mathematica kernels? Is it true that each Mathlink object > creates a separate kernel process? If not, how to achieve such > behavior? Do > the MathLink native libraries support multithreading? > > Pawel Banasik === Subject: Re: Multiple threads using Mathlink Pawel, Generally speaking it is safe to use MathLink with threads. Here are the relevant stipulations: 1. Do not concurrently access the same MLENV object from more than one thread at a time. This means that you do not want multiple threads invoking any of the MLOpen* functions using the same MLENV object simultaneously. You will need to protect access to the MLENV object with a thread locking mechanism. 2. Do not concurrently access the same MLINK object from more than one thread at a time. You will need to protect access to the MLINK object with a thread locking mechanism. To answer your question about MathLink and Kernels, you should understand the following about MathLink. MathLink does not specifically create Kernel processes. MathLink creates a communication link between one process and another process. MathLink supports the ability to start the other process, but fundamentally what you are dealing with is a full duplex communication link between two processes. MathLink links function in a one-to-one paradigm, thus one link can start and communicate with one process. Steve Senior Network/System Protocol Developer Wolfram Research Inc. > I have a question regarding multithreaded access to Mathematica via > MathLink. I'm developing a set of webservices for use with the Taverna Workbench > (taverna.sourceforge.net), a computational biology tool. These > webservices > call Mathematica to perform some computations. Obviously, each > webservice > invocation creates a new thread. As I'd like the Mathematica > environments > belonging to different threads to be completely separated one from > another, > I've implemented a mechanism which creates a new MathLink object for > every > thread. Unfortunately, this leads to serious problems, including an > application service crash, occuring from time to time. Apparently, > this is > some kind of a concurrent access problem - it doesn't happen when I > run only > one thread at a time, with subsequent invocations separated by a few > seconds. Perhaps there is a problem with my understanding of the relation > between > MathLink and Mathematica kernels? Is it true that each Mathlink object > creates a separate kernel process? If not, how to achieve such > behavior? Do > the MathLink native libraries support multithreading? Pawel Banasik === Subject: Mathematica 6: No more memory available problem with ListDensityPlot I just purchased and installed Mathematica 6.0.2.1 for Windows (32 bit, March 13, 2008) on a computer running Windows Vista with 3GB of ram. I was rather surprised and disappointed that the following commands crashed Mathematica: In[1]:= d = RandomReal[{0, 1}, {78, 20003}]; In[2]:= Dimensions[d] Out[2]= {78, 20003} In[3]:= ListDensityPlot[d, AspectRatio -> 0.3, ColorFunction -> Rainbow] During evaluation of In[3]:= No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. ListPlot3D[d] also leads to the same error. The array to be plotted is not forbiddingly large, so I am very puzzled by the out of memory error. Is this a bug or do I need to set memory usage in some way to increase the memory limit? Your help is highly appreciated. Kezhao === Subject: MathLink Wrapper Hello All, I would like to know if there exists a C++ wrapper for MathLink. I know, the C wrapper can be used for this as well, but i would prefer the data to be stored in an object. Functionality I am looking for is: - When the object goes out of scope, the allocated memory is automatically freed using the appropriate Disown or Release functions - No frustrations on finding the right indices into arrays and built-in support for a transpose like function - Automatic interpolation when using floating point indices - Hiding of all kinds of variables unnessecary for the program - etc. I already started a package but i ran into some problems. I wanted to use a Template approach to type as little code as nessecary, but it is not quite working as i want it to work. Any suggestions are welcome. Gao Han _______________________________________________ === Subject: Redundant manipulate I have a manipulate like this: Manipulate[ Row[{a = , a, b = 2 a = , b = 2 a}] , {a, -10, 10, 1}, {b, -20, 20, 1}] If I change a, then b changes, but I also want that when I change b, === Subject: Re: Filtering a list of list for certain elements that are neighbours Hello Steven, I have a solution that you can generalize (and generalize to sublists greater than 3). Here is the short answer: neighboring[a_, b_, list_List] := Or @@ Map[MatchQ[#, Sort[{a, b}]] &, Map[Sort, Rest[Transpose[{list, RotateRight[list]}]]]] notNeighboring[a_, b_, list_List] := Not[neighboring[a, b, list]] Select[mylist, notNeighboring[a, b, #] &] (*returns {{a, c, b}, {b, c, a}} *) Select[mylist, neighboring[a, b, #] &] (*returns {{a, b, c}, {b, a, c}, {c, a, b}, {c, b, a}}*) The long answer is something like this: Transpose[{mylist, RotateRight[list]}] (*forms neigboring pairs*) result =Rest[Transpose[{mylist, RotateRight[list]}] ] (*discounts the end matching case*) (*Sort[] ensures that each pair is in a cannonical order*) Map[MatchQ[#,Sort[{a,b}]&,result] (*is a list of true or falses*) Thus, test = Table[RandomChoice[{aa, bb, cc, dd, ww, xx, yy, zz}, 5], {4}] test // MatrixForm (* returns for example {{dd, ww, cc, bb, bb}, {dd, xx, dd, cc, dd}, {zz, aa, aa, aa, cc}, {ww, ww, cc, bb, ww}} *) Select[test, neighboring[ww, cc, #] &] (* returns {{dd, ww, cc, bb, bb}, {ww, ww, cc, bb, ww}} *) > I have a list of lists mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} I want to filter out all lists that have a being a neighbor to b. I am looking for the following result. {{a,c,b},{b,c,a}} > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. -- W. Craig Carter === Subject: Re: Filtering a list of list for certain elements that >I have a list of lists mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} I want to filter out all lists that have a being a neighbor to b. I am looking for the following result. {{a,c,b},{b,c,a}} >For this toy example, I can probably do it by hand but my real problem >has 120 lists in a list. And I need to filter out various combination >of letters like s cannot be next to d , s cannot be next to j , c >cannot be next to j , h cannot be next to d and h cannot be next >to s. > > One possibility: In[267]:= DeleteCases[mylist, {___, PatternSequence[a, b] | PatternSequence[b, a], ___}] Out[267]= {{a, c, b}, {b, c, a}} Carl Woll Wolfram Research === Subject: Re: Filtering a list of list for certain elements that are neighbours Here's another possibility, which might give more flexibility (not sure). I couldn't figure out how to combine the or statements inside one Cases argument -- any clues? In[1011]:= Cases[Cases[mylist, Except[{___, a, b, ___}]], Except[{___, b, a, ___}]] Out[1011]= {{a, c, b}, {b, c, a}} C.O. > I have a list of lists mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} I want to filter out all lists that have a being a neighbor to b. I am looking for the following result. {{a,c,b},{b,c,a}} > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Filtering a list of list for certain elements that are neighbours Something along these lines might work (needs to be modified for sub-lists of different lengths, containing different symbols, etc.): In[987]:= mylist = {{a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}} Out[987]= {{a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}} In[998]:= (MatchQ[#1, {a, _, b}] || MatchQ[#1, {b, _, a}] & ) /@ mylist Out[998]= {False, True, False, True, False, False} In[999]:= Pick[mylist, %] Out[999]= {{a, c, b}, {b, c, a}} Hope that helps! C.O. > I have a list of lists mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} I want to filter out all lists that have a being a neighbor to b. I am looking for the following result. {{a,c,b},{b,c,a}} > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Filtering a list of list for certain elements that filter[x_List, n1_, n2_] := x /. {{___, n1, n2, ___} -> Sequence[], {___, n2, n1, ___} -> Sequence[]} mylist = {{a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}}; filter[mylist, a, b] {{a, c, b}, {b, c, a}} filter[mylist, a, c] {{a, b, c}, {c, b, a}} filter[mylist, b, c] {{b, a, c}, {c, a, b}} Bob Hanlon > I have a list of lists > > mylist={{a,b,c},{a,c,b},{b,a,c},{b,c,a},{c,a,b},{c,b,a}} > > I want to filter out all lists that have a being a neighbor to b. > > I am looking for the following result. > > {{a,c,b},{b,c,a}} > > > For this toy example, I can probably do it by hand but my real problem > has 120 lists in a list. And I need to filter out various combination > of letters like s cannot be next to d , s cannot be next to j , c > cannot be next to j , h cannot be next to d and h cannot be next > to s. > === Subject: Re: Mathematica 6: No more memory available problem with ListDensityPlot Hello Kezhao, All though the dataset might not be too large, a problem is the fact that the new version of ListDensityPlot in Mathematica (6.0) will make polygons of each of the pixels. Now for smaller images this already generates a lot of memory-consumption, but especially when your image is quite large it will eat away everything you've got in your memory. A better way to solve this problem would be to use ArrayPlot. This function has similar behavior as the old ListDensityPlot. The only difference is that it considers Arrays, and not Images. You can see this difference in the the way coordinates are used within the image. An image plotted with arrayplot appears to be upside down. To solve this, set the option DataReversed to True. Another solution would be to use the package MathVisionTools, which has a function called RasterPlot, which does the same thing as ArrayPlot, but is slightly faster. MathVisionTools is developed at the Technical University of Eindhoven (Netherlands) and can be downloaded from www.mathvisiontools.net (you will have to acquire a login code from the authors). RandomReal[{0,1},{78,20003}]; Dimensions[d] ArrayPlot[d,AspectRatio=C2=AE 0.3,ColorFunction=C2=AERainbow,DataReversed=C2=AETrue] HTH, Gao === Subject: Re: Possible Bug Report: CoefficientList The following will work and gives you a hint of what is going wrong: Table[Chances[numberDice, 6], {numberDice, 3, 5}] To avoid this, localize the scope of x. Chances[dice_, sides_] := Module[{x}, CoefficientList[Expand[(Sum[x^i, {i, sides}])^dice], x]] Table[Chances[x, 6], {x, 3, 5}] > Here is a function using CoefficientList[] that produces a list: > Chances[dice_, sides_] := CoefficientList[Expand[(Sum[x^i, {i, > sides}])^dice], x]; (* This works: *) > Chances[3, 6] > Chances[4,6] > Chances[5,6] (* This fails: *) > Table[ Chances[x, 6], {x, 3, 5}] CoefficientList::ivar: 1 is not a valid variable. > CoefficientList::ivar: 2 is not a valid variable. > CoefficientList::ivar: 3 is not a valid variable. > General::stop: Further output of CoefficientList::ivar will be > suppressed during this calculation. -- W. Craig Carter === Subject: Re: Possible Bug Report: CoefficientList > Here is a function using CoefficientList[] that produces a list: > Chances[dice_, sides_] := CoefficientList[Expand[(Sum[x^i, {i, > sides}])^dice], x]; (* This works: *) > Chances[3, 6] > Chances[4,6] > Chances[5,6] (* This fails: *) > Table[ Chances[x, 6], {x, 3, 5}] CoefficientList::ivar: 1 is not a valid variable. > CoefficientList::ivar: 2 is not a valid variable. > CoefficientList::ivar: 3 is not a valid variable. > General::stop: Further output of CoefficientList::ivar will be > suppressed during this calculation. > This is not a bug but a question of understanding the way Mathematica evaluates certain expressions; in particular case Table. Chances[dice_, sides_] := CoefficientList[Expand[Sum[x^i, {i, sides}]^dice], x]; Table[Evaluate[Chances[x, 6]], {x, 3, 5}] {{1302170688}, {888731494560000}, {2841261564746499300000}} Note the need for Evaluate. Andrzej Kozlowski PS. Did it not seem to you rather remarkable that a bug as basic as this would survive till version 6 of Mathematica? === Subject: Possible Bug Report: CoefficientList Here is a function using CoefficientList[] that produces a list: Chances[dice_, sides_] := CoefficientList[Expand[(Sum[x^i, {i, sides}])^dice], x]; (* This works: *) Chances[3, 6] Chances[4,6] Chances[5,6] (* This fails: *) Table[ Chances[x, 6], {x, 3, 5}] CoefficientList::ivar: 1 is not a valid variable. >> CoefficientList::ivar: 2 is not a valid variable. >> CoefficientList::ivar: 3 is not a valid variable. >> General::stop: Further output of CoefficientList::ivar will be suppressed during this calculation. >> === Subject: Re: FindRoot with a parameter Hello Aaron, Try this: aRoot[a_] := FindRoot[a*x == 1/2, {x, 1}] aRoot[.2] Plot[x /. aRoot[var], {var, .1, .5}] Craig How does one accomplish something like this: K[a_] = FindRoot[a*x == 1/2, {x, 1}] My intention is to plot how the zero of a function depends on > parameters. > Aaron -- W. Craig Carter === Subject: FindRoot with a parameter How does one accomplish something like this: K[a_] = FindRoot[a*x == 1/2, {x, 1}] My intention is to plot how the zero of a function depends on parameters. Aaron === Subject: Reduce and Indeterminate If a complex number appears in an inequality, Reduce issues a warning: Reduce[I > 0] This is useful (to avoid mistakes). But if Indeterminate appears in an inequality, Reduce will immediately say False: Reduce[Indeterminate > 0] While it is debatable what is the correct thing to do mathematically, I naively believe that it would be useful if Reduce at least gave a warning. It is true that it is not a good idea to manipulate expressions completely blindly (without paying attention to what they contain), but some functions may return very large expressions ... and the main advantage of using computers is that they can do large and tedious calculations quickly. What do MathGroup readers think about this? Here's a somewhat artificial example: In[1]:= Integrate[1/x, {x, a, b}] Out[1]= If[(-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0), -Log[a] + Log[b], Integrate[1/x, {x, a, b}, Assumptions -> ! ((-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0))]] In[2]:= First[%] Out[2]= (-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0) In[3]:= Reduce[% && (a | b) [Element] Reals] Out[3]= False Note that unlike Reduce, FullSimplify gives a warning: In[4]:= FullSimplify[%%, (a | b) [Element] Reals] During evaluation of In[4]:= FullSimplify::infd: Expression (-Im[b] Re[a]+Im[a] Re[b])/(Im[a]-Im[b]) simplified to Indeterminate. >> Out[4]= Indeterminate >= 0 && (Im[a/(-a + b)] != 0 || Re[a/(a - b)] >= 1 || (a/(a - b) != 0 && Re[a/(-a + b)] >= 0)) In[5]:= Reduce[Rest[%] && (a | b) [Element] Reals, {a, b}] Out[5]= (a < 0 && (b < a || a < b <= 0)) || (a > 0 && (0 <= b < a || b > a)) === Subject: Re: Reduce and Indeterminate Yes, a statement can be true, it can be false, or it might not make any sense. If it does not make sense, then considering it false is just as bad as considering it true. > Hi Szabolcs, > it would certainly be nice and consistent if a message about a invalid > comparison is produced. But we must ask if real harm can be produced from > this result and I think this is possible. Although all arthmetic operations > on Indeterminate give Indeterminate, it is not hard to come up with a simple > example where things go wrong: > f[x_]:=If[Reduce[x>0],pos,neg,ind]; > Therefore, I think a warning is a must. > Daniel > If a complex number appears in an inequality, Reduce issues a warning: > > Reduce[I > 0] > > This is useful (to avoid mistakes). But if Indeterminate appears in an > inequality, Reduce will immediately say False: > > Reduce[Indeterminate > 0] > > While it is debatable what is the correct thing to do mathematically, I > naively believe that it would be useful if Reduce at least gave a warning. > It is true that it is not a good idea to manipulate expressions completely > blindly (without paying attention to what they contain), but some functions > may return very large expressions ... and the main advantage of using > computers is that they can do large and tedious calculations quickly. > > What do MathGroup readers think about this? > > Here's a somewhat artificial example: > > In[1]:= Integrate[1/x, {x, a, b}] > > Out[1]= If[(-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0), -Log[a] + Log[b], > Integrate[1/x, {x, a, b}, > Assumptions -> ! ((-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0))]] > > In[2]:= First[%] > > Out[2]= (-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0) > > In[3]:= Reduce[% && (a | b) [Element] Reals] > > Out[3]= False > > Note that unlike Reduce, FullSimplify gives a warning: > > In[4]:= FullSimplify[%%, (a | b) [Element] Reals] > > During evaluation of In[4]:= FullSimplify::infd: Expression (-Im[b] > Re[a]+Im[a] Re[b])/(Im[a]-Im[b]) simplified to Indeterminate. > > Out[4]= Indeterminate >= > 0 && (Im[a/(-a + b)] != 0 || > Re[a/(a - b)] >= 1 || (a/(a - b) != 0 && Re[a/(-a + b)] >= 0)) > > In[5]:= Reduce[Rest[%] && (a | b) [Element] Reals, {a, b}] > > Out[5]= (a < 0 && (b < a || a < b <= 0)) || (a > 0 && (0 <= b < a || b > a)) > > 1 === Subject: Re: Reduce and Indeterminate Hi Szabolcs, it would certainly be nice and consistent if a message about a invalid comparison is produced. But we must ask if real harm can be produced from this result and I think this is possible. Although all arthmetic operations on Indeterminate give Indeterminate, it is not hard to come up with a simple example where things go wrong: f[x_]:=If[Reduce[x>0],pos,neg,ind]; Therefore, I think a warning is a must. Daniel > If a complex number appears in an inequality, Reduce issues a warning: > > Reduce[I > 0] > > This is useful (to avoid mistakes). But if Indeterminate appears in an > inequality, Reduce will immediately say False: > > Reduce[Indeterminate > 0] > > While it is debatable what is the correct thing to do mathematically, I > naively believe that it would be useful if Reduce at least gave a > warning. It is true that it is not a good idea to manipulate > expressions completely blindly (without paying attention to what they > contain), but some functions may return very large expressions ... and > the main advantage of using computers is that they can do large and > tedious calculations quickly. > > What do MathGroup readers think about this? > > Here's a somewhat artificial example: > > In[1]:= Integrate[1/x, {x, a, b}] > > Out[1]= If[(-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0), -Log[a] + Log[b], > Integrate[1/x, {x, a, b}, > Assumptions -> ! ((-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0))]] > > In[2]:= First[%] > > Out[2]= (-Im[b] Re[a] + Im[a] Re[b])/(Im[a] - Im[b]) >= > 0 && ((Re[a/(-a + b)] >= 0 && a/(-a + b) != 0) || > Re[a/(a - b)] >= 1 || Im[a/(-a + b)] != 0) > > In[3]:= Reduce[% && (a | b) [Element] Reals] > > Out[3]= False > > Note that unlike Reduce, FullSimplify gives a warning: > > In[4]:= FullSimplify[%%, (a | b) [Element] Reals] > > During evaluation of In[4]:= FullSimplify::infd: Expression (-Im[b] > Re[a]+Im[a] Re[b])/(Im[a]-Im[b]) simplified to Indeterminate. > > Out[4]= Indeterminate >= > 0 && (Im[a/(-a + b)] != 0 || > Re[a/(a - b)] >= 1 || (a/(a - b) != 0 && Re[a/(-a + b)] >= 0)) > > In[5]:= Reduce[Rest[%] && (a | b) [Element] Reals, {a, b}] > > Out[5]= (a < 0 && (b < a || a < b <= 0)) || (a 0 && (0 <= b < a || b > a)) > > === Subject: Re: Dynamic (more) Hi Luca, Dynamic does only evaluate its arguments for display. Convince yourself by: Dynamic[Print[asas];1] this gives a message Dynamic[Print[asas];1]; this gives no message therefore, the statement:q = p + 1 in Dynamic[q = p + 1]; is never executed. Further, q=1;Dynamic[q] does return Dynamic[q] and not 1. Try: q=1;Dynamic[q]//FullForm This is then further evaluated for display to give 1. hope this helps, Daniel > Hi! > > The following gives the (expected?) result 1: > > p = 0; > q = 0; > Dynamic[q = p + 1]; > Dynamic[q] > > This one gives {1, 1}, also as I would expect: > > DynamicModule[{p, q}, > p = 0; > q = 0; > {Dynamic[q = p + 1], > Dynamic[q]}] > > > Can anybody explain why the next gives 0? > > DynamicModule[{p, q}, > p = 0; > q = 0; > Dynamic[q = p + 1]; > Dynamic[q] > ] > > > Try the following pair too: > > DynamicModule[{p = 0, q}, {Dynamic[q = p + 1], Dynamic[q]}] > > DynamicModule[{p = 0, q}, Dynamic[q = p + 1]; Dynamic[q]] > > > > Luca > > === Subject: Re: EdgeRenderingFunction to produce edge labels in >DeleteCases[ >Thread[Range[Length[vertices]] -> (VertexLabel /. >vertices[[All,2 ;;]])], >_ -> VertexLabel >]; >I am just curious. Why the DeleteCases? In this simple example DeleteCases does nothing. In what kind of graph would it have a function? >with friendly greetings, >P_ter > > I wanted my code to handle the case where some or all vertex labels are unspecified. For example, without the DeleteCases you would obtain the following for Cycle[3]: g=Cycle[3] Graph[{{{1, 2}}, {{2, 3}}, {{1, 3}}}, {{{-0.4999999999999998, 0.8660254037844387}}, {{-0.5000000000000004, -0.8660254037844384}}, {{1., 0}}}] vertices = g[[2]]; Thread[Range[Length[vertices]] -> (VertexLabel /. vertices[[All, 2;;]])] {1->VertexLabel,2->VertexLabel,3->VertexLabel} Obviously, I don't want to perform these replacement rules on the list of vertices. Carl Woll Wolfram Research === Subject: Re: List re-arrangement question > I'm trying to do something like the following: > Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, > {b1, b2, b3}}}, {3, 1, 2}] > > expecting to get: > {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, > b3}}} > > However, it looks like Transpose doesn't work with ragged > arrays...so what is the recommended Mathematica style to do the above > transformation? Here are some possible ways: rag={{{a1,a2,a3},{a1},{a1,a2,a3}},{{b1,b2,b3},{b1},{b1,b2,b3}}}; Thread /@ Thread@rag MapThread[Thread[{##}] &, rag] MapThread[Transpose[{##}] &, rag] {{{a1,b1},{a2,b2},{a3,b3}},{{a1,b1}},{{a1,b1},{a2,b2},{a3,b3}}} {{{a1,b1},{a2,b2},{a3,b3}},{{a1,b1}},{{a1,b1},{a2,b2},{a3,b3}}} {{{a1,b1},{a2,b2},{a3,b3}},{{a1,b1}},{{a1,b1},{a2,b2},{a3,b3}}} -- === Subject: Re: List re-arrangement question >I'm trying to do something like the following: >Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, >{b1, b2, b3}}}, {3, 1, 2}] expecting to get: >{{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, >b3}}} However, it looks like Transpose doesn't work with ragged >arrays...so what is the recommended Mathematica style to do the above >transformation? > > In version 6, you can use Flatten: Flatten[ {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1},{b1, b2, b3}}}, {{2}, {3}, {1}} ] {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3, b3}}} Carl Woll Wolfram Research === Subject: Re: Coordinates of vertices Steve, For version 5.2 I could do the following. I assume this will also work for 5.1. <List,2]//Union) ScatterPlot3D[vtc] Maarten King, Peter R ial.ac.uk> cc: === Subject: RE: Coordinates of vertices 16/04/2008 16:00 I forgot to mention that I was using version 5.1 so I don't think I have access to that. My fault. Any other suggestions? > -----Original Message----- > Cc: mathgroup@smc.vnet.net === > Subject: Re: Coordinates of vertices > Peter, The vertices are in the graphics object. > Just use [[ ]] to get them out. tc=Truncate[PolyhedronData[Cube]] > vertices=ph[[1,1]]//N > ListPointPlot3D[vertices ,BoxRatios->Automatic] Hope this helps, maarten > King, Peter R > mathgroup@smc.vnet.net ial.ac.uk> cc: === > Subject: > Coordinates of vertices 16/04/2008 11:02 > I am sure I have done this before but I can't for the life of me > remember how, and I can't find it in the manual. Some help > would be much > appreciated. I'd like to find the coordinates of the vertices of a > truncated cube. Whilst Vertices[cube] correctly gives me the coordinates of a cube > Vertices[Truncate[Polyhedron[Cube]]] doesn't do what I want because > Truncate[Polyhedron[... is a graphics object not a polyhedron > object. So > can I convert the graphics object into a polyhedron and use > vertices, or > work out the vertices some other way (for a cube this is trivial to do > but for more complicated shapes this is much more tedious) > Peter > === Subject: Re: PolarPlot Hi Helen, just saw your reply. A coordinate system as you propose would assign more than one coordinate tuple to any point. Although I can see aplications in graphics (cycloids...), I do not think that this makes life easier for calculations. There are enough problems with unique maps, no need to make artificial ones. Daniel >> Hi Bruce, >> the radius in polar coordinates has to be real and positive. Therefore, > > Actually, no. In polar coordinates r is a *directed* distance, which may > be positive or negative. > >> r=Sqrt[Cos[phi]] can not be the correct formula, we would get imaginary >> values. To prevent this, we may e.g. write: r=Sqrt[Abs[Cos[phi]] what >> gives the plot you are looking for. >> hope this helps, Daniel > === Subject: Re: Directory of Mathematica Add-Ons > On Apr 13, 3:32 am, David Bailey > Contact the Wolfram Partnerships group... >>>http://partnerships.wolfram.com/ >> I don't think that would cover the many Mathematica packages - free and >> otherwise - published independently of Wolfram. > > Correct. it includes only those that have negotiated a partnership > agreement with Wolfram. What does that negotiation entail? -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u === Subject: Re: Select from list One possible way: In[46]:= Flatten@ Position[(MemberQ[#, 2] && MemberQ[#, 3] &) /@ ptX, True] Out[46]= {1, 2, 5} > I have a list like this: ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Select from list Hi Steve, simply use Position: Position[ptX,{___,2,___,3,___}|{___,3,___,2,___}] hope this helps, Daniel > I have a list like this: > > ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} > > and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: > > va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] > > which gives > > {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. > > (This doesn't work if va or vb is zero. That's ok.) > > Steve Gray > === Subject: Re: Select from list > I have a list like this: ptX= > {{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both > a 2 and a 3. In this example I would get {1,2,5}. The best solution I > have, with more generality, is: va = 2; > vb = 3; > za = Map[Cases[#1, va]&, ptX] /. {} -> {0} > zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} > Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} > {{3}, {3}, {0}, {3}, {3}} > {1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray Hi Steve, This approach is using a trick from Carl Woll to get non-zero positions in a list: NonzeroPositions[data_] := SparseArray[data] /. SparseArray[_, _, _, x_] :> Flatten[x[[2, 2]]] With that: findTwo[ptX_,va_,vb_]:= NonzeroPositions[Total[-Unitize[ptX - va] + 1, {2}]*Total[-Unitize[ptX - vb] + 1, {2}]] Here, -Unitize[ptX - va] + 1 replaces each occurance of va with 1, others are 0. Total[...,{2}] then adds up the values (i.e. you get 0 if va is not there) With list = Table[RandomSample[Range[9], 4], {10^6}]; We get In[10]:= Timing[findTwo[list, 2, 3] ;][[1]] Out[10]= 0.641 and some other approaches: In[11]:= Timing[ Flatten[Position[(Map[Cases[#1, 2] &, list] /. {} -> {0})*(Map[ Cases[#1, 3] &, list] /. {} -> {0}), {2*3}]];][[1]] Out[11]= 12.063 === Subject: Re: Select from list >I have a list like this: ptX= >{{1, 2, 3, 4}, {1, 2, 3, 5}, {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5}} and I want a list pointing to all the sublists above that contain both >a 2 and a 3. In this example I would get {1,2,5}. The best solution I >have, with more generality, is: va = 2; >vb = 3; >za = Map[Cases[#1, va]&, ptX] /. {} -> {0} >zb = Map[Cases[#1, vb]&, ptX] /. {} -> {0} >Flatten[Position[za*zb, {va*vb}]] which gives {{2}, {2}, {2}, {0}, {2}} >{{3}, {3}, {0}, {3}, {3}} >{1, 2, 5}. (This doesn't work if va or vb is zero. That's ok.) Steve Gray > > If you are interested in the fastest possible method for doing this, then I would do the following: First, a helper function: NonzeroPosition[data_]:=SparseArray[data] /. HoldPattern[SparseArray[__, {_,{_,x_},_}]]:>x Now, I'll use Clip to convert the input into a 1D list which is 1 if the a sublist has 2 and 0 if it doesn't, and similarly, for 3. twos = Unitize @ Total[ Clip[ ptX, {2,2}, {0,0}], {2}]; threes = Unitize @ Total[ Clip[ ptX, {3,3}, {0,0}], {2}]; both 2 and 3, and 0 otherwise: twothree = BitAnd[twos, threes]; To convert this 1D list into a list of positions, use NonzeroPosition: Flatten@NonzeroPosition[twothree]; Putting the above together, we have: Flatten @ NonzeroPosition @ BitAnd[ Unitize @ Total[ Clip[ ptX, {2,2}, {0,0}], {2}], Unitize @ Total[ Clip[ ptX, {3,3}, {0,0}], {2}] ] As an example, here is a list of length 10^6, and a timing example: data = RandomReal[5, {10^6, 5}]; Flatten @ NonzeroPosition @ BitAnd[ Unitize @ Total[ Clip[ data, {2,2}, {0,0}], {2}], Unitize @ Total[ Clip[ data, {3,3}, {0,0}], {2}] ]; //Timing {0.391,Null} Carl Woll Wolfram Research === Subject: Re: transformation rule (some [cut] : If you are not averse to using a global flag variable, you can do it as : follows. : Unprotect[Integrate]; : globalIntegrateFlag = True; : Integrate[args__] := Block[ : {globalIntegrateFlag=False, res}, : res = Integrate[args]; : If [FreeQ[res,EllipticF], res, HoldForm[Integrate[args]]] : Examples: : In[7]:= InputForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] : Out[7]//InputForm= HoldForm[Integrate[1/Sqrt[1 - m*Sin[phi]^2], phi]] : In[8]:= Integrate[1/Sqrt[1 - phi^2], phi] : Out[8]= ArcSin[phi] Tom. -- Tom Crane, Dept. Physics, Royal Holloway, University of London, Egham Hill, Egham, Surrey, TW20 0EX, England. Email: T.Crane at rhul dot ac dot uk Fax: +44 (0) 1784 472794 === Subject: Re: A Problem with Simplify > [...] >>Capitalization notwithstanding, it need not do any such thing. Integrate >>should give a generic result that behaves sensibly in the limit as a->1 > >>from whatever path is specified to Limit. This is similar to the > >>situation of > > >>In[18]:= InputForm[solns = x /. Solve[a*x^2 + x == 1, x]] >>Out[18]//InputForm= {(-1 - Sqrt[1 + 4*a])/(2*a), >> (-1 + Sqrt[1 + 4*a])/(2*a)} >>In[20]:= Limit[solns, a->0] >>Out[20]= {-Infinity, 1} >>Note that a blind substitution of a->0 will not give nice results. > > > Well. But how I can get the partial answer for the case a=1 with > Limit? > I have tried the foolowing code: > In[1]:= Limit[Integrate[Cos[a*z]/Sin[z],z],a->1] > Out[1]= [Infinity] > In[2]:= Limit[Integrate[Exp[a*z]*Sinh[z],z],a->1] > Out[2]= -[Infinity] > In[3]:= Limit[Integrate[Exp[z]*Sinh[a z],z],a->1] > Out[3]= E^z DirectedInfinity[E^(-I*Im[z])] > In[4]:= Limit[Integrate[Exp[(a-1)*x],x],a->1] > Out[4]= [Infinity] > All results are incorrect! > As I understand, Integrate does not give a generic result that behaves > sensibly in the limit as a->1! Sorry, I should have stated the situation more clearly. Yes, the antiderivatives you see have singularities at the parameter value in question (in all cases, when a is 1). Hence the results you show above. What I should have said is that one can get these obtain definite integrals a la Newton-Leibniz. Here is a standard simple example (modified slightly so as to have a->1 as the bad value). In[22]:= InputForm[i1 = Integrate[x^(-a),x]] Out[22]//InputForm= x^(1 - a)/(1 - a) Certainly it blows up as a->1. In[23]:= Limit[i1, a->1] Out[23]= -Infinity In[24]:= Limit[i1, a->1, Direction->1] Out[24]= Infinity But if we take a pair of values for x, say 2 and 3, to evaluate the definite integral, we in fact get the expected/desired logarithm result in the limit as a->1 (and independent of direction). In[27]:= InputForm[Limit[(i1/.x->3)-(i1/.x->2), a->1]] Out[27]//InputForm= Log[3/2] In[28]:= InputForm[Limit[(i1/.x->3)-(i1/.x->2), a->1, Direction->1]] Out[28]//InputForm= Log[3/2] To see that this really is reproducing the Fundamental Theorem of Calculus result (or at least doing a heckuva job to fool me), I'll show this instead as a definite integral from x0 to x. In[29]:= InputForm[Limit[i1 - (i1/.x->x0), a->1]] Out[29]//InputForm= Log[x] - Log[x0] I believe most of your examples will also behave fine when processed in this way. The Cos[a*z]/Sin[z] integrand might be an exception, but that indicates a limitation of Limit rather than a bug in Integrate. Depending on whether you give symbolic (z,z0) or exact numeric (3,2) input to Limit it either returns a complicated, but seemingly correct result, or else unevaluated. Daniel Lichtblau Wolfram Research === Subject: Re: A kernel, multiple notebooks, and Global? > I just wanted to mention this for the case that the OP asked this > question because he is trying to track down a problem related to this. to say that, unless you do something to deliberately manipulate contexts, a group of several simultaneously open notebooks can generally be used as if they were all parts of one big notebook with one overall global context. I didn't raise this question because of any problems I've encountered, but rather to flush out any problems that might arise in the packages without Packages approach that I'd like to start implementing for my particular Mathematica style of use (and it looks like there needn't be any such problems). This approach says, in essence, that I'm often working on 3 or 4 different physical problems, with the currently active projects changing from time to time (and old projects reviving from time to time). So, I'd like to keep all the materials associated with any given project -- notes, references, other memos, graphics and artwork, materials for publications resulting from the project == and, especially, all the Mathematica notebooks for that project -- in a separate master folder for that project. Moreover, I'd like to have all the Mathematica accessories -- like any packages or modules that do some major computational or display tasks for that project -- be right there, in that same subfolder with the primary notebooks for the project. A typical project -- a study of optical fiber propagation, let's say -- generally has a limited and consistent set or glossary of primary parameters and variables, set by the physics of the problem and the conventional notation in the field, and thus easy to remember. So, those quantities might as well all be global variables, used with the same meaning in all the project notebooks. Suppose then that we might at different times want to do calculations and display results on the modes of these optical fibers, or on their propagation characteristics, or their thermal behavior, or on a perturbation aspect of their behavior, or whatever. Rather than have one large, unwieldy notebook to do all these tasks, we might better have a number of separate much smaller task notebooks that are appropriately named (OpticalFiberModes.nb, etc) and that each do one limited part of the overall project -- and then one modules notebook (OpticalFiberModules.nb) that contains various common basic function and equation definitions for the project, plus individual display modules that create certain graphics or tabular displays of results, plus computational modules that do some complicated iterative numerical calculations -- in other words, any stuff that's lengthy or that might go into a Package in other circumstances. At a given time, one might have only one or two task notebooks open, plus the modules notebook (no real problem on a modern computer screen). If you're polishing up a certain graphic display routine, you edit this routine (probably as a Module[]) in the modules notebook; execute the modules notebook to refresh it (which is very fast, since this notebook does nothing but definitions); then jump to and run the task notebook that calls it, and back again if further editing is needed. What are the virtues of this approach? * Each task notebook can be comparatively short and free of long module definitions -- and thus can be navigated through quickly. * The modules notebook may be longer -- but if too long can be split into setup modules, display modules, computational modules. * **You never have to learn how to create/edit/modify/store away Packages! -- a great virtue, from what the questions I've seen repeatedly posed in this group. * Maybe more important, you don't have to **remember** any of this knowledge on how to work with Packages, nor do you have to remember how you defined a Package, or how to use it, over possibly long interim periods between active periods of a given project. All that knowledge is right there at hand, in the modules notebook, if you go back later to that project. * If you need one part of a project's modules notebook in another project, you just copy it over into that project's modules notebook. I'm not attacking Packages here. It's just that they're necessarily pretty sophisticated constructs (and have to be, if they're going to function in the full Mathematica environment). Hence they have a significant learning curve (and a significant 'evaporation rate' if one moves away from them for any period of time). The above approach seems like it may work for me, and give me one fewer messy construct in Mathematica to worry about. I don't see any serious downsides to this approach, although if any are pointed out by readers -- if any -- of this lengthy screed, I'll certainly have to learn from them. === Subject: Re: A kernel, multiple notebooks, and Global? > to say that, unless you do something to deliberately manipulate > contexts, a group of several simultaneously open notebooks can generally > be used as if they were all parts of one big notebook with one overall > global context. That's true AFAIK... > I didn't raise this question because of any problems I've encountered, > but rather to flush out any problems that might arise in the packages > ... other than that I think if you feel comfortable to work the way you have decribed there is technically no reason to not go for it. The advantage of packages comes in when you want/need encapsulate parts of your code so that different modules don't interfere. This could bite you if you are not careful, but you could cure that by using separate namespaces for them by using BeginPackage and EndPackage statements within your modules notebooks. This you could do without creating *.m files, which is probably what makes you think packages are complicated. Another aspect where package files make sense is when you want to give away code for others to use. If you don't plan to do that I don't see much further advantages for you to dive into packages, although they might be by far not as complicated as you think :-). Also it wouldn't be much work to convert your modules notebooks to genuine packages whenever you think it makes sense... hth, albert === Subject: Re: Any One have an idea? > Does anyone have any idea how to do or come up with the knight's tour problem. > Please give me some idea how to do it! (* Ver 6.01 *) Needs[Combinatorica`] g = KnightsTourGraph[8, 8]; path = Partition[HamiltonianCycle[g], 2, 1]; ShowGraph[Highlight[g, {path}, HighlightedEdgeColors -> Red]] - - HTH :>) Dana DeLouis ----- Original Message ----- === Subject: Any One have an idea? > > Does anyone have any idea how to do or come up with the knight's tour problem. Please give me some idea how to do it! > > The program is used a random number to select a starting position for the knight, and select the next position by selecting one of the available positions at random. When the knight reaches a position from which the number of the last possible available positions, the tour is finished. > > > Anna SJ. > === Subject: Fourier Trasform of a Bessel Function I try to make the following > FourierTransform[BesselJ[n, x], x, w]; > % /. n -> 0 I try > FourierTransform[BesselJ[0, x], x, w] I obtain another result. Why? Vlad === Subject: Re: Extending Integrate[] Hi Szabolcs, it looks like mathematica does not automatically distribute your rule over Plus. This comes a bit as a surprise. But you can teach it. If you additionally give the following rule: Integrate[a_+b_,x_]:=Integrate[a,x]+Integrate[b,x] then your example works. Of course you also need linearity. hope this helps, Daniel > According to the documentation it is possible to extend Integrate[] with > new rules: > > http://reference.wolfram.com/mathematica/tutorial/IntegralsThatCanAndCannotBe Done.html > > The specific example that is given is: > > Unprotect[Integrate] > > Integrate[Sin[Sin[a_. + b_. x_]], x_] := Jones[a, x]/b > > Now Integrate[Sin[Sin[3x]], x] will return Jones[0, x]/3 > > But if I try an integrand that is just slightly more complicated, > Mathematica