Getting data from a point on a non-liner graph

Andy1845c

Member
Join Date
Nov 2021
Location
Minnesota
Posts
1
Hello
I am hoping someone here can maybe at least tell me what I shlould read up on or if this is even possible.

Rockwell Studio 5000 is my environment

if I have a relationship like is expressed in the attached graph, is there a way I can use a PLC to pick point y and have it compute point x?
Has anyone done something like this?

I am far from a pro and struggling to get a start.

Capture.PNG
 
Based on the equation shown at the bottom of your graph. For any value of X, you can compute Y. I've done this type of thing many times for non-linear processes, such as defoamer additions, or converting density to percent solids.

A process engineer or similar, collects empirical data, plugs it into excel and excel produces an equation to fit the numbers given.
 
As noted by @Ken Moore, you can start with an X value and calculate a Y value directly.

Going the other way, from a Y value (position on vertical axis on plot) that you choose, to the corresponding X value (position on horizontal axis on plot), as requested in the original post, however has a problem: for many of the plotted Y values, there are multiple possible X values (roots).
 
Last edited:
I am assuming the dotted line is supposed to approximate the blue line. The dotted line generated by the polynomial does not match the blue line very well, duh.

If you have the data points that were used to generate the blue line then the simple thing to do is to do a linear interpolation between the points that made up the blue line. The blue line does look like it is made of segments. The problem with this is finding the which two point to interpolate between.

What is MUCH easier and I would do is enter the points that made up the blue line into a cam table, Rockwell's name for a cubic spline. This would provide a 3rd order interpolation which is much better than a first order interpolation. The nice thing about this is that Rockwell should provide a function that will then generate a y value given a x value using 3rd order interpolation. This eliminates the need to search through the table to find which two points to interpolated between.

I don't have RS5000 anymore. If would be best if you provided the x and y coordinates that were used to make the blue line. Some kind soul might enter these points in a cam table to show you.

I can show how this is done on other software.
 
As noted by @Ken Moore, you can start with an X value and calculate a Y value directly.

Going the other way, from a Y value (position on vertical axis on plot) that you choose, to the corresponding X value (position on horizontal axis on plot), as requested in the original post, however has a problem: for many of the plotted Y values, there are multiple possible X values (roots).

If OP does want to go from X to Y, then the approximation equation is there and it would not be difficult to code that into Studio 5000, but as @Peter noted, it may not be good enough. You could add a few more polynomial terms to try to get a better match, or do what @Peter said for the spline fit e.g. see this link.

Anyway, welcome to the forum!
 
