On 04/06/12 16:12, Nils Bruin wrote: > > which you *can* provided you avoid the pitfall of "function('f',x)": > > sage: f=function('f') > sage: var('a,b') > (a, b) > sage: midpoint = (1/2)*( f(a) + f(b) ) > sage: midpoint > 1/2*f(a) + 1/2*f(b) > sage: midpoint.substitute_function(f,sin) > 1/2*sin(a) + 1/2*sin(b) > > You can even make that into a function of a,b > sage: mp > (a, b) |--> 1/2*f(a) + 1/2*f(b)
That was a too-simple example. You can't create e.g. a cubic spline because of the evaluated derivatives. In general the form over [-1,1] would look like, s(f;x) = a(x)*f(-1) + b(x)*f'(-1) + c(x)*f(1) + d(x)*f'(1) Swapping out `f` after evaluating it at the endpoints is what causes the biggest problems. If you make `s` a function that takes `f` as an argument, it works, but I need to be able to swap out `f` later for two reasons: 1) With higher order approximations, optimal splines can take a long time to compute. 2) To calculate error bounds, I need to know the coeffients of f, f.diff(),... What's the coefficient of sin(pi)? > > That said, I think your confusion shows that it's probably better if > function('f',x) were to be deprecated in favour of function('f')(x). > The relevant bit of information to glean from the notation is that f > takes one argument. You can already indicate the valid number of > arguments: > This does work better, I'll use it from now on, thanks. -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org