% Compute u(n) using the recursive formula % u(n+2) = 3*u(n+1) - 2*u(n) % with initial values % u(1) = 0.1, u(2) = 0.1 % In exact arithmetic, the answer should be % u(n) = 0.1 for all n % However, in finite precision arithmetic, % we can see the instability. % allocate memory for a 100-dim vector u u = zeros(100,1); % set the first two elements u(1) = 0.1; u(2) = 0.1; % do the iteration for n = 1:98 u(n+2) = 3*u(n+1) - 2*u(n); end % draw the result plot(u) % print out several values u(10) u(50) u(100)
ans = 0.1000 ans = 0.1078 ans = 8.7961e+12
