A105 === Subject: Re: Help with Manipulate Sir, I tried your code and after I use the sliders to generate boxes with three different numbers, I can't find a way to use them. Is there a simple way to apply this to generate 3 global variables like x, y, and z which can be You can create a row of controls manually: Manipulate[u, > {{u, {0, 0, 0}}, None}, > Row[Manipulator[Dynamic@ u[[#]], > AppearanceElements -> {InlineInputField, InputField}, > ImageSize -> Tiny]& /@ > Range[3], Spacer[5]]] It won't look as good if you want to include all the Manipulator > elements though. Maxim Rytin > m.r@inbox.ru > === Subject: Re: Axes at the origin, for 3D plots/graphs That VERY old notebook at MathSource is useful. However: 1. One change is essential: for Mathematica 6, remove entirely the cell that loads Graphics`ParametricPlot3D`. 2. It's not obvious until you experiment or peruse the code, but when the Input prompts ask you for the min and max values for each of the three coordinates, you need to supply them in a list format: {min,max} 3. It is useful if, in the Plot3D expression, you add something like PlotStyle->{Opacity[0.5]}. This allows the axes to be visible beneath and behind the surface that would otherwise hide parts of them. Unfortunately, the package does nothing directly to treat hidden portions of the origin-centered axes. Despite the existence of this package, it is still unforgivable that Mathematica does not offer an option of origin-centered axes for 3D graphics. It would seem to be pure prejudice of scientists and engineers against mathematicians, or at least standard practices of 3D graphing in elementary mathematics such as multivariable calculus, where one draws the axes at the origin. > Does anyone know of a way to move the axes from the outside of the box >> and have it centered at the origin instead? I know you can draw lines >> using the graphics function to do this but it looks bad. I am looking >> for something similar to how you can move the axes using AxisOrigin >> for 2D plots. > You could write your own function. The following notebook might be help > you started. *3D Axes* Sometimes in calculus, it is useful to see the x, y, and z axes in a 3D > plot. This notebook illustrates a method for placing a coordinate axis > set in the middle of a 3D plot as opposed to a bounding box. http://library.wolfram.com/infocenter/MathSource/528/ -- 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: StringMatchQ and Regular Expressions > Hi I'm running Mathematica v6.0.2 on Windows XP. I define a regex thus: doStmt = RegularExpression[do(?=s*w+=)]; and then execute: StringCases[doindex= , doStmt] which brings the response {do} I then execute StringMatchQ[doindex= , doStmt] which brings the response False I had expected that if StringCases found any cases, then StringMatchQ > would return True. Obviously this is not the case, but can anyone out > there throw light upon this. > Mark Westwood > StringMatchQ returns true if the WHOLE string matches the given pattern - not just part of it. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Identical elements ident[x_List] := Length[Union[x]] == 1; n = 100000; ident /@ RandomInteger[{0, 1}, {n, 3}]; Count[%, True]/n // N 0.25012 Bob Hanlon I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. Your help is highly appreciated. > HMQ > === Subject: Re: Fit data with range data = Table[{x, x^2 - 11 x + 24 + 6 RandomReal[]}, {x, 0, 10, .25}]; pltRng = {{0, 10}, 1.2 {Min[data[[All, 2]]], Max[data[[All, 2]]]}}; fit = Fit[data, {1, x, x^2}, x] xmin = 4; xmax = 7; fit2 = Fit[Select[data, xmin <= #[[1]] <= xmax &], {1, x, x^2}, x] Plot[{fit, fit2}, {x, 0, 10}, PlotStyle -> {Green, Blue}, Epilog -> {Red, Point[data]}, PlotRange -> pltRng] Bob Hanlon > Hi I want to fit a polynomial function to a set of data, > only between say xmin to xmax. How can I do that? > I know only how to fit the whole range. For example: data = ReadList[file.dat,{Number,Number}]; fit = Fit[data,{1,x,x^2},x] Plot[fit,{x,0,10}] === Subject: Re: orthonormal eigenvectors >I have a 3X3 matrix M: {1,-i(2^(1/2)),0} {i(2^(1/2)),0,0} {0,0,2} >And I am trying to find a set of orthonormal eigenvectors for M. You can find a set of eigenvectors by doing: In[54]:= m = {{1, -I (2^(1/2)), 0}, {I (2^(1/2)), 0, 0}, {0, 0, 2}}; In[55]:= ev = Eigenvectors[m] Out[55]= {{0, 0, 1}, {-I Sqrt[2], 1, 0}, {I/Sqrt[2], 1, 0}} Then it is easy to normalize these by doing: In[56]:= len = (#.#) & /@ ev; ev /Sqrt[len] Out[57]= {{0, 0, 1}, {-Sqrt[2], -I, 0}, {I, Sqrt[2], 0}} But while all of these have unit length, they do not form an orthonormal set since In[58]:= Dot @@ Rest[%] Out[58]= -2 I Sqrt[2] which is clearly not zero. That is for your matrix, a set of orthonormal eigenvectors doesn't exist. === Subject: Re: MenuView inside Manipulate > (1) Grid[{{MenuView[{1,2}],Graphics[Rectangle[{0,0}]]}}] > > (2) Manipulate[ > Grid[{{MenuView[{1, 2}], > Graphics[Rectangle[{0, 0}]]}}], {item, {0}}, ControlType -> None] > > (1) is a simple grid, and (2) simply embeds this grid in a dummy > Manipulate (i.e., the control variable does not enter the first arg of > the Manipulate, and the control is not explicitly displayed). When > one clicks on the popup menu in (1), the rectangle remains visible. > However, in (2), when one clicks on the popup menu, the rectangle > disappears, and only reappears when the mouse button is released. Is > this a bug? Does anyone know how one can keep the rectangle visible > in (2) when one clicks on the popup menu. (If TabView is substituted > for MenuView, the rectangle remains visible in both cases when a tab > is clicked.) > > dkr I forgot to note that this behaviour was obtained in Mathematica 6.0.1 under Mac OSX 10.5.2 (and also when running (2) in Player 6.0.2) dkr === Subject: Re: MenuView inside Manipulate I'm seeing no such difference in behavior between the two results: the rectangle remains visible in the result of (2) when I click the drop-down selector's arrow and then click 2, or when I click again and select 1. This is with Mathematica 6.0.2 under Windows XP. > (1) Grid[{{MenuView[{1,2}],Graphics[Rectangle[{0,0}]]}}] (2) Manipulate[ > Grid[{{MenuView[{1, 2}], > Graphics[Rectangle[{0, 0}]]}}], {item, {0}}, ControlType -> None] (1) is a simple grid, and (2) simply embeds this grid in a dummy > Manipulate (i.e., the control variable does not enter the first arg of > the Manipulate, and the control is not explicitly displayed). When > one clicks on the popup menu in (1), the rectangle remains visible. > However, in (2), when one clicks on the popup menu, the rectangle > disappears, and only reappears when the mouse button is released. Is > this a bug? Does anyone know how one can keep the rectangle visible > in (2) when one clicks on the popup menu. (If TabView is substituted > for MenuView, the rectangle remains visible in both cases when a tab > is clicked.) dkr > -- 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: can't translate 3D model to 0,0,0 >I have a problem with translating some 3D models to 0,0,0. I have >been using the following code: >ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; >where a is a 3D model made up of many 3D coordinates. However, >this code does not work - in that the new centroid (mean) of the >model is not at 0,0,0. can anyone suggest an alternative method? Your code is more complex than needed since ac = # - ma&/@a is exactly equivalent to your expression for ac. But having said that, there really isn't anything wrong with your code. It should do exactly what you want. === Subject: Re: Identical elements >I have a list and i need to test whether all the elements in the >list are identical or no. What is the efficient way to do that? The >output should be true if all elements are the same and False >otherwise. One line command is preferred if possible. Length[Union@list]==1 will return True if all elements of list are identical and False otherwise === Subject: 32 or 64 bit front-end on 64-bit Mac Just installed Mathematica 6.0.2.1 on a Mac Pro running OS X 10.5.2 (Leopard). TThe system info (portions included below) reports that the Mathematica kernel is 64 bit as expected, it says the front end is 32 bit. Note that in that section, the processor type is reported as x86 not x86-64. SystemInformationData[{Kernel -> {Version -> 6.0 for Mac OS X x86 (64-bit) (March 13, 2008), ReleaseID -> 6.0.2 (1009763, 1009696), ... MachineType -> PC, OperatingSystem -> MacOSX, ProcessorType -> x86-64, .... FrontEnd -> {Version -> 6.0 for Mac OS X x86 (32-bit) (March 13, 2008), ReleaseID -> 6.0.2 (1009763, 1009694), ... MachineType -> PC, OperatingSystem -> MacOSX, ProcessorType -> x86, .... Why doesn't the front end report as 64 bit and not 32 bit? Is this Jay === Subject: Saved a Notebook as .txt, now I need to import it again Hi. Using V. 6. I saved a notebook using math typesetting and thought I could open it and get everything to display right, but it now looks like: !(*OverscriptBox[[Beta], ^]), 0]Subscript[ !(*OverscriptBox[ RowBox[{+, , [Beta]}], ^]), 1]x + [Epsilon] Subscript[ !(*OverscriptBox[[Beta], ^]), 1]=Subscript[S, xy]/Subscript[S, xx] Subscript[ etc... Is there a way I can import this... I did play with the Cell Convert To, but I'm still left with the unevaluated SubScript... and no matter how I try to get those to eval., errors crop up since it cannot seem to eval. all of them at once. Any input would be appreciated. === Subject: Re: Fit data with range Hi Ivan, > I want to fit a polynomial function to a set of data, only > between say xmin to xmax. How can I do that? > I know only how to fit the whole range. For example: data = ReadList[file.dat,{Number,Number}]; fit = Fit[data,{1,x,x^2},x] Plot[fit,{x,0,10}] Select[] is probably the easiest way of isolating a subset of data. Take[] is very brute force. Example: data = {#, # + #^2 + 1.1 RandomReal[]} & /@ Range[-5, 5, .25]; (* generate data *) {dmin, dmax} = {Min@data[[All, 1]], Max@data[[All, 1]]}; (* find Min & Max coords *) ListPlot[data] (* always plot experimental data before fitting *) sdata = Select[data, (-dmin / 2 <= #[[1]] <= dmax /3) &]; (* select data using criterion *) sfit = Fit[sdata, {1, x, x^2}, x] (* fit subset *) afit = Fit[data, {1, x, x^2}, x] (* fit all data -- slight differences as expected *) Show[{ Plot[sfit, {x, dmin, dmax}], Plot[fit, {x, dmin, dmax}, PlotStyle -> Green], ListPlot[sdata, PlotStyle -> Red] }] (* compare both fits with experimental data *) Unfortunately, to get an objective degree of fit, we still need a package. Why this can't be an option to Fit[] is anyone's guess. Perhaps in 6.1? Needs[LinearRegression`] rfit = Regress[sdata, {1, x, x^2}, x] You can see effects of fitting a subset using slightly different data eg. data = {#, (# RandomReal[]) + (# RandomReal[])^2 + 1.5 RandomReal[]} & /@ Range[-5, 5, .25]; Dave. No virus found in this outgoing message. Checked by AVG. 16:34 === Subject: Re: Fit data with range >I want to fit a polynomial function to a set of data, only between >say xmin to xmax. How can I do that? I know only how to fit the >whole range. >For example: >data = ReadList[file.dat,{Number,Number}]; >fit = Fit[data,{1,x,x^2},x] Simply select just the points between xmin and xmax then do the fitting. Assuming your data set consists of {x,y} pairs, then either: Cases[data,{_?(xmin < # < xmax&),_}] or Select[data, xmin < First[#] < xmax&] will do the selection Note, in general it isn't a good idea to use powers of a single variable as a set of basis functions. This will be numerically unstable in general, becoming increasingly unstable for higher powers. There are packages available on Wolfram's web site for doing polynomial fits that avoid this problem. === Subject: Interpolation with FourierTrigSeries with mathematica 6 tia sal2 Interpolation with FourierTrigSeries with mathematica 6 tia sal2 I'm trying to modify these mathematica 6 commands to test some different data points. But I'm having some issues pop up and I don't know why. This is the Code that I had help with that works great: In[358] := data1 = {{0, 0}, {.5, -1}, {1, 0}, {2, 2}, {3, 0}, {4, -2.750000000}, {5, -4}, {6, -2.750000000}, {7, 0}, {8, 2.937500000}, {9, 5.500000000}, {10, 7.312500000}, {11, 8}, {12,7.312500000}, {13, 5.5}, {14, 2.937500000}, {15, 0}, {16, -2.918367347}, {17, -5.346938775}, {18, -6.795918367}, {18.5, -7}, {19, -6.795918368}, {20, -5.346938776}, {21,-2.918367347}, {22, 0}, {23, 2.84}, {24, 4.72}, {24.5, 5}, {25, 4.72}, {26, 2.84}, {27, 0}}; f = Interpolation[data1, PeriodicInterpolation -> True]; << FourierSeries` s[x_] = N[ FourierTrigSeries[f[x], x, 31, FourierParameters -> {-1, 1/27}]] My output is: 0.61887- 0.680232 Cos[0.232711 x] + 2.96293 Cos[0.465421 x] - 0.532024 Cos[0.698132 x] - 0.87105 Cos[0.930842 x] - 0.708467 Cos[1.16355 x] - 0.510603 Cos[1.39626 x] - 0.236222 Cos[1.62897 x] - 0.112403 Cos[1.86168 x] - 0.0682778 Cos[2.0944 x] - 0.0317201 Cos[2.32711 x] - 0.00399665 Cos[2.55982 x] + 0.0110171 Cos[2.79253 x] + 0.0150056 Cos[3.02524 x] + 0.0156793 Cos[3.25795 x] + 0.0122262 Cos[3.49066 x] + 0.00657111 Cos[3.72337 x] + 0.00432201 Cos[3.95608 x] + 0.00341808 Cos[4.18879 x] + 0.00370543 Cos[4.4215 x] + 0.00333083 Cos[4.65421 x] + 0.00210063 Cos[4.88692 x] + 0.00505182 Cos[5.11963 x] + 0.00866377 Cos[5.35234 x] + 0.0110508 Cos[5.58505 x] + 0.0103873 Cos[5.81776 x] + 0.00850073 Cos[6.05047 x] + 0.00811838 Cos[6.28319 x] + 0.00689916 Cos[6.5159 x] + 0.0069005 Cos[6.74861 x] + 0.00596679 Cos[6.98132 x] + 0.00358397 Cos[7.21403 x] + 2.25013 Sin[0.232711 x] - 4.51511 Sin[0.465421 x] + 0.380184 Sin[0.698132 x] + 0.461366 Sin[0.930842 x] + 0.0632479 Sin[1.16355 x] - 0.135095 Sin[1.39626 x] - 0.160692 Sin[1.62897 x] - 0.131694 Sin[1.86168 x] - 0.118779 Sin[2.0944 x] - 0.0966167 Sin[2.32711 x] - 0.0797548 Sin[2.55982 x] - 0.0599806 Sin[2.79253 x] - 0.0380326 Sin[3.02524 x] - 0.0247422 Sin[3.25795 x] - 0.0141664 Sin[3.49066 x] - 0.0078713 Sin[3.72337 x] - 0.0060369 Sin[3.95608 x] - 0.0062354 Sin[4.18879 x] - 0.00650479 Sin[4.4215 x] - 0.00560183 Sin[4.65421 x] - 0.00806245 Sin[4.88692 x] - 0.00982397 Sin[5.11963 x] - 0.00853789 Sin[5.35234 x] - 0.00582364 Sin[5.58505 x] - 0.00249366 Sin[5.81776 x] - 0.00125506 Sin[6.05047 x] - 0.0000310571 Sin[6.28319 x] + 0.000971067 Sin[6.5159 x] + 0.00160663 Sin[6.74861 x] + 0.00321022 Sin[6.98132 x] + 0.00388205 Sin[7.21403 x] When I change different data points to the code example: data2 = {{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, 6}, {19, -2}, {25, -6}, {34, 6}, {41, 4}, {49, -6}, {56, -5}, {63, 4}, {69, 3}, {74, -5}, {77, -3}, {86, 3}, {90, 7}, {95, -3}, {96, -8}, {103, 7}, {112, 9}, {120, -8}, {129, -9}, {138, 9}}; f = Interpolation[data2, PeriodicInterpolation -> True]; << FourierSeries` s[x_] = N[ FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]] my partial output becomes : 0.00729927 NIntegrate[ Interpolation[{{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, 6}, {19, -2}, {25, -6}, {34, 6}, {41, 4}, {49, -6}, {56, -5}, {63, 4}, {69, 3}, {74, -5}, {77, -3}, {86, 3}, {90, 7}, {95, -3}, {96, -8}, {103, 7}, {112, 9}, {120, -8}, {129, -9}, {138, 9}}, PeriodicInterpolation -> True][x], {x, -(137/2), 137/2}] + 0.0145985 Cos[0.0458627 x] NIntegrate.......................... does anyone know why this no longer outputs in the form of just sin and cos? (which I really want) tia sal2 === Subject: Finding the line that caused an error Is there any way to display the specific line of code that caused an error in Mathematica? I'm used to working with C++ compilers that give you a line number along with each error message, and I'm starting to get frustrated with Mathematica. It'd be much simpler to immediately see the cause of the error instead of sifting through many lines of code. === Subject: Re: Locator Hi Albert, ----- Original Message ---- === Subject: Re: Locator > Very recently I started using Mathematica with the hopes of accomplishing the following. I have had some progress by using extensively the documentation center, however, any help will be really appreciated. I have 2 questions in particular and have described them below: Unusual things to try when starting to use Mathematica :-) > I have created 3 notebooks with the following command: > lst = Table[ > NotebookCreate[WindowSize -> {240, 240}, WindowTitle -> new, > WindowMargins -> {{RandomInteger[{0, 100}], Automatic}, { Automatic, > RandomInteger[{0, 50}]}}], {3}]; newlst=Map[WindowMargins /. Options@# &, > Select[Notebooks[], > StringMatchQ[(WindowTitle /. NotebookInformation[#]), new] &]] I then retrieve the notebook locations for the 3 notebooks. > coord = Map[({#[[1, 1]], #[[2, 2]] }) &, newlst] Finally, I want to create locators for each of the above notebooks, such that when I move the locators the notebooks are moved. In other words, the {x,y} position of the locators is mapped to the WindowMargins of that particular notebook. I have successfully created the locators but I have no clue how to map the locators such that the notebooks are moved. Below is the code for it: DynamicModule[{pt = new1}, > LocatorPane[Dynamic[pt], > Dynamic@ > ListPlot[pt, AxesOrigin -> {0, 0}, PlotRange -> {{0, 100}, {0, 50}}]]] I can move the locators, but with the moving of locators I need to the move corresponding notebook. Any help would be of great help when experimenting it is usually easier to get things working for a simple case. Here I'll start of with one notebook. Note that NotebookCreate returns a notebookobject which you can refer to later, so there is no need to search Notebooks[] for it: nb = NotebookCreate[ WindowSize -> {240, 240}, WindowMargins -> { {RandomInteger[{0, 100}], Automatic}, {Automatic, RandomInteger[{0, 50}]} } ] these define the screensizes and are handy lateron: screenheight = (ScreenRectangle /. Options[$FrontEnd])[[2, 2]] screenwidth = (ScreenRectangle /. Options[$FrontEnd])[[1, 2]] this is a function that moves the window for a given notebook to new values of WindowMargins: movenb[nb_, {x_, y_}] := SetOptions[nb, WindowMargins -> {{x, Automatic}, {Automatic, screenheight - y}}] This shows a LocatorPane which will move the window. The trick is to use the two argument version of Dynamic: DynamicModule[{pt = {#1, screenheight - #2} & @@ Flatten[WindowMargins /. Options[nb]][[{1, -1}]]}, LocatorPane[ Dynamic[pt, Function[pt = #; movenb[nb, pt]; pt] ], Graphics[{}, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]) ] ]] It turns out that handling lists is easier with this, which uses Locator instead of LocatorPane and happens to be more compact in this case as well: DynamicModule[{pt = {#1, screenheight - #2} & @@ Flatten[WindowMargins /. Options[nb]][[{1, -1}]]}, Graphics[{Locator[Dynamic[pt, Function[pt = #; movenb[nb, pt]; pt] ]]}, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]) ] ] now we are ready to work with a list of notebooks: nblst = Table[NotebookCreate[ WindowSize -> {240, 240}, WindowMargins -> { {RandomInteger[{0, screenwidth}], Automatic}, {Automatic, RandomInteger[{0, screenheight}]} } ], {3}] This defines a graphics with one locator for each window: nbcoords = Map[Flatten[WindowMargins /. Options[#]][[{1, -1}]] &, nblst] With[{screenheight = (ScreenRectangle /. Options[$FrontEnd])[[2, 2]]}, DynamicModule[{ ptlst = {#1, screenheight - #2} & @@@ nbcoords }, Graphics[{ Table[ With[{nn = n}, Locator[ Dynamic[ptlst[[nn]], Function[movenb[nblst[[nn]], #]; ptlst[[nn]] = #]] ] ], {n, Length[nblst]}] }, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]) ] ] ] to make it look nicer you might want to use rectangles as representations for your windows. You might want them to be of the correct relative size and use the top left corner for their positions to reflect more closely the actual window on screen, which I did not implement here: Deploy@DynamicModule[{ ptlst = {#1, screenheight - #2} & @@@ nbcoords }, Graphics[{ Table[ With[{nn = n}, Locator[ Dynamic[ptlst[[nn]], Function[movenb[nblst[[nn]], #]; ptlst[[nn]] = #]], Graphics[{Opacity[0.5], Rectangle[]}, ImageSize -> 48] ] ], {n, Length[nblst]}] }, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]), FrameTicks -> None ] ] hth, albert === Subject: Question about alignment in Grid and TableForm I wish text objects in Grid would be aligned at center of column and numbers in ScientificForm aligned at .. I have tried to use the following constructions as elements of the Grid but the text objects are not centered at the centers of columns: Item[some text, Alignment -> Center] and Item[1000*Pi // ScientificForm, Alignment -> .]. The code I have tried (it is just example): TableForm[ Insert[Table[ Item[N[Pi a^10] // ScientificForm, Alignment -> .], {a, 1, 5}, {b, 1, 3}], {Item[First Column text, Alignment -> Center], Item[Second Column text, Alignment -> Center], Item[Third Column text, Alignment -> Center]}, 3]] Grid[Insert[ Table[Item[N[Pi a^10] // ScientificForm, Alignment -> .], {a, 1, 5}, {b, 1, 3}], {Item[First Column text, Alignment -> Center], Item[Second Column text, Alignment -> Center], Item[Third Column text, Alignment -> Center]}, 3]] How to place text objects at the centers of the columns? Is this a bug in Alignment option? === Subject: Want a general method to extract cases resulting from Reduce Someone recently posted asking How to remove unneeded constraints. I can see a general use for something perhaps related to this. Reduce often gives back fairly complicated nested boolean structures of constraints. Consider the results from the following concrete example: Reduce[{a x1^2 + b x1 + c == y1, a x2^2 + b x2 + c == y2, a( -b/ (2a))^2+ b ( -b/(2a)) + c == y3, y1 < y3, y2 < y3, x1 < x2, Element[Alternatives[ x1, x2, x3, y1, y2, y3, a, b, c], Reals]}, {a, b, c}] or even worse Reduce[{a x1^2 + b x1 + c == y1, a x2^2 + b x2 + c == y2, a( -b/ (2a))^2+ b ( -b/(2a)) + c == y3, y1 < y3, y2 < y3, x1 < x2, Element[Alternatives[ x1, x2, x3, y1, y2, y3, a, b, c], Reals]}, {a, b, c}, Backsubstitution->True] For examples like these I then spend time carefully matching up () and trying to determine how many layers and which of the nested constraints apply to each of the alternatives. I now realize I could often use a general purpose solution to inspect results like these. For example, (all the conditions except the last one are just the conditions I gave Reduce, the y1 {Version -> 6.0 for Mac OS X x86 (64-bit) (March 13, 2008), ReleaseID -> 6.0.2 (1009763, 1009696), FrontEnd -> {Version -> 6.0 for Mac OS X x86 (32-bit) (March 13, 2008), ReleaseID -> 6.0.2 (1009763, 1009694), === Subject: Definite integral I don't understand Mathematica can't calculate the last definite integral. For the first three integrals works fine, but for the last one crush. You can see in this paper === Subject: Re: Identical elements > I have a list and I need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. Hi. Here's one way. I assume a list with 1 element returns False. AllEqualQ[v_List] := If[Length[v] == 1, False, Equal[1, KroneckerDelta @@ v]] -- HTH :>) Dana DeLouis Mathematica 6.01 (Windows Vista) === Subject: Re: list of dates > >A key aspect of the problem is that the dates are a list, so I want to be >able to operate on them as a list. >The approximation of leap years does not concern me, although the year has > >Adapting your suggestions and after much struggle (I am new to Mathematica), >I came up with this >(date is the list of dates input, t is the list of values output): > >n = Length[date]; >t = year - 1900 + days / 365.24; > >It is however very slow. It takes a couple of minutes for 15,000 dates. >All the other software I have used for a similar calculation (Excel, Stata) >does it in a split second. > >Is there a much more efficient method? > > AbsoluteTime. Carl Woll Wolfram Research >Roger > > > > >>I have a list of dates in the format YYYY-MM-DD and I want to convert them >>to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly >>to 85.5. >> >>Any suggestions on the best way to do this? >> >>Roger >> >> >> >> > > > === Subject: Re: list of dates >Adapting your suggestions and after much struggle (I am new to >Mathematica), I came up with this (date is the list of dates >input, t is the list of values output): >n = Length[date]; >t = year - 1900 + days / 365.24; >takes a couple of minutes for 15,000 dates. All the other software I >have used for a similar calculation (Excel, Stata) does it in a >split second. Your code is doing quite a bit more than what is needed. Bob Hanlon's solution (which I like better than what I had suggested) is easily made to handle lists as follows: Out[3]= {63,85.4959} However, this code may not be all that much faster than your a fairly wide range of date formats. I believe the overhead involved to allow a wide range of date formats is the main slow down. Here is a version that gives about a factor of 2 improvement on my machine Year][[1]] Out[7]= {0.025224,{63,85.4959}} comparing: Out[8]= {0.053429,{63,85.4959}} === Subject: Re: Identical elements list1 = {a, b, c}; list2 = {b, b, b}; SameQ @@ list1 False SameQ @@ list2 True @@ is Apply. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. > > Your help is highly appreciated. > > > HMQ > === Subject: Re: Identical elements > > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. > > Your help is highly appreciated. > > > HMQ > Do you really mean identical and not euqal? This is an important distinction in Mathematica! Assuming that you do: ls = {1, 1, a, 1}; SameQ @@ ls False ls = {a, a, a, a}; SameQ @@ ls True Andrzej Kozlowski === Subject: Re: Identical elements Something like this? In[1]:= MatchQ[{1, 2, 1}, {(x_) ...}] Out[1]= False In[2]:= MatchQ[{1, 1, 1}, {(x_) ...}] Out[2]= True or, less elegant (IMO) Out[3]= False Out[4]= True Adriano Pascoletti > > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. > > Your help is highly appreciated. > > > HMQ > > === Subject: Re: Identical elements > I have a list and i need to test whether all the elements in the list >> are identical or no. What is the efficient way to do that? The output >> should be true if all elements are the same and False otherwise. One >> line command is preferred if possible. >> >> Your help is highly appreciated. A possible approach, thought you did precise neither the type of the > elements of the list (numeric, symbolic, mixed,...) nor whether the list > could contains some other lists, is the following. We test each > remaining element of the list against the first element and return False > as soon as an element differs from the first one. > myCheck[lst_List] := > Module[{fe = First@lst, status = True}, > Scan[If[# != fe, Return[status = False]] &, Rest@lst]; status] myCheck[{1, 1, 1, 1}] > myCheck[{1, 1, -1, 1}] > myCheck[{{1, 2}, {1, 2}, {1, 2}, {1, 2}}] > myCheck[{{1, 2}, {1, 2}, {-1, 2}, {1, 2}}] True False True False A simpler and faster solution is to use *Equal* to test equality of the list against itself slightly rotated. For instance, In[1]:= lst = Join[{0.}, ConstantArray[1., {10^7}]]; Timing[lst == RotateLeft@lst] Out[2]= {0.137857, False} In[3]:= lst = Join[{1.}, ConstantArray[1., {10^7}]]; Timing[lst == RotateLeft@lst] Out[4]= {0.191334, True} -- Jean-Marc === Subject: Re: Identical elements > > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. > > Your help is highly appreciated. > > > HMQ Short answer: Count[x, x[[1]]] == Length[x] seems efficient, especially for the case of large lists with most elements equal. Longer: As I've only very recently started to use Mathematica for 'programming' I thought I'd try a few different ways : version. Side note: Coding the Do loop version was very traumatic for this Fortran programmer as I've just learned that Return behaves much differently in a Do loop than in a For or While loop. And the behaviour which to me seems more consistent (i.e same as For and While) can only be got by using the Return[_,Module] form which is not documented & I only discovered by searching this newsgroup. Moreover the current documentation (6.02) for return is sparse and doesn't really explain any of this clearly. When I do need a loop I prefer Do as it's simple (and close to the Fortran do loop in style so easy for quick conversion) and has the advantage that the looping variables are localized. I know procedural programming is not encouraged in Mathematica but sometimes the flow of control is messy & it's not possible to reduce a block of code to a small function let alone a one liner. I'm now not sure how a given Return[] nested in various loops an other control structures behaves (other than by testing it by trial and error), and since the Return[_,Module] is undocumented I guess it's not safe to use. I know there's Throw/Catch etc. and the real problem is I expected Return to behave like in Fortran/C, but I think this does warrant one or two sentences in the documentation as quite a few programmers must come to Mathematica from Fortran &/ C++. Tom McDermott. In[1]:= f1[x_] := Module[{x1 = x[[1]], i, n = Length[x]}, For[i = 2, i <= n, i++, If[x[[i]] != x1, Return[False]]]; True] In[2]:= f2[x_] := Module[{x1 = x[[1]], n = Length[x]}, Do[If[x[[i]] != x1, Return[False, Module]];, {i, 2, n}]; True] In[3]:= f3[x_] := And @@ (# == x[[1]] & /@ x) In[4]:= f4[x_] := Module[{x1 = x[[1]]}, And @@ (# == x1 & /@ x)] In[5]:= f5[ In[6]:= f6[x_] := Null)] In[7]:= f7[x_] := LengthWhile[x, # == x[[1]] &] == Length[x] In[8]:= f8[x_] := Count[x, x[[1]]] == Length[x] In[9]:= t = ConstantArray[0, {9, 7}]; Do[ For[n = 1; i = 1, n < 10^7, n *= 10; i++, x = ConstantArray[1, {n}]; (*x=RandomInteger[{1,n},n];*) x[[RandomInteger[{1, n}]]] = 0; t[[1, i]] += n; j = 1; Do[ j++; t[[j, i]] += Timing[f[x]][[1]]; , {f, {f1, f2, f3, f4, f5, f6, f7, f8}} ] ] , {k, 10} ]; MatrixForm[t/10] Out[10]//MatrixForm= !(* TagBox[ RowBox[{(, [NoBreak], GridBox[{ {1, 10, 100, 1000, 10000, 100000, 1000000}, {6.083675230250663`*^-16, 5.078402975922103`*^-16, 7.919012667834124`*^-16, 0.001299800000000279`, 0.013097899999999621`, 0.11298270000000028`, 1.1733215999999995`}, {6.083675230250663`*^-16, 0.00010000000000050794`, 7.919012667834124`*^-16, 0.0005999999999994859`, 0.0074988999999999655`, 0.06299050000000009`, 0.6567000999999999`}, {6.083675230250663`*^-16, 7.409871327634932`*^-16, 0.0003999000000004959`, 0.00119989999999912`, 0.01059839999999971`, 0.10818369999999931`, 1.0992327999999991`}, {5.079270337660091`*^-16, 0.00010000000000074099`, 0.00010000000000089772`, 0.0007998000000010313`, 0.007098899999999141`, 0.07198899999999954`, 0.7474868000000006`}, {5.079270337660091`*^-16, 7.919012667834124`*^-16, 0.0001999000000005075`, 0.0007998000000009498`, 0.007598899999999501`, 0.06838960000000004`, 0.7099917000000004`}, {5.079270337660091`*^-16, 7.919012667834124`*^-16, 5.845991008987528`*^-16, 0.0006000000000008052`, 0.006199100000000433`, 0.05239210000000059`, 0.5442175999999997`}, {0.00010000000000050794`, 0.00010000000000047177`, 0.0001000000000005846`, 0.00149979999999977`, 0.01489779999999977`, 0.12608060000000074`, 1.2976026000000003`}, {5.078402975922103`*^-16, 7.919012667834124`*^-16, 5.845096542195228`*^-16, 4.1227871810933796`*^-16, 0.000699799999999542`, 0.00899880000000006`, 0.09288559999999928`} }, GridBoxAlignment->{ Columns -> {{Left}}, ColumnsIndexed -> {}, Rows -> {{Baseline}}, RowsIndexed -> {}}, GridBoxSpacings->{Columns -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, ColumnsIndexed -> {}, Rows -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, RowsIndexed -> {}}], [NoBreak], )}], Function[BoxForm`e$, MatrixForm[BoxForm`e$]]]) Side note: (maybe some gure can comment on this gripe)... Coding the Do loop version was very traumatic for this Fortran programmer as I've just learned that Return behaves much differently in a Do loop than in a For or While loop. And the behaviour which to me seems more consistent (i.e same as For and While) can only be got by using the Return[_,Module] form which is not documented & I only discovered by searching this newsgroup. Moreover the current documentation (6.02) for return is sparse and doesn't really explain any of this clearly. When I do need a loop I prefer Do as it's simple (and close to the Fortran do loop in style so easy for quick conversion) and has the advantage that the looping variables are localized. I know procedural programming is not encouraged in Mathematica but sometimes the flow of control is messy & it's not possible to reduce a block of code to a small function let alone a one liner. I'm now not sure how a given Return[] nested in various loops an other control structures behaves (other than by testing it by trial and error), and since the Return[_,Module] is undocumented I guess it's not safe to use. I know there's Throw/Catch etc. and the real problem is I expected Return to behave like in Fortran/C, but I think this does warrant one or two sentences in the documentation as quite a few programmers must come to Mathematica from Fortran &/ C++. === Subject: Re: Identical elements > > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. > > Your help is highly appreciated. > > > HMQ There's probably a dozen ways to do this. In version six, there's PatternSequence: In[448]:= MatchQ[{q, q, q, q}, PatternSequence[_]] Out[448]= True JM === Subject: Re: Identical elements > > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. > > Your help is highly appreciated. > > > HMQ I'd like to retract that suggestion of PatternSequence. It doesn't work. MatchQ[{q, 1, q, q}, PatternSequence[_]] True JM === Subject: Re: Identical elements I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. SameQ @@ list But note that 0 and 0.0 are not identical (you may need Equal instead of SameQ) === Subject: Re: Identical elements > I have a list and i need to test whether all the elements in the list > are identical or no. What is the efficient way to do that? The output > should be true if all elements are the same and False otherwise. One > line command is preferred if possible. Your help is highly appreciated. A possible approach, thought you did precise neither the type of the elements of the list (numeric, symbolic, mixed,...) nor whether the list could contains some other lists, is the following. We test each remaining element of the list against the first element and return False as soon as an element differs from the first one. myCheck[lst_List] := Module[{fe = First@lst, status = True}, Scan[If[# != fe, Return[status = False]] &, Rest@lst]; status] myCheck[{1, 1, 1, 1}] myCheck[{1, 1, -1, 1}] myCheck[{{1, 2}, {1, 2}, {1, 2}, {1, 2}}] myCheck[{{1, 2}, {1, 2}, {-1, 2}, {1, 2}}] True False True False -- Jean-Marc === Subject: root of complex function I need to get a list of root intervals of a complex function. I tried in vain to use the package IntervalRoots. However, this package seems to work only with real functions. I appreciate it if someone can provide me with a simple code that does the job. I also tried to download the Rootsearch package by Ersek but the package is not downloadable. HMQ === Subject: Manipulate in HelpBrowser: Bug I wanted to use the Manipulate command in some of my old help files, i.e. HelpBrowser and not DocumentationCenter. Thereby I noticed the following weird behavior: Open the HB with FrontEndTokenExecute[HelpDialog]. Evaluate Manipulate[Plot[Sin[k x], {x, 0, 1}], {k, 1, 2}]. It won't behave properly when moving the slider. Now strange is that 1.) Animate works 2.) Copying the output cell and pasting it again works. I used M6 in Windows, on Mac and Linux everything worked as expected. Can anyone explain this behavior or (even better) knows a (simple) workaround. My best idea would be to use Animate instead. Markus Huber === Subject: Re: Fit data with range fit = Fit[Select[data,(xmin<=First[#1]<=xmax) &],{1,x,x^2},x] ?? Jens > Hi I want to fit a polynomial function to a set of data, > only between say xmin to xmax. How can I do that? > I know only how to fit the whole range. For example: data = ReadList[file.dat,{Number,Number}]; fit = Fit[data,{1,x,x^2},x] Plot[fit,{x,0,10}] === Subject: Re: Fit data with range > Hi I want to fit a polynomial function to a set of data, > only between say xmin to xmax. How can I do that? > I know only how to fit the whole range. For example: data = ReadList[file.dat,{Number,Number}]; fit = Fit[data,{1,x,x^2},x] Plot[fit,{x,0,10}] > Filter the data with Select or Case! The exact command to use depends on the shape of the data. E.g. Case[data, {x_, _} /; xmin <= x <= xmax] === Subject: Re: Fit data with range > I want to fit a polynomial function to a set of data, > only between say xmin to xmax. How can I do that? > I know only how to fit the whole range. For example: data = ReadList[file.dat,{Number,Number}]; fit = Fit[data,{1,x,x^2},x] Plot[fit,{x,0,10}] You could use *Select[]* to massage your data. For instance, data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {7, 8}, {9, 11}}; xmin = 1; xmax = 7; pts = Select[data, xmin <= #[[1]] <= xmax &] fit = Fit[pts, {1, x, x^2}, x] Show[ListPlot[pts, PlotStyle -> {Red, PointSize -> Large}], Plot[fit, {x, xmin, xmax}, PlotStyle -> {Blue, Thick}]] {{1, 0}, {3, 2}, {5, 4}, {7, 8}} 2 -0.325 + 0.3 x + 0.125 x -- Jean-Marc === Subject: Re: Problem/bug with ends of thick lines in graphics Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, PlotStyle -> {AbsoluteThickness[20]}] /. Line[pnts_] :> {AbsolutePointSize[20], Point[pnts]} may help in this case. But AFAIK Mathematica has no directive to set the line ends. Jens > In a quick search of things I haven't found a mention of the following > simple graphics issue and I'm checking in with the group to see if > there is a memory of its mention and if there is a simple fix (and > which is not a complicated hack) that I've not been able to come up > with. Consider the following graph: Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {AbsoluteThickness[20]}] When you plot it you will see that the line's ends are not > rectangular, whereas you would certainly want them to be so. (An > alternative would be to have them be rounded, for example, but the > question will remain the same whatever your preference is.) Rather > they appear as polygonal in a way inconsistent with the line itself. One assums that this is an artifact of how the line is rendered based > on the individual line segments, and that that segmental rendering has > to do something with how a segment relates to the segments on either > side of it. The lack of a segment beyond the end segment presumably > runes the algorithm for rendering in a way that leads to this > appearance. I have two related questions here. The first is how, if at all > possible, to fix this in a general way through some specific options > settings for the graphics function. The second is how, when exporting this graphic as, say, a PDF, to make > it behave properly. There was a trick in pre version-6 Mathematica that would involve > adding an explicit postscript command to the PlotStyle option. Though > this would not (I think) correct the screen appearance of the graphic, > it would properly fix it when the graphic was exported to PDF or EPS. > Here is an example of how it was done: Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {{ PostScript[0 setlinecap],AbsoluteThickness[20]}}] This, however, no longer works in Mathematica 6+ presumably because of > the new way that graphics rendering is handled. Does anyone have any solutions to either or both of these issues? > --David > === Subject: Re: Problem/bug with ends of thick lines in graphics > In a quick search of things I haven't found a mention of the following > simple graphics issue and I'm checking in with the group to see if > there is a memory of its mention and if there is a simple fix (and > which is not a complicated hack) that I've not been able to come up > with. Consider the following graph: Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {AbsoluteThickness[20]}] When you plot it you will see that the line's ends are not > rectangular, whereas you would certainly want them to be so. (An > alternative would be to have them be rounded, for example, but the > question will remain the same whatever your preference is.) Rather > they appear as polygonal in a way inconsistent with the line itself. One assums that this is an artifact of how the line is rendered based > on the individual line segments, and that that segmental rendering has > to do something with how a segment relates to the segments on either > side of it. The lack of a segment beyond the end segment presumably > runes the algorithm for rendering in a way that leads to this > appearance. I have two related questions here. The first is how, if at all > possible, to fix this in a general way through some specific options > settings for the graphics function. The second is how, when exporting this graphic as, say, a PDF, to make > it behave properly. There was a trick in pre version-6 Mathematica that would involve > adding an explicit postscript command to the PlotStyle option. Though > this would not (I think) correct the screen appearance of the graphic, > it would properly fix it when the graphic was exported to PDF or EPS. > Here is an example of how it was done: Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {{ PostScript[0 setlinecap],AbsoluteThickness[20]}}] This, however, no longer works in Mathematica 6+ presumably because of > the new way that graphics rendering is handled. Does anyone have any solutions to either or both of these issues? > I brought this up two or three times on MathGroup, but never received a reply ... So I guess that we have to live without this feature in Mathematica 6 ... I used to use PostScript[ ... ] in Mathematica <= 5.2 to set line caps and line joins. The default was round cap and round join. But PostScript[] does not work any more---not even with EPS or MPS output. (One cannot expect it to work with other outputs, of course.) Unfortunately they changed the defaults to square cap and miter join in Mathematica 6. I think that this was the worst possible choice ... The square caps/joins take up more space than either of the two other possibilities (bevel/round join), so it is not even possible to emulate these by adding bullets at line joins ... Miter joins cause heavily fluctuating ListPlots to look very ugly and pointy, like a hedgehog. They could look much better with round joins. Here's an example: ListPlot[{{0, 0}, {1, 5}, {2, 0}}, Joined -> True, PlotStyle -> Thickness[.1], PlotRange -> {{-1, 3}, {-1, 6.5}}] Imagine this repeated a thousand times with sharper angles. http://www.capcode.de/help/setlinejoin http://www.capcode.de/help/setlinecap Unfortunately the pointy line joins are not the only things that can cause troubles ... The shape of a Point[] can also be quite strange at small sizes: Mathematica switches to square or other point shapes at small sizes, which is useful for raster graphics, but does not make any sense for PostScript/PDF output. And the PostScript output generated for Point[]s is just awful: instead of defining one simple point drawing command, and using it consistently, these whole series of commands for drawing these strange shapes is repeated for each point. Just try the following to see what I mean: ExportString[Point[RandomReal[1, {10, 2}]] // Graphics, EPS] Yet another graphics export problem is this: ap = ArrayPlot[RandomInteger[1, {200, 200}], ColorFunction -> (If[# > 0.5, Black, White] &)]; gr = GraphicsRow[{ap, ap}] Export[gr.pdf, gr] Open the PDF and see how the small black and white squares that make up the graphic are completely misaligned, making the output completely useless. The PDF output looks completely different than the rendering in the front end. I really hope that these problems will be fixed for 6.1 ... === Subject: Re: Wolfram Workbench user experiences > >I would be very interested in other people's experiences with the >Wolfram Workbench. I must admit that I prefer to use the frontend as >my 'IDE', and the workbench seemed fairly alien when I tried it. > > I briefly played with Wolfram Workbench. But I didn't see any > significant advantage it had over using the frontend to develop > code. So, like you, I stuck with using the frontend. I would have to disagree with some of these statements. I am a relatively new mathematica user and I find Workbench indispensable. It is especially useful for working on a set of nested packages, particularly with the automatic package reload feature. It catches errors in syntax and has good syntax highlighting. It works nicely in tandem with a source-code repository, writing and debugging C or java mathlink programs. It seems to have been designed with some care. For example, cutting and pasting text from a notebook works seemlessly and inserts spaces in appropriate places. The debugger has a stack trace so it is an easy way to learn what mathematica is actually doing. Setting breakpoints on messages is very useful. For example, if you have problems aborting some buggy code, set a breakpoint on all messages, it breaks on the first message, abort in the frontend, and then run, and the kernel immediately aborts. And it can automatically update itself. But the debugger is buggy and slow for me. Also, Workbench is built around a slightly older version of eclipse which makes it hard to use with other eclipse addons (like the C++ one). It's not natively 64- bit, I think. And it has a critical bug in the console window that causes it to crash on messages that include Short versions of numerical lists (I think the console tries to print the whole list or something). It is also a relative memory hog. And the package editor from the front-end is more 'literate programming' friendly. === Subject: Re: Wolfram Workbench user experiences My general feeling is that I would be sorry to see various features randomly scattered between two vastly different interfaces. Thus I don't really want to have to use WB to get full debugging, but FE to get characters such as [Breve] to display correctly. Use WB to set up documentation, but FE to view the result, etc. Having two interfaces seems to make it much harder to describe how to perform a task (or indeed to teach Mathematica) and generally seems to lead to a loss of focus. debugging and profiling, and one has to ask whether these features would not be better pulled into the main product. Furthermore, editing a .m file in Mathematica seems to be a much more satisfying experience than using WB, because Mathematica can save and restore heading and text cells as comments, so that you get most of the richness of a notebook with all the advantages of a text file. (I would recommend anyone who maintains package files to check out this feature) I would like to see this concept enhanced further - say to include colour. Much of my work involves J/Link accessing compiled Java code. In a way WB might have been ideal for this type of project, but because I was not starting from scratch, I already had a structure to assemble this code, and figuring out how to use WB to perform the equivalent operation seemed formidably hard. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: can't translate 3D model to 0,0,0 > > I have a problem with translating some 3D models to 0,0,0. I have been using the following code: > > ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; > > where a is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method? > > best wishes, > > Will If a is a list of coordinates the code you posted seems fine: a = {{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}, {a41, a42,a43}}; ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; In[4]:= Mean@ac Out[4]= {0, 0, 0} .... as expected === Subject: Re: can't translate 3D model to 0,0,0 what may Normal[Translate[your3DGraphics,ma]] do ?? Jens I have a problem with translating some 3D models to 0,0,0. I have been using the following code: ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; where a is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method? best wishes, Will > === Subject: Re: can't translate 3D model to 0,0,0 > > Hi Szabolcs, > > sorry, I don't understand. for which mean do you get 0,0,0? your final > output is: > > Out[3]= {-1.55431*10^-17, -6.66134*10^-18, 4.44089*10^-18} > > I know it is very close to 0,0,0, but why is it not exactly 0,0,0? We're working with inexact numbers (more precisely: machine precision numbers, which have a precision of approx. 16 digits). It is expected that the result cannot be _exactly_ zero because of numerical errors. Since the numbers in the data are of order of magnitude of 1, and we're working with ~ 16 digits of precision, the numerical error simply cannot be much less than 10^-16. In fact, Mathematica does a much better job with this than programming languages that were not specifically designed for doing math. It uses a special summation algorithm to minimize the numerical error (see the Method option of Total) For example, let's try a similar computation in both Mathematica and Python: The Python version: In [1]: from random import random In [2]: data = [random() for x in xrange(1000000)] In [3]: m = sum(data)/len(data) In [4]: mdata = [x - m for x in data] In [5]: sum(mdata)/len(mdata) Out[5]: -1.2785664860182067e-014 The Mathematica version: In[1]:= data = RandomReal[1, 1000000]; In[2]:= Mean[data - Mean[data]] Out[2]= 2.01783*10^-17 Note that the error is 3 orders of magnitude smaller in the case of Mathematica. > also, > i've found with different models the means are slightly different (not > surprisingly): Of course: RandomReal generates a different sequence of points with each invocation, so the numerical error will be different, too. > > In[6]:= b = RandomReal[1, {100, 3}]; > mb = Mean[b]; > Mean[# - mb & /@ b] > > Out[8]= {1.77636*10^-17, 8.88178*10^-18, 3.9968*10^-17} > > > In[9]:= a = RandomReal[1, {100, 3}]; > ma = Mean[a]; > Mean[# - ma & /@ a] > > Out[11]= {2.05391*10^-17, 2.77556*10^-18, -6.66134*10^-18} > > am i missing the point somehow? > > the models I am working on are of the form in your demonstration, ie: > > {{0.96169, 0.0737274, 0.528905}, {0.297682, 0.741866, 0.67568},..., > {0.584149, 0.95142, 0.0996909}} > === Subject: Re: can't translate 3D model to 0,0,0 I have a problem with translating some 3D models to 0,0,0. I have been using the following code: ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; where a is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method? > What does 'a' contain exactly? In[1]:= a = RandomReal[1, {100, 3}]; In[2]:= ma = Mean[a]; In[3]:= Mean[# - ma & /@ a] Out[3]= {-1.55431*10^-17, -6.66134*10^-18, 4.44089*10^-18} I get {0,0,0} for the mean (as expected). === Subject: Re: can't translate 3D model to 0,0,0 It should work but you can use a slightly simpler expression. Of course, it always helps when posting to MathGroup to give an actual case that doesn't work rather than letting the responders make up their own cases. pts = RandomReal[{0, 1}, {10, 3}] mean = Mean[pts] # - mean & /@ pts Mean[%] // Chop -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > > I have a problem with translating some 3D models to 0,0,0. I have been > using the following code: > > ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; > > where a is a 3D model made up of many 3D coordinates. However, this code > does not work - in that the new centroid (mean) of the model is not at > 0,0,0. can anyone suggest an alternative method? > > best wishes, > > Will > === Subject: Re: orthonormal eigenvectors > > I have a 3X3 matrix M: > {1,-i(2^(1/2)),0} > {i(2^(1/2)),0,0} > {0,0,2} > > And I am trying to find a set of orthonormal eigenvectors for M. > If anyone can help, I would greatly appreciate it. > > Brian m = {{1, -I (2^(1/2)), 0}, {I (2^(1/2)), 0, 0}, {0, 0, 2}}; Eigenvectors[m] {{0, 0, 1}, {-I Sqrt[2], 1, 0}, {I/Sqrt[2], 1, 0}} Eigenvalues[m] {2, 2, -1} Orthogonalize[m] {{1/Sqrt[3], -I Sqrt[2/3], 0}, {I Sqrt[2/3], -(1/Sqrt[3]), 0}, {0, 0, 1}} === Subject: Re: orthonormal eigenvectors > I have a 3X3 matrix M: > {1,-i(2^(1/2)),0} > {i(2^(1/2)),0,0} > {0,0,2} And I am trying to find a set of orthonormal eigenvectors for M. > If anyone can help, I would greatly appreciate it. You could start by writing your matrix in correct Mathematica syntax, then read about (in the documentation center for instance) and use functions such as *Eigenvectors[]* or *Orthogonalize[]*. m = {{1, (-i)*2^(1/2), 0}, {i*2^(1/2), 0, 0}, {0, 0, 2}}; Eigenvectors[m] {{0, 0, 1}, {-((-1 + Sqrt[1 - 8 i^2])/(2 Sqrt[2] i)), 1, 0}, {(1 + Sqrt[1 - 8 i^2])/(2 Sqrt[2] i), 1, 0}} -- Jean-Marc === Subject: Re: orthonormal eigenvectors I have a 3X3 matrix M: > {1,-i(2^(1/2)),0} > {i(2^(1/2)),0,0} > {0,0,2} And I am trying to find a set of orthonormal eigenvectors for M. > If anyone can help, I would greatly appreciate it. The set returned by Eigenvectors[] is already orthogonal, and you can normalize them with Normalize[]. === Subject: Dashing[{}] If I invoke Dashed somewhere in my Graphics3D display code, a subsequent Dashing[{}], Line[...] is supposed to draw solid lines thereafter. It seems to have no effect as everything after that is still dashed. Might there be something simple I'm missing? Or a bug? Steve Gray === Subject: Fitting with a power embedded in a integration I don't know how to fit my data with a power embedded in a integration, and can't find related answer in this forum. This is the function I want to fit !( *SubsuperscriptBox[([Integral]), (w), (R)](c* SuperscriptBox[(x), (-p)] FractionBox[(x), SqrtBox[( *SuperscriptBox[(x), (2)] - *SuperscriptBox[(w), (2)])]] [DifferentialD]x)) w is variable, R is a parameter, and c, p is parameters should be fitted. I can't find a way to simplified the power law to log form so that can't avoid the trouble while fit the power law. Lynn === Subject: Problem: is not a list of numbers with dimensions When run the below code, A=1*10^(-4); k=2/3; g=1.12*10^(-11); Attenuation= 0.23026*0.475*10^(-3); L=7200; Leff=(1-exp[-Attenuation*L])/Attenuation; FindRoot[x-A*exp[k*g*x*Leff-Attenuation*L],{x,0}] It executes the below solution, FindRoot::nlnum: The function value {0.-0.0001 exp[-0.787489+0. (1.+Times[<<2>>])]} is not a list of numbers with dimensions {1} at {x} = {0.}. I need your help about numerical and Alpha_numeric solution of this problem. f(x)= x-A*exp[k*g*x*Leff-Attenuation*L Serdar === Subject: Re: locator snap > > In the example below the locator can be moved to any position in the > graphic. > Can the locator be made to snap to multiples of say 0.1? > > Manipulate[Column@{Graphics[{}, Axes -> True], p}, {{p, {0, 0}}, > Locator}] > > > Maarten Manipulate[ p = Round[p, .1]; Column@{Graphics[{}, Axes -> True], p}, {{p, {0, 0}}, Locator}] Joe === Subject: Hash Table for self avoiding random walks Executive Summary: Can I make a bunch of things that work like hash tables without polluting the global scope? Long winded Version: I've been playing around with self avoiding random walks. Generating them efficiently requires a fast way of checking whether a given step will intersect the set of previous steps, which is generally a sparse subset of the underlying lattice. Using a list of the previous steps isn't so great because searching it for collisions is order the size of the list. Using an array isn't so great because it has predefined boundaries and because, as the dimensionality increases, the size of the array goes like (side length)^dimensions. I think the ideal data structure is a hash table. It takes constant time to add new elements and constant time to check if a trial step collides with a previous step, and there are no predefined boundaries. But it seems Mathematica doesn't have a true hash table. SparseArray doesn't qualify because it wraps negative values and complains if you look for something outside the boundaries. Dispatch doesn't qualify because (as far as I know) there's no way to add new rules to an already created DispatchTables. Daniel Lichtblau: http://library.wolfram.com/infocenter/Conferences/321/ , which shows how downvalues can be used in a similar way to hash still the state of the art. The idea is simple. If I have a walk that took steps {{1,1},{1,2}, {2,2}} then I make a function h: h[{1,1}] = True; h[{1,2}] = True; h[{2,2}] = True; My primary complaint with this technique is that it seems to require giving your hash table a name with global scope. What if I want to make 100 different walks? Do I have to give them all separate names? I guess I could do something like h[10][1,1] = True;, but then I always have to keep track of which walk I'm working on. I'd rather just be able to let them all be anonymous and stick them in a list. Any ideas? Here's my current best effort: neighborhood[n_] := With[{seed = ReplacePart[ConstantArray[0, n], 1 -> 1]}, Join[Permutations[seed], Permutations[-seed]]] availableSteps[{points_, visitedFunction_}] := With[{steps = (Last[points] + #) & /@ neighborhood[Dimensions[points][[2]]]}, Select[steps, visitedFunction[#] =!= True &]] takeStep[{points_, visitedFunction_}] := With[{newStep = RandomChoice[availableSteps[{points, visitedFunction}]]}, visitedFunction[Last[points]] = True; {Append[points, newStep], visitedFunction}] Clear[trail]; {points, trail} = NestWhile[ takeStep, {{{0, 0, 0}}, trail}, (Length[availableSteps[#]] > 0) &]; The part that I really don't like is the Clear[trail] part. As an aside, although there is no documentation for HashTable, doing FullForm[Dispatch[Table[n -> 1, {n, 4}]]] gives Dispatch[List[Rule[1,1],Rule[2,1],Rule[3,1],Rule[4,1]],List[HashTable[1,4,1, List[List[1,2,3],List[],List[4]]]]] Is the feature set I want just hiding? JM === Subject: Re: function to check if array is empty > > is there a function that will check if an array is empty? > i'm looking for a function to return either True (or 1), or False (or > 0) when it checks an array. eg: > X = Array[0 &, {3, 3}] > > then test with function (called ArrayEmpty, for example) > > In: ArrayEmpty[X] > > Out: True >> >> If you deal only with m x n rectangular arrays (matrices) you could use >> >> ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] >> >> A more general function would be >> >> ArrayEmptyQ[arr_List] := >> If[Count[arr, x_ /; x != 0, -1] != 0, False, True] >> >> For instance, >> >> X = Array[0 &, {3, 3}] >> ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] >> ArrayEmptyQ[X] >> X[[1, 2]] = 1; >> X >> ArrayEmptyQ[X] >> >> {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} >> >> True >> >> {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}} >> >> False If speed is important, using *Total* and *Unitize* (to prevent > faster than the above solution. In[1]:= X = Array[0 &, {3, 3}] > ArrayEmptyQ[arr_List] := Total[Unitize[arr], Infinity] == 0 > ArrayEmptyQ[X] > X[[1, 2]] = 1; X[[1, 3]] = -1; > X > ArrayEmptyQ[X] > X = Array[0 &, {1000, 1000}]; > Timing@ArrayEmptyQ[X] Out[1]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} Out[3]= True Out[5]= {{0, 1, -1}, {0, 0, 0}, {0, 0, 0}} Out[6]= False Out[8]= {0.015834, True} In[9]:= Total[X, -1] == 0 Out[9]= True In[10]:= X = Array[0 &, {3, 3}] > ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] > ArrayEmptyQ[X] > X[[1, 2]] = 1; X[[1, 3]] = -1; > X > ArrayEmptyQ[X] > X = Array[0 &, {1000, 1000}]; > Timing@ArrayEmptyQ[X] Out[10]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} Out[12]= True Out[14]= {{0, 1, -1}, {0, 0, 0}, {0, 0, 0}} Out[15]= False Out[17]= {0.714124, True} Of course, if we know before hand that the list is made of non-negative elements only (or non-positive only), we can discard the *Unitize* function, so the resulting function is faster. In[1]:= X = Array[0 &, {3, 3}] ArrayEmptyQ[arr_List] := Total[arr, -1] == 0 ArrayEmptyQ[X] X[[1, 2]] = 1; X[[1, 3]] = -1; X ArrayEmptyQ[X] X = Array[0 &, {1000, 1000}]; Timing@ArrayEmptyQ[X] Out[1]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} Out[3]= True Out[5]= {{0, 1, -1}, {0, 0, 0}, {0, 0, 0}} Out[6]= True Out[8]= {0.009338, True} -- Jean-Marc === Subject: Re: function to check if array is empty > > > > > > is there a function that will check if an array is empty? > > i'm looking for a function to return either True (or 1), or False (or 0) > when it checks an array. eg: > > X = Array[0 &, {3, 3}] > > then test with function (called ArrayEmpty, for example) > > In: ArrayEmpty[X] > > Out: True > > > If you deal only with m x n rectangular arrays (matrices) you could use > > ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] > > A more general function would be > > ArrayEmptyQ[arr_List] := > If[Count[arr, x_ /; x != 0, -1] != 0, False, True] > > For instance, > > X = Array[0 &, {3, 3}] > ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] > ArrayEmptyQ[X] > X[[1, 2]] = 1; > X > ArrayEmptyQ[X] > > {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} > > True > > {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}} > > False > > > Tally provides a very fast way to test for any non-zero elements. It is > faster than the solutions above except in where there are non-zero elements > very close to the beginning of the array. Hi Joe, Nice approach. The code you posted, however, contains a small typo. I have provided a fix; see below. > Test Data > > array1=ConstantArray[0,{1000,1000}]; > array2=DiagonalMatrix[Table[1,{1000}]]; > array3=ConstantArray[0,{1000,1000}]; > array3[[1000,1000]]=1; > > Tally-based solution > ------------------------------------------------------------------^^^------- --------------------^^^ An additional pair of parentheses is required here to mach the structure of the result returned by Tally. > In[24]:= Timing[ZeroMatrixQ[#]]&/@{array1,array2,array3} > Out[24]= {{0.008125,True},{0.006914,False},{0.008563,True}} ---------------------------------------------------------------------------- -------^^^^^ Error: should be false. See below for the explanation and a fix. > MatrixQ-based solution > > Function[array, Timing[MatrixQ[array, ((# == 0) &)]]] /@ {array1, array2, > array3} > > In[29]:= > Function[array,Timing[MatrixQ[array,((#==0)&)]]]/@{array1,array2,array3} > Out[29]= {{0.857164,True},{0.000012,False},{0.866723,False}} In[1]:= array1 = ConstantArray[0, {1000, 1000}]; array2 = DiagonalMatrix[Table[1, {1000}]]; array3 = ConstantArray[0, {1000, 1000}]; array3[[1000, 1000]] = 1; Tally[Flatten@#] & /@ {array1, array2, array3} (*Note that Tally returns *a list of list* even if there is only one kind element that is counted. So, for a list that contains only zeros, say ten, Tally will return {{0,10}} rather than {0,10}*) Timing[ZeroMatrixQ[#]] & /@ {array1, array2, array3} (*It even faster than the solution with Total Unitize*) Function[array, Timing[Total[Unitize[array], -1] == 0]] /@ {array1, array2, array3} Out[5]= {{{0, 1000000}}, {{1, 1000}, {0, 999000}}, {{0, 999999}, {1, 1}}} Out[7]= {{0.004968, True}, {0.004939, False}, {0.005611, False}} Out[8]= {{0.016013, True}, {0.016292, False}, {0.016105, False}} -- Jean-Marc === Subject: Re: function to check if array is empty > is there a function that will check if an array is empty? >> i'm looking for a function to return either True (or 1), or False (or >> 0) when it checks an array. eg: >> X = Array[0 &, {3, 3}] >> >> then test with function (called ArrayEmpty, for example) >> >> In: ArrayEmpty[X] >> >> Out: True If you deal only with m x n rectangular arrays (matrices) you could use ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] A more general function would be ArrayEmptyQ[arr_List] := > If[Count[arr, x_ /; x != 0, -1] != 0, False, True] For instance, X = Array[0 &, {3, 3}] > ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] > ArrayEmptyQ[X] > X[[1, 2]] = 1; > X > ArrayEmptyQ[X] {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} True {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}} False If speed is important, using *Total* and *Unitize* (to prevent faster than the above solution. In[1]:= X = Array[0 &, {3, 3}] ArrayEmptyQ[arr_List] := Total[Unitize[arr], Infinity] == 0 ArrayEmptyQ[X] X[[1, 2]] = 1; X[[1, 3]] = -1; X ArrayEmptyQ[X] X = Array[0 &, {1000, 1000}]; Timing@ArrayEmptyQ[X] Out[1]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} Out[3]= True Out[5]= {{0, 1, -1}, {0, 0, 0}, {0, 0, 0}} Out[6]= False Out[8]= {0.015834, True} In[9]:= Total[X, -1] == 0 Out[9]= True In[10]:= X = Array[0 &, {3, 3}] ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] ArrayEmptyQ[X] X[[1, 2]] = 1; X[[1, 3]] = -1; X ArrayEmptyQ[X] X = Array[0 &, {1000, 1000}]; Timing@ArrayEmptyQ[X] Out[10]= {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} Out[12]= True Out[14]= {{0, 1, -1}, {0, 0, 0}, {0, 0, 0}} Out[15]= False Out[17]= {0.714124, True} -- Jean-Marc === Subject: Re: function to check if array is empty > >> is there a function that will check if an array is empty? >> >> i'm looking for a function to return either True (or 1), or False >> (or 0) when it checks an array. eg: >> >> X = Array[0 &, {3, 3}] >> >> then test with function (called ArrayEmpty, for example) >> >> In: ArrayEmpty[X] >> >> Out: True > > If you deal only with m x n rectangular arrays (matrices) you could > use > > ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] > > A more general function would be > > ArrayEmptyQ[arr_List] := > If[Count[arr, x_ /; x != 0, -1] != 0, False, True] > > For instance, > > X = Array[0 &, {3, 3}] > ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] > ArrayEmptyQ[X] > X[[1, 2]] = 1; > X > ArrayEmptyQ[X] > > {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} > > True > > {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}} > > False Tally provides a very fast way to test for any non-zero elements. It is faster than the solutions above except in where there are non-zero elements very close to the beginning of the array. Test Data array1=ConstantArray[0,{1000,1000}]; array2=DiagonalMatrix[Table[1,{1000}]]; array3=ConstantArray[0,{1000,1000}]; array3[[1000,1000]]=1; Tally-based solution In[24]:= Timing[ZeroMatrixQ[#]]&/@{array1,array2,array3} Out[24]= {{0.008125,True},{0.006914,False},{0.008563,True}} MatrixQ-based solution Function[array, Timing[MatrixQ[array, ((# == 0) &)]]] /@ {array1, array2, array3} In[29]:= Function[array,Timing[MatrixQ[array,((#==0)&)]]]/ @{array1,array2,array3} Out[29]= {{0.857164,True},{0.000012,False},{0.866723,False}} Joe === Subject: Re: Getting the size of the bounding box of a Graphics3D[] no that is a bug. Jens > Is there a reliable way to get the coordinates and size of the bounding= > box of a Graphics3D object? > > I tried > > PlotRange /. AbsoluteOptions[Graphics3D[Sphere[]]] > > but it gives {{0., 1.}, {0., 1.}, {0., 1.}}, whereas the correct answer= > should be {{-1., 1.}, {-1., 1.}, {-1., 1.}}. > === Subject: Re: Getting the size of the bounding box of a Graphics3D[] I think it's a bug for Sphere. It works for other things. plot1 = ParametricPlot3D[{Sin[u], Sin[u], Cos[u]} {Cos[v], Sin[v], 1}, {u, 0, Pi}, {v, 0, 2 Pi}] PlotRange /. AbsoluteOptions[plot1] {{-1., 1.}, {-1., 1.}, {-1., 1.}} -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > > Is there a reliable way to get the coordinates and size of the bounding > box of a Graphics3D object? > > I tried > > PlotRange /. AbsoluteOptions[Graphics3D[Sphere[]]] > > but it gives {{0., 1.}, {0., 1.}, {0., 1.}}, whereas the correct answer > should be {{-1., 1.}, {-1., 1.}, {-1., 1.}}. > === Subject: Re: DSolve Issues Use exact numbers Clear[Phi]; eqn1 = Phi''[r] + 2*r^(-1) Phi'[r] + 104479/1000000*Phi[r] == 0; soln1 = DSolve[{eqn1, Phi[0] == K}, Phi[r], r][[1]] // FullSimplify {Phi[r] -> (1000*K*Sin[(Sqrt[104479]*r)/ 1000])/(Sqrt[104479]*r)} eqn1 /. NestList[D[#, r] &, soln1[[1]], 2] // Simplify True Limit[soln1[[1, 2]], r -> 0] K bc1 = soln1[[1, 2]] /. r -> 3 R; bc2 = D[soln1[[1, 2]], r] /. r -> 3 R // Simplify; eqn2 = Phi''[r] + 2*Phi'[r]/r - 2831/100*Phi[r] == 0; soln2 = DSolve[{eqn2, Phi[3 R] == bc1, Phi'[3 R] == bc2}, Phi[r], r][[1]] // ExpToTrig // FullSimplify {Phi[r] -> (1000*K*Cosh[(1/10)*Sqrt[2831]* (r - 3*R)]* Sin[(3*Sqrt[104479]*R)/1000])/ (Sqrt[104479]*r) + (10*K*Cos[(3*Sqrt[104479]*R)/1000]* Sinh[(1/10)*Sqrt[2831]* (r - 3*R)])/(Sqrt[2831]*r)} eqn2 /. NestList[D[#, r] &, soln2[[1]], 2] // Simplify True (soln2[[1, 2]] /. r -> 3 R) == bc1 True (D[soln2[[1, 2]], r] /. r -> 3 R) == bc2 // Simplify True solnR = Simplify[Reduce[bc1 == 0, R], {K != 0, R > 0, C[1] == 1}][[1]] // ToRules {R -> (2000*Pi)/(3*Sqrt[104479])} soln2[[1, 2]] /. solnR (10*K*Sinh[(1/10)*Sqrt[2831]* (r - (2000*Pi)/Sqrt[104479])])/ (Sqrt[2831]*r) Bob Hanlon > I am solving the following Differential Equation Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ > 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( > 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ > 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) all divided by r. My problem is that Mathematica is not treating those zeros.... as > well zeros. Thus, the solution cannot really be used. In fact, if I > manually reproduce the solution and remove those zeros, then the > solution is fine. I have another similar ODE Anyone have any ideas. Phi''[r]+2*r^(-1)Phi'[r]- 287.31*Phi[r]==0 and Phi[3R]==0(some > constant) ; kinda has a cosh/sinh solution As you might have notice I need to match these two solutions and their > derivatives at some point. The ratio of which gives me what I desire > the value of R. Yet, Mathematica treats those zeros as something else. > === Subject: Re: crosshatch shading Illustrator is a much more robust tool for polishing vector-based graphics. Plus, you don't have to deal with the non-standard data formats that MS uses for their graphs. There may be free or low-cost alternatives to Illustrator. Anything that can save graphics as PDF or postscript has got to be better than Excel. george >> I am preparing a graph for publication. I have been able to shade >> various areas in the graph different colors using the Filling option. >> However, for publication the paper will be in black and white. I >> would >> like to change the shaded areas to be filled in with crosshatches, >> parallel lines, etc. What are the options and commands to do this? I >> have looked online, but have not found an answer. >> >> >> > had this problem in the past, regretfully found no such capability. > gradient shading also not to be found. For bar charts, etc. > I transferred the data back to Excel. > === Subject: StringMatchQ and Regular Expressions Hi I'm running Mathematica v6.0.2 on Windows XP. I define a regex thus: doStmt = RegularExpression[do(?=s*w+=)]; and then execute: StringCases[doindex= , doStmt] which brings the response {do} I then execute StringMatchQ[doindex= , doStmt] which brings the response False I had expected that if StringCases found any cases, then StringMatchQ would return True. Obviously this is not the case, but can anyone out there throw light upon this. Mark Westwood === Subject: Fit data with range Hi I want to fit a polynomial function to a set of data, only between say xmin to xmax. How can I do that? I know only how to fit the whole range. For example: data = ReadList[file.dat,{Number,Number}]; fit = Fit[data,{1,x,x^2},x] Plot[fit,{x,0,10}] === Subject: Re: Convert funcion > > > Hello Jeam Marc, > > > Yes I download the package, but I could not find where that function > located. I also try search on my mechine, but still could not find it. > If you have experience how to find it please let me know. > > > Johum > > > I do not know (and I do not bother to know) how to write such a > function since the function has already been implemented (nicely) in > the IMS (IMTEK Mathematica Supplement) package, which is an *open > source* package. *Open source* means that the source code is available > free of charge. > > Therefore, if I were you, I would download the IMS package, install it > on my machine, then I would play around with the function *ExactCover* > to get acquainted with it (the documentation have some examples about > Latin squares) and I would look at its code (which is provided with > package) if I wish. > > The IMS main web page contains links to the download area as well as > directions to install the package. > > http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/ I do not have the IMS package installed on the machine I am working. However, since the function *ExactCover* is loaded into a Mathematica that the code resides in its own package within a directory called Imtek. So, after a successful installation, look for a directory called Imtek. Within this directory, look for a file called ExactCover.m (the package) and possibly a file called ExactCover.nb (a notebook that is used to build the package). If you cannot find any of these files, that means that the IMS packages are not correctly installed or, at least, not fully installed. -- Jean-Marc === Subject: ExtraAxes for Plot[] once again due to some formatting troubles when posting. Any comments wellcome. (* pacakgae code *) BeginPackage[ExtraAxes`] TickStep},{InsertStartPos,InsertEndPos},YInsertPos]<>n<> step TickStep.<>n<> tThe additional Axes is inserted from x: InsertStartPos to InsertEndPos at y: YInsertPos.<>n<> tOptions can be passed e.g. TicksStyle [Rule]Directive[{Blue,Thick}]<>n <> tInclude the additional Axes by means of Epilog->ExtraXAxes[] TickStep},{InsertStartPos,InsertEndPos},XInsertPos]<>n<> step TickStep.<>n<> tThe additional Axes is inserted from y: InsertStartPos to InsertEndPos at x: XInsertPos.<>n<> tOptions can be passed e.g. TicksStyle [Rule]Directive[{Blue,Thick}]<>n <> tInclude the additional Axes by means of Epilog->ExtraYAxes[] Begin[`Private`] ExtraXAxes[{from_,to_,step_},{xpos_,xend_},ypos_,opts_:{}]:= Graphics[{},AspectRatio->Full,ImagePadding->0,Axes- >{True,False},Sequence@ opts, PlotRange->{{from-1/2 step,to+1/2 step},0{-1,1}},Ticks->{Table[i,{i,from,to,step}],None}]//Inset[#, {xpos,ypos},{ from,0},((step (xend-xpos))/(to-from)+xend-xpos){1,1}]& ExtraYAxes[{from_,to_,step_},{ypos_,yend_},xpos_,opts_:{}]:= Graphics[{},AspectRatio->Full,ImagePadding->0,Axes- >{False,True},Sequence@ opts, PlotRange->{0{-1,1},{from-1/2 step,to+1/2 step}},Ticks->{None,Table[i,{i,from,to,step}]}]//Inset[#,{xpos,ypos}, {0,from}, ((step (yend-ypos))/(to-from)+yend-ypos){1,1}]& End[] EndPackage[] (* sample code *) Plot[{Sin[x], 2 + Cos[x]}, {x, 0 [Pi], 3 [Pi]}, PlotRange -> All, PlotStyle -> {Black, Blue}, Epilog -> {ExtraXAxes[{1/2 [Pi], 3/2 [Pi], [Pi]/8}, {1/2 [Pi], 3/2 [Pi]}, 2, TicksStyle -> Directive[Darker@Magenta, Italic, Bold]], ExtraYAxes[{-150, 350, 50}, {-1.5, 3.5}, 8, {TicksStyle -> Directive[Blue, Large], AxesStyle -> Directive[Orange, Thick]}]} ] === Subject: Re: Convert funcion I am trying to work with this function but it dose not work, if someone could give me a hand! fConver[cmatrix], this function will find all subsets of rows of the rectangular matrix which have exactly one nonzero element in each column. For example: cmatrix=({{0,0,1,0,1,1,0},{1,0,0,1,0,0,1},{0,1,1,0,0,1,0}, {1,0,0,1,0,0,0},{0,1,0,0,0,0,1},{0,0,0,1,1,0,1}}); fConvert[cmatrix] the out put will be {{{1,4},{3,5,6},{2,7}}} Johum S. === Subject: Re: Bilateral cell problem w/ Manipulate Apologies for the length of this post! Grid, Row, Column, and the like work great for manual layout in a notebook, but they don't work well for programmatic interactions with a notebook, as far as I can tell. One of the advantages of the Make Bilateral Cells palette is that one can transform an entire subset of cells in a notebook into bilateral cells by clicking a button (and then undo it, by clicking another button). If one had to manually layout the bilateral cells (and then suppress the code used to generate them) it would be too tedious to bother with. Here's an example of what I mean when I say that Row, Column, and Grid don't work well for this kind of manipulation. The natural construct to try for laying out a bilateral cell is the following: Row[{ Cell[This is a caption., MathCaption], Column[{ Cell[BoxData[RowBox[{1, +, 1}]], Input], Cell[BoxData[2], Output] }] }] Evaluating that just gives the textual representations of the cells, prefixed by Out[n]=. If you put the Row[{...}] expression inside CellPrint[ ], you still get the textual representation of the cells, rather than the displayed form of the cell... but at least we no longer get the Out[n]= label. Ok. Suppose we put a DisplayForm@ in front of the three Cell heads, so that it looks like this: CellPrint[ Row[{ DisplayForm@Cell[This is a caption., MathCaption], Column[{ DisplayForm@ Cell[BoxData[RowBox[{1, +, 1}]], Input], DisplayForm@ Cell[BoxData[2], Output] }] }] ] That sort of works, but it requires us to evaluate the expression manually inside an input cell. It also doesn't preserve the formatting ÷ the MathCaption cell appears with a Courier font, rather than Times, on my machine. Moreover, in order to make bilateral cells programmatically, we would need to be able to use it with NotebookWrite. But the following gives an error: NotebookWrite[InputNotebook[], Row[{ DisplayForm@Cell[This is a caption., MathCaption], Column[{ DisplayForm@Cell[BoxData[RowBox[{1, +, 1}]], Input], DisplayForm@Cell[BoxData[2], Output] }] }], After ] If you put a CellPrint@ before the Row, it does write the cell into preserve the formatting of the MathCaption. The fundamental problem is that NotebookWrite breaks dynamic objects, and so can't be used with arbitrary cells. The following inserts a broken cell into the notebook: NotebookWrite[InputNotebook[], Manipulate[Plot[Sin[a x], {x, 0, 10}], {a, 1, 10}], After ] Moreover, you still get an error if you try the following: 1. Evaluate the above Manipulate[...]. 2. Get the raw cell expression using Show Expression, and copy it to the clipboard. 3. In another input cell, define the variable c1 to equal that raw cell expression (it's long). 4. Evaluate NotebookWrite[InputNotebook[], c1, After] However, in this case CellPrint[ c1 ] does give you a functioning Manipulate cell! So, CellPrint works with Dynamic objects but NotebookWrite doesn't. Jason >> Although AuthorTools is considered legacy code for Mathematica 6, >> I've still been using the bilateral cells palette because I don't >> know = > >> of any other better alternative. Although it still works well, I've >> found that it sometimes breaks =97 but sometimes not =97 when using >> Manipulate, and I don't know why. > > You might consider trying the new Grid, Row, Column, and GraphicsGrid, > GraphicsRow, GraphicsColumn instead of the bilateral cells. > > -- > Helen Read > University of Vermont > -- Dr J. McKenzie Alexander Department of Philosophy, Logic and Scientific Method London School of Economics and Political Science Houghton Street, London WC2A 2AE Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm === Subject: Problem/bug with ends of thick lines in graphics In a quick search of things I haven't found a mention of the following simple graphics issue and I'm checking in with the group to see if there is a memory of its mention and if there is a simple fix (and which is not a complicated hack) that I've not been able to come up with. Consider the following graph: Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, PlotStyle -> {AbsoluteThickness[20]}] When you plot it you will see that the line's ends are not rectangular, whereas you would certainly want them to be so. (An alternative would be to have them be rounded, for example, but the question will remain the same whatever your preference is.) Rather they appear as polygonal in a way inconsistent with the line itself. One assums that this is an artifact of how the line is rendered based on the individual line segments, and that that segmental rendering has to do something with how a segment relates to the segments on either side of it. The lack of a segment beyond the end segment presumably runes the algorithm for rendering in a way that leads to this appearance. I have two related questions here. The first is how, if at all possible, to fix this in a general way through some specific options settings for the graphics function. The second is how, when exporting this graphic as, say, a PDF, to make it behave properly. There was a trick in pre version-6 Mathematica that would involve adding an explicit postscript command to the PlotStyle option. Though this would not (I think) correct the screen appearance of the graphic, it would properly fix it when the graphic was exported to PDF or EPS. Here is an example of how it was done: Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, PlotStyle -> {{ PostScript[0 setlinecap],AbsoluteThickness[20]}}] This, however, no longer works in Mathematica 6+ presumably because of the new way that graphics rendering is handled. Does anyone have any solutions to either or both of these issues? --David === Subject: Identical elements I have a list and i need to test whether all the elements in the list are identical or no. What is the efficient way to do that? The output should be true if all elements are the same and False otherwise. One line command is preferred if possible. Your help is highly appreciated. HMQ === Subject: Options group I think there are at least two ways for dealing with options given in the form of rules. (1) The current (documented) method for using options is to use OptionValue, so given a list of options for a function f[x_, opts:OptionsPattern[]] ; Options[f]={ optA-> A0, optB->B0, ....} and using f[x, optA->a] see function new below then within f the actual values {a,b,...} for the options can be given by {a, b, ...} = OptionValue[#] & /@ {optA, optB, ...}; This is probably an improvement over the previous methods, (2) {a, b, ...} = {optA, optB, ...} /. {opts} /. Options[f] where fis defined as f[x_, opts : ___] see function old below or the undocumented variant {a, b,...} = {optA, optB, ...} /. Flatten[{opts, Options[g]}]; with f[x_, opts : ___?OptionQ] see function old2 below However I'm looking for advice on how to deal with more general options of the form optC->{C0,optD->D0} such as for example NMinimize[{Sin[x] + .5 x, -10 <= x <= 10}, {x}, Method -> {RandomSearch, PostProcess -> InteriorPoint}] I'd like to see some example code demonstrating how such options are parsed. When an option such as this is passed to new,old & old2 below it appears OptionValue and the other methods cannot be used to pick out these interior options automatically so I assume further parsing is required but am wondering if there are already standard ways of doing this. I considered something like FlattenRules[rules : OptionsPattern[]] := Flatten[ rules //. { (a_ -> {m : (_ -> _) ..}) -> m, (a_ -> {x_, m : (_ -> _) ..}) -> {a -> x, m} } ] used in the function test below, but this is not very general. I ask this because I've recently converted an implementation of Shor minimization, SolvOpt (The original author has provided Fortran,C& other code at http://www.uni-graz.at/imawww/kuntsevich/solvopt/ ) to Mathematica. I want to make this version publicly available but i like to give it a Mathematica look and feel first. Currently the options are passed via an array of real values in the style of C/Fortran but I'd like to make it behave in a similar way to NMinimize. Tom McDermott In[2]:= Options[new] = Options[old] = Options[old2] = Options[test] = {optA -> A0, optB -> B0, optC -> {C0, optD -> D0}} Out[2]= {optA -> A0, optB -> B0, optC -> {C0, optD -> D0}} In[3]:= FlattenRules[rules : OptionsPattern[]] := Flatten[ rules //. { (a_ -> {m : (_ -> _) ..}) -> m, (a_ -> {x_, m : (_ -> _) ..}) -> {a -> x, m} } ] In[4]:= FlattenRules[{optA -> A0, optB -> {B0, B1}, optC -> {optD -> D0, optE -> eeee}, optC -> {D0, optE -> eeee}}] Out[4]= {optA -> A0, optB -> {B0, B1}, optD -> D0, optE -> eeee, optC -> D0, optE -> eeee} In[5]:= new[x_, opts : OptionsPattern[]] := Module[{a, b, c, d}, {a, b, c, d} = OptionValue[#] & /@ {optA, optB, optC, optD}; Print[{a,b,c,d}=, {a, b, c, d}]; Print[opts = , opts]; ] In[6]:= old[x_, opts : ___] := Module[{a, b, c, d}, {a, b, c, d} = {optA, optB, optC, optD} /. {opts} /. Options[old]; Print[{a,b,c,d}=, {a, b, c, d}]; Print[opts = , opts]; ] In[7]:= old2[x_, opts : ___?OptionQ] := Module[{a, b, c, d}, {a, b, c, d} = {optA, optB, optC, optD} /. Flatten[{opts, Options[old2]}]; Print[{a,b,c,d}=, {a, b, c, d}]; Print[opts = , opts]; Print[Flatten[{opts,Options[old2]}] = , Flatten[{opts, Options[old2]}]]; ] In[8]:= test[x_, opts : ___?OptionQ] := Module[{a, b, c, d}, {a, b, c, d} = {optA, optB, optC, optD} /. FlattenRules[{opts, Options[test]}]; Print[{a,b,c,d}=, {a, b, c, d}]; Print[opts = , opts]; Print[ Flatten[{opts,Options[test]}] = , Flatten[{opts, Options[test]}]]; Print[FlattenRules[{opts,Options[test]}] = , FlattenRules[{opts, Options[test]}]]; ] In[9]:= new[x, optA -> aaa, optC -> {ccc, optD -> ddd}] During evaluation of In[9]:= OptionValue::optnf: Option name optD not found in defaults for new. >> During evaluation of In[9]:= {a,b,c,d}={aaa,B0,{ccc,optD->ddd},optD} During evaluation of In[9]:= opts = optA->aaaoptC->{ccc,optD->ddd} In[10]:= old[x, A -> aaa, C -> {ccc, D -> ddd}] During evaluation of In[10]:= {a,b,c,d}={A0,B0,{C0,optD->D0},optD} During evaluation of In[10]:= opts = A->aaaC->{ccc,D->ddd} In[11]:= old2[x, optA -> aaa, optC -> {ccc, optD -> ddd}] During evaluation of In[11]:= {a,b,c,d}={aaa,B0,{ccc,optD->ddd},optD} During evaluation of In[11]:= opts = optA->aaaoptC->{ccc,optD->ddd} During evaluation of In[11]:= Flatten[{opts,Options[old2]}] = {optA->aaa,optC->{ccc,optD->ddd},optA->A0,optB->B0,optC->{C0,optD- >D0} } In[12]:= test[x, optA -> aaa, optC -> {ccc, optD -> ddd}] During evaluation of In[12]:= {a,b,c,d}={aaa,B0,ccc,ddd} During evaluation of In[12]:= opts = optA->aaaoptC->{ccc,optD->ddd} During evaluation of In[12]:= Flatten[{opts,Options[test]}] = {optA->aaa,optC->{ccc,optD->ddd},optA->A0,optB->B0,optC->{C0,optD- >D0} } During evaluation of In[12]:= FlattenRules[{opts,Options[test]}] = {optA->aaa,optC->ccc,optD->ddd,optA->A0,optB->B0,optC->C0,optD->D0} === Subject: Re: partial differential equation of diffusion >>When I put my equation as D[M[r, t], t] == a*(D[M[r, t], r, r] + >>(2/r)*D[M[r, t], r]) - k*M[r, t] in to mathematica >and initial and boundary condition as M[r, 0] == M0, D[M[0, t], t] == 0, >M[R, t] == Ms >It can not solve. The mathematica notebook is given in attachment. > dM/d t =a[d^2 M//dr^2 +(2/r) (dM/dr)]-kM >> The differentials are partial differentials. >> a and k are constants. > >> > Do you mean that you do not know how to multiply expressions with > Mathematica? If this is the case you should familiarize yourself with > the basis of Mathematica syntax, this will really help you and be a > time saver in the future. > > D[M[r, t], t] == > a*(D[M[r, t], r, r] + (2/r)*D[M[r, t], r]) - k*M[r, t] > >> >> >> ÌöÄÄr.GÌ.a6r. Ali YILDIRIM >> Gaziantep Ì[Thorn]niversitesi >> Nizip Meslek YÌ.b9ksekokulu >> Gıda Teknolojisi Programı >> 27700-Nizip-Gaziantep/TÌ.b9rkiye >> ayildirim@gantep.edu.tr >> -----------!!!----!!!! >> Not sure for what this D stands here. I discarded it in the example >> below. Also you have a spurious backslash. So you could write your >> equation as >> >> D[M[r, t], t] == D[M[r, t], r, r] + 2/r D[M[r, t], r] - k M[r, t] >> > Boundary conditions are: > > 1-) at t=0, M= Mo >> >> M[r, 0] == M0 >> > 2-) r = 0, dM/dr=0 >> >> D[M[0, t], t] == 0 >> > 3-) at r = R, M = Ms >> >> M[R, t] == Ms >> >> Then you can use DSolve or NDSolve as in >> >> DSolve[{D[M[r, t], t] == >> D[M[r, t], r, r] + 2/r D[M[r, t], r] - k M[r, t], M[r, 0] == M0, >> D[M[0, t], t] == 0, M[R, t] == Ms}, M, {r, t}] >> >> >> >> > > > -- Jean-Marc > === Subject: can't translate 3D model to 0,0,0 I have a problem with translating some 3D models to 0,0,0. I have been using the following code: ma = Mean@a; ac = # + ({0, 0, 0} - ma) & /@ a; where a is a 3D model made up of many 3D coordinates. However, this code does not work - in that the new centroid (mean) of the model is not at 0,0,0. can anyone suggest an alternative method? best wishes, Will === Subject: orthonormal eigenvectors I have a 3X3 matrix M: {1,-i(2^(1/2)),0} {i(2^(1/2)),0,0} {0,0,2} And I am trying to find a set of orthonormal eigenvectors for M. If anyone can help, I would greatly appreciate it. Brian === Subject: Re: list of dates >convert them to a decimal value, so 1963-01-01 goes to 63.0 and >1985-07-01 goes roughly to 85.5. >Any suggestions on the best way to do this? In[1]:= << Units` yearSeconds = First@SI[1 Year] Out[2]= 31536000 In[3]:= fractionalYear[dateString_] := Mod[AbsoluteTime@dateString, yearSeconds]/yearSeconds In[4]:= (ToExpression[StringTake[#, {3, 4}]] + fractionalYear[#]) &@ 1963-01-01 // N Out[4]= 63.0411 In[5]:= (ToExpression[StringTake[#, {3, 4}]] + fractionalYear[#]) &@ 1985-07-01 // N Out[5]= 85.5534 Season to taste === Subject: Re: function to check if array is empty >i'm looking for a function to return either True (or 1), or False >(or 0) when it checks an array. eg: >X = Array[0 &, {3, 3}] >then test with function (called ArrayEmpty, for example) >In: ArrayEmpty[X] >Out: True I would not consider an array where every element is zero an empty array. For a truly empty array emptyArrayQ[x_] := Flatten@x == {} for an array where every element is zero zeroArrayQ[ x_] := {} == (SparseArray[x] /. HoldPattern[SparseArray[_, _, _, {_, {_, a_}, b_}]] :> Flatten@{a, b}) === Subject: Re: Wolfram Workbench user experiences >I would be very interested in other people's experiences with the >Wolfram Workbench. I must admit that I prefer to use the frontend as >my 'IDE', and the workbench seemed fairly alien when I tried it. I briefly played with Wolfram Workbench. But I didn't see any significant advantage it had over using the frontend to develop code. So, like you, I stuck with using the frontend. === Subject: Re: Looping in Mathematica Packages.m >I know mathematica is a one line type software package but is there >a way of looping in a Package.m file. You can use % sign or %%% for >3 lines back but is there a way to go 3 lines back and execute all >the successive lines in a Package? You don't want to even consider using % and its kin to reference previous execution lines in a package file. That would lead to extremely unpredictable performance. If you did it, the executed line would vary according to when the package was loaded and when the function that made the reference was executed. Mathematica has a variety of methods for performing loops. Paste the following in to the Documentation Center search box for a basic description of loops and control structures. tutorial/LoopsAndControlStructures More information on programming found starting at guide/FunctionalProgramming or guide/ProceduralProgramming === Subject: MenuView inside Manipulate (1) Grid[{{MenuView[{1,2}],Graphics[Rectangle[{0,0}]]}}] (2) Manipulate[ Grid[{{MenuView[{1, 2}], Graphics[Rectangle[{0, 0}]]}}], {item, {0}}, ControlType -> None] (1) is a simple grid, and (2) simply embeds this grid in a dummy Manipulate (i.e., the control variable does not enter the first arg of the Manipulate, and the control is not explicitly displayed). When one clicks on the popup menu in (1), the rectangle remains visible. However, in (2), when one clicks on the popup menu, the rectangle disappears, and only reappears when the mouse button is released. Is this a bug? Does anyone know how one can keep the rectangle visible in (2) when one clicks on the popup menu. (If TabView is substituted for MenuView, the rectangle remains visible in both cases when a tab is clicked.) dkr === Subject: Re: Axes at the origin, for 3D plots/graphs > Does anyone know of a way to move the axes from the outside of the box > and have it centered at the origin instead? I know you can draw lines > using the graphics function to do this but it looks bad. I am looking > for something similar to how you can move the axes using AxisOrigin > for 2D plots. Out of the box, the equivalent to the 2D option *AxisOrigin* does not exist in 3D. *Axes origin for 3D Plots* http://forums.wolfram.com/mathgroup/archive/2005/Jun/msg00100.html You could write your own function. The following notebook might be help you started. *3D Axes* Sometimes in calculus, it is useful to see the x, y, and z axes in a 3D plot. This notebook illustrates a method for placing a coordinate axis set in the middle of a 3D plot as opposed to a bounding box. http://library.wolfram.com/infocenter/MathSource/528/ HTH, -- Jean-Marc === Subject: Re: Axes at the origin, for 3D plots/graphs the 3d axis would be hard to see when it is not along the bounding box, and in the most cases it would be hidden by the 3d objects. Jens Does anyone know of a way to move the axes from the outside of the box > and have it centered at the origin instead? I know you can draw lines > using the graphics function to do this but it looks bad. I am looking > for something similar to how you can move the axes using AxisOrigin > for 2D plots. === Subject: Re: DSolve Issues I can't see your code, so I have to guess what you wish to do. There is a difference between 0. and 0 And for good and useful reasons For your case: Rationalize[ 0.104479, .00001] (*is 7/67*) DSolve[Phi''[r] + 2*r^(-1) Phi'[r] + (7/67) Phi[r] == 0 , Phi[r], r] gives a useful solution Even more useful is DSolve[Phi''[r] + 2*r^(-1) Phi'[r] + ArbitraryConstant Phi[r] == 0 , Phi[r], r] > I am solving the following Differential Equation > > Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution > > Yet, Mathematica treats those zeros as something else. > Try this little experiment, it is very instructive for your zero conceptualization (observe the . in the output) matsym = {{1, 1}, {10^24, 10^24}} Det[matsym] matnum = {{1., 1}, {10^24, 10^24}} Det[matnum] matnumappx = {{1., 1}, {10^24 + 1, 10^24}} Det[matnumappx] matappxsym = {{1, 1}, {10^24 + 1, 10^24}} Det[matappxsym] -- W. Craig Carter === Subject: Re: DSolve Issues > I am solving the following Differential Equation > > Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution > > 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ > 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( > 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ > 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) > > all divided by r. > > My problem is that Mathematica is not treating those zeros.... as > well zeros. Thus, the solution cannot really be used. In fact, if I > manually reproduce the solution and remove those zeros, then the > solution is fine. > > I have another similar ODE Anyone have any ideas. > > Phi''[r]+2*r^(-1)Phi'[r]- 287.31*Phi[r]==0 and Phi[3R]==0(some > constant) ; kinda has a cosh/sinh solution > > As you might have notice I need to match these two solutions and their > derivatives at some point. The ratio of which gives me what I desire > the value of R. > > Yet, Mathematica treats those zeros as something else. I just wanted to add the latter ODE works out find and that I have another similar ODE Anyone have any ideas Should be Anyone have any ideas?? I have another similar ODE below that works fine === Subject: Re: DSolve Issues Clear[Phi] {Phi''[r] + 2*r^(-1) Phi'[r] + 0.104479*Phi[r] == 0 , Phi[0] == K} DSolve[%, Phi, r] Phi[r_] = First@(Phi[r] /. % // Chop) Limit[Phi[r], r -> 0] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >I am solving the following Differential Equation > > Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution > > 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ > 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( > 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ > 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) > > all divided by r. > > My problem is that Mathematica is not treating those zeros.... as > well zeros. Thus, the solution cannot really be used. In fact, if I > manually reproduce the solution and remove those zeros, then the > solution is fine. > > I have another similar ODE Anyone have any ideas. > > Phi''[r]+2*r^(-1)Phi'[r]- 287.31*Phi[r]==0 and Phi[3R]==0(some > constant) ; kinda has a cosh/sinh solution > > As you might have notice I need to match these two solutions and their > derivatives at some point. The ratio of which gives me what I desire > the value of R. > > Yet, Mathematica treats those zeros as something else. > > > === Subject: Re: DSolve Issues DSolve[{Phi''[r] + 2*r^(-1) Phi'[r] + 0.104479*Phi[r] == 0, Phi[0] == K}, Phi[r], r] // Chop ?? Jens > I am solving the following Differential Equation Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ > 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( > 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ > 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) all divided by r. My problem is that Mathematica is not treating those zeros.... as > well zeros. Thus, the solution cannot really be used. In fact, if I > manually reproduce the solution and remove those zeros, then the > solution is fine. I have another similar ODE Anyone have any ideas. Phi''[r]+2*r^(-1)Phi'[r]- 287.31*Phi[r]==0 and Phi[3R]==0(some > constant) ; kinda has a cosh/sinh solution As you might have notice I need to match these two solutions and their > derivatives at some point. The ratio of which gives me what I desire > the value of R. Yet, Mathematica treats those zeros as something else. > === Subject: Re: DSolve Issues > I am solving the following Differential Equation Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ > 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( > 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ > 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) all divided by r. My problem is that Mathematica is not treating those zeros.... as > well zeros. Thus, the solution cannot really be used. In fact, if I > manually reproduce the solution and remove those zeros, then the > solution is fine. Say your solution is called sol. You can get ride of the spurious zeros In[1]:= sol = 2.71828^(-0.323232 I r) ((0. + 0. I) + (0. + 0. I) 2.71828^(0.646465 I r) + (0. + 1.54687 I) K - (0. + 1.54687 I) 2.71828^(0.646465 I r) K) // Chop Out[1]= 0.646465 I r 1.54687 I K - 1.54687 I 2.71828 K --------------------------------------------- 0.323232 I r 2.71828 It would be better to use exact arithmetic as early as possible, either by entering exact numbers (e.g. 1.0 is not the same thing as 1 from a computational point of view since the underlaying computer representation is not the same at all) or using the built-in function *Rationalize[]*. *ExpToTrig[]*. For instance, In[2]:= ode = Rationalize[Phi''[r] + 2*r^(-1) Phi'[r] + 0.104479*Phi[r], 0]; sol = DSolve[{ode == 0, Phi[0] == K}, Phi, r] Phi[r] /. sol[[1]] // ExpToTrig Out[3]= 1/500 I Sqrt[104479] r 500 I (-1 + E ) K {{Phi -> Function[{r}, -(-----------------------------------------)]}} (I Sqrt[104479] r)/1000 E (Sqrt[104479] r) Out[4]= 1 Sqrt[104479] r Sqrt[104479] r -(-------------- (500 I K (Cos[--------------] - I Sin[--------------]) Sqrt[104479] r 1000 1000 Sqrt[104479] r Sqrt[104479] r (-1 + Cos[--------------] + I Sin[--------------]))) 500 500 > Yet, Mathematica treats those zeros as something else. No. It treats them as *inexact* numbers, which is fine since you are using inexact (aka *machine-size*) arithmetic. The following multimedia demo illustrates strikingly the difference between floating-point arithmetic and arbitrary/exact arithmetic. http://www.wolfram.com/technology/guide/precisiontracking.html -- Jean-Marc === Subject: Re: DSolve Issues The short answer is: Use Chop[] (look it up). The longer answer is that (imprecise) floating point numbers should not be used in symbolic calculations. Convert them to rationals using Rationalize[], or just use a parameter in their place. 0.0 is not the same as 0 in Mathematica. The latter is exactly zero, while the former is only known to be approximately zero (in you case, approx. to 15 digits). Mathematica keeps 0.0*x unevaluated because it is not sure that 0.0 is an exact zero. To convince you that using imprecise numbers with DSolve is a bad idea, here's a typical example of what might go wrong: Suppose that we solve an equation with floating point coefficients using Solve[]. Solve[] will substitute back the solutions into the equation and verify them. Because of accumulated numerical errors it might find that some of the solutions are not correct, and drop them. So Solve[] might not return all solutions if imprecise numbers were used in the equation. Another note: avoid named starting with capital letters. This way you'll never use a built-in name accidentally. For example, the symbol K that you used is a built-in symbol. > I am solving the following Differential Equation Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some > constant) ; kinda has a cos/sin solution 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ > 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( > 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ > 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) all divided by r. My problem is that Mathematica is not treating those zeros.... as > well zeros. Thus, the solution cannot really be used. In fact, if I > manually reproduce the solution and remove those zeros, then the > solution is fine. I have another similar ODE Anyone have any ideas. Phi''[r]+2*r^(-1)Phi'[r]- 287.31*Phi[r]==0 and Phi[3R]==0(some > constant) ; kinda has a cosh/sinh solution As you might have notice I need to match these two solutions and their > derivatives at some point. The ratio of which gives me what I desire > the value of R. Yet, Mathematica treats those zeros as something else. > === Subject: Re: Help with Manipulate > Details of computations omitted; much too complicated, and irrelevant. > After lots of computation, showit calls Graphics3D[{........}]. > > manip2[xyz_] := Module[{xr}, > ptvertS[[5]] = xyz; > finlist; sphrAll; allspt; setDisp; showit > ] > m1 = 100; m2 = {m1,m1,m1}; > > Manipulate[manip2[xyz], {{xyz, {-22, -92, +47}, V5, XYZ}, -m2, m2}] > > This works fine (at least some of the time), including the= > initial value and label. ptvertS[[1]],...,ptvertS[[5]] are each just > numerical {x,y,z} coordinates. > However the 3-part slider no longer has the little symbol > which you can expand to see values and control them. Is there a way to > see the values of a list in this situation? Currently I use Epilog to > display them. > > *********************** > > BUT this one does not work, giving an error message someth= ing > like indeterminate should be triple of numbers. But as an example, > manip3[{11,22,33},{44,55,66}] by itself works. > > manip3[xyz1_, xyz2_] := Module[{xr}, > ptvertS[[1]] = xyz1; ptvertS[[2]] = xyz2; > finlist; sphrAll; allspt; setDisp; showit > ] > m1 = 100; m2 = {m1, m1, m1}; > Manipulate[manip3[c1, c2], {c1, -m2, m2}, {c2, -m2, m2}] > > I will appreciate any help. > > Steve Gray You can create a row of controls manually: Manipulate[u, {{u, {0, 0, 0}}, None}, Row[Manipulator[Dynamic@ u[[#]], AppearanceElements -> {InlineInputField, InputField}, ImageSize -> Tiny]& /@ Range[3], Spacer[5]]] It won't look as good if you want to include all the Manipulator elements though. Maxim Rytin m.r@inbox.ru === Subject: Re: list of dates {63,85.4959} Bob Hanlon > I have a list of dates in the format YYYY-MM-DD and I want to convert them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly > to 85.5. Any suggestions on the best way to do this? Roger === Subject: Re: Locator > Very recently I started using Mathematica with the hopes of accomplishing the following. I have had some progress by using extensively the documentation center, however, any help will be really appreciated. I have 2 questions in particular and have described them below: Unusual things to try when starting to use Mathematica :-) > I have created 3 notebooks with the following command: > lst = Table[ > NotebookCreate[WindowSize -> {240, 240}, WindowTitle -> new, > WindowMargins -> {{RandomInteger[{0, 100}], Automatic}, { Automatic, > RandomInteger[{0, 50}]}}], {3}]; newlst=Map[WindowMargins /. Options@# &, > Select[Notebooks[], > StringMatchQ[(WindowTitle /. NotebookInformation[#]), new] &]] I then retrieve the notebook locations for the 3 notebooks. > coord = Map[({#[[1, 1]], #[[2, 2]] }) &, newlst] Finally, I want to create locators for each of the above notebooks, such that when I move the locators the notebooks are moved. In other words, the {x,y} position of the locators is mapped to the WindowMargins of that particular notebook. I have successfully created the locators but I have no clue how to map the locators such that the notebooks are moved. Below is the code for it: DynamicModule[{pt = new1}, > LocatorPane[Dynamic[pt], > Dynamic@ > ListPlot[pt, AxesOrigin -> {0, 0}, PlotRange -> {{0, 100}, {0, 50}}]]] I can move the locators, but with the moving of locators I need to the move corresponding notebook. Any help would be of great help when experimenting it is usually easier to get things working for a simple case. Here I'll start of with one notebook. Note that NotebookCreate returns a notebookobject which you can refer to later, so there is no need to search Notebooks[] for it: nb = NotebookCreate[ WindowSize -> {240, 240}, WindowMargins -> { {RandomInteger[{0, 100}], Automatic}, {Automatic, RandomInteger[{0, 50}]} } ] these define the screensizes and are handy lateron: screenheight = (ScreenRectangle /. Options[$FrontEnd])[[2, 2]] screenwidth = (ScreenRectangle /. Options[$FrontEnd])[[1, 2]] this is a function that moves the window for a given notebook to new values of WindowMargins: movenb[nb_, {x_, y_}] := SetOptions[nb, WindowMargins -> {{x, Automatic}, {Automatic, screenheight - y}}] This shows a LocatorPane which will move the window. The trick is to use the two argument version of Dynamic: DynamicModule[{pt = {#1, screenheight - #2} & @@ Flatten[WindowMargins /. Options[nb]][[{1, -1}]]}, LocatorPane[ Dynamic[pt, Function[pt = #; movenb[nb, pt]; pt] ], Graphics[{}, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]) ] ]] It turns out that handling lists is easier with this, which uses Locator instead of LocatorPane and happens to be more compact in this case as well: DynamicModule[{pt = {#1, screenheight - #2} & @@ Flatten[WindowMargins /. Options[nb]][[{1, -1}]]}, Graphics[{Locator[Dynamic[pt, Function[pt = #; movenb[nb, pt]; pt] ]]}, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]) ] ] now we are ready to work with a list of notebooks: nblst = Table[NotebookCreate[ WindowSize -> {240, 240}, WindowMargins -> { {RandomInteger[{0, screenwidth}], Automatic}, {Automatic, RandomInteger[{0, screenheight}]} } ], {3}] This defines a graphics with one locator for each window: nbcoords = Map[Flatten[WindowMargins /. Options[#]][[{1, -1}]] &, nblst] With[{screenheight = (ScreenRectangle /. Options[$FrontEnd])[[2, 2]]}, DynamicModule[{ ptlst = {#1, screenheight - #2} & @@@ nbcoords }, Graphics[{ Table[ With[{nn = n}, Locator[ Dynamic[ptlst[[nn]], Function[movenb[nblst[[nn]], #]; ptlst[[nn]] = #]] ] ], {n, Length[nblst]}] }, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]) ] ] ] to make it look nicer you might want to use rectangles as representations for your windows. You might want them to be of the correct relative size and use the top left corner for their positions to reflect more closely the actual window on screen, which I did not implement here: Deploy@DynamicModule[{ ptlst = {#1, screenheight - #2} & @@@ nbcoords }, Graphics[{ Table[ With[{nn = n}, Locator[ Dynamic[ptlst[[nn]], Function[movenb[nblst[[nn]], #]; ptlst[[nn]] = #]], Graphics[{Opacity[0.5], Rectangle[]}, ImageSize -> 48] ] ], {n, Length[nblst]}] }, Frame -> True, PlotRange -> (ScreenRectangle /. Options[$FrontEnd]), FrameTicks -> None ] ] hth, albert === Subject: Re: list of dates > I have a list of dates in the format YYYY-MM-DD and I want to convert them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly > to 85.5. Any suggestions on the best way to do this? In version 6: hth, albert === Subject: Re: list of dates A key aspect of the problem is that the dates are a list, so I want to be able to operate on them as a list. The approximation of leap years does not concern me, although the year has Adapting your suggestions and after much struggle (I am new to Mathematica), I came up with this (date is the list of dates input, t is the list of values output): n = Length[date]; t = year - 1900 + days / 365.24; It is however very slow. It takes a couple of minutes for 15,000 dates. All the other software I have used for a similar calculation (Excel, Stata) does it in a split second. Is there a much more efficient method? Roger > I have a list of dates in the format YYYY-MM-DD and I want to convert them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly > to 85.5. > > Any suggestions on the best way to do this? > > Roger > > === Subject: Re: list of dates If the dates you have are in the form of strings (or you can get them that Here's an example: (* more dates added so the problem isn't as trivial*) dates = Sort@{1963-01-01, 1900-01-01, 2007-04-04, 1886-05-19, 1985-07-01, 1977-09-28} (* take the dates, turn them into Mathematica's standard form, and then get parse into seconds form to be able to use Rescale in the next step *) (* finally perform the rescaling *) Rescale[absTimes, {1988064000, 2698012800}, {63.0, 85.5}] Hope that helps! C.O. > I have a list of dates in the format YYYY-MM-DD and I want to convert them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly > to 85.5. > > Any suggestions on the best way to do this? > > Roger -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: list of dates The following will be accurate within any given year, though depending on your purposes, it may not be good for date math as different years are of different lengths -- dateToFloat3[datestring_] := Module[{ourdate, yearstart, yearend}, yearend = {ourdate[[1]], 12, 31}; (ourdate[[1]] - 1900) + (AbsoluteTime[ourdate] - AbsoluteTime[yearstart])/(AbsoluteTime[yearend] - AbsoluteTime[yearstart]) // N] (* coded for clarity, you could make it shorter and probably quicker if you wanted *) dateToFloat3[1963-01-01] 63. dateToFloat3[1963-12-31] 64. dateToFloat3[1963-07-01] 63.4959 Michael > > I have a list of dates in the format YYYY-MM-DD and I want to convert > them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes > roughly > to 85.5. > > Any suggestions on the best way to do this? > > To help you started, the following function assume an input date as a > string and that a year as 360 days (i.e. 12 months of 30 days). > > yy = yy - 1900; > td = 30 (mm - 1) + dd; > yy + Rescale[td, {1, 360}] // N > ] > > Out[79]= 63. > > Out[80]= 85.5014 > > -- Jean-Marc > > === Subject: Re: list of dates > >> I have a list of dates in the format YYYY-MM-DD and I want to convert >> them to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 >> goes roughly to 85.5. >> >> Any suggestions on the best way to do this? >> >> Roger >> >> > Perhaps Developer`CalendarData may help: > > In[102]:= Developer`CalendarData[{1985, 7, 1}, TimeInYear] > > Out[102]= 0.49589 > > > > Out[103]= {0.49589,Year} > > Carl Woll > Wolfram Research > In[105]:= Developer`CalendarData[1985-07-01, TimeInYear] Out[105]= 0.49589 Out[106]= {0.49589,Year} Out[107]= {0,Year} Carl Woll Wolfram Research === Subject: Re: list of dates >I have a list of dates in the format YYYY-MM-DD and I want to convert them >to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly >to 85.5. > >Any suggestions on the best way to do this? > >Roger > > > Perhaps Developer`CalendarData may help: In[102]:= Developer`CalendarData[{1985, 7, 1}, TimeInYear] Out[102]= 0.49589 Out[103]= {0.49589,Year} Carl Woll Wolfram Research === Subject: Getting the size of the bounding box of a Graphics3D[] Is there a reliable way to get the coordinates and size of the bounding box of a Graphics3D object? I tried PlotRange /. AbsoluteOptions[Graphics3D[Sphere[]]] but it gives {{0., 1.}, {0., 1.}, {0., 1.}}, whereas the correct answer should be {{-1., 1.}, {-1., 1.}, {-1., 1.}}. === Subject: Re: Wolfram Workbench user experiences > I would be very interested in other people's experiences with the > Wolfram Workbench. I must admit that I prefer to use the frontend as my > 'IDE', and the workbench seemed fairly alien when I tried it. > I haven't used Workbench, but I see that it includes a profiler: http://media.wolfram.com/brochures/workbench_print.pdf I imagine that this must be a very useful feature. I wish it were included with Mathematica. Perhaps people would find it more useful than the already included debugger (I don't really feel the need to use the debugger. I'm happy with Trace[], On[], EvaluationMonitor, etc., or just simply breaking up functions into pieces.) === Subject: Re: Wolfram Workbench user experiences I agree. Was not sure what the payoff (over the ide) was for learning how to work in the environment. > > I would be very interested in other people's experiences with the > Wolfram Workbench. I must admit that I prefer to use the frontend as my > 'IDE', and the workbench seemed fairly alien when I tried it. > > David Bailey > http://www.dbaileyconsultancy.co.uk > > -- Richard Palmer Home 508 877-3862 Cell 508 982-7266 === Subject: Re: Wolfram Workbench user experiences it depends, I have usual a C++/MathLink program to develop, with some Mathematica to turn options into parameters for a C/C++ function. The most compiler have an IDE similar to Eclipse and some things like debugging of profiling work better in the Workbench than in the FrontEnd. So the Workbench remind me on my C++ IDE and the FrontEnd seems to be more alien-like. Jens > I would be very interested in other people's experiences with the > Wolfram Workbench. I must admit that I prefer to use the frontend as my > 'IDE', and the workbench seemed fairly alien when I tried it. David Bailey > http://www.dbaileyconsultancy.co.uk > === Subject: Re: Wolfram Workbench user experiences David, I like Wolfram Workbench a lot. For me the workbench editor is much nicer than using a notebook directly (in particular I have some difficulties with the smart autoformatting in notebooks). The colour highlighting and bracket checking in workbench are working particularly nicely and usefully to my opinion. All my function definitions are then loaded in the accompanying notebook after each editing automatically, and then I work with my functions in the notebook just like with built-in functions. That is I edit in the workbench only such functions which I will use more often. Things like plotting results and all that which requires constant fine-tuning are done in the notebook itself. Of course, all such things are largely a matter of taste, and your personal working style, but I like this division of my work into the core routines which I develop in workbench and then working with them in the notebook. I also tried occasionally the profiler, which was not so much of use to me, and debugging is also not so easy so that I mostly still work with Print[] statements if things go wrong. (But I am not a professional programmer, but a scientist just using Mathematica to solve problems. I would guess that real large scale projects with more than one person working on them and the requirement of professional source code management cannot be done efficiently without such tools as workbench.) Since I often have to connect to remote kernels, I certainly miss the possibility to connect workbench to remote kernels. (At least I didn't get it to connect to a remote kernel until now.) So, in the wake of some recent discussions in this newsgroup about the Wolfram User Interface, I would say, workbench is just a great addition to the possibilties to work with Mathematica. Different people are working differently, and it is good that different working styles are catered for. (Certainly all my tasks could be done without workbench.) I am certainly looking forward to workbench 1.2 and its enhancements... Michael > I would be very interested in other people's experiences with the > Wolfram Workbench. I must admit that I prefer to use the frontend as my > 'IDE', and the workbench seemed fairly alien when I tried it. David Bailey > http://www.dbaileyconsultancy.co.uk > === Subject: Re: Wolfram Workbench user experiences I have pretty much the same experience that you do. I have beta tested several versions of Workbench, but I still much prefer interactive development in Mathematica. Having said that, the debugger in workbench is more powerful than the one in Mathematica, and it should be easier to complete package development with Workbench than in Mathematica. One problem I have is that the other IDEs I have used -- Xcode, CodeWarrior, etc. -- have been much more powerful than the Eclipse environment. The inability to get full API documentation easily in Workbench is a major failing. I am sure that someone coming to Workbench from command line tools would not have this problem. I plan to do my development in Mathematica, and then take the initialization cells and move them to Workbench for the final stages of package development. I see Workbench as a niche tool. It's not for beginners, and useful primarily for development of large or complex packages. george woodrow > I would be very interested in other people's experiences with the > Wolfram Workbench. I must admit that I prefer to use the frontend as > my > 'IDE', and the workbench seemed fairly alien when I tried it. > > David Bailey > http://www.dbaileyconsultancy.co.uk > === Subject: Writing a HoldAll function that evaluates its arguments What is the simplest and most elegant way of implementing a function that has HoldAll, but it still evaluates each of its arguments exactly once (and does not go into infinite evaluation)? I can come up with some ways (explicitly checking whether evaluation changes the arguments), but neithe