Re: [Q] accuracy control in eq. solving?

*To*: mathgroup at smc.vnet.net*Subject*: [mg23741] Re: [mg23678] [Q] accuracy control in eq. solving?*From*: Andrzej Kozlowski <andrzej at tuins.ac.jp>*Date*: Mon, 5 Jun 2000 01:09:34 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

> To: mathgroup at smc.vnet.net > Subject: [mg23741] [mg23678] [Q] accuracy control in eq. solving? > From: research at proton.csl.uiuc.edu (James) To: mathgroup at smc.vnet.net > Date: Mon, 29 May 2000 12:24:06 -0400 (EDT) > Organization: University of Illinois at Urbana-Champaign > Sender: owner-wri-mathgroup at wolfram.com > Hello! > > I have a question regarding to the accuracy control of > the equation solution. > > I'm currently solving polynomial equations(degrees are at least 5), > and wondering if I can control the accuracy level > of the solution. > Specifically, when I recomputed the original equation > by replacing the answers that mathematica gives, > I got the error of roughly 10^-7 or 10^-8 for degree 9. > Regarding this, I have the following questions. > > (1) Is there any way to control(increase) the accuracy? > (2) What would be the best known math tool (in terms of accuracy) > in solving high-degree polynimial equations? > (3) I'm a newbie in mathematica, > so I manually type in, when I check the answer(polynomial eqs.). > Is there any systax for that in mathematica? > > Thank you. The general rule about Mathematica is: anything that can be computed at all can be computed to an arbitrary degree of accuracy. There are actually some rare exceptions but this is not one of them. Probably the easiest way to understand this is to look at an example. Here is a random polynomial of degree 9: In[2]:= poly = Table[Random[Integer, {-10, 10}], {10}].x^Range[0, 9] Out[2]= 2 3 4 5 6 7 8 9 2 - 10 x + 3 x + 9 x + 8 x - 3 x - 3 x + 3 x - 8 x + 4 x We first solve it exactly (infinite accuracy): In[3]:= polyroots = Solve[poly == 0, x] Out[3]= {{x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 1]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 2]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 3]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 4]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 5]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 6]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 7]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 8]}, {x -> Root[2 - 10*#1 + 3*#1^2 + 9*#1^3 + 8*#1^4 - 3*#1^5 - 3*#1^6 + 3*#1^7 - 8*#1^8 + 4*#1^9 & , 9]}} The answer is given in terms of Root objects. (Of course you can't get expressions in terms of radicals in this case). Now we compute these with, say, 20 digits of precision: In[4]:= numpolyroots = N[polyroots, 20] Out[4]= {{x -> -0.98988060577279493540}, {x -> 0.22829237962552395100}, {x -> 0.64224951666033773144}, {x -> -0.61735759466257344187 - 0.70338383228603023397 I}, {x -> -0.61735759466257344187 + 0.70338383228603023397 I}, {x -> 0.15805224924788994907 - 1.2845743104741265788 I}, {x -> 0.15805224924788994907 + 1.2845743104741265788 I}, {x -> 1.5189747001581501193 - 0.20186087093410669801 I}, {x -> 1.5189747001581501193 + 0.20186087093410669801 I}} Mathematica gives its answers in terms of replacement rules. That makes it very easy to substitute these back into the original polynomial: In[5]:= poly /. numpolyroots Out[5]= -18 -20 -19 -18 -18 -18 -18 {0. 10 , 0. 10 , 0. 10 , 0. 10 + 0. 10 I, 0. 10 + 0. 10 I, -17 -17 -17 -17 -16 -16 -16 -16 0. 10 + 0. 10 I, 0. 10 + 0. 10 I, 0. 10 + 0. 10 I, 0. 10 + 0. 10 I} You see that the error is extremly small. You can of course make it even smaller by taking more digits. expr/. {a->b} is the way to substitute a given rule into an expression. You can also substitute a list of rules as in expr/.{{a->b},{a->c},...} to get a list of the results as above. Pay attention to the List brackets. To see why compare the following two cases: In[6]:= x^2 + y^2 /. {x -> 1, y -> 2} Out[6]= 5 In[7]:= x^2 + y^2 /. {{x -> 1}, {y -> 2}} Out[7]= 2 2 {1 + y , 4 + x } -- Andrzej Kozlowski Toyama International University, JAPAN For Mathematica related links and resources try: <http://www.sstreams.com/Mathematica/>