用Octave求泰勒展开(8)
广告
{{v.name}}
常见麦克劳林展开式(8)
\((1+x)^{a}=1+ax+\frac{a(a-1)}{2!}x^{2}+\cdots+\frac{a(a-1)\cdots(a-n+1)}{n!}x^{n}+o(x^{n})\)
求\((1+x)^{a}\)的泰勒展开.
程序代码如下
function [text_result, numeric_result] = func46(order)
    pkg load symbolic;
    x = sym('x');
    a = sym('a');
    question = power((1 - x), a);
    d = taylor(question, x, 'order', order + 1);
    text_result = ["\n", disp(d)];
    numeric_result = eval(d);
endfunction
计算5阶泰勒展开,结果如下
>> [text_result, numeric_result] = func46(5)
    text_result =
    5                                    4                            3                    2
  a⋅x ⋅(a - 4)⋅(a - 3)⋅(a - 2)⋅(a - 1)   a⋅x ⋅(a - 3)⋅(a - 2)⋅(a - 1)   a⋅x ⋅(a - 2)⋅(a - 1)   a⋅x ⋅(a - 1)
- ────────────────────────────────── + ────────────────────────── - ────────────────── + ─────────── - a⋅x + 1
                120                                24                        6                 2

numeric_result = (sym)

    5                                    4                            3                    2
  a⋅x ⋅(a - 4)⋅(a - 3)⋅(a - 2)⋅(a - 1)   a⋅x ⋅(a - 3)⋅(a - 2)⋅(a - 1)   a⋅x ⋅(a - 2)⋅(a - 1)   a⋅x ⋅(a - 1)
- ────────────────────────────────── + ────────────────────────── - ────────────────── + ─────────── - a⋅x + 1
                120                                24                        6                 2
友链