Symbolic solve throwing division by zero error
이전 댓글 표시
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
Torsten
2023년 3월 3일
Why do you use "solve" to get X ?
X is simply the zero matrix.
Walter Roberson
2023년 3월 3일
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
2023년 3월 3일
편집: Joseph Daynger Ruiz
2023년 3월 3일
Walter Roberson
2023년 3월 3일
64 equations in 16 unknowns. You are going to have a lot of difficulty finding the general solution.
Joseph Daynger Ruiz
2023년 3월 3일
편집: Joseph Daynger Ruiz
2023년 3월 3일
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
2023년 3월 3일
편집: Joseph Daynger Ruiz
2023년 3월 3일
Joseph Daynger Ruiz
2023년 3월 3일
편집: Joseph Daynger Ruiz
2023년 3월 3일
답변 (1개)
Muskan
2023년 4월 21일
0 개 추천
Hi Joseph,
I tried running your code in R2022b and it does not seem to give any error for that.
Thanks
댓글 수: 1
Joseph Daynger Ruiz
2023년 4월 21일
편집: Joseph Daynger Ruiz
2023년 4월 21일
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
