I submit the following matrix to both MATLAB and R x= 0.133 0.254 -0.214 0.116 0.254 0.623 -0.674 0.139 -0.214 -0.674 0.910 0.011 0.116 0.139 0.011 0.180 MATLAB's inv(x) provides the following 137.21 -50.68 -4.70 -46.42 -120.71 27.28 -8.94 62.19 -58.15 6.93 -7.89 36.94 8.35 11.17 10.42 -14.82 R's solve(x) provides: 261.94 116.22 150.92 -267.78 116.22 344.30 286.68 -358.30 150.92 286.68 252.96 -334.09 -267.78 =358.30 -334.09 475.22 inv(x)*x = I(4) and solve(x)%*%x = I(4) Is there a way to obtain the MATLAB result in R? Thanks for any help. Pat Gray
I suppose the solution is unstable because x is ill-conditioned:> x[,1] [,2] [,3] [,4] [1,] 0.133 0.254 -0.214 0.116 [2,] 0.254 0.623 -0.674 0.139 [3,] -0.214 -0.674 0.910 0.011 [4,] 0.116 0.139 0.011 0.180> cor(x)[,1] [,2] [,3] [,4] [1,] 1.0000000 0.9963557 -0.9883690 0.8548065 [2,] 0.9963557 1.0000000 -0.9976663 0.8084090 [3,] -0.9883690 -0.9976663 1.0000000 -0.7663847 [4,] 0.8548065 0.8084090 -0.7663847 1.0000000> kappa(x)[1] 2813.326 hth, Kingsford Jones On Thu, Jan 29, 2009 at 7:00 PM, Joseph P Gray <jpgray at uwm.edu> wrote:> I submit the following matrix to both MATLAB and R > > x= 0.133 0.254 -0.214 0.116 > 0.254 0.623 -0.674 0.139 > -0.214 -0.674 0.910 0.011 > 0.116 0.139 0.011 0.180 > > MATLAB's inv(x) provides the following > 137.21 -50.68 -4.70 -46.42 > -120.71 27.28 -8.94 62.19 > -58.15 6.93 -7.89 36.94 > 8.35 11.17 10.42 -14.82 > > R's solve(x) provides: > 261.94 116.22 150.92 -267.78 > 116.22 344.30 286.68 -358.30 > 150.92 286.68 252.96 -334.09 > -267.78 =358.30 -334.09 475.22 > > inv(x)*x = I(4) > and solve(x)%*%x = I(4) > > Is there a way to obtain the MATLAB result in R? > > Thanks for any help. > > > Pat Gray > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Joseph P Gray wrote:> I submit the following matrix to both MATLAB and R > > x= 0.133 0.254 -0.214 0.116 > 0.254 0.623 -0.674 0.139 > -0.214 -0.674 0.910 0.011 > 0.116 0.139 0.011 0.180 > > MATLAB's inv(x) provides the following > 137.21 -50.68 -4.70 -46.42 > -120.71 27.28 -8.94 62.19 > -58.15 6.93 -7.89 36.94 > 8.35 11.17 10.42 -14.82 > > R's solve(x) provides: > 261.94 116.22 150.92 -267.78 > 116.22 344.30 286.68 -358.30 > 150.92 286.68 252.96 -334.09 > -267.78 =358.30 -334.09 475.22 > > inv(x)*x = I(4) > and solve(x)%*%x = I(4) > > Is there a way to obtain the MATLAB result in R?Multiply x[3,4] by 10: > xx <- x > xx[3,4]<-0.11 > solve(xx) [,1] [,2] [,3] [,4] [1,] 137.20892 -50.67500 -4.705127 -46.41581 [2,] -120.71445 27.27570 -8.937571 62.19270 [3,] -58.15073 6.93474 -7.886343 36.93919 [4,] 8.34851 11.17053 10.415928 -14.81602 -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Joseph P Gray wrote:> > I submit the following matrix to both MATLAB and R > > x= 0.133 0.254 -0.214 0.116 > 0.254 0.623 -0.674 0.139 > -0.214 -0.674 0.910 0.011 > 0.116 0.139 0.011 0.180 > > MATLAB's inv(x) provides the following > 137.21 -50.68 -4.70 -46.42 > -120.71 27.28 -8.94 62.19 > -58.15 6.93 -7.89 36.94 > 8.35 11.17 10.42 -14.82 > > R's solve(x) provides: > 261.94 116.22 150.92 -267.78 > 116.22 344.30 286.68 -358.30 > 150.92 286.68 252.96 -334.09 > -267.78 =358.30 -334.09 475.22 > >The matrix x is clearly symmetric. Therefore I expect a symmetric inverse of x. The result of Matlab's inv(x) is clearly not symmetric. R's result is symmetric. I find what is shown as Matlab's result difficult to believe. Berend -- View this message in context: http://www.nabble.com/Matlab-inv%28%29-and-R-solve%28%29-differences-tp21740213p21745164.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- playwith package crashes on Mac
- [PATCH v2 0/8] vsock/virtio: optimizations to increase the throughput
- [PATCH v2 0/8] vsock/virtio: optimizations to increase the throughput
- [PATCH v2 0/8] vsock/virtio: optimizations to increase the throughput
- Poor creat/delete files performance