Re: Precision in Mathematica 6

*To*: mathgroup at smc.vnet.net*Subject*: [mg92311] Re: Precision in Mathematica 6*From*: "David Park" <djmpark at comcast.net>*Date*: Sat, 27 Sep 2008 06:51:12 -0400 (EDT)*References*: <gbflpa$69g$1@smc.vnet.net>

I know, it is really difficult to get started with Mathematica. It does pay to work through some of the basic documentation and work examples. But there is so much of it! To obtain better postings to MathGroup, you can select your Input or Output expressions and then CopyAs, Input Text or Plain Text, or in some cases convert the cells to InputForm with Shift-Ctrl-I, and then copy and paste that into the posting. So let's get to your problem. The first thing I would do, especially when there are problems, is not try to do several complicated things in one statement, such as an integral and finding a root. Let's do the integral first and define a function for the result (even though the result in this case is just another defined function). f[t_] = Integrate[Sin[x]/x, {x, 0, t}] SinIntegral[t] Then we can plot the function so we have some idea of its behavior and where the root(s) might lie. Here the PlotRange -> All option is necessary to get the full range. Otherwise Mathematica just picks what it thinks is the 'interesting' part. Plot[f[t], {t, 0, 15}, PlotRange -> All] Then we see that the root lies somewhere near 1 so we use: answer = FindRoot[f[t] == 1, {t, 1}] {t -> 1.06484} This answer is actually in MachinePrecision but machine precision numbers are, by default, displayed with 6 places. (This can be changed with the Option Inspector, Formatting Options, Expression Formatting, Display Options, PrintPrecision. But generally one doesn't want to do that.) The main misconception about N is that its purpose is to format the output display of numbers. This is basically wrong, although sometimes it does affect the display. The purpose of N is to change EXACT numbers to APPROXIMATE numbers with a given precision. The standard method to adjust the output display of numbers is to use NumberForm. So: NumberForm[answer, 10] {t->1.064839726} However, if we specify a WorkingPrecision in FindRoot we can also obtain a display with more digits: FindRoot[f[t] == 1, {t, 1}, WorkingPrecision -> 10] {t->1.064839726} So Mathematica actually does work fairly conveniently, but the use of N is a source of A LOT of confusion to beginners and WRI might more quickly point users to relevant Help. (Also, the behavior of N changed somewhat over the various versions of Mathematica and that is also a source of confusion. And I might even be corrected on my explanation!) So the rule is: To adjust the format of displayed numbers use NumberForm and not N. -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ "CaveSnow" <cavesnow at gmail.com> wrote in message news:gbflpa$69g$1 at smc.vnet.net... > Hey guys! I have just started using Mathematica (I'm using v. 6) and I > hate to admit that there are some strange things happening. I have > already tried for quit a lot to figure things out but everything works > in a strange way. > > this is the things I written in my notebook > > FindRoot[\!\( > \*SubsuperscriptBox[\(\[Integral]\), \(0\), \(t\)] > FractionBox[\(Sin[x]\), \(x\)] \[DifferentialD]x\) == 1, {t, 1}] > > > N[t, 10] /. % > > > \!\( > \*SubsuperscriptBox[\(\[Integral]\), \(0\), \(t\)] > FractionBox[\(Sin[x]\), \(x\)] \[DifferentialD]x\) - 1 /. %% > > \!\( > \*SubsuperscriptBox[\(\[Integral]\), \(0\), \(1.0648397255365585`\)] > FractionBox[\(Sin[x]\), \(x\)] \[DifferentialD]x\) - 1 > > > \!\( > \*SubsuperscriptBox[\(\[Integral]\), \(0\), \(1.06484\)] > FractionBox[\(Sin[x]\), \(x\)] \[DifferentialD]x\) - 1 > > > In other words I used FindRoot to find the t that makes the definite > integral from 0 to t of sinx/x be 1. > As a result I got a certain rule, that had a small amount of digits > (only 6 of them). Then I issued the second command ti get more digits > from the result. But the result, even if I asked 10 digits remained > the same 1.06484. > Then of course I supposed that the problem was that it was actually > the findroot procedure that calculated only those digits. So then I > did this: first I actually calculated the value of the integral using > the /.%% substitution, thus applying the rule, and it gave me one > answer. Then I triedo to copy and paste the value displayed in the > rule but when I did the paste command it had me written many more > digits than the original 6, and the answer was a little different (it > actually displayed 17 digits). > > And after that I tried to evaluate the integral with the originally > displayed 1.06484 value and the result of the integral was much more > off than in the other two cases. > > The only thing that now I can say that actually the command N[t,10]/.% > actually dowsn't write me those aditional digits and neither does the > sequence of commands t/.% N[%,10]. > > > What the Hell!!! > > I do not understand why these strange things happen. Mathematica is > absolutely unpredictable! Anyway I could find no notice on why using N > doesn't work in this case in the documentation. Is this a bug? Anyway > if it is hard to read the commands in the way I written them I can > send you the nb file. Please help! I already encountered this > seemingly random behavior of mathematica in other occasions and not > having to do only with the precision of numbers. It is rather > annoying, and I am getting rather fed up with this. It may as well be > my fault but there is no documentation to understand why. > > > Thanks in advance >