Reputation: 198
I am attempting to define a function in Maple that defines the Taylor Series (without using the taylor() command). I am using the sigma notation definition as found here.
Essentially, I need a function that takes the variable a, and a variable f where f is a function of a, as seen in that wikipedia page. For simplicity's sake, I've used only the variable a and defined the function myself.
For the scope of this question, let's assume I want my code to return the taylor series of sqrt(x) about x=16
So far I have the following code for the sum:
t:=a->sum((D@@n)(f(a))*(x-a)^n/n!,n=0..4);
I've defined the function f on a previous line, as sqrt(x).
When I call the function, t(16);
, Maple returns only the first term of the series, 4. When I supplant a variable for a, I can see that Maple is taking the derivative of a, rather than the derivative of f(a) at each term. This of course creates zero terms and returns only 4.
Upvotes: 1
Views: 701
Reputation: 7271
The syntax you want for D here is (D@@n)(f)(a) instead of what you had.
You could make the operator accept another parameter to designate the upper bound of the index. Unless you want Maple to try and do symbolic summation (doubtful, for such finite sums and your intent), you're likely better off using add
instead of sum
for this.
restart:
t:=(a,N)->add((D@@n)(f)(a)*(x-a)^n/n!,n=0..N):
f:=sqrt:
Digits:=15:
S:=t(16,4):
eval(S,x=17.0);
4.12310552597046
sqrt(17.0);
4.12310562561766
S:=t(16,10):
eval(S,x=17.0);
4.12310562561768
sqrt(17.0);
4.12310562561766
Upvotes: 0