Invert Matrix Command

A and B are matrices, which A is invers from B. Is there any differences between A=B^-1; A=B.\1; A=inv(B);
coz i have different result from 3 command above

12 Comments

Jan
Jan on 15 Nov 2011
What about trying it in Matlab and comparing the results?
Yes i have tried, but in my case when i used A=B^-1 and A=inv(B) i get Inf result. it was different with A=B.\1 , although explanation in matlab help showed simmiliarity between all those command, that was i guess....maybe im wrong.
As I mentioned, "A=B.\1" method is wrong. First, check the determinant of the matrix. If its determinant is 0, the matrix is singular
is there any method to avoid Inf result when create inverse matrix?
Jan
Jan on 15 Nov 2011
"Avoid"? Building the inverse is a well-defined mathematical operation. There are no degrees of freedom which allow to modify the result.
It is like a division by zero: You can catch this case, but you cannot avoid, that the result is Inf (or NaN for some cases).
what about pinv?is that another choice for me?
Can you write how you make the matrix B and why do you need the inverse matrix?
This is my data, i call it matrix y, which consist y1 and y2.
y1=y(:,1); and y2=y(:,2);
91.3600000000000 9.09000000000000
81.9800000000000 8.04000000000000
83.3900000000000 7.95000000000000
89.9300000000000 7.32000000000000
83.3800000000000 7.94000000000000
88.2100000000000 7.26000000000000
83.1100000000000 6.88000000000000
79.0700000000000 6.44000000000000
94.0500000000000 10.5400000000000
87.3666666666667 8.62756395875771
51.6500000000000 3.79187935524974
96.3123697889276 9.05000000000000
83.5201129290811 6.47628937657751
88.2822635556373 6.53120884650403
97.7485157937070 9.26010524849543
62.9108356860225 6.21188000000000
86.8054178430113 6.10960000000000
87.2876058710136 6.70809271547082
31.7541784301126 3.10103746017809
31.3541784301126 3.89263270542303
31.0704319591464 3.93979332207437
31.8054178430113 2.41932709948679
31.7571174473266 2.45365318072931
32.8654584109626 2.94404622817266
87.1108356860225 6.41229552674817
91.1162535290338 7.32147940127193
76.8792490107883 6.29018684796355
95.7053482338574 7.97101408843632
64.1054178430113 4.45535798833371
30.5254178430113 2.78703470631920
32.6825070580676 3.33189666711284
32.1254178430113 2.89685219459403
32.7709486151037 2.72341621277990
32.1054178430113 2.79210000000000
32.9850988129460 3.42999394839633
99.1000000000000 10.8835853352147
then a wanna make covariance matrix from y1 and y2. After that i need the inverse from that covariance matrix.
I used this command
y1=y(:,1);
y2=y(:,2);
nn=length(y1);
vary1=((y1-mean(y1))*(y1-mean(y1))')/(nn);
vary2=((y2-mean(y2))*(y2-mean(y2))')/(nn);
covy12=((y1-mean(y1))*(y2-mean(y2))')/(nn);
covy21=((y2-mean(y2))*(y1-mean(y1))')/(nn);
w=[vary1 covy12;covy21 vary2];
W=inv(w);
the result always Inf.
I used W for the weight matrix in weighted least square regression for biresponse regression. please help.
Each row in a matrix w is linearly dependent, so rank(w) = 1.
hold all
for k=2:72
plot(w(1,:)./w(k,:))
end
There is no an inverse matrix in this case.
thanks

Sign in to comment.

 Accepted Answer

Statement A=B.\1 doesn't calculate an inverse matrix. You probably mean:
A2=B\eye(size(B))
B^-1 and inv(B) give the same result. B\eye(size(B)) is a little different, because it uses different algorithm.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!