-1

I'm trying to solve a 16 variable linear equation. I tried in Matlab but it says that the solution could not be found. Is there an efficient way to solve the equations.

The equations are

a = a^2+e^2+i^2+m^2,
b = a*b+e*f+I*j+m*n,
c = a*c+e*g+I*k+m*o,
d = a*d+e*h+I*l+m*p,
e = a*b+e*f+I*j+m*n,
f = b^2+f^2+j^2+n^2,
g = b*c+f*g+j*k+n*o,
h = b*d+f*h+j*i+n*p,
i = c*a+g*e+I*k+o*m,
j = c*b+g*f+k*j+o*n,
k = c^2+g^2+k^2+o^2,
l = c*d+g*h+k*l+o*p,
m = d*a+h*e+i*l+p*m,
n = d*b+h*f+l*j+p*n,
o = d*c+h*g+l*k+p*o,
p = d^2+h^2+l^2+p^2

in MATLAB I Tried in the way I mentioned below,

>> syms a b c d e f g h i j k l m n o p
>> e1 = a^2+e^2+i^2+m^2 == a;
>> e2 = a*b+e*f+i*j+m*n == b;
>> e3 = a*c+e*g+i*k+m*o == c;
>> e4 = a*d+e*h+i*l+m*p == d;
>> e5 = a*b+e*f+i*j+m*n == e;
>> e6 = b^2+f^2+j^2+n^2 == f;
>> e7 = b*c+f*g+j*k+n*o == g;
>> e8 = b*d+f*h+j*i+n*p == h;
>> e9 = c*a+g*e+k*i+o*m == i;
>> e10 = c*b+g*f+k*j+o*n == j;
>> e11 = c^2+g^2+k^2+o^2 == k;
>> e12 = c*d+g*h+k*l+o*p == l;
>> e13 = d*a+h*e+l*i+p*m == m;
>> e14 = d*b+h*f+l*j+p*n == n;
>> e15 = d*c+h*g+l*k+p*o == o;
>> e16 = d^2+h^2+l^2+p^2 == p;
>> sol = solve([e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16],[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p]);

Warning: Unable to find an explicit solution. For options, see the help.

In sym/solve (line 317)

Geno C
  • 1,401
  • 3
  • 11
  • 26
Monica
  • 101
  • 2
  • Welcome to Stack Overflow. Please take the [tour] and read about what's on-topic in the [help/on-topic]. Are you using MATLAB or Python? You've tagged both languages here, but your question has nothing to do with Python (nor does it have anything to do with Wolfram Alpha, which you have also tagged). – ChrisGPT was on strike Jul 13 '20 at 19:14
  • 1
    That is not a linear system of equations. It contains squares and multiplications. – Cris Luengo Jul 13 '20 at 20:03
  • 1
    You can write some simple code to numerically solve this system yourself using `fminsearch`. By reframing `a = a^2+e^2+i^2+m^2` as `e1 = (a - a^2+e^2+i^2+m^2)^2` you can minimize the sum of e1, e2, etc... to find an approximate solution. – elliptic_hyperboloid Jul 13 '20 at 20:15

2 Answers2

1

You can try making a matrix equation where M x v = ans gives you the system of equations. v = [a,b,c,d....n,p] and M would look like

enter image description here

You can enter them as a numpy array and then:

numpy.linalg.solve(M, ans)

Be careful because not all system of equations are solvable because the matrix M is not always inherently solvable ie. not every matrix can be made into an identity matrix.

nav610
  • 781
  • 3
  • 8
0

All variables having a value of 0 is one solution

All variables having a value of 1/4 is another solution.

For other solutions try NMinimize.

NMinimize[
  (a-(a^2+e^2+i^2+m^2))^2+(b-(a*b+e*f+i*j+m*n))^2+(c-(a*c+e*g+i*k+m*o))^2+(d-(a*d+e*h+i*l+m*p))^2+
  (e-(a*b+e*f+i*j+m*n))^2+(f-(b^2+f^2+j^2+n^2))^2+(g-(b*c+f*g+j*k+n*o))^2+(h-(b*d+f*h+j*i+n*p))^2+
  (i-(c*a+g*e+i*k+o*m))^2+(j-(c*b+g*f+k*j+o*n))^2+(k-(c^2+g^2+k^2+o^2))^2+(l-(c*d+g*h+k*l+o*p))^2+
  (m-(d*a+h*e+i*l+p*m))^2+(n-(d*b+h*f+l*j+p*n))^2+(o-(d*c+h*g+l*k+p*o))^2+(p-(d^2+h^2+l^2+p^2))^2,
  {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}]

and in an instant it returns one solution:

{8.51161*^-15,{
  a->0.345102,b->0.0918863,c->-0.435568,d->0.166866,
  e->0.0918863,f->0.961563,g->-5.19543*^-7,h->-0.168869,
  i->-0.435567,j->-4.85207*^-7,k->0.564101,l->-0.237006,
  m->0.166866,n->-0.168869,o->-0.237006,p->0.129235}}

With the option Method->"RandomSearch" it returns a completely different solution.

Bill
  • 3,664
  • 1
  • 12
  • 9