Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: PLCwannabe on December 08, 2020, 10:56:40 AM

Title: Need a math whiz
Post by: PLCwannabe 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.
Title: Re: Need a math whiz
Post by: Controls Guy on December 08, 2020, 11:12:33 AM
LERP

(Nothing personal, suggesting you use the BRX instruction LERP for Linear intERPolation)   ;)
Title: Re: Need a math whiz
Post by: Controls Guy 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.
Title: Re: Need a math whiz
Post by: PLCwannabe 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.).
Title: Re: Need a math whiz
Post by: Controls Guy 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 (https://www.automationdirect.com/videos/video?videoToPlay=9vP3oOABuW8)

Title: Re: Need a math whiz
Post by: Bolt on December 08, 2020, 11:35:12 PM
See attached
Title: Re: Need a math whiz
Post by: PLCwannabe 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.