Created
June 2, 2016 13:39
-
-
Save joastbg/336ecd96a5cbe8cba4a67254cf673c87 to your computer and use it in GitHub Desktop.
Fibonacci sequence in state-space form - Octave (MATLAB)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Fibonacci sequence in state-space form | |
% Define the state-space system parameters: | |
A = [0 1; 1 1]; % State transition matrix | |
B = [0; 1]; C = [1 1]; D = 1; % Input, output, feed-around | |
% Set up the input signal, initial conditions, etc. | |
x0 = [0;0]; % Initial state (N=2) | |
Ns = 13; % Number of sample times to simulate | |
u = [1, zeros(1,Ns-1)]; % Input signal (an impulse at time 0) | |
y = zeros(Ns,1); % Preallocate output signal for n=0:Ns-1 | |
% Perform the system simulation: | |
x = x0; % Set initial state | |
for n=1:Ns-1 % Iterate through time | |
y(n) = C*x + D*u(n); % Output for time n-1 | |
x = A*x + B*u(n); % State transitions to time n | |
end | |
y' % print the output y (transposed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aamazing