# How do I develop an equation to describe a line?

Discussion in 'Math' started by strantor, Oct 31, 2014.

1. ### strantor Thread Starter AAC Fanatic!

Oct 3, 2010
4,591
2,473
This is a real-world problem, not an academic exercise.

I have an analog proportional hydraulic flow control valve and its output flow is nonlinear with respect to its input signal. I would like to linearize it, because the joystick adjustment can be tricky, especially in the upper range of movement, between 80% and 100% flow.

I am currently writing an overly complicated 7-point piecewise scaling equation using the 7 points listed below.

This should work just fine, but if there's a way I can reverse-engineer this line and describe it with a single equation that would be ideal. The only thing I know to do is bust out the graphing calculator and plot an exponential curve and then start tweaking values until it looks close; so far I haven't come up with anything close enough to be acceptable (best was y=0.01x^2).

I know there's a better way to approach this, so what is it? Is there some software that could help a math dummy like me, or can someone please school me on how to do this the honest way?

Thanks,
Stantor

2. ### strantor Thread Starter AAC Fanatic!

Oct 3, 2010
4,591
2,473
Disregard; I have discovered Excel's trendline function. Apparently my data set is sufficiently described by the 3rd order polynomial equation y=.0001x^3 - 0.0087x^2 + 0.5708x - 1.0215

I heart excel

elec_mech likes this.
3. ### Papabravo Expert

Feb 24, 2006
11,076
2,152
This is done all the time in statistical modeling. So often in fact that `R' has builtin functions that fit all kinds of curves to various data sets. IIRC in most cases it is a matrix inversion problem at which `R' does an excellent job. Oh and it is still free by the way.

http://www.r-project.org/

jpanhalt likes this.
4. ### WBahn Moderator

Mar 31, 2012
20,059
5,655
You might look at using a quadratic instead of a cubic. It looks as though it might be a close enough fit and is easier/faster to compute.

5. ### djsfantasi AAC Fanatic!

Apr 11, 2010
3,486
1,245
Good point WBahn. And it's just a few clicks in the Excel chart to specify a quadratic equation.

6. ### studiot AAC Fanatic!

Nov 9, 2007
5,005
519
Whether you use a cubic or a quadratic or any other polynomial, you will not get a correct approximation to a graph that goes through the origin with a constant term in the polynomial.

7. ### Papabravo Expert

Feb 24, 2006
11,076
2,152
I would not expect the fit to go through the origin unless that was a specific condition. If the condition was to minimize the squared error for example. It is possible to formulate the problem in a way to require the solution to pass through certain points, or pass through certain points and have certain derivatives at certain points.

8. ### studiot AAC Fanatic!

Nov 9, 2007
5,005
519
Considering the purpose of the graph I most certainly would, otherwise the valve would be offering an output with no input or to put in another way be impossible to shut off.

This just shows how you have to be a litle careful when fitting curves, and use some engineering common sense as well as formulae.

9. ### joeyd999 AAC Fanatic!

Jun 6, 2011
2,964
3,782
atferrari and strantor like this.
10. ### Papabravo Expert

Feb 24, 2006
11,076
2,152
In terms of the error at the origin it is on the order of 1%. That could be more important than zero output for zero input, but your point is well taken. The fit with a constant still has a zero so it is not impossible to shutoff as you put it. Being a 3rd order polynomial you are guaranteed at least one real root. This is not true of a quadratic fit.

Yet another approach is to do a piecewise linear fit with say two or three segments.

11. ### strantor Thread Starter AAC Fanatic!

Oct 3, 2010
4,591
2,473
Thanks for the input, and I've bookmarked that software. I've played around with the equation that excel trend line gave me, and got acceptable results. But I've decided to abandon the equation in favor of the piecewise scaling. Reason being, the curve can change. The curve is a result of dynamic system parameters; If a mechanical adjustment is made to the valve (or a neighboring valve even), or the valve is replaced, or a new pump or new motor is installed, or fluid of a different viscosity is introduced, etc. etc. ... the curve could become more linear or less linear and/or have different end points. It will need to be field-calibration-friendly, and if I can't figure out how to generate and equation for the curve without consulting a panel of experts, I won't ask the end user to do anything of the sort. I will make a "Valve Output Teach" function, where the user adjusts the raw valve output in increments and observes flow feedback (0-100%) and clicks a " Teach" button at intervals of 20%, 40%, ... 100%.

12. ### studiot AAC Fanatic!

Nov 9, 2007
5,005
519
Creating a mapping of %full scale to position is a good way to go.
You already have two points 0% and 100%.
It also allows the addition of a temperature correction if required.

13. ### WBahn Moderator

Mar 31, 2012
20,059
5,655
I'd recommend, if it doesn't add too much code or complexity, the ability for the user to choose either which points to take data at or at least how many total points to take data at, up to some max number of points that you can store. This lets the system be very adaptable so that valves that are sufficiently linear (i.e., linear enough for the application) need only the basic two points while valves that are very non-linear can have as many as needed to linearize the response adequately. It would also allow more points in the regions with high curvature or where performance is more sensitive and few points in other regions.

14. ### shteii01 AAC Fanatic!

Feb 19, 2010
3,922
601
Using my calculator (Casio CFX-9850G), Statistic, Regression:
y=(0.91182788)X-10.283191
or
y=(0.01108248)X^2-(0.1678125)X+2.76215252
or
y=(1.2599*10^-4)X^3-(7.803*10^-3)X^2+(0.52662214)X-0.4615859
or
y=(1.1293*10^-6)X^4-(1*10^-4)X^3+(6.1917*10^-3)X^2+(0.25682719)X+0.12091362

The square does not quiet fit, but is close. The cube seem to fit pretty well.