System of Nonlinear Equations exceeds function evaluation limit
2 ビュー (過去 30 日間)
古いコメントを表示
Attempting to solve a system of three nonlinear equaitons
g = 9.81;
Az_mech = 0.028*g;
Az_dyn = 0.5*g;
Ax_mech = 0.092*g;
Ax_dyn = 2*g;
m=4;
mu = 0.2;
f = @(x) [70*(-m*g+m*(Az_mech+Az_dyn))+55*m*(Ax_mech+Ax_dyn)+140*(x(2)*cos(x(3))+mu*x(2)*sin(x(3)));
-mu*x(1)*cos(x(3))+x(1)*sin(x(3))+m*(Ax_mech+Ax_dyn)-x(2)*sin(x(3))+mu*x(2)*cos(x(3));
x(1)*cos(x(3))+mu*x(1)*sin(x(3))+x(2)*cos(x(3))+mu*x(2)*sin(x(3))+m*(Az_mech+Az_dyn)-m*g];
options = optimoptions(@fsolve, 'MaxFunctionEvaluations', 10000, 'MaxIterations', 10000);
x1 = fsolve(f, [10 10 0])
f(x1)
x2 = fsolve(f, [5 5 0])
f(x2)
x3 = fsolve(f, [0 0 0])
f(x3)
The outputs are:
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 300 (the default value).
x1 =
9.9967 19.7237 -3.0559
ans =
420.0052
80.9845
-48.6414
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 300 (the default value).
x2 =
4.9978 17.7964 -2.8936
ans =
680.8757
82.7503
-41.7372
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 300 (the default value).
x3 =
0.0024 -17.9956 0.3792
ans =
691.5529
85.4092
-36.5683
I try a few different starting points and each gives different solutions. When I try to input the solution into the original function, the result is not zero, as I would expect for a correct solution.
There is no noticable different in runtime, even if i increase the max iterations and evaluations to 1000000 from 300.
0 件のコメント
採用された回答
Star Strider
2022 年 10 月 5 日
You need to tell fsolve that the options sturcture exists —
g = 9.81;
Az_mech = 0.028*g;
Az_dyn = 0.5*g;
Ax_mech = 0.092*g;
Ax_dyn = 2*g;
m=4;
mu = 0.2;
f = @(x) [70*(-m*g+m*(Az_mech+Az_dyn))+55*m*(Ax_mech+Ax_dyn)+140*(x(2)*cos(x(3))+mu*x(2)*sin(x(3)));
-mu*x(1)*cos(x(3))+x(1)*sin(x(3))+m*(Ax_mech+Ax_dyn)-x(2)*sin(x(3))+mu*x(2)*cos(x(3));
x(1)*cos(x(3))+mu*x(1)*sin(x(3))+x(2)*cos(x(3))+mu*x(2)*sin(x(3))+m*(Az_mech+Az_dyn)-m*g];
options = optimoptions(@fsolve, 'MaxFunctionEvaluations', 10000, 'MaxIterations', 10000);
x1 = fsolve(f, [10 10 0],options)
f(x1)
x2 = fsolve(f, [5 5 0],options)
f(x2)
x3 = fsolve(f, [0 0 0],options)
f(x3)
There are likely myriad (fi not an infinity) of solutions because one of the parameters (‘x(3)’) is an arguments to trigonometric funcitons.
.
2 件のコメント
Star Strider
2022 年 10 月 5 日
As always, my pleasure!
The fsolve function does not allow constraints. The fsolve funciton is a root-finder, however if the minima are at the zero-crossings, fmincon could be an option —
g = 9.81;
Az_mech = 0.028*g;
Az_dyn = 0.5*g;
Ax_mech = 0.092*g;
Ax_dyn = 2*g;
m=4;
mu = 0.2;
f = @(x) [70*(-m*g+m*(Az_mech+Az_dyn))+55*m*(Ax_mech+Ax_dyn)+140*(x(2)*cos(x(3))+mu*x(2)*sin(x(3)));
-mu*x(1)*cos(x(3))+x(1)*sin(x(3))+m*(Ax_mech+Ax_dyn)-x(2)*sin(x(3))+mu*x(2)*cos(x(3));
x(1)*cos(x(3))+mu*x(1)*sin(x(3))+x(2)*cos(x(3))+mu*x(2)*sin(x(3))+m*(Az_mech+Az_dyn)-m*g];
options = optimoptions(@fmincon, 'MaxFunctionEvaluations', 10000, 'MaxIterations', 10000);
format long
x1 = fmincon(@(x)norm(f(x)), [10 10 0],[],[],[],[],zeros(1,3),[],[],options)
f(x1)
x2 = fmincon(@(x)norm(f(x)), [5 5 0],[],[],[],[],zeros(1,3),[],[],options)
f(x2)
x3 = fmincon(@(x)norm(f(x)), [0 0 0],[],[],[],[],zeros(1,3),[],[],options)
f(x3)
These results do not appear to be the function roots.
I believe this is the only constrained optimisation function available in the Optimization Toolbox. (Other functions exist in the Global Optimization Toolbox. They are optimisers, not root-finders, so are likely to produce the same results.)
.
その他の回答 (1 件)
Torsten
2022 年 10 月 5 日
編集済み: Torsten
2022 年 10 月 5 日
Substitute
a = x(2)*cos(x(3)), b = x(2)*sin(x(3)), c= x(1)*cos(x(3)), d=x(1)*sin(x(3))
in your equations.
You get an underdetermined linear system of equations.
The general solution is
v = lambda*n + sol
with a parameter lambda, n the nullspace of the system matrix and sol a special solution.
Incorporating the condition b/a = d/c gives
lambda = vpasolve(v(2)/v(1)-v(4)/v(3)==0);
Now
x3 = atan(v(2)/v(1))
x2 = v(1)/cos(x3)
x1 = v(3)/cos(x3)
follow.
The calculation of x3 gives you degrees of freedom for the solution because x3 + n*pi will also satisfy the equation. But it turns out that - although there are infinitely many solutions - none of them satisfies that x1, x2 and x3 are simultaneously positive.
Code is as follows:
g = 9.81;
Az_mech = 0.028*g;
Az_dyn = 0.5*g;
Ax_mech = 0.092*g;
Ax_dyn = 2*g;
m=4;
mu = 0.2;
M = [140 140*mu 0 0; mu -1 -mu 1; 1 mu 1 mu];
n = null(M)
rhs = [-55*m*(Ax_mech+Ax_dyn)-70*(-m*g+m*(Az_mech+Az_dyn));-m*(Ax_mech+Ax_dyn);-m*(Az_mech+Az_dyn)+m*g];
sol = M\rhs;
syms lambda
v = lambda*n + sol;
s = vpasolve(v(2)/v(1)-v(4)/v(3)==0);
v = double(subs(v,lambda,s));
x3 = atan(v(2)/v(1))
x3s = atan(v(4)/v(3))
x1 = v(4)/sin(x3)
x1s = v(3)/cos(x3)
x2 = v(1)/cos(x3)
x2s = v(2)/sin(x3)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Systems of Nonlinear Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!