Documentation / LearningLemur

  • Demos
  • Visit our website
  • Contact us
  • MathType

    • WirisQuizzes

      • LearningLemur

        • CalcMe

          • MathPlayer

            • Store FAQ

              • VPAT for the electronic documentation

                • MathFlow

                  • BF FAQ

                    • Miscellaneous

                      • Wiris Integrations

                        • Home
                        • LearningLemur
                        • Using LearningLemur
                        • Advanced Logic in LearningLemur
                        • Advanced Logic Examples in LearningLemur
                        • Advanced Logic Examples in LearningLemur

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

                        Reading time: 2min

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

                        Your browser does not support HTML5 video.

                        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) != 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 LearningLemur
                        • Common Patterns and Best Practices
                        • Glossary of Commands

                        Was this article helpful?

                        Yes
                        No
                        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 Requirements Steps Define a reusable random function Generate a valid coefficient matrix Define a known integer solution Compute the right-hand side Extract coefficients Verify it worked Full algorithm (copy-paste version) Options and variations Common errors The system has no unique solution Infinite regeneration loop The displayed coefficients don't match the solution Related

                        Making people’s STEM work more meaningful

                        MathType

                        • MathType for Office Tools
                        • MathType for Mac
                        • MathType for Microsoft 365
                        • MathType for Google Workspace
                        • MathType for LMS
                        • MathType for XML Editors
                        • Arabic notation
                        • Our products accessibility
                        • MathType is online

                        WirisQuizzes

                        Learning Lemur

                        Solutions for Education

                        • Blackboard Learn
                        • Brightspace by D2L
                        • Canvas
                        • Google Classroom
                        • Moodle
                        • Schoology

                        Solutions for Publishing Houses

                        Solutions for Technical Writers

                        Solutions for Chemistry

                        Integrations

                        • HTML Editors
                        • MathType in WordPress

                        Pricing

                        Company

                        Careers

                        Blog

                        Contact Us

                        Buy Now

                        Plugin Downloads

                        © Wiris 2025

                        • Cookie Settings
                        • Cookie Policy
                        • Terms of Use
                        • Privacy Policy / GDPR
                        • Student Data Privacy
                        • Compliance
                        • Powered by Helpjuice
                        Expand