need Matlab code for these questions that I am having trouble with....please mak
ID: 3849697 • Letter: N
Question
need Matlab code for these
questions that I am having trouble with....please make sure it works on Matlab r2016a
Explanation / Answer
function fib()
for n=0:15 % n varies from 0 to 15. When nothing given between 0 and 15 step size is 1
sqrtoffive=sqrt(5); % store square root of 5 in a variable as it is used many times in the formula, so need not calculate again
f=1./sqrtoffive .* ( ((1+sqrtoffive)./2).^n - ((1-sqrtoffive)./2).^n ); % Formula. Always use .and then operator to convert it into scalar
fprintf('F%d= %0.0f ',n,f); % print using fprintf, same as printf in C. Give format specifier and then the variable name
X=['F',num2str(n),'= ',num2str(f)]; % Convert everthing to string and store in X
disp(X); % Display the string X
end % for loop ends
end % function ends
Run the following command in the command window:
fib
Comment any one of fprintf or disp to see the result only once
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.