So I was taking a break from my PvZ project in Scratch and trying to see what I could do in Scratch. So here's the thing: I sort of wanted to see if I could make a converter from say, sin(x°) to sin(xradians), which shouldn't be too hard, except here's the thing: sin(xradians) is sin(πx°/180)
Now here's where problems arise, because here is a representation of π:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
tex2jax: {inlineMath: [["$","$"]]},
CommonHTML: {
scale: 120
}
});
</script>
<script type="text/javascript" async src=
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=
TeX-MML-AM_CHTML"></script>
$\sum_{k=0}^\infty\dfrac{50k-6}{2^k\binom{3k}k}$
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
tex2jax: {inlineMath: [["$","$"]]},
CommonHTML: {
scale: 120
}
});
</script>
<script type="text/javascript" async src=
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=
TeX-MML-AM_CHTML"></script>
$\sum_{k=0}^\infty\dfrac{k!(2k)!(50k-6)}{2^k(3k)!}$
How would I format this in Scratch, since there's no code block for Scratch that would allow me to do this. The only workaround that I could possibly see happening is if somehow, there was a way to create summation and products in Scratch. Even in my first question on this site where I was wondering what I would be able to do since there wasn't a way to represent summation, it just turns out that the best that I could do would be something like this:
Raising stuff to a power code:
[scratchblocks]
define pow(base)(power)
set [result v] to [1]
set [base v] to (base)
set [power v] to (round (power))
set [done v] to [0]
if <(power) < [0]> then
set [base v] to [((1) / (base))]
set [power v] to [-1(() *(round (power))]
end
repeat until <[done v] = [1]>
if <(([power v]) mod (2)) = [0]> then
set [result v] to (([result v]) * ([base v]))
change [power v] by (-1)
end
if <(([power v]) mod (2)) > [0]> then
set [done v] to [1]
end
if <<not <<[done v] = [1]>>>
set [base v] to (([base v]) * ([base v]))
set [power v] to (([power v]) / (2))
end
end
[/scratchblocks]
And even then, if I want to write summation, I have to write the exponentiation individually, which honestly is just extremely annoying in my opinion. In fact, if you do want to see how it's written out, here is the link to the Scratch project that I asked about in my first ever question.
And just so people don't get angry and say that it's annoyingly difficult to find, a quick way to find it is by clicking on the "Buy 10 (cursorSprite1" sprite (which this isn't even a typo, this is actually how the sprite name would be typed out)
In fact, the only way I can think of even attempting to write this out would be like how the summation is written out: Looks simple, but has to be extremely complex just for it to work in a simple way. There would have to be a lot of variables/messages going out at the same time, and that would cause a great deal of lag. And I'm not even needing that much precision (only a sum from k=0 to 13), so it seems that it would only be trying to get factorials to work being an honest pain in the butt.
Is there a way that I could create factorials in Scratch, or if not, why and how?
Here's one way to calculate factorials in Scratch.
Think about how factorials are really calculated. You start at n and go down by one until you hit one, each time multiplying the your new number (eg: 3!=3x2x1)
This can be replicated in Scratch quite easily:
Scratchblocks format:
[scratchblocks]
when green flag clicked
ask [enter value for n] and wait
return=(answer)!
say (join (join (answer) [!=]) (return))
stop [all v]
[/scratchblocks]
[scratchblocks]
define return=(n)!
set [index v] to (n)
set [return v] to [1]
repeat ((n))
set [return v] to (([return]) * ([index]))
change [index v] by (-1)
end
[/scratchblocks]