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

1. ## 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?

2. 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

3. 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?

4. 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

5. 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;

6. 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.

7. 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

8. 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

9. Thanks for the help !

10. "
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
"

11. 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

12. 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

13. 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