solving 3 nonlinear equations including max function
5 views (last 30 days)
Show older comments
Hi, I want to solve this system of equations:

I tried this code, but it did't work. My variables are negative but I can't insert this constraint. Can you please help me?
options = optimset('TolX',1e-10,'TolFun',1e-10);
fun = @(x,y,z)[x - max([-1 -1+x -1+x -1+z]);
y - max([-1 -1+y -1+y -1+z]);
z - max([-1+z -1+z -1+y -1+x])];
sol = fsolve(@(z)fun(z(1),z(2),z(3)),[1 1 1],options)
2 Comments
Torsten
on 11 Nov 2022
What is V_*(Z) ? Why do you repeat the same values in the max-command -1+V_*(A),-1+V_*(B) and -1+V_*(C) ?
Answers (3)
Walter Roberson
on 11 Nov 2022
max() has a discontinuous derivative, and so is mathematically unsuited for use with fsolve()
fsolve() relies upon the gradient to locate the zero, but when you have max() then the function becomes flat at boundaries (further travel in one of the directions gives the same result) and that leads to a gradient of zero in places, which fsolve() cannot deal with.
You will need to give up on using fsolve() for this purpose.
What you can do is take fun2 = @(z)fun(z).^2 and ga(fun2, 3) . When you are working with real-valued functions, looking for a zero of the function is equivalent to minimizing the square of the function... at least when there really is a zero of the function.
2 Comments
Walter Roberson
on 11 Nov 2022
See my newer reply in which I prove that the function returns a constant.
Walter Roberson
on 11 Nov 2022
Edited: Walter Roberson
on 11 Nov 2022
Those equations need to be understood as defining the same function recursively. You should not be treating
and
and
as being different functions: there is just one function,
that is being evaluated with different parameters, A, B, C.
Now let us hypothesize that for a given input, function
returns a value less than -1 . Is that potentially consistent? For that we can look at the first definition and see that
is max(-1, -1+V.(A)) and if V.(A) were less than -1 then -1+V.(A) would be less than -1 so the max() would select -1. It is therefore inconsistent for function V. to return a value less than -1 .
Now let us hypothesize that for a given input, function V. returns a value between -1 (exclusive) and 0 (inclusive). Is that potentially consistent? We can look at the first definition again and see max(-1,-1+V.(A)) but if V.(A) is between -1 and 0 then the -1+V.(A) would be less than -1 and the max() would select the -1 again. It is therefore inconsistent for function V. to return a value between -1 and 0.
Now let us hypothesize that for a given input, function V. returns a value greater than 0. This time look at the third definition, and see that there is no -1 in the max, that each of the four possibilities is -1 + the function value. If, for example, V. were to return 4, then the third definition would compute max(-1+4, -1+4, -1+4, -1+4) which is not 4, so it is inconsistent for V. to return any value greater than 0.
We conclude that V. must be the function that returns -1 for all inputs.
And since the constant -1 is never equal to 0, then there is no possibility that fsolve() could work, at least not in the framework you used.
0 Comments
Torsten
on 11 Nov 2022
Edited: Torsten
on 11 Nov 2022
a_old = 0.5;
b_old = 0.25;
c_old = -3.0;
err = 1.0;
itermax = 100;
iter = 0;
while err > 1e-6 && iter < itermax
iter = iter + 1;
a_new = max([-1,-1+a_old,-1+c_old]);
b_new = max([-1,-1+b_old,-1+c_old]);
c_new = max([-1+a_old,-1+b_old,-1+c_old]);
err = abs(a_new-a_old)+abs(b_new-b_old)+abs(c_new-c_old);
a_old = a_new;
b_old = b_new;
c_old = c_new;
end
iter
a_new
b_new
c_new
0 Comments
See Also
Categories
Find more on Systems of Nonlinear Equations 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!