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