Re: Function Programming Problems

*To*: mathgroup at smc.vnet.net*Subject*: [mg90807] Re: Function Programming Problems*From*: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>*Date*: Fri, 25 Jul 2008 06:12:21 -0400 (EDT)*References*: <g69fqt$ie1$1@smc.vnet.net>

Hi, if you say: LinearApproximation[function_, a_, x_] := function[a] + function'[a]*(x - a) you have to give a pure function and LinearApproximation[#^2 &, 0, x] will work For a general expression you have to give a symbol where the expression depend on, i.e. add a rule: LinearApproximation[foo_,y_,at_,x_]:=LinearApproximation[Function[{y},foo],at,x] Regards Jens davey79 at gmail.com wrote: > Hello, > > A colleague and myself are working on some Mathematica labs for > Calculus using Mathematica 6.0 and I can't seem to find any > information or examples that explain defining functions and using > functions as arguments. > > I want to define a LinearApproximation command that preferably would > take two arguments and return the linear approximation. Ideally, > > LinearApproximation[function_,a_] would have > LinearApproximation[Sin[x],0] give "x" as the output. > > So far I have: > LinearApproximation[function_, a_, x_] := function[a] + > function'[a]*(x - a) > > which works mostly nicely, except it only works with > LinearApproximation[Sin,0,x]. > > Does anyone know how I would fix this to allow Sin[x] as input (or > even x^2, etc)? Getting rid of the third argument "x" would be nice, > but not necessary. > > Thanks! > > David Taylor > Roanoke College >