Need assistance with equation

Scantech

Well-Known Member
Licensed User
Longtime User
Any genius out there can help me figure out a single equation for DataUnitValue. My mathematics skill does not serve me well at this time. This works out ok, but I was concern what is the single equation for this?

Thank you

B4X:
   Dim Val, TotalVal, GridMax, GridMin, DataUnitValue As Float
   
   'Plug in any of these DataUnitValue will equal 0.5.  What is the single equation for this???
   'GridMax = 100: GridMin = -40: Val = 30      
   'GridMax = 100: GridMin = 10: Val = 45   
   'GridMax = -10: GridMin = -50: Val = -30
   
   TotalVal = GridMax - GridMin
   If GridMin > 0 Then
      DataUnitValue = (((Val - GridMin)/TotalVal) * 8)      'PART A: EQUATION USED FOR MIN VALUE ABOVE 0
   Else
      DataUnitValue = (((Val + Abs(GridMin))/TotalVal) * 8)   'PART B: EQUATION USED FOR MIN VALUE BELOW 0
   End If

   'Need to equal for 0.5 for the equation to be accurate, using the val above.
 

Kight Riot

Member
Licensed User
Longtime User
If you are wanting

Part A: DataUnitValue = (((Val - GridMin)/TotalVal) * 8)

and

Part B: DataUnitValue = (((Val + Abs(GridMin))/TotalVal) * 8)

a single equation ... maybe


Globals
Dim valueBelowZero, valueAboveZero as Int = 0

... Then in your code ...

If GridMin > 0 Then
valueAboveZero = 1
valueBelowZero = 0
Else
valueAboveZero = 0
valueBelowZero = 1

End If

DataUnitValue = (((((Val - GridMin) * valueAboveZero) + valueBelowZero) * ((Val + Abs(GridMin) * valueBelowZero) + valueAboveZero)) / (TotalVal * 8))

Whoa parenthesis overload.

I think, in this case, you would need to have a pair of "Int"s to help the equation along.

The equations should, essentially de-activate the equation not needed, making it equal to 1, which is then multiplied by the other half "activating" the required equation. If this wasn't what you needed sorry.

Let me know if this works ... or if it was super confusing.
Kight
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User

Thank you both for the reply. I think my mind is overwhelmed. Earlier, I used the equation Klaus suggested and thought I came across a problem with value not matching on the plot screen. The equation makes sense and I will recheck my work. It is late and I will check it out tomorrow. Thank you
 
Last edited:

Kight Riot

Member
Licensed User
Longtime User
Need to work out my Abs!

I came up with this crazy equation and totally didn't realize "Abs" was "The Absolute Value of", I was wondering what value you had given Abs and then didn't think twice. That being the case, the other equation would serve you better.

DataUnitValue = (Val - GridMin) / TotalVal * 8


By the way, my equation as written would not have worked out right, there was a parenthesis misaligned.
This one (though overly complacated) should work ... I think.

(((((Val - GridMin) * valueAboveZero) + valueBelowZero) * (((Val + Abs(GridMin)) * valueBelowZero) + valueAboveZero)) / TotalVal) * 8
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…