my code does not have an answer
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2024 年 12 月 31 日
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
2025 年 1 月 1 日
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.
回答 (2 件)
Manikanta Aditya
2024 年 12 月 31 日
編集済み: Manikanta Aditya
2024 年 12 月 31 日
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 件のコメント
John D'Errico
2025 年 1 月 1 日
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.
John D'Errico
2025 年 1 月 1 日
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 件のコメント
Alex Sha
2025 年 1 月 4 日
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
参考
カテゴリ
Help Center および File Exchange で Equation Solving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!