fsolve exitflag -2, 9 equations 9 variables

16 visualizaciones (últimos 30 días)
Daniel H.
Daniel H. el 2 de Jun. de 2022
Editada: Walter Roberson el 7 de Jun. de 2022
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?

Respuesta aceptada

Torsten
Torsten el 2 de Jun. de 2022
Editada: Torsten el 2 de Jun. de 2022
delta_lambda = 0.1;
lambda_start = delta_lambda;
lambda_end = 1.0;
lambda = lambda_start:delta_lambda:lambda_end;
n = numel(lambda);
x0 = ones(9,1);
x_guess = x0;
for i = 1:n
x = fsolve(@(x)lambda(i)*tst(x)+(1-lambda(i))*(tst(x)-tst(x0)),x_guess);
xguess = x
end
tst(x)
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
  6 comentarios
Daniel H.
Daniel H. el 2 de Jun. de 2022
Yes that is wise
Alex Sha
Alex Sha el 2 de Jun. de 2022
Hi, just reform your equations:
From:
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 );
To:
h(4) = -(x(4) * abs(x(4))) + 1e10*( x(7)^2 - x(8)^2 )/(1.29e9);
h(5) = -(x(5) * abs(x(5))) + 1e10*( x(8)^2 - x(9)^2 )/(1.29e9);
h(6) = -(x(6) * abs(x(6))) + 1e10*( x(9)^2 - x(7)^2 )/(1.29e9);
and then the result will be got without difficult:
x1: 59.9999999999115
x2: -19.9999999999964
x3: -40.0000000000186
x4: 29.2820323027161
x5: 9.28203230277714
x6: -30.717967697215
x7: 50.0000000000274
x8: -48.5521764665935
x9: -48.4043035184201

Iniciar sesión para comentar.

Más respuestas (3)

Walter Roberson
Walter Roberson el 2 de Jun. de 2022
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 comentarios
Matt J
Matt J el 2 de Jun. de 2022
Actually, sign(x4) wouldn't be undefined, but they don't give the same results:
x4=complex(rand,rand);
sign(x4) * x4^2
ans = -0.3368 - 0.5786i
x4*abs(x4)
ans = 0.1170 + 0.6592i
Daniel H.
Daniel H. el 2 de Jun. de 2022
Thanks for the update. But the problem is still unsolved :)

Iniciar sesión para comentar.


Daniel H.
Daniel H. el 3 de Jun. de 2022
Thanks again, yes the problem is solved. But I would like to dig a bit deeper.
Why the order of the coefficients are important here? Why again in the first place TolX and TolFun of 1e-30 could not help?
  1 comentario
Walter Roberson
Walter Roberson el 3 de Jun. de 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

Iniciar sesión para comentar.


Daniel H.
Daniel H. el 3 de Jun. de 2022
@Walter Roberson Thanks, but I need more explanation, maybe also a reference to read from in detail
  • What do you mean by "In order for eps() of a value to be less than 1e-30, the value must have absolute magnitude less than 1e-15 "?
  • And how we can say when the order is 1e9 the tolerance would be around 1e-5? "But instead your values are in the range of 1e9 which can only be distinguished down to roughly 1e-5"
  3 comentarios
Walter Roberson
Walter Roberson el 3 de Jun. de 2022
Editada: Walter Roberson el 7 de Jun. de 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.
Daniel H. el 7 de Jun. de 2022
It is more complicated that i thought, I expected it to be more mathematical rather computer science :)
but anyway, thank you very much

Iniciar sesión para comentar.

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by