solving nonlinear equation including max function
4 views (last 30 days)
More Answers (3)
John D'Errico on 11 Nov 2022
Edited: John D'Errico on 11 Nov 2022
In general, things like the max function introduce non-differentiable points, and even discontinuities into a problem. And that makes the use of solvers, that generally rely on smoothness for their objectives, problematic. But this is only a 2 variable probem. And it should be relatively easy to work things at least, so we can understand what is happening.
Assume two variables, I'll call them A and B, instead of your notation, which is difficult to type. We have two equations:
A = max(0 + 0.9*B, -1 + 0.9*A)
B = max(2 + 0.9*A, 2 + 0.9*A)
The second equation is strange, since the max function has both halves identical. Are you sure this is the case, or is it a typo? Assuming it is correct as written, then the max is irrelevant in equation 2.
B = 2 + 0.9*A
Substitute back into the first equation, we would find
A = max(0 + 0.9*(2 + 0.9*A), -1 + 0.9*A)
A = max(0.81*A + 9/5, 0.9*A - 1)
There would seem to be two cases here. Either A = -10, or A = 9/5*1/0.19. But A=-10 is not a solution to that equation. So we have
A = (9/5)/0.19
Now we can recover B, as
B = 2 + 0.9*A
Could I have used solve instead of paper and pencil?
syms A B
solve(A == max(0 + 0.9*B, -1 + 0.9*A), B == max(2 + 0.9*A, 2 + 0.9*A))
struct with fields:
A: [0×1 sym]
B: [0×1 sym]
Apparently solve fails, if we try it. I would expect solve to fail, and it did, as things like max are often not symbolic friendly operations.
And looking up, I see that Torsten has used fsolve, which did result in (the same) valid solution. However, I also note that if equation 2 is not the trivial one you have, then we have multiple discontinuities that appear in the problem.
Matt J on 11 Nov 2022
Edited: Matt J on 11 Nov 2022
Reorganizing the equations into the form A*x<=b, Aeq*x=beq and using this FEX download,
A=[ -1 0.9;
lb=[1,1]*-1e6; %lcon2vert must solve over a bounded region,
ub=[1,1]*1e6; %so apply generous box constraints.
[A,b, Aeq,beq]=addBounds(A,b, Aeq,beq,lb,ub);
accept=all( V>lb/2 & V<ub/2 ,2);
V=V(accept,:) %Accept only solutions that are interior to the box bounds.
Bruno Luong on 11 Nov 2022
Edited: Bruno Luong on 11 Nov 2022
The dumb method (buts surely reliable and give all possible solution) is to assume one of the 4 combinations
- rhs max in (1) is the first term, rhs max in (2) is the first term
- rhs max in (1) is the first term, rhs max in (2) is the second term
- rhs max in (1) is the second term, rhs max in (2) is the first term
- rhs max in (1) is the second term, rhs max in (2) is the second term
Each of them is a linear 2 x 2 system to solve. Solve then 4 times then check if the corresponding assumption meets.
Of course (2) seem having a typo made by the OP.