Fibonacci数列 Huffman树

本文深入探讨了Fibonacci数列,包括其通项公式、求和通项,以及Fibonacci分布的Huffman树。通过Laplace变换和Z变换解析了Fibonacci数列,并讨论了Huffman树的期望编码长度,揭示了其极限行为。此外,还介绍了Fibonacci数列的其他恒等式。
摘要由CSDN通过智能技术生成

Fibonacci数列

for k = 1:6
    k = int16(k);
    fprintf('f%d = %d\n', k, Fibonacci(k));
end

function fk = Fibonacci(k)
    assert(isinteger(k) && numel(k)==1 && k>=1);
    if k > 2
        %fk = Fibonacci(k-1) + Fibonacci(k-2);
        dp = ones(k,1);
        for i = 3:k
            dp(i) = dp(i-1) + dp(i-2);
        end
        fk = dp(k);
    else
        fk = 1;
    end
end

f1 = 1
f2 = 1
f3 = 2
f4 = 3
f5 = 5
f6 = 8

Fibonacci通项

最简单的证明的方法是使用数学归纳法.
f n = ϕ n − ψ n ϕ − ψ f_n = \frac{\phi^n - \psi^n}{\phi - \psi} fn=ϕψϕnψn
f n + f n + 1 = ϕ n + 1 − ψ n + 1 + ϕ n − ψ n ϕ − ψ = ( ϕ + 1 ) ϕ n − ( ψ + 1 ) ψ n ϕ − ψ = ϕ 2 ϕ n − ψ 2 ψ n ϕ − ψ = f n + 2 f_{n} + f_{n+1} = \frac{\phi^{n+1} - \psi^{n+1} + \phi^{n} - \psi^{n}}{\phi - \psi} = \frac{(\phi+1)\phi^{n} - (\psi+1)\psi^{n}}{\phi - \psi} = \frac{\phi^2 \phi^{n} - \psi^2 \psi^{n}}{\phi - \psi} = f_{n+2} fn+fn+1=ϕψϕn+1ψn+1+ϕnψn=ϕψ(ϕ+1)ϕn(ψ+1)ψn=ϕψϕ2ϕnψ2ψn=fn+2
ϕ = 1 + 5 2 \phi = \frac{1+\sqrt{5}}{2} ϕ=21+5 , ψ = 1 − 5 2 \psi = \frac{1-\sqrt{5}}{2} ψ=215 , ϕ + 1 = ϕ 2 \phi + 1 = \phi^2 ϕ+1=ϕ2, ψ + 1 = ψ 2 \psi + 1 = \psi^2 ψ+1=ψ2, 原因是他们是 x 2 − x − 1 = 0 x^2-x-1=0 x2x1=0的根.

使用初等数学方法求解Fibonacci通项主要通过化归到求解等比数列及其求和的通项.

f n = f n − 1 + f n − 2 f_{n} = f_{n-1} + f_{n-2} fn=fn1+fn2
g n − 1 = f n + B f n − 1 = A ( f n − 1 + B f n − 2 ) = A g n − 2 g_{n-1} = f_{n} + B f_{n-1} = A (f_{n-1} + B f_{n-2}) = A g_{n-2} gn1=fn+Bfn1=A(fn1+Bfn2)=Agn2
g n − 1 = f n + − 1 − 5 2 f n − 1 = 1 − 5 2 ( f n − 1 + − 1 − 5 2 f n − 2 ) = 1 − 5 2 g n − 1 g_{n-1} = f_{n} + \frac{-1-\sqrt{5}}{2} f_{n-1} = \frac{1-\sqrt{5}}{2} \left( f_{n-1} + \frac{-1-\sqrt{5}}{2} f_{n-2} \right) = \frac{1-\sqrt{5}}{2} g_{n-1} gn1=fn+215 fn1=215 (fn1+215 fn2)=215 gn1
g n − 1 = f n + − 1 + 5 2 f n − 1 = 1 + 5 2 ( f n − 1 + − 1 + 5 2 f n − 2 ) = 1 + 5 2 g n − 1 g_{n-1} = f_{n} + \frac{-1+\sqrt{5}}{2} f_{n-1} = \frac{1+\sqrt{5}}{2} \left( f_{n-1} + \frac{-1+\sqrt{5}}{2} f_{n-2} \right) = \frac{1+\sqrt{5}}{2} g_{n-1} gn1=fn+21+5 fn1=21+5 (fn1+21+5 fn2)=21+5 gn1
{ g n = A n g 0 } \{g_n = A^n g_0\} { gn=Ang0}呈等比数列, 容易求解通项.
f n = ( − B ) n ( f 0 + ∑ k = 1 n g n − k ( − B ) n − k + 1 ) = ( − B ) n ( f 0 + ∑ k = 1 n A n − k g 0 ( − B ) n − k + 1 ) = ( − B ) n ( f 0 + g 0 − B ∑ k = 1 n ( A − B ) n − k ) f_n = (-B)^n \left( f_0 + \sum\limits_{k=1}^{n} \frac{g_{n-k}}{(-B)^{n-k+1}} \right) = (-B)^n \left( f_0 + \sum\limits_{k=1}^{n} \frac{A^{n-k} g_0}{(-B)^{n-k+1}} \right) = (-B)^n \left( f_0 + \frac{g_0}{-B} \sum\limits_{k=1}^{n} \left(\frac{A}{-B}\right)^{n-k} \right) fn=(B)n(f0+k=1n(B)nk+1gnk)=(B)n(f0+k=1n(B)nk+1Ankg0)=(B)n(f0+Bg0k=1n(BA)nk)呈等比数列求和, 容易求解通项.

使用高等数学方法求解Fibonacci通项主要通过化归到频域的多项式真分式(proper polynomial fraction).

离散时间线性时不变系统
x [ n ] = x [ n − 1 ] + x [ n − 2 ] x[n] = x[n-1] + x[n-2] x[n]=x[n1]+x[n2]
连续化(上采样)
x ( t ) δ T ( t ) = ∑ n = 0 + ∞ x ( t ) δ ( t − n T ) = ∑ n = 0 + ∞ x ( n T ) δ ( t − n T ) x(t) \delta_T(t) = \sum\limits_{n=0}^{+\infty} x(t) \delta(t-nT) = \sum\limits_{n=0}^{+\infty} x(nT) \delta(t-nT) x(t)δT(t)=n=0+x(t)δ(tnT)=n=0+x(nT)δ(tnT)
Laplace变换
Z [ x [ n ] ] = L [ x ( t ) ] = ∑ n = 0 + ∞ x ( n T ) e − s n T = ∑ n = 0 + ∞ x [ n ] z − n \mathcal{Z}\left[x[n]\right] = \mathcal{L}\left[x(t)\right] = \sum\limits_{n=0}^{+\infty} x(nT) e^{-snT} = \sum\limits_{n=0}^{+\infty} x[n] z^{-n} Z[x[n]]=L[x(t)]=n=0+x(nT)esnT=n=0+x[n]zn
Z变换
X ( z ) = z − 1 ( X ( z ) − x [ − 1 ] z ) + z − 2 ( X ( z ) − x [ − 1 ] z − x [ − 2 ] z 2 ) = ( z − 1 + z − 2 ) X ( z ) + A 0 + A 1 z − 1 X(z) = z^{-1} \left( X(z) - x[-1]z \right) + z^{-2} \left( X(z) - x[-1]z - x[-2]z^{2} \right) = \left( z^{-1} + z^{-2} \right) X(z) + A_0 + A_1 z^{-1} X(z)=z1(X(z)x[1]z)+z2(X(z)x[1]zx[2]z2)=(z1+z

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值