System of linear equations

1 view (last 30 days)
Sk Zeeshan Ali
Sk Zeeshan Ali on 9 May 2021
Commented: Walter Roberson on 9 May 2021
u1, u2, v1, v2, w1, w2 are each 5 by 5 matrix. Following pair of linear equations hold at each grid, for example
At (1,1 ): c1*u1(1,1) + c2*v1(1,1) = w1(1,1)
and c1*u2(1,1) + c2*v2(1,1) = w2(1,1)
At (1,2 ): c1*u1(1,2) + c2*v1(1,2) = w1(1,2)
and c1*u2(1,2) + c2*v2(1,2) = w2(1,2)
...
At (5,5): c1*u1(5,5) + c2*v1(5,5) = w1(5,5)
and c1*u2(5,5) + c2*v2(5,5) = w2(5,5).
How can I solve for c1 and c2 (each in 5 by 5 matrix form)?
  2 Comments
Walter Roberson
Walter Roberson on 9 May 2021
Could you confirm that you need this solved in Simulink? If so then would using a MATLAB Function Block be acceptable, or do you need to make it out of more basic blocks ?
Sk Zeeshan Ali
Sk Zeeshan Ali on 9 May 2021
Hi, I am just looking for the solution in matlab. Giving the tag Simulink was unintentional.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 9 May 2021
c1*u1(1,1) + c2*v1(1,1) = w1(1,1)
How can I solve for c1 and c2 (each in 5 by 5 matrix form)?
If c1 and c2 are 5 x 5, then the implication is that at each location (J,K) in the grid, c1*u1(J,K) + c2*v1(J,K) = w1(J,K) but c1 and c2 are 5 x 5, so the left side would be 5 x 5 and the right side would be a consistent scalar. That would imply that
c1 = (w1(J,K) - c2*v1(J,K))./u1(J,K)
c1 = w1(J,K)./u1(J,K) - c2*(v1(J,K)./u1(J,K))
and that has to hold for all J,K, with c1 and c2 being the same 5 x 5 matrices for each J,K location.
And at the same time,
c1 = w2(J,K)./u2(J,K) - c2*(v2(J,K)./u2(J,K))
This leads to
c1 = (v2.*w1 - v1.*w2) ./ (u1.*v2 - u2.*v1)
c2 = (u1.*w2 - u2.*w1) ./ (u1.*v2 - u2.*v1)
But are you sure that is the equation system you want??
  2 Comments
Sk Zeeshan Ali
Sk Zeeshan Ali on 9 May 2021
The procedure is indeed correct if we apply Cramer's rule. However, i am looking for some quick matlab operator to solve this problem. Because instead of c1 and c2, if we have more number of similar constants, then it would be difficult to apply Cramer's rule. Can we solve this problem using \ operator or similar thing? Any suggestions, much appreciated!
Walter Roberson
Walter Roberson on 9 May 2021
c12 = [u1(:), v1(:); u2(:), v2(:)] \ [w1(:); w2(:)];
c1 = reshape(c12(1:25), 5, 5);
c2 = reshape(c12(26:end), 5, 5);

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!