Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2010-01-27 15:48:19

Raider0451
Member
Registered: 2010-01-27
Posts: 21

I am working on program and need a formula for scaling.

Hi,
This is what I want to happen and I dont even know if its possible.
The app uses two progressbars one is labeled en = energy level and the second is al = alcohol level
As the alcohol level increases. The amount deducted from en decreases and allows longer game play before having to purchase food or drink. If en = 0 game ends. So with the above given I believe I need the following variables to caculate for r = en reduction rate. Where the range rmin & rmax is values that determine the range of r. Also the maximum that rmax value can be is .99 and the minimum that rmin value can be is .1.

Rmx = range maximum preset before calculation by program selection for easy, medimum, hard
Rmn = range minimum preset before calculation by program selection for easy, medimum, hard
al = variable from 0 - 1000
al has to be reversed with this added into the formula
al = 1000 - al (al now is 1000 to 0) (this so when the vlaue of progressbar is high it will give lower reduction rate and when it is low it will give higher reduction rate)
r = the amount deducted from en level. This sets the speed at witch the energy level is decreased.

I plan on when in easy mode at having rmx = .5 and rmn = .1 and on hard rmx = .25 and rmn = .2.
But this has to be adjustable so I can tune the game.

  All of the above is needed because of game design. At night food purchase is very restricted and alcohol is about all that can be purchased because the only thing open is a bar. So this leads to a no win situation. When alcohol is purchased a certain amount of energy is also given. What I am trying to do is reduce the amount of energy deduction when the littleman has high alcohol levels.

I futher explaination is needed I can try but it has me scratching my head.roflol
Raider0451

Offline

#2 2010-01-28 05:06:36

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

As time marches on in the program, simply subtract values to the energy.
If alcohol is higher, subtract more, and subtract more times if on harder level of game.
If e < 0, game over.


igloo myrtilles fourmis

Offline

#3 2010-01-28 08:20:42

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

John,
  Your suggestion is a good one and that is the way I have it written now. 
 
  Maybe a breif discription of the program will help. The program is cartoon like with a man walking around a city picking up items that he can sell and money thats been dropped. He has to buy food and/or drink to stay alive. Once he has made enough money then he can get cleaned up and work to earn more money. He can purchase things like a home, cars and jewlery. All of these items he can use in some way. There is a bank where he can make investments, and deposits to different accounts. Also if certain accounts get overdrawn for a certain lenght of time this causes the game to end. There are Robbers, Police, and other people walking around. The robbers steal you money and Police arrest you for vagrancy or public drunk. You can take bus rides, a limo, a sports car ect. to your home. But you have to pay for all of this such as when you own a home you have to pay morgage or lease, lights, water, gas,and upkeep.

  Those are just a few thing that is in the program. There are quit few others and some that I have not added yet such as a cosino with a one armed bandit (that I have already written and it was a math nightmare). The slot machine is a good program by itself. I wrote it seperate because the size of the project was slowing my programming software down.

  The energy and alcohol level is the stall point. I cannot see a way of tiying them together other than using a calculation that as alcohol is increased the energy level rate of decrease is decreased. Their are multibale reasons for not using if statements to reduce the rate at certain points you. One thing is if your were watching the alcohol and energy when the change was made it would be very visable. Another is the time used by each if statement. I have only a certain amount of time available because of the graphics. The more if statements I used the worse the graphics flow. This program logic is very large.
 
Thanks John

Offline

#4 2010-01-28 09:00:50

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,711

Re: I am working on program and need a formula for scaling.

Perhaps make a polynomial that matches what you want. Polynomials are good for making general smooth curves (within defined limits).

Could you graph it, and we can suggest something.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#5 2010-01-28 10:00:10

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

Hi Mathisforfun,
You have open another door.  LOL
It has been so long since I made a graph that it will take me a little while to refresh my memory on graphs, and polynominal is a subject that I don't remember anything about. So allow me a little while to study these two areas so that I can present an intelligent reply. As I said in the introduction post I started reviewing algebra.  I think I need to finish this review before getting into other areas. It will not take long to finish because the way it is presented makes it so easy to understand. I think this site is great and just what I was looking for.

By the way while I was browsing I noticed a post you posted about studing Quantum Physics. I read  two or three pages of it. I understood it till it got to page two then it all went above me. LOL
Thanks I will make a graph and post it after I can review a little.

Raider

Offline

#6 2010-01-28 10:03:50

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: I am working on program and need a formula for scaling.

Hi Raider0451;

By all means brush up if you need to. I don't need the graph, I just need the data. So post it when you are ready.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#7 2010-01-29 08:59:44

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

Raider wrote:

I cannot see a way of tiying them together other than using a calculation that as alcohol is increased the energy level rate of decrease is decreased. Their are

