How should I use Cramer’s rule in Matlab?
16,852
You can use Cramer's rule like this for your specific 4x4 case. The element at index i
of the result x
is given by the ratio of 2 determinants (See the wikipedia link for a full explanation) - you can create the result with the following loop
x = ones(4,1);
a_det = det(A);
for i = 1:4
C = A;
C(:,i) = B;
x(i,1) = det(C)/a_det;
end
the column vector x
should now be your result. There could be a faster way to do this but this should work. You can verify this by comparing the result with
x = A\B;
Author by
Yigit Can
Updated on June 14, 2022Comments
-
Yigit Can about 2 years
The relationship between the two matrices is shown is
Ax=B
.How do I find
x
using Cramer’s rule?A=[521 202 -176 612;-761 41 -655 712;314 102 -234 891;612 291 209 -318] B=[718;408;215;356]