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.
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))
回答(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 个评论
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
