You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old November 24th, 2021, 04:49 PM   #1
Andy1845c
Member
United States

Andy1845c is offline
 
Join Date: Nov 2021
Location: Minnesota
Posts: 1
Getting data from a point on a non-liner graph

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.
Attached Images
File Type: png Capture.PNG (6.0 KB, 67 views)
  Reply With Quote
Old November 24th, 2021, 04:56 PM   #2
Ken Moore
Lifetime Supporting Member
United States

Ken Moore is offline
 
Ken Moore's Avatar
 
Join Date: May 2004
Location: North, West, South Carolina
Posts: 3,212
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.
__________________
Certified Siemens Functional Safety Professional,
ID: SFSP17010238
NRA Benefactor
  Reply With Quote
Old November 24th, 2021, 05:01 PM   #3
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 3,853
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).
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.

Last edited by drbitboy; November 24th, 2021 at 05:17 PM.
  Reply With Quote
Old November 24th, 2021, 05:09 PM   #4
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: United Welfare States of America
Posts: 7,638
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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old November 24th, 2021, 05:24 PM   #5
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 3,853
Quote:
Originally Posted by drbitboy View Post
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!
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old November 24th, 2021, 05:25 PM   #6
widelto
Member
Colombia

widelto is offline
 
widelto's Avatar
 
Join Date: Jul 2005
Location: Barranquilla, Colombia
Posts: 3,107
@andy:

Have you tried FGEN ?
The FGEN instruction converts an input based on a piece-wise linear function.
__________________
My two cents.
  Reply With Quote
Old November 24th, 2021, 05:48 PM   #7
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 3,853
[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?
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old November 24th, 2021, 06:01 PM   #8
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 3,853
Quote:
Originally Posted by drbitboy View Post
...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.
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old November 24th, 2021, 06:08 PM   #9
JeremyM
Lifetime Supporting Member
United States

JeremyM is online now
 
Join Date: May 2014
Location: Dallas, Texas
Posts: 648
Curiously, the OP asked for how to implement the inverse of this function on Reddit:

https://www.reddit.com/r/PLC/comment...tm_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.
  Reply With Quote
Old November 24th, 2021, 06:12 PM   #10
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 3,853
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.
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old November 25th, 2021, 11:58 AM   #11
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: United Welfare States of America
Posts: 7,638
@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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old November 25th, 2021, 12:28 PM   #12
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 3,853
Quote:
Originally Posted by Peter Nachtwey View Post
@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.

Quote:
Originally Posted by Peter Nachtwey View Post
We have not got a list of Xs and Ys.
Exactly, which is why I was fiddling around wasting time with the process above.

Quote:
Originally Posted by Peter Nachtwey View Post
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.

Quote:
Originally Posted by Peter Nachtwey View Post
@drbitboy, do you know that [...]
Umm, yes. This ain't exactly my first rodeo.

Quote:
Originally Posted by Peter Nachtwey View Post
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.
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old November 26th, 2021, 11:04 AM   #13
Tom Jenkins
Lifetime Supporting Member
United States

Tom Jenkins is offline
 
Tom Jenkins's Avatar
 
Join Date: Apr 2002
Location: Milwaukee, WI
Posts: 6,180
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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Scaling temp. data in C-More Line Trend Graph Dan_S LIVE PLC Questions And Answers 13 March 9th, 2021 12:59 PM
Fatek Plc Floating Point Data Move ishak1057 LIVE PLC Questions And Answers 0 December 26th, 2020 05:34 AM
rs 500 long word data type use Controls Tech LIVE PLC Questions And Answers 3 December 12th, 2018 02:18 PM
Point IO IA4 module - where to find channel data? selectionplc LIVE PLC Questions And Answers 6 May 23rd, 2017 12:18 PM
Omron Cj1m glenncovington LIVE PLC Questions And Answers 10 March 7th, 2012 07:01 PM


All times are GMT -4. The time now is 08:31 PM.


.