A, B and C are matrices.
A*B = C
Now I want to do a reverse i.e calculate A using B and C. How do I do it?
Matlab says that B should be a square matrices to calculate its inverse.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
IF a unique solution exists, then one might best use pinv to find it. Using the example posed by schwarz…
The problem is, B is singular. So there are potentially infinitely many solutions.
See that pinv and slash both yield the same solution, since B is non-singular AND it is well conditioned.
But how about if we try something that is less well conditioned? In this next xample, I’ll use a matrix that is not really that bad.
Well, it has a pretty large condition number, but this matrix is not what I’d call numerically singular.
Lets try several different solutions now.
pinv did quite well.
slash and inv were both not bad, although clearly worse in this case. The pinv solution seems a bit more stable for this problem.
We might as well throw a QR factorization at this too. Use a pivoted solution for the best stability. Note that when your system is nearly singular, we will still expect problems.
You can see the problem by inspecting R. The last diagonal element is tiny compared to the remainder. This will cause problems in the solution, amplifying any noise.
The QR factors have the property that Q*R*P’ = B. So we can solve for A here as:
Note that I’ve arranged the parens to be as efficient as possible, since MATLAB will use the property of R as a triangular matrix to simply do a backsolve. We don’t want MATLAB to be factorizing a matrix that is already factored.
But now lets look at one posed by vahid:
However, the solution posed by vahid was simply terrible. Do NOT use this last form. PLEASE. There is a reason why people tell you not to do so, or they should have told you that! Yes, I know there are a group of people who do not know the mathematics involved, and they keep spreading it. You may even find it in some uninformed textbooks.
The nice thing about pinv is it works for any matrix, singular or not. If a solution exists, it will find one. If the solution is unique, it will work. If the solution is not unique, then well, what do you expect?