Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fibonacci numbers

Subject: fibonacci numbers

From: Maria

Date: 18 Nov, 2008 18:32:02

Message: 1 of 10

i have to write a function that generates the fibonacci sequence with out using loops. the length is specified by the user.if a single number is specified the sequence should be generated for numbers -Fn...Fn and if twoarguments ar given the sequence should run from Fm...Fn. and the zeroth term assume 0 is F0. Can anyone help me??

Subject: fibonacci numbers

From: Matt

Date: 18 Nov, 2008 23:13:02

Message: 2 of 10

"Maria " <mariaki16@hotmail.com> wrote in message <gfv1n2$r4j$1@fred.mathworks.com>...
> i have to write a function that generates the fibonacci sequence with out using loops. the length is specified by the user.if a single number is specified the sequence should be generated for numbers -Fn...Fn and if twoarguments ar given the sequence should run from Fm...Fn. and the zeroth term assume 0 is F0. Can anyone help me??

Looks like there is a closed form expression for the sequence here.

http://en.wikipedia.org/wiki/Fibonacci_number#Power_series

So can't you evaluate it directly?

Subject: fibonacci numbers

From: Maria

Date: 18 Nov, 2008 23:43:02

Message: 3 of 10

no becouse we don't know the array.is given by the user.so i have to create a formula for a random array...the golden radio is recomented to do the formula(http://www.mathworks.com/moler/intro.pdf)

Subject: fibonacci numbers

From: Matt

Date: 19 Nov, 2008 00:17:02

Message: 4 of 10

"Maria " <mariaki16@hotmail.com> wrote in message <gfvju6$8er$1@fred.mathworks.com>...
> no becouse we don't know the array.is given by the user.so i have to create a formula for a random array...the golden radio is recomented to do the formula(http://www.mathworks.com/moler/intro.pdf)

Sorry, I didn't understand that. What is "the array"?

I thought the user inputs the value of n. Once you know n, you can evaluate Fn from the formula.

Subject: fibonacci numbers

From: Matt

Date: 19 Nov, 2008 00:26:20

Message: 5 of 10

"Matt" <mjacobson.removethis@xorantech.com> wrote in message <gfvltu$qpd$1@fred.mathworks.com>...
> "Maria " <mariaki16@hotmail.com> wrote in message <gfvju6$8er$1@fred.mathworks.com>...
> > no becouse we don't know the array.is given by the user.so i have to create a formula for a random array...the golden radio is recomented to do the formula(http://www.mathworks.com/moler/intro.pdf)
>
> Sorry, I didn't understand that. What is "the array"?
>
> I thought the user inputs the value of n. Once you know n, you can evaluate Fn from the formula.

Just to be clear, this is the implementation I'm thinking of:

g=(1+sqrt(5))/2; %The golden ratio

F=@(n) (g.^n- (1-g).^n)/sqrt(5); %Formula for n-th Fibonacci number

sequence= F(0:n); %Fibonacci sequence from 0 to n

Subject: fibonacci numbers

From: Maria

Date: 19 Nov, 2008 00:38:02

Message: 6 of 10

yeah thats right but i've got a problem inputing a single number its have to outpout [-x:x]insteat of that i have this:

>> fibonacci(4)

ans =

     0 0 0 0 0 1 1 2 3

for the 2 inputs is working right
>> fibonacci(4,5)

ans =

     3 5


 

Subject: fibonacci numbers

From: Matt

Date: 19 Nov, 2008 00:48:02

Message: 7 of 10

"Maria " <mariaki16@hotmail.com> wrote in message <gfvn5a$edd$1@fred.mathworks.com>...
> yeah thats right but i've got a problem inputing a single number its have to outpout [-x:x]insteat of that i have this:
>
> >> fibonacci(4)
>
> ans =
>
> 0 0 0 0 0 1 1 2 3

OK. Well, the left hand tail of the sequence obeys the difference equation

F(-k)=F(-k+2)-F(-k+1), k=0,1,...

You must solve this difference equation with boundary conditions

F(0)=0, F(1)=1

to get that half of the sequence.

Subject: fibonacci numbers

From: Maria

Date: 19 Nov, 2008 01:12:01

Message: 8 of 10

oh tnx !!!! great!!! is working;)

Subject: fibonacci numbers

From: Roger Stafford

Date: 19 Nov, 2008 01:22:01

Message: 9 of 10

"Matt" <mjacobson.removethis@xorantech.com> wrote in message <gfvno1$mhd$1@fred.mathworks.com>...
> .........
> OK. Well, the left hand tail of the sequence obeys the difference equation
>
> F(-k)=F(-k+2)-F(-k+1), k=0,1,...
>
> You must solve this difference equation with boundary conditions
>
> F(0)=0, F(1)=1
>
> to get that half of the sequence.

  Matt, I think you will find that the same Binet formula works for negative values of n, so the use of difference equations can be avoided altogether.

Roger Stafford

Subject: fibonacci numbers

From: Matt

Date: 19 Nov, 2008 15:27:02

Message: 10 of 10

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gfvpnp$6tp$1@fred.mathworks.com>...
> "Matt" <mjacobson.removethis@xorantech.com> wrote in message <gfvno1$mhd$1@fred.mathworks.com>...
> > .........
> > OK. Well, the left hand tail of the sequence obeys the difference equation
> >
> > F(-k)=F(-k+2)-F(-k+1), k=0,1,...
> >
> > You must solve this difference equation with boundary conditions
> >
> > F(0)=0, F(1)=1
> >
> > to get that half of the sequence.
>
> Matt, I think you will find that the same Binet formula works for negative values of n, so the use of difference equations can be avoided altogether.
>
> Roger Stafford


OK. Well, then I don't know what problem with negative n that Maria was refering to...

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us