With two different initial values I am getting two different answers in fsolve. How to decide which one is more reliable?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vikash Sahu
am 10 Feb. 2022
Kommentiert: Vikash Sahu
am 10 Feb. 2022
function F = FeMnC300newuipf3variable(x)
F(1) =10.3014287+log(x(3))+3.37E+04*x(3)+(-3.37E+04*x(3)^2)/2-19.1333*0.03592*x(3)- log(x(1)) -21.4105*x(1)+10.41166*x(2)+(21.4105*x(1)^2)/2-10.41166*x(1)*x(2)+(1.99159*x(2)^2)/2;
F(2) =-0.269548173-log(x(2))+19.1333*x(3) +(-3.37E+04*x(3)^2)/2-19.1333*0.03592*x(3)+10.41166*x(1)-1.99159*x(2)+(21.4105*x(1)^2)/2-10.41166*x(1)*x(2)+(1.99159*x(2)^2)/2;
F(3) =-0.643539436+log(1-0.03592-x(3))-log(1-x(2)-x(1))+(-3.37E+04*x(3)^2)/2-19.1333*0.03592*x(3)+(21.4105*x(1)^2)/2-10.41166*x(1)*x(2)+(1.99159*x(2)^2)/2;
end
First initial value- x0 = [0.002 0.4 0.000000001]
Second initial value- x0 = [0.01 0.4 0.000000001]
2 Kommentare
Alex Sha
am 10 Feb. 2022
There is one solution only?
x1 0.00215170099218674
x2 0.406209428191469
x3 9.4346283948294E-10
Akzeptierte Antwort
John D'Errico
am 10 Feb. 2022
Bearbeitet: John D'Errico
am 10 Feb. 2022
When you have different variables with such a large discrepancy in magnitude, the problem is not which solution is more correct, but in how we can improve the solver's efficacy on such a problem.
The trick is to transform the problem so that all variables will be of a similar magnitude. That is, if you think x(3) will be 8 orders of magnitude smaller then the other variables, then scale x(3). I might change do the effective substitution:
u(1) = x(1)
u(2) = x(2)
u(3) = x(3)/1e-8
Now u(3) will be of the same rough order of magnitude as the other variables. So a starting value for u(3) might now be 0.1.
Now use fsolve to look for a solution.
u = fsolve(@FeMnC300newuipf3variable,[0.002 0.4 0.1])
u = fsolve(@FeMnC300newuipf3variable,[0.01 0.4 0.1])
Now you can see that fsolve seems happy, regardless of where you started, giving the same result from either start point. To recover x, just multiply the third element of u by 1e-8.
function F = FeMnC300newuipf3variable(u)
F(1) =10.3014287+log(u(3)*1e-8)+3.37E+04*u(3)*1e-8+(-3.37E+04*u(3)^2*1e-16)/2-19.1333*0.03592*u(3)*1e-8- log(u(1)) -21.4105*u(1)+10.41166*u(2)+(21.4105*u(1)^2)/2-10.41166*u(1)*u(2)+(1.99159*u(2)^2)/2;
F(2) =-0.269548173-log(u(2))+19.1333*u(3)*1e-8 +(-3.37E+04*u(3)^2*1e-16)/2-19.1333*0.03592*u(3)*1e-8+10.41166*u(1)-1.99159*u(2)+(21.4105*u(1)^2)/2-10.41166*u(1)*u(2)+(1.99159*u(2)^2)/2;
F(3) =-0.643539436+log(1-0.03592-u(3)*1e-8)-log(1-u(2)-u(1))+(-3.37E+04*u(3)^2*1e-16)/2-19.1333*0.03592*u(3)*1e-8+(21.4105*u(1)^2)/2-10.41166*u(1)*u(2)+(1.99159*u(2)^2)/2;
end
Always beware large differences in magnitude between variables when you are working in floating point arithmetic.
Finally, could I have used vpasolve to solve this more accurately? Wel, yes. But solving a problem to 40 decimal digits is a bit silly, when the coefficients are known to only 4 significant digits.
Weitere Antworten (1)
AndresVar
am 10 Feb. 2022
The results are almost the same, but you can take a look at the display for each iteration see fsolve documentation, here is an example:
problem.options = optimoptions('fsolve','Display','iter','PlotFcn',@optimplotfirstorderopt);
problem.objective = @FeMnC300newuipf3variable;
problem.solver = 'fsolve';
problem.x0 = [0.002 0.4 0.000000001];
fsolve(problem)
problem.x0 = [0.01 0.4 0.000000001];
fsolve(problem)
The first guess has f(x) closer to 0.
You can also see why the solver converged and increase the tolerances or maximum iterations to see wether the solutions converge regardless of initial guess.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!