Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Okay. On your head be it...

var("alpha, z")
F = vector([cos(alpha),sin(alpha),z])
G = vector([z,cos(alpha),sin(alpha)])
A = vector([0,0,0])
## Replace u==v by u-v (implicitlt ==0).
L=list(F-G-A)

The system is redundant: the second equation is the sum of the first and the third, or, more swiftly,

sage: L
[-z + cos(alpha), -cos(alpha) + sin(alpha), z - sin(alpha)]
sum(L)
0

sympy offers some solutions:

sage: SS=solve(L,[z, alpha], algorithm="sympy"); SS
[{alpha: -3/4*pi, z: -1/2*sqrt(2)}, {alpha: 1/4*pi, z: 1/2*sqrt(2)}]

Easy check:

sage: [[e.subs(s) for e in L] for s in SS]
[[0, 0, 0], [0, 0, 0]]

But, are these solutions THE solution ?

Since the system is redundant, Sage's default solver (i. e. Maxima's) will choke (check it yourself). So let's try solve the second equation first:

sage: S1=L[1].solve(alpha); S1
[sin(alpha) == cos(alpha)]

Really ? One can do better (see the docs...)

sage: S1=L[1].solve(alpha, to_poly_solve=True); S1
[alpha == 1/4*pi + pi*z1]

Aha ! We have an infinity of solutions for alpha. What does it gives us for z ?

## Declare z1 as an integer (neither Sage nor Maxima will do that for you : minor pain in the a$$..)
sage: var("z1", domain="integer")
z1
## Solve the first equation for `z`
sage: S0 = L[0].subs(S1).solve(z) ; S0
[z == 1/2*sqrt(2)*(-1)^z1]

We have two possible solutions for z. Check that this gives us valid solutions for the third equation:

sage: L[2].subs(S1).subs(S0)
1/2*sqrt(2)*(-1)^z1 - sin(1/4*pi + pi*z1)

Huh ? Here, it pays to have declared z1 as integer:

sage: L[2].subs(S1).subs(S0).simplify_trig()
0

Left to the reader as an exercise: alpha and z are bound by z1. Tabulate the results...

More advanced (requires a bit of familiarity with Sage's and Python's modules) : take a result given by Maxima's solver, and retrieve and declare (correctly) the variables created by the solver (useful also for the differential equations solve, etc...)

Brief conclusion of this short story : using a computer to compute solutions does not relieve you of the obligation to think about your problem and its solutions.

HTH,