fsolve exitflag -2, 9 equations 9 variables
Show older comments
The way I am solving it:
function h = tst(x)
h(1)= x(7) - 50;
h(2)= x(2) + 20;
h(3)= x(3) + 40;
h(4) = -(1.29e9) * (x(4) * abs(x(4))) + 1e10*( x(7)^2 - x(8)^2 );
h(5) = -(1.29e9) * (x(5) * abs(x(5))) + 1e10*( x(8)^2 - x(9)^2 );
h(6) = -(1.29e9) * (x(6) * abs(x(6))) + 1e10*( x(9)^2 - x(7)^2 );
h(7) = x(1) + x(6) - x(4) ;
h(8) = x(2) + x(4) - x(5) ;
h(9) = x(3) + x(5) - x(6) ;
end
and I am trying to solve it like:
x0 = abs(randn(9, 1))
fun = @(x) tst(x);
options = optimoptions('fsolve','Display','iter','MaxIterations',2000,...
'MaxFunctionEvaluations',3000,'TolFun',1e-30,'TolX',1e-30)
[x_sol,fval,exitflag,output]= fsolve(fun,x0, options)
my fval is:
0 0 0 -0.0027 0.0006 0.0022 0 -0.0000 0
And this is the message:
No solution found.
fsolve stopped because the relative size of the current step is less than the
value of the step size tolerance squared, but the vector of function values
is not near zero as measured by the value of the function tolerance.
So what is the problem here? Why this cannot be solved?
Accepted Answer
More Answers (3)
Walter Roberson
on 2 Jun 2022
0 votes
If you use the symbolic toolbox, you can work stepwise to solve except for the 4th and 6th equation, solving for variables except x4 and x8. At that point you have to start taking branches of solutions and solving each branch. There is at least one exact solution.
10 Comments
Daniel H.
on 2 Jun 2022
Torsten
on 2 Jun 2022
It can help if this system is representative for the large scale problem. So does the large scale problem have a similar structure to your toy problem ?
Daniel H.
on 2 Jun 2022
Walter Roberson
on 2 Jun 2022
is there a particular reason you have x4*abs(x4) instead of sign(x4) * x4^2 ? Can we assume real variables only?
Daniel H.
on 2 Jun 2022
Daniel H.
on 2 Jun 2022
Daniel H.
on 2 Jun 2022
Actually, sign(x4) wouldn't be undefined, but they don't give the same results:
x4=complex(rand,rand);
sign(x4) * x4^2
x4*abs(x4)
Daniel H.
on 2 Jun 2022
Daniel H.
on 3 Jun 2022
0 votes
1 Comment
Walter Roberson
on 3 Jun 2022
Tolerances are only meaningful if the values of the expression can be distinguished within the given tolerance. That requires that eps() of the value of the expression is less than the tolerance. In order for eps() of a value to be less than 1e-30, the value must have absolute magnitude less than 1e-15 or so. But instead your values are in the range of 1e9 which can only be distinguished down to roughly 1e-5
Daniel H.
on 3 Jun 2022
0 votes
3 Comments
Walter Roberson
on 3 Jun 2022
Edited: Walter Roberson
on 3 Jun 2022
MATLAB stores (most) numbers as IEEE 754 Double Precision, which is industry standard and which is what is built in to the hardware of your CPU (GPU might not follow some of the obscure behaviors.)
IEEE 754 uses 1 sign bit, 11 exponent bits, and 52 bits of precision, but the choice of exponent effectively gives you one more bit of precision. The representation is sign*(2^53 + 52 bit unsigned integer)/2^53 * 2^(exponent - 1024). Two values that differ by less than 2^-53 times the effect of the exponent cannot be distinguished with this format. That works out to approximately 1.6*10^-16 * 2^floor(log2(abs(number)). Each doubling of the input keeps the same relative precision but loses a bit of absolute precision.
You have values in the range of 5e9. In order to be able to distinguish 10^-30 over that range, I calculate that you would need about 130 bits of precision. Even if you were using 128 bit extended precision numbers, that would not be enough.
Walter Roberson
on 3 Jun 2022
Edited: Walter Roberson
on 7 Jun 2022
MATLAB does not store numbers in decimal, with the exception of the symbolic toolbox (and even that is a bit questionable, with some hints that it chains together groups of 2^30)
Daniel H.
on 7 Jun 2022
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!