Subject: Re: Export with jLink >I want to use the power of mathematica from java. >I would like to extract data from a database (oracle), make some >calculations, creates plots and put those plots in a pdf file. >I created a mathematica package which generates plots and export them in >.wmf files. >This works when the package is executed in mathematica, but when this >package is called from java with jLink, empty wmf files are created. Jerome, You will need to provide more details to get any specific help, but I have a suggestion that will probably allow you to find the problem easily. When you use J/Link to call Mathematica, you normally see only the result of the computation, not the full sequence of Print and Message output that is generated. It is very likely that your program is failing in a simple way, but you just can't see it because you do not see warning messages coming from Mathematica. An extremely useful and simple debugging technique is to use J/Link's PacketPrinter class to log all the output that Mathematica sends to your program. This is as simple as adding one line: ml.addPacketListener(new PacketPrinter()); This will cause all the packets that Mathematica sends to Java to be printed on System.out. If your program is not a console program, you can display J/Link's built-in console window by adding just a few lines more (do this before you want to start logging): // At the start of your program: import com.wolfram.jlink.ui.*; .... ConsoleWindow cw = ConsoleWindow.getInstance(); cw.setSize(450, 400); cw.show(); cw.setCapture(ConsoleWindow.STDOUT | ConsoleWindow.STDERR); If you do this, it's likely that you will see the problem right away--a package isn't being found, a function is returning unevaluated because you gave it bad arguments, etc. Todd Gayley Wolfram Research === Subject: Re: plotting groups of polynomial roots This idea was inspired by the w cummutator of Potter matrix groups: ( in this month's Math Monthly journal) A.B=wB.A A^q+B^q=(A+B)^q When A and B are unitary matrices it suggests the root group: x^q+1=(x+1)^q They are an interesting group of polynomials. The de Moivre relationship is: (Cos[t]+I*Sin[t])^n=Cos[n*t]+I*Sin[n*t]=Exp[I*n*t] So the relationship to the unit circle isn't unexpected, but it is nice. The other roots are what makes the result interesting. If nothing else it is a new way to look at Pascal's triangle. >>If you take the first and last term away from a binomial polynomial and >>set the result equal to zero, >>you get a number of strange roots. >>This method allows you to plot such roots. >>but I plan to use it in the future >>on some other polynomial root structures. >>(* root group where x^q+1=(x+1)^q: binomial expansion without x^q and 1*) >>digits=21 >>s[q_]=Sum[(q!/((q-k)!*k!))*x^(q-k),{k,1,q-1}] >>ExpandAll[s[2]] >>ExpandAll[s[3]] >>a=Flatten[Table[x/. NSolve[s[n]==0,x],{n,2,digits}]]; >>a0=Floor[Abs[a]] >>Dimensions[a][[1]] >> >continued... >b = Table[{Re[a[[n]]], Im[a[[n]]]}, {n, 1, Dimensions[a][[1]]}]; >ChopEnds = ListPlot[b, PlotRange -> {{-1, 2}, {-1, 1}}]; >central = ParametricPlot[{Cos[t], Sin[t]}, {t, 0, 2 Pi}]; >displ = ParametricPlot[{Cos[t] - 1, Sin[t]}, {t, 0, 2 Pi}]; >Show[ChopEnds, central, displ]; >Hi Roger, >The roots are neatly herded onto unit circles centered on (0,0) and >(-1,0), (except one point (-0.5, +/-1), as may be expected for complex >roots of z^(1/n),(z+1)^(1/n) somehow with only negative real parts, >|x|<1 . -- Respectfully, Roger L. Bagula tftn@earthlink.net, 11759Waterhill Road, Lakeside,Ca 92040-2905,tel: 619-5610814 : URL : http://home.earthlink.net/~tftn URL : http://victorian.fortunecity.com/carmelita/435/ === Subject: Re: Strange PV results from Integrate > Could somebody pls check if these results persist in 5.0? Thx. > $Version > 4.2 for Power Macintosh (August 27, 2002) > Integrate[Log[ 2+2*Cos[x] ], {x,-Pi,Pi}] > 0 (* correct *) > Integrate[Log[ 2*(1+Cos[x]) ], {x,-Pi,Pi}] > identical integrand returns unevaluated > Integrate[Log[ -2-2*Cos[x] ], {x,-Pi,Pi}]//InputForm; > (2*I)*Pi^2 (* correct *) > Integrate[Log[ -2*(1+Cos[x]) ], {x,-Pi,Pi}] > identical integrand returns unevaluated > Integrate[Log[ 1+ Cos[x] ], {x,-Pi,Pi}] > (I/2)*Pi^2 - 2*Pi*Log[1 + I] - Pi*Log[2] (* wrong *) > FullSimplify[Integrate[Log[ 1+ Cos[x] ], {x,-Pi,Pi}]] > -(Pi*Log[4]) (* wrong *) > These integrals arise on applying the first Szego theorem > to some benchmark infinite Toeplitz matrices. Results > labelled wrong contradict the theorem. An update: a student with 5.0.1 did the tests and the unevaluated integral cases return the values 0 and 2*I*Pi^2. The last value is fine and agrees with Szego theorem. I had the wrong sign in the real part of his Toeplitz asymptotic expansion. The PV for Log[ a*(2+2*Cos[x])] in [-Pi,Pi] should be 2*Pi*Log[a], so the - sign is correct if a=1/2. === Subject: Re: Strange PV results from Integrate > Could somebody pls check if these results persist in 5.0? Thx. > $Version > 4.2 for Power Macintosh (August 27, 2002) > Integrate[Log[ 2+2*Cos[x] ], {x,-Pi,Pi}] > 0 (* correct *) > Integrate[Log[ 2*(1+Cos[x]) ], {x,-Pi,Pi}] > identical integrand returns unevaluated > Integrate[Log[ -2-2*Cos[x] ], {x,-Pi,Pi}]//InputForm; > (2*I)*Pi^2 (* correct *) > Integrate[Log[ -2*(1+Cos[x]) ], {x,-Pi,Pi}] > identical integrand returns unevaluated > Integrate[Log[ 1+ Cos[x] ], {x,-Pi,Pi}] > (I/2)*Pi^2 - 2*Pi*Log[1 + I] - Pi*Log[2] (* wrong *) > FullSimplify[Integrate[Log[ 1+ Cos[x] ], {x,-Pi,Pi}]] > -(Pi*Log[4]) (* wrong *) > These integrals arise on applying the first Szego theorem > to some benchmark infinite Toeplitz matrices. Results > labelled wrong contradict the theorem. Mathematica 5.0 certainly gives the correct values to the first four integrals. As for the last one, well, that's what happens: Integrate[Log[1 + Cos[x]], {x, -Pi, Pi}] (-Pi)*Log[4] N[%] -4.35517 Although you assert this is wrong the result given by Integrate is confirmed by the following numerical check: <0] -4.35517 However, as I have never heard of the first (or any other) Szego theorem I shall leave to the experts the question who is right and wrong here. === Subject: Re: Sterographic plotting program > Has anyone implemented a program to plot stereograms in Mathematica? > Stereograms are used in crystallography to plot the positions of faces > (and other planes) on crystals.[1] > In the following, Loxodromes making +/- 30 Degree to any meridian are > stereographically projected onto plane tangential to South Pole as > equi-angular/Logarithmic spirals. Please add 4 or 6 Loxos around polar > axis to get a full pattern. (Avoided it, as it may clutter up the > graphic). I remember a beautiful picturization similar to this in > 'Mathographics' by Dixon Robert.A., New York, Dover, 1991. Also take a small circle on sphere and project stereographically it on south pole tangent plane, it is again a circle. === Subject: Re: argMax >I've written this without any testing, so I can't tell whether it's faster >or not than your solution (if it happens to be so, it won't be much faster, >though). > ArgMax[f_, arglist_List] := > Module[ > {spectrum}, > spectrum = f /@ arglist; > Flatten[Take[arglist, #] & /@ Position[spectrum, Max[spectrum]]] > ] It is indeed a little bit faster, and this version is just a bit more so (please note the numericization of the list, remove N[ ] if that is a problem): ArgMax[f_, arglist_List] := With[ {spectrum = N[f /@ arglist]}, Apply[arglist[[#]] & , Position[spectrum, Max[spectrum]], 1] ] f[x_] := -x^2 + 7x arglist = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; ArgMax[f, arglist] >Or a multidimensional one, that can give you a list of coordinates of the >points giving you a max. > ArgMax[f_, arglist_List] := > Module[ > {spectrum}, > spectrum = Map[f, arglist, -1]; > Take[arglist, #] & /@ Position[spectrum, Max[spectrum]] > ] Sorry, this won't work. Try this instead for functions of several variables: ArgMax[f_, arglist_List] := Module[ {newarg = Flatten[arglist, Depth[arglist] - 3], spectrum}, spectrum = N[Apply[f, newarg, {-2}]]; Apply[newarg[[#]] & , Position[spectrum, Max[spectrum]], 1] ] f[x_, y_] := Sin[x] - Cos[3y] {arglist = Flatten[Table[{x, y}, {x, 0, 3}, {y, 2, 4}], 1], ArgMax[f, arglist]} {arglist = Table[{x, y}, {x, 0, 3}, {y, 2, 4}], ArgMax[f, arglist]} f[x_, y_, z_] := Sin[x] - Cos[3y] + z {arglist = Table[{x, y, z}, {x, 0, 3}, {y, 2, 4}, {z, -1, 1}], ArgMax[f, arglist]} cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: Re: argMax The dichotomy isn't really one-dimensional versus multi-dimensional, I think; it's values versus positions. These should work for data of any shape at all: positions[f_,arglist_List]:=Module[{spectrum=Map[f,arglist,-1]}, Position[spectrum,Max[spectrum]]] values[f_,arglist_List]:=Extract[arglist,positions[f,arglist]] data=Array[Random[Integer,10]&,{10,5}] values[Identity,data] positions[Identity,data] {{9,5,0,5,4},{7,2,3,6,10},{5,3,0,1,10},{10,1,4,1,3},{8,6,4,1,6},{9,0, 0,7,1},{0,7,9,0,10},{5,8,2,8,8},{0,3,3,7,7},{5,3,9,9,5}} {10,10,10,10} {{2,5},{3,5},{4,1},{7,5}} Bobby >> I miss a fast internal function ArgMax. >> but this will be much slower that Max. How can I have a faster argMax ? > I've written this without any testing, so I can't tell whether it's faster > or not than your solution (if it happens to be so, it won't be much faster, > though). > You can either have a version of ArgMax that works for onedimensional lists > giving you a list of the elements that produce a max (you can have more than > one)... > ArgMax[f_, arglist_List] := > Module[ > {spectrum}, > spectrum = f /@ arglist; > Flatten[Take[arglist, #] & /@ Position[spectrum, Max[spectrum]]] > ] > Or a multidimensional one, that can give you a list of coordinates of the > points giving you a max. > ArgMax[f_, arglist_List] := > Module[ > {spectrum}, > spectrum = Map[f, arglist, -1]; > Take[arglist, #] & /@ Position[spectrum, Max[spectrum]] > ] > (pattern matching can be adopted to have the proc automatically choose the > code to be employed). > hope this helps, > Peltio > -- > Invalid address in reply-to. Crafty demunging required to mail me. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Re: argMax I definitely should have tested with functions other than Identity. Bobby >> The dichotomy isn't really one-dimensional versus multi-dimensional, I > think; it's values versus positions. > Since the OP was looking for a fast procedure I thought it would have been > better to use 'dedicated' functions for each special case in order to keep > the overhead to a minimum. I got my second procedure totally wrong though. > Yours is fine, instead, but... >> positions[f_,arglist_List]:= >> Module[ >> {spectrum=Map[f,arglist,-1]}, >> Position[spectrum,Max[spectrum]] >> ] >> values[f_,arglist_List]:=Extract[arglist,positions[f,arglist]] > I think you had a 'lapsus digitae' after reading my mistake. : ) In fact > Map[f,arglist,-1] > should read > Map[f,arglist,{-1}] > (with onedimensional lists and Identity there are no differences since > either there is no nesting or when there is nesting, nesting Identity won't > change anything). > I was thinking about a way to make the procedure a little faster, but I fear > there is little room for improvement (at least without a real breakthrough - > such as an undocumented function that does just that : )))). > For a start: if the function f to be applied is rather complicated, it could > be advisable to use N. > Also, when the procedure ArgMax is called many times. using With instead of > Module could reduce its overhead (or at least I think so [1]). > I am not sure if, when the original data structure is very complex, there > could be any improvement in processing the flattened structure (but I guess > it's unlikely to have data in a form that is not a neat list, matrix or > tensor...) > Should that be true, this proc should have a ( theoretical : ) ) edge in > case ArgMax is called very many times feeding it complex data structures and > timeconsuming functions: > argMax[f_, arglist_List] := > With[ {newarg = Flatten[N[arglist]]}, > spectrum = Map[f, newarg]; > Extract[newarg, Position[spectrum, Max[spectrum]] ] > ] > But it's very likely it won't show any sensible -practical- improvement over > the original (corrected) multidimensional version. Moreover, Flatten is > useless when the list is onedimensional, so if the other tricks have any > effect whatsoever, it'd be better to use a dedicated proc for onedimensional > lists. > [1] I recall a discussion on Bahder's book (Mathematica for Scientist and > Engineers [2]) about different versions of a procedure called trapIntegrate. > [2] Wouldn't it be nice to have that book updated? > cheers, > Peltio > Invalid address in reply-to. Crafty demunging required to mail me. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: argMax >The dichotomy isn't really one-dimensional versus multi-dimensional, I think; it's values versus positions. Since the OP was looking for a fast procedure I thought it would have been better to use 'dedicated' functions for each special case in order to keep the overhead to a minimum. I got my second procedure totally wrong though. Yours is fine, instead, but... > positions[f_,arglist_List]:= > Module[ > {spectrum=Map[f,arglist,-1]}, > Position[spectrum,Max[spectrum]] > ] > values[f_,arglist_List]:=Extract[arglist,positions[f,arglist]] I think you had a 'lapsus digitae' after reading my mistake. : ) In fact Map[f,arglist,-1] should read Map[f,arglist,{-1}] (with onedimensional lists and Identity there are no differences since either there is no nesting or when there is nesting, nesting Identity won't change anything). I was thinking about a way to make the procedure a little faster, but I fear there is little room for improvement (at least without a real breakthrough - such as an undocumented function that does just that : )))). For a start: if the function f to be applied is rather complicated, it could be advisable to use N. Also, when the procedure ArgMax is called many times. using With instead of Module could reduce its overhead (or at least I think so [1]). I am not sure if, when the original data structure is very complex, there could be any improvement in processing the flattened structure (but I guess it's unlikely to have data in a form that is not a neat list, matrix or tensor...) Should that be true, this proc should have a ( theoretical : ) ) edge in case ArgMax is called very many times feeding it complex data structures and timeconsuming functions: argMax[f_, arglist_List] := With[ {newarg = Flatten[N[arglist]]}, spectrum = Map[f, newarg]; Extract[newarg, Position[spectrum, Max[spectrum]] ] ] But it's very likely it won't show any sensible -practical- improvement over the original (corrected) multidimensional version. Moreover, Flatten is useless when the list is onedimensional, so if the other tricks have any effect whatsoever, it'd be better to use a dedicated proc for onedimensional lists. [1] I recall a discussion on Bahder's book (Mathematica for Scientist and Engineers [2]) about different versions of a procedure called trapIntegrate. [2] Wouldn't it be nice to have that book updated? cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Convert Points to Circles Hi Everyone, I use Mathematica to create ListPlots, which I then save as eps files to touch up in Illustrator. I'm having a problem with the data points, which Illustrator sees as single point paths with no fill and a 2 point stroke. The single pont paths have round cap ends, so they look like circles. My problem comes in when I incorporate the plots into other programs and make PDFs. It seems like this round cap option does not get translated properly, and I end up with invisible single points. This even happens when I do save as PDF in Illustrator, although Apple's Preview seems to convert the EPS files to PDFs proplerly. I'm looking for some solution to this, like a way to convert the points to circles. I've found I can rasterize the points to make them portable, but then the files get huge and they aren't vector graphics. I can't outline the path, because it's only a single point. Any suggestions? -Tim === Subject: Re: normal distribution random number generation > FYI: I've just a little testing and I find that Mathematica ignors the user > defined rules for Random in Table[Random[],{n}] when n >= 250. This is indeed weird. It is easy to reproduce this behaviour: In[1]:= Unprotect[Random] Random[]:=0 Table[Random[], {249}] // Short[#, 1]& Table[Random[], {250}] // Short[#, 1]& Out[3]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, <<227>>, 0, 0, 0, 0, 0, 0, 0} Out[4]= {0.6238474115604462, 0.9251918536300756, <<247>>, 0.7177852283781632} In the last case the user definitions for Random are simply ignored. This seems to affect only Random, not other internal functions. However, I'd say that this example is not unique. Consider: In[1]:= (*restart the kernel*) Unprotect[Power]; ClearAttributes[Power, Listable]; (A_?MatrixQ) ^ p_ := MatrixPower[A, p] E ^ (A_?MatrixQ) := MatrixExp[A]; SetAttributes[Power, Locked]; LaplaceTransform[1, t, p]; Attributes[Power] Out[7]= {Listable, Locked, NumericFunction, OneIdentity, Protected} The definitions for A^p and E^A are given only to show why removing Listable may be useful. What this example demonstrates is that calling LaplaceTransform (only the first time, not the subsequent calls) restores the Listable attribute, and what's more, it ignores the attribute Locked! Since the evaluator checks the attributes before searching for user-defined rules, it means that the definitions for A^p and E^A break down. Overall, redefining the built-in functions seems to be extremely unreliable. Maxim Rytin m.r@inbox.ru === Subject: Re: Re: normal distribution random number generation It's clearly because of packed arrays: < He's right! How the devil does that happen? > Here's a test, with Andrzej's package loaded in my Init file. > First, with n=250: > Quit > SeedRandom[5] > Table[Random[],{250}]; > Last@% > 0.107874 > Unprotect[Random]; > Clear@Random > SeedRandom[5] > Table[Random[],{250}]; > Last@% > 0.107874 > Now, with n=249: > Quit > SeedRandom[5] > Table[Random[],{249}]; > Last@% > 0.656099 > Unprotect[Random]; > Clear@Random > SeedRandom[5] > Table[Random[],{249}]; > Last@% > 0.0708373 > Bobby >> FYI: I've just a little testing and I find that Mathematica ignors >> the user >> defined rules for Random in Table[Random[],{n}] when n >= 250. >The problem is not actually with the way Mathematica's >NormalDistribution but with the uniformly distributed Random[] >function. >NormalDistribution itself is generated (in the package >Statistics`NormalDistribution`) by means of the very classical so >called Boox-Muller method (although actually the Marsaglia variant >below works better). You can try downolading my little >RandomReplacement package form one of my web sites: >http://www.akikoz.net/~andrzej//Mathematica/ in Japan >or >http://www.mimuw.edu.pl/~akoz/Mathematica/ in Poland >The package is based on the post of daniel Lichtblau, which explains >the nature of the problem: > >The package is named init.m and can be loaded automatically at the >start of each Mathematica session. >However, in fact if you are only concerned with normal distributions >it >may be enough to the following. First load the (unmodified) >NormalDistribution package using ><and then evaluate the code below. It will replace the Box-Muller >generator by the Marsaglia one. I have found that this is usually >enough. But if your problem still remains try the RandomReplacement >package. (Or you can use both of course). Here is the Marsaglia code >for normal distribution: >Statistics`NormalDistribution`Private`normal= > Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, > Module[{va=1.,vb,rad=2.,den=1.}, > While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; > rad=va*va+vb*vb]; > den=Sqrt[-2.*(Log[rad]/rad)]; > mu+sigma*va*den]]; >>*This message was transferred with a trial version of >>CommuniGate(tm) >>Pro* >> >>Recently I have encountered a problem in Mathematica's normal >>distribution random number generator. The problem arises when I >>look >>at the distribution of averages of a list of theses numbers. That >>is, >>I generate 1000 numbers and take their average. I do this a number >>of >>times and the plot a frequency distribution. Consistently it seems >>to >>be skewed positive. Specifically, the number of occurrences less >>than >>3 standard deviations is consistent with the expected number, but >>the >>number greater than 3 is always larger (in some cases about twice >>the >>expected number). >> >>I was wondering if anyone else has noticed this and knows of a fix. >>Also, does anyone have code for a good quality normal distribution >>random number generator? >> >>Chris >-- > DrBob@bigfoot.com > www.eclecticdreams.net === Subject: Re: Re: normal distribution random number generation He's right! How the devil does that happen? Here's a test, with Andrzej's package loaded in my Init file. First, with n=250: Quit SeedRandom[5] Table[Random[],{250}]; Last@% 0.107874 Unprotect[Random]; Clear@Random SeedRandom[5] Table[Random[],{250}]; Last@% 0.107874 Now, with n=249: Quit SeedRandom[5] Table[Random[],{249}]; Last@% 0.656099 Unprotect[Random]; Clear@Random SeedRandom[5] Table[Random[],{249}]; Last@% 0.0708373 Bobby > FYI: I've just a little testing and I find that Mathematica ignors the user > defined rules for Random in Table[Random[],{n}] when n >= 250. >> The problem is not actually with the way Mathematica's >> NormalDistribution but with the uniformly distributed Random[] >> function. >> NormalDistribution itself is generated (in the package >> Statistics`NormalDistribution`) by means of the very classical so >> called Boox-Muller method (although actually the Marsaglia variant >> below works better). You can try downolading my little >> RandomReplacement package form one of my web sites: >> http://www.akikoz.net/~andrzej//Mathematica/ in Japan >> or >> http://www.mimuw.edu.pl/~akoz/Mathematica/ in Poland >> The package is based on the post of daniel Lichtblau, which explains >> the nature of the problem: >> >> The package is named init.m and can be loaded automatically at the >> start of each Mathematica session. >> However, in fact if you are only concerned with normal distributions it >> may be enough to the following. First load the (unmodified) >> NormalDistribution package using >> <> and then evaluate the code below. It will replace the Box-Muller >> generator by the Marsaglia one. I have found that this is usually >> enough. But if your problem still remains try the RandomReplacement >> package. (Or you can use both of course). Here is the Marsaglia code >> for normal distribution: >> Statistics`NormalDistribution`Private`normal= >> Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >*This message was transferred with a trial version of CommuniGate(tm) >Pro* >Recently I have encountered a problem in Mathematica's normal >distribution random number generator. The problem arises when I look >at the distribution of averages of a list of theses numbers. That is, >I generate 1000 numbers and take their average. I do this a number of >times and the plot a frequency distribution. Consistently it seems to >be skewed positive. Specifically, the number of occurrences less than >3 standard deviations is consistent with the expected number, but the >number greater than 3 is always larger (in some cases about twice the >expected number). >I was wondering if anyone else has noticed this and knows of a fix. >Also, does anyone have code for a good quality normal distribution >random number generator? >Chris -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Scale Values on Plot[] I would like to plot the simple function of Sin[x] but have the x axis labels be -Pi, -Pi/2, 0, Pi/2, Pi instead of integer values 1, 2, 3, etc. Is this possible? Jeremy Foster === Subject: Re: Scale Values on Plot[] > I would like to plot the simple function of Sin[x] but have the x > axis labels be -Pi, -Pi/2, 0, Pi/2, Pi instead of integer values 1, > 2, 3, etc. Is this possible? Hello Jeremy, there was a post on this newsgroup only a couple of weeks ago (message id ) > Needs[Graphics`Graphics`] > Plot[Sin[x], {x, 0, 2*Pi}, > Ticks -> {PiScale, Automatic}]; Marcus -- Chaos in the midst of chaos isn't funny, but chaos in the midst of order is. -- Steve Martin === Subject: Re: Scale Values on Plot[] Plot[Sin[x], {x, 0, 4Pi}, FrameTicks -> {Table[i Pi/2, {i, 0, 8}], Automatic}, Frame -> True] Jens Jeremy Foster schrieb im Newsbeitrag >I would like to plot the simple function of Sin[x] but have the x axis > labels be -Pi, -Pi/2, 0, Pi/2, Pi instead of integer values 1, 2, 3, etc. > Is > this possible? > Jeremy Foster === Subject: Re: GUI for mathematica app Depending on you intended audience, you may also wish to consider Excel Link, which allows your Mathematica functions to be called from Excel, taking advantage of any user familiarity with the Excel interface and of course the built-in button, menu, and VBA constructs. I had to create an interface for nursing staff, who are relatively non-technical and only intermittent users of the application, and it was an effective approach. A. Sharma > There is GUIKit and it is best to use the examples as your help documents > to start with. Also there is JLink which will allow you to use everything > that Java has to offer. Search for JLink documents and tutorials in the > Wolfram website. > Below is a link where you can find some examples other than those > contained in the help files. > http://www.wolfram.com/solutions/mathlink/jlink/examples.html > Yas > I'm a research student in Physics, > I've recently finished writing an application in Mathematica. > I would like to make a nice user interface for it - > a screen in which the user will insert the variables and function he > wishes to run, and get the results, insead of going into the notebook > - > I would like to know what the best option to do that, since I checked > and it looks to me that there is no built in way to do that. > Ran F. === Subject: subscripts and conflicts with built in Mathematica symbols or letters Since I havent seen anyone else give this answer about using Subscripts I thought I'd send it in. I have resolved this problem not by using the Notations Utility but by using the Palette, forget the name of it, that has Greek, Script, DoubleStruck, etc. characters on it...This is an alternative method that I find much easier to use. jerry blimbaum === Subject: Showing Complete Solution. Hi all... I need to watch the entire solution of integrates and other functions like limits. Just the answer is not all. I need the path too. I am using Mathematica 5. Someone could help??? === Subject: Re: Showing Complete Solution. > Hi all... > I need to watch the entire solution of integrates and other functions like > limits. > Just the answer is not all. I need the path too. > I am using Mathematica 5. > Someone could help??? The site http://calc101.com/ uses WebMathematica. You can see all the steps for derivatives. To see all the steps for other functions you need to get a password. Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: Showing Complete Solution. a) if you would see the solution path it would not help you because Mathematica does it in the most cases more compilcated than a human would do and it does it more general b) some functions like Integrate[] are Kernel function written in C/C++ and you will never see what the compiled program does. Jens > Hi all... > I need to watch the entire solution of integrates and other functions like > limits. > Just the answer is not all. I need the path too. > I am using Mathematica 5. > Someone could help??? === Subject: histograms of identical distribution is different. maybe binnumber is the problem? i found the code attached below in the archives. it will display two histograms without shading in one graph. note both histograms are generated exactly the same way using exactly the same number of sample points. for me, at least, it will show a pattern of a few of the distributions having a lower number of points about the mean. what causes this? I think it has to do with the way histograms are made? is there a way to control bin width or number in a convenient way? like.. binwidth-> (numberof points)/(whatever bin number you want to use) Do[ normdata = RandomArray[NormalDistribution[], 10000]; h1 = Histogram[normdata, BarEdgeStyle -> Hue[0], BarStyle -> {}, DisplayFunction -> Identity]; normdata2 = RandomArray[NormalDistribution[], 10000]; h2 = Histogram[normdata2, BarStyle -> {}, DisplayFunction -> Identity]; DisplayTogether[h1, h2], {i, 10}] __________________________________ Do you Yahoo!? Y! Messenger - Communicate in real time. Download now. http://messenger.yahoo.com === Subject: Solving an equation I have an equation, Gamma[a+I b] = some complex number. I need to solve this equation for a and b. I can write a+I b as z, but it can't be solved through NSolve. What I have been doing is a double do loop for a and b and getting some number. Then I compare this to the number I have. Then I narrow down my possibilities for a and b, and go through the process again. Does anyone know of a better way to do this problem? Is there a way to have Mathematica compare each result of the do loop to a given value, and given certain conditions spit out an answer for a and b? Hope that makes sense. === Subject: Re: Solving an equation > I have an equation, Gamma[a+I b] = some complex number. I need to > solve this equation for a and b. Typically, there will be infinitely many solutions. See below. > I can write a+I b as z, but it can't > be solved through NSolve. What I have been doing is a double do loop > for a and b and getting some number. Then I compare this to the > number I have. Then I narrow down my possibilities for a and b, and > go through the process again. Does anyone know of a better way to do > this problem? Is there a way to have Mathematica compare each result > of the do loop to a given value, and given certain conditions spit out > an answer for a and b? Certainly look at the response already given by Daniel Lichtblau, but let me mention a very different approach which might be of use. Some time ago, I developed an approximation for the inverse (principal branch) of the real gamma function; see Inverse Gamma Function at . [At the time I similar.] Bizarrely, until I saw your question, I had never considered using my approximation in the complex domain, but it works nicely! The main adaptation I've made to my previous approximation is to allow different braches of the logarithm to be used, since we're now working with complex numbers and multiple solutions. AIG stands for ApproximateInverseGamma. L[z_, n_] := Log[z/Sqrt[2*Pi]] + 2*n*Pi*I; AIG[z_, n_] := L[z, n]/ProductLog[L[z, n]/E] + 1/2 For our first examples, let's use the same value, 3 + 5*I, used by Daniel earlier in this thread. In[5]:= N[AIG[3 + 5*I, 0]] Out[5]= 4.040766662437202 + 0.809458889448528*I In[6]:= Gamma[%] Out[6]= 2.9542538687291082 + 4.952066867619615*I To get this solution far more precisely In[7]:= FindRoot[Gamma[z] == 3 + 5*I, {z, 4}] Out[7]= {z -> 4.048806909342241 + 0.8061219366736553*I} but, _considering its simplicity_, AIG works reasonably well here. Note that 4.04... + 0.809...*I is not an approximation of one of the two solutions mentioned by Daniel. To get an approximation of one of those, we use a different branch: In[8]:= N[AIG[3 + 5*I, 1]] Out[8]= 5.244221150676627 + 4.373221814339161*I The other solution which Daniel gave apparently cannot be approximated by AIG. Nonetheless, AIG provides a very easy way to approximate as many solutions as desired by using different branches. For example, In[9]:= Table[N[AIG[3 + 5*I, n]], {n, -5, 5}] Out[9]= {8.569173560584497 - 12.901034605395182*I, 7.78702834003813 - 10.821866222844191*I, 6.934032296216477 - 8.612108708227566*I, 5.976814285932365 - 6.197862806430168*I, 4.850615201546351 - 3.3750113310836416*I, 4.040766662437202 + 0.809458889448528*I, 5.244221150676627 + 4.373221814339161*I, 6.305341094465263 + 7.019856094350459*I, 7.223222083387802 + 9.354604278933351*I, 8.05025152253416 + 11.515933830777435*I, 8.813678677993034 + 13.561294899894799*I} In[10]:= Gamma[%] Out[10]= {3.0072272893524876 + 4.9857740150544645*I, 3.0078603511604793 + 4.983133706384024*I, 3.008514748161956 + 4.979089858939104*I, 3.0087772161344706 + 4.972015650130263*I, 3.005054077852697 + 4.956321056315101*I, 2.9542538687291082 + 4.952066867619615*I, 2.964000082914953 + 4.989287532490715*I, 2.9736755655173486 + 4.995940237826113*I, 2.9790047897469507 + 4.998218781373197*I, 2.982384214170453 + 4.999269332306986*I, 2.9847360144047173 + 4.999834250625654*I} Warning: This response was written without much thought. There may be significant drawbacks to using AIG besides those indicated above. Two other examples are given below my signature. David Cantrell -------------------- In[11]:= Table[N[AIG[-1000 + 500*I, n]], {n, -5, 5}] Out[11]= {10.103501062631734 - 11.759987470562999*I, 9.408940901896164 - 9.611831291928395*I, 8.688014667678077 - 7.3105338016372166*I, 7.96307707563004 - 4.774416610794671*I, 7.359670522007456 - 1.86061579553127*I, 7.303476737078219 + 1.3916310116941213*I, 8.580151565437184 + 6.953715688390507*I, 9.30403553110932 + 9.283247761845434*I, 10.002805023824852 + 11.450602602247157*I, 10.673157495331035 + 13.504122688835286*I} In[12]:= Gamma[%] Out[12]= {-997.2020455370163 + 501.2529882211875*I, -996.6745283937655 + 501.2448117163233*I, -995.9084815611002 + 501.10356272765165*I, -994.7820367943481 + 500.5422207949927*I, -993.6010090005602 + 498.70204334626004*I, -994.7397151088763 + 495.88073677360353*I, -997.0568231220326 + 495.4391448543616*I, -998.3076913751443 + 495.97846657249335*I, -998.9362942218514 + 496.52193170456474*I, -999.2856828595261 + 496.9546427379604*I, -999.4984812216452 + 497.2926327205642*I} In[13]:= Table[N[AIG[1/10 - I/100, n]], {n, -5, 5}] Out[13]= {7.415124675510394 - 13.763230671478823*I, 6.581440974084747 - 11.745953506345964*I, 5.656159764730283 - 9.62586568815651*I, 4.584178930684972 - 7.360386847096441*I, 3.2175773919763313 - 4.868560486894651*I, 0.8612595008894053 - 2.2335248837759987*I, 3.165306832522787 + 4.784429834864226*I, 4.546634252963682 + 7.2853914707074425*I, 5.624821510167048 + 9.556522209402686*I, 6.5536846870598895 + 11.680437088713305*I, 7.389767664831733 + 13.700531235115555*I} In[14]:= Gamma[%] Out[14]= {0.09985412458625637 - 0.010229263731083432*I, 0.09982683837834178 - 0.010264829400209013*I, 0.0997856659169176 - 0.010317687391232877*I, 0.09971559657048247 - 0.010407682128041808*I, 0.09956788845157781 - 0.010613474995339423*I, 0.09949551308490184 - 0.011799689100020628*I, 0.09969297553821639 - 0.00930046867734496*I, 0.09979975412801753 - 0.009539584065042078*I, 0.09985161429417513 - 0.009643757588497417*I, 0.09988195063236968 - 0.009704591748427947*I, 0.0999018902264989 - 0.00974531144339588*I} === Subject: Re: Solving an equation > I have an equation, Gamma[a+I b] = some complex number. I need to > solve this equation for a and b. > Typically, there will be infinitely many solutions. See below. > I can write a+I b as z, but it can't > be solved through NSolve. What I have been doing is a double do loop > for a and b and getting some number. Then I compare this to the > number I have. Then I narrow down my possibilities for a and b, and > go through the process again. Does anyone know of a better way to do > this problem? Is there a way to have Mathematica compare each result > of the do loop to a given value, and given certain conditions spit out > an answer for a and b? > Certainly look at the response already given by Daniel Lichtblau, but let > me mention a very different approach which might be of use. Some time > ago, I developed an approximation for the inverse (principal branch) of > the real gamma function; see Inverse Gamma Function at > . [At the time I > similar.] Bizarrely, until I saw your question, I had never considered > using my approximation in the complex domain, but it works nicely! > The main adaptation I've made to my previous approximation is to allow > different braches of the logarithm to be used, since we're now working > with complex numbers and multiple solutions. AIG stands for > ApproximateInverseGamma. > L[z_, n_] := Log[z/Sqrt[2*Pi]] + 2*n*Pi*I; > AIG[z_, n_] := L[z, n]/ProductLog[L[z, n]/E] + 1/2 > For our first examples, let's use the same value, 3 + 5*I, used by Daniel > earlier in this thread. > In[5]:= N[AIG[3 + 5*I, 0]] > Out[5]= 4.040766662437202 + 0.809458889448528*I > In[6]:= Gamma[%] > Out[6]= 2.9542538687291082 + 4.952066867619615*I > To get this solution far more precisely > In[7]:= FindRoot[Gamma[z] == 3 + 5*I, {z, 4}] > Out[7]= {z -> 4.048806909342241 + 0.8061219366736553*I} > but, _considering its simplicity_, AIG works reasonably well here. > Note that 4.04... + 0.809...*I is not an approximation of one of the two > solutions mentioned by Daniel. To get an approximation of one of those, > we use a different branch: > In[8]:= N[AIG[3 + 5*I, 1]] > Out[8]= 5.244221150676627 + 4.373221814339161*I > The other solution which Daniel gave apparently cannot be approximated by > AIG. Nonetheless, AIG provides a very easy way to approximate as many > solutions as desired by using different branches. For a more complete answer, I'll now mention how still other solutions (such as the other one given by Daniel) can be very easily approximated. This will give another infinite family of approximate solutions. Nice _algebraic_ asymptotic approximations can be obtained fairly easily for all nonprincipal branches. (For all nonpositive n, the gamma function has a simple pole at n.) For example, for the -1 branch, the function 1/(g+x), where g is the Euler gamma constant (approximately 0.577216), works well when |x| is large. ... For all other branches, the simplest nice asymptotic approximations are rational functions having both numerator and denominator of degree 1. As examples: For the -2 branch, we have the approximation (2-g+x)/(g-1-x), and for the -3 branch, 4(g-2+2x)/(3-2g-4x). So now let's see how to get an approximation for that other solution previously mentioned by Daniel. Of course, we could use something like In[20]:= FindRoot[Gamma[z] == 3 + 5*I, {z, 0.1}] Out[20]= {z -> 0.09103227139407653 - 0.13362798410019328*I} But an alternative, if we can settle for a simple approximation, is to use AIGNP[z_, n_] := -n + 1/(EulerGamma + (-1)^n*(n!*z + StirlingS1[n+1,2]/n!)) where AIGNP stands for ApproximateInverseGammaNearPole at -n for nonnegative integer n. We then get In[25]:= N[AIGNP[3 + 5*I, 0]] Out[25]= 0.09464416872334132 - 0.13228747941025595*I [By the way, substantially better, but messier, approximations than AIGNP are readily available near the poles. For example, instead of using AIGNP above, we could have used In[26]:= N[2/(EulerGamma + z + Sqrt[-EulerGamma^2 - Pi^2/3 + 2*EulerGamma*z + z^2])]/. z -> 3 + 5*I Out[26]= 0.0905892579464156 - 0.1332971242252317*I In[27]:= Gamma[%] Out[27]= 3.0051527268465104 + 5.020664268483219*I However, for simplicity, we'll stay with just AIGNP for the rest of this post.] Note that AIGNP agrees with the three simple approximations mentioned in the quotation above: In[28]:= Table[Together[AIGNP[z, n]], {n, 0, 2}] Out[28]= {1/(EulerGamma + z), (2 - EulerGamma + z)/(-1 + EulerGamma - z), -((4*(-2 + EulerGamma + 2*z))/(-3 + 2*EulerGamma + 4*z))} AIGNP allows us to get as many approximate solutions as desired. For example, In[29]:= Table[N[AIGNP[3 + 5*I, n]], {n, 0, 7}] Out[29]= {0.09464416872334132 - 0.13228747941025595*I, -1.0932246259350227 + 0.136182442140838*I, -1.9596335538408043 - 0.07950508472241272*I, -3.015152775376722 + 0.02360721247808417*I, -3.9963605517971357 - 0.006195343055295479*I, -5.000736925510258 + 0.0012224158911233105*I, -5.999877501029459 - 0.00020434212160696532*I, -7.000017508100925 + 0.000029176278728846562*I} In[30]:= Gamma[%] Out[30]= {3.0978502145116456 + 4.8903488180579275*I, 3.130381565322433 + 4.81893763567967*I, 3.0336452404650402 + 4.921088107165388*I, 3.005898092059356 + 4.99124348680135*I, 3.0004015914098887 + 4.999305766120647*I, 3.000018510086481 + 4.999969393030145*I, 3.0000005650151262 + 4.999999056961428*I, 3.00000001254731 + 4.999999979090844*I} Apparently, as n increases, so does the accuracy of the approximation. So AIG and AIGNP give approximations of solutions in infinite disjoint families. But do we now have a complete set of approximations, or are there other solutions lying outside of those families? I suspect the former. David Cantrell === Subject: Re: Solving an equation Try using FindRoot[] It should work if you have a starting value near the root. It gives a zeta zero root by this method: FindRoot[Zeta[z]==0,{z,{1/2+14*I,1/2+I*200*I}}] >I have an equation, Gamma[a+I b] = some complex number. I need to >solve this equation for a and b. I can write a+I b as z, but it can't >be solved through NSolve. What I have been doing is a double do loop >for a and b and getting some number. Then I compare this to the >number I have. Then I narrow down my possibilities for a and b, and >go through the process again. Does anyone know of a better way to do >this problem? Is there a way to have Mathematica compare each result >of the do loop to a given value, and given certain conditions spit out >an answer for a and b? >Hope that makes sense. -- Respectfully, Roger L. Bagula tftn@earthlink.net, 11759Waterhill Road, Lakeside,Ca 92040-2905,tel: 619-5610814 : alternative email: rlbtftn@netscape.net URL : http://home.earthlink.net/~tftn === Subject: Re: Solving an equation > I have an equation, Gamma[a+I b] = some complex number. I need to > solve this equation for a and b. I can write a+I b as z, but it can't > be solved through NSolve. What I have been doing is a double do loop > for a and b and getting some number. Then I compare this to the > number I have. Then I narrow down my possibilities for a and b, and > go through the process again. Does anyone know of a better way to do > this problem? Is there a way to have Mathematica compare each result > of the do loop to a given value, and given certain conditions spit out > an answer for a and b? > Hope that makes sense. I'm not sure what might be the best way to do this, but one workable approach is to treat it as an optimization. Say your complex number is 3+5*I. Belwo we find roots near 1-2*I and 5+4*I respectively. In[9]:= FindMinimum[Abs[Gamma[a+I*b]-(3+5*I)], {a,1}, {b,-2}] FindMinimum::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. -8 Out[9]= {2.39838 10 , {a -> 0.0910323, b -> -0.133628}} In[10]:= FindMinimum[Abs[Gamma[a+I*b]-(3+5*I)], {a,5}, {b,4}] FindMinimum::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. -7 Out[10]= {1.10535 10 , {a -> 5.24561, b -> 4.37032}} If you like you can use a root finder instead, or in conjunction with this. I tend to prefer the second approach, using it as a polishing step, because it does not always perform well without a good initial point. Also, as the functions are not analytic, we should either provide a gradient or use a secant method by specifying two initial values per argument. eqns = Thread[{Re[Gamma[a+I*b]],Im[Gamma[a+I*b]]}=={3,5}]; In[16]:= FindRoot[eqns, {a,5.24,5.25}, {b,4.3,4.4}, WorkingPrecision->20, AccuracyGoal->20, PrecisionGoal->20] Out[16]= {a -> 5.2456145798271348496, b -> 4.3703225075594339402} We could instead have requested higher precision/accuracy in FindMinimum but that is slower and also, to judge from residuals, not quite as accurate. Daniel Lichtblau Wolfram Research === Subject: Re: Solving an equation > Does anyone know of a better way to do > this problem? You could try using FindRoot eg. FindRoot[{Re[Gamma[a + I b]] == 3, Im[Gamma[a + I b]] == 4}, {{a, 0.1}, {b, 0.1}}] > Is there a way to have Mathematica compare each result > of the do loop to a given value, and given certain conditions spit out > an answer for a and b? You could use an If expression and a Print eg. Do[expression;expression;...;If[test,Print[Some Message]];...,{iterations}] > Hope that makes sense. I hope my answer's are helpful. Ssezi === Subject: Re: Solving an equation and FindRoot[Evaluate[ Thread[{Re[#], Im[#]} & /@ (Gamma[x + I*y] == 2 + I*4)]], {x, 3}, {y, 3}] does ot help ?? Jens Scott schrieb im Newsbeitrag >I have an equation, Gamma[a+I b] = some complex number. I need to > solve this equation for a and b. I can write a+I b as z, but it can't > be solved through NSolve. What I have been doing is a double do loop > for a and b and getting some number. Then I compare this to the > number I have. Then I narrow down my possibilities for a and b, and > go through the process again. Does anyone know of a better way to do > this problem? Is there a way to have Mathematica compare each result > of the do loop to a given value, and given certain conditions spit out > an answer for a and b? > Hope that makes sense. === Subject: Re: Change head, with Apply? Brian Christensen ha scritto: > I have made a function that contains Series[...], I need to add some > ekstra to this and therefor i use Normal[Series[...]]+R. If i use > Head[%], it shows Plus And i would like to change this to > TaylorSeriesData, How do i do this? I have tried a lot, but i cant get > anywhere. If i do not use Normal, Head will return SeriesData, but i > need to add the R > How do i change the function to TaylorSeriesData? > -Brian Try using Apply in this way: In[1]: Normal[Series[f[x],{x,x0,n}]]+R Out[1]:.... In[2]: SeriesData @@ {x,x0,{%1},nmin,nmax,den} Out[2]: (hope It is what you meant) The effect is the same as having not normalized the Taylor series: Series[...]+R The output has SeriesData head and therefore contains residuals. Hope It helps. Matteo Delfino === Subject: Change head, with Apply? I have made a function that contains Series[...], I need to add some ekstra to this and therefor i use Normal[Series[...]]+R. If i use Head[%], it shows Plus And i would like to change this to TaylorSeriesData, How do i do this? I have tried a lot, but i cant get anywhere. If i do not use Normal, Head will return SeriesData, but i need to add the R How do i change the function to TaylorSeriesData? -Brian === Subject: Re: Series [was Change head, with Apply?] > I have made a function that contains Series[...], I need to add some > ekstra to this and therefor i use Normal[Series[...]]+R. If i use > Head[%], it shows Plus And i would like to change this to > TaylorSeriesData, How do i do this? I have tried a lot, but i cant get > anywhere. If i do not use Normal, Head will return SeriesData, but i > need to add the R > How do i change the function to TaylorSeriesData? For definiteness, suppose your series is series = f[x] + O[x]^3 Note that adding the term O[x]^3 automatic coerces series expansion. Now, I must be missing the point of your question. Is R meant to be remainder (of higher order than the given series) or just an arbitrary term? If it is the latter then you can just add it to the series series + R However, if your R is, say, a x^4, then you would need to do this: Normal[series] + a x^4 + O[x]^5 Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: Change head, with Apply? I don't know, if there's a TaylorSeriesData head in version 5, but a look at the help for SeriesData leads to the way: In[1]:= sd = Series[Exp[x], {x, 0, 2}]; sd // FullForm Out[2]//FullForm= SeriesData[x, 0, List[1, 1, Rational[1, 2]], 0, 3, 1] In[3]:= sd[[3, 1]] += R; Head[sd] Out[4]= SeriesData -- Peter Pein, Berlin to write to me, start the subject with [ Brian Christensen schrieb im Newsbeitrag > I have made a function that contains Series[...], I need to add some > ekstra to this and therefor i use Normal[Series[...]]+R. If i use > Head[%], it shows Plus And i would like to change this to > TaylorSeriesData, How do i do this? I have tried a lot, but i cant get > anywhere. If i do not use Normal, Head will return SeriesData, but i > need to add the R > How do i change the function to TaylorSeriesData? > -Brian === Subject: Re: Outer product in mathematica >Jonas, >The function you are looking for is Cross, not Outer. >Outer in Mathematica is more like the tensor outer product, not the >antisymmetric tensor product. >Outer product (or tensor product) and cross product are not the same >thing.Outer product is defined between two tensors and produces a tesor > of higher rank,cross product takes two vector (read:tensor of the same >rank) and produces another vector (read:tensor of the same rank as >before).In mathematica cross product is defined as Cross[] and Outer >product as Outer[]. only the tensor outer product, meanwhile in German .8ausseres Produkt has more the sense of the antisymmetric tensor product (wedge-product)? Our professor talked only about the second one... When I tried several things with the functions Outer to get the antisymmetric tensor product, I figured out it's possible even without Cross: Let u, v be vectors of R^n, A = Outer[Times, u, v] so A is a nxn-matrix, then set A = A - Transpose[A] for A becomes a skewsymmetric nxn-matrix. Then take the upper-right components of A (without the diagonal). They are exactly the components of the antisymmetric tensor product of u and v. So right? I didn't manage to use Cross for vectors of other dimension than three, but anyway, Outer does it as well. === Subject: Re: Re: Outer product in mathematica Yesterday evening I was looking ways to find out quickly if a list of string patterns match a list of strings or not. Outer came handy. Here is a small example: In[20]:= lst={actagagactagag,actagag,acta,gag}; fragpatt={*acta*,*tag*,*gag*}; Outer[StringMatchQ[#1,#2]&,lst,fragpatt] Out[22]= {{True,True,True},{True,True,True},{True,False,False},{False,False,True} } The first sublist of the Out shows how the first element of lst measured up to the elements of fragpatt, etc... J.87nos >> only the tensor outer product, meanwhile in German .8ausseres Produkt >> has more the sense of the antisymmetric tensor product >> (wedge-product)? Our professor talked only about the second one... > I have often heard the term direktes Produkt for what Outer does. > Albert. ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: Outer product in mathematica > only the tensor outer product, meanwhile in German .8ausseres Produkt > has more the sense of the antisymmetric tensor product > (wedge-product)? Our professor talked only about the second one... I have often heard the term direktes Produkt for what Outer does. Albert. === Subject: Re: Outer product in mathematica Jonas Sourlier ha scritto: > Hi there > In the lections at my University I have learnt that the outer product > of two Vectors is defined as follows: > (a) x (b) = 0 > (a, b) x (c, d) = ad - bc > (a, b, c) x (d, e, f) = (bf - ce, cd - af, ae - bd) > For two four-dimensional Vectors the outer product produces a > six-dimensional Vector (handled as a skew-symmetric 4x4-matrix). > The general, axiomatic definition of the outer product says that it is > graduately anti-commutative: u x v = (-1)^(k+l) (v x u) > bilinear: (u + v) x w = u x w + v x w > for two vectors u, v and w with dimensions k, l, m. > Now, my question: The outer product seems to be implemented in > Mathematica with the function Outer. But whatever I've tried so far > with Outer I didn't manage to get the outer product of two vectors as > described above. > Outer[Times, {a,b,c},{d,e,f}] produces the 3x3-Matrix > {{a d, a e, a f}, {b d, b e, b f}, {c d, c e, c f}} > How can I calculate the outer product of two vectors with Mathematica? > Jonas Outer product (or tensor product) and cross product are not the same thing.Outer product is defined between two tensors and produces a tesor of higher rank,cross product takes two vector (read:tensor of the same rank) and produces another vector (read:tensor of the same rank as before).In mathematica cross product is defined as Cross[] and Outer product as Outer[]. YOU MUST USE CROSS[]. DEFINITION OF CROSS PRODUCT BY OUTER PRODUCT It is still possible to extend the definition of Cross[] product to http://www.math.wisc.edu/~milewski/321f04/fwnotestensors.pdf Hope It helps. Delfino Matteo === Subject: Re: Outer product in mathematica Jonas, The function you are looking for is Cross, not Outer. Outer in Mathematica is more like the tensor outer product, not the antisymmetric tensor product. > Hi there > In the lections at my University I have learnt that the outer product > of two Vectors is defined as follows: > (a) x (b) = 0 > (a, b) x (c, d) = ad - bc > (a, b, c) x (d, e, f) = (bf - ce, cd - af, ae - bd) > For two four-dimensional Vectors the outer product produces a > six-dimensional Vector (handled as a skew-symmetric 4x4-matrix). > The general, axiomatic definition of the outer product says that it is > graduately anti-commutative: u x v = (-1)^(k+l) (v x u) > bilinear: (u + v) x w = u x w + v x w > for two vectors u, v and w with dimensions k, l, m. > Now, my question: The outer product seems to be implemented in > Mathematica with the function Outer. But whatever I've tried so far > with Outer I didn't manage to get the outer product of two vectors as > described above. > Outer[Times, {a,b,c},{d,e,f}] produces the 3x3-Matrix > {{a d, a e, a f}, {b d, b e, b f}, {c d, c e, c f}} > How can I calculate the outer product of two vectors with Mathematica? > Jonas ____________________________ John Browne === Subject: GUI Support for Zoom I have a very basic question: Does Mathematica offer the possibility to zoom into a plot (e.g. a simple 2-D plot like the result of Plot[Sin[x],{x,0,2*Pi}]) by using the mouse? I am talking about a feature that many other tools offer. I know that one can use the PlotRange option to zoom into a plot region, but it can be quite awkward for every zoom to use this option. Rainer === Subject: Re: NMinimize inconsistencies Skirmantas, as a general rule, you have to specify closed sets for defining the feasible region in any continuous optimization problem (think of minimizing x on 0I'm puzzled by some inconsistencies of NMinimize. >Namely, >NMinimize[{ Log[( C + P*m - b*P*m)/( C + P*m - a*P*m)]/(a - b), 105 < >C < 315&&2000 < P < 4000&&0 < a < 1 &&0 < b < 1 &&a < b &&0 < m < 5}, >{{C, 105, 315}, {P, 2000,4000}, {a, 0, 1}, {b, 0, 1}, {m, 0, 5}}, >Method -> NelderMead] >converges to 0 on a computer running Mathematica 5.0.0. and complains >about 1/0 infinities on a computer running Mathematica 5.0.1. In >Mathematica 5.0.1., changing ab still leads to 1/0 infinities >(why?) but then changing a>b to a!=b converges to a solution that is, >amazingly, a>b. Why does NMinimize keep running into 1/0 infinities if >I demand that a>b but not if a!=b? Are there any differences in the >NMinimize implementation in Mathematica 5.0.0. and Mathematica 5.0.1.? >Any help would be appreciated. >Skirmantas === Subject: NMinimize inconsistencies I'm puzzled by some inconsistencies of NMinimize. Namely, NMinimize[{ Log[( C + P*m - b*P*m)/( C + P*m - a*P*m)]/(a - b), 105 < C < 315&&2000 < P < 4000&&0 < a < 1 &&0 < b < 1 &&a < b &&0 < m < 5}, {{C, 105, 315}, {P, 2000,4000}, {a, 0, 1}, {b, 0, 1}, {m, 0, 5}}, Method -> NelderMead] converges to 0 on a computer running Mathematica 5.0.0. and complains about 1/0 infinities on a computer running Mathematica 5.0.1. In Mathematica 5.0.1., changing ab still leads to 1/0 infinities (why?) but then changing a>b to a!=b converges to a solution that is, amazingly, a>b. Why does NMinimize keep running into 1/0 infinities if I demand that a>b but not if a!=b? Are there any differences in the NMinimize implementation in Mathematica 5.0.0. and Mathematica 5.0.1.? Any help would be appreciated. Skirmantas === Subject: Re: Re: normal distribution random number generation I think I have now fixed the problem reported by Mark Fisher. The new version of the RandomReplacement now works like this: SeedRandom[5] Timing[First[Table[Random[],{10000}]]] {0.01 Second,0.786599} < It's clearly because of packed arrays: > < PackedArrayQ[Table[Random[],{249}]] > False > PackedArrayQ[Table[Random[],{250}]] > True > Obviously Mathematica uses a different method of generating random > packed arrays. There are various ways of getting round this (e.g. > constructing lists as joins of lists of length less than 250 etc) but > one will loose the benefits of packed arrays and with that, presumably, > a lot of speed. This seems to be something that only WRI can change. > Note however that not all situations in which one uses Random[] require > generating this type of lists. > Moreover, for problems involving the normal distribution it seems to me > that using the Marsaglia generator gives good results even with the > built in Random[]. But certainly we should hope that something will > finally be done do deal with this issue in version 6. > Andrzej >> He's right! How the devil does that happen? >> Here's a test, with Andrzej's package loaded in my Init file. >> First, with n=250: >> Quit >> SeedRandom[5] >> Table[Random[],{250}]; >> Last@% >> 0.107874 >> Unprotect[Random]; >> Clear@Random >> SeedRandom[5] >> Table[Random[],{250}]; >> Last@% >> 0.107874 >> Now, with n=249: >> Quit >> SeedRandom[5] >> Table[Random[],{249}]; >> Last@% >> 0.656099 >> Unprotect[Random]; >> Clear@Random >> SeedRandom[5] >> Table[Random[],{249}]; >> Last@% >> 0.0708373 >> Bobby >FYI: I've just a little testing and I find that Mathematica ignors >the user >defined rules for Random in Table[Random[],{n}] when n >= 250. >>The problem is not actually with the way Mathematica's >>NormalDistribution but with the uniformly distributed Random[] >>function. >>NormalDistribution itself is generated (in the package >>Statistics`NormalDistribution`) by means of the very classical so >>called Boox-Muller method (although actually the Marsaglia variant >>below works better). You can try downolading my little >>RandomReplacement package form one of my web sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ in Poland >> >>The package is based on the post of daniel Lichtblau, which explains >>the nature of the problem: >> >>>msg00088.html> >> >> >> >>The package is named init.m and can be loaded automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned with normal distributions >>it >>may be enough to the following. First load the (unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will replace the Box-Muller >>generator by the Marsaglia one. I have found that this is usually >>enough. But if your problem still remains try the RandomReplacement >>package. (Or you can use both of course). Here is the Marsaglia code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >> Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in Mathematica's normal >distribution random number generator. The problem arises when I >look >at the distribution of averages of a list of theses numbers. That >is, >I generate 1000 numbers and take their average. I do this a number >of >times and the plot a frequency distribution. Consistently it seems >to >be skewed positive. Specifically, the number of occurrences less >than >3 standard deviations is consistent with the expected number, but >the >number greater than 3 is always larger (in some cases about twice >the >expected number). > >I was wondering if anyone else has noticed this and knows of a fix. >Also, does anyone have code for a good quality normal distribution >random number generator? > >Chris > >> >> >> -- >> DrBob@bigfoot.com >> www.eclecticdreams.net === Subject: Re: Eigenvalues and eigenvectors of a matrix with nonpolynomial elements. Why not let Mathematica do the work? mat = {{-1, 0, -1, 0}, {-Cos[k], -Sin[k], - Cosh[k], -Sinh[k]}, {1, 0, -1, 0}, {Sin[k], -Cos[k], -Sinh[ k], -Cosh[k]}}; mat // MatrixForm Eigensystem@mat (voluminous output omitted) Your use of FindRoot below didn't find the eigenvalues of a single matrix; it found the values of k that make the matrix singular. At each value of k (whether it's one of those roots or not), the matrix has a different Eigensystem. Bobby > I need to find the eigenvalues and eigenvectors of matrices where the elements depend on a variable, k, in a nonpolynomial manner. Thus, according to my (limited) knowledge of eigensystems, the eigenvalues are the values of k that make the determinant zero and there should be an eigenvector associated with each eigenvalue. A simple warm-up example is given below; my actual cases will be more complicated. I wish to know if the method I have put together below, using engineering rather than maths, is suitable and what accuracy I can expect. > First, here is the warm-up problem; the matrix is called mat and depends on the variable k. I start by working out the determinant. > In[39]:= > mat = {{-1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, {1, 0, -1, 0}, > {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}}; > In[40]:= > d = Det[mat] > Out[40]= > 2*Cosh[k]*Sin[k] - 2*Cos[k]*Sinh[k] > Second, I find one of the roots. There are an infinite number of roots and Ted Ersek's method for finding all the roots in an interval might help. I assume that each root is an eigenvalue: is this always true? > In[41]:= > rt = FindRoot[d, {k, 6, 8}] > Out[41]= > {k -> 7.068582745628732} > Third, I attempt to get the eigenvector. It has been necessary to go numeric and so I need a method that will cope with numerical issues. I try singular value decomposition because I feel that the information is in there somewhere. > In[43]:= > {u, w, v} = SingularValueDecomposition[mat /. rt]; > Examination of the singular values indicates that the last one is zero. I assume that this means that this singular value is associated with a zero determinant. I select the column of v associated with the zero singular value and hope that this is the eigenvector. > In[46]:= > vec = Transpose[v][[-1]]; > A check shows that the selected vector when multiplied by the matrix evaluated at the eigenvalue gives approximately zero: this looks hopeful. Am I on the correct track? > In[47]:= > (mat /. rt) . vec > Out[47]= > {3.883820346708995*^-17, 1.2588519636425044*^-13, -1.1055045534287126*^-16, 1.255173265671261*^-13} > Are there better methods? In general how do I set up the number of figures to give me a target accuracy for the eigenvalue and vector? > Hugh Goyder -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Eigenvalues and eigenvectors of a matrix with nonpolynomial elements. I need to find the eigenvalues and eigenvectors of matrices where the elements depend on a variable, k, in a nonpolynomial manner. Thus, according to my (limited) knowledge of eigensystems, the eigenvalues are the values of k that make the determinant zero and there should be an eigenvector associated with each eigenvalue. A simple warm-up example is given below; my actual cases will be more complicated. I wish to know if the method I have put together below, using engineering rather than maths, is suitable and what accuracy I can expect. First, here is the warm-up problem; the matrix is called mat and depends on the variable k. I start by working out the determinant. In[39]:= mat = {{-1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, {1, 0, -1, 0}, {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}}; In[40]:= d = Det[mat] Out[40]= 2*Cosh[k]*Sin[k] - 2*Cos[k]*Sinh[k] Second, I find one of the roots. There are an infinite number of roots and Ted Ersek's method for finding all the roots in an interval might help. I assume that each root is an eigenvalue: is this always true? In[41]:= rt = FindRoot[d, {k, 6, 8}] Out[41]= {k -> 7.068582745628732} Third, I attempt to get the eigenvector. It has been necessary to go numeric and so I need a method that will cope with numerical issues. I try singular value decomposition because I feel that the information is in there somewhere. In[43]:= {u, w, v} = SingularValueDecomposition[mat /. rt]; Examination of the singular values indicates that the last one is zero. I assume that this means that this singular value is associated with a zero determinant. I select the column of v associated with the zero singular value and hope that this is the eigenvector. In[46]:= vec = Transpose[v][[-1]]; A check shows that the selected vector when multiplied by the matrix evaluated at the eigenvalue gives approximately zero: this looks hopeful. Am I on the correct track? In[47]:= (mat /. rt) . vec Out[47]= {3.883820346708995*^-17, 1.2588519636425044*^-13, -1.1055045534287126*^-16, 1.255173265671261*^-13} Are there better methods? In general how do I set up the number of figures to give me a target accuracy for the eigenvalue and vector? Hugh Goyder === Subject: Re: Re: Factor 2 error in Inverse Laplace Transform >> I suggest to put a little safeguard into InverseLaplaceTransform and >> force it to avoid this trap. > Problem 3a: > InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] If this works in a single example, that doesn't mean it's a reliable strategy in general. Everything I've seen on the group in three years says the Laplace functions are unreliable. You'd best check every answer. Bobby > Maxim, > As far as your Log example is considered, it really shows > inconsistency. > The other examples are also interesting, but you make very general > comments and they bother me a bit. Somehow I feel they are unfair. > For instance, in your second example, first you consider the > input-output pair > In[1]= > Integrate[DiracDelta[x - a], {x, 0, 1}] > Out[1]= > UnitStep[1 - a]*UnitStep[a] > then you are substituting a->1 into the result and Mathematica gives 0. > You compare this to the pair > In[2]= > Integrate[DiracDelta[x], {x, 0, 1}] > Out[2]= > 1/2 > and draw the conclusion that something is wrong. > I respectfully disaggree with you. > In the Help of Integrate, Mathematica explicitely warns us: > When an integrand depends on a parameter, the indefinite integral > should be considered valid for generic values of the parameter. For > certain values the reported integral may be meaningless,... > In general, it is extremely easy to ask Mathematica to derive a parametric > result, and then to substitute something very special into the > parameter to obtain contradiction. > Personally, I am not really interested in that. > My examples try to mimic the situation when a user wants to solve a > specific problem, arrives at a Laplace transform and tries to find the > original using the InverseLaplaceTransform service of Mathematica. > In such a situation a factor of 2 error is dangerous and I think with > a little modification Mathematica could avoid it. > For instance here is Problem 3: > InverseLaplaceTransform[s/(1+s)^(3/2),s,t] > It gives an answer that is wrong by a factor of two, while > Problem 3a: > InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] > gives the right answer because then Mathematica finds other rules to apply and > they are correct. >I suggest to put a little safeguard into InverseLaplaceTransform and > force it to avoid this trap. This can be done without redefining > DiracDelta and UnitStep. (Those are used extensively by Mathematica and > therefore any change would impact the whole system in too many ways.) > Peter >> >> InverseLaplaceTransform is an extremely useful part of Mathematica >> (since v 4.1). >> However, in the following simple problem it gives the wrong answer: >> Problem 1: >> InverseLaplaceTransform[s/(s+1),s,t] >> -1/(2*E^t)+DiracDelta[t] >> where the factor 2 is completely wrong. >> >> To see that I slightly rewrite Problem 1 into >> Problem 1a: >> InverseLaplaceTransform[Apart[s/(s+1)],s,t] >> and then I get the correct answer: >> -E^(-t)+DiracDelta[t] >> >> Of course one can Unprotect InverseLaplaceTransform and teach it to >> give the correct answer but that is not the point. >> (Also one can start a long debate about the meaning of DiracDelta in >> Mathematica, but that is also not the point here. ) >> >> There are several similar simple examples when the wrong factor of two >> shows up, for instance >> Problem 2: >> InverseLaplaceTransform[ s ArcTan[1/s],s,t] >> >> Using the Trace one can find out that all these factor 2 errors have >> a common origin. >> Solving Problem 1 Mathematica calculates the convolution integral >> >> Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,0,t}] >> >> and because the lower limit is exactly zero,the factor 2 shows up in >> -1/(2*E^t), that is Mathematica halves the Dirac delta and all its >> derivatives at the origin. >> >> I think the InverseLaplaceTransform function could be much improved if >> the above convolution integral would be evaluated more carefully. >> >> For instance, doing it in two steps: >> res1=Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,-eps,t}, >> Assumptions -> eps>0]; >> res2=res1/.eps -> 0 >> would give the right result. >> (This caution is necessary only, if generalized functions are involved >> in the integration.) >> >> I wonder if further examples/suggestions are welcome in this group >> regarding InverseLaplaceTransform??? >> >> Peter >> I'd say that this is two messes mixed together. One is a rather poor >> implementation of integral transforms, especially when there are >> generalized functions involved. For example: >> In[1]:= >> LaplaceTransform[InverseLaplaceTransform[Log[p], p, t], t, p] - Log[p] >> LaplaceTransform[InverseLaplaceTransform[PolyGamma[p], p, t], t, p] - >> PolyGamma[p] >> Out[1]= >> EulerGamma >> Out[2]= >> EulerGamma >> We can see that LaplaceTransform/InverseLaplaceTransform aren't >> consistenly defined for these functions (here Mathematica doesn't >> internally take integrals of distributions). Another issue is the >> question of how the integral of DiracDelta on [0,a] should be >> interpreted: >> In[3]:= >> Integrate[DiracDelta[x], {x, 0, 1}] >> Integrate[DiracDelta[x - a], {x, 0, 1}] >> Integrate[DiracDelta[x - 1], {x, 1, 2}] >> Out[3]= >> 1/2 >> Out[4]= >> UnitStep[1 - a]*UnitStep[a] >> Out[5]= >> 0 >> The value of the first integral is by convention taken to be 1/2; >> however, substituting a=0 into Out[4] we obtain 1, and making the >> change of variables x->x-1 (the third integral) we get 0. Similarly >> for the integrals of the DiracDelta derivatives: >> In[6]:= >> Integrate[DiracDelta'[x]*phi[x], {x, -eps, Infinity}] >> Integrate[DiracDelta'[x]*phi[x], {x, 0, Infinity}] >> Integrate[DiracDelta'[x]*x, {x, 0, Infinity}] >> Out[6]= >> (-DiracDelta[eps])*phi[0] - phi'[0] >> Out[7]= >> 0 >> Out[8]= >> -(1/2) >> The value of the first integral for eps<0 is incorrect in any case, >> and Out[7] and Out[8] are not consistent with each other. >> Maxim Rytin >> m.r@inbox.ru -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Re: Factor 2 error in Inverse Laplace Transform I don't use the Laplace functions often enough to gain an appreciation for their usefulness (in case that is possible). All I see are posts that point out failures. I fear satisfied users may not realize how often they are getting wrong answers. If they aren't checking every answer, they're living in a fool's paradise. >> Unfortunately, I do not see a process in place where reasonable suggestions are accepted and handled to make the improvements. Amen. Bobby > Bob, > 1) If this works in a single example, that doesn't mean it's a > reliable strategy in general. > I am sorry if my previous message gave you the false impression that > it is enough safeguard to insert Apart before doing > InverseLaplaceTransform. > That was just an example to show that going through different paths, > the function InverseLaplaceTransform can come up with the wrong or > right answer. > In general, the safeguard has to be inserted into the code of > InverseLaplaceTransform itself. Whenever the convolution theorem is > used to obtain the result, the algorithm needs to check whether > DiracDelta (or its derivatives) are involved and need to do things > differently, if the answer is yes. Another fix should be inserted > regarding the inverse of Log[s] and or the transform (or rather > generalized transform) of 1/t. > 2) Everything I've seen on the group in three years says the Laplace > functions are unreliable. > If this statement is true it is very unfortunate. In fact the > LaplaceTransform and its inverse are both extremely powerful functions > and represent the quintessence of what a CAS is good for. Both these > functions rely heavily on Mathematica's integration package and I > think it is needless to tell this Group that Integrate is one of the > greatest things in Mathematica. > As far as I understand LaplaceTransform causes little trouble (in fact > it is quite good.) Most of the haevy usage and most of the problems > are related to InverseLaplaceTransform. > There are various reasons why InverseLaplaceTransform might have a bad > reputation. >i) Oftentimes the user knows a certain result but Mathematica rather > gives back the expression unevaluated. This is embarassing, but it can > be easily fixed by teaching Mathematica more and more Laplace > transform pairs. Andre Mallet posted some fixes on MathSource for > version 4.1 and it is my understanding that some of those fixes made > it into version 5. > Recently Urs Graf published an excellent book (Applied Laplace > Birkhauser) on the subject. In his package he teaches Mathematica a > lot of pairs (especially those involving Bessel functions and other > special functions either in the original or in the transform or both.) > Also he uses a more elaborate concept of pseudo functions, showing > that if you really miss something you can always create it in > Mathematica. > ii) More embarrasing is (at least for me) if Mathematica comes up with > a pseudo answer, which still contains an unevaluated Integrate. I > think this happens inadvertently and should be eliminated. > iii) Finally in certain cases Mathematica comes up with an answer that > is just deadly wrong. This is the most dangerous situation and it is > almost always related to the interpretation of the integral of a > DiracDelta or one of its derivatives, or to the integral of the log > function. These problems could be easily fixed. (Unfortunately, I do > not see a process in place where reasonable suggestions are accepted > and handled to make the improvements.) > Additional remarks: > In my opinion teaching more and more pairs to Mathematica is not the > real solution. In fact the more and more the function > InverseLaplaceTransform is relying on general rules and calling the > Integrate function, the more and more powerful it will be. This is the > strength of Mathematica: applying very simple and general rules. > However, if there is a glitch in one of the general rules, it MUST be > corrected soon, because it effects more and more results and destroys > the reputation of an extreemly valuable tool. > In MathSource there is a function available called GWR. This function > can calculate the inverse of a Laplace transform at a given value of > time with any required accuracy. I use it often to check an analytic > result coming out from InverseLaplaceTransform and this check always > reveals if there is a problem (somewhat similarly to making a plot if > you are not sure about a limit...) > Peter >I suggest to put a little safeguard into InverseLaplaceTransform and >force it to avoid this trap. >> Problem 3a: >> InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] >> If this works in a single example, that doesn't mean it's a reliable strategy in general. >> Everything I've seen on the group in three years says the Laplace functions are unreliable. >> You'd best check every answer. >> Bobby >> Maxim, >> >> As far as your Log example is considered, it really shows >> inconsistency. >> The other examples are also interesting, but you make very general >> comments and they bother me a bit. Somehow I feel they are unfair. >> >> For instance, in your second example, first you consider the >> input-output pair >> In[1]= >> Integrate[DiracDelta[x - a], {x, 0, 1}] >> Out[1]= >> UnitStep[1 - a]*UnitStep[a] >> then you are substituting a->1 into the result and Mathematica gives 0. >> >> You compare this to the pair >> In[2]= >> Integrate[DiracDelta[x], {x, 0, 1}] >> Out[2]= >> 1/2 >> >> and draw the conclusion that something is wrong. >> I respectfully disaggree with you. >> >> In the Help of Integrate, Mathematica explicitely warns us: >> When an integrand depends on a parameter, the indefinite integral >> should be considered valid for generic values of the parameter. For >> certain values the reported integral may be meaningless,... >> >> In general, it is extremely easy to ask Mathematica to derive a parametric >> result, and then to substitute something very special into the >> parameter to obtain contradiction. >> >> Personally, I am not really interested in that. >> My examples try to mimic the situation when a user wants to solve a >> specific problem, arrives at a Laplace transform and tries to find the >> original using the InverseLaplaceTransform service of Mathematica. >> In such a situation a factor of 2 error is dangerous and I think with >> a little modification Mathematica could avoid it. >> >> For instance here is Problem 3: >> InverseLaplaceTransform[s/(1+s)^(3/2),s,t] >> It gives an answer that is wrong by a factor of two, while >> Problem 3a: >> InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] >> gives the right answer because then Mathematica finds other rules to apply and >> they are correct. >>I suggest to put a little safeguard into InverseLaplaceTransform and >> force it to avoid this trap. This can be done without redefining >> DiracDelta and UnitStep. (Those are used extensively by Mathematica and >> therefore any change would impact the whole system in too many ways.) >> >> Peter >> >> >> > >InverseLaplaceTransform is an extremely useful part of Mathematica >(since v 4.1). >However, in the following simple problem it gives the wrong answer: >Problem 1: >InverseLaplaceTransform[s/(s+1),s,t] >-1/(2*E^t)+DiracDelta[t] >where the factor 2 is completely wrong. > >To see that I slightly rewrite Problem 1 into >Problem 1a: >InverseLaplaceTransform[Apart[s/(s+1)],s,t] >and then I get the correct answer: >-E^(-t)+DiracDelta[t] > >Of course one can Unprotect InverseLaplaceTransform and teach it to >give the correct answer but that is not the point. >(Also one can start a long debate about the meaning of DiracDelta in >Mathematica, but that is also not the point here. ) > >There are several similar simple examples when the wrong factor of two >shows up, for instance >Problem 2: >InverseLaplaceTransform[ s ArcTan[1/s],s,t] > >Using the Trace one can find out that all these factor 2 errors have >a common origin. >Solving Problem 1 Mathematica calculates the convolution integral Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,0,t}] > >and because the lower limit is exactly zero,the factor 2 shows up in >-1/(2*E^t), that is Mathematica halves the Dirac delta and all its >derivatives at the origin. > >I think the InverseLaplaceTransform function could be much improved if >the above convolution integral would be evaluated more carefully. > >For instance, doing it in two steps: > res1=Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,-eps,t}, > Assumptions -> eps>0]; > res2=res1/.eps -> 0 >would give the right result. >(This caution is necessary only, if generalized functions are involved >in the integration.) > >I wonder if further examples/suggestions are welcome in this group >regarding InverseLaplaceTransform??? > >Peter > >I'd say that this is two messes mixed together. One is a rather poor >implementation of integral transforms, especially when there are >generalized functions involved. For example: > >In[1]:= >LaplaceTransform[InverseLaplaceTransform[Log[p], p, t], t, p] - Log[p] >LaplaceTransform[InverseLaplaceTransform[PolyGamma[p], p, t], t, p] - >PolyGamma[p] > >Out[1]= >EulerGamma > >Out[2]= >EulerGamma > >We can see that LaplaceTransform/InverseLaplaceTransform aren't >consistenly defined for these functions (here Mathematica doesn't >internally take integrals of distributions). Another issue is the >question of how the integral of DiracDelta on [0,a] should be >interpreted: > >In[3]:= >Integrate[DiracDelta[x], {x, 0, 1}] >Integrate[DiracDelta[x - a], {x, 0, 1}] >Integrate[DiracDelta[x - 1], {x, 1, 2}] > >Out[3]= >1/2 > >Out[4]= >UnitStep[1 - a]*UnitStep[a] > >Out[5]= >0 > >The value of the first integral is by convention taken to be 1/2; >however, substituting a=0 into Out[4] we obtain 1, and making the >change of variables x->x-1 (the third integral) we get 0. Similarly >for the integrals of the DiracDelta derivatives: > >In[6]:= >Integrate[DiracDelta'[x]*phi[x], {x, -eps, Infinity}] >Integrate[DiracDelta'[x]*phi[x], {x, 0, Infinity}] >Integrate[DiracDelta'[x]*x, {x, 0, Infinity}] > >Out[6]= >(-DiracDelta[eps])*phi[0] - phi'[0] > >Out[7]= >0 > >Out[8]= >-(1/2) > >The value of the first integral for eps<0 is incorrect in any case, >and Out[7] and Out[8] are not consistent with each other. > >Maxim Rytin >m.r@inbox.ru >> >> >> >> -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Factor 2 error in Inverse Laplace Transform Bob, 1) If this works in a single example, that doesn't mean it's a reliable strategy in general. I am sorry if my previous message gave you the false impression that it is enough safeguard to insert Apart before doing InverseLaplaceTransform. That was just an example to show that going through different paths, the function InverseLaplaceTransform can come up with the wrong or right answer. In general, the safeguard has to be inserted into the code of InverseLaplaceTransform itself. Whenever the convolution theorem is used to obtain the result, the algorithm needs to check whether DiracDelta (or its derivatives) are involved and need to do things differently, if the answer is yes. Another fix should be inserted regarding the inverse of Log[s] and or the transform (or rather generalized transform) of 1/t. 2) Everything I've seen on the group in three years says the Laplace functions are unreliable. If this statement is true it is very unfortunate. In fact the LaplaceTransform and its inverse are both extremely powerful functions and represent the quintessence of what a CAS is good for. Both these functions rely heavily on Mathematica's integration package and I think it is needless to tell this Group that Integrate is one of the greatest things in Mathematica. As far as I understand LaplaceTransform causes little trouble (in fact it is quite good.) Most of the haevy usage and most of the problems are related to InverseLaplaceTransform. There are various reasons why InverseLaplaceTransform might have a bad reputation. i) Oftentimes the user knows a certain result but Mathematica rather gives back the expression unevaluated. This is embarassing, but it can be easily fixed by teaching Mathematica more and more Laplace transform pairs. Andre Mallet posted some fixes on MathSource for version 4.1 and it is my understanding that some of those fixes made it into version 5. Recently Urs Graf published an excellent book (Applied Laplace Birkhauser) on the subject. In his package he teaches Mathematica a lot of pairs (especially those involving Bessel functions and other special functions either in the original or in the transform or both.) Also he uses a more elaborate concept of pseudo functions, showing that if you really miss something you can always create it in Mathematica. ii) More embarrasing is (at least for me) if Mathematica comes up with a pseudo answer, which still contains an unevaluated Integrate. I think this happens inadvertently and should be eliminated. iii) Finally in certain cases Mathematica comes up with an answer that is just deadly wrong. This is the most dangerous situation and it is almost always related to the interpretation of the integral of a DiracDelta or one of its derivatives, or to the integral of the log function. These problems could be easily fixed. (Unfortunately, I do not see a process in place where reasonable suggestions are accepted and handled to make the improvements.) Additional remarks: In my opinion teaching more and more pairs to Mathematica is not the real solution. In fact the more and more the function InverseLaplaceTransform is relying on general rules and calling the Integrate function, the more and more powerful it will be. This is the strength of Mathematica: applying very simple and general rules. However, if there is a glitch in one of the general rules, it MUST be corrected soon, because it effects more and more results and destroys the reputation of an extreemly valuable tool. In MathSource there is a function available called GWR. This function can calculate the inverse of a Laplace transform at a given value of time with any required accuracy. I use it often to check an analytic result coming out from InverseLaplaceTransform and this check always reveals if there is a problem (somewhat similarly to making a plot if you are not sure about a limit...) Peter >> I suggest to put a little safeguard into InverseLaplaceTransform and >> force it to avoid this trap. > Problem 3a: > InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] > If this works in a single example, that doesn't mean it's a reliable strategy in general. > Everything I've seen on the group in three years says the Laplace functions are unreliable. > You'd best check every answer. > Bobby > Maxim, > As far as your Log example is considered, it really shows > inconsistency. > The other examples are also interesting, but you make very general > comments and they bother me a bit. Somehow I feel they are unfair. > For instance, in your second example, first you consider the > input-output pair > In[1]= > Integrate[DiracDelta[x - a], {x, 0, 1}] > Out[1]= > UnitStep[1 - a]*UnitStep[a] > then you are substituting a->1 into the result and Mathematica gives 0. > You compare this to the pair > In[2]= > Integrate[DiracDelta[x], {x, 0, 1}] > Out[2]= > 1/2 > and draw the conclusion that something is wrong. > I respectfully disaggree with you. > In the Help of Integrate, Mathematica explicitely warns us: > When an integrand depends on a parameter, the indefinite integral > should be considered valid for generic values of the parameter. For > certain values the reported integral may be meaningless,... > In general, it is extremely easy to ask Mathematica to derive a parametric > result, and then to substitute something very special into the > parameter to obtain contradiction. > Personally, I am not really interested in that. > My examples try to mimic the situation when a user wants to solve a > specific problem, arrives at a Laplace transform and tries to find the > original using the InverseLaplaceTransform service of Mathematica. > In such a situation a factor of 2 error is dangerous and I think with > a little modification Mathematica could avoid it. > For instance here is Problem 3: > InverseLaplaceTransform[s/(1+s)^(3/2),s,t] > It gives an answer that is wrong by a factor of two, while > Problem 3a: > InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] > gives the right answer because then Mathematica finds other rules to apply and > they are correct. >I suggest to put a little safeguard into InverseLaplaceTransform and > force it to avoid this trap. This can be done without redefining > DiracDelta and UnitStep. (Those are used extensively by Mathematica and > therefore any change would impact the whole system in too many ways.) > Peter >> >> InverseLaplaceTransform is an extremely useful part of Mathematica >> (since v 4.1). >> However, in the following simple problem it gives the wrong answer: >> Problem 1: >> InverseLaplaceTransform[s/(s+1),s,t] >> -1/(2*E^t)+DiracDelta[t] >> where the factor 2 is completely wrong. >> >> To see that I slightly rewrite Problem 1 into >> Problem 1a: >> InverseLaplaceTransform[Apart[s/(s+1)],s,t] >> and then I get the correct answer: >> -E^(-t)+DiracDelta[t] >> >> Of course one can Unprotect InverseLaplaceTransform and teach it to >> give the correct answer but that is not the point. >> (Also one can start a long debate about the meaning of DiracDelta in >> Mathematica, but that is also not the point here. ) >> >> There are several similar simple examples when the wrong factor of two >> shows up, for instance >> Problem 2: >> InverseLaplaceTransform[ s ArcTan[1/s],s,t] >> >> Using the Trace one can find out that all these factor 2 errors have >> a common origin. >> Solving Problem 1 Mathematica calculates the convolution integral >> >> Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,0,t}] >> >> and because the lower limit is exactly zero,the factor 2 shows up in >> -1/(2*E^t), that is Mathematica halves the Dirac delta and all its >> derivatives at the origin. >> >> I think the InverseLaplaceTransform function could be much improved if >> the above convolution integral would be evaluated more carefully. >> >> For instance, doing it in two steps: >> res1=Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,-eps,t}, >> Assumptions -> eps>0]; >> res2=res1/.eps -> 0 >> would give the right result. >> (This caution is necessary only, if generalized functions are involved >> in the integration.) >> >> I wonder if further examples/suggestions are welcome in this group >> regarding InverseLaplaceTransform??? >> >> Peter >> >> I'd say that this is two messes mixed together. One is a rather poor >> implementation of integral transforms, especially when there are >> generalized functions involved. For example: >> >> In[1]:= >> LaplaceTransform[InverseLaplaceTransform[Log[p], p, t], t, p] - Log[p] >> LaplaceTransform[InverseLaplaceTransform[PolyGamma[p], p, t], t, p] - >> PolyGamma[p] >> >> Out[1]= >> EulerGamma >> >> Out[2]= >> EulerGamma >> >> We can see that LaplaceTransform/InverseLaplaceTransform aren't >> consistenly defined for these functions (here Mathematica doesn't >> internally take integrals of distributions). Another issue is the >> question of how the integral of DiracDelta on [0,a] should be >> interpreted: >> >> In[3]:= >> Integrate[DiracDelta[x], {x, 0, 1}] >> Integrate[DiracDelta[x - a], {x, 0, 1}] >> Integrate[DiracDelta[x - 1], {x, 1, 2}] >> >> Out[3]= >> 1/2 >> >> Out[4]= >> UnitStep[1 - a]*UnitStep[a] >> >> Out[5]= >> 0 >> >> The value of the first integral is by convention taken to be 1/2; >> however, substituting a=0 into Out[4] we obtain 1, and making the >> change of variables x->x-1 (the third integral) we get 0. Similarly >> for the integrals of the DiracDelta derivatives: >> >> In[6]:= >> Integrate[DiracDelta'[x]*phi[x], {x, -eps, Infinity}] >> Integrate[DiracDelta'[x]*phi[x], {x, 0, Infinity}] >> Integrate[DiracDelta'[x]*x, {x, 0, Infinity}] >> >> Out[6]= >> (-DiracDelta[eps])*phi[0] - phi'[0] >> >> Out[7]= >> 0 >> >> Out[8]= >> -(1/2) >> >> The value of the first integral for eps<0 is incorrect in any case, >> and Out[7] and Out[8] are not consistent with each other. >> >> Maxim Rytin >> m.r@inbox.ru === Subject: Re: Factor 2 error in Inverse Laplace Transform Maxim, As far as your Log example is considered, it really shows inconsistency. The other examples are also interesting, but you make very general comments and they bother me a bit. Somehow I feel they are unfair. For instance, in your second example, first you consider the input-output pair In[1]= Integrate[DiracDelta[x - a], {x, 0, 1}] Out[1]= UnitStep[1 - a]*UnitStep[a] then you are substituting a->1 into the result and Mathematica gives 0. You compare this to the pair In[2]= Integrate[DiracDelta[x], {x, 0, 1}] Out[2]= 1/2 and draw the conclusion that something is wrong. I respectfully disaggree with you. In the Help of Integrate, Mathematica explicitely warns us: When an integrand depends on a parameter, the indefinite integral should be considered valid for generic values of the parameter. For certain values the reported integral may be meaningless,... In general, it is extremely easy to ask Mathematica to derive a parametric result, and then to substitute something very special into the parameter to obtain contradiction. Personally, I am not really interested in that. My examples try to mimic the situation when a user wants to solve a specific problem, arrives at a Laplace transform and tries to find the original using the InverseLaplaceTransform service of Mathematica. In such a situation a factor of 2 error is dangerous and I think with a little modification Mathematica could avoid it. For instance here is Problem 3: InverseLaplaceTransform[s/(1+s)^(3/2),s,t] It gives an answer that is wrong by a factor of two, while Problem 3a: InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] gives the right answer because then Mathematica finds other rules to apply and they are correct. I suggest to put a little safeguard into InverseLaplaceTransform and force it to avoid this trap. This can be done without redefining DiracDelta and UnitStep. (Those are used extensively by Mathematica and therefore any change would impact the whole system in too many ways.) Peter > > InverseLaplaceTransform is an extremely useful part of Mathematica > (since v 4.1). > However, in the following simple problem it gives the wrong answer: > Problem 1: > InverseLaplaceTransform[s/(s+1),s,t] > -1/(2*E^t)+DiracDelta[t] > where the factor 2 is completely wrong. > > To see that I slightly rewrite Problem 1 into > Problem 1a: > InverseLaplaceTransform[Apart[s/(s+1)],s,t] > and then I get the correct answer: > -E^(-t)+DiracDelta[t] > > Of course one can Unprotect InverseLaplaceTransform and teach it to > give the correct answer but that is not the point. > (Also one can start a long debate about the meaning of DiracDelta in > Mathematica, but that is also not the point here. ) > > There are several similar simple examples when the wrong factor of two > shows up, for instance > Problem 2: > InverseLaplaceTransform[ s ArcTan[1/s],s,t] > > Using the Trace one can find out that all these factor 2 errors have > a common origin. > Solving Problem 1 Mathematica calculates the convolution integral > > Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,0,t}] > > and because the lower limit is exactly zero,the factor 2 shows up in > -1/(2*E^t), that is Mathematica halves the Dirac delta and all its > derivatives at the origin. > > I think the InverseLaplaceTransform function could be much improved if > the above convolution integral would be evaluated more carefully. > > For instance, doing it in two steps: > res1=Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,-eps,t}, > Assumptions -> eps>0]; > res2=res1/.eps -> 0 > would give the right result. > (This caution is necessary only, if generalized functions are involved > in the integration.) > > I wonder if further examples/suggestions are welcome in this group > regarding InverseLaplaceTransform??? > > Peter > I'd say that this is two messes mixed together. One is a rather poor > implementation of integral transforms, especially when there are > generalized functions involved. For example: > In[1]:= > LaplaceTransform[InverseLaplaceTransform[Log[p], p, t], t, p] - Log[p] > LaplaceTransform[InverseLaplaceTransform[PolyGamma[p], p, t], t, p] - > PolyGamma[p] > Out[1]= > EulerGamma > Out[2]= > EulerGamma > We can see that LaplaceTransform/InverseLaplaceTransform aren't > consistenly defined for these functions (here Mathematica doesn't > internally take integrals of distributions). Another issue is the > question of how the integral of DiracDelta on [0,a] should be > interpreted: > In[3]:= > Integrate[DiracDelta[x], {x, 0, 1}] > Integrate[DiracDelta[x - a], {x, 0, 1}] > Integrate[DiracDelta[x - 1], {x, 1, 2}] > Out[3]= > 1/2 > Out[4]= > UnitStep[1 - a]*UnitStep[a] > Out[5]= > The value of the first integral is by convention taken to be 1/2; > however, substituting a=0 into Out[4] we obtain 1, and making the > change of variables x->x-1 (the third integral) we get 0. Similarly > for the integrals of the DiracDelta derivatives: > In[6]:= > Integrate[DiracDelta'[x]*phi[x], {x, -eps, Infinity}] > Integrate[DiracDelta'[x]*phi[x], {x, 0, Infinity}] > Integrate[DiracDelta'[x]*x, {x, 0, Infinity}] > Out[6]= > (-DiracDelta[eps])*phi[0] - phi'[0] > Out[7]= > Out[8]= > -(1/2) > The value of the first integral for eps<0 is incorrect in any case, > and Out[7] and Out[8] are not consistent with each other. > Maxim Rytin > m.r@inbox.ru === Subject: Re: Factor 2 error in Inverse Laplace Transform I do not question your suggestion to replace the interval of integration [0,Infinity] with [-eps,Infinity]. Curiously, Mathematica does exactly that for the direct transform; if we pass it the (indeterminate?) expression DiracDelta[t]*Log[t], we can see the evaluation path: In[1]:= LaplaceTransform[DiracDelta[t]*Log[t], t, p] Out[1]= Limit[Integrate[(DiracDelta[t]*Log[t])/E^(p*t), {t, System`LaplaceTransformDump`low$38, Infinity}, Assumptions -> p > 0 && System`LaplaceTransformDump`low$38 < 0, GenerateConditions -> False, PrincipalValue -> False], System`LaplaceTransformDump`low$38 -> 0, Direction -> 1] The low$38 parameter is your -eps. Taking the limit is a more accurate way than making the substitution eps->0. Consider the next integral: In[2]:= Assuming[p>0 && eps>0, Integrate[Log[t]*E^(-p*t), {t, -eps, Infinity}]] Out[2]= (Gamma[0, (-eps)*p] + E^(eps*p)*(I*Pi + Log[eps]))/p It would be incorrect to substitute eps->0, since this expression is undefined at 0. However, Limit[%2,eps->0] gives the correct value for LaplaceTransform[Log[t],t,p]. The substitution seems to be safe for DiracDelta[t], because then the integral just samples the value at 0 and eps simply will not appear in the output. Therefore, you have either to take the limit or to separate the terms containing DiracDelta from the rest of the integrand before making the substitution eps->0, because the integrand may contain both generalized and ordinary functions, e.g. DiracDelta[t]+Log[t]. Maxim Rytin m.r@inbox.ru > Maxim, > As far as your Log example is considered, it really shows > inconsistency. > The other examples are also interesting, but you make very general > comments and they bother me a bit. Somehow I feel they are unfair. > For instance, in your second example, first you consider the > input-output pair > In[1]= > Integrate[DiracDelta[x - a], {x, 0, 1}] > Out[1]= > UnitStep[1 - a]*UnitStep[a] > then you are substituting a->1 into the result and Mathematica gives 0. > You compare this to the pair > In[2]= > Integrate[DiracDelta[x], {x, 0, 1}] > Out[2]= > 1/2 > and draw the conclusion that something is wrong. > I respectfully disaggree with you. > In the Help of Integrate, Mathematica explicitely warns us: > When an integrand depends on a parameter, the indefinite integral > should be considered valid for generic values of the parameter. For > certain values the reported integral may be meaningless,... > In general, it is extremely easy to ask Mathematica to derive a parametric > result, and then to substitute something very special into the > parameter to obtain contradiction. > Personally, I am not really interested in that. > My examples try to mimic the situation when a user wants to solve a > specific problem, arrives at a Laplace transform and tries to find the > original using the InverseLaplaceTransform service of Mathematica. > In such a situation a factor of 2 error is dangerous and I think with > a little modification Mathematica could avoid it. > For instance here is Problem 3: > InverseLaplaceTransform[s/(1+s)^(3/2),s,t] > It gives an answer that is wrong by a factor of two, while > Problem 3a: > InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] > gives the right answer because then Mathematica finds other rules to apply and > they are correct. > I suggest to put a little safeguard into InverseLaplaceTransform and > force it to avoid this trap. This can be done without redefining > DiracDelta and UnitStep. (Those are used extensively by Mathematica and > therefore any change would impact the whole system in too many ways.) > Peter > > InverseLaplaceTransform is an extremely useful part of Mathematica > (since v 4.1). > However, in the following simple problem it gives the wrong answer: > Problem 1: > InverseLaplaceTransform[s/(s+1),s,t] > -1/(2*E^t)+DiracDelta[t] > where the factor 2 is completely wrong. > > To see that I slightly rewrite Problem 1 into > Problem 1a: > InverseLaplaceTransform[Apart[s/(s+1)],s,t] > and then I get the correct answer: > -E^(-t)+DiracDelta[t] > > Of course one can Unprotect InverseLaplaceTransform and teach it to > give the correct answer but that is not the point. > (Also one can start a long debate about the meaning of DiracDelta in > Mathematica, but that is also not the point here. ) > > There are several similar simple examples when the wrong factor of two > shows up, for instance > Problem 2: > InverseLaplaceTransform[ s ArcTan[1/s],s,t] > > Using the Trace one can find out that all these factor 2 errors have > a common origin. > Solving Problem 1 Mathematica calculates the convolution integral > > Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,0,t}] > > and because the lower limit is exactly zero,the factor 2 shows up in > -1/(2*E^t), that is Mathematica halves the Dirac delta and all its > derivatives at the origin. > > I think the InverseLaplaceTransform function could be much improved if > the above convolution integral would be evaluated more carefully. > > For instance, doing it in two steps: > res1=Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,-eps,t}, > Assumptions -> eps>0]; > res2=res1/.eps -> 0 > would give the right result. > (This caution is necessary only, if generalized functions are involved > in the integration.) > > I wonder if further examples/suggestions are welcome in this group > regarding InverseLaplaceTransform??? > > Peter > > I'd say that this is two messes mixed together. One is a rather poor > implementation of integral transforms, especially when there are > generalized functions involved. For example: > > In[1]:= > LaplaceTransform[InverseLaplaceTransform[Log[p], p, t], t, p] - Log[p] > LaplaceTransform[InverseLaplaceTransform[PolyGamma[p], p, t], t, p] - > PolyGamma[p] > > Out[1]= > EulerGamma > > Out[2]= > EulerGamma > > We can see that LaplaceTransform/InverseLaplaceTransform aren't > consistenly defined for these functions (here Mathematica doesn't > internally take integrals of distributions). Another issue is the > question of how the integral of DiracDelta on [0,a] should be > interpreted: > > In[3]:= > Integrate[DiracDelta[x], {x, 0, 1}] > Integrate[DiracDelta[x - a], {x, 0, 1}] > Integrate[DiracDelta[x - 1], {x, 1, 2}] > > Out[3]= > 1/2 > > Out[4]= > UnitStep[1 - a]*UnitStep[a] > > Out[5]= > 0 > > The value of the first integral is by convention taken to be 1/2; > however, substituting a=0 into Out[4] we obtain 1, and making the > change of variables x->x-1 (the third integral) we get 0. Similarly > for the integrals of the DiracDelta derivatives: > > In[6]:= > Integrate[DiracDelta'[x]*phi[x], {x, -eps, Infinity}] > Integrate[DiracDelta'[x]*phi[x], {x, 0, Infinity}] > Integrate[DiracDelta'[x]*x, {x, 0, Infinity}] > > Out[6]= > (-DiracDelta[eps])*phi[0] - phi'[0] > > Out[7]= > 0 > > Out[8]= > -(1/2) > > The value of the first integral for eps<0 is incorrect in any case, > and Out[7] and Out[8] are not consistent with each other. > > Maxim Rytin > m.r@inbox.ru === Subject: Re: Factor 2 error in Inverse Laplace Transform Steven/Maxim, I agree. Peter > I do not question your suggestion to replace the interval of > integration [0,Infinity] with [-eps,Infinity]. Curiously, Mathematica > does exactly that for the direct transform; if we pass it the > (indeterminate?) expression DiracDelta[t]*Log[t], we can see the > evaluation path: > In[1]:= > LaplaceTransform[DiracDelta[t]*Log[t], t, p] > Out[1]= > Limit[Integrate[(DiracDelta[t]*Log[t])/E^(p*t), > {t, System`LaplaceTransformDump`low$38, Infinity}, > Assumptions -> p > 0 && System`LaplaceTransformDump`low$38 < 0, > GenerateConditions -> False, PrincipalValue -> False], > System`LaplaceTransformDump`low$38 -> 0, Direction -> 1] > The low$38 parameter is your -eps. Taking the limit is a more accurate > way than making the substitution eps->0. Consider the next integral: > In[2]:= > Assuming[p>0 && eps>0, > Integrate[Log[t]*E^(-p*t), {t, -eps, Infinity}]] > Out[2]= > (Gamma[0, (-eps)*p] + E^(eps*p)*(I*Pi + Log[eps]))/p > It would be incorrect to substitute eps->0, since this expression is > undefined at 0. However, Limit[%2,eps->0] gives the correct value for > LaplaceTransform[Log[t],t,p]. > The substitution seems to be safe for DiracDelta[t], because then the > integral just samples the value at 0 and eps simply will not appear in > the output. Therefore, you have either to take the limit or to > separate the terms containing DiracDelta from the rest of the > integrand before making the substitution eps->0, because the integrand > may contain both generalized and ordinary functions, e.g. > DiracDelta[t]+Log[t]. > Maxim Rytin > m.r@inbox.ru > Maxim, > > As far as your Log example is considered, it really shows > inconsistency. > The other examples are also interesting, but you make very general > comments and they bother me a bit. Somehow I feel they are unfair. > > For instance, in your second example, first you consider the > input-output pair > In[1]= > Integrate[DiracDelta[x - a], {x, 0, 1}] > Out[1]= > UnitStep[1 - a]*UnitStep[a] > then you are substituting a->1 into the result and Mathematica gives 0. > > You compare this to the pair > In[2]= > Integrate[DiracDelta[x], {x, 0, 1}] > Out[2]= > 1/2 > > and draw the conclusion that something is wrong. > I respectfully disaggree with you. > > In the Help of Integrate, Mathematica explicitely warns us: > When an integrand depends on a parameter, the indefinite integral > should be considered valid for generic values of the parameter. For > certain values the reported integral may be meaningless,... > > In general, it is extremely easy to ask Mathematica to derive a parametric > result, and then to substitute something very special into the > parameter to obtain contradiction. > > Personally, I am not really interested in that. > My examples try to mimic the situation when a user wants to solve a > specific problem, arrives at a Laplace transform and tries to find the > original using the InverseLaplaceTransform service of Mathematica. > In such a situation a factor of 2 error is dangerous and I think with > a little modification Mathematica could avoid it. > > For instance here is Problem 3: > InverseLaplaceTransform[s/(1+s)^(3/2),s,t] > It gives an answer that is wrong by a factor of two, while > Problem 3a: > InverseLaplaceTransform[Apart[s/(1+s)^(3/2)],s,t] > gives the right answer because then Mathematica finds other rules to apply and > they are correct. > > I suggest to put a little safeguard into InverseLaplaceTransform and > force it to avoid this trap. This can be done without redefining > DiracDelta and UnitStep. (Those are used extensively by Mathematica and > therefore any change would impact the whole system in too many ways.) > > Peter > > > > > InverseLaplaceTransform is an extremely useful part of Mathematica > (since v 4.1). > However, in the following simple problem it gives the wrong answer: > Problem 1: > InverseLaplaceTransform[s/(s+1),s,t] > -1/(2*E^t)+DiracDelta[t] > where the factor 2 is completely wrong. > > To see that I slightly rewrite Problem 1 into > Problem 1a: > InverseLaplaceTransform[Apart[s/(s+1)],s,t] > and then I get the correct answer: > -E^(-t)+DiracDelta[t] > > Of course one can Unprotect InverseLaplaceTransform and teach it to > give the correct answer but that is not the point. > (Also one can start a long debate about the meaning of DiracDelta in > Mathematica, but that is also not the point here. ) > > There are several similar simple examples when the wrong factor of two > shows up, for instance > Problem 2: > InverseLaplaceTransform[ s ArcTan[1/s],s,t] > > Using the Trace one can find out that all these factor 2 errors have > a common origin. > Solving Problem 1 Mathematica calculates the convolution integral > > Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,0,t}] > > and because the lower limit is exactly zero,the factor 2 shows up in > -1/(2*E^t), that is Mathematica halves the Dirac delta and all its > derivatives at the origin. > > I think the InverseLaplaceTransform function could be much improved if > the above convolution integral would be evaluated more carefully. > > For instance, doing it in two steps: > res1=Integrate[E^(-t+x)*Derivative[1][DiracDelta][x],{x,-eps,t}, > Assumptions -> eps>0]; > res2=res1/.eps -> 0 > would give the right result. > (This caution is necessary only, if generalized functions are involved > in the integration.) > > I wonder if further examples/suggestions are welcome in this group > regarding InverseLaplaceTransform??? > > Peter > > I'd say that this is two messes mixed together. One is a rather poor > implementation of integral transforms, especially when there are > generalized functions involved. For example: > > In[1]:= > LaplaceTransform[InverseLaplaceTransform[Log[p], p, t], t, p] - Log[p] > LaplaceTransform[InverseLaplaceTransform[PolyGamma[p], p, t], t, p] - > PolyGamma[p] > > Out[1]= > EulerGamma > > Out[2]= > EulerGamma > > We can see that LaplaceTransform/InverseLaplaceTransform aren't > consistenly defined for these functions (here Mathematica doesn't > internally take integrals of distributions). Another issue is the > question of how the integral of DiracDelta on [0,a] should be > interpreted: > > In[3]:= > Integrate[DiracDelta[x], {x, 0, 1}] > Integrate[DiracDelta[x - a], {x, 0, 1}] > Integrate[DiracDelta[x - 1], {x, 1, 2}] > > Out[3]= > 1/2 > > Out[4]= > UnitStep[1 - a]*UnitStep[a] > > Out[5]= > 0 > > The value of the first integral is by convention taken to be 1/2; > however, substituting a=0 into Out[4] we obtain 1, and making the > change of variables x->x-1 (the third integral) we get 0. Similarly > for the integrals of the DiracDelta derivatives: > > In[6]:= > Integrate[DiracDelta'[x]*phi[x], {x, -eps, Infinity}] > Integrate[DiracDelta'[x]*phi[x], {x, 0, Infinity}] > Integrate[DiracDelta'[x]*x, {x, 0, Infinity}] > > Out[6]= > (-DiracDelta[eps])*phi[0] - phi'[0] > > Out[7]= > 0 > > Out[8]= > -(1/2) > > The value of the first integral for eps<0 is incorrect in any case, > and Out[7] and Out[8] are not consistent with each other. > > Maxim Rytin > m.r@inbox.ru === Subject: One quesiton about Combinatorica I have a few point in 2-dimension. (3,0),(2,8),(1,5),(4,5) I want to find the ShortestPathSpanningTree and the sum of edges' weights of this spanning tree. Could you tell me how to generated a graph with all vertex on grids? The distance between two vertices are difined in terms of Manhattan distance. Here is a simple example in Combinatorica's tutorial, but I don't know what function can substitute the function GridGraph. ShowGraph[ShortestPathSpanningTree[GridGraph[5, 5], 1]]; Peng === Subject: Sorting a list of pairs on the second elements I have a list, for example In[101]:= collectedDnaBin Out[101]= {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg tcataa cttaatgtttttatttaaaatacc,1},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13}, { tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg tca, 122},{aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ actgcttcttcttgcctttgcggaatttg,1221},{ gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta aa, 1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1 331},{ tgaaaattttccggttt,13311}} It is a list of pair of Strings. I would like to Sort it on the second elements of the pairs. I can do the naive approach with: In[109]:= Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] Out[109]= {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg tcataa cttaatgtttttatttaaaatacc,1},{tatttttgtaattcaatactgcttcttctt,11},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ aaattttccggtttaaggcgtttccgttcttcttcgtca,122},{actgcttcttcttgcctttgcggaat ttg, 1221},{tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttat cg,13} ,{gctatttat,131},{gctatttatgaaaattttccggtttaaggcg,132},{gcggaatttggccttt taaa, 1321},{aaattttcc,13211},{ gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1331},{tgaaaattttccggttt,1 3311}} and it does the job, but I am wondering if it can be done by Sort[list,func] where func would tell Sort to do the sorting of the pairs by the second elements. I tried from Ted .83rsek's excellent page http://www.verbeia.com/mathematica/tips/HTMLLinks/Tricks_P-Z_22.html Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] but that does not want to do the trick for me. The Mapping of RoteteLeft and RotateRight, which is a generalization of my naive approach above, he shows on the same page, does it, but I do not know how to put that into Sort as second argument. Maybe I should not, but rather to write a mySort function based upon his idea... ? In general, if I have a list whose elements are m-member lists, like {{a1,...,am},...,{z1,...,zm}}, then my question is what is the best/fastest way to sort it on the k-th elements of the members where 1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and use as little memory for it as possible. J.87nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: Re: Sorting a list of pairs on the second elements Both methods do the same thing at my machine, and there's also a third method that may do better: sss={{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg tcataacttaatgtttttatttaaaatacc,1},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg tca,122},{aaattttccggtttaaggcgtttccgttctt,121},{ ttcttgcctttgcgg,1211},{actgcttcttcttgcctttgcggaatttg,1221},{ gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta aa, 1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt, 1331},{tgaaaattttccggttt,13311}}; Sort[sss, (Last[#1] < Last[#2]) &] % == Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ sss] %% == Reverse /@ Sort[Reverse /@ sss] {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg tcataacttaatgtttttatttaaaatacc,1},{tatttttgtaattcaatactgcttcttctt,11},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13},{ aaattttccggtttaaggcgtttccgttctt,121},{aaattttccggtttaaggcgtttccgttcttcttcg tca,122},{gctatttat,131},{gctatttatgaaaattttccggtttaaggcg,132},{ gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ttcttgcctttgcgg, 1211},{actgcttcttcttgcctttgcggaatttg,1221},{aa gcggaatttggcctttta,1321},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1331 }, {aaattttcc,13211},{tgaaaattttccggttt,13311}} True True Bobby > Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] > Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] >but that does not want to do the trick for me. >> I wonder why. It should work, albeit inefficently. Mmmmm, have you >> tried >> with parenthesis wrapped around the pure function? >> Sort[collectedDnaBin,(#1[[2]] < #2[[2]])&] >> Have you tried it in a fresh kernel? > Yes, and yes. It does not work. > In[31]:= > Sort[sss, (Last[#1] < Last[#2] )&] > Out[31]= > {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg > > tcataacttaatgtttttatttaaaatacc,1},{ > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13}, > { > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ > tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg > tca, > 122},{aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ > actgcttcttcttgcctttgcggaatttg,1221},{ > gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ > gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta > aa, > 1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1 > 331},{ > tgaaaattttccggttt,13311}} > Maybe because they are Strings ? I am just guessing... >In general, if I have a list whose elements are m-member lists, like >{{a1,...,am},...,{z1,...,zm}}, then my question is what is the >best/fastest way to sort it on the k-th elements of the members where >1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and >use as little memory for it as possible. >> Dunno for the general case, but this -very inelegant - approach to sort >> according to the last element seems to be pretty fast (lots of >> procedures >> but applied to the data as a whole, without timeconsuming mapping on >> every >> single element) >> Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ >> collectedDnaBin ] > This one works fine. >> ( The first and last three procs just implement a swap function >> swap[list_]:=Transpose@Reverse@Transpose[list] >> ) >> The group's gurus will certainly find a proc at least ten times faster >> than >> this, I'm sure. > I don't know. The suggestions I got via the list and private are all > excellent, but the data I had to sort got so big that I even did not > get to that point to able to sort because the Kernel just quitted on me > half way. Now I am on a different war-path to get the results I need > :) /My secret prayers go out for a real 64-bit, or MORE, Mathematica > on OSX..../ > J.87nos >> cheers, >> Peltio >> Invalid address in reply-to. Crafty demunging required to mail me. > I tried to employ Mathematica in Crafty demunging but I failed, so I > send it as is. Now I embrace for an Addressee not found... > thunder... :) > ------------------------------------------------------------------- > J.87nos L.9abb > Yale University School of Medicine > Department of Pathology > Phone: 203-737-5204 > Fax: 203-785-7303 > E-mail: janos.lobb@yale.edu -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Re: Re: Sorting a list of pairs on the second elements >> Both methods do the same thing at my machine, > They should not when the data is actually made of Strings. I copied from the e-mail, foolishly thinking the list was in usable InputForm. Bobby >> Both methods do the same thing at my machine, > They should not when the data is actually made of Strings. > sss={{ttcttgcctttgcgg,121},...} > and not symbols and integers as in > sss={{ttcttgcctttgcgg,121},...} >> Reverse /@ Sort[Reverse /@ sss] > I had already tried that one but it was slower than > Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ > sss] > Mapping Reverse on every row of a long list is more time consuming than > tranposing the matrix and swapping its *two* long rows. > This is the side effect of working with an interpreted language, I guess. > cheers, > Peltio > Invalid address in reply-to. Crafty demunging required to mail me. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Re: Sorting a list of pairs on the second elements >Both methods do the same thing at my machine, They should not when the data is actually made of Strings. sss={{ttcttgcctttgcgg,121},...} and not symbols and integers as in sss={{ttcttgcctttgcgg,121},...} > Reverse /@ Sort[Reverse /@ sss] I had already tried that one but it was slower than Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ sss] Mapping Reverse on every row of a long list is more time consuming than tranposing the matrix and swapping its *two* long rows. This is the side effect of working with an interpreted language, I guess. cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: Re: Sorting a list of pairs on the second elements >> Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] >> Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] >> but that does not want to do the trick for me. > I wonder why. It should work, albeit inefficently. Mmmmm, have you > tried > with parenthesis wrapped around the pure function? > Sort[collectedDnaBin,(#1[[2]] < #2[[2]])&] > Have you tried it in a fresh kernel? Yes, and yes. It does not work. In[31]:= Sort[sss, (Last[#1] < Last[#2] )&] Out[31]= {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg tcataacttaatgtttttatttaaaatacc,1},{ tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13}, { tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg tca, 122},{aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ actgcttcttcttgcctttgcggaatttg,1221},{ gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta aa, 1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1 331},{ tgaaaattttccggttt,13311}} Maybe because they are Strings ? I am just guessing... >> In general, if I have a list whose elements are m-member lists, like >> {{a1,...,am},...,{z1,...,zm}}, then my question is what is the >> best/fastest way to sort it on the k-th elements of the members where >> 1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and >> use as little memory for it as possible. > Dunno for the general case, but this -very inelegant - approach to sort > according to the last element seems to be pretty fast (lots of > procedures > but applied to the data as a whole, without timeconsuming mapping on > every > single element) > Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ > collectedDnaBin ] This one works fine. > ( The first and last three procs just implement a swap function > swap[list_]:=Transpose@Reverse@Transpose[list] > The group's gurus will certainly find a proc at least ten times faster > than > this, I'm sure. I don't know. The suggestions I got via the list and private are all excellent, but the data I had to sort got so big that I even did not get to that point to able to sort because the Kernel just quitted on me half way. Now I am on a different war-path to get the results I need :) /My secret prayers go out for a real 64-bit, or MORE, Mathematica on OSX..../ J.87nos > cheers, > Peltio > Invalid address in reply-to. Crafty demunging required to mail me. I tried to employ Mathematica in Crafty demunging but I failed, so I send it as is. Now I embrace for an Addressee not found... thunder... :) ------------------------------------------------------------------- J.87nos L.9abb Yale University School of Medicine Department of Pathology Phone: 203-737-5204 Fax: 203-785-7303 E-mail: janos.lobb@yale.edu === Subject: Re: Sorting a list of pairs on the second elements > [...] the data I had to sort got so big that I even did not get to > that point to able to sort because the Kernel just quitted on me > half way. Assuming you can get your data into memory, would you be satisfied with an ordered list of pointers? With the requirement that the list members are to be ordered in terms of their kth elements, Sort[Range[Length[list]], OrderedQ[{list[[#1,k]],list[[#2,k]]}]&] should give the same as Ordering[list, All, OrderedQ[{#1[[k]],#2[[k]]}]&] without creating a second copy of list. (Or maybe Ordering already does it that way?) === Subject: Re: Re: Sorting a list of pairs on the second elements {tgaaaattttccggttt,13311} >Maybe because they are Strings ? I am just guessing... I think you guessed right. I did not read your original post with due attention. You clearly stated that the elements were strings, but I took your data sample as 'real' Mathematica code and, since I did not see any quotes to delimit those strings, I surmised they were symbols and numbers. With String the ordering function using OrderedQ posted by other people should do the work, but I fear it would be very slow when compared with Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ data ] Perhaps coding the second element of your list as Integer could speed things up a bit (moreover, such a conversion would allow you to exploit Ted Ersek's trick). > the data I had to sort got so big that I even did not >get to that point to able to sort because the Kernel just quitted on me >half way. You mean that you are not even able to Sort your raw data? Or that the whole swapping+sorting+swapping procedure is too much a burden for your machine? In the latter case, I wonder if clearing variables at intermediate steps could help you somehow. The above approach is quite fast but could be building a lot of intermediate data. (I suppose that a oneliner keeps every intermediate result in memory before passing it to the next wrapper...) I won't be able to test this until next week, but can this intermediate clearing reduce the amount of memory swallowed by Mathematica? MemoryInUse[] temp = Transpose[collectedDnaBin]; Clear[collectedDnaBin]; MemoryInUse[] temp1 = Reverse[temp]; Clear[temp]; MemoryInUse[] temp = Transpose[temp1]; Clear[temp1]; MemoryInUse[] temp1 = Sort[temp]; Clear[temp]; MemoryInUse[] temp = Transpose[temp1]; Clear[temp1]; MemoryInUse[] temp1 = Reverse[temp]; Clear[temp]; MemoryInUse[] sortedDnaBin = Transpose[temp1]; Clear[temp1]; MemoryInUse[] If clearing a variable frees the memory previously allocated for it, this step-by-step approach should ask less memory than the oneliner. If clearing a variable does not free any memory (is there a command that frees allocated memory, or is this a strictly OS task?) you might want to quit the kernel between every single step, saving the data to a file that will be read in for the subsequent step. If killing the kernel won't free the memory previously allocated (it would not surprise me if certain OSes wouldn't free any memory at all) you could try by killing the kernel, the front end, turning off the power, unplugging the machine from the outlet and only then trying the next step. Obviously this would give you benefits only if your system is able to sort data that big without quitting the kernel. If that is not the case, well, you might want to consider writing a C routine to be interfaced to Mathematica via Mathlink. Sorry I couldnt' help more. >> Invalid address in reply-to. Crafty demunging required to mail me. >I tried to employ Mathematica in Crafty demunging but I failed, so I >send it as is. Now I embrace for an Addressee not found... >thunder... :) Munging is *very powerful* in keeping spam away from my mailbox. Unfortunately it kills a lot of the privately sent answers I could get from newsgroups. My munged address peltioNOSP@Mdespammed.com.invalid requires capital letters and .invalid suffix to be removed in order to turn into a valid address. A Mathematica routine to demung it should read something like... demung[ address_String ] := ToCharacterCode[ Characters[ address]]],_?CapitalQ], -8]] CapitalQ[ code_Integer ] := (64 < code < 91) : ) cheers, Peltio Invalid address etc. etc. === Subject: Re: Sorting a list of pairs on the second elements > [...] > In general, if I have a list whose elements are m-member lists, like > {{a1,...,am},...,{z1,...,zm}}, then my question is what is the > best/fastest way to sort it on the k-th elements of the members where > 1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and > use as little memory for it as possible. Sort[list, OrderedQ[{#1[[k]],#2[[k]]}]& ] works for me with your data. === Subject: Re: Sorting a list of pairs on the second elements J.87nos, Using a smaller example: collectedDnaBin = {{a, 2}, {b, 1}}; ord[p1_, p2_] := OrderedQ[{p1[[2]], p2[[2]]}]; Sort[collectedDnaBin, ord] will result in {{b, 1}, {a, 2}} Peter > I have a list, for example > In[101]:= > collectedDnaBin > Out[101]= > {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg > tcataa > cttaatgtttttatttaaaatacc,1},{ > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13}, > { > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ > tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg > tca, > 122},{aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ > actgcttcttcttgcctttgcggaatttg,1221},{ > gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ > > gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta > aa, > 1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1 > 331},{ > tgaaaattttccggttt,13311}} > It is a list of pair of Strings. I would like to Sort it on the second > elements of the pairs. > I can do the naive approach with: > In[109]:= > Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] > Out[109]= > {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg > tcataa > cttaatgtttttatttaaaatacc,1},{tatttttgtaattcaatactgcttcttctt,11},{ > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ > aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ > aaattttccggtttaaggcgtttccgttcttcttcgtca,122},{actgcttcttcttgcctttgcggaat > ttg, > 1221},{tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttat > cg,13} > ,{gctatttat,131},{gctatttatgaaaattttccggtttaaggcg,132},{gcggaatttggccttt > taaa, > 1321},{aaattttcc,13211},{ > gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ > aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1331},{tgaaaattttccggttt,1 > 3311}} > and it does the job, but I am wondering if it can be done by > Sort[list,func] where func would tell Sort to do the sorting of the > pairs by the second elements. I tried from Ted .83rsek's excellent page > http://www.verbeia.com/mathematica/tips/HTMLLinks/Tricks_P-Z_22.html > Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] but that does not want to do > the trick for me. The Mapping of RoteteLeft and RotateRight, which is > a generalization of my naive approach above, he shows on the same page, > does it, but I do not know how to put that into Sort as second > argument. Maybe I should not, but rather to write a mySort function > based upon his idea... ? > In general, if I have a list whose elements are m-member lists, like > {{a1,...,am},...,{z1,...,zm}}, then my question is what is the > best/fastest way to sort it on the k-th elements of the members where > 1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and > use as little memory for it as possible. > J.87nos > ---------------------------------------------- > Trying to argue with a politician is like lifting up the head of a > corpse. > (S. Lem: His Master Voice) === Subject: Re: Sorting a list of pairs on the second elements > Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] > Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] > but that does not want to do the trick for me. I wonder why. It should work, albeit inefficently. Mmmmm, have you tried with parenthesis wrapped around the pure function? Sort[collectedDnaBin,(#1[[2]] < #2[[2]])&] Have you tried it in a fresh kernel? >In general, if I have a list whose elements are m-member lists, like >{{a1,...,am},...,{z1,...,zm}}, then my question is what is the >best/fastest way to sort it on the k-th elements of the members where >1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and >use as little memory for it as possible. Dunno for the general case, but this -very inelegant - approach to sort according to the last element seems to be pretty fast (lots of procedures but applied to the data as a whole, without timeconsuming mapping on every single element) Transpose@Reverse@Transpose@Sort@Transpose@Reverse@Transpose[ collectedDnaBin ] ( The first and last three procs just implement a swap function swap[list_]:=Transpose@Reverse@Transpose[list] ) The group's gurus will certainly find a proc at least ten times faster than this, I'm sure. cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: Sorting a list of pairs on the second elements Sort[collectedDnaBin, Last[#1] < Last[#2] &] Jens J.87nos schrieb im Newsbeitrag > I have a list, for example > In[101]:= > collectedDnaBin > Out[101]= > {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg > tcataa > cttaatgtttttatttaaaatacc,1},{ > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttatcg,13}, > { > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ > tatttttgtaattcaatactgcttcttctt,11},{aaattttccggtttaaggcgtttccgttcttcttcg > tca, > 122},{aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ > actgcttcttcttgcctttgcggaatttg,1221},{ > gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ > gctatttatgaaaattttccggtttaaggcg,132},{gctatttat,131},{gcggaatttggcctttta > aa, > 1321},{aaattttcc,13211},{aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1 > 331},{ > tgaaaattttccggttt,13311}} > It is a list of pair of Strings. I would like to Sort it on the second > elements of the pairs. > I can do the naive approach with: > In[109]:= > Map[Reverse,Sort[Map[Reverse,collectedDnaBin]]] > Out[109]= > {{gggcggcgacctcgcgggttttcgctatttatgaaaattttccggtttaaggcgtttccgttcttcttcg > tcataa > cttaatgtttttatttaaaatacc,1},{tatttttgtaattcaatactgcttcttctt,11},{ > tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaa,12},{ > aaattttccggtttaaggcgtttccgttctt,121},{ttcttgcctttgcgg,1211},{ > aaattttccggtttaaggcgtttccgttcttcttcgtca,122},{actgcttcttcttgcctttgcggaat > ttg, > 1221},{tatttttgtaattcaatactgcttcttcttgcctttgcggaatttggccttttaaaagtatttat > cg,13} > ,{gctatttat,131},{gctatttatgaaaattttccggtttaaggcg,132},{gcggaatttggccttt > taaa, > 1321},{aaattttcc,13211},{ > gctatttatgaaaattttccggtttaaggcgtttccgttcttcttcgtcataa,133},{ > aatactgcttcttcttgcctttgcggaatttggccttttaaaagt,1331},{tgaaaattttccggttt,1 > 3311}} > and it does the job, but I am wondering if it can be done by > Sort[list,func] where func would tell Sort to do the sorting of the > pairs by the second elements. I tried from Ted .83rsek's excellent page > http://www.verbeia.com/mathematica/tips/HTMLLinks/Tricks_P-Z_22.html > Sort[collectedDnaBin,#1[[2]] < #2[[2]] &] but that does not want to do > the trick for me. The Mapping of RoteteLeft and RotateRight, which is > a generalization of my naive approach above, he shows on the same page, > does it, but I do not know how to put that into Sort as second > argument. Maybe I should not, but rather to write a mySort function > based upon his idea... ? > In general, if I have a list whose elements are m-member lists, like > {{a1,...,am},...,{z1,...,zm}}, then my question is what is the > best/fastest way to sort it on the k-th elements of the members where > 1<=k<=m and ak,...,zk are arbitrary objects - in my case Strings - and > use as little memory for it as possible. > J.87nos > ---------------------------------------------- > Trying to argue with a politician is like lifting up the head of a > corpse. > (S. Lem: His Master Voice) === Subject: Re: Re: normal distribution random number generation I know... It's werid for me... which i wanted to ask you all. when i used the code below I still got the low 24 bin value. In[1]:=<All] ListPlot[plotvec,PlotRange->All] used it exactly as it is shown. but the below works, it seems... SeedRandom[1111111]; vec1 = Table[Random[Integer,1000],{10^6}]; vec2 = Map[If[#<=44,1,0]&, vec1]; ones = Flatten[Position[vec2,1]]; Length[ones]/10.^6 plotvec = Map[Length, Split[Sort[Drop[ones-RotateRight[ones,1],1]]]]; ListPlot[ Log[plotvec], PlotRange->All] ListPlot[plotvec, PlotRange->All] maybe other people can try it and see if it's just me? (I took out the init.m btw) sean > This is exactly what it is mean to do. The problem > was due to the > usage of the SWB algortithm by the built in Random[] > for generating > random reals. RandomReplace makes Mathematica use > the Wolfran CA random > number generator, which Mathematica uses for > generating random integers > instead of the SWB. This cures the problem > reported int hat message. > Have you got any reason to think it does not? > Andrzej > *This message was transferred with a trial version > of CommuniGate(tm) > Pro* > Hi andrej > thank you so much for making your package > available. > I think I may have found another problem... (may > have > found being operative phrase, or non-operative > for > that matter) hl=en&lr=&newwindow=1&safe=off&threadm=a5t1fq%245vt%241%40smc.vnet.net& > rnum=1&prev=/ groups%3Fhl%3Den%26lr%3D%26newwindow%3D1%26safe%3Doff%26q%3Dchange%2Bth is%2Bnumber%2Bto%2Bget%2Banother%2Brandom%2Bsequence%26meta%3Dgroup%253 > Dcomp.soft-sys.math.mathematica > shows a thread dealing with random reals and > getting a > much smaller frequency at position 24 than others > positions. > Daniel posted a work around showing the use of > Random > Integers to fix the problem, which as far I > understand, the Random replacement also > implements. > It seems the RandomReplacement doesn't take care > of > the appearance of the lower than expected > frequency at > position 24(or interval 24 as the OP had noted). > I must be missing something. > sean >> *This message was transferred with a trial > version >> of CommuniGate(tm) Pro* >> I think I have now fixed the problem reported by >> Mark Fisher. The new >> version of the RandomReplacement now works like >> this: >> >> >> SeedRandom[5] >> >> >> Timing[First[Table[Random[],{10000}]]] >> >> >> {0.01 Second,0.786599} >> >> >> <> >> Timing[First[Table[Random[],{10000}]]] >> >> >> {0.02 Second,0.409222} >> >> >> As you can see there is a loss of speed involved. >> There may also be >> still some as yet undiscovered problems. However, >> the new package is >> available form my sites, though I still should > write >> some documentation >> of the latest changes (a few bugs in the previous >> version have also >> been fixed). >> >> Andrzej Kozlowski >> >> Andrzej Kozlowski >> Chiba, Japan >> http://www.akikoz.net/~andrzej/ >> http://www.mimuw.edu.pl/~akoz/ >> >> >> >> >*This message was transferred with a trial > version >> of CommuniGate(tm) >Pro* >It's clearly because of packed arrays: > > >< > >PackedArrayQ[Table[Random[],{249}]] > > >False > > >PackedArrayQ[Table[Random[],{250}]] > > >True > > > >Obviously Mathematica uses a different method of >> generating random >packed arrays. There are various ways of getting >> round this (e.g. >constructing lists as joins of lists of length >> less than 250 etc) but >one will loose the benefits of packed arrays and >> with that, presumably, >a lot of speed. This seems to be something that >> only WRI can change. >Note however that not all situations in which > one >> uses Random[] require >generating this type of lists. >Moreover, for problems involving the normal >> distribution it seems to me >that using the Marsaglia generator gives good >> results even with the >built in Random[]. But certainly we should hope >> that something will >finally be done do deal with this issue in > version >> 6. > >Andrzej > > > > > >>He's right! How the devil does that happen? >> >>Here's a test, with Andrzej's package loaded in >> my Init file. >> >>First, with n=250: >> >>Quit >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Now, with n=249: >> >>Quit >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.656099 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.0708373 >> >>Bobby >> >> Fisher >> >FYI: I've just a little testing and I find > that >> Mathematica ignors >the user >defined rules for Random in > Table[Random[],{n}] >> when n >= 250. > >>The problem is not actually with the way >> Mathematica's >>NormalDistribution but with the uniformly >> distributed Random[] >>function. >>NormalDistribution itself is generated (in > the >> package >>Statistics`NormalDistribution`) by means of > the >> very classical so >>called Boox-Muller method (although actually >> the Marsaglia variant >>below works better). You can try downolading > my >> little >>RandomReplacement package form one of my web >> sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ >> in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ > in >> Poland >> >>The package is based on the post of daniel >> Lichtblau, which explains >>the nature of the problem: >> >> >> > >>msg00088.html> >> >> >> >>The package is named init.m and can be loaded >> automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned > with >> normal distributions >>it >>may be enough to the following. First load > the >> (unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will >> replace the Box-Muller >>generator by the Marsaglia one. I have found >> that this is usually >>enough. But if your problem still remains try >> the RandomReplacement >>package. (Or you can use both of course). > Here >> is the Marsaglia code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >> >> Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> >While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial >> version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in >> Mathematica's normal >distribution random number generator. The >> problem arises when I >look >at the distribution of averages of a list of >> theses numbers. That >is, >I generate 1000 numbers and take their >> average. I do this a number >of >times and the plot a frequency distribution. >> Consistently it seems >to >be skewed positive. Specifically, the > number >> of occurrences less >than >3 standard deviations is consistent with the >> expected number, but >the >number greater than 3 is always larger (in >> some cases about twice >the >expected number). > >I was wondering if anyone else has noticed >> this and knows of a fix. >Also, does anyone have code for a good > quality >> normal distribution >random number generator? > >Chris > >> >> > > > > >> >> >> >>-- >>DrBob@bigfoot.com >>www.eclecticdreams.net >> > > >> > > __________________________________ > Do you Yahoo!? > Yahoo! Mail Address AutoComplete - You start. We > finish. > http://promotions.yahoo.com/new_mail __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com === Subject: Re: Re: normal distribution random number generation Are you using the latest version of the RandomReplacement package? (The one I posted last night). The earlier one had a bug and ddi not work with calls to Random[Real,{a,b}] where a and b are integers. You had to use Random[Real,N[{a,b}]]. I think (I hope) I fixed that in the latest version. Andrzej > *This message was transferred with a trial version of CommuniGate(tm) > Pro* > I know... It's werid for me... which i wanted to ask > you all. > when i used the code below I still got the low 24 bin > value. > In[1]:=< In[2]:= > SeedRandom[1111111 ]; > vec1=Table[Random[Real,{0,1000}],{10^6}]; > vec2=Map[If[#<44,1,0]&,vec1]; > ones=Flatten[Position[vec2,1]]; > plotvec=Map[Length,Split[Sort[Drop[ones-RotateRight[ones,1],1]]]]; > ListPlot[Log[plotvec],PlotRange->All] > ListPlot[plotvec,PlotRange->All] > used it exactly as it is shown. > but the below works, it seems... > SeedRandom[1111111]; > vec1 = Table[Random[Integer,1000],{10^6}]; > vec2 = Map[If[#<=44,1,0]&, vec1]; > ones = Flatten[Position[vec2,1]]; > Length[ones]/10.^6 > plotvec = > Map[Length, > Split[Sort[Drop[ones-RotateRight[ones,1],1]]]]; > ListPlot[ > Log[plotvec], PlotRange->All] > ListPlot[plotvec, PlotRange->All] > maybe other people can try it and see if it's just me? > (I took out the init.m btw) > sean >> *This message was transferred with a trial version >> of CommuniGate(tm) Pro* >> This is exactly what it is mean to do. The problem >> was due to the >> usage of the SWB algortithm by the built in Random[] >> for generating >> random reals. RandomReplace makes Mathematica use >> the Wolfran CA random >> number generator, which Mathematica uses for >> generating random integers >> instead of the SWB. This cures the problem >> reported int hat message. >> Have you got any reason to think it does not? >> Andrzej >*This message was transferred with a trial version >> of CommuniGate(tm) >Pro* >Hi andrej >thank you so much for making your package >> available. >I think I may have found another problem... (may >> have >found being operative phrase, or non-operative >> for >that matter) > hl=en&lr=&newwindow=1&safe=off&threadm=a5t1fq%245vt%241%40smc.vnet.net& >rnum=1&prev=/ > groups%3Fhl%3Den%26lr%3D%26newwindow%3D1%26safe%3Doff%26q%3Dchange%2Bth > is%2Bnumber%2Bto%2Bget%2Banother%2Brandom%2Bsequence%26meta%3Dgroup%253 >Dcomp.soft-sys.math.mathematica >shows a thread dealing with random reals and >> getting a >much smaller frequency at position 24 than others >positions. >Daniel posted a work around showing the use of >> Random >Integers to fix the problem, which as far I >understand, the Random replacement also >> implements. >It seems the RandomReplacement doesn't take care >> of >the appearance of the lower than expected >> frequency at >position 24(or interval 24 as the OP had noted). >I must be missing something. >sean >>*This message was transferred with a trial >> version >>of CommuniGate(tm) Pro* >>I think I have now fixed the problem reported by >>Mark Fisher. The new >>version of the RandomReplacement now works like >>this: >> >> >>SeedRandom[5] >> >> >>Timing[First[Table[Random[],{10000}]]] >> >> >>{0.01 Second,0.786599} >> >> >><> >>Timing[First[Table[Random[],{10000}]]] >> >> >>{0.02 Second,0.409222} >> >> >>As you can see there is a loss of speed involved. >>There may also be >>still some as yet undiscovered problems. However, >>the new package is >>available form my sites, though I still should >> write >>some documentation >>of the latest changes (a few bugs in the previous >>version have also >>been fixed). >> >>Andrzej Kozlowski >> >>Andrzej Kozlowski >>Chiba, Japan >>http://www.akikoz.net/~andrzej/ >>http://www.mimuw.edu.pl/~akoz/ >> >> >> >> >*This message was transferred with a trial >> version >>of CommuniGate(tm) >Pro* >It's clearly because of packed arrays: > > >< > >PackedArrayQ[Table[Random[],{249}]] > > >False > > >PackedArrayQ[Table[Random[],{250}]] > > >True > > > >Obviously Mathematica uses a different method of >>generating random >packed arrays. There are various ways of getting >>round this (e.g. >constructing lists as joins of lists of length >>less than 250 etc) but >one will loose the benefits of packed arrays and >>with that, presumably, >a lot of speed. This seems to be something that >>only WRI can change. >Note however that not all situations in which >> one >>uses Random[] require >generating this type of lists. >Moreover, for problems involving the normal >>distribution it seems to me >that using the Marsaglia generator gives good >>results even with the >built in Random[]. But certainly we should hope >>that something will >finally be done do deal with this issue in >> version >>6. > >Andrzej > > > > > >>He's right! How the devil does that happen? >> >>Here's a test, with Andrzej's package loaded in >>my Init file. >> >>First, with n=250: >> >>Quit >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Now, with n=249: >> >>Quit >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.656099 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.0708373 >> >>Bobby >> >>Fisher >> >FYI: I've just a little testing and I find >> that >>Mathematica ignors >the user >defined rules for Random in >> Table[Random[],{n}] >>when n >= 250. > >>The problem is not actually with the way >>Mathematica's >>NormalDistribution but with the uniformly >>distributed Random[] >>function. >>NormalDistribution itself is generated (in >> the >>package >>Statistics`NormalDistribution`) by means of >> the >>very classical so >>called Boox-Muller method (although actually >>the Marsaglia variant >>below works better). You can try downolading >> my >>little >>RandomReplacement package form one of my web >>sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ >>in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ >> in >>Poland >> >>The package is based on the post of daniel >>Lichtblau, which explains >>the nature of the problem: >> >> >> >>msg00088.html> >> >> >> >>The package is named init.m and can be loaded >>automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned >> with >>normal distributions >>it >>may be enough to the following. First load >> the >>(unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will >>replace the Box-Muller >>generator by the Marsaglia one. I have found >>that this is usually >>enough. But if your problem still remains try >>the RandomReplacement >>package. (Or you can use both of course). >> Here >>is the Marsaglia code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >> >Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> >> >> While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial >>version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in >>Mathematica's normal >distribution random number generator. The >>problem arises when I >look >at the distribution of averages of a list of >>theses numbers. That >is, >I generate 1000 numbers and take their >>average. I do this a number >of >times and the plot a frequency distribution. >>Consistently it seems >to >be skewed positive. Specifically, the >> number >>of occurrences less >than >3 standard deviations is consistent with the >>expected number, but >the >number greater than 3 is always larger (in >>some cases about twice >the >expected number). > >I was wondering if anyone else has noticed >>this and knows of a fix. >Also, does anyone have code for a good >> quality >>normal distribution >random number generator? > >Chris > >> >> > > > > >> >> >> >>-- >>DrBob@bigfoot.com >>www.eclecticdreams.net >> > > >> > >__________________________________ >Do you Yahoo!? >Yahoo! Mail Address AutoComplete - You start. We >> finish. >http://promotions.yahoo.com/new_mail > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com === Subject: Re: Re: normal distribution random number generation i just took a look at Part[plotvec, 24] the respective values, for me, are, 375 and 686. so i did a test with the following. in the fresh kernel, I get exactly the same thing as you have. but I decided to evaluate the code In[5]:= SeedRandom[1111111 ]; vec1=Table[Random[Real,{0,1000}],{10^6}]; vec2=Map[If[#<44,1,0]&,vec1]; ones=Flatten[Position[vec2,1]]; plotvec=Map[Length, Split[Sort[Drop[ones-RotateRight[ones,1],1]]]]; Part[plotvec, 24] ListPlot[Log[plotvec],PlotRange->All] ListPlot[plotvec,PlotRange->All] Out[10]= 375 and then reevaluate the codes In[13]:= SeedRandom[5] In[14]:= Timing[First[Table[Random[],{10000}]]] Out[14]= {0.01 Second,0.786599} In[15]:= < I think I have now fixed the problem reported by > Mark Fisher. The new > version of the RandomReplacement now works like > this: > SeedRandom[5] > Timing[First[Table[Random[],{10000}]]] > {0.01 Second,0.786599} > < Timing[First[Table[Random[],{10000}]]] > {0.02 Second,0.409222} > As you can see there is a loss of speed involved. > There may also be > still some as yet undiscovered problems. However, > the new package is > available form my sites, though I still should write > some documentation > of the latest changes (a few bugs in the previous > version have also > been fixed). > Andrzej Kozlowski > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ > *This message was transferred with a trial version > of CommuniGate(tm) > Pro* > It's clearly because of packed arrays: > < PackedArrayQ[Table[Random[],{249}]] > False > PackedArrayQ[Table[Random[],{250}]] > True > Obviously Mathematica uses a different method of > generating random > packed arrays. There are various ways of getting > round this (e.g. > constructing lists as joins of lists of length > less than 250 etc) but > one will loose the benefits of packed arrays and > with that, presumably, > a lot of speed. This seems to be something that > only WRI can change. > Note however that not all situations in which one > uses Random[] require > generating this type of lists. > Moreover, for problems involving the normal > distribution it seems to me > that using the Marsaglia generator gives good > results even with the > built in Random[]. But certainly we should hope > that something will > finally be done do deal with this issue in version > 6. > Andrzej >> He's right! How the devil does that happen? >> >> Here's a test, with Andrzej's package loaded in > my Init file. >> >> First, with n=250: >> >> Quit >> SeedRandom[5] >> Table[Random[],{250}]; >> Last@% >> >> 0.107874 >> >> Unprotect[Random]; >> Clear@Random >> SeedRandom[5] >> Table[Random[],{250}]; >> Last@% >> >> 0.107874 >> >> Now, with n=249: >> >> Quit >> SeedRandom[5] >> Table[Random[],{249}]; >> Last@% >> >> 0.656099 >> >> Unprotect[Random]; >> Clear@Random >> SeedRandom[5] >> Table[Random[],{249}]; >> Last@% >> >> 0.0708373 >> >> Bobby >Fisher >> >FYI: I've just a little testing and I find that > Mathematica ignors >the user >defined rules for Random in Table[Random[],{n}] > when n >= 250. > >>The problem is not actually with the way > Mathematica's >>NormalDistribution but with the uniformly > distributed Random[] >>function. >>NormalDistribution itself is generated (in the > package >>Statistics`NormalDistribution`) by means of the > very classical so >>called Boox-Muller method (although actually > the Marsaglia variant >>below works better). You can try downolading my > little >>RandomReplacement package form one of my web > sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ > in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ in > Poland >> >>The package is based on the post of daniel > Lichtblau, which explains >>the nature of the problem: >> >> >msg00088.html> >> >> >> >>The package is named init.m and can be loaded > automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned with > normal distributions >>it >>may be enough to the following. First load the > (unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will > replace the Box-Muller >>generator by the Marsaglia one. I have found > that this is usually >>enough. But if your problem still remains try > the RandomReplacement >>package. (Or you can use both of course). Here > is the Marsaglia code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >> Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> > While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial > version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in > Mathematica's normal >distribution random number generator. The > problem arises when I >look >at the distribution of averages of a list of > theses numbers. That >is, >I generate 1000 numbers and take their > average. I do this a number >of >times and the plot a frequency distribution. > Consistently it seems >to >be skewed positive. Specifically, the number > of occurrences less >than >3 standard deviations is consistent with the > expected number, but >the >number greater than 3 is always larger (in > some cases about twice >the >expected number). > >I was wondering if anyone else has noticed > this and knows of a fix. >Also, does anyone have code for a good quality > normal distribution >random number generator? > >Chris > >> >> > > > > >> >> >> >> -- >> DrBob@bigfoot.com >> www.eclecticdreams.net >> __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail === Subject: Save graphics In my previous post I forgot to say that I want to save plots in the running program, not manually. I am making so many plots that (apparently) memory fills up and the program stops by itself. Steve Gray === Subject: Re: Save graphics Steve Gray === Subject: Re: Save graphics make a graphics: gr = Plot[Sin[x], {x, 0, Pi}]; save it Put[gr, tmp.m] read it to gr1 gr1 = Get[tmp.m]; Show[gr1] Jens Steve Gray schrieb im Newsbeitrag > In my previous post I forgot to say that I want to save plots in the > running program, not > manually. I am making so many plots that (apparently) memory fills up and > the program stops by > itself. > Steve Gray === Subject: Mathematica Symbolic Toolbox for MATLAB--Version 2.0 This is an announcement that the Mathematica Symbolic Toolbox for MATLAB has been upgraded to Version 2.0. Maintenance for this toolbox has been transferred to Ben Barrowes. The toolbox can be downloaded from the mathsource: http://library.wolfram.com/infocenter/MathSource/ and MATLAB's file exchange: http://www.mathworks.com/matlabcentral/fileexchange/ This version was developed on an x86 Linux system, but is believed to be mex'able on other platforms. Reports of success would be appreciated. Here is the text of the email from Doug Stein transferring maintenance: Ben, I did in fact author the toolbox (back in 1994, I think). Since then, as we both know, MATLAB and Mathematica have gone through many versions! I'm not surprised that the need is still there and I'm glad you want to take over the maintenance. I haven't been an employee of Wolfram since spring 1994 and while I do remain fluent in Mathematica (and MATLAB from to devote any time to maintenance. I'd also like to introduce you to a former colleague of mine at Wolfram Research (Todd Gayley). He is responsible for leading the MathLink technology and its derivatives (e.g. J/Link, .NET/Link, etc.) and would feel free to contact me if you have any questions. Cordially, Doug Stein VP Development and Technology Learning.com dstein@learning.com Also, here is the text of the README included with this toolbox: ------------------------------------------------------------------------ Using the MathLink communication standard supplied with Mathematica and the MEX facility of MATLAB we write a toolbox that provides MATLAB users with all of the symbolic and high-precision numeric capabilities of Mathematica. In addition, since MathLink can pass native MATLAB matrices (and not just strings) between Mathematica and MATLAB it is quick and easy to construct matrices in either system and pass them to the other. You can freely mix Mathematica code and MATLAB code without the bother of writing M-files to convert matrices into strings and back. The Mathematica Symbolic Toolbox for MATLAB is implemented as a single MEX-file and we have included the source code. Two important points: 1) The Mathematica Symbolic Toolbox for MATLAB works with newer (MLVERSION in mathlink.h >= 3) versions of Mathematica (I have not tested the new version on the Macintosh). This version has been tested to work with Mathematica 4.2 and Matlab 7.0. Instuctions for mex'ing this file are given below. 2) Since MathLink connects programs on different computers just as easily as it connects programs on the same computer, you can harness the power of more than one computer. Simply run MATLAB on one computer, Mathematica on another; the Mathematica Symbolic Toolbox for MATLAB transparently connects the two. This capability is also especially helpful in schools and industrial sites where MATLAB and Mathematica might be licensed for different machines. Functions provided in the Mathematica Symbolic Toolbox for MATLAB ----------------------------------------------------------------- math('string') : 'string' is sent to Mathematica and evaluated; the : result is returned as a string. : : : Mathematica will automatically be started if you : make an alias of the Mathematica Kernel icon, call : the alias MathKernel, and place the alias in the : same folder as MATLAB itself. If you don't make the : alias, the MathLink library will pose a dialog box : and ask you to find a Mathematica Kernel. math('matlab2math', 'mname', mat) : The MATLAB matrix mat is assigned : to the Mathematica symbol denoted : by the string 'mname'. The result : returned to MATLAB is 'mname'. math('math2matlab', 'expr') : The matrix resulting from the evaluation : of 'expr' by Mathematica is returned. If : 'expr' doesn't yield a matrix, this function : returns a MATLAB string containing '$Failed' math('quit') or math('exit') : These close the link and shut down Mathematica. All of the above automatically open a MathLink connection with default arguments if one hasn't already been opened. If the user wishes to open the connection with particular arguments, the full form of the linkopen command is: math('linkopen', 'linkname', 'linkmode', 'linkprotocol', 'swapEOL') : The first argument must be the string 'linkopen'. : The second argument must be the name of the link : defined as usual for Mathematica's LinkOpen or the MathLink : library's MLOpen(). Again, for simplicity, math('linkopen') uses : the default arguments. LinkOpen and MLOpen() are described : in the MathLink Reference Guide that ships with Mathematica. : The third argument is either 'Launch', 'Connect', or 'Listen'. : The fourth argument is either 'PPC' or 'TCP' on Macintosh, : 'Local' or 'TCP' on Windows, and 'Pipes' or 'TCP' on Unix. : If the fifth argument is 'swapEOL' then carriage-return and : linefeed will be swapped; this is useful when connecting : MATLAB and Mathematica processes residing on computers with : different notions of end-of-line (for example, MATLAB on a Mac : with Mathematica on a Sun SPARC). If the fifth argument is : anything else, line termination will be unchanged. In addition to the behavior above, any Mathematica warning or error messages as well as the output from Mathematica's Print[] function will appear in the MATLAB command window. Here's an example of a session with MATLAB and Mathematica. -----------------MATLAB Transcript Begins-------------- >> math('$Version') Mathematica Kernel loading... ans = 4.2 for Linux (August 23, 2002) >> math('N[EulerGamma,40]') ans = 0.5772156649015328606065120900824024310422 >> math('Integrate[Log[x]^(3/2),x]') ans = 3 Sqrt[Pi] Erfi[Sqrt[Log[x]]] -3 x ----------------------------- + Sqrt[Log[x]] (---- + x Log[x]) 4 2 >> math('InputForm[Integrate[Log[x]^(3/2),x]]') ans = (3*Sqrt[Pi]*Erfi[Sqrt[Log[x]]])/4 + Sqrt[Log[x]]*((-3*x)/2 + x*Log[x]) >> math(['Integrate[',ans,',x]']) ans = 3 Sqrt[Pi] x Erfi[Sqrt[Log[x]]] ------------------------------- - 4 Pi 3 Sqrt[--] Erfi[Sqrt[2] Sqrt[Log[x]]] 2 > ------------------------------------- + 16 2 2 -9 x x Log[x] > Sqrt[Log[x]] (----- + ---------) 8 2 >> math('matlab2math', 'hilbert',hilb(20)) ans = hilbert >> math('{Dimensions[hilbert],Det[hilbert]}') ans = -196 {{20, 20}, 5.76706 10 } >> math('exactHilbert = Table[1/(i+j-1),{i,20},{j,20}];') ans = Null >> math('Det[exactHilbert]') ans = 1 / 23774547167685345090916442434276164401754198377534864930331853312 > 3441975931064458518758576681657377344056575986726555897176563841 > 9710793303386582324149811241023554489166154717809635257797836800 > 000000000000000000000000000000000 >> math('N[Det[exactHilbert], 40]') ans = -226 4.206178956624722655882045573396941339798 10 >> math('invHilbert = Inverse[hilbert];') Inverse::luc: Warning: Result for Inverse of badly conditioned matrix {<<20>> } may contain significant numerical errors. ans = Null >> math('math2matlab', 'invHilbert') ans = Columns 1 through 3 113.178979337215 -5919.74491450191 88499.6060995985 -5629.19259643555 325661.692155659 -3310610.4742403 65006.8583984375 -1379341.32904625 -103113004.666097 118827.09765625 -79580628.7093658 3960703542.87468 -6565667.125 1190624660.87695 -45191708684.4323 46772334 -7091389994.79395 243317770201.644 -145560961 20192244670.1055 -637766577741.674 169011227 -20094863396.0078 483223248366.23 157581726.375 -30107722916.5508 1395746315716.95 -546314566 84022049827.8926 -3190940224029.26 80248995 -11721686137.6553 450511619653.419 833248230 -122474248390.773 4379013519678.3 -674342533 104770453206.729 -4031562266231.86 500368351.25 -89613291085.4766 3920435126867.95 -1801550550 275002011616.359 -10261097652172.7 1527154928 -217344388348.539 7466476394136.89 1967461622 -297514562257.922 10968437168811 -4087459016 598118479308.156 -21248040416754.2 2536304908 -367436527858.172 12900351189283.5 -556537420 80183462241.6113 -2796768045312.38 Columns 4 through 6 -510445.978184683 1625336.99449522 -13839361.0719537 -9658895.9244982 154136706.044553 1179106970.13898 2489819979.39821 -15829389980.4342 -22534638103.2292 -61985228341.3854 352708793931.11 208838077525.952 626372659122.163 -3303972916153.63 -2361562991155.11 -3117508119218.49 14577360685521.7 27656719467887.7 7263188344560.42 -22452456771233.5 -196769542511847 -1882343817286.72 -55027672976967.9 799011448910185 -27691532280774.3 293318008894301 -1.84730158415938e+15 51889758217630.2 -443863883411908 2.17875625601591e+15 -7896861578382.06 76597384647696.5 -436258295972536 -65586615447360.4 499265995940208 -2.05686232422449e+15 66931544708134.1 -593960900048081 3.13308913938148e+15 -73524919098267.8 735312012156663 -4.3614722023589e+15 161767546721285 -1.31433910593269e+15 5.90584653456277e+15 -105483962086627 721680799531158 -2.25711546888483e+15 -170230255738406 1.35368201226982e+15 -5.88829318181532e+15 314698551295346 -2.33671275736643e+15 8.95426658136452e+15 -188140325001210 1.36415981861825e+15 -4.97813317427672e+15 40436869193657.2 -289269694936324 1.02575324251412e+15 Columns 7 through 9 128463960.845981 -601044166.649502 1429838357.0824 -19128247290.709 94462427341.4881 -224406297982.711 720199029095.715 -3661148980429.49 8648986818221.74 -11955479624388.5 60917045341235.7 -142305837330720 108543400858323 -537572089649284 1.23174088330313e+15 -599432326737334 2.77719960420449e+15 -6.15954631982161e+15 2.12400714758352e+15 -8.74075476518521e+15 1.83057787280303e+16 -4.91321335401271e+15 1.66251137580989e+16 -3.1049432231791e+16 7.26270179623264e+15 -1.77797337843886e+16 2.4451092374039e+16 -6.17851681929922e+15 8.74126540763949e+15 730681432392497 1.36751936984959e+15 -1.17653480550358e+15 -8.11354131313642e+15 4.38070034687638e+15 -3.77446405631302e+15 3.24465172631833e+15 -1.04209857079999e+16 2.28651032241006e+16 -3.59245590361003e+16 1.61341389380097e+16 -3.75709087333385e+16 5.30886713313908e+16 -1.40749937684324e+16 1.14322562731591e+16 2.13683192447793e+16 238183180090668 2.1111586005894e+16 -6.64449524106293e+16 1.32081802571475e+16 -8.31943633136647e+15 -2.38039088159902e+16 -1.36906588054635e+16 -1.86581479894883e+16 1.06576273114568e+17 6.15301300424444e+15 1.73828465470931e+16 -7.45576848238949e+16 -1.08793241125756e+15 -4.4351683548491e+15 1.71902970120607e+16 Columns 10 through 12 -1433092579.96435 -661797089.535329 2934344030.9709 221454748157.325 107797999574.982 -459259272483.272 -8404437399828.31 -4295430604576.11 17669950431082.8 135914908153839 73077539261115.5 -290584835202507 -1.15093263821656e+15 -657559222051283 2.51890192345663e+15 5.57298124524197e+15 3.47155302832127e+15 -1.26678561078404e+16 -1.56350424279102e+16 -1.13410269963666e+16 3.82834657298677e+16 2.30132413690387e+16 2.3761995414146e+16 -6.85599721886391e+16 -7.83635329774751e+15 -3.48126031051241e+16 6.89123335940669e+16 -2.55178056593037e+16 4.7041638070212e+16 -4.68141026355175e+16 3.68666814103448e+16 -7.34103689965472e+16 7.34844032586819e+16 -2.97460533862245e+16 9.48302586560573e+16 -1.24259060820449e+17 4.8898705429703e+16 -6.77693799706299e+16 8.16174916900524e+16 -4.1086351632482e+16 1.91239346335733e+16 -3.27421696167911e+16 -4.85258771625178e+16 -1.10443996059956e+16 1.12428901554771e+17 7.8934684133657e+16 6.1139213054271e+15 -9.90785867183554e+16 3.74089092063926e+16 4.39989770064524e+16 -1.4710926958948e+17 -1.27012120837591e+17 -7.53618734019761e+16 2.98650647805885e+17 8.47650219942711e+16 4.6161751111216e+16 -1.84897165303488e+17 -1.90774193124695e+16 -1.01757078288663e+16 4.05054108939442e+16 Columns 13 through 15 -2446423712.23972 1865172235.03629 -4662791179.38423 383898150102.123 -296945159399.429 722520215463.328 -14849500279794.7 11633931246808 -27450047604165.1 246318773641883 -195130939326616 443586541791183 -2.16281687789633e+15 1.72807706095922e+15 -3.743895936715e+15 1.10797429167903e+16 -8.88275139656445e+15 1.79899796320497e+16 -3.43508417547259e+16 2.727271573706e+16 -4.96525696025277e+16 6.34191690372566e+16 -4.78145207757838e+16 7.04002023047312e+16 -6.33664382381491e+16 3.69311889061952e+16 -2.06979713970156e+16 2.72184774288887e+16 1.17452222595548e+16 -5.99655987685971e+16 -1.92657727484354e+16 -2.72199659872601e+16 8.93280128386663e+15 6.07511811235594e+16 -2.9344466445376e+16 1.30407738989029e+17 -7.21783088243212e+16 6.64099680322212e+16 -9.08546431463167e+16 6.28849035674626e+16 -4.00789665685201e+16 -1.77020620269233e+16 -9.93635441334253e+16 3.34478869224447e+16 -1.12656435360884e+17 6.21374409941305e+16 -2.86056329229755e+16 1.82301423013235e+17 1.14544740784714e+17 -4.85749131605373e+16 1.27395404094863e+17 -2.12572779157258e+17 1.0853124878165e+17 -3.79252855436206e+17 1.29108219274511e+17 -7.19148791095348e+16 2.54604320218465e+17 -2.81152257017536e+16 1.65535819944235e+16 -5.79226957175225e+16 Columns 16 through 18 6010764228.37905 -1752433341.0017 -2483833528.68668 -918433335055.881 262715788389.949 380607729139.388 34388014740620.7 -9645612276272 -14291854739214.4 -546796936786676 150091955166348 228056752126632 4.52698023761335e+15 -1.21079355314895e+15 -1.89774606064267e+15 -2.12105133647067e+16 5.47808266608817e+15 8.96721778243928e+15 5.63450659354091e+16 -1.37529710883796e+16 -2.42201880178417e+16 -7.39341305381217e+16 1.57927824556192e+16 3.3217847929549e+16 1.07541166738604e+16 2.20651795808375e+15 -8.48693306129385e+15 6.62250695751404e+16 -1.51363632169552e+16 -2.71121550747623e+16 2.89282935888942e+16 -2.44211627004609e+16 -772089829157155 -1.8808272895544e+17 6.84602247828256e+16 5.83867643987357e+16 9.0428541201657e+16 -2.82145286639271e+16 -2.64787776673404e+16 2.89012222373552e+16 2.67537543949077e+15 -1.72731584619987e+16 2.13033838663796e+17 -1.12607908075586e+17 -4.50849362143225e+16 -3.10672585960735e+17 1.77537758521734e+17 1.84834696167326e+16 -1.55278840876447e+17 -4.1792814378581e+16 1.98738415416993e+17 5.21004049186954e+17 -9.7057669178095e+16 -3.06781915060056e+17 -3.4935062130957e+17 8.15343716795949e+16 1.77923392942204e+17 7.88955692681663e+16 -1.96316109147183e+16 -3.78233534425734e+16 Columns 19 through 20 2232569196.11812 -547094668.842378 -339530344027.39 82925009059.4386 12652542703558.7 -3079614638026.62 -200256676099775 48563748889473.9 1.65083453286884e+15 -398678512680276 -7.70793561936204e+15 1.85192551569666e+15 2.04527032242424e+16 -4.87776556492204e+15 -2.70605754407013e+16 6.35892780164074e+15 5.0459094190706e+15 -1.00351846398172e+15 2.26425730663842e+16 -5.40406006382957e+15 7.42919517083055e+15 -2.26233899190568e+15 -5.8055446316467e+16 1.44196263198346e+16 2.52497196324359e+16 -6.23047888321419e+15 8.66447599589122e+15 -1.3232510045469e+15 6.45762181080283e+16 -1.76726149387426e+16 -5.66707840051854e+16 1.62477441275126e+16 -1.3688660905156e+17 3.11653357291696e+16 2.47524149697134e+17 -5.88099500057462e+16 -1.48686172057182e+17 3.55631656797113e+16 3.20196864941092e+16 -7.66963557697005e+15 >> math('quit') Mathematica Kernel quitting per your request... -----------------MATLAB Transcript Ends-------------- Where to get the Mathematica Symbolic Toolbox for MATLAB -------------------------------------------------------- (1) http://library.wolfram.com/infocenter/MathSource/ What's included in this archive ------------------------------- README - this file math.c - source code suitable for MATLAB 7.0 MEX facility math.mexglx - precompiled binary of math.c for x86 Linux. testscript.m - MATLAB test script which runs the examples above math.tar.gz - tar'ed, gzip'ed file containing the files above How to build the Mathematica Symbolic Toolbox for MATLAB -------------------------------------------------------- First of all, you need access to a licensed copy of Mathematica. The standard Mathematica distribution includes the MathLink header and library files. NOTE 1: You need the MathLink header and library files for the machine on which you are running MATLAB (since you are building a MEX-file to work with that version of MATLAB). If you don't have the appropriate MathLink files, send email to support@wri.com with your Mathematica license number and the machine for which you want them. NOTE: As of version 1.2, math.c properly compiles with non-ANSI compilers, particularly the default Sun C compiler. My apologies for previously forgetting users stuck with such old-style C compilers. Version 2.0 has not been tested with non-ANSI compilers. Macintosh: ----------- 1) Unknown. If you succeed in building this on a Mac, send me the directions. *NIX: ----------- 0) Make a directory to hold the toolbox. In this directory, untar the file: tar zxvf math.tar.gz You might want to put this directory on MATLAB's path using addpath in your startup.m 1) Find out where libML.a and mathlink.h are installed on your system. 2) Properly install the MEX tools for MATLAB. The default settings in mexopts.sh should be sufficient. then type: mex -Iinclude_path -Llibrary_path -lML math.c (where include_path is the path to mathlink.h and library_path is the path to libML.a) Windows: -------- 1) Again, unknown, but assumed to be usable. Mail me if you find a working combination. Questions ? ----------- 1) If you have suggestions about how to make this free Mathematica Symbolic Toolbox for MATLAB better, send email to: barrowes@alum.mit.edu HTH, ---- Benjamin E. Barrowes ---- === Subject: Re: Mathematica Symbolic Toolbox for MATLAB--Version 2.0 Where exactly? The both links are not directed to the Mathematica Symbolic Toolbox for MATLAB. Michal Kvasnicka Ben Barrowes p.92Õe v diskusn.92m p¿.92sp.93vku > This is an announcement that the > Mathematica Symbolic Toolbox for MATLAB > has been upgraded to Version 2.0. Maintenance for this toolbox has been > transferred to Ben Barrowes. The toolbox can be downloaded from the > mathsource: > http://library.wolfram.com/infocenter/MathSource/ > and MATLAB's file exchange: > http://www.mathworks.com/matlabcentral/fileexchange/ > This version was developed on an x86 Linux system, but is believed to be > mex'able on other platforms. Reports of success would be appreciated. > Here is the text of the email from Doug Stein transferring maintenance: > Ben, === Subject: Re: Mathematica Symbolic Toolbox for MATLAB--Version 2.0 ditto for me. though... what i could use is an utility for sending data to MATLAB from mathematica front end. like defined some nonlinear PDE in Mathematica then send the equations and parameters and loop constructs to MATLAB. i dunno if that's possible. sean > Where exactly? The both links are not directed to the Mathematica Symbolic > Toolbox for MATLAB. > Michal Kvasnicka > Ben Barrowes p.92Õe v diskusn.92m p¿.92sp.93vku > This is an announcement that the > Mathematica Symbolic Toolbox for MATLAB > has been upgraded to Version 2.0. Maintenance for this toolbox has been > transferred to Ben Barrowes. The toolbox can be downloaded from the > mathsource: > http://library.wolfram.com/infocenter/MathSource/ > and MATLAB's file exchange: > http://www.mathworks.com/matlabcentral/fileexchange/ > This version was developed on an x86 Linux system, but is believed to be > mex'able on other platforms. Reports of success would be appreciated. > Here is the text of the email from Doug Stein transferring maintenance: > Ben, === Subject: Re: Mathematica Symbolic Toolbox for MATLAB--Version 2.0 Hi Michal, The links I provided are only portals, I will provide specific links to the exact page when they are posted (within a couple of days hopefully). I posted a bit prematurely as these sites are taking some time to actually post the code. Ben > Where exactly? The both links are not directed to the Mathematica Symbolic > Toolbox for MATLAB. > Michal Kvasnicka > Ben Barrowes p.8f.bc»e v diskusn.95À¸ p.95À¸sp.95À¸ku >>This is an announcement that the >>Mathematica Symbolic Toolbox for MATLAB >>has been upgraded to Version 2.0. Maintenance for this toolbox has been >>transferred to Ben Barrowes. The toolbox can be downloaded from the >>mathsource: >>http://library.wolfram.com/infocenter/MathSource/ >>and MATLAB's file exchange: >>http://www.mathworks.com/matlabcentral/fileexchange/ >>This version was developed on an x86 Linux system, but is believed to be >>mex'able on other platforms. Reports of success would be appreciated. >>Here is the text of the email from Doug Stein transferring maintenance: >>Ben, === Subject: GUIKit / GraphEditor - java code for SetPropertyValue[] hello all. in the Graph Editor example, the Mathematica code calls the SetPropertyValue[] function, that changes the value of the graph. can someone tell me where is the java code that is applied when we call that function? I really need to do that change to the code, so if someone can help me, I will be very thankful. Wishmaster7 === Subject: Cylindrical coordinates problem I'm having a hard time understanding how Cylindrical Coordinates work in Mathematica. I have several questions: 1. What is the expression for unit vectors in Cylindrical Coordinates in Mathematica? For example is this correct: r_unit = {1,0,0}, phi_unit = {0,1,0}, and z_unit = {0,0,1}??? 2. How do you perform vector cross product of these unit vectors in Cylindrical coordinates in Mathematica? for example: CrossProduct [ {1, 0, 0}, {0, 1, 0}] gives = {0, 0, 0} which is not the correct answer, then how am I supposed to be doing it? Can anyone please help? === Subject: FilledPlot Sideways? How can I make FilledPlots sideways? So I want the equivalent of FilledPlot [x^2, {x,-2,2}], but with the axes transposed. The curve is something like ParametricPlot[{x^2, x}, {x,-2,2}]. How to do the shading? Tom Aldenberg === Subject: Re: FilledPlot Sideways? Needs[Graphics`FilledPlot`] gg = FilledPlot [x^2, {x, -2, 2}]; Show[gg /. (h : Line | Polygon)[pnts_] :> h[Reverse /@ pnts]] Jens Tom Aldenberg schrieb im Newsbeitrag > How can I make FilledPlots sideways? > So I want the equivalent of FilledPlot [x^2, {x,-2,2}], but with the axes > transposed. > The curve is something like ParametricPlot[{x^2, x}, {x,-2,2}]. How to do > the shading? > Tom Aldenberg === Subject: NMinimize inconsistencies I'm not sure what NMinimize is doing wrong, but it hardly matters. The point is to solve the problem, I hope, since it's already known that NMinimize isn't very dependable. In the first place, p and m need not be separate variables, since they appear only as the product p m in the problem. Secondly, intuition suggests the objective will be minimized when b-a is maximum, namely at b=1, a=0. That's simply because the range of values Log's argument takes on apparently isn't constrained by the values of a and b. With these ideas in mind, take the argument of Log and minimize it (since Log is monotone): exp = (c + pm - b*pm)/(c + pm - a*pm); NMinimize[{exp, 105 <= c <= 315 && 0 <= pm <= 5*4000 && 0 <= a <= b <= 1}, {{c, 105, 315}, {pm, 0, 5*4000}, {a, 0, 1}, {b, 0, 1}}] {0.005222581447401144, {a -> 2.7767903863779616*^-27, b -> 1., c -> 105., pm -> 20000.}} As expected, exp is minimized when b-a is maximum. (It would have been sufficient to show that exp CAN be minimized with b-a at its maximum.) It follows that the same is true for exp/(b-a), so we have an optimal solution. We can go one step farther as follows: objective = Log[exp]/(b - a) /. {a -> 0, b -> 1} Log[c/(c + pm)] NMinimize[{objective, 105 <= c <= 315 && 0 <= pm <= 5*4000}, {{c, 105 - delta, 315 + delta}, {pm, 0, 5*4000}}] {-5.254763469173851, {c -> 105., pm -> 20000.}} Bobby === Subject: NMinimize inconsistencies I'm puzzled by some inconsistencies of NMinimize. Namely, NMinimize[{ Log[( C + P*m - b*P*m)/( C + P*m - a*P*m)]/(a - b), 105 < C < 315&&2000 < P < 4000&&0 < a < 1 &&0 < b < 1 &&a < b &&0 < m < 5}, {{C, 105, 315}, {P, 2000,4000}, {a, 0, 1}, {b, 0, 1}, {m, 0, 5}}, Method -> NelderMead] converges to 0 on a computer running Mathematica 5.0.0. and complains about 1/0 infinities on a computer running Mathematica 5.0.1. In Mathematica 5.0.1., changing ab still leads to 1/0 infinities (why?) but then changing a>b to a!=b converges to a solution that is, amazingly, a>b. Why does NMinimize keep running into 1/0 infinities if I demand that a>b but not if a!=b? Are there any differences in the NMinimize implementation in Mathematica 5.0.0. and Mathematica 5.0.1.? Any help would be appreciated. Skirmantas === Subject: Starting Mathematica 5 - List of RHS illegal values I'm trying to start Mathematica 5 on Linux Mandrake 10.0, but as in the Mandrake 9.1 I recive a first Startup Warning about a possible internal error Assertion'VerticalLineBOxMEtaclassDEfaults.ch!=((void*)0)'failed at spanbox.c:2981 and then lots of other errors about illegal right hand sides values of a lot of options like background, fontcolor, magnification ... following you'll find the full list ... after this ton of error Mathematica starts, with a wrong keybord mapping, and wrong characters display (I see don't see [ ] or {} but strange rectangles) Plots look fine ... In mathkernel all seem to be ok, except confort! I need a GUI. I tried adding LANG=C export LANG after # Make certain that ${PATH} includes /usr/bin and /bin PATH=/usr/bin:/bin:${PATH} in my /usr/local/bin/mathematica and /usr/local/bin/Mathematica scripts but I always have the same errors. what can I do to fix it? > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextAlignment. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextAlignment. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextJustification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextJustification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextJustification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextJustification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextJustification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option CellFrame. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option CellFrame. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Magnification. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option LinebreakAdjustments. > Error occurred in the cell starting on line: 53. > Front End Message (10:26:18 on 10/14/04) > An illegal right-hand side value was specified for the cell style option GridBoxOptions, RowSpacings. > Error occurred in the cell starting on line: 1845. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Error occurred in the cell starting on line: 1902. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Error occurred in the cell starting on line: 1990. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option GridBoxOptions, RowSpacings. > Error occurred in the cell starting on line: 3908. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Error occurred in the cell starting on line: 3965. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Error occurred in the cell starting on line: 4051. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option GridBoxOptions, RowSpacings. > Error occurred in the cell starting on line: 5969. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Error occurred in the cell starting on line: 6026. > Front End Message (10:26:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option Background. > Error occurred in the cell starting on line: 6112. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option LineSpacing. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option AdjustmentBoxOptions, BoxBaselineShift. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option AdjustmentBoxOptions, BoxMargins. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option AdjustmentBoxOptions, BoxMargins. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option AdjustmentBoxOptions, BoxMargins. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option AdjustmentBoxOptions, BoxMargins. > Front End Message (10:26:28 on 10/14/04) > An illegal right-hand side value was specified for the cell style option AdjustmentBoxOptions, BoxMargins. > Front End Message (10:26:29 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:29 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:26:51 on 10/14/04) > An illegal right-hand side value was specified for the cell style option FontColor. > Front End Message (10:27:51 on 10/14/04) > An illegal right-hand side value was specified for the cell style option LineSpacing. > Front End Message (10:33:19 on 10/14/04) > An illegal right-hand side value was specified for the cell style option ButtonBoxOptions, Background. > Front End Message (10:35:25 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextAlignment. > Front End Message (10:36:10 on 10/14/04) > An illegal right-hand side value was specified for the cell style option TextJustification. === Subject: Re: Jeremy, You can use the Tick, or FrameTicks with a Frame, option. One method is just to make a simple table of the tick locations and values. Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, FrameTicks -> {Table[{v, v}, {v, -Pi, Pi, Pi/2}], Automatic, Table[{v, }, {v, -Pi, Pi, Pi/2}], Automatic}, Axes -> False, ImageSize -> 450]; A second method is to use the PiScale routine from the standard package Graphics`Graphics`. (There is also a LogScale and LinearScale. Use ?*Scale for information.) Needs[Graphics`Graphics`] Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, FrameTicks -> {PiScale, Automatic, None, Automatic}, Axes -> False, ImageSize -> 450]; This, however, has the slight disadvantage of not providing matching but unlabeled ticks on the top of the frame. If you use PiScale where None is you get the values again and if you use Automatic you get unmatching tick marks. One could revert to the Table. It would be much better if Graphics`Graphics` had an option in PiScale for displaying or not displaying the values. If you are using Axes instead of a Frame this is not a problem. But labeled Axes are not great if they run through the middle of a plot. If you use the DrawGraphics package from my web site below, there is a CustomTicks function that allows more flexibility including using a function to transform the plot coordinate values to tick values and an option to control the number formatting - here used to suppress the labels on the top of the frame. I was able to specify large labeled and small unlabeled ticks on the bottom of the frame and large and small unlabeled ticks on the top of the frame. PiScale doesn't allow that and it's a lot more work to specified large and small ticks with a Table specification. Needs[DrawGraphics`DrawingMaster`] Draw2D[ {Draw[Sin[x], {x, -Pi, Pi}]}, Frame -> True, FrameTicks -> {CustomTicks[Identity, {-Pi, Pi, Pi/2, 2}], Automatic, CustomTicks[Identity, {-Pi, Pi, Pi/2, 2}, CTNumberFunction -> ( &)], Automatic}, ImageSize -> 450 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I would like to plot the simple function of Sin[x] but have the x axis labels be -Pi, -Pi/2, 0, Pi/2, Pi instead of integer values 1, 2, 3, etc. Is this possible? Jeremy Foster === Subject: how to display colors for group of samples while plotting a given signal sir, i am facing problem on displaying colors for separate group of samples for a given signal.HINT the signal length is 3000.in that sample for 100 sample each i want to display one color and for another sample of 200 each i want to display another color.if anyone guide to solve this problem .pls reply .urgent. kumar === Subject: Re: how to display colors for group of samples while plotting a given signal Kumar: pl = ListPlot[Table[Sin[x/123], {x, 3000}]]; (*You can assume pl is your already generated (black & white) plot.*) plcol = pl /. p:Point[{x_, _}] :> Sequence[p, If[Mod[x, 300, 1] < 100, RGBColor[1, 0, 0], RGBColor[0, 0, 1]]]; Show[plcol]; Have success, Peter -- Peter Pein, Berlin to write to me, start the subject with [ kumar schrieb im Newsbeitrag > sir, > i am facing problem on displaying colors for separate group of > samples for a given signal.HINT the signal length is 3000.in that > sample for 100 sample each i want to display one color and for another > sample of 200 each i want to display another color.if anyone guide to > solve this problem .pls reply .urgent. > kumar === Subject: Re: FilledPlot Sideways? Needs[Graphics`]; FilledPlot[{-Sqrt[x],Sqrt[x]},{x,0,4}]; FilledPlot[{-2,-Sqrt[ x],Sqrt[x],2},{x,0,4},Fills->{Turquoise,White, Turquoise}]; Bob Hanlon === > Subject: FilledPlot Sideways? > How can I make FilledPlots sideways? > So I want the equivalent of FilledPlot [x^2, {x,-2,2}], but with the axes > transposed. > The curve is something like ParametricPlot[{x^2, x}, {x,-2,2}]. How to do > the shading? > Tom Aldenberg === Subject: Re: Part of a matrix or array Gregory, Take seems pretty good. mat = Array[f, {14, 14}]; Take[mat, {3, 7}, {11, 14}] // MatrixForm The following might be more intuitive, but Range is a function. mat[[Range[3, 7], Range[11, 14]]] // MatrixForm The MatrixManipulation package isn't any simpler. Needs[LinearAlgebra`MatrixManipulation`] TakeMatrix[mat, {3, 11}, {7, 14}] // MatrixForm David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hello everyone, Mathematica has so many functions for accessing parts of arrays that I'm not sure which one I should be using to get a submatrix, for example, rows 3 to 7 and columns 11 to 14 of matrix X. Should I use Take? Take[X,{3,7},{11,14}] Is there a more compact way where I don't have to explicit refer to a function? Greg === Subject: Re: Showing Complete Solution. I don't think it's possible to see the intermediate steps for these functions (Integrate and Limit) in Mathematica. It's all programmed in C and the methods used would probably not be informative to general users. (They might be informative to a real expert who had some problem in a specific case.) The methods are generally not the ones taught in undergraduate calculus books. If you are using Mathematica to teach or learn basic calculus, then it is possible to bypass these routines, use intermediate derivation steps and perhaps apply the routines only when you get to simple basic forms. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi all... I need to watch the entire solution of integrates and other functions like limits. Just the answer is not all. I need the path too. I am using Mathematica 5. Someone could help??? === Subject: Re: Need to calculate Nyquist frequency from data > How i will calculates Nyquest frequency from a time series, details of > time series are, it having 122 data values, daily one data id there, so > total 122 days data,how i can calculates cutt of frequencies,,,etc The Nyquist frequency is 1/2 the reciprocal of the sample rate, so your data has a Nyquist frequency of 1/(2 days) or converting days to seconds 1/(172,800 seconds) or roughly 5.8 10^-6 Hz. Ssezi === Subject: Need to calculate Nyquist frequency from data How i will calculates Nyquest frequency from a time series, details of time series are, it having 122 data values, daily one data id there, so total 122 days data,how i can calculates cutt of frequencies,,,etc === Subject: Re: Need Help: 1st order nonlinear differential equation Sorry, after I solved the problems with the format of the posting I became aware that there is a typo in the restriction. This should read: 1 >= a >= 0 && n > 2 && Z >= 0 && 1 > [Delta] > 0 && 1 > [Rho] > 0 && 0 < r < n/(-2 + n) Please ignore the term 1 > r > 0 in the previous posting. It creates inconsistencies. Moreover, please consider Z>=0 instead of Z>0. It was very early in the morning when I prepared the original message to get help. Please excuse the shortcomings in the posting, there is no other typo left. >I became aware that the essential lines in my previous posting are >unreadable. So let me correct for this. My problem is: >I need to solve the following 1st order nonlinear differential >equation. I am really stuck. DSolve refuses to give an answer and I >need the algebraic solution for a[Z]. >Derivative[1][a][Z] == (a[Z]*((-1 + n)*r* (n - Z*(2*[Delta] + >[Rho])) + n*(1 + r - n*r)*a[Z]))/ ((-1 + n)*(n*(-1 + r) - >2*r)*r*Z*(-n + Z*[Delta] + n*a[Z])) >where >1 >= a >= 0 && n > 2 && Z > 0 && 1 > [Delta] > 0 && 1 > [Rho] > 0 && >1 > r > 0 && 0 < r < n/(-2 + n) >Does anybody know how to solve this problem? >Has anybody tips how to impose domain restrictions while solving >differential equations in >Mathematica (version 5.0.1.0.)? >Respectfully; >Wolfgang === Subject: Re: Need Help: 1st order nonlinear differential equation I became aware that the essential lines in my previous posting are unreadable. So let me correct for this. My problem is: I need to solve the following 1st order nonlinear differential equation. I am really stuck. DSolve refuses to give an answer and I need the algebraic solution for a[Z]. Derivative[1][a][Z] == (a[Z]*((-1 + n)*r* (n - Z*(2*[Delta] + [Rho])) + n*(1 + r - n*r)*a[Z]))/ ((-1 + n)*(n*(-1 + r) - 2*r)*r*Z*(-n + Z*[Delta] + n*a[Z])) where 1 >= a >= 0 && n > 2 && Z > 0 && 1 > [Delta] > 0 && 1 > [Rho] > 0 && 1 > r > 0 && 0 < r < n/(-2 + n) Does anybody know how to solve this problem? Has anybody tips how to impose domain restrictions while solving differential equations in Mathematica (version 5.0.1.0.)? Respectfully; Wolfgang === Subject: Re: Solving an equation Scott, Try FindRoot. As an example... FindRoot[Gamma[z] == 2 + 3*I, {z, 1}] {z -> -1.1423913504357908 + 0.2086374207214744*I} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I have an equation, Gamma[a+I b] = some complex number. I need to solve this equation for a and b. I can write a+I b as z, but it can't be solved through NSolve. What I have been doing is a double do loop for a and b and getting some number. Then I compare this to the number I have. Then I narrow down my possibilities for a and b, and go through the process again. Does anyone know of a better way to do this problem? Is there a way to have Mathematica compare each result of the do loop to a given value, and given certain conditions spit out an answer for a and b? Hope that makes sense. === Subject: Re: Calculus : limits The documentation is there in the front end (at least in Mathematica 5.0.1), just not in The Mathematica Book: Options[Limit] {Analytic -> False, Assumptions :> $Assumptions, Direction -> Automatic} ?Direction Direction is an option for Limit. Limit[expr, x -> x0, Direction -> 1] computes the limit as x approaches x0 from smaller values. Limit[expr, x -> x0, Direction -> -1] computes the limit as x approaches x0 from larger values. Direction -> Automatic uses Direction -> -1 except for limits at Infinity, where it is equivalent to Direction -> 1. >>I'd like to find the limit of >>Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] >>I use Mathematica v.5. I get the wrong (??) answer : 1 >>While I try to display the graph of this function by using Plot, it >>seems that there is no limit at the point x=0. >>Please help... >>Amir > Mathematica's answer is correct but ... Limit always computes > directional limits. Thus: > Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> -1] > but > Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> 1] > -1 > So the limits as x goes to 0 form above and form below are different > and thus there is n limit'. > Also, as you see by default Limit computes from above. However, I > still can't find this clearly documented in version 5, even though I > remeber myself (and others) complaining about this lack of > documentation in version 4 (if not earlier). > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ -- 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: Calculus : limits That's the right answer, and a Plot confirms it at my machine. f[x_] = (Sin[x] - Sin[2*x])/x; Limit[f[x], x -> 0] -1 Limit[Abs[f[x]], x -> 0] 1 Plot[f[x], {x, -1, 1}] A look at the Series representations makes the answer very clear: Series[Sin[x], {x, 0, 5}] Series[Sin[2*x], {x, 0, 5}] (%% - %)/x SeriesData[x, 0, {1, 0, -1/6, 0, 1/120}, 1, 6, 1] SeriesData[x, 0, {2, 0, -4/3, 0, 4/15}, 1, 6, 1] SeriesData[x, 0, {-1, 0, 7/6, 0, -31/120}, 0, 5, 1] Or, in even simpler terms, when x is close to 0, Sin[x] is close to x and Sin[2x] is close to 2x, so their difference is close to -x. Divide by x, and that's close to -1. Take Abs and you get 1. Bobby > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 > While I try to display the graph of this function by using Plot, it > seems that there is no limit at the point x=0. > Please help... > Amir -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Calculus : limits Amir ha scritto: > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 > While I try to display the graph of this function by using Plot, it > seems that there is no limit at the point x=0. > Please help... > Amir Try with: Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0,Direction->1] and you will get the answer as x approaches to x0 from smaller values (odd limit). Read mathematica help for more informations on Limit[] and Direction option. Matteo Delfino === Subject: Re: Calculus : limits > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 > While I try to display the graph of this function by using Plot, it > seems that there is no limit at the point x=0. > Please help... > Amir Mathematica's answer is correct but ... Limit always computes directional limits. Thus: Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> -1] 1 but Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> 1] -1 So the limits as x goes to 0 form above and form below are different and thus there is n limit'. Also, as you see by default Limit computes from above. However, I still can't find this clearly documented in version 5, even though I remeber myself (and others) complaining about this lack of documentation in version 4 (if not earlier). Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Calculus : limits I'd like to find the limit of Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] I use Mathematica v.5. I get the wrong (??) answer : 1 While I try to display the graph of this function by using Plot, it seems that there is no limit at the point x=0. Please help... Amir === Subject: Re: Re: Calculus : limits >>I'd like to find the limit of >>Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] >>I use Mathematica v.5. I get the wrong (??) answer : 1 > Unfortunately, Mathematica by default takes the limit from the right, > and does not check to see if it's the same as the limit from the left. > It does not actually do a two-sided limit. In any example where the > one-sided limits are not the same, instead of an error message that > the limit does not exist, Mathematica instead gives you the limit from > the right. Worse, there's nothing in the Help that even tells you that > Limit means limit from the right unless you specify the left. > It will do the one-sided limits correctly if you ask for them separately. > To find the limit as x->0 from the right: > Limit[(Abs[Sin[x] - Sin[2 x]])/x, x -> 0, Direction -> -1] > To find the limit as x->0 from the left: > Limit[(Abs[Sin[x] - Sin[2 x]])/x, x -> 0, Direction -> 1] > In effect, > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > is the same as > Limit[(Abs[Sin[x] - Sin[2 x]])/x, x -> 0, Direction -> -1] > and is *not* a two-sided limit. > (I don't like it either.) > -- > Helen Read > University of Vermont For an explanation of why the notion of a two sided limit makes little sense for a general Limit function, I refer to a prior post to MathGroup: http://forums.wolfram.com/mathgroup/archive/2001/Nov/msg00190.html I tend to agree that the default behavior of Direction->Automatic warrants explicit documentation. Daniel Lichtblau Wolfram Research === Subject: Re: Calculus : limits Using the option Direction (limit from below/above) solves the problem: In[6]:= Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> 1] Out[6]= -1 In[5]:= Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> -1] Out[5]= 1 Wolfgang > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 > While I try to display the graph of this function by using Plot, it > seems that there is no limit at the point x=0. > Please help... > Amir === Subject: Re: Calculus : limits Amir >Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] >I use Mathematica v.5. I get the wrong (??) answer : 1 >While I try to display the graph of this function by using Plot, it >seems that there is no limit at the point x=0. Yep, the limit from the left is -1, while that from the right is +1. They can hardly agree in zero. : ] Ultimately your limit is equivalent to that of Abs[x]/x for x->0 You should load the package Calculus`Limit` to compute limits with discontinuos functions such as Abs. (But don't forget, as you've just done, to double check the result you get). cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: Calculus : limits > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 > While I try to display the graph of this function by using Plot, it > seems that there is no limit at the point x=0. > Please help... > Amir -- If a function is not continuous - which is the case here - you have to use the Direction option : In[1]:=Limit[Abs[Sin[x] - Sin[2x]]/x, x -> 0, Direction -> -1] Out[1]=1 In[2]:=Limit[Abs[Sin[x] - Sin[2x]]/x, x -> 0, Direction -> 1] Out[2]=-1 v.a. -- 0% de pub! Que du bonheur et des vrais adh.8erents ! Vous aussi inscrivez-vous sans plus tarder!! Message post.8e .88 partir de http://www.gyptis.org, BBS actif depuis 1995. === Subject: Re: Calculus : limits > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 Unfortunately, Mathematica by default takes the limit from the right, and does not check to see if it's the same as the limit from the left. It does not actually do a two-sided limit. In any example where the one-sided limits are not the same, instead of an error message that the limit does not exist, Mathematica instead gives you the limit from the right. Worse, there's nothing in the Help that even tells you that Limit means limit from the right unless you specify the left. It will do the one-sided limits correctly if you ask for them separately. To find the limit as x->0 from the right: Limit[(Abs[Sin[x] - Sin[2 x]])/x, x -> 0, Direction -> -1] To find the limit as x->0 from the left: Limit[(Abs[Sin[x] - Sin[2 x]])/x, x -> 0, Direction -> 1] In effect, Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] is the same as Limit[(Abs[Sin[x] - Sin[2 x]])/x, x -> 0, Direction -> -1] and is *not* a two-sided limit. (I don't like it either.) -- Helen Read University of Vermont === Subject: Re: Calculus : limits Strictly speaking Direction option has to be specified. The default is Automatic but in this case Mathematica takes (seemingly) Direction-> -1 as default. Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0,Direction->-1] Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0,Direction->1] will give you two right answers (that are not equal.) The truth of the matter is, that Calculus-type functions do not handle Abs very well and if possible I use other things, e.g. UnitStep. P. > I'd like to find the limit of > Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] > I use Mathematica v.5. I get the wrong (??) answer : 1 > While I try to display the graph of this function by using Plot, it > seems that there is no limit at the point x=0. > Please help... > Amir === Subject: Re: Re: Very basic question: Zoom into a 2-D plot with the mouse ImageSize does not change the PlotRange, hence does NOT have the effect of zooming in (or out) of a graphic. When people speak of zoom in or zoom out, they ordinarily mean that the physical image size remains the same. >>I have a very basic question: Does Mathematica offer the possibility >>to zoom into a plot (e.g. a simple 2-D plot like the result of >>Plot[Sin[x],{x,0,2*Pi}]) by using the mouse? I am talking about a >>feature that many other tools offer. I know that one can >>use the PlotRange option to zoom into a plot region, but it can be >>quite awkward for every zoom to use this option. >>Rainer > You are perhaps aware that if you select the plot by clicking in it, you can drag the corners to > make it as big as your screen allows. In the program itself, Plot has the option ImageSize, which > you might try. You would do > Plot[Sin[x], {x, 0, 2*Pi}, ImageSize -> 800] > which makes it quite large. -- 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: Re: Very basic question: Zoom into a 2-D plot with the mouse Evidently, yes, a matter of definition. I distinguish between the size of an image and the magnification used in the viewing window. Look, for example, at mapquest.com When you choose to zoom in or zoom out on a map there, you do not get a larger or smaller image, but rather the center or some other specified point). The same thing is the case in any graphing calculator. Often, that's what folks want when they want to zoom in on a graph -- to examine some feature of it more closely, given the same viewing window physical space in which to view it. >>ImageSize does not change the PlotRange, hence does NOT have the effect >>of zooming in (or out) of a graphic. When people speak of zoom in or >>zoom out, they ordinarily mean that the physical image size remains the >>same. > Huh? I think there's a semantics problem here. If I replot a plot with > ImageSize tripled, the image size _on the screen_ is three times larger, > which is certainly what I think of as the effect of zooming in an > on-screen graphic, or as the physical image size of an on-screen > graphic. -- 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: Very basic question: Zoom into a 2-D plot with the mouse > ImageSize does not change the PlotRange, hence does NOT have the effect > of zooming in (or out) of a graphic. When people speak of zoom in or > zoom out, they ordinarily mean that the physical image size remains the > same. Huh? I think there's a semantics problem here. If I replot a plot with ImageSize tripled, the image size _on the screen_ is three times larger, which is certainly what I think of as the effect of zooming in an on-screen graphic, or as the physical image size of an on-screen graphic. === Subject: Re: Very basic question: Zoom into a 2-D plot with the mouse >I have a very basic question: Does Mathematica offer the possibility >to zoom into a plot (e.g. a simple 2-D plot like the result of >Plot[Sin[x],{x,0,2*Pi}]) by using the mouse? I am talking about a >feature that many other tools offer. I know that one can >use the PlotRange option to zoom into a plot region, but it can be >quite awkward for every zoom to use this option. >Rainer You are perhaps aware that if you select the plot by clicking in it, you can drag the corners to make it as big as your screen allows. In the program itself, Plot has the option ImageSize, which you might try. You would do Plot[Sin[x], {x, 0, 2*Pi}, ImageSize -> 800] which makes it quite large. === Subject: Re: GUIKIT / GraphEdit > is there an idea how can I use the options of Showgraph[] to control > the > appearance of a displayed graph but using the interactive GraphEdit > command? > Frank Hello Frank, In this release of GUIKit, the GraphEdit example application does not provide any options to control the visual appearance of the nodes and edges in the interactive display. This example was put together to illustrate how you can hook up third party Java libraries to the GUIKit framework, in this case the Java 2D graphics and graph library, DIVA, http://embedded.eecs.berkeley.edu/diva/ Unfortunately, if you wanted to play with the appearances and options of the GraphEdit display window you would currently have to modify the underlying Java classes that make these graphs. Source code is provided for these classes and you would want to look at the code in the com.wolfram.guikit.graph.* package if you were willing to delve into the Java source code side of things. Jeff Adams Wolfram Research === Subject: GUIKIT / GraphEdit is there an idea how can I use the options of Showgraph[] to control the appearance of a displayed graph but using the interactive GraphEdit command? Frank === Subject: Re: Mathgroup posting Actually, the publisher's web site (springeronline.com) says the Graphics volume is Not yet published, although the Programming volume is listed as published. But the Springer-Verlag site accepted my order for both volumes. And as you say at www.mathematicaguidebooks.org, amazon.com seems to know nothing about this -- not even that the original complete set is being split into the 2 volumes now and that the Numerics volume is Not yet published. There's no mention of the Symbolics volume. I look forward to using all volumes (eventually)! > I'm glad that today I can announce that the Programming volume and the > Graphics volume of the Mathematica GuideBooks have been printed and > are available. -- 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: Mathgroup posting I'm glad that today I can announce that the Programming volume and the Graphics volume of the Mathematica GuideBooks have been printed and are available. Many of you have mailed me over the last years or posted to his group and asked when they will be out. This long publishing adventure, which started back in 1991 with a 1600+ page manuscript, and continued with a contract to publish the book in September 1994, has had five editors and now (finally) has reached the state of two printed books. The books have been updated repeatedly over the years and are Mathematica 4 and 5 compatible. Every volume comes with a DVD containing the evaluated notebooks for that volume, and the unevaluated notebooks for the other three volumes. The table of contents, preface, introduction, additions, additional problems and solutions, and related material can be found at: http://www.mathematicaguidebooks.org/ I hope the books will be useful for some of you Mathematica users. Michael Trott === Subject: Re: Stats Pack and LocationReport You are doing nothing wrong. Mathematica is not following a consistent approach when it evaluates LocationReport as compared to the evaluation of Mean (and the other location parameters). The evaluation of Mean uses (or so it seems) a simple application of Plus to a list and then divides by the Length of the list. But Plus has attribute Listable, so that if the elements of the list are themselves lists (as in your example), Plus computes first the sum of each sublist and then goes on to compute the sum of the resulting sums. However, LocationReport[lst] checks first whether lst is a vector of numbers and if that is True then it goes on. In your case, the list is not a vector (it is a list of lists), so that it returns False and stops right there. You may use Trace to see what is going on internally. Evaluate Trace[LocationReport[{2, 1, 3, 6}]] and Trace[LocationReport[{{2}, {1}, {3}, {6}}]] Why does LocationReport has to check VectorQ on the list lst, but Mean doesn't? A feature, I guess. Tomas Garza Mexico City ----- Original Message ----- === Subject: Stats Pack and LocationReport > Hello Everyone, > Never know what I'm wrong... > I loaded the stats pack as > << Statistics`DescriptiveStatistics` > I can compute various univariate statistics as > Mean[Take[X, {t0, t1}, {6, 6}]] > Median[Take[X, {t0, t1}, {6, 6}]] > Variance[Take[X, {t0, t1}, {6, 6}]], > where I am referring to a portion of one column of matrix X. > But LocationReport[Take[X, {t0, t1}, {6, 6}]] and DisxpersionReport[.] > do not work. They simply return a listing of my data. What am I doing > wrong? > Greg === Subject: Re: Stats Pack and LocationReport Possibly this is what you mean to do: x = Table[Cos@t + Sin@i, {t, 1, 6}, {i, 1, 7}]; data = Take[x, {4, 6}, {5, 6}] LocationReport /@ Transpose@data DispersionReport /@ Transpose@data (* output omitted) Bobby > Hello Everyone, > Never know what I'm wrong... > I loaded the stats pack as > << Statistics`DescriptiveStatistics` > I can compute various univariate statistics as > Mean[Take[X, {t0, t1}, {6, 6}]] > Median[Take[X, {t0, t1}, {6, 6}]] > Variance[Take[X, {t0, t1}, {6, 6}]], > where I am referring to a portion of one column of matrix X. > But LocationReport[Take[X, {t0, t1}, {6, 6}]] and DisxpersionReport[.] > do not work. They simply return a listing of my data. What am I doing > wrong? > Greg -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Stats Pack and LocationReport Hello Everyone, Never know what I'm wrong... I loaded the stats pack as << Statistics`DescriptiveStatistics` I can compute various univariate statistics as Mean[Take[X, {t0, t1}, {6, 6}]] Median[Take[X, {t0, t1}, {6, 6}]] Variance[Take[X, {t0, t1}, {6, 6}]], where I am referring to a portion of one column of matrix X. But LocationReport[Take[X, {t0, t1}, {6, 6}]] and DisxpersionReport[.] do not work. They simply return a listing of my data. What am I doing wrong? Greg === Subject: Re: Part of a matrix or array I suggest you take a look at the add-on LinearAlgebra`MatrixManipulation`. Therein you will find a number of ways to select parts of a matrix. Now, I don't know if you can avoid using a 'function' to do what you want. Tomas Garza Mexico City ----- Original Message ----- === Subject: Part of a matrix or array > Hello everyone, > Mathematica has so many functions for accessing parts of arrays that > I'm not sure which one I should be using to get a submatrix, for > example, rows 3 to 7 and columns 11 to 14 of matrix X. Should I use > Take? > Take[X,{3,7},{11,14}] > Is there a more compact way where I don't have to explicit refer to a > function? > Greg === Subject: Re: Part of a matrix or array > Hello everyone, > Mathematica has so many functions for accessing parts of arrays that > I'm not sure which one I should be using to get a submatrix, for > example, rows 3 to 7 and columns 11 to 14 of matrix X. Should I use > Take? > Take[X,{3,7},{11,14}] > Is there a more compact way where I don't have to explicit refer to a > function? You could use Part and Range X[[Range[3,7],Range[11,4]]] Ssezi === Subject: Re: Part of a matrix or array > Hello everyone, > Mathematica has so many functions for accessing parts of arrays that > I'm not sure which one I should be using to get a submatrix, for > example, rows 3 to 7 and columns 11 to 14 of matrix X. Should I use > Take? > Take[X,{3,7},{11,14}] > Is there a more compact way where I don't have to explicit refer to a > function? > Greg Well, yes and no .... X[[Range[3, 7], Range[11, 14]]] you can write that also as X[[{3,4,5,6,7},{11,12,13,14}]] so now you do not refer to a function but this can hardly be called more compact. Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Part of a matrix or array Hello everyone, Mathematica has so many functions for accessing parts of arrays that I'm not sure which one I should be using to get a submatrix, for example, rows 3 to 7 and columns 11 to 14 of matrix X. Should I use Take? Take[X,{3,7},{11,14}] Is there a more compact way where I don't have to explicit refer to a function? Greg === Subject: Re: Part of a matrix or array I am sure by now you have realized that Part[X, Range[3, 7], Range[11, 14]] does what you want. Peter > Hello everyone, > Mathematica has so many functions for accessing parts of arrays that > I'm not sure which one I should be using to get a submatrix, for > example, rows 3 to 7 and columns 11 to 14 of matrix X. Should I use > Take? > Take[X,{3,7},{11,14}] > Is there a more compact way where I don't have to explicit refer to a > function? > Greg === Subject: Re: RandomReplacement Hi Andrej, Ok. this new fix seems to get rid of all the bugs I have seen in this group. thank you so much for making the fix.(there was no need to give me credit for pointing out the problem, it's not liek I helped with the fixing the code, o_0) i'll keep my eye out for anything strange as i use it. the timing doesn't seem to be too different om my machine. (Dell Inspiron 4150 laptop. 1.7ghz, 1gig ram, windows XP, Mathematica 5.0) without RandomReplacement loaded, i get In[6]:= Timing[Table[RandomArray[NormalDistribution[5, 2]],{10^7}];] Out[6]= {3.375 Second,Null} In[7]:=Timing[Table[RandomArray[NormalDistribution[5, 2]],{10^8}];] Out[7]={33.999 Second,Null} with RandomReplacement loaded, In[5]:= Timing[Table[RandomArray[NormalDistribution[5, 2]],{10^7}];] Out[5]= {3.545 Second,Null} In[6]:= Timing[Table[RandomArray[NormalDistribution[5, 2]],{10^8}];] Out[6]= {34.58 Second,Null} i can't evaluate Timing[Table[RandomArray[NormalDistribution[5, 2]],{10^9}];] No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. I wonder why the timing increases exponentially... but anyway, thank you so much the fix! sean > I am sending you a new version of the package, which > I think now works. > It is a lot slower than the using the built in > Random[] but it gives > the right answer in the example that you tested it > on last time. > There may still be some bugs in it so I would be > grateful if you'd let > me know if you observe anything strange. > suggesting the cause! > Andrzej > ATTACHMENT part 2 application/octet-stream x-unix-mode=0644; name=RandomReplacement.m _______________________________ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com === Subject: Re: Save a graphic Use Put (>>) directly on your plot. Then you may recover it later with Get (<<) and plot it again with Show. For example, In[1]:= g = Plot[Sin[x], {x, -Pi, Pi}]; In[2]:= g >> savedPlot; Later on In[3]:= g = << savedPlot; In[4]:= Show[g]; Tomas Garza Mexico City ----- Original Message ----- === Subject: Save a graphic > I know how to save a plot to disk as a GIF (bitmap), but I want to save it in Mathematica's native > format so I can read it in later and rescale it, etc. I don't see how to do this. Can anyone help? I > also don't see any alternatives to GIF, but there must be some. > Steve Gray === Subject: Re: Save a graphic > Use Put (>>) directly on your plot. Then you may recover it later with Get > (<<) and plot it again with Show. For example, > In[1]:= > g = Plot[Sin[x], {x, -Pi, Pi}]; > In[2]:= > g >> savedPlot; If there's a memory overflow problem involved, will >> release the memory used by g? -- or should he also add In[3]:= Clear[g] or even Remove[g] Which would be preferred? And I assume he could use something like g >> savedPlot<>ToString[kkk] to assign a notebook-generated serial number kkk to each saved plot? === Subject: Save a graphic I know how to save a plot to disk as a GIF (bitmap), but I want to save it in Mathematica's native format so I can read it in later and rescale it, etc. I don't see how to do this. Can anyone help? I also don't see any alternatives to GIF, but there must be some. Steve Gray === Subject: Question about derivatives I want to treat a function abstractly, I know that it is a function of n variables. I wish to take its derivative after addition or multiplication with another function. However Derivative does not return what I expect. Derivative[0,1][f+g] gives (f+g)^(0,1) instead of f^(0,1)+g^(0,1) and Derivative[0,1][fg] gives (fg)^(0,1) instead of f^(0,1)g+g^(0,1)f. Now perhaps I'm going about my problem in the wrong way, if I am please tell me. I also have some other questions about Derivative, Derivative[0,1][Composition[f,g]] gives f^(0,1)(g)g^(0,1), the correct result, why does Derivative know the chain rule and not the product rule? Also, in order to get the correct behaviour for Derivative[0,1][f+g], I can use the Map function, that is Map[Derivative[0,1],f+g] returns f^(0,1) +g^(0,1). Which is fine except that if I have the function 1+f and apply the same command to it I get 0& + f^(0,1), instead of f^(0,1). Clearly this is because of the presence of the command Function[0], however I have been unable to find a function that fixes this problem. In essence I want to do vector operations of the ring of functions, but find that doing this in Mathematica is hard. How can I do this easily? Surely someone else has figured out a convenient way of do this. Ben === Subject: Re: Solving an equation Use FindRoot z=10*Random[]+10*Random[]*I 2.7189941354763025 + 3.8818603982038162*I {a, b} = {Re[z1], Im[z1]} /. FindRoot[Gamma[z1] == z, {z1,1}] {0.12160253863826206, -0.15339958773484796} Chop[Gamma[a+b*I]-z] 0 Bob Hanlon === > Subject: Solving an equation > I have an equation, Gamma[a+I b] = some complex number. I need to > solve this equation for a and b. I can write a+I b as z, but it can't > be solved through NSolve. What I have been doing is a double do loop > for a and b and getting some number. Then I compare this to the > number I have. Then I narrow down my possibilities for a and b, and > go through the process again. Does anyone know of a better way to do > this problem? Is there a way to have Mathematica compare each result > of the do loop to a given value, and given certain conditions spit out > an answer for a and b? > Hope that makes sense. === Subject: Re: Solving an equation OK, I figured out how to find these roots graphically. We want the solutions of Gamma[x+ I y]=a+Ib. A=Plot3D[Re[Gamma[x+I y]]-a,{x,..},{y,..}, PlotRange->{0,10^-10},ClipFill->None,ViewPoint->{0,0,10^5}] B=Plot3D[Im[Gamma[x+Iy]]-b,{x,..},{y,..}, PlotRange->{0,10^-10},ClipFill->None,ViewPoint->{0,0,10^5}] Show[A,B] The intersections where y is not =0 are solutions. === Subject: Re: histograms of identical distribution is different. maybe binnumber is the problem? Use the HistogramScale option Needs[Statistics`NormalDistribution`]; Needs[Graphics`Graphics`]; Do[ normdata=RandomArray[NormalDistribution[],10000]; normdata2=RandomArray[NormalDistribution[],10000]; DisplayTogether[ Histogram[normdata,BarEdgeStyle->Hue[0], BarStyle->{}, HistogramScale->1], Histogram[normdata2,BarStyle->{}, HistogramScale->1]], {i,10}] Bob Hanlon === > Subject: histograms of identical distribution is different. maybe binnumber is the problem? > i found the code attached below in the archives. it > will display two histograms without shading in one > graph. > note both histograms are generated exactly the same > way using exactly the same number of sample points. > for me, at least, it will show a pattern of a few of > the distributions having a lower number of points > about the mean. > what causes this? I think it has to do with the way > histograms are made? is there a way to control bin > width or number in a convenient way? > like.. > binwidth-> (numberof points)/(whatever bin number you > want to use) > Do[ > normdata = RandomArray[NormalDistribution[], 10000]; > h1 = Histogram[normdata, BarEdgeStyle -> Hue[0], > BarStyle -> {}, DisplayFunction -> Identity]; > normdata2 = RandomArray[NormalDistribution[], 10000]; > h2 = Histogram[normdata2, BarStyle -> {}, > DisplayFunction -> Identity]; > DisplayTogether[h1, h2], > {i, 10}] > > __________________________________ > Do you Yahoo!? > Y! Messenger - Communicate in real time. Download now. > http://messenger.yahoo.com === I've only been playing around with the trial version of Mathematica for a few hours but I can't figure out how the heck to plot a histogram. I have a list of data (below) that I want to plot. The range is 80 to 100 and I want 5 bins, across 4 points each. I feel that this is a pretty straightforward thing to do, but I can't even plot a single histogram, even when I reproduce the samples that they give in the math book word for word. The data is below, any help would be greatly appreciated. 97,90,91,98,93,100,90,98,91,93,98,93,97,93,80,95,93,99,96,80,98,85,94,98,96, 88,93,92,88,97,90,90 === Subject: Re: Eigenvalues and eigenvectors of a matrix with nonpolynomial elements. >>I need to find the eigenvalues and eigenvectors of matrices where the elements depend on a variable, k, in a nonpolynomial manner. Thus, according to my (limited) knowledge of eigensystems, the eigenvalues are the values of k that make the determinant zero and there should be an eigenvector associated with each eigenvalue. A simple warm-up example is given below; my actual cases will be more complicated. I wish to know if the method I have put together below, using engineering rather than maths, is suitable and what accuracy I can expect. >>No, eigenvalues for a matrix mat are values lambda for which > mat - lambda*IndentityMatrix[...] > is singular (that is, has zero determinant. In your example these would > be functions of k. In simplified form I get > Out[8]//InputForm= > {-1 + I, -1 - I, (-Cosh[k] - Sin[k] - > Sqrt[Cosh[k]^2 - 2*Cosh[k]*Sin[k] + Sin[k]^2 + 4*Cos[k]*Sinh[k]])/2, > (-Cosh[k] - Sin[k] + Sqrt[Cosh[k]^2 - 2*Cosh[k]*Sin[k] + Sin[k]^2 + > 4*Cos[k]*Sinh[k]])/2} > Daniel Lichtblau > Wolfram Research > In[103]:= > DSolve[Derivative[4][y][x] - k^4*y[x] == 0, y[x], x] > Out[103]= > {{y[x] -> C[2]/E^(k*x) + E^(k*x)*C[4] + C[1]*Cos[k*x] + C[3]*Sin[k*x]}} > I have translated this solution to the equivalent form > In[104]:= > e1 = A1*Cos[k*x] + A2*Sin[k*x] + A3*Cosh[k*x] + A4*Sinh[k*x]; > The boundary conditions are > In[107]:= > bc = {0 == (e1 /. x -> 0), 0 == (1/k^2)*(D[e1, {x, 2}] /. x -> 0), 0 == (e1 /. x -> 1), > 0 == (1/k)*(D[e1, x] /. x -> 1)}; > Which give rise to a set of linear equations whose coefficient matrix may be found from > In[108]:= > e2 = Normal[CoefficientArrays[bc, {A1, A2, A3, A4}]] > Out[108]= > {{0, 0, 0, 0}, {{-1, 0, -1, 0}, {1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, > {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}}} > The values of k that satisfy this equation I am calling eigenvalues. Each value of {A1, A2, A3, A4} which is associated with each eigenvalue I am calling an eigenvector. We thus come to the matrix which I defined previously from which my eigenvalues and vectors must be extracted. > In[109]:= > e3 = e2[[2]] > Out[109]= > {{-1, 0, -1, 0}, {1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, > {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}} Okay. I had considered that you might be doing some sort of Sturm-Liouville problem, but the setup looked too much like a standard linear algebra eigensystem. So we begin anew with the matrix and its determinant. mat = {{-1, 0, -1, 0}, {1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}}; det = Det[mat]; For the task at hand you can use NullSpace numerically after first extracting the root in k. In[130]:= root = FindRoot[det==0, {k,6,8}] Out[130]= {k -> 7.06858} In[132]:= Chop[NullSpace[mat /. root]] Out[132]= {{0, -0.999999, 0, 0.00120412}} But there is a symbolic approach as well. We set up the symbolic expression mat.vec==0 with vec a vector of indeterminates. We algebraicize by converting trigs and hyperbolics to ordinary variables and adding subsidiary defining relations e.g. Sin[k]->sk, Cos[k]->ck, and we have sk^2+ck^2==1. Variations on this idea involve different algebraic substitutions. For example we could convert to exponentials, or use the standard rational parametrization of the trig and hyperbolic functions. vars = Array[x,Length[mat]]; subs = {Cos[k]->ck,Sin[k]->sk,Cosh[k]->chk,Sinh[k]->shk}; polys1 = mat . vars /. subs; polys2 = {ck^2+sk^2-1, chk^2-shk^2-1}; detpoly = Det[mat]/.subs; We could normalize the eigenvector with a relation that the sum of squares of its components must be unity. As it will lead to a simpler result, we instead insist that a particular component be unity. This must be done carefully as it is is not really a generic approach. So we use the earlier numeric computation to choose one of the components, the second one, say, that did not vanish. In[144]:= InputForm[polys = Join[polys1,polys2,{x[2]-1,detpoly}]] Out[144]//InputForm= {-x[1] - x[3], x[1] - x[3], -(ck*x[1]) - sk*x[2] - chk*x[3] - shk*x[4], sk*x[1] - ck*x[2] - shk*x[3] - chk*x[4], -1 + ck^2 + sk^2, -1 + chk^2 - shk^2, -1 + x[2], 2*ck*shk - 2*chk*sk} In[146]:= InputForm[soln = vars /. Solve[polys==0, vars]] Out[146]//InputForm= {{0, 1, 0, -(chk*ck) + shk*sk}} Daniel Lichtblau Wolfram Research === Subject: Re: Eigenvalues and eigenvectors of a matrix with nonpolynomial elements. > I need to find the eigenvalues and eigenvectors of matrices where the elements depend on a variable, k, in a nonpolynomial manner. Thus, according to my (limited) knowledge of eigensystems, the eigenvalues are the values of k that make the determinant zero and there should be an eigenvector associated with each eigenvalue. A simple warm-up example is given below; my actual cases will be more complicated. I wish to know if the method I have put together below, using engineering rather than maths, is suitable and what accuracy I can expect. >No, eigenvalues for a matrix mat are values lambda for which mat - lambda*IndentityMatrix[...] is singular (that is, has zero determinant. In your example these would be functions of k. In simplified form I get Out[8]//InputForm= {-1 + I, -1 - I, (-Cosh[k] - Sin[k] - Sqrt[Cosh[k]^2 - 2*Cosh[k]*Sin[k] + Sin[k]^2 + 4*Cos[k]*Sinh[k]])/2, (-Cosh[k] - Sin[k] + Sqrt[Cosh[k]^2 - 2*Cosh[k]*Sin[k] + Sin[k]^2 + 4*Cos[k]*Sinh[k]])/2} Daniel Lichtblau Wolfram Research In[103]:= DSolve[Derivative[4][y][x] - k^4*y[x] == 0, y[x], x] Out[103]= {{y[x] -> C[2]/E^(k*x) + E^(k*x)*C[4] + C[1]*Cos[k*x] + C[3]*Sin[k*x]}} I have translated this solution to the equivalent form In[104]:= e1 = A1*Cos[k*x] + A2*Sin[k*x] + A3*Cosh[k*x] + A4*Sinh[k*x]; The boundary conditions are In[107]:= bc = {0 == (e1 /. x -> 0), 0 == (1/k^2)*(D[e1, {x, 2}] /. x -> 0), 0 == (e1 /. x -> 1), 0 == (1/k)*(D[e1, x] /. x -> 1)}; Which give rise to a set of linear equations whose coefficient matrix may be found from In[108]:= e2 = Normal[CoefficientArrays[bc, {A1, A2, A3, A4}]] Out[108]= {{0, 0, 0, 0}, {{-1, 0, -1, 0}, {1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}}} The values of k that satisfy this equation I am calling eigenvalues. Each value of {A1, A2, A3, A4} which is associated with each eigenvalue I am calling an eigenvector. We thus come to the matrix which I defined previously from which my eigenvalues and vectors must be extracted. In[109]:= e3 = e2[[2]] Out[109]= {{-1, 0, -1, 0}, {1, 0, -1, 0}, {-Cos[k], -Sin[k], -Cosh[k], -Sinh[k]}, {Sin[k], -Cos[k], -Sinh[k], -Cosh[k]}} -- This message has been scanned for viruses and dangerous content by the Cranfield MailScanner, and is believed to be clean. === Subject: comment lines In Mathematica 5.0, is there a problem with comment lines? Because when I combine a comment section with a computational section, I sometimes get errors, for example: (* THIS IS A COMMENT LINE *) Integrate[x+y, x] % = = 98 z eq1 = % If the above is written all in same cell, I get error sometimes, specially if I save the file and re-open, same thing will not execute properly and gives errors. Is this system bug?? === Subject: Re: comment lines You should get an error _every_ time. Try % == 98 z instead of % = = 98 z -- Peter Pein, Berlin to write to me, start the subject with [ symbio schrieb im Newsbeitrag > In Mathematica 5.0, is there a problem with comment lines? Because when I > combine a comment section with a computational section, I sometimes get > errors, for example: > (* THIS IS A COMMENT LINE *) > Integrate[x+y, x] > % = = 98 z > eq1 = % > If the above is written all in same cell, I get error sometimes, specially > if I save the file and re-open, same thing will not execute properly and > gives errors. Is this system bug?? === Subject: RandomReplacement package I have just uploaded the latest version of the fix for the problem with Mathematica's uniform distribution generator Random[]. The package now seems to work correctly with constructions like Table[Random[],{n}] for any n, though it is a lot slower than using the built in Random. The idea of the fix is as described in my last posting. The package may still contain bugs as I have been able to do very litttle testing so I welcome any reports of strange behaviour. The package can be downloaded form http://www.akikoz.net/~andrzej/Mathematica/index.html or http://www.mimuw.edu.pl/~akoz/Mathematica/index.html Andrzej Kozlowski Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Gaussian Noise Hi Everyone, I have a funtion and I would like to add some gaussian noise over the interval of (0,1) So basically f = x(sub)i + gauss (0,1) Is there a way of doing this in Mathematica? Ekta === Subject: Re: Gaussian Noise << Statistics`NormalDistribution` nd = NormalDistribution[0, 1] Plot[Sin[x] + 0.125 Random[nd], {x, 0, Pi}] but be carefull repeated calls of f[x_]:=Sin[x]+Random[nd] give differnt results for the same argument. Jens Ekta . schrieb im Newsbeitrag > Hi Everyone, > I have a funtion and I would like to add some gaussian noise over the > interval of (0,1) > So basically f = x(sub)i + gauss (0,1) > Is there a way of doing this in Mathematica? > Ekta === Subject: Re: FilledPlot Sideways? I suggest the following: from the original plot (not the FilledPlot) extract the coordinates of the points on the curve. Then Reverse the two coordinates in each point. This transposes the two axes. Now work separately with those points which are on the positive side and those on the negative side, and construct for each list the ListFilledPlot. Finally, Show the two plots together. Example: In[1]:= g1 = Plot[x^2, {x, -2, 2}]; In[2]:= transpPtsOnCurve = Cases[g1, x_ -> x, {5}] /. {x_, y_} -> {y, x} In[3]:= posPts = Cases[transpPtsOnCurve, {x_, y_} /; y >= 0] In[4]:= upPart = FilledListPlot[posPts, DisplayFunction -> Identity]; In[5]:= dnPart = FilledListPlot[posPts /. {x_, y_} -> {x, -y}, DisplayFunction -> Identity]; In[6]:= Show[upPart, dnPart, DisplayFunction -> $DisplayFunction]; By the way, this has the interior of the curve filled. If you want the exterior to be filled instead, that is a different situation, but not difficult to handle. Tomas Garza Mexico City ----- Original Message ----- === Subject: FilledPlot Sideways? > How can I make FilledPlots sideways? > So I want the equivalent of FilledPlot [x^2, {x,-2,2}], but with the axes > transposed. > The curve is something like ParametricPlot[{x^2, x}, {x,-2,2}]. How to do > the shading? > Tom Aldenberg === Subject: Re: FilledPlot Sideways? Tom, One method for doing this is to use the DrawGraphics package from my web site below. The Draw statements generate the primitive graphics (Line, Polygon etc.) and then DrawingTransform can be used to transform these objects. In this case we just switch the x and y coordinates. Needs[DrawGraphics`DrawingMaster`] Draw2D[ {FilledDraw[x^2, {x, -2, 2}] /. DrawingTransform[#2 &, #1 &]}, AspectRatio -> Automatic, Axes -> True]; If more general transformations are used, it may be necessary to use FineGrainPolygons and FineGrainLines so the straight edges will bend properly with the transformation. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ How can I make FilledPlots sideways? So I want the equivalent of FilledPlot [x^2, {x,-2,2}], but with the axes transposed. The curve is something like ParametricPlot[{x^2, x}, {x,-2,2}]. How to do the shading? Tom Aldenberg === Subject: Re: Re: normal distribution random number generation The speed difference can be pretty dramatic: Quit a=First@Timing[Table[Random[Real,{0,1000}],{10^6}];] < I think I have now fixed the problem reported by Mark Fisher. The new > version of the RandomReplacement now works like this: > SeedRandom[5] > Timing[First[Table[Random[],{10000}]]] > {0.01 Second,0.786599} > < Timing[First[Table[Random[],{10000}]]] > {0.02 Second,0.409222} > As you can see there is a loss of speed involved. There may also be > still some as yet undiscovered problems. However, the new package is > available form my sites, though I still should write some documentation > of the latest changes (a few bugs in the previous version have also > been fixed). > Andrzej Kozlowski > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ >> It's clearly because of packed arrays: >> <> PackedArrayQ[Table[Random[],{249}]] >> False >> PackedArrayQ[Table[Random[],{250}]] >> True >> Obviously Mathematica uses a different method of generating random >> packed arrays. There are various ways of getting round this (e.g. >> constructing lists as joins of lists of length less than 250 etc) but >> one will loose the benefits of packed arrays and with that, presumably, >> a lot of speed. This seems to be something that only WRI can change. >> Note however that not all situations in which one uses Random[] require >> generating this type of lists. >> Moreover, for problems involving the normal distribution it seems to me >> that using the Marsaglia generator gives good results even with the >> built in Random[]. But certainly we should hope that something will >> finally be done do deal with this issue in version 6. >> Andrzej >He's right! How the devil does that happen? >Here's a test, with Andrzej's package loaded in my Init file. >First, with n=250: >Quit >SeedRandom[5] >Table[Random[],{250}]; >Last@% >0.107874 >Unprotect[Random]; >Clear@Random >SeedRandom[5] >Table[Random[],{250}]; >Last@% >0.107874 >Now, with n=249: >Quit >SeedRandom[5] >Table[Random[],{249}]; >Last@% >0.656099 >Unprotect[Random]; >Clear@Random >SeedRandom[5] >Table[Random[],{249}]; >Last@% >0.0708373 >Bobby >>FYI: I've just a little testing and I find that Mathematica ignors >>the user >>defined rules for Random in Table[Random[],{n}] when n >= 250. >> >The problem is not actually with the way Mathematica's >NormalDistribution but with the uniformly distributed Random[] >function. >NormalDistribution itself is generated (in the package >Statistics`NormalDistribution`) by means of the very classical so >called Boox-Muller method (although actually the Marsaglia variant >below works better). You can try downolading my little >RandomReplacement package form one of my web sites: > >http://www.akikoz.net/~andrzej//Mathematica/ in Japan > >or > >http://www.mimuw.edu.pl/~akoz/Mathematica/ in Poland > >The package is based on the post of daniel Lichtblau, which explains >the nature of the problem: > >msg00088.html> > > > >The package is named init.m and can be loaded automatically at the >start of each Mathematica session. >However, in fact if you are only concerned with normal distributions >it >may be enough to the following. First load the (unmodified) >NormalDistribution package using > >< >and then evaluate the code below. It will replace the Box-Muller >generator by the Marsaglia one. I have found that this is usually >enough. But if your problem still remains try the RandomReplacement >package. (Or you can use both of course). Here is the Marsaglia code >for normal distribution: > > >Statistics`NormalDistribution`Private`normal= > Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, > Module[{va=1.,vb,rad=2.,den=1.}, > While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; > rad=va*va+vb*vb]; > den=Sqrt[-2.*(Log[rad]/rad)]; > mu+sigma*va*den]]; > > > > > >>*This message was transferred with a trial version of >>CommuniGate(tm) >>Pro* >> >>Recently I have encountered a problem in Mathematica's normal >>distribution random number generator. The problem arises when I >>look >>at the distribution of averages of a list of theses numbers. That >>is, >>I generate 1000 numbers and take their average. I do this a number >>of >>times and the plot a frequency distribution. Consistently it seems >>to >>be skewed positive. Specifically, the number of occurrences less >>than >>3 standard deviations is consistent with the expected number, but >>the >>number greater than 3 is always larger (in some cases about twice >>the >>expected number). >> >>I was wondering if anyone else has noticed this and knows of a fix. >>Also, does anyone have code for a good quality normal distribution >>random number generator? >> >>Chris >> > > >> >> >> >> >-- >DrBob@bigfoot.com >www.eclecticdreams.net -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Re: normal distribution random number generation that I ever imagined. The main culprit is somethig otherwise very useful: Mathematica's packed array technology. The essential point, I think, is this: When Mathematica 'sees that it is asked to generate sufficiently large' array, where sufficiently large means large enough for the PackedArray technology to be used, it ignores any custom rules for Random[] and reverts to using the built in Random[] generator. Actually, I suspect this is not exactly what happens; rather than reverting probably Mathematica uses special code for generating packed arrays containing random numbers, but since this code uses the same random number generator as random[] the effect is the same as if the user defined rules were being ignored. What makes the problem harder to overcome is that the same principle applies for nested lists, but it is harder to work out precisely when the PackedArray technology is going to be used. What follows is a rather long explanation of what is going on including the history of my recent attempts to solve this problem. At the end there current best solution'. It results in a substantial loss of speed compared with simple usage of the unmodified Random[] function. While it seems clear to me that no satisfactory solution can be found until WRI provides a built in one, I hope someone will think of some improvements to this temporary fix, as i think the matter is of some importance. First let us choose a particular random seed that we shall use throughout to compare random outcomes with different definitions of Random[]. SeedRandom[5] standardValue=Random[] 0.786599 Next we shall redifine Random[], according to the original idea of Daniel Lichblau, in the form proposed by Bobby Treat and including a suggestion of Ray Koopman. Unprotect[Random]; With[{m1=1/(2.^30-1.),m2=2^30-2},randomSubstitutionFunction= Compile[{},((Random[Integer,m2]+.5)*m1+Random[Integer,m2])*m1]; Random[]:=randomSubstitutionFunction[]] With this definition we now get: SeedRandom[5];Random[] 0.66205 At this point almost all of us believed we had a fix, until Mark Fisher pointed out that; In[6]:= SeedRandom[5];First[a=Table[Random[],{249}]] 0.66205 SeedRandom[5];First[b=Table[Random[],{250}]] 0.786599 we got the standardValue again. The explanation seems to lie here: Developer`PackedArrayQ[a] False Developer`PackedArrayQ[b] True As I already stated above whenever Mathematica generates a packed array it reverts to using the built in Random[] no matter what rules we define. Now for lists the point at which the packed array technology enters seems to be at length 250. So I thought I could solve the problem by adding a rule for random: Random /: Table[Random[], {n_}] /; n Ò 250 := Developer`ToPackedArray[ Flatten[{Table[Random[], {i, 1, Quotient[n, 249]}, {j, 1, 249}], Table[Random[], {i, 1, Mod[n, 249]}]}]] I thought I had it solved: SeedRandom[5];First[b=Table[Random[],{300}]] 0.66205 No problem. Then Sean Kim sent me a message pointing out that things were still not working. At first I thought he must be using the old package (which in any case was full of bugs) but eventually I cam to realize that the problem was still there: SeedRandom[5];First[b=Table[Random[],{1000}]] 0.786599 Developer`PackedArrayQ[b] True The point is that I had thought that I could avoid the problem by constructing long lists as lists of lists of 249 elements (plus a shorter list), but Mathematica anticipates this and at some point the PackedArray technology again kicks in and the problem returns. To see it more clearly let's look at the following way of generating a table: We shall first clear Random and redefine it form the beginning; Clear[Random] With[{m1=1/(2.^30-1.),m2=2^30-2},randomSubstitutionFunction= Compile[{},((Random[Integer,m2]+.5)*m1+Random[Integer,m2])*m1]; Random[]:=randomSubstitutionFunction[]] Now compare: n=10^4;SeedRandom[5]; First[a=Flatten[{Table[Table[Random[],{j,1,249}],{i, 1,Quotient[n,249]}],Table[Random[],{i,1,Mod[n,249]}]}]] 0.66205 n=10^5;SeedRandom[5]; First[b=Flatten[{Table[Table[Random[],{j,1,249}],{i, 1,Quotient[n,249]}],Table[Random[],{i,1,Mod[n,249]}]}]] 0.786599 So we clearly see that for lists of lists the problem again occurs, although for much larger lists: of size around 10000. What about the solution? Well, at the moment the only thing that comes to my mind is to generate tables using something like this: SeedRandom[5];Timing[First[Flatten[ReleaseHold[{Table[ Hold[Table[Random[],{j,1,249}]],{i,1,Quotient[n,249]}],Table[Random[],{i , 1,Mod[n,249]}]}]]]] = {1.57 Second,0.147012} if we clear Random we get a different answer, a lot faster: Clear[Random] SeedRandom[5]; Timing[First[a=Flatten[ReleaseHold[{Table[Hold[Table[Random[],{ j,1,249}]],{i,1,Quotient[n,249]}],Table[Random[],{i,1,Mod[n,249]}]}]]]] {0.28 Second,0.160058} Note that this is no longer what we called standardvalue, since this time the first element of the list is not the first random number that was generated. But at least for now it seems to me that I have got a rather slow fix. I am no longer convinced that this is necessarily the best way to approach the problem: there should be a faster way to randomize' the uniform random number generator than this. But we obviously need WRI to do something about this matter soon. Andrzej Kozlowski Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ > This is exactly what it is mean to do. The problem was due to the > usage of the SWB algortithm by the built in Random[] for generating > random reals. RandomReplace makes Mathematica use the Wolfran CA > random number generator, which Mathematica uses for generating random > integers instead of the SWB. This cures the problem reported int > hat message. Have you got any reason to think it does not? > Andrzej >> *This message was transferred with a trial version of CommuniGate(tm) >> Pro* >> Hi andrej >> thank you so much for making your package available. >> I think I may have found another problem... (may have >> found being operative phrase, or non-operative for >> that matter) === Subject: Re: Re: normal distribution random number generation This is exactly what it is mean to do. The problem was due to the usage of the SWB algortithm by the built in Random[] for generating random reals. RandomReplace makes Mathematica use the Wolfran CA random number generator, which Mathematica uses for generating random integers instead of the SWB. This cures the problem reported int hat message. Have you got any reason to think it does not? Andrzej > Hi andrej > thank you so much for making your package available. > I think I may have found another problem... (may have > found being operative phrase, or non-operative for > that matter) > hl=en&lr=&newwindow=1&safe=off&threadm=a5t1fq%245vt%241%40smc.vnet.net& > rnum=1&prev=/ > groups%3Fhl%3Den%26lr%3D%26newwindow%3D1%26safe%3Doff%26q%3Dchange%2Bth > is%2Bnumber%2Bto%2Bget%2Banother%2Brandom%2Bsequence%26meta%3Dgroup%253 > Dcomp.soft-sys.math.mathematica > shows a thread dealing with random reals and getting a > much smaller frequency at position 24 than others > positions. > Daniel posted a work around showing the use of Random > Integers to fix the problem, which as far I > understand, the Random replacement also implements. > It seems the RandomReplacement doesn't take care of > the appearance of the lower than expected frequency at > position 24(or interval 24 as the OP had noted). > I must be missing something. > sean >> *This message was transferred with a trial version >> of CommuniGate(tm) Pro* >> I think I have now fixed the problem reported by >> Mark Fisher. The new >> version of the RandomReplacement now works like >> this: >> SeedRandom[5] >> Timing[First[Table[Random[],{10000}]]] >> {0.01 Second,0.786599} >> <> Timing[First[Table[Random[],{10000}]]] >> {0.02 Second,0.409222} >> As you can see there is a loss of speed involved. >> There may also be >> still some as yet undiscovered problems. However, >> the new package is >> available form my sites, though I still should write >> some documentation >> of the latest changes (a few bugs in the previous >> version have also >> been fixed). >> Andrzej Kozlowski >> Andrzej Kozlowski >> Chiba, Japan >> http://www.akikoz.net/~andrzej/ >> http://www.mimuw.edu.pl/~akoz/ >*This message was transferred with a trial version >> of CommuniGate(tm) >Pro* >It's clearly because of packed arrays: ><PackedArrayQ[Table[Random[],{249}]] >False >PackedArrayQ[Table[Random[],{250}]] >True >Obviously Mathematica uses a different method of >> generating random >packed arrays. There are various ways of getting >> round this (e.g. >constructing lists as joins of lists of length >> less than 250 etc) but >one will loose the benefits of packed arrays and >> with that, presumably, >a lot of speed. This seems to be something that >> only WRI can change. >Note however that not all situations in which one >> uses Random[] require >generating this type of lists. >Moreover, for problems involving the normal >> distribution it seems to me >that using the Marsaglia generator gives good >> results even with the >built in Random[]. But certainly we should hope >> that something will >finally be done do deal with this issue in version >> 6. >Andrzej >>He's right! How the devil does that happen? >> >>Here's a test, with Andrzej's package loaded in >> my Init file. >> >>First, with n=250: >> >>Quit >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Now, with n=249: >> >>Quit >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.656099 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.0708373 >> >>Bobby >> >> Fisher >> >FYI: I've just a little testing and I find that >> Mathematica ignors >the user >defined rules for Random in Table[Random[],{n}] >> when n >= 250. > >>The problem is not actually with the way >> Mathematica's >>NormalDistribution but with the uniformly >> distributed Random[] >>function. >>NormalDistribution itself is generated (in the >> package >>Statistics`NormalDistribution`) by means of the >> very classical so >>called Boox-Muller method (although actually >> the Marsaglia variant >>below works better). You can try downolading my >> little >>RandomReplacement package form one of my web >> sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ >> in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ in >> Poland >> >>The package is based on the post of daniel >> Lichtblau, which explains >>the nature of the problem: >> >>msg00088.html> >> >> >> >>The package is named init.m and can be loaded >> automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned with >> normal distributions >>it >>may be enough to the following. First load the >> (unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will >> replace the Box-Muller >>generator by the Marsaglia one. I have found >> that this is usually >>enough. But if your problem still remains try >> the RandomReplacement >>package. (Or you can use both of course). Here >> is the Marsaglia code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> >> While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial >> version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in >> Mathematica's normal >distribution random number generator. The >> problem arises when I >look >at the distribution of averages of a list of >> theses numbers. That >is, >I generate 1000 numbers and take their >> average. I do this a number >of >times and the plot a frequency distribution. >> Consistently it seems >to >be skewed positive. Specifically, the number >> of occurrences less >than >3 standard deviations is consistent with the >> expected number, but >the >number greater than 3 is always larger (in >> some cases about twice >the >expected number). > >I was wondering if anyone else has noticed >> this and knows of a fix. >Also, does anyone have code for a good quality >> normal distribution >random number generator? > >Chris > >> >> > > > > >> >> >> >>-- >>DrBob@bigfoot.com >>www.eclecticdreams.net > > __________________________________ > Do you Yahoo!? > Yahoo! Mail Address AutoComplete - You start. We finish. > http://promotions.yahoo.com/new_mail === Subject: Re: Re: normal distribution random number generation Hi andrej thank you so much for making your package available. I think I may have found another problem... (may have found being operative phrase, or non-operative for that matter) shows a thread dealing with random reals and getting a much smaller frequency at position 24 than others positions. Daniel posted a work around showing the use of Random Integers to fix the problem, which as far I understand, the Random replacement also implements. It seems the RandomReplacement doesn't take care of the appearance of the lower than expected frequency at position 24(or interval 24 as the OP had noted). I must be missing something. sean > I think I have now fixed the problem reported by > Mark Fisher. The new > version of the RandomReplacement now works like > this: > SeedRandom[5] > Timing[First[Table[Random[],{10000}]]] > {0.01 Second,0.786599} > < Timing[First[Table[Random[],{10000}]]] > {0.02 Second,0.409222} > As you can see there is a loss of speed involved. > There may also be > still some as yet undiscovered problems. However, > the new package is > available form my sites, though I still should write > some documentation > of the latest changes (a few bugs in the previous > version have also > been fixed). > Andrzej Kozlowski > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ > *This message was transferred with a trial version > of CommuniGate(tm) > Pro* > It's clearly because of packed arrays: > < PackedArrayQ[Table[Random[],{249}]] > False > PackedArrayQ[Table[Random[],{250}]] > True > Obviously Mathematica uses a different method of > generating random > packed arrays. There are various ways of getting > round this (e.g. > constructing lists as joins of lists of length > less than 250 etc) but > one will loose the benefits of packed arrays and > with that, presumably, > a lot of speed. This seems to be something that > only WRI can change. > Note however that not all situations in which one > uses Random[] require > generating this type of lists. > Moreover, for problems involving the normal > distribution it seems to me > that using the Marsaglia generator gives good > results even with the > built in Random[]. But certainly we should hope > that something will > finally be done do deal with this issue in version > 6. > Andrzej >> He's right! How the devil does that happen? >> >> Here's a test, with Andrzej's package loaded in > my Init file. >> >> First, with n=250: >> >> Quit >> SeedRandom[5] >> Table[Random[],{250}]; >> Last@% >> >> 0.107874 >> >> Unprotect[Random]; >> Clear@Random >> SeedRandom[5] >> Table[Random[],{250}]; >> Last@% >> >> 0.107874 >> >> Now, with n=249: >> >> Quit >> SeedRandom[5] >> Table[Random[],{249}]; >> Last@% >> >> 0.656099 >> >> Unprotect[Random]; >> Clear@Random >> SeedRandom[5] >> Table[Random[],{249}]; >> Last@% >> >> 0.0708373 >> >> Bobby >Fisher >> >FYI: I've just a little testing and I find that > Mathematica ignors >the user >defined rules for Random in Table[Random[],{n}] > when n >= 250. > >>The problem is not actually with the way > Mathematica's >>NormalDistribution but with the uniformly > distributed Random[] >>function. >>NormalDistribution itself is generated (in the > package >>Statistics`NormalDistribution`) by means of the > very classical so >>called Boox-Muller method (although actually > the Marsaglia variant >>below works better). You can try downolading my > little >>RandomReplacement package form one of my web > sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ > in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ in > Poland >> >>The package is based on the post of daniel > Lichtblau, which explains >>the nature of the problem: >> >> >msg00088.html> >> >> >> >>The package is named init.m and can be loaded > automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned with > normal distributions >>it >>may be enough to the following. First load the > (unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will > replace the Box-Muller >>generator by the Marsaglia one. I have found > that this is usually >>enough. But if your problem still remains try > the RandomReplacement >>package. (Or you can use both of course). Here > is the Marsaglia code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >> Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> > While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial > version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in > Mathematica's normal >distribution random number generator. The > problem arises when I >look >at the distribution of averages of a list of > theses numbers. That >is, >I generate 1000 numbers and take their > average. I do this a number >of >times and the plot a frequency distribution. > Consistently it seems >to >be skewed positive. Specifically, the number > of occurrences less >than >3 standard deviations is consistent with the > expected number, but >the >number greater than 3 is always larger (in > some cases about twice >the >expected number). > >I was wondering if anyone else has noticed > this and knows of a fix. >Also, does anyone have code for a good quality > normal distribution >random number generator? > >Chris > >> >> > > > > >> >> >> >> -- >> DrBob@bigfoot.com >> www.eclecticdreams.net >> __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail === Subject: Re: Re: normal distribution random number generation I know. I now have some ideas about how to make it a bit faster, but need to test them first. But there is no way it can ever be as fast as the built-in Random. I do hope the decision makers at WRI take this issue more seriously and do something about it in Mathematica 6. As computers grow faster the problem is becoming more visible and the number of users affected by it seems to be growing. Andrzej > The speed difference can be pretty dramatic: > Quit > a=First@Timing[Table[Random[Real,{0,1000}],{10^6}];] > < b=First@Timing[Table[Random[Real,{0,1000}],{10^6}];] > b/a > 0.375 Second > 10.078 Second > 26.8747 > I can probably live with it, however, in cases where I'm concerned > about built-in Random's non-random behavior. > Bobby >> I think I have now fixed the problem reported by Mark Fisher. The new >> version of the RandomReplacement now works like this: >> SeedRandom[5] >> Timing[First[Table[Random[],{10000}]]] >> {0.01 Second,0.786599} >> <> Timing[First[Table[Random[],{10000}]]] >> {0.02 Second,0.409222} >> As you can see there is a loss of speed involved. There may also be >> still some as yet undiscovered problems. However, the new package is >> available form my sites, though I still should write some >> documentation >> of the latest changes (a few bugs in the previous version have also >> been fixed). >> Andrzej Kozlowski >> Andrzej Kozlowski >> Chiba, Japan >> http://www.akikoz.net/~andrzej/ >> http://www.mimuw.edu.pl/~akoz/ >It's clearly because of packed arrays: ><PackedArrayQ[Table[Random[],{249}]] >False >PackedArrayQ[Table[Random[],{250}]] >True >Obviously Mathematica uses a different method of generating random >packed arrays. There are various ways of getting round this (e.g. >constructing lists as joins of lists of length less than 250 etc) but >one will loose the benefits of packed arrays and with that, >presumably, >a lot of speed. This seems to be something that only WRI can change. >Note however that not all situations in which one uses Random[] >require >generating this type of lists. >Moreover, for problems involving the normal distribution it seems to >me >that using the Marsaglia generator gives good results even with the >built in Random[]. But certainly we should hope that something will >finally be done do deal with this issue in version 6. >Andrzej >>He's right! How the devil does that happen? >> >>Here's a test, with Andrzej's package loaded in my Init file. >> >>First, with n=250: >> >>Quit >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{250}]; >>Last@% >> >>0.107874 >> >>Now, with n=249: >> >>Quit >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.656099 >> >>Unprotect[Random]; >>Clear@Random >>SeedRandom[5] >>Table[Random[],{249}]; >>Last@% >> >>0.0708373 >> >>Bobby >> >> >FYI: I've just a little testing and I find that Mathematica ignors >the user >defined rules for Random in Table[Random[],{n}] when n >= 250. > >>The problem is not actually with the way Mathematica's >>NormalDistribution but with the uniformly distributed Random[] >>function. >>NormalDistribution itself is generated (in the package >>Statistics`NormalDistribution`) by means of the very classical so >>called Boox-Muller method (although actually the Marsaglia variant >>below works better). You can try downolading my little >>RandomReplacement package form one of my web sites: >> >>http://www.akikoz.net/~andrzej//Mathematica/ in Japan >> >>or >> >>http://www.mimuw.edu.pl/~akoz/Mathematica/ in Poland >> >>The package is based on the post of daniel Lichtblau, which >>explains >>the nature of the problem: >> >>>msg00088.html> >> >> >> >>The package is named init.m and can be loaded automatically at the >>start of each Mathematica session. >>However, in fact if you are only concerned with normal >>distributions >>it >>may be enough to the following. First load the (unmodified) >>NormalDistribution package using >> >><> >>and then evaluate the code below. It will replace the Box-Muller >>generator by the Marsaglia one. I have found that this is usually >>enough. But if your problem still remains try the >>RandomReplacement >>package. (Or you can use both of course). Here is the Marsaglia >>code >>for normal distribution: >> >> >>Statistics`NormalDistribution`Private`normal= >> Compile[{{mu,_Real},{sigma,_Real},{q1,_Real},{q2,_Real}}, >> Module[{va=1.,vb,rad=2.,den=1.}, >> While[rad>=1.,va=2.*Random[]-1.;vb=2.*Random[]-1.; >> rad=va*va+vb*vb]; >> den=Sqrt[-2.*(Log[rad]/rad)]; >> mu+sigma*va*den]]; >> >> >> >> >> >*This message was transferred with a trial version of >CommuniGate(tm) >Pro* > >Recently I have encountered a problem in Mathematica's normal >distribution random number generator. The problem arises when I >look >at the distribution of averages of a list of theses numbers. >That >is, >I generate 1000 numbers and take their average. I do this a >number >of >times and the plot a frequency distribution. Consistently it >seems >to >be skewed positive. Specifically, the number of occurrences less >than >3 standard deviations is consistent with the expected number, but >the >number greater than 3 is always larger (in some cases about twice >the >expected number). > >I was wondering if anyone else has noticed this and knows of a >fix. >Also, does anyone have code for a good quality normal >distribution >random number generator? > >Chris > >> >> > > > > >> >> >> >>-- >>DrBob@bigfoot.com >>www.eclecticdreams.net >-- > DrBob@bigfoot.com > www.eclecticdreams.net === Subject: Re: Question about derivatives > I want to treat a function abstractly, I know that it is a function > of n > variables. I wish to take its derivative after addition or > multiplication > with another function. However Derivative does not return what I > expect. > Derivative[0,1][f+g] gives (f+g)^(0,1) instead of f^(0,1)+g^(0,1) and > Derivative[0,1][fg] gives (fg)^(0,1) instead of f^(0,1)g+g^(0,1)f. > Now > perhaps I'm going about my problem in the wrong way, if I am please > tell me. > I also have some other questions about Derivative, > Derivative[0,1][Composition[f,g]] gives f^(0,1)(g)g^(0,1), the correct > result, why does Derivative know the chain rule and not the product > rule? > Also, in order to get the correct behaviour for Derivative[0,1][f+g], > I can > use the Map function, that is Map[Derivative[0,1],f+g] returns f^(0,1) > +g^(0,1). Which is fine except that if I have the function 1+f and > apply > the same command to it I get 0& + f^(0,1), instead of f^(0,1). > Clearly > this is because of the presence of the command Function[0], however I > have > been unable to find a function that fixes this problem. > In essence I want to do vector operations of the ring of functions, > but find > that doing this in Mathematica is hard. How can I do this easily? > Surely > someone else has figured out a convenient way of do this. > Ben This question has been asked and answered many times (including quite recently). The answer I am posting I have also already posted several times. For reasons which I do not want to argue about again Mathematica does not implement the algebra of functions. that is, if f and g are functions, whether defined using patterns as in f[x_]:= or as pure functions using Function, f+g, f*g etc. are not is not treated by Mathematica as functions. If you wan to change this you can always do so: Unprotect[Times, Plus, Power]; (a_?NumericQ*f_.)[x__] := a f[x]; (f_ + g_)[x__] := f[x] + g[x]; (f_*g_)[x__] := f[x]*g[x]; (f_^n_?NumericQ)[x__] := f[x]^n Protect[Times, Plus, Power]; Now you will get: Derivative[0, 1][f + g] Derivative[0, 1][f][#1, #2] + Derivative[0, 1][g][#1, #2] & Derivative[0, 1][f*g] g[#1, #2]*Derivative[0, 1][f][#1, #2] + f[#1, #2]* Derivative[0, 1][g][#1, #2] & You have to be aware however that in general it is not a good idea to modify basic functions such as Times, Plus, Power. They are used by practically every other Mathematica function and you can never tell if having additional rules or modifications like those above will not produce unexpected and unintended behaviour. Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Concatenate matrices Hi all Does someone know if there is a function in Mathematica to simply concatenate matrices (provided their dimensions are right). Example: / e11 e12 e13 E = | e21 e22 e23 | e31 e32 e33 / / f11 f12 F = | f21 f22 | f31 f32 / I'd like to have: / e11 e12 e13 f11 f12 R = | e21 e22 e23 f21 f22 | e31 e32 e33 f31 f32 / Any ideas? T. -- Thomas Guignard Laboratory of Electromagnetics and Acoustics Swiss Federal Institute of Technology, Lausanne === Subject: Re: Concatenate matrices > Hi all > Does someone know if there is a function in Mathematica to simply > concatenate matrices (provided their dimensions are right). > Example: > / e11 e12 e13 > E = | e21 e22 e23 | > e31 e32 e33 / > / f11 f12 > F = | f21 f22 | > f31 f32 / > I'd like to have: > / e11 e12 e13 f11 f12 > R = | e21 e22 e23 f21 f22 | > e31 e32 e33 f31 f32 / Consider Transpose. A = Table[Subscript[a,i + 10 k] , {i, 1, 2}, {k, 1, 3}] B = Table[Subscript[b,i + 10 k] , {i, 1, 2}, {k, 1, 2}] cc = Flatten/@ Transpose[{A,Transpose[B]}] -- Roland Franzius === Subject: Re: Concatenate matrices > Hi all > Does someone know if there is a function in Mathematica to simply > concatenate matrices (provided their dimensions are right). Hi Thomas, I use these functions: JoinMatrices[m_?MatrixQ,l_?MatrixQ]:= Join[Transpose[m],Transpose[l]]//Transpose AddCol[m_?MatrixQ,l_?VectorQ]:=Append[Transpose[m],l]//Transpose AddCol[m_?VectorQ,l_?VectorQ]:=Append[{m},l]//Transpose m = {{1, 3}, {2, 4}}; l = {5, 6}; n = {{5, 7}, {6, 8}}; JoinMatrices[m,n] AddCol[m,l] AddCol[l,l] Out= {{1,3,5,7},{2,4,6,8}} {{1,3,5},{2,4,6}} {{5,5},{6,6}} Marcus -- The truth is rarely pure and never simple. -- Oscar Wilde === Subject: Re: Concatenate matrices Try this: << LinearAlgebra`MatrixManipulation` MatrixForm[e = {{e11, e12, e13}, {e21, e22, e23}, {e31, e32, e33}}] MatrixForm[f = {{f11, f12}, {f21, f22}, {f31, f32}}] MatrixForm[BlockMatrix[{{e, f}}]] Steve Luttrell > Hi all > Does someone know if there is a function in Mathematica to simply > concatenate matrices (provided their dimensions are right). > Example: > / e11 e12 e13 > E = | e21 e22 e23 | > e31 e32 e33 / > / f11 f12 > F = | f21 f22 | > f31 f32 / > I'd like to have: > / e11 e12 e13 f11 f12 > R = | e21 e22 e23 f21 f22 | > e31 e32 e33 f31 f32 / > Any ideas? > T. > -- > Thomas Guignard > Laboratory of Electromagnetics and Acoustics > Swiss Federal Institute of Technology, Lausanne === Subject: Re: Concatenate matrices > Hi all > Does someone know if there is a function in Mathematica to simply > concatenate matrices (provided their dimensions are right). > Example: > / e11 e12 e13 > E = | e21 e22 e23 | > e31 e32 e33 / > / f11 f12 > F = | f21 f22 | > f31 f32 / > I'd like to have: > / e11 e12 e13 f11 f12 > R = | e21 e22 e23 f21 f22 | > e31 e32 e33 f31 f32 / I don't know of a simple built-in function to do this, but it is easy to write your own. In[1]:= a={{a11,a12,a13},{a21,a22,a23}}; In[2]:= b={{b11,b12},{b21,b22}}; In[3]:= concatenateMat[matA_?MatrixQ,matB_?MatrixQ]:=MapThread[Join,{matA,matB},1] In[4]:= concatenateMat[a,b] Out[4]= {{a11,a12,a13,b11,b12},{a21,a22,a23,b21,b22}} -- Curt Fischer === Subject: Concatenate matrices Hi all Does somebody know if there's a simple function in mathematica to concatenate matrices? Example: / 1 2 3 A = | 3 4 5 | 5 6 7 / / 11 12 B = | 13 14 | 15 16 / I'd like to have / 1 2 3 11 12 R = | 3 4 5 13 14 | 5 6 7 15 16 / And so on. See what I mean? T. -- Thomas Guignard Laboratory of Electromagnetics and Acoustics Swiss Federal Institute of Technology, Lausanne === Subject: Re: PDE Notation options (one works the other does not) The second call to NDSolve fails because: D[C[20, t], x] == 0 True That's accurate, since C[20,t] isn't a function of x. You mean, I suppose, to differentiate with respect to C's first (unnamed) variable, evaluated when that (unnamed) variable is equal to 20. But that's what Derivative does in the other call to NDSolve. Derivative[1, 0][C][20, t] == 0 Derivative[1, 0][C][20, t] == 0 By the way, it's a very bad idea to use C as a variable like this. Look up C in Help, and you'll see that it's often used to represent arbitrary constants of integration, arbitrary functions, et cetera. Even if you don't see it happening explicitly, it can happen in the background, when NDSolve calls some other function. To avoid conflicts with built-in symbols, you should NEVER start your own variables with capitals. Bobby > Bob > Sorry for the gobbledygook posted earlier. I've installed your Palette which makes all the difference, in particular it shows the difference in the way Mathematica is parsing the information using Derivative[] in the first example and D[] in the second! Aren't they the same? > The first call to NDSolve works whereas the second does not. > In[16]:= > [Lambda] = 0.1; > V = 2.; > [Beta] = 0.3; > C0 = 5; > L = 20; > solution = C /. First[NDSolve[ > {D[C[x, t], t] == (-[Lambda])*C[x, t] - > V*D[C[x, t], x] + [Beta]*D[C[x, t], > {x, 2}], C[x, 0] == 0, > C[0, t] == C0*(1 - Exp[-t]), > Derivative[1, 0][C][20, t] == 0}, C, > {x, 0, 20}, {t, 0, 10}, > MaxStepFraction -> 1/50, AccuracyGoal - 5]] > In[5]:= > solution = C /. First[ > NDSolve[{D[C[x, t], t] == > (-[Lambda])*C[x, t] - > V*D[C[x, t], x] + > [Beta]*D[C[x, t], > {x, 2}], C[x, 0] == > 0, C[0, t] == > C0*(1 - Exp[-t]), > D[C[20, t], x] == 0}, > C, {x, 0, 20}, > {t, 0, 10}, > MaxStepFraction -> 1/50, > AccuracyGoal -> 5]] > Robert Prince-Wright > Risk Management Engineer, EP Americas > Shell Exploration & Production Company > One Shell Square > P. O. Box 61933 > New Orleans > LA 70161-1933 > United States of America > Tel: +1 504 728 7720 > Fax: +1 504 728 4573 > Email: robert.prince-wright@shell.com > Internet: http://www.shell.com -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: PDE Notation options (one works the other does not) Must you paste unreadable junk into e-mail? I can't paste it back into Mathematica without errors. I recommend the Copy as InputForm palette: http://eclecticdreams.net/DrBob/copy_as_inputform.htm Bobby > Hello Group. > Can someone explain why 'format 1' below works but 'format 2' does not. > Also how do you know when to use the different Notations for partial > derivatives. > Bob > !(* > RowBox[{solution, =, > RowBox[{u, /., > RowBox[{First, [, [IndentingNewLine], > RowBox[{NDSolve, [, [IndentingNewLine], > RowBox[{ > RowBox[{{, [IndentingNewLine], > RowBox[{(?_t u[x, t] == (-0.1) > u[x, t] - 2 ?_x u[x, t] + 0.3 ?_{x, 2}u[x, t]), ,, > [IndentingNewLine], (u[x, 0] == 0), ,, > [IndentingNewLine], (u[0, > t] == 5 ((1 - Exp[(-t)]))), ,, = > [IndentingNewLine], > RowBox[{ > RowBox[{ > SuperscriptBox[u, > TagBox[((1, 0)), > Derivative], > MultilineFunction->None], [, (20, t), > ]}], ==, 0}]}], [IndentingNewLine], }}], ,, > [IndentingNewLine], u, ,, ({x, 0, 20}), ,, > ({ > t, 0, 10})}], ]}], ]}]}]}]) > !(solution = u /. > First[[IndentingNewLine]NDSolve[[IndentingNewLine]{ > [IndentingNewLine]?_t u[x, t] == (-0.1) u[x, t] - 2 ?_x > u[x, > t] + 0.3 ?_{x, 2}u[x, > t], [IndentingNewLine]u[x, 0] == > 0, [IndentingNewLine]u[0, t] == 5 ((1 - > Exp[(- > t)])), [IndentingNewLine]?_x u[20, t] == > 0[IndentingNewLine]}, [IndentingNewLine]u, {x, 0, > 20}, {t, > 0, 10}]]) > Robert Prince-Wright > Risk Management Engineer, EP Americas > Shell Exploration & Production Company > One Shell Square > P. O. Box 61933 > New Orleans > LA 70161-1933 > United States of America > Tel: +1 504 728 7720 > Fax: +1 504 728 4573 > Email: robert.prince-wright@shell.com > Internet: http://www.shell.com -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: PDE Notation options (one works the other does not) Hello Group. Can someone explain why 'format 1' below works but 'format 2' does not. Also how do you know when to use the different Notations for partial derivatives. Bob !(* RowBox[{solution, =, RowBox[{u, /., RowBox[{First, [, [IndentingNewLine], RowBox[{NDSolve, [, [IndentingNewLine], RowBox[{ RowBox[{{, [IndentingNewLine], RowBox[{(?_t u[x, t] == (-0.1) u[x, t] - 2 ?_x u[x, t] + 0.3 ?_{x, 2}u[x, t]), ,, [IndentingNewLine], (u[x, 0] == 0), ,, [IndentingNewLine], (u[0, t] == 5 ((1 - Exp[(-t)]))), ,, = [IndentingNewLine], RowBox[{ RowBox[{ SuperscriptBox[u, TagBox[((1, 0)), Derivative], MultilineFunction->None], [, (20, t), ]}], ==, 0}]}], [IndentingNewLine], }}], ,, [IndentingNewLine], u, ,, ({x, 0, 20}), ,, ({ t, 0, 10})}], ]}], ]}]}]}]) !(solution = u /. First[[IndentingNewLine]NDSolve[[IndentingNewLine]{ [IndentingNewLine]?_t u[x, t] == (-0.1) u[x, t] - 2 ?_x u[x, t] + 0.3 ?_{x, 2}u[x, t], [IndentingNewLine]u[x, 0] == 0, [IndentingNewLine]u[0, t] == 5 ((1 - Exp[(- t)])), [IndentingNewLine]?_x u[20, t] == 0[IndentingNewLine]}, [IndentingNewLine]u, {x, 0, 20}, {t, 0, 10}]]) Robert Prince-Wright Risk Management Engineer, EP Americas Shell Exploration & Production Company One Shell Square P. O. Box 61933 New Orleans LA 70161-1933 United States of America Tel: +1 504 728 7720 Fax: +1 504 728 4573 Email: robert.prince-wright@shell.com Internet: http://www.shell.com === Subject: NewtonZero never comes down I've tried several ways to find better values for zeta zeros fast and easy... FindRoot[] just doesn't give much accuracy. NewtonZero[] tends to just spin it's wheels on my machine.... Here's what I came up with that gets about 20 places and pretty fast relatively. It's much better than FindRoot[] anyway! The zeta zeros all seem to be transcendental irrational numbers and are harder to calculate than most numbers in modern number theory. (* finding Zeta Zero roots*) (* using approximation from analyitic continuation on 0<=z<=1 strip where zeta dosesn't converge*) Clear[RSzeta,t,g3,f,g,a] RSzeta[t_]=RiemannSiegelZ[t]/Exp[I*RiemannSiegelTheta[t]] Digits=10000 t=(2 Sqrt[2])*25*Pi^2*Sqrt[n]/(6*Sqrt[Digits])-16 (* gives the zeta zeros given in Jahnke-Emde Tables of Functions, Dover*) g3=Delete[Union[Table[If[N[Abs[RSzeta[t]]]<0.01,N[t,20],0],{n,1,Digits}]],1] Dimensions[g3] ListPlot[g3,PlotJoined->True] (* definition of Newton function*) f[x_]:=N[x-Zeta[x]/Zeta'[x],20] (* ten iterations toward the zero*) g[x_]:=NestList[f,1/2+I*x,10][[10]] (* values starting at the continuation values approximated*) a=Table[g[g3[[n]]],{n,1,Dimensions[g3][[1]]}] ListPlot[Im[a],PlotJoined->True] Respectfully, Roger L. Bagula tftn@earthlink.net, 11759Waterhill Road, Lakeside,Ca 92040-2905,tel: 619-5610814 : alternative email: rlbtftn@netscape.net URL : http://home.earthlink.net/~tftn === Subject: Integrate vs. NIntegrate Which one is the correct answer? f=2+Cos[2 x]+ I*Sin[2 x]; Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] //InputForm]; 0.34657359027997264 + 1.5707963267948966*I Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; 0.6931471805599428 + 0.*I I believe the second one, have doubts about the first. === Subject: Re: Integrate vs. NIntegrate I get a different answer here (with version 5.0.1): N[Simplify[Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]]//InputForm 0.6931471805599453 NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi)//InputForm 0.693147180559943 + 0.*I Bobby > Which one is the correct answer? > f=2+Cos[2 x]+ I*Sin[2 x]; > Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] //InputForm]; > 0.34657359027997264 + 1.5707963267948966*I > Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; > 0.6931471805599428 + 0.*I > I believe the second one, have doubts about the first. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Integrate vs. NIntegrate > Which one is the correct answer? > f=2+Cos[2 x]+ I*Sin[2 x]; > Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] //InputForm]; > 0.34657359027997264 + 1.5707963267948966*I > Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; > 0.6931471805599428 + 0.*I > I believe the second one, have doubts about the first. The 2nd answer of Log[2] is verified by a brute force Gauss-Legendre numerical integrator used in HWs: NIntGauss3[fx_,x_,lower_,upper_,n_]:= Module[{fint,d,x1,x2,f, g1=N[(1+Sqrt[3/5])/2],g2=N[1/2],g3=N[(1-Sqrt[3/5])/2]}, d=(upper-lower)/n; fint=0; f=fx; Do[ x1=lower+(i-1)*d; x2=lower+i*d; fint +=(N[5*f/.x->N[x1*g1+x2*g3]]+ N[8*f/.x->N[(x1+x2)/2]]+ N[5*f/.x->N[x1*g3+x2*g1]])*N[d/18], {i,1,n}]; Return[fint]]; f=2+Cos[2 x]+ I*Sin[2 x]; Print[ NIntGauss3[Log[f],x,-Pi,Pi,200]/(2*Pi) //InputForm]; 0.6931471805599455 - 3.969653887102225*^-17*I Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; 0.6931471805599428 + 0.*I Print[ N[Log[2]] //InputForm]; 0.6931471805599453 so NIntegrate[] gives 14 correct digits. === Subject: Re: Integrate vs. NIntegrate > Which one is the correct answer? > f=2+Cos[2 x]+ I*Sin[2 x]; > Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] //InputForm]; > 0.34657359027997264 + 1.5707963267948966*I > Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; > 0.6931471805599428 + 0.*I > I believe the second one, have doubts about the first. The second one is correct (except for the last few decimal places). What version are you using? In version 5.0.0.0, f = 2 + Cos[2*x] + I*Sin[2*x]; Simplify[Integrate[Log[f], {x, -Pi, Pi}]/(2*Pi)] Log[2] N[%] 0.6931471805599453 David Cantrell === Subject: Re: Integrate vs. NIntegrate > Which one is the correct answer? > f=2+Cos[2 x]+ I*Sin[2 x]; > Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] //InputForm]; > 0.34657359027997264 + 1.5707963267948966*I > Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; > 0.6931471805599428 + 0.*I > I believe the second one, have doubts about the first. Carlos, since you integrate twice along the unit circle with center 2 and log(conj(z))==conj(log(z)) on this path, the imaginary part has to cancel out. (or I'm wrong?) You can easily verify it: Integrate[Log[2 + Exp[2*I*x]], {x, -Pi, Pi}]/(2*Pi) Peter -- Peter Pein, Berlin === Subject: Re: Re: Very basic question: Zoom into a 2-D plot with the mouse Hi Rainer, Follow the link http://library.wolfram.com/infocenter/MathSource/191/ to MathSource, and you find a handy palette designed for this purpose. It is named ImageRegionPalette.nb. It controls the ImageRegion parameter of the picture, and it is written by Timothy Lottes. Ingolf Dahl Sweden -----Original Message----- >I have a very basic question: Does Mathematica offer the possibility >to zoom into a plot (e.g. a simple 2-D plot like the result of >Plot[Sin[x],{x,0,2*Pi}]) by using the mouse? I am talking about a >feature that many other tools offer. I know that one can >use the PlotRange option to zoom into a plot region, but it can be >quite awkward for every zoom to use this option. >Rainer === Subject: Re: Concatenate matrices << > Hi all > Does somebody know if there's a simple function in mathematica to > concatenate matrices? > Example: > / 1 2 3 > A = | 3 4 5 | > 5 6 7 / > / 11 12 > B = | 13 14 | > 15 16 / > I'd like to have > / 1 2 3 11 12 > R = | 3 4 5 13 14 | > 5 6 7 15 16 / > And so on. See what I mean? > T. > -- > Thomas Guignard > Laboratory of Electromagnetics and Acoustics > Swiss Federal Institute of Technology, Lausanne You can use AppendRows (and AppendColumns) form the package << LinearAlgebra`MatrixManipulation` A = {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}}; B = {{11, 12}, {13, 14}, {15, 16}}; AppendRows[A, B] {{1, 2, 3, 11, 12}, {3, 4, 5, 13, 14}, {5, 6, 7, 15, 16}} Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Re: Integrate vs. NIntegrate This appears to be version dependent. $Version f=2+Cos[2 x]+I*Sin[2 x]; N[Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]//InputForm 0.6931471805599453 NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi)//InputForm 0.693147180559943 + 0.*I Bob Hanlon === > Subject: Integrate vs. NIntegrate > Which one is the correct answer? > f=2+Cos[2 x]+ I*Sin[2 x]; > Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] //InputForm]; > 0.34657359027997264 + 1.5707963267948966*I > Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) //InputForm]; > 0.6931471805599428 + 0.*I > I believe the second one, have doubts about the first. === Subject: Re: Concatenate matrices These are all equivalent Table[Join[A[[n]],B[[n]]],{n,Length[A]}] Join[#[[1]],#[[2]]]& /@ Transpose[{A,B}] Join[Sequence@@##]& /@ Transpose[{A,B}] Using an add-on package: Needs[LinearAlgebra`MatrixManipulation`]; AppendRows[A,B] Bob Hanlon === > Subject: Concatenate matrices > Hi all > Does somebody know if there's a simple function in mathematica to > concatenate matrices? > Example: > / 1 2 3 > A = | 3 4 5 | > 5 6 7 / > / 11 12 > B = | 13 14 | > 15 16 / > I'd like to have > / 1 2 3 11 12 > R = | 3 4 5 13 14 | > 5 6 7 15 16 / > And so on. See what I mean? > T. > -- > Thomas Guignard > Laboratory of Electromagnetics and Acoustics > Swiss Federal Institute of Technology, Lausanne === Subject: Re: Concatenate matrices Thomas, Use the LinearAlgebra`MatrixManipulation` standard package. Needs[LinearAlgebra`MatrixManipulation`] emat = Array[e, {3, 3}]; fmat = Array[f, {3, 2}]; AppendRows[emat, fmat] or BlockMatrix[{{emat, fmat}}] With a little more work it can also be done outside of the package. Join[Transpose[emat], Transpose[fmat]] // Transpose David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi all Does someone know if there is a function in Mathematica to simply concatenate matrices (provided their dimensions are right). Example: / e11 e12 e13 E = | e21 e22 e23 | e31 e32 e33 / / f11 f12 F = | f21 f22 | f31 f32 / I'd like to have: / e11 e12 e13 f11 f12 R = | e21 e22 e23 f21 f22 | e31 e32 e33 f31 f32 / Any ideas? T. -- Thomas Guignard Laboratory of Electromagnetics and Acoustics Swiss Federal Institute of Technology, Lausanne === Subject: Cursor is deactivated after Ctrl+Alt-combination Hallo, I use Mathematica 4 on a Windows XP SP1 computer. As I have a German (QWERTZ) keyboard, I have to use very often the Ctrl+Alt-combination in order to write characters like brackets or backslashes. The annoying thing is that after I release Ctrl+Alt (precisely: first Alt, then Ctrl), the menu bar gets the focus and therefore the cursor is deactivated (it's still there but it doesn't blink anymore). Apparently, the problem is that Mathematica thinks that I want to do something with the menu because I have pressed alt, but doesn't consider the fact that I have also pressed Ctrl. Another effect is that Mathematica beeps all the time I type one of these special characters. I assume that this is because Mathematica thinks I want to open a menu by a shortcut that doesn't exist. I didn't have this problem on Windows Me. It seems to be quite general, because my TeX-editor (TeXnicCenter) shows the same behaviour and even some Windows applications are slightly behaving like this (they just underline the shortcut letters in the menu bar when releasing ctrl+alt, so it's not that bad). So actually there must be a simple solution. I would be very glad if somebody could help me on this or on the problem with the TeX-editor, Richard Bamler === Subject: Re: Integrate vs. NIntegrate >Which one is the correct answer? >f=2+Cos[2 x]+ I*Sin[2 x]; >Print[ N[Simplify[ Integrate[Log[f],{x,-Pi,Pi}]/(2*Pi)]] >//InputForm]; 0.34657359027997264 + 1.5707963267948966*I >Print[ NIntegrate[Log[f],{x,-Pi,Pi}]/(2*Pi) >//InputForm]; 0.6931471805599428 + 0.*I >I believe the second one, have doubts about the first. When I look at the following plots Plot[Im[Log[f]], {x, -Pi, Pi}]; Plot[Re[Log[f]], {x, -Pi, Pi}]; I see the imaginary portion of f seems to have equal areas above and below the x-axis indicating the imaginary portion of the integral should be near 0. And the plot of the real portion of f is everywhere positive over the range of interest. So, it seems to me clear the first result cannot be correct and I would take the second as correct. Additionall from what others have reported in this forum, it seems whenever there is a disagreement between using N[Integrate[... and NIntegrate[... it is N[Integrate[... that produces the incorrect answer. In fact, this seems to pop up so often here that I would always use NIntegrate when I wanted a numerical answer instead of converting the results of Integrate to a number. -- To reply via email subtract one hundred and four === Subject: table format question I have a table created by the following input: counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; papers = Plus @@ counts; pcts = 100. counts/papers; grades = {A ,A-,B+,B ,B-,C+,C ,C-,D+,D ,F }; TableForm[Transpose[ {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}], TableHeadings -> {None, {Grade, Number, Per Cent}}] 1. How can I get a 0 to display after the decimal point in the last column's first and last rows? (I tried to wrap the entire thing with an obvious PaddedForm expression, but that had the unfortunate effect of giving me decimals in the 2nd column, which should be integers without any decimal point or trailing decimal places whatsoever.) 2. How can I get the numbers in columns 2 and three to be right-justified? (I tried TableAlignments but that didn't seem to do it.) -- 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: table format question Yes, thank you. Bob Hanlon's posting, similar to yours, accomplishes what I need, too. >> ... >> 1. How can I get a 0 to display after the decimal point in the last >> column's first and last rows? (I tried to wrap the entire thing with an >> obvious PaddedForm expression, but that had the unfortunate effect of >> giving me decimals in the 2nd column, which should be integers without >> any decimal point or trailing decimal places whatsoever.) >> 2. How can I get the numbers in columns 2 and three to be >> right-justified? (I tried TableAlignments but that didn't seem to do >> it.) > Does this work? > counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; > papers = Plus @@ counts; > pcts = 100. counts/papers; > grades = {A , A-, B+, B , B-, C+, C , C-, D+, D , F > }; > TableForm[Transpose[ > {grades, NumberForm[#, 3, NumberPadding -> { , }] & /@ counts, > NumberForm[#, {4, 1}, NumberPadding -> { , 0}] & /@ pcts}], > TableHeadings -> {None, {Grade, Number, Per Cent}}] > I think the non-obvious tricks are the space as the first argument to > NumberPadding to produce right-alignment, and the 0 as the second > argument to pad with zeros on the right. -- 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: table format question > counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; > papers = Plus @@ counts; > pcts = 100. counts/papers; > grades = {A ,A-,B+,B ,B-,C+,C ,C-,D+,D ,F }; > TableForm[Transpose[ > {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}], > TableHeadings -> {None, {Grade, Number, Per Cent}}] > 1. How can I get a 0 to display after the decimal point in the last > column's first and last rows? (I tried to wrap the entire thing with > an > obvious PaddedForm expression, but that had the unfortunate effect of > giving me decimals in the 2nd column, which should be integers without > any decimal point or trailing decimal places whatsoever.) > 2. How can I get the numbers in columns 2 and three to be > right-justified? (I tried TableAlignments but that didn't seem to do > it.) Does this work? counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; papers = Plus @@ counts; pcts = 100. counts/papers; grades = {A , A-, B+, B , B-, C+, C , C-, D+, D , F }; TableForm[Transpose[ {grades, NumberForm[#, 3, NumberPadding -> { , }] & /@ counts, NumberForm[#, {4, 1}, NumberPadding -> { , 0}] & /@ pcts}], TableHeadings -> {None, {Grade, Number, Per Cent}}] I think the non-obvious tricks are the space as the first argument to NumberPadding to produce right-alignment, and the 0 as the second argument to pad with zeros on the right. -- Ben Kovitz Humboldt State University === Subject: Re: table format question Use NumberPadding thus NumberForm[#, {4, 1}, NumberPadding -> {, 0}] Steve Luttrell >I have a table created by the following input: > counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; > papers = Plus @@ counts; > pcts = 100. counts/papers; > grades = {A ,A-,B+,B ,B-,C+,C ,C-,D+,D ,F }; > TableForm[Transpose[ > {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}], > TableHeadings -> {None, {Grade, Number, Per Cent}}] > 1. How can I get a 0 to display after the decimal point in the last > column's first and last rows? (I tried to wrap the entire thing with an > obvious PaddedForm expression, but that had the unfortunate effect of > giving me decimals in the 2nd column, which should be integers without > any decimal point or trailing decimal places whatsoever.) > 2. How can I get the numbers in columns 2 and three to be > right-justified? (I tried TableAlignments but that didn't seem to do it.) > -- > 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: vertical scale on Histogram I create a Histogram (from Graphics`Graphics`Histogram) of frequencies of a data set as distributed into 20 categories of equal width. What HistogramScale or other option do I specify, and with what value, so that the tick labels on the vertical axis show the percentage represented by each group? Please try to tell me in plain language: I cannot understand the docs for Histogram in the HelpBrowser. -- 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: Biokmod 3.2 for solving compartmental, biokinetic and ICRP models I release Biokmod 3.2 (standard). It can be downloaded from http://web.usal.es/~guillerm/biokmod.htm Also, there are a webMathematica application of Biokmod called BiokmodWeb (available in http://www3.enusa.es/webMathematica/Public/biokmod.html ). It runs on line, you don't need to download any thing in your computer. It contains most of the main features of the Mathematica Tool Biokmod Biokmod include I.- Functions for solving compartmental models (with application in biokinetic, pharmacokinetic, internal dosimetry and nuclear medicine) I.1) The user can himself define compartmental models obtaining the differential equations, their solutions, graphic representation and Us (disintegrations). I.2) Options for fitting coefficients in linear differential equations are included. human body according ICRP Models II.1) The respiratory tract model (according ICRP 66) for modelling the intake of radioactive aerosols is solved. Gives the Intake Retention Fractions (IRF), their analytical expressions, the Intake Retention Functions (RF), and the graphic representation. II.2) Radioactive intake by injection, ingestion and inhalation in the human body according ICRP models II.3) Acute, Chronic, Continuous (variable in the time) , Multi-Acute and randon intakes can be simulated. II.4) Analytical and numeric solutions are given. II.5) Disintegrations (Us) over at time t -choose by user- are computed analytically (better than using mean residence time). III.- Some tutorials and a complete help is included I will appreciate any comments. Guillermo Sanchez http://web.usal.es/~guillerm/ === Subject: Re: Calculus : limits >> But, as I am sure Bobby Treat would agree, itought to be under Limit. You got THAT right. Bobby > Yes, you are right. But, as I am sure Bobby Treat would agree ;-) , it > ought to be under Limit. The point is that unless you have a reason to > suspect that Limit by default computes directional limits it is > unlikely you will look under Direction to find out. But I have to agree > that I was wrong: the long ago made promise to put this into the > documentation was kept, even though, in my opinion, not in the most > natural way. > Andrzej >> The documentation is there in the front end (at least in Mathematica >> 5.0.1), just not in The Mathematica Book: >> Options[Limit] >> {Analytic -> False, Assumptions :> $Assumptions, Direction -> >> Automatic} >> ?Direction >> Direction is an option for Limit. Limit[expr, x -> x0, Direction -> 1] >> computes the limit as x approaches x0 from smaller values. Limit[expr, >> x >> -> x0, Direction -> -1] computes the limit as x approaches x0 from >> larger values. Direction -> Automatic uses Direction -> -1 except for >> limits at Infinity, where it is equivalent to Direction -> 1. >> >>I'd like to find the limit of >>Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] >> >>I use Mathematica v.5. I get the wrong (??) answer : 1 >> >>While I try to display the graph of this function by using Plot, it >>seems that there is no limit at the point x=0. >>Please help... >> >>Amir >> >Mathematica's answer is correct but ... Limit always computes >directional limits. Thus: >Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> -1] >1 >but >Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> 1] >-1 >So the limits as x goes to 0 form above and form below are different >and thus there is n limit'. >Also, as you see by default Limit computes from above. However, I >still can't find this clearly documented in version 5, even though I >remeber myself (and others) complaining about this lack of >documentation in version 4 (if not earlier). >Andrzej Kozlowski >Chiba, Japan >http://www.akikoz.net/~andrzej/ >http://www.mimuw.edu.pl/~akoz/ >> -- >> 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 -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Calculus : limits Yes, you are right. But, as I am sure Bobby Treat would agree ;-) , it ought to be under Limit. The point is that unless you have a reason to suspect that Limit by default computes directional limits it is unlikely you will look under Direction to find out. But I have to agree that I was wrong: the long ago made promise to put this into the documentation was kept, even though, in my opinion, not in the most natural way. Andrzej > The documentation is there in the front end (at least in Mathematica > 5.0.1), just not in The Mathematica Book: > Options[Limit] > {Analytic -> False, Assumptions :> $Assumptions, Direction -> > Automatic} > ?Direction > Direction is an option for Limit. Limit[expr, x -> x0, Direction -> 1] > computes the limit as x approaches x0 from smaller values. Limit[expr, > -> x0, Direction -> -1] computes the limit as x approaches x0 from > larger values. Direction -> Automatic uses Direction -> -1 except for > limits at Infinity, where it is equivalent to Direction -> 1. >I'd like to find the limit of >Limit[(Abs[Sin[x]-Sin[2 x]]) / x, x->0] >I use Mathematica v.5. I get the wrong (??) answer : 1 >While I try to display the graph of this function by using Plot, it >seems that there is no limit at the point x=0. >Please help... >Amir >> Mathematica's answer is correct but ... Limit always computes >> directional limits. Thus: >> Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> -1] >> 1 >> but >> Limit[Abs[Sin[x] - Sin[2*x]]/x, x -> 0, Direction -> 1] >> -1 >> So the limits as x goes to 0 form above and form below are different >> and thus there is n limit'. >> Also, as you see by default Limit computes from above. However, I >> still can't find this clearly documented in version 5, even though I >> remeber myself (and others) complaining about this lack of >> documentation in version 4 (if not earlier). >> Andrzej Kozlowski >> Chiba, Japan >> http://www.akikoz.net/~andrzej/ >> http://www.mimuw.edu.pl/~akoz/ > -- > 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 === Or this: Needs[Graphics`Graphics`] hst = {97, 90, 91, 98, 93, 100, 90, 98, 91, 93, 98, 93, 97, 93, 80, 95, 93, 99, 96, 80, 98, 85, 94, 98, 96, 88, 93, 92, 88, 97, 90, 90}; Histogram[hst, HistogramCategories -> Range[Min@hst, 1 + Max@hst]] Bobby >> I've only been playing around with the trial version of Mathematica >> for a few hours but I can't figure out how the heck to plot a >> histogram. I have a list of data (below) that I want to plot. The >> range is 80 to 100 and I want 5 bins, across 4 points each. I feel >> that this is a pretty straightforward thing to do, but I can't even >> plot a single histogram, even when I reproduce the samples that they >> give in the math book word for word. The data is below, any help would >> be greatly appreciated. >> 97,90,91,98,93,100,90,98,91,93,98,93,97,93,80,95,93,99,96,80,98,85,94,9 >> 8,96,88,93,92,88,97,90,90 > Needs[Graphics`Graphics`] > hst = {97, > 90, 91, 98, 93, 100, 90, 98, 91, 93, 98, 93, 97, 93, 80, 95, 93, 99, > 96, 80, 98, 85, 94, 98, 96, 88, 93, 92, 88, 97, 90, 90}; > BarChart[Map[{Length[#], #[[1]]} &, Split[Sort[hst]]]] > It is a width=1 histogram. > J.87nos > ---------------------------------------------- > Trying to argue with a politician is like lifting up the head of a > corpse. > (S. Lem: His Master Voice) -- DrBob@bigfoot.com www.eclecticdreams.net === > I've only been playing around with the trial version of Mathematica > for a few hours but I can't figure out how the heck to plot a > histogram. I have a list of data (below) that I want to plot. The > range is 80 to 100 and I want 5 bins, across 4 points each. I feel > that this is a pretty straightforward thing to do, but I can't even > plot a single histogram, even when I reproduce the samples that they > give in the math book word for word. The data is below, any help would > be greatly appreciated. > 97,90,91,98,93,100,90,98,91,93,98,93,97,93,80,95,93,99,96,80,98,85,94,9 > 8,96,88,93,92,88,97,90,90 Needs[Graphics`Graphics`] hst = {97, 90, 91, 98, 93, 100, 90, 98, 91, 93, 98, 93, 97, 93, 80, 95, 93, 99, 96, 80, 98, 85, 94, 98, 96, 88, 93, 92, 88, 97, 90, 90}; BarChart[Map[{Length[#], #[[1]]} &, Split[Sort[hst]]]] It is a width=1 histogram. J.87nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Perhaps you simply forgot to load the package Graphics`Graphics` prior to calling the function Histogram (mind the syntax: use the French accent grave ` ). Try In[1]:= << Graphics`Graphics` In[2]:= data = {97, 90, 91, 98, 93, 100, 90, 98, 91, 93, 98, 93, 97, 93, 80, 95, 93, 99, 96, 80, 98, 85, 94, 98, 96, 88, 93, 92, 88, 97, 90, 90}; In[3]:= Histogram[data]; Tomas Garza Mexico City ----- Original Message ----- === > I've only been playing around with the trial version of Mathematica > for a few hours but I can't figure out how the heck to plot a > histogram. I have a list of data (below) that I want to plot. The > range is 80 to 100 and I want 5 bins, across 4 points each. I feel > that this is a pretty straightforward thing to do, but I can't even > plot a single histogram, even when I reproduce the samples that they > give in the math book word for word. The data is below, any help would > be greatly appreciated. 97,90,91,98,93,100,90,98,91,93,98,93,97,93,80,95,93,99,96,80,98,85,94,98,96, 88,93,92,88,97,90,90 === data={97,90,91,98,93,100,90,98,91,93,98,93,97,93,80,95,93,99,96,80,98, 85,94,98,96,88,93,92,88,97}; Needs[Graphics`Graphics`]; Histogram[data]; It is not clear how you want to handle values on the interval boundaries. Histogram[data, HistogramCategories->Table[k,{k,80,100,4}], Ticks->IntervalCenters]; Histogram[data, HistogramCategories->Table[k,{k,80,101,4+10^-6}], Ticks->IntervalCenters]; Bob Hanlon === > I've only been playing around with the trial version of Mathematica > for a few hours but I can't figure out how the heck to plot a > histogram. I have a list of data (below) that I want to plot. The > range is 80 to 100 and I want 5 bins, across 4 points each. I feel > that this is a pretty straightforward thing to do, but I can't even > plot a single histogram, even when I reproduce the samples that they > give in the math book word for word. The data is below, any help would > be greatly appreciated. 97,90,91,98,93,100,90,98,91,93,98,93,97,93,80,95,93,99,96,80,98,85,94,9 8,96,88,93,92,88,97,90,90 === Subject: Maximizing likelihood function I run into a problem when the function gets too close to 0 or 1, resulting in the function returning Indeterminate after taking Log[0]. I tried to fix this by changing the function F[data_, param_] := Logit[data, param] /. {0->10^-5} /. {1->1-10^-5}) Since those points are not going to be the max anyway. But when I use Nmaximize, it seems that the replacement rule is not obeyed, and the Indeterminates are still returned. Is there a way to force Nmax to use the replacement? Alternatively different solutions would also be appreciated, since this seems to be a pretty clunky solution. Ming Hsu === Subject: How to find out the transformation used in Mathematica I tried the following indefinite integral Integrate[Exp[-x^2/2]/(4 + x^2), {x, -Infinity, Infinity}] Mathematica gave me Pi*e^2*Erfc[Sqrt[2]] which is very nice. However, I don't know how Mathematica got this answer and would like to find out what kind of transformation that it uses to get this answer. Is there anyway for us to ask Mathematica to provide the transformation that it uses to arrive at this answer. Or alternatively, can anyone tell me how to get the integral above? Best, Ann === Subject: Re: How to find out the transformation used in Mathematica > I tried the following indefinite integral > Integrate[Exp[-x^2/2]/(4 + x^2), {x, -Infinity, Infinity}] > Mathematica gave me > Pi*e^2*Erfc[Sqrt[2]] > which is very nice. However, I don't know how Mathematica got > this answer and would like to find out what kind of transformation > that it uses to get this answer. Is there anyway for us to ask > Mathematica to provide the transformation that it uses to arrive at > this answer. Or alternatively, can anyone tell me how to get the > integral above? > Best, > Ann Storing tables is one way. That integral is 7.4.11 of Abramowitz and Stegun (1964) Some tables, e.g. Gradshteyn, now come in cdrom with the results typeset-ready for cut & paste in TeX. === Subject: Re: How to find out the transformation used in Mathematica Hi of transformation that we need to make in order to arrive at the formula in Abramowitz and Stegun? Best, Ann >> I tried the following indefinite integral >> Integrate[Exp[-x^2/2]/(4 + x^2), {x, -Infinity, Infinity}] >> Mathematica gave me >> Pi*e^2*Erfc[Sqrt[2]] >> which is very nice. However, I don't know how Mathematica got >> this answer and would like to find out what kind of transformation >> that it uses to get this answer. Is there anyway for us to ask >> Mathematica to provide the transformation that it uses to arrive at >> this answer. Or alternatively, can anyone tell me how to get the >> integral above? >> Best, >> Ann >Storing tables is one way. That integral is 7.4.11 of Abramowitz and >Stegun (1964) >Some tables, e.g. Gradshteyn, now come in cdrom with the results >typeset-ready for cut & paste in TeX. === Subject: Re: How to find out the transformation used in Mathematica > Hi > of transformation that we need to make in order to arrive at the > formula in Abramowitz and Stegun? > Best, > Ann http://mathworld.wolfram.com/NormalDistribution.html Done by S. Poisson long ago. === Subject: viewing 3D surfaces Is there now a way to look continuously all around at 3D surfaces by mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. It can save much space in the code compared to SpinShow frame animations. === Subject: Re: Re: viewing 3D surfaces BTW, you can call Live3D directly from Mathematica via J/Link. http://omegaconsultinggroup.com/Services/ezine19.html ---------------------------------------------- Omega Consulting The final answer to your Mathematica needs. http://omegaconsultinggroup.com >> Is there now a way to look continuously all around at 3D surfaces by >> mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. >> It can save much space in the code compared to SpinShow frame >> animations. > Check out LiveGraphics3D, the stunning java applet by Martin Kraus > http://wwwvis.informatik.uni-stuttgart.de/~kraus/LiveGraphics3D/ > for > LiveGraphics3D and Kraus on Google). > cheers, > Peltio > Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: viewing 3D surfaces newsgroup I remember to have read that what another system has by way of graphics 3D manipulation Mathematica does not, but here I see it again. Narasimham > Is there now a way to look continuously all around at 3D surfaces by > mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. > It can save much space in the code ( more I meant graphics repeated > output frames) compared to SpinShow frame animations. === Subject: Re: viewing 3D surfaces >Is there now a way to look continuously all around at 3D surfaces by >mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. >It can save much space in the code compared to SpinShow frame >animations. Check out LiveGraphics3D, the stunning java applet by Martin Kraus http://wwwvis.informatik.uni-stuttgart.de/~kraus/LiveGraphics3D/ LiveGraphics3D and Kraus on Google). cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: viewing 3D surfaces Use << RealTime3D` to switch on 3D viewing using Click-Drag and Ctrl-Click-Drag to orient and zoom. Use << Default3D` to switch it off again. Steve Luttrell > Is there now a way to look continuously all around at 3D surfaces by > mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. > It can save much space in the code compared to SpinShow frame > animations. === Subject: How to find out the transformation used in Mathematica I tried the following indefinite integral Integrate[Exp[-x^2/2]/(4 + x^2), {x, -Infinity, Infinity}] Mathematica gave me Pi*e^2*Erfc[Sqrt[2]] which is very nice. However, I don't know how Mathematica got this answer and would like to find out what kind of transformation that it uses to get this answer. Is there anyway for us to ask Mathematica to provide the transformation that it uses to arrive at this answer. Or alternatively, can anyone tell me how to get the integral above? Best, Ann === Subject: Re: Concatenate matrices You can try: A=Partition[Range[9],3] B=Partition[Range[6]+10,2] Join[A[[#]],B[[#]]]&/@{1,2,3}//MatrixForm Hope i am not misunderstanding. Daohua > Hi all > Does somebody know if there's a simple function in mathematica to > concatenate matrices? > Example: > / 1 2 3 > A = | 3 4 5 | > 5 6 7 / > / 11 12 > B = | 13 14 | > 15 16 / > I'd like to have > / 1 2 3 11 12 > R = | 3 4 5 13 14 | > 5 6 7 15 16 / > And so on. See what I mean? > T. > -- > Thomas Guignard > Laboratory of Electromagnetics and Acoustics > Swiss Federal Institute of Technology, Lausanne === Subject: Re: Concatenate matrices Here are two methods: a = {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}} b = {{11, 12}, {13, 14}, {15, 16}} Transpose[Join @@ Transpose /@ {a, b}] {{1, 2, 3, 11, 12}, {3, 4, 5, 13, 14}, {5, 6, 7, 15, 16}} Needs[LinearAlgebra`MatrixManipulation`] BlockMatrix[{{a, b}}] {{1, 2, 3, 11, 12}, {3, 4, 5, 13, 14}, {5, 6, 7, 15, 16}} Bobby > Hi all > Does somebody know if there's a simple function in mathematica to > concatenate matrices? > Example: > / 1 2 3 > A = | 3 4 5 | > 5 6 7 / > / 11 12 > B = | 13 14 | > 15 16 / > I'd like to have > / 1 2 3 11 12 > R = | 3 4 5 13 14 | > 5 6 7 15 16 / > And so on. See what I mean? > T. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Concatenate matrices >Does someone know if there is a function in Mathematica to simply >concatenate matrices (provided their dimensions are right). >Example: > / e11 e12 e13 >E = | e21 e22 e23 | > e31 e32 e33 / > / f11 f12 >F = | f21 f22 | > f31 f32 / >I'd like to have: > / e11 e12 e13 f11 f12 >R = | e21 e22 e23 f21 f22 | > e31 e32 e33 f31 f32 / This can be done as follows: m3 = Transpose@Join[Transpose@m1, Transpose@m2] Here I've used m1, m2 and m3 as the name of the matrices to join to avoid usage of capital letters and conflict with built in symbols. Specifically, E is already defined by Mathematica and cannot be used as a matrix name. An alternative approach to joining matrices in this fashion would be to use the routines in either LinearAlgebra`MatrixManipulation` or Statistics`DataManipulation` -- To reply via email subtract one hundred and four === Subject: Simple question sabout setting directory (1)Everytime i load a math.nb file, i want it to set the directory to be the same one where the file is. e.g. Once you load c:math.nb, the defalut directory will be set to c:. (so i can manage the .nb file and other data file in the same direcotry ) (2)If i open several math programms in the same time, how to change from one to another? just like what Alt+tab does in windows operation system. I remember someone had asked before.. Sorry.. Daohua === Subject: Re: Simple question sabout setting directory > (1) Everytime i load a math.nb file, i want it to set the > directory to be the same one where the file is. MyNotebookDir = DirectoryName@ToFileName@(FileName /. NotebookInformation[EvaluationNotebook[]] /. {FileName -> }); If[MyNotebookDir != , SetDirectory[MyNotebookDir]] See also Marcus -- Time enough to think of the future when you havent any future to think of. -- George Bernard Shaw === Subject: Re: Simple question sabout setting directory Regarding your first question: thisDir=ToFileName[ (FileName/.NotebookInformation[EvaluationNotebook[]])[[1]]]; SetDirectory[thisDir]; Peter > (1)Everytime i load a math.nb file, i want it to set the directory to > be the same one where the file is. > e.g. Once you load c:math.nb, the defalut directory will be set to > c:. (so i can manage the .nb file and other data file in the same > direcotry ) > (2)If i open several math programms in the same time, how to change > from one to another? just like what Alt+tab does in windows operation > system. > I remember someone had asked before.. Sorry.. > Daohua === Subject: RealValued functions and their derivatives I would be grateful for some help with Alebra`ReIm`. I can declare a function to be real-valued (for real-valued arguments) by < counts = > {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; > papers = Plus @@ counts; > pcts = 100. counts/papers; > grades = > {A , A-, B+, B , B-, C+, > C , C-, D+, D , F }; > TableForm[Transpose[{ > StyleForm[#, FontFamily -> Courier] & /@ grades, > counts, > PaddedForm[#, {3, 1}] & /@ pcts}], > TableHeadings - {None, {Grade, Number, Per Cent}}, > TableAlignments -> Right] > Bob Hanlon === >>Subject: table format question >>I have a table created by the following input: >>counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; >>papers = Plus @@ counts; >>pcts = 100. counts/papers; >>grades = {A ,A-,B+,B ,B-,C+,C ,C-,D+,D ,F }; >>TableForm[Transpose[ >> {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}], >> TableHeadings -> {None, {Grade, Number, Per Cent}}] >>1. How can I get a 0 to display after the decimal point in the last >>column's first and last rows? (I tried to wrap the entire thing with an >>obvious PaddedForm expression, but that had the unfortunate effect of >>giving me decimals in the 2nd column, which should be integers without >>any decimal point or trailing decimal places whatsoever.) >>2. How can I get the numbers in columns 2 and three to be >>right-justified? (I tried TableAlignments but that didn't seem to do it.) >>-- >>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 -- 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: table format question counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; papers = Plus @@ counts; pcts = 100. counts/papers; grades = {A , A-, B+, B , B-, C+, C , C-, D+, D , F }; TableForm[Transpose[{ StyleForm[#, FontFamily -> Courier] & /@ grades, counts, PaddedForm[#, {3, 1}] & /@ pcts}], TableHeadings -> {None, {Grade, Number, Per Cent}}, TableAlignments -> Right] Bob Hanlon === > Subject: table format question > I have a table created by the following input: > counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; > papers = Plus @@ counts; > pcts = 100. counts/papers; > grades = {A ,A-,B+,B ,B-,C+,C ,C-,D+,D ,F }; > TableForm[Transpose[ > {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}], > TableHeadings -> {None, {Grade, Number, Per Cent}}] > 1. How can I get a 0 to display after the decimal point in the last > column's first and last rows? (I tried to wrap the entire thing with an > obvious PaddedForm expression, but that had the unfortunate effect of > giving me decimals in the 2nd column, which should be integers without > any decimal point or trailing decimal places whatsoever.) > 2. How can I get the numbers in columns 2 and three to be > right-justified? (I tried TableAlignments but that didn't seem to do it.) > -- > 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: Corrupted file I executed a working notebook which had written several thousand lines of text output at the bottom of the notebook. When I saved it I accidentally answered Yes when it asked whether I wanted to save the changes. All the changes were the text output it had written, which I have already written to a different file, so I didn't need them. When I wanted to open the same file, it said something about a format error at line 32868, and displayed a few characters it didn't like. I removed them with Mathematica but the file will not execute. Also it displays in the pure text form so it's very hard to know where in the file that I recognize the error(s?) begin. I would like to restore in readable form the file up to the error(s) so I can reconstruct the rest of it, but I don't know if or how this is done. I can't work with the file in the pure text form. I'd be grateful for any help. Steve Gray === Subject: Re: Corrupted file Corruption.m (I think it was) but not without a lot of anxiety and confusion. MY biggest problem in dealing with such situations is preventing myself from throwing the computer out the window. But I haven't yet! Steve Gray === Subject: Re: Corrupted file may be that the AuthorTools`NotebookRestore[] function can help you. Jens Steve Gray schrieb im Newsbeitrag >I executed a working notebook which had written several thousand > lines of text output at the bottom of the notebook. When I saved it I > accidentally answered Yes when it asked whether I wanted to save the > changes. All the changes were the text output it had written, which > I have already written to a different file, so I didn't need them. > When I wanted to open the same file, it said something about a format > error at line 32868, and displayed a few characters it didn't like. I > removed them with Mathematica but the file will not execute. Also it > displays > in the pure text form so it's very hard to know where in the file that > I recognize the error(s?) begin. I would like to restore in readable > form the file up to the error(s) so I can reconstruct the rest of it, > but I don't know if or how this is done. I can't work with the file in > the pure text form. I'd be grateful for any help. > Steve Gray === Subject: Plotting two differently scaled graphs together figure out how to scale and plot two graphs together, along with scaled y-axes. I am plotting Yield and Ultimate tensile stress, both on the order of 100-500MPa, along with %elongation, which ranges from .25-16.75. %Cold Work is the x-axis. DisplayTogether[ListPlot[S_y, PlotStyle -> PointSize[0.01]], ListPlot[S_u, PlotStyle -> PointSize[0.01]], ListPlot[Elong, PlotStyle -> PointSize[0.01]], AxesLabel -> {%CW, MPa}, PlotLabel -> YS, UTS, and %Elongation vs %CW of Brass] Of course, Elong ends up being an almost horizontal line along the bottom. How can I scale Elong by about 25, and add a 2nd y-axis on the right-hand of the graph to reflect the scaling? I've looked through the Help and searched a bit through the list archives, but I haven't found anything. Marcin === Subject: Re: Plotting two differently scaled graphs together This info: http://support.wolfram.com/mathematica/graphics/2d/twoaxisgraph.html May do what you need. Mike > figure out how to scale and plot two graphs together, along with scaled > y-axes. > I am plotting Yield and Ultimate tensile stress, both on the order of > 100-500MPa, along with %elongation, which ranges from .25-16.75. %Cold Work > is the x-axis. > DisplayTogether[ListPlot[S_y, PlotStyle -> PointSize[0.01]], > ListPlot[S_u, PlotStyle -> PointSize[0.01]], > ListPlot[Elong, PlotStyle -> PointSize[0.01]], > AxesLabel -> {%CW, MPa}, > PlotLabel -> YS, UTS, and %Elongation vs %CW of Brass] > Of course, Elong ends up being an almost horizontal line along the bottom. > How can I scale Elong by about 25, and add a 2nd y-axis on the right-hand of > the graph to reflect the scaling? I've looked through the Help and searched > a bit through the list archives, but I haven't found anything. > Marcin === Subject: Re: Simple question sabout setting directory >(1)Everytime i load a math.nb file, i want it to set the directory to >be the same one where the file is. e.g. Once you load c:math.nb, the >defalut directory will be set to c:. (so i can manage the .nb file >and other data file in the same direcotry ) The following function will return the directory name where the notebook file is stored. NotebookDirectory[]:= DirectoryName@ToFileName[FileName/.NotebookInformation@EvaluationNotebook []] I have this as part of my init.m file that gets executed at the start of every session. Then to achieve what you want all I do is SetDirectory@NotebookDirectory[] at the begining of the notebook file I omitted your second question since it deals with how Mathematica runs under Windows. Since I use a Mac, I've no idea how to achieve the desired response with Windows. On a Mac running OS 10.3 what you want can be achieved with Expose. -- To reply via email subtract one hundred and four === Subject: Re: Question about derivatives >> I suggest that the answer be easier to find. Look to the subject of your own query. Does it describe what you want to do or how it can be done? If not, how can a search engine zero in on it? The same applies to archived answers to your question. >> why this behaviour is not built into Mathematica The same reason a million other behaviors aren't built in. They're not well defined, not practical, not high enough on anyone's priority list, .... et cetera. Bobby > Before I asked this question, I searched, the archives, the FAQ and the > Mathematica Help extensively. If the question has been asked so many times, > I suggest that the answer be easier to find. I would also be interested in > why this behaviour is not built into Mathematica (or why there is no package > with new functions that does the same thing), where can I find the answers > to these questions? > Ben > -----Original Message----- === > Subject: Question about derivatives >> I want to treat a function abstractly, I know that it is a function >> of n >> variables. I wish to take its derivative after addition or >> multiplication >> with another function. However Derivative does not return what I >> expect. >> Derivative[0,1][f+g] gives (f+g)^(0,1) instead of f^(0,1)+g^(0,1) and >> Derivative[0,1][fg] gives (fg)^(0,1) instead of f^(0,1)g+g^(0,1)f. >> Now >> perhaps I'm going about my problem in the wrong way, if I am please >> tell me. >> I also have some other questions about Derivative, >> Derivative[0,1][Composition[f,g]] gives f^(0,1)(g)g^(0,1), the correct >> result, why does Derivative know the chain rule and not the product >> rule? >> Also, in order to get the correct behaviour for Derivative[0,1][f+g], >> I can >> use the Map function, that is Map[Derivative[0,1],f+g] returns f^(0,1) >> +g^(0,1). Which is fine except that if I have the function 1+f and >> apply >> the same command to it I get 0& + f^(0,1), instead of f^(0,1). >> Clearly >> this is because of the presence of the command Function[0], however I >> have >> been unable to find a function that fixes this problem. >> In essence I want to do vector operations of the ring of functions, >> but find >> that doing this in Mathematica is hard. How can I do this easily? >> Surely >> someone else has figured out a convenient way of do this. >> Ben > This question has been asked and answered many times (including quite > recently). The answer I am posting I have also already posted several > times. > For reasons which I do not want to argue about again Mathematica does > not implement the algebra of functions. that is, if f and g are > functions, whether defined using patterns as in f[x_]:= or as pure > functions using Function, f+g, f*g etc. are not is not treated by > Mathematica as functions. If you wan to change this you can always do > so: > Unprotect[Times, Plus, Power]; > (a_?NumericQ*f_.)[x__] := a f[x]; > (f_ + g_)[x__] := f[x] + g[x]; > (f_*g_)[x__] := f[x]*g[x]; > (f_^n_?NumericQ)[x__] := f[x]^n > Protect[Times, Plus, Power]; > Now you will get: > Derivative[0, 1][f + g] > Derivative[0, 1][f][#1, #2] + > Derivative[0, 1][g][#1, #2] & > Derivative[0, 1][f*g] > g[#1, #2]*Derivative[0, 1][f][#1, > #2] + f[#1, #2]* > Derivative[0, 1][g][#1, #2] & > You have to be aware however that in general it is not a good idea to > modify basic functions such as Times, Plus, Power. They are used by > practically every other Mathematica function and you can never tell if > having additional rules or modifications like those above will not > produce unexpected and unintended behaviour. > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Question about derivatives Before I asked this question, I searched, the archives, the FAQ and the Mathematica Help extensively. If the question has been asked so many times, I suggest that the answer be easier to find. I would also be interested in why this behaviour is not built into Mathematica (or why there is no package with new functions that does the same thing), where can I find the answers to these questions? Ben -----Original Message----- === Subject: Question about derivatives > I want to treat a function abstractly, I know that it is a function > of n > variables. I wish to take its derivative after addition or > multiplication > with another function. However Derivative does not return what I > expect. > Derivative[0,1][f+g] gives (f+g)^(0,1) instead of f^(0,1)+g^(0,1) and > Derivative[0,1][fg] gives (fg)^(0,1) instead of f^(0,1)g+g^(0,1)f. > Now > perhaps I'm going about my problem in the wrong way, if I am please > tell me. > I also have some other questions about Derivative, > Derivative[0,1][Composition[f,g]] gives f^(0,1)(g)g^(0,1), the correct > result, why does Derivative know the chain rule and not the product > rule? > Also, in order to get the correct behaviour for Derivative[0,1][f+g], > I can > use the Map function, that is Map[Derivative[0,1],f+g] returns f^(0,1) > +g^(0,1). Which is fine except that if I have the function 1+f and > apply > the same command to it I get 0& + f^(0,1), instead of f^(0,1). > Clearly > this is because of the presence of the command Function[0], however I > have > been unable to find a function that fixes this problem. > In essence I want to do vector operations of the ring of functions, > but find > that doing this in Mathematica is hard. How can I do this easily? > Surely > someone else has figured out a convenient way of do this. > Ben This question has been asked and answered many times (including quite recently). The answer I am posting I have also already posted several times. For reasons which I do not want to argue about again Mathematica does not implement the algebra of functions. that is, if f and g are functions, whether defined using patterns as in f[x_]:= or as pure functions using Function, f+g, f*g etc. are not is not treated by Mathematica as functions. If you wan to change this you can always do so: Unprotect[Times, Plus, Power]; (a_?NumericQ*f_.)[x__] := a f[x]; (f_ + g_)[x__] := f[x] + g[x]; (f_*g_)[x__] := f[x]*g[x]; (f_^n_?NumericQ)[x__] := f[x]^n Protect[Times, Plus, Power]; Now you will get: Derivative[0, 1][f + g] Derivative[0, 1][f][#1, #2] + Derivative[0, 1][g][#1, #2] & Derivative[0, 1][f*g] g[#1, #2]*Derivative[0, 1][f][#1, #2] + f[#1, #2]* Derivative[0, 1][g][#1, #2] & You have to be aware however that in general it is not a good idea to modify basic functions such as Times, Plus, Power. They are used by practically every other Mathematica function and you can never tell if having additional rules or modifications like those above will not produce unexpected and unintended behaviour. Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: Pretty print Hello To make a paper containing mathematical notation I'd need to see the definition I enter as pretty printed. For example: I enter: f[x_] = 2*x Then Mathematica gives as output: 2 x But I'd need something like: f(x) = 2 x Is there a way to do that ? === Subject: Re: viewing 3D surfaces < Is there now a way to look continuously all around at 3D surfaces by > mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. > It can save much space in the code compared to SpinShow frame > animations. === Subject: Re: viewing 3D surfaces Use <{ URL[ C:......file.html], None}, ButtonStyle->Hyperlink]], Text] However, I would like to be able to specify the file path relative to the notebook's location, because this would allow me to move the whole directory tree around (to a different disk, say) without breaking the links. How can this be done? Steve Luttrell === Subject: Re: Corrupted file I should have first looked up corrupt file in the Mathematica archive, which gives directions for loading a corrupted file. I did what it said, which did not quite work, but modifying the procedure gave me a version of my notebook. That version will not execute, but at least it's in readable form, and I can see what new features it has and even copy/paste sections from it into a new notebook. If anyone wants details, e-mail me or who responds. Steve Gray === Subject: MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True Hi people, I'll need some help in oder to have a decent plot. Using PlotJoined -> True into the MultipleListPlot you can have a line between the points of your list. And it's a very nice feature to use, but when you have something like 1000 point in Plot, and specially if they are very close to each other, you risk to not see the line joining the points beacuse of the Symbols used to draw the points in the list. How can I turn off the point marker drawing? This naturally happen using ListPlot. In ListPlot when you activate the PointJoined option the point's shape automatically turn off and you have only a line. I'd like to have the same result with MultipleListPlot because I'm goind to use different colors for different data sets. Anyone can help me? thank you. Roberto ------------------------------------------------------------- tutto ci=F2 che ho scritto =E8 sempre In My Humble Opinion (IMHO) probabilmente l'ho scritto di fretta, quindi scusate se sono stato sbrigati= vo. === Subject: RE: table format question I use the following code (or variations thereof) to get nicely printed tables. Define first a function (imprime1) which takes care of the trailing zeros and all that. Then use StylePrint, Style Box and GridBox, which have a lot of options to play with: In[1]:= imprime1[x_] := NumberForm[x, {12, 1}, NumberPadding -> {, 0}, DigitBlock -> 3, ExponentFunction -> (Null & )]; In[2]:= Attributes[imprime1] = {Listable}; In[3]:= rows = Transpose[{grades, counts, imprime1[pcts]}]; In[4]:= StylePrint[DisplayForm[StyleBox[ GridBox[{{GridBox[rows, GridFrame -> 2, ColumnLines -> True, RowLines -> True, ColumnAlignments -> {Left, Right, Right}]}}]]], FontFamily -> Arial, FontSize -> 9] The GridBox inside the other may be used for table titles or footnotes. Tomas Garza Mexico City Original Message: ----------------- === Subject: table format question I have a table created by the following input: counts = {25, 10, 14, 10, 13, 12, 3, 6, 10, 8, 68}; papers = Plus @@ counts; pcts = 100. counts/papers; grades = {A ,A-,B+,B ,B-,C+,C ,C-,D+,D ,F }; TableForm[Transpose[ {grades, counts, NumberForm[#, {4, 1}] & /@ pcts}], TableHeadings -> {None, {Grade, Number, Per Cent}}] 1. How can I get a 0 to display after the decimal point in the last column's first and last rows? (I tried to wrap the entire thing with an obvious PaddedForm expression, but that had the unfortunate effect of giving me decimals in the 2nd column, which should be integers without any decimal point or trailing decimal places whatsoever.) 2. How can I get the numbers in columns 2 and three to be right-justified? (I tried TableAlignments but that didn't seem to do it.) -- 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 -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ . === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) === point and concern is in the Subject: LegendreP (Symbolic) is different in Mathematica 5 than previous versions (M4, M3 ..) Your comment means ttht the Mathematica 5 result is not simply 'a different form' but 'the wrong answer'? Peter ----- Original Message ----- === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) >> LegendreP[1,1,mu] >> Out[with m4] = -Sqrt[1 - mu^2] >> Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) >> While this ( and common sense) show they are equal .. >> dum = m4 - m5 // FullSimplify >> PowerExpand[dum] >> Out[]= 0 > Well, it seems to me that the commonsense thing to do in such situations > is not to rely too much on common sense and even less on PowerExpand. In > fact your two expressions are certainly not equal: > a[mu_] := -Sqrt[1 - mu^2]; > b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); > a[2] > (-I)*Sqrt[3] > FullSimplify[b[2]] > I*Sqrt[3] > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) Peter: >Type 1 is the form I want, and am using; by the way, the four >argument form (LegendreP[n,m,a,z]) is not very consipicuous in the >documentation, as it is not included in the summary of arguments at >the top. Because Type 1 is the default case and engineers, like yourself, want Type1 only. This type argument is an optional argument and options for Mathematica functions are not given in the summary of arguments. >In the end, the effect on my old notebooks of 'adding more/ all >branch cuts' is to make them difficult to rework. But it is more important for Mathematica functions to be valid in the complex plane that just being valid for real integer parameters and real arguments over a limited part of the real axis. >This is in much the same way as the improvements to integrate (which >has, I believe, also introduced some real bugs?). In both cases >improvements to conditional Simplifications will be a useful way >forward. >Do you have a 'nice' way of simplifying the Mathematica5 >LegendreP[1,1, z] to get the elegant M4 one? Why is this elegance important? What is wrong with Sqrt[(-z - 1)/(z - 1)] (z - 1) anyway? It appears slightly more complicated than - Sqrt[1 - z^2] but both plot or evaluate for -1 < z < 1 in the same way. Values on the cut -1 < x < 1 are given by Abramowitz and Stegun 8.6.6 and can be generated using (this corrects the earlier formula for m >= 1 and adds the case of m < 0): P[n_, m_, x_] := (-1)^m (1 - x^2)^(m/2) D[LegendreP[n, x], {x, m}] P[n_, m_ /; m < 0, x_] := (-1)^m ((n + m)!/(n - m)!) P[n, -m, x] These are the 'more elegant' expressions that you want. >DesiredFullSimpify[Sqrt[(-z - 1)/(z - 1)] (z - 1) , Abs[z] < 1] = - >Sqrt[1 - z^2], Abs[z] < 1] As Andrzej pointed out, such algebraic reduction is not, in general, trivial. If you produce a table of values of LegendreP[n, m, x], tab1 = Table[LegendreP[n, m, x], {n, 0, 4}, {m, -n, n}] and compare this to the table of values on the cut, tab2 = Table[P[n, m, x], {n, 0, 4}, {m, -n, n}] to me it is arguable which table is more elegant. The two tables clearly agree on the cut: FullSimplify[tab1/tab2, -1 < x < 1] Paul === >Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than >previous versions (M4, M3 ..) === >point and concern is in the Subject: >>Real -- but over what range? And I disagree that the argument z (mu is >>usually used as one of the parameters) is usually real, at least in the >>applications I need it for. I assume that you are restricting attention >>to z = x in -1 < x < 1. In that case, Andrzej Kozlowski's suggestion of >>using >> P[n_, m_, x_] := (-1)^m (1 - x^2)^(m/2) D[LegendreP[n, x], x] >>(for m >= 0) is one way to go. >>Remember, Mathematica is designed to work with functions (and parameters >>and arguments) assumed to be complex, in general. >LegendreP (Symbolic) is different in Mathematica 5 than previous versions >(M4, M3 ..) >Your comment means ttht the Mathematica 5 result is not simply 'a different >form' but 'the wrong answer'? >>The answer is _not_ wrong. If you look at the online documentation for >>LegendreP you will see that it accepts FOUR arguments. By default >>LegendreP[1,1,mu] gives the Type 1 case, which is defined only for z >>within the unit circle in the complex plane. Indeed, although >>FullSimplify[Sqrt[(-z - 1)/(z - 1)] (z - 1) + Sqrt[1 - z^2], Abs[z] < 1] >>returns 0, FullSimplify fails to reduce Sqrt[(-z - 1)/(z - 1)] (z - 1) >>to -Sqrt[1 - z^2]. But the result is not wrong. The definition needs to >>handle different possible branch cuts. For example, Type 3 functions >>have a single branch cut from -Infinity to +1. >>Paul === >Subject: Re: LegendreP (Symbolic) is different in Mathematica5 >than previous versions (M4, M3 ..) >> >LegendreP[1,1,mu] >Out[with m4] = -Sqrt[1 - mu^2] >Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) > >While this ( and common sense) show they are equal .. > >dum = m4 - m5 // FullSimplify >PowerExpand[dum] >Out[]= 0 > >> >> Well, it seems to me that the commonsense thing to do in such > situations >> is not to rely too much on common sense and even less on PowerExpand. > In >> fact your two expressions are certainly not equal: >> >> a[mu_] := -Sqrt[1 - mu^2]; >> b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); >> >> a[2] >> (-I)*Sqrt[3] >> >> FullSimplify[b[2]] >> >> I*Sqrt[3] >> >> >> Andrzej Kozlowski >> Chiba, Japan >> http://www.akikoz.net/~andrzej/ >> http://www.mimuw.edu.pl/~akoz/ >> >> >>-- >>Paul Abbott Phone: +61 8 6488 2734 >>School of Physics, M013 Fax: +61 8 6488 1014 >>The University of Western Australia (CRICOS Provider No 00126G) >>35 Stirling Highway >>Crawley WA 6009 mailto:paul@physics.uwa.edu.au >>AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) === > point and concern is in the Subject: Real -- but over what range? And I disagree that the argument z (mu is usually used as one of the parameters) is usually real, at least in the applications I need it for. I assume that you are restricting attention to z = x in -1 < x < 1. In that case, Andrzej Kozlowski's suggestion of using P[n_, m_, x_] := (-1)^m (1 - x^2)^(m/2) D[LegendreP[n, x], x] (for m >= 0) is one way to go. Remember, Mathematica is designed to work with functions (and parameters and arguments) assumed to be complex, in general. > LegendreP (Symbolic) is different in Mathematica 5 than previous versions > (M4, M3 ..) > Your comment means ttht the Mathematica 5 result is not simply 'a different > form' but 'the wrong answer'? The answer is _not_ wrong. If you look at the online documentation for LegendreP you will see that it accepts FOUR arguments. By default LegendreP[1,1,mu] gives the Type 1 case, which is defined only for z within the unit circle in the complex plane. Indeed, although FullSimplify[Sqrt[(-z - 1)/(z - 1)] (z - 1) + Sqrt[1 - z^2], Abs[z] < 1] returns 0, FullSimplify fails to reduce Sqrt[(-z - 1)/(z - 1)] (z - 1) to -Sqrt[1 - z^2]. But the result is not wrong. The definition needs to handle different possible branch cuts. For example, Type 3 functions have a single branch cut from -Infinity to +1. Paul > ----- Original Message ----- === > Subject: Re: LegendreP (Symbolic) is different in Mathematica5 > than previous versions (M4, M3 ..) >> LegendreP[1,1,mu] >> Out[with m4] = -Sqrt[1 - mu^2] >> Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) >> >> While this ( and common sense) show they are equal .. >> >> dum = m4 - m5 // FullSimplify >> PowerExpand[dum] >> Out[]= 0 >Well, it seems to me that the commonsense thing to do in such situations > is not to rely too much on common sense and even less on PowerExpand. In > fact your two expressions are certainly not equal: > a[mu_] := -Sqrt[1 - mu^2]; > b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); > a[2] > (-I)*Sqrt[3] > FullSimplify[b[2]] > I*Sqrt[3] > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/~andrzej/ > http://www.mimuw.edu.pl/~akoz/ -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) >> real. > Since LegendreP is a polynomial this is not an issue. If two > polynomials are equal for all real values of the argument they have to > be also equal for all complex values. I got confused here. I forgot that the problem is with the associated Legendre functions and not with the Legendre polynomial itself. For two such functions it is of course possible to be equal in an open set of the complex plane without necessarily being equal everywhere. This appears to be the case here. The two expressions for the associated Legendre function returned by Mathematica version 4 and 5 are equal in the unit disk, although Mathematica seems unable to prove it. Mathematica can show that a[mu_] := -Sqrt[1 - mu^2]; b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); Simplify[a[z]-b[z], -1> My === >> point and concern is in the Subject: >> LegendreP (Symbolic) is different in Mathematica5 than previous >> versions >> (M4, M3 ..) >> Your comment means taht the M5 result is not simply 'a different >> form' but 'the wrong >> answer'? > It seems so. Note that if you simply define your own associated > Legendre function using the definition given in Mathematica's help: > P[n_, m_, x_] := (-1)^m*(1 - x^2)^(m/2)*D[LegendreP[n, x], x] > then > P[1, 1, x] > -Sqrt[1 - x^2] > which is the answer v, 4 gives. So it seems that there is a bug in > Mathematca 5, although it seems only to affect the associated Legendre > function and not Legendre polynomial itself. > Andrzej Kozlowski >> Peter >> >> Cc: === >> Subject: Re: LegendreP (Symbolic) is different in >> Mathematica5 >> than previous versions (M4, M3 ..) >*This message was transferred with a trial version of >CommuniGate(tm) Pro* >>LegendreP[1,1,mu] >>Out[with m4] = -Sqrt[1 - mu^2] >>Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) >> >>While this ( and common sense) show they are equal .. >> >>dum = m4 - m5 // FullSimplify >>PowerExpand[dum] >>Out[]= 0 >> >Well, it seems to me that the commonsense thing to do in such >situations >is not to rely too much on common sense and even less on >PowerExpand. In >fact your two expressions are certainly not equal: >a[mu_] := -Sqrt[1 - mu^2]; >b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); >a[2] >(-I)*Sqrt[3] >FullSimplify[b[2]] >I*Sqrt[3] >Andrzej Kozlowski >Chiba, Japan >http://www.akikoz.net/~andrzej/ >http://www.mimuw.edu.pl/~akoz/ === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) > *This message was transferred with a trial version of CommuniGate(tm) > Pro* Since LegendreP is a polynomial this is not an issue. If two polynomials are equal for all real values of the argument they have to be also equal for all complex values. > My === > point and concern is in the Subject: > LegendreP (Symbolic) is different in Mathematica5 than previous > versions > (M4, M3 ..) > Your comment means taht the M5 result is not simply 'a different form' > but 'the wrong > answer'? It seems so. Note that if you simply define your own associated Legendre function using the definition given in Mathematica's help: P[n_, m_, x_] := (-1)^m*(1 - x^2)^(m/2)*D[LegendreP[n, x], x] then P[1, 1, x] -Sqrt[1 - x^2] which is the answer v, 4 gives. So it seems that there is a bug in Mathematca 5, although it seems only to affect the associated Legendre function and not Legendre polynomial itself. Andrzej Kozlowski > Peter > === > Subject: Re: LegendreP (Symbolic) is different in > Mathematica5 > than previous versions (M4, M3 ..) >> *This message was transferred with a trial version of CommuniGate(tm) >> Pro* >LegendreP[1,1,mu] >Out[with m4] = -Sqrt[1 - mu^2] >Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) >While this ( and common sense) show they are equal .. >dum = m4 - m5 // FullSimplify >PowerExpand[dum] >Out[]= 0 >> Well, it seems to me that the commonsense thing to do in such >> situations >> is not to rely too much on common sense and even less on PowerExpand. >> In >> fact your two expressions are certainly not equal: >> a[mu_] := -Sqrt[1 - mu^2]; >> b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); >> a[2] >> (-I)*Sqrt[3] >> FullSimplify[b[2]] >> I*Sqrt[3] >> Andrzej Kozlowski >> Chiba, Japan >> http://www.akikoz.net/~andrzej/ >> http://www.mimuw.edu.pl/~akoz/ === Subject: Re: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) > LegendreP[1,1,mu] > Out[with m4] = -Sqrt[1 - mu^2] > Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) > While this ( and common sense) show they are equal .. > dum = m4 - m5 // FullSimplify > PowerExpand[dum] > Out[]= 0 Well, it seems to me that the commonsense thing to do in such situations is not to rely too much on common sense and even less on PowerExpand. In fact your two expressions are certainly not equal: a[mu_] := -Sqrt[1 - mu^2]; b[mu_] := Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu); a[2] (-I)*Sqrt[3] FullSimplify[b[2]] I*Sqrt[3] Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/ === Subject: LegendreP (Symbolic) is different in Mathematica5 than previous versions (M4, M3 ..) LegendreP gives answers in a different form in Mathematica5 than Mathematica4 (and, from memory, all previous versions). Simplifying the new form to the 'nicer' previous one seems 'tough'. Any ideas, and will this be changed in the latest M5? [While I have loads of more compex expressions derived from from LegendreP which are now'a mess' with M5 it seems best to start at the simplest] In[187]:= LegendreP[1,1,mu] Out[with m4] = -Sqrt[1 - mu^2] Out[with m5] = Sqrt[(-1 - mu)/(-1 + mu)]*(-1 + mu) While this ( and common sense) show they are equal .. dum = m4 - m5 // FullSimplify PowerExpand[dum] Out[]= 0 .. I am far from a strategy for useful general simplification. In[247]:= {m4,m5}//PowerExpand//FullSimplify//InputForm Out[248]//InputForm= {-Sqrt[1 - mu^2], Sqrt[-1 - mu]*Sqrt[-1 + mu]} === Subject: Re: Solving an equation problem and I think I can find all the poles graphically. Here is what I am thinking, but don't necessarily know how to do it. I don't really understand the Project command well enough to do what I want it to do. I can Plot3D[ Re[Gamma[x+I y]]] for some region, then project onto a plane z==some number. I now have a curve in the x,y plane, at least theoretically. (In practice I just get the plane, since I must be doing something wrong.) If I do the same for Im[Gamma[x + Iy]] and project onto a plane z== #. I now have another xy plot. I can then use the Show command to merge the two plots. Every intersection of the curves should be a solution I am looking for...correct? Does that make sense? === Subject: Re: Need code to calculate the Lower Envelope for a set of (non collinear) points. And here's the fastest (without ConvexHull) solution yet... if you don't mind using Real arithmetic to test the points: Clear[iterate, inverseSlope] inverseSlope[a_, b_] := Compile[{{x, _Real, 1}}, (x[[1]] - a)/(x[[2]] - b)] iterate@{} := {} iterate@{one_} := (Sow@one; {}) iterate[{{a_, b_}, rest__}] := ( Sow@{a, b}; Drop[{Null, rest}, First@Ordering[inverseSlope[a, b] /@ {rest}, -1]] ) Timing@First@Last@Reap@FixedPoint[iterate, a] {0. Second, {{4, 2}, {16, 5}, {44, 13}, { 92, 31}, {688, 269}, {992, 421}, {1000, 491}}} Bobby > The ConvexHull solutions depend on ConvexHull returning its result in counterclockwise order, and that seems to be undocumented. Can we count on it? > So here's a solution without ConvexHull: > rule = {x___, {a_, b_}, {c_, d_}, {e_, f_}, y___} /; > (d - b)/(c - a) > (f - b)/(e - a) : {x, {a, b}, {e, f}, y}; > Timing[a //. rule] > MultipleListPlot[{Last[%], a}, PlotJoined -> True, > PlotStyle -> {Hue[0.6]}] > {0.047 Second, {{4, 2}, {8, 3}, {16, 5}, {44, 13}, {92, 31}, > {688, 269}, {992, 421}, {1000, 491}}} >= rather than > gives a correct result with fewer points: > rule = {x___, {a_, b_}, {c_, d_}, {e_, f_}, y___} /; > (d - b)/(c - a) >= (f - b)/(e - a) : {x, {a, b}, {e, f}, y}; > Timing[a //. rule] > MultipleListPlot[{Last[%], a}, PlotJoined -> True, > PlotStyle -> {Hue[0.6]}] > {0.047 Second, {{4, 2}, {16, 5}, {44, 13}, {92, 31}, > {688, 269}, {992, 421}, {1000, 491}}} > Here's a method using FixedPoint: > iterate@{lowerEnvelope_, {}} := {lowerEnvelope, {}} > iterate@{lowerEnvelope_, {a_}} := {Append[lowerEnvelope, a], {}} > iterate@{lowerEnvelope_, data_} := Module[{one = First@data}, > {Append[lowerEnvelope, one], Drop[data, First@Ordering[ > Divide @@ (# - one) & /@ Rest@data, -1]]} > ] > Timing@First@FixedPoint[iterate, {{}, a}, 9] > {0.031 Second, {{4, 2}, {16, 5}, {44, 13}, > {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} > Finally, here are three almost identical solutions using Sow and Reap: > Clear@iterate > iterate@{} := {} > iterate@{a_} := (Sow@a; {}) > iterate[data_] := Module[{one = First@data}, > Sow@one; > Drop[data, First@Ordering[Divide @@ (# - one) & /@ Rest@data, -1]] > ] > Timing@First@Last@Reap@FixedPoint[iterate, a] > {0.016 Second, {{4, 2}, {16, > 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} > Clear@iterate > iterate@{} := {} > iterate@{one_} := (Sow@one; {}) > iterate[data : {one_, rest__}] := (Sow@one; > Drop[data, First@Ordering[Divide @@ (# - one) & /@ {rest}, -1]] > ) > Timing@First@Last@Reap@FixedPoint[iterate, a] > {0.016 Second, {{4, 2}, {16, > 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} > Clear@iterate > iterate@{}:={} > iterate@{one_}:=(Sow@one;{}) > iterate[{one_,rest__}]:=(Sow@one; > Drop[{rest},-1+First@Ordering[Divide@@(#-one)&/@{rest},-1]] > ) > Timing@First@Last@Reap@FixedPoint[iterate,a] > {0.016 Second,{{4,2},{16,5},{44,13},{92,31},{688,269},{992,421},{1000,491}}} > I like the last solution best of all these, but ConvexHull still gives a faster solution. > Bobby >> Just for fun, here's a slightly different solution (for sorted data): >> LowerEnvelope[a_] := Module[{hull = ConvexHull@a}, >> a[[hull /. {{x___, 1, y___, Length@a, z___} :> {1, y, >> Length@a}, {x___, Length@a, y___, 1, z___} :> {1, z, x, Length@a}}]] >> ] >> It may be faster, as it uses /. once, rather than twice. >> Bobby >Your Lower Envelope Module works like a charm! >Intuitively I knew that using the Convex Hull would facilitate finding >the Lower Envelope, but my attempts to modify the code of the Convex >Hull program always failed. Your solution is both compact and clever! I >Very grateful to you: >Gilmar >-----Original Message----- === >Subject: Re: Need code to calculate the Lower Envelope for a >set of (non collinear) points. >I think this does it if the data is already sorted: >LowerEnvelope[a_]:=Module[{hull=ConvexHull@a}, > a[[hull/.{x___,1,y___}:>{1,y,x} > /.{x__,Length@a,y___}:>{x,Length@a}]] > ] >LowerEnvelope@a > MultipleListPlot[{%,a},PlotJoined[Rule]True,PlotStyle[Rule]{Hue[.6]}] >{{4,2},{8,3},{16,5},{44,13},{92,31},{688,269},{992,421},{1000,491}} >If the data might NOT be pre-sorted, the function would be: >LowerEnvelope[a_] := Module[{data = Sort@a, hull}, > hull = ConvexHull@data; > data[[hull /. {x___, 1, y___} :> {1, y, x} > /. {x__, Length@a, y___} :> {x, Length@a}]] > ] >Testing with a random reordering of a still gives the same answer: >LowerEnvelope[Sort[a, Random[] < 0.5 &]] >MultipleListPlot[{%, a}, PlotJoined -> True, PlotStyle -> {Hue[.6]}] >{{4, 2}, {8, 3}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, >{1000, 491}} >Bobby >> >>I'm looking for a program to calculate the Lower Envelope >>(LE for short)for a set of (non-collinear) points on the >>plane. Please download the following file containing an >>arbitrary set of such points(which I'm calling A) by >>double-clicking the following shortcut: >> >>http://gilmarlily.netfirms.com/download/A.txt >> >>You can also down load: >> >>http://gilmarlily.netfirms.com/download/Lower Envelope.nb >> >>to evaluate the following steps using Mathematica (version 5): >> >>If your define your working directory as C:Temporary, then kindly >>evaluate the following Mathematica commands: >> >>In[1]: A = ReadList[C:TemporaryA.txt, {Number, Number}]; >> >>Next, plot the set A: >> >>In[2]: plt1 = ListPlot[A, PlotJoined -> True, PlotStyle -> {Hue[.7]}] >> >>I can manipulate the program ConvexHull to find the Lower Envelope >>for the set A as follows: >> >>In[3]: << DiscreteMath`ComputationalGeometry` >> >>In[4]: convexhull = ConvexHull[A] >> >>The following input gives a picture of the Convex Hull: >> >>In[5]: plt2 = ListPlot[Table[A[[convexhull[[i]]]], {i, >> 1, Length[convexhull]}], PlotJoined -> True, PlotStyle -> >{Hue[.6]}] >> >>Modifying the starting value of index i in In[5] above >>(starting at i=96 instead of i=1) gives a picture of the >>Lower Envelope of A: >> >>In[6]:plt3 = ListPlot[Table[A[[convexhull[[i]]]], {i, >> 96, Length[convexhull]}], PlotJoined -> True, PlotStyle -> >{Hue[.6]}] >> >>In[7]: Show[plt1, plt3] >> >>The Lower Envelope of A (LEA for short) is given by: >> >>In[8]: LEA = Table[A[[convexhull[[i]]]], {i, 96, Length[convexhull]}] >> >>So my question is: How can the code of the ConvexHull program be >modified, >>to get a program that calculates the LE of a set? >> >>The following (clumsy)alternative attempt: >> >>In[9]: LE[B_] := Module[{M}, {L = Length[B]; M = {}; >> AppendTo[M, B[[L]]]; {Xg, Yg} = B[[L]]; Do[If[B[[ >> L - i + 1]][[2]] < Yg, {{Xg, Yg} = B[[L - >> i + 1]], AppendTo[M, B[[L - i + 1]]]}], {i, 1, L - 1}]}; >Sort[M]] >> >>In[10]: LE[A] >> >>In[11]: plt4 = ListPlot[LE[A], PlotJoined -> True, PlotStyle -> >{Hue[.1]}] >> >>In[12]: Show[plt1, plt4] >> >>gives me something that is not even close, and no cigar. >> >>What I need is an algorithm that gives me the Lower Envelope E of A >> >> >> >> -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Need code to calculate the Lower Envelope for a set of (non collinear) points. The ConvexHull solutions depend on ConvexHull returning its result in counterclockwise order, and that seems to be undocumented. Can we count on it? So here's a solution without ConvexHull: rule = {x___, {a_, b_}, {c_, d_}, {e_, f_}, y___} /; (d - b)/(c - a) > (f - b)/(e - a) :> {x, {a, b}, {e, f}, y}; Timing[a //. rule] MultipleListPlot[{Last[%], a}, PlotJoined -> True, PlotStyle -> {Hue[0.6]}] {0.047 Second, {{4, 2}, {8, 3}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} >= rather than > gives a correct result with fewer points: rule = {x___, {a_, b_}, {c_, d_}, {e_, f_}, y___} /; (d - b)/(c - a) >= (f - b)/(e - a) :> {x, {a, b}, {e, f}, y}; Timing[a //. rule] MultipleListPlot[{Last[%], a}, PlotJoined -> True, PlotStyle -> {Hue[0.6]}] {0.047 Second, {{4, 2}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} Here's a method using FixedPoint: iterate@{lowerEnvelope_, {}} := {lowerEnvelope, {}} iterate@{lowerEnvelope_, {a_}} := {Append[lowerEnvelope, a], {}} iterate@{lowerEnvelope_, data_} := Module[{one = First@data}, {Append[lowerEnvelope, one], Drop[data, First@Ordering[ Divide @@ (# - one) & /@ Rest@data, -1]]} ] Timing@First@FixedPoint[iterate, {{}, a}, 9] {0.031 Second, {{4, 2}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} Finally, here are three almost identical solutions using Sow and Reap: Clear@iterate iterate@{} := {} iterate@{a_} := (Sow@a; {}) iterate[data_] := Module[{one = First@data}, Sow@one; Drop[data, First@Ordering[Divide @@ (# - one) & /@ Rest@data, -1]] ] Timing@First@Last@Reap@FixedPoint[iterate, a] {0.016 Second, {{4, 2}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} Clear@iterate iterate@{} := {} iterate@{one_} := (Sow@one; {}) iterate[data : {one_, rest__}] := (Sow@one; Drop[data, First@Ordering[Divide @@ (# - one) & /@ {rest}, -1]] ) Timing@First@Last@Reap@FixedPoint[iterate, a] {0.016 Second, {{4, 2}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}}} Clear@iterate iterate@{}:={} iterate@{one_}:=(Sow@one;{}) iterate[{one_,rest__}]:=(Sow@one; Drop[{rest},-1+First@Ordering[Divide@@(#-one)&/@{rest},-1]] ) Timing@First@Last@Reap@FixedPoint[iterate,a] {0.016 Second,{{4,2},{16,5},{44,13},{92,31},{688,269},{992,421},{1000,491}}} I like the last solution best of all these, but ConvexHull still gives a faster solution. Bobby > Just for fun, here's a slightly different solution (for sorted data): > LowerEnvelope[a_] := Module[{hull = ConvexHull@a}, > a[[hull /. {{x___, 1, y___, Length@a, z___} :> {1, y, > Length@a}, {x___, Length@a, y___, 1, z___} :> {1, z, x, Length@a}}]] > ] > It may be faster, as it uses /. once, rather than twice. > Bobby >> Your Lower Envelope Module works like a charm! >> Intuitively I knew that using the Convex Hull would facilitate finding >> the Lower Envelope, but my attempts to modify the code of the Convex >> Hull program always failed. Your solution is both compact and clever! I >> Very grateful to you: >> Gilmar >> -----Original Message----- === >> Subject: Re: Need code to calculate the Lower Envelope for a >> set of (non collinear) points. >> I think this does it if the data is already sorted: >> LowerEnvelope[a_]:=Module[{hull=ConvexHull@a}, >> a[[hull/.{x___,1,y___}:>{1,y,x} >> /.{x__,Length@a,y___}:>{x,Length@a}]] >> ] >> LowerEnvelope@a >> MultipleListPlot[{%,a},PlotJoined[Rule]True,PlotStyle[Rule]{Hue[.6]}] >> {{4,2},{8,3},{16,5},{44,13},{92,31},{688,269},{992,421},{1000,491}} >> If the data might NOT be pre-sorted, the function would be: >> LowerEnvelope[a_] := Module[{data = Sort@a, hull}, >> hull = ConvexHull@data; >> data[[hull /. {x___, 1, y___} :> {1, y, x} >> /. {x__, Length@a, y___} :> {x, Length@a}]] >> ] >> Testing with a random reordering of a still gives the same answer: >> LowerEnvelope[Sort[a, Random[] < 0.5 &]] >> MultipleListPlot[{%, a}, PlotJoined -> True, PlotStyle -> {Hue[.6]}] >> {{4, 2}, {8, 3}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, >> {1000, 491}} >> Bobby >I'm looking for a program to calculate the Lower Envelope >(LE for short)for a set of (non-collinear) points on the >plane. Please download the following file containing an >arbitrary set of such points(which I'm calling A) by >double-clicking the following shortcut: >http://gilmarlily.netfirms.com/download/A.txt >You can also down load: >http://gilmarlily.netfirms.com/download/Lower Envelope.nb >to evaluate the following steps using Mathematica (version 5): >If your define your working directory as C:Temporary, then kindly >evaluate the following Mathematica commands: >In[1]: A = ReadList[C:TemporaryA.txt, {Number, Number}]; >Next, plot the set A: >In[2]: plt1 = ListPlot[A, PlotJoined -> True, PlotStyle -> {Hue[.7]}] >I can manipulate the program ConvexHull to find the Lower Envelope >for the set A as follows: >In[3]: << DiscreteMath`ComputationalGeometry` >In[4]: convexhull = ConvexHull[A] >The following input gives a picture of the Convex Hull: >In[5]: plt2 = ListPlot[Table[A[[convexhull[[i]]]], {i, > 1, Length[convexhull]}], PlotJoined -> True, PlotStyle -> >> {Hue[.6]}] >Modifying the starting value of index i in In[5] above >(starting at i=96 instead of i=1) gives a picture of the >Lower Envelope of A: >In[6]:plt3 = ListPlot[Table[A[[convexhull[[i]]]], {i, > 96, Length[convexhull]}], PlotJoined -> True, PlotStyle -> >> {Hue[.6]}] >In[7]: Show[plt1, plt3] >The Lower Envelope of A (LEA for short) is given by: >In[8]: LEA = Table[A[[convexhull[[i]]]], {i, 96, Length[convexhull]}] >So my question is: How can the code of the ConvexHull program be >> modified, >to get a program that calculates the LE of a set? >The following (clumsy)alternative attempt: >In[9]: LE[B_] := Module[{M}, {L = Length[B]; M = {}; > AppendTo[M, B[[L]]]; {Xg, Yg} = B[[L]]; Do[If[B[[ > L - i + 1]][[2]] < Yg, {{Xg, Yg} = B[[L - > i + 1]], AppendTo[M, B[[L - i + 1]]]}], {i, 1, L - 1}]}; >> Sort[M]] >In[10]: LE[A] >In[11]: plt4 = ListPlot[LE[A], PlotJoined -> True, PlotStyle -> >> {Hue[.1]}] >In[12]: Show[plt1, plt4] >gives me something that is not even close, and no cigar. >What I need is an algorithm that gives me the Lower Envelope E of A -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Need code to calculate the Lower Envelope for a set of (non collinear) points. I think this does it if the data is already sorted: LowerEnvelope[a_]:=Module[{hull=ConvexHull@a}, a[[hull/.{x___,1,y___}:>{1,y,x} /.{x__,Length@a,y___}:>{x,Length@a}]] ] LowerEnvelope@a MultipleListPlot[{%,a},PlotJoined[Rule]True,PlotStyle[Rule]{Hue[.6]}] {{4,2},{8,3},{16,5},{44,13},{92,31},{688,269},{992,421},{1000,491}} If the data might NOT be pre-sorted, the function would be: LowerEnvelope[a_] := Module[{data = Sort@a, hull}, hull = ConvexHull@data; data[[hull /. {x___, 1, y___} :> {1, y, x} /. {x__, Length@a, y___} :> {x, Length@a}]] ] Testing with a random reordering of a still gives the same answer: LowerEnvelope[Sort[a, Random[] < 0.5 &]] MultipleListPlot[{%, a}, PlotJoined -> True, PlotStyle -> {Hue[.6]}] {{4, 2}, {8, 3}, {16, 5}, {44, 13}, {92, 31}, {688, 269}, {992, 421}, {1000, 491}} Bobby > I'm looking for a program to calculate the Lower Envelope > (LE for short)for a set of (non-collinear) points on the > plane. Please download the following file containing an > arbitrary set of such points(which I'm calling A) by > double-clicking the following shortcut: > http://gilmarlily.netfirms.com/download/A.txt > You can also down load: > http://gilmarlily.netfirms.com/download/Lower Envelope.nb > to evaluate the following steps using Mathematica (version 5): > If your define your working directory as C:Temporary, then kindly > evaluate the following Mathematica commands: > In[1]: A = ReadList[C:TemporaryA.txt, {Number, Number}]; > Next, plot the set A: > In[2]: plt1 = ListPlot[A, PlotJoined -> True, PlotStyle -> {Hue[.7]}] > I can manipulate the program ConvexHull to find the Lower Envelope > for the set A as follows: > In[3]: << DiscreteMath`ComputationalGeometry` > In[4]: convexhull = ConvexHull[A] > The following input gives a picture of the Convex Hull: > In[5]: plt2 = ListPlot[Table[A[[convexhull[[i]]]], {i, > 1, Length[convexhull]}], PlotJoined -> True, PlotStyle -> {Hue[.6]}] > Modifying the starting value of index i in In[5] above > (starting at i=96 instead of i=1) gives a picture of the > Lower Envelope of A: > In[6]:plt3 = ListPlot[Table[A[[convexhull[[i]]]], {i, > 96, Length[convexhull]}], PlotJoined -> True, PlotStyle -> {Hue[.6]}] > In[7]: Show[plt1, plt3] > The Lower Envelope of A (LEA for short) is given by: > In[8]: LEA = Table[A[[convexhull[[i]]]], {i, 96, Length[convexhull]}] > So my question is: How can the code of the ConvexHull program be modified, > to get a program that calculates the LE of a set? > The following (clumsy)alternative attempt: > In[9]: LE[B_] := Module[{M}, {L = Length[B]; M = {}; > AppendTo[M, B[[L]]]; {Xg, Yg} = B[[L]]; Do[If[B[[ > L - i + 1]][[2]] < Yg, {{Xg, Yg} = B[[L - > i + 1]], AppendTo[M, B[[L - i + 1]]]}], {i, 1, L - 1}]}; Sort[M]] > In[10]: LE[A] > In[11]: plt4 = ListPlot[LE[A], PlotJoined -> True, PlotStyle -> {Hue[.1]}] > In[12]: Show[plt1, plt4] > gives me something that is not even close, and no cigar. > What I need is an algorithm that gives me the Lower Envelope E of A -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Need code to calculate the Lower Envelope for a set of (non collinear) points. I'm looking for a program to calculate the Lower Envelope (LE for short)for a set of (non-collinear) points on the plane. Please download the following file containing an arbitrary set of such points(which I'm calling A) by double-clicking the following shortcut: http://gilmarlily.netfirms.com/download/A.txt You can also down load: http://gilmarlily.netfirms.com/download/Lower Envelope.nb to evaluate the following steps using Mathematica (version 5): If your define your working directory as C:Temporary, then kindly evaluate the following Mathematica commands: In[1]: A = ReadList[C:TemporaryA.txt, {Number, Number}]; Next, plot the set A: In[2]: plt1 = ListPlot[A, PlotJoined -> True, PlotStyle -> {Hue[.7]}] I can manipulate the program ConvexHull to find the Lower Envelope for the set A as follows: In[3]: << DiscreteMath`ComputationalGeometry` In[4]: convexhull = ConvexHull[A] The following input gives a picture of the Convex Hull: In[5]: plt2 = ListPlot[Table[A[[convexhull[[i]]]], {i, 1, Length[convexhull]}], PlotJoined -> True, PlotStyle -> {Hue[.6]}] Modifying the starting value of index i in In[5] above (starting at i=96 instead of i=1) gives a picture of the Lower Envelope of A: In[6]:plt3 = ListPlot[Table[A[[convexhull[[i]]]], {i, 96, Length[convexhull]}], PlotJoined -> True, PlotStyle -> {Hue[.6]}] In[7]: Show[plt1, plt3] The Lower Envelope of A (LEA for short) is given by: In[8]: LEA = Table[A[[convexhull[[i]]]], {i, 96, Length[convexhull]}] So my question is: How can the code of the ConvexHull program be modified, to get a program that calculates the LE of a set? The following (clumsy)alternative attempt: In[9]: LE[B_] := Module[{M}, {L = Length[B]; M = {}; AppendTo[M, B[[L]]]; {Xg, Yg} = B[[L]]; Do[If[B[[ L - i + 1]][[2]] < Yg, {{Xg, Yg} = B[[L - i + 1]], AppendTo[M, B[[L - i + 1]]]}], {i, 1, L - 1}]}; Sort[M]] In[10]: LE[A] In[11]: plt4 = ListPlot[LE[A], PlotJoined -> True, PlotStyle -> {Hue[.1]}] In[12]: Show[plt1, plt4] gives me something that is not even close, and no cigar. What I need is an algorithm that gives me the Lower Envelope E of A === Subject: What reduction was used to determine integrals listed on Wolfram's function page for laguerre polynomials Hello Mathematica users: Is it possible to find out what reduction was used, presumably inside Mathematica, to determine the value of the integrals listed at: http://functions.wolfram.com/HypergeometricFunctions/LaguerreL3General/21/01 /02/03/ I am specifically the first one more than any of the others. I would like to understand what sort of transformation one needs to do in order to integrate Laguerre polynomials since I need to determine so similar types of integrals for my Master's Thesis. Jim Ramberg SF State University Dept of P+A === Subject: Re : Pretty print Is this what you want ? HoldForm[f[x] = 2x] // TraditionalForm F.Jaccard -----Message d'origine----- DeÊ: Kaba [mailto:none@here.com] ËÊ: mathgroup@smc.vnet.net ObjetÊ: Pretty print Hello To make a paper containing mathematical notation I'd need to see the definition I enter as pretty printed. For example: I enter: f[x_] = 2*x Then Mathematica gives as output: 2 x But I'd need something like: f(x) = 2 x Is there a way to do that ? === Subject: Re: Re : Pretty print > Is this what you want ? > HoldForm[f[x] = 2x] // TraditionalForm No, not exactly, this has the drawback that it does not really define the function, that is, I can't evaluate f[4] after this. I got a === Subject: Re: Pretty print SetAttributes[eqnDef, {Listable,HoldFirst}]; eqnDef[f_] := ToString[TraditionalForm[HoldForm[f]]] <> = <> ToString[TraditionalForm[f]]; f[x]:= x^2; g[n_, z_] := x^2*Exp[-x]*BesselI[n, z]; eqnDef[f[x]] eqnDef[{f[x],g[n,x]}]//ColumnForm Bob Hanlon === > Subject: Pretty print > Hello > To make a paper containing mathematical notation I'd need to see the > definition I enter as pretty printed. > For example: > I enter: f[x_] = 2*x > Then Mathematica gives as output: 2 x > But I'd need something like: f(x) = 2 x > Is there a way to do that ? === Subject: Re: Pretty print > SetAttributes[eqnDef, {Listable,HoldFirst}]; > eqnDef[f_] := > ToString[TraditionalForm[HoldForm[f]]] < = <> ToString[TraditionalForm[f]]; > f[x]:= x^2; > g[n_, z_] := x^2*Exp[-x]*BesselI[n, z]; > eqnDef[f[x]] > eqnDef[{f[x],g[n,x]}]//ColumnForm > Bob Hanlon === Subject: Re: MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True tests=INVALID_DATE,QUOTED_EMAIL_TEXT,RCVD_IN_ORBS, Use SymbolShape->None Needs[Graphics`]; list1=Table[{x, Sin[x]}, {x, 0, 2Pi, Pi/100}]; list2=Table[{x, Cos[x]}, {x, 0, 2Pi, Pi/100}]; MultipleListPlot[list1, list2, PlotJoined->True, PlotStyle->{Blue, Red}, SymbolShape->None, Ticks->{PiScale, Automatic}]; Bob Hanlon === > Subject: MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True > Hi people, I'll need some help in oder to have a decent plot. > Using PlotJoined -> True into the MultipleListPlot you can have a line > between the points of your list. And it's a very nice feature to use, but > when you have something like 1000 point in Plot, and specially if they > are very close to each other, you risk to not see the line joining the > points beacuse of the Symbols used to draw the points in the list. How > can I turn off the point marker drawing? This naturally happen using > ListPlot. In ListPlot when you activate the PointJoined option the point's > shape automatically turn off and you have only a line. I'd like to have > the same result with MultipleListPlot because I'm goind to use different > colors for different data sets. > Anyone can help me? > thank you. > Roberto === Subject: Re: MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True tests=INVALID_DATE,QUOTED_EMAIL_TEXT,RCVD_IN_ORBS, > SymbolShape->None Fantastic! is the simpler solution, and the smarter too! I tried smething similar on my own before writing here, but it didn't worked. probably a mistyping, the error was about None, I was not sure None to exist as an option for SymbolShape so I given up immediatly. Now it's fantstic. Why None in not listed as a possible SymbolShape on Math.5 help? is a generally existing option? bye ------------------------------------------------------------- tutto ci.98 che ho scritto .8f sempre In My Humble Opinion (IMHO) probabilmente l'ho scritto di fretta, quindi scusate se sono stato sbrigativo. === Subject: Re : MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True Hello ! Just take the value of mySize very small ! << Graphics`MultipleListPlot` mySize = 5; MultipleListPlot[{{0, 0}, {2, 3}, {4, 5}}, PlotRange -> {{-0.2, 5}, {-0.2, 6}}, PlotJoined -> True, SymbolShape -> {PlotSymbol[Triangle, mySize]}]; F.Jaccard -----Message d'origine----- ËÊ: mathgroup@smc.vnet.net ObjetÊ: MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True Hi people, I'll need some help in oder to have a decent plot. Using PlotJoined -> True into the MultipleListPlot you can have a line between the points of your list. And it's a very nice feature to use, but when you have something like 1000 point in Plot, and specially if they are very close to each other, you risk to not see the line joining the points beacuse of the Symbols used to draw the points in the list. How can I turn off the point marker drawing? This naturally happen using ListPlot. In ListPlot when you activate the PointJoined option the point's shape automatically turn off and you have only a line. I'd like to have the same result with MultipleListPlot because I'm goind to use different colors for different data sets. Anyone can help me? thank you. Roberto ------------------------------------------------------------- tutto ci=F2 che ho scritto =E8 sempre In My Humble Opinion (IMHO) probabilmente l'ho scritto di fretta, quindi scusate se sono stato sbrigati= vo. === Subject: Why is there a listing for the asymptotic expansion for generalized laguerre polynomials at the wolfram sites Hello Mathematica users: I was hoping that maybe some people might enlighten me why there is an asymptotic series expansion for generalized Laguerre Polynomials listed in : http://functions.wolfram.com/HypergeometricFunctions/LaguerreL3General/06/02 / But when I use FunctionAdvisor in another system; an error is returned. > FunctionAdvisor(asymptotic_expansion,LaguerreL(n,m,x)); The system is unable to compute the asymptotic_expansion for LaguerreL(n,m,x) . Jim Ramberg SF State University === Subject: Re: Re: viewing 3D surfaces And also the simple use of SpinShow from the Animation package should not be overlooked. It has the advantage that it retains all of the graphics directives. If you use the up/down arrow keys you can turn the object around at will and stop to look at a particular view. But you only obtain rotation about one axis. However, this is often sufficient. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ newsgroup I remember to have read that what another system has by way of graphics 3D manipulation Mathematica does not, but here I see it again. Narasimham > Is there now a way to look continuously all around at 3D surfaces by > mouse click/drag, in the way 3D ViewPoint Selector cube can be moved. > It can save much space in the code ( more I meant graphics repeated > output frames) compared to SpinShow frame animations. === Subject: Re: MultipleListPlot without any Point Shape, only with line made by PlotJoined -> True Roberto, One simple option is not to use MultipleListPlot. Just apply Line to your data points and put a graphics color directive first. <True] You can also add Text statements labeling the curves, provided you don't have too many of them on one plot. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi people, I'll need some help in oder to have a decent plot. Using PlotJoined -> True into the MultipleListPlot you can have a line between the points of your list. And it's a very nice feature to use, but when you have something like 1000 point in Plot, and specially if they are very close to each other, you risk to not see the line joining the points beacuse of the Symbols used to draw the points in the list. How can I turn off the point marker drawing? This naturally happen using ListPlot. In ListPlot when you activate the PointJoined option the point's shape automatically turn off and you have only a line. I'd like to have the same result with MultipleListPlot because I'm goind to use different colors for different data sets. Anyone can help me? thank you. Roberto ------------------------------------------------------------- tutto ci=F2 che ho scritto =E8 sempre In My Humble Opinion (IMHO) probabilmente l'ho scritto di fretta, quindi scusate se sono stato sbrigati= vo. === Subject: can't MATHEMATICA simplify simple expressions? if I enter: FullSimplify [ (a^2)^(3/2) ] (in correct MATHEMATICA syntax, the program does not yield the correct result, a^3 ... why is that? -- Johnny: [plugging back in the runway lights] Just kidding. ('Airplane!', 1980) === Subject: Re: Re: can't MATHEMATICA simplify simple expressions? But one should use PowerExpand with caution! As the HelpBrowser entry says: PowerExpand converts (a b)^c to a^c b^c, whatever the form of c is. PowerExpand also converts (a^b)^c to a^(b c), whatever the form of c is. The transformations made by PowerExpand are correct in general only if c is an integer or a and b are positive real numbers. > a) because only for real vaules youn get a^3 > b) PowerExpand[(a^2)^(3/2) ] doesn what you want > Jens > Cole Turner schrieb im Newsbeitrag >>if I enter: >>FullSimplify [ (a^2)^(3/2) ] >>(in correct MATHEMATICA syntax, the program does not yield the correct >>result, a^3 ... >>why is that? -- 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: Re: can't MATHEMATICA simplify simple expressions? It doesn't get that answer because it isn't the right answer--unless, as in PowerExpand, we assume all the variables are positive reals. Bobby >> (in correct MATHEMATICA syntax, the program does not yield the correct >> result, a^3 ... > Try PowerExpand. >> why is that? > Don't know. I'm only just starting to explore the program using the > demo. > Ian -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: can't MATHEMATICA simplify simple expressions? Maybe because you are wrong and it is right? let a=-3. Then a^3 is -27. but (a^2)^(3/2) is 9^(3/2) = 27. At least by conventional interpretation of the symbols In earlier versions of Mathematica, such simplifications WERE done, leading to errors. You might be able to do something with assumptions on the value of a. > if I enter: > FullSimplify [ (a^2)^(3/2) ] > (in correct MATHEMATICA syntax, the program does not yield the correct > result, a^3 ... > why is that? === Subject: Re: can't MATHEMATICA simplify simple expressions? Good observation. I think it's because Mathematica uses an uncommon algorithim to do its calculations -- which is why it can (or COULD, I haven't really tested it out too much in 5) be difficult to get Mathematica to show the steps it took to reach an answer. === Subject: Re: can't MATHEMATICA simplify simple expressions? try making assumptions such as a in Reals ------------------------------------------------------------- tutto ci.98 che ho scritto .8f sempre In My Humble Opinion (IMHO) probabilmente l'ho scritto di fretta, quindi scusate se sono stato sbrigativo. === Subject: Re: can't MATHEMATICA simplify simple expressions? In[12] := Simplify[(a^2)^(3/2), Element[a, Reals]] Out[12] = Abs[a]^3 In[10] := Simplify[(a^2)^(3/2), Element[a, Reals] && a >= 0] Out[10] = a^3 The correct result is a^3 only when a is real and a>=0 jean pellegri Cole Turner a .8ecrit dans le message de > if I enter: > FullSimplify [ (a^2)^(3/2) ] > (in correct MATHEMATICA syntax, the program does not yield the correct > result, a^3 ... > why is that? > -- > Johnny: [plugging back in the runway lights] > Just kidding. > ('Airplane!', 1980) === Subject: Re: can't MATHEMATICA simplify simple expressions? The problem is that you are assuming that a is a real number. While this is normal for most humans, it need not be in a strict mathematical sense. By default Mathematica assumes all variables can be complex. For a complex number the result is not simply a^3. You can place conditions on the simplicication: For example if a>0 In[4]:= FullSimplify [ (a^2)^(3/2),a>0 ] Out[4]= a^3 For a simply a real number In[5]:= FullSimplify [ (a^2)^(3/2),Element[a,Reals] ] Out[5]= Abs[a]^3 > if I enter: > FullSimplify [ (a^2)^(3/2) ] > (in correct MATHEMATICA syntax, the program does not yield the correct > result, a^3 ... > why is that? === Subject: Re: can't MATHEMATICA simplify simple expressions? You need to constrain the domain of a if you want to get the simplification you seek (which is NOT correct in general). FullSimplify [ (a^2)^(3/2) ,a>0] does what you want. Steve Luttrell > if I enter: > FullSimplify [ (a^2)^(3/2) ] > (in correct MATHEMATICA syntax, the program does not yield the correct > result, a^3 ... > why is that? > -- > Johnny: [plugging back in the runway lights] > Just kidding. > ('Airplane!', 1980) === Subject: Re: can't MATHEMATICA simplify simple expressions? Perhaps because the result would NOT necessarily be correct in the case that the number a is complex? Example: a = -I; Then a^3 I By definition, the principal value of (-1)^(3/2) is Exp[(3/2) Log[-1]] that is, Exp[(3/2) (Log[Abs[-1]] + I Arg[-1])] which, since Arg[-1], as Mathematica will tell you, is Pi, is: Exp[(3/2) I Pi] -I Or: a = -1; {a^3, (a^2)^(3/2)} {-1, 1} But: Clear[a] Simplify[(a^2)^(3/2), Element[a, Reals]] Abs[a]^3 Simplify[(a^2)^(3/2), a > 0] a^3 > if I enter: > FullSimplify [ (a^2)^(3/2) ] > (in correct MATHEMATICA syntax, the program does not yield the correct > result, a^3 ... > why is that? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: can't MATHEMATICA simplify simple expressions? Cole Turner ha scritto: > if I enter: > FullSimplify [ (a^2)^(3/2) ] > (in correct MATHEMATICA syntax, the program does not yield the correct > result, a^3 ... > why is that? Mathematica does not know whether a is a positive real number or not (it does not even know it is a number...),you must specify it with Assumptions (see mathematica help): FullSimplify[(a^2)^(3/2),a>0] yelds the correct result. Matteo Delfino