mm-4319 === Subject: Re: Documentation Center On a Mac the following line has a line break that splits a Map ( /@ ). After removing the line break it runs fine. StringTake[#, {StringPosition[#, $PathnameSeparator][[-1, 1]] + 1, -4}], #} &/ @fn; Bob Hanlon > Hi Selwyn, Still won't work on my Intel Mac OSX 10.4.10 with Mathematica Version > 6.0.1.0 Tim Brophy > and did a bit of tidying-up so that it runs without squawking or > showing the notebooks that are opened and so that section title links > are in the right font and have spaces between words. - Selwyn Hollis > fn = FileNames[ > *Overview.nb, ToFileName[{$InstallationDirectory , > Documentation, English, System, Tutorials}]]; > (*Find Overview.nb files in the tutorials-directory*) > nameList = {StringTake[#, > {StringPosition[#, $PathnameSeparator][[-1, 1]] +1,-12}], > paclet:tutorial/ < StringTake[#, > {StringPosition[#, $PathnameSeparator][[-1, 1]] +1,-4}], #}&/ > @fn; > (*create a list of strings needed for future code*) > Do[nameList[[i, 1]] = > New: <> nameList[[i, 1]], {i, {3,6,7,8,18,28,29,40,41,46,48}}]; > (* mark the chapter not present in v5.2 with New: *) > orderOfChapters = {{36, 3, 8, 31, 4, 47, 1, 39, 32, 14, 20, 16, 18, > 17, 11, 43}, {10, 13, 35, 48, 22, 45, 9, 27, 38, 42, 44, 23, > 12, > 26, 15, 40, 41}, {30, 25, 2, 21, 5, 7, 37, 19, 33, 34, 28, > 29, 6, > 46, 24}}; > (*The file list is alphabetical-this is the order in which the > chapters should appear*) > structure = Table[nameList[[i]], {k, 3}, {i, orderOfChapters[[k]]}]; > (*needed for the code further down-represents the structure of the > Mathematica book*) > mainChapters = {A Practical Introduction to Mathematica, > Principles of Mathematica, > Advanced Mathematics in Mathematica}; > (*The three main headings*) > d[x_] := Module[{sectitle = StringReplace[StringReplace[First[x], > {l1_?LowerCaseQ ~~ l2_?UpperCaseQ :> l1 <> <> l2}], > { And -> and , Of -> of , In -> in , > The -> the , For -> for }]}, > Cell[ > BoxData[TagBox[ > ButtonBox[ > PaneSelectorBox[{False -> sectitle, > True -> StyleBox[sectitle, HyperlinkActive]}, > Dynamic[CurrentValue[MouseOver]], > BaselinePosition -> Baseline, FrameMargins -> 0, > ImageSize -> Automatic], > BaseStyle -> {Link, Subsection}, > ButtonData -> x[[2]], ButtonNote -> x[[2]] ], > Annotation[#, x[[2]], Hyperlink] &]], Subsection, > CellDingbat -> None, ShowGroupOpener -> True, > CellMargins -> {{36, 0}, {2, 7}}] ] > (*Cell representing a hyperlink to the ...Overview.nb files*) > nb = NotebookPut[]; > SetOptions[nb, StyleDefinitions -> Book/Textbook.nb]; > NotebookWrite[ > nb, {Cell[The Virtual Mathematica Book (v6), Title], > Cell[A collection of links to the tutorials present in the > Mathematica 6.0 Documentation Center, arranged in the order of > chapters in The Mathematica Book., Text, > CellMargins -> {{27, 0}, Inherited}] } ]; > Do[NotebookWrite[nb, Cell[mainChapters[[k]], Section] ]; > Do[NotebookWrite[nb, d[i]]; > With[{nb1 = NotebookOpen[i[[3]], Visible -> False ]}, > NotebookFind[nb1, TOCChapter, All, CellStyle]; > NotebookWrite[nb, NotebookRead[nb1] //. > TOCChapter -> Sequence @@ > {Text, CellMargins -> {{48, 0}, Inherited}}]; > NotebookClose[nb1]], {i, structure[[k]]}], {k, 3}]; > SelectionMove[nb, All, Notebook]; FrontEndExecute[ > FrontEndToken[SelectionCloseAllGroups]]; > FrontEndExecute[ FrontEndToken[OpenCloseGroup]]; > (*Creates the Mathematica Book.The With[...] block in the middle > opens an Overview.nb file,extracts the embedded hyperlinks,and > prints those into the Mathematica Book as well.*) > Many users on this discussion group have complained about the absence > of The Mathematica Book in the new Documentation Center; mainly > because of a missing linear introductory text of Mathematica which > was > present in the old Help system. > I completely agree. However, I noticed that the various tutorial > files > in the Documentation center contain the text of The Book. What is > really missing is the outline. So I decided to build my own do-it- > yourself version of the book. It turned out to be quite simple, > to the ingenious naming rules of the tutorial files (all main chapter > TOC files end with ...Overview.nb.) > The following code opens a new notebook, and prints a collection of > hyperlinks to Documentation Center tutorials, laid out in the > order of > the good old Mathematica book. Simply execute the code and save the > notebook for your own use. There are 11 chapters that I could not > find > in The Mathematica Book of the v5.2 Help system, I integrated them > in an order that seemed most appropriate to me. The are marked by > New: . > Note that this link collection does not contain links to all > tutorials. For example, no links to the Manipulate tutorials exist. > Neither are the packages represented. > Also be warned that the code opens help files to extract hyperlinks > for incorporation in The Book, and closes them again. Lots of > windows appearing and disappearing on the screen. There will also be > warnings and a beeps popping up because of a mismatch in cell > styles, which you can ignore. Everything works fine despite the > mismatch. At the end, just close the Why the beep dialog box. > Here is the code that you need to execute to build your own book in > v6.0.x: > [...] > I hope that you might find this as helpful as I do! > Happy clicking, > Thomas === Subject: Re: Re: Documentation Center (v6): do-it-yourself Mathematica Hi David, Tim > Hi Tim, The original posting was Windows specific because it used explicit > path constructs. See the original thread for an OS-indepenedent > version: browse_thread/thread/cd70b00cdf27107f/2e54396141432495 > --David > On my Intel Mac using OSX 10.4.10 this code does not work. I have to > click the OK button when error messages come up or Mathematica > doesn't go any further. Tim Brophy > Please ignore the reply I sent earlier about this not formatting > correctly: I instinctually clicked an OK button on one of the pop-up > warning message windows. I re-ran the code without doing that and > everything was fine. > The idea and execution of this code are very clever -- and very > useful! > Now perhaps some enterprising soul will create some code that will: > (1) number the parts, sections, and subsections; > (2) append a contents listing for The Mathematica Book's Part A. > Mathematica Reference Guide; > (3) print in order, and correctly numbered, all the tutorial > content of > the sections, subsections, and items in this table of contents -- > including all the home pages for functions that would > correspond to > The Book's section A.10, Listing of Major Built-in Mathematica > Objects; > (4) create and print an index; and > (5) export a file to control one of those new 3D printers in > order to > produce a hardbound cover and spine. > Presumably it is currently beyond the control capabilities of > Mathematica to take the final, missing step: to stitch together the > printed pages and attach said binding to them. > Many users on this discussion group have complained about the > absence > of The Mathematica Book in the new Documentation Center; mainly > because of a missing linear introductory text of Mathematica which > was > present in the old Help system. > I completely agree. However, I noticed that the various tutorial > files > in the Documentation center contain the text of The Book. What is > really missing is the outline. So I decided to build my own do-it- > yourself version of the book. It turned out to be quite simple, > to the ingenious naming rules of the tutorial files (all main > chapter > TOC files end with ...Overview.nb.) > The following code opens a new notebook, and prints a collection of > hyperlinks to Documentation Center tutorials, laid out in the > order of > the good old Mathematica book. Simply execute the code and save the > notebook for your own use. There are 11 chapters that I could not > find > in The Mathematica Book of the v5.2 Help system, I integrated > them > in an order that seemed most appropriate to me. The are marked by > New: . > Note that this link collection does not contain links to all > tutorials. For example, no links to the Manipulate tutorials > exist. > Neither are the packages represented. > Also be warned that the code opens help files to extract hyperlinks > for incorporation in The Book, and closes them again. Lots of > windows appearing and disappearing on the screen. There will > also be > warnings and a beeps popping up because of a mismatch in cell > styles, which you can ignore. Everything works fine despite the > mismatch. At the end, just close the Why the beep dialog box. > Here is the code that you need to execute to build your own book in > v6.0.x: > fn = FileNames[ > *Overview.nb, $InstallationDirectory <> DocumentationEnglishSystemTutorials]; > (*Find Overview.nb files in the tutorials-directory*) > nameList = {StringTake[#, {StringPosition[#, ][[-1, 1]] + > 1, -12}], > paclet:tutorial/ <> StringTake[#, {StringPosition[#, ][[-1, 1]] + > 1, -4}], #} & /@ fn; > (*create a list of strings needed for future code*) > Do[nameList[[i, 1]] = > New: <> nameList[[i, 1]], {i, {3, 6, 7, 8, 18, 28, 29, 40, > 41, > 46, 48}}]; > (* mark the chapter not present in v5.2 with New: *) > orderOfChapters = {{36, 3, 8, 31, 4, 47, 1, 39, 32, 14, 20, 16, 18, > 17, 11, 43}, {10, 13, 35, 48, 22, 45, 9, 27, 38, 42, 44, 23, > 12, > 26, 15, 40, 41}, {30, 25, 2, 21, 5, 7, 37, 19, 33, 34, 28, > 29, 6, > 46, 24}}; > (*The file list is alphabetical-this is the order in which the > chapters should appear*) > structure = Table[nameList[[i]], {k, 3}, {i, orderOfChapters > [[k]]}]; > (*needed for the code further down-represents the structure of > the > Matehmatica book*) > mainChapters = {A practical introduction to Mathematica, > Principles of Mathematica, > Advanced Mathematics in Mathematica}; > (*The three main headings*) > d[x_] := Cell[ > BoxData[TagBox[ > ButtonBox[ > PaneSelectorBox[{False -> x[[1]], > True -> StyleBox[x[[1]], HyperlinkActive]}, > Dynamic[CurrentValue[MouseOver]], > BaselinePosition -> Baseline, FrameMargins -> 0, > ImageSize -> Automatic], BaseStyle -> Link, > ButtonData -> x[[2]], ButtonNote -> x[[2]]], > Annotation[#, x[[2]], Hyperlink] &]], Subsection]; > (*Cell representing a hyperlink to the ...Overview.nb files*) > nb = NotebookPut[]; > SetOptions[nb, StyleDefinitions -> BookTextbook.nb]; > NotebookWrite[ > nb, {Cell[The Virtual Mathematica Book (v6), Title], > Cell[A collection of links to the tutorials present in the > Mathematica 6.0 Documentation Center, arranged in the order of > chapters in The Mathematica Book., Author]}]; > Do[NotebookWrite[nb, Cell[mainChapters[[k]], Section]]; > Do[NotebookWrite[nb, d[i]]; > With[{nb1 = NotebookOpen[i[[3]]]}, > NotebookFind[nb1, TOCChapter, All, CellStyle]; > NotebookWrite[nb, NotebookRead[nb1]]; NotebookClose[nb1]], {i, > structure[[k]]}], {k, 3}]; > SelectionMove[nb, All, Notebook]; FrontEndExecute[ > FrontEndToken[SelectionCloseAllGroups]]; FrontEndExecute[ > FrontEndToken[OpenCloseGroup]]; > (*Creates the Mathematica Book.The With[...] block in the middle > opens an Overview.nb file,extracts the embedded hyperlinks,and > prints those into the Mathematica Book as well.*) > I hope that you might find this as helpful as I do! > Happy clicking, > Thomas > -- > Murray Eisenberg mur...@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: Progess bar in Mathematica Reply-to: Dr. Wolfgang Hintze Is it possible to generate a kind of progess indicator in Mathematica? I could use Print[] but this scrolls the screen. Im looking for something like Application.StatusBar = Please be patient... in Visual Basic for Applications for Excel. Any hints are greatly appreciated. Wolfgang === I have a list (a time series): data={{00:00:30,x1},{00:01:00,x2},{00:01:30,x3},....} at equally spaced time intervals (30 seconds). The length od data is 8100 (24 h) ListPlot[data[[All,2]]] does it in less than 0.1 sec.... improve it? Best, Arek === Subject: How to let output data in mathematica note book become data in wordpad. Hello dear all: My questions are as follows: I have some data in mathematica note book ,but I want to let these data become into wordpad,then use these data in wordpad into Tecplot to plot graphy. If I direct copy the data in mathematica note book , then paste in the wordpad,sometimes the data will malposition or disorder,and when I use the copy and paste in wordpad,the program code in mathematica note book will paste in wordpad,too. So,I want to know how to let output data in mathematica note book become data in wordpad. About above statement,I give a example In mathematica note book I have data as follows: 0.5 0 -3.54839E34 0.5 0.5 8.35014E19 0.5 1 -2.28982E12 0.5 1.5 -7.55475E7 0.5 2 111888 0.5 2.5 -32.2785 0.5 3 -48.9518 0.5 3.5 -3.1687 0.5 4 0.268688 0.5 4.5 0.339734 0.5 5 0.214192 0.5 5.5 0.124596 0.5 6 0.0673404 0.5 6.5 0.0286447 0.5 7 0.00022441 0.5 7.5 -0.0223948 0.5 8 -0.0416674 1 0 0 1 0.5 8.93875E9 1 1 4.46247E7 1 1.5 -248451 1 2 275.046 1 2.5 3.5647 1 3 9.43887 1 3.5 -0.475709 1 4 0.715417 1 4.5 0.817926 1 5 0.592825 1 5.5 0.374401 1 6 0.207512 1 6.5 0.0813604 1 7 -0.0182152 1 7.5 -0.101253 1 8 -0.174169 but when I paste to the wordpad it will become !(*GridBox[{ {0.5`, 0, (-3.5483888083337505`*^34)}, {0.5`, 0.5`, 8.350139205560998`*^19}, {0.5`, 1.`, (-2.289817957793992`*^12)}, {0.5`, 1.5`, (-7.554752273944195`*^7)}, {0.5`, 2.`, 111887.68419682512`}, {0.5`, 2.5`, (-32.27849924478728`)}, {0.5`, 3.`, (-48.95175852696526`)}, {0.5`, 3.5`, (-3.1687029851513375`)}, {0.5`, 4.`, 0.26868832556046757`}, {0.5`, 4.5`, 0.3397343573125788`}, {0.5`, 5.`, 0.2141915242910175`}, {0.5`, 5.5`, 0.12459556032158843`}, {0.5`, 6.`, 0.06734040113993797`}, {0.5`, 6.5`, 0.028644727373548104`}, {0.5`, 7.`, 0.00022441038042603223`}, {0.5`, 7.5`, (-0.022394784835583534`)}, {0.5`, 8.`, (-0.041667393157546494`)}, {1.`, 0, 0}, {1.`, 0.5`, 8.93874965187576`*^9}, {1.`, 1.`, 4.462474932862874`*^7}, {1.`, 1.5`, (-248451.2105254929`)}, {1.`, 2.`, 275.04572112711736`}, {1.`, 2.5`, 3.5646987110223947`}, {1.`, 3.`, 9.438874116544737`}, {1.`, 3.5`, (-0.4757091455964974`)}, {1.`, 4.`, 0.7154169114542397`}, {1.`, 4.5`, 0.8179258123350419`}, {1.`, 5.`, 0.5928249634487628`}, {1.`, 5.5`, 0.3744006137437067`}, {1.`, 6.`, 0.20751194656397315`}, {1.`, 6.5`, 0.08136042333154708`}, {1.`, 7.`, (-0.018215215580189348`)}, {1.`, 7.5`, (-0.10125281059779162`)}, {1.`, 8.`, (-0.17416921776672623`)}, RowSpacings->1, ColumnSpacings->3, RowAlignments->Baseline, ColumnAlignments->{Left}]) I want to the data in wordpad as same as in mathematica note book. Please tell me how to do it. Evanescence 2007 08 07 === Subject: Re: Projectile motion I haven't worked through your example in detail, but maybe this snippet of code already gets you going sol = NDSolve[{x'[t] == 1, x[0] == 0}, x[t], {t, 0, 2}, StoppingTest :> {x[t] > 1}][[1]]; tmax = (x[t] /. sol)[[0, 1, 1, 2]] Bye Ben > All: I'd like to be able to stop the disk when it arrives at xmax. Can anyone give me a hint? Thx, Mike Manipulate[ > Module[{eqns, soln, x, y, t}, > eqns = {x'[t] == v Cos[Theta], x[0] == 0, > y'[t] == -g t + v Sin[Theta], y[0] == 0}; > soln = Flatten[NDSolve[eqns, {x, y}, {t, 0, p}]]; > With[{d = x[p] /. soln, h = y[p] /. soln}, > Graphics[{Blue, Disk[{d, h}, .2]}, > PlotRange -> {{-.5, 12}, {-.5, 6}}, Frame -> True, > PlotLabel - TableForm[{Theta = < ToString[NumberForm[Theta 180/Pi , {2, 0}]], > vx = < ToString[NumberForm[Chop[N[v Cos[Theta]]] , {2, 1}]], > vy = < ToString[NumberForm[Chop[N[v Sin[Theta]]] , {2, 1}]], > xmax = < ToString[NumberForm[N[(v^2 Sin[2 Theta])/g] , {3, 2}]], > ymax = < ToString[ > NumberForm[N[(v Sin[Theta])^2/(2 g)] , {3, 2}]]}]]]], {{v, > 5, Initial Velocity}, 1, > 10}, {{g, 9.8, Gravitational Constant}, 0, > 30}, {{Theta, Pi/4 , Theta}, 0, Pi/ > 2}, {{p, 0, Animate}, 0, 2, ControlType -> Trigger}] === Subject: Re: Projectile motion a) it is not wise to solve the ode every time even when the analytical solution can be found and the time where the ball hit the ground is known to be 2 v Sin[Theta]/g b) Manipulate[ Module[{eqns, soln, x, y, t}, eqns = {x'[t] == v Cos[Theta], x[0] == 0, y'[t] == -g t + v Sin[Theta], y[0] == 0}; soln = Flatten[NDSolve[eqns, {x, y}, {t, 0, 2 v Sin[Theta]/g}]]; With[{d = x[p] /. soln, h = y[p] /. soln}, Graphics[{Blue, Disk[{d, h}, .2]}, PlotRange -> {{-.5, 12}, {-.5, 6}}, Frame -> True, PlotLabel -> TableForm[{Theta = <> ToString[NumberForm[Theta 180/Pi, {2, 0}]], vx = <> ToString[NumberForm[Chop[N[v Cos[Theta]]], {2, 1}]], vy = <> ToString[NumberForm[Chop[N[v Sin[Theta]]], {2, 1}]], xmax = <> ToString[NumberForm[N[(v2 Sin[2 Theta])/g], {3, 2}]], ymax = <> ToString[ NumberForm[N[(v Sin[Theta]) 2/(2 g)], {3, 2}]]}]]]], {{v, 5, Initial Velocity}, 1, 10}, {{g, 9.8, Gravitational Constant}, 0, 30}, {{Theta, Pi/4, Theta}, 0, Pi/2}, {{p, 0, Animate}, 0, 2 v Sin[Theta]/g, ControlType -> Trigger}] will do that. Jens > All: I'd like to be able to stop the disk when it arrives at xmax. Can anyone give me a hint? Thx, Mike > Manipulate[ > Module[{eqns, soln, x, y, t}, > eqns = {x'[t] == v Cos[Theta], x[0] == 0, > y'[t] == -g t + v Sin[Theta], y[0] == 0}; > soln = Flatten[NDSolve[eqns, {x, y}, {t, 0, p}]]; > With[{d = x[p] /. soln, h = y[p] /. soln}, > Graphics[{Blue, Disk[{d, h}, .2]}, > PlotRange -> {{-.5, 12}, {-.5, 6}}, Frame -> True, > PlotLabel - TableForm[{Theta = < ToString[NumberForm[Theta 180/Pi , {2, 0}]], > vx = < ToString[NumberForm[Chop[N[v Cos[Theta]]] , {2, 1}]], > vy = < ToString[NumberForm[Chop[N[v Sin[Theta]]] , {2, 1}]], > xmax = < ToString[NumberForm[N[(v^2 Sin[2 Theta])/g] , {3, 2}]], > ymax = < ToString[ > NumberForm[N[(v Sin[Theta])^2/(2 g)] , {3, 2}]]}]]]], {{v, > 5, Initial Velocity}, 1, > 10}, {{g, 9.8, Gravitational Constant}, 0, > 30}, {{Theta, Pi/4 , Theta}, 0, Pi/ > 2}, {{p, 0, Animate}, 0, 2, ControlType -> Trigger}] > === Subject: Re: Re: how to collapse a cell in v.6 Yes, #1 will eventually get to the cell bracket of the current cell (and even, if you continue, the bracket for its group). However, once you've used it to select that one cell's bracket, #2 does NOT close the cell. I think you've confused closing a group with closing an individual cell. In Windows version of Mathematica use the following steps: 1. use Ctrl + . repeatedly to choose the parent bracket of cells which appears at the right side of the window. 2. use Ctrl + Shift + [ ot Ctrl + Shift + ] to expand or collapse the parent bracket. that's all > -- 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: how to collapse a cell in v.6 > In version 5 of Mathematica one could complete the keystrokes > alt + c > alt + r > alt + c > to collapse and/or expand cells. > How does one accomplish this in version 6. please - and thank you in > advance. On my Windows system, the sequence of keystrokes 'Alt + c' opens the > /Cell/ menu and 'Alt + r' opens the /Format/ menu. Since hitting the > 'Alt' key plus a letter to access some menu options is the conventional > way to build GUI in Windows, either you are not using Windows (but still > have a keyboard with the 'Alt' key) or you have a heavily customized > version of Mathematica. At any rate, the default keystrokes to open or close a group of cells is > 'Alt + shift + {' and 'Alt + shift + }', respectively. They match the > menu entries Cell -> Grouping -> Open All Subgroups and Cell -> Grouping > -> Close All Subgroups. HTH, > Jean-Marc > Sir, I am using V5.1 and I have wondered a long time how one > can group or ungroup cells. It would be handy at times to be > able to collapse a group of cells. But how does one define a > group of cells so they can be collapsed or uncollapsed? I've > tried highlighting a bunch of cells and then used every > cell/group menu item I can find but nothing ever happens. You will be able to collapse only cells that have some hierarchical relationship. The most obvious is when using sections, subsections, etc., in a notebook. (Think of them as headers, sub-headers, etc.) For instance, go to menu Cell -> Style and choose Section. Enter some text in this cell, and below create a new cell with, say, a plot command. Evaluate it. You should see some bold text, the plot command and a graphic. Now select all the cell with Ctrl + A, and then Ctrl + { Now you should see only the title in bold. > By the way my Windows system menu says Ctrl+' is the > keyboard shortcut - nothing about Alt+Shift. I stand corrected. Of course your are right: the keyboard shortcuts start with the control key Ctrl and not Alt (same thing in version 6). > I've looked all through the help system and have found > nothing about this subject. Could you give me a few key I believe that a good source of information and tutorial is section 1.3.5 Notebooks as Documents of The Mathematica Book. It is available in the online help or at http://documents.wolfram.com/mathematica/book/section-1.3.5 HTH, Jean-Marc === Subject: Re: how to collapse a cell in v.6 > In version 5 of Mathematica one could complete the keystrokes > alt + c > alt + r > alt + c > to collapse and/or expand cells. > > How does one accomplish this in version 6. please - and thank you in > advance. > On my Windows system, the sequence of keystrokes 'Alt + c' opens the > /Cell/ menu and 'Alt + r' opens the /Format/ menu. Since hitting the > 'Alt' key plus a letter to access some menu options is the conventional > way to build GUI in Windows, either you are not using Windows (but still > have a keyboard with the 'Alt' key) or you have a heavily customized > version of Mathematica. At any rate, the default keystrokes to open or close a group of cells is > 'Alt + shift + {' and 'Alt + shift + }', respectively. They match the > menu entries Cell -> Grouping -> Open All Subgroups and Cell -> Grouping > -> Close All Subgroups. I think the OP wanted to open and close cells, not cell groups. This > functionality is still there, but since for version 6 the menues have > been changed, the key sequences did, too: Alt-c p o or also (with holding the Alt-Key pressed all the time): Alt-c Alt-p Alt-o do what he intended to do (at least on windows, which I supspect is what > he asked for). Note that when using the alt key sequences the possible > next letters are underlined in the menu, something also very > conventional for GUIs. You can access every menu entry that way. You are definitely right: I totally missed the point and failed to answer the OP question. Event worse, as noted by rob, the shortcut I gave for opening/closing a group of cells are erroneous! The correct shortcuts are Opening a group of cells: Ctrl + Shift + { Closing a group of cells: Ctrl + Shift + } and not the silly one I gave starting with the Alt key. Sorry for the confusion, Jean-Marc === Subject: Re: problems with delayed write: tag list How about this: aList = {{1, 2}, {2, 7}, {4, 9},{-7, -2}}; nowFunction[myList_, myDiff_] := Select[myList,Abs[#1[[1]] - #1[[2]]] == myDiff & ] nowFunction[aList, 5] === Subject: Re: the same utility you should declare the packages dependencies using the second argument of BeginPackage, for example; BeginPackage[foo`,{Statistics`ContinuousDistributions`}] This will solve the problem you are having, see the documentation for BeginPackage at http://reference.wolfram.com/mathematica/ref/BeginPackage.html Adam Berry Wolfram Research, Inc > Hi Here is a problem a I face with: > I define two packages. Both needs the same > Statistics`ContinuousDistibutions` package. However, the second one > can not use it. Why? And how to resolve this problem? To make it more exact, in the following example I will define two > packages: ff and gg with the corresponding f and g functions both > using NormalDistribution. The first one evaluated works while the > second does not. the problem is even more disappointing if we Get[] > one packege twice and then are unable to use the function. More > complicated verisions can appear using the Sytem` functions or using > built-in packages where we does not even know what other packages are > invited. Does anyone have a solution for this problem? Bence In[1]:=BeginPackage[ff`] > Out[1]=ff` > In[2]:=Unprotect[f] > Out[2]={} > In[3]:=Begin[`Private`] > Out[3]=ff`Private` > In[4]:=Needs[Statistics`ContinuousDistributions`] > In[5]:=Options[f]:={MyDistributionFunction[Rule](NormalDistribution[#, > 0.2 #]&)} > f[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[7]:=End[] > Out[7]=ff`Private` > In[8]:=Protect[f] > Out[8]={f} > In[9]:=EndPackage[] In[10]:=f[3] > Out[10]=2.16487 > In[11]:=ff`f[3] > Out[11]=4.16217 In[12]:=BeginPackage[gg`] > Out[12]=gg` > In[13]:=Unprotect[g] > Out[13]={} > In[14]:=Begin[`Private`] > Out[14]=gg`Private` > In[15]:=Needs[Statistics`ContinuousDistributions`] > In[16]:=Options[g]:={MyDistributionFunction[Rule] > (NormalDistribution[#,0.2 #]&)} > g[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[18]:=End[] > Out[18]=gg`Private` > In[19]:=Protect[g] > Out[19]={g} > In[20]:=EndPackage[] In[21]:=f[3] > Out[21]=2.88763 > In[22]:=ff`f[3] > Out[22]=3.09767 In[23]:=g[3] > RowBox[{(Random::randt), ((:)( )), specification !( > gg`Private`MyDistributionFunction[3]) in > !(Random[((gg`Private`MyDistributionFunction[3]))] ) > should be > Real, Integer, or Complex. !(*ButtonBox[More..., > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>Random::randt])>}]) > Out[23]=Random[gg`Private`MyDistributionFunction[3]] > In[24]:=gg`g[3] > RowBox[{(Random::randt), ((:)( )), specification !( > gg`Private`MyDistributionFunction[3]) in > !(Random[((gg`Private`MyDistributionFunction[3]))] ) > should be > Real, Integer, or Complex. !(*ButtonBox[More..., > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>Random::randt])>}]) > Out[24]=Random[gg`Private`MyDistributionFunction[3]] === Subject: RE: the same Hi Benedek, > Here is a problem a I face with: > I define two packages. Both needs the same > Statistics`ContinuousDistibutions` package. However, the > second one can not use it. Why? And how to resolve this problem? To make it more exact, in the following example I will define two > packages: ff and gg with the corresponding f and g functions > both using NormalDistribution. The first one evaluated works > while the second does not. the problem is even more > disappointing if we Get[] one packege twice and then are > unable to use the function. More complicated verisions can > appear using the Sytem` functions or using built-in packages > where we does not even know what other packages are invited. Does anyone have a solution for this problem? Bence The In[] & Out[]'s here are very unhelpful .... > In[1]:=BeginPackage[ff`] > Out[1]=ff` > In[2]:=Unprotect[f] > Out[2]={} > In[3]:=Begin[`Private`] > Out[3]=ff`Private` > In[4]:=Needs[Statistics`ContinuousDistributions`] > In[5]:=Options[f]:={MyDistributionFunction[Rule](NormalDistri > bution[#, > 0.2 #]&)} > f[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[7]:=End[] > Out[7]=ff`Private` > In[8]:=Protect[f] > Out[8]={f} > In[9]:=EndPackage[] In[10]:=f[3] > Out[10]=2.16487 > In[11]:=ff`f[3] > Out[11]=4.16217 In[12]:=BeginPackage[gg`] > Out[12]=gg` > In[13]:=Unprotect[g] > Out[13]={} > In[14]:=Begin[`Private`] > Out[14]=gg`Private` > In[15]:=Needs[Statistics`ContinuousDistributions`] > In[16]:=Options[g]:={MyDistributionFunction[Rule] > (NormalDistribution[#,0.2 #]&)} > g[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[18]:=End[] > Out[18]=gg`Private` > In[19]:=Protect[g] > Out[19]={g} > In[20]:=EndPackage[] You have a typo. You meant Options[g] rather than Options[f] in your definition of g. Also note that you don't need either of the two Needs[] statements. As online help shows, defining your packages BeginPackage[ff`, {Statistics`ContinuousDistributions`}] BeginPackage[gg`, {Statistics`ContinuousDistributions`}] Does the same thing. Dave. === Subject: FindRoot can NOT handle mixed real and complex variables I'm (re)posting this as an assertion, not a question, hoping to rouse a little more interest, since it appears to be a significant weakness in FindRoot, and a previous post, rather unusually, brought no satisfactory resolution; The problem is to find the roots of two complex equations u * BesselJ[1, u] * BesselK[0, w] == w * BesselK[1, w] * BesselJ[0, u] u^2 + w^2 == g with constraints Re[g] == Re[w] == 0 So that's two complex (or four real) equations; four real numbers in the desired output; and at least one solution exists in general for any choice of DN and can be found using other methods -- but there appears to be NO WAY (no straightforward way, anyway) to find it using FindRoot, -- or even to get FindRoot to tackle the basic problem. Right???????? ------ [For testing purposes, a sample starting point close to but not exactly one particular solution, would be DN = -200, g0 = DN + 0.8 I = -200 + 0.8 I, u0 = 2.39 + 0.17 I, w0 = 0 + 14.34 I ] === Subject: show residuals of circle fit I am having a problem with displaying residuals after fitting a circle to a set of points. I am using some code that I found on the mathgroup to generate the points and fit the circle: points generation and display: points = Table[theta = Random[]; {2*Cos[theta] + 1 + .05*Random[], 2*Sin[theta] - 3 + .05*Random[]}, {30}] plot = ListPlot[points, AspectRatio -> Automatic] circle fitting and display with points: fit circle: hypersphereFit[data_List] := Module[{mat, rhs, qq, rr, params, cen}, mat = Map[Append[#, 1] &, data]; rhs = Map[#.# &, data]; {qq, rr} = QRDecomposition[mat]; params = LinearSolve[rr, qq.rhs]; cen = Drop[params, -1]/2; {Sqrt[Last[params] + cen.cen], cen}] display circle (using Graphics[Circle[]] inputing the results from the above function) and points: Show[Graphics[ Circle[Part[hypersphereFit[points], 2], Part[hypersphereFit[points], 1], {0, 1}]], plot] now i really want to be able to display the residuals for the points, but can't figure out how to. If it is any help i use the following code when displaying residuals from a quadratic curve fit: quadratic fit: func = Fit[points, {1, x, x^2}, x] define range of plot: Insert[Part[Sort[points], {1, -1}, 1], x, 1] out: {x, 2.1305, 3.04856} copy and paste this output into the range for the Plot function: Show[Graphics[ Plot[func, {x, 2.1305, 3.04856}]], ListPlot[points, PlotStyle -> {Red, PointSize[Small]}], Axes -> True, AspectRatio -> Automatic] this shows the quadratic fitted line with the points then calculate and display the residuals for the quadratic fit: res = Transpose[{First /@ points, Last /@ points - (func /. x -> First /@ points)}]; ListPlot[res] I would really, really like to be able to do this residuals calculation and display for the circle fit. Any help would be much appreciated, William Parr === Subject: Re: problems with delayed write: tag list > I have a list of elements of two numbers:myList = {{1,2},{2,7},..}. The first number is in this case always the position. I want to know when the difference is a certain value,myDiff, eg. 5 > i=1;myDiff==5; > now= Reap[While[i If[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w] > My question is: how do I make nowFunction[myDiff_]:=? > I run into tag list errors in the definition when I try that. > P_ter > Perhaps this would be clearer if you either a) Gave us a few samples of input and the corresponding output or b) Supply some complete code that fails. Note also that on line 1 you have written myDiff==5, where you presumably meant myDiff=5 . David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: problems with delayed write: tag list I assume you mean nowFunction to be some kind of inverse function, which takes a difference to the index or indices where that difference is achieved. In each case below, Scan defines the inverse, and then I list its values at the observed differences. n = 20; myList = Transpose[{Range@Length@#, #}] &@RandomInteger[{1, 10}, n] differences = myList.{-1, 1} {{1, 2}, {2, 10}, {3, 7}, {4, 8}, {5, 3}, {6, 4}, {7, 1}, {8, 5}, {9, 9}, {10, 10}, {11, 3}, {12, 2}, {13, 1}, {14, 1}, {15, 1}, {16, 9}, {17, 3}, {18, 8}, {19, 4}, {20, 6}} {1, 8, 4, 4, -2, -2, -6, -3, 0, 0, -8, -10, -12, -13, -14, -7, -14, -10, -15, -14} Clear[lastFound] Scan[(lastFound[#.{-1, 1}] = #.{1, 0}) &, myList]; lastFound /@ differences {1, 2, 4, 4, 6, 6, 7, 8, 10, 10, 11, 18, 13, 14, 20, 16, 20, 18, 19, 20} Clear[allFound] allFound[i_] = {}; Scan[(allFound[#.{-1, 1}] = Append[allFound[#.{-1, 1}], #.{1, 0}]) &, myList]; allFound /@ differences {{1}, {2}, {3, 4}, {3, 4}, {5, 6}, {5, 6}, {7}, {8}, {9, 10}, {9, 10}, {11}, {12, 18}, {13}, {14}, {15, 17, 20}, {16}, {15, 17, 20}, {12, 18}, {19}, {15, 17, 20}} Clear[find, firstFound] firstFound[x - j] = j Scan[find, myList]; firstFound /@ differences {1, 2, 3, 3, 5, 5, 7, 8, 9, 9, 11, 12, 13, 14, 15, 16, 15, 12, 19, 15} This is similar to your original attempt: i = 0; now = Reap[ While[i < Length@myList, i++; Sow[i, myList[[i]].{-1, 1}] ]] {Null, {{1}, {2}, {3, 4}, {5, 6}, {7}, {8}, {9, 10}, {11}, {12, 18}, {13}, {14}, {15, 17, 20}, {16}, {19}}} or this: Clear[allFound] i = 0; now = Reap[ While[i < Length@myList, i++; Sow[i, myList[[i]].{-1, 1}] ], _, (allFound[#1] = #2) &] allFound /@ differences {Null, {{1}, {2}, {3, 4}, {5, 6}, {7}, {8}, {9, 10}, {11}, {12, 18}, {13}, {14}, {15, 17, 20}, {16}, {19}}} {{1}, {2}, {3, 4}, {3, 4}, {5, 6}, {5, 6}, {7}, {8}, {9, 10}, {9, 10}, {11}, {12, 18}, {13}, {14}, {15, 17, 20}, {16}, {15, 17, 20}, {12, 18}, {19}, {15, 17, 20}} Bobby On Tue, 07 Aug 2007 00:38:06 -0500, P_ter = > I have a list of elements of two numbers:myList = {{1,2},{2,7},..}. = The = > first number is in this case always the position. I want to know when = = > the difference is a certain value,myDiff, eg. 5 > i=1;myDiff==5; > now= Reap[While[i If[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w] > My question is: how do I make nowFunction[myDiff_]:=? > I run into tag list errors in the definition when I try that. > P_ter -- = DrMajorBob@bigfoot.com === Subject: Re: problems with delayed write: tag list > I have a list of elements of two numbers:myList = {{1,2},{2,7},..}. The first number is in this case always the position. I want to know when the difference is a certain value,myDiff, eg. 5 > i=1;myDiff==5; ------------^^ Error: must be a single equal sign = to make an assignment; otherwise it is a logical comparison returning True or False. > now= Reap[While[i If[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w] ------------^ Q: What is w? Below, I shall assume that it is the current element, so that you wanted something like a lit of {position, pair}. > My question is: how do I make nowFunction[myDiff_]:=? > I run into tag list errors in the definition when I try that. In[1]:= myList = {{1, 2}, {2, 7}, {3, 5}, {4, 9}}; Clear[nowFun] nowFun[lst_List, delta_Integer] := Module[{i = 0, len = Length@lst}, Flatten[Reap[ While[i++ < len, If[lst[[i, 2]] - lst[[i, 1]] == delta, Sow[{i, lst[[i, All]]}] ] ] ][[2]], 1] ] nowFun[myList, 5] Out[4]= {{2, {2, 7}}, {4, {4, 9}}} Note that it might be worth investigating some others more efficient, less error-prone approaches (depending, of course, of your real needs) such as In[5]:= myDiff = 5 Select[myList, #[[2]] - #[[1]] == myDiff &] Cases[myList, x_ /; x[[2]] - x[[1]] == myDiff] Cases[myList, {x_, y_} /; y - x == myDiff] Position[myList, {x_, y_} /; y - x == myDiff] Out[5]= 5 Out[6]= {{2, 7}, {4, 9}} Out[7]= {{2, 7}, {4, 9}} Out[8]= {{2, 7}, {4, 9}} Out[9]= {{2}, {4}} Jean-Marc === Subject: Re: problems with delayed write: tag list first you should change > i=1;myDiff==5; into > i=1;myDiff=5; Jens > I have a list of elements of two numbers:myList = {{1,2},{2,7},..}. The first number is in this case always the position. I want to know when the difference is a certain value,myDiff, eg. 5 > i=1;myDiff==5; > now= Reap[While[i If[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w] > My question is: how do I make nowFunction[myDiff_]:=? > I run into tag list errors in the definition when I try that. > P_ter > === Subject: FindRoot migration question I have recently migrated form mathematica 4 to mathematica 6, and some of the programs I was using are not correct any more. One recurrent error occurs with functions including FindRoot. I enclose here an example: guillermo quit; cmin = 10^(-10); cmax = 1/100; sigma1[n1_, nx_, cov_, L_] := (4 Pi^2 L^2 nx (1 - n1))/(Log[1/cov] - ((3 - cov) (1 - cov)/2)) LL1[nx_, cov_] := FindRoot[nx L^2 Pi (Log[L^2 Pi] - (1 - (1/(Pi L^2)))) == Log[1/cov] - (1 - cov), {L, 1.0, 2.0}] sigm1[n1_, nx_, cov_] := sigma1[n1, nx, cov, L /. LL1[nx, cov]] sigm1[1/10000000000, 1/10000000000, 1/10000000000] (* this works perfectly *) (* however, if I want to interpolate the sim1 function, it complains *) sig1 = FunctionInterpolation[sigm1[n1, nx, cov], {n1, cmin, cmax}, {nx, cmin, cmax}, {cov, cmin,cmax}]; === Subject: Can model parameters be global? When implementing a mathematical model in physics or psychology, for example, how do other people deal with model parameters in Mathematica? Would you represent the speed of light as a global variable or a local variable. For example, would you use Energy[m_]:=m*c^2 (* c is a global variable *) or Energy[m_,c_]:=m*c^2 (* c is a local variable *) ? The first seems neater. But problems arise in psychology, my domain, where the values of model parameters are unknown and are left as free parameters, adjusted to best-fit the data. Both local and global methods work well with optimisation. For example, NMinimize[Energy[1],{c}] {0., {c -> 0.}} and NMinimize[Energy[1,c],{c}] {0., {c -> 0.}} But the global variable solution does not work well with Manipulate. For example, Manipulate[Dynamic[Energy[1]], {c, 0, 1}, LocalizeVariables -> False] works, but looks a right mess and also results in c taking a value that needs a Clear[c] before using other functions like NMinimize. On the other hand the local variable version Manipulate[Energy[1, c], {c, 0, 1}] is nice and simple. But the local variable solution results in having to pass all of the model parameters to the function. This is fine in this trivial example, but becomes unwieldy when there are ten model parameters and the model is defined using a set of functions. (A c-like struct could help, but there does not seem to be a neat way to do this in Mathematica.) So what do other people do? I'd be really interested to hear. === Subject: Block vs. ReplaceAll Take a function f of some global variables and a function g that depends on f. f := a^2 + b^2 (* f is a function of a and b, a and b are global variables *) g := Count[Table[f, {10}], 0] (* g in turn depends on f *) Solutions can be found for a and b that minimize f. solution = NMinimize[{f, a > 0 && b > 0}, {a, b}] {0., {a -> 0., b -> 0.}} But how is it best to use the solution? Block[{a = 0, b = 0}, f] (* Fast *) 0 or f /. Last[solution] (* Slow *) 0 For this trivial example obviously both are fast, but when f is non-trivial, Block[] is much faster. Further for g, only Block[] works as I intend (counting the number of times ten calls to f evaluate 0): Block[{a = 0, b = 0}, g] (* Fast and works as I intend *) 10 g /. Last[solution] (* Slow, and doesn't count the number of times f is zero as I intended *) I understand why this happens: Count[] counts the fs in the table in symbolic form, before a and b are replaced and f is evaluated at 0. My question is, how is it best to take solution - which is a list of replace rules - and use it in a Block[] statement - which requires a list of assignments? I need the speed that Block[] gives by making replacements before f is evaluated. I'm keen to keep the simplicity of having model parametes as global variables to avoid having to pass model parameters explicitly to model functions as this is messy with a non-trivial model. === Subject: Re: problems with delayed write: tag list >I have a list of elements of two numbers: >myList ={{1,2},{2,7},..}. >The first number is in this case always the >position. I want to know when the difference is a certain >value,myDiff, eg. 5 >i=1;myDiff==5; >now= Reap[While[iIf[myList[[i,2]]-myList[[i,1]]==myDiff,Sow[i]]];w] >My question is: how do I make nowFunction[myDiff_]:=? I run into >tag list errors in the definition when I try that. P_ter It seems to me your code is more complex than necessary. Using either Cases seems to me to be more efficient. First, generate some data: In[10]:= data = MapIndexed[Join[#2, {#1}] &, RandomInteger[{1, 20}, 20]] Out[10]= {{1, 9}, {2, 18}, {3, 8}, {4, 4}, {5, 15}, {6, 19}, {7, 8}, {8, 4}, {9, 18}, {10, 3}, {11, 19}, {12, 8}, {13, 20}, {14, 17}, {15, 12}, {16, 11}, {17, 1}, {18, 14}, {19, 13}, {20, 12}} In[11]:= diff = 5; In[12]:= Cases[data, _?(Subtract @@ # == -diff &)][[All, 1]] Out[12]= {3} Then nowFunction would be: nowFunction[diff_, data_] := Cases[data, _?(Subtract @@ # == -diff &)][[All, 1]] -- To reply via email subtract one hundred and four === Subject: Re: How to extract generated plot data (or mesh data) from a Graphics3D >I would be thankful if someone can help me on this problem: I am >using Mathematica 6.0 and it introduces new graphical capabilities >that is not compatible with ver. 5.2, I could extract generated mesh >data from a Plot3D for further manipulation using for instance the >following code: >p=Plot3D[Sin[x] y, {x, 0, 4}, {y, 0, 4}] >p // FullForm (* to see the structure of p *) >p[[1, 1]] (* a list of mesh points in p *) >now in ver. 6.0 I cannot exctract mesh data from a Graphics3D object >especially when used with built in commands like Sphere[...] like >this: >g = Graphics3D[Sphere[{0, 0, 0}, 1]] >g // InputForm (* !!! no useful output to extract mesh data !!!!*) Your first example with Sin works fine in version 6.01. But I would be surprised if you second example with Sphere ever worked. In your first example, you used a function which Mathematica must sample in order to construct the graphic. In the second case, you've used a graphics primitive which Mathematica knows how to construct without sampling. Consequently, there will be no list of sampled points. -- To reply via email subtract one hundred and four === Subject: Re: forming continuous trail with Locator Mark, you made the first argument of Manipulate a list, the three elements are AppendTo, LocatorPane, and FinishDynamic. You suppressed the output of the first and the output of the third is Null - which is exactly what you see in the Manipulate panel. Bye, Mariusz > Hi Murray, > Does this do what you want?: list = {}; > Manipulate[{AppendTo[list, pnt]; > LocatorPane[ > Dynamic[pnt], {Graphics[{{Gray, Disk[{32, 32}, 32]}, > Dynamic[{Hue[0], Point /@ DeleteCases[list, Null]}]}]}], > FinishDynamic[]}, {pnt}] - sorry about the Null next to the graphic - not sure why it's there! To plot the trace afterwards: ListPlot[DeleteCases[list, Null], Joined -> True, PlotRange -> All, > AspectRatio -> Automatic] > Is there some way in Mathematica 6 to use a Locator so as to create a > continuous-appearing trail after you click and then drag the cursor > around? Of course one could write code allowing addition of points through > successive clicks, and then one could try to click repeatedly on > successive points very near one another, but that could get very tedious. I mean the sort of thing one gets in drawing programs (and with the > Mathematica 6 2D Drawing Tools). -- > Murray Eisenberg mur...@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 Best wishes, Mark > ___________________ > Mark R. Holt, BA, PhD > Cardiovascular Division and > Randall Division of Cell and Molecular Biophysics > New Hunt's House > King's College London > Guy's Hospital Campus > LONDON, U.K., SE1 1UL > Phone: +44 20 7848 6438 > Fax: +44 20 7848 6435 > === Subject: Re: How to extract generated mesh data from a Graphics3D object ? Sphere[] is a build-in graphics primitive and generates no explicit polygonal description. You have to use g = ParametricPlot3D[ {Cos[phi]*Sin[th], Sin[phi]*Sin[th], Cos[th]}, {th, 0, Pi}, {phi, 0, 2 Pi}] and Cases[g, _GraphicsComplex, Infinity][[1]] /. GraphicsComplex[points_, poly_, ___] :> points to get the coordinates of the verticies. Jens I am using Mathematica ver 6.0 and I need to extract generated mesh data from a drawn Graphics3D object like the way I do it with a Plot3D object as follows: p = Plot3D[ Sin[x y], {x, 0, 4}, {y, 0, 4}] > p[[1, 1]] // FullForm (* this is OK and extracts actual generated mesh data *) g = Graphics3D[ Sphere[{0, 0, 0},1] ] > g[[1, 1]] // FullForm (* ???? how is it possible to extract the actual generated data by Graphics3D ? *) > === Subject: Re: Two different packages can not Need[] the same utility package? > Hi Here is a problem a I face with: > I define two packages. Both needs the same > Statistics`ContinuousDistibutions` package. However, the second one > can not use it. Why? And how to resolve this problem? To make it more exact, in the following example I will define two > packages: ff and gg with the corresponding f and g functions both > using NormalDistribution. The first one evaluated works while the > second does not. the problem is even more disappointing if we Get[] > one packege twice and then are unable to use the function. More > complicated verisions can appear using the Sytem` functions or using > built-in packages where we does not even know what other packages are > invited. Does anyone have a solution for this problem? Bence In[1]:=BeginPackage[ff`] > Out[1]=ff` > In[2]:=Unprotect[f] > Out[2]={} > In[3]:=Begin[`Private`] > Out[3]=ff`Private` > In[4]:=Needs[Statistics`ContinuousDistributions`] > In[5]:=Options[f]:={MyDistributionFunction[Rule](NormalDistribution[#, > 0.2 #]&)} > f[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[7]:=End[] > Out[7]=ff`Private` > In[8]:=Protect[f] > Out[8]={f} > In[9]:=EndPackage[] In[10]:=f[3] > Out[10]=2.16487 > In[11]:=ff`f[3] > Out[11]=4.16217 In[12]:=BeginPackage[gg`] > Out[12]=gg` > In[13]:=Unprotect[g] > Out[13]={} > In[14]:=Begin[`Private`] > Out[14]=gg`Private` > In[15]:=Needs[Statistics`ContinuousDistributions`] > In[16]:=Options[g]:={MyDistributionFunction[Rule] > (NormalDistribution[#,0.2 #]&)} > g[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[18]:=End[] > Out[18]=gg`Private` > In[19]:=Protect[g] > Out[19]={g} > In[20]:=EndPackage[] In[21]:=f[3] > Out[21]=2.88763 > In[22]:=ff`f[3] > Out[22]=3.09767 In[23]:=g[3] > RowBox[{(Random::randt), ((:)( )), specification !( > gg`Private`MyDistributionFunction[3]) in > !(Random[((gg`Private`MyDistributionFunction[3]))] ) > should be > Real, Integer, or Complex. !(*ButtonBox[More..., > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>Random::randt])>}]) > Out[23]=Random[gg`Private`MyDistributionFunction[3]] > In[24]:=gg`g[3] > RowBox[{(Random::randt), ((:)( )), specification !( > gg`Private`MyDistributionFunction[3]) in > !(Random[((gg`Private`MyDistributionFunction[3]))] ) > should be > Real, Integer, or Complex. !(*ButtonBox[More..., > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>Random::randt])>}]) > Out[24]=Random[gg`Private`MyDistributionFunction[3]] Please remember to paste InputForm in your posts! Try putting the Needs statement before the BeginPackage statement. Note that this can still end up in a package file - these do not need to start with BeginPackage. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Two different packages can not Need[] the same utility package? you need a shared package for MyDistributionFunction, i.e. Package 1--- BeginPackage[myoption`] MyDistributionFunction::usage = An option for the usefull function.; EndPackage[]; End---------- Package 2---- BeginPackage[ff`, {myoption`, Statistics`ContinuousDistributions`}] func::usage = A usefull function.; Begin[`Private`] Options[func] = {MyDistributionFunction -> (NormalDistribution[#, 0.2 #] &)} func[x_, opts___] := Random[(MyDistributionFunction /. {opts} /. Options[func])[x]] End[] EndPackage[] End------------- and Package 3------- BeginPackage[gg`, {myoption`, Statistics`ContinuousDistributions`}] gunc::usage = An other usefull function. Begin[`Private`] Options[gunc] = {MyDistributionFunction -> (NormalDistribution[#, 0.2 #] &)}; gunc[x_, opts___] := Random[(MyDistributionFunction /. {opts} /. Options[gunc])[x]] End[] EndPackage[] End------------- Jens > Hi Here is a problem a I face with: > I define two packages. Both needs the same > Statistics`ContinuousDistibutions` package. However, the second one > can not use it. Why? And how to resolve this problem? To make it more exact, in the following example I will define two > packages: ff and gg with the corresponding f and g functions both > using NormalDistribution. The first one evaluated works while the > second does not. the problem is even more disappointing if we Get[] > one packege twice and then are unable to use the function. More > complicated verisions can appear using the Sytem` functions or using > built-in packages where we does not even know what other packages are > invited. Does anyone have a solution for this problem? Bence In[1]:=BeginPackage[ff`] > Out[1]=ff` > In[2]:=Unprotect[f] > Out[2]={} > In[3]:=Begin[`Private`] > Out[3]=ff`Private` > In[4]:=Needs[Statistics`ContinuousDistributions`] > In[5]:=Options[f]:={MyDistributionFunction[Rule](NormalDistribution[#, > 0.2 #]&)} > f[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[7]:=End[] > Out[7]=ff`Private` > In[8]:=Protect[f] > Out[8]={f} > In[9]:=EndPackage[] In[10]:=f[3] > Out[10]=2.16487 > In[11]:=ff`f[3] > Out[11]=4.16217 In[12]:=BeginPackage[gg`] > Out[12]=gg` > In[13]:=Unprotect[g] > Out[13]={} > In[14]:=Begin[`Private`] > Out[14]=gg`Private` > In[15]:=Needs[Statistics`ContinuousDistributions`] > In[16]:=Options[g]:={MyDistributionFunction[Rule] > (NormalDistribution[#,0.2 #]&)} > g[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]] > In[18]:=End[] > Out[18]=gg`Private` > In[19]:=Protect[g] > Out[19]={g} > In[20]:=EndPackage[] In[21]:=f[3] > Out[21]=2.88763 > In[22]:=ff`f[3] > Out[22]=3.09767 In[23]:=g[3] > RowBox[{(Random::randt), ((:)( )), specification !( > gg`Private`MyDistributionFunction[3]) in > !(Random[((gg`Private`MyDistributionFunction[3]))] ) > should be > Real, Integer, or Complex. !(*ButtonBox[More..., > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>Random::randt])>}]) > Out[23]=Random[gg`Private`MyDistributionFunction[3]] > In[24]:=gg`g[3] > RowBox[{(Random::randt), ((:)( )), specification !( > gg`Private`MyDistributionFunction[3]) in > !(Random[((gg`Private`MyDistributionFunction[3]))] ) > should be > Real, Integer, or Complex. !(*ButtonBox[More..., > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>Random::randt])>}]) > Out[24]=Random[gg`Private`MyDistributionFunction[3]] === Subject: Re: Beta function, Integral > Hi The following integral does not seem to give the correct answer. The > answer should be the Euler Beta function, Beta[p,q]. Can anybody let > me know what I am doing wrong? Or is this a bug? In[12]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions - {p > 0, q > 0}] Out[12]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} > Asim Ansari First note that you used List where you should have used parentheses! A common mistake. It must be t^(p-1); not {p-1}. In the Mathematica I work, I took: In[18]:= $Version Out[18]= 5.2 for Microsoft Windows (June 20, 2005) In[20]:= Integrate[t^(p - 1)*(1 - t)^(q - 1), {t, 0, 1}, Assumptions -> {p > 0, q > 0}] FunctionExpand[Beta[p, q] - %] Out[20]= (Gamma[p]*Gamma[q])/Gamma[p + q] Out[21]= 0 Ommiting { } from your output, we have also In[28]:= FullSimplify[Beta[p, q] - (Pi*Csc[Pi*q]*Gamma[p])/(Gamma[1 - q]*Gamma[p + q])] Out[28]= 0 as it must be. Note also that In[30]:= Beta[p, q] // FunctionExpand Out[30]= (Gamma[p] Gamma[q])/Gamma[p + q] and In[46]:= FullSimplify[(Gamma[p]*Gamma[q])/Gamma[p + q] == Beta[p, q]] Out[46]= True but In[47]:= FullSimplify[(Gamma[p]*Gamma[q])/Gamma[p + q]] Out[47]= (Gamma[p]*Gamma[q])/Gamma[p + q] Dimitris === Subject: Re: Beta function, Integral Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, z}, Assumptions -> {p > 0 && q > 0 && Re[z] <= 1}] works, but best of all it return a List[] with the expression inside ... Thats a bug. Jens > Hi The following integral does not seem to give the correct answer. The > answer should be the Euler Beta function, Beta[p,q]. Can anybody let > me know what I am doing wrong? Or is this a bug? > In[12]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions - > {p > 0, q > 0}] Out[12]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} Asim Ansari === Subject: Re: Beta function, Integral > The following integral does not seem to give the correct answer. The > answer should be the Euler Beta function, Beta[p,q]. Can anybody let > me know what I am doing wrong? Or is this a bug? > In[12]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions - > {p > 0, q > 0}] Out[12]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} The /mathematical/ expression that is returned by Mathematica 6 is correct, indeed. However, the answer has funny extra curly brackets and if one try to use the expression to check its validity against Beta[p,q] the expression returned unevaluated. On the other hand, if one type in the expression by hand, the simplification occurs and the identity is checked positively. In[1]:= $Version Out[1]= 6.0 for Microsoft Windows (32-bit) (June 19, 2007) In[2]:= sol = Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions -> {p > 0, q > 0}] Out[2]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} --------^------------^ Note the spurious curly brackets. In[3]:= FullSinplify[Beta[p, q] == sol[[1]]] Out[3]= FullSinplify[ Beta[p, q] == ([Pi] Csc[[Pi] q] Gamma[p])/( Gamma[1 - q] Gamma[p + q])] Even though we took out the contains of the list, Mathematica returns the FullSimplify unevaluated. In[4]:= FullSimplify[ Beta[p, q] == (Pi Csc[Pi q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])] Out[4]= True Now, having entered the expression by hand, Mathematica is able to check the identity. A similar behavior can be seen with Mathematica 5.2, though the expression returned is different. In[1]:= $Version Out[1]= 5.2 for Microsoft Windows (June 20, 2005) In[2]:= sol = Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions -> {p > 0, q > 0}] Out[2]= {(Gamma[p]*Gamma[q])/Gamma[p + q]} In[3]:= FullSinplify[Beta[p, q] == sol[[1]]] Out[3]= FullSinplify[Beta[p, q] == (Gamma[p]*Gamma[q])/ Gamma[p + q]] In[4]:= FullSimplify[Beta[p, q] == (Gamma[p]*Gamma[q])/ Gamma[p + q]] Out[4]= True -- Jean-Marc === Subject: Re: Beta function, Integral > The following integral does not seem to give the correct answer. The > answer should be the Euler Beta function, Beta[p,q]. Can anybody let > me know what I am doing wrong? Or is this a bug? In[12]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions - {p > 0, q > 0}] Out[12]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} What version are you using? First, note that the reason you're getting your answer in braces, rather than just the answer -- i.e. {antiderivative}, rather than just the antiderivative -- is that you put your first exponent in braces, rather than parentheses. With that problem fixed, then in version 5.2, the result is Gamma[p] Gamma[q]/Gamma[p + q]. The antiderivative you got is equivalent to that and also to Beta[p,q]. Thus, there is no bug. David === Subject: Re: Beta function, Integral I'm getting In[12]:= $Version Out[12]= 5.2 for Microsoft Windows (June 20, 2005) In[1]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions -> {p > 0, q > 0}] Out[1]= {(Gamma[p]*Gamma[q])/Gamma[p + q]} which is what we would expect (Euler's Beta function written in terms of Gamma functions) but which is also equivalent to your result because of In[11]:= eq = FullSimplify[Gamma[q] == Pi*(Csc[Pi*q]/Gamma[1 - q])] Out[11]= True Hence no wrongdoing, no bug - simply inconvenience! Wolfgang Asim schrieb im Newsbeitrag Hi The following integral does not seem to give the correct answer. The > answer should be the Euler Beta function, Beta[p,q]. Can anybody let > me know what I am doing wrong? Or is this a bug? > In[12]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, > Assumptions - > {p > 0, q > 0}] Out[12]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} Asim Ansari === Subject: Re: Beta function, Integral It is correct. int1 = Integrate[t^(p - 1)*(1 - t)^(q - 1), {t, 0, 1}, Assumptions -> {p > 0, q > 0}] (Pi*Csc[Pi*q]*Gamma[p])/ (Gamma[1 - q]*Gamma[p + q]) To force an alternate form add the assumption that p and q are integers. int2 = Integrate[t^(p - 1)*(1 - t)^(q - 1), {t, 0, 1}, Assumptions -> {Element[{p, q}, Integers], p > 0, q > 0}] (Gamma[p]*Gamma[q])/Gamma[p + q] Verifying that the forma are equivalent and equal to Beta function int1 == int2 == Beta[p, q] // FullSimplify True Hence Solve[int1 == int2, Gamma[1 - q]][[1, 1]] Gamma[1 - q] -> (Pi*Csc[Pi*q])/ Gamma[q] FullSimplify[Equal @@ %] True Bob Hanlon Hi The following integral does not seem to give the correct answer. The > answer should be the Euler Beta function, Beta[p,q]. Can anybody let > me know what I am doing wrong? Or is this a bug? > In[12]:= Integrate[t^{p - 1}*(1 - t)^(q - 1), {t, 0, 1}, Assumptions - > {p > 0, q > 0}] Out[12]= {([Pi] Csc[[Pi] q] Gamma[p])/(Gamma[1 - q] Gamma[p + q])} Asim Ansari === Subject: Re: How show Locator point and its image under a function? > The following code displays a fixed point and its image under a > specified function f: f[{x_,y_}]:={2x+1,y+2} > Module[{pt = {-1, 0.5}}, > Row[{ > Framed@Graphics[Point[pt], PlotRange -> 5], > Framed@Graphics[Point[f[pt]], PlotRange -> 5] > }] > ] Now I want to have the point in the left-hand graphic to be dynamic, > controlled by a Locator, and to have its changed image under the > function to be shown in the right-hand graphic. The idea is something like the following (WRONG!) code: DynamicModule[{pts={{0,0}}}, > Row[{ > LocatorPane[Dynamic[pts],Graphics[{},PlotRange->5]], > Graphics[Dynamic[f/@pts],PlotRange->5] > }] > ] That code produces error messages, 1 is not a Graphics primitive or > directive, 2 is not a Graphics primitive or directive. this is because f/@pts just gives a List of Numbers, which is not a Graphics primitive. > How can it actually be done? make the list of coordinates a list of Points: DynamicModule[{pts = {{0, 0}}}, Row[{ LocatorPane[Dynamic[pts], Graphics[{}, PlotRange -> 5]], Graphics[Dynamic[Point /@ f /@ pts], PlotRange -> 5] }] ] hth, albert === Subject: Re: How show Locator point and its image under a function? > The following code displays a fixed point and its image under a > specified function f: f[{x_,y_}]:={2x+1,y+2} > Module[{pt = {-1, 0.5}}, > Row[{ > Framed@Graphics[Point[pt], PlotRange -> 5], > Framed@Graphics[Point[f[pt]], PlotRange -> 5] > }] > ] Now I want to have the point in the left-hand graphic to be dynamic, > controlled by a Locator, and to have its changed image under the > function to be shown in the right-hand graphic. The idea is something like the following (WRONG!) code: DynamicModule[{pts={{0,0}}}, > Row[{ > LocatorPane[Dynamic[pts],Graphics[{},PlotRange->5]], > Graphics[Dynamic[f/@pts],PlotRange->5] > }] > ] That code produces error messages, 1 is not a Graphics primitive or > directive, 2 is not a Graphics primitive or directive. How can it actually be done? > Murray, You forgot to make Point objects in your Graphics! DynamicModule[{pts = {{0, 0}}}, Row[{LocatorPane[Dynamic[pts], Graphics[{}, PlotRange -> 5]], Graphics[Dynamic[Point /@ f /@ pts], PlotRange -> 5]}]] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: How show Locator point and its image under a function? I oversimplified my requirements... Actually, I want to do more: I want to include a LocatorAutoCreate->All option for the left-hand graphics portion so that as each point there is clicked it remains there and its image in the right-hand graphics is automatically shown an remains showing even as I click new points on the left. > The following code displays a fixed point and its image under a > specified function f: f[{x_,y_}]:={2x+1,y+2} > Module[{pt = {-1, 0.5}}, > Row[{ > Framed@Graphics[Point[pt], PlotRange -> 5], > Framed@Graphics[Point[f[pt]], PlotRange -> 5] > }] > ] Now I want to have the point in the left-hand graphic to be dynamic, > controlled by a Locator, and to have its changed image under the > function to be shown in the right-hand graphic. The idea is something like the following (WRONG!) code: DynamicModule[{pts={{0,0}}}, > Row[{ > LocatorPane[Dynamic[pts],Graphics[{},PlotRange->5]], > Graphics[Dynamic[f/@pts],PlotRange->5] > }] > ] That code produces error messages, 1 is not a Graphics primitive or > directive, 2 is not a Graphics primitive or directive. How can it actually be done? > -- 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: How show Locator point and its image under a function? Hi Murray, Manipulate[ Row[{Framed@Graphics[Point[pt], PlotRange -> 5], Framed@Dynamic[Graphics[Point[f[pt]], PlotRange -> 5]]}], {{pt, {-1, 1/2}}, Locator} ] may do it Jens > The following code displays a fixed point and its image under a > specified function f: f[{x_,y_}]:={2x+1,y+2} > Module[{pt = {-1, 0.5}}, > Row[{ > Framed@Graphics[Point[pt], PlotRange -> 5], > Framed@Graphics[Point[f[pt]], PlotRange -> 5] > }] > ] Now I want to have the point in the left-hand graphic to be dynamic, > controlled by a Locator, and to have its changed image under the > function to be shown in the right-hand graphic. The idea is something like the following (WRONG!) code: DynamicModule[{pts={{0,0}}}, > Row[{ > LocatorPane[Dynamic[pts],Graphics[{},PlotRange->5]], > Graphics[Dynamic[f/@pts],PlotRange->5] > }] > ] That code produces error messages, 1 is not a Graphics primitive or > directive, 2 is not a Graphics primitive or directive. How can it actually be done? >