I don't understand why if the alcohol level goes up, the energy reduction amount goes down, wouldn't the
amount you decrease by go up with the alcohol level?


igloo myrtilles fourmis

Offline

#8 2010-01-29 10:01:29

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

John.
  Yes it would in a standard calculation and that is one of the reasons I cannot get any of the formulas that I have used in PLC programming to work. In plc programming there is a calculation that is used to scale an input siginal 0 to 20 mv  to an output of 0 to 60 Hz. This uses a 16 bit register which has a maximum of  value of 32768. The 0 to 20 mv is converted to 0 to 32768 then a input minimum value(Imin) and input maximum(Imax) value is used to say that the 0 to 32768  =  Imin to Imax. In this way you can set the Imin to any value less than Imax and Imax can be set to any value greater than Imin and the result of the actual input value will fall between the two.  The output calculation takes this result and uses it with the Omax, Omin to calculate a value that falls between Omin and Omax. The output is then coverted to depending on Omin and Omax to Hz. Example 10 mv input siginal is coverted to 16384. This then is coverted if our Imin is 1000 and Imax is 10000 the the result would be 4500. if the 10 mv changed to say 5 mv with the same parameters then input would be 8192 and the result would be 2250.

I need this so that the value being deducted from energy is lower when the value of alcohol is higher. Alcohol is energy and alcohol is being deduct at 2x the rate of energy at this moment. But Alcohol at this moment does not affect the game except for the speed the man walks. So they have no reason to purchase alcohol but if they Know that it slows the energy rate down then they will be more apt to use alcohol. This will increase the fun by being arrested for public drunk and make gameplay adjustable as to hardness.

But either the formula I remember is incorrect or the requirements are very different. It is most likely my memory.

curtis

Last edited by Raider0451 (2010-01-29 10:18:02)

Offline

#9 2010-01-29 10:19:13

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

Okay, very well, I've used PLC's too by the way!! (in metal grinder machines)
Let's do an example.
Say you have an input range from 2.0 to 8.0 and want an output range from 300 to 900.
I will show how to do this...
First here is the answer in case you want to analyze it:
output = 100(input + 1)
If you plug in 2.0 or 8.0 into input above equation, you get 300 and 900 you will see.



How did I arrive at this equation however, I will show you below...

It has to do with plotting two points;
(2,300) and (8,900) because you want
2 to go to 300 and  8 to go to 900.


I knew an equation for a linear relationship or a straight line on a diagonal of the
form:
y = mx or more complicated,
y- constant1 = m(x - constant2)
Here's what I plugged in from this memorization :
(y-300) = ((900-300)/(8-2))(x-2)
simplify...
y - 300 = (600/6)(x-2)

output - 300 = 100x - 200
output = 100x + 100
output = 100(input + 1)
Sorry, i couldn't explain better yet...
It is very poor i know...

Last edited by John E. Franklin (2010-01-29 10:24:16)


igloo myrtilles fourmis

Offline

#10 2010-01-29 10:49:30

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

Raider, I'll do this one more time in case it helps.
Say your input range is 2.0 to 8.0, but now your
output range is 300 to 1000.
Answer now is:
output = (116 2/3)input + 66 2/3
One point is (2.0,300), the other is (8.0, 1000).
(y - 300) = m ( x - 2.0), where m
is a fraction.
m = ((1000 - 300)/(8-2))
m is the slope of the line.
It is like the gradient of going up  hill if 100 is degrees, well not really, that is different.
The tangent of the angle is actually the slope.
Rise over Run
Rise divided by Run
is slope
or m.

So
y - 300 = (700/6) (x-2)

y = 116 2/3 x - 233 1/3 + 300

I put the 300 on the other side the equation above.

y = 116 2/3 x + 66 2/3

those are two-thirds or 116.666666 and 66.666666

y is output.
x is input.

Hope that helps... smile


igloo myrtilles fourmis

Offline

#11 2010-01-29 10:55:36

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

John,
This is what I have been studing for the last two days. LOL
John,

  That is a much simpler formula than what used in the PLC's I have been using. They had a formula that could be divided into three parts the actual volatge input conversion, the result conversion and the output conversion. Very complex.

  I can see right off that it works for a positive conversion.

But what if you have the same parameters as above and you plug in an input of  1 or 9 then you get 200 and 1000. That is the problem I am running up on. That is when the input can be from 0 to 10 and I want the output range to be between 300 and 800 or 400 and 600 etc. Where the input is larger than the allowable range that is where I am running into trouble.

Curtis

Offline

#12 2010-01-29 11:03:37

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

I have plotted the parameters on a graph and would insert them but I am not sure how. I know that at the of post reply is the browse and I can find the imgage file then when I press img to insert it comes up with {img}/{img} am I supposed to type the location of the image into the brackets or what?

