Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python equation solver (max and min)

How can I resolve the equation like x * max(x,15) = 10 with python (maybe Sympy) libraries?
The max() means the maximum between given two arguments.
My equations has a more complicated form, but I want to resolve it in simplified form.

like image 574
Kenenbek Arzymatov Avatar asked Sep 26 '22 04:09

Kenenbek Arzymatov


1 Answers

When I plug your equation into sympy.solve, it gives NotImplementedError, meaning the algorithms to solve it are not implemented (I opened https://github.com/sympy/sympy/issues/10158 for this).

I think to solve equations like these, you would need to replace each Max or Min with its arguments and solve every iteration, and then remove the solutions where the Max or Min was not actually maximal or minimal in its argument.

I'll leave the full algorithm to you or some other answerer (or hopefully someone will implement it in SymPy). Some useful tips:

  • expr.atoms(Max, Min) will extract all instances of Max and Min from expr.

  • expr.subs(old, new) will return a new expression with old replaced with new in expr.

like image 62
asmeurer Avatar answered Sep 30 '22 08:09

asmeurer