Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Function Programming Problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90830] Re: Function Programming Problems
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 25 Jul 2008 06:18:06 -0400 (EDT)

On 7/24/08 at 4:51 AM, davey79 at gmail.com wrote:

>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.

Your version will work with x^2 provided you supply this as a
pure function. That is,

LinearApproximation[#^2 &, a, x]

a^2+2 (x-a) a

However, I would define this using the built-in function Series.
And to get rid of the third argument I would do

LinearApproximation[func_, a_] :=
  Block[{x}, Normal@Series[func[x], {x, a, 1}]]

Like your code, to use this with x^2 you need to supply this as
a pure function.


  • Prev by Date: Re: Solving 3d degree polynomial
  • Next by Date: Re: Function Programming Problems
  • Previous by thread: Re: Function Programming Problems
  • Next by thread: Re: Function Programming Problems