News:

  • September 25, 2026, 09:53:44 AM

Login with username, password and session length

Author Topic: Need a math whiz  (Read 9324 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Need a math whiz
« on: December 08, 2020, 10:56:40 AM »
  I'm trying to come up with a math formula for a setpoint curve, but can't quite figure it out.  I want to be able to pick random day numbers, write a setpoint for that day, and then have the program figure out the setpoint linearly for the days in between.
Eg day1  SP=40,     Day7   SP=50,   Day12  SP=60. So now I want to fill in all the days in between eg. day4 would be about 45.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Need a math whiz
« Reply #1 on: December 08, 2020, 11:12:33 AM »
LERP

(Nothing personal, suggesting you use the BRX instruction LERP for Linear intERPolation)   ;)
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Need a math whiz
« Reply #2 on: December 08, 2020, 11:32:42 AM »
If you wanted to roll your own, I wouldn't try to put the known points in a table with a line for each day, just leave the dates and SPs in one or two arrays of just the defined points.

Step through your array and calculate the Mx + b for each pair, then store the M's and b's in two additional arrays.

When you want to use the table, use COUNTIFLE on the date array to find the table index, then fetch the corresponding M and b, and do the interpolation calc.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Need a math whiz
« Reply #3 on: December 08, 2020, 07:30:47 PM »
Sorry, the second post is pretty much french to me. LERP doesn't really work, because the input (daynumber) really has no direct relation to the output(Setpoint.).

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Need a math whiz
« Reply #4 on: December 08, 2020, 11:32:51 PM »
Well, your collection of points DEFINES a set of transfer functions.  LERP is for exactly what you're doing.

Here's a video   https://www.automationdirect.com/videos/video?videoToPlay=9vP3oOABuW8

I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Need a math whiz
« Reply #5 on: December 08, 2020, 11:35:12 PM »
See attached

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Need a math whiz
« Reply #6 on: December 09, 2020, 11:19:09 AM »
Ok, now I got it working exactly like it needs to with LERP. Thanks for the help.