solving nonlinear equation including max function

8 views (last 30 days)
Hi,
i want to solve this system of equations using matlab. can you please help me to do this?
  1 Comment
Torsten
Torsten on 11 Nov 2022
Two times the same number in the max-operator in (2) ? That's strange ...

Sign in to comment.

Accepted Answer

Torsten
Torsten on 11 Nov 2022
Edited: Torsten on 11 Nov 2022
options = optimset('TolX',1e-10,'TolFun',1e-10);
fun = @(x,y)[x - max(0.9*y,-1+0.9*x);y - max(2+0.9*x,2+0.9*x)]
fun = function_handle with value:
@(x,y)[x-max(0.9*y,-1+0.9*x);y-max(2+0.9*x,2+0.9*x)]
sol = fsolve(@(z)fun(z(1),z(2)),[1 1],options)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
sol = 1×2
9.4737 10.5263
fun(sol(1),sol(2))
ans = 2×1
0 0

More Answers (3)

John D'Errico
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
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
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
  1. rhs max in (1) is the first term, rhs max in (2) is the first term
  2. rhs max in (1) is the first term, rhs max in (2) is the second term
  3. rhs max in (1) is the second term, rhs max in (2) is the first term
  4. 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.

Categories

Find more on Mathematics 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!