# Revision history [back]

Some useful resources:

The variables:

sage: x, y, z, w = SR.var('x, y, z, w')


The equations (writing == 0 is not needed in order to solve):

sage: eqq = [x + 2*y + 2*z + 2*w, 2*x + 4*y + 6*z + 8*w, 3*x + 6*y + 8*z + 10*w]


The solutions (always give a name to anything you compute):

sage: sols = solve(eqq, x, y, z, w)
sage: sols
[[x == 2*r1 - 2*r2, y == r2, z == -2*r1, w == r1]]


Get the desired V with

sage: sol = sols
sage: sol
[x == 2*r1 - 2*r2, y == r2, z == -2*r1, w == r1]
sage: V = [s.rhs() for s in sol]
sage: V
[2*r1 - 2*r2, r2, -2*r1, r1]


or directly

sage: V = [s.rhs() for s in sols]; V
[2*r1 - 2*r2, r2, -2*r1, r1]


The dimension of the space of solutions is the dimension of the kernel of the corresponding matrix.

Compute the matrix:

sage: vv = x, y, z, w
sage: a = matrix([[eq.coefficient(v) for v in vv] for eq in eqq])
sage: a
[ 1  2  2  2]
[ 2  4  6  8]
[ 3  6  8 10]


Dimension of the (right) kernel:

sage: a.right_kernel().dimension()
2


Some useful resources:

The variables:

sage: x, y, z, w = SR.var('x, y, z, w')


The equations (writing == 0 is not needed in order to solve):

sage: eqq = [x + 2*y + 2*z + 2*w, 2*x + 4*y + 6*z + 8*w, 3*x + 6*y + 8*z + 10*w]


The solutions (always give a name (tip: naming things you compute makes them easier to anything you compute):reuse):

sage: sols = solve(eqq, x, y, z, w)
sage: sols
[[x == 2*r1 - 2*r2, y == r2, z == -2*r1, w == r1]]


Get the desired V withwith:

sage: sol = sols
sage: sol
[x == 2*r1 - 2*r2, y == r2, z == -2*r1, w == r1]
sage: V = [s.rhs() for s in sol]
sage: V
[2*r1 - 2*r2, r2, -2*r1, r1]


or directlydirectly:

sage: V = [s.rhs() for s in sols]; V
[2*r1 - 2*r2, r2, -2*r1, r1]


The dimension of the space of solutions is the dimension of the kernel of the corresponding matrix.

Compute the matrix:

sage: vv = x, y, z, w
sage: a = matrix([[eq.coefficient(v) for v in vv] for eq in eqq])
sage: a
[ 1  2  2  2]
[ 2  4  6  8]
[ 3  6  8 10]


The kernel:

sage: E = a.right_kernel()
sage: E
Vector space of degree 4 and dimension 2 over Symbolic Ring
Basis matrix:
[  1   0  -1 1/2]
[  0   1  -2   1]


Dimension of the (right) kernel:

sage: a.right_kernel().dimension()
k = E.dimension()
sage: k
2


Basis of the kernel:

sage: B = E.basis()
sage: B
[
(1, 0, -1, 1/2),
(0, 1, -2, 1)
]


Linear combination of kernel basis vectors, similar to the one given by solve:

sage: s, t = SR.var('s t')
sage: E.linear_combination_of_basis((2*(s - t), t))
(2*s - 2*t, t, -2*s, s)