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} ψ=21−5, ϕ + 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 x2−x−1=0的根.使用初等数学方法求解Fibonacci通项主要通过化归到求解等比数列及其求和的通项.
f n = f n − 1 + f n − 2 f_{n} = f_{n-1} + f_{n-2} fn=fn−1+fn−2
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} gn−1=fn+Bfn−1=A(fn−1+Bfn−2)=Agn−2
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} gn−1=fn+2−1−5fn−1=21−5(fn−1+2−1−5fn−2)=21−5gn−1
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} gn−1=fn+2−1+5fn−1=21+5(fn−1+2−1+5fn−2)=21+5gn−1
{ 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=1∑n(−B)n−k+1gn−k)=(−B)n(f0+k=1∑n(−B)n−k+1An−kg0)=(−B)n(f0+−Bg0k=1∑n(−BA)n−k)呈等比数列求和, 容易求解通项.使用高等数学方法求解Fibonacci通项主要通过化归到频域的多项式真分式(proper polynomial fraction).
离散时间线性时不变系统
x [ n ] = x [ n − 1 ] + x [ n − 2 ] x[n] = x[n-1] + x[n-2] x[n]=x[n−1]+x[n−2]
连续化(上采样)
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)δ(t−nT)=n=0∑+∞x(nT)δ(t−nT)
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)e−snT=n=0∑+∞x[n]z−n
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)=z−1(X(z)−x[−1]z)+z−2(X(z)−x[−1]z−x[−2]z2)=(z−1+z