Discuss Scratch

l0ve1y
Scratcher
100+ posts

How can I make powers in Scratch?

I need to know how to make powers in Scratch! The reason is… my oldest brother (who's a computer science major) has just given me a challenge to create a program that calculates Fibonacci numbers. So I looked up the formula, and it says this: (1.168)n÷√5 (the ‘n’ is supposed to be a power), and then you round it to the nearest whole number. I can do most of the formula in Scratch, but I can't figure out how to do the power! I've tried and tried, and I can't do it!! I need help!







l0ve1y
dracae
Scratcher
1000+ posts

How can I make powers in Scratch?

You don't neccessarily need that formula.
You could just use the recursive formula: n(a) = n(a-1) + n(a-2)
Lone-Wolf
Scratcher
87 posts

How can I make powers in Scratch?

Well, powers are multiplied multiples. So as you may know, 3^2 is 3*3. You could use this method, or there is an operator that MAY work. At the very bottom of the operator page is a green block. This appears to have square roots in it and similar functions. That might work. (Maybe .3.)
l0ve1y
Scratcher
100+ posts

How can I make powers in Scratch?

dracae wrote:

You don't neccessarily need that formula.
You could just use the recursive formula: n(a) = n(a-1) + n(a-2)

And what does ‘a’ stand for?
mitchboy
Scratcher
1000+ posts

How can I make powers in Scratch?

l0ve1y wrote:

I need to know how to make powers in Scratch! The reason is… my oldest brother (who's a computer science major) has just given me a challenge to create a program that calculates Fibonacci numbers. So I looked up the formula, and it says this: (1.168)n÷√5 (the ‘n’ is supposed to be a power), and then you round it to the nearest whole number. I can do most of the formula in Scratch, but I can't figure out how to do the power! I've tried and tried, and I can't do it!! I need help!
l0ve1y
Well, I had a project on this, but apparently my test account didn't get transferred or something.

Anyway, here's how I did it:
when green flag clicked
set (number) to (1)
set (prev. number) to (0)
add (prev. number) to (Fibonacci numbers)
add (number) to (Fibonacci numbers)
repeat (however many you want) times
set (number) to ((number)+(prev. number))
set (prev. number) to (item [last v] of (Fibonacci numbers)
add (number) to (Fibonacci numbers)

This should work. If it doesn't tell me. I hope this is what you meant.
DadOfMrLog
Scratcher
1000+ posts

How can I make powers in Scratch?

x ^ y = e ^ ( y * ln(x) )

Look amongst the green operators (in the drop-down that shows “sqrt”), and you'll find both e^ and ln (that's known as “natural logarithm”) - so you can do it via those.

Try it with, for example, e^(5*ln(10)), and you'll get the answer 100000, which is 10^5.
dracae
Scratcher
1000+ posts

How can I make powers in Scratch?

Here's the easy way to do it: http://scratch.mit.edu/projects/10330799/
See inside to see how I did it!
Hope I helped!
kayybee
Scratcher
1000+ posts

How can I make powers in Scratch?

Yeah, I think you should do the original way of Fibonacci, the formula isn't exact as the phi is an estimate.
dracae
Scratcher
1000+ posts

How can I make powers in Scratch?

kayybee wrote:

Yeah, I think you should do the original way of Fibonacci, the formula isn't exact as the phi is an estimate.
Of course, you could just use the rounding block to make it.
Though other ways are more convenient. : |

Last edited by dracae (May 20, 2013 01:55:42)

mitchboy
Scratcher
1000+ posts

How can I make powers in Scratch?

Here. This project has square numbers, triangular numbers, and Fibonacci numbers.
DadOfMrLog
Scratcher
1000+ posts

How can I make powers in Scratch?

Using “round( 1.618034^n / sqrt(5) )” should be fine to find the nth value (assuming you don't want to find all the digits, accurately, as n gets into the hundreds).

i.e. with the e^ and ln: round( e^(n*ln(1.618034)) / sqrt(5) )
kayybee
Scratcher
1000+ posts

How can I make powers in Scratch?

I still think you should do it the original method by calculating numbers by adding the previous two.
dracae
Scratcher
1000+ posts

How can I make powers in Scratch?

kayybee wrote:

I still think you should do it the original method by calculating numbers by adding the previous two.
I agree with kaybee. This method is easier, and makes more sense.
DadOfMrLog
Scratcher
1000+ posts

How can I make powers in Scratch?

Well, it'll certainly be more accurate to use the addition formula - that should be a more accurate computation over more digits than using the e^ and ln.

Does quick check…

Yes, using e^ and ln it breaks down when n=43 (that's even with a more accurate value of 1.6180339887), which means those operators must be pretty low accuracy. Using addition it breaks down by n=79.

OK, here's something that's a bit more of challenge then…

Write a script in Scratch that uses the addition method to calculate Fibonacci numbers, but which *doesn't* break down.
In fact, make it work to at least n=5000, if not theoretically infinite - assuming you have that much memory and time
(Hint: use the numbers as strings and work in chunks that it can deal with…)

Once you've done that you should be well on your way to figuring out how you could do things like calculate pi to many thousands of places…
(Has anyone done that yet with Scratch…?)
Hmmm, should we rename this topic “Fun with maths”…?

Last edited by DadOfMrLog (May 20, 2013 12:52:59)

woodchester50
Scratcher
60 posts

How can I make powers in Scratch?

I have made a really simple engine that doesnt involve triangle or Fibonacci or decimal numbers.
whenclickedforeveraskNumber?andwaitsetAtoansweraskPower?andwaitsetBtoanswerbroadcastmessage1andwaitsayAnswerfor2secswhenIreceivemessage1setCtoAsetAtoArepeatB-1setCtoA*CsetAnswertoC

Last edited by woodchester50 (May 16, 2015 19:22:52)

iheanyi06
Scratcher
5 posts

How can I make powers in Scratch?

All you have to do is make costumes one to superpowers costume and one do normal costume. Then
Sprite1whenbackdropswitchestowhen blankkeypressedswitchcostumeto super power.Sprite2whenIreceive superman....;)Hopethishelpedbye:):D:lol:
PikaPal54
Scratcher
100+ posts

How can I make powers in Scratch?

Please don't necropost.

Powered by DjangoBB