MATLAB中泰勒级数展开项的分离和分配

时间:2019-05-07 10:14:32

标签: matlab symbolic-math taylor-series

如何将泰勒级数展开式的各个术语“分开”?我正在使用此工具在管理会计中进行差异分析。

我需要将单个术语分配给影响因素。

此代码可能是永久年金的最简单表示。我想展示折现率(b)和现金流量(a)的变化如何影响价值。

syms a b a1 b1 test;
test = evalin(symengine,'mtaylor(a/b , [a = a1, b = b1], 4)')
dtest = subs(test, [a, a1, b, b1],[40,150,0.01,0.12])-(a1/b1)
dtest2 = subs(dtest, [a1,b1],[150,0.12])   
test =
 a1/b1 + (a - a1)/b1 - (a1*(b - b1))/b1^2 - ((a - a1)*(b - b1))/b1^2 + (a1*(b - b1)^2)/b1^3 - (a1*(b - b1)^3)/b1^4 + ((a - a1)*(b - b1)^2)/b1^3

dtest2 =
 545875/864

以下分离是手动进行的:

+(a - a1)/b1                  affected by delta cashflow
-(A1*(b - B1))/B1^2           affected by delta discount rate
-((a - a1)*(b - b1))/b1^2     affected by a mix of cashflow and disc. rate
+(a1*(b - b1)^2)/b1^3         affected by delta discount rate
-(a1*(b - b1)^3)/b1^4         affected by delta discount rate
+((a - a1)*(b - b1)^2)/b1^3   affected by a mix of cashflow and disc. rate

dtest2 -->>> The whole deviation 

为减少系列扩展的余数,我想扩展到“ 200”的量级,例如这就是为什么我要系统地而不是手动地分离和分配单个术语。

1 个答案:

答案 0 :(得分:1)

找到两个连续的泰勒级数展开,然后从以前的级数中减去当前级数,您将获得所需的其他单个零件。

syms a b a1 b1 test test2;
n = 4 % Taylor Expansion degree
for i = 1:n
    test(i) = evalin(symengine,strcat('mtaylor(a/b , [a = a1, b = b1], ', num2str(i), ')'));
     if i == 1
        test2(i) = test(i);
     else
        test2(i) = test(i)-test(i-1);
     end
end

test2(1) = a1/b1
test2(2) = (a - a1)/b1 - (a1*(b - b1))/b1^2
test2(3) = (a1*(b - b1)^2)/b1^3 - ((a - a1)*(b - b1))/b1^2
test2(4) = ((a - a1)*(b - b1)^2)/b1^3 - (a1*(b - b1)^3)/b1^4

过滤test2(2)

  filter = children(test2(2) + (a-a1) + (b-b1));
  filter = [ a, -a1, b, -b1, (a - a1)/b1, -(a1*(b - b1))/b1^2]

忽略前四个数组元素

filter(5) = (a - a1)/b1
filter(6) = -(a1*(b - b1))/b1^2

过滤test2(3)

filter = children(test2(3) + (a-a1) + (b-b1));
filter = [ a, -a1, b, -b1, -((a - a1)*(b - b1))/b1^2, (a1*(b - b1)^2)/b1^3]

忽略前四个数组元素

filter(5) = -((a - a1)*(b - b1))/b1^2
filter(6) = a1*(b - b1)^2)/b1^3