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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: Re: > 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 You really do not want to look at or modify the general underlying code of SetPropertyValue[]. This is a fundamental GUIKit framework function for modifying any and all properties of all widgets in the entire system. You are more specifically interested in the expr property of the GraphPanel and so you want to look at the code that gets and sets this specific property. As I have mentioned to you in previous personal correspondences, this would be in the com.wolfram.guikit.graph.* classes and in particular, the setExpr(Expr e) method on the class com.wolfram.guikit.graph.ExprAccessibleGraphPane.java This is where all of the construction of the nodes and edges of the graph begin by reading the corresponding Mathematica graph expression structure and this is where you would begin to look at or modify how the GraphEdit visual nodes and edges are constructed based on the Mathematica expression being passed in. Jeff Adams Wolfram Research === Subject: Re: Needs[Graphics`Graphics`]; Plot[Sin[x], {x,-Pi,Pi}, Ticks->{PiScale, Automatic}]; Bob Hanlon === > Subject: > 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: 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: 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: 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: 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: 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 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: 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: 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: 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: 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: 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: 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: 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: 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 === 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 === 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: 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: 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: 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: 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 < 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 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