Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here an example where you don't have to rewrite the code. I do not distinguish between minima and maxima. Controlling behavior for x to infinity: set some additional points.

L_roots = [-1,0]
L_min_max = [(1,1),(5,1)]
L_other = [(10,10)]
N = len(L_roots)+2*len(L_min_max)+len(L_other) -1

param_str = reduce(lambda x,y:x+y,['a%s,'%(k) for k in [0..N]])
params = var(param_str[:-1])

f(x) = sum([ params[k]*x^k for k in [0..N]])
df = diff(f,x)
show(f)

eqns = [ f(x0)==0 for x0 in L_roots ]
eqns += [ f(P[0])==P[1] for P in L_min_max ]
eqns += [ df(P[0])==0 for P in L_min_max ] 
eqns += [ f(P[0])==P[1] for P in L_other ]
sol=solve(eqns,params,solution_dict=True)
show(f.substitute(sol[0]))

Here an example where you don't have to rewrite the code. I do not distinguish between minima and maxima. Controlling behavior for x to infinity: set some additional points.

L_roots = [-1,0]
L_min_max = [(1,1),(5,1)]
L_other = [(10,10)]
N = len(L_roots)+2*len(L_min_max)+len(L_other) -1

param_str = reduce(lambda x,y:x+y,['a%s,'%(k) for k in [0..N]])
params param_list = var(param_str[:-1])

f(x) = sum([ params[k]*x^k param_list[k]*x^k for k in [0..N]])
df = diff(f,x)
show(f)

eqns = [ f(x0)==0 for x0 in L_roots ]
eqns += [ f(P[0])==P[1] for P in L_min_max ]
eqns += [ df(P[0])==0 for P in L_min_max ] 
eqns += [ f(P[0])==P[1] for P in L_other ]
sol=solve(eqns,params,solution_dict=True)
sol=solve(eqns,param_list,solution_dict=True)
show(f.substitute(sol[0]))