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

numeric_result = (sym)

     5    4    3    2
    x    x    x    x
    ── - ── + ── - ── + x
    5    4    3    2
计算10阶泰勒展开,结果如下
>> [text_result, numeric_result] = func44(10)
text_result =
       10    9    8    7    6    5    4    3    2
      x     x    x    x    x    x    x    x    x
    - ─── + ── - ── + ── - ── + ── - ── + ── - ── + x
      10    9    8    7    6    5    4    3    2

numeric_result = (sym)

       10    9    8    7    6    5    4    3    2
      x     x    x    x    x    x    x    x    x
    - ─── + ── - ── + ── - ── + ── - ── + ── - ── + x
      10    9    8    7    6    5    4    3    2
友链