# Solving a system of weird equations

I'm trying to have Mathematica solve a system of equations for a friend's work in Computer Vision. I'm essentially going in blind to this and am not very familiar with Mathematica syntax, so would anybody be able to tell me what I could be doing incorrectly? I'd like to solve for the variables a and b in terms of all of the other stuff that's there.

Code:

c1 = c == a* s + 2*k*a*b + l*(r^2 + 2 a^2);
c2 = d == b* s + k*(r^2 + 2 b^2) + 2*l*a*b;
s  = ((1 + m*r^2 + f*r^4 + g*r^6)/(1 + h*r^2 + n*r^4 + j*r^6));
r  = Sqrt[ a^2 + b^2];
Solve[{c1, c2}, {a, b}]


Any idea as to what's going on? Thanks in advance for anybody's help.

• Please write down the equations as code no as an image Commented Jul 2, 2015 at 18:42
• Sorry, I attached the code.
– Luc
Commented Jul 2, 2015 at 18:51
• When you put in kab and lab, do you mean k*a*b and l*a*b? If so, you need to insert asterisks or spaces between them. Commented Jul 2, 2015 at 19:34
• r^2 = a^2 + b^2 must be r^2 == a^2 + b^2 Commented Jul 2, 2015 at 19:39
• Sorry, I mistyped again in my code. I have r^2 as == a^2 + b^2. I also added multiplication signs everywhere and it still tells me that it's not a qauantified system of equations and inequalities
– Luc
Commented Jul 2, 2015 at 21:07

Your definition of c and d are not related to any other variables, so the system is fundamentally underdetermined as you have written it. It is as if you wrote $$c = a + x, \quad d = b + y, \quad r^2 = a^2 + b^2,$$ and you want to solve for $a,b$.

Moreover, you have a syntax error, which is why Mathematica will not complete the evaluation. The == symbol is not the same as the assignment operator =. You can do something like this:

 c = a x + b y;
d = a x^2 + b y^2;
Solve[{c == d, x + y == 5}, {a, b, x, y}]


and you can see that the = assigns the expression a x + b y to c, and will do the substitution in all subsequent inputs, but the == symbol represents the function Equal[]; that is to say, c == d returns True if c equals d, and False otherwise.

• Thanks, that's what I suspected! I appreciate your clarification.
– Luc
Commented Jul 3, 2015 at 5:01

Some additional progress can be made to Solve these equations. Begin with the first three lines from the Question.

s = ((1 + m*r^2 + f*r^4 + g*r^6)/(1 + h*r^2 + n*r^4 + j*r^6));
c1 = c == a*s + 2*k*a*b + l*(r^2 + 2 a^2);
c2 = d == b*s + k*(r^2 + 2 b^2) + 2*l*a*b;


and Simplify them a bit with

{c1, c2} /. Equal[z1_, z2_] :> Equal[Collect[(z2 - z1) // Together // Numerator //
Simplify, 1 + h r^2 + n r^4 + j r^6, Simplify], 0]

(* {a (1 + m r^2 + f r^4 + g r^6) + (-c + 2 a b k + 2 a^2 l + l r^2) (1 +
h r^2 + n r^4 + j r^6) == 0,
b (1 + m r^2 + f r^4 + g r^6) + (-d + 2 b^2 k + 2 a b l + k r^2) (1 +
h r^2 + n r^4 + j r^6) == 0} *)


Next, eliminate r (but not with Eliminate, which yields very complicated expressions in this case).

eqs = % /. r^z_ :> (a^2 + b^2)^(z/2)

(* {a (1 + (a^2 + b^2)^2 f + (a^2 + b^2)^3 g + (a^2 + b^2) m) + (-c + 2 a b k +
2 a^2 l + (a^2 + b^2) l) (1 + (a^2 + b^2) h + (a^2 +
b^2)^3 j + (a^2 + b^2)^2 n) == 0,
b (1 + (a^2 + b^2)^2 f + (a^2 + b^2)^3 g + (a^2 + b^2) m) + (-d + 2 b^2 k +
(a^2 + b^2) k + 2 a b l) (1 + (a^2 + b^2) h + (a^2 +
b^2)^3 j + (a^2 + b^2)^2 n) == 0} *)


At this point, I tried

Solve[eqs, {a, b}]


to solve this 14th order system but terminated it after two hours. I next tried a simpler, 6th order problem,

Solve[eqs/. {g -> 0, j -> 0, f -> 0, n -> 0}, {a, b}]


which after 50 minutes produced a lengthy solution, one twelfth of which is

