mm-1009 == The problem is that Mathematica does not export proprietary fonts. The solution depends on which Mathematica version you use. If you use Mathematica 4.0 or 4.1, you can download paul hinton's emmathfnt tool which manages inclusion of the fonts or you can configure ghostscript so that it puts Mathematica fonts into the graphics files. If you use 4.2.0, give it up, since font export isn't possible any more for the unexperienced user. This is because the emmathfnt tool does not work with the new font naming scheme. And neither the emmathfnt tool nor hinton who explained me the issues involved in a friendly and clear reply and referred me to the wolfram support team. Now I am waiting about one week for an answer from support@wolfram.com. If you are an experienced user (with a c compiler available), try to adapt the source code of emmathfnt and recompile it. I tried to do this but I failed, since I don't understand the font naming scheme and other details. If you use version 4.2.1, you can configure font export in the preferences dialog (or give it as an option). [Wolfram research seems to have realized *finally* that eps font export is an important feature demanded by many users. It is surprising that this process lasted some years, since EPS font export questions were a FAQ in MathGroup.] If you have premier service, simply obtain the updated version. Johannes Ludsteck Johannes Ludsteck Institut fuer Volkswirtschaftslehre Lehrstuhl Prof. Dr. Moeller Universitaet Regensburg Universitaetsstrasse 31 93053 Regensburg Hi Borut, This happens because the application you're inserting the graphic in dosen't understand where to find the particular font that Mathematica uses to render the characters ( & ) (& more besides ...). The cure is to embed the fonts in the graphic and you can use PJ Hinton's emmathfnt for this purpose. It's explained in reasonable detail at http://support.wolfram.com/mathematica/graphics/export/includefonts.html where you can find a link to the above program. Dave. Dr. David Annetts EM Modelling Analyst Australia David.Annetts@csiro.au Not a function call but a pattern with Head tree. Actually pretty basic Mathematica programming. Look up the Mathematica book under Head etc. Oh, by the way, one more thing. Knowing too much about other programming languages is actually a bit of a handicap as far as Mathematica is concerned, unless they are Lisp and Prolog (and even then you have to be pretty careful for things tend to be not quite what they seem...) Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ Steve, The header tree is not a function call but a wrapper for three objects. Is the following code as much of a mystery? pick3rdOnListOf3[List[_, _, third_]]:= third David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ means that I don't feel comfortable with the syntax. Is there somewhere in the Mathematica Book , or Help which discusses such arcana? -- STH Hatton's Law: There is only One inviolable Law. It's best to forget about function calls, think about expression evaluation. What I mean is Mathematica operates using a read-eval-print loop similarly to LISP (again, it really helps to have some exposure to LISP and Prolog when dealing with programming issues in Mathematica). So you enter an expression, Mathematica reads it, then passes it off to be evaluated then finally prints the resulting expression. Function call implies all sorts of arcana about putting references or copies of arguments on a call stack, jumping to a subroutine, restoring the call stack etc. that really isn't a factor in Mathematica. What does this have to do with the above expression? First let's get rid of the infix notation rightTree[tree[_,_,right_]]:=right is equivalent to SetDelayed[rightTree[tree[_,_,right_]],right] when the evaluator sees the SetDelayed it means means create a rule associating the DownValue of the first argument (held) with the second (also held). Since all the arguments are held there is no more evaluation. That's pretty simple, the real magic happens when you evaluate the expression rightTree[(some expression with head tree and three arguments, let's call it t for now)]. The evaluator searches the rule list of rightTree for the most specific match, since t has head tree (and assuming no more specific rule has been written) that's the rule that transforms the expression. That rule says that the third argument of the expression tree[_,_,_] is to be called right and that is the value of the expression rightTree[tree[_,_,right_]]. So the expression represented by the pattern right_ is passed to the evaluator. If that expression has no transformation rules associated with it then evaluation stops and that value is returned. This isn't really a question of syntax (since the LISP syntax looks something like (defun rightTree (tree) (car (nthcdr 2 tree))), I've omitted the type checking) it's a question of semantics. Incidentally I believe the Prolog syntax actually looks a lot more like the Mathematica, it's been a while since I dealt with Prolog but I think rightTree is isaTree(Node) :- atom(Node) isaTree([Left,Node,Right]) :- isatree(Left),atom(Node),isatree(Right). rightTree(tree) :- isaTree(tree),Right. This version has the type checking but a real Prolog programmer would probably use guards. This is all explained in section 2.5.4 of the Mathematica book. The key is to understand that at the most basic level all Mathematica does is take expressions, match them to rules (as expressed by patterns), apply the transformation and repeat the above process until no more transformations can be done. Ssezi Is it possible to get an analytical solution from 30 nonlinear equations(with 30 unknowns) solving by Mathematica? and how? Do you have any other recommendation for solving this kind of nonlinear equation? I argued over the more appropriate definition of (or algorithm for) the inverse cotangent function with someone, based on what math we have learned. (A) arccot x = Pi/2 - arctan x (B) arccot x = arctan 1/x My calculus book used the definition A when it talked about the derivatives of inverse trig functions. I think it said that definition B is also used in some situations, but I don't have the book now. It's obvious why my calculus book and most calculus study guides found on the Internet use the definition A--arccot would be continuous on its domain, and the complementary angle relationship is preserved. But Mathematica uses definition B, or a definition closer to B. See http://mathworld.wolfram.com/InverseCotangent.html So, is there any merit of definition B, besides convenience? Should we sacrifice the continuity of inverse cotangent just to satisfy the simple And this page http://mathworld.wolfram.com/InverseTrigonometricFunctions.html says the domain (my math teacher would say range) of ArcCot is (0, Pi/2) or (-Pi, -Pi/2). Where does that come from? It's not even consistent with the graph on Wolfram's own inverse cotangent page! The range for ArcCsc listed there is strange too. Also, Wolfram doesn't say that arccot is not differentiable because of discontinuity at x=0 when it lists the first derivative of ArcCot[z], while definition B would require that. Is it something in more advanced mathematics that I don't know yet? When I argued over the two definitions few weeks ago, my opinion was that definition B was acceptable, or even should be authoritative, because Wolfram and possibly other systems use it. But after my opponent pointed out that inconsistency, I didn't know what to say. Still, I believe there is a reason why definition B not only survived but also is used in these authoritative Yaohan Chen I am stuck with subsequent problem of FrontEnd programming. Perhaps, someone knows the solution. I would appreciate an answer : when a sequence of graphics cells for an animation is generated it would be favorable if all subsequent graphics cells would be grouped with respect to the top graphic cell (and not with respect to the preceding input cell evaluated). Then the graphics cells to be grouped should be closed so that only the top level graphics cell is visible and animation is started with double- clicking the top level graphics cell only. I found a partial solution which does the correct marking of the graphics cells being generated by a command such as CloseAniSequenceTest where the following code for manipulating the notebook is used : CloseAniSequenceTest := Module[ { }, SelectionMove[ EvaluationNotebook[ ], After, EvaluationCell ]; SelectionMove[ EvaluationNotebook[ ], Next, Cell ]; SelectionMove[ EvaluationNotebook[ ], Next, GeneratedCell ]; ????? FrontEndTokenExecute[OpenCloseGroup] ] But before using the final command FrontEndTokenExecute[OpenCloseGroup] there should be another command preceding that actually does the cell grouping wanted. The option does not perform the action I expected, and I could not find any hint in chapt. 2.10 of the Mathematica book for the solution. With the code above the graphics cells are marked correctly using the command CloseAniSequenceTest but no cell grouping as intended is done. Which additional Notebook command has to be inserted instead of ????. I think only one additional line of code is required to do this but I cannot not find the right answer. Robert Kragler --------------------------------------------------------------------- Prof. Dr. Robert Kragler Fachhochschule Ravensburg-Weingarten University of Applied Sciences FB Physikalische Technik / Rechenzentrum P.O.B 1241 , D-88241 Weingarten Germany E-Mail: kragler@rz.fh-weingarten.de HomePage: http://www.fh-weingarten.de/ --------------------------------------------------------------------- Robert, The following usually works. 1}, SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[OpenCloseGroup]; FrontEndTokenExecute[SelectionAnimate]; The last three statements can be pasted in using the DrawGraphics palette that comes with the DrawGraphics package at my web site. But sometimes the FrontEnd starts the animation before closing the group. So I have lately been using the following instead. 1}, SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[OpenCloseGroup]; Pause[0.01]; The Pause ensures that the cell group is closed before the animation starts. The last statement gives more control over the animation. The first parameter in FrontEnd`SelectionAnimate is the time in seconds to run the animation. The AnimationDisplayTime is the time in seconds to display each frame. The AnimationDirection can be Forward, Backward or ForwardBackward. The only problem I have with this is that Pause is supposed to work down to $TimeUnit, which on my Mathematica is 1/1000 (second). But I can never obtain a pause of less than a second. This is acceptable for the purpose, but it does seem to be a bug in Pause. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ be grouped should be closed so that only the top level graphics cell is visible and animation is started with double- clicking the top level graphics cell only. I found a partial solution which does the correct marking of the graphics cells being generated by a command such as CloseAniSequenceTest where the following code for manipulating the notebook is used : CloseAniSequenceTest := Module[ { }, SelectionMove[ EvaluationNotebook[ ], After, EvaluationCell ]; SelectionMove[ EvaluationNotebook[ ], Next, Cell ]; SelectionMove[ EvaluationNotebook[ ], Next, GeneratedCell ]; ????? FrontEndTokenExecute[OpenCloseGroup] ] But before using the final command FrontEndTokenExecute[OpenCloseGroup] there should be another command preceding that actually does the cell grouping wanted. The option does not perform the action I expected, and I could not find any hint in chapt. 2.10 of the Mathematica book for the solution. With the code above the graphics cells are marked correctly using the command CloseAniSequenceTest but no cell grouping as intended is done. Which additional Notebook command has to be inserted instead of ????. I think only one additional line of code is required to do this but I cannot not find the right answer. Robert Kragler --------------------------------------------------------------------- Prof. Dr. Robert Kragler Fachhochschule Ravensburg-Weingarten University of Applied Sciences FB Physikalische Technik / Rechenzentrum P.O.B 1241 , D-88241 Weingarten Germany E-Mail: kragler@rz.fh-weingarten.de HomePage: http://www.fh-weingarten.de/ --------------------------------------------------------------------- Robert, The exact commands that should be used depend upon whether you are using Automatic or Manual Grouping. For Automatic Grouping... Needs[Graphics`Animation`] 1}, SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[OpenCloseGroup]; Pause[0.01]; FrontEndTokenExecute[SelectionAnimate]; For Manual Grouping... 1}, SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute[CellGroup]; FrontEndTokenExecute[OpenCloseGroup]; Pause[0.01] FrontEndTokenExecute[SelectionAnimate]; I recommend AutomaticGrouping. I have never seen a good notebook done with manual grouping. Many people fall into using it but I have never seen a good reason for it and it usually results in long messy and unstructured notebooks that are difficult to add to or modify. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ be grouped should be closed so that only the top level graphics cell is visible and animation is started with double- clicking the top level graphics cell only. I found a partial solution which does the correct marking of the graphics cells being generated by a command such as CloseAniSequenceTest where the following code for manipulating the notebook is used : CloseAniSequenceTest := Module[ { }, SelectionMove[ EvaluationNotebook[ ], After, EvaluationCell ]; SelectionMove[ EvaluationNotebook[ ], Next, Cell ]; SelectionMove[ EvaluationNotebook[ ], Next, GeneratedCell ]; ????? FrontEndTokenExecute[OpenCloseGroup] ] But before using the final command FrontEndTokenExecute[OpenCloseGroup] there should be another command preceding that actually does the cell grouping wanted. The option does not perform the action I expected, and I could not find any hint in chapt. 2.10 of the Mathematica book for the solution. With the code above the graphics cells are marked correctly using the command CloseAniSequenceTest but no cell grouping as intended is done. Which additional Notebook command has to be inserted instead of ????. I think only one additional line of code is required to do this but I cannot not find the right answer. Robert Kragler --------------------------------------------------------------------- Prof. Dr. Robert Kragler Fachhochschule Ravensburg-Weingarten University of Applied Sciences FB Physikalische Technik / Rechenzentrum P.O.B 1241 , D-88241 Weingarten Germany E-Mail: kragler@rz.fh-weingarten.de HomePage: http://www.fh-weingarten.de/ --------------------------------------------------------------------- one possibility is: CloseAniSequenceTest := (SelectionMove[EvaluationNotebook[], After, EvaluationCell]; SelectionMove[EvaluationNotebook[], Next, Cell]; SelectionMove[ EvaluationNotebook[], Next, GeneratedCell]; FrontEndExecute[ {FrontEndToken[EvaluationNotebook[], OpenCloseGroup]}]) Needs[Graphics`Animation`]; Graphics`Animation`Animate[Plot[Sin[x*t], {x, -Pi, Pi}], {t, 1, 3, 1}]; CloseAniSequenceTest Rolf Mertig -- Mertig Consulting, Berlin, Germany Specialized Software & Training http://www.mertig.com I'm using DSolve to solve a differential equation, the result of which should be real but instead I get combinations of quantities involving the imaginary I (which I assume reduces to a real quantity). How do I get results that look DSolve[(-Derivative[2][t][r])*r^2 + M*Derivative[1][t][r]^3 == 0, t[r], r]] (I*M*Log[2*((-I)*Sqrt[2]*Sqrt[r*C[1]] + Sqrt[2*M - 2*r*C[1]])])/(Sqrt[2]*C[1]^(3/2))}, (I*M*Log[2*((-I)*Sqrt[2]*Sqrt[r*C[1]] + Sqrt[2*M - 2*r*C[1]])])/(Sqrt[2]*C[1]^(3/2))}} You can get an expression not involving explicit I by evaluating: ComplexExpand[t[r]/.DSolve[(-Derivative[ 2][t][r])*r^2+ This expression is very much more complicated than the one you go originally. What's more, it is only an illusion that it is real. Since the answer contains *arbitrary* constants it will be real for some choices of these and complex for others. All you are doing is giving yourself a certain psychological comfort without any mathematical benefit. The answer is not any more real than before but it is so much more complicated as to be nearly useless. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ In[13]:= ?Re Re[z] gives the real part of the complex number z. So )[DSolve[(-Derivative[2][t][r])*r^2 +M*Derivative[1][t][r]^3 == 0, t[r], r]]] Yas Hey, run the notebook on Mathematica 3.0, it crashes at the number of 3 000 000, whereas the idea is to visualize 3 000 000 000, I wanted to ask if someone with a newer version of Mathematica would like to run it for me with that number. Inge Jonckheere Research Associate KULeuven link to the notebooks: http://perswww.kuleuven.ac.be/~u0023176/ I have data of the form {x,y,z} which I would like to plot as a contour plot. I have read in the data as: and would now like to make a simple contour plot of the z values on my regularly spaced grid. The option ListContourPlot[t] doesn't do the job. Could you help? It says in the on-line help that ListContourPlot accepts an array of z values only. So you need to specify the ranges of x and y separately as the MeshRange option. Given, for example, the following result of ReadList, t = Flatten[ Table[{x, y, x x + y y}, {x, 2, 40, 2}, {y, 3, 30, 3}], 1] here is one way to do this: ts = Split[t,First[#1]==First[#2]&] mr = { {ts[[1,1,1]], ts[[-1,1,1]]}, {ts[[1,1,2]], ts[[1,-1,2]]} } ta=ts[[All,All,3]] Nadia, you'r not telling enough to give a straight answer. So I try to give some winded explanations on ListContourPlot. The First statement to be made can ListContourPlot[array] generates a contour plot from an array of height values That is: a two dimensional array of z-values! But you have got a linear List of {x,y,z} values, which has to be processed first. Before doing so let us consider an example: In[1]:= ContourPlot[Sin[x]*y,{x,0,Pi},{y,0,1}] This gives a CountourGraphics, which is the same as from ListContourPlot of the array In[2]:= ca = Table[Sin[x]*y, {y, 0, 1, 1/(15 - 1)}, {x, 0, Pi, Pi/(15 - 1)}]; (Here 15 is the default value of PlotPoints, we used.) Let us now assume we had got a corresponding list of {x,y,z} in an unspecified order: In[4]:= << DiscreteMath`Permutations` In[5]:= xyza = Table[{x, y, Sin[x]*y}, {y, 0, 1, 1/(15 - 1)}, {x, 0, Pi, Pi/(15 - 1)}]; In[6]:= rl = Flatten[xyza, 1][[RandomPermutation[15*15]]]; We bring this into appropriate order and extract the ranges, to... In[7]:= rls = Transpose[Partition[Sort[rl], 15]]; In[10]:= ListContourPlot[rls[[All,All,3]], rls[[All,1,2]][[{1, -1}]]}] ...reconstruct the very same ContourGraphics. If you happen to have your {x,y} pairs from a regular rectangular grid (and have them all) this procedure (In[7] and In[10]) should work (you only have to replace 15 with the correct number of PlotPoints (in x-direction), this may be automated of course)) . Else you may resort to a package from Tom Wickham-Jones, available from which extends ListContourPlot to allow plotting of irregular data: In[13]:= << ExtendGraphics`Contour` In[14]:= ListContourPlot[rl] ...gives you again the Contours, the ContourShading is missing however (TWJ lacked to implement it, and the world is waiting for someone to fill in the gap -- but it's not quite trivial however! (to find an efficient algorithm, but perhaps a slow one is better than none. I think in one of the earliest versions of Mathematica ContourPlot had been in an Add-on Package; if only someone will pass it over, I'd have a look at it).) Hope that helped. -- Hartmut Wolf I have the following data of the following form. {123-456-7899, John Smith,2223334444} How can I convert this to {123,456,7899, John,Smith,222,333,4444} and then to {1234567899johnsmith00000) 1. The - are removed 2. John Smith is concerted to lower case 3. The space between John and Smith is removed (ie john and smith is concatenated) 4. 123454567899johnsmith is padded right so the the total number of characters is 24. John G'day John, robust. Some notes and function foobar[file_String] follows; 1. Import the file as Word(s), not String 2. Replace the hyphen first to avoid confusion with minus 3. WRT l3 in foobar, first step takes 222333444 and inserts a comma and space in the 4th and 7th positions. Second step takes the remaining elements and makes a list. Then convert to string and then to expression. The space after the comma just got inserted as one character I think and you can't do much with that. 4. WRT to l4, get rid of the last three entries in the expression and add the zeroes, convert to string and replace the unwanted characters with wanted characters. In[1]:= foobar[file_String] := Module[{l1, l2, l3, l4}, l3 = {Drop[l2, -1], StringInsert[Last[l2], , , {4, 7}]} // ToString //ToExpression // Flatten; l4 = StringReplace[{Drop[l3, -3], {0, 0, 0, 0, 0}} // Flatten // ] In[2]:= foobar[~/Desktop/data.txt] Out[2]= {1234567899johnsmith00000} Yas John, Here is a long journey to your forms - I am assuming that we start with {123-456-7899,John Smith,2223334444} and I show input forms to distinguish strings. (fm1=MapAt[ StringReplace[ StringTake[ {-1}])//InputForm {123,456,7899, John,Smith, 222,333,4444} (fm2=StringJoin@@ PadRight[ Characters[ 0])//InputForm 1234567899johnsmith00000 -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 John, Here's one approach. I'm assuming that you're starting out with strings. data1 = {123-456-7899, John Smith, 2223334444}; {l1, l2, l3} = Characters /@ data1; data2 = Flatten[{ StringJoin[DeleteCases[#1,-]]&/@ Partition[l1, 4], StringJoin[#1]&@ l2[[Range@@ Prepend[Flatten[Position[l2, ]]-1, 1]]], StringJoin[#1]&@ l2[[Range@@ Append[Flatten[Position[l2, ]]+1, Length[l2]]]], StringJoin[#1]&/@ {l3[[{1,2,3}]], l3[[{4,5,6}]], l3[[{7,8,9,10}]]}}] {123, 456, 7899, John, Smith, 222, 333, 4444} data3 = StringJoin[data3 = StringJoin[data2[[Range[1,5]]]], StringJoin[Table[0, {24 - Length[Characters[data3]]}]]] 1234567899JohnSmith00000 --- Selwyn Hollis Did you have a look at operations on strings in the book (chapter 2.7.2 in version 4)? StringJoin, StringTake, StringReplace should get you going. eg (should do most of the work): YXXXYXXXaYYXXX Hope that helps. Marc -- Marc Heusser remove the obvious CHEERS and MERCIAL... from the reply address I'm asking a general question about whether excess data gets stored in a graphic when the data that's supplied to create the graphic has a lot more data than is needed to create the graphic. In particular: 1) If you make a ListPlot of a large array in which the majority of the array points fall way outside the boundaries of the explicitly given PlotRange, is all the unused data from the array still somehow stored in the graphic, either internally or when it's Exported as an EPS file? 2) Same question, except assuming you make a ListPlot of an array using about 6 points are needed to define the simple curve that shows up in the graphic. Are the 1000 points carried into the Exported EPS graphic, or only a much smaller number? ----- Power tends to corrupt. Absolute power corrupts absolutely. Lord Acton (1834-1902) (slightly modified) Dependence on advertising tends to corrupt. Total dependence on advertising corrupts totally. -- Modern equivalent. Hey, For anyone interested, I've done some handy work on Dungeons & Dragons dice math. This notebook creates a table, lookup function, and accompanying graph for any dice combination! Good for the over-zelous DM :) Just copy all the text below, and paste/interpret into mathematica -:|:- AngleWyrm Notebook[{ Cell[BoxData[{ StyleBox[Dice, Title], [IndentingNewLine], StyleBox[((Dungeons &) Dragons Dice Math), Subtitle]}], Input, Cell[BoxData[{ (The formula for any homgenous dice combination (is : (([Sum]+(i = 1)%sidesPerDie x^i))^numDice)), n, (The polynomial expansion of this expression lists the number of occurances of every possible combination . For instance, with 3 ( (d6)(:)))}], Text], Cell[CellGroupData[{ Cell[BoxData[ (TraditionalForm`Expand[(([Sum]+(i = 1)%6 x^i))^3])], Input, Cell[BoxData[ (x^3 + 3 x^4 + 6 x^5 + 10 x^6 + 15 x^7 + 21 x^8 + 25 x^9 + 27 x^10 + 27 x^11 + 25 x^12 + 21 x^13 + 15 x^14 + 10 x^15 + 6 x^16 + 3 x^17 + x^18)], Output] }, Open ]], Cell[< The power of x represents the die totals, and the coefficient lists the number of ways to achieve that total. Let us make a useful function to extract the coefficient of any dice roll, given the number of dice, and the sides per die: Cell[BoxData[ (Chances[ numDice_, sidesPerDie_, roll_] := Coefficient[(([Sum]+(i = 1)%sidesPerDie x^i))^numDice, x^roll])], Input], Cell[BoxData[ (For instance, with 3 d6, how many ways ((out of 6^3 = 216)) are there to get a ((13)(?)))], Text], Cell[CellGroupData[{ Cell[BoxData[ (Chances[3, 6, 13])], Input], Cell[BoxData[ (21)], Output] }, Open ]], Cell[TextData[{ Which can be confirmed by looking at the coefficient for , Cell[BoxData[ (TraditionalForm`x^13)]], in the polynomial expansion of , Cell[BoxData[ (TraditionalForm`((x + x^2 + x^3 + x^4 + x^5 + x^6))^3)]], above. Let us create a table, listing in order:nRoll, Chances, PercentageChance, and Frequency: }], Text], Cell[CellGroupData[{ Cell[BoxData[{ (die = 3; sides = 6;), [IndentingNewLine], (Table[ {i, Chances[die, sides, i], N[Chances[die, sides, i]/sides^die], sides^die/Chances[die, sides, i]}, {i, die, die[Times]sides}] // TableForm), [IndentingNewLine], (ListPlot[ Table[{i, Chances[die, sides, i]}, {i, die, die[Times]sides}]])}], Input], Cell[BoxData[ TagBox[GridBox[{ {3, 1, 0.004629629629629629`, 216}, {4, 3, 0.013888888888888888`, 72}, {5, 6, 0.027777777777777776`, 36}, {6, 10, 0.046296296296296294`, (108/5)}, {7, 15, 0.06944444444444445`, (72/5)}, {8, 21, 0.09722222222222222`, (72/7)}, {9, 25, 0.11574074074074074`, (216/25)}, {10, 27, 0.125`, 8}, {11, 27, 0.125`, 8}, {12, 25, 0.11574074074074074`, (216/25)}, {13, 21, 0.09722222222222222`, (72/7)}, {14, 15, 0.06944444444444445`, (72/5)}, {15, 10, 0.046296296296296294`, (108/5)}, {16, 6, 0.027777777777777776`, 36}, {17, 3, 0.013888888888888888`, 72}, {18, 1, 0.004629629629629629`, 216} }, (TableForm[ #]&)]], Output] }, Open ]] }, ] Mathematica 4.2 comes with seven font families, compared with five in the previous version. I am wondering if anyone knows how compatible these fonts are. The reason I ask is that I have a large number of graphics exported from Mathematica 4.1 under Mac OS 9, which now need to be incorporated into a (pdf)LaTeX document under Mac OS X. TeXShop/teTeX under Mac OS X chokes badly on the OS9 versions of the old font sets, but if I edit my LaTeX .map file to tell pdfLaTeX to embed Mathematica1.pfa instead of Math1(.pfa), everything seems to work. Ditto for Mathematica2/Math2. So I'm getting rhos and thetas where I should be getting rhos and thetas. This is a relief, but I'm wondering whether this trick will work in general for Mathematica graphics generated under from previous versions. What's in the new fonts that's not in the old fonts? The documentation just says New characters for double struck, script, and Gothic numbers, the planets, and musical notes. Does this mean that Math[Bold,Mono][1-5] = Mathematica[Bold,Mono][1-5]? Luci Ellis All of the old Math1-5 glyph mappings are precisely the same in Mathematica1-5 except for the double-struck and gothic characters (e.g. [DoubleStruckA], [GothicA]). The gothics moved into Mathematica6, and the double-strucks moved into Mathematica7. We needed to add fonts because the existing ones were running out of room. It made sense for these alphabetical sets to have mappings in fonts which mapped the alphanumeric glyphs to the expected positions, instead of having the alphanumeric glyphs sitting in oddball locations in Math5 like they were before (the script letters/numbers currently occupy the alphanumeric positions in Math5/Mathematica5).. In fact, much of Mathematica 5 is not presently different from the old Math5. If you look at the font, you'll still see many (but not all) double-strucks and gothics in it, but this will change in the future, and anything generated with 4.2 or later will always reference the Mathematica6/7 locations of these glyphs. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. particular needs, and I will update the rest of my LaTeX map file to reflect this. Luci Ellis http://www.verbeia.com/mathematica/ In order to get native rendering of MathML in Mozilla (and, I presume, in Netscape 7), one is supposed to download the fonts Math1, etc., from the Wolfram site (according to the link on the mozilla.org site). Does that imply that, for purposes of web-viewing MathML pages, one CANNOT yet dispense with those old Math1, etc., fonts even if one has installed the new Mathematica1, etc., fonts from Mathematica 4.2? -- 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 Amherst, MA 01375 In a word sir, yes. You are correct. -- STH Hatton's Law: There is only One inviolable Law. the SystemFiles/Include directory include already the map fiels for pdflatex and dvips. mostly unchanged but the Math5 font has the gothic, the double struck and the caligraphic alphabet inside. Now Mathematica5 hold the caligraphic characters, Mathematica6 the ghotic characters and Mathematica7 the double struck characters. And so your trick work for greek letters but not for ghotic, double struck and some of the caligraphic letters. Jens How do I extract the subset of answers in a list that are pure integers? As an example, in: Table[x/2, {x, 1, 5}] IntegerQ /@ % out: { 1/2, 1, 3/2, 2, 5/2 } { False, True, False, True, False } But I want to get a result of: { 1, 2 } -:?- AngleWyrm Angle Try something like Cases[Table[x/2, {x, 1, 5}], _Integer] Hope this helps. Mark Westwood Cases[%,_Integer] will return {1,2} Hi Mr.AngleWyrm You can use Select rather than mapping IntegerQ to list. Table[x/2, {x, 1, 5}] Select[%, IntegerQ] Here a easy way : In[7]:=DeleteCases[Table[x/2, {x, 1, 5}], x_ /; !IntegerQ[x]] Out[7]={1, 2} Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : mer., 20. novembre 2002 15:09 ?: mathgroup@smc.vnet.net Objet : Extracting a sub-list? How do I extract the subset of answers in a list that are pure integers? As an example, in: Table[x/2, {x, 1, 5}] IntegerQ /@ % out: { 1/2, 1, 3/2, 2, 5/2 } { False, True, False, True, False } But I want to get a result of: { 1, 2 } -:?- AngleWyrm In[4]:= Select[Table[x/2, {x, 1, 5}], IntegerQ[#1] & ] Out[4]= {1,2} Tomas Garza Mexico City ----- Original Message ----- Here a easy way : In[7]:=DeleteCases[Table[x/2, {x, 1, 5}], x_ /; !IntegerQ[x]] Out[7]={1, 2} Meilleures salutations Florian Jaccard -----Message d'origine----- Envoy.8e : mer., 20. novembre 2002 15:09 ?: mathgroup@smc.vnet.net Objet : Extracting a sub-list? How do I extract the subset of answers in a list that are pure integers? As an example, in: Table[x/2, {x, 1, 5}] IntegerQ /@ % out: { 1/2, 1, 3/2, 2, 5/2 } { False, True, False, True, False } But I want to get a result of: { 1, 2 } -:?- AngleWyrm Cases[Table[x/2, {x, 1, 5}], _Integer] Yas Several ways: lst = Table[x/2, {x, 1, 5}] {1/2, 1, 3/2, 2, 5/2} Select[lst, IntegerQ] {1, 2} Cases[lst, _Integer] {1, 2} Cases[lst, _?IntegerQ] {1, 2} Cases[lst, x_ /; IntegerQ[x]] {1, 2} Information on these techniques is available in the Help Browser under Select,Cases,Condition,PatternTest Also note DeleteCases. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 is there a function/command to find out what's the current notebook's path on the file system? for example, i opened an existing notebook from harddisk. I want to run a command in that notebook that gives me the full path of the notebook. Xah xah@xahlee.org http://xahlee.org/PageTwo_dir/more.html (Welcome back Xah!) ToFileName[FileName/.NotebookInformation[EvaluationNotebook[]]] will do what you want. Andrzej Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ Directory[ ] gives the current working directory. Well, Olly, here's another fine mess you've gotten us into... My global options are greyed out now, and my magnification is defaulting to 200%--Too big! How do I re-enable global options? As I am generating Mathematica images for inserting them into TeX, problems occur, like Helvetica) not taken into account, ... Can you direct me to any relevant material on the internet, book about ways to tackle this problems? Borut Levart look into the $TopDirectory/SystemFiles/IncludeFiles/TeX/texmf/doc/wolfram directory and read the msymdoc.pdf it include the instructions to make the Mathematica fonts work with TeX/Ghostscript .. Jens Note to Wolfram: As messages about this particular gotcha keep appearing and reappearing time after time after time (from me among others), perhaps it's time to implement a more long-term solution to this whole Operator Substitution hassle than just repeatedly replying to these newsgroup messages. It may be too late to change the default setting on the Operator Substitution option -- although my view would be that if a user wants, and Operator Substitution should definitely be automatically turned off. In addition: 1) Add at least a brief notation on this issue in the Help messages for TextStyle and other places, so useres will at least learn of the Operator Substitution problem and have a pointer to look for more detailed info. 2) *Much* upgraded documentation within the Help system of the (presently very mysterious) PrivateFont and OperatorSubstitution options Power tends to corrupt. Absolute power corrupts absolutely. Lord Acton (1834-1902) Dependence on advertising tends to corrupt. Total dependence on advertising corrupts totally. (today's equivalent) is Mathematica able to compute the following equation with products of veryvery-close-to-one values? f[R_, N_] := 1 - Exp[-N]*(1 - N/R)^(N - R - 1/2) f[2^63, 10000] After typing the equation, I always get under/overlows: General::ovfl: Overflow occurred in computation. General::unfl: Underflow occurred in computation. General::unfl: Underflow occurred in computation. General::unfl: Underflow occurred in computation. General::stop: Further output of !(General :: unfl) will be suppressed during this calculation. I also tried to increase the allowed exponent range with or to increase the precision with N[f[2^63, 10000], 100000] but it didn't help. Any suggestions? Kilian Sure. One way is to express the second argument as a real number with more than than the default precision: f[2^63, SetPrecision[10000,30]] I wish to display a given graphic via ListPlot at various scales, in a way such that the points and such stay the same absolute size. The following shows (at least on my wintel nt4) that the axis labels and lines stay the same absolute size, but the points vary according to the ImageSize. I'd like everything to stay the same size, just get more spread out. For bonus points, I'd like to know how to make everything scale by ImageSize, as well. I'm aware of AbsolutePointSize[], but don't see how to get that into ListPlot. << Graphics`Graphics` Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, Scan[ {1000, 500, 250, 125}]] Kirk, ListPlot is often more a hinderance than a help. You can just map Point onto your list of points. Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, Scan[ Show[Graphics[ {AbsolutePointSize[3], Point /@ d}], {1000, 500, 250, 125}]] There is a problem with axes tick labeling with the smallest size. The following scales everything except the axes styles with ImageSize. Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, Scan[ Show[Graphics[ {PointSize[0.01], Point /@ d}], {1000, 500, 250, 125}]] David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ << Graphics`Graphics` Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, Scan[ {1000, 500, 250, 125}]] Kirk, Using the PlotStyle-option with AbsolutePointSize[] will do it. The TextStyle-option let you control the fontsize of the text in the plot. Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, {1000, 500, 250, 125}]] Beware of the optical illusion that may result from the code above. Points in the smaller plots look larger compared with points in the larger plots /Helge Kirk, look at this: Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, {1000, 500, 250, 125}]] -- Hartmut Wolf Kirk, Use PlotStyle: Module[{d = Table[{i, Random[Real, {0, 10}]}, {i, 2000}]}, Scan[ ] &, {1000, 500, 250, 125} ] ] -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay@haystack.demon.co.uk Voice: +44 (0)116 271 4198 If one wants to control the size of a plot, it can be done with ImageSize as follows. plot1 = Plot[Sin[x], {x, 0, 2Pi}, But how does one control the positioning of the plot? Suppose I wanted to move the plot over to the left edge. Suppose I wanted to do this for just a specific plot in a notebook and not for all graphics output cells. How would I do that? (I know that I can use the mouse to move the plot over, but I want it to come up in the correct position in the first place.) Whereas ImageSize is an option that can be used in Graphics (although it appears to be transferred to the generated graphics cell as a Cell option) ImageMargins and ImageRegion can not be used in Graphics expressions. These seems inconsistent and I could find no examples of their use in the documentation. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ For univariate systems InequalitySolve uses Solve rather than CylindricalAlgebraicDecomposition. The problem in this example is that Solve gives a real solution in a form in which it is not recognized as real by inequalities. In[1]:= e = (-1)^(2/3)(1/2-Sqrt[5]/2)^(1/3); In[2]:= Im[e] Out[2]= 0 2/3 1 Sqrt[5] 1/3 Greater::nord: Invalid comparison with (-1) (- - -------) attempted. 2 2 2/3 1 Sqrt[5] 1/3 2 2 One can fix this problem by loading a file InequalitySolveFix.m containing the following code. (It redefines Solve when called from inside InequalitySolve code.) (* ------- Begin InequalitySolveFix.m ------- *) Unprotect[Algebra`InequalitySolve`InequalitySolve]; Clear[Algebra`InequalitySolve`InequalitySolve]; InequalitySolve`BugFlag=False; Algebra`InequalitySolve`InequalitySolve[ineqs_, vars_] /; Not[InequalitySolve`BugFlag] := Block[{InequalitySolve`BugFlag=True}, Algebra`InequalitySolve`InequalitySolve[ineqs, vars]] Unprotect[{Solve}]; Solve[a__]/;InequalitySolve`BugFlag := Block[{InequalitySolve`BugFlag=False}, RootReduce[Solve[a]]] Protect[{Solve}]; < 0, > PlotPoints -> 20, Mesh -> Full, NormalsFunction -> None] > This gives a version 5-like plot but the white lines of spurious polygons, remain visible when exported as pdf. One solution to this problem can be found in http://library.wolfram.com/infocenter/MathSource/7029/ by Will Robertson. Saving as print selection PDF, or using bitmap, also remove these lines. Is Wolfram Research planing to solve this issue in a future upgrade? A. Verga. Aix-Marseille Universite === Subject: debugging code that contains compile I have some code where I define some functions using compile to speed them up. Code runs fine without compile, but when using compile I get some errors. So what I wanna do now is of course analyze where these errors come from. Unfortunately Mathematica Frontend just tells me the kind of error and what variables are involved. Due to my code being pretty large, it's no easy task to figure out where these errors in deed appear. My question now is: Can I investigate these errors any closer? (using Mathematica or Wolfram Workbench) Here is what I tried so far: 1)Modify the error messages by setting $MessagePrePrint to append the $Line. But as you might guess my function is called somewhere in the frontend and exactly the line of that call is returned by $Line not where the error really appears in the code! 2) Of course I used the debugger and that's why I mentioned that I use the Compile Command. Because for usual code using the debugger would of course show me where the error appears. But when the debugger reaches the Compile Command neither the stack view nor the code view show me where code is currently evaluated. I just at some point get the error message on the stack. So, is there any way to get one of the above methods to work or should I use a different approach? Software available: Mathematica 6 Wolfram Workbench === Subject: Re: minimize with complex numbers > hi , > when i use minimize command with real numbers i get > the required answer but > with complex number it doesnt give me any answer or > r error Syntax::sntxb : Expression cannot begin with (1+1 i) > ` x[1]+(1-1 i) ` x[2]. > Syntax::tsntxi : (1+1 i) ` x[1] is incomplete; more > input is needed. > Syntax::sntxi : Incomplete expression; more input is > needed. > My minimize expression is ((1+1i)*x[1] +(1-1i)*x[2] )^2 +(x[1]+x[2])^2 in methamatica it becomes Minimize[{( x[1]+x[2])2 > +((1+1i)x[1]+(1-1 i)x[2])2},{x[1],x[2]}] > i want my answer to be in complex number come > somebody tell me where i am wrong The complex number field can not be ordered ; so minimization of a complex expression does not make sense. Maybe you want to minimize the norm of a complex expression ? Best wishes Torsten. === Subject: Re: minimize with complex numbers Well, minimize doesn't work with complex arguments. And that is in no way a restriction, because seen from a mathematical standpoint searching for a minimum in a complex set doesn't make any sense without further specification. I could go into detail about that, but this may be confusing for you, so let me just mention the main idea: To explain what is a minimum you need to have a smaller than (<) relation. So one has to define that for a set of complex numbers. Consider the following example of two complex numbers z1=1+2i and z2=2+0.5i. Which one would you say is greater than the other one? Hard to say that here, right? So what usually appears in applications (and that's something you might want to take in account) is that you compare complex numbers by their absolute value respectively their norm. Usually one takes the euclidean norm |.|, which is defined by |z|=sqrt(a^2+b^2) where z=a+ib. So the norm delivers a real number (a norm always does) and your are in your first case of comparing real numbers. Hope this helps understanding the problem. === Subject: Re: Finding only final values in NDSolve Zakseidov, How about something like this: First[{y[3], y'[3]} /. NDSolve[{y''[t] + y[t] == 0, y[0] == 1, y'[0] == -1}, y, {t, 0, 3}]] Kevin > 1. I use NDSolve for integration from some t0 to some tf, but I'm > interested only in FINAL VALUES y(tf),y'(tf). > How to do it (I mean: avoiding InterpolatingFunction and saving all > intermediate values)? > 2. I use WorkingPrecision -> 32(or larger). Final values y(tf),y'(tf) > are of lesser Precision than 32D so i can't use them directly for > further integrations. I do some manupulations to take more artificial > digits... > But what's the best way for doing it automatically not manually? > 3. In other words: I need only values of y(t), y'(t) in fixed t_i with > fixed interval d. > How to do it using NDSolve economically without InterpolatingFunction > (which I guess takes a lot of time if MaxSteps -> 10^8(or larger))? > zakseidov > === Subject: Re: ListLinePlot and Tooltip > Start with a simple plot: (1) ListLinePlot[{{{1, 1}, {2, 2}}}] (We get the expected result.) Now just add tooltips to the two points of the curve: (2) ListLinePlot[{{Tooltip[{1, 1}], Tooltip[{2, 2}]}}] (A pair of > axes are drawn but no curve.) Next add a third point to the list, also with Tooltip: (3) ListLinePlot[{{Tooltip[{1, 1}], Tooltip[{2, 2}], > Tooltip[{3, 2.5}]}}] (Now we get the curve drawn correctly.) Next take (1) and add a second curve: (4) ListLinePlot[{{{1, 1}, {2, 2}}, {{1, 1.5}, {2, 2.5}}}] (We get > both curves drawn as expected.) Next add Tooltips to the points on the second curve: (5) ListLinePlot[{{{1, 1}, {2, 2}}, {Tooltip[{1, 1.5}], > Tooltip[{2, 2.5}]}}] (Neither curve is drawn.) In these examples, whenever we have a curve with exactly two points > and Tooltips (see (2) and (5)), ListLinePlot does not draw the curves. > Removing the Tooltips (see (1) and (4)) or just adding a third point > (see (3)) restores the drawing of the curves. Can anyone explain why? A short explanation could be, A bug. > Mathematica 6.0.1 on OS10.5.2 Same behavior on my system 64-bit Intel Core 2 Duo Mac OS X Leopard 1.5.4 Mathematica 6.0.3. === Subject: Re: Making parts of formulae blinking thank you for your helpful comment. I agree that it is an important problem, especially if one wants to use Mathematica for giving talks on subjects of general interest, rather than only on Mathematica itself. The question we discuss is thus, in no case a disposable one. You are right, it is much easier, if one can avoid going to graphics, and I like your approach much. However, I still have an unsolved question concerning using the operator Accentuate[]. In my previous letter for the sake of shortness I have given an oversimplified expression AB+xy. The procedure Accentuate works perfectly on it. In reality however, one often needs to accentuate parts of an expression that have different lengths. Further, often there are more than two parts of the same expression that should be accentuated separately. In this case a straightforward use of the operator Accentuate results in a change of the order of the parts of the expression. For example, I need to discuss four parts of the same expression. They should be discussed separately from one another. Here they are: a1 = Text[Style[!(*SuperscriptBox[[Alpha][Eta], RowBox[{ , 2}]])+!(*SuperscriptBox[[Beta][Eta], RowBox[{ , 4}]]), FontFamily -> Times New Roman, 22, Italic]] a2 = Text[ Style[g([CapitalDelta][Eta]!(*SuperscriptBox[), 2]), FontFamily -> Times New Roman, 22, Italic]] a3 = Text[ Style[!(*FractionBox[1, 2])!(*SubscriptBox[C, ijkl])!(*SubscriptBox[[Epsilon], ij])!(*SubscriptBox[[Epsilon], kl]), FontFamily -> Times New Roman, 22, Italic]] a4 = Text[Style[!(*SuperscriptBox[A[Eta], RowBox[{ , 2}]])!(*SubscriptBox[[Epsilon], ii]), Times New Roman, 22, Italic]] These illustrate a problem from the area of phase transitions. Applying the operator Accentuate to these parts in a direct way: expression=Accentuate[a1]+Accentuate[a2]+Accentuate[a3]+Accentuate[a4] or like this a1 + a2 + a3 + a4; Accentuate /@ % I get a nicely working output, but no control on the order in which the parts appear. This may make my message obscure to the audience and therefore, should be changed. Could you give a hint of how this problem could be fixed? Alexei, This is a very interesting question because in the larger sense it relates to how one manipulates expressions and presents concepts, in a clear and elegant manner, to a reader of a notebook. I think this is somewhat an open question and we have to learn how to do it. So my answer is not going to be totally responsive and I think that your first approach is not the best because it draws you off into computer science and away from the math and physics. Also, a blinking graphical display may serve a tutorial purpose but it is a dead-end expression that can't be further used. (Also I don't know right off how to get some blinking in, but I'm certain some member of MathGroup will do it.) So instead of going to graphics, which in general might be quite complicated to get all the formatting correct, let's try to stay with regular expressions that can be accentuated with EventHandlers and then returned again to regular expressions. Here are two routines to help do that: Accentuate[expr_] := Module[{col = Black, size = Medium}, EventHandler[ Style[expr, FontColor -> Dynamic[col], FontSize -> Dynamic[size]], {MouseClicked :> (col = col /. {Black -> Red, Red -> Black}; size = size /. {Large -> Medium, Medium -> Large})}]] ClearAccentuate[expr_] := expr /. HoldPattern[EventHandler[Style[subexpr_, __], __]] -> subexpr Now we can use these on your example and then return to a normal expression. Or we could have just saved the initial expression. In any case, we don't have to go to graphics. A B + x y Accentuate /@ % % // ClearAccentuate // InputForm -- Alexei Boulbitch, Dr., Habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: mixed partial derivatives X[-3, v] == X[3, v] will not work with mixed derivatives aspecial on the interval u in [0,3] and not u in [-3,3] and your equation is singular. Jens > When mixed derivatives are not allowed, what is the fix? TIA p=D[X[u,v],u]; q=D[X[u,v],v]; r =D[X[u,v],u,u]; s=D[X[u,v],u,v]; > t=D[X[u,v],v,v]; > GC[u_,v_] = (r t - s^2)/(1+p^2 + q^2)^2 > NDSolve[{GC[u,v]== 1, X[u, 0] == Cosh[u], Derivative[0,1][X][u, 0] == > 0, > X[-3, v] == X[3, v]},X[u,v], {u,0,3},{v,0,3}] Narasimham > === Subject: Re: mixed partial derivatives > When mixed derivatives are not allowed, what is the fix? TIA p=D[X[u,v],u]; q=D[X[u,v],v]; r =D[X[u,v],u,u]; s=D[X[u,v],u,v]; > t=D[X[u,v],v,v]; > GC[u_,v_] = (r t - s^2)/(1+p^2 + q^2)^2 > NDSolve[{GC[u,v]== 1, X[u, 0] == Cosh[u], Derivative[0,1][X][u, 0] == > 0, > X[-3, v] == X[3, v]},X[u,v], {u,0,3},{v,0,3}] Is your question related to the following messages I got on my system or it is something completely different? In[1]:= p = D[X[u, v], u]; q = D[X[u, v], v]; r = D[X[u, v], u, u]; s = D[X[u, v], u, v]; t = D[X[u, v], v, v]; GC[u_, v_] = (r t - s^2)/(1 + p^2 + q^2)^2 NDSolve[ {GC[u, v] == 1, X[u, 0] == Cosh[u], Derivative[0, 1][X][u, 0] == 0, X[-3, v] == X[3, v]}, X[u, v], {u, 0, 3}, {v, 0, 3}] Out[3]= (1,1) 2 (0,2) (2,0) -X [u, v] + X [u, v] X [u, v] ------------------------------------------ (0,1) 2 (1,0) 2 2 (1 + X [u, v] + X [u, v] ) During evaluation of In[1]:= NDSolve`FiniteDifferenceDerivative::ordred: There are insufficient points in dimension 1 to achieve the requested approximation order. Order will be reduced to 1. During evaluation of In[1]:= NDSolve`FiniteDifferenceDerivative::conw: There are insufficient points in dimension 1 to generate consistent finite different weights. Out[4]= (1,1) 2 (0,2) (2,0) -X [u, v] + X [u, v] X [u, v] NDSolve[{------------------------------------------ == 1, (0,1) 2 (1,0) 2 2 (1 + X [u, v] + X [u, v] ) (0,1) X[u, 0] == Cosh[u], X [u, 0] == 0, X[-3, v] == X[3, v]}, X[u, v], {u, 0, 3}, {v, 0, 3}] === Subject: minimize with complex numbers hi i have transformed my complex valued problem into real value problem as below but still when i try to MInimize it i didnt get a solution (a1+b1i)x[1] +(a2+b2i) x[2]=0 (c1+d1i)x[1] +(c2+d2i) x[2]=0 a1 u1 - b1 v1 + a2 u2 - b2 v2 = 0 c1 u1 - d1 v1 + c2 u2 - d2 v2 = 0 a1 v1 + b1 u1 + a2 v2 + b2 u2 = 0 c1 v1 + d1 u1 + c2 v2 + d2 u2 = 0, Minimize[{(0.83 u1+0.4 u2-0.25 u3+3 u4+0.16 v1+0.6 v2+1.25 v3-2 v4)2+(2 u1-0.16 u2-0.6 u3-1.25 u4+3 v1+0.83 v2+0.4 v3-0.25 v4)2+(0.4 u1-0.25 u2+3 u3+0.83 u4+0.6 v1+1.25 v2-2 v3+0.16 v4)2+(-1.25 u1+2 u2-0.16 u3-0.6 u4-0.25 v1+3 v2+0.83 v3+0.4 v4)2+(-0.25 u1+3 u2+0.83 u3+0.4 u4+1.25 v1-2 v2+0.16 v3+0.6 v4)2+(-0.6 u1-1.25 u2+2 u3-0.16 u4+0.4 v1-0.25 v2+3 v3+0.83 v4)2+(3 u1+0.83 u2+0.4 u3-0.25 u4-2 v1+0.16 v2+0.6 v3+1.25 v4)2+(-0.16 u1-0.6 u2-1.25 u3+2 u4+0.83 v1+0.4 v2-0.25 v3+3 v4)2},{u1>0,v1>0,u2>0,v2>0,u3>0,v3>0,u4>0,v4>0},{u1,v1,u2,v2,u3,v3,u4,v4}] The error is Minimize::vdom : Variable domain {u1,v1,u2,v2,u3,v3,u4,v4} should be either Reals or Integers. i didnt understand it can anybody tell me what should i do . === Subject: Re: Importing Mathematica objects you can only Get[] what you have Put[] before. Import[] must be nonsense because Mathematica don't need to import its own expressions. Jens I saved a Mathematica expression (InterpolatingFunction object) in a file: > Save[file,expression]; However, when I want to load the expression again, it doesnt't work. I > do not even get an error. I tried > Get[file] > Import[file] The file is rather large (180 MB). Might that be a problem. Any idea? > joerg > === Subject: Re: Importing Mathematica objects I saved a Mathematica expression (InterpolatingFunction object) in a file: > Save[file,expression]; However, when I want to load the expression again, it doesnt't work. I > do not even get an error. I tried > Get[file] > Import[file] The file is rather large (180 MB). Might that be a problem. Any idea? Use *DumpSave* as in the following example: s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}] Plot[Evaluate[y[x] /. s], {x, 0, 30}, PlotRange -> All] DumpSave[s.mx, s] Clear[s] Plot[Evaluate[y[x] /. s], {x, 0, 30}, PlotRange -> All] << s.mx Plot[Evaluate[y[x] /. s], {x, 0, 30}, PlotRange -> All] === Subject: Re: Importing Mathematica objects I saved a Mathematica expression (InterpolatingFunction object) in a file: > Save[file,expression]; However, when I want to load the expression again, it doesnt't work. I > do not even get an error. I tried > Get[file] > Import[file] The file is rather large (180 MB). Might that be a problem. Any idea? > joerg > Can you post a small example with all the relevant code. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Importing Mathematica objects >I saved a Mathematica expression (InterpolatingFunction object) in a >file: Save[file,expression]; >However, when I want to load the expression again, it doesnt't work. >I do not even get an error. I tried Get[file] Import[file] Use Get not Import >The file is rather large (180 MB). Might that be a problem. This should not be an issue. When you say Get[file] doesn't work, what do you mean? Do you mean there is no apparent output? If so, that is what is supposed to happen. Start with a fresh session and do the following: a = 5; f[x_]:=x^2 Save[test,{a,f}] Note that ?Global`* shows both a and f exist Now do Remove[a,f]; ?Global`* you should see both a and f are gone =46inally, do Get[test] ?Global`* you should see both a and f are back and behave as expected. If the above doesn't work in a fresh session, then there is a problem. === Subject: DO loop I am new with mathematica and I have the following problem: I want to repeat a procedure that involves a two main functions for a precise number of times. Which would be the format of a do loop in mathematica in order to calculate them and write the results of each iteration to a matrix? In order to be more exact I want to solve the following : I have a function........ Vz[r_]=1/r intE = EA + e ........................which I solve and the real solutions are the intergartion limits at the intergral that follows Solve[Vz[r] == intE, r] olok = NIntegrate[f1[r], {r, Ra, Rb}] // N; I would like to repeat this procure for several e values and write a matrix. I future I would like to include a second function in the do loop which is also a function of e. Maria === Subject: Re: fractional derivative (order t) of (Log[x])^n and Log[Log[x]] etc.? If you go to the link you mention, and then click on the formula you're interested in, you should be taken to a page which contains the InputForm of that formula. For example, I clicked on the 6th one down, which takes me to http://functions.wolfram.com/ElementaryFunctions/Log/20/03/0006/. This page contains the InputForm of that formula, which I can then paste into Mathematica: D[Log[z]^n, {z, [Alpha]}] == FDLogConstant[z, 0, n, [Alpha]]/z^[Alpha] /; Element[n, Integers] && n > 0 . Hope that helps! C.O. > I'd be grateful if someone could tell me a nicely computable formula > for the fractional derivative w.r.t. x (order t) of (Log[x])^n, where > n is a positive integer. (Ideally I would like a formula where t can be any real number, but > one for t>=0 would be most helpful!) The second thing I am seeking is a formula for the fractional > derivative w.r.t. x (order t) of Log[Log[x]], Log[Log[Log[x]]], etc., > and more generally, of Log[...[Log[Log[x]]...], where there are n > nested log functions, where n is of course a positive integer. (I have visited: > , and > there is a formula there for the t-th (fractional) derivative of > Log[x]^n, but I do not understand how to input it!! Basically I need formulae for the order-t fractional derivatives of > (Log[x])^n and of Log[Log[x]], Log[Log[Log[x]]] (and generally with n > nested logs), which I can use for variable x and given values of n and > t, and can also evaluate at given values of x. > Michael -- 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: Trouble Implementing Schelling's Segregation Model Hi All, I'm trying to write a demonstration for a class on Schelling's 1978 segregation model. An implementation exists from Gaylord and D'Andria, 1998, but it's not playing ball with Mathematica 6.0. If anyone wants (*Schelling Model (1978, 147 - 153) Demonstration Model uses a square n*n lattice with wraparound boundary conditions with a population density p of individuals occupying lattice sites and the rest empty. System evolves over t time steps. *) neighborhood[n_, p_, v_, w_, t_] := Module[{walk, movestay, society, RND, Moore, GN} , RND := RandomInteger[ {1, 4}] society := Table[Floor[p + RandomInteger[]], {n}, {n}] /. 1 :> {RND, Table[Integer, {1, w}], {v}}; movestay[0, __] := 0; movestay[{a_, b_}, res__] := {a* Round[1 - Count[Map[ Count[b - #[[2]], 0] &, {res}/.0 -> {0, 0}], _?{# >= v/2 &}]/8.] , b }; (*Walk Rules*) Moore[func_, lat_] := MapThread[func, Map[RotateRight[lat, #] &, {{0, 0}, {1, 0}, {0, -1}, {-1, 0}, {0, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1}} , 2]; GN[func_, lat_] := MapThread[func, Map[RotateRight[lat, #] &, {{0, 0}, {1, 0}, {0, -1}, {-1, 0}, {0, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1}, {2, 0}, {0, -2}, {-2, 0}, {0, 2}}], 2]; NestList[GN[walk, Moore[movestay, #]] &, society, t]]] SeedRandom[9] results = neighborhood[20, 0.6, 1, 2, 500] Show[GraphicsArray[ Map[Show[Graphics[ Raster[# /. {0 -> RGBColor[0.7, 0.7, 0.7], {_, {1}} -> RGBColor[0, 1, 0], {_, {2}} -> RGBColor[0, 0, 1]}]], AspectRatio -> Automatic, DisplayFunction -> Identity] &, {First[ results], Last[results]}]]] === Subject: Feynman slash notation I need to insert the slash notation into a Mathematica document. Does Mathematica support this? === Subject: Move frame labels closer to frame? It seems to me that the frame labels are too far from the frame. Is there a way to control their placement and/or move them closer to the frame? For example, Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> True, PlotLabel -> Plot label, FrameLabel -> {{y, None}, {x, None}}, FrameTicks -> Automatic] I just think the x and y labels are too far from the frame. This becomes a real issue for me when I'm putting a bunch of plots in a GraphicsGrid. --Mark P.S. I'm using 6.0 for Microsoft Windows (32-bit) (May 21, 2008) === Subject: Re: fractional derivative (order t) of (Log[x])^n and Log[Log[x]] > I'd be grateful if someone could tell me a nicely computable formula > for the fractional derivative w.r.t. x (order t) of (Log[x])^n, where > n is a positive integer. , and > there is a formula there for the t-th (fractional) derivative of > Log[x]^n, but I do not understand how to input it!! You may have not notice but if you look at the upper-left corner below the graphic, more or less at the same level at the section title Elementary Functions Log[z] Differentiation, you can see a paragraph titled DOWNLOAD FORMULAS FOR THIS FUNCTION: just below it you can choose to download the file as a Mathematica notebook or as PDF. http://functions.wolfram.com/ElementaryFunctions/Log/20/03/ Then you can explore and manipulate the formulae directly from within Mathematica. For instance, In[1]:= FullSimplify[ D[Log[z], {z, [Alpha]}] == Piecewise[ {{((-1)^([Alpha] - 1)* ([Alpha] - 1)!)/z^[Alpha], Element[[Alpha], Integers] && [Alpha] > 0}}, (Log[z] - EulerGamma - PolyGamma[1 - [Alpha]])/ Gamma[1 - [Alpha]]/z^[Alpha]]] Out[1]= [Alpha] -(-1) Gamma[[Alpha]] Piecewise[{{---------------, [Alpha] z [Alpha] [Element] Integers && [Alpha] > 0}}, -HarmonicNumber[-[Alpha]] + Log[z] ---------------------------- [Alpha] z Gamma[1 - [Alpha]] ([Alpha]) ] == Log [z] HTH, === Subject: Re: fractional derivative (order t) of (Log[x])^n and Log[Log[x]] click on any formula at and you will find the Mathematica input. For the first formula it is D[Log[1 + z], {z, [Alpha]}] == z^(1 - [Alpha]) Hypergeometric2F1Regularized[1, 1, 2 - [Alpha], -z] Jens > I'd be grateful if someone could tell me a nicely computable formula > for the fractional derivative w.r.t. x (order t) of (Log[x])^n, where > n is a positive integer. (Ideally I would like a formula where t can be any real number, but > one for t>=0 would be most helpful!) The second thing I am seeking is a formula for the fractional > derivative w.r.t. x (order t) of Log[Log[x]], Log[Log[Log[x]]], etc., > and more generally, of Log[...[Log[Log[x]]...], where there are n > nested log functions, where n is of course a positive integer. (I have visited: > , and > there is a formula there for the t-th (fractional) derivative of > Log[x]^n, but I do not understand how to input it!! Basically I need formulae for the order-t fractional derivatives of > (Log[x])^n and of Log[Log[x]], Log[Log[Log[x]]] (and generally with n > nested logs), which I can use for variable x and given values of n and > t, and can also evaluate at given values of x. > Michael > === Subject: Re: Grouping and constraining slider controls > First - I am as green as it comes to Mathematica and have tried to RTFM > to find my answer but alas I have come up short and need some help. I > want to group X number of slider controls that each have a value range > from 0 to 100 and constrain this group so that the total of the values > from the group is not greater than 100 (representing 100%). So in > theory slider 1 starts at 100% and has other sliders are moved they > decrement proportionally the other sliders that are currently greater > than 0. I think that you are looking for something along the lines: DynamicModule[{x = 100}, Column[{{Slider[Dynamic[x], {0, 100, 1}], Dynamic[x]}, {Slider[ Dynamic[100 - x, (x = 100 - #) &], {0, 100, 1}], Dynamic[100 - x]}}]] The tutorial Introduction to Dynamic explains in detail how a control can control another control and most of the examples are with sliders. tutorial/IntroductionToDynamic http://reference.wolfram.com/mathematica/tutorial/IntroductionToDynamic.html HTH, === Subject: Re: Grouping and constraining slider controls Tim, Here is one possible solution using three sliders. We use the second argument of Dynamic to calculate the value of the slider and other variables. See the section 'The Second Argument of Dynamic' in the 'Introduction to Dynamic' tutorial. (And why or why doesn't WRI put section openers in their tutorials? Especially since the brackets are also omitted. The scroll went out of fashion 2000 years ago - and for good reason! http://en.wikipedia.org/wiki/Codex#History) Module[ {x1 = 100, x2 = 0, x3 = 0, total = 100}, Column[ {Slider[ Dynamic[x1, (total = # + x2 + x3; If[total > 100, {x1, x2, x3} = 100/total {#, x2, x3}, x1 = #]) &], {0, 100}], Slider[ Dynamic[x2, (total = x1 + # + x3; If[total > 100, {x1, x2, x3} = 100/total {x1, #, x3}, x2 = #]) &], {0, 100}], Slider[ Dynamic[x3, (total = x1 + x2 + #; If[total > 100, {x1, x2, x3} = 100/total {x1, x2, #}, x3 = #]) &], {0, 100}], Dynamic@{x1, x2, x3, x1 + x2 + x3}}] ] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hello First - I am as green as it comes to Mathematica and have tried to RTFM > to find my answer but alas I have come up short and need some help. I > want to group X number of slider controls that each have a value range > from 0 to 100 and constrain this group so that the total of the values > from the group is not greater than 100 (representing 100%). So in > theory slider 1 starts at 100% and has other sliders are moved they > decrement proportionally the other sliders that are currently greater > than 0. === Subject: Re: Integrating DiracDelta to get UnitStep >> Hi: >> I am a bit confused by Mathematica 6.0.3 behavior. I expect that: >> In[n]:= Integrate[DiracDelta[x], {x, -[Infinity], t}, >> Assumptions -> Im[t] == 0] >> Will produce: >> Out[n]= UnitStep[t] >> But instead it produces: >> Out[n]= 1 >> However, >> In[n+1]:= Plot[ Integrate[DiracDelta[x], {x, -[Infinity], t}, >> Assumptions -> Im[t] == 0], {t, -2, 2} ] >> produces the expected plot of UnitStep[t]. >> Why doesn't the integration output the UnitStep function? I share your concern and will be interested to see what others say. > Here's something which is closely related but which works as it > should: In[2]:= Integrate[DiracDelta[x], {x, t, Infinity}, > Assumptions -> Im[t] == 0] Out[2]= HeavisideTheta[-t] Perhaps that will help. > David > Also, Integrate[DiracDelta[x], {x, -Infinity, t}, Assumptions -> t < 0] 0 Integrate[DiracDelta[x], {x, -Infinity, t}, Assumptions -> t <= 0] HeavisideTheta[t] Integrate[DiracDelta[x], {x, -Infinity, t}, Assumptions -> t > 0] 1 all of which are correct. Andrzej Kozlowski === Subject: Re: Integrating DiracDelta to get UnitStep > Hi: I am a bit confused by Mathematica 6.0.3 behavior. I expect that: In[n]:= Integrate[DiracDelta[x], {x, -[Infinity], t}, > Assumptions -> Im[t] == 0] Will produce: Out[n]= UnitStep[t] But instead it produces: Out[n]= 1 However, In[n+1]:= Plot[ Integrate[DiracDelta[x], {x, -[Infinity], t}, > Assumptions -> Im[t] == 0], {t, -2, 2} ] produces the expected plot of UnitStep[t]. > Why doesn't the integration output the UnitStep function? If you consider the integration limit t as a complex number, you have to chose a contour for integration from -oo to t+i*0. The UnitStep distribution along the real axis is a limit of the difference of the complex logarithms with with cut along the positive real axis from above and below. Its derivative therefore is a boundary value of the analytic function z->1/z. What Mathematica knows about the complex representation of these distributions you see here In: Assuming[x [Element] Reals, Integrate[DiracDelta[x ], {x, a, b}]] Out: If[Element[a, Reals] && Element[b, Reals], (-1 + 2*HeavisideTheta[-a + b])*HeavisideTheta[ (-b)*HeavisideTheta[a - b] - a*HeavisideTheta[-a + b]]* HeavisideTheta[ a*HeavisideTheta[a - b] + b*HeavisideTheta[-a + b]], Integrate[DiracDelta[x], {x, a, b}, Assumptions -> Element[x, Reals] && (NotElement[a, Reals] || NotElement[b, Reals])]] As displyed by the last expression Mathematica has no clue about the integral as a complex countour integral. For the real case we have In: f[a_, b_] = Assuming[{a, b, x} [Element] Reals, Integrate[DiracDelta[x ], {x, a, b}]] Out: (-1 + 2*HeavisideTheta[-a + b])*HeavisideTheta[ (-b)*HeavisideTheta[a - b] - a*HeavisideTheta[-a + b]]* HeavisideTheta[a*HeavisideTheta[a - b] + b*HeavisideTheta[-a + b]] which is correct as you see with Plot3D. In: f[DirectedInfinity[ -1], 1] Out: HeavisideTheta[Indeterminate] In: HeavisideTheta[-1+I] Out: HeavisideTheta[-1+I] Hope it helps. -- Roland Franzius === Subject: Re: Integrating DiracDelta to get UnitStep > Note that HeavisideTheta[x] is not defined for x == 0 and that the > value > of the integral is 1/2 for x form -inf to zero. This might explained > why > Mathematica does not returned HeavisideTheta[t]. > In[2]:= Integrate[DiracDelta[x], {x, -[Infinity], t}, > Assumptions -> Im[t] == 0 && Re[t] < 0] Out[2]= 0 In[3]:= Integrate[DiracDelta[x], {x, -[Infinity], t}, > Assumptions -> Im[t] == 0 && Re[t] == 0] Out[3]= 1/2 In[4]:= Integrate[DiracDelta[x], {x, -[Infinity], t}, > Assumptions -> Im[t] == 0 && Re[t] > 0] Out[4]= 1 However, Mathmatica does return HeavisideTheta[t] here: Integrate[DiracDelta[x], {x, -Infinity, t}, Assumptions -> t <= 0] HeavisideTheta[t] and this,appears to include to contradict Integrate[DiracDelta[x], {x, -Infinity, 0}] 1/2 This may perhaps be justified by reference to the fact that Integrate for functions with parameters returns results which, in general, are only generically correct (in some informal sense of generically). Andrzej Kozlowski === Subject: Re: Help with StyleSheets > Actually, the principle point here is that the font is being overridden by the > StandardForm style. So, make the changes to the StandardForm style instead. > John Fultz > jfu...@wolfram.com > User Interface Group > Wolfram Research, Inc. A really useful feature would be to provide some way to determine > exactly where an option - such as a font setting for a particular cell - > was defined. David Baileyhttp://www.dbaileyconsultancy.co.uk To whom it may help, when I have a stylesheet or formatting problem, I either save the .nb as a package (.m) which clears most of useless formats, or simply use for selected celles the option clear formatting in Format.... Then I start afresh with it. === Subject: NDSolve precision and velocity problem I have an ODE system that takes lots of time to solve with NDSolve (several minutes), whereas the same system with the FORTRAN solver LSODA solves the problem in an second. When I decrease the precision, e.g. AccuracyGoal->6, NDSolve crashes. It often crashes, because it finds complex values in a less-than-comparison. Maybe it's a method problem. How do I tell NDSolve, to use the same methods as the LSODEA solver? joerg === Subject: Another Out of Memory Problem I can do the following: Integrate[Cos[2*x]* Exp[I*z*Cos[x]], {x, -Pi, Pi}] which produces a Bessel function answer; however if I change the argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* Exp[I*z*Cos[x]], {x, -Pi, Pi}] I almost immediately get this: No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. Kevin === Subject: Re: More Inquiries > RandomReal BurrDistribution /: RandomReal[ > BurrDistribution[c_?NumericQ, k_?NumericQ]] := > > InverseCDF[BurrDistribution[c, k], RandomReal[]]; BurrDistribution /: RandomReal[ > BurrDistribution[c_?NumericQ, k_?NumericQ], > n_Integer?Positive] := > Table[InverseCDF[BurrDistribution[c, k], RandomReal[]], {n}]; Just wanted to add a note on efficiency of random number generation and on some available documentation and utilities that are relevant for anyone who is interested in this type of thing. When it is possible to get more than one RandomReal (or RandomInteger, RandomChoice) at a time, and/or use vector evaluation, this will typically be faster than direct one at a time evaluation. In this case, we could reduce to one RandomReal call and use vector evaluation (though most of the speed gain comes from the vector evaluation). For the generator we could use the following: In[1]:= randomBurr[c_?Positive, k_?Positive, n_Integer?Positive] := ((1 - RandomReal[1, n])^(-1/k) - 1)^(1/c) In[2]:= Timing[randomBurr[1, 2, 10^6];] Out[2]= {0.875, Null} In comparison, here is the timing for the direct one at a time evaluation approach In[3]:= BurrDistribution /: InverseCDF[BurrDistribution[c_, k_], q_] := ((1 - q)^(-1/k) - 1)^(1/c); In[4]:= Timing[Table[ InverseCDF[BurrDistribution[1, 2], RandomReal[]], {10^6}];] Out[4]= {5.906, Null} Also, there is a section in the Random Number Generation tutorial ( tutorial/RandomNumberGeneration in the Documentation Center or http://reference.wolfram.com/mathematica/tutorial/RandomNumberGeneration.htm l online) titled Defining Distributions which discusses how additional distributional generators can be defined using some built-in utilities so that they work like RandomReal|RandomInteger[builtinDistribution,...]. === Subject: x-axis value issues Hello! I posted this on physicsforums.com but I thought I would link here, too, for better coverage (plus I could download the necessary files). Any help is much appreciated! http://physicsforums.com/showthread.php?t=249880 === Subject: Re: Making parts of formulae blinking > In my previous letter for the sake of shortness I have given an oversimplified > expression AB+xy. The procedure Accentuate works perfectly on it. In reality however, one often > needs to accentuate parts of an expression that have different lengths. Further, often there are more than two > parts of the same expression that should be accentuated separately. In this case a straightforward use > of the operator Accentuate results in a change of the order of the parts of the expression. For example, I need to discuss four parts of the same expression. They should be discussed separately > from one another. Here they are: > My solution to this would be to define a simple function - say acc: acc[x_] := Dynamic[Refresh[Style[x, Hue[Random[]]], UpdateInterval -> 0.3]] Now you can write partially accentuated expressions such as acc[a]+b^acc[c] and it will evaluate to a partially accentuated expression. Please note, however, that the randomly varying hue is meant as a joke - I don't want to be held responsible for any headaches it produces! BTW, I agree very much with David Park that there is enormous value in being able to pick out parts of expressions and to move beyond the 'dead' expressions that displayed in textbooks! David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: minimize with complex numbers 0,v1>0,u2>0,v2>0,u3>0,v3>0,u4>0,v4>0},{u1,v1,u2,v2,u3,v3,u4,v4}] The error is > Minimize::vdom : Variable domain {u1,v1,u2,v2,u3,v3,u4,v4} should be either Reals or Integers. > i didnt understand it can anybody tell me what should i do . You have a spurious closing curly bracket at the end of the objective function. Your expression should read, Minimize[{(0.83 u1 + 0.4 u2 - 0.25 u3 + 3 u4 + 0.16 v1 + 0.6 v2 + 1.25 v3 - 2 v4) 2 + (2 u1 - 0.16 u2 - 0.6 u3 - 1.25 u4 + 3 v1 + 0.83 v2 + 0.4 v3 - 0.25 v4) 2 + (0.4 u1 - 0.25 u2 + 3 u3 + 0.83 u4 + 0.6 v1 + 1.25 v2 - 2 v3 + 0.16 v4) 2 + (-1.25 u1 + 2 u2 - 0.16 u3 - 0.6 u4 - 0.25 v1 + 3 v2 + 0.83 v3 + 0.4 v4) 2 + (-0.25 u1 + 3 u2 + 0.83 u3 + 0.4 u4 + 1.25 v1 - 2 v2 + 0.16 v3 + 0.6 v4) 2 + (-0.6 u1 - 1.25 u2 + 2 u3 - 0.16 u4 + 0.4 v1 - 0.25 v2 + 3 v3 + 0.83 v4) 2 + (3 u1 + 0.83 u2 + 0.4 u3 - 0.25 u4 - 2 v1 + 0.16 v2 + 0.6 v3 + 1.25 v4) 2 + (-0.16 u1 - 0.6 u2 - 1.25 u3 + 2 u4 + 0.83 v1 + 0.4 v2 - 0.25 v3 + 3 v4) 2, {u1 > 0, v1 > 0, u2 > 0, v2 > 0, u3 > 0, v3 > 0, u4 > 0, v4 > 0}}, {u1, v1, u2, v2, u3, v3, u4, v4}] === Subject: Re: minimize with complex numbers >i have transformed my complex valued problem into real value problem as be= low but still when i try to MInimize it i didnt get a solution >(a1+b1i)x[1] +(a2+b2i) x[2]=0 You almost certainly have a syntax issue here. That is not to say this isn't a valid Mathematica expression. Rather it almost certainly isn't what you think. This expression in Mathematica will evaluate as follows: add a1 to b1i multiply this result by the *function* x evaluated at 1 add a2 to b2i multiply this result by the *function* x evaluated at 2 add the two products found above then *set* the entire thing to 0 In essence, minimizing this expression is equivalent to minimizing the constant 0 which clearly makes no sense. First, what is it you are trying to represent as x[1]? Is this supposed to be a subscripted variable? If so, that is possible to do in Mathematica but not particularly convenient. You can create subscripted variables that behave like unsubscripted variables using the Notation package. Failure to use that package will almost certainly give results you don't expect at some point. So, the first thing to get out of the problems you have is simply not to use subscripted variables until you become more expert with Mathematica. Next, if you intended for the expression to be an *equation* you need to be aware a single = is an assignment operator in Mathematica. Equations are expressed using a double =, e.g. x + y == 0 would be an equation in Mathematica. But for a minimization problem, it really doesn't make sense to minimize an equation. >Minimize[{(0.83 u1+0.4 u2-0.25 u3+3 u4+0.16 v1+0.6 v2+1.25 v3-2 v4)2+(2 u1= -0.16 u2-0.6 u3-1.25 u4+3 v1+0.83 v2+0.4 v3-0.25 v4)2+(0.4 u1-0.25 u2+3 u3+= 0.83 u4+0.6 v1+1.25 v2-2 v3+0.16 v4)2+(-1.25 u1+2 u2-0.16 u3-0.6 u4-0.25 v1= +3 v2+0.83 v3+0.4 v4)2+(-0.25 u1+3 u2+0.83 u3+0.4 u4+1.25 v1-2 v2+0.16 v3+0= .6 v4)2+(-0.6 u1-1.25 u2+2 u3-0.16 u4+0.4 v1-0.25 v2+3 v3+0.83 v4)2+(3 u1+0= .83 u2+0.4 u3-0.25 u4-2 v1+0.16 v2+0.6 v3+1.25 v4)2+(-0.16 u1-0.6 u2-1.25 u= 3+2 u4+0.83 v1+0.4 v2-0.25 v3+3 v4)2},{u1>0,v1>0,u2>0,v2>0,u3>0,v3>0,u4>0,v= 4>0},{u1,v1,u2,v2,u3,v3,u4,v4}] >The error is >Minimize::vdom : Variable domain {u1,v1,u2,v2,u3,v3,u4,v4} >should be either Reals or Integers. i didnt understand it can >anybody tell me what should i do . The first thing you should do when you get an error message you don't understand is read the online documentation for the function you are trying to use. In particular for Minimize you will find it expects at most three arguments an expression to minimize a list of variables a domain for those variable You provided an expression to minimize a list of inequalities a list of variables Mathematica saw the third argument wasn't a valid domain and generated the error message you saw If you look at the examples in the online documentation you will see the constraints on the variables are to be included in a single list with the expression to be minimized. That is: Minimize[{x - 2 y, x^2 + y^2 <= 1}, {x, y}] will minimize x 2 y subject to the constraint x^2 + y^2 <=1 But Minimize[{x - 2 y}, {x^2 + y^2 <= 1}, {x, y}] will generate the same kind of error message you saw. However, when I correct your syntax to be what Minimize expects, I get the result that the expression is 0 when all of the variables are 0. Since that almost certainly isn't a useful result, I strongly suspect you have other problems that are not apparent from your post. === Subject: Re: debugging code that contains compile > I have some code where I define some functions using compile to speed them up. Code runs fine without compile, but when using compile I get some errors. So what I wanna do now is of course analyze where these errors come from. Unfortunately Mathematica Frontend just tells me the kind of error and what variables are involved. Due to my code being pretty large, it's no easy task to figure out where these errors in deed appear. By errors, do you mean you get any error messages of the form CompiledFunction::error_code:error_text For instance, CompiledFunction::cfsa: Argument 1+u at position 1 should be a machine-size real number. CompiledFunction::cfn: Numerical error encountered at instruction 2; proceeding with uncompiled evaluation. encounter when compiling some working-as-expected-before-compilation code are: . wrong expectations about Compile: not every function is compilable and successfully compiled code does not systematically translate as speed improvement . wrong format for input variables and/or output results returned by intermediate calls === Subject: Re: Adjoint Frechet Derivative in Mathematica Anyone? :( === Subject: Re: DO loop > I am new with mathematica and I have the following problem: > I want to repeat a procedure that involves a two main functions for a > precise number of times. Which would be the format of a do loop in > mathematica in order to calculate them and write the results of each > iteration to a matrix? > In order to be more exact I want to solve the following : I have a function........ Vz[r_]=1/r > intE = EA + e > .........................which I solve and the real solutions are the > intergartion limits at the intergral that follows > Solve[Vz[r] == intE, r] olok = NIntegrate[f1[r], {r, Ra, Rb}] // N; I would like to repeat this procure for several e values and write a > matrix. > I future I would like to include a second function in the do loop > which is also a function of e. Speaking about iteration Do and Table have the same syntax and do the same thing iterating process, except that Do does not returned or build anything by itself, while Table builds and returns a list (or list of lists depending on the number of iterators involved). So I would definitely go with Table (or with some even more functional constructs, but this is another story). (Note that both examples below are optimistic: they assume that Solve will always returned two real solutions. They are just starters for you own complete code with error checking and/or exception catching.) In[1]:= EA = r; Vz[r_] = 1/r; intE = EA + e; f1[r_] := r^2 m = {}; Module[{sols, Ra, Rb}, Do[ sols = Solve[Vz[r] == intE, r]; Ra = r /. sols[[1]]; Rb = r /. sols[[2]]; AppendTo[m, NIntegrate[f1[r], {r, Ra, Rb}]], {e, 3} ] ] m Out[4]= {1.49071, 4.71405, 12.0185} In[5]:= Module[{sols}, Table[ sols = Solve[Vz[r] == intE, r]; NIntegrate[f1[r], {r, r /. sols[[1]], r /. sols[[2]]}], {e, 3} ] ] Out[5]= {1.49071, 4.71405, 12.0185} === Subject: Re: DO loop since you where not so kind to provide a working example here is one a) define the potential: V[eps_, sigma_][r_] := With[{x = sigma/r}, 4*eps*(x^12 - x^6)] b) compute the radii LJRadii[eps_, sigma_][e_] := Select[r /. Solve[V[eps, sigma][r] == e, r], FreeQ[#, _Complex] && # > 0 &] c) define a integral condition BohrSommerfeld[eps_, sigma_, m_: 1, hbar_: 1][e_, n_Integer] /; e < 0 := Module[{r1, r2, r}, {r1, r2} = LJRadii[eps, sigma][e]; NIntegrate[ Sqrt[2]*Sqrt[m*(hbar*n + (4*eps*sigma^6*(r^6 - sigma^6))/r^12)], {r, r1, r2}] ] d) and now, comes the DO loop, that compute the function for energy values between [-0.9,-0.01] in steps of 0.0125 BohrSommerfeld[1, 1][#, 0] & /@ Table[e, {e, -0.9, -0.01, 0.0125}] Ooops ! there is no DO loop, let try a version with out stuff like & and /@ Table[BohrSommerfeld[1, 1][e, 0],{e, -0.9, -0.01, 0.0125}] Now lets make a matrix Table[BohrSommerfeld[1, 1][e, n], {e, -0.9, -0.01, 0.0125}, {n, 0, 4}] and there is again no DO loop and I never found out for what a DO loop is good for in Mathematica. I had times where I forgot the syntax, that can be found by typing ?Do Jens I am new with mathematica and I have the following problem: > I want to repeat a procedure that involves a two main functions for a > precise number of times. Which would be the format of a do loop in > mathematica in order to calculate them and write the results of each > iteration to a matrix? > In order to be more exact I want to solve the following : I have a function........ Vz[r_]=1/r > intE = EA + e > ........................which I solve and the real solutions are the > intergartion limits at the intergral that follows > Solve[Vz[r] == intE, r] olok = NIntegrate[f1[r], {r, Ra, Rb}] // N; I would like to repeat this procure for several e values and write a > matrix. > I future I would like to include a second function in the do loop > which is also a function of e. > Maria > === Subject: ODE in mathematica. what is wrong? I am a freshman of Mathematica, I need help here... I met such problem as: NDSolve[{ y'[x] == -[Rho]y[x], y[0] == Subscript[y, 0], I[HBar] y'[x] == [Epsilon]y[x], y[0] == Subscript[y, 0], y''[x] + 2 [Rho]y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}, y, x] NDSolve::dvnoarg: The function y appears with no arguments. How to Handle??? === Subject: Re: Move frame labels closer to frame? Mark, I first did this with the Presentations package. The idea is to draw the sin curve without FrameLabel, leave the necessary amount of ImagePadding to accommodate the desired labels, set PlotRangeClipping -> False, then Inset the frame labels where we want using ImageScaled coordinates. Needs[Presentations`Master`] Draw2D[ {Draw[Sin[x], {x, 0, 2 Pi}], Inset[Style[x, 14], ImageScaled[{.60, .045}]], Inset[Style[y axis, 14], ImageScaled[{.04, .54}], {Center, Center}, Automatic, {0, 1}]}, AspectRatio -> 1/GoldenRatio, Axes -> True, Frame -> True, PlotLabel -> Plot label, PlotRangeClipping -> False, ImagePadding -> {{40, 5}, {30, 5}}] This takes some hand adjusting to get the ImageCoordinates correct. It is also possible to use actual plot coordinates, which is a little easier. But it is necessary to specify an explicit PlotRange so the Insets will fall outside the frame. The plot coordinates for the Insets will be outside the frame, but that's ok. Draw2D[ {Draw[Sin[x], {x, 0, 2 Pi}], Inset[Style[x, 14], {3.5, -1.3}], Inset[Style[y axis, 14], {-.6, 0}, {Center, Center}, Automatic, {0, 1}]}, AspectRatio -> 1/GoldenRatio, Axes -> True, Frame -> True, PlotRange -> {{0, 2 Pi}, {-1, 1}}, PlotRangePadding -> .1, PlotLabel -> Plot Labels Where I Want!, PlotRangeClipping -> False, ImagePadding -> {{40, 5}, {30, 5}}] While the Presentations paradigm helps me think of this, because the frame labels are just two more things we want to draw, I have to be honest and show how this can also be done without Presentations. You just have to remember that you can use the Epilog option to add primitives to a set-piece plot. Plot[Sin[x], {x, 0, 2 Pi}, Axes -> True, Frame -> True, PlotRange -> {{0, 2 Pi}, {-1, 1}}, PlotRangePadding -> .1, PlotLabel -> Plot Labels Where I Want!, PlotRangeClipping -> False, ImagePadding -> {{40, 5}, {30, 5}}, Epilog -> {Inset[Style[x, 14], {3.5, -1.3}], Inset[Style[y axis, 14], {-.6, 0}, {Center, Center}, Automatic, {0, 1}]}] http://home.comcast.net/~djmpark/ It seems to me that the frame labels are too far from the frame. Is > there a way to control their placement and/or move them closer to the > frame? For example, Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> True, > PlotLabel -> Plot label, FrameLabel -> {{y, None}, {x, None}}, > FrameTicks -> Automatic] I just think the x and y labels are too far from the frame. This > becomes a real issue for me when I'm putting a bunch of plots in a > GraphicsGrid. P.S. I'm using 6.0 for Microsoft Windows (32-bit) (May 21, 2008) > === Subject: Re: Move frame labels closer to frame? and gr = FullGraphics[ Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> True, PlotLabel -> Plot label, FrameLabel -> {x, y, None, None}, FrameTicks -> Automatic]]; Manipulate[ Show[gr /. {Text[x, a_, opts___] :> Text[x, Scaled[p1], opts], Text[y, a_, opts___] :> Text[y, Scaled[p2], opts]}, AspectRatio -> 1/GoldenRatio], {{p1, {0.5, 0.1}}, {-0.5, -0.5}, {1.5, 1.5}, ControlType -> Slider2D}, {{p2, {-0.1, 0.5}}, {-0.5, -0.5}, {1.5, 1.5}, ControlType -> Slider2D} ] will let you move the labels to the positions you like. Jens It seems to me that the frame labels are too far from the frame. Is > there a way to control their placement and/or move them closer to the > frame? For example, Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Axes -> True, > PlotLabel -> Plot label, FrameLabel -> {{y, None}, {x, None}}, > FrameTicks -> Automatic] I just think the x and y labels are too far from the frame. This > becomes a real issue for me when I'm putting a bunch of plots in a > GraphicsGrid. > --Mark P.S. I'm using 6.0 for Microsoft Windows (32-bit) (May 21, 2008) > === Subject: Re: Feynman slash notation You can create new notations in Mathematica with the Notations Package (add-on), which is already included in Mathematica, see this link: http://reference.wolfram.com/mathematica/Notation/guide/NotationPackage.h= tml I hope that helps Jose Mexico -----Mensaje original----- De: Shaun Culver [mailto:admin@shaunculver.com] Enviado el: Mi=E9rcoles, 13 de Agosto de 2008 03:42 Para: mathgroup@smc.vnet.net Asunto: Feynman slash notation I need to insert the slash notation into a Mathematica document. Does Mathematica support this? === Subject: Re: Feynman slash notation Stephen Luttrell's solution worked really well for my purposes. I hope that Mathematica staff will incorporate this notation in future releases. === Subject: Fastest way to check inequality I need to test the inequality A . x <= 0, where x is a three-D vector. A is a 35000x3 matrix. I need to test this for 20000 points. So I set this up as follows: A = RandomReal[{0,1},{35000,3}]; x = RandomReal[{0,1},{20000,3}]; (And @@ NonPositive[constrMat . # ]) & /@ x; Is this the fastest way? Ravi The University of Washington Seattle, WA === Subject: Re: Fastest way to check inequality > (And @@ NonPositive[constrMat . # ]) & /@ x; That's a very fast way to do nothing, since constrMat is undefined. A.x also makes no sense, since A and x don't have compatible dimensions. There are a couple of ways to make them compatible, namely a = RandomReal[{0, 1}, {3500, 3}]; x = RandomReal[{0, 1}, {2000, 3}]; a.Transpose[x] // Dimensions {3500, 2000} x.Transpose[a] // Dimensions {2000, 3500} (I shrank the dimensions so that I didn't get old waiting for results.) Now the question is whether you intend 35000 inequalities, 20000, or 35000*20000. I'm guessing the latter. That is, ALL entries must be non-positive in EITHER of the dot products above. If that guess is correct, we can speed things up by stopping when we reach a failure. Since Dot is a special case of Inner, we can do it this way: Catch[Inner[Times, a, Transpose@x, (Plus[##] > 0 && Throw[False]) &]; True] Here are a couple of examples with obvious answers: a = RandomReal[{-1, 0}, {35, 3}]; x = RandomReal[{0, 1}, {20, 3}]; Catch[Inner[Times, a, Transpose@x, (Plus[##] > 0 && Throw[False]) &]; True] True a = RandomReal[{0, 1}, {35, 3}]; x = RandomReal[{0, 1}, {20, 3}]; Catch[Inner[Times, a, Transpose@x, (Plus[##] > 0 && Throw[False]) &]; True] False Bobby > Hello Math-groupers, I need to test the inequality A . x <= 0, where x is a three-D vector. > A is a 35000x3 matrix. I need to test this for 20000 points. So I set this up as follows: A = RandomReal[{0,1},{35000,3}]; x = RandomReal[{0,1},{20000,3}]; (And @@ NonPositive[constrMat . # ]) & /@ x; Is this the fastest way? Ravi > The University of Washington > Seattle, WA > -- DrMajorBob@longhorns.com === Subject: Re: Fastest way to check inequality On Aug 18, 12:38 am, Ravi Balasubramanian A is a 35000x3 matrix. I need to test this for 20000 points. So I set this up as follows: A = RandomReal[{0,1},{35000,3}]; x = RandomReal[{0,1},{20000,3}]; (And @@ NonPositive[constrMat . # ]) & /@ x; Is this the fastest way? Ravi > The University of Washington > Seattle, WA See the discussion 'short circuiting And and Or', Oct 20-21, 2006: === Subject: Incorrect integral in Mathematica Hi All, I'm getting a nonsensical answer of 0 for the following integral in Mathematica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? === Subject: Re: Incorrect integral in Mathematica > Hi All, I'm getting a nonsensical answer of 0 for the following integral in Mathe= matica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], > {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? > I tried this integral in version 4 on a PC and got the correct answer (although in a slightly different form).: (2*Pi)/(Sqrt[1/w^2]*Sqrt[1/z^2]) === Subject: Re: Incorrect integral in Mathematica > I'm getting a nonsensical answer of 0 for the following integral in Mathematica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], > {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? Seems to be a bug. Note that the result you expect is valid only for both w and z real and of same sign, so you may want to add some assumptions (either with Assuming[] or the option Assumptions -> ...) Mathematica 6.0.3 gives a complete and correct solution. In[1]:= Integrate[ Exp[-x^2/(2 w^2)] Exp[-(y - y0)^2/(2 z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] Out[1]= (1/Sqrt[(1/(z^2))])Sqrt[2 [Pi]] If[Re[w^2] > 0, Sqrt[2 [Pi]]/Sqrt[1/w^2], Integrate[E^(-(x^2/(2 w^2))), {x, -[Infinity], [Infinity]}, Assumptions -> Re[w^2] <= 0]] In[2]:= Assuming[Element[w | z, Reals], Integrate[ Exp[-x^2/(2 w^2)] Exp[-(y - y0)^2/(2 z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}]] Out[2]= 2 [Pi] Abs[w] Abs[z] In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) === Subject: Re: Incorrect integral in Mathematica You might try using the Assumptions option in the Integrate expression. In 6.0.3 (and probably in 5.0) this gives: Integrate[ Exp[-x^2/(2 w^2)] Exp[-(y - y0)^2/(2 z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, Assumptions -> w > 0 [And] z > 0] 2 [Pi] w z -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > Hi All, I'm getting a nonsensical answer of 0 for the following integral in > Mathematica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], > {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? === Subject: Re: Incorrect integral in Mathematica With version 6.0.3 I get 2Pi w z > Hi All, I'm getting a nonsensical answer of 0 for the following integral in Mathematica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], > {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? === Subject: Re: Locate palette at top edge of screen? Jens, command cannot move the palette ABOVE the bottom of the main title bar, at least not on my system. After executing the commands written in your message, when I drag the created slider upward with my mouse, the palette faithfully tracks the slider position until the top edge of the palette reaches the bottom edge of the main title bar. Thereafter, as I continue to drag the slider upward, the palette does not respond. Increasing the vertical coordinates of the initial position and/or that of the maximum slider position the numerical parameters in the Manipulate command still does not allow the palette to be position above the bottom edge of the main title bar. So far, the only way I have found to get the palette above the bottom edge of the title bar is to drag it manually with the mouse. Dwynn try pal = CreatePalette[PasteButton[[Alpha]]]; Manipulate[ > SetOptions[pal, > WindowMargins -> {{p[[1]], Automatic}, {p[[2]], Automatic}}]; p, > {{p, {0, 0}}, {0, 0}, {1280, 1024}, ControlType -> Slider2D} > ] and use the position you like. Jens > (Windows XP SP3, Mathematica 6.0.3) >> I am trying to create a command that moves a palette so that its top >> edge is at or near the top edge of the screen, i.e., superimposed on the >> space occupied by the main title bar (the bar containing Wolfram >> Mathematica 6.0 - and the menu titles.) >> If I simply use the example in the CreatePalette entry in the Help >> documentation >> pal = CreatePalette[PasteButton[[Alpha]]]; >> a small palette is created. (In my case, most of it extends off the >> right edge of my screen). >> I then use the mouse to drag this palette onto the center area of the >> main title bar, placing its top edge at the top edge of the screen and >> thus practically coincident with the top edge of the main title bar. >> To determine the coordinates (window margins) in this desired location, >> I execute the command >> Options[pal, WindowMargins] >> and the result in this case is >> {WindowMargins -> {{599, Automatic}, {Automatic, -50}}} >> Using the mouse, I drag the palette away from this location, then >> execute the following command, expecting it to move the palette back to >> the desired position. >> SetOptions[pal, WindowMargins -> {{599, Automatic}, {Automatic, -50}} >> Instead, the palette moves to the correct horizontal postion, but its >> top edge is at the BOTTOM edge of the main title bar, not at the top >> edge of the screen. Executing the command >> Options[pal, WindowMargins] >> yields >> {WindowMargins -> {{599, Automatic}, {Automatic, -50}}} >> which is inconsistent with the screen position. Indeed, if I again move >> the mouse to another location, then execute >> SetOptions[pal, WindowMargins -> {{599, Automatic}, {Automatic, 0}} >> the palette moves back to its previous position right below the main >> title bar. Thus an upper margin of 0 corresponds with the bottom edge >> of the main title bar, therefore implying a value of -50 should be above >> that edge. However, it seems a command of the form >> SetOptions[...,WindowMargins->{{...},{Automatic,x}}] converts negative >> values of x to 0. >> Is there a command that can move a palette so its top edge is at the top >> edge of the screen? >> Dwynn > -- L. Dwynn Lafleur Professor of Physics University of Louisiana at Lafayette lafleur@louisiana.edu === Subject: Re: troubling simple integral On Aug 17, 12:41 pm, Jean-Marc Gulliet 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == = 0, > FullSimplify[ > Integrate[(b + k*x)/k^2*Exp[-k*x]*Sin[k*a]*Sin[k*y], {k, 0, > Infinity}]]] Out[1]= 1/4 (2 b ((-a + y) ArcTan[(a - y)/x] + (a + y) ArcTan[(a + y)/ > x] - x ArcTanh[(2 a y)/(a^2 + x^2 + y^2)]) + > x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) > Note that *Assuming* passes the assumptions to both Integrate[] *and* > FullSimplify[]. (In your original expression, only Integrate[] could > take into account the assumptions.) I understand that. But what I find puzzling the result obtained by Alberto (I got the same). I'm wondering if there is an issue there. === Subject: Possible Bug with Specific Combination of Integrate and Assumptions >> On Aug 17, 12:41 pm, Jean-Marc Gulliet > Does the following result look better? >> In[1]:= Assuming[x > 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == >> = 0, > FullSimplify[ > Integrate[(b + k*x)/k^2*Exp[-k*x]*Sin[k*a]*Sin[k*y], {k, 0, > Infinity}]]] >> Out[1]= 1/4 (2 b ((-a + y) ArcTan[(a - y)/x] + (a + y) ArcTan[(a + y)/ > x] - x ArcTanh[(2 a y)/(a^2 + x^2 + y^2)]) + > x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) > Note that *Assuming* passes the assumptions to both Integrate[] *and* > FullSimplify[]. (In your original expression, only Integrate[] could > take into account the assumptions.) >> I understand that. But what I find puzzling the result obtained by >> Alberto >> (I got the same). I'm wondering if there is an issue there. The issue might be platform specific. On my system 64-bit Intel Core 2 > expression returns unevaluated after few dozens of seconds. In[1]:= > Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], > {k,0,Infinity},Assumptions->Element[{a,y},Reals]] Out[1]= > Integrate[(E^-k Sin[a k] Sin[k y])/k^2, > {k,0,[Infinity]},Assumptions->(a|y)[Element]Reals] In[2]:= $Version Out[2]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) Gist: The above integral cannot be correctly evaluated when using the option *Assumptions*; however, it is evaluated quickly and correctly when the assumptions are passed via the command *Assuming[]*. Following a private communication w/ Alberto Verga, I realized that I did not try to evaluate the integral twice within the same Mathematica session. Indeed, the first time one evaluates the above expression, the integral is returned unevaluated (having consumed about 90s of cpu time). Evaluating again the integral, Sqrt[-1]/8 is returned (having consumed about 60s of cpu time). Note that both results are erroneous (see below for the correct one). Also, it seems that the system cache and the evaluation of the integral interfere in some unexpected way. If we clear the symbolic system cache before evaluating again the expression, the expression is then returned unevaluated as in the first run. In[1]:= Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}, Assumptions -> Element[{a, y}, Reals]] // Timing Out[1]= {89.2521, Integrate[(E^-k Sin[a k] Sin[k y])/k^2, {k, 0, [Infinity]}, Assumptions -> (a | y) [Element] Reals]} In[2]:= Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}, Assumptions -> Element[{a, y}, Reals]] // Timing Out[2]= {62.8449, I/8} In[3]:= ClearSystemCache[Symbolic] In[4]:= Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}, Assumptions -> Element[{a, y}, Reals]] // Timing Out[4]= {85.4576, Integrate[(E^-k Sin[a k] Sin[k y])/k^2, {k, 0, [Infinity]}, Assumptions -> (a | y) [Element] Reals]} Now if we use the command *Assuming[]* rather than the option Assumptions (of course, using the same set of assumptions) we consistently get the correct result in few seconds. In[1]:= Assuming[Element[{a, y}, Reals], Integrate[ 1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}]] // Timing Out[1]= {4.87668, 1/2 ((-a + y) ArcTan[a - y] + (a + y) ArcTan[a + y] - ArcTanh[(2 a y)/(1 + a^2 + y^2)])} In[2]:= Assuming[Element[{a, y}, Reals], Integrate[ 1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}]] // Timing Out[2]= {0.639187, 1/2 ((-a + y) ArcTan[a - y] + (a + y) ArcTan[a + y] - ArcTanh[(2 a y)/(1 + a^2 + y^2)])} Tested on: 64-bit Intel Core 2 Duo 4 GB Mac OS X Leopard 1.5.4 Mathematica 6.0.3 === Subject: Re: troubling simple integral > On Aug 17, 12:41 pm, Jean-Marc Gulliet Does the following result look better? >> In[1]:= Assuming[x > 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == > = 0, >> FullSimplify[ >> Integrate[(b + k*x)/k^2*Exp[-k*x]*Sin[k*a]*Sin[k*y], {k, 0, >> Infinity}]]] >> Out[1]= 1/4 (2 b ((-a + y) ArcTan[(a - y)/x] + (a + y) ArcTan[(a + y)/ >> x] - x ArcTanh[(2 a y)/(a^2 + x^2 + y^2)]) + >> x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) >> Note that *Assuming* passes the assumptions to both Integrate[] *and* >> FullSimplify[]. (In your original expression, only Integrate[] could >> take into account the assumptions.) I understand that. But what I find puzzling the result obtained by Alberto > (I got the same). I'm wondering if there is an issue there. The issue might be platform specific. On my system 64-bit Intel Core 2 expression returns unevaluated after few dozens of seconds. In[1]:= Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k,0,Infinity},Assumptions->Element[{a,y},Reals]] Out[1]= Integrate[(E^-k Sin[a k] Sin[k y])/k^2, {k,0,[Infinity]},Assumptions->(a|y)[Element]Reals] In[2]:= $Version Out[2]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) === Subject: Re: debugging code that contains compile > The errors I get are Compile::cif errors. I don't know of a way to directly get information during runtime from within a CompiledFunction (except using Print of course...), but for the case of Compile::cif it should be relativley easy to extract the parts that cause problems when beeing compiled by looking at the Inputform of the resulting CompiledFunction: Compile[{{x, _Real, 1}, {y, _Real, 2}, {t, True | False}}, If[t, x, y]] // InputForm If something could not be compiled that part of the code is contained within the compiled code like here: CompiledFunction[{{_Real, 1}, {_Real, 2}, True | False}, {{3, 1, 0}, {3, 2, 1}, {1, 0, 0}, {3, 0, 0}}, {1, 0, 1, 0, 2}, {{1, 5}, {54, Function[{x, y, t}, If[t, x, y]], 3, 1, 0, 3, 2, 1, 1, 0, 0, 3, 0, 0}, {2}}, Function[{x, y, t}, If[t, x, y]], Evaluate] so in this case you can see that it is the If that causes the error. Of course this approach might be uncomfortable if your compiled function is huge, but you can then use Mathematica's pattern matching to extract those parts within the compiled function that have not been compiled... === Subject: Version 2.4 of the Mathematica Baseball package is available Version 2.4 of the Mathematica Baseball package is available at http://homepage.mac.com/klevasseur/erm/ See examples a few examples of what can be done with the package at http://homepage.mac.com/klevasseur/erm/HTMLLinks/gallery.html Have fun, Ken Levasseur === Subject: Re: Solving nonlinear inequality constraints > (1) Get rid of all the Hold usage. If you need it, you are doing > something > wrong. (2) If you spend a bit of time debugging this, say, computing various > functions for various small values of t (e.g. inv[2]), you will quickly > learn that you have not defined [Mu][t_]. This means there will be no > end > of symbolic computation in trying to resolve various inequalities, etc. (3) There could be other issues. For one, you might have complex values > which will cause inequalities to be unevaluated. This, too, might be > determined by computing various values (after resolving issue (2) above). Daniel Lichtblau > Wolfram Research suggestions but question whether your points can be implemented because of the following issues: (1) Hold usage cannot be removed on constraints because they immediately start to evaluate for true/false eg. 0.02*k[periods] <= inv[periods], which is not wanted because they need to remain symbolic to be combined with the objective function (and because they burst the Recursion limit). (2) [Mu][t_] is deliberately not defined or else the the {x,y,...} in NMinimize[{f,cons},{x,y,...}] are immediately evaluated. As with the constraints, the {x,y,...} need to remain symbolic to be of use in NMinimize. Instead of a using the function that you suggested, I have left the [Mu][t] to be provided by NMinimize. Given (1) and (2), how can your suggestion can be implemented? (3) Complex values do not arise with any of the cases I can evaluate but it is agreed that this would need to be watched. Interestingly, using NMinimize, 7 periods takes 35 minutes and 8 periods takes 77 minutes. The memory usage is 2.3Gb and 11.3Gb respectively. Using _NumericQ in each of the function definitions actually slows down execution by about 1 minute. I really appreciate your thoughts, Stuart -- Stuart Nettleton FCPA, MBA, MEngSci, BEng(Hons), GradDipAICD Senior Lecturer, Faculty of Engineering Privacy and Confidentiality Notice: The information in this e-mail may be confidential and /or legally privileged. It is intended solely for the addressee. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Virus Information: It is the recipient/client's duty to virus scan and otherwise test the information provided before loading onto any computer system. No warranty is made that this material is free from computer virus or any other defect or error. Any loss/damage incurred by using this material is not the sender's responsibility. -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects. === Subject: Re: Solving nonlinear inequality > I have taken a completely different approach by using active data for > auto-topology and using NMaximize to solve only for the leaves. This means > small numbers of periods calculate very quickly. So after setting a 25 > period version running on our university high performance cluster I went > to sleep at 3am. Waking up I felt jubilant at the elegance, truth and > beauty in my new solution. However, I was dismayed to find the > Mathematica > blue screen of death: No more memory available. Mathematica kernel has > shut > down. Try quitting other applications and then retry. Of course I was the > only person on the cluster node and all I had running was Mathematica. I > am not sure of the memory size on our nodes so I will check this. With Red > Hat > linux it should be a Windows problem. Would somebody be able to help me by having a brief look at this code and > see if I have made an error somewhere or if the code can be made both > beautiful and run for up to 60 periods? Stuart > [...] (1) Get rid of all the Hold usage. If you need it, you are doing something wrong. (2) If you spend a bit of time debugging this, say, computing various functions for various small values of t (e.g. inv[2]), you will quickly learn that you have not defined [Mu][t_]. This means there will be no end of symbolic computation in trying to resolve various inequalities, etc. (3) There could be other issues. For one, you might have complex values which will cause inequalities to be unevaluated. This, too, might be determined by computing various values (after resolving issue (2) above). Daniel Lichtblau Wolfram Research === Subject: NDSolve Hallo, I was trying to solve the heat equation with NDSolve(one spatial dimension, x, and time t). The simulated device (centered around x=0) consists of three regions: Two rather big volumina (with thickness each being dg) to the left and right of a thin layer (with thickness dp). A heat source is only present in the thin layer. The outer left boundary of the whole device is open, i.e. the spatial derivative of the temperature is zero there. At the right boundary, there is perfect cooling, i.e. the temperature stays constant. As the heat is generated only in the thin layer, the change is quite abrupt. What I would like to know is if there is a way to tell Mathematica to place a very fine grid there because the result I get is not correct. Here is the code: dp=1e-5; dg=1e-3; eta=500/dp; sol=u/.First[ NDSolve[D[u[t, x],t]==ldrp[x,0.5*dp,0.1*dp]*D[u[t,x],(x,2)]+eta*heat[x,0.5*dp,0.1*dp], u[0,x]==0,D[u[t,-dg-dp/2],x]==0,u[t,dg+dp/2]==0},u,{t,0,tmax},{x,-dg-dp/2,dg +dp/2},MaxSteps->25000,MaxStepFraction->0.0002,PrecisionGoal->2]] with heat[x,a,b]:=-1+1/(Exp[(x - a)/b]+1)+1/(Exp[-(x+a)/b] being the (steep) function describing the extension of the heat source and ldrp[x,a,b]:=kg-(kg-kp)*heat[x,a,b] describing the spatial characteristics of the heat conductivity divided by the product of mass density and heat capacity. The result depends unfortunately very much on the thickness of the thin layer, although the TOTAL heat generated there is always the same (as eta=500/dp). Also, the steady-state temperature distribution in the right volume (with the cooling at the outer right boundary) where there is no heat generation should be just a function of the total generated heat and the heat conductivity of that volume. So the temperature difference should (in the steady-state) always be: u[x=dp/2]-u[x=dg+dp/2]=500/lambda_g, with lambda_g being the heat conductivity of that volume. But the results produced by Mathematica are different. Do you know what I am doing wrong or is it just that it is not possible to handle such abrupt changes? Uli === Subject: Re: Equations system with zero y/(9y) is undefined (meaningless) when y is zero. End of story. Bobby > Hi alll, Let the following equations system for x, y Reals Solve[{y/(9y)==0/(5x),x^2+3y^2},{x,y}] > {} Mathematica 6.0.1 yields no solution. But the solutions exist. They > are four solutions x=0, y=+-Sqrt[1/3] > y=0, x=+-1 Mathematica first simplifying y/(9y) -> 1/9 and it compare with 0/(5x) - >> and yiels False and it stops the process. Is this correct?. In my opinion, the correct process would be > (5*x*y)==(9*y*0) > 5xy=0 ----> x=0 or y=0 and substitution in the second equation. -- DrMajorBob@longhorns.com === Subject: Equations system with zero Hi alll, Let the following equations system for x, y Reals Solve[{y/(9y)==0/(5x),x^2+3y^2},{x,y}] {} Mathematica 6.0.1 yields no solution. But the solutions exist. They are four solutions x=0, y=+-Sqrt[1/3] y=0, x=+-1 Mathematica first simplifying y/(9y) -> 1/9 and it compare with 0/(5x) - > and yiels False and it stops the process. Is this correct?. In my opinion, the correct process would be (5*x*y)==(9*y*0) 5xy=0 ----> x=0 or y=0 and substitution in the second equation. === Subject: Re: Equations system with zero > Let the following equations system for x, y Reals Solve[{y/(9y)==0/(5x),x^2+3y^2},{x,y}] > {} Mathematica 6.0.1 yields no solution. And it is correct. > But the solutions exist. I am afraid this is an erroneous claim (see below). > They > are four solutions x=0, y=+-Sqrt[1/3] > y=0, x=+-1 Let's pick the solution {y == 0, x == 1} and plug these values into the system The second equation x^2 + 3 y^2 == 0 becomes 1^2 + 3*(0)^2 == 0 <==> 1*1 + 3*0*0 == 0 <==> 1 + 3*0 == 0 <==> 1 + 0 == 0 <==> 1 == 0 Since one is not equal to zero, we conclude that (1, 0) is not solution of the second equation. Indeed, the second equation is a sum of two squares. Since a square is always non-negative (we are working on R), the only real values for x and y that solve this equation are x == 0 and y == 0. Now, the first equation is not defined for x == 0 or y == 0, because the rules of algebra do not allows us to divide by zero. Thus, since (0, 0) is the only solution to the second equation and is not solution to the first equation (again because dividing by zero is not allowed/does not make sense), we conclude that the system has no solution. > Mathematica first simplifying y/(9y) -> 1/9 and it compare with 0/(5x) - >> and yiels False and it stops the process. Is this correct?. Yes. > In my opinion, the correct process would be > (5*x*y)==(9*y*0) > 5xy=0 ----> x=0 or y=0 What you really have here is that x == 0 and y in R, and also y ==0 and x in R. For instance, x == 0 and y == 3.14 ==> 5*0*3.14 == 0 <==> 5*0 == 0 <==> 0 == 0, which is true, thus we conclude that (0, 3.14) is a solution. x == -14 and y == 0 ==> 5*(-14)*0 == 0 <==> 5*0 == 0 <==> 0 == 0, which is true, thus we conclude that (-14, 0) is a solution. Now, keep in mind that the original equation y/(9 y) == 0/(5 x) is defined only for x != 0 and y != 0, so all the above solutions are not solutions to the original equation since each of them violates the domain of definition. > and substitution in the second equation. === Subject: Re: About the error message Indeterminate > I think you all might have been check the example the bouncer in the > entry Dynamic. But it is on a flat ground. So I want to make some > change to let it bounce on hills, which formed by Sine function. The > collisional consummation and reflection angle have been taken > considered, but when the point touches the ground, it doesn't move any > longer and the velocity shows indeterminate. I know indeterminate > means such an issue like 0/0, but I replace my reflecting function > with the colliding position and get a certain answer. I don't know if > is there any other issues will cause indeterminate. Anyway, check the code first. function[x_] := Sin[x] + 0.5 Sin[6 x]; > Reflection[{{x_, y_}, {vx_, vy_}}] := {{x, y}, > 0.8 Sqrt[vx^2 + vy^2] {Cos[2 ArcTan[function'[x]] - ArcTan[vy/vx]], > Sin[2 ArcTan[function'[x]] - ArcTan[vy/vx]]}} (* where function[] means the ground and Reflection[] shows how the > ball bounces up, where x, y means position and vx, vy means velocity. > 0.8 Is the consummation of collision, Sqrt is the norm of speed and > the latter stuff is the new velocity in x and y direction. *) PointSet = {{4, 6}, {0, -0.01}}; > Plot[function[x], {x, -5, 5}, Axes -> None, Filling -> Bottom, > PlotRange -> {{-5, 5}, {-2, 8}}, AspectRatio -> 1, > Epilog - Point[Dynamic[ > PointSet = > If[PointSet[[1, 2]] >= > function[PointSet[[1, 1]]], {PointSet[[1]] + PointSet[[2]], > PointSet[[2]] + {0, -0.001}}, Reflection[PointSet]]; > PointSet[[1]]]]] > Dynamic[PointSet] (*I used Epilog to draw the point. I didn't use Mouseclick because it > will cause a dump*) The function ArcTan[] has two forms: ArcTan[y/x], which does not trap division by zero or indeterminate forms, and ArcTan[x, y], which does handle such cases. Note that the second form may return an *Interval[]* object rather than a value. In[1]:= {ArcTan[y/x], ArcTan[x, y]} /. {x -> 0, y -> 0} During evaluation of In[1]:= Power::infy:Infinite expression 1/0 encountered. During evaluation of In[1]:= [Infinity]::indet:Indeterminate expression 0 ComplexInfinity encountered. During evaluation of In[1]:= ArcTan::indet:Indeterminate expression ArcTan[0,0] encountered. Out[1]= {Indeterminate, Interval[{-Pi, Pi}]} In[2]:= {ArcTan[y/x], ArcTan[x, y]} /. {x -> 0, y -> 1} During evaluation of In[2]:= Power::infy:Infinite expression 1/0 encountered. Out[2]= {Indeterminate, Pi/2} So you could write your function as follows: In[1]:= function[x_] := Sin[x] + 0.5 Sin[6 x]; Reflection[{{x_, y_}, {vx_, vy_}}] := {{x, y}, 0.8 Sqrt[vx^2 + vy^2] {Cos[2 ArcTan[function'[x]] - ArcTan[vx, vy]], Sin[2 ArcTan[function'[x]] - ArcTan[vx, vy]]}} PointSet = {{4, 6}, {0, -0.01}}; Plot[function[x], {x, -5, 5}, Axes -> None, Filling -> Bottom, PlotRange -> {{-5, 5}, {-2, 8}}, AspectRatio -> 1, Epilog -> Point[Dynamic[ PointSet = If[PointSet[[1, 2]] >= function[PointSet[[1, 1]]], {PointSet[[1]] + PointSet[[2]], PointSet[[2]] + {0, -0.001}}, Reflection[PointSet]]; PointSet[[1]]]]] Dynamic[PointSet] === Subject: Re: About the error message Indeterminate try ArcTan[x,y] instead of ArcTan[y/x] Jens > I think you all might have been check the example the bouncer in the > entry Dynamic. But it is on a flat ground. So I want to make some > change to let it bounce on hills, which formed by Sine function. The > collisional consummation and reflection angle have been taken > considered, but when the point touches the ground, it doesn't move any > longer and the velocity shows indeterminate. I know indeterminate > means such an issue like 0/0, but I replace my reflecting function > with the colliding position and get a certain answer. I don't know if > is there any other issues will cause indeterminate. Anyway, check the code first. function[x_] := Sin[x] + 0.5 Sin[6 x]; > Reflection[{{x_, y_}, {vx_, vy_}}] := {{x, y}, > 0.8 Sqrt[vx^2 + vy^2] {Cos[2 ArcTan[function'[x]] - ArcTan[vy/vx]], > Sin[2 ArcTan[function'[x]] - ArcTan[vy/vx]]}} (* where function[] means the ground and Reflection[] shows how the > ball bounces up, where x, y means position and vx, vy means velocity. > 0.8 Is the consummation of collision, Sqrt is the norm of speed and > the latter stuff is the new velocity in x and y direction. *) PointSet = {{4, 6}, {0, -0.01}}; > Plot[function[x], {x, -5, 5}, Axes -> None, Filling -> Bottom, > PlotRange -> {{-5, 5}, {-2, 8}}, AspectRatio -> 1, > Epilog - Point[Dynamic[ > PointSet = > If[PointSet[[1, 2]] >= > function[PointSet[[1, 1]]], {PointSet[[1]] + PointSet[[2]], > PointSet[[2]] + {0, -0.001}}, Reflection[PointSet]]; > PointSet[[1]]]]] > Dynamic[PointSet] (*I used Epilog to draw the point. I didn't use Mouseclick because it > will cause a dump*) > Tao Yue > === Subject: Re: About the error message Indeterminate On Aug 18, 3:38 pm, Jens-Peer Kuska try ArcTan[x,y] instead of ArcTan[y/x] Jens > I think you all might have been check the example the bouncer in the > entry Dynamic. But it is on a flat ground. So I want to make some > change to let it bounce on hills, which formed by Sine function. The > collisional consummation and reflection angle have been taken > considered, but when the point touches the ground, it doesn't move any > longer and the velocity shows indeterminate. I know indeterminate > means such an issue like 0/0, but I replace my reflecting function > with the colliding position and get a certain answer. I don't know if > is there any other issues will cause indeterminate. > Anyway, check the code first. > function[x_] := Sin[x] + 0.5 Sin[6 x]; > Reflection[{{x_, y_}, {vx_, vy_}}] := {{x, y}, > 0.8 Sqrt[vx^2 + vy^2] {Cos[2 ArcTan[function'[x]] - ArcTan[vy/vx]], > Sin[2 ArcTan[function'[x]] - ArcTan[vy/vx]]}} > (* where function[] means the ground and Reflection[] shows how the > ball bounces up, where x, y means position and vx, vy means velocity. > 0.8 Is the consummation of collision, Sqrt is the norm of speed and > the latter stuff is the new velocity in x and y direction. *) > PointSet = {{4, 6}, {0, -0.01}}; > Plot[function[x], {x, -5, 5}, Axes -> None, Filling -> Bottom, > PlotRange -> {{-5, 5}, {-2, 8}}, AspectRatio -> 1, > Epilog - > Point[Dynamic[ > PointSet = > If[PointSet[[1, 2]] >= > function[PointSet[[1, 1]]], {PointSet[[1]] + PointSet[[2= ]], > PointSet[[2]] + {0, -0.001}}, Reflection[PointSet]]; > PointSet[[1]]]]] > Dynamic[PointSet] > (*I used Epilog to draw the point. I didn't use Mouseclick because it > will cause a dump*) > Tao Yue === Subject: Re: Connecting pipes > Place a sphere at the connection point? e.g., Graphics3D[ > {EdgeForm[], Cylinder[{{0, 0, 0}, {0, 0, 1}}, .1], > Cylinder[{{0, 0, 0}, {1, 0, 0}}, .1], > Cylinder[{{1, 0, 0}, {1, 0, 1}}, .1], > Cylinder[{{1, 0, 1}, {0, 0, 1}}, .1], > Sphere[{0, 0, 0}, .1], > Sphere[{1, 0, 0}, .1], > Sphere[{0, 0, 1}, .1], > Sphere[{1, 0, 1}, .1] > }] - Selwyn Hollis > I'd like to draw a network of connecting of pipes (like that 3D pipe > screen saver). Supposed I have the coordinates stored in Coord, and > I'd like to connect, say, Coord[[4]] to Coord[[2]], etc. > I figure I could use the cylinder function (damned Euler angle!) to > draw a single pipe, but haven't quite figured out how to connect them > together. Any suggestion? > Caosau > PS. Bonus if I can do it with cartesian coords. I'll take a look at MathGl3D and the ref. Selwyn, Is this Cylinder function from a newer version of Mathematica? I use 5.2 and it does not seem to accept the syntax. Caosau === Subject: Re: Incorrect integral in Mathematica This has been fixed. $Version 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) Integrate[ Exp[-x^2/(2 w^2)] Exp[-(y - y0)^2/(2 z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, Assumptions -> {w > 0, z > 0}] 2*Pi*w*z Hi All, I'm getting a nonsensical answer of 0 for the following integral in Mathematica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: Hello Mathematica friends, Sometime back I posted this question on the usage of nested If[] and Piecewise[] inside NDSolve[]. I followed Oliver's reply and was able to solve that particular case. I also could solve another problem which is similar to the posted problem. But when I tried the same (like enclosing the expressions with Evaluate[]) on another notebook which has similar usage of nested If[], it did not work. I have included the code here, you can also notice that Piecewise[] also did not work here. Gopinath Student University of Oklahoma (* Code starts here *) mperl = 2303; ag = 9.81; bs = 3.757; ht = 2.1; moi = (bs ht^3)/12; emod = 2.87*10^9; sep = 8; (* sep is the axle spacing or parameter D of Fryba's *) pmI = 11515 sep^2; (* pmI is equivalent to parameter I (polar moment of inertia) of Fryba's *) spload = 508329.675; fwload = 28240.5375; rwload = 28240.5375; d1 = 0.33 sep; d2 = sep - d1; load = spload + fwload + rwload; Print[The total load of vehicle is , load]; tmass = load/ag; logdampdecbeam = 0.5; len = 25; vel = 30; (* default is 4.778 *) Tfact = len/vel; mfact = 1/(2 - sep/len); [Beta] = 1/(2 [Pi]) logdampdecbeam; (* replace logdampdecbeam with single parameter [Beta] later *) dwrf1 = 0.5; dwrf2 = 0.5; deflmid = (2 load len^3)/([Pi]^4 emod moi); [Omega][j_] := (j^2 [Pi]^2)/len^2 Sqrt[(emod moi)/mperl]; q1 = (fwload + spload d2/sep)/load; q2 = (rwload + spload d1/sep)/load; deflmid1 = q1 deflmid; deflmid2 = q2 deflmid; sK1 = (0.04 [Omega][ 1])^2 tmass; (* sK1 is equivalent to parameter Subscript[C, 1] of Fryba's and change 0.04 to some value to effect a change in srf1 *) sK2 = (0.04 [Omega][1])^2 tmass; [CapitalOmega][k_] := (k [Pi])/Tfact; vfreq = ([Pi] vel)/len; w = ([Pi] vel)/len; (* Remove this parameter later *) Print[The natural frequency of the beam is , [Omega][1]]; fs1 = 1/(2 [Pi]) Sqrt[sK1/ tmass]; (* The reason fs1 is defined like this instead of fs1 = 0.04 [Omega][1]/(2 [Pi]) or fs1 = srf1 [Omega][1]/(2 [Pi]) is to have flexibility to change sK1 later *) fs2 = 1/(2 [Pi]) Sqrt[sK2/tmass]; dsK1 = 2 dwrf1 tmass fs1; dsK2 = 2 dwrf2 tmass fs2; wK1 = (0.2 [Omega][ 1])^2 tmass; (* wK1 is equivalent to parameter Subscript[K, 1] of Fryba's and change 0.2 to effect a change in wrf1 *) wK2 = (0.2 [Omega][1])^2 tmass; fw1 = 1/(2 [Pi]) Sqrt[wK1/tmass]; fw2 = 1/(2 [Pi]) Sqrt[wK2/tmass]; Print[The frequency of sprung mass w.r.t to front wheel is , fs1]; Print[The frequency of sprung mass w.r.t to rear wheel is , fs2]; Print[The frequency of unsprung front wheel mass is , fw1]; Print[The frequency of unsprung rear wheel mass is , fw2]; [Kappa] = load/(ag mperl len); [Kappa]1 = fwload/load; [Kappa]2 = rwload/load; rI = (pmI ag)/(load sep^2); [Alpha] = vfreq/[Omega][1]; Print[The speed parameter is , [Alpha]]; srf1 = (2 [Pi] fs1)/[Omega][ 1]; (* srf1 is equivalent to Subscript[[Beta], 1] of Fryba's and if you want to change srf1, change 0.04 in sK1 definition *) srf2 = (2 [Pi] fs2)/[Omega][1]; wrf1 = (2 [Pi] fw1)/[Omega][ 1]; (* wrf1 is equivalent to Subscript[[Gamma], 1] of Fryba's and if you want to change wrf1, change 0.2 in wK1 definition *) wrf2 = (2 [Pi] fw2)/[Omega][1]; Print[srf1 equals , srf1]; Print[srf2 equals , srf2]; Print[wrf1 equals , wrf1]; Print[wrf2 equals , wrf2]; Subscript[[Omega], b] = [Beta] [Omega][1]; [Omega]jd[j_] := Sqrt[([Omega][j])^2 - Subscript[[Omega], b]^2]; dwrf1 = dsK1/(2 tmass fs1); dwrf2 = dsK2/(2 tmass fs2); step = 0; nmx = 3; bdefm = Table[v[im][t], {im, 1, nmx}]; bdefm1t = D[bdefm, t]; bdefm2t = D[bdefm, {t, 2}]; ictp1 = Table[bdefm[[im]] /. t -> 0, {im, 1, nmx}]; ictp2 = Table[1/Tfact bdefm1t[[im]] /. t -> 0, {im, 1, nmx}]; tpld[im_, t_] := If[Evaluate[0 <= t <= sep/len], Evaluate[2 q1 Sin[im [Pi] t]], Evaluate[ If[Evaluate[sep/len < t < 1], Evaluate[ 2 q1 Sin[im [Pi] t] + 2 q2 Sin[im [Pi] (t - sep/len)]], Evaluate[ If[Evaluate[1 <= t <= 1 + sep/len], Evaluate[2 q2 Sin[im [Pi] (t - sep/len)]], 0]]]]]; modset = Table[[Pi]^2 [Alpha]^2 bdefm2t[[im]] + 2 [Pi]^3 [Alpha] [Beta] bdefm1t[[im]] + im^4 [Pi]^4 bdefm[[im]] - 48 tpld[im, t], {im, 1, nmx}]; sol1 = Table[ NDSolve[{modset[[im]] == 0, ictp1[[im]] == 0, ictp2[[im]] == 0}, bdefm[[im]], {t, 0, 1 + sep/len}], {im, 1, nmx}]; bdefmsol1 = Table[Chop[bdefm[[im]] /. sol1[[im]]], {im, 1, nmx}]; bdefm1tsol1 = Table[Chop[D[bdefmsol1[[im]], t] /. sol1[[im]]], {im, 1, nmx}]; bdeftpld[x_] := !( *UnderoverscriptBox[([Sum]), (im = 1), (nmx)]((bdefmsol1[([)(im)(])] Sin[ im [Pi] x]))); (* this is the beam displacement solution we use to substitute later for iterating the vehicle beam interaction *) p1 = Plot[bdeftpld[0.5], {t, 0, 1 + sep/len}] bdeftot[x_] := Table[-bdeftpld[x], {t, 0, 1 + sep/len, (len + sep)/(20 len)}]; time = Table[t, {t, 0, 1 + sep/len, (len + sep)/(20 len)}]; xlis = Table[xs, {xs, 0, 1, 0.1}]; gridxt = {xlis, time}; bdeftotintp = Table[Chop[bdeftot[x]], {x, 0, 1, 0.1}]; func[x_, y_] := ListInterpolation[bdeftotintp, gridxt, InterpolationOrder -> 3][x, y]; pbtpldint = Plot[-func[1/2, t], {t, 0, 1 + sep/len}, PlotRange -> All, PlotStyle -> {Red}] definstxt1 = Table[If[0 <= t <= 1, Chop[func[t, t]], 0], {t, 0, 1 + sep/len, ( len + sep)/(20 len)}]; definstxt2 = Table[If[sep/len <= t <= 1 + sep/len, Chop[func[t - sep/len, t]], 0], {t, 0, 1 + sep/len, (len + sep)/(20 len)}]; Print[The deflection of beam at locations of contact of load 1 and 2 are ]; definstxt1 // MatrixForm definstxt2 // MatrixForm definstxt1itr = definstxt1; definstxt2itr = definstxt2; wdef1itr[t_] := v1[t]; wdef2itr[t_] := v2[t]; (* Start While/Do Loop from here *) bdefmitr = Table[vi[im][t], {im, 1, nmx}]; bdefmitr1t = D[bdefmitr, t]; bdefmitr2t = D[bdefmitr, {t, 2}]; icon1 = Table[bdefmitr[[im]] /. t -> 0, {im, 1, nmx}]; Print[icon1 is , icon1 // MatrixForm]; icon2 = Table[1/Tfact bdefmitr1t[[im]] /. t -> 0, {im, 1, nmx}]; Print[icon2 is , icon2 // MatrixForm]; wdef1icon1 = v1[t] /. t -> 0; wdef1icon2 = D[v1[t], t] /. t -> 0; wdef2icon1 = v2[t] /. t -> 0; wdef2icon2 = D[v2[t], t] /. t -> 0; sdeficon1 = v3[t] /. t -> 0; sdeficon2 = D[v3[t], t] /. t -> 0; phicon1 = [Phi][t] /. t -> 0; phicon2 = D[[Phi][t], t] /. t -> 0; wnet1[t_] := v3[t] + d1/sep [Phi][t] - v1[t]; wnet2[t_] := v3[t] - d2/sep [Phi][t] - v2[t]; Print[Defining the reaction forces]; reactP1[t_] := ([Pi]^4 [Kappa] wrf1^2)/ 24 (Chop[wdef1loop[t]] - Chop[func[t, t]]); (* See if we are using definstxt that is updating within loop *) reactP2[t_] := ([Pi]^4 [Kappa] wrf2^2)/ 24 (Chop[wdef2loop[t]] - Chop[func[t - sep/len, t]]); tplditr[im_?NumericQ, t_?NumericQ] := Evaluate[If[Evaluate[0 <= t < sep/len], Evaluate[reactP1[t] Sin[im [Pi] t]], Evaluate[ If[Evaluate[sep/len <= t <= 1], Evaluate[ reactP1[t] Sin[im [Pi] t] + reactP2[t] Sin[im [Pi] (t - sep/len)]], Evaluate[reactP2[t] Sin[im [Pi] (t - sep/len)]]]]]]; tplditrPiece[im_?NumericQ, t_?NumericQ] := Piecewise[{{reactP1[t] Sin[im [Pi] t], 0 <= t < sep/len}, {reactP1[t] Sin[im [Pi] t] + reactP2[t] Sin[im [Pi] (t - sep/len)], sep/len <= t <= 1}, {reactP2[t] Sin[im [Pi] (t - sep/len)], 1 < t <= 1 + sep/len}}]; phieq = -[Phi]''[t] - (d1 sK1 Tfact^2)/(sep rI tmass) wnet1[t] - ( d1 dsK1 Tfact)/(sep rI tmass) wnet1'[t] + (d2 sK2 Tfact^2)/( sep rI tmass) wnet2[t] + (d2 dsK2 Tfact)/(sep rI tmass) wnet2'[t]; v3eq = (1 - [Kappa]1 - [Kappa]2)/Tfact^2 [Alpha]^2 v3''[t] + srf1^2 [Pi]^2 wnet1'[t] + dwrf1 [Alpha] srf1 wnet1'[t] + srf2^2 [Pi]^2 wnet2[t] + dwrf2 [Alpha] srf2 wnet2'[t]; v1eq = v1''[t] - ( 24 Tfact^2)/([Pi]^2 [Kappa]1 [Kappa] [Alpha]^2) (2 q1 + ([Pi]^4 [Kappa] srf1^2 wnet1[t])/ 24 + ([Pi]^2 dwrf1 srf1 [Kappa] [Alpha] wnet1'[t])/24 - reactP1[t]); v2eq = v2''[t] - ( 24 Tfact^2)/([Pi]^2 [Kappa]2 [Kappa] [Alpha]^2) (2 q2 + ([Pi]^4 [Kappa] srf2^2 wnet2[t])/ 24 + ([Pi]^2 dwrf2 srf2 [Kappa] [Alpha] wnet2'[t])/24 - reactP2[t]); modsetitrIfloop = Table[[Pi]^2 [Alpha]^2 bdefmitr2t[[im]] + 2 [Pi]^3 [Alpha] [Beta] bdefmitr1t[[im]] + im^4 [Pi]^4 bdefmitr[[im]] - Evaluate[48 tplditr[im, t]], {im, 1, nmx}]; modsetitrPiece = Table[[Pi]^2 [Alpha]^2 bdefmitr2t[[im]] + 2 [Pi]^3 [Alpha] [Beta] bdefmitr1t[[im]] + im^4 [Pi]^4 bdefmitr[[im]] - Evaluate[48 tplditrPiece[im, t]], {im, 1, nmx}]; Print[The modsetitr equation is , modsetitrIfloop // MatrixForm]; eqn1 = Table[ Flatten[{wdef1icon1, wdef1icon2, wdef2icon1, wdef2icon2, sdeficon1, sdeficon2, phicon1, phicon2, phieq, v3eq, v1eq, v2eq, Evaluate[modsetitrIfloop[[im]]]}], {im, 1, nmx}]; eqn2 = Table[ Flatten[{wdef1icon1, wdef1icon2, wdef2icon1, wdef2icon2, sdeficon1, sdeficon2, phicon1, phicon2, phieq, v3eq, v1eq, v2eq, Evaluate[modsetitrPiece[[im]]]}], {im, 1, nmx}]; Print[eqn1 is given by , eqn1 // MatrixForm]; Print[eqn1[[1]] is given by , eqn1[[1]] // MatrixForm]; Print[eqn1 is given by , eqn2 // MatrixForm]; Print[Solving the set of equations]; solnitr1 = Table[NDSolve[{Flatten[eqn1[[im]] == 0], icon1[[im]] == 0, icon2[[im]] == 0}, bdefmitr[[im]], {t, 0, 1 + sep/len}], {im, 1, nmx}]; solnitr2 = Table[NDSolve[{Flatten[eqn2[[im]] == 0], icon1[[im]] == 0, icon2[[im]] == 0}, bdefmitr[[im]], {t, 0, 1 + sep/len}], {im, 1, nmx}]; Print[After Solving the set of equation]; Print[The solution to first set of Equations - eqn1 is given by , solnitr1 // MatrixForm]; Print[The solution to second set of Equations - eqn2 is given by , solnitr2 // MatrixForm]; (* Code ends here *) === Subject: Re: Equations system with zero >Let the following equations system for x, y Reals >Solve[{y/(9y)==0/(5x),x^2+3y^2},{x,y}] {} Mathematica 6.0.1 yields no solution. But the solutions exist. They >are four solutions >x=0, y=+-Sqrt[1/3] y=0, x=+-1 None of these solve the problem as written. For any x, y not equal to zero, the left hand side of the first equation evaluates to a non-zero value and the right hand side evaluates to 0. And if either x or y equal zero, as written one side or the other evaluates to 0/0 which is undefined. And if you fix this problem, Solve still will have a problem since the second expression isn't an equation. === Subject: Legend text font how can I set the font for a legend text? I have to use a construct with Showlegend: ShowLegend[Show[graphics,BaseStyle->{FontFamily->Arial,FontSize->16}],Le gend] The BaseStyle option does not seem to apply for the legend and I didn't find an option to set the font for the legend text. best, joerg === Subject: Fourier-Motzkin elimination Hello friends, I have a set of inequalities A . x <= b, where x is a six-element symbolic vector {x1, x2, x3, x4, x5, x6}, A is a 14x6 matrix, and b is a 14-element vector. I want to reduce these inequalities to two variables, say, x5 and x6, so that I can visualize these constraints. For example, I want to transform the above inequalities to the form: A2 . {x5, x6} <= b2 Apparently, this process is called Fourier-Motzkin elimination where you can choose which variables to eliminate. Is there a Mathematica package to do this? Ravi The University of Washington Seattle, WA === Subject: Re: Player Pro Usage > (1) Does encryption work well to keep the source > code confidential - from being viewed by the user > of the application? this topic has been discussed in almost any group for almost any interpreted language and the outcome is that whenever you deliver code, it is only a matter of how much effort someone is going to invest to view the code in one way or the other (in fact this is even true for compiled languages, in the end, the processor needs to understand the code to execute it...). Using encoding and the attributes ReadProtect and Locked for your Symbols would do a decent job in the sense that it will need good knowledge of Mathematica, criminal energy and some effort to get at your code, but there are still tricks to play. If you want to be on the (very) safe side, you shouldn't deliver code at all but deploy via webmathematica, if that's an option... > (2) Are there any limitations to the functionality > of packages that can be used with PlayPro? Specifically, > do front end dynamic capabilities like Manipulate sliders, Input Fields etc. work with PlayPro? I guess you know this: http://www.wolfram.com/solutions/interactivedeployment/compare.html Other than that, I only know that ToExpression is limited so it will only parse certain mathematical functions, mainly to prevent the programming of an alternative frontend. Maybe you can find more details on that at wolframs site... hth, albert === Subject: Re: Player Pro Usage > Does anyone have experience using PlayerPro > for distributing Mathematica Package applications? > I am especially interested in the following issues: (1) Does encryption work well to keep the source > code confidential - from being viewed by the user > of the application? (2) Are there any limitations to the functionality > of packages that can be used with PlayPro? Specifically, > do front end dynamic capabilities like Manipulate sliders, Input Fields etc. work with PlayPro? > Don > I too have a client using PlayerPro. I am confident that this technology will enable a whole range of applications where the client does not need to purchase Mathematica. Note however, that to the best of my knowledge, PlayerPro does does not add anything new in terms of encryption - you are free to encrypt your code for use with Mathematica, but with PlayerPro packages must be encrypted to prevent PlayerPro being used in an open-ended way as if it were Mathematica. This restriction, together with the restriction on modifying the contents of notebooks, does however prevent an end-user exploring your code by entering his own commands, as he could with Mathematica. I do have reservations about relying on the encryption provided by Encode, at least without the use of an explicit key (the third argument). I have discovered that if you Encode two versions of a file with just one byte difference, you only find two bytes differ in the encoded files. This suggests to me that the encryption is weak - presumably because at the time the algorithm was defined, there were restrictions on incorporating strong encryption in software for export. Even with an explicit key, the encoded files are not completely different (try the same experiment with, say PGP, for comparison). David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Player Pro Usage > Does anyone have experience using PlayerPro > for distributing Mathematica Package applications? Yes, some quite significant applications distributed through my consulting business. > I am especially interested in the following issues: (1) Does encryption work well to keep the source > code confidential - from being viewed by the user > of the application? Encryption is done using Mathematica's function Encode. Though this creates a .m file that is not directly human readable, unless you take other measures the function definitions that result from loading those files will still be readable by using Mathematica's Information function (as wellas the equivalent ?? command). There still are ways to hide the material from users, but this involves setting attributes like ReadRprotected and Locked. These however are not foolproof and a variety of tricks are still needed to preserve the full functionality of your functions when you use these. Aside from this, you need to remember that anything that your from disk using Get or Needs will need to have been saved using Encode. (2) Are there any limitations to the functionality > of packages that can be used with PlayPro? Specifically, > do front end dynamic capabilities like Manipulate sliders, Input Fields e= tc. work with PlayPro? Yes, all work in my experience and I have used them extensively.... I hope that this helps... --David A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... Trial Version at: http://scientificarts.com/worklife/ > Don === Subject: Re: Connecting pipes >> Place a sphere at the connection point? e.g., Graphics3D[ >> {EdgeForm[], Cylinder[{{0, 0, 0}, {0, 0, 1}}, .1], >> Cylinder[{{0, 0, 0}, {1, 0, 0}}, .1], >> Cylinder[{{1, 0, 0}, {1, 0, 1}}, .1], >> Cylinder[{{1, 0, 1}, {0, 0, 1}}, .1], >> Sphere[{0, 0, 0}, .1], >> Sphere[{1, 0, 0}, .1], >> Sphere[{0, 0, 1}, .1], >> Sphere[{1, 0, 1}, .1] >> }] - Selwyn Hollis > I'd like to draw a network of connecting of pipes (like that 3D pipe > screen saver). Supposed I have the coordinates stored in Coord, and > I'd like to connect, say, Coord[[4]] to Coord[[2]], etc. > I figure I could use the cylinder function (damned Euler angle!) to > draw a single pipe, but haven't quite figured out how to connect them > together. Any suggestion? > Caosau > PS. Bonus if I can do it with cartesian coords. > I'll take a look at MathGl3D and the ref. Selwyn, Is this Cylinder function from a newer version of Mathematica? I use > 5.2 and it does not seem to accept the syntax. The graphics directive *Cylinder[]* has been introduced with version 6.0. http://reference.wolfram.com/mathematica/ref/Cylinder.html === Subject: Graphing Difference Equation I have a trouble in graphing differece equation using mathematica. For instance, I get a difference equation, y_{t} = 1.5y_{t-1} - .5y_{t-2} = 0 Since I don't know how to input the code for graphics and just want to check how the graph looks like, I input the solution instead, A(-1.2)^t + B(.5)^t where A and B constants For simplicity, I choose A = B = 1. Plot[(-1.2)^t + (.5)^t,{t,0,20}] The problem is that it doesn't work at all. If anyone who know exact way to graph difference equation, plz tell me. === Subject: Re: Graphing Difference Equation a) you have serious problems with the Mathematica syntax the equation y_{t} = 1.5y_{t-1} - .5y_{t-2} = 0 is total nonsense because you have either y[t] == 3*y[t - 1]/2 - y[t - 2]/2 or 3*y[t - 1]/2 - y[t - 2]/2==0 or y[t]==0 b) If you have a discrete equation you must plot discrete values and not a continuous function, i.e. sol = y[t] /. RSolve[y[t] == 3*y[t - 1]/2 - y[t - 2]/2, y[t], t][[1]]; ListPlot[Table[Evaluate[sol /. {C[1] -> 1 , C[2] -> 0}], {t, 0, 10}]] Jens I have a trouble in graphing differece equation using mathematica. For instance, I get a difference equation, y_{t} = 1.5y_{t-1} - .5y_{t-2} = 0 Since I don't know how to input the code for graphics and just want to check how the graph looks like, I input the solution instead, A(-1.2)^t + B(.5)^t where A and B constants For simplicity, I choose A = B = 1. Plot[(-1.2)^t + (.5)^t,{t,0,20}] The problem is that it doesn't work at all. If anyone who know exact way to graph difference equation, plz tell me. === Subject: Conflicting Switch Statements Hi Folks, Why is it if you place 2 switch statements next to each other (as in the test code below), the presence of the second switch interferes with proper execution of the first? I feel like I'm missing something fundamental. Would you have any ideas on how to make both switch statements co-exist peacefully, as I really need a good way to control which portions of code get executed inside a manipulate statement? Todd Manipulate[ Switch[var1,0,(result=1),1,(result=2)]; Switch[var2,0,(result=3),1,(result=4)]; result, {{var1,0},{0->Ok,1->Now},ControlType->PopupMenu}, {{var2,0},{0->Please,1->Work},ControlType->PopupMenu}] === Subject: Re: Conflicting Switch Statements since Switch[var2,0,(result=3),1,(result=4)]; is executed *after* Switch[var1,0,(result=1),1,(result=2)]; it will always win because you mean something like If[changed[var1], Switch[var1, 0, (result = 1), 1, (result = 2)] ]; If[changed[var2], Switch[var2, 0, (result = 3), 1, (result = 4)] ]; Jens > Hi Folks, Why is it if you place 2 switch statements next to each other (as in the test code below), the presence of the second switch interferes with proper execution of the first? I feel like I'm missing something fundamental. Would you have any ideas on how to make both switch statements co-exist peacefully, as I really need a good way to control which portions of code get executed inside a manipulate statement? Todd Manipulate[ Switch[var1,0,(result=1),1,(result=2)]; Switch[var2,0,(result=3),1,(result=4)]; result, {{var1,0},{0->Ok,1->Now},ControlType->PopupMenu}, {{var2,0},{0->Please,1->Work},ControlType->PopupMenu}] > > === Subject: LaTex to Mathematica Hi all Does anyone know how to convert LaTex file to Mathematica ? For example, the formula that I typed in LaTex is: ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1} If I copy the above LaTex command to Mathematica, it only shows the original LaTex command. I'd like to have symbols for beta, alpha, and also for subscript and superscript. That is, I hope it looks like the pdf file that LaTex produces instead of showing beta, alpha, etc. Please advise. -- Message posted using http://www.talkaboutcomputing.com/group/comp.soft-sys.math.mathematica/ More information at http://www.talkaboutcomputing.com/faq.html === Subject: Re: LaTex to Mathematica > Does anyone know how to convert LaTex file to Mathematica ? > For example, the formula that I typed in LaTex is: > ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1} > If I copy the above LaTex command to Mathematica, it only shows the > original LaTex command. I'd like to have symbols for beta, alpha, and also > for subscript and superscript. That is, I hope it looks like the pdf file > that LaTex produces instead of showing beta, alpha, etc. code you have adheres to this standard, you will get varying results with the automatic conversion process. Converting a LaTeX file can be done via the command *Import* [1], e.g. Import[filename.tex] If you want to convert just one expression in TeX/LaTeX, you can use use ToExpression with the option TeXForm [2, 3]. Note that the expression must be enclosed within double quotes, must start and end with a dollar sign, and backlashes must be repeated. In[12]:= ToExpression[$ln{H}^{*}&={X}_{1} {beta}_{1}+{alpha}_{1}lnE+{varepsilon}_{1}$, TeXForm] Out[12]= l n !(*SuperscriptBox[H, *]) == E l n Subscript[[Alpha], 1] + Subscript[X, 1] Subscript[[Beta], 1] + Subscript[[Epsilon], 1] - Jean-Marc [1] http://reference.wolfram.com/mathematica/ref/format/LaTeX.html [2] http://reference.wolfram.com/mathematica/ref/TeXForm.html [3] http://reference.wolfram.com/mathematica/ref/ToExpression.html === Subject: Re: LaTex to Mathematica ImportString[ $ln{H}^{*}&={X}_{1} {beta}_{1}+{alpha}_{1}lnE+{varepsilon}_{1}$, TeX] // NotebookPut ?? Jens > Hi all > Does anyone know how to convert LaTex file to Mathematica ? > For example, the formula that I typed in LaTex is: > ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1} > If I copy the above LaTex command to Mathematica, it only shows the > original LaTex command. I'd like to have symbols for beta, alpha, and also > for subscript and superscript. That is, I hope it looks like the pdf file > that LaTex produces instead of showing beta, alpha, etc. > Please advise. -- > Message posted using http://www.talkaboutcomputing.com/group/comp.soft-sys.math.mathematica/ > More information at http://www.talkaboutcomputing.com/faq.html === Subject: reconstruction of 3D grid with connectivity For surface ParametricPlot3D[{x = f(u,v), y = g(u,v), z = h(u,v)}, {u,umin,umax,ustep},{v,vmin,vmax,vstep}] how to obtain the connectivity matrix (when u and v are each incremented by given ustep and vstep), using Delaunay or Voronoi triangulations? In this case there would be curved or skewed quadrilaterals instead of triangles that discretizes the surface.When connectivity matrix and coordinate matrix are given with each point ID reference number, the surface should be reconstructed, i.e., plotted, and/or Shown without again giving out the above command. Narasimham === Subject: Re: reconstruction of 3D grid with connectivity a) your assumption when u and v are each incremented by given ustep and vstep because ParametricPlot3D[] make a irregular triangle mesh you can see the mesh with plt=ParametricPlot3D[{Cos[phi]*Sin[th], Sin[phi]*Sin[th], Cos[th]}, {th, 0, Pi}, {phi, 0, 2 Pi}, Mesh -> All] b) the connectivity can be shown with GraphPlot[ Union[Flatten[(Rule @@@ Partition[#, 2, 1, {-1}]) & /@ Cases[plt, _Polygon, Infinity][[1, 1]] /. (a_ -> b_) /; a > b :> (b -> a)] ]] Jens > For surface ParametricPlot3D[{x = f(u,v), y = g(u,v), z = h(u,v)}, > {u,umin,umax,ustep},{v,vmin,vmax,vstep}] how to obtain the connectivity matrix (when u and v are each > incremented by given ustep and vstep), using Delaunay or Voronoi > triangulations? In this case there would be curved or skewed > quadrilaterals instead of triangles that discretizes the surface.When > connectivity matrix and coordinate matrix are given with each point > ID reference number, the surface should be reconstructed, i.e., > plotted, and/or Shown without again giving out the above command. > Narasimham === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: > Sometime back I posted this question on the usage of nested If[] and Piecewise[] inside NDSolve[]. I followed Oliver's reply and was able to solve that particular case. I also could solve another problem which is similar to the posted problem. But when I tried the same (like enclosing the expressions with Evaluate[]) on another notebook which has similar usage of nested If[], it did not work. I have included the code here, you can also notice that Piecewise[] also did not work here. > Apparently, you have forgotten to provide the definitions of the functions v1, v2, and v3. I cannot find any in the posted code nor can NDSolve. ----------- Some parts of the output generated [... snip ...] eqn1 is given by ([NoBreak]v1[0] (v1^[Prime])[0] v2[0] (v2^[Prime])[0] v3[0] (v3^[Prime])[0] [Phi][0] ([Phi]^[Prime])[0] 0.533478+3.35388 (-v2[t]+v3[t]-0.67 [Phi][t])-1.65191 (-v1[t]+v3[t]+0.33 [Phi][t])-0.262758 (-(v1^ [Prime])[t]+(v3^[Prime])[t]+0.33 ([Phi]^[Prime])[t])-([Phi]^ [... snip ....] [Pi]^4 vi[3][t]+1.23953 (vi[3]^[Prime])[t]+0.155674 (vi[3]^[Prime] [Prime])[t] [NoBreak]) Solving the set of equations NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. [... snip ...] ----------------- End of output === Subject: Mathematica and Jaws I have some questions on working with Mathmatica 6.0 by means of Jaws. Jaws is screenreader for poor eyesight users. This program can pronounce only textual information. So, there is a problem with reading two-level expression in Mathematica, Greek letters and so on. Jaws can read inputform expression, but not standardform and outputform (as I believe it is due to boxes). So, the questions are: 1. How to make Mathematica complitly work in inputform? 2. How to make Mathematica preferences dialog became readable? The ordinary Window's dialoges are readable but Mathematica's not. 3. If there way to make all Mathematica settings in notepad or in nb file? 4. How to make Messages (and information ? ) to be generated in inputform, not in boxes, but jast like plain text? 5. If there way to convert help into textform or inputform with no boxes? 6. What setting you use (if you work with Jaws) to better working with Jaws and Mathematica? 7. How to make Greek letters readable? Any sugestions are helpful! === Subject: Re: Mathematica and Jaws > Hello! > I have some questions on working with Mathmatica 6.0 by means of Jaws. > Jaws is screenreader for poor eyesight users. This program can > pronounce only textual information. So, there is a problem with > reading two-level expression in Mathematica, Greek letters and so on. > Jaws can read inputform expression, but not standardform and > outputform (as I believe it is due to boxes). > So, the questions are: > 1. How to make Mathematica complitly work in inputform? > 2. How to make Mathematica preferences dialog became readable? The > ordinary Window's dialoges are readable but Mathematica's not. > 3. If there way to make all Mathematica settings in notepad or in nb > file? > 4. How to make Messages (and information ? ) to be generated in > inputform, not in boxes, but jast like plain text? > 5. If there way to convert help into textform or inputform with no > boxes? > 6. What setting you use (if you work with Jaws) to better working with > Jaws and Mathematica? > 7. How to make Greek letters readable? Any sugestions are helpful! > Is this for you personally, or is it part of a larger project, where more effort might be appropriate. If it is for you personally, and you are partially sighted, I would explore the notebook magnification control in the bottom right hand side of every notebook, that can give you up to 300% magnification if you need it. You could also create a stylesheet using very large fonts. I would imagine that spoken inputform will be very hard to comprehend if the expressions are at all complicated. If Jaws has an API, accessible from Java, it might be more effective to write a Mathematica program to interpret some subset of expressions in a mathematically meaningful way. You could attach this to $Post so that each line of output would be interpreted as it was generated. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Legend text font > how can I set the font for a legend text? I have to use a construct with Showlegend: ShowLegend[Show[graphics,BaseStyle->{FontFamily->Arial,FontSize->16}],Leg end] The BaseStyle option does not seem to apply for the legend and I didn't > find an option to set the font for the legend text. http://reference.wolfram.com/mathematica/ref/Style.html Arguably not the best work of art ever, but this is just an example :) ShowLegend[ Plot[Sin[x], {x, 0, 10}, Filling -> Axis, FillingStyle -> {Red, Blue}, BaseStyle -> {FontFamily -> Arial, FontSize -> 16}], {{{Graphics[{Blue, Disk[{0, 0}, 1]}], Style[Sin[x] > 0, FontFamily -> Courier, Bold, FontSize -> Large]}, {Graphics[{Red, Disk[{0, 0}, 1]}], Style[Sin[x] < 0, FontFamily -> Helvetica, Underlined, FontSize -> Tiny]}}}] === Subject: Re: NDSolve > I was trying to solve the heat equation with NDSolve(one spatial dimension, x, and time t). The simulated device (centered around x=0) consists of three regions: Two rather big volumina (with thickness each being dg) to the left and right of a thin layer (with thickness dp). A heat source is only present in the thin layer. The outer left boundary of the whole device is open, i.e. the spatial derivative of the temperature is zero there. At the right boundary, there is perfect cooling, i.e. the temperature stays constant. > As the heat is generated only in the thin layer, the change is quite abrupt. What I would like to know is if there is a way to tell Mathematica to place a very fine grid there because the result I get is not correct. Here is the code: > dp=1e-5; > dg=1e-3; > eta=500/dp; sol=u/.First[ > NDSolve[D[u[t, x],t]==ldrp[x,0.5*dp,0.1*dp]*D[u[t,x],(x,2)]+eta*heat[x,0.5*dp,0.1*dp], > u[0,x]==0,D[u[t,-dg-dp/2],x]==0,u[t,dg+dp/2]==0},u,{t,0,tmax},{x,-dg-dp/2,dg+ dp/2},MaxSteps->25000,MaxStepFraction->0.0002,PrecisionGoal->2]] with > heat[x,a,b]:=-1+1/(Exp[(x - a)/b]+1)+1/(Exp[-(x+a)/b] > being the (steep) function describing the extension of the heat source and > ldrp[x,a,b]:=kg-(kg-kp)*heat[x,a,b] > describing the spatial characteristics of the heat conductivity divided by the product of mass density and heat capacity. > The result depends unfortunately very much on the thickness of the thin layer, although the TOTAL heat generated there is always the same (as eta=500/dp). > Also, the steady-state temperature distribution in the right volume (with the cooling at the outer right boundary) where there is no heat generation should be > just a function of the total generated heat and the heat conductivity of that volume. So the temperature difference > should (in the steady-state) always be: > u[x=dp/2]-u[x=dg+dp/2]=500/lambda_g, > with lambda_g being the heat conductivity of that volume. > But the results produced by Mathematica are different. > Do you know what I am doing wrong or is it just that it > is not possible to handle such abrupt changes? Mathematica has few syntactic rules and convention; however, these rules and conventions must be followed rigorously and they may differ significantly from other programming languages and CAS. For instance, the following input is almost certainly not what you want: In[1]:= dp = 1e-5 dg = 1e-3 eta = 500/dp Out[1]= -5+e Out[2]= -3+e Out[3]= 500/(-5+e) I believe that what you meant is In[4]:= dp = 10^-5 dg = 10^-3 eta = 500/dp Out[4]= 1/100000 Out[5]= 1/1000 Out[6]= 50000000 Also, parentheses and curly brackets are not interchangeable: In[12]:= D[u[t,x],(x,2)] During evaluation of In[12]:= Syntax::sntxf: ( cannot be followed by x,2). During evaluation of In[12]:= Syntax::tsntxi: x,2 is incomplete; more input is needed. During evaluation of In[12]:= Syntax::sntxi: Incomplete expression; more input is needed. The correct syntax is: In[7]:= D[u[t,x],{x,2}] Out[7]= (u^(0,2))[t,x] The following partial derivative always evaluates to zero since it is independent of the variable x: In[8]:= D[u[t,-dg-dp/2],x] Out[8]= 0 In[9]:= heat[x,a,b]:=-1+1/(Exp[(x-a)/b]+1)+1/(Exp[-(x+a)/b] ) ldrp[x,a,b]:=kg-(kg-kp)*heat[x,a,b] Note that NDSolve failed because you have not provided a value for tmax and the condition D[u[t, -dg - dp/2], x] == 0 is meaningless for it is always true. In[11]:= NDSolve[{D[u[t, x], t] == ldrp[x, 0.5*dp, 0.1*dp]*D[u[t, x], {x, 2}] + eta*heat[x, 0.5*dp, 0.1*dp], u[0, x] == 0, D[u[t, -dg - dp/2], x] == 0, u[t, dg + dp/2] == 0}, u, {t, 0, tmax}, {x, -dg - dp/2, dg + dp/2}, MaxSteps -> 25000, MaxStepFraction -> 0.0002, PrecisionGoal -> 2] During evaluation of In[11]:= NDSolve::deqn: Equation or list of equations expected instead of True in the first argument {<<1>>}. Out[11]= NDSolve[{(u^(1,0))[t,x]==50000000 heat[x,5.*10^-6,1.*10^-6]+ldrp[x,5.*10^-6,1.*10^-6] (u^(0,2))[t,x],u[0,x]==0,True,u[t,201/200000]==0},u, {t,0,tmax},{x,-(201/200000),201/200000}, MaxSteps->25000,MaxStepFraction->0.0002,PrecisionGoal->2] So, you should post some code on MathGroup (this list/newsgroup) that one can easily cut and past into Mathematica and that reproduces the problem you have. === Subject: Re: Fourier-Motzkin elimination > Hello friends, I have a set of inequalities A . x <= b, where x is a six-element symbolic vector {x1, x2, x3, x4, x5, x6}, A is > a 14x6 matrix, and b is a 14-element vector. I want to reduce these inequalities to two variables, say, x5 and x6, so > that I can visualize these constraints. For example, I want to > transform the above inequalities to the form: A2 . {x5, x6} <= b2 Apparently, this process is called Fourier-Motzkin elimination where you > can choose which variables to eliminate. Is there a Mathematica package > to do this? Ravi > The University of Washington > Seattle, WA Here is a package which I submitted to the Wolfram Library Archive; it uses Fourier-Motzkin elimination to eliminate variables from a system f linear inequalities. -- Christopher J. Henrich chenrich@monmouth.com htp://www.mathinteract.com === Subject: Re: Need a Faster Solution to Number Theory Problem > I got hooked on the following little number theory problem which appears in > the August issue of Discovery magazine. Susan has more than one dollar in > change, but she still can't make exact change for a dollar bill. What is the > maximum amount of money that Susan could have in pennies, nickels, dimes and > quarters for this to be true? I solved the problem using the following Mathematica code: coins={1,5,10,25}; > dollar=FrobeniusSolve[coins,100]; Catch[Do[t=Times@@Length/@(Cases[dollar,{p_,n_,d_,q_}/; (p<=#1&&n<=#2 && > d<=#3 && q<=#4)]&@@@FrobeniusSolve[coins,a]); > If[t==0,Throw[a]],{a,130,101,-1}]] Starting with a maximum guess of $1.30 this gives the correct answer of > $1.19 in about 5 seconds. The problem is that if the problem is made more > complicated by adding more possible coin denominations (and/or paper > currency) the execution time become very long indeed. Is there a way to speed up the solution to this type of problem so that I > can handle more complicated cases in a reasonable time? > John Late response, but I didn't get time to look hard at this until now. It seems to be a difficult problem in terms of complexity, though I'm not certain I have the best possible approach. First the uninteresting case: if one denomination does not divide the avoided amount then the answer is infinity. So we'd want to rule out that case, and just handle the rest under the assumption that all denominations divide the value we need to avoid. Here, in brief, is one way to go about this. The set of solutions to the Frobenius instance problem carve out a staircase in the denominations. Any set giving a maximum value must always have an element below the elbows of this staircase. In effect this gives a domain quite similar to the fundamental domain of the Frobenius number problem, as discussed here: http://www.integers-ejcnt.org/vol7.html (look for A15: Frobenius Numbers by Lattice Point Enumeration) or http://citeseerx.ist.psu.edu/viewdoc/summary;jsessionid=A56BBBFE608FF49E382B E25E84F2EBC3?doi=10.1.1.88.9057 Given the elbows, we need to find a maximal corner, with l_1 norm (that is, Manhattan distance) weighted by the set of denominations. There are various ways to do this. I'll give code for one such below (it's adapted from code related to the paper at the URLs above). Other ways involve ideas from the theory of monomial ideals; see work by Bjarke Roune for details on efficient approaches. the reference. I simply mention that there might be ways to simplify it because the original was written for a slightly different problem, and I may have missed modifications that could make it better for the problem now at hand. Suffice it to say that the slow step is in tracking through all the corners to find the largest. Possibly there is a smart way to improve on this. dominationKernel[X_] := Module[{Y = X[[Ordering[Map[Tr, X]]]], Z, i = 2, len = 1, k}, Z = Table[{}, {Length[Y]}]; Z[[1]] = Y[[1]]; While[i <= Length[Y] && Tr[Y[[i]]] == Tr[Y[[1]]], len++; Z[[len]] = Y[[i]]; i++]; Do[k = 1; While[k <= len, If[And @@ Thread[Z[[k]] <= Y[[j]]], k = len + 2; Break[], k++]]; If[k == len + 1, len++; Z[[len]] = Y[[j]]], {j, len + 1, Length[Y]}]; Sort[Take[Z, len]]] ClearNegsAndDeleteZeroVector[vecs_] := If[vecs == {}, {}, Union[DeleteCases[vecs /. _?Negative :> 0, Table[0, {Length[vecs[[1]]]}]]]]; farthest[corns_, A_] := Fold[If[#2.A > #1[[2]], {#2, #2.A}, #1] &, {Table[0, {Length[A]}], 0}, corns][[1]] FarthestCorner[A_, elbows_?MatrixQ] := Module[{pts, p1, p2, B, cc, trQ, farvertex, maxes, currfar}, currfar = farthest[elbows, A].A; pts = Select[elbows, #[[1]] > 0 &]; Scan[({p1, p2} = {First[#], Rest[#]}; B = Rest /@ Select[elbows, #[[1]] < p1 &]; B = dominationKernel[ ClearNegsAndDeleteZeroVector[# - p2 & /@ B]]; maxes = Prepend[Max /@ Transpose[B], 0]; If[(maxes + #).A > currfar, cc = FarthestCornerSub[A, B, currfar, #]; farvertex = farthest[Prepend[# + p2, p1] & /@ cc, A]; currfar = Max[currfar, farvertex.A]; ]) &, pts]; {currfar - Total[A], farvertex - 1}] /; Length[elbows[[1]]] > 2; FarthestCorner[A_, elbows_?MatrixQ] := farthest[FarthestCornerSub[A, elbows], A].Rest[A] - Total[A] /; Length[elbows[[1]]] == 2 FarthestCornerSub[A_, elbows_, currfar_, backdata_] := Module[{p1, p2, pts, B, maxes}, pts = Select[elbows, First[#] > 0 &]; Flatten[Map[( {p1, p2} = {#[[1]], Rest[#]}; B = Rest /@ Select[elbows, First[#] < p1 &]; B = dominationKernel[ ClearNegsAndDeleteZeroVector[# - p2 & /@ B]]; If[B == {}, {}, maxes = Prepend[Max /@ Transpose[B], 0]; If[(PadLeft[maxes + #, Length[A]] + backdata).A > currfar, Prepend[# + p2, p1] & /@ FarthestCornerSub[A, B, currfar, PadLeft[#, Length[A]] + backdata], {}] ]) &, pts], 1]] /; Length[elbows[[1]]] > 2; FarthestCornerSub[_, elbows_, ___] := (Partition[ Take[Flatten[Reverse /@ Reverse[elbows]], {2, -2}], 2]) /; Length[elbows[[1]]] == 2; maxNoChange[coins_List, amount_Integer /; amount >= 1] /; Not[And @@ Map[IntegerQ, amount/coins]] := Infinity maxNoChange[coins_List, amount_Integer /; amount >= 1] := FarthestCorner[coins, FrobeniusSolve[coins, amount]] Your example: In[230]:= maxNoChange[{1, 5, 10, 25}, 100] // Timing Out[230]= {0.96806, {119, {4, 0, 4, 3}}} We'll add one coin and up the amount. In[231]:= maxNoChange[{1, 5, 10, 25, 50}, 150] // Timing Out[231]= {13.9929, {169, {4, 0, 4, 1, 2}}} It gets slow quickly, so to speak. In[235]:= maxNoChange[{1, 5, 10, 25, 50}, 200] // Timing Out[235]= {82.3371, {219, {4, 0, 4, 1, 3}}} Daniel Lichtblau Wolfram Research === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage: Hello Jean, I use v1[t], v2[t], v3[t], phi[t](symbol phi) and vi[i][j] as unknown functions (you can say variables, thats why I introduced 5 equations and 10 initial conditions). I sincerely believe there should not be any problem as such in doing so. The last time I posted, Oliver and DrMajorBob, both pointed out that the parts of the expressions inside the If[] remain unevaluated. For that I used Evaluate[] for each of the parts/expressions inside If[] and it worked - produced same result as the Piecewise[] did. Now for this case (which is very similar), the Piecewise[] itself did not work. Thats why I am clueless. (* Working sample code starts here *) sep = 1; len = 3; wdef1[t_] := y[t]; wdef2[t_] := y[t]; val1 = 50; val2 = 20; xv = 1/2; yv = 1/5; funifcase2[t_] := Evaluate[If[Evaluate[0 <= t < sep/len], Evaluate[val1 + val1 xv yv^2 (wdef1[t]) Sin[t]], Evaluate[ If[Evaluate[sep/len <= t <= (2 sep)/len], Evaluate[ val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]], Evaluate[ If[Evaluate[(2 sep)/len < t <= 1], Evaluate[ val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]]]]]; (* previous definition of funifcase2[t] -- not working *) (* funifcase2[t_] := If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], If[sep/len <= t <= (2 sep)/len, val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], If[(2 sep)/len < t <= 1, val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]; *) funifcase3[t_] := Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], 0 <= t < sep/len}, {val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], sep/len <= t <= (2 sep)/len}, {val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= 1}}]; Chop[Table[funifcase2[t], {t, 0, 1, 0.1}]] Print[compare values, just to check the correctness of equation above]; Chop[Table[funifcase3[t], {t, 0, 1, 0.1}]] Print[The definition funifcase2[t] is , funifcase2[t]]; Print[The definition funifcase3[t] is , funifcase3[t]]; ?funifcase2 ?funifcase3 solifcase2 = NDSolve[{y''[t] + y'[t] + y[t] - funifcase2[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; Plot[Evaluate[{y[t], y'[t]} /. solifcase2], {t, 0, 1}, PlotStyle -> Automatic] Print[Proceeding to solve the above equation with Piecewise definition]; solifcase3 = NDSolve[{y''[t] + y'[t] + y[t] - funifcase3[t] == 0, y[0] == 0, y'[0] == 1}, y, {t, 0, 1}]; Plot[Evaluate[{y[t], y'[t]} /. solifcase3], {t, 0, 1}, PlotStyle -> {Black, {Red, Dashed}}] (* Code ends here *) === Subject: NURBS Package Available It has been suggested a number of times that the ability to export analytic surfaces to a CAD interchange format (IGES, STEP, DXF, etc) would be valuable. I have developed a package that enables one to create and export B-spline curves and surfaces based on user-supplied control points, data points, or analytic functions. The idea is that the user has control over the creation of the B-spline object, and so the creation of the IGES file and its fidelity in the CAD package is completely predictable. It will be located at my website, http://www.thebushman.net. It is a work in progress, so please be kind, and be sure to leave some constructive comments. The package was developed in part with assistance from Wolfram Research staff, as part of their 2008 Advanced Mathematica Summer School. Steve B === Subject: Re: Solving nonlinear inequality constraints Daniel's suggestions have led me to refine my notebook (below), which has reduced memory usage slightly and thereby allowed a marginally increased projection period from 9 to 10 periods: 1. Introducing a function for mu[t_] - this has not been achieved. Perhaps I am missing something very major but I cannot see how this can be done! As soon as mu[1], mu[2] are generated in variables, they are immediately evaluated by the arbitrary function (such as mu[t_]:=0.5). The effect of providing functions for all the variables is to evaluate the objective and constraints. Therefore, NMinimize merely has a numeric value for the objective function, a set of true and false for the constraints, and no variables for optimising. The notebook below shows that not only mu[t] but also variables like k[t] and s[t] need to be freed for optimization (as in the standard Nordhaus model), which I can only see means that variables cannot be given their own functions. 2. Removing Hold - the need for Hold is removed by using _?NumberQ in functions to prevent the symbolic evaluation that would otherwise occur. The first notebook below has this feature. The second notebook continues to use Holds, which are eliminated before the NMinimize function. I have some preference for the Hold approach because answers with small numbers of periods can be different than when _?NumberQ is used and I tend to think symbolic answers are more accurate. 3. Using the Hold approach (ie. without using _?NumberQ in functions) provides the following performance and memory usage on an intel 64bit/16Gb: Projection Compilation Total Memory Periods Time Minutes Mb 5 1.0 sec 1.2 234 6 2.4 secs 2.4 535 7 8.9 secs 24.8** 1234 8 0.5 mins 12.8 2572 9 2.3 mins 40.9 4943 10 9.4 mins 66.3 8908 11 33.5 mins* runs out of memory * 10.5Gb used in compilation phase ** looks odd but retested and this was the same result, so perhaps its due to the shape of the curve Usually at 6 periods and upwards there were one or two complaints that NMinimize::incst: NMinimize was unable to generate any initial points satisfying the inequality constraints but the function kept running to a final solution. 4. As previously observed, the result using _?NumberQ in functions is surprisingly similar to that with Hold. There is a shorter compilation phase of 1 minute offset by longer optimisation phase of 1.5 minutes, resulting in a slightly longer calculation period. The comparative statistics for 10 periods are: Approach Compilation Total Memory Minutes Minutes Mb Hold 9.4 mins 66.3 8908 _?NumberQ 8.3 mins 66.8 8901 Conclusion: It is some success that the number of projection periods has increased from 8 to 10. However, I still need to ramp-up to 60 periods and would like to achive this in less than an hour if possible. The continued interest of Daniel and participants on this list is warmly appreciated! Stuart **** Notebook using _?NumberQ **** (*AppendTo[$Echo,stdout];*) (*SetOptions[stdout,PageWidth->110] ; *) (* Nordhaus Brief Climate Change Policy Model May 2008 *) (* Stuart Nettleton July 2008 *) starttime = AbsoluteTime[]; periods = 5; (* projection periods *) maxit = 5000; (* maximum iterations *) (* objective function *) (* program always minimises, so negative for maximisation *) obj = {-cumu[periods]}; (* optimisation variables: topolology leaves *) (* .. for NMinimize provide both upper and lower bounds *) (* .. for FindMinimum provide a single start estimate *) (* hold function prevents premature evaluation *) (*opt = {{[Mu][t],0.001,1},{k[t],100,10000}};*) opt = {{[Mu][t], 0.001, 1}}; (* exogenous parameters *) pop0 = 6514; popg = 0.35; popa = 8600; dela = 0.001; d[Sigma]1 = 0.003; d[Sigma]2 = 0.000; pback = 1.17; backrat = 2; gback = 0.05; [Rho] = 0.015; fex0 = -0.06; fex1 = 0.30; [Kappa]1 = 1; [Kappa]2 = 1; [Kappa]21 = 1; d[Kappa] = 0; [Theta] = 2.8; sr = 0.22; (* exogenous variables *) gfacpop[t_] := gfacpop[t] = (Exp[popg*(t - 1)] - 1)/Exp[popg*(t - 1)]; l[t_] := l[t] = pop0*(1 - gfacpop[t]) + gfacpop[t]*popa; ga[t_] := ga[t] = ga[0]*Exp[-dela*10*(t - 1)]; a[t_] := a[t] = a[t - 1]/(1 - ga[t - 1]); g[Sigma][t_] := g[Sigma][t] = g[Sigma][0]* Exp[-d[Sigma]1*10*(t - 1) - d[Sigma]2*10*(t - 1)^2]; [Sigma][t_] := [Sigma][t] = [Sigma][t - 1]/(1 - g[Sigma][t]); [CapitalTheta][ t_] := [CapitalTheta][ t] = (pback*[Sigma][t]/[Theta])*((backrat - 1 + Exp[-gback*(t - 1)])/backrat); eland[t_] := eland[t] = eland[0]*(1 - 0.1)^(t - 1); r[t_] := r[t] = 1/(1 + [Rho])^(10*(t - 1)); fex[t_] := fex[t] = fex0 + If[t < 12, 0.1*(fex1 - fex0)*(t - 1), 0.36]; [Kappa][t_] := [Kappa][t] = If[t >= 25, [Kappa]21, [Kappa]21 + ([Kappa]2 - [Kappa]21)* Exp[-d[Kappa]*(t - 2)]]; [CapitalPi][t_] := [CapitalPi][t] = [Kappa][t]^(1 - [Theta]); (*s[t_]:= s[t] =sr;*) (* initial values of exogenous variables *) ga[0] = 0.092; a[1] = a[0] = 0.02722; g[Sigma][0] = -0.0730; [Sigma][1] = [Sigma][0] = 0.13418; eland[0] = 11; [Kappa][1] = [Kappa][0] = 0.25372; (* endogenous parameters *) [Alpha] = 2.0; [Gamma] = .30; [Delta] = 0.1; [Eta] = 3.8; t2xco2 = 3; [Psi]1 = 0.00000; [Psi]2 = 0.0028388; [Psi]3 = 2.00; [Xi]1 = 0.220; [Xi]2 = [Eta]/t2xco2; [Xi]3 = 0.300; [Xi]4 = 0.050; [Phi]12 = 0.189288; [Phi]12a = 0.189288; [Phi]11 = 1 - [Phi]12a; [Phi]23 = 0.05; [Phi]23a = 0.05; [Phi]21 = 587.473*[Phi]12a/1143.894; [Phi]22 = 1 - [Phi]21 - [Phi]23a; [Phi]32 = 1143.894*[Phi]23a/18340; [Phi]33 = 1 - [Phi]32; mat1750 = 596.4; k0 = 137; y0 = 61.1; c0 = 30; mat0 = 808.9; mup0 = 1255; mlo0 = 18365; tat0 = 0.7307; tlo0 = 0.0068; [Mu]0 = 0.005; ceind0 = 0; cumu0 = 381800; scale1 = 194; (* endogenous equality constraints*) ceind[t_?NumberQ] := eind[t - 1] + ceind[t - 1]; eind[t_?NumberQ] := 10 *[Sigma][t] *(1 - [Mu][t]) *ygr[t] + eland[t]; for[t_?NumberQ] := [Eta]*(Log[(matav[t] + 0.000001)/mat1750]/ Log[2]) + fex[t]; mat[t_?NumberQ] := eind[t - 1] + [Phi]11*mat[t - 1] + [Phi]21*mup[t - 1]; matav[t_?NumberQ] := (mat[t] + mat[t + 1])/2; mlo[t_?NumberQ] := [Phi]23*mup[t - 1] + [Phi]33*mlo[t - 1]; mup[t_?NumberQ] := [Phi]12*mat[t - 1] + [Phi]22* mup[t - 1] + [Phi]32*mlo[t - 1]; tat[t_?NumberQ] := tat[t - 1] + [Xi]1*(for[t] - [Xi]2* tat[t - 1] - [Xi]3*(tat[t - 1] - tlo[t - 1])); tlo[t_?NumberQ] := tlo[t - 1] + [Xi]4*(tat[t - 1] - tlo[t - 1]); ygr[t_?NumberQ] := a[t]* k[t]^[Gamma] *l[t]^(1 - [Gamma]); dam[t_?NumberQ] := ygr[t]*(1 - 1/(1 + [Psi]1*tat[t] + [Psi]2*(tat[t]^[Psi]3))); [CapitalLambda][t_?NumberQ] := ygr[t] *[CapitalPi][t] *[CapitalTheta][t] *[Mu][t]^[Theta]; y[t_?NumberQ] := ygr[t]*(1 - [CapitalPi][t]*[CapitalTheta][ t]*[Mu][t]^[Theta])/(1 + [Psi]1* tat[t] + [Psi]2*(tat[t]^[Psi]3)); inv[t_?NumberQ] := (y[t] + 0.001)*s[t]; (*k[t_?NumberQ]:=10*inv[t-1]+((1-[Delta])^10)*k[t-1];*) ri[t_?NumberQ] := [Gamma]*y[t]/k[t] - (1 - (1 - [Delta])^10)/10; c[t_?NumberQ] := y[t] - inv[t]; u[t_?NumberQ] := ((c[t]/l[t])^(1 - [Alpha]) - 1)/(1 - [Alpha]); cumu[t_?NumberQ] := cumu[t - 1] + (l[t]*u[t]*r[t]*10)/scale1; cpc[t_?NumberQ] := c[t]*1000/l[t]; pcy[t_?NumberQ] := y[t]*1000/l[t]; (* initial values of endogenous variables *) cumu[1] = cumu[0] = cumu0; ceind[1] = ceind[0] = ceind0; mat[1] = mat[0] = mat0; mlo[1] = mlo[0] = mlo0; mup[1] = mup[0] = mup0; tat[1] = tat[0] = tat0; tlo[1] = tlo[0] = tlo0; y[0] = y0; k[1] = k[0] = k0; c[0] = c0; [Mu][1] = [Mu][0] = [Mu]0; (* endogenous inequality constraints*) endog = { k[t] <= 10*inv[t - 1] + ((1 - [Delta])^10)*k[t - 1], 0.02*k[periods] <= inv[periods], 100 <= k[t], 20 <= c[t], 10 <= mat[t], 100 <= mup[t], 1000 <= mlo[t], -1 <= tlo[t] <= 20, 0 <= tat[t] <= 20, ceind[t] <= 6000, 0 <= y[t], 0 <= inv[t], 0 <= ygr[t], 0 <= eind[t], 0 <= matav[t], 0 <= [Mu][t] }; (* processing ... *) (*prepare the objective function*) objvars = Simplify[obj]; objectimous = Simplify[ Flatten[Union[Map[objvars /. t -> # &, Range[periods]]] /. x_Symbol[i_Integer /; i < 0] -> 0]]; (*prepare the endogenous constraints*) endovars = Simplify[endog]; endogenous = Simplify[ Flatten[Union[Map[endovars /. t -> # &, Range[periods]]] /. x_Symbol[i_Integer /; i < 0] -> 0]]; (*prepare the independent optimising variables*) optvars = Simplify[opt]; optimous = Union[Cases[ Flatten[Map[optvars /. t -> # &, Range[periods]], 1], {x_Symbol[_Integer], _Integer | _Real} | {x_Symbol[_Integer], _Integer | _Real, _Integer | _Real} | {x_Symbol[_Integer], _Integer | _Real, _Integer | _Real, _Integer | _Real}, Infinity]]; optimousvars = Union[Cases[optimous, x_Symbol[i_Integer] -> x[i], Infinity]]; (*include any additional optimising variables arising from the endogenous constraints*) primafacievars = Union[Cases[objectimous, x_Symbol[i_Integer] -> x[i], Infinity], Cases[endogenous, x_Symbol[i_Integer] -> x[i], Infinity]]; extendedvariables = Union[optimous, Complement[primafacievars, optimousvars]]; (*prepare optimising function*) Print[Round[(AbsoluteTime[] - starttime), 0.01], seconds compilation time, commencing optimisation ...]; soln = NMinimize[Join[objectimous, endogenous], extendedvariables, MaxIterations -> maxit]; (*output results*) Print[Solution: , soln]; Print[Round[(AbsoluteTime[] - starttime)/60, 0.01], minutes from start to completion]; Print[Round[N[MaxMemoryUsed[]*10^-6], 0.1], Mb memory used]; **** Notebook using Hold **** (*AppendTo[$Echo,stdout];*) (*SetOptions[stdout,PageWidth->110] ; *) (* Nordhaus Brief Climate Change Policy Model May 2008 *) (* Stuart Nettleton July 2008 *) starttime = AbsoluteTime[]; periods = 11; (* projection periods *) maxit = 5000; (* maximum iterations *) (* objective function *) (* program always minimises, so negative for maximisation *) obj = Hold[-cumu[periods]]; objvars = Apply[List, Map[Hold, obj]]; (* preferences for optimisation variables (topolology leaves) *) (* .. for NMinimize provide both upper and lower bounds *) (* .. for FindMinimum provide a single start estimate *) (* hold function prevents premature evaluation *) (*opt = Hold[{[Mu][t],0.001,1},{k[t],100,10000}];*) opt = Hold[{[Mu][t], 0.001, 1}]; optvars = Apply[List, Map[Hold, opt]]; (* exogenous parameters *) pop0 = 6514; popg = 0.35; popa = 8600; dela = 0.001; d[Sigma]1 = 0.003; d[Sigma]2 = 0.000; pback = 1.17; backrat = 2; gback = 0.05; [Rho] = 0.015; fex0 = -0.06; fex1 = 0.30; [Kappa]1 = 1; [Kappa]2 = 1; [Kappa]21 = 1; d[Kappa] = 0; [Theta] = 2.8; sr = 0.22; (* exogenous variables *) gfacpop[t_] := gfacpop[t] = (Exp[popg*(t - 1)] - 1)/Exp[popg*(t - 1)]; l[t_] := l[t] = pop0*(1 - gfacpop[t]) + gfacpop[t]*popa; ga[t_] := ga[t] = ga[0]*Exp[-dela*10*(t - 1)]; a[t_] := a[t] = a[t - 1]/(1 - ga[t - 1]); g[Sigma][t_] := g[Sigma][t] = g[Sigma][0]* Exp[-d[Sigma]1*10*(t - 1) - d[Sigma]2*10*(t - 1)^2]; [Sigma][t_] := [Sigma][t] = [Sigma][t - 1]/(1 - g[Sigma][t]); [CapitalTheta][ t_] := [CapitalTheta][ t] = (pback*[Sigma][t]/[Theta])*((backrat - 1 + Exp[-gback*(t - 1)])/backrat); eland[t_] := eland[t] = eland[0]*(1 - 0.1)^(t - 1); r[t_] := r[t] = 1/(1 + [Rho])^(10*(t - 1)); fex[t_] := fex[t] = fex0 + If[t < 12, 0.1*(fex1 - fex0)*(t - 1), 0.36]; [Kappa][t_] := [Kappa][t] = If[t >= 25, [Kappa]21, [Kappa]21 + ([Kappa]2 - [Kappa]21)* Exp[-d[Kappa]*(t - 2)]]; [CapitalPi][t_] := [CapitalPi][t] = [Kappa][t]^(1 - [Theta]); (*s[t_]:= s[t] =sr;*) (* initial values of exogenous variables *) ga[0] = 0.092; a[1] = a[0] = 0.02722; g[Sigma][0] = -0.0730; [Sigma][1] = [Sigma][0] = 0.13418; eland[0] = 11; [Kappa][1] = [Kappa][0] = 0.25372; (* endogenous parameters *) [Alpha] = 2.0; [Gamma] = .30; [Delta] = 0.1; [Eta] = 3.8; t2xco2 = 3; [Psi]1 = 0.00000; [Psi]2 = 0.0028388; [Psi]3 = 2.00; [Xi]1 = 0.220; [Xi]2 = [Eta]/t2xco2; [Xi]3 = 0.300; [Xi]4 = 0.050; [Phi]12 = 0.189288; [Phi]12a = 0.189288; [Phi]11 = 1 - [Phi]12a; [Phi]23 = 0.05; [Phi]23a = 0.05; [Phi]21 = 587.473*[Phi]12a/1143.894; [Phi]22 = 1 - [Phi]21 - [Phi]23a; [Phi]32 = 1143.894*[Phi]23a/18340; [Phi]33 = 1 - [Phi]32; mat1750 = 596.4; k0 = 137; y0 = 61.1; c0 = 30; mat0 = 808.9; mup0 = 1255; mlo0 = 18365; tat0 = 0.7307; tlo0 = 0.0068; [Mu]0 = 0.005; ceind0 = 0; cumu0 = 381800; scale1 = 194; (* endogenous equality constraints*) ceind[t_] := eind[t - 1] + ceind[t - 1]; eind[t_] := 10 *[Sigma][t] *(1 - [Mu][t]) *ygr[t] + eland[t]; for[t_] := [Eta]*(Log[(matav[t] + 0.000001)/mat1750]/Log[2]) + fex[t]; mat[t_] := eind[t - 1] + [Phi]11*mat[t - 1] + [Phi]21*mup[t - 1]; matav[t_] := (mat[t] + mat[t + 1])/2; mlo[t_] := [Phi]23*mup[t - 1] + [Phi]33*mlo[t - 1]; mup[t_] := [Phi]12*mat[t - 1] + [Phi]22*mup[t - 1] + [Phi]32* mlo[t - 1]; tat[t_] := tat[t - 1] + [Xi]1*(for[t] - [Xi]2* tat[t - 1] - [Xi]3*(tat[t - 1] - tlo[t - 1])); tlo[t_] := tlo[t - 1] + [Xi]4*(tat[t - 1] - tlo[t - 1]); ygr[t_] := a[t]* k[t]^[Gamma] *l[t]^(1 - [Gamma]); dam[t_] := ygr[t]*(1 - 1/(1 + [Psi]1*tat[t] + [Psi]2*(tat[t]^[Psi]3))); [CapitalLambda][t_] := ygr[t] *[CapitalPi][t] *[CapitalTheta][t] *[Mu][t]^[Theta]; y[t_] := ygr[t]*(1 - [CapitalPi][t]*[CapitalTheta][ t]*[Mu][t]^[Theta])/(1 + [Psi]1* tat[t] + [Psi]2*(tat[t]^[Psi]3)); inv[t_] := (y[t] + 0.001)*s[t]; (*k[t_]:=10*inv[t-1]+((1-[Delta])^10)*k[t-1];*) ri[t_] := [Gamma]*y[t]/k[t] - (1 - (1 - [Delta])^10)/10; c[t_] := y[t] - inv[t]; u[t_] := ((c[t]/l[t])^(1 - [Alpha]) - 1)/(1 - [Alpha]); cumu[t_] := cumu[t - 1] + (l[t]*u[t]*r[t]*10)/scale1; cpc[t_] := c[t]*1000/l[t]; pcy[t_] := y[t]*1000/l[t]; (* initial values of endogenous variables *) cumu[1] = cumu[0] = cumu0; ceind[1] = ceind[0] = ceind0; mat[1] = mat[0] = mat0; mlo[1] = mlo[0] = mlo0; mup[1] = mup[0] = mup0; tat[1] = tat[0] = tat0; tlo[1] = tlo[0] = tlo0; y[0] = y0; k[1] = k[0] = k0; c[0] = c0; [Mu][1] = [Mu][0] = [Mu]0; (* endogenous inequality constraints*) endog = Hold[ k[t] <= 10*inv[t - 1] + ((1 - [Delta])^10)*k[t - 1], 0.02*k[periods] <= inv[periods], 100 <= k[t], 20 <= c[t], 10 <= mat[t], 100 <= mup[t], 1000 <= mlo[t], -1 <= tlo[t] <= 20, 0 <= tat[t] <= 20, ceind[t] <= 6000, 0 <= y[t], 0 <= inv[t], 0 <= ygr[t], 0 <= eind[t], 0 <= matav[t], 0 <= [Mu][t] ]; endovars = Apply[List, Map[Hold, endog]]; (* processing ... *) (* prepare the objective function *) objectimous = Simplify[ Flatten[Apply[List, Map[ReleaseHold, Union[Map[objvars /. t -> # &, Range[periods ]]]]] /. x_Symbol[i_Integer /; i < 0] -> 0]]; (* prepare the endogenous constraints *) endogenous = Simplify[ Flatten[Apply[List, Map[ReleaseHold, Union[Map[endovars /. t -> # &, Range[periods ]]]]] /. x_Symbol[i_Integer /; i < 0] -> 0]]; (* prepare the independent optimising variables *) optimous = Union[Cases[ Apply[List, Map[ReleaseHold, Flatten[Map[optvars /. t -> # &, Range[periods]]]]], {x_Symbol[_Integer], _Integer | _Real} | {x_Symbol[_Integer], _Integer | _Real, _Integer | _Real} | {x_Symbol[_Integer], _Integer | _Real, _Integer | _Real, _Integer | _Real}, Infinity]]; optimousvars = Union[Cases[optimous, x_Symbol[i_Integer] -> x[i], Infinity]]; (* include any additional optimising variables arising from the endogenous constraints *) primafacievars = Union[Cases[objectimous, x_Symbol[i_Integer] -> x[i], Infinity], Cases[endogenous, x_Symbol[i_Integer] -> x[i], Infinity]] ; extendedvariables = Union[optimous, Complement[primafacievars, optimousvars]]; (* prepare optimising function *) Print[Round[(AbsoluteTime[] - starttime), 0.01], seconds compilation time, commencing optimisation ...]; soln = NMinimize[Join[objectimous, endogenous], extendedvariables, MaxIterations -> maxit]; (* output results *) Print[Solution: , soln]; Print[Round[(AbsoluteTime[] - starttime)/60, 0.01], minutes from start to completion]; Print[Round[N[MaxMemoryUsed[]*10^-6], 0.1], Mb memory used]; -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects. === Subject: Colors in Histogram how can I set the color of the bars in a Histogram? === Subject: Re: Making parts of formulae blinking I thank very much David Park, David Bailey, Jens-Peer Kuska and David Reiss for their kind answers. I believe we all agree ////with David Park that the problem is important and worth thinking about. In addition to what has been already written about it, it seems that most of us agree that Mathematica potentially offers by far more possibilities for making scientific presentations than Power Point. However, for static accentuation of expressions Power Point offers a solution by few mouse clicks, while Mathematica requires some programming. It is important therefore, to simplify and (may be) standardize this to make it easily applicable. Otherwise it will be very difficult to often use such an accentuation, say, for university lecturing. Further to my knowledge Power Point does not offer any approach for making dynamic accentuation. It seems however, that Mathematica may offer a way for this, though so far I cannot find it. Because of this I would like to rise this problem once more and to ask you to think about it, if possible. Let me explain my point. The approach of David Park gives a nice solution for a static accentuation of an expression. It can be used right away. My point is however, that if one could make parts of the expression blinking, this would make a still stronger effect. However, all approaches proposed for its dynamic accentuation (i.e. blinking) are still not acceptable. You have noted this yourself in your responses by mentioning that this may cause medical consequences like a headache or epileptic attack. These effects are of coarse, not our aim. Instead, when we give talks we need to convey information in a most easy-to-catch way. For this reason for example, an arbitrary variation of colors in a part of an expression is disadvantageous, rather than advantageous. This is not only for medical reasons, but also since these colors are sometimes difficult to see. Further, the way of dynamic accentuation which is not limited in time is disadvantageous. Again not only for medical reasons. When I accentuate some part of expression, I need to do it only for the time interval during which I discuss this part. As soon as this discussion is finished, the second part of the expression should be accentuated, while the first one should become plain, and so on. When I stop the whole discussion all the parts of the expression should become plain. Blinking of all the parts of the expression at once will mislead the audience and thus, cause the effect opposite to the one I want to achieve. I imagine myself that the dynamic accentuation may look like the following: By a mouse click on the part of the expression that should be discussed this part blinks 3 to 5 times. It is important that the blinking should look like successive variations of color from say, black to say, red and back. The size and/or the weight may also vary. After the last (e.g. for instance, the third) blinking the accentuated part of the formula should stay statically accentuated. This means that it stays red, while the rest of the expression stays black. It would be even better, if the rest of the formula becomes gray, since it is a generally accepted notation of blending. Further, by the mouse click one makes this formula part black (or gray), while its next part becomes first dynamically and then statically accentuated in the sense described above. After the last expression part has been accentuated and discussed, the whole formula should be done plain (e.g. in its initial format: Color->Black, Weight->Plain, etc.) by a mouse click. I believe that these few blinking will not cause any medical problem, but instead will catch the eyes of the audience and help it to easier concentrate on the content of the talk. Could you please think of something like this? Alexei > In my previous letter for the sake of shortness I have given an oversimplified > expression AB+xy. The procedure Accentuate works perfectly on it. In reality however, one often > needs to accentuate parts of an expression that have different lengths. Further, often there are more than two > parts of the same expression that should be accentuated separately. In this case a straightforward use > of the operator Accentuate results in a change of the order of the parts of the expression. For example, I need to discuss four parts of the same expression. They should be discussed separately > from one another. Here they are: > My solution to this would be to define a simple function - say acc: acc[x_] := Dynamic[Refresh[Style[x, Hue[Random[]]], UpdateInterval -> 0.3]] Now you can write partially accentuated expressions such as acc[a]+b^acc[c] and it will evaluate to a partially accentuated expression. Please note, however, that the randomly varying hue is meant as a joke - I don't want to be held responsible for any headaches it produces! BTW, I agree very much with David Park that there is enormous value in being able to pick out parts of expressions and to move beyond the 'dead' expressions that displayed in textbooks! -- Alexei Boulbitch, Dr., Habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: Another Out of Memory Problem > I can do the following: Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] I almost immediately get this: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. Start the task manager (Alt+Ctrl+Del) and keep track of the memory in use. Windows class A Mathematica is able to adress 2 GB of memory maximally. Since it is running atop the Windows Desktop it is not able to issue the out of memory warning because of lack of memory in its own adress space, the old windows blue screen trap. With a machine that is able to adress 3 GB the warning is issued. With a 2 GB machine it is a question of how much memory is allocated for the graphics system. With less than 2 GB available the kernel crases on memory overflow. Integrate[Cos[2.5`20*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] consumes about 1GB maximum of memory while Integrate[Cos[2.5*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] needs around 1.97 GB and begins to block the task manager as well as the windows event handler. Its difficult to reach the Abort menu activation 2 GB intel dual core Windows Vista system. -- Roland Franzius === Subject: Locate palette at top edge of screen? (Windows XP SP3, Mathematica 6.0.3) I am trying to create a command that moves a palette so that its top edge is at or near the top edge of the screen, i.e., superimposed on the space occupied by the main title bar (the bar containing Wolfram Mathematica 6.0 - and the menu titles.) If I simply use the example in the CreatePalette entry in the Help documentation pal = CreatePalette[PasteButton[[Alpha]]]; a small palette is created. (In my case, most of it extends off the right edge of my screen). I then use the mouse to drag this palette onto the center area of the main title bar, placing its top edge at the top edge of the screen and thus practically coincident with the top edge of the main title bar. To determine the coordinates (window margins) in this desired location, I execute the command Options[pal, WindowMargins] and the result in this case is {WindowMargins -> {{599, Automatic}, {Automatic, -50}}} Using the mouse, I drag the palette away from this location, then execute the following command, expecting it to move the palette back to the desired position. SetOptions[pal, WindowMargins -> {{599, Automatic}, {Automatic, -50}} Instead, the palette moves to the correct horizontal postion, but its top edge is at the BOTTOM edge of the main title bar, not at the top edge of the screen. Executing the command Options[pal, WindowMargins] yields {WindowMargins -> {{599, Automatic}, {Automatic, -50}}} which is inconsistent with the screen position. Indeed, if I again move the mouse to another location, then execute SetOptions[pal, WindowMargins -> {{599, Automatic}, {Automatic, 0}} the palette moves back to its previous position right below the main title bar. Thus an upper margin of 0 corresponds with the bottom edge of the main title bar, therefore implying a value of -50 should be above that edge. However, it seems a command of the form SetOptions[...,WindowMargins->{{...},{Automatic,x}}] converts negative values of x to 0. Is there a command that can move a palette so its top edge is at the top edge of the screen? === Subject: Re: Locate palette at top edge of screen? try pal = CreatePalette[PasteButton[[Alpha]]]; Manipulate[ SetOptions[pal, WindowMargins -> {{p[[1]], Automatic}, {p[[2]], Automatic}}]; p, {{p, {0, 0}}, {0, 0}, {1280, 1024}, ControlType -> Slider2D} ] and use the position you like. Jens > (Windows XP SP3, Mathematica 6.0.3) I am trying to create a command that moves a palette so that its top > edge is at or near the top edge of the screen, i.e., superimposed on the > space occupied by the main title bar (the bar containing Wolfram > Mathematica 6.0 - and the menu titles.) If I simply use the example in the CreatePalette entry in the Help > documentation pal = CreatePalette[PasteButton[[Alpha]]]; a small palette is created. (In my case, most of it extends off the > right edge of my screen). I then use the mouse to drag this palette onto the center area of the > main title bar, placing its top edge at the top edge of the screen and > thus practically coincident with the top edge of the main title bar. > To determine the coordinates (window margins) in this desired location, > I execute the command Options[pal, WindowMargins] and the result in this case is {WindowMargins -> {{599, Automatic}, {Automatic, -50}}} Using the mouse, I drag the palette away from this location, then > execute the following command, expecting it to move the palette back to > the desired position. SetOptions[pal, WindowMargins -> {{599, Automatic}, {Automatic, -50}} Instead, the palette moves to the correct horizontal postion, but its > top edge is at the BOTTOM edge of the main title bar, not at the top > edge of the screen. Executing the command Options[pal, WindowMargins] yields {WindowMargins -> {{599, Automatic}, {Automatic, -50}}} which is inconsistent with the screen position. Indeed, if I again move > the mouse to another location, then execute SetOptions[pal, WindowMargins -> {{599, Automatic}, {Automatic, 0}} the palette moves back to its previous position right below the main > title bar. Thus an upper margin of 0 corresponds with the bottom edge > of the main title bar, therefore implying a value of -50 should be above > that edge. However, it seems a command of the form > SetOptions[...,WindowMargins->{{...},{Automatic,x}}] converts negative > values of x to 0. Is there a command that can move a palette so its top edge is at the top > edge of the screen? > Dwynn > === Subject: Exporting ContourPlot data into text file to plot somewhere else.. Hi How can I export ContourPlot data to a text file? I read some instructions in this forum to do this for normal plots: e.g.: plt = Plot[Sin[x], {x, 0, 5}] First[Cases[plt, _Line, Infinity] /. Line[pnts_] :> pnts] which return a neat list of pairs of numbers to plot somewhere else. With ContourPlot though, this command returns only one column of numbers in sequencial order... Not good...! Angel === Subject: Re: Exporting ContourPlot data into text file to plot somewhere else.. > How can I export ContourPlot data to a text file? I read some instructions in this forum to do this for normal plots: e.g.: plt = Plot[Sin[x], {x, 0, 5}] > First[Cases[plt, _Line, Infinity] /. Line[pnts_] :> pnts] which return a neat list of pairs of numbers to plot somewhere else. > With ContourPlot though, this command returns only one column of > numbers in sequencial order... Not good...! Different kind of plots have different internal structures. Fortunately, since in Mathematica everything is an expression, plots can be manipulated as any other expression. Therefore, FullForm[] will reveal internal structure (in Mathematica language) of the expression that represents a given plot and Part[], provided withe the correct indices, will extract any parts of the plot as it would do for any other expression. (Of course, other method are applicable, such as replacement rules, which does not mean that a given replacement rule will work on every plots.) For instance, cp = ContourPlot[Cos[x] + Cos[y] == 1/2, {x, 0, 4 Pi}, {y, 0, 4 Pi}] FullForm[cp] (* To see the internal structure of the plot. *) cp[[1, 1]] (* To extract only the relevant structure of the plot*) === Subject: Re: Exporting ContourPlot data into text file to plot somewhere else.. cntrplt = ContourPlot[ x*Exp[-x^2 - y^2], {x, -3, 3}, {y, -2, 2}, ContourShading -> False, Contours -> 64]; lst = Cases[cntrplt /. gc_GraphicsComplex :> Normal[gc], _Line, Infinity] /. Line :> List; and to see if it had worked Graphics[Line @@@ lst] Jens > Hi How can I export ContourPlot data to a text file? I read some instructions in this forum to do this for normal plots: e.g.: plt = Plot[Sin[x], {x, 0, 5}] > First[Cases[plt, _Line, Infinity] /. Line[pnts_] :> pnts] which return a neat list of pairs of numbers to plot somewhere else. > With ContourPlot though, this command returns only one column of > numbers in sequencial order... Not good...! > Angel === Subject: Re: fractional derivative of 1/(log x)? > derivative (order t) of 1/(log x), where t can range from -2 and -0.5. Since you have already posted a similar question on this newsgroup few days ago [1] and also you are asking the same ambiguous question on MathForum [2], it is hard to tell what kind of help you are seeking? (Note that comp.soft-sys.math.mathematica is a newsgroup dedicated to the computer algebra system (CAS) Mathematica.) So are you seeking help about . Mathematica . the concepts involved in fractional calculus . some specificities of the function 1/log(x) Also, . What about the previous replies you got? . Have you investigated them? . Did you try anything by yourself? . ... At any rate, it would be useful to restate your query in a more precise way, to show your work and/or attempts, describe any difficulties faced, give relevant background information, ... - Jean-Marc [1] Re: fractional derivative (order t) of (Log[x])^n and Log[Log[x]] http://forums.wolfram.com/mathgroup/archive/2008/Aug/msg00332.html [2] _The Math Forum @ Drexel_ http://mathforum.org/kb/thread.jspa?threadID=1786274&tstart=0 === Subject: troubling simple integral Mathematica 6.0.3.0 has trouble computing the quite simple integral In[2]:= FullSimplify[ Integrate[ (b + k*x) / k^2 * Exp[-k*x] * Sin[k*a] * Sin[k*y] , {k, 0,Infinity}, Assumptions -> x > 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == 0 ]] Out[2]= -(1/8) I (b + 2 I x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) which is obviously wrong. Repeating the computation, I get different results. What should I do to get a correct answer? (This one I can do by hand, but I have more complicated similar ones to evaluate.) === Subject: Re: troubling simple integral > Mathematica 6.0.3.0 has trouble computing the quite simple integral In[2]:= FullSimplify[ Integrate[ (b + k*x) / k^2 * Exp[-k*x] * > Sin[k*a] * Sin[k*y] , {k, 0,Infinity}, > Assumptions -> x > 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == 0 ]] Out[2]= -(1/8) I (b + 2 I x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) which is obviously wrong. Repeating the computation, I get different > results. What should I do to get a correct answer? > (This one I can do by hand, but I have more complicated similar ones > to evaluate.) Does the following result look better? In[1]:= Assuming[x > 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == 0, FullSimplify[ Integrate[(b + k*x)/k^2*Exp[-k*x]*Sin[k*a]*Sin[k*y], {k, 0, Infinity}]]] Out[1]= 1/4 (2 b ((-a + y) ArcTan[(a - y)/x] + (a + y) ArcTan[(a + y)/ x] - x ArcTanh[(2 a y)/(a^2 + x^2 + y^2)]) + x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) Note that *Assuming* passes the assumptions to both Integrate[] *and* FullSimplify[]. (In your original expression, only Integrate[] could take into account the assumptions.) HTH, === Subject: Re: troubling simple integral > Mathematica 6.0.3.0 has trouble computing the quite simple integral In[2]:= FullSimplify[ Integrate[ (b + k*x) / k^2 * Exp[-k*x] * > Sin[k*a] * Sin[k*y] , {k, 0,Infinity}, > Assumptions -> x > 0 && Im[a] == 0 && Im[b] == 0 && Im[y] == = 0 ]] Out[2]= -(1/8) I (b + 2 I x Log[1 + (4 a y)/(x^2 + (a - y)^2)]) which is obviously wrong. Repeating the computation, I get different > results. What should I do to get a correct answer? > (This one I can do by hand, but I have more complicated similar ones > to evaluate.) The integral proportional to b (the one proportional to x poses no problem) gives a strange result if you specifies Assumptions-> Element[{a,y},Reals] In[11]:= Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}, Assumptions -> Element[{a, y}, Reals]] Out[11]= I/8 However if you replace the parameters by some constants (here Catalan and EulerGamma) you get a result In[7]:= ii1 = Integrate[ 1/k^2*Exp[-k]*Sin[Catalan k] Sin[EulerGamma k], {k, 0, Infinity}] /. {Catalan -> a, EulerGamma -> y} Out[7]= 1/4 (-2 a (ArcTan[a - y] - ArcTan[a + y]) + 2 y (ArcTan[a - y] + ArcTan[a + y]) + Log[1 + a^2 - 2 a y + y^2] - Log[1 + a^2 + 2 a y + y^2]) The same result can be obtained using the option GenerateConditions -> False: In[9]:= ii2 = Integrate[1/k^2*Exp[-k]*Sin[a k] Sin[y k], {k, 0, Infinity}, GenerateConditions -> False] Out[9]= 1/4 (2 (-a + y) ArcTan[a - y] + 2 (a + y) ArcTan[a + y] + Log[1 + I a - I y] + Log[1 - I a + I y] - Log[I (-I + a + y)] - Log[-I (I + a + y)]) In[10]:= Table[ii1 - ii2, {a, .1, 1., .2}, {y, .1, 1., .2}] // Chop Out[10]= {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}} I agree with you, the output I/8 is difficult to understand... Alberto Verga === Subject: Re: No Memory Available windows XP Pro. > I am using Mathematica 6.0 [... Cross posted to MathGroup ...] OK. AFAIK, the default/standard system configuration of Windows XP Professional 32-bit edition allows only 2 GB of memory per user process, i.e. each individual user/application process will not be allowed by the operating system to request memory over this 2 GB limit, even though the theoretical limit is 4 GB on a 32-bit system. Now, there exist two switches for this version of Windows that allows the system to allocate up to 3 GB per user process. See the following to use them: On 32-bit versions of Windows, the /3GB parameter enables 4-gigabyte user-mode virtual address space to 3 GB and restricts the kernel-mode components to the remaining 1 GB. [1] Alone and/or combine with $HistoryLength=0 and ClearSystemCache[], this might solve your memory issue. - Jean-Marc Address Extension parameter, http://support.microsoft.com/kb/291988 [2] Memory Management - Demystifying /3GB http://blogs.technet.com/askperf/archive/2007/03/23/memory-management-demyst ifying-3gb.aspx Adel > I am using NDSolve to do integration in time for 24 variables. I can > choose > only to do the integration for a short time range, otherwise I get the > error: >> No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. be Though you did not tell us, I believe you are using a 32-bit system, which >> mean that depending on the combination of hardware and operating system, a >> user process can get between 2 and about 3 GB of virtual memory maximum. > tell Mathematica to wipe the memory out during the run? ClearSystemCache[Numeric] or ClearSystemCache[] might help reclaiming >> some memory (assuming you are using version 6.x.x). http://reference.wolfram.com/mathematica/ref/ClearSystemCache.html Anyway, it is really hard to be specific without any hint about your >> hardware, software, and the system you are trying to solve. === Subject: Re: No Memory Available > I am using NDSolve to do integration in time for 24 variables. I can choose > only to do the integration for a short time range, otherwise I get the > error: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. tell Mathematica to wipe the memory out during the run? ClearSystemCache[Numeric] or ClearSystemCache[] might help reclaiming some memory (assuming you are using version 6.x.x). http://reference.wolfram.com/mathematica/ref/ClearSystemCache.html Anyway, it is really hard to be specific without any hint about your hardware, software, and the system you are trying to solve. === Subject: Dynamic FindFit??????? Hi I'm Julio and I'm new with mathematica and I have a problem. I want to create a Dynamic FindFit without using Manipulate, just using Dynamic, but I'm not sure if it is possible. If you can help me it will be great. === Subject: Re: Dynamic FindFit??????? I had the impression that a example of dynamic findfit just appears in the documentation. But unfortunately I don't remember which entry includes, at least it's not in the entry Dynamic. On Aug 16, 5:54 pm, ..~ J u L i O ~.. ..~ L. A.~.. > Hi I'm Julio and I'm new with mathematica and I have a problem. I want to > create a Dynamic FindFit without using Manipulate, just using Dynamic, > but I'm not sure if it is possible. If you can help me it will be grea= t. === Subject: Re: Dynamic FindFit??????? > I'm Julio and I'm new with mathematica and I have a problem. I want to > create a Dynamic FindFit without using Manipulate, just using Dynamic, > but I'm not sure if it is possible. If you can help me it will be great. I am not sure whether this is what you are looking for, but have you try to wrap FindFit[] within Dynamic[]? In[1]:= data = Table[Prime[x], {x, 20}] Out[1]= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71} In[2]:= Dynamic[FindFit[data, a Exp[-k t], {a, k}, t]] Out[2]= {a->8.17859,k->-0.112575} (* Note that upon evaluation of In[3], Out[2] automatically updates to the following *) Out[2]= {a->72.2284,k->-0.0431004} In[3]:= data = Table[Prime[x], {x, 20, 40}] Out[3]= {71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173} === Subject: Re: Dynamic FindFit??????? How about a simple example of what you mean by a Dynamic FindFit. > I'm Julio and I'm new with mathematica and I have a problem. I want to > create a Dynamic FindFit without using Manipulate, just using Dynamic, > but I'm not sure if it is possible. If you can help me it will be great. === Subject: plotting plane & a triangle i'm working on developing some 3d software and I was hoping to use mathematica to test the results of some of my code. Specifically, I'm trying to visualize a plane and a triangle, to see if they intersect, and if not, which side of the plane the triangle's points are on (I'm calculating this using algebra, and need to check the results) so far I've done: (the triangle) pl1 = Graphics3D[{Polygon[{{-80.2576, -594.271, 224.043}, {-120.608, -588.635, 221.101}, {1.32756, -598.31,261.244}}]}] (the plane) pl2 = Plot3D[0.402395*x - 0.899308*y + 0.171241*z + 274.122 = 0,{x, -10000, 10000}, {y, -10000, 10000}] then: Show[pl1, pl2] questions: 1) the Polygon is displayed fine on its own, but the plane looks completely flat along z=0 and is axis-aligned, so I'm not sure what's wrong... 2) the final Show command results in a really flat graph that doesn't show me anything... do I need to increase or fix the range? any help would be much appreciated imran === Subject: Re: plotting plane & a triangle > i'm working on developing some 3d software and I was hoping to use > mathematica to test the results of some of my code. Specifically, I'm > trying to visualize a plane and a triangle, to see if they intersect, > and if not, which side of the plane the triangle's points are on (I'm > calculating this using algebra, and need to check the results) so far I've done: > (the triangle) > pl1 = Graphics3D[{Polygon[{{-80.2576, -594.271, 224.043}, {-120.608, > -588.635, 221.101}, {1.32756, -598.31,261.244}}]}] (the plane) > pl2 = Plot3D[0.402395*x - 0.899308*y + 0.171241*z + 274.122 = 0,{x, > -10000, 10000}, {y, -10000, 10000}] Plot3D seems cannot plot implicit function. So change it into pl2 = Plot3D[(0.402395*x - 0.899308*y + 274.122)/0.171241, {x, -10000, 10000}, {y, -10000, 10000}] and everything goes on well. then: > Show[pl1, pl2] questions: > 1) the Polygon is displayed fine on its own, but the plane looks > completely flat along z=0 and is axis-aligned, so I'm not sure what's > wrong... > 2) the final Show command results in a really flat graph that > doesn't show me anything... do I need to increase or fix the range? any help would be much appreciated > imran === Subject: Re: plotting plane & a triangle > i'm working on developing some 3d software and I was hoping to use > mathematica to test the results of some of my code. Specifically, I'm > trying to visualize a plane and a triangle, to see if they intersect, > and if not, which side of the plane the triangle's points are on (I'm > calculating this using algebra, and need to check the results) so far I've done: > (the triangle) > pl1 = Graphics3D[{Polygon[{{-80.2576, -594.271, 224.043}, {-120.608, > -588.635, 221.101}, {1.32756, -598.31,261.244}}]}] (the plane) > pl2 = Plot3D[0.402395*x - 0.899308*y + 0.171241*z + 274.122 = 0,{x, -------------------------------------------------------------!!!!! *Syntax error*: must be double equal sign (==) to check for equality. Single equal sign (=) denotes the assignment operator (set a value to something). > -10000, 10000}, {y, -10000, 10000}] then: > Show[pl1, pl2] questions: > 1) the Polygon is displayed fine on its own, but the plane looks > completely flat along z=0 and is axis-aligned, so I'm not sure what's > wrong... You should write the equation of the plane as a function of two variables x and y rather than as an equation of three variables x, y, and z. Plot3D[5.83972 (-274.122 - 0.402395 x + 0.899308 y), {x, -1000, 1000}, {y, -10000, 10000}] Since, Solve[0.402395*x - 0.899308*y + 0.171241*z + 274.122 == 0, z] {{z -> 5.83972 (-274.122 - 0.402395 x + 0.899308 y)}} z /. %[[1]] 5.83972 (-274.122 - 0.402395 x + 0.899308 y) === Subject: Re: plotting plane & a triangle pl1 = Graphics3D[{Glow[RGBColor[0, 1, 0]], Polygon[{{-80.2576, -594.271, 224.043}, {-120.608, -588.635, 221.101}, {1.32756, -598.31, 261.244}}]}] pl2 = ContourPlot3D[ 0.402395*x - 0.899308*y + 0.171241*z + 274.122 == 0, {x, -600, 600}, {y, -600, 600}, {z, -600, 600}, Contours -> 0, Mesh -> None] and Show[pl1, pl2] where the little speck of dust is your polygon. Jens > i'm working on developing some 3d software and I was hoping to use > mathematica to test the results of some of my code. Specifically, I'm > trying to visualize a plane and a triangle, to see if they intersect, > and if not, which side of the plane the triangle's points are on (I'm > calculating this using algebra, and need to check the results) so far I've done: > (the triangle) > pl1 = Graphics3D[{Polygon[{{-80.2576, -594.271, 224.043}, {-120.608, > -588.635, 221.101}, {1.32756, -598.31,261.244}}]}] (the plane) > pl2 = Plot3D[0.402395*x - 0.899308*y + 0.171241*z + 274.122 = 0,{x, > -10000, 10000}, {y, -10000, 10000}] then: > Show[pl1, pl2] questions: > 1) the Polygon is displayed fine on its own, but the plane looks > completely flat along z=0 and is axis-aligned, so I'm not sure what's > wrong... > 2) the final Show command results in a really flat graph that > doesn't show me anything... do I need to increase or fix the range? any help would be much appreciated > imran > === Subject: Re: debugging code that contains compile > By errors, do you mean you get any error messages > of the form > CompiledFunction::error_code:error_text The errors I get are Compile::cif errors. Well, that errors appear, but my question is: How can I get more details? I'm not asking anybody here to help me out with my code directly, it's not about getting rid of one specific error. I wanna know how to get more information about the errors to handle them better in general. That's what I wanted to say in my first post. I want to know if there's a better way to use the debugger or if there is a way to get more precise error messages (telling me the line, where the error appears). In my case everything is a bit more complicated, because I'm dealing with compile. But if someone can give me hints on that in general, I'd be very pleased, too. So the central question again: Is there a better way to deal with the situation than explained in 1) an 2) in my thread opener? === Subject: Inclusion-Exclusion Principle in Mathematica Hey guys, first post! I believe I've just solved a problem, and I'm trying to use mathematica to test my solution for known results, but I haven't been able to write my expression into mathematica. It looks a lot like the inclusion-exclusion principle, which is equation (3) on the following mathworld page: http://mathworld.wolfram.com/Inclusion-ExclusionPrinciple.html My expression is similar in that it contains alternating series of multiple series, where the multiple series are of increasing depth. I hope that's clear. I can enter it in the way it's written on that page, but that wouldn't be practical for me. I can't have it in the form sum1[] - sum2[] + sum3[] - sum4[], etc. It needs to be in the form sum[-1^(j-1)sumj[]], because I'm working with a very large and varying number of sets and I can't type in all of the series manually. To do this, I need to know how to specify the depth, or number of series in a multiple series, with a number. I've gone through the documentation, contacted mathematica tech support and posted in the student support forum, but I haven't gotten a solution yet. Can anyone who's more familiar with mathematica that me help me out? I just downloaded the program a few days ago! === Subject: Player Pro Usage Does anyone have experience using PlayerPro for distributing Mathematica Package applications? I am especially interested in the following issues: (1) Does encryption work well to keep the source code confidential - from being viewed by the user of the application? (2) Are there any limitations to the functionality of packages that can be used with PlayPro? Specifically, do front end dynamic capabilities like Manipulate sliders, Input Fields etc. work with PlayPro? Don === Subject: Re: Connecting pipes Place a sphere at the connection point? e.g., Graphics3D[ {EdgeForm[], Cylinder[{{0, 0, 0}, {0, 0, 1}}, .1], Cylinder[{{0, 0, 0}, {1, 0, 0}}, .1], Cylinder[{{1, 0, 0}, {1, 0, 1}}, .1], Cylinder[{{1, 0, 1}, {0, 0, 1}}, .1], Sphere[{0, 0, 0}, .1], Sphere[{1, 0, 0}, .1], Sphere[{0, 0, 1}, .1], Sphere[{1, 0, 1}, .1] }] - Selwyn Hollis I'd like to draw a network of connecting of pipes (like that 3D pipe > screen saver). Supposed I have the coordinates stored in Coord, and > I'd like to connect, say, Coord[[4]] to Coord[[2]], etc. I figure I could use the cylinder function (damned Euler angle!) to > draw a single pipe, but haven't quite figured out how to connect them > together. Any suggestion? > Caosau > PS. Bonus if I can do it with cartesian coords. > === Subject: Re: Connecting pipes a) the actual version of MathGl3d has a TubularPlot3D[]/ListTubularPlot3D[] function that does this whithout any Euler angle b) you can use the algorithm from http://i2.cs.hku.hk/GraphicsGroup/publications/RMF_rev.pdf Jens I'd like to draw a network of connecting of pipes (like that 3D pipe > screen saver). Supposed I have the coordinates stored in Coord, and > I'd like to connect, say, Coord[[4]] to Coord[[2]], etc. I figure I could use the cylinder function (damned Euler angle!) to > draw a single pipe, but haven't quite figured out how to connect them > together. Any suggestion? > Caosau > PS. Bonus if I can do it with cartesian coords. > === Subject: Re: Feynman slash notation In Mathematica you can overwrite characters by first of all typing them next to each other in the usual way, and then selecting each block of characters that you want to shift (left or right), and using ALT-LEFTARROW or ALT-RIGHTARROW repeatedly to nudge the block to wherever you want it to be. For instance, here is the Dirac equation that I created by nudging a / leftwards so that it sits on top of a [PartialD]: Cell[TextData[Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ RowBox[{(, RowBox[{i, , RowBox[{[PartialD], RowBox[{ AdjustmentBox[/, BoxMargins->{{-0.6666666666666666, 0.6666666666666666}, {0., 0.}}], RowBox[{-, m}]}]}]}], )}], [Psi]}], =, 0}], TraditionalForm]]]], Text] Paste this Cell Expression into a notebook to see it rendered. -- Stephen Luttrell West Malvern, UK >I need to insert the slash notation into a Mathematica document. Does > Mathematica support this? > === Subject: Re: Feynman slash notation > I need to insert the slash notation into a Mathematica document. Does > Mathematica support this? > One answer would be to use the fact that since version 6.0 it has been possible to use graphics objects in expressions. The following represents A-slash + B: Interpretation[ Graphics[{Text[Style[A, FontSize -> 14], {0, 0}], Text[Style[/, FontSize -> 14], {0, 0}]}, ImageSize -> 20], ASlash] + B The interpretation box ensures that the kernel 'sees' a symbol corresponding to A-slash. Unfortunately you would need to adjust the font size to suit the size of the surrounding font. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Feynman slash notation To Jose Luis Gomez, Package can only be used to define convenient/new notation conventions using the standard Mathematica symbols. Incorporating the Feynman slash notation can be described as a typographical issue. This link may be useful: http://www.physicsforums.com/showthread.php?p=1830003 This feature seems to be supported by the LaTeX typesetting system used by, for example, Wikipedia: http://en.wikipedia.org/wiki/Feynman_slash_notation > You can create new notations in Mathematica with the Notations Package > (add-on), which is already included in Mathematica, see this link: http://reference.wolfram.com/mathematica/Notation/guide/NotationPackage.h= > tml I hope that helps Jose > Mexico -----Mensaje original----- > De: Shaun Culver [mailto:admin@shaunculver.com] > Enviado el: Mi=E9rcoles, 13 de Agosto de 2008 03:42 > Para: mathgroup@smc.vnet.net > Asunto: Feynman slash notation I need to insert the slash notation into a Mathematica document. Does > Mathematica support this? === Subject: About the error message Indeterminate I think you all might have been check the example the bouncer in the entry Dynamic. But it is on a flat ground. So I want to make some change to let it bounce on hills, which formed by Sine function. The collisional consummation and reflection angle have been taken considered, but when the point touches the ground, it doesn't move any longer and the velocity shows indeterminate. I know indeterminate means such an issue like 0/0, but I replace my reflecting function with the colliding position and get a certain answer. I don't know if is there any other issues will cause indeterminate. Anyway, check the code first. function[x_] := Sin[x] + 0.5 Sin[6 x]; Reflection[{{x_, y_}, {vx_, vy_}}] := {{x, y}, 0.8 Sqrt[vx^2 + vy^2] {Cos[2 ArcTan[function'[x]] - ArcTan[vy/vx]], Sin[2 ArcTan[function'[x]] - ArcTan[vy/vx]]}} (* where function[] means the ground and Reflection[] shows how the ball bounces up, where x, y means position and vx, vy means velocity. 0.8 Is the consummation of collision, Sqrt is the norm of speed and the latter stuff is the new velocity in x and y direction. *) PointSet = {{4, 6}, {0, -0.01}}; Plot[function[x], {x, -5, 5}, Axes -> None, Filling -> Bottom, PlotRange -> {{-5, 5}, {-2, 8}}, AspectRatio -> 1, Epilog -> Point[Dynamic[ PointSet = If[PointSet[[1, 2]] >= function[PointSet[[1, 1]]], {PointSet[[1]] + PointSet[[2]], PointSet[[2]] + {0, -0.001}}, Reflection[PointSet]]; PointSet[[1]]]]] Dynamic[PointSet] (*I used Epilog to draw the point. I didn't use Mouseclick because it will cause a dump*) Tao Yue === Subject: Non Default stylesheet format and syntax coloring Hello everyone, When I open a new notebook, it has the =93NaturalColor=94 stylesheet format because I prefer it to the =93Default=94 format. In the Mathematica Preferences, I changed the font color for =93Global symbols that have no values assigned=94. Problem is that this new color for unassigned symbols shows up in a notebook that has the =93Default=94 format but not the =93NaturalColor=94 one=85 I guess the =93NaturalColor=94 format does not inherit the changes I make in the preferences=85 Does anyone knows how do I solve this issue ? === Subject: Maximization of a Likelihood Function Just curious to know if anyone has written a Mathematica routine to maximize a likelihood function. I'd like to tinker with one and apply it to multivariate GARCH if that is possible. I know that the Time Series package has a univariate GARCH command, but I am unaware of any multivariate routines. Gregory === Subject: Integral of radial solution (hydrogen atom) is not evaluated Hi! I want to integrate the radial solution of the hydrogen atom from zero to infinity. The following code (for the corresponding cell expression, see below) just returns an unevaluated integral: In:: R=r^l*Exp[-(r/n)]*(2/n)^l*2/n^2*Sqrt[(n-l-1)!/(n+l)!]*LaguerreL[n- l-1,2*l+1,(2*r)/n] Assuming[{Element[n,Integers],Element[l,Integers],n>0,n>l>=0},integrand=Full Simplify[(R*r)^2];Simplify[Integrate[integrand, {r,0,[Infinity]}]]] Out:: !( *SubsuperscriptBox[([Integral]), (0), ([Infinity])]( FractionBox[( *SuperscriptBox[(4), (1 + l)] *SuperscriptBox[(E), (- *FractionBox[(2 r), (n)])] *SuperscriptBox[(n), ((-2) ((2 + l)))] *SuperscriptBox[(r), (2 + 2 l)] Gamma[(-l) + n] *SuperscriptBox[(LaguerreL[(-1) - l + n, 1 + 2 l, *FractionBox[(2 r), (n)]]), (2)]), (((l + n))!)] [DifferentialD]r)) I do not know, why the integral is left unevaluated and what I am doing wrong respectively. Any help appreciated. Yours Wolfgang --- Cell[BoxData[{ RowBox[{R, =, RowBox[{ SuperscriptBox[r, l], *, RowBox[{Exp, [, RowBox[{-, FractionBox[r, n]}], ]}], *, SuperscriptBox[ RowBox[{(, FractionBox[2, n], )}], l], *, FractionBox[2, SuperscriptBox[n, 2]], *, SqrtBox[ FractionBox[ RowBox[{ RowBox[{(, RowBox[{n, -, l, -, 1}], )}], !}], RowBox[{ RowBox[{(, RowBox[{n, +, l}], )}], !}]]], *, RowBox[{LaguerreL, [, RowBox[{ RowBox[{n, -, l, -, 1}], ,, RowBox[{ RowBox[{2, *, l}], +, 1}], ,, FractionBox[ RowBox[{2, *, r}], n]}], ]}]}]}], [IndentingNewLine], RowBox[{Assuming, [, RowBox[{ RowBox[{{, RowBox[{ RowBox[{Element, [, RowBox[{n, ,, Integers}], ]}], ,, RowBox[{Element, [, RowBox[{l, ,, Integers}], ]}], ,, RowBox[{n, >, 0}], ,, RowBox[{n, >, l, [GreaterEqual], 0}]}], }}], ,, RowBox[{ RowBox[{integrand, =, RowBox[{FullSimplify, [, SuperscriptBox[ RowBox[{(, RowBox[{R, *, r}], )}], 2], ]}]}], ;, RowBox[{Simplify, [, RowBox[{Integrate, [, RowBox[{integrand, ,, RowBox[{{, RowBox[{r, ,, 0, ,, [Infinity]}], }}]}], ]}], ]}]}]}], ]}]}], Input, CellChangeTimes->{{3.427632357819639*^9, 3.427632377400957*^9}, { 3.427632644205412*^9, 3.427632664272697*^9}, 3.4282990139911003`*^9, {3.428323376643766*^9, 3.428323506586858*^9}, {3.42832353786147*^9, 3.428323548325508*^9}, {3.428324884676128*^9, 3.428324891782604*^9}}] === Subject: Re: Solving nonlinear inequality constraints Fortunately William Nordhaus has provided most of the domain specific information we need for these equations. You are quite correct that s[0] gets a bit out of hand. It is an artifact of me releasing s, which I did to demonstrate that it was more than just mu[t] that needed to be optimised (as Nordhaus does). Probably Nordhaus doesn't correct for s[0] because it is a beginning effect that doesn't adversely affect his solver (conopt) and he never subsequently uses s[0] as a meaningful data point. In our case it is quite appropriate to set an initial value for s[0] and s[1] which I have done in the slightly amended notebook below. This notebook also takes up your suggestion that the simple variables are precalculated rather than left to be plumbed. This is done by defining a list of variables and evaluating them in the first part of the processing phase. It only takes 0.4 second and 6Mb to do either 10 or 60 periods. I had high hopes for these changes on my first run of 10 periods because the compile and processing time were cut by 2/3! However, memory is still the limiting factor and the new efficiency wasn't sufficient to permit 11 periods to be evaluated in 16Gb. Using the _NumberQ version of the notebook (below), the comparison statistics are: Approach Periods Compilation Total Memory Minutes Minutes Mb Old plumbed 10 8.3 mins 66.8 8901 New precalculated 10 6.0 mins 21.8 9051 New precalculated 11 23.9 mins Ran out of memory exceeds anything I could imagine in help on this group! I am proceeding to examine your suggestion of using rational numbers for simple decimals and will let you know what I find. Nevertheless, I wonder if we are getting down to secondary issues and missing a lurking primary issue that is causing Mm to use so much memory? Stuart > I cannot really help you much. The model requires serious > domain-specific knowledge even to begin to check for, say, > implementation errors. I can only make a few general remarks that might > help a bit. I strongly suspect there are in fact issues with your code > implementation. Having run the case of 5 periods, and looked at both > constraints/objective function and the results, I see two red flags. First is that the result has a huge value for s[0]. In[268]:= (*prepare optimising function*) > Timing[ > soln = NMinimize[Join[objectimous, endogenous], extendedvariables, > MaxIterations -> 50];] Out[268]= {50.8672, Null} In[269]:= soln Out[269]= {-283917., {k[2] -> 403.596, k[3] -> 319.585, > k[4] -> 278.518, k[5] -> 208.303, s[0] -> 6.66695*10^6, > s[1] -> 0.640164, s[2] -> 0.198601, s[3] -> 0.173787, > s[4] -> 0.106845, > s[5] -> 0.039112, [Mu][2] -> 0.129617, [Mu][3] - 0.113797, [Mu][4] -> 0.0955035, [Mu][5] -> 0.0550562}} And this remains the case when I allow more iterations, use fifferent > methods, etc. So I do not think it is an artifact of the NMinimize > internals. The second issue is that the objective, and some of the constraints, are > deeply nested expressions of their variables. I realize that the > recurrence nature of the definitions can allow this to happen. But I do > not believe that Nordhaus' implementation can suffer from this, or else > I believe he'd have no serious chance of handling 600 years (60 periods) > using any software. The upshot is I would recommend careful proof reading of the system. > I've looked a bit at p 2008 of his The Challenge of Global Warming... > and confess the equations for y[t], etc. do indeed look dauntingly > recursive. But still I suspect there is something he does to unravel the > mess. Finally, if any of the equalities are simple e.g. linear in some > variable(s), I'd say solve for such variables, use that to plug into > everything else, in the hope that some of the deep nestedness might be > removable. A last recommendation is that you use rational numbers for simple > decimals like 0.0 or .05. This may help to collapse things a bit, thus > possibly reducing the complexity. Daniel (*AppendTo[$Echo,stdout];*) (*SetOptions[stdout,PageWidth->110] ; *) (* Nordhaus Brief Climate Change Policy Model May 2008 *) (* Stuart Nettleton July 2008 *) starttime = AbsoluteTime[]; periods = 10; (* projection periods *) maxit = 5000; (* maximum iterations *) (* objective function *) (* program always minimises, so negative for maximisation *) obj = {-cumu[periods]}; (* optimisation variables: topolology leaves *) (* .. for NMinimize provide both upper and lower bounds *) (* .. for FindMinimum provide a single start estimate *) (* hold function prevents premature evaluation *) (*opt = {{[Mu][t],0.001,1},{k[t],100,10000}};*) opt = {{[Mu][t], 0.001, 1}}; (* exogenous parameters *) pop0 = 6514; popg = 0.35; popa = 8600; dela = 0.001; d[Sigma]1 = 0.003; d[Sigma]2 = 0.000; pback = 1.17; backrat = 2; gback = 0.05; [Rho] = 0.015; fex0 = -0.06; fex1 = 0.30; [Kappa]1 = 1; [Kappa]2 = 1; [Kappa]21 = 1; d[Kappa] = 0; [Theta] = 2.8; sr = 0.22; (* exogenous variables *) exogvars = {gfacpop, l, ga, a, g[Sigma], [Sigma], [CapitalTheta], eland, r, fex, [Kappa], [CapitalPi]}; gfacpop[t_] := gfacpop[t] = (Exp[popg*(t - 1)] - 1)/Exp[popg*(t - 1)]; l[t_] := l[t] = pop0*(1 - gfacpop[t]) + gfacpop[t]*popa; ga[t_] := ga[t] = ga[0]*Exp[-dela*10*(t - 1)]; a[t_] := a[t] = a[t - 1]/(1 - ga[t - 1]); g[Sigma][t_] := g[Sigma][t] = g[Sigma][0]* Exp[-d[Sigma]1*10*(t - 1) - d[Sigma]2*10*(t - 1)^2]; [Sigma][t_] := [Sigma][t] = [Sigma][t - 1]/(1 - g[Sigma][t]); [CapitalTheta][ t_] := [CapitalTheta][ t] = (pback*[Sigma][t]/[Theta])*((backrat - 1 + Exp[-gback*(t - 1)])/backrat); eland[t_] := eland[t] = eland[0]*(1 - 0.1)^(t - 1); r[t_] := r[t] = 1/(1 + [Rho])^(10*(t - 1)); fex[t_] := fex[t] = fex0 + If[t < 12, 0.1*(fex1 - fex0)*(t - 1), 0.36]; [Kappa][t_] := [Kappa][t] = If[t >= 25, [Kappa]21, [Kappa]21 + ([Kappa]2 - [Kappa]21)* Exp[-d[Kappa]*(t - 2)]]; [CapitalPi][t_] := [CapitalPi][t] = [Kappa][t]^(1 - [Theta]); (*s[t_]:= s[t] =sr;*) (* initial values of exogenous variables *) s[1] = s[0] = sr; ga[0] = 0.092; g[Sigma][0] = -0.0730; eland[0] = 11; a[1] = a[0] = 0.02722; [Sigma][1] = [Sigma][0] = 0.13418; [Kappa][1] = [Kappa][0] = 0.25372; (* endogenous parameters *) [Alpha] = 2.0; [Gamma] = .30; [Delta] = 0.1; [Eta] = 3.8; t2xco2 = 3; [Psi]1 = 0.00000; [Psi]2 = 0.0028388; [Psi]3 = 2.00; [Xi]1 = 0.220; [Xi]2 = [Eta]/t2xco2; [Xi]3 = 0.300; [Xi]4 = 0.050; [Phi]12 = 0.189288; [Phi]12a = 0.189288; [Phi]11 = 1 - [Phi]12a; [Phi]23 = 0.05; [Phi]23a = 0.05; [Phi]21 = 587.473*[Phi]12a/1143.894; [Phi]22 = 1 - [Phi]21 - [Phi]23a; [Phi]32 = 1143.894*[Phi]23a/18340; [Phi]33 = 1 - [Phi]32; mat1750 = 596.4; k0 = 137; y0 = 61.1; c0 = 30; mat0 = 808.9; mup0 = 1255; mlo0 = 18365; tat0 = 0.7307; tlo0 = 0.0068; [Mu]0 = 0.005; ceind0 = 0; cumu0 = 381800; scale1 = 194; (* endogenous equality constraints*) ceind[t_?NumberQ] := eind[t - 1] + ceind[t - 1]; eind[t_?NumberQ] := 10 *[Sigma][t] *(1 - [Mu][t]) *ygr[t] + eland[t]; for[t_?NumberQ] := [Eta]*(Log[(matav[t] + 0.000001)/mat1750]/ Log[2]) + fex[t]; mat[t_?NumberQ] := eind[t - 1] + [Phi]11*mat[t - 1] + [Phi]21*mup[t - 1]; matav[t_?NumberQ] := (mat[t] + mat[t + 1])/2; mlo[t_?NumberQ] := [Phi]23*mup[t - 1] + [Phi]33*mlo[t - 1]; mup[t_?NumberQ] := [Phi]12*mat[t - 1] + [Phi]22* mup[t - 1] + [Phi]32*mlo[t - 1]; tat[t_?NumberQ] := tat[t - 1] + [Xi]1*(for[t] - [Xi]2* tat[t - 1] - [Xi]3*(tat[t - 1] - tlo[t - 1])); tlo[t_?NumberQ] := tlo[t - 1] + [Xi]4*(tat[t - 1] - tlo[t - 1]); ygr[t_?NumberQ] := a[t]* k[t]^[Gamma] *l[t]^(1 - [Gamma]); dam[t_?NumberQ] := ygr[t]*(1 - 1/(1 + [Psi]1*tat[t] + [Psi]2*(tat[t]^[Psi]3))); [CapitalLambda][t_?NumberQ] := ygr[t] *[CapitalPi][t] *[CapitalTheta][t] *[Mu][t]^[Theta]; y[t_?NumberQ] := ygr[t]*(1 - [CapitalPi][t]*[CapitalTheta][ t]*[Mu][t]^[Theta])/(1 + [Psi]1* tat[t] + [Psi]2*(tat[t]^[Psi]3)); inv[t_?NumberQ] := (y[t] + 0.001)*s[t]; (*k[t_?NumberQ]:=10*inv[t-1]+((1-[Delta])^10)*k[t-1];*) ri[t_?NumberQ] := [Gamma]*y[t]/k[t] - (1 - (1 - [Delta])^10)/10; c[t_?NumberQ] := y[t] - inv[t]; u[t_?NumberQ] := ((c[t]/l[t])^(1 - [Alpha]) - 1)/(1 - [Alpha]); cumu[t_?NumberQ] := cumu[t - 1] + (l[t]*u[t]*r[t]*10)/scale1; cpc[t_?NumberQ] := c[t]*1000/l[t]; pcy[t_?NumberQ] := y[t]*1000/l[t]; (* initial values of endogenous variables *) cumu[1] = cumu[0] = cumu0; ceind[1] = ceind[0] = ceind0; mat[1] = mat[0] = mat0; mlo[1] = mlo[0] = mlo0; mup[1] = mup[0] = mup0; tat[1] = tat[0] = tat0; tlo[1] = tlo[0] = tlo0; y[0] = y0; k[1] = k[0] = k0; c[0] = c0; [Mu][1] = [Mu][0] = [Mu]0; (* endogenous inequality constraints*) endog = { k[t] <= 10*inv[t - 1] + ((1 - [Delta])^10)*k[t - 1], 0.02*k[periods] <= inv[periods], 100 <= k[t], 20 <= c[t], 10 <= mat[t], 100 <= mup[t], 1000 <= mlo[t], -1 <= tlo[t] <= 20, 0 <= tat[t] <= 20, ceind[t] <= 6000, 0 <= y[t], 0 <= inv[t], 0 <= ygr[t], 0 <= eind[t], 0 <= matav[t], 0 <= [Mu][t] }; (* processing ... *) (* calculate exogenous variables *) Do[Map[exogvars[[i]], Range[periods]], {i, Range[Length[exogvars]]}]; (*prepare the objective function*) objvars = Simplify[obj]; objectimous = Simplify[ Flatten[Union[Map[objvars /. t -> # &, Range[periods]]] /. x_Symbol[i_Integer /; i < 0] -> 0]]; (*prepare the endogenous constraints*) endovars = Simplify[endog]; endogenous = Simplify[ Flatten[Union[Map[endovars /. t -> # &, Range[periods]]] /. x_Symbol[i_Integer /; i < 0] -> 0]]; (*prepare the independent optimising variables*) optvars = Simplify[opt]; optimous = Union[Cases[ Flatten[Map[optvars /. t -> # &, Range[periods]], 1], {x_Symbol[_Integer], _Integer | _Real} | {x_Symbol[_Integer], _Integer | _Real, _Integer | _Real} | {x_Symbol[_Integer], _Integer | _Real, _Integer | _Real, _Integer | _Real}, Infinity]]; optimousvars = Union[Cases[optimous, x_Symbol[i_Integer] -> x[i], Infinity]]; (*include any additional optimising variables arising from the endogenous constraints*) primafacievars = Union[Cases[objectimous, x_Symbol[i_Integer] -> x[i], Infinity], Cases[endogenous, x_Symbol[i_Integer] -> x[i], Infinity]]; extendedvariables = Union[optimous, Complement[primafacievars, optimousvars]]; (*prepare optimising function*) Print[Round[(AbsoluteTime[] - starttime)/60, 0.1], minutes compilation time, commencing optimisation ...]; soln = NMinimize[Join[objectimous, endogenous], extendedvariables, MaxIterations -> maxit]; (*output results*) Print[Solution: , soln]; Print[Round[(AbsoluteTime[] - starttime)/60, 0.1], minutes from start to completion]; Print[Round[N[MaxMemoryUsed[]*10^-6], 1], Mb memory used]; === Subject: Re: Real and Complex Roots on Same Plot To The Moderator MMA Please replace the original with the following on my behalf, in which I made a small change for clarity. We are unable to Remove. [Posts cannot be replaced or removed - just corrected - moderator] Narasimham How to plot all real and complex roots of the following function in 3- D using Manipulate by varying constant c? q = 2.304 ; z[c_,x_ ] = q Sin[ c x ] + c Sin[q x]. The real roots of z[c] = 0 ( 0 < x < 20, 0 < real part of complex root < 20 ) should be plotted on x-axis, complex conjugates on y -axis, and (x, z) plot is in x -z plane where parameter c varies between 0.5 and 2.0 Narasimham === Subject: Re: mixed partial derivatives On Aug 13, 6:36 pm, Jens-Peer Kuska X[-3, v] == X[3, v] will not work with mixed derivatives aspecial on the > interval u in [0,3] and not u in [-3,3] > and your equation is singular. Jens > When mixed derivatives are not allowed, what is the fix? TIA > p=D[X[u,v],u]; q=D[X[u,v],v]; r =D[X[u,v],u,u]; s=D[X[u,v],u,v]; > t=D[X[u,v],v,v]; > GC[u_,v_] = (r t - s^2)/(1+p^2 + q^2)^2 > NDSolve[{GC[u,v]== 1, X[u, 0] == Cosh[u], Derivative[0,1][X][u, 0] == > 0, > X[-3, v] == X[3, v]},X[u,v], {u,0,3},{v,0,3}] > Narasimham p = D[X[u, v], u]; q = D[X[u, v], v]; r = D[X[u, v], u, u]; s = D[X[u, v], u, v]; t = D[X[u, v], v, v]; GC[u_, v_] = (r t - s^2)/(1 + p^2 + q^2)^2 NDSolve[{GC[u, v] == 1, X[u, 0] == Cosh[u], X[0, v] == Cos[v], Derivative[0, 1][X][0, v] == 0, Derivative[1, 0][X][u, 0] == 0}, X[u, v], {u, 0, 3}, {v, 0, 3}] Here also output says mixed partials are not allowed. Narasimham === Subject: Re: Installing package documentation usual locations (and my colleagues probably have too). This common directory is a supplement to those. JMJ > While learning how to get documentation for my own packages = to > show up in the Mathematica 6 Documentation Center, I came across > something that may puzzle other people. Perhaps it's worth a posting: > Although I prepared the documentation of the package complete with > pacletinfo.m file, etc., I found that it did now show up in the > Installed Add0Ons page of the Documentation Center. This turned ou= t > to be because I installed the packages, not in $BaseDirectory/ > Applications or $UserBaseDirectory/Applications, but in another > directory that is prepended to the value of $Path on kernel startup > (by my kernel init.m file). I do this because I share the packages > with colleagues and it saves them the trouble of re-installing when I > make small updates (one can discuss whether this is good practice or > not ...). > Anyway, it turns out that there is a global option for the Front End > called AddOnHelpPath that seems to control the path searched. Howeve= r > its help page says > This function has not been fully integrated into the long-term > Mathematica system, and is subject to change > So now I am trying to decide whether to tell my colleagues to change > this or to switch to distributing packages for them to install on > their own computers. > John Jowett Do you know about the environment variables MATHEMATICA_BASE and > MATHEMATICA_USERBASE which can be set on most (all?) platforms? It might > be an alternative to changing the various $*Path variables at the right > places... Of course your colleages would need to change that variable or > use a special start-script for mathematica which sets that variable. hth, albert- Hide quoted text - - Show quoted text - === Subject: Maximize Not sure why this won't work. I'm trying to maximize with respect to x subject to a constraint. I get an error message saying that the constraint is not a valid variable. Maximize[ g + (1-g)*x -(g/2)*x^2 - (g/2)*v, x = (a/c) + sqrt((d/c)*(v - 1/c)), x ] === Subject: Re: Extrema of 2D Interpolating function Is the fitted surface f(x,y) sufficiently smooth and successive partial derivatives continuous ? === Subject: Re: Extrema of 2D Interpolating function Use FindRoot approx[x_, base_] := RootApproximant[x/base, 2]*base data = Flatten[Table[{{x, y}, Sin[x] Sin[y]}, {x, 0, 2 Pi, Pi/3}, {y, 0, 2 Pi, Pi/3}], 1]; f[x_, y_] = Interpolation[data][x, y]; Plot3D[f[x, y], {x, 0, 2 Pi}, {y, 0, 2 Pi}] soln = FindRoot[{D[f[x, y], x] == 0, D[f[x, y], y] == 0}, {{x, #[[1]]}, {y, #[[2]]}}] & /@ {{1, 1}, {1, 5}, {3, 3}, {5, 1}, {5, 5}}; soln /. n_?NumberQ :> approx[n, Pi] {{x -> Pi/2, y -> Pi/2}, {x -> Pi/2, y -> (3*Pi)/2}, {x -> Pi, y -> Pi}, {x -> (3*Pi)/2, y -> Pi/2}, {x -> (3*Pi)/2, y -> (3*Pi)/2}} === Subject: Re: very long dendrogram > I have produced a hierarchical clustering > of 3,107 U. S. counties based on 1995-2000 > migration flows between the counties using a certain non-standard > methodology > (http://arxiv.org/abs/0807.1550). I have been able to > convert the results into a cluster object for use by > the `Hierarchical Clustering package of Mathematica. However, if I try to produce the full (very long) > dendrogram or even use the command, say, > TruncateDendrogram->{1,25}], , using say > Orientation->Right, the result is > not readable, being crammed into a small space. > So, I would like to expand this space by several orders. If this problem can be overcome, I would also > like to be able to eventually label the leaves of the dendrogram > by the names of the counties. But > For Cluster objects, the LeafLabels option > can take a function but not a list or Automatic, > as there is no unambiguous mapping between > the labels and data points in a Cluster object. > So, I am not sure how to proceed in this regard. Graphics options like AspectRatio and ImageSize are allowed to pass through DendrogramPlot, so you could play with these options to make a readable graphic. For instance, << HierarchicalClustering` data = BlockRandom[SeedRandom[1]; RandomInteger[10^6, 3107]]; DendrogramPlot[data, TruncateDendrogram -> {1, 25}, Orientation -> Right, AspectRatio -> 2, LeafLabels -> (# &)] is readable for me. To add names to the clustering, consider the {e1,e2,...}->{v1,v2,...} data syntax for FindClusters and Agglomerate. If you are performing the clustering via Agglomerate, you can simply use this syntax. As an example, compare the following two clusterings and plots. cl1 = Agglomerate[2^Range[3]] DendrogramPlot[cl1, LeafLabels -> Automatic] cl2 = Agglomerate[2^Range[3] -> {name1, name2, name3}] DendrogramPlot[cl2, LeafLabels -> Automatic] However, it sounds like you may have constructed your own Cluster object from information in the paper referenced. If this is the case, you can compare the results for cl1 and cl2 above to see where you would need to place the country names in your object and then use LeafLabels->Automatic in DendrogramPlot. Darren Glosemeyer Wolfram Research === Subject: Re: very long dendrogram dendrogram or even use the command, say, > TruncateDendrogram->{1,25}], , using say > Orientation->Right, the result is > not readable, being crammed into a small space. > So, I would like to expand this space by several orders. Paul, You can use the option *ImageSize* like in any other plot command. Note that this option is not listed by Options[DendrogramPlot] and is displayed in red by the syntactic checker. Nevertheless, it works like a charm :) For instance, Needs[HierarchicalClustering`] data = RandomInteger[{1, 100000}, {100}]; DendrogramPlot[data, LeafLabels -> (# &), Orientation -> Right] DendrogramPlot[data, LeafLabels -> (# &), Orientation -> Right, ImageSize -> 5000] === Subject: Re: very long dendrogram I have been doing something similar, though not with quite that number of leaves for the dendrograms. I think you'll want to do something like the following (setting AspectRatio and possibly ImageSize): DendrogramPlot[Rest /@ sheet1dat, AspectRatio -> 8, ImageSize -> {Automatic, 2500}, LeafLabels -> sheet1sites] I've never had a problem with the LeafLabels being out of order or anything like that. Note that my sheet1sites IS simply a list (I possibly made the right choice of not paying too much attention to the documentation, or it's wrong, or it didn't apply to my case or something), and the result is quite pretty. Note that it's also possible (through some really kludgy hackery) to present these things in what I call radial form, quite like the plot about halfway down this page: http://www.santafe.edu/~aaronc/randomgraphs/ . Basically, I make the regular, rectangular dendrogram first, then do a conformal transform on all the line coordinates to get the radial spokes and circumferential branches, then plot the result. It takes a while (and probably longer on your dataset, as there's lots of interpolation my code does to get smoothly-curved circular arcs), but it's quite nice. The leaves may also be labeled and color-coded, in a way that's nice and readable. I'm not quite sure I have perfected the package yet (and it may be considered somewhat proprietary by a colleague at this point), but I'll be happy to send examples off-list. Best wishes, Curtis O. > I have produced a hierarchical clustering > of 3,107 U. S. counties based on 1995-2000 > migration flows between the counties using a certain non-standard > methodology > (http://arxiv.org/abs/0807.1550). I have been able to > convert the results into a cluster object for use by > the `Hierarchical Clustering package of Mathematica. However, if I try to produce the full (very long) > dendrogram or even use the command, say, > TruncateDendrogram->{1,25}], , using say > Orientation->Right, the result is > not readable, being crammed into a small space. > So, I would like to expand this space by several orders. If this problem can be overcome, I would also > like to be able to eventually label the leaves of the dendrogram > by the names of the counties. But > For Cluster objects, the LeafLabels option > can take a function but not a list or Automatic, > as there is no unambiguous mapping between > the labels and data points in a Cluster object. > So, I am not sure how to proceed in this regard. Paul B. Slater -- 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: Help to remove equivalent (redundant) solutions from FindRoot[] Assume I have the following code to find extrema of the function interpolating Sin[x]Cos[y] in the square [0,2Pi]x[0,2Pi]: f[x_, y_] := Sin[x ] Cos[y] data = Flatten[ Table[{{x, y}, f[x, y]}, {x, 0, 2 Pi}, {y, 0, 2 Pi}], 1] g = Interpolation[data, InterpolationOrder -> 4] grad = D[g[x, y], {{x, y}, 1}] Table[FindRoot[grad, {{x, x0, 0, 2 Pi}, {y, y0, 0, 2 Pi}}], {x0, 0, 2 Pi}, {y0, 0, 2 Pi}] This will yield a list of the extrema, some of them are equivalent, but since the starting point of the algorithm is different every time one will get numerical errors that leads to tiny differences in the final values. Therefore, some entries of this list which ought to be equivalent are treated like distinct elements. Union[] or subsequent use of N[] with a given precision and Union[] won't help me get rid of the redundant elements. Any ideas how to bypass this problem? === Subject: Symbolic Linear Function I could not find anything in this group or on the internet about defining a generic linear function in Mathematica. I wanted a symbolic simplification of an expression where I had an (undefined) function that I knew was linear. I did the following: SetAttributes[e,{Flat, Orderless}]; e[a_?NumericQ * x_]:= a * e[x]; e[x_Plus]:=e/@x; This seemed to work fine and gave me the insight I wanted, but I was wondering if other people have thought about this and have different solutions or have any comments on my solution. p.s. The expression I was interested in was Variance[Log[1+x]]. I defined Variance[x_]:=e[x^2]-e[x]^2 where e is representing expectation, although I am not using any properties of expectation other than its linearity. I then looked at the Taylor expansion to order 5 with Variance[Normal[Series[Log[1+x],{x,0,5}]]] === Subject: Re: Notebook???? > well, I'm here again, this time I want to create a Notebook wih colors > and those things like Mathematica's Help, but really I don't how to do it You could use style sheets (this is certainly the easiest way to get good professional looking documents), See guide/Stylesheets http://reference.wolfram.com/mathematica/guide/Stylesheets.html === Subject: Re: Hypergeometric1F1 polynomial *Assumptions*, usually in combination with functions such as Simplify or > FullSimplify (when special functions are involved). For instance, In[1]:= Assuming[Element[n, Integers] && n > 0, > FullSimplify[ > Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}]]] Out[1]= E^x Hypergeometric0F1[1/2 - n, x^2/4] But that is the wrong answer as well. The sum is a polynomial of x of degree n, while Out[1] is not. For example, In[2]:= % /. n -> 1 Out[2]= -(1/2) E^x x (-((2 Cosh[x])/x) + 2 Sinh[x]) while it should be 1+x. > Note that the original result you got is equivalent for all n, indeed, to > the hypergeometric function you claim to be the correct solution. That is a bug. They are not equal for positive integer n. One is a polynomial of x, and another one is not. Alec === Subject: Re: Hypergeometric1F1 polynomial > Mathematica gives the wrong answer to the following sum, In[1]:= Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}] Out[1]= 2^(-(1/2) - n) E^x x^(1/2 + n) > BesselI[1/2 (-1 - 2 n), x] Gamma[1/2 - n] The correct answer is 1 for n=0 and Hypergeometric1F1[-n, -2 n, 2 x] for > integer n>0, which would be equal to the expression given by Mathematica if > n was not a positive integer. Another form of the correct answer is (2 x)^(n+1/2) E^x BesselK[n+1/2,x] n!/(2 n)!/Sqrt[Pi] Is there a way to apply some assumptions to get the correct answer? Alec, option *Assumptions*, usually in combination with functions such as Simplify or FullSimplify (when special functions are involved). For instance, In[1]:= Assuming[Element[n, Integers] && n > 0, FullSimplify[ Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}]]] Out[1]= E^x Hypergeometric0F1[1/2 - n, x^2/4] Note that the original result you got is equivalent for all n, indeed, to the hypergeometric function you claim to be the correct solution. In[2]:= s = Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}] Out[2]= 2^(-(1/2) - n) E^x x^(1/2 + n) BesselI[1/2 (-1 - 2 n), x] Gamma[1/2 - n] In[3]:= FullSimplify[s] Out[3]= E^x Hypergeometric0F1[1/2 - n, x^2/4] In[4]:= FullSimplify[s == Hypergeometric1F1[-n, -2 n, 2 x]] Out[4]= True In[5]:= s /. n -> 0 Out[5]= E^x Cosh[x] In[6]:= % // TrigToExp Out[6]= 1/2 + E^(2 x)/2 The above result, however, does not match the following: In[7]:= With[{n = 0}, Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}]] Out[7]= 1 (So the sum is now equal to one for n == 0, as you claimed.) The *With[]* construct rewrite the sum as Sum[Binomial[0, k]/Binomial[2 0, k]/k! (2 x)^k, {k, 0, 0}]] *before* evaluating it. Note that Mathematica fails in a weird way ( function == 0 ) checking the equivalence of In[8]:= FullSimplify[(2 x)^(n + 1/2) E^x BesselK[n + 1/2, x] n!/(2 n)!/Sqrt[Pi] == Hypergeometric1F1[-n, -2 n, 2 x]] Out[8]= (2^-n E^x x^(1/2 + n) BesselI[1/2 + n, x] Sec[n [Pi]])/ Gamma[1/2 + n] == 0 === Subject: Re: Hypergeometric1F1 polynomial > Mathematica gives the wrong answer to the following sum, In[1]:= Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}] Out[1]= 2^(-(1/2) - n) E^x x^(1/2 + n) > BesselI[1/2 (-1 - 2 n), x] Gamma[1/2 - n] The correct answer is 1 for n=0 and Hypergeometric1F1[-n, -2 n, 2 x] for > integer n>0, which would be equal to the expression given by Mathematica if > n was not a positive integer. Another form of the correct answer is (2 x)^(n+1/2) E^x BesselK[n+1/2,x] n!/(2 n)!/Sqrt[Pi] Is there a way to apply some assumptions to get the correct answer? Alec Here's one way to obtain the correct answer. The intermediate steps In[1]:= Sum[ Binomial[n, k] (2 x)^k/(Binomial[2 n, k] k!) // FunctionExpand // # /. Gamma[a_ - k] :> (-1)^k Pi Csc[a Pi]/Gamma[1 - a + k]&, {k, 0, n}] // FullSimplify // Simplify[#, Element[n, Integers]]& Out[1]= 1/Gamma[1/2 + n] 2^-n ((-2)^n E^x Pi Hypergeometric0F1Regularized[1/2 - n, x^2/4] + Sqrt[Pi] (-x)^(1 + n) HypergeometricPFQRegularized[{1, 1}, {1 - n, 2 + n}, 2 x]) Maxim Rytin m.r@inbox.ru === Subject: Re: Hypergeometric1F1 polynomial > The polynomial form you are expecting (see In[1]) can be obtained by > taking the series expansion about x == 0 to the order n (see In[2]). Well, I can obtain it even without series expansion. For example, as In[3]:= Hypergeometric1F1[-1, -2, 2 x] Out[3]= 1 + x The problem is that the answers given by Mathematica to the Sum problem, are not the same - they are not polynomials, with the series expansion, or without. === Subject: Re: Hypergeometric1F1 polynomial *Assumptions*, usually in combination with functions such as Simplify or >> FullSimplify (when special functions are involved). For instance, In[1]:= Assuming[Element[n, Integers] && n > 0, >> FullSimplify[ >> Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}]]] Out[1]= E^x Hypergeometric0F1[1/2 - n, x^2/4] But that is the wrong answer as well. The sum is a polynomial of x of degree > n, while Out[1] is not. For example, In[2]:= % /. n -> 1 Out[2]= -(1/2) E^x x (-((2 Cosh[x])/x) + 2 Sinh[x]) while it should be 1+x. > Note that the original result you got is equivalent for all n, indeed, to >> the hypergeometric function you claim to be the correct solution. That is a bug. They are not equal for positive integer n. One is a > polynomial of x, and another one is not. The polynomial form you are expecting (see In[1]) can be obtained by taking the series expansion about x == 0 to the order n (see In[2]). In[1]:= Table[Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}], {n, 0, 5}] // TableForm Out[1]//TableForm= 1 1 + x 2 x 1 + x + -- 3 2 3 2 x x 1 + x + ---- + -- 5 15 2 3 4 3 x 2 x x 1 + x + ---- + ---- + --- 7 21 105 2 3 4 5 4 x x x x 1 + x + ---- + -- + -- + --- 9 9 63 945 In[2]:= Table[Series[Hypergeometric1F1[-n, -2 n, 2 x], {x, 0, n}] // Normal, {n, 0, 5}] // TableForm Out[2]//TableForm= 1 1 + x 2 x 1 + x + -- 3 2 3 2 x x 1 + x + ---- + -- 5 15 2 3 4 3 x 2 x x 1 + x + ---- + ---- + --- 7 21 105 2 3 4 5 4 x x x x 1 + x + ---- + -- + -- + --- 9 9 63 945 -- Jean-Marc === Subject: Minimize with complex values HI i want to minimize the absolute value of the following expression how ca= n i do this in methamatica [exp(pi/4) +exp(3*pi/4)*exp(jp)]+[exp(pi/4) *exp(-5*pi*/4)]+[exp(3*pi/4= )*exp(-3*pi*j/4)exp(jp)]+ [exp(pi/4) *exp(-10*pi*j/4)]+[exp(pi/4) *exp(-3*pi*j/2)exp(jp)]+[exp(pi= /4)*exp(-15*pi*j/4)]+ [exp(3*pi/4)*exp(-9*pi*j/4)exp(jp)] p is the unknown value ,and it represent the phase...which is other than 0 = .....is there any way to calculate it. === Subject: Re: Multifile search Do you perhaps refer to the Wolfram Notebook Indexer, which is an indexing plug-in for Google Desktop? This utility has been shipping with Mathematica since at least 6.0 and perhaps even since 5.2. The Mathematica installer offers to install it after the main installation of Mathematica itself. If you didn't install it then, you may be able to find it on your installation media. You can also find the plug-in by browsing to: and then searching for it; however the version there is 1.1 beta, whereas the one shipped with Mathematica 6 is version 2. > I thought I saw an announcement of a search utility that would act > like Google Desktop but for Mathematica files. I want to find what file > references certain symbols without having to go through hundreds of > files. I can't recall where I saw this or even if I already have it. Steve Gray > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Multifile search I like Google Desktop (use the linux version), but there's one thing which is VERY annoying to me, and pretty much a show-stopper for searching for my Mathematica .m files (at least on linux): It ignores hidden (dot) files. Google knows of this, and ignores it (or has decided it's not worth changing for privacy reasons or something like that, but I haven't read a good explanation). This isn't a huge issue for many things, but my main Mathematica package files are in a /home/username/.Mathematica directory, which I am loath to change. Therefore, Google Desktop never sees them. Instead, I have to use Recoll and/or some of the newer strigi tools (for linux). On Windows, I have had a few issues with Copernic losing its indexes, or locking up, but otherwise it's quite nice, and finds .m files. I haven't used Google Desktop on Windows, though. Hopefully something in there might be useful to you! Curtis O. > I thought I saw an announcement of a search utility that would act > like Google Desktop but for Mathematica files. I want to find what file > references certain symbols without having to go through hundreds of > files. I can't recall where I saw this or even if I already have it. > > Steve Gray > http://library.wolfram.com/infocenter/Utilities/5596 be what you were looking for... === Subject: problems with condition in ReplaceAll can anybody help me to find an expression in order to replace only subexpressions of which the numerator is strictly positive in the following ReplaceAll command? !(ReplaceAll[1 + 0^((1/(1 - ìª_n))), If[FreeQ[_, 0^_], 0^_ -> If[Assuming[{0 < ìª_n < 1}, Sign[_[([2])]] > 0], 0, Hold[0]], 0^_ -> 1]])? I tried to use a sign command for the second part of the subexpression which is to be tested, but obviously the pattern symbol _ is not the correct wildcard symbol. frhes === Subject: graph question Hi I have a graph that is simillat to the booleanAlgebra graphs as shown here: http://www.cs.sunysb.edu/~skiena/combinatorica/animations/ham.html however, my graph is not boolean, it is actually multidimensional. I am not sure if mathematica has a function that can allow for customzing the function ShowGraph[ a = BooleanAlgebra[5]] to be a 5 dimensional graph for instance, each dimension has an upper bound that is not boolean, could be anything, like I give it a vector of 5 elements, where the elements are the bounds of the dimensions, and the length of the vector is the dimensionality. Is there any built in function like that? or if there is not, how can I implement a function like that, I appreciate any hints, Manal === Subject: Re: Need a Faster Solution > I got hooked on the following little number theory problem which appears in > the August issue of Discovery magazine. Susan has more than one dollar in > change, but she still can't make exact change for a dollar bill. What is the > maximum amount of money that Susan could have in pennies, nickels, dimes and > quarters for this to be true? I solved the problem using the following Mathematica code: coins={1,5,10,25}; > dollar=FrobeniusSolve[coins,100]; Catch[Do[t=Times@@Length/@(Cases[dollar,{p_,n_,d_,q_}/; (p<=#1&&n<=#2 && > d<=#3 && q<=#4)]&@@@FrobeniusSolve[coins,a]); > If[t==0,Throw[a]],{a,130,101,-1}]] Starting with a maximum guess of $1.30 this gives the correct answer of > $1.19 in about 5 seconds. The problem is that if the problem is made more > complicated by adding more possible coin denominations (and/or paper > currency) the execution time become very long indeed. Is there a way to speed up the solution to this type of problem so that I > can handle more complicated cases in a reasonable time? > John >> Late response, but I didn't get time to look hard at this until now. It >> seems to be a difficult problem in terms of complexity, though I'm not >> certain I have the best possible approach. >> [...] I forgot a few things. One is that Mathematica already has the > functionality for elbows-to-corners (e2c) conversion built in. It seems > to be maybe 10 x faster than what I had shown. Another is that one can often use term rewriting methods to bring down > the number of elbows under consideration. This specifically applies in > the case where the first denomination divides all others, and the second > divides all others above it. In our example we can swap 5 pennies for a > nickel and not hurt ourselves. It turns out that this removes most of > the elbows from consideration, thus making the job of e2c easier. Here is the entire code needed. It assumes the first two denominations > are 1 and 5 respectively. Were this not the case, one could still have > working code by removing the replacement rule that begins {p_,n_,rest}... maxNoChange2[coins_List, amount_Integer /; amount >= 1] /; > Not[And @@ Map[IntegerQ, amount/coins]] := Infinity maxNoChange2[coins_List, amount_Integer /; amount >= 1] := > Reduce`FarthestCorner[ > coins, (FrobeniusSolve[coins, > amount] /. {p_, n_, rest___} /; > p > 5 :> {p - 5*(Floor[p/5] - 1), n + Floor[p/5] - 1, rest})] - > Total[coins] So here is the example that was taking around 80 seconds. Without the > elbow penny-to-nickel replacement rule it is around 6 seconds, and with > it we are down to 1 second. In[19]:= coins = {1, 5, 10, 25, 50}; In[20]:= Timing[maxNoChange2[coins, 200]] > Out[20]= {0.992062, 219} There may well be further improvements to be had. I'm not certain I have > exhausted all possible replacements (though I am certain we need to > retain 5 pennies when there are more than 5). I am not certain there is > no better way to go about this. Frankly, I'm not sure of much of > anything at the moment. One resource I will mention, since it is really good for computing http://portal.acm.org/citation.cfm?id=1328333.1328354&coll=&dl= This and others of relevance can be obtained in pdf form at the URL below. http://www.broune.com/papers/ Daniel Lichtblau > Wolfram Research This can get addicting. I'll outline a couple of additional speed improvements. (1) We can do more swaps than just pennies for nickels. Provided we keep at least one nickel, we can safely swap 2 nickels for 1 dime. We can swap 5 dimes for 2 quarters. Etc. Here I show this with the two lowest denomination allowable swaps. AAgain, it is not so obvious (to me) how to generalize this idea for a different set of coin denominations. maxNoChange3[coins_List, amount_Integer /; amount >= 1] /; Not[And @@ Map[IntegerQ, amount/coins]] := Infinity maxNoChange3[coins_List, amount_Integer /; amount >= 1] := Reduce`FarthestCorner[coins, Union[(FrobeniusSolve[coins, amount] /. ({p_, n_, rest___} /; p >= 5 :> {p - 5*(Floor[(p - 1)/5]), n + Floor[(p - 1)/5], rest}) /. {p_, n_, d_, rest__} /; n >= 3 :> {p, n - 2*Floor[(n - 1)/2], d + Floor[(n - 1)/2], rest})]] - Total[coins] coins = {1, 5, 10, 25, 50}; In[150]:= Timing[maxNoChange3[coins, 200]] Out[150]= {0.376025, 219} The bottleneck is now in the FrobeniusSolve. Well, it would be, if we do more swaps as described above to further reduce the number of elbows. Already that solve step is more than 50% of the time spent. We can reduce further, in general, by observing that we can reduce the amount to avoid ($2 above) by multiples of the lcm of our denominations, until we are less than twice that lcm. So in this case we might instead look at how much we can have if we cannot make change for 50 cents. Then just add 150 cents to the result. I leave proof of this to the interested reader. Daniel Lichtblau Wolfram Research === Subject: Re: LaTex to Mathematica > I tried Import to import the Latex file but it shows error info as below: > Import::texerr: Error: Math character 'alpha ' in non-math mode. Can you please let me know what is the problem? The following message strongly suggests that your input file is not correctly written in LaTeX. Apparently you have some regular (plain) text that contains special math character without being enclosed within dollar sign $. For instance, . The parameter alpha is of crucial importance. will generate an error, while . The parameter $alpha$ is of crucial importance. will be parse correctly. Having said that, I would strongly suggest that you latexify (i.e. compile with whatever installation of LaTeX you have) your source file to be sure to check and correct any error and also warning messages. Note that it is very likely that LaTeX, when processing the first sentence will generate a warning about math mode missing, yet add the missing math mode characters in the intermediate file that is producing, leaving the original source file untouched. Therefore, you must fix these warnings/errors by yourself within the source file you are going to give to Mathematica. === Subject: Re: LaTex to Mathematica > I tried something similar, but using ToExpression[...,TeXForm], > likewise removing the trailing from the original. (I was surprised that Mathematica just ignored the &, which is > evidently in the original expression because that expression is part of > a larger LaTeX construct such as a begin{align}...end{align). However, I was unable to see how to let Mathematica itself convert the > single backslashes, which of course are interpreted as escape symbols, > to the needed double-backslashes. The obvious thing, expr = ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ > {varepsilon}_{1}; expr/. -> does not work, of course. However, *StringReplace[expr, -> ]* works. . Note, that expr needs some additional editing before being converted because b is an ASCII escape sequence for Bell and it is converted -- more or less -- to its numeric value. Therefore beta becomes .08eta :) . Also, depending on your settings, Mathematica can automatically convert the escape character into when pasting a string. In[2]:= expr = ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1} Out[2]= ln{H}^{*} &= {X}_{1} {.08eta}_{1} + {alpha}_{1}lnE+ { varepsilon}_{1} . Finally, the string must start and end with a dollar sign $ that denotes math mode in LaTeX. StringReplace[ $ <> ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1} <> $, -> ] ToExpression[%, TeXForm] (Note that TeXForm is entered without double quotes.) === Subject: No Memory Available I am using NDSolve to do integration in time for 24 variables. I can choose only to do the integration for a short time range, otherwise I get the error: No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. What frustrates me is that I get this error only after a minute or so although I can accept to carry out the run for a much longer time to reach the steady state solution but this error prevents me from this by killing the whole kernel. I tried to set the Historylength to zero with no improvement. I checked the documentation and previous threads on this error but could not find any thing useful. Is there a way I can increase the allocated memory even virtually, or maybe tell Mathematica to wipe the memory out during the run? === Subject: Re: x-axis value issues > I posted this on physicsforums.com but I thought I would link here, > too, for better coverage (plus I could download the necessary files). Any help is much appreciated! http://physicsforums.com/showthread.php?t=249880 You could get more answers from this newsgroup by stating your problem and giving an example of code (and possibly some data) to reproduce the error. At least, if you post any files somewhere, they should be freely accessible and not require any form of registration (I tried to download the files, but I was stopped short since I am not a member of the forum and no I am not going to become a member of the incriminated forum :) === Subject: Re: NDSolve precision and velocity problem Actually, I tried Method->Adams, but after 10 minutes waiting I gave up. BDF seems to work fine though. I did't see it in the Documentation. > I have an ODE system that takes lots of time to solve with NDSolve >> (several minutes), >> whereas the same system with the FORTRAN solver LSODA >> solves the problem in an second. >> When I decrease the precision, e.g. AccuracyGoal->6, NDSolve crashes. >> It often crashes, because it finds complex values in a >> less-than-comparison. Maybe it's a method problem. >> How do I tell NDSolve, to use the same methods as the LSODEA solver? If by the above you mean using either Adams or Backward > Differentiation Formula (BDF) methods [1], for nonstiff or stiff > cases, respectively, you can use the option *Method*. The following might be worth reading (or at least browsing): [2, 3, 4] - Jean-Marc [1] LSODE, _Serial Fortran Solvers for ODE Initial Value Problems_, > https://computation.llnl.gov/casc/odepack/odepack_home.html [2] _IDA Method for NDSolve_, [3] Adams methods, _NDSolve Method Plug-in Framework_, > http://reference.wolfram.com/mathematica/tutorial/NDSolvePlugIns.html [4] _Monitoring and Selecting Algorithms_, > http://reference.wolfram.com/mathematica/tutorial/MonitoringAndSelectingAlgor ithms.html > -- ---------------------------------------------- JÌ.a6rg Schaber Max Planck Institute for Molecular Genetics Ihnestrasse 63-73, 14195 Berlin, Germany Phone: +49 30 804093 19, Fax: +49 30 804093 22 ---------------------------------------------- === Subject: Re: NDSolve precision and velocity problem what mean same methods as the LSODEA has five methods implemented, as listed in http://www.netlib.org/odepack/opksmain.f and you don't tell us what method you use. And *why* you want to re-invent the wheel if you already *have* a solution with LSODA. Jens I have an ODE system that takes lots of time to solve with NDSolve > (several minutes), > whereas the same system with the FORTRAN solver LSODA > solves the problem in an second. > When I decrease the precision, e.g. AccuracyGoal->6, NDSolve crashes. It > often crashes, because it finds complex values in a less-than-comparison. Maybe it's a method problem. > How do I tell NDSolve, to use the same methods as the LSODEA solver? > joerg === Subject: Re: NDSolve precision and velocity problem > I have an ODE system that takes lots of time to solve with NDSolve > (several minutes), > whereas the same system with the FORTRAN solver LSODA > solves the problem in an second. > When I decrease the precision, e.g. AccuracyGoal->6, NDSolve crashes. It often crashes, because it finds complex values in a less-than-comparison. Maybe it's a method problem. > How do I tell NDSolve, to use the same methods as the LSODEA solver? If by the above you mean using either Adams or Backward Differentiation Formula (BDF) methods [1], for nonstiff or stiff cases, respectively, you can use the option *Method*. The following might be worth reading (or at least browsing): [2, 3, 4] - Jean-Marc [1] LSODE, _Serial Fortran Solvers for ODE Initial Value Problems_, https://computation.llnl.gov/casc/odepack/odepack_home.html [2] _IDA Method for NDSolve_, [3] Adams methods, _NDSolve Method Plug-in Framework_, http://reference.wolfram.com/mathematica/tutorial/NDSolvePlugIns.html [4] _Monitoring and Selecting Algorithms_, http://reference.wolfram.com/mathematica/tutorial/MonitoringAndSelectingAlgo rithms.html === Subject: Re: Move frame labels closer to frame? solutions. --Mark === Subject: Connecting pipes I'd like to draw a network of connecting of pipes (like that 3D pipe screen saver). Supposed I have the coordinates stored in Coord, and I'd like to connect, say, Coord[[4]] to Coord[[2]], etc. I figure I could use the cylinder function (damned Euler angle!) to draw a single pipe, but haven't quite figured out how to connect them together. Any suggestion? Caosau PS. Bonus if I can do it with cartesian coords. === Subject: fractional derivative of 1/(log x)? derivative (order t) of 1/(log x), where t can range from -2 and -0.5. Michael -- View this message in context: http://www.nabble.com/fractional-derivative-of-1-%28log-x%29--tp18990545p1899 0545.html Sent from the MathGroup mailing list archive at Nabble.com. === Subject: Re: Another Out of Memory Problem > I can do the following: Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] I almost immediately get this: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. > Kevin > This seems to fail for any decimal coefficient - not just 2.5. It is obviously a bug, and should be reported to Wolfram. Some bugs - either in user code, or within Mathematica - manifest themselves as a never ending loop of some sort that uses up whatever memory is available. Even if you were to run the calculation with 100 Gb of memory (i.e. using a 64-bit machine) you would almost certainly see the same result, but it would take a little longer while it consumed the extra memory! David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Another Out of Memory Problem Confirmed on 32-bit linux (kernel 2.6.25-2-686) with 3.5 GB of memory. --C.O. > I can do the following: Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] I almost immediately get this: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. === Subject: Re: Another Out of Memory Problem Jean-Marc, Kevin >> fast. The error message comes up within less than 1 second. >> [... Cross-posted on MathGroup ...] Kevin, I have just tried to do the integration with approximate coefficient > Mathematica 6.0.3). . On this 64-bit platform, the kernel does not crash: the expression > returns unevaluated after about four minutes elapsed-time (or about > two minutes cpu-time) . However, the computation takes up to about 2.2 GB of memory, which > is fine on a 64-bit system but is too much on a standard 32-bit > platform command) that the memory consumption varies/oscillates quickly from > nearly nothing (few dozens of MB) to one or two GB in a fraction of > second . OTOH, with exact coeffiecients, the integration consumes about 200 > MB of memory (steady increase from the beginning to the end, no wild > variations, as far as I can tell), though the process is seven time > slower So it seems that the algorithm goes wild when used with approximate > numbers, for reasons I am clueless about. (* Timing and memory consumption with *floating-point* coefficients *) In[1]:= Integrate[Cos[2.5*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing Out[1]= > I z Cos[x] > {112.795, Integrate[E Cos[2.5 x], {x, -Pi, Pi}]} In[2]:= MaxMemoryUsed[]/2.^30 GB Out[2]= 2.19748 GB In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) (* Timing and memory consumption with *exact* coefficients *) In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing Out[1]= > I z Cos[x] 5 x > {705.092, Integrate[E Cos[---], {x, -Pi, Pi}]} > 2 In[2]:= MaxMemoryUsed[]/2.^30 GB Out[2]= 0.191426 GB In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) >> Kevin >> >> I can do the following: >> Integrate[Cos[2*x]* >> Exp[I*z*Cos[x]], >> {x, -Pi, Pi}] >> which produces a Bessel function answer; however if I change the >> argument in the cosine to 2.5 as in: >> Integrate[Cos[2.5*x]* >> Exp[I*z*Cos[x]], >> {x, -Pi, Pi}] >> I almost immediately get this: >> No more memory available. >> Mathematica kernel has shut down. >> Try quitting other applications and then retry. >> Any ideas why? I am running XP with 2Gb of memory. >> > When using symbolic function (i.e. Integrate rather than NIntegrate, Solve > rather than NSolve, etc.) it is always a good idea to feed the function with > *exact* (infinite precision) numbers, thus 5/2 rather 2.5 in your case. > (Mathematica does not find any closed form for your integrand. Note that it > take a while to compute but memory consumption is under control.) >> In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] >> Out[1]= >> I z Cos[x] 5 x > Integrate[E Cos[---], {x, -Pi, Pi}] > 2 > > -- Kevin J. McCann Research Associate Professor JCET/Physics University of Maryland, Baltimore County (UMBC) 1000 Hilltop Circle Baltimore, MD 21250 === Subject: Re: Another Out of Memory Problem > Jean-Marc, guess I can rationalize the coefficients. Kevin Unfortunately, I am afraid that it might be not that simple or straightforward depending on the complexity or size of the rational numbers generated. For instance, using different approximations/rationalizations to 2.718281828, Mathematica reaches 2 GB of memory in less than 20 s, about 42 s, and never when fed with 1633527/600941, 15062/5541, and 193/71, respectively, as coefficients of x. So you may have to monitor the behavior of Integrate and fine tune accordingly the second parameter of Rationalize to find the best comprise among memory consumption, performances, and accuracy of the result. IIn[1]:= f = Rationalize[Cos[2.718281828*x]*Exp[I*z*Cos[x]], 10^-12] Out[1]= E^(I*z*Cos[x])*Cos[(1633527*x)/600941] In[2]:= MemoryConstrained[Integrate[f, {x, -Pi, Pi}], 2 2^30, More than 2 GB required] // Timing Out[2]= {19.8789, More than 2 GB required} In[3]:= MaxMemoryUsed[]/2.^30 GB Out[3]= 2.02337 GB In[1]:= f = Rationalize[Cos[2.718281828*x]*Exp[I*z*Cos[x]], 10^-7] Out[1]= E^(I*z*Cos[x])*Cos[(15062*x)/5541] In[2]:= MemoryConstrained[Integrate[f, {x, -Pi, Pi}], 2 2^30, More than 2 GB required] // Timing Out[2]= {42.521, More than 2 GB required} In[3]:= MaxMemoryUsed[]/2.^30 GB Out[3]= 2.01026 GB In[1]:= f = Rationalize[Cos[2.718281828*x]*Exp[I*z*Cos[x]], 10^-4] Out[1]= E^(I*z*Cos[x])*Cos[(193*x)/71] In[2]:= MemoryConstrained[Integrate[f, {x, -Pi, Pi}], 2 2^30, More than 2 GB required] // Timing Out[2]= $Aborted (* After one hour -- elapsed time *) In[3]:= MaxMemoryUsed[]/2.^30 GB Out[3]= 0.41452 GB - Jean-Marc > fast. The error message comes up within less than 1 second. > [... Cross-posted on MathGroup ...] Kevin, I have just tried to do the integration with approximate coefficient > Mathematica 6.0.3). . On this 64-bit platform, the kernel does not crash: the expression > returns unevaluated after about four minutes elapsed-time (or about > two minutes cpu-time) . However, the computation takes up to about 2.2 GB of memory, which > is fine on a 64-bit system but is too much on a standard 32-bit > platform command) that the memory consumption varies/oscillates quickly from > nearly nothing (few dozens of MB) to one or two GB in a fraction of > second . OTOH, with exact coeffiecients, the integration consumes about 200 > MB of memory (steady increase from the beginning to the end, no wild > variations, as far as I can tell), though the process is seven time > slower So it seems that the algorithm goes wild when used with approximate > numbers, for reasons I am clueless about. (* Timing and memory consumption with *floating-point* coefficients *) In[1]:= Integrate[Cos[2.5*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing Out[1]= > I z Cos[x] > {112.795, Integrate[E Cos[2.5 x], {x, -Pi, Pi}]} In[2]:= MaxMemoryUsed[]/2.^30 GB Out[2]= 2.19748 GB In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) (* Timing and memory consumption with *exact* coefficients *) In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing Out[1]= > I z Cos[x] 5 x > {705.092, Integrate[E Cos[---], {x, -Pi, Pi}]} > 2 In[2]:= MaxMemoryUsed[]/2.^30 GB Out[2]= 0.191426 GB In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) Kevin > I can do the following: Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] I almost immediately get this: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. > When using symbolic function (i.e. Integrate rather than NIntegrate, Solve > rather than NSolve, etc.) it is always a good idea to feed the function with > *exact* (infinite precision) numbers, thus 5/2 rather 2.5 in your case. > (Mathematica does not find any closed form for your integrand. Note that it > take a while to compute but memory consumption is under control.) In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] Out[1]= I z Cos[x] 5 x > Integrate[E Cos[---], {x, -Pi, Pi}] > 2 === Subject: Re: Another Out of Memory Problem Jens > I can do the following: Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] I almost immediately get this: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. > Kevin > === Subject: Re: Another Out of Memory Problem > I can do the following: Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] I almost immediately get this: No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. Any ideas why? I am running XP with 2Gb of memory. When using symbolic function (i.e. Integrate rather than NIntegrate, Solve rather than NSolve, etc.) it is always a good idea to feed the function with *exact* (infinite precision) numbers, thus 5/2 rather 2.5 in your case. (Mathematica does not find any closed form for your integrand. Note that it take a while to compute but memory consumption is under control.) In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] Out[1]= I z Cos[x] 5 x Integrate[E Cos[---], {x, -Pi, Pi}] 2 === Subject: Re: Another Out of Memory Problem > fast. The error message comes up within less than 1 second. [... Cross-posted on MathGroup ...] Kevin, I have just tried to do the integration with approximate coefficient Mathematica 6.0.3). . On this 64-bit platform, the kernel does not crash: the expression returns unevaluated after about four minutes elapsed-time (or about two minutes cpu-time) . However, the computation takes up to about 2.2 GB of memory, which is fine on a 64-bit system but is too much on a standard 32-bit platform command) that the memory consumption varies/oscillates quickly from nearly nothing (few dozens of MB) to one or two GB in a fraction of second . OTOH, with exact coeffiecients, the integration consumes about 200 MB of memory (steady increase from the beginning to the end, no wild variations, as far as I can tell), though the process is seven time slower So it seems that the algorithm goes wild when used with approximate numbers, for reasons I am clueless about. (* Timing and memory consumption with *floating-point* coefficients *) In[1]:= Integrate[Cos[2.5*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing Out[1]= I z Cos[x] {112.795, Integrate[E Cos[2.5 x], {x, -Pi, Pi}]} In[2]:= MaxMemoryUsed[]/2.^30 GB Out[2]= 2.19748 GB In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) (* Timing and memory consumption with *exact* coefficients *) In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing Out[1]= I z Cos[x] 5 x {705.092, Integrate[E Cos[---], {x, -Pi, Pi}]} 2 In[2]:= MaxMemoryUsed[]/2.^30 GB Out[2]= 0.191426 GB In[3]:= $Version Out[3]= 6.0 for Mac OS X x86 (64-bit) (May 21, 2008) > Kevin > > I can do the following: >> Integrate[Cos[2*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] > which produces a Bessel function answer; however if I change the > argument in the cosine to 2.5 as in: >> Integrate[Cos[2.5*x]* > Exp[I*z*Cos[x]], > {x, -Pi, Pi}] >> I almost immediately get this: >> No more memory available. > Mathematica kernel has shut down. > Try quitting other applications and then retry. >> Any ideas why? I am running XP with 2Gb of memory. When using symbolic function (i.e. Integrate rather than NIntegrate, Solve >> rather than NSolve, etc.) it is always a good idea to feed the function with >> *exact* (infinite precision) numbers, thus 5/2 rather 2.5 in your case. >> (Mathematica does not find any closed form for your integrand. Note that it >> take a while to compute but memory consumption is under control.) In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] Out[1]= I z Cos[x] 5 x >> Integrate[E Cos[---], {x, -Pi, Pi}] >> 2 === Subject: Re: ODE in mathematica. what is wrong? > I am a freshman of Mathematica, I need help here... I met such problem as: NDSolve[{ y'[x] == -[Rho]y[x], y[0] == Subscript[y, 0], > I[HBar] y'[x] == [Epsilon]y[x], y[0] == Subscript[y, 0], > y''[x] + 2 [Rho]y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}, y, x] > NDSolve::dvnoarg: The function y appears with no arguments. How to Handle??? Few remarks: . Do not use subscripted functions/variables or use the Symbolize command from the Notation package . Spaces between variables are important since they are interpreted as implicit multiplication (a b == a*b != ab) otherwise you just have a name two ore more symbols . Capital I is a reserved/built in symbol that denote the imaginary unit Sqrt[-1], here I believe you want i . Your system is overdetermined, which usually mean that you have conflicting equations . NDSolve requires to have numeric values for every parameter, otherwise you may want to use DSolve, which is a symbolic solver In[1]:= NDSolve[{(y^[Prime])[x]==-[Rho] y[x],y[0]==y0,i [HBar] (y^[Prime])[x]==[Epsilon] y[x],y[0]==y0,(y^[Prime][Prime])[x]+2 [Rho] (y^[Prime])[x]+k^2==0,(y^[Prime])[0]==g0},y,x] During evaluation of In[1]:= NDSolve::overdet: There are fewer dependent variables, {y[x]}, than equations, so the system is overdetermined. Out[1]= NDSolve[{(y^[Prime])[x]==-[Rho] y[x],y[0]==y0,i [HBar] (y^[Prime])[x]==[Epsilon] y[x],y[0]==y0,k^2+2 [Rho] (y^[Prime])[x]+(y^[Prime][Prime])[x]==0,(y^[Prime])[0]==g0},y,x] In[2]:= DSolve[{(y^[Prime])[x]==-[Rho] y[x],y[0]==y0},y,x] Out[2]= {{y->Function[{x},E^(-x [Rho]) y0]}} === Subject: Re: ODE in mathematica. what is wrong? > I am a freshman of Mathematica, I need help here... I met such problem as: NDSolve[{ y'[x] == -[Rho]y[x], y[0] == Subscript[y, 0], > I[HBar] y'[x] == [Epsilon]y[x], y[0] == Subscript[y, 0], > y''[x] + 2 [Rho]y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}, y, x] > NDSolve::dvnoarg: The function y appears with no arguments. How to Handle??? Take a look at the parameters needed by NDSolve. -- Franco Milicchio DiS - Dept. of Studies on Structures DIA - Dept. of Computer Science and Engineering University Roma Tre http://www.dia.uniroma3.it/~milicchi/ === Subject: Re: ODE in mathematica. what is wrong? Several things are wrong. First, you didn't put spaces between things like rho and y, where I assume you meant to multiply. Second, for a numerical integration everything must be a number (except y and its derivatives); so, you need to specify hbar, rho, epsilon,k, ... Those are just the syntax issues. BTW, if you are going to use subscripted things like y_sub_o you need to use the Notation package and Symbolize them. Now, your differential equation set has multiple equations for y'[x]. Is that what you really meant? I am not sure what problem you are solving here. Perhaps one second order differential equation with different sets of initial conditions? I am not sure. Kevin > I am a freshman of Mathematica, I need help here... I met such problem as: NDSolve[{ y'[x] == -[Rho]y[x], y[0] == Subscript[y, 0], > I[HBar] y'[x] == [Epsilon]y[x], y[0] == Subscript[y, 0], > y''[x] + 2 [Rho]y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}, y, x] > NDSolve::dvnoarg: The function y appears with no arguments. How to Handle??? > === Subject: Re: ODE in mathematica. what is wrong? First, insert the missing spaces between other names and y (and avoid the Subscript expressions): NDSolve[{y'[x]==-[Rho] y[x],y[0]==y0,I [HBar] y'[x]==[Epsilon] y[x],y[0]==y0,y''[x]+2 [Rho] y'[x]+k^2==0,y'[0]==g0},y,x] Second,it doesn't make sense to ask for a NUMERICAL solution, with NDSolve, unless you specify an interval: the last argument should not be x but rather something like {x,0,2}. Third, I'm suspicious of your system of differential equations, because if I ask for an exact, symbolic expression by using DSolve instead of NDSolve... DSolve[{y'[x]==-[Rho] y[x],y[0]==y0,I [HBar] y'[x]==[Epsilon] y[x],y[0]==y0,y''[x]+2 [Rho] y'[x]+k^2==0,y'[0]==g0},y[x],x] ... then I get an error DSolve::overdet There are fewer dependent variables than equations, so the system is overdetermined. > I am a freshman of Mathematica, I need help here... I met such problem as: NDSolve[{ y'[x] == -[Rho]y[x], y[0] == Subscript[y, 0], > I[HBar] y'[x] == [Epsilon]y[x], y[0] == Subscript[y, 0], > y''[x] + 2 [Rho]y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}, y, x] > NDSolve::dvnoarg: The function y appears with no arguments. How to Handle??? === Subject: Re: ODE in mathematica. what is wrong? the first thing whats wrong is, that you have 3 equations for y[x] and the solution of y'[x] == -[Rho]y[x] is different form the solution I[HBar] y'[x] == [Epsilon]y[x] and has nothing to do with the solution of y''[x] + 2 [Rho]y'[x] + k^2 == 0 The second thing that is wrong, is that you call NDSolve[] instead of DSolve[] and the third thing is that you use Subscript[y,0] as initial value, because you have said that the symbol y stand for the solution function in the ode and it can't be the solution *and* the inital value. But DSolve[#, y[x], x] & /@ {{y'[x] == -[Rho] y[x], y[0] == Subscript[[ScriptY], 0]}, {I [HBar] y'[x] == [Epsilon] y[x], y[0] == Subscript[[ScriptY], 0]}, {y''[x] + 2 [Rho] y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}} work as it should. Jens > I am a freshman of Mathematica, I need help here... I met such problem as: NDSolve[{ y'[x] == -[Rho]y[x], y[0] == Subscript[y, 0], > I[HBar] y'[x] == [Epsilon]y[x], y[0] == Subscript[y, 0], > y''[x] + 2 [Rho]y'[x] + k^2 == 0, y'[0] == Subscript[g, 0]}, y, x] > NDSolve::dvnoarg: The function y appears with no arguments. How to Handle??? > === Subject: Installing package documentation While learning how to get documentation for my own packages to show up in the Mathematica 6 Documentation Center, I came across something that may puzzle other people. Perhaps it's worth a posting: Although I prepared the documentation of the package complete with pacletinfo.m file, etc., I found that it did now show up in the Installed Add0Ons page of the Documentation Center. This turned out to be because I installed the packages, not in $BaseDirectory/ Applications or $UserBaseDirectory/Applications, but in another directory that is prepended to the value of $Path on kernel startup (by my kernel init.m file). I do this because I share the packages with colleagues and it saves them the trouble of re-installing when I make small updates (one can discuss whether this is good practice or not ...). Anyway, it turns out that there is a global option for the Front End called AddOnHelpPath that seems to control the path searched. However its help page says This function has not been fully integrated into the long-term Mathematica system, and is subject to change So now I am trying to decide whether to tell my colleagues to change this or to switch to distributing packages for them to install on their own computers. John Jowett === Subject: Re: Installing package documentation > While learning how to get documentation for my own packages to > show up in the Mathematica 6 Documentation Center, I came across > something that may puzzle other people. Perhaps it's worth a posting: Although I prepared the documentation of the package complete with > pacletinfo.m file, etc., I found that it did now show up in the > Installed Add0Ons page of the Documentation Center. This turned out > to be because I installed the packages, not in $BaseDirectory/ > Applications or $UserBaseDirectory/Applications, but in another > directory that is prepended to the value of $Path on kernel startup > (by my kernel init.m file). I do this because I share the packages > with colleagues and it saves them the trouble of re-installing when I > make small updates (one can discuss whether this is good practice or > not ...). Anyway, it turns out that there is a global option for the Front End > called AddOnHelpPath that seems to control the path searched. However > its help page says This function has not been fully integrated into the long-term > Mathematica system, and is subject to change So now I am trying to decide whether to tell my colleagues to change > this or to switch to distributing packages for them to install on > their own computers. John Jowett > Do you know about the environment variables MATHEMATICA_BASE and MATHEMATICA_USERBASE which can be set on most (all?) platforms? It might be an alternative to changing the various $*Path variables at the right places... Of course your colleages would need to change that variable or use a special start-script for mathematica which sets that variable. hth, albert === Subject: Re: Graphing Difference Equation > I have a trouble in graphing differece equation using mathematica. For instance, I get a difference equation, y_{t} = 1.5y_{t-1} - .5y_{t-2} = 0 Since I don't know how to input the code for graphics and just want to check how the graph looks like, I input the solution instead, A(-1.2)^t + B(.5)^t where A and B constants For simplicity, I choose A = B = 1. Plot[(-1.2)^t + (.5)^t,{t,0,20}] The problem is that it doesn't work at all. If anyone who know exact way to graph difference equation, plz tell me. The plotting function *ListPlot* [1], combined with *Table* [2], should generate the desired graph. For instance, In[1]:= pts = Table[{t, (-1.2)^t + (.5)^t}, {t, 0, 20}] ListPlot[pts, Filling -> Axis] Out[1]= {{0, 2}, {1, -0.7}, {2, 1.69}, {3, -1.603}, {4, 2.1361}, {5, -2.45707}, {6, 3.00161}, {7, -3.57537}, {8, 4.30372}, {9, -5.15783}, {10, 6.19271}, {11, -7.4296}, {12, 8.91634}, {13, -10.6992}, {14, 12.8392}, {15, -15.407}, {16, 18.4884}, {17, -22.1861}, {18, 26.6233}, {19, -31.948}, {20, 38.3376}} Out[2]= [... graphic displayed w/ points above & below the x-axis ...] Also, note that difference equations can be solved with *RSolve* [3]. [1] http://reference.wolfram.com/mathematica/ref/ListPlot.html [2] http://reference.wolfram.com/mathematica/ref/Table.html [3] http://reference.wolfram.com/mathematica/ref/RSolve.html === Subject: serious flaw in KroneckerProduct with SparseArrays? It appears KroneckerProduct doesn't work properly with SparseArrays which have a nonzero constant. Below, the end result should be True: In[349]:= a=SparseArray[{1->0},{2},1] b=Normal[a]; u=KroneckerProduct[a,a]//Normal v=KroneckerProduct[b,b] u==v Out[349]= SparseArray[<1>,{2},1] Out[351]= {{0,1},{1,1}} Out[352]= {{0,0},{0,1}} Out[353]= False === Subject: Mathematica Special Interest Group (Washington DC Area) UPDATED The Washington D.C. area Mathematica Special Interest Group will meet Friday, 22 August, 7:30 to 9:30 a.m. at the SAIC Enterprise Center building in Tysons Corner (see directions below). Early risers meet before 7:00 in the morning for admission at the front desk, then we have a Dutch treat breakfast downstairs. By about 7:30 we have moved to one of the classrooms. Meetings consist of prepared talks, informal discussion about Mathematica programming and applications, general questions, and new business. The prepared talks are: - An Application of Mathematica to Internal Wave Generation by Dave Vasholz - The Finite Element Method With Mathematica by Mel Friedman (back from his Computational Electromagnetics course and summer absence) To inquire about attending, e-mail Dan Martinez (dmartinez@sprintmail.com) or Bruce Colletti (bcolletti@compuserve.com). In your e-mail subject line, please include 'Mathematica SIG.' The SIG-site is http://web.mac.com/hrbishop.pmsi/DCSIG.m/DCSIG.html A SIG representative will meet you in the lobby. Please arrive no later than ten minutes to seven if you wish to join us for breakfast, and no later than twenty after seven to attend the meeting only. The desk officer will ask for a driver's license before issuing a visitor's badge. === Subject: Re: reconstruction of 3D grid with connectivity On Aug 20, 3:23 pm, Jens-Peer Kuska a) your assumption when u and v are each incremented by given ustep > and vstep because ParametricPlot3D[] make a irregular triangle mesh > you can see the mesh with plt=ParametricPlot3D[{Cos[phi]*Sin[th], Sin[phi]*Sin[th], Cos[th]}, > {th, 0, Pi}, {phi, 0, 2 Pi}, Mesh -> All] b) the connectivity can be shown with GraphPlot[ > Union[Flatten[(Rule @@@ Partition[#, 2, 1, {-1}]) & /@ > Cases[plt, _Polygon, Infinity][[1, 1]] /. (a_ -> b_) /; > a > b :> (b -> a)] > ]] Jens > For surface ParametricPlot3D[{x = f(u,v), y = g(u,v), z = h(u,v)}, > {u,umin,umax,ustep},{v,vmin,vmax,vstep}] > how to obtain the connectivity matrix (when u and v are each > incremented by given ustep and vstep), using Delaunay or Voronoi > triangulations? In this case there would be curved or skewed > quadrilaterals instead of triangles that discretizes the surface.When > connectivity matrix and coordinate matrix are given with each point > ID reference number, the surface should be reconstructed, i.e., > plotted, and/or Shown without again giving out the above command. > Narasimham If p1,p2 etc are labels, ( p1= {x1,y1,z1} ; p2 = (x2,y2,z2} ), connectivity p1 -> p2 etc is required. Narasimham === Subject: Re: DiffMaps package > a couple of months ago, you were kind enough to reply to my email on how to compute extrema of 2D functions (see below). Imagine now that I have a list of data for the values of a two variable function, from which I can get an Interpolating function f[x,y] in mathematica following the standard procedure. When trying to apply your code below to f[x,y], the Solve or Nsolve command fails to provide the solutions of the equation D[f[x,y],{{x,y}},1]==0 for the zeros of the gradient in a specified x-y range. I wonder if you know a getaround for this problem. I am also somewhat worried about the discontinuity of the derivatives of f[x,y], I wonder how to obtain a smoother interpolation than the one provided by the default procedure. I'd be very grateful if you could briefly answer to these questions. [... Message crossposted to MathGroup ...] (Do not forget to post your query to the list/newsgroup MathGroup (comp.soft-sys.math.newsgroup) to get a broader on how to solve your problem.) With an interpolating function, you can use *FindRoot* to find zeros. Pay particular attention to the various ways of entering the initial value(s) for each variable for they influence the choice of a search method and allow to restrict the search to a specific interval. You can change the interpolating order with the option *InterpolatingOrder->n* and also tell Mathematica whether the fuctiion is periodic with the option *PeriodicInterpolation -> True*. The following example illustrate some technics you could use and some pitfall you may encounter. f[x_, y_] := Sin[x ] Cos[y] Plot3D[f[x, y], {x, 0, 2 Pi}, {y, 0, 2 Pi}] Plot3D[f[x, y] + 1/10 RandomReal[], {x, 0, 2 Pi}, {y, 0, 2 Pi}] data = Flatten[ Table[{{x, y}, f[x, y] + 1/10 RandomReal[]}, {x, 0, 2 Pi}, {y, 0, 2 Pi}], 1] g = Interpolation[data, InterpolationOrder -> 4] Plot3D[g[x, y], {x, 0, 2 Pi}, {y, 0, 2 Pi}] ListPlot3D[Flatten /@ data] grad = D[g[x, y], {{x, y}, 1}] FindRoot[grad, {{x, 1, 0, 2 Pi}, {y, 1, 0, 2 Pi}}] grad /. % // Chop Table[FindRoot[grad, {{x, x0, 0, 2 Pi}, {y, y0, 0, 2 Pi}}], {x0, 0, 2 Pi}, {y0, 0, 2 Pi}] grad /. % // Chop - Jean-Marc > Hi everybody, > Say that the function we want to study is the following: f[x_, y_] := 3*x*y - x^3 - y^3 We compute the first derivatives of f w.r.t. to x and y: D[f[x, y], {{x, y}, 1}] {-3 x^2 + 3 y, 3 x - 3 y^2} We equate each derivative to zero and solve for x and y: Solve[% == 0] {{x -> 0, y -> 0}, {x -> 1, y -> 1}, {x -> -(-1)^(1/3), >> y -> (-1)^(2/3)}, {x -> (-1)^(2/3), y -> -(-1)^(1/3)}} We want only the real points, so we discard the complex solutions: pts = >> Cases[%, {x -> vx_, y -> vy_} /; Im[vx] == 0 && Im[vy] == 0] {{x -> 0, y -> 0}, {x -> 1, y -> 1}} So we have two critical points: (0, 0) and (1, 1). Now, we compute the Hessian matrix, D[f[x, y], {{x, y}, 2}] {{-6 x, 3}, {3, -6 y}} and take its determinant: % // Det -9 + 36 x y Then we compute the values of the Hessian determinant at the critical >>points: % /. pts {-9, 27} Since the Hessian is negative at the point (0, 0), we conclude that this >>is a saddle point. Since the Hessian is positive at the point (1, 1), we conclude that this >>is a local maximum. We can check (or anticipate) these results by plotting the function: Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotRange -> All] ContourPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, >> ColorFunction -> SunsetColors] === Subject: in non-math mode Hi all I am trying to convert Latex code to Mathematica by using the example: ToExpression[sqrt{x y}, TeXForm]. I came across a problem of non-math mode: The code I put into Mathematica is as below: ToExpression[lbrace 1- Phi [({{Sigma}_{22} - {{Sigma}_{12}})*(-{X}_{4}* {beta}_{4} - {Sigma}_{21}*(left( begin{array}{c} {varepsilon}_{1} {varepsilon}_{2} end{array} right)))]rbrace*phi({varepsilon}_{1} , {varepsilon}_{2})*(1-alpha_{1}alpha_{31}), TeXForm] The error info is: Import::texerr: Error: Math primitive delimiter in non-math mode. How can I solve this problem? === Subject: very long dendrogram I have produced a hierarchical clustering of 3,107 U. S. counties based on 1995-2000 migration flows between the counties using a certain non-standard methodology (http://arxiv.org/abs/0807.1550). I have been able to convert the results into a cluster object for use by the `Hierarchical Clustering package of Mathematica. However, if I try to produce the full (very long) dendrogram or even use the command, say, TruncateDendrogram->{1,25}], , using say Orientation->Right, the result is not readable, being crammed into a small space. So, I would like to expand this space by several orders. If this problem can be overcome, I would also like to be able to eventually label the leaves of the dendrogram by the names of the counties. But For Cluster objects, the LeafLabels option can take a function but not a list or Automatic, as there is no unambiguous mapping between the labels and data points in a Cluster object. So, I am not sure how to proceed in this regard. Paul B. Slater === Subject: Real and Complex Roots on Same Plot How to plot all real and complex roots of the following function in 3- D using Manipulate by varying constant c? q = 2.304 ; z[c_] = q Sin[ c x ] + c Sin[q x]. The real roots of z[c] = 0 ( 0 < x < 20, 0 < real part of complex root < 20 ) to be plotted on x-axis, complex conjugates on y-axis, and z[c] on z-axis as c is varied between 0.5 and 2.0 Narasimham === Subject: Multifile search I thought I saw an announcement of a search utility that would act like Google Desktop but for Mathematica files. I want to find what file references certain symbols without having to go through hundreds of files. I can't recall where I saw this or even if I already have it. Steve Gray === Subject: Re: Multifile search > I thought I saw an announcement of a search utility that would act > like Google Desktop but for Mathematica files. I want to find what file > references certain symbols without having to go through hundreds of > files. I can't recall where I saw this or even if I already have it. Steve Gray http://library.wolfram.com/infocenter/Utilities/5596 be what you were looking for... hth, albert === Subject: Notebook???? Hi there. How how are you??? fine??? well, I'm here again, this time I want to create a Notebook wih colors and those things like Mathematica's Help, but really I don't how to do it _________________________________________________________________ Tenemos lo que b=FAscas=85JUEGOS. http://club.prodigymsn.com/ = === Subject: Re: Graphing Difference Equation For difference equations use RSolve In[1]:= Clear[y]; In[2]:= y[t_] = y[t] /. RSolve[{ y[t] == (3*y[t - 1] - y[t - 2])/2, y[0] == 0, y[1] == 1}, y[t], t][[1]] // Simplify Out[2]= 2 - 2^(1 - t) In[3]:= {y[0], y[1]} Out[3]= {0,1} In[4]:= Plot[y[t], {t, 0, 20}, PlotRange -> All] I have a trouble in graphing differece equation using mathematica. For instance, I get a difference equation, y_{t} = 1.5y_{t-1} - .5y_{t-2} = 0 Since I don't know how to input the code for graphics and just want to check how the graph looks like, I input the solution instead, A(-1.2)^t + B(.5)^t where A and B constants For simplicity, I choose A = B = 1. Plot[(-1.2)^t + (.5)^t,{t,0,20}] The problem is that it doesn't work at all. If anyone who know exact way to graph difference equation, plz tell me. === Subject: Re: NDSolve[] with nested If[] and Piecewise[] usage I'd use one of these: sep = 1; len = 3; wdef1[t_] := y[t]; wdef2[t_] := y[t]; val1 = 50; val2 = 20; xv = 1/2; yv = 1/5; Clear[t] funifcase2b[t_] = If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], If[sep/len <= t <= (2 sep)/len, val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], If[(2 sep)/len < t <= 1, val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]] /. If -> if /. if -> If // PiecewiseExpand [Piecewise] { {20 - Sin[1/3 - t] y[t], 2/3 < t <= 1}, {50 + Sin[t] y[t], 0 <= t < 1/3}, {70 - Sin[1/3 - t] y[t] + Sin[t] y[t], 1/3 <= t <= 2/3} } or funifcase3b[t_] = Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], 0 <= t < sep/len}, {val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], sep/len <= t <= (2 sep)/len}, {val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= 1}}] [Piecewise] { {50 + Sin[t] y[t], 0 <= t < 1/3}, {70 - Sin[1/3 - t] y[t] + Sin[t] y[t], 1/3 <= t <= 2/3}, {20 - Sin[1/3 - t] y[t], 2/3 < t <= 1} } Evaluate doesn't evaluate everything, because If has the attribute HoldRest; I defeated that by replacing If with if, then replacing if with If. Then I created a Piecewise equivalent via PiecewiseExpand. Piecewise didn't work as you expected (I think) because you used SetDelayed (:=) where you needed Set (=). The two definitions above are equivalent functions, but one could be faster than the other, depending on what intervals x is more likely to inhabit. You want the most likely interval first, least likely last, etc. That's probably a very slight improvement at best, however. Bobby > Hello Jean, > I use v1[t], v2[t], v3[t], phi[t](symbol phi) and vi[i][j] as unknown > functions (you can say variables, thats why I introduced 5 equations and > 10 initial conditions). I sincerely believe there should not be any problem as such in doing so. > The last time I posted, Oliver and DrMajorBob, both pointed out that the > parts of the expressions inside the If[] remain unevaluated. For that I > used Evaluate[] for each of the parts/expressions inside If[] and it > worked - produced same result as the Piecewise[] did. Now for this case (which is very similar), the Piecewise[] itself did > not work. Thats why I am clueless. Just for your reference, please see the code at the bottom: After > putting Evaluate[] inside for one of the problem, I was able to solve > it. But this is not the problem I am looking to solve - it is already > solved from suggestions given by Oliver and DrMajorBob. Please see my > previous post that starts with Sometime back I posted this question on > the ... posted on August 19. You can browse the bottom for the code (* Working sample code starts here *) sep = 1; > len = 3; > wdef1[t_] := y[t]; > wdef2[t_] := y[t]; > val1 = 50; > val2 = 20; > xv = 1/2; > yv = 1/5; > funifcase2[t_] := > Evaluate[If[Evaluate[0 <= t < sep/len], > Evaluate[val1 + val1 xv yv^2 (wdef1[t]) Sin[t]], > Evaluate[ > If[Evaluate[sep/len <= t <= (2 sep)/len], > Evaluate[ > val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]], > Evaluate[ > If[Evaluate[(2 sep)/len < t <= 1], > Evaluate[ > val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]]]]]; (* previous definition of funifcase2[t] -- not working *) (* funifcase2[t_] := > If[0 <= t < sep/len, val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > If[sep/len <= t <= (2 sep)/len, > val1 + val2 + val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > If[(2 sep)/len < t <= 1, > val2 + val2 yv xv^2 (wdef2[t]) Sin[t - sep/len]]]]; *) funifcase3[t_] := > Piecewise[{{val1 + val1 xv yv^2 (wdef1[t]) Sin[t], > 0 <= t < sep/len}, {val1 + val2 + > val1 xv yv^2 (wdef1[t]) Sin[t] + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], > sep/len <= t <= (2 sep)/len}, {val2 + > val2 yv xv^2 (wdef2[t]) Sin[t - sep/len], (2 sep)/len < t <= > 1}}]; > Chop[Table[funifcase2[t], {t, 0, 1, 0.1}]] > Print[compare values, just to check the correctness of equation > above]; > Chop[Table[funifcase3[t], {t, 0, 1, 0.1}]] > Print[The definition funifcase2[t] is , funifcase2[t]]; > Print[The definition funifcase3[t] is , funifcase3[t]]; > ?funifcase2 > ?funifcase3 solifcase2 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase2[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase2], {t, 0, 1}, > PlotStyle -> Automatic] > Print[Proceeding to solve the above equation with Piecewise > definition]; > solifcase3 = > NDSolve[{y''[t] + y'[t] + y[t] - funifcase3[t] == 0, y[0] == 0, > y'[0] == 1}, y, {t, 0, 1}]; > Plot[Evaluate[{y[t], y'[t]} /. solifcase3], {t, 0, 1}, > PlotStyle -> {Black, {Red, Dashed}}] (* Code ends here *) -- DrMajorBob@longhorns.com === Subject: Re: Incorrect integral in Mathematica >> Hi All, I'm getting a nonsensical answer of 0 for the following integral in Mathe= >matica 5.0 (Mac OSX): Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], >> {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] The result should be (2 Pi w z). Any ideas why this fails? I tried this integral in version 4 on a PC and got the correct answer >(although in a slightly different form).: (2*Pi)/(Sqrt[1/w^2]*Sqrt[1/z^2]) I tried it in Mathematica 3.0 on Windows XP and obtained If[Re[z^2] > 0 && Re[y0/z^2] < 0 && Re[w^2] > 0, 2*Pi*Sqrt[w^2]*Sqrt[z^2], Integrate[Integrate[E^ (-(x^2/(2*w^2)) - (y - y0)^2/(2*z^2)), {y, -Infinity, Infinity}], {x, -Infinity, Infinity}]] === Subject: Re: LaTex to Mathematica I tried something similar, but using ToExpression[...,TeXForm], likewise removing the trailing from the original. (I was surprised that Mathematica just ignored the &, which is evidently in the original expression because that expression is part of a larger LaTeX construct such as a begin{align}...end{align). However, I was unable to see how to let Mathematica itself convert the single backslashes, which of course are interpreted as escape symbols, to the needed double-backslashes. The obvious thing, expr = ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1}; expr/. -> does not work, of course. ImportString[ > $ln{H}^{*}&={X}_{1} > {beta}_{1}+{alpha}_{1}lnE+{varepsilon}_{1}$, > TeX] // NotebookPut ?? Jens > Hi all >> Does anyone know how to convert LaTex file to Mathematica ? >> For example, the formula that I typed in LaTex is: >> ln{H}^{*} &= {X}_{1} {beta}_{1} + {alpha}_{1}lnE+ {varepsilon}_{1} >> If I copy the above LaTex command to Mathematica, it only shows the >> original LaTex command. I'd like to have symbols for beta, alpha, and also >> for subscript and superscript. That is, I hope it looks like the pdf file >> that LaTex produces instead of showing beta, alpha, etc. >> Please advise. -- >> Message posted using http://www.talkaboutcomputing.com/group/comp.soft-sys.math.mathematica/ >> More information at http://www.talkaboutcomputing.com/faq.html > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: LaTex to Mathematica I tried Import to import the Latex file but it shows error info as below: Import::texerr: Error: Math character 'alpha ' in non-math mode. Can you please let me know what is the problem? === Subject: Re: Making parts of formulae blinking As some others have suggested, a blinking expression can be very unpleasant and annoying to see. It is far better to change the expression's text color or size or weight or slant, or its background color. The approach of David Park gives a nice solution for a static accentuation of an expression. It can be used right away. > My point is however, that if one could make parts of the expression blinking, this would make a still stronger effect. -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: small flaw in KroneckerProduct Hope this is the right place to post this, but KroneckerProduct doesn't work with a single argument, which I think it should. An easy workaround is of course: Unprotect[KroneckerProduct]; KroneckerProduct[a_] := a Protect[KroneckerProduct]; Best, WPB === Subject: Re: Colors in Histogram << BarCharts` lst = Partition[Table[RandomInteger[{0, 255}], {9}], 3]; BarChart[lst, BarStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1]}] ?? Jens how can I set the color of the bars in a Histogram? === Subject: Re: Colors in Histogram Look at the Options Needs[Histograms`]; Options[Histogram] Histogram[ RandomReal[NormalDistribution[0, 1], {1000}], BarStyle -> LightRed] how can I set the color of the bars in a Histogram? === Subject: Re: Need a Faster Solution to Number Theory >> I got hooked on the following little number theory problem which appears in >> the August issue of Discovery magazine. Susan has more than one dollar in >> change, but she still can't make exact change for a dollar bill. What is the >> maximum amount of money that Susan could have in pennies, nickels, dimes and >> quarters for this to be true? I solved the problem using the following Mathematica code: coins={1,5,10,25}; >> dollar=FrobeniusSolve[coins,100]; Catch[Do[t=Times@@Length/@(Cases[dollar,{p_,n_,d_,q_}/; (p<=#1&&n<=#2 && >> d<=#3 && q<=#4)]&@@@FrobeniusSolve[coins,a]); >> If[t==0,Throw[a]],{a,130,101,-1}]] Starting with a maximum guess of $1.30 this gives the correct answer of >> $1.19 in about 5 seconds. The problem is that if the problem is made more >> complicated by adding more possible coin denominations (and/or paper >> currency) the execution time become very long indeed. Is there a way to speed up the solution to this type of problem so that I >> can handle more complicated cases in a reasonable time? Late response, but I didn't get time to look hard at this until now. It > seems to be a difficult problem in terms of complexity, though I'm not > certain I have the best possible approach. > [...] I forgot a few things. One is that Mathematica already has the functionality for elbows-to-corners (e2c) conversion built in. It seems to be maybe 10 x faster than what I had shown. Another is that one can often use term rewriting methods to bring down the number of elbows under consideration. This specifically applies in the case where the first denomination divides all others, and the second divides all others above it. In our example we can swap 5 pennies for a nickel and not hurt ourselves. It turns out that this removes most of the elbows from consideration, thus making the job of e2c easier. Here is the entire code needed. It assimes the first two denominations are 1 and 5 respsctively. Were this not the case, one could still have working code by removing the replacement rule that begins {p_,n_,rest}... maxNoChange2[coins_List, amount_Integer /; amount >= 1] /; Not[And @@ Map[IntegerQ, amount/coins]] := Infinity maxNoChange2[coins_List, amount_Integer /; amount >= 1] := Reduce`FarthestCorner[ coins, (FrobeniusSolve[coins, amount] /. {p_, n_, rest___} /; p > 5 :> {p - 5*(Floor[p/5] - 1), n + Floor[p/5] - 1, rest})] - Total[coins] So here is the example that was taking around 80 seconds. Without the elbow penny-to-nickel replacement rule it is around 6 seconds, and with it we are down to 1 second. In[19]:= coins = {1, 5, 10, 25, 50}; In[20]:= Timing[maxNoChange2[coins, 200]] Out[20]= {0.992062, 219} There may well be further improvements to be had. I'm not certain I have exhausted all possible replacements (though I am certain we need to retain 5 pennies when there are more than 5). I am not certain there is no better way to go about this. Frankly, I'm not sure of much of anything at the moment. One resource I will mention, since it is really good for computing http://portal.acm.org/citation.cfm?id=1328333.1328354&coll=&dl= This and others of relevance can be obtained in pdf form at the URL below. http://www.broune.com/papers/ Daniel Lichtblau Wolfram Research === Subject: Re: Incorrect integral in Mathematica This was a bug. Essentially, the following should have Sqrt[Pi]/Sqrt[a], but it was incorrectly giving zero in version 5.0.x: Integrate[Exp[-a*(y - y0)^2], {y, -Infinity, Infinity}, GenerateConditions->False] Here are a couple of workarounds: In[1]:= Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, GenerateConditions->True] /. If[_,res_,_]:>res //InputForm Integrate::gener: Unable to check convergence. Out[1]//InputForm= Sqrt[2*Pi]*Sqrt[z^2]*If[Re[w^2] > 0, Sqrt[2*Pi]*Sqrt[w^2], Integrate[E^(-x^2/(2*w^2)), {x, -Infinity, Infinity}, Assumptions -> Re[w^2] <= 0]] In[2]:= Integrate[Exp[-x^2/(2w^2)]Exp[-(y - y0)^2/(2z^2)], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, Assumptions->z>0] //InputForm Out[2]//InputForm= Sqrt[2*Pi]*z*If[Re[w^2] > 0, Sqrt[2*Pi]*Sqrt[w^2], Integrate[E^(-x^2/(2*w^2)), {x, -Infinity, Infinity}, Assumptions -> z > 0 && Re[w^2] <= 0]] The integral works correctly in version 5.1 and newer versions. Sorry for the inconvenience. Bhuvanesh, Wolfram Research === Subject: Hypergeometric1F1 polynomial Mathematica gives the wrong answer to the following sum, In[1]:= Sum[Binomial[n, k]/Binomial[2 n, k]/k! (2 x)^k, {k, 0, n}] Out[1]= 2^(-(1/2) - n) E^x x^(1/2 + n) BesselI[1/2 (-1 - 2 n), x] Gamma[1/2 - n] The correct answer is 1 for n=0 and Hypergeometric1F1[-n, -2 n, 2 x] for integer n>0, which would be equal to the expression given by Mathematica if n was not a positive integer. Another form of the correct answer is (2 x)^(n+1/2) E^x BesselK[n+1/2,x] n!/(2 n)!/Sqrt[Pi] Is there a way to apply some assumptions to get the correct answer? Alec