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!
