-
MathType
-
WirisQuizzes
-
LearningLemur
-
CalcMe
-
MathPlayer
-
Store FAQ
-
VPAT for the electronic documentation
-
MathFlow
-
BF FAQ
-
Miscellaneous
-
Wiris Integrations
How to generate a 3×3 linear system with a unique integer solution
Reading time: 2minWhen to use this: Use this method when you want students to solve a system of three linear equations in three variables and ensure that the system has a unique solution with integer values.
What you'll achieve: You will generate a 3×3 linear system whose determinant is non-zero and whose solution is predefined and guaranteed to be composed of integers.
See it in action: Watch how this logic is implemented inside LearningLemur:
Before you begin
Requirements
- Basic knowledge of how to create a LearningLemur question
- Familiarity with adding an algorithm to generate random variables
- Basic understanding of matrices and determinants
Steps
Define a reusable random function
r() := random([-5..5]/[0])This helper function generates random non-zero integers.
Generate a valid coefficient matrix
repeat
A = [ [r(), r(), r()],
[r(), r(), r()],
[r(), r(), r()] ]
until determinant(A) != 0This guarantees that the system has a unique solution.
Define a known integer solution
sx = r()
sy = r()
sz = r()
solution_vect = [ sx, sy, sz ]This sets the exact solution the system will have.
Compute the right-hand side
b_vect = A * solution_vectThis ensures that the generated system corresponds to the predefined solution.
Extract coefficients
a11 = A subindex_operator(1,1)
a12 = A subindex_operator(1,2)
a13 = A subindex_operator(1,3)
a21 = A subindex_operator(2,1)
a22 = A subindex_operator(2,2)
a23 = A subindex_operator(2,3)
a31 = A subindex_operator(3,1)
a32 = A subindex_operator(3,2)
a33 = A subindex_operator(3,3)
b1 = b_vect subindex_operator(1)
b2 = b_vect subindex_operator(2)
b3 = b_vect subindex_operator(3)These variables can now be used to display the system:
Verify it worked
- Preview the question multiple times
- Confirm that the determinant of matrix
Ais never 0 - Solve the generated system manually
- Verify that the solution is always
(sx, sy, sz)
Full algorithm (copy-paste version)
Use the complete version below if you want to copy the logic directly into your question algorithm:
# Define a function to generate random integers, excluding zero
r() := random([-5..5]/[0])
# Generate a coefficient matrix A with a non-zero determinant
repeat
A = [ [r(), r(), r()],
[r(), r(), r()],
[r(), r(), r()] ]
until determinant(A) != 0
# Generate a unique integer solution vector
sx = r()
sy = r()
sz = r()
solution_vect = [ sx, sy, sz ]
# Calculate the right-hand side vector
b_vect = A * solution_vect
# Extract coefficients
a11 = A subindex_operator(1,1)
a12 = A subindex_operator(1,2)
a13 = A subindex_operator(1,3)
a21 = A subindex_operator(2,1)
a22 = A subindex_operator(2,2)
a23 = A subindex_operator(2,3)
a31 = A subindex_operator(3,1)
a32 = A subindex_operator(3,2)
a33 = A subindex_operator(3,3)
b1 = b_vect subindex_operator(1)
b2 = b_vect subindex_operator(2)
b3 = b_vect subindex_operator(3)Options and variations
- If you want larger systems, you can increase the interval in
r() - If you want rational solutions instead of integers, you can allow fractions in the
r()function - If you want more challenging systems, you can use larger coefficient ranges to increase computational difficulty
Common errors
The system has no unique solution
Ensure the condition determinant(A) != 0 is correctly applied
Infinite regeneration loop
Broaden the interval if the determinant condition is too restrictive
The displayed coefficients don't match the solution
Confirm that the right-hand side vector is computed as A * solution_vect