Subject: Math and Computing: Matlab 2. Write a script file that defines a number
ID: 3195047 • Letter: S
Question
Subject: Math and Computing: Matlab
2. Write a script file that defines a number n and prints to the screen an array called fil containing the first n terms of the Fibonacci sequence (,1,2, 3, 5, 8, 13,...). Set n 12, and turn in the array 3. Run the script file from problem 2 to create an array fib of length 20. Now (either in the same script file or in a new one) create an array of length 19 called ratio that consists of the ratios of consecutive entries in the array fib. The larger number should be in the numerator. The components of ratio seem to be converging to a limit. What number are they approaching (include 3 decimal places)? Google this number (to 3 decimal places) What is special about it?Explanation / Answer
(2) x = input ('Pick the first number of the sequence ');
y = input ('Pick the second number of the sequence ');
k = input ('Enter the total number of elements desired /n');
fib = zeros(1,n) ;
fib(1) = x;
fib(2) = y;
n=3;
while n<=k
fib (n) = fib(n-2) +fib(n-1) ;
n = n+1;
end
plot(1:k,fit);
polar(theta,fib);
theta = (1:k ) /180 *pi;
fprintf(' The fibonacci sequence to %d terms is /n',k);
fprintf(' ');
valueOffib = zeros(1,k);
for n = 1:k
fib = fib(n);
valueOffib(n) =fib;
end
(3) x(0) = 0 ,x(1)=1,x(i) = x(i-1) +x(i-2)
fib = recursivevector (start = [0,1] , expr= @(i,x) x(1)+x(2) , len=20
x2(1) = x(1) , x2(i) = a*x(i) +(1-a)*x2(i-1)
denoised = recursivevector(start =[noised(1)], expr= @(i,x) a*x(1)+(1,a)*noised(2), len = length(noised)
function y = exponentialdenoise(x,a)
y = zeros(size(x));
y(1) = x(1);
for i =2:length(x)
y(i) = a*x (i) +(1-a)*y (i-1);
end