Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Mathematical Challenge!
- bobbybee
- Scratcher
1000+ posts
Mathematical Challenge!
Y=5x^2 - 5x
Z=X*10
Z=X*10
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- ev3coolexit987654
- Scratcher
1000+ posts
Mathematical Challenge!
Y = 5(x-1)(x)
Z = X*10
Edit: D'aww… ninja'd.
Z = X*10
Edit: D'aww… ninja'd.
Last edited by ev3coolexit987654 (July 1, 2015 17:24:33)
- bobbybee
- Scratcher
1000+ posts
Mathematical Challenge!
On deriving the above equations:
Z is pretty simple. It's a linear equation; you're simply multiplying every number by 10. Not too hard, eh?
Y is more interesting, however. We have this data set : . To simplify this a bit, I will rewrite the data set as : . That is, I subtracted 1 from all of the X values and divided all of the Y values by 10.
Take a moment looking at those Y values. There's something interesting you might notice:
1 - 0 = 1
3 - 1 = 2
6 - 3 = 3
10 - 6 = 4
It's… counting! Naively, we might want to express this as a recursive function:
f(x) = f(x - 1) + x
But there is a better way, of course! Let's expand this recursive function a bit:
f(0) = null + 0 = 0
f(1) = f(0) + 1 = (null + 0) + 1
f(2) = f(1) + 2 = ((null + 0) + 1) + 2
….
You might notice something:
f(N) = the sum of all of the natural numbers up to and including N.
Say, what does that help us? Well, turns out there is a brilliant formula derived by a young child that computes that very function (That young child was Gauss, by the way):
f(N) = n*(n+1)/2 = n^2+n/2
Well, we're done, right? We have our formula? Not quite. Remember, at the beginning we changed every N to be X - 1. Therefore, we now need to substitute in N to be X - 1.
f(X) = (X-1)*(X-1+1)/2 = X*(X-1)/2
And finally, we divided all of the Y values by 10, so we have to multiply that function by 10 to account for the change.
f(X) = 10*X*(X-1)/2 = X*(X-1)*(10/2) = 5*X*(X-1) = 5x^2 - 5x
Z is pretty simple. It's a linear equation; you're simply multiplying every number by 10. Not too hard, eh?
Y is more interesting, however. We have this data set : . To simplify this a bit, I will rewrite the data set as : . That is, I subtracted 1 from all of the X values and divided all of the Y values by 10.
Take a moment looking at those Y values. There's something interesting you might notice:
1 - 0 = 1
3 - 1 = 2
6 - 3 = 3
10 - 6 = 4
It's… counting! Naively, we might want to express this as a recursive function:
f(x) = f(x - 1) + x
But there is a better way, of course! Let's expand this recursive function a bit:
f(0) = null + 0 = 0
f(1) = f(0) + 1 = (null + 0) + 1
f(2) = f(1) + 2 = ((null + 0) + 1) + 2
….
You might notice something:
f(N) = the sum of all of the natural numbers up to and including N.
Say, what does that help us? Well, turns out there is a brilliant formula derived by a young child that computes that very function (That young child was Gauss, by the way):
f(N) = n*(n+1)/2 = n^2+n/2
Well, we're done, right? We have our formula? Not quite. Remember, at the beginning we changed every N to be X - 1. Therefore, we now need to substitute in N to be X - 1.
f(X) = (X-1)*(X-1+1)/2 = X*(X-1)/2
And finally, we divided all of the Y values by 10, so we have to multiply that function by 10 to account for the change.
f(X) = 10*X*(X-1)/2 = X*(X-1)*(10/2) = 5*X*(X-1) = 5x^2 - 5x
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- ev3coolexit987654
- Scratcher
1000+ posts
Mathematical Challenge!
Java implementation
import java.util.scanner; public static void main(String[] args){ System.out.println("Enter x: "); Scanner scanner = new Scanner(System.in); int num = Integer.parseInt(scanner.nextLine()); long x = num; long y = 5 * (x - 1) * x long z = 10 * x System.out.println ("X: " + x + " Y: " + y + " Z: " + z); }
- bobbybee
- Scratcher
1000+ posts
Mathematical Challenge!
Thanks guys! I can always count on Scratchers for equations.
Was my explanation sufficiently lively for you? Haha :p
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- turkey3
- Scratcher
1000+ posts
Mathematical Challenge!
Frankly it confused me a bit XD but fortunately you have it in simple form in your first post.Thanks guys! I can always count on Scratchers for equations.
Was my explanation sufficiently lively for you? Haha :p
Also, in the equation is it (5x)^2 or 5(x^2)?
Last edited by turkey3 (July 1, 2015 18:06:41)
- ev3coolexit987654
- Scratcher
1000+ posts
Mathematical Challenge!
What did you even need this for?
By the way, I had to post the java program
By the way, I had to post the java program
- bobbybee
- Scratcher
1000+ posts
Mathematical Challenge!
Oh, neatI needed it for Floddle to calculate level based on total XP. What did you even need this for?
By the way, I had to post the java program
Do also consider an exponential curve though.
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- bobbybee
- Scratcher
1000+ posts
Mathematical Challenge!
I was but I like the sum curve (or whatever it is )Oh, neatI needed it for Floddle to calculate level based on total XP. What did you even need this for?
By the way, I had to post the java program
Do also consider an exponential curve though.
It's just plain old quadratic
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- gtoal
- Scratcher
1000+ posts
Mathematical Challenge!
On deriving the above equations:
Z is pretty simple. It's a linear equation; you're simply multiplying every number by 10. Not too hard, eh?
Y is more interesting, however. We have this data set : . To simplify this a bit, I will rewrite the data set as : . That is, I subtracted 1 from all of the X values and divided all of the Y values by 10.
…
An old and pretty easy technique for deriving an equation is to construct a table of finite differences. http://math.illinoisstate.edu/day/courses/old/305/contentfinitedifferences.html
You can also use this technique in reverse to take an equation and expand the first few terms, and create an iterative solution using the table of differences to show you how to calculate each step. For example the sequences defined by x^2 or x^3 can be generated by simple adds and no multiplies. This used to be a useful technique in the days when multiplies did not exist in hardware or were at least extremely expensive. (See http://www.gtoal.com/src/squares/cubes.c.html as an example)
The sequence given here is generated by:
x = y = z = 0; for (;;) {x+=1; z+=10; printf("%d -> %d/%d\n", x, y, z); y+=z;}
Last edited by gtoal (July 11, 2015 23:29:56)
- gtoal
- Scratcher
1000+ posts
Mathematical Challenge!
It's just plain old quadratic
Well, to be pedantic, it coincides with a plain old quadratic for the given integer values. Without a more detailed specification, you don't know whether that formula holds outside the range or how it behaves between the given values…
G
- bobbybee
- Scratcher
1000+ posts
Mathematical Challenge!
It's just plain old quadratic
Well, to be pedantic, it coincides with a plain old quadratic for the given integer values. Without a more detailed specification, you don't know whether that formula holds outside the range or how it behaves between the given values…
G
It's a quadratic on the five integer values which are in its domain from the original problem..
Of course, there are infinitely many solutions which solve *just* the table, but it would be a reasonable assumption that OP wanted this one
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- Discussion Forums
- » Advanced Topics
- » Mathematical Challenge!