A32 == I'm woking on a kind of a Mathematica cheat-sheet. So I don't have to repeatthe same learning process if I get pulled away for another 6 months.I've attempted to get my domain name to resolve to my IP address, but it seems Verisign and I have different ideas about what 24 hours is.The site is supposed to be www.globalsymmetry.com, but that will not currently resolve. Here's the IP and path:http://66.92.149.152/proprietary/com/wri/index.htmlThis is not a literary masterpiece. It's probably proof that giving just anybody the power to publish is, perhaps, not a guaranty that more quality publication will take place.If anybody has answers to the questions I've come up with, or comments about the answeres, etc. I'd be happy to know. ==== =>>I believe the complexity is O(n log n), so this should be good enough.Umm ...good enough? I understand the words individually, but thephrase makes no sense to me.Bobby Treat-----Original Message-----> crash the Front End. I was thinking about the fact that I calculated> all those digits and then threw them away. I could save them withSave> or DumpSave, and read them in with Get the next time I wanted any of> them, although the file would be close to 70 MB (if not more). I maydo> that, in fact -- I have plenty of disk space. The next step would be to somehow reuse the stored digits if I wanted> MORE digits. But how? The Bailey-Borwein-Plouffe Pi algorithm is an avenue of attack, sinceit> can calculate digits far from the decimal point, without calculating> those in between. Unfortunately, it calculates hexadecimal digits in> that way, not decimal digits. (That's true for the version I've seen,> anyway.) Still, I could take the stored digits, convert tohexadecimal,> add more hexadecimal digits with the B-B-P algorithm, and then convert> back to decimal. In both conversions, I'd have to be very cognizantof> how much precision I end up with, but that shouldn't be too difficult.> It might go faster if I store hexadecimal digits, as well as decimal> digits, to eliminate one of those conversions at each increase in the> number of digits. The next step would be to set up an application that allowed anyone to> ping for digits across the Internet, and would return them if they're> stored. Hasn't someone already done that? It seems as if someone would have. Bobby TreatIf you're interested in decimal digits, I don't think the BBP algorithmis theway to go. In order to get the nth decimal digit of Pi you need tocompute theprevious n-1 digits, since base conversion is global, not local. ThealgorithmMathematica uses for computing Pi is quite fast - I believe thecomplexity is O(nlog n), so this should be good enough.David> -----Original Message-----calculation in So would it take about the same amont of time for the completeprintout> of digits? Of course it would take a few additional seconds to format> the output... Or does Mathematica take alot less time when it truncates the output?> > Could you tell me the CPU you used and its speed etc...i amcurious,performance> to> other programs out there.> > I used one processor of a dual 1GH Mac and got the same answer with> the> following speed:> > 4.2 for Mac OS X (June 4, 2002)> oldmax = $MaxPrecision> 6> 1. 10> $MaxPrecision = Infinity> Infinity> With[{n = 2^26}, Timing[> pd = RealDigits[N[Pi, n + 1], 10, 20,> 19 - n]; ]]> {28794.1 Second, Null}> MaxMemoryUsed[]> 512055204> pd> {{3, 3, 8, 6, 3, 2, 2, 0, 8, 9, 6, 2, 2, 3,> > 4, 0, 9, 8, 0, 3}, -67108844}> > Tom Burton ==== =Edit ->Preferences -> Font OptionsIn Preferences you will find everything you need to configure yourMathematica environment. Also you may want to look up Style Sheets in thebook or the on line help.Yas> I've been trying to get my Mathematica 4.1 properly configured. I set:> ############################################################# ######> /usr/local/mathematica/SystemFiles/FrontEnd/TextResources/X/ Specific.tr:> @@resource maxForXListFonts> 10000 # xlsfonts | wc -l> 5572 /etc/X11/XF86Config:> FontPath /usr/X11R6/lib/X11/fonts/100dpi:unscaled> FontPath /usr/X11R6/lib/X11/fonts/75dpi:unscaled> FontPath /usr/X11R6/lib/X11/fonts/CID> FontPath /usr/X11R6/lib/X11/fonts/Speedo> FontPath /usr/X11R6/lib/X11/fonts/Type1> FontPath /usr/X11R6/lib/X11/fonts/URW> FontPath /usr/X11R6/lib/X11/fonts/kwintv:unscaled> FontPath /usr/X11R6/lib/X11/fonts/latin2/Type1> FontPath /usr/X11R6/lib/X11/fonts/local/mma/Type1> FontPath /usr/X11R6/lib/X11/fonts/local/mma/X:unscaled> FontPath /usr/X11R6/lib/X11/fonts/misc:unscaled> FontPath /usr/X11R6/lib/X11/fonts/misc/sgi:unscaled> FontPath /usr/X11R6/lib/X11/fonts/truetype> FontPath /usr/X11R6/lib/X11/fonts/uni:unscaled # ls -R /usr/X11R6/lib/X11/fonts/ | grep /> /usr/X11R6/lib/X11/fonts/:> /usr/X11R6/lib/X11/fonts/100dpi:> /usr/X11R6/lib/X11/fonts/75dpi:> /usr/X11R6/lib/X11/fonts/CID:> /usr/X11R6/lib/X11/fonts/Speedo:> /usr/X11R6/lib/X11/fonts/Type1:> /usr/X11R6/lib/X11/fonts/URW:> /usr/X11R6/lib/X11/fonts/encodings:> /usr/X11R6/lib/X11/fonts/encodings/large:> /usr/X11R6/lib/X11/fonts/kwintv:> /usr/X11R6/lib/X11/fonts/latin2:> /usr/X11R6/lib/X11/fonts/latin2/Type1:> /usr/X11R6/lib/X11/fonts/local:> /usr/X11R6/lib/X11/fonts/local/mma:> /usr/X11R6/lib/X11/fonts/local/mma/Type1:> /usr/X11R6/lib/X11/fonts/local/mma/X:> /usr/X11R6/lib/X11/fonts/misc:> /usr/X11R6/lib/X11/fonts/misc/sgi:> /usr/X11R6/lib/X11/fonts/truetype:> /usr/X11R6/lib/X11/fonts/uni:> /usr/X11R6/lib/X11/fonts/util: ######################################################## When I open the Mathematica Book Reference Guide in the Help Browser, I get> a beep and the message says: Unable to find font with family Helvetica, weight Bold, slant Plain, and> size 26. Substituting Courier. Compared to the things which *were* broken, this is a minor problem. I can> live with the beep. What I would now like to know is how to tell Mathematica what> fonts to use by default. This seemingly simple question seems to have no> simple answer. Could someone please help me. TIA, ^L ==== => Edit ->Preferences -> Font Options> In Preferences you will find everything you need to configure your> Mathematica environment. Also you may want to look up Style Sheets in the> book or the on line help.> Yas> I went into the preferences browser, and it was not clear to me what I was modifying. At one point I clicked on a field filled with text. I had inteded to edit it, and all the text vanished. It didn't bother me as much as such things use to, because I believe I know a backout strategy. It's been a while since I looked at this stuff, and I have to admit it seems far more tractible than it did a year ago. I'll look at the discussion again, and see if it makes more sence to me now.STH ==== => As an example, I spent several hours trying to figure out how to tell> Mathematica to understand the delete key in the way most contemporary> systems understand it. I wanted to avoid modifying system> configuration files such as:> /usr/local/mathematica/SystemFiles/FrontEnd/TextResources/ KeyEventTranslations.tr I expected to be able to change something in my own ~/.Mathematic> directory, but I could not figure out an obvious way to affect this> modification.If you could post a precise description of what you expect the Delete keyto do when depressed, we could probably provide you with a clear cutanswer of what needs to be done.> I want to adjust the font size used in the widgets, but again, I see> no ovbious means of modifying these attributes. I suspect it can be> accomplished by modifying the ~/.Mathematica/4.1/FrontEnd/init.m.> Perhaps to an experienced Mathematica user, the syntax and semantics> of this file are obvious. They aren't to me.The size of fonts in user interface elements is not specified through theMathemtica init.m file. It is set through an X resource. If you are notfamiliar with resources, you may want to track down an introductory texton the X Window System. Information on application-specific resourcesettings can be found in the Mathematica Getting Started Guide:http://documents.wolfram.com/v4/GettingStarted/ TroubleshootingUnixX.htmlThe setting that you would need to adjust is XMathematica*fontList. Thevalue of the resource is an X Logical Font Description field.> I also find the overall look & feel of the interface to be archaic.That's because Mathematica relies on the Motif library for user interfaceelements.http://www.opengroup.org/desktop/ motif.htmlThe appearance of these elements, such as the menu and scroll bars, wouldbe the same for any other Motif application, such as the DDD debugger orreleases of Netscape prior to verison 4.-- User Interface Programmer paulh@wolfram.comWolfram Research, Inc. ==== =hi,> I sholdn't have to. If I start messing with X resource settings for my> user environment, I am sure to break something else which is configured> based on the current settings. There should either be a GUI interface, or a> clearly documented, and easily accessible configuration file to modify such> properties as the size of the fonts in the GUI widgets. This is> functionality which is rightfully expected of a modern desktop UI.[snip]> And I'm sure there is some configuration file in which I could place that,> and hope that what you think will be read by my system *will* in fact be> read, and not subsequently overridden during xsession startup. Things> aren't the way they used to be back in the 1980s. The modern Unix desktop> has moved beyond the paradigm of openlook and motif. See for example> http://www.trolltech.com, http://www.gnome.org, and http://www.kde.org>moving the frontend over to QT would have some neat side effects: consistent look & feel with the modern linux gui, themeability, source code truetype fonts as QT supports Xrender and Xft (looks great - see KDE3). i think all of those points are of value, but the most important might be source compatibility. ONE frontend for MOST (or ALL) platforms - sounds like a dream :-))gerald -- *************************************Gerald RothM@th Desktop Development************************************* ==== => If you could post a precise description of what you expect the Delete key> to do when depressed, we could probably provide you with a clear cut> answer of what needs to be done.Item[KeyEvent[Delete], DeleteNext]'Most' means Ômore than half.' > I want to adjust the font size used in the widgets, but again, I see> no ovbious means of modifying these attributes. I suspect it can be> accomplished by modifying the ~/.Mathematica/4.1/FrontEnd/init.m.> Perhaps to an experienced Mathematica user, the syntax and semantics> of this file are obvious. They aren't to me.> The size of fonts in user interface elements is not specified through the> Mathemtica init.m file. It is set through an X resource. If you are not> familiar with resources, you may want to track down an introductory text> on the X Window System. I sholdn't have to. If I start messing with X resource settings for my user environment, I am sure to break something else which is configured based on the current settings. There should either be a GUI interface, or a clearly documented, and easily accessible configuration file to modify such properties as the size of the fonts in the GUI widgets. This is functionality which is rightfully expected of a modern desktop UI.> Information on application-specific resource> settings can be found in the Mathematica Getting Started Guide:> http://documents.wolfram.com/v4/GettingStarted/ TroubleshootingUnixX.htmlIt should be in a clear and easy to access configuraton interface, or at least be redily available through the help system in such a way that reasonable queries will locate it. Changing fonts does not belong in a section on trouble shooting, unless this is an acknowledgement that the UI is broken.> The setting that you would need to adjust is XMathematica*fontList. The> value of the resource is an X Logical Font Description field.And I'm sure there is some configuration file in which I could place that, and hope that what you think will be read by my system *will* in fact be read, and not subsequently overridden during xsession startup. Things aren't the way they used to be back in the 1980s. The modern Unix desktop has moved beyond the paradigm of openlook and motif. See for example http://www.trolltech.com, http://www.gnome.org, and http://www.kde.org > I also find the overall look & feel of the interface to be archaic.> That's because Mathematica relies on the Motif library for user interface> elements.> http://www.opengroup.org/desktop/motif.html> The appearance of these elements, such as the menu and scroll bars, would> be the same for any other Motif application, such as the DDD debugger or> releases of Netscape prior to verison 4.My point exactly. ==== =Awk! Legends!Basically, the answer to your question is that the PlotLegend option worksONLY for the Plot command and does not work for other types of plots. Forother types of plots you have to use ShowLegend. And ShowLegend is not allthat easy to use, especially since WRI does not give an example for multiplecurves in the Help.Needs[Graphics`Graphics`]Needs[Graphics`Legend`]{q1[t_], q2[t_], q3[t_]} = {0.1 Exp[-0.02 t], 0.2 Exp[-0.025 t], 0.4 Exp[-0.028 t]};Let's look at your first plot.Plot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> {{AbsoluteThickness[0.5], AbsoluteDashing[{4, 4}]}, AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1, 8}]}}, AxesLabel -> {Y, X}, PlotLabel -> Title, PlotLegend -> {1, 3, 5}, LegendPosition -> {0.5, 0}, ImageSize -> 500];The legend is almost as big as the plot. It distracts from the realinformation you are trying to convey. Furthermore, the order of the curvesin the legend is the reverse of their order in the plot.The following shows how to put the legend in a LogLogPlot, or other types ofplots. I defined the plot styles independently because they are used inseveral places. I made the legend much smaller and put it in an empty areaof the plot. I also reversed the order of the keys so they would match theorder of the curves in the plot.styles={{AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]},{AbsoluteThickness[1.5]},{ AbsoluteThickness[ 2],AbsoluteDashing[{1,8}]}};ShowLegend[ LogLogPlot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> styles, AxesLabel -> {Y, X}, PlotLabel -> Title, ImageSize -> 500, DisplayFunction -> Identity], {MapThread[{Graphics[{Sequence @@ #1, Line[{{0, 0}, {1, 0}}]}], #2} &, {styles, {1, 3, 5}}] // Reverse, LegendPosition -> {-0.7, -0.4}, LegendSize -> {0.2, 0.3}, LegendShadow -> {0.02, -0.02}, LegendSpacing -> 0.5} ];But why use a legend at all? After all, a legend is nothing but another plotin which you have put labels on the curves. Why not put the labels directlyon the curves in the real plot in the first place?LogLogPlot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> styles, AxesLabel -> {Y, X}, PlotLabel -> Title, ImageSize -> 500, Epilog -> MapThread[ Text[SequenceForm[Case , #1], {Log[10, 0.01], Log[10, #2[0.01]]}, {0, -1}] &, {{1, 2, 3}, {q1, q2, q3}}]];In the legend you have keyed the curves to numbers 1, 3 and 5. (Perhaps youjust used these as examples and meant to use something different in the realplots?) But these don't seem to have any obvious relation to your functions.I suppose the reader will have to look at another table or look into thetext of your paper or notebook to find out what 1, 3 and 5 mean. So thereader has to go from the graph to the legend then to the text and thenmentally transfer the meaning of the curve back to the main plot. It is somuch nicer to put the meaning right on the curve if you can.For the most part, legends are just computer junk and not even easy tonicely construct. When the legend urge comes over you - try to resist.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1,8}]}}, AxesLabel[Rule]{Y, X}, PlotLabel[Rule]Title, PlotLegend[Rule]{1,3,5}, LegendPosition[Rule] {0.5,0}](*However with LogPlot or LogLogPlot the legend desappear*)LogLogPlot[{q1[t],q2[t],q3[t]}, {t, 0, 100},PlotStyle[Rule]{ {AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]}, AbsoluteThickness[1.5], {AbsoluteThickness[2], AbsoluteDashing[{1,8}]}}, AxesLabel[Rule]{Y, X}, PlotLabel[Rule]Title, PlotLegend[Rule]{1,3,5}, LegendPosition[Rule] {0.5,0}]I have shown a particular case, but I has this problem always with LegendandLogPlot and LogPlotPlot. I will appreciate any help.GuillermoSanchez---------------------------------------- -----This message was sent using Endymion MailMan. ==== =Using the Front End as a interface with the kernel I was running some calulations when suddenly pressing Shift+Enter causes the contents of the cell being evaluated to transform to the next text underlined with a red line: NotebookObject[FrontEndObject[LinkObject[dd8,1,1]],8] foollowed by the next messages:An unknown box name (NotebookObject) was sent as the BoxForm for the expression. Check the format rules for the expression.An unknown box name (FrontEndObject) was sent as the BoxForm for the expression. Check the format rules for the expression.An unknown box name (LinkObject) was sent as the BoxForm for the expression. Check the format rules for the expression.An invalid typeset structure was generated: Missing BoxFormData.Any suggestions will be very aprreciated.Cesar ==== =I have an odd problem. I need to use and simplify functions that havebeen provided by a piece of software that insists on outputing thefunctional results of a data mining proceedure, using e whenoutputing numbers in scientific notation.I'm having difficultly using Replace, Hold, etc. to correctly evaluatethese types of function formats. For example, y = 5e+5x1+2e-1x2,should be transcribed into 5 10^5 x1 + 0.2 x2.ChuckReply-To: kuska@informatik.uni-leipzig.de ==== =str = 5e+5x1+2e-1x2;StringJoin[Characters[str] /. e -> *10^] // ToExpression??Work fine for me.But this type of output is typical generated by a C/FORTRANProgram and you should rewrite the formating rules inthe code that produce this output. Jens> I have an odd problem. I need to use and simplify functions that have> been provided by a piece of software that insists on outputing the> functional results of a data mining proceedure, using e when> outputing numbers in scientific notation.> I'm having difficultly using Replace, Hold, etc. to correctly evaluate> these types of function formats. For example, y = 5e+5x1+2e-1x2,> should be transcribed into 5 10^5 x1 + 0.2 x2.> Chuck ==== =RB> I am considering the following integralRB> W[m_,n_]:=Integrate[BesselJ[m, x]*BesselJ[n, x], {x, 0, Infinity}]RB> where m,n are reals >=0. With Mathematica 4.1 I obtain:RB> If[Re[m+n]>-1, -Cos[(m-n)Pi/2]/(2 Pi)*RB> (2 EulerGamma + Log[4] +RB> PolyGamma[0, 1/2(1 + m - n)] +RB> PolyGamma[0, 1/2(1 - m + n)] +RB> 2PolyGamma[0, 1/2(1 + m + n)])RB> Any explanation about the analytical expression will beRB> gratefully accepteed.The expression for W[m_,n_] returned by Mathematica is wrong.To prove, just substitute m = n = 0 which is exactly what you had doneand observe that the output you had hadW[0,0]=-(2 EulerGamma + Log[4] + 4 PolyGamma[0, 1/2])/(2 Pi)= 0.84564was incorrect. The correct answer is 1/2.Mathematica can handle the numeric integration successfullyIn[1] := NIntegrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}, Method -> Oscillatory] (* The warnings are skipped *)Out[1] = 0.5Using NIntegrate[BesselJ[0, x]*BesselJ[0, x], {x, 0, Infinity}]without Method -> Oscillatory is not the optimal choice asthe integrand oscillates fairly rapidly over the integrationregion.RB> I suspect that these integrals are divergent (*).In fact, not exactly.Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]is equal to 1/2, and Mathematica 4.1 for Microsoft Windows(November 2, 2000) does it correctly, while Mathematica 4.2for Microsoft Windows (February 28, 2002) concocts a strangemixture of a wrong divergence message and the warning thatit cannot check the convergence [should I trust to the secondwarning? or the first?]As a matter of fact,Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]converges because the integrand is regular at x=0, bounded overthe whole right semi-axis, and decays as2*Cos[Pi/4 - x]*Cos[(3*Pi)/4 - x]/(Pi*x) + o(1/x)at x -> Infinity .Say, calculateNormal[Series[BesselJ[1, x], {x, Infinity, 1}]] Normal[Series[BesselJ[0, x], {x, Infinity, 1}]] // InputForm->(2*(Cos[Pi/4 - x] - Sin[Pi/4 - x]/(8*x))*(Cos[(3*Pi)/4 - x] +(3*Sin[(3*Pi)/4 - x])/(8*x)))/(Pi*x)then Plot[%,{x,1,10}]and Plot[BesselJ[1,x]*BesselJ[0,x],{x,1,10}]and you could hardly see the difference.Generally, to get to the convergence domain for W in terms ofm and n is easy via the asymtotics of the Bessel functions(use something likeExpand[Normal[Series[BesselJ[m, x], {x, Infinity, 1}]]Normal[Series[BesselJ[n, x], {x, Infinity, 1}]]]then analyze the main term).Best wishes,Vladimir BondarenkoMathematical DirectorSymbolic Testing GroupWeb : http://www.CAS-testing.org/ http://maple.bug-list.org/VER2/ (under tuning) http://maple.bug-list.org/VER3/ (under tuning) http://maple.bug-list.org/VER1/ (under tuning) http://www.beautyriot.com/ (teamwork) http://www.ohaha.com/ (teamwork) Voice: (380)-652-447325 Mon-Fri 9 a.m. - 6 p.m.Mail : 76 Zalesskaya Str, Simferopol, Crimea, Ukraine ==== => inside a program I need to solve this linear equation in terms of p1.> However something odds happens. Sometimes the solution is computed and> sometimes the result is empty [I mean no output...]. Is this a bug of the> solve command or am I doing something wrong? The problem is robust to:> changing name to the variables and other makeups..> DavidThat's the weirdest bug I've seen in weeks. As it happens, it's mine. Atleast the inconsistent behavior, that is. I'll fix it, and maybe alsotry to address the issue of how to handle approximate numbers in testingsubexpressions for zero.I've excised your code and put in place a substantially smaller examplethat I believe is responsible. The table will tend to give erraticresults.zz = (-1.*x^7*(-1. + p - 7.*x^6 + p*x^6 + 6.*x^7)* (7.000000000000002 - 7.000000000000002*x + 14.000000000000004*x^6 - 14.000000000000004*x^7 + 7.000000000000002*x^12 -6.999999999999998*x^13))/ (p^2*(1. + 0.9*x^6)^2*(1. + x^6)^5);One workaround would be to use exact input, say by preprocessing withRationalize.Daniel LichtblauWolfram Research ==== =>inside a program I need to solve this linear equation in terms of p1.>However something odds happens. Sometimes the solution is computed and>sometimes the result is empty [I mean no output...]. Is this a bug of the>solve command or am I doing something wrong? The problem is robust to:>changing name to the variables and other makeups..>David>>ps: Sorry for the stupid way in which I copied the command...>>Solve[(x^2*((-0.9*x^7*(p^2*(-1 - 5.8*x^6 - 14.010000000000002*x^12 -> 18.04*x^18 - 13.06*x^24 -> 5.040000000000001*x^30 - 0.81*x^36) +> x*(7.777777777777779 - 9.074074074074076*x +> 30.333333333333336*x^6 -> 21.51851851851852*x^7 -> 16.333333333333336*x^8 +> 44.33333333333334*x^12 +> 3.188888888888883*x^13 -> 65.68333333333332*x^14 +> 28.777777777777786*x^18 +> 47.937037037037044*x^19 -> 100.10000000000002*x^20 + 7.*x^24 +> 45.6037037037037*x^25 -> 69.53333333333333*x^26 +> 13.299999999999999*x^31 -> 19.833333333333332*x^32 -> 1.0499999999999996*x^38) +> p*(-6 + 8.296296296296296*x -> 28.799999999999997*x^6 +> 32.785185185185185*x^7 +> 9.333333333333336*x^8 -> 55.260000000000005*x^12 +> 49.04777777777776*x^13 +> 38.38333333333334*x^14 -> 52.980000000000004*x^18 +> 34.20518518518518*x^19 +> 60.20000000000001*x^20 -> 25.380000000000003*x^24 +> 11.736296296296294*x^25 +> 43.63333333333334*x^26 - 4.86*x^30 +> 2.8999999999999986*x^31 +> 13.533333333333333*x^32 + 0.81*x^37 +> 1.0499999999999996*x^38)))/(x + 1.9*x^7 +> 0.9*x^13)^2 - ((-1 + p - 7*x^6 + p*x^6 +> 6*x^7)*(1.2962962962962965 - 3.111111111111112*x^6>+> 9.333333333333336*x^7 - 10.111111111111114*x^12>+> 22.05*x^13 - 5.703703703703705*x^18 + 17.15*x^19>+> 5.483333333333331*x^25 + 1.0499999999999996*x^31>+> p1*x^5*(7.000000000000002 - 7.000000000000002*x>+> 14.000000000000004*x^6 -> 14.000000000000004*x^7 +> 7.000000000000002*x^12 -> 6.999999999999998*x^13) -> 1.166666666666667*p*x^4*x1 -> 3.500000000000001*p*x^10*x1 -> 1.0500000000000003*p*x^11*x1 -> 3.500000000000001*p*x^16*x1 -> 3.150000000000001*p*x^17*x1 -> 1.166666666666667*p*x^22*x1 -> 3.150000000000001*p*x^23*x1 -> 1.0500000000000003*p*x^29*x1))/((1 + 0.9*x^6)^2*(1>+> x^6)^2)))/(p^2*(1 + x^6)^3) == 0, p1]>You might find it more robust (and the results cleaner) if you Simplify the equation prior to using Solve. Such asSolve[eqn // Rationalize // Simplify, p1]However, if you are assigning values to p or x prior to using Solve, there may not be a solution. That is, for whenever the numerator of the expression for p1 would be zero, e.g., p = (-6 x^7 + 7 x^6 +1)/(x^6 + 1).Bob Hanlon ==== =I prefer to delete all output and then Copy As>Notebook expression. ItBobby-----Original Message-----andoutput --- I try to use one tab indent for input and two tabs indent foroutput, plus some blank line adjustment.I wonder if anyone has a way of automatically achieving thisreformating.--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Often posters to MathGroup copy and paste in the complete cellexpression,> including the In and Out numbers, when posting to MathGroup. I wonder if this is the best method because one can't then just copyoutall> the statements and paste them into a Mathematica notebook. All thestatement> numbers have to be edited out and if there are many statementdefinitions> this is an extended task for any responder. This, of course, decreasesthe> chances for a response. A better method is for the poster to just copyand> paste the CONTENTS of each cell. This is more work for the poster, butit> may pay off in better responses. David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/ ==== =Could someone explain what is going on here, please?In[1]:= a = 77617.; b = 33096.; In[2]:=SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity]; SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:=f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b)In[5]:=SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:=fOut[6]=-1.1805916207174113*^21In[7]:=a = 77617; b = 33096; In[8]:=g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + (55/10)*b^8 + a/(2*b)In[9]:=gOut[9]=-(54767/66192)In[10]:=N[%]Out[10]=- 0.8273960599468214PK ==== =Peter,I hope that the following example will help - it is a matter or when thingsevaluate.The a in SetAccuracy[a, Infinity], below, evaluates before SetAccuracy acts,so we getSetAccuracy[2.3, Infinity]. The value of a is not changed. a = 2.3; aa = SetAccuracy[a, Infinity] 2589569785738035/1125899906842624But, a 2.3Whereas aa 2589569785738035/1125899906842624--Allan--------------------- Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Could someone explain what is going on here, please? In[1]:=> a = 77617.; b = 33096.; In[2]:=> SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];> SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:=> f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) In[5]:=> SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:=> f Out[6]=> -1.1805916207174113*^21 In[7]:=> a = 77617; b = 33096; In[8]:=> g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + (55/10)*b^8+ a/(2*b) In[9]:=> g Out[9]=> -(54767/66192) In[10]:=> N[%] Out[10]=> -0.8273960599468214> PK> ==== =In receiving notebooks from many different people I have noticed thatbeginners often do not know how to use Text cells and write all of theircomments as Input cells. I have even run across some extremely advancedusers who did not know the easy method for entering Text cells. A goodnotebook is usually a blend of Text cells, Input/Output cells and graphicscells. Text cells are very useful for documenting what you are doing andpassing information to other people. Since many people do not know how touse Text cells, I thought I would write a little explanation for beginnerswho are followers of MathGroup.The very easiest method for entering a Text cell is to put the insertionpoint where you want the new cell to be (at the end of the notebook orbetween two existing cells) and then type Alt-7. Then just start typing andyou will have a Text cell.Alternatively you can use MenuFormatStyleText to start a new Text cell.Often, it is useful to put the ToolBar at the top of the notebook. UseMenuFormatShow ToolBar. The drop-down menu on the ToolBar has the variouskinds of cells available for the current style of the notebook. You canselect Text (or any other style) from there.Some users may hesitate to use Text cells because they want to include amathematical expression in the comments. However, that is also very easy.Just use an Inline cell within the text cell. At the point within the textcell where you want to include a mathematical expression, start an Inlinecell by typing Ctrl-(. A selection placeholder will appear on a pinkbackground. You can type a Mathematica expression there just as in an Inputcell. Use Ctrl-) to complete the Inline cell, or Shift-Space. You can evenselect an Inline cell and evaluate it with Shift-Ctrl-Enter.Putting comments in Text cells is far better than using Input cells (or cellgroup header cells). Mathematica won't try to evaluate Text cells, the textwill wrap properly and adjust better to the notebook width if you change it.You can also check the spelling of words by putting the cursor after a wordand using Ctrl-K. (In an Input cell Mathematica doesn't use the dictionary,but uses the table of symbols instead and hence it won't check spelling.)David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ Reply-To: murray@math.umass.edu ==== =David Park's posting reminded me of a frequent annoyance when I am trying to include some Mathematica expressions within text cells -- a Mathematica input expression in Standard Form that involves use of a Control-key combination to form a superscript, square-root, or built-up fraction:For example, suppose I want to include within a text cell a Standard Form expression for the square of x, with the exponent 2 raised. If I type the x first, even if I immediately highlight it and change it to Courier (to match the default font for Input cells in Standard Form), as soon as I press the Control-^ key combination, an Inline cell is created beginning with the x, and then when I type the exponent 2 everything in that Inline cell is now in Times, and the x is Italic. To change both characters to Courier is not so easy: it seems to require separately the entire Inline cell and selecting Courier does not change the exponent!)So to avoid this annoyance I normally must first type the desired expression in a separate Input cell, then copy the contents of that cell to the desired point in the Text cell.Any suggestions on a more efficient method for handling this?> In receiving notebooks from many different people I have noticed that> beginners often do not know how to use Text cells ....> Some users may hesitate to use Text cells because they want to include a> mathematical expression in the comments....> Just use an Inline cell within the text cell....-- Murray Eisenberg murray@math.umass.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375Reply-To: kuska@informatik.uni-leipzig.de ==== =just one comment: the meaning of the Alt-7 key depend on the style sheet that is in use.The TMJ style use Alt-8 for text and one hasto learn new key short-cuts for every style sheet ! Jens> In receiving notebooks from many different people I have noticed that> beginners often do not know how to use Text cells and write all of their> comments as Input cells. I have even run across some extremely advanced> users who did not know the easy method for entering Text cells. A good> notebook is usually a blend of Text cells, Input/Output cells and graphics> cells. Text cells are very useful for documenting what you are doing and> passing information to other people. Since many people do not know how to> use Text cells, I thought I would write a little explanation for beginners> who are followers of MathGroup.> The very easiest method for entering a Text cell is to put the insertion> point where you want the new cell to be (at the end of the notebook or> between two existing cells) and then type Alt-7. Then just start typing and> you will have a Text cell.> Alternatively you can use MenuFormatStyleText to start a new Text cell.> Often, it is useful to put the ToolBar at the top of the notebook. Use> MenuFormatShow ToolBar. The drop-down menu on the ToolBar has the various> kinds of cells available for the current style of the notebook. You can> select Text (or any other style) from there.> Some users may hesitate to use Text cells because they want to include a> mathematical expression in the comments. However, that is also very easy.> Just use an Inline cell within the text cell. At the point within the text> cell where you want to include a mathematical expression, start an Inline> cell by typing Ctrl-(. A selection placeholder will appear on a pink> background. You can type a Mathematica expression there just as in an Input> cell. Use Ctrl-) to complete the Inline cell, or Shift-Space. You can even> select an Inline cell and evaluate it with Shift-Ctrl-Enter.> Putting comments in Text cells is far better than using Input cells (or cell> group header cells). Mathematica won't try to evaluate Text cells, the text> will wrap properly and adjust better to the notebook width if you change it.> You can also check the spelling of words by putting the cursor after a word> and using Ctrl-K. (In an Input cell Mathematica doesn't use the dictionary,> but uses the table of symbols instead and hence it won't check spelling.)> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/ ==== =Solve[youre equation, p1, VerifySolutions->True] will return a solution. So willSolve[Rationalize[your equation],p1].Andrzej KozlowskiToyama International UniversityJAPAN inside a program I need to solve this linear equation in terms of p1.> However something odds happens. Sometimes the solution is computed and> sometimes the result is empty [I mean no output...]. Is this a bug of > the> solve command or am I doing something wrong? The problem is robust to:> changing name to the variables and other makeups..> David ps: Sorry for the stupid way in which I copied the command... Solve[(x^2*((-0.9*x^7*(p^2*(-1 - 5.8*x^6 - 14.010000000000002*x^12 -> 18.04*x^18 - 13.06*x^24 -> 5.040000000000001*x^30 - 0.81*x^36) +> x*(7.777777777777779 - 9.074074074074076*x +> 30.333333333333336*x^6 -> 21.51851851851852*x^7 -> 16.333333333333336*x^8 +> 44.33333333333334*x^12 +> 3.188888888888883*x^13 -> 65.68333333333332*x^14 +> 28.777777777777786*x^18 +> 47.937037037037044*x^19 -> 100.10000000000002*x^20 + 7.*x^24 +> 45.6037037037037*x^25 -> 69.53333333333333*x^26 +> 13.299999999999999*x^31 -> 19.833333333333332*x^32 -> 1.0499999999999996*x^38) +> p*(-6 + 8.296296296296296*x -> 28.799999999999997*x^6 +> 32.785185185185185*x^7 +> 9.333333333333336*x^8 -> 55.260000000000005*x^12 +> 49.04777777777776*x^13 +> 38.38333333333334*x^14 -> 52.980000000000004*x^18 +> 34.20518518518518*x^19 +> 60.20000000000001*x^20 -> 25.380000000000003*x^24 +> 11.736296296296294*x^25 +> 43.63333333333334*x^26 - 4.86*x^30 +> 2.8999999999999986*x^31 +> 13.533333333333333*x^32 + 0.81*x^37 +> 1.0499999999999996*x^38)))/(x + 1.9*x^7 +> 0.9*x^13)^2 - ((-1 + p - 7*x^6 + p*x^6 +> 6*x^7)*(1.2962962962962965 - > 3.111111111111112*x^6 +> 9.333333333333336*x^7 - > 10.111111111111114*x^12 +> 22.05*x^13 - 5.703703703703705*x^18 + > 17.15*x^19 +> 5.483333333333331*x^25 + > 1.0499999999999996*x^31 +> p1*x^5*(7.000000000000002 - > 7.000000000000002*x +> 14.000000000000004*x^6 -> 14.000000000000004*x^7 +> 7.000000000000002*x^12 -> 6.999999999999998*x^13) -> 1.166666666666667*p*x^4*x1 -> 3.500000000000001*p*x^10*x1 -> 1.0500000000000003*p*x^11*x1 -> 3.500000000000001*p*x^16*x1 -> 3.150000000000001*p*x^17*x1 -> 1.166666666666667*p*x^22*x1 -> 3.150000000000001*p*x^23*x1 -> 1.0500000000000003*p*x^29*x1))/((1 + > 0.9*x^6)^2*(1 +> x^6)^2)))/(p^2*(1 + x^6)^3) == 0, p1]>Reply-To: murray@math.umass.edu ==== =For all names, perhaps: Names[*`*]For names you defined at a normal session (without changing to some other context than the default Global`): Names[Global`*]> IIRC, there is a way to get a list of all the symbols defined in the > currently running session. I can't seem to find the reference to that > command. Could somone point me in the direction of documentation which > will tell me how to get information about the current session?> TIA,> -- Murray Eisenberg murray@math.umass.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375 ==== => For all names, perhaps:> Names[*`*]> For names you defined at a normal session (without changing to some> other context than the default Global`):> Names[Global`*]> IIRC, there is a way to get a list of all the symbols defined in the> currently running session. I can't seem to find the reference to that> command. Could somone point me in the direction of documentation which> will tell me how to get information about the current session?> TIA,> I think I asked the wrong question. I'll have to look at things some more. What you gave me resulted in far more than I was looking for.http://public.globalsymmetry.com/proprietary/com/wri/ system-symbols.htmlhttp://66.92.149.152/proprietary/com/wri/ system-symbols.htmlI think I really hosed the code for generating that table. I used 5 lines. I probably didn't need more than two, but I'm too tired right now to think about it. Mathematica is totaly awesome when it comes to what it was intended for. They really need to rent a Troll for a few months and fix this interface. Qt will run on just about anything. Heck, my Win-XP partition runs XFree86, with the KDE, or it did when I booted into XP a month ago.STH ==== =?*does the trick. You can limit it to Global variables with?Global`*Bobby-----Original Message-----Sender: steve@smc.vnet.netApproved: Steven M. Christensen , Moderator ==== =Well, first of of all, your using SetAccuracy and SetPrecision does nothing at all here, since they do not change the value of a or b. You should use a = SetAccuracy[a, Infinity] etc. But even then you won't get the same answer as when you use exact numbers because of the way you evaluate f. Here is the order of evaluation that will give you the same answer, and should explain what is going on:f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121* b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity];a = 77617.; b = 33096.;a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity];f 54767-(-----) 66192Andrzej KozlowskiToyama International UniversityJAPAN> Could someone explain what is going on here, please? In[1]:=> a = 77617.; b = 33096.; In[2]:=> SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];> SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:=> f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + > a/(2*b) In[5]:=> SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:=> f Out[6]=> -1.1805916207174113*^21 In[7]:=> a = 77617; b = 33096; In[8]:=> g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + > (55/10)*b^8 + a/(2*b) In[9]:=> g Out[9]=> -(54767/66192) In[10]:=> N[%] Out[10]=> -0.8273960599468214> PK> ==== =Andrzej, Bobby, PeterIt looks as if using SetAccuracy succeeds here because the inexact numbersthat occur have finite binary representations. If we change them slightly toavoid this then we have to use Rationalize:1) Using SetAccuracy Clear[a,b,f] f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b ^8+a/(2*b), Infinity]; a=77617.1; b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity ]; f - 15640321149084868351974949239896188679725401538739519428131155 14949389123623452500771916869370459119776018798804630436149786 9199129319625743010292363124675/ 10867106143970760551000357827554793888198143135975649579607989 867743572824016 06539536129829321813712324363677397376040962) Rewriting as fractions a=776171/10; b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2 *b) -(5954133808997234115690303589909929091649391296257/ 41370125000000)3) Using Rationalize Clear[a,b,f]f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121* b^4-2)+5.4*b^8+a/(2*b),0]; a=77617.1; b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ 41370125000000)I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Well, first of of all, your using SetAccuracy and SetPrecision does> nothing at all here, since they do not change the value of a or b. You> should use a = SetAccuracy[a, Infinity] etc. But even then you won't> get the same answer as when you use exact numbers because of the way> you evaluate f. Here is the order of evaluation that will give you the> same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*> b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.;> b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767> -(-----)> 66192 Andrzej Kozlowski> Toyama International University> JAPAN> Could someone explain what is going on here, please?> > In[1]:=> a = 77617.; b = 33096.;> > In[2]:=> SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];> SetPrecision[a, Infinity]; SetPrecision[b, Infinity];> > In[4]:=> f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 +> a/(2*b)> > In[5]:=> SetAccuracy[f, Infinity]; SetPrecision[f, Infinity];> > In[6]:=> f> > Out[6]=> -1.1805916207174113*^21> > In[7]:=> a = 77617; b = 33096;> > In[8]:=> g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +> (55/10)*b^8 + a/(2*b)> > In[9]:=> g> > Out[9]=> -(54767/66192)> > In[10]:=> N[%]>> Out[10]=> -0.8273960599468214> > PK> > ==== => Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}] is equal to 1/2, and Mathematica 4.1 for Microsoft Windows> (November 2, 2000) does it correctly, while Mathematica 4.2> for Microsoft Windows (February 28, 2002) concocts a strange> mixture of a wrong divergence message and the warning that> it cannot check the convergence [should I trust to the second> warning? or the first?]In[6]:=Integrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity}]Out[6]=1/2In[7]:=Out[7]=4.2 for Mac OS X (June 4, 2002)Andrzej KozlowskiToyama International UniversityJAPAN ==== =That should read ...denominator of the expression for p1... Bob>You might find it more robust (and the results cleaner) if you Simplify>the >equation prior to using Solve. Such as>>Solve[eqn // Rationalize // Simplify, p1]>>However, if you are assigning values to p or x prior to using Solve, there>>may not be a solution. That is, for whenever the numerator of the expression>>for p1 would be zero, e.g., >>p = (-6 x^7 + 7 x^6 +1)/(x^6 + 1).>Bob Hanlon ==== => The expression for W[m_,n_] returned by Mathematica is wrong. To prove, just substitute m = n = 0 which is exactly what you had done> and observe that the output you had had> W[0,0]=-(2 EulerGamma + Log[4] + 4 PolyGamma[0, 1/2])/(2 Pi)> = 0.84564> was incorrect. The correct answer is 1/2.> Mathematica can handle the numeric integration successfully> In[1] := NIntegrate[BesselJ[1, x]*BesselJ[0, x], {x, 0, Infinity},> Method -> Oscillatory]> (* The warnings are skipped *)> Out[1] = 0.5You'll find that W[m=1,n=0]=1/2, so Mathematica gets that right. W[0,0]diverges. Mathematica gets that wrong.I note that Mathematica yields a result forIntegrate[BesselJ[m, a*x]*BesselJ[n, b*x], {x, 0, Infinity}]that appears to agree with formula 6.512(1) of Gradshteyn and Ryshik (4thed., 1965), including the condition b True]If the zi's need to be scaled, then you can do something like this:colorfn = Hue[.67#]&;With[{ m = {Min[#],Max[#]}&@vals }, Show[Graphics[ {colorfn[#[[3]]], PointSize[.01], Point[{#[[1]],#[[2]]}]}]& /@ (data /. {x_,y_,z_} -> {x, y, (z-m[[1]])/(m[[2]]-m[[1]])}), Axes -> True]]---Selwyn Hollis> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of > ==== =John,It is easier to do without ListPlot:Make some data,dat= Table[Random[],{10},{3}];Show[Graphics[{PointSize[.05],{Hue[2 /3#3],Point[{#1,#2}]}&@@@dat} ], Frame->True ];If the points need to be joined then something likeShow[Graphics[{ Line /@Partition[dat[[All,{1,2}]],2,1], PointSize[.05],{Hue[2/3#3],Point[{#1,#2}]}&@@@dat } ], Frame->True ];--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of ==== =A few years ago we made a package that do just this. Seehttp://cern.ch/jowett/Mathematica/Graphics/ ColorListPlot.htmlThe type of plot you want is covered in the section Examples thenThree-dimensional data. The Introduction gives links for downloading thepackage.JMJ> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of ==== =Your problem can be solved in numerous ways of course, try something like .:Module[ { data=Flatten[Table[{x,y,Random[]},{x,10},{y,10}],1] }, Show[ Graphics[ { AbsolutePointSize[10], data/.{x_,y_,z_}[Rule]{Hue[z],Point[{x,y}]} } ] ,AspectRatio[Rule]Automatic ] ]Note that you can replace the main part, ie the transforming rule from pointlists to colored point directives with a function for example .:{Hue[#3],Point[{#1,#2}]}&@@@databye,Borut| I have a list of points l1={xi,yi,zi} how can I make a 2D list plot ofReply-To: kuska@informatik.uni-leipzig.de ==== =data = Table[{Random[], Random[], Random[]}, {20}];Show[Graphics[ {Hue[Last[#]], Point[Take[#, 2]]} & /@ data, Axes -> True ] ] Jens> I have a list of points l1={xi,yi,zi} how can I make a 2D list plot of ==== =input = 5e+5x1+2e-1x2;StringJoin[Characters[input] //. e -> *10^]5*10^+5x1+2*10^-1x2ToExpression[%]500000*x1 + x2/5Bobby Treat-----Original Message-----should be transcribed into 5 10^5 x1 + 0.2 x2.Chuck ==== =Neither SetAccuracy[expr,n] nor SetPrecisions[expr,n] modify expr. These functions modify the prinout not the internal representation. So, the first computation of f is done with approximate numbers and doesn't result in a correct answer due to approximate arithmetic.By assigning a rational expression to each of the variables, you have made them exact numbers and Mathematica responds with an exact solution.>Could someone explain what is going on here, please?>>In[1]:= a = 77617.; b = 33096.;>>In[2]:= SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];>SetPrecision[a, Infinity]; SetPrecision[b, Infinity];>>In[4]:= f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +>5.5*b^8 + a/(2*b)>>In[5]:= SetAccuracy[f, Infinity]; SetPrecision[f, Infinity];>>In[6]:= f>>Out[6]= -1.1805916207174113*^21>>In[7]:= a = 77617; b = 33096;>>In[8]:= g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +>(55/10)*b^8 + a/(2*b)>>In[9]:= g>>Out[9]= -(54767/66192)>>In[10]:= N[%]>>Out[10]= -0.8273960599468214>PK> ==== =SetAccuracy. However, I still don't understand why the order in which we set the accuracies for f, a, and b matters.In[1]:=f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = SetAccuracy[77617., Infinity]; b = SetAccuracy[33096., Infinity]; In[4]:=fOut[4]=-(54767/66192)In[5]:=f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity] Out[5]=1180591620717411303424Similarily:In[1]:=f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 50]; a = SetAccuracy[77617., 100]; b = SetAccuracy[33096., 100]; In[4]:=fOut[4]=-0.8273960599468212641107299556`11.4133In[5]:= f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; Out[5]=1.180591620717411303424`121.0721*^21-PK ==== =Hallo,I have the problem, that I want to determine the numerical solution of a double integral, like e.g. the following:<< Statistics`ContinuousDistributions`ndist = NormalDistribution[0, 1];N[Sigma^2/(Abs[Mu_1^2 - Mu_2^2]) Integrate[(Integrate[1/y_1 1/(y - y_1) PDF[ndist, d*Log[y_1] + c*Log[y - y_1] + f]*PDF[ndist, Sigma*(c*Log[y_1] + d*Log[y - y_1] + g)], {y_1,0,y}]), {y,0,Lambda}]]wherebyLambda := 3;Mu_1 := 4;Mu_2 := 5;Sigma := 0.25;a = 1/2 (Mu_1^2 + Mu_2^2/Sigma^2)b = 1/2 (Mu_2^2 + Mu_1^2/Sigma^2)c = -Mu_2/(Mu_1^2 - Mu_2^2)d = -Mu_1/(Mu_2^2 - Mu_1^2)f = d*a + c*bg = c*a + d*bSorry for the poor code... The problem is, that Mathematica doesn't give me a result (after waiting 2 hours I turned my machine off).Thus, the question is, if there is still a possibility of solving such complicated expressions...TIA,Sven. ==== =I am trying to solve a system of simultaneous equations with 26 variablesand 14 equations (the 12 free variables can be any of the 26 from the eqns..preferably ones that will minimize the computation time for the other 14).These equation are not linearly related.. the highest degree in any one eqnis degree 4 i believe.. and there are some cross terms in the equations butnot every equation depends on every variable.. (some are actually rathersimple eqns). Any ideas on how to get started with this using mathematica (any ideas for algorithms)..Anything will be helpful..I can be reached at ngupta2@seas.upenn.eduMany thanks,Nachi ==== =I should add that the solution is over natural numbers.. this willprobably make a big difference..Nachi> I am trying to solve a system of simultaneous equations with 26 variables> and 14 equations (the 12 free variables can be any of the 26 from the eqns..> preferably ones that will minimize the computation time for the other 14).> These equation are not linearly related.. the highest degree in any one eqn> is degree 4 i believe.. and there are some cross terms in the equations but> not every equation depends on every variable.. (some are actually rather> simple eqns). Any ideas on how to get started with this using> mathematica (any ideas for algorithms)..>> Anything will be helpful.. I can be reached at ngupta2@seas.upenn.edu Many thanks, Nachi ==== =This may seem like a trivial issue, but I find it very frustrating. I use variety of intellectual domains. In every package (JBuilder, KMail, Emacs, XEmacs, Mozilla, xterm, Konsole, etc.) the keyboar mapping is a bit differnt from the other. There are certain idioms which I find to be fairly invaraint between these different packages. I tend to use this common subset more than the package specific idioms.Switching from one package to the next can be a very disorienting experience. It can be even trickier to try and copy and paste from one to the next. I also use Ôspecial' characters in certain domains, .8d,?,.81,?,[CapitalYAcute],fi, §, ø, etc. Add to all of this, that I run beta code for just about everything. The function of my keyboard changed like the weather. I have spent hours trying to figure out why I can no longer type Ô.9a'. This doesn't even address the problems of switching between character encodings, or keyboard compose modes. The last thing I want to start doing is messing with the key mappings in my user environment. I want to control the way my keyboard works with Mathematica from within the Mathematica runtime environment. That is, the configuration should be loaded when Mathematica loads, and should not impact the rest of my X environment.If I have come across as a bit jaded regarding this issue, there are reasons. There is a history. I don't find keyboard configuration issues interesting. I want my fine keyboard to just work, the way I want it to Shift+point movement = select text.Ctrl+Insert = copyShift+Insert = pasteCtrl+c = copyCtrl+x = cutCtrl+v = pasteShift+End = select to end of line.etc.Yes, I said I use XEmacs, and Emacs. Yes (X)Emacs is different, but adding yet another alteration with Mathematica is just too much. Is there a way around this?STH ==== =>FrontEndExecute[{> FrontEnd`NotebookWrite[FrontEnd`SelectedNotebook[],> [LeftDoubleBracket][RightDoubleBracket],After]}] FrontEndExecute[{ FrontEnd`NotebookWrite[FrontEnd`SelectedNotebook[], [LeftDoubleBracket][RightDoubleBracket],After], FrontEnd`SelectionMove[FrontEnd`SelectedNotebook[], Previous, Character]}]orFrontEndExecute[{ FrontEnd`NotebookWrite[FrontEnd`SelectedNotebook[], [LeftDoubleBracket][SelectionPlaceholder][RightDoubleBracket] , Placeholder]}]----------------------------------------------- ---------------Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== =I'm trying to address the special issues related to using Mathematica on the would not if I used a Windows system. These are typically not all that big if a problem _once I figure out what's going on_. What I hope to do is collect all such matters and document them effectively in something like a haven't discussed here http://66.92.149.152/proprietary/com/wri/index.html I'm interested in hearing what you have to say. Of particular interest are the issues faced by a person who is not familiar with the technical aspects would help make this less painful?STHReply-To: jmt@dxdydz.net ==== =See the MathLink API for C, or the JLink API for java.JLink is easier to use, MathLink is a lower level but native interface. JLink is built on MathLink.As far as I know, the perl API Math::ematica has not been upgraded to Mathematica 4.> Is it possible to get a document of the description of how to> interface with the kernel? Kind of what should an interface say to the> kernel and how to connect to it.> Paulo> ==== =Is it possible to get a document of the description of how tointerface with the kernel? Kind of what should an interface say to thekernel and how to connect to it.Paulo ==== =for your extensive answer but I still have some doubts about convergence of the following integral (m,nintegrers>=0)W[m_,n_]:=Integrate[BesselJ[m, x]*BesselJ[n, x], {x, 0, Infinity}]for wich Mathematica gives the close form W[m_,n_]:= -Cos[(m-n)Pi/2]/(2 Pi)* ( 2 EulerGamma + Log[4] + PolyGamma[0, 1/2(1 + m - n)] + PolyGamma[0, 1/2(1 - m + n)] + 2PolyGamma[0, 1/2(1 + m + n)] )You say this integral is convergent to 1/2 for m=0 and n=1.Also Mathematica agrees to you since for m>=0W[m,m+1]=1/2W[m,m+3]=-1/2Numerically we haveNIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, 0, Infinity}]NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy....0.597973NIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, 0, Infinity}, Method ->Oscillatory]NIntegrate::ploss : ....0.5So I define also the corresponding numeric definitionNW[m_, n_] := NIntegrate[BesselJ[m, x]*BesselJ[n, x], {x, 0, Infinity},Method -> Oscillatory]THEORYThe integral is the critical case of Weber-Schafheitlin integral(see Watson book on Bessel function p.402, or Ryzhik-Gradshteyn 6.574(2)).According to this theoryWS[m_,n_,p_]:=Integrate[BesselJ[m, x]*BesselJ[n, x] x^-p, {x, 0, Infinity}]= A/BwhereA=Gamma[p]*Gamma[(n+m-p+1)/2]B=2^p Gamma[(n-m+p+1)/2]Gamma[(n+m+p+1)/2]Gamma[(m-n+p+1)/2]By the presence of Gamma[p] in numerator A, in the case p=0 as in W[m,n]all these integrals are divergent since Gamma[0]=Infinity.The integral exist if m+n+1 > p > 0.ASYMPTOTICSThe Watson theory is in conßict with Mathematica and your notes accordingwhichthe asyntotic trend 1/x of the integrand in W[m,n] is enough forconvergernce. I divide the integral in two partsWasy[m_,n_,a_]=NIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, 0, a]+ NIntegrate[BesselJ[0, x]*BesselJ[1, x], {x, a, Infinity}]and if a>>1 I use asyntotic expansion of Bessel function in the secondintegralso that I can writeWasy[m_,n_,a_]= int1[m,n,a]+int2[m,n,a]whereint1[m_,n_,a_]:=NIntegrate[ BesselJ[0, x]*BesselJ[1, x], {x, 0, a]+int2[m_,n_,a_]:=(2/Pi)Integrate[Cos[x-(2m+1)Pi/4]*Cos[x-( 2n+1)Pi/4], {x, a,Infinity}]The first integral is a quite normal finite integral. The second (int2) issingularand according to Mathematica 4.1 int2[m_, n_, a_] := -(1/Pi)*Log[a]*Cos[1/2(m - n)Pi]*]Log[a] + (1/Pi)*CosIntegral[2 a]*Sin[1/2(m+n)Pi] + 1/(2*Pi)*Cos[1/2(m+n)Pi]*(Pi-SinIntegral[2*a]) RESULTSm=1;n=0;a=20.;WS[m,n,0]=divergentW[m,n]=1/2NW[m,n]= 0.5Wasy[m,n,a]=.49816m=2;n=0;a=20.;WS[m,n,0]=divergentW[m,n]= 0.427599NW[m,n]=-2.43818Wasy[m,n,a]=-1.48052m=3;n=1;a=20.;WS[ m,n,0]=divergentW[m,n]=0.639806NW[m,n]=-2.31957Wasy[m,n,a]=- 1.26822m=4;n=0;a=20.;WS[m,n,0]=divergentW[m,n]=-.852012NW[m,n ]=1.45786Wasy[m,n,a]=1.06835The cases W[m,m+1],W[m,m+3] well agrre with the numerical counterpart.Other case are doubtfully.I think the main problem is the convergence of this kind of integrals.Any suggestion will be well considerd.RobertRoberto BrambillaCESIVia Rubattino 5420134 Milanotel +39.02.2125.5875fax +39.02.2125.5492rlbrambilla@cesi.it ==== =On Sun, 29 Sep 2002 09:35:41, in the message Re: A Bessel integral,VB>> The expression for W[m_,n_] returned by Mathematica is wrong.VB>>VB>> To prove, just substitute m = n = 0 which is exactly what you had doneVB>>VB>> and observe that the output you had hadVB>>VB>> W[0,0]=-(2 EulerGamma + Log[4] + 4 PolyGamma[0, 1/2])/(2 Pi)VB>>VB>> = 0.84564VB>>VB>> was incorrect. The correct answer is 1/2. ^^^^^^^^^^^^^^^^^^^^^^^^^^TB> W[0,0]diverges. Mathematica gets that wrong.(That my terrible bug shows how it is dangerous to do severalposting to the MathGroup before sending them ;-)Why sure, you are right, the integral Integrate[BesselJ[0, z]^2, {z, 0, Infinity}]diverges because the integrand is bounded everywhereover the integration region and decays at z -> Infinityas Cos[Pi/4 - z]^2/z + o(z), that is as In[1] := Expand[TrigExpand[Cos[Pi/4 - z]^2/z]] // InputForm Out[1] = 1/(2*z) + (Cos[z]*Sin[z])/zwhich means that the integral Integrate[BesselJ[0, z]^2, {z, 0, x}]diverges logarithmically in x.By the way, the main term of Expand[Normal[Series[BesselJ[0, z], {z, Infinity, 1}]]^2]is (2*Cos[Pi/4 - z]^2)/(Pi*z) which conveys the suggestion thatwe should try it, too.This reveals us another integral which Mathematica 4.1 fails to calculate In[1] := Integrate[Cos[Pi/4 - z]^2/z, {z, 1, Infinity}] // N Out[1]= -0.0173083 Out[2]= 4.1 for Microsoft Windows (November 2, 2000)but Mathematica 4.2 handles correctly In[1] := Integrate[Cos[Pi/4 - z]^2/z, {z, 1, Infinity}] Out[1] = Integrate::idiv: Integral of... does not converge on {1, Infinity). Out[2]= 4.2 for Microsoft Windows (February 28, 2002)Even simpler, In[1] := Integrate[Cos[z]^2/z, {z, 1, Infinity}] Out[1] = -EulerGamma/2 - Log[2]/2 + (EulerGamma - CosIntegral[2] + Log[2])/2 Out[2]= 4.1 for Microsoft Windows (November 2, 2000)which is wrong while Mathematica 4.2 works excellent In[1] := Integrate[Cos[z]^2/z, {z, 1, Infinity}] Out[1] = Integrate::idiv: Integral of...does not converge on {1, Infinity). Out[2]= 4.2 for Microsoft Windows (February 28, 2002)Best wishes,Vladimir BondarenkoMathematical DirectorSymbolic Testing GroupWeb : http://www.CAS-testing.org/ http://maple.bug-list.org/VER2/ (under tuning) http://maple.bug-list.org/VER3/ (under tuning) http://maple.bug-list.org/VER1/ (under tuning) http://www.beautyriot.com/ (teamwork) http://www.ohaha.com/ (teamwork) Voice: (380)-652-447325 Mon-Fri 9 a.m. - 6 p.m.Mail : 76 Zalesskaya Str, Simferopol, Crimea, Ukraine ==== =John,You could do something like this.points = With[{del = 2Pi/24}, Table[{Cos[t], Sin[t], t/(2Pi)}, {t, 0, 2Pi - del, del}]];Show[Graphics[ {AbsolutePointSize[7], {Hue[Last[#]], Point[#[[{1, 2}]]]} & /@ points, Line[Drop[#, -1] & /@ points]}], AspectRatio -> Automatic, Background -> GrayLevel[0.4], ImageSize -> 400];When I made the point list I made certain the z values were between 0 and 1.Otherwise you will have to define a color function that will associate aproper color with each value of z.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ Approved: Steven M. Christensen , Moderator ==== =Many thanks to all who replied.The original problem was as follows:In a presentation I wish to use Plot to generate a sequence of frames andthen animate them. The problem is that the audience sees the animationtwice. Once when the frames are being generated and then again after I haveclosed the group and double clicked on the top graphic. However, the firstshowing during generation is enough (but uncontrolled). Is it possible to tidy up the generation of the graphic so that it becomesthe animation?There were two main solutions which I now apply to my real problem and notthe simple, generic, problem in the original post. The real problem was how to build up a probably density function (PDF) inreal time. In the examples below I redraw the PDF every time I add 10points.Initialise<500] ], {500}]; NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs, Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}] ]This solution works but it generates 500 frames and sometimes exceeds thememory. The paradigm here is generate all frames, then animate all frames. Wereally need a loop that does: generate next frame, delete last frame, show next frameIs it possible to do this?Bobby Treat also offered a solution involving SelectionMove.The second solution was from Jerry Blimbaum and uses JAVAInstallJava[];UseFrontEndForRendering = False;createWindow[] := Module[{frame}, frame = JavaNew[com.wolfram.jlink.MathFrame, Probability DensityFunction]; drawArea = JavaNew[com.wolfram.jlink.MathCanvas]; drawArea@setUsesFE[UseFrontEndForRendering]; drawArea@setSize[800, 600];JavaBlock[frame@setLayout[JavaNew[java.awt.BorderLayout] ]; frame@add[drawArea, ReturnAsJavaObject[BorderLayout`CENTER]]; frame@pack[]; frame@setSize[800, 600]; frame@setLocation[100, 100]; JavaShow[frame]];frame]ClearAll[drawString]; drawString[] :=( data=Flatten[Join[data,RandomArray[wb,10]]]; freq=BinCounts[data,{0,50,1}]; BarChart[Transpose[{freq,midpts}],ImageSize ->500, DisplayFunction -> Identity]) LoadJavaClass[java.lang.Thread]; AnimationPlot[n_] := JavaBlock[ Block[{frm}, frm = createWindow[]; Do[(obj = drawString[]; drawArea@setMathCommand[obj]; drawArea@repaintNow[]; Thread@sleep[];) ,{n} ]]]data={}; AnimationPlot[500];This solution works and does not use significant memory. However, we havenot managed to control the speed of this animation. The JAVA code sleep doesnot work nor does the use of a Mathematica Pause which always rounds up toan integer (is this a bug?).Hugh Goyder ==== =>>I need a loop that goes generate next frame, delete old frame, shownew frame so that the number of frames does not become excessive.I'm pinging the group for that. I'm just following along in this, otherthan the trick of taking advantage of the half-period.I'll be very interested in a solution myself, as I frequently run out ofmemory in animations of fairly modest size -- despite having 1024MB ofRAM.Bobby-----Original Message-----need a loop that goes generate next frame, delete old frame, show new frameso that the number of frames does not become excessive.Any ideas?Hugh Goyder-----Original Message----- graphs = Rest@Join[half, Rest@Reverse@half]; NotebookWrite[EvaluationNotebook[], Cell[CellGroupData[graphs,Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}]]Bobby-----Original Message----->showing during generation is enough (but uncontrolled).>>Hugh GoyderThis creates a graphics cell from a graphics expression.GraphicCell[graphics_] := Cell[GraphicsData[PostScript, DisplayString[graphics]],Graphics]cellgroup.Block[{$ DisplayFunction=Identity, graphs}, graphs = Table[GraphicCell[ Plot[Sin[t]*Sin[x], {x, 0, Pi}, PlotRange -> {{0, Pi}, {-1,1}}, ImageSize -> 400]], {t,0,15,.1}]; NotebookWrite[EvaluationNotebook[],Cell[CellGroupData[graphs, Closed]]]; SelectionMove[EvaluationNotebook[], All, GeneratedCell]; FrontEndExecute[{FrontEndToken[EvaluationNotebook[], SelectionAnimate]}] ]------------------------------------------------------------ --Omega ConsultingThe final answer to your Mathematica needsSpend less time searching and more time finding.http://www.wz.com/internet/Mathematica.html ==== = Actually, we don't know whether SetAccuracy succeeds, because we don'tknow how inexact those numbers really are. If they are known to moredigits than shown in the original post, they should be entered with asmuch precision as they deserve. If not, there's no trick or algorithmthat will give the result precision, because the value of f really isin the noise. That is, we have no idea what the value of f should be.Mathematica's failing is in returning a value without pointing out thatit has no precision.Bobby-----Original Message----- f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b ^8+a/(2*b), Infinity]; a=77617.1; b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity ]; f - 15640321149084868351974949239896188679725401538739519428131155 14949389123623452500771916869370459119776018798804630436149786 9199129319625743010292363124675/ 10867106143970760551000357827554793888198143135975649579607989 867743572824016 06539536129829321813712324363677397376040962) Rewriting as fractions a=776171/10; b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2 *b) -(5954133808997234115690303589909929091649391296257/ 41370125000000)3) Using Rationalize Clear[a,b,f]f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121* b^4-2)+5.4*b^8+a/(2*b),0]; a=77617.1; b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/ 41370125000000)I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000--Allan---------------------Allan HayesMathematica Training and ConsultingLeicester UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice: +44 (0)116 271 4198> Well, first of of all, your using SetAccuracy and SetPrecision does> nothing at all here, since they do not change the value of a or b. You> should use a = SetAccuracy[a, Infinity] etc. But even then you won't> get the same answer as when you use exact numbers because of the way> you evaluate f. Here is the order of evaluation that will give you the> same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*> b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.;> b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767> -(-----)> 66192 Andrzej Kozlowski> Toyama International University> JAPAN> Could someone explain what is going on here, please?> > In[1]:=> a = 77617.; b = 33096.;> > In[2]:=> SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];> SetPrecision[a, Infinity]; SetPrecision[b, Infinity];> > In[4]:=> f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 +> a/(2*b)> > In[5]:=> SetAccuracy[f, Infinity]; SetPrecision[f, Infinity];> > In[6]:=> f> > Out[6]=> -1.1805916207174113*^21> > In[7]:=> a = 77617; b = 33096;> > In[8]:=> g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +> (55/10)*b^8 + a/(2*b)> > In[9]:=> g> > Out[9]=> -(54767/66192)> > In[10]:=> N[%]>> Out[10]=> -0.8273960599468214> > PK> > ==== =It seems clear to me that what Allan and what you mean by succeeds here refer to quite different things and your objection is therefore beside the point. There are obviously two ways in which one can interpret the original posting. The first interpretation, which Allan and myself adopted, was that the question concerned purely the computational mechanism of Mathematica. Or, to put it in other words, it was why are the results of these two computations not the same?. In this sense success means no more than making Mathematica return the same answer using the two different routes the original poster used.You on the other hand choose to assume that the posting shows that its author does not understand not just the mechanism of significance arithmetic used by Mathematica but also computations with inexact numbers in general. I do not think this is necessarily the correct assumption. I also don't see that Mathematica is doing anything wrong. After all, one can always check the accuracy of your answer:In[1]:=a = 77617.; b = 33096.;In[2]:=f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b)In[3]:=fOut[3]=-1.1805916207174113*^21In[4]:=Accuracy[ %]Out[4]=-5which tells you that it can't be very reliable. What more do you demand?AndrzejAndrzej KozlowskiYokohama, Japanhttp://www.mimuw.edu.pl/~akoz/http:// platon.c.u-tokyo.ac.jp/andrzej/> Actually, we don't know whether SetAccuracy succeeds, because we > don't> know how inexact those numbers really are. If they are known to more> digits than shown in the original post, they should be entered with as> much precision as they deserve. If not, there's no trick or algorithm> that will give the result precision, because the value of f really is> in the noise. That is, we have no idea what the value of f should > be. Mathematica's failing is in returning a value without pointing out that> it has no precision. Bobby -----Original Message-----> Sent: Monday, September 30, 2002 11:59 AM Andrzej, Bobby, Peter It looks as if using SetAccuracy succeeds here because the inexact> numbers> that occur have finite binary representations. If we change them> slightly to> avoid this then we have to use Rationalize: 1) Using SetAccuracy Clear[a,b,f]> f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b ^8+a/ > (2*b),> Infinity]; a=77617.1;> b=33096.1; a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity ]; f> - 15640321149084868351974949239896188679725401538739519428131155 14949> 3891236234 52500771916869370459119776018798804630436149786919912931962574 301029236 > 3> 1246> 75 / > 10867106143970760551000357827554793888198143135975649579607989 867743572> 8240> 16> 0653953612982932181371232436367739737604096 2) Rewriting as fractions a=776171/10;> b=330961/10; f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2 *b) -(5954133808997234115690303589909929091649391296257/> 41370125000000) 3) Using Rationalize Clear[a,b,f]> f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b ^8+a/ > (2*b),> 0]; a=77617.1;> b=33096.1; a=Rationalize[a,0];b=Rationalize[b,0]; f -(5954133808997234115690303589909929091649391296257/> 41370125000000)> I use Rationalize[. , 0] besause of results like Rationalize[3.1415959] 3.1416 Rationalize[3.1415959,0] 31415959/10000000> --> Allan ---------------------> Allan Hayes> Mathematica Training and Consulting> Leicester UK> www.haystack.demon.co.uk> hay@haystack.demon.co.uk> Voice: +44 (0)116 271 4198> Well, first of of all, your using SetAccuracy and SetPrecision does> nothing at all here, since they do not change the value of a or b. You> should use a = SetAccuracy[a, Infinity] etc. But even then you won't> get the same answer as when you use exact numbers because of the way> you evaluate f. Here is the order of evaluation that will give you the> same answer, and should explain what is going on: f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*> b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity]; a = 77617.;> b = 33096.; a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity]; f 54767> -(-----)> 66192 Andrzej Kozlowski> Toyama International University> JAPAN> Could someone explain what is going on here, please? In[1]:=> a = 77617.; b = 33096.; In[2]:=> SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];> SetPrecision[a, Infinity]; SetPrecision[b, Infinity]; In[4]:=> f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 +> a/(2*b) In[5]:=> SetAccuracy[f, Infinity]; SetPrecision[f, Infinity]; In[6]:=> f Out[6]=> -1.1805916207174113*^21 In[7]:=> a = 77617; b = 33096; In[8]:=> g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +> (55/10)*b^8 + a/(2*b) In[9]:=> g Out[9]=> -(54767/66192) In[10]:=> N[%] Out[10]=> -0.8273960599468214> PK> ==== =Here's a refinement of my previous post. Everything is wrapped up in a function named DotPlot, which takes the following options:ColorFunction (default: Hue)ColorFunctionScaling (default: True)DotSize (default: 0.01)You can also provide other options such as Axes, Frame, Background, etc. Needs[Utilities`FilterOptions`]; DotPlot[data_?MatrixQ, opts___Rule] := Module[{colorfn, scale, dotsize}, colorfn = ColorFunction/.{opts}/.{ColorFunction->Hue}; scale = ColorFunctionScaling/.{opts}/.{ColorFunctionScaling->True}; dotsize = DotSize/.{opts}/.{DotSize->.01}; With[{m = If[scale,{Min[#],Max[#]}&@Transpose[data][[3]], {0,1}]}, Show[(Graphics[ {colorfn[#[[3]]],PointSize[dotsize],Point[{#[[1]],#[[2]]}]}]& )/@ (data /. {x_,y_,z_}-> {x,y,(z-m[[1]])/(m[[2]]-m[[1]])}), FilterOptions[Graphics, opts] ] ] ]Example: vals = Table[{Random[], Random[], .5 Random[]}, {100}]; DotPlot[vals, ColorFunction -> (Hue[#, 1, 1-#] & ), ColorFunctionScaling -> False, DotSize -> 0.02, Frame -> True]---Selwyn Hollis ==== =These expressions are condensation of larger ones(about 700 lines or so each) but they illustrate randomsubstitution failures in 4.2. Question: how can thesubstitution Sqrt[...]->Q always be made to work? The help file under ReplaceAll, ReplaceRepeated, etc, does not address this problem.f=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]/4*F^2);Print[(f/. Sqrt[X+Y+Z]->Q)//InputForm]; B*(A + Q) + (4*C)/(F^2*Sqrt[X + Y + Z]) (* fails *)g=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]*4*F^2);Print[(g/.Sqrt[X+ Y+Z]->Q)//InputForm];B*(A + Q) + C/(4*F^2*Sqrt[X + Y + Z]) (* fails *)h=B*(A+Sqrt[X+Y+Z])+C/(Sqrt[X+Y+Z]+4*F^2); ==== =====> BRIEF> Mathematica seems to support 3 levels of nesting:> section, subsection, and subsubsection.> Q: how can I obtain more levels of nesting?> I typically go 6-7 levels deep.Well, I started by editting the notebook in a text editor(having used Edit Style Sheet to unshare),and I created stylesSub3section ... Sub9section,with Dewey decimal numbering 1.2.3.4.5.6.7.8.9.10I got collapsable group working, by mucking with CellGroupingRules->{SectionGrouping, 100},changing the number.I am not sure what the number is, but I'm guessingit may be a pixel count for the nesting boxesat the left of the screen.I'm a bit worried about whether this is fragile. ==== Was there any way to accomplish this from the GUI?Or was using a text editor mandatory? ==== Related: this exercise makes it obvious that acommon operation is to push down or pull upa whole subtree - e.g. a Subsection becomes aSubsubsection, a Subsubsection becomes aSub3section, etc. The sort of thing that MicrosoftWord does with Outline mode.Q: has anyone got something like Outline modefor Mathematica?I'm tempted to go the other way, and ask if anyonehas a front end that allows Mathematica to be embeddedin Word documents. But that might be a hassle,since Word runs on Windows, and the Mathematicalicence I have access to runs on Suns. ==== => inFile = OpenRead[197-tst.txt]> y = ReadList[inFile, String, 1, RecordLists -> True]> Close[inFile];> This appears to pull in a line. Now I want to take characters > 25 to 110 to get just the stuff I want:> y1=StringTake[y ,{25,110}];> Here's the output. StringTake doesn't seem to work.> -1281.9 -229. 321. 317. 367. -115. 126. > 146. -410. -426.000000EF 75.}, {25, 110}]> It doesn't take loading another package as far> as I can tell from the help. I'm thinking that it doesn't > work because it's trying to work on a list> rather than a string. I've tried Flatten, and other stuff to > try to get to just a string and not a list but> nothing has worked so far. I'm a long way from getting to > those numbers in there but heck, I> can't even get to the string. Can anyone point me in the > right direction?You might try lst = Read[StringToStream[y1], {Word, Table[Number, {16}], Word,Number}]//Flatten;You can then pick the numbers (or words) from the list lst.A quicker alternative might be as follows:-ifile = ReadList[197-tst.txt, {Word, Table[Number, {16}], Word, Number}];Dave. ==== ======================================= Dr. David Annetts EM Modelling Analyst Australia David.Annetts@csiro.au ==== ==================================== ==== =====I was and do have problems reading files Exported files in AdobeIllustrator format (.ai) from Adobe Illustrator 10.0.3.With an upgrade to Adobe Illustrator 10.0.3, I can read EPS filescreated by Mathematica 4.0.1.A message from tech support at Wolfram implies that Adobe Illustratorformat files can be read ONLY if you are using the correct Adobe andWolfram programs. Additionally, Mathematica is going to favor the exportof EPS files (is that clear enough?).My approach to using Mathematica as a source of images for AdobeIllustrator 10.0.3 is:Create the image in MathematicaExport[ImageFileName.eps, theMathematicaImageCreated, EPS]Open the file ImageFileName.eps within Adobe Illustrator 10.0.3Save the file as a .ai fileBe sure to check the ImageSize as it is not often what you toldMathematica. ==== =Have you tried deleting ... Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nbThere are two BrowserIndex files. Only delete the .nb one (or just move itsomewhere else).> What about this problem? I have tried the previous suggestions but none of> them worked. Will Wolfram help us in this problem? ==== =I ran it 10 times on 4.2 with no crashes.> Jens-Peer Kuska tells me that he gets no crash with Mathematica 4.2,however after working> with this program for more than a month, trying every possible permutationand> manipulation, and having it still crash, I am still worried that upgradingto 4.2> won't solve my problem. Can anyone else with 4.2 try running this programfor me a> good number of times, say 3 or 4, and see if they get similar goodresults?> Bernard Gress> Dear Group,> I have a program to take the local polynomial non parametric regression> of two variables. It uses Compile, unfortunately, and regularly, but> inconsistently, causes Mathematica to crash (in Win2K, with I forget> what error, and in Win98/Mathematica4.0 with an invalid memory access from> MathDLL.dll). I am running Mathematica 4.1, and have this problemconsistently> on 4 different machines.> Here is the code, if it doesn't crash the first time, it will the second> or third:> (*> w = Compile[{{xj, _Real, 0}, {XX, _Real, 1}, {YY, _Real, 1}, {h, _Real,> 0},> {nn, _Integer, 0}, {ord, _Integer, 0}},> First[Inverse[Sum[Outer[Times, Table[If[Positive[q], (XX[[i]] - xj)^q,> 1], {q, 0, ord}],> Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0,> ord}]*E^(-0.5*((XX[[i]] - xj)/h)^2)], {i, nn}]] .> Sum[(Table[If[Positive[q], (XX[[i]] - xj)^q, 1.], {q, 0, ord}]*YY[[i]])*> E^(-0.5*((XX[[i]] - xj)/h)^2), {i, nn}]]];> *)> (*> !(tt = MemoryInUse[];> ListPlot[Table[{((i + 1))^2, (Timing[> nn = ((i + 1))^2; [Epsilon] = Table[Random[]*3, {i,> nn}];> testX = Table[i* .3 - Random[]*2, {i, nn}];> testY = Table[Sin[i/3] - 2, {i, nn}] + [Epsilon];> Map[w[#, testX, testY, .1 + Random[], nn, 0] &,> testX];])[([1])]/Second}, {i, 15}], PlotJoined ->> True,> PlotLabel -> ];> MemoryInUse[] - tt)> *) ==== =In his not-so-subtle way, Jens-Peer is trying to tell you that since yousee z in the error message, that's what NIntegrate saw too. z is asymbol, and NIntegrate needs numbers. Now I'll have to search onlinefor your original problem, since I deleted my copy long ago... (Excuseme a few minutes...) Hmm... OK, I'm back.Well... there's still a missing (or extra) parenthesis in the definitionof f and a missing bracket in the definition of F, but I also can't seethat you've given z a numerical value. The error shouldn't occur untilyou use F though, since you used SetDelayed. So, the error message goeswith a line you didn't include in your post. However, in your latestpost, the linesNumericQ[z]Falsetell me z is NOT a real number. For instance,NumericQ[1.2]TrueSo, proceeding with the theory that z needs to be numeric, let's tryF[1.2]NIntegrate::itraw:Raw object 1.2` cannot be used as an iterator.NIntegrate[f[y, 1.2], {1.2, 0, Infinity}]NIntegrate::itraw:Raw object !(1.2`) cannot be used as aniterator.As you see, in the definition of F, you've used z as an iterator. Nomatter what the argument z to F is -- number, symbol, whatever -- youcan't use it as an iterator, because it already has an identity, anditerators are stand-ins -- temporary variables that don't exist outside(in this case) NIntegrate. So, as Jens-Peer pointed out, y should havebeen your iterator. (Probably. We don't actually know what you weretrying to do. We only know for sure that z couldn't be the iterator.)So, if I've made the right guesses, the definition for F should beF[z_] := NIntegrate[f[y, z], {y, 0, Infinity}]But... F[z] will still give you an error if z doesn't have a numericalvalue, so it's even better to define F this way:ClearAll[F]F[z_?NumericQ] := NIntegrate[f[y, z], {y, 0, Infinity}]That way, F[z] is left unevaluated if z isn't numeric.I can't go any further, since I don't know the value of f -- because Idon't know where to add or subtract that pesky parenthesis. (I askedstill isn't.)Bobby Treat-----Original Message-----> F[z_?NumericQ]: = NIntegrate[f[y,z], {y, 0, Infinity}]I'm a newbie, bat I mean:*************************In[1]= NumericQ[z]Out[1]=False*************************BTW, z is a real number.--Rob_jack ==== =I'm learning the fine art of patterns and Hold one tricky example at atime.Bobby-----Original Message-----> I want to make a list of all symbols in the Global context, as in> Names[Global`*]> and compute a ByteCount for each symbol's OwnValues -- without> evaluating the symbols.> It seems possible in principle, but I haven't found a way.> Bobby Treat ==== =Here's the fairly useful bit of code I came up with, using Jens-Peer'sbrilliant solution:names = Names[Global`*];counts = ToExpression[#, StandardForm, Hold] & /@ names /. Hold[a_] :> ByteCount[OwnValues[a]];Select[Transpose[{names, counts}], Last@# > 16 &] // TableFormIt tells me how some of my memory is being spent.Bobby Treat-----Original Message-----> I want to make a list of all symbols in the Global context, as in> Names[Global`*]> and compute a ByteCount for each symbol's OwnValues -- without> evaluating the symbols.> It seems possible in principle, but I haven't found a way.> Bobby Treat ==== =>Try deleting ...>Mathematica4.2DocumentationEnglishMainBookBrowserIndex.nb ==== =Jack,Often, what I do when developing a slightly complicated module is to firsttest it after I add each statement L1, L2, etc. But then often I want tomake changes after I have all the statements in. Then to debug I just addtemporary Print statements. For example...myFunction[f_] := Module[ {L1,L2,L3},L1 = ... ;L2 = ... ;Print[{L1, L2}];l3 = ... ;]Sometimes I use multiple Print statements. The only problem with thisapproach is that sometimes the difficulty might be in a subexpression of alonger expression.This forces me to temporarily break out the longer expression into multiplestatements, or perhaps duplicate the subexpression in the Print statement.But I find that the easiest method to track down errors.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/l3 = ... ; final step ]To see what went wrong, I use (* *) selectively as follows:Stage 1myFunction[f_] := Module[ {L1,L2,L3},L1 = ... (*;L2 = ... ;L3 = ... ; final step *) ]Thus I see if L1 worked as expected. The next step is to put (* after L2and see if this works. I continue this til the bitter end and I usuallyfind my errors.My question; The process of moving (* *) step by step through theprogram is quite tedious when the code has lots more lines. What I wouldlike is a meta-program which (like FoldList) does this job for me. Theoutput of this meta-program is the list of outputs of each line in themodule, probably best printed as a column.This sounds like Trace but my problem with Trace is it is terriblydifficult to read. For the not-so-subtle programming I do, the only thingI need is what expression is returned line by line.Any advice? All remarks are appreciated!JackReply-To: kuska@informatik.uni-leipzig.de ==== =does help you ? Jens> I often run into this difficulty: when designing a program, say as a> module, and testing it for various inputs, I get wrong answers. What to> do? I use a method that works for me but may not be the best available.> I want to show my method and then ask a question about how it can be> imporved. (Oh yes, I abandoned Trace a long time ago!)> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... ;> L2 = ... ;> l3 = ... ;> final step> ]> To see what went wrong, I use (* *) selectively as follows:> Stage 1> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... (*;> L2 = ... ;> L3 = ... ;> final step *)> ]> Thus I see if L1 worked as expected. The next step is to put (* after L2> and see if this works. I continue this til the bitter end and I usually> find my errors.> My question; The process of moving (* *) step by step through the> program is quite tedious when the code has lots more lines. What I would> like is a meta-program which (like FoldList) does this job for me. The> output of this meta-program is the list of outputs of each line in the> module, probably best printed as a column.> This sounds like Trace but my problem with Trace is it is terribly> difficult to read. For the not-so-subtle programming I do, the only thing> I need is what expression is returned line by line.> Any advice? All remarks are appreciated!> Jack ==== =I've enhanced the code for PartialEvaluation (see my post, which Iincorrectly attaced to someone else's reply). It is somewhat moreßexible now and does more error checking. It finds the rule inDownValues that matches f[args] (allowing for more than one rule inDownValues); it allows the user to specify the position of the mainCompoundExpression; and it allows the user to specify an expressionthat gets appended to the truncated CompoundExpression (and henceevaluated and returned). The package is just a bit too large to posthere. It can be downloaded from my web site athttp://www.markfisher.net/~mefisher/mma/ mathematica.htmlNevertheless, I can give an outline of the code here (absent the errorchecking stuff).PartialEvaluation[f[args], n, expr]:(* get the DownValues and turn them off *)dv = DownValues[f];DownValues[f] = {};(* find the rule that matches *)matches = Position[MatchQ[f[args], #]& /@ dv[[All, 1]], True];match = dv[[ matches[[1, 1]] ]];(* find the main CompoundExpression *)ppos = Position[match, HoldPattern[CompoundExpression[__]]];pos = First[Sort[ppos]];(* extract, truncate, append to, and reinsert it *)held = Extract[match, pos, Hold];held = ReplacePart[held, Sequence, {1, 0}];held = Take[held, n];held = Join[held, Hold[expr]];held = ReplacePart[Hold[Evaluate[held]], CompoundExpression, {1, 0}];match = ReplacePart[match, held, pos, 1];(* apply the modified rule and restore DownValues *)result = f[args] /. match;DownValues[f] = dv;result--Mark> I often run into this difficulty: when designing a program, say as a> module, and testing it for various inputs, I get wrong answers. What to> do? I use a method that works for me but may not be the best available.> I want to show my method and then ask a question about how it can be> imporved. (Oh yes, I abandoned Trace a long time ago!)> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... ;> L2 = ... ;> l3 = ... ;> final step> ]> To see what went wrong, I use (* *) selectively as follows:> Stage 1> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... (*;> L2 = ... ;> L3 = ... ;> final step *)> ]> Thus I see if L1 worked as expected. The next step is to put (* after L2> and see if this works. I continue this til the bitter end and I usually> find my errors.> My question; The process of moving (* *) step by step through the> program is quite tedious when the code has lots more lines. What I would> like is a meta-program which (like FoldList) does this job for me. The> output of this meta-program is the list of outputs of each line in the> module, probably best printed as a column.> This sounds like Trace but my problem with Trace is it is terribly> difficult to read. For the not-so-subtle programming I do, the only thing> I need is what expression is returned line by line.> Any advice? All remarks are appreciated!> Jack ==== =The following code is my attempt to provide the functionality yourequested. It does some rudimentary error checking, but I haven'ttried very hard to fool it. The code manipulates the DownValues,locating the highest CompoundExpression (see the lines in whichpos is defined), keeping only those expressions specified.DownValues are restored after the expression is evaluated. The trickypart is keeping the CompoundExpression from evaluating while it isbeing manipulated. (See the lines in which held and new aredefined.) I'm not sure I'm doing this part the most elegant way, butit seems to work.(* code starts here *)PartialEvaluation::usage = PartialEvaluation[f[args], n] returnsf[args] where only the first n expressions are evaluated in themainCompoundExpression in DownValues[f]. For example:ntClear[f]ntf[x_] := Module[{a,b}, a=3; b=4; a b x]ntPartialEvaluation[f, 2]n returns 4.PartialEvaluation::dvprob = DownValues[``] is either empty or hasmorethan one element.PartialEvaluation::toobig = There are only `1` expressions inthe CompoundExpression in `2`.PartialEvaluation::noce = There are no CompoundExpressions inDownValues[``].SetAttributes[PartialEvaluation, HoldFirst]PartialEvaluation[f_[args__], n_Integer] := Module[{dv, pos, held, new, eval}, Catch[ dv = DownValues[f]; If[Length[dv] != 1, Message[PartialEvaluation::dvprob, f]; Throw[HoldForm[f[args]]]]; pos = Sort[Position[dv, CompoundExpression]]; If[pos == {}, Message[PartialEvaluation::noce, f]; Throw[HoldForm[f[args]]]]; pos = Drop[First @ pos, -1]; held = Extract[dv, pos, Hold] /. CompoundExpression -> Sequence; If[Abs[n] > Length[held], Message[PartialEvaluation::toobig, Length[held], HoldForm[f[args]]]; Throw[HoldForm[f[args]]]]; new = ReplacePart[dv, Take[held, n] /. Hold[x__] :> Hold[CompoundExpression[x]], pos, 1]; DownValues[f] = new; eval = f[args]; DownValues[f] = dv; eval ]](* code ends here *)--Mark.P.S. The version of this message I posted directly from my newsreaderdidn't show up, so I'm reposting (a slightly improved version) fromGoogle.> Jack,> Often, what I do when developing a slightly complicated module is to first> test it after I add each statement L1, L2, etc. But then often I want to> make changes after I have all the statements in. Then to debug I just add> temporary Print statements. For example...> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... ;> L2 = ... ;> Print[{L1, L2}];> l3 = ... ;> ]> Sometimes I use multiple Print statements. The only problem with this> approach is that sometimes the difficulty might be in a subexpression of a> longer expression.> This forces me to temporarily break out the longer expression into multiple> statements, or perhaps duplicate the subexpression in the Print statement.> But I find that the easiest method to track down errors.> David Park> djmp@earthlink.net> http://home.earthlink.net/~djmp/> I often run into this difficulty: when designing a program, say as a> module, and testing it for various inputs, I get wrong answers. What to> do? I use a method that works for me but may not be the best available.> I want to show my method and then ask a question about how it can be> imporved. (Oh yes, I abandoned Trace a long time ago!)> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... ;> L2 = ... ;> l3 = ... ;> final step> ]> To see what went wrong, I use (* *) selectively as follows:> Stage 1> myFunction[f_] := Module[ {L1,L2,L3},> L1 = ... (*;> L2 = ... ;> L3 = ... ;> final step *)> ]> Thus I see if L1 worked as expected. The next step is to put (* after L2> and see if this works. I continue this til the bitter end and I usually> find my errors.> My question; The process of moving (* *) step by step through the> program is quite tedious when the code has lots more lines. What I would> like is a meta-program which (like FoldList) does this job for me. The> output of this meta-program is the list of outputs of each line in the> module, probably best printed as a column.> This sounds like Trace but my problem with Trace is it is terribly> difficult to read. For the not-so-subtle programming I do, the only thing> I need is what expression is returned line by line.> Any advice? All remarks are appreciated!> Jack ==== =Mathematica often produces complex resluts. But the problem is not complex:TrySolve[FR == Pi r1^2 - Pi r2^2, r1]It is simple to eliminate it in this case. Just square it.Does someone give me a hint, how to write ra rule for simplify, lik Ted Ersek did inhttp://www.verbeia.com/mathematica/tips/Links/Tricks_lnk_41 .htmlI thin, one has to to replace the patterni Sqrt[-a_]bySqrt[(i Sqrt[-a_])^2]and then one has to simplify it?Peter Klamser ==== =There has been an interesting discussion about using InterpolatingFunctionfor an empirical CDF.If one is willing to sacrifice some theoretical soundness, an empirical CDFmay be computed in a simplified form:simpleEmpiricalCDF[distr_/;VectorQ[distr,NumberQ]] :=With[{nonu=Sort[distr], u=Union[distr]},Transpose[{u,FoldList[Plus,0,(Count[nonu,#]&/ @u)/Length[nonu]]//Rest}]]This code does not return a function, and the result needs someinterpretation. Nevertheless, it may be of some use.data = {0.59, 0.72, 0.47, 0.43, 0.31, 0.56, 0.22, 0.9, 0.96, 0.78, 0.66,0.18, 0.73, 0.43, 0.58, 0.11}(the tie [0.43] will be accounted for in a way that is consistent with sometextbooks)simpleEmpiricalCDF[data]//N returns{{0.11,0.0625},{0.18,0.125},{0.22,0.1875},{0.31,0.25}, {0.43,0.375},{0.47,0.4375},{0.56,0.5},{0.58,0.5625},{ 0.59,0.625},{0.66,0.6875},{0.72,0.75},{0.73,0..8125},{ 0.78,0.875},{0.9,0.9375},{0.96,1.}}A plot may be given with:simpleEmpiricalCDFPlot[distr_/;VectorQ[distr,NumberQ]] :=Module[{res,x,p},res=simpleEmpiricalCDF[distr];x=({#,#}& /@ Transpose[res][[1]])//Flatten;p=({#,#}& /@ Transpose[res][[2]])//Flatten;p= Join[{0},Drop[p,-2],{1}];ListPlot[Transpose[{x,p}],c]]Again, this plot does not reßect theoretical considerations at the lowerand upper end.With regardHermann Meier ==== =Caution: where right- and left-continuity are concerned, Daniel'srelying on undocumented behavior that may change in the next version.Bobby-----Original Message-----that evaluates the empirical CDF given the observations in the list.The function is defined on the entire real line.MakeEmpiricalCDF[list_?(VectorQ[#, NumericQ]&)] := Module[{n, s, a, r, idata}, n = Length[list]; s = Sort[list]; a = Append[s, s[[-1]] + 1]; (* phantom obs. *) r = Range[1/n, 1 + 1/n, 1/n]; (* phantom value 1 + 1/n *) idata = Last /@ Split[Transpose[{-a, r}], #1[[1]] == #2[[1]]&]; (* -a is the first sign change *) Block[{x}, Function @@ {x, Which @@ { x < s[[ 1]], 0., x > s[[-1]], 1., True, Interpolation[idata, InterpolationOrder -> 0][-x] (* -x is the second sign change *) }}] ]The construction Last /@ Split[ ... ] accounts for duplicate values.Here are two examples. Needs[Statistics`ContinuousDistributions`]list1 = RandomArray[NormalDistribution[0, 1], 100];f1 = MakeEmpiricalCDF[list1];Plot[f1[x], {x, -4, 4}]list2 = Table[Random[Integer, {1, 10}], {10}];f2 = MakeEmpiricalCDF[list2];Plot[f2[x], {x, 0, 11}]--Mark> I'm trying to write a fast empirical cummulative distribution function> (CDF). Empirical CDFs are step functions that can be expressed in> terms of a Which statement. For example, given the list of> observations {1, 2, 3},> f = Which[# < 1, 0, # < 2, 1/3, # < 3, 2/3, True, 1]&> is the empirical CDF. Note that f /@ {1, 2, 3} returns {1/3, 2/3, 1}> and f is continuous from the right.> When the number of observations is large, the Which statement> evaluates fairly slowly (even if it has been Compiled). Since> InterpolationFunction evaluates so much faster in general, I've tried> to use Interpolation with InterpolationOrder -> 0. The problem is that> the resulting InterpolatingFunction doesn't behave the way (I think)> it ought to. For example, let> g = Interpolation[{{1, 1/3}, {2, 2/3}, {3, 1}}, InterpolationOrder - 0]> Then, g /@ {1, 2, 3} returns {2/3, 2/3, 1} instead of {1/3, 2/3, 1}.> In addition, g is continuous from the left rather than from the right.> Obviously I am not aware of the considerations that went into> determining the behavior of InterpolationFunction when> InterpolationOrder -> 0.> So I have two questions: > (1) Does anyone have any opinions about how InterpolatingFunction> ought to behave with InterpolationOrder -> 0?> (2) Does anyone have a faster way to evaluate an empirical CDF than a> compiled Which function?> By the way, here's my current version:> CompileEmpiricalCDF[list_?(VectorQ[#, NumericQ] &)] :=> Block[{x}, Compile[{{x, _Real}}, Evaluate[> Which @@ Flatten[> Append[> Transpose[{> Thread[x < Sort[list]],> Range[0, 1 - 1/#, 1/#] & @ Length[list]> }],> {True, 1}]]> ]]]> --Mark ==== =Hey,How can I duplicate those nifty ÔMore' hyperlinks in my usagestatements? That is the hyperlinks that appears at the end of text thatis generated after invoking a Ô?' to get more information about a function.Lawrence ==== =>I've got to extract some numbers from a file that are in lines of>text. Since the line contents are not numbers, I presume I must pull>the line out as a string. Here I start by pulling out just one line:>inFile = OpenRead[197-tst.txt] >y = ReadList[inFile, String, 1, RecordLists -> True] >Close[inFile];>This appears to pull in a line. Now I want to take characters 25 to>110 to get just the stuff I want: y1=StringTake[y ,{25,110}];>Here's the output. StringTake doesn't seem to work.ReadList returns a List not a String. So, y is a List and StringTake fails since it expects a String.Also, you do not need the options RecordLists->True when reading Strings. Nor do you need the OpenRead/Close statements with ReadListTryy = First[readList[197-tst.txt,String,1];y1 = StringTake[y, {25,110}]; ==== =>Does anybody know how to calculate in Mathematica: >a)empirical CDF,>b)empirical PDF, >c)normal QQ-plot; >d)QQ-plot two different random samples?!Yes, but there are a number of issues particularly with an empirical PDF. A very nice package that does all of the above and more is mathStatica. See http://www.mathstatica.com for details.Obviously, it is less expensive to write your own functions.Just recently in message Mark Fisher posted code that addresses the empirical CDF. However, in this code you may want to replace 1/n with 1/(n+1) or (j-0.5)/n depending on your application. Note, these will have no significant effect for large data sets. ==== => I am trying to implement a very simple sorted tree to quickly store some> real numbers I need. I have written an add, delete, minimum, and pop> (delete the lowest value) function and they seem to work ok but are very> slow. Let's just look @ my implementation of the add part:> nums=Null;(*my initial blank Tree)> In[326]:=> Clear[add]> In[327]:=> add[Null,x_Real]:=node[x,Null,Null]> add[Null,node[x_Real,lower_,higher_]]=node[x,lower,higher]> In[328]:=> add[node[x_Real,lower_,higher_],y_Real]:=> If[x>y,node[x,add[lower,y],higher],node[x,lower,add[higher,y] ]]> In[288]:=> add[node[x_Real,lowerx_,higherx_],node[y_Real,lowery_,highery _]]:=If[x>y,> node[x,add[lowerx,node[y,lowery,highery]],higherx],> node[x,lowerx,add[higherx,node[y,lowery,highery]]]> ]> Now this is my attempt to test how fast my add works:> SeedRandom[5];> Do[nums=add[nums,Random[]],{5000}];//Timing> Out[333]=> {13.279 Second,Null}> running on an 1.4GHz Athlon with 1GB of ram).> Questions:> 1. Is this as fast as I can get my code to run?> 2. Am I doing something obviously stupid?> 3. would Compiling things help?> HusainI'll respond to your third question first. No, use of Compile will nothelp. You do not have a tensor structure and moreover it will copy itsarguments. Hence invoking it within a loop would be quite slow for aproblem where the argument grows in size.One thing you did not check is the actual run-time complexity of yourcode. On my 15.GHz machine I get:In[6]:= SeedRandom[5];In[7]:= ee = Table[Random[], {10000}];In[8]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,1000}];]Out[8]= {0.34 Second, Null}In[9]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,2000}];]Out[9]= {1.28 Second, Null}In[10]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,4000}];]Out[10]= {4.94 Second, Null}In[11]:= nums = Null; Timing[Do[nums = add[nums,ee[[j]]],{j,8000}];]Out[11]= {25.08 Second, Null}We see this is clearly of no better than quadratic complexity, whereas Iwould guess you were expecting O(n*Log[n]). So this indicates a problem.Offhand I do not know what aspect of your code is responsible, but I'llgive some different code that has the desired complexity.Note that some of this, and code very similar to that below, isdiscussed at:http://library.wolfram.com/conferences/devconf99/lichtblau /in the section entitled Trees.There is a corresponding Mathematica notebook available at:http://library.wolfram.com/conferences/devconf99/near the bottom of the web page.The code I used to implement a tree structure similar to yours is below.One difference is that, as I place node values in the center, when theyare ßattened the tree is automatically sorted. You might (or might not)regard this as an added benefit.leftsubtree[node[left_, _, _]] := leftrightsubtree[node[_, _, right_]] := rightnodevalue[node[_, val_, _]] := valemptyTree = node[];Clear[treeInsert]treeInsert[emptyTree, elem_] := node[emptyTree, elem, emptyTree]treeInsert[tree_, elem_] /; OrderedQ[{nodevalue[tree], elem}] := node[leftsubtree[tree], nodevalue[tree], treeInsert[rightsubtree[tree], elem]]treeInsert[tree_, elem_] := node[treeInsert[leftsubtree[tree],elem], nodevalue[tree], rightsubtree[tree]]Now for some tests.In[40]:= tt1k = First[Timing[ff1k = node[]; Do[ff1k = treeInsert[ff1k, ee[[j]]], {j,1000}];]] Out[40]= 0.15 SecondWe will check that the ßattened version is actually sorted.In[41]:= gg1k = Apply[List,Flatten[ff1k]];In[42]:= gg1k ==== Sort[Take[ee,1000]]Out[42]= TrueAlso we will observe that the maximum depth is reasonable.In[43]:= Depth[ff1k]Out[43]= 23In the perfectly balanced case it would be 10 so this is not too bad.For larger examples I'll just show timings.In[44]:= tt2k = First[Timing[ff2k = node[]; Do[ff2k = treeInsert[ff2k, ee[[j]]], {j,2000}];]]Out[44]= 0.32 SecondIn[45]:= tt4k = First[Timing[ff4k = node[]; Do[ff4k = treeInsert[ff4k, ee[[j]]], {j,4000}];]]Out[45]= 0.73 SecondIn[47]:= tt8k = First[Timing[ff8k = node[]; Do[ff8k = treeInsert[ff8k, ee[[j]]], {j,8000}];]]Out[47]= 1.58 SecondIn[53]:= SeedRandom[5]; ee = Table[Random[], {32000}];In[54]:= tt32k = First[Timing[ff32k = node[]; Do[ff32k = treeInsert[ff32k, ee[[j]]], {j,32000}];]]Out[54]= 7.58 SecondThis is not of blinding speed but it has the advantage of exhibiting theappropriate run-time complexity. One can, with careful coding, cut downon tree size but if you check with LeafCount you will find that theversion above is already not too wasteful (3x larger than #valuesstored). Moreover the code needed would run a bit slower as it wouldhave more cases to check.As for removing nodes, I think you will need to use some form of heldattribute so as to avoid copying the entire tree when you alterelements.Daniel LichtblauWolfram Research ==== =>>So far, so good. It seems that you want these 11 numbers, OK? Theproblemnow, I think, is that this is just a string and I can think of no easywayto convert it precisely into a list of 11 real numbers.You could try StringToStream followed by a Read from that stream.Bobby Treat-----Original Message-----None];This allowed me to examine your records and I found out that in this wayeach record comes out as a list of length 1: In[2]:=Head[a[[1]]]Out[2]=ListIn[3]:=Length[a[[1]]]Out[3]= 1That is,In[3]:=a[[1]]Out[3]=317. 367. -115. 126. 146. -410. -426.000000EF 75.}In[4]:=StringLength[a[[1,1]]]Out[4]=140and the characters you want areIn[5]:=StringTake[a[[1,1]], {25, 110}]Out[5]=5935.80 5946.66 27.06 -1281.9 -229. 321. 317. 367. -115.126. 146.So far, so good. It seems that you want these 11 numbers, OK? Theproblemnow, I think, is that this is just a string and I can think of no easywayto convert it precisely into a list of 11 real numbers. Then, I suggestyouread the file in a different way, without the WordSeparators option:In[6]:=b=ReadList[197-tst.txt,Word,RecordLists -> True];In[7]:=b[[1]]Out[7]=.,-115.,126.,146.,-410.,- 426.000000EF,75.}In[8]:=Head[b[[1]]]Out[8]=ListIn[9]:=Length[ b[[1]]]Out[9]=19so that each record is now a list of 19 strings. What you want isstrings 6to 16, but converted to reals (unless I'm being presumptuous). This willachieve that:In[10]:=ToExpression[Take[b[[1]],{6,16}]]Out[10]={ 5935.8,5946.66,27.06,-1281.9,-229.,321.,317.,367.,-115.,126., 146.} Now you have a nice list of real numbers to work with. You can do thisforthe whole file like this:In[11]:=ToExpression[Take[#,{6,16}]&/@b]; I hope this will solve your problem.Tomas GarzaMexico City> ----- Original Message -----> Sent: Friday, September 13, 2002 12:14 AMfrom a file...> I've got to extract some numbers from a file that are in lines oftext.> Since the line contents are not numbers, I presume I must pull thelineout> as a string. Here I start by pulling out just one line:> > inFile = OpenRead[197-tst.txt]> y = ReadList[inFile, String, 1, RecordLists -> True]> Close[inFile];> > This appears to pull in a line. Now I want to take characters 25 to110to> get just the stuff I want:> y1=StringTake[y ,{25,110}];> > Here's the output. StringTake doesn't seem to work.>-229.> 321. 317. 367. -115. 126. 146. -410. -426.000000EF 75.},> {25, 110}]> > It doesn't take loading another package as far> as I can tell from the help. I'm thinking that it doesn't workbecause> it's trying to work on a list> rather than a string. I've tried Flatten, and other stuff to try togetto> just a string and not a list but> nothing has worked so far. I'm a long way from getting to thosenumbers> in there but heck, I> can't even get to the string. Can anyone point me in the rightdirection?> >------------------------------------------------------------ -------- ==== =Evaluate ?Floor and then, with your cursor in the output cell from that,push Ctrl-Shift-E, and you should see something like:Information[Floor, LongForm -> False]Floor[x] gives the greatest integer less than or equal tox.*Button[More[Ellipsis], ButtonData :> Floor, Active -> True, ButtonStyle -> RefGuideLink]OK. Change ButtonData :> Floor to ButtonData :> Ceiling, and pushCtrl-Shift-E again. Push the More... button, and you should go toCeiling in the Help Browser, not Floor.Another method is to click Input>Create Button>RefLink and type inCeiling. You should get a button that takes you to Help for Ceiling.Push Ctrl-Shift-E in both cells and compare, and you'll see some cluesto your options. Clues are all you get in Mathematica, so get used toit!Bobby Treat-----Original Message----- ==== =Since r1 and r2 only appear squared, you can do it this way:Simplify[Solve[FR == Pi*r1Sq - Pi*r2Sq, r1Sq]]{{r1Sq -> FR/Pi + r2Sq}}orSimplify[Solve[FR == Pi*r1Sq - Pi*r2^2, r1Sq]]{{r1Sq -> FR/Pi + r2^2}}Then r1 is the square root of r1Sq. In the complex plane, real numbershave two square roots, but we usually ignore that.Bobby Treat-----Original Message-----http://www.verbeia.com/mathematica/tips/Links/ Tricks_lnk_41.htmlI thin, one has to to replace the patterni Sqrt[-a_]bySqrt[(i Sqrt[-a_])^2]and then one has to simplify it?Peter Klamser ==== => My question; The process of moving (* *) step by step through the> program is quite tedious when the code has lots more lines. What I would> like is a meta-program which (like FoldList) does this job for me. The> output of this meta-program is the list of outputs of each line in the> module, probably best printed as a column.Beside the Print statements, sometimes I do the following. Put the functionto be tested in its own context and then empty the list of local symbols,e.g.,myfunction[stuff__] := Module [{}, expr1; expr2; ... ]so that all temporary variables defined within the function are now globalwithin the new context. Then I can examine the values of all these variablesafter execution of the function and can often find the error. If the erroris caused by a complex expression of nested functions, then I unwind thecomplex expression, adding more temporary variables, until I see theproblem. Then I think twice before recomplexifying.The two advandages of a special context are (1) I don't get the previouslylocal symbols mixed up with other symbols and (2) I can examine all of themand only them with TableForm[{#,ToExpression[#]}&/@Names[mynewcontext`*]]Once I do this, I often leave the new context in place. Mathematica seems tobe able to handle a large number of contexts efficiently.Tom Burton ==== =I have quite an easy and annoying problem with mathematica:I need to define a function f(x,y) which takes some values forx=0,2pi,4pi (indepently of y) and has a different expression for allthe other values of y. This is easily done for one-dimensionalfunctions but I am in serious troubles for my two-dimensional problem:any suggestion?FabioReply-To: kuska@informatik.uni-leipzig.de ==== =Clear[f]f[0, _] := qf[Pi, _] := pf[2Pi, _] := rf[x_, y_] := x^2*y^2??? Jens> I have quite an easy and annoying problem with mathematica:> I need to define a function f(x,y) which takes some values for> x=0,2pi,4pi (indepently of y) and has a different expression for all> the other values of y. This is easily done for one-dimensional> functions but I am in serious troubles for my two-dimensional problem:> any suggestion?> Fabio ==== => I have quite an easy and annoying problem with mathematica:> I need to define a function f(x,y) which takes some values for> x=0,2pi,4pi (indepently of y) and has a different expression for all> the other values of y. This is easily done for one-dimensional> functions but I am in serious troubles for my two-dimensional problem:> any suggestion?> FabioThere were some typos in my last message. It should have read:Let the known values of the function at x={0,2Pi,4Pi} be {f0,f2,f4}.Your conditions can be met byf(x,y)=x(x-2Pi)(x-4Pi)g(y)+h(x),where {h(0),h(2Pi),h(4Pi)}={f0,f2,f4}. An h(x) can be found by quadratic interpolation: h[x]= a + bx + cx^2;Solve[{a==f0,a+2Pi b +(2Pi)^2 c==f2, a+4Pi b+(4Pi)^2 c==f4},{a,b,c}]{{b -> -(3*f0 - 4*f2 + f4)/(4*Pi), c -> -(-f0 + 2*f2 - f4)/(8*Pi^2), a -> f0}} ==== => I have quite an easy and annoying problem with mathematica:> I need to define a function f(x,y) which takes some values for> x=0,2pi,4pi (indepently of y) and has a different expression for all> the other values of y. This is easily done for one-dimensional> functions but I am in serious troubles for my two-dimensional problem:> any suggestion?> FabioLet the known values of the function at x={0,2Pi,4Pi} be {f0,f2,f4}.Your conditions can be met byf(x,y)=x(x-2Pi)(x-4Pi)g(y)+h(x),where {h(0),h(2Pi),h(4Pi)}={f0,f2,f4}. An h(x) can be found by quadratic interpolation: h[x]= a + bx + cx^2;Solve[{a==f0,a+2Pi b +(2Pi)^2+(2Pi)^2 c==f2, a+4Pi b+(4Pi)^2 c==f4]{{b -> -(3*f0 - 4*f2 + f4)/(4*Pi), c -> -(-f0 + 2*f2 - f4)/(8*Pi^2), a -> f0}}Maurice ==== => I have quite an easy and annoying problem with mathematica:> I need to define a function f(x,y) which takes some values for> x=0,2pi,4pi (indepently of y) and has a different expression for all> the other values of y. This is easily done for one-dimensional> functions but I am in serious troubles for my two-dimensional problem:> any suggestion?> FabioSomething like this?In[1]:= f[x_,y_] := If[Mod[x,2*Pi] ==== 0, Exp[x], Sin[y]+x]In[2]:= f[4*Pi, y] 4 PiOut[2]= EIn[3]:= f[1, y]Out[3]= 1 + Sin[y]--Bhuvanesh,Wolfram Research. ==== => I have quite an easy and annoying problem with mathematica:> I need to define a function f(x,y) which takes some values for> x=0,2pi,4pi (indepently of y) and has a different expression for all> the other values of y. This is easily done for one-dimensional> functions but I am in serious troubles for my two-dimensional problem:> any suggestion?> Fabiof[0, y_] := 5f[2 Pi, y_] := 7f[4 Pi, y_] := -3f[x_ /; x < 0, y_] := x yf[x_ /; 0 < x < 2 Pi, y_] := x + yf[x_ /; 2Pi < x < 4 Pi, y_] := x - yf[x_ /; 4Pi < x, y_] := 2x y ==== =>-----Original Message----->Sent: Monday, September 16, 2002 6:34 AM >I have quite an easy and annoying problem with mathematica:>I need to define a function f(x,y) which takes some values for>x=0,2pi,4pi (indepently of y) and has a different expression for all>the other values of y. This is easily done for one-dimensional>functions but I am in serious troubles for my two-dimensional problem:>any suggestion?>FabioIt's difficult to guess what you wanted to attain and what your problemswere. Perhaps this example might help you:In[11]:= f[x_, _] /; Mod[x, 2Pi] == 0 := x/(2Pi)In[12]:= f[x_, y_] := x + yIn[13]:= epsilon = $MachineEpsilonOut[13]= 2.220446049250313*^-16In[14]:=f[6Pi(1 + epsilon Sin[#]), #] & /@ Range[0, 4Pi, Pi 10^-1]Out[14]={3, 3., 19.4779, 19.792, 20.1062, 20.4204, 20.7345, 21.0487, 21.3628, 3., 3,22.3053, 22.6195, 22.9336, 23.2478, 23.5619, 23.8761, 24.1903, 24.5044, 24.8186, 3, 3., 25.7611, 26.0752, 26.3894, 26.7035, 27.0177, 27.3319,27.646, 3., 3, 28.5885, 28.9027, 29.2168, 29.531, 29.8451, 30.1593, 30.4734,30.7876, 31.1018, 3}Look close at the values returned (compare with epsilon Sin[Range[0, 4Pi, Pi 10^-1]]), also to recognize the dangers of such a definition.--Hartmut ==== =I am new with Mathematica, I have one question,I know that the sollution might be very easy, but I wasn't able tofind it by now.I would like to draw an ellipse, the formula let's say is as follows:0.09 x^2 +0.04 x y + 0.06 y^2 = 4Maciej ==== =Although it is not outstanding, I prefer to write your equation in the form:9*x^2+4*x*y+6*y^2==400In order to plot the ellipse you can use the package Graphics`ImplicitPlot`in this way:In[1]:=<< Graphics`ImplicitPlot`In[2]:=ImplicitPlot[ 9*x^2 + 4*x*y + 6*y^2 == 400, {x, -7, 7}, PlotStyle -> RGBColor[1, 0, 0]];Germ.87n Buitrago A.----- Original Message -----> 0.09 x^2 +0.04 x y + 0.06 y^2 = 4> Maciej ==== =first this in not an ellipse.the ellipse generic formula is : (x^2)/(a^2)+(y^2)/(b^2) = 0.I guest that you want report a graph of the solution y of the equation: 0.09x^2 +0.04 x y + 0.06 y^2 = 4 for x varying into a given range.As you can veryfing using:Solve[0.09 x^2 + 0.04 x y + 0.06 y^2 == 4, y]the solutins are two:{{y -> 8.333333333333334*(-0.04*x -0.1414213562373095*Sqrt[48.00000000000001 + 0.*x - 1.*x^2])}, {y -> 8.333333333333334*(-0.04*x +0.1414213562373095*Sqrt[48.00000000000001 + 0.*x - 1.*x^2])}}than you can construct a function:function1[x_] = 8.333333333333334*(-0.04*x -0.1414213562373095*Sqrt[48.00000000000001 - *x^2])},that is a real value only if (48.00000000000001 - *x^2)>0, i.e. ifapproximatively -6 True]the same for the other soluztion.good luck-upimak ha scritto nel messaggio> I am new with Mathematica, I have one question,> I know that the sollution might be very easy, but I wasn't able to> find it by now.> I would like to draw an ellipse, the formula let's say is as follows:> 0.09 x^2 +0.04 x y + 0.06 y^2 = 4> MaciejReply-To: murray@math.umass.edu ==== =One way is:ContourPlot[0.09 x^2 + 0.04 x y + 0.06 y^2, {x, -10, 10}, {y, -10, 10}, Contours -> {4}, PlotPoints -> 50, ContourShading -> False];> I am new with Mathematica, I have one question,> I know that the sollution might be very easy, but I wasn't able to> find it by now.> I would like to draw an ellipse, the formula let's say is as follows:> 0.09 x^2 +0.04 x y + 0.06 y^2 = 4> Maciej> -- Murray Eisenberg murray@math.umass.eduMathematics & Statistics Dept.Lederle Graduate Research Tower phone 413 549-1020 (H)University of Massachusetts 413 545-2859 (W)710 North Pleasant StreetAmherst, MA 01375Reply-To: kuska@informatik.uni-leipzig.de ==== =Needs[Graphics` ImplicitPlot`]ImplicitPlot[0.09 x^2 + 0.04 x y + 0.06 y^2 == 4, {x, -10, 10}, {y, -10, 10}]may help. Jens> I am new with Mathematica, I have one question,> I know that the sollution might be very easy, but I wasn't able to> find it by now.> I would like to draw an ellipse, the formula let's say is as follows:> 0.09 x^2 +0.04 x y + 0.06 y^2 = 4> Maciej ==== =I pretend to know how many times the function f has to be evaluated when using NDSolve to solve a differential equation.I've tried :cont=0;f[x_]:=(cont++;x^2);NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}]I obtain the solution of the ODE but cont returns 1 instead the number of funtion evaluations.How can I obtain it? ==== => I pretend to know how many times the function f has to be evaluated when > using NDSolve to solve a differential equation.> I've tried :> cont=0;> f[x_]:=(cont++;x^2);> NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}]> I obtain the solution of the ODE but cont returns 1 instead the number > of funtion evaluations.> How can I obtain it?> you need to make sure that the function f[x] is evaluated only when itgets a numeric argument. Otherwise, Mathematica expands f[x]symbolically to the expression x^2 before NDSolve is called.Writing your code as follows will solve your problem:cont=0;f[x_?NumericQ]:=(cont++;x^2);NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}] Eckhard Hennig ==== => I pretend to know how many times the function f has to be evaluated when > using NDSolve to solve a differential equation.> I've tried :> cont=0;> f[x_]:=(cont++;x^2);> NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}]> I obtain the solution of the ODE but cont returns 1 instead the number > of funtion evaluations.> How can I obtain it?cont=0;f[x_?NumericQ]:=(cont++;x^2)NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}]-> cont = 94-Jim ==== =Try the following:Clear[f]cont=0;f[x_?NumericQ]:=(cont++;x^2);NDSolve [ {y''[x]+y[x]==f[x],y[0]==1,y'[0] ==0},y,{x,0,6}]The problem you are encountering occurs because NDSolve evaluates it'sinputs first, and so NDSolve is trying to solve the differential equationy''[x]+y[x]==x^2 instead of y''[x]+y[x]==f[x]. By restricting the definitionof f to evaluate only when it's input is numeric, NDSolve will keep the f[x]in the differential equation. I've included a Clear[f] statement just incase the old definition of f was still there.Carl WollPhysics DeptU of Washington> I pretend to know how many times the function f has to be evaluated when> using NDSolve to solve a differential equation.> I've tried :> cont=0;> f[x_]:=(cont++;x^2);> NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}]> I obtain the solution of the ODE but cont returns 1 instead the number> of funtion evaluations.> How can I obtain it?Reply-To: kuska@informatik.uni-leipzig.de ==== =and aftercont = 0;f[x_?NumericQ] := (cont++; x^2);NDSolve[{y''[x] + y[x] == f[x], y[0] == 1, y'[0] == 0}, y, {x, 0, 6}]cont is 93.Thats because *you* gave only a blank pattern for f[x_] and NDSolve[]evaluate it to compile the right hand sides or translate itto an internal function. So *your* function is only oncewhen Mathematica can include it into it's internal functionfor the right hand sides. Jens> I pretend to know how many times the function f has to be evaluated when> using NDSolve to solve a differential equation.> I've tried :> cont=0;> f[x_]:=(cont++;x^2);> NDSolve[ {y''[x]+y[x]==f[x],y[0]==1,y'[0 ]==0},y,{x,0,6}]> I obtain the solution of the ODE but cont returns 1 instead the number> of funtion evaluations.> How can I obtain it?> ==== =Fabio,f[x_ /; IntegerQ[Rationalize[x/(2Pi)]], y] := g[x]f[x_, y_] := h[x, y]f[# Pi, y] & /@ Range[10]{h[Pi, y], g[2*Pi], h[3*Pi, y], g[4*Pi], h[5*Pi, y], g[6*Pi], h[7*Pi, y], g[8*Pi], h[9*Pi, y], g[10*Pi]}f[2.0Pi, y]g[6.28319]f[3.5, y]h[3.5, y]f[4.01Pi, 5]h[12.5978, 5]You can use a second argument in Rationalize to control how small arationalization error is allowed and there is always the question about whatdomain around 2nPi you want to include in the first definition.David Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/ ==== =yes , this is a comon problem.You can either do:y=If[x>1000, ToExpression[BigVariable][[x]],x] ]or, maybe more readable, declare at the begging of ThisPackage:bigvar := bigvar = ToExpression[OtherPackage`BigVariable];and then y=If[x>1000, bigvar, x](* ************************** *)Alternatively you can create .mx files which load much quicker than .m files.It would be really nice if WRI could investigate why loading larger .m files is so slow ( I suspect it has to do something with the speed of side effectslike DownValues declarations etc., but I don't know ).Rolf MertigMertig Consultinghttp://www.mertig.com ==== =========================== ==== =DeclareePackage[OtherPackage`, {BigVariable} ]. The idea was to preventthe loading of a large file in routine cases. However, when ThisPackage`defines its functions, inside the Private` area, it includes a conditionalcall to BigVariable. It turns out that OtherPackage is loaded when thatfunction is defined. I was wondering if there is a way to avoid this.Roughly speaking, here is the setting:BeginPackage[ OtherPackage` ]BigVariable::usage=exampleBegin[Private`]BigVariable=Table[x y,{x,1000},{y,1000}]End[ ]EndPackage[ ]BeginPackage[ ThisPackage` ]function::usage=exampleBegin[Private`]function[x_]:=Module[{ y},y=If[x>1000,BigVariable[[x]],x] ]End[ ]EndPackage[ ]I don't want OtherPakage to be loaded unless function[x] is called withx>1000 but it loads when function is defined. Any ideas?Nicholas ==== =I was looking for a function that can convert numbers between bases.For example, going from Base 3 to Base 9, or from Base 16 to Base 8.It seems like I have to a few steps and then use BaseForm to convert to thedesired end base.Is there a single command or simple function to do such conversions? Forexample,ConvertBase[from_, to_, num_]would convert from base to base 9 using the number num as the number toconvert (it would best be allowed to let users input in that specific basesince they'd be going from base 3 to base 9, for example so maybe num isneeded at all). ==== =Dear NGMabye this is too simple, but I cant just figure it outI want to get an inverse function for y[t] where y[t_]:=NIntegrate[R[x]^4,{x,0,t}] /. ndsolution[[1]]andR[t] is an interpolatingfunction(R>0 from NDSolve) on the interval 0= Dear NG> Mabye this is too simple, but I cant just figure it out> I want to get an inverse function for y[t] where> y[t_]:=NIntegrate[R[x]^4,{x,0,t}] /. ndsolution[[1]]> and> R[t] is an interpolatingfunction(R>0 from NDSolve) on the interval 0= after that I hope to be able to calculate the integral :> a = (1/y[T])*> NIntegrate[R[InvFunction[y[t]]*Cos[y[t]], {y[t], 0, y[T]}]> it works with a constant instead of R[t].> Hope you can help, and that the above is understandable.> Martin Skogstad ==== =You may have noticed that there have been no posts to the Mathematicaice storm in North Carolina and my power was out for several days andT-1 circuits all over the area were out until today. Everything is backto normal now. Posts will start going out tonight.Sorry for the delays,Steve ChristensenModeratorReply-To: ==== =Dear Luiz,The theory of Levemberg-Marquardt algorithm is described in many books; Isuggest, for example, Numerical Recipes, W.H Press, B.P. Flannery, S.A. Teukolsky, Cambridgeuniversity press, in whichthere is also the source code in Fortran Language.However, the Mathematica calculated errors differ from the originaltheoretical errors.***********************************************Stefano FricanoDip. di Scienze Fisiche ed AstronomicheUniversit.88 degli StudiVia Archirafi, 36Palermo 90123********************************************* ==== =There seems to be a bug here due to the fact that ContinuousDistributions.m(4.0.0) does not check that q is numeric.Quantile[NoncentralChiSquareDistribution[2, 10], q]Produces a load of errors and some incorrect results when used in LogPlot.LogPlot[Quantile[NoncentralChiSquareDistribution[2, 10], q], {q, .1, .9}]This is of course a pain. What is the best way to correct this? Is it tocopy the particular function from ContinuousDistribution.m and re-include itin a little add on or is there an updated version.TIA-- Nigel ==== =I am confused by this result:In: Module[{a}, a = x; g[x_] = a]; g[y]Out: xSomehow I would expect the same output asIn: Module[{}, a = x; g[x_] = a]; g[y]Out: yIn the first case ?g gives g[x$_] = x,while in the second it gives g[x_] = x.The difference is a dollar sign.Can anyone explain why the dollar is inserted in one casebut not in the other? The x was not a local variablein either case.My version is 4.1 for PowerMac. Gianluca Gorni-- +---------------------------------+ | Gianluca Gorni | | Universita` di Udine | | Dipartimento di Matematica | | e Informatica | | via delle Scienze 208 | | I-33100 Udine UD | | Italy | +---------------------------------+ | Ph.: (39) 0432-558422 | | http://www.dimi.uniud.it/~gorni | +---------------------------------+ ==== => I tried to do but I can't. mathematica says sigma^2 is not a valid> variable.> is there any way to do that ? I can do that if I replace sigma^2 with> some variable and then differentiate it with respect to the some> variable not having power term.You can do this with the change rule. If the following example, f is afunction of s, and g[s s] ==== f[x].f[s_] = (Sin[t]*Cos[2*t])/s + 3*t^3 /. t -> s*sg[t_] = (Sin[t]*Cos[2*t])/Sqrt[t] + 3*t^3Although we cannot find the derivative of f wrt s^2 directly, we can use thechain rule:d1 = f'[s]/D[s*s, s]To check the answer, for the equivalent derivative on g:d2 = g'[t] /. t -> s*sSimplify[PowerExpand[d1 - d2]]Hope this helps,Tom Burton ==== =I guess I never learn anything the easy way. I've been told this before, but until I actually started poking around in the data from Mathematica 3D animations, I didn't understand what all this meant. I had been creating my straight line segments with ParametricPlot3D and not setting PlotPoints->2. When I looked at how they were represented, I realised how much useless data was being generated. Anyhow, just about the time I was ready to put this on the web, I had the first hard drive failure in my life (on my own system). What luck! It was the drive holind my web-site. Fortunately, I have backups of everything. N