Offline

#13 2010-01-29 11:06:35

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

If the image is under 65536 bytes, you can upload it to our forum.
Otherwise use [im.g.e]http:stuff here [/imagimg] for a link to it.

I do not know how to do this without using an "if" statement in your code.
Because instead of a line that goes diagonally on graph paper forever, now
you want it to stop and go to zero, making a trapazoid.
If you can't stop the input signal somehow, I don't know how to stop the
output signal.  Maybe someone else has an idea.
Maybe the formula needs to have those pseudo-if thingy's like case-things.
Like ((x>8):0,or use formula here).  Do you have that in your language?

Another possibility is to use a hash table instead.
Get all your inputs into a simple format by using
divide or mod and int or ceiling and use an array to
jump to the answer.

Also another way is to take your inputs and mod them in a circle so
if you go out of range you start back at the left of your range.
The disadvantage, is the program still will do something you don't like,
but can you live with it?

Last edited by John E. Franklin (2010-01-29 11:12:38)


igloo myrtilles fourmis

Offline

#14 2010-01-29 11:17:39

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

Yes I can write any kind of math operation, with if's, do's,for's and <>=+*^: etc. or any combination. The only draw back is to many if statements and it will cause the application to slow down and this causes the 200ms update of parameters to be off. It's not a problem yet but will be. A math calculation would be much faster.

Offline

#15 2010-01-29 11:28:24

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

It does not actually go to zero it is restricted in the program to actually 100 to 1000. The al level is 0 to 1000 but where the calculation is made the level has to be above 100 and using one or two if statements will not hurt its if I have to use 10 or 12 if statements then it might become a real issue. I have already prevented certain program code for being run on every scan due to timeing problems.

Offline

#16 2010-01-29 11:32:23

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

I would recommend with the little I know to try (casting) the floating point input number to a whole number.
Such as WholeInputA = (long int)InputA;
Or such as:  WholeInputA = int(InputA);
Then have a really big array "getOutputVal[big number size]".
Then have a loop at initialization of program fill the
array with the answers for the output, given the inputs.
Then you will save time in the program, you will
not even need an equation.  And your out of
limits can be covered if the array is very large, hopefully, right?


igloo myrtilles fourmis

Offline

#17 2010-01-29 11:34:58

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

Hey That is a good Idea. I build the array automatically at with the form load and then only scan it for the correct answer to the plot.

Offline

#18 2010-01-29 11:40:17

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

I hope it works for you! smile


igloo myrtilles fourmis

Offline

#19 2010-01-29 11:42:24

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

Thanks John
I think this will work I only have to have 100 points of the plot to compare the al value to and the 2nd element of the array would be the answer or rate.

Thanks very much I was stuck and now I see light.

Curtis

Offline

#20 2010-01-29 11:48:09

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: I am working on program and need a formula for scaling.

Over-and-Out for now anyway...


igloo myrtilles fourmis

Offline

#21 2010-01-30 11:48:52

Raider0451
Member
Registered: 2010-01-27
Posts: 21

Re: I am working on program and need a formula for scaling.

Hi all,

John, Mathisfun and Bobbym after trying Johns method and it worked. But a little jumpy when it was scanning. So I went back to some old notes. It took a lot of searching about 2 hours going threw old notes and formulas to find it.
I thought they were lost in a move But my wife remembered seeing them in storage.
But I do not wish I had tried to find them before because it caused me to discover this site. I have learned more in the few days that I have been on this site than in several months in school.eekdizzydizzy

So the following is the notes and formula that will take an input and transform it to a value between a min and max.

Equations used in calculating a linear relationship:

Scaled value = (input value x rate) + offset

Rate = (scaled max. - scaled min.) / (input max. - input min.)

Offset = scaled minimum - (input minimum x rate)

Translation to needed to formula for use in program
Original             new            description

Scaled value =  r         = (rate of deduction)
scaled max.  =  rmax   = (r maximum scale)
scaled min.   =  rmin   = (r minimum scale)
Input Max     =  Imax   = ( Maximum value of al)
Input Min     =  Imin    = ( minimum value of al)
Rate           =  Rate1   = (calculated Value)
offset          =  offset  = (calculated value)

r = ( al * rate1 ) + offset
rate1 = ( rmax - rmin ) / ( Imax - Imin )
offset = rmin - ( Imin * rate1 )

This is the program line used in the computer

r = (al * (rmax - rmin) / (Imax - Imin)) + (rmin - (Imin * ((rmax - rmin) / (Imax - Imin))))

Thanks for your help waveup
I know I'll be on this site a lot
For now I have to get back to my program
But I'm Like a bad apple I'll keep showing up

Curtis

Last edited by Raider0451 (2010-01-30 12:20:22)

Offline

Board footer

Powered by FluxBB