-
MathType
-
WirisQuizzes
-
Nubric
-
CalcMe
-
MathPlayer
-
Store FAQ
-
MathFlow
-
BF FAQ
-
Miscellaneous
-
Wiris Integrations
How to generate linearly independent or dependent 3D vectors
Reading time: 2minUse this method when you want students to determine whether a set of three 3D vectors is linearly independent or linearly dependent, with a controlled outcome.
Following this guide, you will generate a set of three 3D vectors that is guaranteed to be either:
- Linearly dependent (by construction), or
- Linearly independent (by determinant check).
See it in action: Watch how this logic is implemented inside Nubric:
Before you begin
Requirements
- Basic knowledge of how to create a Nubric question.
- Familiarity with adding and editing question algorithms.
- Basic understanding of determinants and linear dependence.
Steps
Generate two linearly independent base vectors.
u1 = random([-5..5] / [0])
u2 = random([-5..5] / [0])
u3 = random([-5..5] / [0])
u = [u1, u2, u3]
v1 = random([-5..5] / [0])
v2 = random([-5..5] / [0])
v3 = random([-5..5] / [0])
while vectorial_product(u,[v1,v2,v3])==[0,0,0]
v1 = random([-5..5] / [0])
v2 = random([-5..5] / [0])
v3 = random([-5..5] / [0])
end
v = [v1, v2, v3]This ensures:
-
uis a non-zero vector. -
vis not a scalar multiple ofu - So
{u, v}is linearly independent.
Generate a dependent third vector (controlled dependence).
k1 = random([-3..3] / [0])
k2 = random([-3..3] / [0])
w = k1 * u + k2 * vSince w is a linear combination of u and v, the set {u, v, w} is guaranteed to be linearly dependent.
Generate an independent third vector (controlled independence).
t1 = random([-5..5] / [0])
t2 = random([-5..5] / [0])
t3 = random([-5..5] / [0])
while determinant([u,v,[t1,t2,t3]]) == 0
t1 = random([-5..5] / [0])
t2 = random([-5..5] / [0])
t3 = random([-5..5] / [0])
end
t = [t1, t2, t3]This ensures that {u, v, t} is linearly independent.
Verify it worked
- Preview the question multiple times.
- For dependent sets, verify that one vector is a linear combination of the others.
- For independent sets, confirm the determinant of the matrix formed by the vectors is non-zero.
- Ensure no zero vectors appear.
Full algorithm (copy-paste version)
Use the complete version below if you want to copy the logic directly into your question algorithm:
# Generate two linearly independent 3D vectors u and v
u1 = random([-5..5] / [0])
u2 = random([-5..5] / [0])
u3 = random([-5..5] / [0])
u = [u1, u2, u3]
v1 = random([-5..5] / [0])
v2 = random([-5..5] / [0])
v3 = random([-5..5] / [0])
while vectorial_product(u,[v1,v2,v3])==[0,0,0]
v1 = random([-5..5] / [0])
v2 = random([-5..5] / [0])
v3 = random([-5..5] / [0])
end
v = [v1, v2, v3]
# Generate dependent third vector
k1 = random([-3..3] / [0])
k2 = random([-3..3] / [0])
w = k1 * u + k2 * v
# Generate independent third vector
t1 = random([-5..5] / [0])
t2 = random([-5..5] / [0])
t3 = random([-5..5] / [0])
while determinant([u,v,[t1,t2,t3]]) == 0
t1 = random([-5..5] / [0])
t2 = random([-5..5] / [0])
t3 = random([-5..5] / [0])
end
t = [t1, t2, t3]Options and variations
- If you only want dependent sets, you can remove the independent vector generation section.
- If you only want independent sets, you can remove the dependent vector logic.
- If you want larger coordinate values, you can increase the interval in the
random()calls. - If you want 2D vectors instead, you can remove the third coordinate and adapt determinant checks accordingly.
Common errors
Vectorial product is always zero.
Ensure vectors are regenerated inside the while loop.
Determinant loop runs too long.
Broaden the interval to increase variability.
An unexpected zero vector appears.
Confirm that zero is excluded in the random interval (/[0]).