Advertisement

Formula needed to describe this pattern.

Started by January 07, 2003 11:28 AM
10 comments, last by MatthewB 22 years, 1 month ago
I need a formula where Y evaluates to 1 while X is in the range 1-5, and then Y exponentially increases for X > 5. I don''t care about X < 1 since I will only be using it in my application if it is an integer greater than 0. I tried Y = (X * (X-5)) + 5 But that is only true for X = 1 and X = 4. Any ideas? Thanks.
If X is an integer you''ll need something like

(X-1)*(X-2)*(X-3)*(X-4)*(X-5)

and then do some compensating for the extra factor introduced.

Can''t you just use an if...else though?

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement
I could do Y = (X * (X-6)) + 6 and then
IF (Y < 1) Y = 1;
but I was hoping to have one formula do it all for me.
What is your application?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Just define it piece-wise. The formula you are asking for is not derivable at x=5, so none of the basic continuously derivable functions will fit.

Cédric
Oops, double post.

[edited by - matthewb on January 7, 2003 1:20:17 PM]
Advertisement
I have a "spinner" button, that as I hold down on the mouse and move sideways it increments the amount in a textbox next to it. So at lower movement speeds, I want the incrementation to be very precise, while at higher movement speeds to increase rapidly.
Actually, Paradigm Shifter provided a solution that will work for the bottom half anyway.
Y = (X-1)*(X-2)*(X-3)*(X-4)*(X-5) + 1
A little lengthy, but better than multiple IF statements.


[edited by - matthewb on January 7, 2003 1:25:10 PM]
After modifying Paradigm Shifter''s formula to this, it does what I need it to. Thanks.
Y = ((X-1)*(X-2)*(X-3)*(X-4)*(X-5))/(2*X) + 1
On second and third thought, it would be simpler to do it with a switch statement:

  switch (diff){    case 1:    case 2:    case 3:    case 4:    case 5:        retval = 1;        break;    default:        retval = diff * diff;        break;}  

This topic is closed to new replies.

Advertisement