# Solving a linear system of equations depending of a parameter

Hi,

Let $a$ be a fixed parameter, and let $$(S) : \begin{cases} x - y + a z = a ~ ; \ a+ay-z=-1 ~ ; \ x + y +z = 2 \end{cases}$$

I want to determine the solution of this system depending on the value of $a$. "By hand", I find that there is a unique solution if and only if $a \not \in {-1 ; 3 }$, that there is no solution if $a=3$, and that there are infinitely many solutions if $a=-1$. But when try with SageMath, I only get the case where $a \not \in { -1 ; 3 }$...

var('x,y,z,a')
eq1 = x-y+a*z==a
eq2 = x+a*y-z==-1
eq3 = x+y+z==2
solve([eq1,eq2,eq3],x,y,z)


returns

[[x == (a - 1)/(a - 3), y == -1/(a - 3), z == (a - 4)/(a - 3)]]


How could I we do to solve properly this kind of problem with SageMath ?

edit retag close merge delete

Sort by ยป oldest newest most voted

Well... Run :

reset()
var("x, y, z, a")
Eqs=[x-y+a*z==a, a+a*y-z==-1, x+y+z==2]
S1=solve(Eqs, (x, y, z))


Then :

sage: S1
[[x == (2*a - 1)/(a - 2), y == -(a^2 - a + 1)/(a^2 - a - 2), z == (a^2 - 4*a - 2)/(a^2 - a - 2)]]


(Note : your "resolution by hand" seems to be erroneous...)

Check :

sage: [[bool(u.subs(s)) for u in Eqs] for s in S1]
[[True, True, True]]


The problem arises from the presence of the parameter $a$ in the denominator of the elements of the solution(s). Collect these denominators :

sage: Dens=set(flatten([[u.rhs().denominator() for u in s] for s in S1])) ; Dens
{a^2 - a - 2, a - 2}


We can now solve for $a$ each of these denominators, giving us a list of problematic values :

sage: PV=set(flatten([u.solve(a) for u in Dens])) ; PV
{a == 2, a == -1}


We can substitute each of these problematic values for a in the system :

sage: {u: [v.subs(u) for v in Eqs] for u in PV}
{a == 2: [x - y + 2*z == 2, 2*y - z + 2 == -1, x + y + z == 2],
a == -1: [x - y - z == -1, -y - z - 1 == -1, x + y + z == 2]}


and try to solve the substituted system in each case :

sage: {u: solve([v.subs(u) for v in Eqs], (x, y, z)) for u in PV}
{a == 2: [], a == -1: []}


In both cases, the system is impossible...

Neither Sympy, Giac, Fricas nor Mathematica seem to check the validity of the solution of this system ; it seems to be a general weakness of CASes, which do not check the conditions of existence of the expressions...

HTH,

more