HM5_Alfredson.txt - thomas Alfredson ETGR-2122 Homework 5...

This preview shows 1 out of 2 pages.

% thomas Alfredson % 3/20/18 % ETGR-2122 % Homework 5 %%%%%%%%%%%%%%%%%%%%%%% problem 19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Fibonacci Numbers % The nth Fibonacci number is defined by the followingrecursive equations: % f(1) =1 f(2)=2 f(n) = f(n-1)+ f(n-2) n = input('Enter a number to calculate the Fibonacci Number: '); functionf = zeros(1:n); nextconstant = 3; functionf(1) = 1; functionf(2) = 2; while (nextconstant <= n) functionf(nextconstant)= functionf(nextconstant-2) + functionf(nextconstant- 1); nextconstant = nextconstant + 1; end fprintf('Fibocanni to the Nth is: %d \n', functionf(n)) %%%%%%%%%%%%%%%%%%%%%%% answer is as followed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%% homework5prob19 Enter a number to calculate the Fibonacci Number: 5 Fibocanni to the Nth is: 8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% problem 24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Geometric Mean The geometric mean of a set of numbers through % Xn is defined as the nth root of the product of the numbers: % sqrt(x1-x2*x3...Xn) to the Nth root arth = 0; geom = 1; k = 0; disp 'Enter a positive number to calculate the arithmatic and geometric mean, once a negative number is entered a calculation will be give' user = input('Enter a positive number to calculate: \n'); while( user >= 0) k = k +1; x(k) = user;
Image of page 1

Subscribe to view the full document.

Image of page 2
You've reached the end of this preview.
  • Spring '14
  • CarlosE.Orozco
  • Negative and non-negative numbers, Fibonacci number, positive number, arth

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern