Matlab Fibonacci problem

  • #1
Joon
85
2

Homework Statement


Modify the function so that instead of returning all n numbers, it only returns the nth number.

Homework Equations




The Attempt at a Solution


I'm not sure how to return only the nth number of the fibonacci sequence. Please help.
 

Attachments

  • fibonacci problem.png
    fibonacci problem.png
    9.6 KB · Views: 318

Answers and Replies

  • #2
anorlunda
Staff Emeritus
Insights Author
10,871
8,182
If I gave you a sequence of any random set of numbers, could you return only the Nth one?
 
  • #3
Joon
85
2
I know how to return a number in a nth row / nth column matrices/vectors but I'm confused where to start.
 
  • #4
Joon
85
2
For example, I know that c = A(2,2:2:end); sets c equal to columns {2,4,6,8,10} of row 2 of A
and that c=A(2,2) sets c equal to the number that is in row 2 column 2 of A.
 
  • #5
gneill
Mentor
20,945
2,886
If you only are required to return the nth number I don't see why you'd bother to store them all in an array; you only need the previous two to generate the next one. You should be able to do this with a small set of scalar variables and a loop.
 
  • #6
RPinPA
Science Advisor
Homework Helper
587
329
For example, I know that c = A(2,2:2:end); sets c equal to columns {2,4,6,8,10} of row 2 of A
and that c=A(2,2) sets c equal to the number that is in row 2 column 2 of A.

So you're familar with END. Are you aware that f(end) is the last element of vector f?
 

Suggested for: Matlab Fibonacci problem

  • Last Post
Replies
1
Views
102
  • Last Post
Replies
10
Views
163
  • Last Post
Replies
3
Views
377
Replies
5
Views
686
  • Last Post
Replies
1
Views
375
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
1
Views
414
  • Last Post
Replies
12
Views
810
  • Last Post
Replies
6
Views
780
Top