Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: LinearSolve[m, b] is not equivalent to LinearSolve[m][b]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84361] RE: [mg84283] LinearSolve[m, b] is not equivalent to LinearSolve[m][b]
  • From: "Tony Harker" <a.harker at ucl.ac.uk>
  • Date: Thu, 20 Dec 2007 00:08:22 -0500 (EST)

It's certainly true that they are not the same, though IN PRINCIPLE the
results are the same. Try, for example,
s1 = LinearSolve[Array[a, {3, 3}], Array[b, 3]]
s2 = LinearSolve[Array[a, {3, 3}]][Array[b, 3]]
s1 - s2 // Simplify 

 Your matrix m is badly conditioned, which may be where the problem arises. 

 Incidentally, why did Wolfram think it was a good idea to remove
MatrixConditionNumber from the standard add-on packages? I'm happy with the
idea that things from the add-ons get 'promoted' to the standard system, but
I've always regarded the standard add-ons as something I could rely on being
there. Seeing some of their content whisked away to a web address seems to
be a step backwards. And the only way I found this out was to fire up 5.2
with its vastly superior help file to remind me of the precise name of the
function, then go back to 6.1 to find out where it had gone.

Tony Harker

Dr A.H. Harker
Department of Physics and Astronomy
University College London
Gower Street
London
WC1E 6BT

Tel: (44)(0) 2076793404
E:    a.harker at ucl.ac.uk
  

]-> -----Original Message-----
]-> From: Andrew Moylan [mailto:andrew.j.moylan at gmail.com] 
]-> Sent: 18 December 2007 00:16
]-> To: mathgroup at smc.vnet.net
]-> Subject: [mg84283] LinearSolve[m, b] is not equivalent to 
]-> LinearSolve[m][b]
]-> 
]-> At the bottom of this message I define a machine-precision 
]-> matrix m and a machine precision vector b. (I apologise for 
]-> their large size.)
]-> 
]-> 
]-> 1. LinearSolve[m, b] is not equivalent to LinearSolve[m][b].
]-> 
]-> The documentation for LinearSolve states that 
]-> "LinearSolve[m,b] is equivalent to LinearSolve[m][b]." For 
]-> m and b, however:
]-> 
]-> sol1 = LinearSolve[m, b]
]-> >>
]-> {-1.68129*10^9,-7.29642*10^11,-6.31285*10^20,4.99506*10^22,3
]-> .84561*10^24,-1.
]-> 3535*10^26,-7.82045*10^25,1.69903*10^27,2.25713*10^25,-2.492
]-> 72*10^26,-1.0616
]-> *10^26,9.03507*10^26,-4.77786*10^24,2.87158*10^25,4.55334*10
]-> ^25,-2.43647*10^
]-> 26,-2.82578*10^26,1.27101*10^27,-1.38448*10^28,5.52681*10^30}
]-> 
]-> sol2 = LinearSolve[m][b]
]-> >>
]-> {-1.8893*10^-6,0.00627488,-0.000025753,-0.00767333,0.0000624
]-> 517,-0.000027213
]-> 7,-0.0000464774,0.00188393,7.51337*10^-6,-0.0000585884,6.018
]-> 09*10^-6,-0.0004
]-> 30135,-6.4536*10^-7,-0.0000946245,-1.29985*10^-6,0.000070139
]-> 2,-4.03265*10^-7
]-> ,0.0000499027,4.97681*10^-7,9.8366*10^-6}
]-> 
]-> Needless to say, sol2 is the one that approximately solves 
]-> m.x==b. Type
]-> (m.sol1 - b) and (m.sol2 - b) to see this. sol1 is wild.
]-> 
]-> 
]-> 2. When using arbitrary precision arithmetic instead of 
]-> machine precision arithmetic, the wild behaviour does not occur.
]-> 
]-> Here are m and b at precision $MachinePrecision (i.e., 15.9546):
]-> mm = SetPrecision[m, $MachinePrecision]; bb = 
]-> SetPrecision[b, $MachinePrecision];
]-> 
]-> For these definitions, LinearSolve[mm,bb] and 
]-> LinearSolve[mm][bb] *are* approximately equal, and they are 
]-> approximately equal to sol2 (the tame solution).
]-> 
]-> 
]-> Can anyone shed some light on this topic? My working 
]-> hypothesis is that 1.
]-> sol1 is the result of a bug (or inconsistent/bad handling 
]-> of poorly conditioned matrices); and 2. that bug isn't 
]-> present in the arbitrary precision version of LinearSolve. 
]-> Then the workaround would be: don't use LinearSolve[m, b]; 
]-> instead use LinearSolve[m][b].
]-> 
]-> 
]-> Andrew Moylan
]->  
]-> 
]-> Here are the definitions of m and b:
]->  
]-> m={{0.,120.,4.,-120.,-16.,120.,36.,-120.,-64.,120.,100.,-120
]-> .,-144.,120.,196
]-> .,-120.,-256.,120.,324.,-120.},{-120.,0.,120.,4.,-120.,-16.,
]-> 120.,36.,-120.,-
]-> 64.,120.,100.,-120.,-144.,120.,196.,-120.,-256.,120.,324.},{
]-> 0.,137.667770123
]-> 3155,4.,-126.52361302070159,-14.704805681953697,94.895372832
]-> 69993,28.5433706
]-> 5200333,-47.90363918197348,-40.5445084603741,-6.843659629032
]-> 01,45.5838278268
]-> 89575,60.48297480676686,-39.728436874545594,-104.33013932096
]-> 895,21.378320417
]-> 681632,131.28632837898377,8.062099516267708,-136.98735411779
]-> 6,-44.1577316683
]-> 6576,120.51022451941246},{-137.6677701233155,0.,126.52361302
]-> 070159,4.,-94.89
]-> 537283269993,-14.704805681953697,47.90363918197348,28.543370
]-> 65200333,6.84365
]-> 962903201,-40.5445084603741,-60.48297480676686,45.5838278268
]-> 89575,104.330139
]-> 32096895,-39.728436874545594,-131.28632837898377,21.37832041
]-> 7681632,136.9873
]-> 54117796,8.062099516267708,-120.51022451941246,-44.157731668
]-> 36576},{0.,190.5
]-> 9730297009568,4.,-140.79278017868444,-11.819078485136764,17.
]-> 407811913964213,
]-> 14.191990544591762,115.0747432704792,-4.317884714201286,-187
]-> .4174897103089,-
]-> 15.679345960738772,161.81300927620237,34.27414014713948,-51.
]-> 64259235864097,-
]-> 37.12435871470173,-85.51702774336465,16.98339066468509,177.9
]-> 8415019794658,19
]-> .503939521116326,-177.43405229412292},{-190.59730297009568,0
]-> .,140.7927801786
]-> 8444,4.,-17.407811913964213,-11.819078485136764,-115.0747432
]-> 704792,14.191990
]-> 544591762,187.4174897103089,-4.317884714201286,-161.81300927
]-> 620237,-15.67934
]-> 5960738772,51.64259235864097,34.27414014713948,85.5170277433
]-> 6465,-37.1243587
]-> 1470173,-177.98415019794658,16.98339066468509,177.4340522941
]-> 2292,19.50393952
]-> 1116326},{0.,322.872632447701,4.,-154.48510511279565,-7.6555
]-> 31727995272,-175
]-> .03942948598953,-1.0111563678108242,321.98759337281865,16.60
]-> 122006528058,-13
]-> 3.08385014981712,-18.17273422029246,-194.634138709607,-4.033
]-> 538586739716,319
]-> .3373281801208,29.944998291495985,-110.95299226741214,-27.37
]-> 121776748681,-21
]-> 3.1618091027223,-9.033977175382377,314.93636636525736},{-322
]-> .872632447701,0.
]-> ,154.48510511279565,4.,175.03942948598953,-7.655531727995272
]-> ,-321.9875933728
]-> 1865,-1.0111563678108242,133.08385014981712,16.6012200652805
]-> 8,194.6341387096
]-> 07,-18.17273422029246,-319.3373281801208,-4.033538586739716,
]-> 110.952992267412
]-> 14,29.944998291495985,213.1618091027223,-27.37121776748681,-
]-> 314.936366365257
]-> 36,-9.033977175382377},{0.,688.6670919150857,4.,-114.7211902
]-> 4973249,-2.66535
]-> 03057498296,-650.4455719765721,-10.667982702682368,331.42935
]-> 32674049,10.0696
]-> 8577122105,540.0236559683539,13.586339913460915,-511.3483803
]-> 35829,-20.536381
]-> 943186196,-369.6583357342561,-11.038447478035566,634.5070001
]-> 073631,31.584889
]-> 64242715,158.26040739218521,2.3538027804037114,-687.23442826
]-> 12197},{-688.667
]-> 0919150857,0.,114.72119024973249,4.,650.4455719765721,-2.665
]-> 3503057498296,-3
]-> 31.4293532674049,-10.667982702682368,-540.0236559683539,10.0
]-> 6968577122105,51
]-> 1.348380335829,13.586339913460915,369.6583357342561,-20.5363
]-> 81943186196,-634
]-> .5070001073631,-11.038447478035566,-158.26040739218521,31.58
]-> 488964242715,687
]-> .2344282612197,2.3538027804037114},{0.,1955.742698127284,4.,
]-> 319.116359538738
]-> 95,2.610702193856547,-1851.6029756343717,-10.722043885311114
]-> ,-923.3643533687
]-> 346,-9.886748303381077,1550.2743077507857,13.837048847537616
]-> ,1429.2774204092
]-> 866,20.248784522486616,-1083.847095614267,-11.66260123591745
]-> 1,-1782.97766919
]-> 99382,-31.348033453698886,501.9941315420778,3.48596962079657
]-> 45,1946.79731676
]-> 494},{-1955.742698127284,0.,-319.11635953873895,4.,1851.6029
]-> 756343717,2.6107
]-> 02193856547,923.3643533687346,-10.722043885311114,-1550.2743
]-> 077507857,-9.886
]-> 748303381077,-1429.2774204092866,13.837048847537616,1083.847
]-> 095614267,20.248
]-> 784522486616,1782.9776691999382,-11.662601235917451,-501.994
]-> 1315420778,-31.3
]-> 48033453698886,-1946.79731676494,3.4859696207965745},{0.,826
]-> 7.868082849189,4
]-> .,3927.69394068881,7.6008836161019895,-4536.125017493609,-1.
]-> 1674815477135652
]-> ,-8237.513731446,-16.680749126890216,-3290.4228773517743,-17
]-> .86489003655355,
]-> 5111.248564132217,4.652781192989794,8146.673560968948,30.168
]-> 278100627578,262
]-> 8.9911352802987,26.554230419975788,-5648.841605090274,-10.40
]-> 4652778807701,-7
]-> 996.014586041039},{-8267.868082849189,0.,-3927.69394068881,4
]-> .,4536.125017493
]-> 609,7.6008836161019895,8237.513731446,-1.1674815477135652,32
]-> 90.4228773517743
]-> ,-16.680749126890216,-5111.248564132217,-17.86489003655355,-
]-> 8146.67356096894
]-> 8,4.652781192989794,-2628.9911352802987,30.168278100627578,5
]-> 648.841605090274
]-> ,26.554230419975788,7996.014586041039,-10.404652778807701},{
]-> 0.,66714.5128785
]-> 9093,4.,49053.640102814905,11.764430373243481,5421.503814372
]-> 8425,13.95034162
]-> 6292579,-41081.027085007,3.8241097110929165,-65833.364164734
]-> 65,-16.221120559
]-> 06104,-55730.47653404341,-34.361001075598665,-16121.29969181
]-> 952,-36.24174857
]-> 068484,32023.238065218116,-15.09440727983296,63213.194009826
]-> 875,21.624753701
]-> 270276,60935.1643846494},{-66714.51287859093,0.,-49053.64010
]-> 2814905,4.,-5421
]-> .5038143728425,11.764430373243481,41081.027085007,13.9503416
]-> 26292579,65833.3
]-> 6416473465,3.8241097110929165,55730.47653404341,-16.22112055
]-> 906104,16121.299
]-> 69181952,-34.361001075598665,-32023.238065218116,-36.2417485
]-> 7068484,-63213.1
]-> 94009826875,-15.09440727983296,-60935.1643846494,21.62475370
]-> 1270276},{0.,2.1
]-> 09193656453301*^6,4.,1.931251213300796*^6,14.650157570060415
]-> ,1.4274481663250
]-> 76*^6,28.242584405174718,682791.3566687256,39.65940348013593
]-> 6,-177073.045991
]-> 05718,43.712855697405764,-1.0070598598161684*^6,36.570928350
]-> 44224,-1.6671251
]-> 576076704*^6,16.935107017831488,-2.0458959211793535*^6,-13.3
]-> 18096903865762,-
]-> 2.0794620445450086*^6,-49.21136470378096,-1.7621599055136922
]-> *^6},{-2.1091936
]-> 56453301*^6,0.,-1.931251213300796*^6,4.,-1.427448166325076*^
]-> 6,14.65015757006
]-> 0415,-682791.3566687256,28.242584405174718,177073.0459910571
]-> 8,39.65940348013
]-> 5936,1.0070598598161684*^6,43.712855697405764,1.667125157607
]-> 6704*^6,36.57092
]-> 835044224,2.0458959211793535*^6,16.935107017831488,2.0794620
]-> 445450086*^6,-13
]-> .318096903865762,1.7621599055136922*^6,-49.21136470378096},{
]-> 0.,3.21113804748
]-> 0835*^10,4.,3.2001703830231155*^10,15.945351888106718,3.1673
]-> 423099192696*^10
]-> ,35.67267128166534,3.1128780771958237*^10,62.91151228627201,
]-> 3.03714973078828
]-> 5*^10,97.28714180413428,2.94067457209015*^10,138.32438810885
]-> 077,2.8241116242
]-> 59851*^10,185.4525285933514,2.6882571304243427*^10,238.01117
]-> 208726953,2.5340
]-> 39114531167*^10,295.2570820108493,2.362511042003884*^10},{-3
]-> .211138047480835
]-> *^10,0.,-3.2001703830231155*^10,4.,-3.1673423099192696*^10,1
]-> 5.94535188810671
]-> 8,-3.1128780771958237*^10,35.67267128166534,-3.0371497307882
]-> 85*^10,62.911512
]-> 28627201,-2.94067457209015*^10,97.28714180413428,-2.82411162
]-> 4259851*^10,138.
]-> 32438810885077,-2.6882571304243427*^10,185.4525285933514,-2.
]-> 534039114531167*
]-> ^10,238.01117208726953,-2.362511042003884*^10,295.2570820108493}};
]-> 
]-> b={1.4715177646857693,0.,1.7272858774111686,0.,2.43844948323
]-> 59858,0.,3.86819
]-> 71196755,0.,6.1130185623361015,0.,7.4508820294899945,0.,3.39
]-> 3321220405215,0.
]-> ,0.03385691675272283,0.,3.3743307736651725*^-14,0.,1.2388511
]-> 2322841128107475
]-> 3`10.061735978331926*^-496,0.};
]-> 
]-> 
]-> 



  • Prev by Date: Re: express a quadratic, in the form (x+a)^2 + b
  • Next by Date: Re: Re: LinearSolve[m, b] is not equivalent to LinearSolve
  • Previous by thread: Re: Re: LinearSolve[m, b] is not equivalent to LinearSolve
  • Next by thread: Interesting problem: Use of NonlinearRegress inside a package