(*  a -> Root[9 c^4 h^2 k^2 - 6 c^3 d h^2 k l + 18 c^3 h k^2 l +
c^2 d^2 h^2 l^2 - 12 c^2 d h k l^2 + 9 c^2 k^2 l^2 - c l^3 +
2 c d^2 h l^3 - 6 c d k l^3 + d^2 l^4 - 2 c^2 l^2 m -
c^3 l m^2 + (-9 c^3 h^2 k^2 + 6 c^2 d h^2 k l - 27 c^2 h k^2 l -
c d^2 h^2 l^2 + 22 c d h k l^2 - 12 c k^2 l^2 + l^3 -
4 c^2 h l^3 - 3 d^2 h l^3 + 8 d k l^3 - 4 c l^4 -
3 c^3 h k^2 m + 2 c^2 d h k l m + 3 c^2 k^2 l m + 2 c l^2 m -
4 c^3 h l^2 m + c d^2 h l^2 m - 6 c d k l^2 m - 4 c^2 l^3 m +
3 d^2 l^3 m + c^2 l m^2) #1 + (9 c^4 h^3 k^2 +
9 c^2 d^2 h^3 k^2 + 6 c^2 d h^2 k^3 + 9 c^2 h k^4 -
6 c^3 d h^3 k l - 6 c d^3 h^3 k l + 9 c h k^2 l -
18 c^3 h^2 k^2 l - 12 c d^2 h^2 k^2 l - 30 c d h k^3 l +
c^2 d^2 h^3 l^2 + d^4 h^3 l^2 - 10 d h k l^2 +
8 c^2 d h^2 k l^2 + 2 d^3 h^2 k l^2 + 3 k^2 l^2 -
63 c^2 h k^2 l^2 + d^2 h k^2 l^2 - 12 d k^3 l^2 + 3 c h l^3 -
4 c^3 h^2 l^3 + 2 c d^2 h^2 l^3 + 34 c d h k l^3 -
36 c k^2 l^3 + 7 l^4 - 8 c^2 h l^4 + d^2 h l^4 + 20 d k l^4 -
4 c l^5 + 3 c^2 h k^2 m - 2 c d h k l m - 4 c k^2 l m +
2 c^2 h l^2 m - 3 d^2 h l^2 m + 10 d k l^2 m + 10 c l^3 m -
c^3 h l m^2 - c d^2 h l m^2 + 3 c^2 l^2 m^2 +
3 d^2 l^2 m^2) #1^2 + (-24 c d h^2 k^3 - 12 c h k^4 +
24 d^2 h^2 k^2 l + 12 d h k^3 l + 8 c d h^2 k l^2 +
36 c h k^2 l^2 - 8 d^2 h^2 l^3 - 20 d h k l^3 + 16 k^2 l^3 +
16 c h l^4 + 16 l^5 - 12 c^3 h^2 k^2 m - 12 c d^2 h^2 k^2 m +
8 c^2 d h^2 k l m + 8 d^3 h^2 k l m + k^2 l m -
8 c^2 h k^2 l m - 8 d^2 h k^2 l m - 4 d k^3 l m -
4 c^3 h^2 l^2 m - 4 c d^2 h^2 l^2 m - 20 c k^2 l^2 m + l^3 m +
8 c^2 h l^3 m + 8 d^2 h l^3 m + 28 d k l^3 m + 12 c l^4 m +
2 d k l m^2 + 2 c l^2 m^2 + c^2 l m^3 +
d^2 l m^3) #1^3 + (-12 c^2 d h^3 k^3 - 12 d^3 h^3 k^3 +
3 h k^4 + 12 c^2 h^2 k^4 - 24 d^2 h^2 k^4 - 12 d h k^5 -
36 c^3 h^3 k^2 l - 36 c d^2 h^3 k^2 l - 96 c d h^2 k^3 l -
12 c h k^4 l + 20 c^2 d h^3 k l^2 + 20 d^3 h^3 k l^2 +
6 h k^2 l^2 - 48 c^2 h^2 k^2 l^2 + 40 d^2 h^2 k^2 l^2 +
8 d h k^3 l^2 + 12 k^4 l^2 - 4 c^3 h^3 l^3 - 4 c d^2 h^3 l^3 +
32 c d h^2 k l^3 + 8 c h k^2 l^3 + 3 h l^4 + 4 c^2 h^2 l^4 +
20 d h k l^4 + 24 k^2 l^4 + 20 c h l^5 + 12 l^6 +
6 d h k^3 m + 10 c h k^2 l m + 6 d h k l^2 m + 4 k^2 l^2 m +
10 c h l^3 m + 4 l^4 m + 3 c^2 h k^2 m^2 + 3 d^2 h k^2 m^2 -
4 c k^2 l m^2 + 7 c^2 h l^2 m^2 + 7 d^2 h l^2 m^2 +
8 d k l^2 m^2 + 4 c l^3 m^2) #1^4 + (12 c h^2 k^4 +
12 h k^4 l + 24 c h^2 k^2 l^2 + 24 h k^2 l^3 + 12 c h^2 l^4 +
12 h l^5 - 12 c h k^4 m + 16 c^2 h^2 k^2 l m +
16 d^2 h^2 k^2 l m + 32 d h k^3 l m + 4 k^4 l m +
8 c h k^2 l^2 m + 16 c^2 h^2 l^3 m + 16 d^2 h^2 l^3 m +
32 d h k l^3 m + 8 k^2 l^3 m + 20 c h l^4 m +
4 l^5 m) #1^5 + (12 c^2 h^3 k^4 + 12 d^2 h^3 k^4 +
24 d h^2 k^5 + 12 h k^6 + 24 c h^2 k^4 l +
24 c^2 h^3 k^2 l^2 + 24 d^2 h^3 k^2 l^2 + 48 d h^2 k^3 l^2 +
36 h k^4 l^2 + 48 c h^2 k^2 l^3 + 12 c^2 h^3 l^4 +
12 d^2 h^3 l^4 + 24 d h^2 k l^4 + 36 h k^2 l^4 +
24 c h^2 l^5 + 12 h l^6) #1^6 &, 1] *)


with a LeafCount of 1756. Note that the corresponding solution for b can be obtained by interchanging c with d, and k with l. Unless this symmetry can be utilized in some way to further simply the problem, it seems unlikely that Solve is a practical approach.