I would like to define a function that uses another function with a variable number of parameters passed as parameter. The problem is to get the parameters in (1) and pass them to the call in (2):
def f1(x):
return x
def f2(x,a):
return x+a
def f3(x,a,b):
return b*x+a
def genStr(x0,x1, n, f, *params): # <----------------- (1)
out = ''
dx = (x1-x0)/(n-1)
x = x0
out += r'\draw[thick] '
for k in range(0,n):
if k!=0:
out += r' -- '
out += '({:.4f},{:.4f})'.format(x,f(x,params)) # <------- (2)
x += dx
out += r';'
return out
print(genStr(0, 2, 3, f1))
print(genStr(0, 2, 3, f2, 0.1))
print(genStr(0, 2, 3, f3, 2, 0.3))