Wiris

Documentation / Nubric

  • Demos
  • Visit our website
  • Contact us
  • MathType

    • WirisQuizzes

      • Nubric

        • CalcMe

          • MathPlayer

            • Store FAQ

              • MathFlow

                • BF FAQ

                  • Miscellaneous

                    • Wiris Integrations

                      • Home
                      • Nubric
                      • Using Nubric
                      • Advanced Logic in Nubric
                      • Advanced Logic Examples in Nubric
                      • Advanced Logic Examples in Nubric

                      How to generate a 3×3 linear system with a unique integer solution

                      Reading time: 2min

                      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.

                      Following this guide, 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 Nubric:

                      Your browser does not support HTML5 video.

                      Before you begin

                      Requirements

                      • Basic knowledge of how to create a Nubric 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) != 0

                      This 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_vect

                      This 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:

                      a11x+ a12y+ a13z = b1 a21x+ a22y+ a23z = b2 a31x+ a32y+ a33z = b3

                      Verify it worked

                      • Preview the question multiple times.
                      • Confirm that the determinant of matrix A is 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

                      Related

                      • Understanding Advanced Logic in Nubric
                      • Common Patterns and Best Practices
                      • Glossary of Commands

                      Was this article helpful?

                      Give feedback about this article

                      Related Articles

                      • Linear algebra
                      • Smith normal form

                      How to generate a 3×3 linear system with a unique integer solution

                      Before you begin Steps Verify it worked Full algorithm (copy-paste version) Options and variations Common errors Related

                      Empowering STEM education

                      MathType

                      • Office Tools
                      • LMS
                      • XML
                      • HTML

                      WirisQuizzes

                      Nubric

                      Integrations

                      Solutions

                      • Education
                      • Publishing houses – platforms and interactive
                      • Publishing houses – Print and digital
                      • Technical writers

                      Pricing

                      Downloads

                      Blog

                      • Success stories

                      About us

                      • Careers
                      • Partnership

                      Contact Us

                      Contact Sales

                      European union (European Regional Development Fund) and 1EdTech (TrustEd Apps Certified)
                      • Cookie Policy
                      • Terms of Use
                      • Privacy Policy / GDPR
                      • Student Data Privacy
                      • Compliance
                      • Cookie Settings

                      © Wiris 2026

                      Expand