[oh dear, now I'm hooked]

Hey @Peter,

If the dotted line is

  • 3E-5 x**3 -0.0063 x**2 + .4796 x + 6.summat
then the slope is the quadratic

  • 9e-5 x**2 -0.0126 x + .4796
Did I flub something there?

I ask because my calibrated eyeball tells me that dotted line has a zero slope with a positive second derivative (concave upward) at an X value near where the cubic term of the annotation is.

But when I solve for the quadratic roots I get this:
>>> import math

>>> print( (0.0126 + math.sqrt(0.0126**2 - 4*9e-5*.4796))/(2*9e-5))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
Huh? That error could only be a negative discriminant, right?
>>> print(0.0126**2 - 4*9e-5*.4796)
-1.3896000000000004e-05
Really?
>>> .0126**2
0.00015876

>>> 4 * 9e-5 * .4796
0.000172656
What am I doing wrong? I know I make a lot of mistakes, but now with the quadratic formula too?
 
...What am I doing wrong? I know I make a lot of mistakes, but now with the quadratic formula too?

Never mind, it's eXcel being useless eXcel as usual: the cubic term needs more digits, it's probably around 2.75e-5 or less; my calibrated eyeball tells me those local extrema near the inflection point are not too severe.
 
Curiously, the OP asked for how to implement the inverse of this function on Reddit:

https://www.reddit.com/r/PLC/commen...urce=share&utm_medium=ios_app&utm_name=iossmf

Which problem are we solving?

If your input is ‘x’ and output is ‘y’ then what I said there applies:

Lookup tables are costly with the precious few bytes of memory Rockwell provides. The function is small, fixed, and easily implemented as others have said with a CPT expression closely resembling the mathematical notation.

The other way around?

Piece-wise linear regression across the known range.
 
Anyway, if OP is going from X to Y and has the raw data, then @widelto's suggestion of FGEN is probably the quickest route to a solution; see this link.

If OP is going from Y to X, then there is no unique solution for the data presented.
 
@drbitboy, in #7 your derivative is correct but I can't tell what you are trying to achieve after that.
I didn't know about FGEN but if is is only piecewise linear then cam tables would be better of accuracy is required.

@drbitboy, do you know that
Code:
y=a*x^3+b*x^2+c*x+d
can be written as
Code:
y = ((a*x+b)*x+c)*x+d
It is more efficient since the operation is just a series of multiplies and add. Also, there is a little less error due to rounding or truncating floats.

@JeremyM, I thought the PLCs have lots of memory now. I stated above that it is best if the programmer doesn't need to determine which two points he is interpolating between.

Use cam tables/splines if accuracy is required
Use FGEN if piecewise linear interpolation is good enough.
Both methods will avoid the messy searching through a table to see which two points one is interpolating between.

We have not got a list of Xs and Ys.
 
@drbitboy, in #7 your derivative is correct but I can't tell what you are trying to achieve after that.

I was trying to annotate the axis (i.e. figure out the scaling); one way to do that would be to calculate the X and Y of the local minimum on the plot, and to do that I need to solve for the upper root of the quadratic that is the derivative.

The eventual goal was, once I know how to extract the XY data, to see if a higher-order polynomial could do a better job of modeling the data.

Anyway, I figured out the problem: it was the resolution of the posted model's coefficients.

We have not got a list of Xs and Ys.

Exactly, which is why I was fiddling around wasting time with the process above.

I didn't know about FGEN but if is is only piecewise linear then cam tables would be better of accuracy is required.

I'll bet that FGEN/piece-linear will be more than adequate.

@drbitboy, do you know that [...]

Umm, yes. This ain't exactly my first rodeo.

Both methods will avoid the messy searching through a table to see which two points one is interpolating between.

FGEN will take care of that, and anyway it's neither messy nor slow; cf. here.
 
1) The equation for the trend line shown is only third order. Excel lets you go to sixth. Keep increasing the order until R² stops increasing.

2) As Dr. Bitboy says, you generally need to use scientific notation with at least five decimal places in the coefficients to get reasonable results.

3) This is an irregular function, and you don't identify the physical parameters on x and y. You also don't give magnitudes of the x and y grid. Your plot could be right, or it could represent ± experimental errors around what should be a straight line or a sinusoidal curve. Consider the theoretical expectation of what the plot should be and adjust the equation accordingly.

4) To get the inverse function simply use another graph swapping x and y values and create a new trend line.
 

Similar Topics

All, I have a CompactLogix L33 and would like to get data from a height gauge. The gauge is a Fowler Sylac Mark VI with RS232 output. I can...
Replies
8
Views
2,575
Hi, Guys I'm trying to upgrade a device witch comms is thru a RS232. The PLC is a Compactlogix L16ER to a remote PIO 1734-AENT then on this PIO a...
Replies
22
Views
8,157
Hello Eveyone, I need your advice on one problem.I am using CompactLogix PLC.I am looking for some ways.So, that a PLC program can read data from...
Replies
26
Views
13,103
Hi all, I'm trying to use the Data Preserve Tool for Logix5k (CompactLogix controller) but I keep getting comms errors and I'm not sure why. I've...
Replies
4
Views
4,009
Hi, I have the following setup: PLC connected to HMI through RS485 communication. I have the program of PLC but I need to convert the HMI to other...
Replies
1
Views
2,680
Back
Top Bottom