1354 === Subject: Re: Reading csv with ; ...not very well paid though ..... 2009/5/11 DrMajorBob : >> standard documentation. I imagine there could be a whole cottage >> industry filling the gaps in the official documentation. > > Mathgroup IS that cottage industry. > > Bobby > > === Subject: Optimize speed of plotting mesh I have to bring coordinates with the corresponding mesh (at each coordinate) together. The question is not, how do it but how to do it more efficiently. The following steps are necessary a) Generation of the coordinates from a dx in each spatial direction. At the moment I am doing this with table coordinates=Table[i*dx+j*dy+k*dz,{i,0,imax},{j,0,jmax},{k,0,kmax}] which seems to be the true bottleneck (takes 24 sec's for 2299968 Points) b) Bring coordinates and mesh together (Flatten[#1]) & /@ Transpose[{coordinates, mesh}] Takes about 6 secs c) Delete Cases, in which the mesh data is lower than a certain value choppedData=DeleteCases[data, {_, _, _, x_ /; x <= 10^-4}] Also takes about 6 secs. Might be unnecessary, but I thought it is a good idea to decrease the number of mesh points for the CounterPlot. d) Plot the mesh ListContourPlot3D[choppedData, Mesh -> None, Contours -> 5, PlotRange -> All, MaxPlotPoints -> 50, ContourStyle -> Yellow] // Timing I guess, this can be improved by Interpolation of the data, though I have not tried it yet. I have to use a large value for MaxPlotPoints, because otherwise the mesh does not look smooth. Yours Wolfgang === Subject: Re: Optimize speed of plotting mesh and ContourPlot3D[] doesn not accept data on a regular grid anymore ? My Mathematica 7 does data = Table[ Sin[x*y*z], {x, 0, Pi, Pi/8}, {y, 0, Pi, Pi/8}, {z, 0, Pi, Pi/8}]; ListContourPlot3D[data] and your \coordinates\ generation is complete useless. And it is not better for an interpolation when you remove values. Jens > > I have to bring coordinates with the corresponding mesh (at each > coordinate) together. The question is not, how do it but how to do it > more efficiently. The following steps are necessary > > a) Generation of the coordinates from a dx in each spatial direction. > At the moment I am doing this with table > > coordinates=Table[i*dx+j*dy+k*dz,{i,0,imax},{j,0,jmax},{k,0,kmax}] > > which seems to be the true bottleneck (takes 24 sec's for 2299968 > Points) > > b) Bring coordinates and mesh together > > (Flatten[#1]) & /@ Transpose[{coordinates, mesh}] > > Takes about 6 secs > > c) Delete Cases, in which the mesh data is lower than a certain value > > choppedData=DeleteCases[data, {_, _, _, x_ /; x <= 10^-4}] > > Also takes about 6 secs. Might be unnecessary, but I thought it is a > good idea to decrease the number of mesh points for the CounterPlot. > > d) Plot the mesh > > ListContourPlot3D[choppedData, Mesh -> None, Contours -> 5, > PlotRange -> All, MaxPlotPoints -> 50, > ContourStyle -> Yellow] // Timing > > I guess, this can be improved by Interpolation of the data, though I > have not tried it yet. I have to use a large value for MaxPlotPoints, > because otherwise the mesh does not look smooth. > > Yours Wolfgang > > === Subject: Re: Help! 6 equation non-linear system > I'm very new to Mathematica, and I'm trying to solve a fairly complex > system involving 3 non-linear implicit equations (Colebrook > equations). I've tried just doing a Solve and NSolve function, but my > Core 2 Duo @ 2.2GHz with 3 GB ram running on XP runs out of memory and > can't produce anything. > > Here are my equations: > > 190200=999*V3^2/2-999*V1^2/2+33266.7*f3*V3^2+166533*f1*V1^2+14185.2*V3^2 > > 180400=999*V2^2/2-999*V1^2/2+199800*f2*V2^2+166533*f1*V1^2+25874.1*V2^2 > > V1=V2+V3 > > 1/sqrt(f1)=-2*log(2.7*10^-5+1.88*10^-4/(V1*sqrt(f1))) > > 1/sqrt(f2)=-2*log(2.7*10^-5+1.88*10^-4/(V2*sqrt(f2))) > > 1/sqrt(f3)=-2*log(2.7*10^-5+1.88*10^-4/(V3*sqrt(f3))) > > > Variables: > > V1: should be in the range 0 < V1 < 20 > V2: should be in the range 0 < V2 < 10 > V3: should be in the range 0 < V3 < 10 > f1: should be in the range 0 < f1 < 0.1 > f2: should be in the range 0 < f2 < 0.1 > f3: should be in the range 0 < f3 < 0.1 > > > Any help would be greatly appreciated, I'm stuck!! Main suggestions: (1) Use actual Mathematica syntax. (2) Use FindRoot, with starting points inside the domain of interest. You will not be able to use NSolve because you do not have a polynomial system of equations in the variables of interest (due to presence of logs). c1 = 27*10^(-6); c2 = 188*10^(-6); exprs = { 999*V3^2/2-999*V1^2/2+332667/10*f3*V3^2+166533*f1*V1^2+ 141852/10*V3^2-190200, 999*V2^2/2-999*V1^2/2+199800*f2*V2^2+166533*f1*V1^2+ 258741/10*V2^2-180400, V2+V3-V1, -2*Log[c1+c2/(V1*Sqrt[f1])] - 1/Sqrt[f1], -2*Log[c1+c2/(V2*Sqrt[f2])] - 1/Sqrt[f2], -2*Log[c1+c2/(V3*Sqrt[f3])] - 1/Sqrt[f3]}; I'll use Chop to get rid of small imaginary parts. In[44]:= InputForm[solns = Chop[FindRoot[exprs==0, {V1,10}, {V2,5}, {V3,5}, {f1,1/20}, {f2,1/20}, {f3,1/20}]]] Out[44]//InputForm= {V1 -> 6.009425355323082, V2 -> 2.506571958922738, V3 -> 3.502853396400344, f1 -> 0.00433243520465387, f2 -> 0.005321604673945427, f3 -> 0.004904934117761941} Check result: In[45]:= InputForm[exprs/.solns] Out[45]//InputForm= {2.9103830456733704*^-11, 0., 0., 0., 1.7763568394002505*^-15, 0.} I could get higher precision results by use of higher working precision: solns = Chop[FindRoot[exprs==0, {V1,10}, {V2,5}, {V3,5}, {f1,1/20}, {f2,1/20}, {f3,1/20}, WorkingPrecision->20]] Note that there may be other roots in the range of interest. Indeed, tehre must be others, due to the input equation symmetry {V2,V3,f2,f3} <--> {V3,V2,f3,f2}. Daniel Lichtblau Wolfram Research === Subject: Re: Getting Workbench to Work Workbench has much promise for creating nifty application projects such as electronic textbooks, courseware and major research projects, complete with packages and documentation. But, unfortunately, it is suffering from a lot of developmental neglect in the way of capabilities, convenience and documentation. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ I cannot help you regarding Workbench specifics as I tried the first release, encountered many problems and stopped after that. But try it yourself. Presumably the initial bugs are fixed now. Hannes Kessler === Subject: Re: simple Question This finds a maximum on EACH curve: Cases[Plot[Sin@x, {x, 0, Pi}], Line[pts_List] :> Max@pts[[All, 2]], Infinity Max@% {1.} 1. Cases[Table[Plot[x Sin[k x], {x, 0, Pi}], {k, 0, 13}], Line[pts_List] :> Max@pts[[All, 2]], Infinity] Max@% {0., 1.81971, 0.909853, 2.63891, 1.97918, 2.83447, 2.36206, 2.92068, \\ 2.5556, 2.96913, 2.67221, 3.00017, 2.75015, 3.02171} 3.02171 This doesn't require knowing the structure of the Plot or other graphic (only that it's made up of Lines), so it might not change from version to version. Bobby > Hi Oliver, > > Various possibilities here: > > If you just want to quickly know the maximum value shown in the plot > you may select the plot, press shift-period and move the cursor to the > highest point in your plot. The maximum will be in the tooltip. > > Second possibility is to examine the graphics commands underlying the > plot. You can see them if you use FullForm. You have to delve deep for > the nested data you need, but you can get there. For example: > (Plot[Sin[x], {x, 0, Pi}] // FullForm)[[1, 1, 1, 3, 2, 1, All, > 2]] // Max > > Third possibility is to use MaxValue or Maximize on the function you > plotted using the plotrange as constraint: > MaxValue[{Sin[Cos[5 x]], 0 <= x <= 2 \\[Pi]}, x] > > Hope this helps. > > > >> Hallo, >> how can i read the max value in a plot in mathematica? >> Oli. > > -- DrMajorBob@bigfoot.com === Subject: Re: simple question Hi Francisco, your compare function is wrong. Try e.g.: {#1[[1]], #[1[2]]} =!= {#2[[1]], #2[[2]]} & Here is a simplified example: f = Max[0, # - 1] &; NestWhile[f, 10, #1 =!= #2 &, 2] Daniel > I have a function whose output is of the form {{a,b,c},{d,e,f},k} > > That is, a list of length 3, of which the first two parts are lists and \ the last part is a number > > Now, I want to iterate it, with the following termination criterion: stop \ if the first two parts of the output are identical in two successive runs. > > The intuitive (or naively intuitive if you want) way of attacking the \ problem, I think, is the following: > > NestWhile[f,startinglist,UnsameQ[{#[[1]],#[[2]]}&,2] > > But it does not work. > > What is the solution? > Fg > === Subject: Re: Frequency data Give an example where it fails. Bobby > Hi everybody, > > I'm using Mathematica 6.0 and would like to get frequency of data > given intervals, i tried to do it with BinCounts[data, h] , where h > is the distance of the intervals, but it doesn't work correctly, can > anybody help me how to get frquency data > > Sukhrob. > -- DrMajorBob@bigfoot.com === Subject: Re: Frequency data Hi Sukhrob, Could you be more specific about the reason why you think BinCounts doesn't work correctly? Perhaps one of the other BinCounts variants works better for you (the one in which you provide the starting, value, end value and step value, or the one in which you specify all bin boundaries)? > Hi everybody, > > I'm using Mathematica 6.0 and would like to get frequency of data > given intervals, i tried to do it with BinCounts[data, h] , where h > is the distance of the intervals, but it doesn't work correctly, can > anybody help me how to get frquency data > > Sukhrob. === Subject: Re: Frequency data $Version 6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007) Needs[\Histograms`\]; n = 1000; data = RandomReal[NormalDistribution[0, 1], {n}]; lb = Floor[5*Min[data]]/5. ub = Ceiling[5*Max[data]]/5. freq = BinCounts[data, {lb, ub, .2}]/n; Total[freq] 1 GraphicsArray[{ Show[{ Histogram[data, HistogramScale -> 1], Plot[PDF[NormalDistribution[0, 1], x], {x, lb, ub}, PlotStyle -> {Red, AbsoluteThickness[2]}]}], Histogram[freq, FrequencyData -> True]}, ImageSize -> 600] Bob Hanlon Hi everybody, I'm using Mathematica 6.0 and would like to get frequency of data given intervals, i tried to do it with BinCounts[data, h] , where h is the distance of the intervals, but it doesn't work correctly, can anybody help me how to get frquency data Sukhrob. === Subject: Re: ColorFunction on a linux system (xorg) loses graphics When I try the XLIB... export, Mathematica shows many \holes\ in the \ Plot3D graphs, and the rotations are much slower and jerkier than usual. I \ guess I'll just live with the state of things as they are now, until \ Mathematica learns to work with the drivers, or the driver writers can agree \ on a unified front (ha!). Curtis O. > > Hi Curtis, > > on an Ubuntu system I use a script, which calls Mathematica with \ parameters > > which let me use the mouse-wheel and the NumLock-key. Additionally it \ sets the > > environment variable XLIB_SKIP_ARGB_VISUALS to 1, which removed problems \ > > similar to the one you describe. Maybe it is worth a try (the little \ utility > > \imwheel\ has to be installed): > > > > petsie@leierkasten:~$ cat run-math > > #!/bin/sh > > > > # run-math.sh version 4 > > # `-r' flag means don't use the \Configurator\ > > # and pass wheel events to the root window > > # > > # Ensure a single instance of Mathematica with > > # the option `-singleLaunch'. > > # Allow the use of the NumLock key with the > > # '-primaryModifierMask' and '-secondaryModifierMask' > > # switches. > > > > MARGS=\-singleLaunch -primaryModifierMask Mod1Mask \ -secondaryModifierMask > > Mod3Mask\ > > > > if `ps -C imwheel > /dev/null`; then > > XLIB_SKIP_ARGB_VISUALS=1 Mathematica $1 $MARGS > > else > > imwheel -r > > XLIB_SKIP_ARGB_VISUALS=1 Mathematica $1 $MARGS > > imwheel -kq > > fi > > > > Oops... this works with the proprietary drivers for an ATI Mobility 3470 > graphics card on a laptop, but not with the opensource radeon driver on a \ > desktop workstation with a HIS x1050 graphic card?? > Must be a bug in the OSS-Radeon-driver. > B.t.w.: compiz is installed on both computers. > Peter > > -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 === Subject: Re: Why is equation set can't solve in Mathematica? Perhaps you didn't wait long enough... I didn't have the time or patience either. But, let's have a closer look. There are two equations for yx13b, so we may equate both right-hand sides and solve for yx13a. It takes a couple of minutes and then Mathematica finds a some huge answers (and a small one, 0). If you enter these in the original equations you'll have yx13b. > This: > > Solve[{yx13b == (-dg sxa yx13a + > Sqrt[-dg dx1 sxa^2 yx13a + dg px013a sxa^2 yx13a - > dg hxa sxa^2 yx13a^2 - dg sxa vx13a yx13a^2])/(dg sxa), > yx13b == (-dx3 sxb + px013b sxb - 2 dg sxb yx13a - Sqrt[ > 4 dg sxb (-dg sxb - hxb sxb - vx13b) yx13a^2 + (-dx3 sxb + > px013b sxb - 2 dg sxb yx13a)^2])/( > 2 (dg sxb + hxb sxb + vx13b))}, {yx13a, yx13b}] > > can't solve. Why? === Subject: SparseArray and Compile I have difficulties to speed up my calculation regarding SparseArray: rp = {}; AppendTo[rp, SparseArray[UnitStep[0.01 - dat - dat[[#]]]]] & /@ Range[Length[dat]]; dat is a list of Reals containing approx. 24000 elements. I had to use SparseArray for each line to prevent a memory crash; the final matrix has 574 million elements. The calculation takes 2' 43'' on my WinXP I would like to speed up the calculation using compile, but the SparseArray object doesn't fit the tensor format. I have tried: Compile[{{data, _Real, 1}}, Block[{rp}, rp = {}; AppendTo[rp, SparseArray[UnitStep[0.01 - data - data[[#]]]]] & /@ Range[Length[data]]]] Compile::cpts: The result after evaluating Insert[rp,SparseArray [UnitStep[0.01-data-data[[System`Private`CompileSymbol[<<1>>] [[System`Private`CompileSymbol[<<1>>]]]]]]],-1] should be a tensor. Nontensor lists are not supported at present; evaluation will proceed with the uncompiled function. >> The calculation is used calculate a recurrence plot. The fixed value of 0.01 will be replaced by a variable later on; therefore, I need to speed up the calculation. Any help is appreciated. === Subject: Re: Replace specific element with specific value. >Let me elaborate on this problem again with numbers only. >data = {{0, 2}, {2, 3}, {3, 4}, {4, 6}, {6, 8}, {8, 9}, {9, 10}} >positionList = {3, 6, 7} >replacementList = {8, 17, 25} >needed output: >{{0, 2}, {2, 3}, {3, 8}, {4, 6}, {6, 8}, {8, 17}, {9, 25}} >Based on the positionList - replacementList information, the >function must replace the 2nd element in the 3rd, 6th and 7th list >of data with the value 8, 17 and 25 respectively. Here is one way: In[6]:= ReplacePart[data, Thread[Evaluate[{#, 2} & /@ positionList] -> replacementList]] Out[6]= {{0, 2}, {2, 3}, {3, 8}, {4, 6}, {6, 8}, {8, 17}, {9, 25}} Note, the output is what you want and the original list is unchanged. That is: In[7]:= data Out[7]= {{0, 2}, {2, 3}, {3, 4}, {4, 6}, {6, 8}, {8, 9}, {9, 10}} Obviously, if you want the original list changed all you need do is set the original list to the output. === Subject: Re: Making a user interface snip > > Probably you could implement such a system using EventHandler, but > it would take some effort. > -- yeah, I can atest to that. I looked into this for my palette. Ouch. Later for 1.5 ;-) Now, if someone made a rich tutorial on EventHandlers, it might be smoother. === Subject: Graph with 3 variables I want to plot a graph with 3 variables (x,y,z) and it is an inequality: (x/y)* Constant >= z How can I plot for this in mathematica. Thnaks in advance. Shobhit. === Subject: Re: Graph with 3 variables RegionPlot3D[(x/y)*3 >= z, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}] ? Jens > I want to plot a graph with 3 variables (x,y,z) and it is an inequality: > (x/y)* Constant >= z > > How can I plot for this in mathematica. > > Thnaks in advance. > > Shobhit. > === Subject: Re: Introducing the Wolfram Mathematica Tutorial Collection > > In fact, on the Mac, I cannot see any benefit to PDF > > documentation over the existing online documentation. and (if I'm kept the threads straight) Bill F replied > You can set your own Bookmarks, you can add notes, you can search for > a string and see all the occurances at once and then click on any one > of them to go to a specific spot in the document, you could even merge > your own notes into the document by inserting pages from one PDF to > another and the resulting document would be a whole lot more useful to > your specific needs. I would wager there are more... > > > So, can you do any of that with the DC interface - NOPE. Are these of > benefit? For some yes, and some no. And Bill F is exactly right -- and there are more such benefits. PDF is a long-standing, stable, high-quality open standard that was designed for \documentation\ (online and printed); is near universally used for it (in myriad ways); and is very good at it. Mathematica isn't. === Subject: Re: Introducing the Wolfram Mathematica Tutorial In addition, the Mac OS/X Spotlight will search _all_ text PDFs on the disk for a word or phrase, almost instantly. Every PDF that includes the word BinCounts, say, appears at once. Each promising document has to be opened separately for a local search, but it's not hard to ignore your own \ notebooks if you want to, or FOCUS on your own code examples, if you prefer. This would also work for Doc center notebooks if they were (a) on the disk \ and (b) NOT in system directories ignored by Spotlight. (So it DOESN'T work for Doc center notebooks.) Bobby >> >> >> >> >Bob F (author of the original post appended below) and I are >> >evidently very much in agreement about the value of PDF >> >documentation. Let me just add one note. >> >Split windows are certainly good, particularly if you have either >> >large (or multiple) monitors and/or excellent eyesight. >> >An equally good, maybe even better, alternative is to be able to >> >jump back and forth (preferably with a single keystroke or >> >mouseclick) between two different full-screen \environments\ or >> >\views\, with Mathematica open and running in one of these and the >> >PDF documentation open and viewable in some reader-friendly >> >application in the other. >> >The \Spaces\ capability in Apple's Leopard OS provides a >> >sophisticated way to do this; the Cmd-Tab application switching >> >capability in earlier Mac operating systems is almost equally handy. >> >I'd assume there are equivalent capabilities on most other >> >platforms. >> >> On the Mac platform, you can do precisely this with the existing >> online documentation as follows: >> >> Open the documentation center >> Hit the key that shows all spaces (for me F7) >> Drag the documentation center window to an empty space >> >> Now you can switch from the space running your main notebook to >> the space with the documentation center by using whatever key >> stroke you set up to switch among the spaces you've set up. This >> has the added benefit over PDF documentation of being able to >> copy and paste from whatever you are viewing in the >> documentation center window to your running notebook. >> >> In fact, on the Mac, I cannot see any benefit to PDF >> documentation over the existing online documentation. > > You can set your own Bookmarks, you can add notes, you can search for > a string and see all the occurances at once and then click on any one > of them to go to a specific spot in the document, you could even merge > your own notes into the document by inserting pages from one PDF to > another and the resulting document would be a whole lot more useful to > your specific needs. I would wager there are more... > > All these things are something I do with Acrobat Professional, not > sure if Acrobat Reader does them all. > > So, can you do any of that with the DC interface - NOPE. Are these of > benefit? For some yes, and some no. > > But, there are some things you can't do - and these have been pointed > out in other threads here. > > So, neither format is perfect, just choose the one that has what you > need to do for the moment. > > -Bob > -- DrMajorBob@bigfoot.com === Subject: Recovering data from DumpSave Hello all, I slipped and did a terribly long calculation and then used DumpSave of a variable defined inside a Module. Previous tests of the code were fine, but of course, I was testing outside the Module structure. Now Get doesn't load anything, although the data must be on the file data along with a temporary variable name in the context that was on at that time, as it was one of the variables inside the Module. So, now when I try to Get it it loads it up somewhere (takes a little time) but then dumps it because the context does not exist anymore...I can see in the files that my variable (originally named phase) has $anumber attached to it, indicating it is a temporary variable. I don't know how to find the context name in the file, let alone how to recreate \ it. Any ideas on how to recover the data? The variable is a list containing trees (more lists) filled with numbers. Please don't suggest computing everything again as it took a week to do it... Fernando === Subject: Re: Recovering data from DumpSave > Hello all, > > I slipped and did a terribly long calculation and then used DumpSave > of a variable defined inside a Module. Previous tests of the code were > fine, but of course, I was testing outside the Module structure. Now > Get doesn't load anything, although the data must be on the file > data along with a temporary variable name in the context that was on > at that time, as it was one of the variables inside the Module. So, > now when I try to Get it it loads it up somewhere (takes a little > time) but then dumps it because the context does not exist anymore...I > can see in the files that my variable (originally named phase) has > $anumber attached to it, indicating it is a temporary variable. I don't > know how to find the context name in the file, let alone how to recreate \ it. > Any ideas on how to recover the data? The variable is a list > containing trees (more lists) filled with numbers. Please don't > suggest computing everything again as it took a week to do it... I can't tell for sure, but a simple test makes me believe that Import[filename, \MX\] could work. If you don't know the $number attached to your variable, just type your variable name and use Ctrl-K (might be some other key combination if you are not on Windows) to get a list of defined variable names. hth, albert === Subject: Curated Data : Issues with FiniteGroupData It seems that FiniteGroupData is rather incomplete. For example the MultiplicationTable of many indexed groups is missing Table[FiniteGroupData[{\SymmetricGroup\, n}, \MultiplicationTable\], {n, 1, 5}] gives NotAvailable or missing information. Same problem with CyclicGroup, ect. Am I doing something wrong, or are there really big holes in this data (at the moment)? === Subject: Re: derivative of a well-behaved function Hi Maxim, I get the following error message evaluating your expression with my system setup as listed below: > D[f[g[z]], z, Direction -> z0] == > g'[z]*D[f[w], w, Direction -> z0*g'[z]] /. w -> g[z] and Direction is highlighted in red. D::optx: Unknown option Direction in D[f[g[z]],z,Direction->z0]. >> D::optx: Unknown option Direction in D[f[w],w,Direction->z0 (g^\\ [Prime])[z]]. >> D::optx: Unknown option Direction in D[f[g[z]],g[z],Direction->z0 (g^\\ [Prime])[z]]. >> General::stop: Further output of D::optx will be suppressed during this calculation. >> In my documentation Direction is listed as an option for Limit[] Are you running a developer version? Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com Mathematica 7.0.1 for Mac OS X x86 (64 - bit) (18th February 2009) MacOS X V 10.5.6 > Essentially you want to compute a directional derivative of f[g[z]] > with g analytic and f non-analytic, where f == Abs and the direction > vector z0 == 1. Then (making up the notation as we go along) > > D[f[g[z]], z, Direction -> z0] == > g'[z]*D[f[w], w, Direction -> z0*g'[z]] /. w -> g[z] === Subject: Re: Replace specific element with specific value. myReplacePart[data_List, pos_List, parts_List] := Module[{newList = data}, ( newList = ReplacePart[newList, #[[1]] -> #[[2]]]) & /@ Transpose[{Thread[{pos, 2}], parts}]; newList] /; Length[pos] == Length[parts] data = {{0, 2}, {2, 3}, {3, 4}, {4, 6}, {6, 8}, {8, 9}, {9, 10}}; positionList = {3, 6, 7}; replacementList = {8, 17, 25}; myReplacePart[data, positionList, replacementList] {{0, 2}, {2, 3}, {3, 8}, {4, 6}, {6, 8}, {8, 17}, {9, 25}} Bob Hanlon Bill, you are right. To manually input the replacement rules is fine for only a view variables. For simplicity I kept my example short. However, I am dealing with quite large lists (100+), so a functional/ programatical approach is necessary. Also, I used characters for clarity. Rule @@@ (ToExpression[{#, # <> \+\ <> # <> #}] & /@ {\1\, \2\, \ \3\}) gives: {1 -> 12, 2 -> 24, 3 -> 36} Let me elaborate on this problem again with numbers only. data = {{0, 2}, {2, 3}, {3, 4}, {4, 6}, {6, 8}, {8, 9}, {9, 10}} positionList = {3, 6, 7} replacementList = {8, 17, 25} needed output: {{0, 2}, {2, 3}, {3, 8}, {4, 6}, {6, 8}, {8, 17}, {9, 25}} Based on the positionList - replacementList information, the function must replace the 2nd element in the 3rd, 6th and 7th list of data with the value 8, 17 and 25 respectively. I experimented with MapThread[ReplacePart ... but without success. === Subject: Re: Palette Management > > In a few weeks I am about ready to want to install my final palette > for entering nearly all native functions (yeah no more typing or > trying to remember spelling), minus option symbol names etc. So what > is best way to install the palette and how to uninstall if I need to > (there are always bugs and minor enhancements ;-) ). Btw, anyone can > tell me how to filter the Names[] listing to just native Mathematica > function names without my own? I want to check the completeness of my > get this far. > > > Andrew Andrew, I am curious: how did you input all the native Mathematica names if you did not use Mathematica itself to give you the names? I mean: if you did not use Names[\System`*\] to get the names (and then create the palette), how did you do it? === Subject: Re: Palette Management === Subject: Re: Help! 6 equation non-linear system eqns = { 190200 == 999*(V3^2/2) - 999*(V1^2/2) + 33266.7*f3*V3^2 + 166533*f1*V1^2 + 14185.2*V3^2, 180400 == 999*(V2^2/2) - 999*(V1^2/2) + 199800*f2*V2^2 + 166533*f1*V1^2 + 25874.1*V2^2, V1 == V2 + V3, 1/Sqrt[f1] == -2*Log[2.7*10^-5 + 1.88*10^-4/(V1*Sqrt[f1])], 1/Sqrt[f2] == -2*Log[2.7*10^-5 + 1.88*10^-4/(V2*Sqrt[f2])], 1/Sqrt[f3] == -2*Log[2.7*10^-5 + 1.88*10^-4/(V3*Sqrt[f3])]}; soln = FindRoot[ eqns, {{V1, 10}, {V2, 5}, {V3, 5}, {f1, 0.05}, {f2, 0.05}, {f3, 0.05}}] // Chop {V1->6.00943,V2->2.50657,V3->3.50285,f1->0.00433244,f2->0.0053216,f3->\\ 0.00490493} eqns /. soln {True,True,True,True,True,True} Bob Hanlon I'm very new to Mathematica, and I'm trying to solve a fairly complex system involving 3 non-linear implicit equations (Colebrook equations). I've tried just doing a Solve and NSolve function, but my Core 2 Duo @ 2.2GHz with 3 GB ram running on XP runs out of memory and can't produce anything. Here are my equations: 190200=999*V3^2/2-999*V1^2/2+33266.7*f3*V3^2+166533*f1*V1^2+14185.2*V3^2 180400=999*V2^2/2-999*V1^2/2+199800*f2*V2^2+166533*f1*V1^2+25874.1*V2^2 V1=V2+V3 1/sqrt(f1)=-2*log(2.7*10^-5+1.88*10^-4/(V1*sqrt(f1))) 1/sqrt(f2)=-2*log(2.7*10^-5+1.88*10^-4/(V2*sqrt(f2))) 1/sqrt(f3)=-2*log(2.7*10^-5+1.88*10^-4/(V3*sqrt(f3))) Variables: V1: should be in the range 0 < V1 < 20 V2: should be in the range 0 < V2 < 10 V3: should be in the range 0 < V3 < 10 f1: should be in the range 0 < f1 < 0.1 f2: should be in the range 0 < f2 < 0.1 f3: should be in the range 0 < f3 < 0.1 Any help would be greatly appreciated, I'm stuck!! === Subject: Problem with strings and backslashes I'm trying to work with strings wich are LaTeX codes of formulas. I want to make substitution of particular substrings. The problem is that Mathematica (5.1) has a strange behaviour with the backslashes. When it finds \\\tau\ it removes the \\\t\ in the output. The same happen with \\\right\ which becomes \ight\. To make it work properly I need to manually add on the input an additional backslash at the beginning of \\\tau\ and \\\right\: \\\\\tau\ becames \\\tau\. But \ in this way my work go on too slowly. What can I do? === Subject: Re: Problem with strings and backslashes Mathematica need a double back slash \\\\\\ for a true back slash, because it use \\ in combinations for control codes \\\n\ for new line, \\\t\ for a tabulator. But there is not really a problem StringReplace[\$\\\\tau\\\\,\\sin(\\\\xi \\\\pi)$\, \\\\\tau\ -> \ \tan(\\\\psi)\] work as it should. Jens > I'm trying to work with strings wich are LaTeX codes of formulas. I > want to make substitution of particular substrings. The problem is > that Mathematica (5.1) has a strange behaviour with the backslashes. > When it finds \\\tau\ it removes the \\\t\ in the output. The same > happen with \\\right\ which becomes \ight\. To make it work properly \ I > need to manually add on the input an additional backslash at the > beginning of \\\tau\ and \\\right\: \\\\\tau\ becames \\\tau\. But \ in this > way my work go on too slowly. What can I do? > === Subject: Manipulate, Opacity, slow down I wonder if you can give me some hints without a code. I have a program using Manipulate[ParametricPlot[f[a]]]. 1. If I define outside the function f used in ParametricPlot, and then insert the function name into ParametricPlot, then the program slows down extremely compared to the version when the formula of the function is inserted. 2. If I add Opacity to the Directives, again the timing increases tremendously. If you think you could help seeing the (long) code I'll be ready to show it. J=E1nos === Subject: export Disdyakis Dodecahedron to 3D model (maya) I would like to find a partner for a isohedron project. My location is France (Normandy) :-) === Subject: Question about filenames for Export[...] I'm using Mathematica 6. I'd like to know how to define a file name (to be later used in Export) so that the file name contains the value of an index variable i. To exemplify, in Fortran this task would be accomplished by something like: character(len) :: FileName ... write(FileName,'(A,I4.4)') 'MyName', i These lines would produce filenames which, for i=1,2,... are MyName0001, MyName0002, ... Is there any neat way of doing the same with Mathematica? Lorenzo === Subject: Re: Dsolve matrix you should give an example. Anyway, did you mean something like: DSolve[{f'[x] == a f[x], f[0] == 1}, f, x] Daniel > Hi guys, > > I'd like to solve a system of three differential equations using \ mathematica. The terms of the equations are variables. > Dsolve is the appropriate command for that? > Can i calculate the laplace transformation of this system with the \ Mathematica? > > === Subject: Re: Frequency data problem, it works : $Version 6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007) Needs[\Histograms`\]; n = 1000; data = RandomReal[NormalDistribution[0, 1], {n}]; lb = Floor[5*Min[data]]/5. ub = Ceiling[5*Max[data]]/5. freq = BinCounts[data, {lb, ub, .2}]/n; Total[freq] 1 GraphicsArray[{ Show[{ Histogram[data, HistogramScale -> 1], Plot[PDF[NormalDistribution[0, 1], x], {x, lb, ub}, PlotStyle -> {Red, AbsoluteThickness[2]}]}], Histogram[freq, FrequencyData -> True]}, ImageSize -> 600] === Subject: Re: Problem with strings and backslashes > I'm trying to work with strings wich are LaTeX codes of formulas. I > want to make substitution of particular substrings. The problem is > that Mathematica (5.1) has a strange behaviour with the backslashes. > When it finds \\\tau\ it removes the \\\t\ in the output. The same > happen with \\\right\ which becomes \ight\. To make it work properly \ I > need to manually add on the input an additional backslash at the > beginning of \\\tau\ and \\\right\: \\\\\tau\ becames \\\tau\. But \ in this > way my work go on too slowly. What can I do? > One answer might be to use some other character - of which there are plenty in Mathematica - instead of the backslash, and then use StringReplace somewhere in your code to change it into the backslash character. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Matrix Minimization Hi , i would like to minimize the following matrix M with respect to A. M= E_X + A E_S A' + A E_P A' E_X H' +A E_S H' H E_X + H E_S A' H E_X H' + H E_S H' + E_Q where E_X, E_S, E_P and E_Q are covariance matrices.. can we do matrix optimization in mathematica? === Subject: Re: numbered figures I copied the default style sheet Default.nb to Default.modified.nb into my $UserBaseDirectory/SystemFiles/FrontEnd/StyleSheets directory and added your style with a text editor. Now it can be loaded into an open notebook from the Format->Stylesheet menu. I inserted also the option MenuPosition->10000 after CounterIncrements->\Figure\. After that, the new Figure style can be chosen from the style dropdown menu in the edit toolbar if that has been switched on in the option inspector (ctrl-shift-o, Show option values->Global preferences, Lookup->WindowToolbars->Editbar). Hannes Kessler > I put the following cells in my local style sheet. Then \Figure\ is a > defined style. I do the same for Tables. Use an Automatic Numbering > object to reference Figure by number. The key elements in the text > below are CounterBox and CounterIncrements. The rest is formating, > which you can change to suit your taste, although you should probably > retain PageBreakAbove->False. > > Cell[StyleData[\Figure\], > CellMargins->{{55, 50}, {5, 5}}, > PageBreakAbove->False, > CellFrameLabels->{{ > Cell[ > TextData[{\Figure \, > CounterBox[\Figure\], \. \}]], None}, {None, None}}, > Hyphenation->True, > CounterIncrements->\Figure\, > FontFamily->\Ariel\, > FontSize->10, > FontWeight->\Bold\] > Cell[StyleData[\Figure\, \Presentation\], > CellMargins->{{55, 50}, {5, 5}}, > PageBreakAbove->False, > Hyphenation->True, > FontFamily->\Ariel\, > FontSize->13, > FontWeight->\Bold\] > Cell[StyleData[\Figure\, \Printout\], > CellMargins->{{55, 55}, {5, 2}}, > FontSize->8] > > It would probably be better to add this to an external style sheet and = > then reference the sheet, but I've never learned to do that. > > BTW, this dates back to version 5. There may be better ways now to do > this. === Subject: Assign new values to matrix using indices This simple problem has got me confounded (despite 2 years of Mathematica experience). Say I would like to divide all lower diagonal elements of a matrix by 2. It is fairly easy to generate a list of indices, here an example for 3 by 3 matrix In[120]:= Table[{j, i}, {j, 2, cdim = 3}, {i, 1, j - 1}] // Flatten[#, 1] & Out[120]= {{2, 1}, {3, 1}, {3, 2}} Now if I would like to divide the elements of a 3 x 3 matrix by 2, I don't know how to do this. The problem is the complex interplay of Part [], Set[] and Apply[]. To set the elements of hte matrix I can do this In[219]:= t2 = {{0, 0, 0}, {2, 0, 0}, {2, 2, 0}}; f = Function[{x}, Apply[Set[Part[t2, ##], 1] &, x]]; Scan[f, {{2, 1}, {3, 1}, {3, 2}}] t2 Out[222]= {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}} which seems complicated for a simple operation. However, to divide all elements with indices given in the form above i.e. {{2, 1}, {3, 1}, {3, 2}} by 2 has got me stumped. Any help would be appreciated Mac === Subject: Re: Assign new values to matrix using indices with m = {{a, b, c}, {d, e, f}, {h, i, j}}; try MapIndexed[If[Greater @@ #2, #1/2, #1] &, m, {2}] Jens > This simple problem has got me confounded (despite 2 years of > Mathematica experience). Say I would like to divide all lower diagonal > elements of a matrix by 2. It is fairly easy to generate a list of > indices, here an example for 3 by 3 matrix > > In[120]:= > Table[{j, i}, {j, 2, cdim = 3}, {i, 1, j - 1}] // Flatten[#, 1] & > > Out[120]= {{2, 1}, {3, 1}, {3, 2}} > > Now if I would like to divide the elements of a 3 x 3 matrix by 2, I > don't know how to do this. The problem is the complex interplay of Part > [], Set[] and Apply[]. To set the elements of hte matrix I can do > this > > In[219]:= t2 = {{0, 0, 0}, {2, 0, 0}, {2, 2, 0}}; > f = Function[{x}, Apply[Set[Part[t2, ##], 1] &, x]]; > Scan[f, {{2, 1}, {3, 1}, {3, 2}}] > t2 > > Out[222]= {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}} > > which seems complicated for a simple operation. However, to divide all > elements with indices given in the form above i.e. {{2, 1}, {3, 1}, > {3, 2}} by 2 has got me stumped. > > Any help would be appreciated > > Mac > === Subject: Re: Manipulate, Opacity, slow down Janos, I don't see much difference between Manipulate[ ParametricPlot[{Sin[a u], Cos[ u/a]}, {u, 0, 4 Pi}], {a, 1, 5}] and f[a_] := ParametricPlot[{Sin[a u], Cos[ u/a]}, {u, 0, 4 Pi}] Manipulate[f[a], {a, 1, 5}] What is it precisely you did? > I wonder if you can give me some hints without a code. > I have a program using Manipulate[ParametricPlot[f[a]]]. > 1. If I define outside the function f used in ParametricPlot, and then > insert the function name into ParametricPlot, then the program slows > down extremely compared to the version when the formula of the > function is inserted. > 2. If I add Opacity to the Directives, again the timing increases > tremendously. > > If you think you could help seeing the (long) code I'll be ready to > show it. > > > J=E1nos === Subject: Re: Manipulate, Opacity, slow down adding transparency will slow down an any hardware accelerated rendering system. And with f1[t_] := {Cos[t], Sin[t], t} AbsoluteTiming[ ParametricPlot3D[f1[t], {t, 0, 2 Pi}, PlotPoints -> 4096]][[1]] gives 0.1110000 but AbsoluteTiming[ ParametricPlot3D[f1[t] // Evaluate, {t, 0, 2 Pi}, PlotPoints -> 4096]][[1]] gives 0.075 and this is nearly the same as AbsoluteTiming[ ParametricPlot3D[{Cos[t], Sin[t], t}, {t, 0, 2 Pi}, PlotPoints -> 4096]][[1]] with 0.079 Jens > I wonder if you can give me some hints without a code. > I have a program using Manipulate[ParametricPlot[f[a]]]. > 1. If I define outside the function f used in ParametricPlot, and then > insert the function name into ParametricPlot, then the program slows > down extremely compared to the version when the formula of the > function is inserted. > 2. If I add Opacity to the Directives, again the timing increases > tremendously. > > If you think you could help seeing the (long) code I'll be ready to > show it. > > > J=E1nos > === Subject: Focus ring for controls I find no examples or docs on setting or showing any focus ring for controls. In my case, I am wanting to set the color of border of buttons and ActionMenus (the main btn not the menuitems). Anyone? Is this even doable? Andrew === Subject: Re: Introducing the Wolfram Mathematica Tutorial >In addition, the Mac OS/X Spotlight will search _all_ text PDFs on >the disk for a word or phrase, almost instantly. Every PDF that >includes the word BinCounts, say, appears at once. Each promising >document has to be opened separately for a local search, but it's >not hard to ignore your own notebooks if you want to, or FOCUS on >your own code examples, if you prefer. >This would also work for Doc center notebooks if they were (a) on >the disk and (b) NOT in system directories ignored by Spotlight. (So >it DOESN'T work for Doc center notebooks.) But Spotlight isn't the only tool available on a Mac for doing searches on a Mac. There are the Unix tools find and grep which allow searches for any text in any file regardless of whether it is part of an application package or not. Additionally, this can be done from Mathematica itself using FindList with FileNames. And all of this works just fine with notebooks. In fact, since notebooks are ASCII files, these tools work better with notebooks than PDF files. === Subject: Re: Question about filenames for Export[...] >file name (to be later used in Export) so that the file name >contains the value of an index variable i. To exemplify, in Fortran >this task would be accomplished by something like: >character(len) :: FileName ... write(FileName,'(A,I4.4)') 'MyName',i >These lines would produce filenames which, for i=1,2,... are >MyName0001, MyName0002, ... >Is there any neat way of doing the same with Mathematica? Creating a list of indexed strings can be done as follows: In[1]:= \file\ <> ToString[NumberForm[#, 4, NumberPadding -> {\0\, \0\}]] & /@ Range[5] Out[1]= {file00001,file00002,file00003,file00004,file00005} Or if I wanted to export a list of things to a set of indexed files I would do MapIndexed[ Export[\file\ <> ToString[NumberForm[#2[[1]], 4, NumberPadding -> {\0\, \0\}]], #1, \Table\] &, data] Here, data is assumed to be a list of the things to export and is assumed to be less than 10000 items. === Subject: Label Bar Chart from data Given mydata={{44970, 2357.7}, {54324, 1859.34}, {49500, 1797.44}, {54161, 1432.26}, {49505, 1421.2}, {49605, 1292}, {54640, 1260}, {39503, 760}, {49525, 711.31}, {43324, 617.1}} This should be simple, but I can't seem to find the answer. I want a BarChart of the second values {2357.7, 1859.34,....}, labeled with the corresponding first value. This comes close, but all \bars' are labeled with 44970, not sequentially. ; BarChart[{#[[2]]} & /@ mydata, ChartLabels -> {#1} & /@ mydata] The actual data is much larger, precluding simply entering the ten values given above. Can someone point me in the right direction? === Subject: Re: Label Bar Chart from data may be that BarChart[#[[2]] & /@ mydata, ChartLabels -> (#[[1]] & /@ mydata)] helps Jens > Given > > mydata={{44970, 2357.7}, {54324, 1859.34}, {49500, 1797.44}, {54161, > 1432.26}, {49505, 1421.2}, {49605, 1292}, {54640, 1260}, {39503, > 760}, {49525, 711.31}, {43324, 617.1}} > > This should be simple, but I can't seem to find the answer. I want a > BarChart of the second values {2357.7, 1859.34,....}, labeled with the > corresponding first value. This comes close, but all \bars' are > labeled with 44970, not sequentially. > ; > BarChart[{#[[2]]} & /@ mydata, ChartLabels -> {#1} & /@ mydata] > > The actual data is much larger, precluding simply entering the ten > values given above. Can someone point me in the right direction? > > === Subject: GuiKit, seeking some guidance and comments I am considering porting my palette to GuiKit in a few months. Hey, I need to enjoy using my palette for awhile doing math right. ;-) What do you long time users of Mathematica think of GuiKit? What is its strengths and weakness, is it worth mastering as preparing for the future of Mathematica? How is the best way to learn GuiKit, what are the best examples of GuiKit to be studied? How polished and stable is GuiKit? Andrew === Subject: Re: second simple problem >> I have the following list: >> ex={1,5,7,4,\M\,6,7,8,9,1,\M\,3} >> I want to replace the M's in the following way: the first M by 5, and the \ second by2. >> Thus I have a replacement list >> rL={5,2} >> The problem is to get ={1,5,7,4,5,6,7,8,9,1,2,3} >> How can I do this in the most general form (for any length of ex and any \ number of values of \M\)? >> Francisco >> > Hi Francisco, > sorry for not answering. > Can anyone please explain, why the \obvious\ > Fold[Replace[#1, \M\ -> #2] &, ex, {a, b}] > leads to an unchanged \ex\? It is nearly 3 am and I guess it is better \ to go > to sleep, than to try to solve this one. Hi Peter, You fell into the mistake of thinking that Replace will replace only the first match in a list. The difference between Replace and ReplaceAll is that Replace works on the whole expression by default, and not on any subparts. We can tell it to work at a specific depth, e.g. Replace[list, a->b, {1}] replaces elements of the list, but this will replace *all* elements of list that match. I cannot remember if there is a function/syntax that replaces only the first element found, and I cannot find one in the docs right now. If you discover a simple way to do that, please let me know! Perhaps we can use Replace[#1, {be___, \M\, en___} :> {be, #2, en}] &, but that is rather ugly. === Subject: Re: Question about filenames for Export[...] > I'm using Mathematica 6. > I'd like to know how to define a file name (to be later used in Export) so \ > that the file name contains the value of an index variable i. > To exemplify, in Fortran this task would be accomplished by something \ like: > > character(len) :: FileName > ... > write(FileName,'(A,I4.4)') 'MyName', i > > These lines would produce filenames which, for i=1,2,... are MyName0001, > MyName0002, ... > > Is there any neat way of doing the same with Mathematica? > StringJoin[\MyName\,ToString[i]] or short: \MyName\<>ToString[i] depending on how many indices you need, maybe something like this is more convenient: ToString[StringForm[\MyName`1`-`2`-`3`-`4`\,i,j,k,l]] hth, albert === Subject: Re: Question about filenames for Export[...] > I'm using Mathematica 6. > I'd like to know how to define a file name (to be later used in Export) so \ > that the file name contains the value of an index variable i. > To exemplify, in Fortran this task would be accomplished by something \ like: > > character(len) :: FileName > ... > write(FileName,'(A,I4.4)') 'MyName', i > > These lines would produce filenames which, for i=1,2,... are MyName0001, > MyName0002, ... > I'd also like to know if there is a \neat\ way to achieve this. The way I've been using was not that pretty ... makeFileName[i_Integer] := \prefix\ <> ToString@PaddedForm[i, 4, NumberPadding -> \0\] What I hate about this is that it adds an extra zero ... See what makeFileName[12345] outputs. Another way is makeFileName2[i_] := \prefix\ <> ToString /@ IntegerDigits[i, 10, 5] But do we really need to do so much work---breaking the number into digits---for something so simple? === Subject: Re: Question about filenames for Export[...] here is one of many possible solutions: Table[StringForm[\FullPath/No``.dat\, i], {i, 1, 5}] here is a slightly more complex solution: Table[\FullPath/MyName\ <> ToString[NumberForm[i, 3, NumberPadding -> \0\]] <> \.dat\, {i, 8,12}] Daniel > I'm using Mathematica 6. > I'd like to know how to define a file name (to be later used in Export) so \ > that the file name contains the value of an index variable i. > To exemplify, in Fortran this task would be accomplished by something \ like: > > character(len) :: FileName > ... > write(FileName,'(A,I4.4)') 'MyName', i > > These lines would produce filenames which, for i=1,2,... are MyName0001, > MyName0002, ... > > Is there any neat way of doing the same with Mathematica? > > Lorenzo > > > === Subject: Re: Question about filenames for Export[...] Table[\MyName\<>ToString[PaddedForm[i,3,NumberPadding->{\0\,\0\}]],{i,\ 0,10}] ? Jens > I'm using Mathematica 6. > I'd like to know how to define a file name (to be later used in Export) so \ > that the file name contains the value of an index variable i. > To exemplify, in Fortran this task would be accomplished by something \ like: > > character(len) :: FileName > ... > write(FileName,'(A,I4.4)') 'MyName', i > > These lines would produce filenames which, for i=1,2,... are MyName0001, > MyName0002, ... > > Is there any neat way of doing the same with Mathematica? > > Lorenzo > > > === Subject: Re: Question about filenames for Export[...] Hi Lorentzo, Here are some possibilities; replace 27 with your number or variable. \MyName\ <> StringDrop[ToString[10000 + #], 1] & @ 27 StringReplacePart[\MyName0000\, #, {-StringLength[#], -1}] &@ ToString@27 \MyName\ <> ToString[PaddedForm[27, 4, NumberPadding -> \0\, NumberSigns -> {\\, \\}]] \MyName\ <> ToString[PaddedForm[27, 3, NumberPadding -> \0\]] > I'm using Mathematica 6. > I'd like to know how to define a file name (to be later used in Export) \ s= o > that the file name contains the value of an index variable i. > To exemplify, in Fortran this task would be accomplished by something \ lik= e: > > character(len) :: FileName > ... > write(FileName,'(A,I4.4)') 'MyName', i > > These lines would produce filenames which, for i=1,2,... are MyName0001= , > MyName0002, ... > > Is there any neat way of doing the same with Mathematica? > > Lorenzo === Subject: Re: Question about filenames for Export[...] > I'm using Mathematica 6. > I'd like to know how to define a file name (to be later used in Export) \ so > that the file name contains the value of an index variable i. > To exemplify, in Fortran this task would be accomplished by something \ like: > > character(len) :: FileName > ... > write(FileName,'(A,I4.4)') 'MyName', i > > These lines would produce filenames which, for i=1,2,... are MyName0001, > MyName0002, ... > > Is there any neat way of doing the same with Mathematica? > > Lorenzo Wonder how many different solutions this question will generate? One way is to use IntegerString and StringJoin in something like: i = 1; filename = StringJoin[\MyName\, IntegerString[i, 10, 4]] HTH... -Bob === Subject: Re: Palette Management > Andrew, I am curious: how did you input all the native Mathematica names \ if > you did not use Mathematica itself to give you the names? > I mean: if you did not use > > Names[\System`*\] > > to get the names (and then create the palette), how did you do it? -- LOL The hard, ill-informed way by OCR-ing pdf out put from the Function Navigator; then later the index page from on-line via copy/ paste. Uggh, Had I known about Names earlier. :-( Btw, the Doc help browser failed to find anything using \Function Names\ (683 hits), but no 'Names'. I am convinced the indexing for Help browser is poor; hence, having the PDFs for deep searching is wonderful. There should be a testing suite for searching within the Help Browser for completeness. I hate wasting my efforts, but eventually I got there. Sigh. === Subject: Re: export Disdyakis Dodecahedron to 3D model (maya) How about Export[\C:\\\\Users\\\\Francois Bonnard\\\\Documents\\\\Math\\\\DisdyakisDodecahedron.ma\, PolyhedronData[\DisdyakisDodecahedron\], \Maya\] ? Any more problem?? Ingolf Dahl -----Original Message----- === Subject: export Disdyakis Dodecahedron to 3D model (maya) I would like to find a partner for a isohedron project. My location is France (Normandy) :-) === Subject: barchart labeling Hi Two commands issued from the documentation center in labeling Barchart No difference in the reuslting plots ! ? BarChart[{1, 2, 3}, LabelingFunction -> Automatic] BarChart[{1, 2, 3}, LabelingFunction -> None] Alain Mazure Laboratoire d'Astrophysique de Marseille P=F4le de l'=C9toile Site de Ch=E2teau-Gombert 38, rue Fr=E9d=E9ric Joliot-Curie 13388 Marseille cedex 13, France http://alain.mazure.free.fr/ Mails: alain.mazure@oamp.fr alain.mazure@free.fr Phones: Lab: 33(0)491055902 Mobile: 33(0)603556287 Fax: 33(0)491661855 SKYPE: MAZURE-ALAIN === Subject: Re: Optimize speed of plotting mesh Hi! > and ContourPlot3D[] doesn not > accept data on a regular grid anymore ? > and your \coordinates\ generation is complete useless. Why? I have forgotten to say, that the mesh-File just consists of a list of mesh-values and the construction scheme for the corresponding coordinates. Yours Wolfgang === Subject: Re: Matrix Minimization you may minimize a real scalar but not a matrix. However, what you can do is to minimize some measure like a Norm of the matrix. Towards this aim, you will have to calculate e.g. Norm[] and then minimize it. Daniel > Hi , > > i would like to minimize the following matrix M with respect to A. > > M= E_X + A E_S A' + A E_P A' E_X H' +A E_S H' > H E_X + H E_S A' H E_X H' + H E_S H' + E_Q > > where E_X, E_S, E_P and E_Q are covariance matrices.. > > can we do matrix optimization in mathematica? > > === Subject: Re: Matrix Minimization > > you may minimize a real scalar but not a matrix. However, what you can > > do is to minimize some measure like a Norm of the matrix. > > Towards this aim, you will have to calculate e.g. Norm[] and then > > minimize it. > > Daniel > > > Hi , > > > i would like to minimize the following matrix M with respect to A. > > > M= E_X + A E_S A' + A E_P A' E_X H' +A E_S H' > > H E_X + H E_S A' H E_X H= ' + H E_S H' + E_Q > > > where E_X, E_S, E_P and E_Q are covariance matrices.. > > > can we do matrix optimization in mathematica? > Hi Daniel, sorry for my mistake. i want to optimize log det (M) with respect to A. can i use mathematica for that? === Subject: Selt-test error Good morning, Launching Mathematica generates this error message in a systematic manner: INTERNAL SELF-TEST ERROR: MacFont|c|818 If the application is shut down and relaunched, then it does not start and crashes. Could it be a font issue ? $Version \7.0 for Mac OS X x86 (64-bit) (February 19, 2009)\ === Subject: Re: second simple problem - Follow-up It just came to my mind that another semantics may be more useful: we can isolate the rule so that it can be used in all replacement \ functions. In[1] = Clear[oneTimeRule]; oneTimeRule[rule : (_RuleDelayed | _Rule)] := Module[{used = False}, rule /. (head : (RuleDelayed | Rule))[lhs_, rhs_] :> head[lhs /; ! used && (used = True), rhs]]; In[2] = Range[4, 10] /. oneTimeRule[x_?OddQ -> 100] Out[2] = {4, 100, 6, 7, 8, 9, 10} In[3] = Range[4, 10] /. oneTimeRule[x_?OddQ :> x^2] Out[3] = {4, 25, 6, 7, 8, 9, 10} In[4] = {2, 3, {4, 5, 6, 7, 8}} /. oneTimeRule[x_?OddQ :> x^2] Out[4] = {2, 9, {4, 5, 6, 7, 8}} In[5] = Replace[{2, 3, {4, 5, 6, 7, 8}}, oneTimeRule[x_?OddQ :> x^2], {2}] Out[5] = {2, 3, {4, 25, 6, 7, 8}} Leonid 2009/5/13 Szabolcs Horv=E1t > >> I have the following list: > >> ex={1,5,7,4,\M\,6,7,8,9,1,\M\,3} > >> I want to replace the M's in the following way: the first M by 5, and > the second by2. > >> Thus I have a replacement list > >> rL={5,2} > >> The problem is to get ={1,5,7,4,5,6,7,8,9,1,2,3} > >> How can I do this in the most general form (for any length of ex and a \ ny > number of values of \M\)? > >> Francisco > >> > > Hi Francisco, > > sorry for not answering. > > Can anyone please explain, why the \obvious\ > > Fold[Replace[#1, \M\ -> #2] &, ex, {a, b}] > > leads to an unchanged \ex\? It is nearly 3 am and I guess it is better \ to > go > > to sleep, than to try to solve this one. > > Hi Peter, > > You fell into the mistake of thinking that Replace will replace only the > first match in a list. The difference between Replace and ReplaceAll is > that Replace works on the whole expression by default, and not on any > subparts. We can tell it to work at a specific depth, e.g. > Replace[list, a->b, {1}] replaces elements of the list, but this will > replace *all* elements of list that match. > > I cannot remember if there is a function/syntax that replaces only the > first element found, and I cannot find one in the docs right now. If > you discover a simple way to do that, please let me know! > > Perhaps we can use Replace[#1, {be___, \M\, en___} :> {be, #2, en}] &, > but that is rather ugly. > === Subject: Templates and menuitems hi, I am finally able to stick pretty templates into an ActionMenu: D1=HoldForm[Style[Plot,15][Placeholder[Style[\f\,12]],{Placeholder [Style[\x\,12]],Placeholder[Style[\Subscript[min, y]\,12]],Placeholder [Style[\Subscript[max, x]\,12]]}]]; ActionMenu[ \test\, { D1 :> NotebookApply[InputNotebook[], D1 // ToBoxes] } ] I need the style to enlarge the font size but I would like to do it smarter. Everything I try gets hung up on the Defer. I am looking to make something like this: stylPl[a]=Placeholder[Style[a,12] so I can change the size for all placeholders with one function/rule call. Andrew === Subject: Re: Introducing the Wolfram Mathematica Tutorial > But Spotlight isn't the only tool available on a Mac for doing > searches on a Mac. There are the Unix tools find and grep which > allow searches for any text in any file regardless of whether it > is part of an application package or not. Additionally, this can > be done from Mathematica itself using FindList with FileNames. > And all of this works just fine with notebooks. In fact, since > notebooks are ASCII files, these tools work better with > notebooks than PDF files. Many of the documentation notebooks in Mathematica seem to open with many of their cells closed, and in a \paged\ mode (you only see one page on screen, so far as I can tell, and have to jump from page to page, rather than scrolling continuously). So do these various tools find stuff in closed cells? And if you're viewing some documentation notebook on screen and do a search, willl these tools open the closed cell for each hit, and let you jump down through all the pages and see all the hits using, for example, the key combo Cmd-G? (which is a fairly widely used standard for \Find Next\ in many other situations). === Subject: Introducing Wolfram Mathematica Solutions web pages Today's Mathematica technology provides unique solutions for many different industry sectors. See our new Wolfram Mathematica Solutions web pages to learn how Mathematica can benefit you in your field: http://www.wolfram.com/solutions Fifteen pages are now available--fourteen for Industry and one for Technology--with many more to come: * Chemical Engineering * Image Processing * Materials Science * Mechanical Engineering * Petroleum Engineering * Bioinformatics * Actuarial Sciences * Data Analysis and Mining * Financial Risk Management * Statistics * Software Engineering * Biological Sciences * Environmental Sciences * Geosciences * High-Performance and Parallel Computing (HPC) Feel free to give your feedback on how you plan to use these valuable tools and which fields you'd like to see added in the future. For more information, visit: http://www.wolfram.com/solutions === Subject: number dot (with space) Hi guys, sorry for the silly question (I am a Mathematica dummy). I have integrated out an expression, and I do not know how to interpret the term like this: (-1. g + r)^4) What throws me off is \1. g\ (g is a parameter), what is that dot after \ one and there is also a SPACE after the dot and before \g\ symbol. Sometimes \ I get smth. like \1. r\ what is that supposed to mean? If r=2, then how to === Subject: Re: Focus ring for controls > I find no examples or docs on setting or showing any focus ring for > controls. In my case, I am wanting to set the color of border of > buttons and ActionMenus (the main btn not the menuitems). Anyone? Is > this even doable? In general, user interface elements in Mathematica are not keyboard navigable. They probably should be. Please send your feedback to Wolfram tech support to help Wolfram Research prioritize these enhancements. http://support.wolfram.com/submitabug.cgi -Rob === Subject: Re: GuiKit, seeking some guidance and comments > I am considering porting my palette to GuiKit in a few months. Hey, I > need to enjoy using my palette for awhile doing math right. ;-) > What do you long time users of Mathematica think of GuiKit? What is > its strengths and weakness, is it worth mastering as preparing for the > future of Mathematica? How is the best way to learn GuiKit, what are > the best examples of GuiKit to be studied? How polished and stable is > GuiKit? GUIKit is the Mathematica 5 way of doing user interfaces. Mathematica 6-7 have support for building user interfaces which are better integrated with the rest of the system. GUIKit should still work, and if it does exactly what you want go ahead and use it. You should keep in mind that Wolfram Research's development resources are likely to be focused more on the Mathematica 6 integrated user interface features than on the old GUIKit features. If you find the integrated user interface support lacks features (found in GUIKit or elsewhere) please send your feedback to Wolfram tech support. -Rob === Subject: Re: Assign new values to matrix using indices The solution from Jens has the merit of being relatively short and clear. However it makes use of If statements to identify lower triangular matrix elements. Assuming that we would like to use any set of indices (e.g. derived from alternate criteria) and, thinking about it a little more, a general method for such assignments could be the following. In[38]:= m = {{a, b, c}, {d, e, f}, {h, i, j}}; ind = {{2, 1}, {3, 1}, {3, 2}}; Scan[Set[m[[#[[1]], #[[2]]]], m[[#[[1]], #[[2]]]]/2] &, ind] m Out[41]= {{a, b, c}, {d/2, e, f}, {h/2, i/2, j}} Mac On May 13, 12:19 pm, Jens-Peer Kuska > > with > > m = {{a, b, c}, {d, e, f}, {h, i, j}}; > > try > > MapIndexed[If[Greater @@ #2, #1/2, #1] &, m, {2}] > > Jens > > > This simple problem has got me confounded (despite 2 years of > > Mathematica experience). Say I would like to divide all lower diagonal > > elements of a matrix by 2. It is fairly easy to generate a list of > > indices, here an example for 3 by 3 matrix > > > In[120]:= > > Table[{j, i}, {j, 2, cdim = 3}, {i, 1, j - 1}] // Flatten[#, 1] & > > > Out[120]= {{2, 1}, {3, 1}, {3, 2}} > > > Now if I would like to divide the elements of a 3 x 3 matrix by 2, I > > don't know how to do this. The problem is the complex interplay of Part > > [], Set[] and Apply[]. To set the elements of hte matrix I can do > > this > > > In[219]:= t2 = {{0, 0, 0}, {2, 0, 0}, {2, 2, 0}}; > > f = Function[{x}, Apply[Set[Part[t2, ##], 1] &, x]]; > > Scan[f, {{2, 1}, {3, 1}, {3, 2}}] > > t2 > > > Out[222]= {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}} > > > which seems complicated for a simple operation. However, to divide all > > elements with indices given in the form above i.e. {{2, 1}, {3, 1}, > > {3, 2}} by 2 has got me stumped. > > > Any help would be appreciated > > > Mac === Subject: Re: Assign new values to matrix using indices I think Jens-Peer's method is the easiest, but for the sake of \diversity\ here is a very different one: m = {{a, b, c}, {d, e, f}, {h, i, j}}; Normal[SparseArray[{{i_, j_} /; i > j :> m[[i, j]]/2, {i_, j_} /; i <= j :> m[[i, j]]}, Dimensions[m]]] > > with > > m = {{a, b, c}, {d, e, f}, {h, i, j}}; > > try > > MapIndexed[If[Greater @@ #2, #1/2, #1] &, m, {2}] > > Jens > >> This simple problem has got me confounded (despite 2 years of >> Mathematica experience). Say I would like to divide all lower >> diagonal >> elements of a matrix by 2. It is fairly easy to generate a list of >> indices, here an example for 3 by 3 matrix >> >> In[120]:= >> Table[{j, i}, {j, 2, cdim = 3}, {i, 1, j - 1}] // Flatten[#, 1] & >> >> Out[120]= {{2, 1}, {3, 1}, {3, 2}} >> >> Now if I would like to divide the elements of a 3 x 3 matrix by 2, I >> don't know how to do this. The problem is the complex interplay of >> Part >> [], Set[] and Apply[]. To set the elements of hte matrix I can do >> this >> >> In[219]:= t2 = {{0, 0, 0}, {2, 0, 0}, {2, 2, 0}}; >> f = Function[{x}, Apply[Set[Part[t2, ##], 1] &, x]]; >> Scan[f, {{2, 1}, {3, 1}, {3, 2}}] >> t2 >> >> Out[222]= {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}} >> >> which seems complicated for a simple operation. However, to divide >> all >> elements with indices given in the form above i.e. {{2, 1}, {3, 1}, >> {3, 2}} by 2 has got me stumped. >> >> Any help would be appreciated >> >> Mac >> > === Subject: Re: Assign new values to matrix using indices Hi Mac, With m your matrix, (m - LowerTriangularize[m, -1]/2) does the trick. > This simple problem has got me confounded (despite 2 years of > Mathematica experience). Say I would like to divide all lower diagonal > elements of a matrix by 2. It is fairly easy to generate a list of > indices, here an example for 3 by 3 matrix > > In[120]:= > Table[{j, i}, {j, 2, cdim = 3}, {i, 1, j - 1}] // Flatten[#, 1] & > > Out[120]= {{2, 1}, {3, 1}, {3, 2}} > > Now if I would like to divide the elements of a 3 x 3 matrix by 2, I > don't know how to do this. The problem is the complex interplay of Part > [], Set[] and Apply[]. To set the elements of hte matrix I can do > this > > In[219]:= t2 = {{0, 0, 0}, {2, 0, 0}, {2, 2, 0}}; > f = Function[{x}, Apply[Set[Part[t2, ##], 1] &, x]]; > Scan[f, {{2, 1}, {3, 1}, {3, 2}}] > t2 > > Out[222]= {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}} > > which seems complicated for a simple operation. However, to divide all > elements with indices given in the form above i.e. {{2, 1}, {3, 1}, > {3, 2}} by 2 has got me stumped. > > Any help would be appreciated > > Mac === Subject: Future for Mathematica on Solaris I was interested in purchasing a copy of Mathematica for Solaris, but have seen various things on the net suggesting the Solaris (and to a lesser extent linux) versions are more buggy than the Windows version. Looking on the Wolfram web site where one can request a trial http://www.wolfram.com/products/mathematica/experience/request.cgi I find one can't request a trail on Solaris from the web site. So I contacted Wolfram Research directly by email and asked about a 14-day save-disabled trail. I received a reply in a couple of days, telling me no trial version of Mathematica exists for Solaris. Given the Solaris version is more expensive than the windows one, there are various reports of bugs on Solaris, and one can't even get a trail version, it does beg the question whether Wolfram Research are serious about the future of Mathematica on Solaris. Peter === Subject: Re: Label Bar Chart from data Hi Charles, try e.g.: BarChart[mydata[[All, 2]], ChartLabels -> mydata[[All, 1]]] Daniel > Given > > mydata={{44970, 2357.7}, {54324, 1859.34}, {49500, 1797.44}, {54161, > 1432.26}, {49505, 1421.2}, {49605, 1292}, {54640, 1260}, {39503, > 760}, {49525, 711.31}, {43324, 617.1}} > > This should be simple, but I can't seem to find the answer. I want a > BarChart of the second values {2357.7, 1859.34,....}, labeled with the > corresponding first value. This comes close, but all \bars' are > labeled with 44970, not sequentially. > ; > BarChart[{#[[2]]} & /@ mydata, ChartLabels -> {#1} & /@ mydata] > > The actual data is much larger, precluding simply entering the ten > values given above. Can someone point me in the right direction? > > === Subject: Re: Label Bar Chart from data mydata = {{44970, 2357.7}, {54324, 1859.34}, {49500, 1797.44}, {54161, 1432.26}, {49505, 1421.2}, {49605, 1292}, {54640, 1260}, {39503, 760}, {49525, 711.31}, {43324, 617.1}}; BarChart[#[[2]] & /@ mydata, ChartLabels -> (#[[1]] & /@ mydata)] BarChart[Last /@ mydata, ChartLabels -> First /@ mydata] BarChart[Last /@ #, ChartLabels -> First /@ #] &[mydata] BarChart[mydata[[All, 2]], ChartLabels -> mydata[[All, 1]]] BarChart[#[[All, 2]], ChartLabels -> #[[All, 1]]] &[mydata] True However, to find anything on this chart by label (particularly if \actual \ data is much larger\), then sorting might be useful. sortedData = Sort[mydata]; BarChart[Last /@ #, ChartLabels -> First /@ #] &[sortedData] Bob Hanlon Given mydata={{44970, 2357.7}, {54324, 1859.34}, {49500, 1797.44}, {54161, 1432.26}, {49505, 1421.2}, {49605, 1292}, {54640, 1260}, {39503, 760}, {49525, 711.31}, {43324, 617.1}} This should be simple, but I can't seem to find the answer. I want a BarChart of the second values {2357.7, 1859.34,....}, labeled with the corresponding first value. This comes close, but all \bars' are labeled with 44970, not sequentially. ; BarChart[{#[[2]]} & /@ mydata, ChartLabels -> {#1} & /@ mydata] The actual data is much larger, precluding simply entering the ten values given above. Can someone point me in the right direction? -- Bob Hanlon === Subject: Re: barchart labeling Hoover your mouse over both bar charts and be enlightened. Sjoerd > Hi > > Two commands issued from the documentation center in labeling > Barchart > > No difference in the reuslting plots ! ? > > BarChart[{1, 2, 3}, LabelingFunction -> Automatic] > > BarChart[{1, 2, 3}, LabelingFunction -> None] > > Alain Mazure > > Laboratoire d'Astrophysique de Marseille > P=F4le de l'=C9toile Site de Ch=E2teau-Gombert > 38, rue Fr=E9d=E9ric Joliot-Curie > 13388 Marseille cedex 13, France > > http://alain.mazure.free.fr/ > > Mails: > alain.maz...@oamp.fr > alain.maz...@free.fr > > Phones: > Lab: 33(0)491055902 > Mobile: 33(0)603556287 > Fax: 33(0)491661855 > SKYPE: MAZURE-ALAIN === Subject: Re: barchart labeling The first one has tooltips. The second one has no labels. The following has printed labels above the bars: BarChart[{1, 2, 3}, LabelingFunction -> Above] David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ Hi Two commands issued from the documentation center in labeling Barchart No difference in the reuslting plots ! ? BarChart[{1, 2, 3}, LabelingFunction -> Automatic] BarChart[{1, 2, 3}, LabelingFunction -> None] Alain Mazure Laboratoire d'Astrophysique de Marseille P=F4le de l'=C9toile Site de Ch=E2teau-Gombert 38, rue Fr=E9d=E9ric Joliot-Curie 13388 Marseille cedex 13, France http://alain.mazure.free.fr/ Mails: alain.mazure@oamp.fr alain.mazure@free.fr Phones: Lab: 33(0)491055902 Mobile: 33(0)603556287 Fax: 33(0)491661855 SKYPE: MAZURE-ALAIN === Subject: Re: barchart labeling As stated in the documentation, this command displays values in Tooltips and \ in the StatusArea BarChart[{1, 2, 3}, LabelingFunction -> Automatic] This command has no Tooltips and values do not display in StatusArea BarChart[{1, 2, 3}, LabelingFunction -> None] This command has custom labels in Tooltips and the StatusArea BarChart[{1, 2, 3}, LabelingFunction -> (If[OddQ[#], \a\, \b\] &)] Bob Hanlon Hi Two commands issued from the documentation center in labeling Barchart No difference in the reuslting plots ! ? BarChart[{1, 2, 3}, LabelingFunction -> Automatic] BarChart[{1, 2, 3}, LabelingFunction -> None] Alain Mazure Laboratoire d'Astrophysique de Marseille P=F4le de l'=C9toile Site de Ch=E2teau-Gombert 38, rue Fr=E9d=E9ric Joliot-Curie 13388 Marseille cedex 13, France http://alain.mazure.free.fr/ Mails: alain.mazure@oamp.fr alain.mazure@free.fr Phones: Lab: 33(0)491055902 Mobile: 33(0)603556287 Fax: 33(0)491661855 SKYPE: MAZURE-ALAIN === Subject: Re: Question about filenames for Export[...] The extra 0 is because of the position for the invisible plus sign in positive numbers. Use NumberSigns -> {\\, \\} if you want to remove them. > > I'm using Mathematica 6. > > I'd like to know how to define a file name (to be later used in \ Export)= so > > that the file name contains the value of an index variable i. > > To exemplify, in Fortran this task would be accomplished by something \ l= ike: > > > character(len) :: FileName > > ... > > write(FileName,'(A,I4.4)') 'MyName', i > > > These lines would produce filenames which, for i=1,2,... are MyName00= 01, > > MyName0002, ... > > I'd also like to know if there is a \neat\ way to achieve this. The \ wa= y > I've been using was not that pretty ... > > makeFileName[i_Integer] := > \prefix\ <> ToString@PaddedForm[i, 4, NumberPadding -> \0\] > > What I hate about this is that it adds an extra zero ... See what > makeFileName[12345] outputs. > > Another way is > > makeFileName2[i_] := \prefix\ <> ToString /@ IntegerDigits[i, 10, 5] > > But do we really need to do so much work---breaking the number into > digits---for something so simple? === Subject: Re: Question about filenames for Export[...] Nice, IntegerString had crossed the border below my radar. > > > > > I'm using Mathematica 6. > > I'd like to know how to define a file name (to be later used in \ Export)= so > > that the file name contains the value of an index variable i. > > To exemplify, in Fortran this task would be accomplished by something \ l= ike: > > > character(len) :: FileName > > ... > > write(FileName,'(A,I4.4)') 'MyName', i > > > These lines would produce filenames which, for i=1,2,... are MyName00= 01, > > MyName0002, ... > > > Is there any neat way of doing the same with Mathematica? > > > Lorenzo > > Wonder how many different solutions this question will generate? > > One way is to use IntegerString and StringJoin in something like: > > i = 1; > filename = StringJoin[\MyName\, IntegerString[i, 10, 4]] > > HTH... > > -Bob === Subject: Re: second simple problem Hi Szabolcs, >I cannot remember if there is a function/syntax that replaces only the >first element found, and I cannot find one in the docs right now. If >you discover a simple way to do that, please let me know! One way is to define our own single-replacement function, like this: In[1] = Clear[replaceOnce]; replaceOnce[expr_, rule : (_RuleDelayed | _Rule)] := With[{onceonly = Module[{used = False}, rule /. (head : (RuleDelayed | Rule))[lhs_, rhs_] :> head[lhs /; ! used && (used = True), rhs]]}, expr /. onceonly]; In[2] = replaceOnce[Range[4, 10], x_?OddQ :> x^2] Out[2] = {4, 25, 6, 7, 8, 9, 10} In[3] = replaceOnce[Range[4, 10], x_?OddQ -> 100] Out[3] = {4, 100, 6, 7, 8, 9, 10} This does induce some overhead though. Also, I did not test it extensively enough to be sure that it will always work. Leonid 2009/5/13 Szabolcs Horv=E1t > >> I have the following list: > >> ex={1,5,7,4,\M\,6,7,8,9,1,\M\,3} > >> I want to replace the M's in the following way: the first M by 5, and > the second by2. > >> Thus I have a replacement list > >> rL={5,2} > >> The problem is to get ={1,5,7,4,5,6,7,8,9,1,2,3} > >> How can I do this in the most general form (for any length of ex and \ a= ny > number of values of \M\)? > >> Francisco > >> > > Hi Francisco, > > sorry for not answering. > > Can anyone please explain, why the \obvious\ > > Fold[Replace[#1, \M\ -> #2] &, ex, {a, b}] > > leads to an unchanged \ex\? It is nearly 3 am and I guess it is better \ = to > go > > to sleep, than to try to solve this one. > > Hi Peter, > > You fell into the mistake of thinking that Replace will replace only the > first match in a list. The difference between Replace and ReplaceAll is > that Replace works on the whole expression by default, and not on any > subparts. We can tell it to work at a specific depth, e.g. > Replace[list, a->b, {1}] replaces elements of the list, but this will > replace *all* elements of list that match. > > I cannot remember if there is a function/syntax that replaces only the > first element found, and I cannot find one in the docs right now. If > you discover a simple way to do that, please let me know! > > Perhaps we can use Replace[#1, {be___, \M\, en___} :> {be, #2, en}] &, > but that is rather ugly. > > === Subject: Heatmap I was wondering if there is any function in Mathematica for heatmaps? http://en.wikipedia.org/wiki/Heat_map Any help would be much appreciated! Ashutosh. === Subject: Re: barchart labeling >Two commands issued from the documentation center in labeling >Barchart >No difference in the reuslting plots ! ? >BarChart[{1, 2, 3}, LabelingFunction -> Automatic] >BarChart[{1, 2, 3}, LabelingFunction -> None] There is a difference that will only become apparent when your cursor is positioned over the bars in the plot. With the Automatic setting, a label will appear when the cursor is positioned over a bar. With the None setting nothing happens. And this is precisely what is supposed to happen according to the documentation for LablingFunction. === Subject: Re: Question about filenames for Export[...] >I'd also like to know if there is a \neat\ way to achieve this. The >way I've been using was not that pretty ... >makeFileName[i_Integer] := >\prefix\ <> ToString@PaddedForm[i, 4, NumberPadding -> \0\] I typically use NumberForm rather than PaddedForm. But I don't think this difference would meet your criteria for \neat\ >What I hate about this is that it adds an extra zero ... See what >makeFileName[12345] outputs. There is an \extra\ space associated with positive numbers which is replace by zero. Since this always happens for positive numbers, there is a simple way to get rid of the extra zero. Changing your function above to: makeFileName[i_Integer] := \prefix\ <> StringDrop[ToString@PaddedForm[i, 4, NumberPadding -> \0\],1] or makeFileName[i_Integer] := \prefix\ <> StringTake[ToString@PaddedForm[i, 4, NumberPadding -> \0\],-4] will get rid of the extra zero. === Subject: Mathematica 7 - Miscellaneous`RealOnly` The above package no longer exists in Mathematica 7 and must be downloaded. Then to use the feature it seems there must be additional code entered to turn off certain warnings. It's an annoyance. When graphing functions such as f(x) = x^(1/3) is there a workaround to get the full graph, -inf from Mathematica 7. The device basically streams data in hex format > and I would like to do a FFT on the data as it streams in. > Unfortunately in OS X it doesn't show up when I run > ControllerInformation[] and in Windows with the driver installed it > shows up but doesn't show any available controls. What options do I > have to get the data into Mathematica if it won't automatically read > this device? I believe Java would be the easiest but I don't know of > any good USB API's for OSX, leaving me with C which seems to be a bit > more complicated to integrate with Mathematica. Any suggestions? If the device does not conform to the USB HID specification, Mathematica will not be able to communicate with it via the ControllerState[] mechanism. Your only option would be to write a C/C+ +/Java MathLink program to bridge the device to Mathematica. -Rob === Subject: Re: Mathematica 7 - Miscellaneous`RealOnly` Clear[f]; f[x_] = x^(1/3); Plot[Sign[x] Abs[f[x]], {x, -10, 10}] However, if this graph represents the function that you want, then the \ function definition should be similar to Clear[f]; f[x_] = Sign[x] Abs[x]^(1/3); Plot[f[x], {x, -10, 10}] Bob Hanlon The above package no longer exists in Mathematica 7 and must be downloaded. Then to use the feature it seems there must be additional code entered to turn off certain warnings. It's an annoyance. When graphing functions such as f(x) = x^(1/3) is there a workaround to get the full graph, -inf \Month\ list1 appears to be the High for the first > trading day of each month ... rather than the high > during each month. doesn't match the actual behavior. What one sees is that in each case of these non-day periods (Month, Year) for queries of this sort of data, the DATE reported with the result is the earliest Mod(Period) relevant day. Compare the DATES for these: FinancialData[\AAPL\, \High\, {{2005}, {2006}, \Month\}] FinancialData[\AAPL\, \High\, {{2005}, {2006}, \Year\}] (\Relevant\ is important here ... for \Return\, which works close-to-close, the first relevant date would be the second close of trading which the operator works against. Now, I'm not saying this is a reasonable behavior ... revealing the mechanics of the operation to the semantics of the operator, and in the process nullifying consistent use of the date range. In fact I think it unreasonable and clunky.) As a counter-example to this Mod(Period) theory, consider \Dividend\ with \Month\ or \Year\ ... which does provide a date other than the Mod(Period) and consistently. And necessarily, btw, otherwise you couldn't use the results to reconstruct events. This is not a necessary condition for \High\ or \Return\. In any case, this date issue is an ancillary confusion. I agree, it is a confusion, one that should be more- clearly documented. And fixed. Actually, it's a bit more than just confusing, since it limits the methods for processing such data. That is, if you want the ACTUAL (first) date for the months high, you cannot use the result, but must process the day results. That is in part why getting different VALUES is troublesome (esp, say, if you might look for more than one case of that HIGH in a month or year ... for that you need consistency and comparability in the value). The real issue in my question is the (apparently) disjoint sets of source data VALUEs. Compare \Raw\ to \RawHigh\: FinancialData[\GE\, \RawHigh\, {{2005}, {2006}, \Month\}] FinancialData[\GE\, \RawHigh\, {{2005, 1, 1}, {2005, 2, 1}}] Now, fine, these produce a set of values different than \High\; that's expected -- it is a different (unadjusted) source set. The two \Raw\ operators appear to work from the same source set: the VALUE of the highs match. So maybe the challenge with \High\ concerns the adjustments. But here's the thing: 1. One can't explain the difference I report simply from High vs RawHigh ... as \Dividend\ (correctly) doesn't report any for that period, there was no split, and to me it's mysterious what \related changes\ could > \For historical data, properties such as \High\, > \Low\, \Close\ are adjusted for stock splits, > dividends and related changes.\ 2. But even a cause found in (1.) would still be troublesome. Both queries are (apparently) for the same range of trading days, one is grouped by day, the other month. Wouldn't we expect the same adjustment to apply? So, does the difference come from a difference in source sets (why?), or in normalization of some sort (what?)? Or some other cause, including operator error? ... Your specific observation about the Feb 1, 2005, results concerns the vagaries of the current design of period operators, not the difference of the results. When using \Month\ or \Year\ you'll end up with with a result for the period using as many dates as selected by the date range. Here, 1 day. (The same effect occurs from the starting date too: try on the 14th.) Again, I think that's not very clear ... and not very sensible, too: when one switches to periods, aggregates or clusters, the semantics of time (ranges or otherwise) also changes. Or should change. But they don't in this case. But indeed you have found another case of the error I asked about. > FinancialData[\GE\, \High\, {{2005}, {2006}, \Month\}] > ... {{2005, 2, 1}, 31.160102272727272}, ... Compare: FinancialData[\GE\, \High\, {{2005, 2, 1}, {2005, 3, 1}}] ... {{2005, 2, 15}, 30.9661}, ... If one compares to other datasets, adjusting for dividends and splits, this 30.9661 is a reasonable, close-enough, adjusted high. It is on the right date by any account. I cannot account for that 31.16. results for the (apparently) same query from the same time frame?) with the related question: What difference in operation would produce 31.16, which is a comparatively large difference/error? Could one (weird) explanation for both could be that the starting basis is different for different \period\ queries? E.g.: Year uses a different starting basis than Month, and both are different than day, the default? --N > list1 = FinancialData[\GE\, \High\, {{2005}, {2006}, \Month\}] > > {{{2005, 1, 3}, 31.20283420979795}, > {{2005, 2, 1}, 31.160102272727272}, > {{2005, 3, 1}, 31.05757071547421}, ... > > list1 appears to be the High for the first trading day > of each month in 2005 rather than the high during each month. > > list2 = FinancialData[\GE\, \High\, {{2005, 1, 1}, {2005, 2, 1}}] > > {{{2005, 1, 3}, 31.203757857338065}, > {{2005, 1, 4}, 31.172143845089906}, > {{2005, 1, 5}, 30.74689674366825}, > {{2005, 1, 6}, 30.80918829376036}, ... > Monday {2005, 1, 17} was a US National holiday (MLK Birthday) > > list2 appears to be the Highs for each trading day in Jan > and the first trading day of Feb. > > The real oddity is that there are different values > for {2005, 2, 1} > > list1[[2]] > {{2005,2,1},31.1601} > > list2 // Last > {{2005,2,1},30.7746} > > Bob Hanlon > > > > I have a puzzle, probably easily explained; apparently so > easily that it hasn't even appeared here. > > > Give the monthly highs for a stock price over a range of dates: > > FinancialData[\GE\, \High\, {{2005}, {2006}, \Month\}] > > High is defined as: > High: Highest price during the trading day > > My guess, then, is that the source set is all intraday prices > for from start {2005,1,1} until end {2006,1,1}. > > Consequentially I expect that there will be an intersection > for January between that result and this result: > > FinancialData[\GE\, \High\, {{2005, 1, 1}, {2005, 2, 1}}] > > There is not. The maximum for the date range: > > Map[#[[2]] &, > FinancialData[\GE\, \High\, {{2005, 1, 1}, {2005, 2, 1}}]] // Max > > = 31.2038 > > While from the earlier \Month\ query we have > > = {{2005, 1, 3}, 31.2028} > > If one considers that the date-range version might have a superset > of times, and the high occured in that interregnum, then comparing > March's result will disappoint: the opposite occurs (the high appears > in the \Month\ result). > > If one wishes to explain this by precision effect during calculation, > although I find that dubious, consider that FoldList[] on \Return\ > will produce what \CumulativeReturn\ delivers. > > So, what's the simple explanation? > > --N > === Subject: Re: number dot (with space) The coefficient of g is approximately 1 and the space is implied multiplication of the inexact 1 times g. You will also sometimes get an approximate zero as a coefficient. expr = (-1. g + r)^4 (r - 1.*g)^4 expr // Rationalize (r - g)^4 Bob Hanlon > Hi guys, > sorry for the silly question (I am a Mathematica dummy). I have > integrated out an expression, and I do not know how to interpret the > term like this: > (-1. g + r)^4) > What throws me off is \1. g\ (g is a parameter), what is that dot > after one > and there is also a SPACE after the dot and before \g\ symbol. > Sometimes I > get smth. like \1. r\ what is that supposed to mean? If r=2, then how > to === Subject: Re: Heatmap data = RandomReal[{0, 1}, {10, 10}]; ArrayPlot[data] ArrayPlot[data, ColorFunction -> \Temperature\] ColorData[\Temperature\, \Image\] Bob Hanlon > I was wondering if there is any function in Mathematica for heatmaps? > http://en.wikipedia.org/wiki/Heat_map > > Any help would be much appreciated! > Ashutosh. === Subject: saving initialization cells as a .m file I have the following code which runs fine in a notebook: SuperDagger[A_List] := Conjugate[Transpose[A]] eqn = {f'[t] == -f[t]^\\[Dagger].f[t], f[0] == RandomReal[{0, 0.1}, {3, \ 3}]}; NDSolve[eqn, f, {t, 0, 10}] but when I save the first two lines (definition of SuperDagger and eqn) in a \ .m file and load them with a Get command, although Mathematica loads the \ definitions, NDSolve doesn't like the input and complains that derivative at \ t=0 is not defined. Weirdly if I copy and paste the output of NDSolve and \ evaluate it, it runs fine. Do you know how can I fix this? Baris Altunkaynak === Subject: Re: saving initialization cells as a .m file Hi Baris, f[t]^\\[Dagger] does not apply SuperDagger. You would have to say SuperDagger[f[t]] Daniel > > I have the following code which runs fine in a notebook: > > SuperDagger[A_List] := Conjugate[Transpose[A]] > eqn = {f'[t] == -f[t]^\\[Dagger].f[t], f[0] == RandomReal[{0, 0.1}, {3, \ 3}]}; > NDSolve[eqn, f, {t, 0, 10}] > > but when I save the first two lines (definition of SuperDagger and eqn) in \ a .m file and load them with a Get command, although Mathematica loads the \ definitions, NDSolve doesn't like the input and complains that derivative at \ t=0 is not defined. Weirdly if I copy and paste the output of NDSolve and \ evaluate it, it runs fine. Do you know how can I fix this? > > > > Baris Altunkaynak > > > > === Subject: Re: Introducing the Wolfram Mathematica Tutorial > > >> But Spotlight isn't the only tool available on a Mac for doing >> searches on a Mac. There are the Unix tools find and grep which >> allow searches for any text in any file regardless of whether it >> is part of an application package or not. Additionally, this can >> be done from Mathematica itself using FindList with FileNames. >> And all of this works just fine with notebooks. In fact, since >> notebooks are ASCII files, these tools work better with >> notebooks than PDF files. >> > Many of the documentation notebooks in Mathematica seem to open with > many of their cells closed, and in a \paged\ mode (you only see one \ page > on screen, so far as I can tell, and have to jump from page to page, > rather than scrolling continuously). > > So do these various tools find stuff in closed cells? > > And if you're viewing some documentation notebook on screen and do a > search, willl these tools open the closed cell for each hit, and let you > jump down through all the pages and see all the hits using, for example, > the key combo Cmd-G? (which is a fairly widely used standard for \Find > Next\ in many other situations). This absolutely works (both Command+G on the Mac and finding in closed \ groups). But this is something of an apples and oranges comparison. The PDFs are generated from the tutorial notebooks, which generally don't have the cell groups closed as you describe. I'm sure you're generally thinking of the function reference pages here. But your implication that closed cell groups are somehow immune to Find is \ not correct. I use this feature regularly, for example, to find all examples \ for a function which use a particular option. You are correct, of course, about the Find feature being limited to the scope of the existing documentation notebook. It won't find anything in separate documentation notebooks which are linked sequentially in the \ narrative. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. === Subject: Re: Bug with Hypergeometric2F1? not work the way I expected. I should have thought of the machine Irchans > When I run this code: > > vol1[n_, k_] = Sum[ Binomial[n, i], {i, 0, k}] > vol1[1000, 1] > vol1[1000, 1.] > > I get > > Out[1] = 1001 > > Out[2] = 7.12935*10^288 > > I am running Mathematica 7.0.0 on windows 2000. Does anyone else have > this problem? === Subject: Re: Is there a BNF for Mathematica? >I have been looking for a Backus-Naur Form grammar for Mathematica. Is > there one out there?? You can obtain one with the DMS Software Reengineering Toolkit. It handles the generic mathematica expressions, as well as the special forms that make up various means for definining functions, and the control structures. See http://www.semanticdesigns.com/Products/DMS/DMSToolkit.html Ira D. Baxter, CTO Semantic Designs, Inc. === Subject: Re: Heatmap a combination of ArrayPlot[] and DendrogramPlot[] should be abel to do \ that. Jens > I was wondering if there is any function in Mathematica for heatmaps? > http://en.wikipedia.org/wiki/Heat_map > > Any help would be much appreciated! > Ashutosh. > === Subject: Re: Heatmap I found the definition of a heat plot a bit unclear but it looks like an ArrayPlot or MatrixPlot with an appropriate ColorFunction may work. > I was wondering if there is any function in Mathematica for \ heatmaps?http= ://en.wikipedia.org/wiki/Heat_map > > Any help would be much appreciated! > Ashutosh. === Subject: Re: Heatmap look up DensityPlot or ContourPlot. You may eventually want to use the option ColorFunction. Daniel > I was wondering if there is any function in Mathematica for heatmaps? > http://en.wikipedia.org/wiki/Heat_map > > Any help would be much appreciated! > Ashutosh. > === Subject: Re: number dot (with space) The space is just a multiplication just as in x y. So 1. g equals 1 (an approximate numerical result) times g. On May 14, 7:40 am, Emin Gahramanov > Hi guys, > sorry for the silly question (I am a Mathematica dummy). I have \ integrated > out an expression, and I do not know how to interpret the term like this: > (-1. g + r)^4) > What throws me off is \1. g\ (g is a parameter), what is that dot after \ one > and there is also a SPACE after the dot and before \g\ symbol. \ Sometimes I > get smth. like \1. r\ what is that supposed to mean? If r=2, then how \ to === Subject: Re: number dot (with space) you have given an floating point number and not an exact one (1. instead of 1 or 0.5 instead of 1/2). Floating point numbers have a finite precision, so that 1.*g is not the same as 1*g. Since Mathematica does not print the multiplication symbol \*\ and uses a space instead to print a*b*c and a b c the multiplication 1.*g is printed as 1. g Jens > Hi guys, > sorry for the silly question (I am a Mathematica dummy). I have integrated \ > out an expression, and I do not know how to interpret the term like this: > (-1. g + r)^4) > What throws me off is \1. g\ (g is a parameter), what is that dot after \ one > and there is also a SPACE after the dot and before \g\ symbol. \ Sometimes I > get smth. like \1. r\ what is that supposed to mean? If r=2, then how \ to > === Subject: Re: number dot (with space) Probably you had a decimal somewhere in your expression, and the result of the integration produces a result that involves -1 (as a decimal) times g. > Hi guys, > sorry for the silly question (I am a Mathematica dummy). I have integrated \ > out an expression, and I do not know how to interpret the term like this: > (-1. g + r)^4) > What throws me off is \1. g\ (g is a parameter), what is that dot after \ one > and there is also a SPACE after the dot and before \g\ symbol. \ Sometimes I > get smth. like \1. r\ what is that supposed to mean? If r=2, then how \ to > -- 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: number dot (with space) > Hi guys, > sorry for the silly question (I am a Mathematica dummy). I have integrated \ > out an expression, and I do not know how to interpret the term like this: > (-1. g + r)^4) > What throws me off is \1. g\ (g is a parameter), what is that dot after \ one > and there is also a SPACE after the dot and before \g\ symbol. \ Sometimes I > get smth. like \1. r\ what is that supposed to mean? If r=2, then how \ to > It means -1.0*g. Avoid inexact numbers when doing symbolic calculations. Of course 1*g is just g, but in Mathematica 1.0 means 1 with a certain precision, not necessarily precisely 1. Use Rationalize to convert floating point numbers to rationals. === Subject: Re: number dot (with space) Hi Emin, \1.\ is an machine number with a limited precision. \1\ is an accurate number. Daniel > Hi guys, > sorry for the silly question (I am a Mathematica dummy). I have integrated \ > out an expression, and I do not know how to interpret the term like this: > (-1. g + r)^4) > What throws me off is \1. g\ (g is a parameter), what is that dot after \ one > and there is also a SPACE after the dot and before \g\ symbol. \ Sometimes I > get smth. like \1. r\ what is that supposed to mean? If r=2, then how \ to > === Subject: Re: number dot (with space) >Hi guys, sorry for the silly question (I am a Mathematica dummy). I >have integrated out an expression, and I do not know how to >interpret the term like this: (-1. g + r)^4) What throws me off is >\1. g\ (g is a parameter), what is that dot after one >and there is also a SPACE after the dot and before \g\ symbol. >Sometimes I get smth. like \1. r\ what is that supposed to mean? If The expression \1. g\ is the product of 1 and g. Mathematic uses a space in expressions like this to represent multiplication. The value 1. will be a machine precision number that isn't quite 1. For example, here is an operation that will generate an equivalent expression In[4]:= y = (1. + 1/10^8)*x Out[4]= 1. x And I can show the constant isn't quite 1 by doing In[5]:= y[[1]] - 1 Out[5]= 1.*10^-8 === Subject: Re: Heatmap >heatmaps? http://en.wikipedia.org/wiki/Heat_map The Mathematica functions for generating similar plots include DensityPlot, ContourPlot, ListDensityPlot and ListContourPLot. === Subject: Re: Mathematica 7 - Miscellaneous`RealOnly` > The above package no longer exists in Mathematica 7 and must be > downloaded. Then to use the feature it seems there must be additional > code entered to turn off certain warnings. It's an annoyance. When > graphing functions such as f(x) = x^(1/3) is there a workaround to get > the full graph, -inf f[x_] = Sign[x] Abs[x]^(1/3) Plot[f[x], {x, -10, 10}] And for x^(2/3): g[x_] = Abs[x]^(2/3) -- Helen Read University of Vermont === Subject: Re: Mathematica 7 - Miscellaneous`RealOnly` Plot[Abs[x^(1/3)] Sign[x], {x, -5, 5}] > The above package no longer exists in Mathematica 7 and must be > downloaded. Then to use the feature it seems there must be additional > code entered to turn off certain warnings. It's an annoyance. When > graphing functions such as f(x) = x^(1/3) is there a workaround to get > the full graph, -inf>But Spotlight isn't the only tool available on a Mac for doing >>searches on a Mac. There are the Unix tools find and grep which >>allow searches for any text in any file regardless of whether it is >>part of an application package or not. Additionally, this can be >>done from Mathematica itself using FindList with FileNames. And all >>of this works just fine with notebooks. In fact, since notebooks >>are ASCII files, these tools work better with notebooks than PDF >>files. >Many of the documentation notebooks in Mathematica seem to open with >many of their cells closed, and in a \paged\ mode (you only see one >page on screen, so far as I can tell, and have to jump from page to >page, rather than scrolling continuously). >So do these various tools find stuff in closed cells? Yes. >And if you're viewing some documentation notebook on screen and do a >search, willl these tools open the closed cell for each hit, and let >you jump down through all the pages and see all the hits using, for >example, the key combo Cmd-G? (which is a fairly widely used >standard for \Find Next\ in many other situations). No. If you open a notebook file with a text editor, you will find it is an ASCII file searchable by a wide variety of readily available tools. But since tools like the Unix tools find and grep cannot interpret the Mathematica code in the notebook, these tools are incapable of displaying the contents as they would appear when opened by the Mathematica front end. They are used to simply find the file containing the desired information. You would then need to open that file in the Mathematica front end to display the information in an useful way. But keep in mind, Mathematica notebooks can be seen as expressions that can be manipulated in Mathematica. So, it is entirely possible to find the correct file, have it opened displaying the appropriate information in your desired format all from Mathematica. In fact, there is no reason you could not replace the Documentation Center with your own search function that would display the information in any manner you found suitable. There is absolutely nothing that can be done with PDF formated files that cannot be done with Mathematica and the existing documentation in notebook format. The only issue is how much time you want to spend creating a set of tools to be used and your ability to create tools. === Subject: Re: Matrix Minimization if you want to minimize log det (M) you define a function of the parameters that returns log det (M). Subsequently you minimize this function using e.g. Minimize, NMinimize, FindMinimum.. Daniel >> >> you may minimize a real scalar but not a matrix. However, what you can >> >> do is to minimize some measure like a Norm of the matrix. >> >> Towards this aim, you will have to calculate e.g. Norm[] and then >> >> minimize it. >> >> Daniel >> >>> Hi , >>> i would like to minimize the following matrix M with respect to A. >>> M= E_X + A E_S A' + A E_P A' E_X H' +A E_S H' >>> H E_X + H E_S A' H E_X H= > ' + H E_S H' + E_Q >>> where E_X, E_S, E_P and E_Q are covariance matrices.. >>> can we do matrix optimization in mathematica? > > Hi Daniel, > > sorry for my mistake. i want to optimize log det (M) with respect to > A. can i use mathematica for that? > > === Subject: Re: Matrix Minimization > > > > > > you may minimize a real scalar but not a matrix. However, what you can > > > do is to minimize some measure like a Norm of the matrix. > > > Towards this aim, you will have to calculate e.g. Norm[] and then > > > minimize it. > > > Daniel > > > > Hi , > > > > i would like to minimize the following matrix M with respect to A. > > > > M= E_X + A E_S A' + A E_P A' E_X H' +A E_S H' > > > H E_X + H E_S A' H E_X= H= > ' + H E_S H' + E_Q > > > > where E_X, E_S, E_P and E_Q are covariance matrices.. > > > > can we do matrix optimization in mathematica? > > > Hi Daniel, > > sorry for my mistake. i want to optimize log det (M) with respect to > A. can i use mathematica for that? > I think log det is concave (maybe only on the positive semidefinite cone, don't remember). You may want to just calculate the gradient and use one of the standard FindMaximize methods with bfgs or conjugate gradient. This is not the best way to solve the problem (see Boyd and Vanderberghe) but may work. P=E5l === Subject: Re: Matrix Minimization To solve your particular problem you need to first use that log det M = trace log M. You will have to teach Mathematica the rules that it needs in order to represent and manipulate your expression. For instance, you could define (your posting was a bit garbled so I might not have accurately transcribed the expression for your matrix.) mat[a_] := prod[ex] + prod[a, es, trans[a]] + prod[a, ep, trans[a]] + prod[ex, trans[h]] + prod[a, es, trans[h]] + prod[h, ex] + prod[h, es, trans[a]] + prod[h, ex, trans[h]] + prod[h, es, trans[h]] + prod[eq]; which introduces prod and trans which represent prod[x1,x2,...] is the matrix product x1.x2... trans[x] is the matrix transpose of x Make two further definitions in order to do simple manipulations on prod and \ trans. trans[x_ + y_] := trans[x] + trans[y]; prod[u___, x_ + y_, v___] := prod[u, x, v] + prod[u, y, v]; Now we are ready to differentiate mat[a] w.r.t. a. mat[a + da] - mat[a] yields prod[a, ep, trans[da]] + prod[a, es, trans[da]] + prod[da, ep, trans[a]] + prod[da, ep, trans[da]] + prod[da, es, trans[a]] + prod[da, es, trans[da]] + prod[da, es, trans[h]] + prod[h, es, trans[da]] and so on... Variations on this general theme, where you make Mathematica definitions to \ push the calculation along in the direction you would have followed \by hand\, will eventually solve your problem. It is a good idea to read up all about Mathematica patterns before you try this approach. -- Stephen Luttrell West Malvern, UK >> >> you may minimize a real scalar but not a matrix. However, what you can >> >> do is to minimize some measure like a Norm of the matrix. >> >> Towards this aim, you will have to calculate e.g. Norm[] and then >> >> minimize it. >> >> Daniel >> >> > Hi , >> >> > i would like to minimize the following matrix M with respect to A. >> >> > M= E_X + A E_S A' + A E_P A' E_X H' +A E_S H' >> > H E_X + H E_S A' H E_X H= > ' + H E_S H' + E_Q >> >> > where E_X, E_S, E_P and E_Q are covariance matrices.. >> >> > can we do matrix optimization in mathematica? >> > > Hi Daniel, > > sorry for my mistake. i want to optimize log det (M) with respect to > A. can i use mathematica for that? > > === Subject: Re: Manipulate, Opacity, slow down Without the code it is not quite clear, why the 2D parametric plot is noticeably slowed down in your case. I met such situations only in 3D cases. Probably your function is too heavy for whatever reason. Anyway, if you need the result for a presentation (for what else?), you may be quite sutisfied with timing of the discrete Manipulate version, instead of the continuous one, like the following: f[a_] := ParametricPlot[{Sin[a u], Cos[u/a]}, {u, 0, 4 Pi}] Manipulate[f[a], {a, 1, 5, 0.5}] If this is still too slow in your case, try the FlipView like below: tab = Table[ ParametricPlot[{Sin[a u], Cos[u/a]}, {u, 0, 4 Pi}], {a, 1, 5, 0.5}]; FlipView[tab] This must be fast. Alexei > I wonder if you can give me some hints without a code. > I have a program using Manipulate[ParametricPlot[f[a]]]. > 1. If I define outside the function f used in ParametricPlot, and then > insert the function name into ParametricPlot, then the program slows > down extremely compared to the version when the formula of the > function is inserted. > 2. If I add Opacity to the Directives, again the timing increases > tremendously. > > If you think you could help seeing the (long) code I'll be ready to > show it. > > > J=E1nos -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu === Subject: Re: Focus ring for controls forthcoming.... andrew === Subject: Random choice Good day, Given this example : In[1]:= RandomChoice[Range[500], 100] // Union // Length Out[1]= 91 what is the best way to get *exactly* 100 different random numbers ranging from 1 to 500 ? Any piece of advice would be appreciated. -- Valeri Astanoff === Subject: Re: Random choice This is superfast: a=Table[i,{i,1,500}];b={}; For[i=0,i<100,i+ + ,add = a [[RandomInteger [{1,Length[a]}]]];b=Append[b,add];a=Delete[a,Position[a,add]]] In[4]:= Length[Union[b]] Out[4]= 100 Filippo > Hi Valeri, > > RandomChoice does not guarantee that all picked items (numbers) > will be > different. In v.6,0+, use RandomSample: > > In[1] = RandomSample[Range[500],100]//Short > > Out[1] = {467,487,153,196,<<92>>,65,104,399,386} > > For earlier versions, you can load Combinatorica: > > In[2] = << DiscreteMath`Combinatorica`; > > and use RandomPermutation: > > In[3] = #[[Take[RandomPermutation[#], 100]]] &@Range[500]//Short > > Out[3] = {120,122,328,6,241,<<90>>,291,58,409,314,109} > > However, both methods will become very memory-hungry if your > upper limit is large enough (more than say 10^7), due to the > necessity to > temporarily store an entire range of numbers. The used memory > will be quickly released back to the OS, of course (Mathematica > garbage > collector is quite good at this), but the peak load may be > significant. > > Here is the version from my book (slightly modified) > > ( http://www.mathprogramming-intro.org/book/node514.html ), > > which is free from this drawback. It works best when the third > optional > parameter (updatenum) is about a quarter of the total numbers asked > (n) > (this is a heuristics of course). > > > In[4] = > > Clear[randomNumsOrdered]; > randomNumsOrdered[numrange_List, n_Integer, > updatenum_Integer: 100] := > Take[NestWhile[ > Union[Join[#, RandomInteger[numrange, updatenum]]] &, > {}, Length[#] < n &], n]; > > For example, > > In[5] = randomNumsOrdered[{1, 50000000}, 100] // Timing // Short > > Out[5] = {0.,{292330,<<98>>,49669303}} > > Finally, you may do it more systematically by constructing a binary > search > tree (see Mathematica implementation, for example, in R.Maeder > \Computer > science with Mathematica\) and then test each newly generated number > against > those in the tree and insert if it isn't present already. > But in practice, I doubt that this solution will be faster in > Mathematica. > > Hope this helps. > > Leonid > > > >> Good day, >> >> Given this example : >> >> In[1]:= RandomChoice[Range[500], 100] // Union // Length >> >> Out[1]= 91 >> >> what is the best way to get *exactly* 100 different >> random numbers ranging from 1 to 500 ? >> >> Any piece of advice would be appreciated. >> >> -- >> >> Valeri Astanoff >> >> ------------------------------------------------------------ Mobile (IT): +39 340 6104269 Mobile (NL): +31 064 3949827 Home (IT): +39 0438 59360 P.O. Box 9504 NL 2300 RA LEIDEN msn: dr.ziofil@hotmail.com skype: filippo.miatto Quantum Optics Group Mail: miatto@molphys.leidenuniv.nl === Subject: Re: Random choice Hi Valeri, RandomChoice does not guarantee that all picked items (numbers) will be different. In v.6,0+, use RandomSample: In[1] = RandomSample[Range[500],100]//Short Out[1] = {467,487,153,196,<<92>>,65,104,399,386} For earlier versions, you can load Combinatorica: In[2] = << DiscreteMath`Combinatorica`; and use RandomPermutation: In[3] = #[[Take[RandomPermutation[#], 100]]] &@Range[500]//Short Out[3] = {120,122,328,6,241,<<90>>,291,58,409,314,109} However, both methods will become very memory-hungry if your upper limit is large enough (more than say 10^7), due to the necessity to temporarily store an entire range of numbers. The used memory will be quickly released back to the OS, of course (Mathematica garbage collector is quite good at this), but the peak load may be significant. Here is the version from my book (slightly modified) ( http://www.mathprogramming-intro.org/book/node514.html ), which is free from this drawback. It works best when the third optional parameter (updatenum) is about a quarter of the total numbers asked (n) (this is a heuristics of course). In[4] = Clear[randomNumsOrdered]; randomNumsOrdered[numrange_List, n_Integer, updatenum_Integer: 100] := Take[NestWhile[ Union[Join[#, RandomInteger[numrange, updatenum]]] &, {}, Length[#] < n &], n]; For example, In[5] = randomNumsOrdered[{1, 50000000}, 100] // Timing // Short Out[5] = {0.,{292330,<<98>>,49669303}} Finally, you may do it more systematically by constructing a binary search tree (see Mathematica implementation, for example, in R.Maeder \Computer science with Mathematica\) and then test each newly generated number \ against those in the tree and insert if it isn't present already. But in practice, I doubt that this solution will be faster in Mathematica. Hope this helps. Leonid > Good day, > > Given this example : > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > Out[1]= 91 > > what is the best way to get *exactly* 100 different > random numbers ranging from 1 to 500 ? > > Any piece of advice would be appreciated. > > -- > > Valeri Astanoff > > === Subject: Re: Random choice You need to do sampling without replacement. This code fragment will sample \ m times (without replacement) from a pool of n indices: n; m=5; Nest[({Append[#1[[1]],#1[[2,#2]]],Delete[#1[[2]],#2]}&[#,RandomInteger[{1,Le\ ngth[#[[2]]]}]])&,{{},Range[n]},m] {{12,6,13,14,8},{1,2,3,4,5,7,9,10,11,15,16,17,18,19,20}} The code returns 2 lists: the sampled indices and the residue of the pool which was sampled from. This output can be fed back into the code fragment for further sampling if required. -- Stephen Luttrell West Malvern, UK > Good day, > > Given this example : > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > Out[1]= 91 > > what is the best way to get *exactly* 100 different > random numbers ranging from 1 to 500 ? > > Any piece of advice would be appreciated. > > -- > > Valeri Astanoff > === Subject: Re: Random choice Here is one suggestion: Nest[Append[#, RandomChoice[Complement[Range[500], #]]] &, {}, 100] First time we execute RandomChoice, a number among 500 is chosen. The next time that number is excluded from the list. Next time two numbers are excluded, and so on. Ingolf Dahl -----Original Message----- === Subject: Random choice Good day, Given this example : In[1]:= RandomChoice[Range[500], 100] // Union // Length Out[1]= 91 what is the best way to get *exactly* 100 different random numbers ranging from 1 to 500 ? Any piece of advice would be appreciated. -- Valeri Astanoff === Subject: Re: Random choice Hi Valeri, the magic word is: RandomSample. Daniel > Good day, > > Given this example : > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > Out[1]= 91 > > what is the best way to get *exactly* 100 different > random numbers ranging from 1 to 500 ? > > Any piece of advice would be appreciated. > > -- > > Valeri Astanoff > === Subject: Re: Random choice Table[RandomReal[{1,500}],{i,1,100}] Filippo > Good day, > > Given this example : > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > Out[1]= 91 > > what is the best way to get *exactly* 100 different > random numbers ranging from 1 to 500 ? > > Any piece of advice would be appreciated. > > -- > > Valeri Astanoff > ------------------------------------------------------------ Mobile (IT): +39 340 6104269 Mobile (NL): +31 064 3949827 Home (IT): +39 0438 59360 Via Scossore, 94 31029 Vittorio Veneto (TV) italy msn: dr.ziofil@hotmail.com skype: filippo.miatto Quantum Optics Group Mail: miatto@molphys.leidenuniv.nl === Subject: Re: Random choice > Good day, > > Given this example : > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > Out[1]= 91 > > what is the best way to get *exactly* 100 different > random numbers ranging from 1 to 500 ? > > Any piece of advice would be appreciated. > > -- > > Valeri Astanoff RandomSample[Range[500], 100] // Union // Length Given the well-established meaning of m_Choose_n for sampling without replacement, whoever decided on the new terminology got RandomChoice and RandomSample backwards. === Subject: Re: Random choice > > > > > > > Good day, > > > Given this example : > > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > > Out[1]= 91 > > > what is the best way to get *exactly* 100 different > > random numbers ranging from 1 to 500 ? > > > Any piece of advice would be appreciated. > > > -- > > > Valeri Astanoff > > RandomSample[Range[500], 100] // Union // Length > > Given the well-established meaning of m_Choose_n for sampling without > replacement, whoever decided on the new terminology got RandomChoice > and RandomSample backwards.- Masquer le texte des messages \ pr=E9c=E9dents= - > > - Afficher le texte des messages pr=E9c=E9dents - know the existence of \RandomSample\ : it does just what I was looking for. v.a. === Subject: Re: SparseArray and Compile It's not clear how you intend to use rp, so it's hard to say much more than that you can cut the uncompiled time substantially by defining rp = SparseArray[ UnitStep[ .01 - dat - dat[[#]] ] ] & /@ Range[Length[dat]]; The resulting rp will be exactly the same as in your version. > > I have difficulties to speed up my calculation regarding SparseArray: > > rp = {}; > AppendTo[rp, SparseArray[UnitStep[0.01 - dat - dat[[#]]]]] & /@ > Range[Length[dat]]; > > dat is a list of Reals containing approx. 24000 elements. I had to > use SparseArray for each line to prevent a memory crash; the final > matrix has 574 million elements. The calculation takes 2' 43'' on > > I would like to speed up the calculation using compile, but the > SparseArray object doesn't fit the tensor format. I have tried: > > Compile[{{data, _Real, 1}}, > Block[{rp}, rp = {}; > AppendTo[rp, SparseArray[UnitStep[0.01 - data - data[[#]]]]] & /@ > Range[Length[data]]]] > > Compile::cpts: The result after evaluating Insert[rp,SparseArray > [UnitStep[0.01-data-data[[System`Private`CompileSymbol[<<1>>] > [[System`Private`CompileSymbol[<<1>>]]]]]]],-1] should be a tensor. > Nontensor lists are not supported at present; evaluation will proceed > with the uncompiled function. >> > > The calculation is used calculate a recurrence plot. The fixed value > of 0.01 will be replaced by a variable later on; therefore, I need to > speed up the calculation. > > Any help is appreciated. === Subject: Re: Question about filenames for Export[...] [...] > Wonder how many different solutions this question will generate? > > One way is to use IntegerString and StringJoin in something like: > > i = 1; > filename = StringJoin[\MyName\, IntegerString[i, 10, 4]] > Wow, that you all for the very many suggestions! Bob's one-liner quoted above does exactly what I was looking for and worked \ like a charm. I haven't tried all of the other suggestion but they are good material to get to know about some Mathematica functons I'm not very familiar with. Lorenzo === Subject: Exports to eps, pdf ImageSize Hello Exports of a graphics expression to .pdf (and also .eps) create bigger \ images when the files are sent to a printer or a viewer than raster graphics \ as .png, .gif etc. or scalable vector graphics .svg. Setting the ImageSize \ does not solve the problem, unfortunately. gr = Plot[Cos[x], {x, -2, 2}]; Export[\C:\\\\test1.pdf\, gr, ImageSize -> {360, 224}]; Export[\C:\\\\test1.eps\, gr, ImageSize -> {360, 224}]; Export[\C:\\\\test1.jpg\, gr, ImageSize -> {360, 224}]; Export[\C:\\\\test1.gif\, gr, ImageSize -> {360, 224}]; I also tried many options like ImageMargins, ImagePadding, PlotRangePadding, \ PlotRange, PlotRangeClipping etc. without success. Why is it that .pdf and .eps create bigger images and how can I compute as \ exactly as possible the ratios of these relative enlargements? The problem \ arises in Version 5, 6 and 7 and on different machines (Windows XP, \ Switzerland). Bernhard Zgraggen, HSR === Subject: Re: Exports to eps, pdf ImageSize > Exports of a graphics expression to .pdf (and also .eps) create bigger \ im= ages when the files are sent to a printer or a viewer than raster graphics \ = as .png, .gif etc. or scalable vector graphics .svg. Setting the ImageSize \ = does not solve the problem, unfortunately. > > gr = Plot[Cos[x], {x, -2, 2}]; > Export[\C:\\\\test1.pdf\, gr, ImageSize -> {360, 224}]; > Export[\C:\\\\test1.eps\, gr, ImageSize -> {360, 224}]; > Export[\C:\\\\test1.jpg\, gr, ImageSize -> {360, 224}]; > Export[\C:\\\\test1.gif\, gr, ImageSize -> {360, 224}]; > > I also tried many options like ImageMargins, ImagePadding, \ PlotRangePaddi= ng, PlotRange, PlotRangeClipping etc. without success. > > Why is it that .pdf and .eps create bigger images Just to clarify, when you say \bigger images\ are you referring to the file size or the image dimensions? Regarding file size, as you stated, PDF & EPS are vector formats. In this particular example they simply contain more data than the raster formats, resulting in larger file size. Regarding image dimensions, this is probably a quirk of the viewer software. If you examine the PDF or EPS file you see that the dimensions are correctly specified as 360x224. If you import the PDF back into Mathematica you'll see it correctly displayed at 360x224. If you display it in Preview (or presumably Adobe Reader) it appears physically larger. These viewer applications try to be clever by taking your actual screen resolution into account. The PDF & EPS coordinate systems are 72 DPI. For this example they compute the desired size to be 5\x3.11\. Then they try to display it as close to 5\x3.11\ as possible, rather than at the natural 360x244. > and how can I compute as exactly as possible the ratios of these \ relative= enlargements? The problem arises in Version 5, 6 and 7 and on different \ ma= chines (Windows XP, Switzerland). You would have to know what the viewer application thinks your physical screen resolution is. If it is 100 DPI the graphic would appear 500x311 pixels. If it is 133 DPI the graphic would appear 665x414 pixels. {w,h}*actualDPI/72. -Rob === Subject: Problems in fitting the experimental data with the expression My exp data x-values are ax = expdata[[All, 1]] {600.58, 598.2, 595.81, 593.43, 591.04, 588.66, 586.27, 583.88, \\ 581.49, 579.1, 576.71, 574.32, 571.93, 569.54, 567.15, 564.76, \\ 562.36, 559.97, 557.58, 555.18, 552.79, 550.39, 547.99, 545.6, 543.2, \\ 540.8, 538.4, 536, 533.6, 531.2, 528.79, 526.39, 523.99, 521.58, \\ 519.18, 516.77, 514.37, 511.96, 509.55, 507.15, 504.74, 502.33, \\ 499.92, 497.51, 495.1, 492.69, 490.27, 487.86, 485.45, 483.03, \\ 480.62, 478.2, 475.79, 473.37, 470.95, 468.54, 466.12, 463.7, 461.28, \\ 458.86, 456.44, 454.01, 451.59, 449.17, 446.75, 444.32, 441.9, \\ 439.47, 437.04, 434.62, 432.19, 429.76, 427.33, 424.9, 422.47, \\ 420.04, 417.61, 415.18, 412.75, 410.31, 407.88, 405.44, 403.01, \\ 400.57} y-datas are ay = expdata[[All, 2]] {241.27, 241.5, 241.8, 246.63, 243.53, 242.6, 242.53, 242.03, 243.57, \\ 242.57, 240.4, 242.33, 240.27, 239.37, 239.3, 236.73, 237.07, 240.17, \\ 238.6, 241.53, 238.07, 243.47, 240.3, 241.8, 244.73, 244.67, 246.9, \\ 252.53, 257.67, 263.77, 275.23, 291.53, 335.87, 438.13, 563.43, 527, \\ 437.7, 405.73, 414.07, 426.1, 451.97, 479.97, 511.9, 552.8, 592.97, \\ 619.57, 644.3, 645.07, 635.07, 602, 569.2, 520.17, 472.13, 436.83, \\ 404.53, 384.13, 366.23, 350.73, 337.57, 325.67, 314.47, 307.77, \\ 301.4, 295.13, 289.53, 288.03, 284.37, 274.6, 272.8, 269.2, 265.8, \\ 263.7, 261.87, 262.87, 259.43, 261.07, 262.57, 264.97, 262.1, 263.5, \\ 265.13, 261, 259.03, 264.43} fw[w_?NumericQ, L_?NumericQ] := NIntegrate[ 4*Pi*q^2*Exp[-(L^2*q^2)/(16* Pi^2)]/((w - (520 - (120*(q/1.15712)^2)))^2 + (3.5/2)^2), {q, a, b}] I want to fit the value of L. w : values are taken from the x-data of the experiment. FindFit[ay, fw[w, L], {L}, {ax[[1]], ax[[84]]}] I got the error as General::ivar: 600.58` is not a valid variable. >> I don't know how to solve this problem of fitting the value of L with the experimental data. Kindly do the needful to solve this === Subject: Re: is accessing parts of an hdf5 dataset possible? > I have a large HDF5 dataset that cannot fit into memory if I do an > Import of the dataset. > > Is there a way to load only a portion of a dataset? My dataset is a > two dimensional array. Ideally, I would be able to Import and Export > portions of the array via part assignments. Without this feature, it > is a little difficult to work with large HDF5 datasets in Mathematica, > isn't it? > > I assume the answer is no in case I get no replies. > > But before I write mathlink wrappers, just wanted to double check. > Such a feature is available in two python wrappers of the HDF5 library > (h5py and pytables). > > P=E5l. I think you can read one dataset elements at a time, but I'm not sure if there is a way to read an part of an array. If you figure that out, let me know because these are big issues for these Earth Science datasets. Kevin === Subject: Why \InputForm[x,NumberMarks->False]\ can not return correctly in \ my Hellow, I understand that result for \InputForm[x,NumberMarks->False]\ is to return without number mark \ ` \. But my Mathematica HelpBrowser does not return that way. It returns as almost same as undefined function. So I checked a web site.The name of the site is \Numerical Precision - Wolfram Mathematica Documentation Center\. There is a difference between my help browser's content and the documentation center's . Content in the Documentation Center is below. In[13]:= N[Pi,20] Out[13]= 3.1415926535897932385 In[14]:= InputForm[%] Out[14]//InputForm= 3.1415926535897932384626433832795028842`20 In[15]:= InputForm[%,NumberMarks->False] Out[15]//InputForm= 3.14159265358979323846 Above result is the same as my expectation. But in my Mathematica HelpBrowser, \InputForm[%,NumberMarks->False]\ is still remained in output, and a value with \ ` \ mark is substituted only for \%\. That value is corresponding to the value of above \InputForm Out [14]\ . I think result of HelpBrowser is essentially same between my own and Wolfram's Documentation Center's in the web site. What should I do to get the correct answer in my HelpBrowser ? === Subject: creating Graphics using ParallelTable[] Hello all, I generate \video frames\ from time-consuming 3DPlot[]s (to export them into a video file later on): frame[x_] := Plot3D[... something big using x ...]; movieframes = Table[frame[x], {x, start, end, (end-start)/steps}]; I have a double core CPU; so now I would like to create these frames in parallel with Mathematica 7, using ParallelTable[]. But I don't derive any advantage from doing this: My Windows taskmanager shows three \MathKernel.exe\. When I use ParallelTable[] for the described problem, only one \MathKernel.exe\ $ProcessorCount is 2, there is 1 \master\ and 2 \local\ in \Parallel Kernel Status\. The \parallelizeabletest\ ParallelTable[$KernelID, {10}] succeeds. I tried `DistributeDefinitions[frame];` before invoking ParallelTable [], but it did not change anything. One core needs about 20 seconds to create one single frame without displaying it: An extensive analytical function (among others there are nested Coth[]s) has to be calculated with Plotpoints->100 option. In my opinion - simply expressed - each core can take one `x` out of the queue and create the corresponding 3DPlot Graphics object, while the other core is doing the same. This should work, because the tasks are totally independent and my way to use the Table[] is the least complex one. I don't see the \data management overhead\ that often reduces or even prevents advantages from parallelizing, because each core just needs to get the function definitions and a simple number: `x` - no more overhead. (At which point) do I think wrong or does Mathematica work weird (less likely..)? Is there a way for me to create these frames using all my CPU power? Sincereley, Jan-Philip Gehrcke === Subject: Weird palette stuff, still learning...Help! hi, Ok, when I use my large, rich palette via CreatePalette, it just works fine. All my dynamic stuff works, all my ActionMenus work too. But once I save the palette and use it 'standalone' after relaunching Mathematica, it breaks. Dynamic fails and some of the ActionMenus are not firing when selected. Now, if I evaluate all the key cells from its source notebook while the broken palette is up, it gets \healed\ and works fine. Please explain to me how coding for a palette works so to restore my sanity. ;-) === Subject: Mathematica SIG (Washington DC Area) Mathematica SIG (web.mac.com/hrbishop.pmsi/DCSIG.m/DCSIG.html) MEETING 22 May 2009, 7:30 am Science Applications International Corporation (SAIC) 8301 Greensboro Drive McLean VA Southern Corner of Westpark Drive and Greensboro Drive Agenda 1. Prepared Talks A Search Model for IEDs, by Mel Friedman Abstract. A model that describes search (using a thermal imaging sensor) from a moving vehicle for objects that are on the road or on the side of \ the road will be presented. The long term goal is to develop a model that describes the detection of improvised explosive devices (IEDs) using a thermal imaging system. The model was developed using Mathematica. This talk is based upon one recently given to The International Society for Optical Engineering. Automatic Numbering of Objects, by Eric Bynum Abstract. The title says it all. Eric's talk launches the first of what will be many memorable Mathematica tutorials. History Timelines of Notable Savants about fifty notable and prolific contributors to science and technology, or its discourse, are presented with dynamic categorization and time-marking. The structure of the database and its supporting functions will be explained, and the plot's dynamic properties will be demonstrated. Dan also will illustrate how the database's structure facilitates the use of time-series information from virtually any field of scholarship. 2. Mathematica Gems and Discoveries - Sharing of Mathematica programming oddities - Applications of Mathematica to some areas of science - Something recently read and worth sharing 3. Mathematica Questions, Possible Approaches and Discussion 4. New Business - Select next meeting presentation, time and place Directions to 8301 Greensboro Drive, McLean VA (tall, boxy and white SAIC Enterprise Building at south corner of Westpark Drive and Greensboro \ Drive): Route 123 (Chain Bridge Road). Turn right onto Westpark Drive (Gosnell Road in the other direction). Turn right at the next light onto Greensboro Drive and then right into the parking lot. Visitor's Parking is adjacent to Westpark Drive. A SIG representative will meet you in the lobby. officer will ask for a driver's license before issuing a visitor's badge. === Subject: 2D ray tracer I am looking for something like a 2D ray tracer. Here is the problem: I have a 2D random field (power spectrum has a decay of 1 or 2, so the field appears not very smooth) of propagation speeds. For a given start point (x0,y0) in the field I want to find for each point (x_i,y-i) the shortest propagation time between (x0,y0) and (x_i,y_i). A typical dimension for the field would be something like 512 x 256. Is anyone aware of a 2D raytracer that could be used to get the shortest travel time for each point? Or does someone maybe have an alternative approach? Preferred would be something non-commercial (free that is) Tank you very much Jan === Subject: Re: GuiKit, seeking some guidance and comments > Btw, I am shocked there was no > scrolling list widget Pane[] has a ScrollBars option that can be used to emulate a scrolling list. > nor any support for hierarchy in popup/Action > menus. Doing that via dynamic is, from my point of view, a hack; but I > will master dynamic. Mac popup menus and the equivalent Windows combo/list boxes never have submenus. It is a reasonable suggestion that ActionMenu should support submenus in the future. In the meantime you might be able to achieve a similar effect using indentation. -Rob === Subject: Re: GuiKit, seeking some guidance and comments Guilink for making my palette. And yes, once I spend some time looking at guikit, I will submit reports. Btw, I am shocked there was no scrolling list widget nor any support for hierarchy in popup/Action menus. Doing that via dynamic is, from my point of view, a hack; but I will master dynamic. andrew === Subject: Re: GuiKit, seeking some guidance and comments I am not sure why anyone would want to write things for GuiKit at this point. It was originally developed prior to Mathematica version 6 when Mathematica only had very poor user interface elements. Version 6 changes the landscape completely. I wouldn't ever consider using GuiKit at this point.... Jut my 2 cents... --David > > I am considering porting my palette to GuiKit in a few months. Hey, I > need to enjoy using my palette for awhile doing math right. ;-) > What do you long time users of Mathematica think of GuiKit? What is > its strengths and weakness, is it worth mastering as preparing for the > future of Mathematica? How is the best way to learn GuiKit, what are > the best examples of GuiKit to be studied? How polished and stable is > GuiKit? > > Andrew === Subject: Re: GuiKit, seeking some guidance and comments > > I am considering porting my palette to GuiKit in a few months. Hey, I > need to enjoy using my palette for awhile doing math right. ;-) > What do you long time users of Mathematica think of GuiKit? What is > its strengths and weakness, is it worth mastering as preparing for the > future of Mathematica? How is the best way to learn GuiKit, what are > the best examples of GuiKit to be studied? How polished and stable is > GuiKit? > > Andrew > IMHO, GuiKit sufferes from insufficient documentation, and its design seems overly complicated, and to require that the user also knows a fair bit of Java. When I last tried to use it, it also contained some irritating bugs. hopefully better alternative - so if you want a Java GUI, I think you should at least try that first. I used to base my SWP on GuiKit, but more recently, I reorganised it to work directly with J/Link, substantial quantities of compiled Java code. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: saving initialization cells as a .m file === Subject: Re: saving initialization cells as a .m file Hi Baris, f[t]= ^\\[Dagger] does not apply SuperDagger. You would have to say SuperDagger[f[t]] Daniel I have the following code which runs fine in a notebook: SuperDagger[A_List] := Conjugate[Transpose[A]] eqn = {f'[t] == -f[t]^\\[Dagger].f[t], f[0] == RandomReal[{0, 0.1}, {3, 3}]}; NDSolve[eqn, f, {t, 0, 10}] but when I save the first two lines (definition of SuperDagger and eqn) in a .m file and load them with a Get command, although Mathematica loads the definitions, NDSolve doesn't like the input and complains that derivative at t=0 is not defined. Weirdly if I copy and paste the output of NDSolve and evaluate it, it runs fine. Do you know how can I fix this? Baris Altunkaynak === Subject: PlotLegend Hi All, I have a problem with the usage of Legend option in a mathematica notebook. Although I'm giving 4 legends to the plot it shows 5 legends with one is empty. Can anyone, if has, send me a sample code for this issue? kenan === Subject: excel link with mathematica dear math group, i have used nminimize in mathematica. now i want to use it in \ excel by using excel link with mathematica. can any1 give me the syntax of \ nminimize in excel? i want to write the code in excel , and get the result in \ excel too....just any simple nminize function used in excel? === Subject: Re: Wolfram|Alpha Lookup Tool for Mathematica Alas, the tool may be of limited value right now, because Wolfram|Alpha is overloaded to the point of barely working. That's on a Saturday morning about 10:20 a.m. EDT. Even when I browsed directly to wolframalpha.com, it took several minutes for the home page to load. Then, when I typed in a query (my birthdate), I got back a message: \I'm sorry Dave, I'm afraid I can't do that... Wolfram|Alpha has temporarily exceeded its current maximum test load. See the live video feed of the Control Center>>\ Several minutes later, I tried again. I got a report back almost immediately giving the Input interpretation and showing a date format, but below that just 6 progress bars that kept running for several minutes until I gave up. Next, I typed in one of the suggested math formulas: x^2 sin(x). I got back information about that -- graphs, an alternate form using complex exponentials, roots, series expansion, ..., almost immediately! (But perhaps that one was already cached on the site?) > With the release of Wolfram|Alpha I have created a small tool that > allows you to send a query to Wolfram|Alpha directly from Mathematica. > > The tool is a simple dialog with an input field where you can type a > query to be sent to Wolfram|Alpha. > > After entering your query in the input field simply click on the > \Wolfram|Alpha Lookup\ button and the query will be sent to Wolfram| > Alpha via your default web browser. > > You can download the tool from here: > > http://www.scientificarts.com/mathematicatools/blog/ > > or here: > > \ http://www.scientificarts.com/mathematicatools/blog/BE3451431867/BE3451431867\ .html > > Enjoy! > > --David > -- 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: Wolfram|Alpha Lookup Tool for Mathematica With the release of Wolfram|Alpha I have created a small tool that allows you to send a query to Wolfram|Alpha directly from Mathematica. The tool is a simple dialog with an input field where you can type a query to be sent to Wolfram|Alpha. After entering your query in the input field simply click on the \Wolfram|Alpha Lookup\ button and the query will be sent to Wolfram| Alpha via your default web browser. You can download the tool from here: http://www.scientificarts.com/mathematicatools/blog/ or here: http://www.scientificarts.com/mathematicatools/blog/BE3451431867/BE345143186\ 7.html Enjoy! --David === Subject: Re: Preventing swapping (high memory use) Hi Szabolcs, How about this: In[1] = ClearAll[totalMemoryConstrained]; SetAttributes[totalMemoryConstrained, HoldRest]; Module[{memException}, totalMemoryConstrained[max_, body_, failexpr_] := Catch[MemoryConstrained[body, Evaluate[ If[# < 0, Throw[failexpr, memException], #] &@(max - MemoryInUse[])], failexpr], memException]]; To test, I start with a fresh kernel: In[2] = MemoryInUse[] Out[2] = 5815968 In[3] = n = 0; lst = {}; totalMemoryConstrained[10000000, For[lst = {}; n = 10000, n < 100000, n++, lst = Join[lst, Range[n]]], Print[n]] Out[3] = 10043 (Printed) In[4] = MemoryInUse[] Out[4] = 8257328 I deliberately use globals to prevent them from being garbage-collected after the function returns. Now take a limit smaller than the current usage: In[5] = n = 0; lst = {}; totalMemoryConstrained[3000000, For[lst = {}; n = 10000, n < 100000, n++, lst = Join[lst, Range[n]]], Print[n]] Out[3] = 0 (Printed) - we just stop right away (through exception, obviously). This of course relies on how often does MemoryConstrained[] recompute its parameters, and how precise is MemoryInUse[]. My simple tests indicated that it works, up to plus-minus a few Mb, but obviously more tests are needed. Leonid 2009/5/16 Szabolcs Horv=E1t > > Sometimes I don't realize how much memory a computation would take up > (or I simply make a mistake, and start a calculation that requires too > much memory), and my computer starts swapping. > > This makes Mathematica (and often the OS too) completely unresponsive > for a long time. In this case my only hope is that in spite of the > system unresponsiveness I can manage to kill the kernel, so that I can > at least save the notebook ... > > Is there any way to prevent swapping, for example by putting a cap on > the kernel's memory use? Even if the kernel just quits when it runs out > of memory, I still have the notebook. But if the computer gets so > unresponsive that I have to restart it, then I lose the notebook too, > which is a much more serious loss ... > > I tried using MemoryConstrained (with $Pre), but it seems to constrain > only the memory used by current computation, not the full kernel memory > use. > > > To summarize: I'm simply looking for a way to prevent the computer from > locking up because of excessive swapping. > === Subject: Preventing swapping (high memory use) Sometimes I don't realize how much memory a computation would take up (or I simply make a mistake, and start a calculation that requires too much memory), and my computer starts swapping. This makes Mathematica (and often the OS too) completely unresponsive for a long time. In this case my only hope is that in spite of the system unresponsiveness I can manage to kill the kernel, so that I can at least save the notebook ... Is there any way to prevent swapping, for example by putting a cap on the kernel's memory use? Even if the kernel just quits when it runs out of memory, I still have the notebook. But if the computer gets so unresponsive that I have to restart it, then I lose the notebook too, which is a much more serious loss ... I tried using MemoryConstrained (with $Pre), but it seems to constrain only the memory used by current computation, not the full kernel memory \ use. To summarize: I'm simply looking for a way to prevent the computer from locking up because of excessive swapping. === Subject: Re: Map conditional sums by date Hi Charles, the following will do what you want and more, since the first setting of each slider is \All\, which allows you to total over the full range of \ items this slider is responsible for (day, month or year), and thus you can \ decide if you want AND or OR logic for each item, and therefore be as specific or as general as you wish. Clear[getUI]; getUI[data_] := Module[{months, monthSelect, yearSelect, daySelect, totalize, years, days}, months = {All, \Jan\, \Feb\, \Mar\, \Apr\, \May\, \Jun\, \ \Jul\, \Aug\, \Sep\, \Oct\, \Nov\, \Dec\}; years = Prepend[Union@data[[All, 1, 1]], All]; With[{part = #2}, #1[arg_] := Select[#, #[[1, part]] == arg &] &] & @@@ Transpose[{{yearSelect, monthSelect, daySelect}, {1, 2, 3}}]; daySelect[0] = yearSelect[All] = monthSelect[0] = # &; totalize = Total[#[[All, 3]]] &; days = Prepend[Range[31], All]; Manipulate[ Grid[{{\Year\, \Month\, \Day\, \Amount\}, {years[[j]], months[[i]], days[[k]], totalize@ yearSelect[years[[j]]]@ monthSelect[i - 1]@daySelect[k - 1]@data}}, Frame -> All], {{i, 1, \Month\}, 1, 13, 1}, {{j, 1, \Year\}, 1, Length[years], 1}, {{k, 1, \Day\}, 1, Length[days], 1}, Alignment -> Center]]; Usage: getUI[mydata], with from your e-mail. Note that I made explicit use of your specific format and therefore you have to maintain it for this to work. The main idea of this implementation is that 3 selector functions monthSelect, yearSelect, daySelect select the corresponding records and pass the resulting structure to the next selector function in the \ chain. If any of them receives the parameter, it simply stays idle and \ passes the entire data to the next selector function. It shouldn't be hard to attach a barchart-generating code to this if \ needed. Hope this helps. Leonid > Hi > > I want to (ultimately) use Manipulate to provide date selections > (year, months, days) to create a BarChart. I am able to get the > results from my data in a kludgy way. The data is in the form {{yr, > mo, day, h,min,sec}, code, amount}, as seen below: > > mydata={{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}, {{2006, 8, 23, 0, 0, > 0}, 54163, 3}, {{2007, 12, 5, 0, 0, 0}, 43280, 17.25`}, {{2009, 2, > 5, > 0, 0, 0}, 54161, 3.27`}} > > I want to conditionally total the amounts (3rd column), by yr OR by > month OR by day; which I can do with : > > Select[mydata, #[[1, 2]] == 7 &] > (* would give me all the rows in which July (7th mo) is the month, for > example*) > OR > Select[mydata, #[[1, 1]] == 2008 &] > (* would give me all the rows in which 2008 is the year *) > > I can sum the amounts with: > Total[#[[3]] & /@ %] > > I need basic help with putting these into a function, but ultimately I > want to be able to select yr or mo or day of week via Manipulate and > get the total.... > > My failed attempts: > > (* parameters are yrmoday -> 1 is year, 2 is mo, 3 is day, and x is > the specific year or month or day*) > > sumbydate[x_, yrmoday_] := > If[#[[1, yrmoday]] == x, myresult += #[[3]], myresult += 0] & /@ > mydata; myresult > > OR > > (* this would be sum by month, if it worked...) > > sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, res += #[[3]], res > += 0] & /@ temp; Map[ > sumrvubydate2[#] &, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}] > > > === Subject: Map conditional sums by date Hi I want to (ultimately) use Manipulate to provide date selections (year, months, days) to create a BarChart. I am able to get the results from my data in a kludgy way. The data is in the form {{yr, mo, day, h,min,sec}, code, amount}, as seen below: mydata={{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}, {{2006, 8, 23, 0, 0, 0}, 54163, 3}, {{2007, 12, 5, 0, 0, 0}, 43280, 17.25`}, {{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}} I want to conditionally total the amounts (3rd column), by yr OR by month OR by day; which I can do with : Select[mydata, #[[1, 2]] == 7 &] (* would give me all the rows in which July (7th mo) is the month, for example*) OR Select[mydata, #[[1, 1]] == 2008 &] (* would give me all the rows in which 2008 is the year *) I can sum the amounts with: Total[#[[3]] & /@ %] I need basic help with putting these into a function, but ultimately I want to be able to select yr or mo or day of week via Manipulate and get the total.... My failed attempts: (* parameters are yrmoday -> 1 is year, 2 is mo, 3 is day, and x is the specific year or month or day*) sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, myresult += #[[3]], myresult += 0] & /@ mydata; myresult OR (* this would be sum by month, if it worked...) sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, res += #[[3]], res += 0] & /@ temp; Map[ sumrvubydate2[#] &, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}] === Subject: Re: Map conditional sums by date This gets more complicated if you want to be able to simultaneously select \ multiple years, months, days, and/or codes. mydata = { {{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}, {{2006, 8, 23, 0, 0, 0}, 54163, 3}, {{2007, 12, 5, 0, 0, 0}, 43280, 17.25`}, {{2009, 2, 5, 0, 0, 0}, 54161, 3.27`} }; months = {\Jan\, \Feb\, \Mar\, \Apr\, \May\, \Jun\, \Jul\, \Aug\, \Sep\, \Oct\, \Nov\, \Dec\}; codes = Union[mydata[[All, 2]]]; Manipulate[condTotal = Total[Select[mydata, (Not[yrQ] || #[[1, 1]] == yr) && (Not[moQ] || #[[1, 2]] == Position[months, mo][[1, 1]]) && (Not[ dayQ] || #[[1, 3]] == day) && (Not[codeQ] || #[[2]] == code) &][[All, 3]]], {{yrQ, False, \Year\}, {True, False}}, Range @@ {Min[#], Max[#]} &[mydata[[All, 1, 1]]]}, {{moQ, False, \Month\}, {True, False}}, {{mo, \Jan\, \\}, months}, {{dayQ, False, \Day\}, {True, False}}, {{day, 1, \\}, Range[31]}, {{codeQ, False, \Code\}, {True, False}}, {{code, codes[[1]], \\}, codes}] Dynamic[condTotal] 26.79 Bob Hanlon Hi I want to (ultimately) use Manipulate to provide date selections (year, months, days) to create a BarChart. I am able to get the results from my data in a kludgy way. The data is in the form {{yr, mo, day, h,min,sec}, code, amount}, as seen below: mydata={{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}, {{2006, 8, 23, 0, 0, 0}, 54163, 3}, {{2007, 12, 5, 0, 0, 0}, 43280, 17.25`}, {{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}} I want to conditionally total the amounts (3rd column), by yr OR by month OR by day; which I can do with : Select[mydata, #[[1, 2]] == 7 &] (* would give me all the rows in which July (7th mo) is the month, for example*) OR Select[mydata, #[[1, 1]] == 2008 &] (* would give me all the rows in which 2008 is the year *) I can sum the amounts with: Total[#[[3]] & /@ %] I need basic help with putting these into a function, but ultimately I want to be able to select yr or mo or day of week via Manipulate and get the total.... My failed attempts: (* parameters are yrmoday -> 1 is year, 2 is mo, 3 is day, and x is the specific year or month or day*) sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, myresult += #[[3]], myresult += 0] & /@ mydata; myresult OR (* this would be sum by month, if it worked...) sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, res += #[[3]], res += 0] & /@ temp; Map[ sumrvubydate2[#] &, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}] === Subject: How to resize elements in GraphicsGrid Hi Mathematica Folks, I'm trying to write a Mathematica program which will draw a Leopold Matrix. This is used in environmental science. I've managed to create a program which does indeed draw the matrix but there is just one problem - I can't seem to scale the final output properly. If I draw the graphic and make it smaller the individual elements in the GraphicsGrid don't resize properly. I've tried making the inidivual items in the grid smaller to start with (with the variable 'cellsize') but oddly that seems to have little effect. If someone could have a quick look over my code and make some suggestions I'd be VERY grateful! Otherwise when I run the program with the full set of data (something like 20 x 20) the output is going to be gargantuan. A simple operation in Mathematica to scale down the \ whole output would be ok. David. Code: cellsize=0.125; cell[x_,y_]=Graphics[ { Line[{{0,0},{cellsize,cellsize}}], Text[Style[x,Large,Bold,Black],{cellsize/4,3cellsize/4}], Text[Style[y,Large,Bold,Black],{3cellsize/4,cellsize/4}] } ]; word[x_]=Graphics[ {Text[Style[x,Large,Bold,Black],{0,cellsize/2}] } ]; vword[x_]=Graphics[ {Rotate[ Text[Style[x,Large,Bold,Black],{0,cellsize/2}], 90Degree] } ]; uppers={1,3,5,7,9,11,13,15,G}; lowers={2,4,6,8,10,12,14,F,H}; vlabels1={aardvark,beowulf,church}; vlabels2={dragon,earwig,flimflam}; vlabels3={greengrocer,hello,indigo}; hlabels1={Angstrom,Beeblebox,Chatterbox}; hlabels2={Dribble,Elongated,Freddy}; hlabels3={Glue,Hulaballo,Iridescant}; g=Grid[Table[ cell[ uppers[[3(i-1)+j]], lowers[[3(i-1)+j]] ], {i,3},{j,3} ], {Spacings->{0,0},Frame->All} ]; hl=Grid[Table[ List[ word[vlabels1[[i]]], word[vlabels2[[i]]], word[vlabels3[[i]]] ],{i,3} ], {Spacings->{0,0},Frame->All} ]; vl=Grid[Table[ List[ vword[hlabels1[[i]]], vword[hlabels2[[i]]], vword[hlabels3[[i]]] ],{i,3} ], {Spacings->{0,0},Frame->All} ]; spaces=Grid[Table[ List[ Graphics[Text[\ \]], Graphics[Text[\ \]], Graphics[Text[\ \]] ],{i,3} ], {Spacings->{0,0}} ]; GraphicsGrid[{{spaces,vl},{hl,g}},ImageSize->Tiny] === Subject: Re: Problems in fitting the experimental data with the expression >fw[w_?NumericQ, L_?NumericQ] := >NIntegrate[ 4*Pi*q^2*Exp[-(L^2*q^2)/(16* Pi^2)]/((w - (520 - >(120*(q/1.15712)^2)))^2 + (3.5/2)^2), {q, a, b}] >I want to fit the value of L. >w : values are taken from the x-data of the experiment. >FindFit[ay, fw[w, L], {L}, {ax[[1]], ax[[84]]}] >I got the error as >General::ivar: 600.58` is not a valid variable. >> The reason you are getting this error is you are not using FindFit correctly. The the basic syntax for FindFit is as follows: FindFit[data, model, parameters, variables] data needs to be a matrix with the dependent variable in the right most column. For your particular case. Setting data to Transpose@{ax,ay} will satisfy this requirement. the model needs to be an expression relating the independent variables to the dependent variable. For example, if you were doing a simple linear fit, this would be m x + b. parameters is a list of the unknown parameters in the model. For the linear model above, the parameters are {m,b} Finally, variables is a list of the independent variables in the model. For the linear model above, this would be x. This list needs to be a list of symbols and should have n-1 members where n is the number of columns in data. You have failed to meet either of these requirements since you are supplying a list of two real numbers for the variables. This is the source of the error. Notice 600.58 is the first value in ax. You simply cannot use this as a variable. So, correct syntax would be FindFit[Transpose@{ax,ay}, fw[w, L], {L}, {w}] However, while this will correct the specific error you got from fw will not work as written. In that function you have specified the limits of integration as a,b and nowhere defined a or b. Consequently, NIntegrate cannot work since it needs numeric integration limits. === Subject: Re: Weird palette stuff, still learning...Help! > hi, > > Ok, when I use my large, rich palette via CreatePalette, it just works > fine. All my dynamic stuff works, all my ActionMenus work too. But > once I save the palette and use it 'standalone' after relaunching > Mathematica, it breaks. Dynamic fails and some of the ActionMenus are > not firing when selected. Now, if I evaluate all the key cells from > its source notebook while the broken palette is up, it gets \healed\ > and works fine. Please explain to me how coding for a palette works so > to restore my sanity. ;-) Your palette is depending upon state that you've loaded in the kernel, such \ as global variables/function definitions or packages that need to be loaded. You need to initialize this state within constructs in the palette. A \ typical way to do this would be to use the Initialization option of DynamicModule. \ Any code you put in the Initialization option (which should use a RuleDelayed, recall...not a Rule) is guaranteed to run before anything in the contents \ of that DynamicModule. -John === Subject: Re: Wolfram|Alpha Lookup Tool for Mathematica Later this morning (Saturday) and at various times in the afternoon, the \I'm sorry Dave\ message, but typically if I waited a few seconds and re-submitted the query, the normal response followed. What I did not know until I watched the pre-launch video at justin.tv was that this weekend is NOT supposed to be a normal up-time, but rather a public test run. > Alas, the tool may be of limited value right now, because Wolfram|Alpha > is overloaded to the point of barely working. That's on a Saturday > morning about 10:20 a.m. EDT. > > Even when I browsed directly to wolframalpha.com, it took several > minutes for the home page to load. Then, when I typed in a query (my > birthdate), I got back a message: > > \I'm sorry Dave, I'm afraid I can't do that... > Wolfram|Alpha has temporarily exceeded its > current maximum test load. > See the live video feed of the Control Center>>\ > > Several minutes later, I tried again. I got a report back almost > immediately giving the Input interpretation and showing a date format, > but below that just 6 progress bars that kept running for several > minutes until I gave up. > > Next, I typed in one of the suggested math formulas: x^2 sin(x). I got > back information about that -- graphs, an alternate form using complex > exponentials, roots, series expansion, ..., almost immediately! (But > perhaps that one was already cached on the site?) > > >> With the release of Wolfram|Alpha I have created a small tool that >> allows you to send a query to Wolfram|Alpha directly from Mathematica. >> >> The tool is a simple dialog with an input field where you can type a >> query to be sent to Wolfram|Alpha. >> >> After entering your query in the input field simply click on the >> \Wolfram|Alpha Lookup\ button and the query will be sent to Wolfram| >> Alpha via your default web browser. >> >> You can download the tool from here: >> >> http://www.scientificarts.com/mathematicatools/blog/ >> >> or here: >> >> \ http://www.scientificarts.com/mathematicatools/blog/BE3451431867/BE3451431867\ .html >> >> Enjoy! >> >> --David >> > -- 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: Problem with parallel evaluation of integrals depending on a \ parameter like: G[s_]:=Integrate[F[x],{x,0,S}] NIntegrate[G[s],{s,0,1}] to parallel kernels. The operation is successful in the base kernel but fails in the other kernels due to the interior integral not being evaluated. The error is as follows. NIntegrate::\inumr\ : \The integrand ( SubsuperscriptBox[ =E2=88=A7 , \ 0 , \\ S ] Sin[ SubscriptBox[ =CF=86$10572 , 11 ]\\ SubscriptBox[ =CF=88$10572 \ , 11 ] [x]] \\ =C2=AE=EF=A1=BFx ) SubscriptBox[\\\F$10572\\\, \\\1\\\] [S] has \ evaluated to non- numerical \\ values for all sampling points in the region with boundaries {{0, 1}}.\ For some reason the upper bound of the interior integral is not replaced with the grid points on {0,1} in the parallel evaluation. I have Distributed the global variable definitions to the kernels after the function G[s] have been defined. I have tried several things to break this loose but have been unsuccessful. Any pointers are appreciated. AB ________________________________________________________ Alan A. Barhorst, PhD, PE | alan.barhorst@ttu.edu Professor | http://www.me.ttu.edu/ Mechanical Engineering | Phone: 806-742-3563, ext 241 Texas Tech University Lubbock, TX 79409-1021 When leaders disregard the law and human dignity, kooks are emboldened; innocence lost. Human potential cannot be developed or measured from a floating moral reference frame. ________________________________________________________ === Subject: How to execute multiple statements from one SQLExecute? I would like to execute some SQL (MySQL) that looks like this: UPDATE Table1 SET (...) WHERE Column1='SomeValue'; IF row_count() =0 INSERT INTO Table1 VALUES (...) But when I try it, Mathematica gives me the error: JDBC::error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF row_count ()=0 ... Trying another simpler test yields a similar problem: SQLExecute[conn, \SELECT * FROM TABLE1;SELECT row_count()\]; If I put the semi-colon at the end of a single statement everything is fine, but a second statement chokes SQLExecute. Therefore I'm assuming that my delimiter is ok, but that SQLExecute can't handle multiple statements. How can I get Mathematica to feed multiple statements through? Obviously if I send a second SQLExecute, row_count() is not going to be valid! Michael === Subject: Help with Agent Problem... Code: ************ \Making a World of Agents and Stuff\ makeNewWorld[agents_]:=Apply[Join,Partition[Riffle[RandomReal[{-10,10},{agen\ ts,3}],RandomInteger[9,{agents,3}]],2],1] makeNewStuff[resources_]:=RandomReal[{-10,10},{resources,3}] agentlocations=makeNewWorld[10][[All,1;;3]]; stufflocations=makeNewStuff[5]; \The Problem of Movement\ \Agents search for nearest stuff and move along the vector between their current position and that of the stuff.\ Steplist=NestList[#+Sign[stufflocations[[Map[First[Ordering[#,1]]&,Outer[Nor\ m[#1-#2]&,#,stufflocations,1]]]]-#]/10.&,agentlocations,2000]; Manipulate[ListPointPlot3D[{Steplist[[j]],stufflocations},PlotStyle->PointSi\ ze[Large]],{j,1,Length[Steplist],1}] ************* How could I alter this code so that at each iteration an IF statement (or multiple IF statements) is applied to the agents, allowing them to, say, ignore stuff that's already found by another agent? I've been trying to figure it out on my own for weeks... My idea's outpace my intelligence... === Subject: Re: Help with Agent Problem... Hi Earl, simply change the function inside NestList to e.g.: # + If[ myCheck, Sign[stufflocations[[Map[First[Ordering[#, 1]], 0] & If myCheck evaluates to True, this will do what it did so far, but if myCheck is False, the agent position is not changed. Daniel > Code: > > > ************ > > \Making a World of Agents and Stuff\ > > > \ makeNewWorld[agents_]:=Apply[Join,Partition[Riffle[RandomReal[{-10,10},{agent\ s,3}],RandomInteger[9,{agents,3}]],2],1] > > > makeNewStuff[resources_]:=RandomReal[{-10,10},{resources,3}] > > > agentlocations=makeNewWorld[10][[All,1;;3]]; > > stufflocations=makeNewStuff[5]; > > > > \The Problem of Movement\ > > > \Agents search for nearest stuff and move along the vector between their > current position and that of the stuff.\ > > > \ Steplist=NestList[#+Sign[stufflocations[[Map[First[Ordering[#,1]]&,Outer[Norm\ [#1-#2]&,#,stufflocations,1]]]]-#]/10.&,agentlocations,2000]; > > > > \ Manipulate[ListPointPlot3D[{Steplist[[j]],stufflocations},PlotStyle->PointSiz\ e[Large]],{j,1,Length[Steplist],1}] > ************* > > How could I alter this code so that at each iteration an IF statement (or > multiple IF statements) is applied to the agents, allowing them to, say, > ignore stuff that's already found by another agent? > > I've been trying to figure it out on my own for weeks... My idea's \ outpace > my intelligence... === Subject: Re: PlotLegend Hi Kenan, What's wrong with the examples in the documentation? Please, post your code so that we can see what might be the problem. On May 16, 11:17 am, \kenanso...@gmail.com\ > Hi All, > I have a problem with the usage of Legend option in a mathematica > notebook. Although I'm giving 4 legends to the plot it shows 5 legends > with one is empty. Can anyone, if has, send me a sample code for this > issue? > kenan === Subject: weird Dynamic behavior with an Inset LocatorPane I'm having problems getting LocatorPane to always properly display its locators within an inset. Here is a simple example which reproduces the problem I am seeing: w = 800; h = 600; pts = {{60, 380}}; img = Graphics[{RGBColor[1, 0, 0], Rectangle[{1, 1}, {800, 600}]}, ImageSize -> {w, h}, PlotRange -> {{1, w}, {1, h}}]; Dynamic[Pane[Graphics[{ RGBColor[0, 0, 0], Inset[ LocatorPane[Dynamic[pts], img, ImageSize -> {w, h}, LocatorAutoCreate -> True]] }, ImageSize -> {w, h}, PlotRange -> {{1, w}, {1, h}}], ImageSize -> {640, 480}, ImageSizeAction -> \Scrollable\, Scrollbars -> True]] I run this code immediately after Mathematica starts up. What is see is that the left half of the locator is missing. Occasionally it renders correctly, but then upon doing any action (even moving the mouse over the image) part of the locator disappears. But if I use slowly drag the bottom scrollbar to the right, the missing locator starts to re-appear! If it move it back to the left, part of the locator disappears again. Playing with the location of the locator there appears to be a region on the screen where the locator will not show up properly. However if I run this command: pts = Flatten[Table[{x, y}, {x, 10, 780, 20}, {y, 10, 580, 20}], 1]; Then all the locators show up properly - but on my machine there is a split second when I can see the region in which locators are not drawn. I thought maybe I was doing something wrong with Dynamic, not wrapping something in Dynamic that needed it, but various attempts to add Dynamic[] around various elements of the expression produce no change in the output. Anybody have any ideas? Michael === Subject: Followup question: Problem with parallel evaluation of integrals \ depending on a parameter when I try to feed parallel kernels the things I need evaluated. Here is a session that shows how the order of when the grid point iterates for NIntegrate are applied to an interior integral. The help menu shows how to do what I want in the main kernel, but something about using ParallelEvaluate releases the hold on the NIntegrate before the place holder symbol is assigned a numerical value. Any help is appreciated. AB ________________________________________________________ Alan A. Barhorst, PhD, PE | alan.barhorst@ttu.edu Professor | http://www.me.ttu.edu/ Mechanical Engineering | Phone: 806-742-3563, ext 241 Texas Tech University Lubbock, TX 79409-1021 When leaders disregard the law and human dignity, kooks are emboldened; innocence lost. Human potential cannot be developed or measured from a floating moral reference frame. ________________________________________________________ ParallelEvaluate[$ProcessID] testfunc6[FF_, GG_] := Module[{xxx, yyy, ff, gg}, SetSharedFunction[ff, gg]; ParallelEvaluate[ff[x_] := FF[x]]; ParallelEvaluate[gg[x_] := GG[x]]; Print[\ff[x]=\, ff[x]]; Print[\gg[x]=\, gg[x]]; SetSharedFunction[xxx]; ParallelEvaluate[xxx[S_] := Integrate[Sin[ff[x]], {x, 0, S}] // N]; Print[\xxx[.1]=\, ParallelEvaluate[xxx[.1]]]; Print[\xxx[.1]=\, xxx[.1]]; Print[\Int(xxx[S])=\, ParallelEvaluate[Integrate[xxx[S], {S, 0, 1}] // N]]; (*here since the function is subscripted it must be defined in the base kernel as well*) SetSharedFunction[yyy]; yyy[S_] := Integrate[Cos[gg[x]], {x, 0, S}] // N; ParallelEvaluate[yyy[S_] := Integrate[Cos[gg[x]], {x, 0, S}] // N]; Print[\yyy[1][.1]=\, ParallelEvaluate[yyy[1][.1]]]; Print[\yyy[1][.1]=\, yyy[1][.1]]; Print[\Int(yyy[1][S])=\, ParallelEvaluate[Integrate[yyy[1][S], {S, 0, 1}] // N]]; UnsetShared[\*\]; ] f1 = Interpolation[Table[{i, i}, {i, 0, 1, 1/2}]] f2 = 3 f1 testfunc6[f1, f2] === Subject: Why can't I perfectly align an Inset LocatorPane with its \ container? Here's the code: Module[{w, h, pts, img}, w = 800; h = 600; pts = {{60, 380}}; img = Graphics[{ RGBColor[0, 0, 1], Table[Rectangle[{x - 1, 0}, {x + 1, 600}], {x, 0, 800, 20}], Table[Rectangle[{0, y - 1}, {800, y + 1}], {y, 0, 600, 20}], Rectangle[{100, 100}, {200, 200}] }, ImageSize -> {w, h}, PlotRange -> {{0, w}, {0, h}}, PlotRangeClipping -> True]; Pane[Graphics[{ RGBColor[0, 0, 0], RGBColor[1, 0, 0], Table[Rectangle[{x - 1, 0}, {x + 1, 600}], {x, 0, 800, 20}], Table[Rectangle[{0, y - 1}, {800, y + 1}], {y, 0, 600, 20}], Rectangle[{150, 150}, {250, 250}], Opacity[0.5], Inset[ LocatorPane[Dynamic[pts], img, ImageSize -> {w, h}, LocatorAutoCreate -> True] (*,{397,302} *)] }, ImageSize -> {w, h}, PlotRange -> {{0, w}, {0, h}}, PlotRangeClipping -> True], ImageSize -> {800, 600}, ImageSizeAction -> \Scrollable\, Scrollbars -> Automatic] ] Both the inset and the containing Graphics[] are supposed to be the same size, yet for some reason the default alignment (\Center\) shows a noticable offset. If I uncomment the coordinates {392,302} (why I pretty much had to determine by visual inspection of the misalignment!) then everything aligns properly, but I'm still missing one pixel of the inset at the bottom edge, and two at the right edge. If I use a Pane instead of a LocatorPane, then the centered alignment is much closer, but it still appears to be off by one. Unrelated question, why doesn't LocatorPane have all the Options that Pane does? Specifically ImageSizeAction and ScrollPosition are missing. Michael === Subject: Followup question: Problem with parallel evaluation of integrals \ depending on a parameter into a function with a module I am trying (where X[s_]=InterpolatingFunction[...][s] func[Z_]:=Module[{xx=Z,Y},Y[S_]:=xx[S];....] Then I try func[X[S]] If I try to use Y[.1] in the module, it returns unevaluated. If I do Y[S]/.S->.1 it returns a number. So somehow I am missing how to assign the parameter S to the interpolation inside the module. Any help is appreciated. AB ________________________________________________________ Alan A. Barhorst, PhD, PE | alan.barhorst@ttu.edu Professor | http://www.me.ttu.edu/ Mechanical Engineering | Phone: 806-742-3563, ext 241 Texas Tech University Lubbock, TX 79409-1021 When leaders disregard the law and human dignity, kooks are emboldened; innocence lost. Human potential cannot be developed or measured from a floating moral reference frame. ________________________________________________________ === Subject: Re: Preventing swapping (high memory use) > Sometimes I don't realize how much memory a computation would take up > (or I simply make a mistake, and start a calculation that requires too > much memory), and my computer starts swapping. > > This makes Mathematica (and often the OS too) completely unresponsive > for a long time. In this case my only hope is that in spite of the > system unresponsiveness I can manage to kill the kernel, so that I can > at least save the notebook ... > > Is there any way to prevent swapping, for example by putting a cap on > the kernel's memory use? Even if the kernel just quits when it runs out > of memory, I still have the notebook. But if the computer gets so > unresponsive that I have to restart it, then I lose the notebook too, > which is a much more serious loss ... > > I tried using MemoryConstrained (with $Pre), but it seems to constrain > only the memory used by current computation, not the full kernel memory \ use. > > > To summarize: I'm simply looking for a way to prevent the computer from > locking up because of excessive swapping. > What OS ? === Subject: Re: Preventing swapping (high memory use) On May 18, 9:31 am, \Dr. David Kirkby\ > > Sometimes I don't realize how much memory a computation would take up > > (or I simply make a mistake, and start a calculation that requires too > > much memory), and my computer starts swapping. > > > This makes Mathematica (and often the OS too) completely unresponsive > > for a long time. In this case my only hope is that in spite of the > > system unresponsiveness I can manage to kill the kernel, so that I can > > at least save the notebook ... > > > Is there any way to prevent swapping, for example by putting a cap on > > the kernel's memory use? Even if the kernel just quits when it runs = out > > of memory, I still have the notebook. But if the computer gets so > > unresponsive that I have to restart it, then I lose the notebook too, > > which is a much more serious loss ... > > > I tried using MemoryConstrained (with $Pre), but it seems to constrain > > only the memory used by current computation, not the full kernel \ memory= use. > > > To summarize: I'm simply looking for a way to prevent the computer f= rom > > locking up because of excessive swapping. > > What OS ? WinXP on a laptop (i.e. slow hard drive). === Subject: \SelectionData\ and palettes With[ {p = ToExpression[CurrentValue[InputNotebook[], \SelectionData\]]}, PresentTmpls[p] I found a similar code fragment on MathGroup. I wanted to use it in my palette. However, once the palette is standalone it fails to work; otherwise within a current session of a notebook it works fine. Is there a more stable way to grab a text selection so it can be used for Andrew === Subject: Re: \SelectionData\ and palettes follow up, this code work fine as a button but once used in an actionMenu it fails to work. Is there some kind of hidden stuff going on for ActionMenu that prevents this. Seeking clarity. === Subject: Re: Future for Mathematica on Solaris > I was interested in purchasing a copy of Mathematica for Solaris, but > have seen various things on the net suggesting the Solaris (and to a > lesser extent linux) versions are more buggy than the Windows version. > > Looking on the Wolfram web site where one can request a trial > > http://www.wolfram.com/products/mathematica/experience/request.cgi > > I find one can't request a trail on Solaris from the web site. > > So I contacted Wolfram Research directly by email and asked about a > 14-day save-disabled trail. I received a reply in a couple of days, > telling me no trial version of Mathematica exists for Solaris. > > Given the Solaris version is more expensive than the windows one, > there are various reports of bugs on Solaris, and one can't even get a > trail version, it does beg the question whether Wolfram Research are > serious about the future of Mathematica on Solaris. > > Peter > Was this for SPARC or x86? When I was a lot younger, Sun were pretty much the defacto standard in scientific computing. But now the SPARC processors are simply not up to but I don't think it is in scientific computing like it used to be. So it would not surprise me if there was not a long term commitment to Mathematica on SPARC and perhaps Wolfram decision not to make a trial available is a result of that. I see Solaris x86 as having a bright future. It's much more stable than Linux (stable in the sense that not there are not n-million distributions all a bit different.) It is also very fast and growing in user base now it is open-source. Given 3) A fix to Mathematica to allow it to run on Intel processors is quite easy (just replace a couple of libraries from those supplied by WRI to those supplied by Sun) I am somewhat surprised Wolfram have not made more effort for Solaris x86. So perhaps Solaris support will be dropped, like HP-UX support was recently dropped. Having seem various talks from WRI staff, its clear that almost all their staff's usage is on Windows. Unless more effort is made to get their staff to regularly use other platforms, bugs are far more likely to be found internally on Windows than on those other platforms. Hence users of the rarer platforms are more likely to encounter bugs. (That's my theory anyway - it might be completely wrong). === Subject: trying to \install\ a palette... CreatePalette[ Button[\Delete Output\, FrontEndTokenExecute[\DeleteGeneratedCells\]; FrontEndTokenExecute[\Save\]]] When the above code is executed inside a notebook, a palette is created on \ the desktop that works (I still have to select \yes\, that I want to delete \ the cells for some reason). But now I'd like to have this pallete come up when I start M7. The only help \ I get from Wolfram says I need to \install palette\ (that's all the detail \ I get). Since the Palette menu under install gives the Clipboard as a source, \ I tried that (after copying the above code into the Clipboard). Nothing \ happens if I select \your user Mathematica base directory\ but if I select \ \System-wide Mathematica directory\, the window closes. Since I see no palette anywhere, I shut down and restart M7, still nothing. I put the above code in a file and saved it as xx.nb. I tried using that as \ a source, same thing happens, no palette gets installed immediately or when I \ restart. I've about run out of things to try. Can someone please give me a hint on \ how to install a palette -- or point me to some insructions? I simply can't \ find any help in my Wolfram HELP system. === Subject: Re: creating Graphics using ParallelTable[] > I generate \video frames\ from time-consuming 3DPlot[]s > (to export them into a video file later on): > > frame[x_] := Plot3D[... something big using x ...]; > movieframes = Table[frame[x], {x, start, end, > (end-start)/steps}]; > > I have a double core CPU; so now I would like to create > these frames in parallel with Mathematica 7, using > ParallelTable[]. But I don't derive any advantage from > doing this: As you mention in you message, there is overhead associated with parallel processing so it is certainly possible for a parallel implementation to run slower. It's hard to know what's going on without a closer look at your code but I would not be too surprised if a two core machine doesn't yield much benefit on this type of problem. Here's a specific example: frame[R_] := ParametricPlot3D[ {r*Cos[t], r*Sin[t], Sin[(r*R)^2]/r}, {r, 0, 1}, {t, 0, 2 Pi}, PlotPoints -> 100, BoxRatios -> {1, 1, 1/3}]; Table[frame[R], {R, 0.5, 5, 0.5}]; // AbsoluteTiming This runs in about 8 seconds on my Mac Pro running V7.0. The following runs in only 3 seconds: LaunchKernels[]; DistributeDefinitions[frame]; ParallelTable[frame[R], {R, 0.5, 5, 0.5}]; // AbsoluteTiming My machine launches 8 kernels when I do that, but I certainly didn't get an eight-fold increase in speed. Furthermore, my laptop (which gives me only 2 kernels) runs the parallel version with no speed up at all. One reason that we might not expect this example to run well in parallel is that the run time of frame[n] varies quite a lot with n. If the computation is broken into halves, the second half takes much more than half the computation time. > My Windows taskmanager shows three \MathKernel.exe\. > When I use ParallelTable[] for the described problem, > only one \MathKernel.exe\ is working, causing 50% CPU Now that is strange. This is not at all what I see on my Mac. Mark McClure === Subject: Re: creating Graphics using ParallelTable[] Jan-Philip, I have no idea what's the problem in your case. I have been doing something very similar and it worked nicely. Both CPU load indicators at a full 100%. > Hello all, > > I generate \video frames\ from time-consuming 3DPlot[]s (to export > them into a video file later on): > > frame[x_] := Plot3D[... something big using x ...]; > movieframes = Table[frame[x], {x, start, end, (end-start)/steps}]; > > I have a double core CPU; so now I would like to create these frames > in parallel with Mathematica 7, using ParallelTable[]. But I don't > derive any advantage from doing this: > > My Windows taskmanager shows three \MathKernel.exe\. When I use > ParallelTable[] for the described problem, only one \MathKernel.exe\ > > $ProcessorCount is 2, there is 1 \master\ and 2 \local\ in \Parallel > Kernel Status\. The \parallelizeabletest\ ParallelTable[$KernelID, > {10}] succeeds. > > I tried `DistributeDefinitions[frame];` before invoking ParallelTable > [], but it did not change anything. > > One core needs about 20 seconds to create one single frame without > displaying it: An extensive analytical function (among others there > are nested Coth[]s) has to be calculated with Plotpoints->100 option. > > In my opinion - simply expressed - each core can take one `x` out of > the queue and create the corresponding 3DPlot Graphics object, while > the other core is doing the same. This should work, because the tasks > are totally independent and my way to use the Table[] is the least > complex one. I don't see the \data management overhead\ that often > reduces or even prevents advantages from parallelizing, because each > core just needs to get the function definitions and a simple number: > `x` - no more overhead. > > (At which point) do I think wrong or does Mathematica work weird (less > likely..)? > > Is there a way for me to create these frames using all my CPU power? > > Sincereley, > > Jan-Philip Gehrcke === Subject: Re: creating Graphics using ParallelTable[] frame[t_?NumericQ] := Plot3D[Sin[x*y + t], {x, 0, Pi}, {y, 0, Pi}, PlotPoints -> 128] DistributeDefinitions[frame] movieframes = ParallelTable[frame[x], {x, 0, 16, 1}]; ListAnimate[movieframes] gives a speedup of 3.26 in the Parallel Kernel Status window on my Quad core May be it help you post the full code and not only fragments. Jens > Hello all, > > I generate \video frames\ from time-consuming 3DPlot[]s (to export > them into a video file later on): > > frame[x_] := Plot3D[... something big using x ...]; > movieframes = Table[frame[x], {x, start, end, (end-start)/steps}]; > > I have a double core CPU; so now I would like to create these frames > in parallel with Mathematica 7, using ParallelTable[]. But I don't > derive any advantage from doing this: > > My Windows taskmanager shows three \MathKernel.exe\. When I use > ParallelTable[] for the described problem, only one \MathKernel.exe\ > > $ProcessorCount is 2, there is 1 \master\ and 2 \local\ in \Parallel > Kernel Status\. The \parallelizeabletest\ ParallelTable[$KernelID, > {10}] succeeds. > > I tried `DistributeDefinitions[frame];` before invoking ParallelTable > [], but it did not change anything. > > One core needs about 20 seconds to create one single frame without > displaying it: An extensive analytical function (among others there > are nested Coth[]s) has to be calculated with Plotpoints->100 option. > > In my opinion - simply expressed - each core can take one `x` out of > the queue and create the corresponding 3DPlot Graphics object, while > the other core is doing the same. This should work, because the tasks > are totally independent and my way to use the Table[] is the least > complex one. I don't see the \data management overhead\ that often > reduces or even prevents advantages from parallelizing, because each > core just needs to get the function definitions and a simple number: > `x` - no more overhead. > > (At which point) do I think wrong or does Mathematica work weird (less > likely..)? > > Is there a way for me to create these frames using all my CPU power? > > Sincereley, > > Jan-Philip Gehrcke > === Subject: Re: Map conditional sums by date > Hi Charles, > > the following will do what you want and more, since the first setting of > each slider is \All\, which allows you to total over the full range of \ it= ems > this slider is responsible for (day, month or year), and thus you can \ dec= ide > if you want AND or OR logic for each item, and therefore be as specific \ o= r > as general as you wish. > > Clear[getUI]; > getUI[data_] := > Module[{months, monthSelect, yearSelect, daySelect, totalize, years, > days}, > months = {All, \Jan\, \Feb\, \Mar\, \Apr\, \May\, \Jun\, \ \Jul\, > \Aug\, \Sep\, \Oct\, \Nov\, \Dec\}; > years = Prepend[Union@data[[All, 1, 1]], All]; > With[{part = #2}, #1[arg_] := > Select[#, #[[1, part]] == arg &] &] & @@@ > Transpose[{{yearSelect, monthSelect, daySelect}, {1, 2, 3}}]; > daySelect[0] = yearSelect[All] = monthSelect[0] = # &; > totalize = Total[#[[All, 3]]] &; > days = Prepend[Range[31], All]; > Manipulate[ > Grid[{{\Year\, \Month\, \Day\, \Amount\}, {years[[j]], > months[[i]], days[[k]], > totalize@ > yearSelect[years[[j]]]@ > monthSelect[i - 1]@daySelect[k - 1]@data}}, > Frame -> All], {{i, 1, \Month\}, 1, 13, 1}, {{j, 1, \Year\}, 1= , > Length[years], 1}, {{k, 1, \Day\}, 1, Length[days], 1}, > Alignment -> Center]]; > > Usage: > > getUI[mydata], > > with from your e-mail. Note that I made explicit use of your > specific format and therefore you have to maintain it for this to work. > The main idea of this implementation is that 3 selector functions > monthSelect, yearSelect, daySelect select the corresponding records > and pass the resulting structure to the next selector function in the \ cha= in. > If any of them receives the parameter, it simply stays idle and \ pas= ses > the entire data to the next selector function. > > It shouldn't be hard to attach a barchart-generating code to this if \ need= ed. > > Hope this helps. > > Leonid > ote: > > > Hi > > > I want to (ultimately) use Manipulate to provide date selections > > (year, months, days) to create a BarChart. I am able to get the > > results from my data in a kludgy way. The data is in the form {{yr, > > mo, day, h,min,sec}, code, amount}, as seen below: > > > mydata={{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}, {{2006, 8, 23, 0, 0, > > 0}, 54163, 3}, {{2007, 12, 5, 0, 0, 0}, 43280, 17.25`}, {{2009, 2, > > 5, > > 0, 0, 0}, 54161, 3.27`}} > > > I want to conditionally total the amounts (3rd column), by yr OR by > > month OR by day; which I can do with : > > > Select[mydata, #[[1, 2]] == 7 &] > > (* would give me all the rows in which July (7th mo) is the month, for > > example*) > > OR > > Select[mydata, #[[1, 1]] == 2008 &] > > (* would give me all the rows in which 2008 is the year *) > > > I can sum the amounts with: > > Total[#[[3]] & /@ %] > > > I need basic help with putting these into a function, but ultimately I > > want to be able to select yr or mo or day of week via Manipulate and > > get the total.... > > > My failed attempts: > > > (* parameters are yrmoday -> 1 is year, 2 is mo, 3 is day, and x is > > the specific year or month or day*) > > > sumbydate[x_, yrmoday_] := > > If[#[[1, yrmoday]] == x, myresult += #[[3]], myresult += 0] = & /@ > > mydata; myresult > > > OR > > > (* this would be sum by month, if it worked...) > > > sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, res += #[[3= ]], res > > += 0] & /@ temp; Map[ > > sumrvubydate2[#] &, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}] > Both of these solutions work perfectly. cls === Subject: Interesting Mersenne identities and a prime based graph sequence My original line of thought this identity: Mod[2^n-1,3] =Mod[n,2] Are there others? Table[Mod[2^(2^n - 1) - 1, 7], {n, 1, 10}] {1, 0, 1, 0, 1, 0, 1, 0, 1, 0} Mod[2^(2^n - 1) - 1, 7]=Mod[n,2] What about? Mod[2^(2^(2^n - 1) - 1) - 1, 15] Mod[2^(2^(2^(2^n - 1) - 1) - 1) - 1, 31] That gave me the idea for: t[n,m]=Mod[Prime[n]^m-2,Prime[n+1] where t[n,m]=0 The pairs {n,m} seems to form a connected graph to n=m=10 at least. http://www.geocities.com/rlbagulatftn/prime_graph100.gif The idea of a way of connecting the primes to some graph pattern seems a new one at least to me. The graph isn't connected at 20 and appears more random. At 100 primes which is about what I can get out of my Mathematica version on my old computer, the graph begins to look like a random natural network ( the appearance of the primes is sometimes said to be \normal\). This method at least gives a visualization of that chaos. It also gives a quantization in terms of spectral graph theory in which roots can be associated to different levels of primes. It seems very lucky that I noticed a pattern in the appearance of these zeros. Mathematica: << DiscreteMath`GraphPlot`; << DiscreteMath`ComputationalGeometry` << DiscreteMath`Combinatorica` t[n_, m_] = Mod[Prime[n]^m - 2, Prime[n + 1]] n0 = 20 g1 = Delete[Union[Flatten[Table[If[t[n, m] == 0, {n, m}, {}], {n, 1, n0}, {m, 1, n0}], 1]], 1] g2 = Table[Reverse[g1[[n]]], {n, 1, Length[g1]}] Length[%] g3 = Join[g1, g2] Length[%] a = Table[0, {n, n0}, {m, n0}]; Table[If[n == g3[[k, 1]] && m == g3[[k, 2]], a[[n, m]] = 1, {}], {k, 1, Length[g3]}, {n, n0}, {m, n0}]; a CharacteristicPolynomial[a, x] \⁃Graph:< 27 20 \Undirected\>⁃ GraphPlot3D[a] What I'm wondering is if there is a way to get a correspondence of NSolve[CharacteristicPolynomial[a, x]==0,x] type roots to the primes involved: new root<->{ Prime[n],Prime[n+1]}<->{n,m} edge Roger Bagula === Subject: Solve a couple mode equation with Mathematica. To whom my concern, w = 2 *\\[Pi]*f; c = 3*10^8; nnl = 0.01; L = 3000*10^-6; eqns1 = A1'[z] == -(w/c)*(2*nnl)/\\[Pi]*((Abs[A1 (z)])^2 + (Abs[A2 (z)]) ^2)*A2[z]; eqns2 = A2'[z] == -(w/c)*(2*nnl)/\\[Pi]*((Abs[A1 (z)])^2 + (Abs[A2 (z)]) ^2)*A1[z]; eqns3 = A1[0] == 1; eqns4 = A2[L] == 0; DSolve[{eqns1, eqns2, eqns3, eqns4}, {A1[z], A2[z]}, z] I am trying solve A1[z] and A2[z] in terms of f. Any help will be appreciated. === Subject: Use of names Hi I would like to import files from directories (e.g .png files) The names are not always the same but the extension is. I could find them by the command: FileNames[\*.png\] which gives their names, but how could I import all of them since the = command : Import[\TEMPO_*.png\] does not work in Mathematica Files examples: {\TEMPO_ALL_histo.png\, \TEMPO_histo_17.png\} Alain Mazure Laboratoire d'Astrophysique de Marseille P=F4le de l'=C9toile Site de Ch=E2teau-Gombert 38, rue Fr=E9d=E9ric Joliot-Curie 13388 Marseille cedex 13, France http://alain.mazure.free.fr/ Mails: alain.mazure@oamp.fr alain.mazure@free.fr Phones: Lab: 33(0)491055902 Mobile: 33(0)603556287 Fax: 33(0)491661855 SKYPE: MAZURE-ALAIN === Subject: Re: saving initialization cells as a .m file Hi Baris, if you want b^\\[Dagger] to mean SuperDagger[b] internall, you may define this e.g. by: Clear[SuperDagger, A]; SuperDagger[A_List] := Conjugate[Transpose[A]]; Format[A_^\\[Dagger], SuperDagger[A_]]; SuperDagger /; A_^\\[Dagger] := SuperDagger[A]; The Format line ensures that Dagger is printed instead of SuperDagger. The next line transforms an input of SuperDagger to Dagger. You may check the working by: b =.; SuperDagger[b] b^\\[Dagger] // FullForm Daniel > === > Subject: Re: saving initialization cells as a .m file > > Hi Baris, > f[t]= ^\\[Dagger] does not apply SuperDagger. > You would have to say SuperDagger[f[t]] > Daniel > > I have the following code which runs fine in a > notebook: > SuperDagger[A_List] := Conjugate[Transpose[A]] > eqn = {f'[t] == -f[t]^\\[Dagger].f[t], f[0] == > RandomReal[{0, 0.1}, {3, 3}]}; > NDSolve[eqn, f, {t, 0, 10}] > but when I save the first two lines (definition of > SuperDagger and eqn) in a .m file and load them with a Get > command, although Mathematica loads the definitions, NDSolve > doesn't like the input and complains that derivative at t=0 > is not defined. Weirdly if I copy and paste the output of > NDSolve and evaluate it, it runs fine. Do you know how can I > fix this? > Baris Altunkaynak > > === Subject: Re: saving initialization cells as a .m file Hi Baris, I think this is a Mathematica bug involving SuperDagger. SuperDagger[x] prints as an x with a superscripted dagger. When you type x ctrl-^ esc dg esc == SuperDagger[x] you get True. However, x ^ esc dg esc (without ctrl together with ^) prints as something very similar, but it isn't. Check the two for equality and you get False. Internally, the first one is represented as SuperDagger [x] and the second one as Power[x, \\[Dagger]]. Now, the bug is that if you copy the real SuperDagger (x ctrl-^ esc dg esc) to a text file, it is stored as ^\\[Dagger]. If this is read in on its turn it is interpreted as a dagger power which doesn't work. Mathematica should have copied it as SuperDagger[ ]. If I run the code directly as shown in your post I get the same error you are reporting. If I replace the dagger with the ctrl-^ version it works. So, the workaround is changing the f[t]^\\[Dagger] part in your .m file in SuperDagger[f[t]]. I guess you should send in a bug report. On May 15, 10:13 am, Baris Altunkaynak > > I have the following code which runs fine in a notebook: > > SuperDagger[A_List] := Conjugate[Transpose[A]] > eqn = {f'[t] == -f[t]^\\[Dagger].f[t], f[0] == RandomReal[{0, 0.= 1}, {3, 3}]}; > NDSolve[eqn, f, {t, 0, 10}] > > but when I save the first two lines (definition of SuperDagger and eqn) \ i= n a .m file and load them with a Get command, although Mathematica loads \ th= e definitions, NDSolve doesn't like the input and complains that \ derivative= at t=0 is not defined. Weirdly if I copy and paste the output of NDSolve= and evaluate it, it runs fine. Do you know how can I fix this? > > > Baris Altunkaynak === Subject: Re: saving initialization cells as a .m file Daniel, [x]. > Hi Baris, > > f[t]^\\[Dagger] does not apply SuperDagger. > > You would have to say SuperDagger[f[t]] > > Daniel > > > > I have the following code which runs fine in a notebook: > > > SuperDagger[A_List] := Conjugate[Transpose[A]] > > eqn = {f'[t] == -f[t]^\\[Dagger].f[t], f[0] == RandomReal[{0, = 0.1}, {3, 3}]}; > > NDSolve[eqn, f, {t, 0, 10}] > > > but when I save the first two lines (definition of SuperDagger and \ eqn)= in a .m file and load them with a Get command, although Mathematica loads \ = the definitions, NDSolve doesn't like the input and complains that \ derivati= ve at t=0 is not defined. Weirdly if I copy and paste the output of NDSol= ve and evaluate it, it runs fine. Do you know how can I fix this? > > > > Baris Altunkaynak === Subject: problem in expression I am wondering if some one can help me in the following problem. Whenever I solve or do some manipulation with certain matrix or vector, it gives me result in the following form e.g. F=0.x1+0.x2+1.x3+0.x4 It is clear that F=x3 but why the expression contains multiples of zeros. If certain vector is multiplied by zero the result should be zero and it must not be appear in the final expression. Could you people please help me out to get rid of these zeros in the final expression? Obaid === Subject: Re: How to resize elements in GraphicsGrid you should use a scalable fontsize. E.g.: FontSize -> Scaled[0.1] But this does not fix everything. GraphicsGrid does not listen to the option: ImageSize->Automatic. It should display all of the pictures without truncation. This looks to me like a bug, maybe you want to tell Wolfram. Daniel > Hi Mathematica Folks, > > I'm trying to write a Mathematica program which will draw a Leopold \ Matrix. > This is used in environmental science. I've managed to create a > program which does indeed draw the matrix but there is just one > problem - I can't seem to scale the final output properly. If I draw > the graphic and make it smaller the individual elements in the > GraphicsGrid don't resize properly. I've tried making the inidivual > items in the grid smaller to start with (with the variable 'cellsize') > but oddly that seems to have little effect. > > If someone could have a quick look over my code and make some > suggestions I'd be VERY grateful! Otherwise when I run the program > with the full set of data (something like 20 x 20) the output is going > to be gargantuan. A simple operation in Mathematica to scale down the \ whole > output would be ok. > > David. > > Code: > > cellsize=0.125; > cell[x_,y_]=Graphics[ > { > Line[{{0,0},{cellsize,cellsize}}], > Text[Style[x,Large,Bold,Black],{cellsize/4,3cellsize/4}], > Text[Style[y,Large,Bold,Black],{3cellsize/4,cellsize/4}] > } > ]; > > word[x_]=Graphics[ > {Text[Style[x,Large,Bold,Black],{0,cellsize/2}] > } > ]; > > vword[x_]=Graphics[ > {Rotate[ > Text[Style[x,Large,Bold,Black],{0,cellsize/2}], > 90Degree] > } > ]; > > > uppers={1,3,5,7,9,11,13,15,G}; > > lowers={2,4,6,8,10,12,14,F,H}; > > > vlabels1={aardvark,beowulf,church}; > vlabels2={dragon,earwig,flimflam}; > vlabels3={greengrocer,hello,indigo}; > > hlabels1={Angstrom,Beeblebox,Chatterbox}; > hlabels2={Dribble,Elongated,Freddy}; > hlabels3={Glue,Hulaballo,Iridescant}; > > g=Grid[Table[ > cell[ > uppers[[3(i-1)+j]], > lowers[[3(i-1)+j]] > ], > {i,3},{j,3} > ], > {Spacings->{0,0},Frame->All} > ]; > > hl=Grid[Table[ > List[ > word[vlabels1[[i]]], > word[vlabels2[[i]]], > word[vlabels3[[i]]] > ],{i,3} > ], > {Spacings->{0,0},Frame->All} > ]; > > vl=Grid[Table[ > List[ > vword[hlabels1[[i]]], > vword[hlabels2[[i]]], > vword[hlabels3[[i]]] > ],{i,3} > ], > {Spacings->{0,0},Frame->All} > ]; > > spaces=Grid[Table[ > List[ > Graphics[Text[\ \]], > Graphics[Text[\ \]], > Graphics[Text[\ \]] > ],{i,3} > ], > {Spacings->{0,0}} > ]; > > GraphicsGrid[{{spaces,vl},{hl,g}},ImageSize->Tiny] >