5

When I use Maxima to calculate the Taylor series:

f(x,y) := taylor((x+y)^3, [x, y], [2, 3], 2);
f(2,3);  /* error: wrong number of arguments */

Basically I want to define a function as a expansion of (x+y)^3, which takes in x,y as parameter. How can I achieve this?

nbro
  • 15,395
  • 32
  • 113
  • 196
gongzhitaao
  • 6,566
  • 3
  • 36
  • 44

1 Answers1

4

Try

(%i1) f(x,y) := ''(ratdisrep(taylor(('x+'y)^3, ['x, 'y], [2, 3], 2))) $

(%i2) f(2, 3);
(%o2)                                 125

or

(%i1) define(f(x, y), ratdisrep(taylor(('x+'y)^3, ['x, 'y], [2, 3], 2)))$

(%i2) f(2, 3);
(%o2)                                 125
slitvinov
  • 5,693
  • 20
  • 31
  • Though I don't know what's going on here, this works. I may need to dive into the Maxima manual for this. Thanks. – gongzhitaao Apr 25 '14 at 14:52
  • 2
    @gongzhitaao Ordinarily the body of a function is not evaluated when the function is defined via `:=`. The reason that `f(x, y) := ''(...))` and `define(f(x, y), ...)` work is that they evaluate the body of the function (the Taylor expansion) at the time the function is defined. – Robert Dodier Apr 25 '14 at 17:02