Solving Linear Equations

To find a particular solution of a linear equation in a Galois field, use the \ or / operator on Galois arrays. The table below indicates the equation that each operator addresses, assuming that A and B are previously defined Galois arrays.

OperatorLinear EquationSyntaxEquivalent Syntax Using \
Backslash (\)A * x = Bx = A \ BNot applicable
Slash (/)x * A = Bx = B / Ax = (A'\B')'

The results of the syntax in the table depend on characteristics of the Galois array A:

Example: Solving Linear Equations

The examples below illustrate how to find particular solutions of linear equations over a Galois field.

m = 4;
A = gf(magic(3),m); % Square nonsingular matrix
Awide=[A, 2*A(:,3)]; % 3-by-4 matrix with redundancy on the right
Atall = Awide'; % 4-by-3 matrix with redundancy at the bottom
B = gf([0:2]',m);
C = [B; 2*B(3)];
D = [B; B(3)+1];
thesolution = A \ B; % Solution of A * x = B
thesolution2 = B' / A; % Solution of x * A = B'
ck1 = all(A * thesolution == B) % Check validity of solutions.
ck2 = all(thesolution2 * A == B')
% Awide * x = B has infinitely many solutions. Find one.
onesolution = Awide \ B;
ck3 = all(Awide * onesolution == B) % Check validity of solution.
% Atall * x = C has a solution.
asolution = Atall \ C;
ck4 = all(Atall * asolution == C) % Check validity of solution.
% Atall * x = D has no solution.
notasolution = Atall \ D;
ck5 = all(Atall * notasolution == D) % It is not a valid solution.

The output from this example indicates that the validity checks are all true (1), except for ck5, which is false (0).


© 1994-2005 The MathWorks, Inc.