Skip to content

Instantly share code, notes, and snippets.

@demoth
Created June 3, 2013 12:04
Show Gist options
  • Save demoth/5697694 to your computer and use it in GitHub Desktop.
Save demoth/5697694 to your computer and use it in GitHub Desktop.
# параметр сглаживания
a = 1/100
# аппроксимация модуля
ma = (a + x^2)^(1/2)
# выражение максимума через модуль
var('xm1 xm2')
xmax=1/2*(ma(xm1-xm2) + xm1 + xm2)
var_names = 'x1 x2 x3 x4'
args = var(var_names)
# понтовый дифференцируемый максимум нескольких переменных
def max_many(args):
#args = []
n = len(args)
res = args[0]
for i in range(n-1):
res = xmax.subs({xm1:res, xm2:args[i+1]})
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment