MathGroup Archive 2008

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

Search the Archive

Re: Function Programming Problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90825] Re: [mg90782] Function Programming Problems
  • From: "Adriano Pascoletti" <adriano.pascoletti at gmail.com>
  • Date: Fri, 25 Jul 2008 06:17:08 -0400 (EDT)
  • References: <200807240851.EAA18893@smc.vnet.net>

David,

1.

In[8]:= LinearApproximation[f_, x0_, x_] := (f /. {x -> x0}) +  (D[f, x] /.
{x -> x0})*(x - x0);

LinearApproximation[Sin[x], Pi/4, x]


Out[9]= 1/Sqrt[2] + (-(Pi/4) + x)/Sqrt[2]


2.

In[10]:= LinearApproximation1[f_, x0_, x_] := Normal[Series[f, {x, x0,
1}]];


LinearApproximation1[Sin[x], Pi/4, x]


Out[11]= 1/Sqrt[2] + (-(Pi/4) + x)/Sqrt[2]


3.

In[14]:= LinearApproximation2[f_, x0_, x_, n_] := Normal[Series[f, {x, x0,
n}]];


LinearApproximation2[Sin[x], Pi/4, x, 5]


Out[15]= 1/Sqrt[2] + (-(Pi/4) + x)/Sqrt[2] - (-(Pi/4) + x)^2/(2*Sqrt[2]) -
   (-(Pi/4) + x)^3/(6*Sqrt[2]) + (-(Pi/4) + x)^4/(24*Sqrt[2]) +
   (-(Pi/4) + x)^5/(120*Sqrt[2])


Adriano Pascoletti


2008/7/24 <davey79 at gmail.com>:

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



  • 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