# Matlab help plots, finding nth number....

• Mar 2nd 2010, 07:32 PM
Mathhelpz
Matlab help plots, finding nth number....
1) COOLnumbers are the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34 … As you can (probably) see, each COOL number is the sum of the previous two. ugly numbers, on the other hand, are the sum of the previous three.
a. Find the 19th and 119th ugly numbers.
b. Use “bar” to give a bar plot of the first 10 ugly numbers. Label your axes.
c. Plot the first 100 ugly numbers on a logarithmic y-scale. Do you notice anything? What might it mean?

Can anyone help me make this script for matlab?
• Mar 2nd 2010, 07:39 PM
CaptainBlack
Quote:

Originally Posted by Mathhelpz
1) COOLnumbers are the sequence 1, 1, 2, 3, 5, 8, 13, 21, 34 … As you can (probably) see, each COOL number is the sum of the previous two. ugly numbers, on the other hand, are the sum of the previous three.
a. Find the 19th and 119th ugly numbers.
b. Use “bar” to give a bar plot of the first 10 ugly numbers. Label your axes.
c. Plot the first 100 ugly numbers on a logarithmic y-scale. Do you notice anything? What might it mean?

Can anyone help me make this script for matlab?

We need the first three "ugly numbers" before we can start.

CB
• Mar 2nd 2010, 10:06 PM
Mathhelpz
alright ill get back to you,
could you put like what general matlab script i need to know? Like how would i find the nth term, using bar, and then plotting?
• Mar 2nd 2010, 10:21 PM
CaptainBlack
Quote:

Originally Posted by Mathhelpz
alright ill get back to you,
could you put like what general matlab script i need to know? Like how would i find the nth term, using bar, and then plotting?

The first 100 will be produced by:

Code:

```TriNacci=zeros(1:100); TriNacci(1:3)=[1,1,2];  %put the three initial values here for idx=4:100   TriNacci(idx)=TriNacci(idx-3)+TriNacci(idx-2)+TriNacci(idx-1); end```
or you could solve the recurrence and code the solution as a function of n

CB
• Mar 8th 2010, 08:06 AM
Mathhelpz
can you check if this is correct??

for n=1:119
phi=(1+sqrt(5))*(1/2);
F=((phi^n)-(1-phi)^n)/sqrt(5);
bar(1:10 ,F)
xlabel('numbers')
ylabel('range')
semilogy(1:100 ,F)
end;
• Mar 8th 2010, 09:05 AM
Jeroentje
I would say that

"
u(1)=1;
u(2)=1;

for kk=3:100;
u(kk)=u(kk-1)+u(kk-2);
end
"

would do the trick. Looking to u on a logaritmic Yscale you see a straight line. This indicates that u is some kind of logaritmic function.
• Mar 8th 2010, 11:09 AM
CaptainBlack
Quote:

Originally Posted by Mathhelpz
can you check if this is correct??

for n=1:119
phi=(1+sqrt(5))*(1/2);
F=((phi^n)-(1-phi)^n)/sqrt(5);
bar(1:10 ,F)
xlabel('numbers')
ylabel('range')
semilogy(1:100 ,F)
end;

Check what? These are the Fibonacci numbers (your so called COOL numbers) not your UGLY numbers.

CB
• Mar 8th 2010, 11:12 AM
CaptainBlack
Quote:

Originally Posted by Jeroentje
I would say that

"
u(1)=1;
u(2)=1;

for kk=3:100;
u(kk)=u(kk-1)+u(kk-2);
end
"

would do the trick. Looking to u on a logaritmic Yscale you see a straight line. This indicates that u is some kind of logaritmic function.

These are also the COOL-Fibonacci numbers.

CB
• Mar 8th 2010, 12:17 PM
Mathhelpz
Thanks for the help !
• Mar 8th 2010, 11:15 PM
Jeroentje
"
u(1)=1;
u(2)=1;
u(3)=2;

for kk=4:100;
u(kk)=u(kk-1)+u(kk-2)+u(kk-3);
end
"
• Mar 9th 2010, 12:25 AM
CaptainBlack
Quote:

Originally Posted by Jeroentje
"
u(1)=1;
u(2)=1;
u(3)=2;

for kk=4:100;
u(kk)=u(kk-1)+u(kk-2)+u(kk-3);
end
"

Which has already been posted in message #4 in this thread (only with better syntax)

CB
• Mar 10th 2010, 03:28 PM
Mathhelpz
i need help doing the bar plot....

u(1)=0;
u(2)=1;
u(3)=1;

for kk=4:119;
u(kk)=u(kk-1)+u(kk-2)+u(kk-3);
end

Find1 = u(19);
Find2 = u(119);

That's the program and it works for what i want to find.
How to I do the bar plot part..

* a. Use “bar” to give a bar plot of the first 10 ugly numbers. Label your axes.*

I Tried doing like bar (range(1:10))*u or something but that doens't seem right... Hope you can help
• Mar 10th 2010, 08:25 PM
CaptainBlack
Quote:

Originally Posted by Mathhelpz
i need help doing the bar plot....

u(1)=0;
u(2)=1;
u(3)=1;

for kk=4:119;
u(kk)=u(kk-1)+u(kk-2)+u(kk-3);
end

Find1 = u(19);
Find2 = u(119);

That's the program and it works for what i want to find.
How to I do the bar plot part..

* a. Use “bar” to give a bar plot of the first 10 ugly numbers. Label your axes.*

I Tried doing like bar (range(1:10))*u or something but that doens't seem right... Hope you can help

bar(u(1:10));

CB