solving nonlinear equation including max function
8 views (last 30 days)
Show older comments
Hi,
i want to solve this system of equations using matlab. can you please help me to do this?
1 Comment
Accepted Answer
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
A =
9.473684210526315
Now we can recover B, as
B = 2 + 0.9*A
B =
10.526315789473683
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))
ans =
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;
-0.1 0];
b=[0;1];
Aeq=[0.9 -1];
beq=-2;
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);
V=lcon2vert(A,b,Aeq,beq)
accept=all( V>lb/2 & V<ub/2 ,2);
V=V(accept,:) %Accept only solutions that are interior to the box bounds.
V =
9.4737 10.5263
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!