Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mathgenerator/_gen_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@
("tribonacci_series", "computer_science"),
("nth_tribonacci_number", "computer_science"),
("velocity_of_object", "misc"),
("system_of_equations_2var", "algebra")
]
32 changes: 32 additions & 0 deletions mathgenerator/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,35 @@ def orthogonal_projection(min_val=-10, max_val=10):
problem = f'Find the orthogonal projection of ${v}$ onto ${u}$'
solution = f'$[{y[0]}, {y[1]}]$'
return problem, solution

def system_of_equations_2var(max_coef=10):
r"""System of Equations in 2 Variables

| Ex. Problem | Ex. Solution |
| --- | --- |
| Solve the system: $2x + 3y = 12$ and $4x - y = 6$ | $x = 3, y = 2$ |
"""
# Generate coefficients that will give integer solutions
while True:
a1 = random.randint(1, max_coef)
b1 = random.randint(1, max_coef)
a2 = random.randint(1, max_coef)
b2 = random.randint(1, max_coef)
c1 = random.randint(1, max_coef * 2)
c2 = random.randint(1, max_coef * 2)

# Calculate determinant
det = a1 * b2 - a2 * b1

if det != 0: # Ensure system has unique solution
x = (c1 * b2 - c2 * b1) / det
y = (a1 * c2 - a2 * c1) / det

# Check if solutions are integers (for simplicity)
if x == int(x) and y == int(y):
x, y = int(x), int(y)
break

problem = f"Solve the system: ${a1}x + {b1}y = {c1}$ and ${a2}x + {b2}y = {c2}$"
solution = f"$x = {x}, y = {y}$"
return problem, solution