Symbolic solve throwing division by zero error
Afficher commentaires plus anciens
The following code periodically throws a division by zero error.
m = 4;
n = 4;
X = sym('X', [m n]);
A = randi([0 1],n,n^2);
B = randi([0 1],m,m^2);
E = X*A - B*kron(X,X);
S = solve(E == 0,X);
S

Is it because there are too many variables?
Is it trying to numerically get solutions and is dividing by small numbers?
The error message is an image because the error rarely happens and I could not get it to happen while writing up this question.
8 commentaires
Torsten
le 3 Mar 2023
Why do you use "solve" to get X ?
X is simply the zero matrix.
Walter Roberson
le 3 Mar 2023
You marked that you are using R2022b, but you can see from the above printout that the code does not give a problem in R2022b.
Joseph Daynger Ruiz
le 3 Mar 2023
Modifié(e) : Joseph Daynger Ruiz
le 3 Mar 2023
Walter Roberson
le 3 Mar 2023
64 equations in 16 unknowns. You are going to have a lot of difficulty finding the general solution.
Joseph Daynger Ruiz
le 3 Mar 2023
Modifié(e) : Joseph Daynger Ruiz
le 3 Mar 2023
I don't know why this problem occurs. Maybe it's in cases where only the zero solution for x exists.
X = sym('X', [4 4]);
Q = [[1,0,0,0,0,-1, 0,0,0,0,-1, 0,0, 0,0,-1];...
[0,1,0,0,1, 0, 0,0,0,0, 0,-1,0, 0,1, 0];...
[0,0,1,0,0, 0, 0,1,1,0, 0, 0,0,-1,0, 0];...
[0,0,0,1,0, 0,-1,0,0,1, 0, 0,1, 0,0, 0]];
E = X*Q - Q*kron(X,X);
E = E(:);
F = matlabFunction(E);
x = lsqnonlin(@(x)F(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16)),rand(16,1),[],[],optimset('TolFun',1e-12,'TolX',1e-12))
F(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16))
Joseph Daynger Ruiz
le 3 Mar 2023
Modifié(e) : Joseph Daynger Ruiz
le 3 Mar 2023
Joseph Daynger Ruiz
le 3 Mar 2023
Modifié(e) : Joseph Daynger Ruiz
le 3 Mar 2023
Réponses (1)
Muskan
le 21 Avr 2023
0 votes
Hi Joseph,
I tried running your code in R2022b and it does not seem to give any error for that.
Thanks
1 commentaire
Joseph Daynger Ruiz
le 21 Avr 2023
Modifié(e) : Joseph Daynger Ruiz
le 21 Avr 2023
Catégories
En savoir plus sur Polynomials dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
