0

I am trying to use a Taylor polynomial programmatically in Maple, but the following does not seem to work...

T[6]:=taylor(sin(x),x=Pi/4,6);convert(T[6], polynom, x);
f:=proc(x)
  convert(T[6], polynom, x);
end proc;
f(1);

All of the following also do not work:

  • f:=convert(T[6], polynom);
  • f:=convert(T[6], polynom, x);
  • f:=x->convert(T[6], polynom);
  • f:=x->convert(T[6], polynom, x);.

Is there a way of doing this without copying and pasting the output of convert into the definition of f?

kzh
  • 19,810
  • 13
  • 73
  • 97
  • Note that convert (in this case) only takes two arguments: a series and the name polynom. Everything else is discarded, so convert(T,polynom,x) doesn't do anything more than convert(T,polynom) does. – qedi Dec 02 '09 at 14:45

3 Answers3

2

If I understood you correctly, this accomplishes what you want:

f := proc(z)
    local p :: polynom;
    p := convert(T[6], polynom); 
    return subs(x = z, p)
end proc
jmbr
  • 3,298
  • 23
  • 23
2

Several earlier answers involving procedures and subs will do the entire taylor series derivation, as well as the conversion to polynom, for each and every input. That is highly inefficient.

You only need to produce the taylor result, and convert to polynom, once. With that result in hand you can then create an operator (with which to act on as many inputs as you wish, merely by evaluating the polynomial at the point but without having to recompute the whole taylor answer).

Below is a way to create a procedure f with which to evaluate at any given point for the argument x. It computes the (truncated) taylor series and converts to polynom just once.

> f:=unapply(convert(taylor(sin(x),x=Pi/4,6),polynom),x):
acer
  • 6,671
  • 15
  • 15
  • Since it is Summer and school is out of session, I do not have a copy of Maple to test your answer, but +1 for a very well thought out answer. You'll have to wait until Fall to see if you get the green check of awesome answering skills. – kzh May 13 '10 at 18:38
1

It might also be natural to define T as a function.

T:=y->subs(x=y,convert(taylor(sin(x),x=Pi/4,6),polynom));

T(1);
qedi
  • 2,195
  • 1
  • 13
  • 6