Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Problems with code with symbolic variables.
2 ビュー (過去 30 日間)
古いコメントを表示
Hi guys, I have an issue with this code. The problem is that with k>3, the algorithm stops and does not work. I tried deleting the variables but does not work either. If someone knows how to work with symbolic variables we can talk via gmail or Telegram if you wish I will be really grateful for that.
function [S, Gnew,Enew] = BGroebner1(k)
M = 3*k + 1;
x = sym('x');
r = sym('r');
c = sym('c', [1 M+1]);
% Define the sum of monomials with negative coefficients
CC = x;
for i = 1:M+1
CC = CC + c(1,i)*x^(-i);
end
sM = expand(CC^(3));
for i = M:1:3*M+3
sM = subs(sM, x^(-i), r);
end
sMnew = sM;
sMnew = subs(sMnew,r,0);
sMnew1 = expand(x^(M-1)*sMnew);
C =coeffs(sMnew1,x);
E =sym('E',[1,M-1]);
for i= M-1:-1:1
E(1,M-i) = C(1,i);
end
% Calculate Groebner basis,
num_syms = M+1;
syms_cell = cell(1, num_syms);
for i = M+1:-1:1
syms_cell{i} = sym(['c', num2str(M+2-i)]);
end
c = [syms_cell{:}];
G = gbasis(E,c,"MonomialOrder",'Lexicographic');
J = (M+1)*M;
sM1 = expand(CC^{M});
sMnew2 = expand(x^(J)*sM1);
E2 = coeffs(sMnew2,x);
EM = E2(J);
EM1=E2(J-1);
F= sym('F');
Enew = [E,EM,EM1+F];
% Groebner basis with (E^M)_1, (E^M)_2 + F
Gnew = gbasis(Enew,[F c],"MonomialOrder",'Lexicographic');
%% Calculate the solutions of the E_{1}, E_{2},...
eqn =sym('eqn', [1 M-1]);
for i=1:1:M-1
eqn(i)= Enew(i)==0;
end
d = sym('c', [1 M+1]);
S = vpasolve(eqn,d);
end
0 件のコメント
回答 (1 件)
John D'Errico
2024 年 6 月 18 日
No. I won't consult by gmail, or whatever. But there is no need.
Even for k==2, what do I see?
eqn =
[3*c1^2 + 3*c3 == 0, 3*c4 + 6*c1*c2 == 0, c1^3 + 6*c3*c1 + 3*c2^2 + 3*c5 == 0, 3*c2*c1^2 + 6*c4*c1 + 3*c6 + 6*c2*c3 == 0, 3*c1^2*c3 + 3*c1*c2^2 + 6*c5*c1 + 6*c4*c2 + 3*c3^2 + 3*c7 == 0, 3*c4*c1^2 + 6*c3*c1*c2 + 6*c6*c1 + c2^3 + 6*c5*c2 + 3*c8 + 6*c3*c4 == 0]
A messy nonlinear polynomial system of equations. And even at that, the solver took some serious time to find a solution. (And that was only one solution. Note that for any such problem, there would almost always be multiple solutions available. vpasolve finds only ONE solution. And the solution it does find may not be one that makes you happy, even if you could indeed recognize what about such a solution is even good or bad.) For larger values of k, the system will become far more complex, with many thousands, even millions of terms generated internally in those equations.
Your computer is not infinitely powerful. Well it is not, unless you work in TV or in a movie, where computers can do anything within a tiny fraction of a second, and only a few clicks on the keyboard or even a spoken command.
Just because you can write code to do something, does not mean a solution can be found in a finite amount of time.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!