Jump to content
Server Maintenance This Week. ×

Linear number list


IanMaz

This topic is 1380 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi,

I am trying to create a script or function that will take an input of 3 numbers, min, max and count.
The function would then create a list of numbers, lets say 256 individual numbers, evenly spaced (or linearly if that’s the correct word) between the min and max values.

For example the beginning number would be 109 and the ending would be 3394.  I would need to fill the 254 numbers between them.
 

I really have no idea where to begin.  Math was never my strong subject.

Thanks for the help!!

Link to comment
Share on other sites

42 minutes ago, IanMaz said:

Math was never my strong subject.

It's actually pretty basic arithmetic. Start by calculating the interval between the numbers; in your example, this would be:

( 3394 - 109 ) / ( 256 - 1 ) = 12.8823529411764706

Now you can build a looping script that starts with 109 and adds the interval 256 - 1 times.

Note that due to rounding errors the final number might not be exactly 3394 - you can use the Round() function to compensate for that.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thanks for the help!  2am brain wasn’t working at all.

I managed to shove it in 2 custom functions and a script.  Depending on the starting/ending values, it will overrun by a few lines.
That’s ok, I added a dialog with a warning, now the user can remove the extras manually, which is better so they can determine which values aren’t needed.

Link to comment
Share on other sites

2 minutes ago, IanMaz said:

I managed to shove it in 2 custom functions and a script.

If you're using a script - which you probably* should - then there is no need for any custom functions. On the contrary, it's good practice to place all the required logic in a single place. The task itself is certainly simple enough to be handled by nothing more than a short loop, and I cannot imagine how you can possibly get it to "overrun by a few lines". Consider:

Set Variable [ $interval; Value:( Table::Max - Table::Min ) / ( Table::Count - 1 ) ] 
Loop
  Set Variable [ $result; Value:List ( $result ; Round ( Table::Min + $i * $interval ; 3 ) ) ] 
  Set Variable [ $i; Value:$i + 1 ]
  Exit Loop If [ $i ≥ Table::Count ]
End Loop
Set Field [ Table::Result; $result ]

 

---
(*) I am saying "probably" because you did not tell us what you intend to do with the result.

 

  • Thanks 1
Link to comment
Share on other sites

Just now, comment said:

If you're using a script - which you probably* should - then there is no need for any custom functions. On the contrary, it's good practice to place all the required logic in a single place. The task itself is certainly simple enough to be handled by nothing more than a short loop, and I cannot imagine how you can possibly get it to "overrun by a few lines". Consider:


Set Variable [ $interval; Value:( Table::Max - Table::Min ) / ( Table::Count - 1 ) ] 
Loop
  Set Variable [ $result; Value:List ( $result ; Round ( Table::Min + $i * $interval ; 3 ) ) ] 
  Set Variable [ $i; Value:$i + 1 ]
  Exit Loop If [ $i ≥ Table::Count ]
End Loop
Set Field [ Table::Result; $result ]

 

---
(*) I am saying "probably" because you did not tell us what you intend to do with the result.

 

Thanks, the custom functions splits out some of the functions that are used elsewhere for displaying some of the data.
But your script is better for the final data list.  Thanks again!  I will add that today.


My next step is to try to figure out if I can weight it.  The blue curve is the linear but needs to be more like the other 2.
They tend to be weighted down towards the middle.  I am trying to make up for a data set the originating application keeps messing up on that particular channel.

I am trying to research the proper terminology, I think its an exponential curve but im probably wrong.
Any ideas on how to create that data set?

Thanks!

Screen Shot 2020-07-15 at 2.59.07 PM.jpg

Link to comment
Share on other sites

6 minutes ago, IanMaz said:

The blue curve is the linear but needs to be more like the other 2.

I am afraid this is rather obscure requirement. Can you formulate it in terms of input and expected output? And also explain what is the purpose of this exercise?

 

Link to comment
Share on other sites

2 minutes ago, comment said:

I am afraid this is rather obscure requirement. Can you formulate it in terms of input and expected output? And also explain what is the purpose of this exercise?

 

I think the best way I can explain it is that the blue line (which is based on a linear progression from lets say 102-1800) should have a more S curve shape.

I have attached a txt file with the data.  The Data C is what I made up.
It should be more like Data B, weighted towards one end.

The purpose is to fix the data generated from a calibration application that’s failing on the blue line data.
Its an application from the early 2ks, developer is long gone but it’s the only app that works for this system.
It interpolates from a reading and outputs what it thinks is the next best number.
For whatever reason its failing only on one data channel.  According to someone familiar with it, its happened before but they cant remember the fix.  So I need to make up the data.

Hope that helps and Thanks again!
 

Data.txt

Link to comment
Share on other sites

I am afraid that makes no sense to me, sorry. I suggest you consult with a mathematician to arrive at a formula that should govern your graph. I am guessing you want a parabola or perhaps a quadratic equation, rotated (or an arc?). In the given example the formula you are looking for would generate y = 109 for x = 0 and y = 3394 for x = 255, with the interim values forming the curve you are looking for. Once you have such formula, you can use it to generate the y values - although I must say I fail to see how this relates to actual data generated by actual measurements. The interpolation and/or regression of such data are entirely different issues.

 

Edited by comment
Link to comment
Share on other sites

This topic is 1380 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.