1. Dec 17, 2012

### simpComp

Hello,

Help! I am stuck again

Okay, I vaguely remember how to factorize the following:

0 = 2x^2 + 5x - 7

The above is easy since all we have to do is find two numbers that when multiplied together gives us -14, and
we have to find two numbers that when added together gives us 5, hence, 7 and -2!!!

So it becomes:

(2x+7) (x-1)

Now I need to do the same factorization but for this:

114 = -0.026x^2 + 1.928x + 90.96
-0.026x^2 + 1.928x -23.04 = 0

Here, I have to find two numbers that when multiplied together gives us (0.026*-23.04) 0.59904 and
we have to do is find two numbers that when added together gives us 1.928... how do I find that

Is there a mathematical tool in Excel that can do this for me?

Once I can factor my equation I can come up with an equation where I can solve for x every time!
So no matter what y is, I can plug y into an equation and figure out x.

Last edited: Dec 17, 2012
2. Dec 17, 2012

### Staff: Mentor

There is a general equation for the solutions of a quadratic equation. If x1 and x2 are solutions, your equation is equivalent to (x-x1)(x-x2)=0.

3. Dec 17, 2012

### sjb-2812

You could always try completing the square. So for your "simple" example your equation is

2x2 + 5x - 7 = 0

x2 + 5x/2 - 7/2 = 0

(x+5/4)2 -7/2 -25/16 = 0

(x+5/4)2 -81/16 = 0

(x+5/4) = ± 9/4; so x =?

Alternatively, try something like http://mathportal.org/calculators/solving-equations/quadratic-equation-solver.php ?

4. Dec 17, 2012

### simpComp

thanks sjb-2812,

Okay I tried it with the calculator and it does work... please view attachment... GAWD!! this reminds me of high school and college!!!!!! To bad I don't have much time to review this stuff.

Any how, I would have to now find a way to enter this in my micro-controller so that, given any 'y' value I would be able to solve for 'x2'.

#### Attached Files:

File size:
31.8 KB
Views:
114
5. Dec 17, 2012

### jbriggs444

You should be aware that the quadratic formula as usually presented can be numerically ill conditioned in some cases. The formula can be manipulated into a version that is less subject to such problems.

A quick trip to Google found a reference near the bottom of http://introcs.cs.princeton.edu/java/91float/

Look for item 17 there.

6. Dec 17, 2012

### simpComp

Well as shown in example calculator.. is it okay if I always put it in terms of a fraction and then multiply every term by the lowest common denominator as done in this case by 500???

7. Dec 17, 2012

### symbolipoint

The idea is to make the equation simpler, or easier to manage its solution. There are rational coefficients and since 500 is the lowest common denominator, multiplying both sides of the equation by 500 will clear the fractions.

8. Dec 17, 2012

### simpComp

Hello fellows... I am having a hard time..... jeeeze doing math once every 5 years is not fun!

Therefore I have tried sticking with the quadratic... since I won't be going with very much small numbers anyways... and also for simplicity. The completing the square way... is long in terms of programming... for now I will try the quadratic.

okay

So, I have tried two points on my graph and one works out but the other doesn't.

Given by Excel calculator here is the equation of the graph in Q1 attachment:

y = -0.026x^2 +1.928x + 90.96

In Q2 I used the quadratic formula to solve for x when y = 114. The result was very close to 14 which is quite acceptable. However, in Q2, when I tried to solve for x when y = 126, x was way off.. does someone see something I am doing wrong. I was supposed to get 38.. instead I calculated 31 ??? Also, I did another point at: (30, 124)... when I tried to solve for x when y is 124, I get 26.8" instead of 30". Why is it so imprecise ???

Also, I was wondering if the equation:

y = -0.026x^2 +1.928x + 90.96

can be used to figure out a y value of 140?? Because, that's what I need, I may require to go further on the x axis then what the graph shows...
Therefore I don't know if a quadratic is right here... confused!!!

In summary, the x axis can go til about 240 inches when the y axis is about 155 steps. I need a formula that no matter what the y value is, I can figure out the respective x value!
Here, in the office I can test up to about 54" max... but based on these values, isn't there a way that we can get a formula that will allow calculations up to when y = 155 steps???

