my code does not have an answer
Ältere Kommentare anzeigen
syms a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
k1=-184.4;
k2=-207.5;
k3=-212.07;
k4=-69.8;
k5=-186.9;
k6=-367.5;
eq1=a1+a4-1;
eq2=2*a2+a5+2*a8-4;
eq3=2*a3+a6+a10-18.8;
eq4=a8^2*a7-k1*a2^2*a11;
eq5=2*a1+a2+a4+a5+a6+2*a7+a9-5;
eq6=a4^2*a7-k2*a1^2*a11;
eq7=a8*a5^2-k3*a2^2*a11;
eq8=a6^2-k4*a3*a7;
eq9=a9^2-k5*a7*a11;
eq10=a10^2-k6*a3*a11;
eq11=a1+a2+a3+a4+a5+a6+a7+a8+a9+a10-a11;
s=solve(eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11)
disp eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11
3 Kommentare
Matt J
am 31 Dez. 2024
A symbolic solution to general multi-variate quadratic equations doesn't exist. You will have to accept a numerical solution.
Walter Roberson
am 31 Dez. 2024
s=solve([eq1,eq2,eq3,eq4,eq5,eq6], [a1, a2, a10, a11, a4,a5,a6],'MaxDegree',4)
takes a bit of time but eventually calculates 8 solutions, each of which is very long.
Going much beyond that to additional equations and variables is computationally not very feasible.
Walter Roberson
am 1 Jan. 2025
Trying
s=solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7], [a1, a2, a10, a11, a4,a5,a6,a7],'MaxDegree',4)
eventually told me no solutions found.
Antworten (2)
Manikanta Aditya
am 31 Dez. 2024
Bearbeitet: Manikanta Aditya
am 31 Dez. 2024
The reason why you did not see any output for the above code as it sounds like the system of equations is quite complex, leading to long computation times.
I have modified the code as below, this gives output and as expected.
% Define the equations as a function
function F = myEquations(x)
k1 = -184.4;
k2 = -207.5;
k3 = -212.07;
k4 = -69.8;
k5 = -186.9;
k6 = -367.5;
F(1) = x(1) + x(4) - 1;
F(2) = 2*x(2) + x(5) + 2*x(8) - 4;
F(3) = 2*x(3) + x(6) + x(10) - 18.8;
F(4) = x(8)^2 * x(7) - k1 * x(2)^2 * x(11);
F(5) = 2*x(1) + x(2) + x(4) + x(5) + x(6) + 2*x(7) + x(9) - 5;
F(6) = x(4)^2 * x(7) - k2 * x(1)^2 * x(11);
F(7) = x(8) * x(5)^2 - k3 * x(2)^2 * x(11);
F(8) = x(6)^2 - k4 * x(3) * x(7);
F(9) = x(9)^2 - k5 * x(7) * x(11);
F(10) = x(10)^2 - k6 * x(3) * x(11);
F(11) = x(1) + x(2) + x(3) + x(4) + x(5) + x(6) + x(7) + x(8) + x(9) + x(10) - x(11);
end
% Initial guesses
initial_guesses = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
% Solve the system of equations
options = optimoptions('fsolve', 'Display', 'iter', 'MaxIterations', 1000);
[x, fval, exitflag] = fsolve(@myEquations, initial_guesses, options);
% Display the solutions
disp('Solutions:');
disp(x);
- The equations are defined in a function myEquations.
- Provided initial guesses to help the solver.
- Used fsolve to solve the system numerically.
These are steps, I took to solve the equations. I hope this helps you.
3 Kommentare
John D'Errico
am 31 Dez. 2024
Bearbeitet: John D'Errico
am 31 Dez. 2024
More than just quite complex, it is highly likely that no algebraic solution exists for that system.
If you start with any system of quadratics (or any system of nonlinear polynomial equations), then start to eliminate variables as if you were doing Gaussian elimination, you will find the order of the equations that remain increases in degree. This is ok, in a sense, but when the system has too many equations, the equations grow to an effective degree higher than 4. As soon as that happens, you now fall into the Abel-Ruffini trap, that a general polynomial equation of degree greater than 4 has no algebraic solutions.
The problem is, solve does not see that happening. It keeps on trying to eliminate variables, hoping (to the extent that a computer code can hope) that a solution will drop out. And those equations get more and more nasty.
As a net of course, there is no alternative to the use of a numerical tool, like fsolve, or vpasolve. However, it looks like vpasolve will be far slower to converge on this problem than will fsolve. I tried it, and it is still running 20 minutes or so later on my machine.
Manikanta Aditya
am 1 Jan. 2025
Yeah, I agree.
However, I notice that fsolve did not actually converge to a solution from that start point. There is no assurance a solution exists at all to any completely general system.
And that means you NEED to test what comes out.
function F = myEquations(x)
k1 = -184.4;
k2 = -207.5;
k3 = -212.07;
k4 = -69.8;
k5 = -186.9;
k6 = -367.5;
F(1) = x(1) + x(4) - 1;
F(2) = 2*x(2) + x(5) + 2*x(8) - 4;
F(3) = 2*x(3) + x(6) + x(10) - 18.8;
F(4) = x(8)^2 * x(7) - k1 * x(2)^2 * x(11);
F(5) = 2*x(1) + x(2) + x(4) + x(5) + x(6) + 2*x(7) + x(9) - 5;
F(6) = x(4)^2 * x(7) - k2 * x(1)^2 * x(11);
F(7) = x(8) * x(5)^2 - k3 * x(2)^2 * x(11);
F(8) = x(6)^2 - k4 * x(3) * x(7);
F(9) = x(9)^2 - k5 * x(7) * x(11);
F(10) = x(10)^2 - k6 * x(3) * x(11);
F(11) = x(1) + x(2) + x(3) + x(4) + x(5) + x(6) + x(7) + x(8) + x(9) + x(10) - x(11);
end
% Initial guesses
initial_guesses = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
% look at the objective function at the start point.
myEquations(initial_guesses)
% Solve the system of equations
options = optimoptions('fsolve', 'Display', 'iter', 'MaxIterations', 1000);
[x, fval, exitflag] = fsolve(@myEquations, initial_guesses, options);
fval
As you can see, while fsolve did manage to reduce the elements of the objective towards zero, it did not even come close to converging, stopping due to a limit on the number of iterations.
In fact, I tried it again, but now pushing the limits a bit wider, and it still fails to converge.
options = optimoptions('fsolve', 'Display', 'final', 'MaxIterations', 100000,'MaxFunction',100000);
[x, fval, exitflag] = fsolve(@myEquations, initial_guesses, options);
fval
Again, fsolve is not converging.
ALWAYS TEST a result. Did it converge? In this case, it appears there may well be no solution at all.
The failure of both vpasolve and fsolve suggests it is lkely no solutions exist at all for your problem. But merely the failure of those two codes is not conclusive. So I'll throw GA at it, to see if it can do any better.. A problem is, I don't know how far out the code must search. What are reasonable bounds?
function F = myEquations(x)
k1 = -184.4;
k2 = -207.5;
k3 = -212.07;
k4 = -69.8;
k5 = -186.9;
k6 = -367.5;
F(1) = x(1) + x(4) - 1;
F(2) = 2*x(2) + x(5) + 2*x(8) - 4;
F(3) = 2*x(3) + x(6) + x(10) - 18.8;
F(4) = x(8)^2 * x(7) - k1 * x(2)^2 * x(11);
F(5) = 2*x(1) + x(2) + x(4) + x(5) + x(6) + 2*x(7) + x(9) - 5;
F(6) = x(4)^2 * x(7) - k2 * x(1)^2 * x(11);
F(7) = x(8) * x(5)^2 - k3 * x(2)^2 * x(11);
F(8) = x(6)^2 - k4 * x(3) * x(7);
F(9) = x(9)^2 - k5 * x(7) * x(11);
F(10) = x(10)^2 - k6 * x(3) * x(11);
F(11) = x(1) + x(2) + x(3) + x(4) + x(5) + x(6) + x(7) + x(8) + x(9) + x(10) - x(11);
end
obj = @(x) norm(myEquations(x));
lb = repmat(-200,[1,11]);
ub = repmat(200,[1,11]);
options = optimoptions('ga', 'Display', 'final', 'MaxGenerations', 100000);
[xfinal,fval,exitflag] = ga(obj,11,[],[],[],[],lb,ub,[],options)
myEquations(xfinal)
As you can see, the best solution it was able to find is, while considerably better than what fsolve could find, does not in fact even come close to a solution for your problem.
As has been sugggested, there is likely no solution at all to this system of polynomial equations. Of course, it is possible that my bounds were too tight. that seems to be unlikely, since none of the unknowns come even close to the bounds I posed.
1 Kommentar
Alex Sha
am 4 Jan. 2025
there is actually a stable solution, absolutely:
a1: 14.3999986585031
a2: 14.4000005201237
a3: 9.39999825064551
a4: -13.3999986585031
a5: -24.8000010402474
a6: 3.09085138251274E-6
a7: -1.40808571949123E-14
a8: -2.35734583921126E-15
a9: -1.22923077450232E-6
a10: 4.07857597673348E-7
a11: 3.28647435957887E-17
fval:
0
-4.88498130835069E-15
0
1.25665533876502E-12
-2.04281036531029E-14
-1.11428057950672E-12
-4.64031866173406E-15
3.14631965397327E-13
1.51100829698357E-12
1.87200495910687E-13
-1.93982956360012E-15
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!