Matrix inverse for non-square matrix

I am trying to create a code that solves viscoelastic mechanical behavior problems using the collocation method. In order to do this I need to solve the following;
[A]{D}={B} where is D is the array needing to be solved. Therefore {D}=[A]^-1 {B} where A is a (j x k) matrix and B is a (k x 1) array making the resulting D a (j x 1) array. In my current code j = 11 and k = 1,400,000. I've tried the following codes but the results are not correct;
Dj = pinv(Akj).*Bk;
However, this results in a k x j matrix for D.
and;
Dj = (Akj.^(-1))*Bk;
Which does result in the correct j x 1 array for D, but I do not believe it is given the correct values.
Thank you for your time.

댓글 수: 4

David Goodmanson
David Goodmanson 2019년 4월 13일
Hi John,
If A is (j x k) then D has to be (k x 1) and B is (j x 1). Do you mean that A is (k x j)?
David Wilson
David Wilson 2019년 4월 13일
편집: David Wilson 2019년 4월 13일
If A is (j*k), however that is less likely given that A then is "short and wide".
In any case, a better computational approach is never to compute the inverse explicitly, but rather use "backslash",
D = A\B
Read the help on mldivide.
If A is sparse, you might want to take advantage of that.
I agree with David, probably the best would be to just use backslash.
Also, in your call
pinv(Akj).*Bk
the .* operator does an elementwise multiplication, not a matrix multiplication as you were probably intending.
The inv function errors for non-square matrices, so it should just not work, not give you any wrong results.
John Chesser
John Chesser 2019년 4월 15일
편집: John Chesser 2019년 4월 15일
As mentioned above, A is supposed to be a (k x j) matrix. When filling A with it's values I had isssues in my loops which were causing A to be a (j x k) matrix. I have since fixed this and have implemented the suggested D = A\B, and it is working correctly and giving correct solutions. Thank you all for your help!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 4월 11일

편집:

2019년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by