PS. Please note that for these calculations, I didn't bother finding a common denominator as the calculator does at: http://mathportal.org/calculators/so...ion-solver.php [Broken] ?

Thanks for all help!

#### Attached Files:

File size:
67.4 KB
Views:
146
File size:
26.7 KB
Views:
124
• ###### q3.jpg
File size:
51.9 KB
Views:
97
Last edited by a moderator: May 6, 2017
9. Dec 17, 2012

### symbolipoint

SimpComp,

Not yet having looked at your q1,q2,q3 images yet, but having read of your checked values not conforming to all of your data, you may be able to obtain more reliable curve fitting using a higher degree polynomial. You only need to form the proper matrices and learn to use software technology for matrix handling, mostly for making "reduced row echelon" forms for your matrices. The programs can be your/a graphing calculator or an online web-based tool.

Back from your quadratic fit tries for your points (130,38) (132,30) (136,22) (142,14) (155, 6); you need to choose a combination of any THREE points to form a system of equations, make the matrix, and .... solve the system (meaning, you can use some technology to row reduce the matrix). I tried solving this system and I found two good combinations of data points and one bad combination of data points. I looked at how each solved system would work when I use the model to see how every point of the original data works in calculation. How well does each data point satisfy the modeled equation?
One of the good models was like, y=0.0554x^2-17.06x+1320

One thing you need to know by your own experience is, how consistant are your measurements for Steps and Distances From The Sensor? Do they give precisely the same results every time, or do they change every time you use the same Steps?

10. Dec 17, 2012

### symbolipoint

Visually, in image q1, a parabolic fit seems like a good choice. Notice, you have FIVE points to choose from. You only need a combination of ANY THREE points to find a model. Try a few different combinations of points and then check how each resulting model give computations that are near or not near.

11. Dec 18, 2012

### simpComp

Okay symbolipoint,

First and foremost, I want to thank you for your help and patience with me.

I have made some recent changes based on your suggestions. I re-calibrated my power supplies and swapped the axis of inches and steps. I think this will be easier if I solve for x from a given form of quadratic equation such as:

ax^2 + bx + c

Also I re-measured all the distances and this time I checked them 3 times each to make sure that they weren't changing on me.

The values are a little different since the power supplies have been meticulously adjusted. Please view the new graph copied from Excel. The new equation is now:

y = 0.054x^2 - 11.84x + 656.4

I now solve for x directly with this equation... I think this is much simpler for me. Therefore,
for a certain step value of 'x' I can solve the respective distance as y just by plugging in x in the above equation!!!

So, based on the above equation, I have tried calculating certain coordinates as shown in my other attachments. I tried the following coordinates:

(110,6)
(125,22)
(135,38)
(137,54)

I notice though that the higher I go in step wise 'x', the more error is in the distance???

I don't understand why this cannot be more precise???

Another thing is, what is the R2 in Excel's graph?? >>> Root #2 ???

The only thing is, if I try to solve for 150 steps... I would not know how off my distance is... cause I don't have enough room in my office to try such a distance LOL!!!!
But given the amount of error in the above coordinates, I don't think I can trust this equation for greater distances than 54"...
given the fact that already at this distance I am off 6 inches!! :surprised

Also, in the Excel graph, which doesn't the line stretch til the last coordinate (137, 54) ??

In any case, if you can, please get back concerning these issues... It would be greatly appreciated!

thanks so much for your assistance!

Thanks all!

#### Attached Files:

File size:
62 KB
Views:
115
File size:
56.2 KB
Views:
93
• ###### Calc2.jpg
File size:
44 KB
Views:
129
Last edited: Dec 18, 2012
12. Dec 18, 2012

### Staff: Mentor

It is a measure of the fit quality. R^2=1 would be a perfect fit, R^2=0.941 shows that your data deviates from the fitted function.

It is plotted up to 137 and the corresponding y-value. You can extend this manually in Excel.

It would be useful to know more about your data source. What do you test/measure? Is there any reason to expect a quadratic formula, or something else?

13. Dec 18, 2012

### simpComp

Hello mfb,

I tried to click on line and then select the last plotted dot and tried to drag it to the non-plotted dot... but that didn't work ???

Well, one thing I just noticed, it seems to have to do with Excel!!!! Consider the following graph which I altered a little... It almost pretty much gives a linear line... but its not...
its still a parabola.

