Skip to content

Instantly share code, notes, and snippets.

@Sorseg
Forked from demoth/max_many.sage
Created June 3, 2013 12:06
Show Gist options
  • Save Sorseg/5697703 to your computer and use it in GitHub Desktop.
Save Sorseg/5697703 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(1,n):
res = xmax.subs({xm1:res, xm2:args[i]})
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment