Re: NullSpace[m], why different result for symbolic vs numerical matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg59238] Re: NullSpace[m], why different result for symbolic vs numerical matrix?
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 3 Aug 2005 01:19:44 -0400 (EDT)
- Organization: The Open University, Milton Keynes, U.K.
- References: <dcmu9h$gjd$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Nasser Abbasi wrote: > > hello, This 5.2 on windows. > > The help for NullSpace function says: > > "NullSpace works on both numerical and symbolic matrices. " > > But why do I get different answer if matrix A is numeric vs symbolic? > > What Am I missing? > > Both answers are correct in the sense that A times each of null > vectors produced does give 0. > > ------------ > Remove["Global`*"] > A = {{0, 1, 1, 2}, {1, 2, 3, 4}, {2, 0, 2, 0}}; > m1 = NullSpace[A] > m2 = NullSpace[N[A, 16]] > > > Out[190]= {{0, -2, 0, 1}, {-1, -1, 1, 0}} > > Out[191]= > {{0.5286741846941267165032578206`16., -0.4493204281752718232493645376`16., > -0.5286741846941267165032578206`16., > 0.488997306434699269876311179`16.}, > {-0.4183886482487962269364866589`16., -0.78504329244074722971820122`16., > 0.4183886482487962269364866589`16., > 0.1833273220959755013908572806`16.}} > > ------------- > > thanks > Nasser > Hi Nasser, I would bet that Mathematica uses different algorithms depending on the type of computations required ? that is symbolic or numeric ? and that the numeric algorithms are sensitive to the level of precision. So what does that mean? Since any linear combination of vectors in the null space is also a vector in the null space, it seems that Mathematica returns different basis depending on the level of precision required (see the examples below). First, we start with your set of instructions: In[1]:= A = {{0, 1, 1, 2}, {1, 2, 3, 4}, {2, 0, 2, 0}} m1 = NullSpace[A] m2 = NullSpace[N[A, 16]] Out[1]= {{0, 1, 1, 2}, {1, 2, 3, 4}, {2, 0, 2, 0}} Out[2]= {{0, -2, 0, 1}, {-1, -1, 1, 0}} Out[3]= {{0.5286741846941267165032578206`16., -0.4493204281752718232493645376`16., -0.5286741846941267165032578206`16., 0.488997306434699269876311179`16.}, {-0.4183886482487962269364866589`16., -0.78504329244074722971820122`16., 0.4183886482487962269364866589`16., 0.1833273220959755013908572806`16.}} m1 and m2 seem to be very different! However, we can easily check that the dot product of the matrix A with any vector or linear combination of vectors in the null spaces yields the null vector: In[4]:= A . m2[[1]] Out[4]= {0``15.708633541785163, 0``15.3037024397948, 0``15.674751904468202} In[5]:= Chop[%] Out[5]= {0, 0, 0} In[6]:= A . m2[[2]] Out[6]= {0``15.804076397081605, 0``15.4004498182078, 0``15.776360115962408} In[7]:= Chop[%] Out[7]= {0, 0, 0} Here we try an arbitrary linear combination of the previous two vectors: In[8]:= A . (0.3*m2[[1]] + Pi*m2[[2]]) Out[8]= {0., 0., 0.} In[9]:= Chop[%] Out[9]= {0, 0, 0} Now, let compute the null space with different precisions. First, we use machine-size precision, In[10]:= m3 = NullSpace[N[A]] Out[10]= {{0.6635579956810613, -0.025578590096125134, -0.6635579956810613, 0.34456829288859336}, {-0.11931571947227673, -0.9041723032201953, 0.11931571947227686, 0.39242829187395917}} Although the above vectors look very different from m2, they still represent the same null space: In[11]:= A . ((1/3)*m3[[1]] + Sqrt[2]*m3[[2]]) Out[11]= {-8.326672684688674*^-17, 0., 3.3306690738754696*^-16} In[12]:= Chop[%] Out[12]= {0, 0, 0} Finally, we try to find the null space with 30-digit precision. Again, we have, some, very different values from m2 or m3 but we can check that the vectors are still in the null space. In[13]:= m4 = NullSpace[N[A, 30]] Out[13]= {{0.674199862463238261523033089320117282800097714724`30., 0.13484006776473518222792910747178292795000432815`30., -0.674199862463238261523033089320117282800080485231`30., 0.269679897349251539647551990924167177425035857902`30.}, {-7.1814038029693919022999324086749460854468`30.*^-8, 0.89442717663710319855583138799277287812406086137`30., 7.1814038029693919022999324086749409848716`30.*^-8, -0.447213624225570614124875205496048482436735355042`30.}} In conclusion, we can assume that the internal algorithms used by Mathematica to compute a given null space yield different numeric values depending on the degree of precision asked, and the result is always expressed as a linear combination of a normal orthogonal basis as we can check with the *GramSchmidt* method: In[14]:= Needs["LinearAlgebra`Orthogonalization`"] In[15]:= GramSchmidt[m2] == m2 Out[15]= True In[16]:= GramSchmidt[m3] == m3 Out[16]= True In[17]:= GramSchmidt[m4] == m4 Out[17]= True In[18]:= $Version Out[18]= "5.2 for Microsoft Windows (June 20, 2005)" Hope this makes sense! Best regards, /J.M.