However when I use the suggested equation to calculate y for the first point (6, 109) the result is 0.451 " ??? Which in respect to the graph is totally erroneous!!!

Bof!!! we are supposed to come close to 6"
You can try it yourself !!!

Weird!

Here is what I tried:

y = 0.009x^2 - 0.272x - 76.83
y = 0.009(109)^2 - 0.272(109) - 76.83
y = 0.451 ????

Thanks!

#### Attached Files:

• ###### C11.jpg
File size:
47.8 KB
Views:
93
Last edited: Dec 18, 2012
14. Dec 18, 2012

### Staff: Mentor

Well, this is not an Excel help forum, and I don't even know which version you use, but you could try this:
Right-click on the fitted line -> "format trend line" -> "trend line options" -> "forward" -> 2.0 (or other values)
I translated the labels to english, the real names might be different.

That is a result of the finite precision of the given equation - try formulas like
y = 0.0092x^2 - 0.272x - 76.83
y = 0.0094x^2 - 0.272x - 76.83
They all get rounded to 0.009, but give different results if you compute values based on this equations. You can reduce this problem if you use "distance-100" instead of distance in your graph.

15. Dec 18, 2012

### symbolipoint

Exactly! Back in my post #9, a suggestion is made that higher order polynomial fit may give better results. I also tried an exponential fit but the resulting model with found values was bad.

16. Dec 18, 2012

### simpComp

Okay guys... this is what I have came up with!

I played around with the first coefficient and the values are pretty close. Please view the attachment!

Row "K" holds my steps and "L" holds my respective distances actually tested.

Row "O2" to "O11" holds the values actually calculated by the equation.
Note, row "O1" holds the first term coefficient which I played with in order to get the best results possible.

So the whole equation I will enter in my program will be:

f(x) = 0.000731x^2 + 1.619x + 175.6

I have done the tests up to 120" and the equation pretty much holds +/- 2" tolerance. I can't do any physical tests passed 120" b/c my room is too small LOL!!!

I could try to rely on the equation for distances greater than 120" but I don't know how precise this will be... According to formula if I have 190 steps I would have a distance of 158.3" !!!!

But in any case, for now, if the distance is passed the 120" mark, I will just indicate on my screen:

"> 10 feet" ...

step 158 gives a calculated distance of 98.4" which is the only one that is a little more off than the others (should be 96"). According to this chart of values, how can I specify the error tolerance factor? Can I take the reading with the most error.. for example the 98.4" is the one with the most error, can I express it this way:

Error tolerance worst case scenario:

2.4"/120" = 0.02 or 2% error max

Anyways these tests were done with a solid object. Tomorrow, I will have to try it with a human hand. I expect a different equation since infra-red goes through the human hand and results in less infra red bouncing back to the sensor!!

#### Attached Files:

• ###### FinalCurve_Obj.jpg
File size:
42.8 KB
Views:
112
17. Dec 18, 2012

### symbolipoint

You are now using a function, f(x) = 0.000731x^2 + 1.619x + 175.6, with such a small coefficient on x^2, and your graph image in the attachment looks like a line. You seem to have an interval of steps for which a linear model will work very, very well. Below ~110 steps, your model may need to be a curve.

18. Dec 18, 2012

### simpComp

well, I don't need any measurements below 107 steps!!!

I will look into using a linear model...

Last edited: Dec 18, 2012
19. Dec 18, 2012

### symbolipoint

The ordered pairs shown in your FinalCurve_Obj.jpg image attachment can be plotted onto a cartesian coordinate system, and a best line can be drawn. Any points on the line can be used for finding slope, and several points can be used for finding a y-intercept, an average of these taken, and then this can be used as the best y-intercept. I tried this and found a line to fit as
y=(114/63)x-188

Similar to what you said, near x=148 and x=158, the resulting y deviates about 3 inches from what you expected. Much of the rest of the line is a very good fit.

20. Dec 19, 2012

### Staff: Mentor

Careful with mixing relative and absolute error, the value for 112 steps has a larger relative error.
I agree that 2-3 inch are a reasonable value for a maximal error (not including possible measurement uncertainties), but the relative error can be large for small values in column L.