Modify Fibonacci Function to Return nth Number - Matlab Homework

  • Thread starter Thread starter Joon
  • Start date Start date
  • Tags Tags
    Matlab Sequence
Click For Summary

Discussion Overview

The discussion revolves around modifying a Fibonacci function in Matlab to return only the nth number of the sequence, rather than the entire sequence. The scope includes programming techniques and approaches to efficiently compute the desired output.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant expresses uncertainty about how to modify the function to return only the nth Fibonacci number.
  • Another participant questions whether the same approach could be applied to return the nth number from any arbitrary sequence of numbers.
  • A participant mentions familiarity with accessing elements in matrices and vectors but feels confused about how to start with the Fibonacci sequence.
  • One participant suggests that if only the nth number is needed, it may not be necessary to store all Fibonacci numbers in an array, proposing that only the previous two numbers are required to compute the next one using scalar variables and a loop.
  • Another participant references the use of Matlab's indexing features, specifically mentioning how to access elements using the 'end' keyword.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the best approach to modify the function, with multiple viewpoints and methods being discussed without resolution.

Contextual Notes

Some participants' comments suggest a reliance on specific programming knowledge and techniques, which may not be universally applicable. There is also a lack of clarity on the exact requirements of the function modification.

Who May Find This Useful

Individuals interested in Matlab programming, particularly those working on homework related to functions and sequences, may find this discussion beneficial.

Joon
Messages
85
Reaction score
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
    6.4 KB · Views: 449
Physics news on Phys.org
If I gave you a sequence of any random set of numbers, could you return only the Nth one?
 
I know how to return a number in a nth row / nth column matrices/vectors but I'm confused where to start.
 
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.
 
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.
 
Joon said:
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?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
5K
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K