1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to create a simple mathematical model!

  1. Dec 10, 2012 #1

    I am really not very good with math... over the years, I totally lost it. But today, it caught up with me... LOL! I hope someone can help me.

    In my spare time I am fiddling around with proximity sensors. I have a proximity sensor that accepts 135 steps. Therefore, when I am at step 135, the sensor is able to detect an object 0 inches away. When I am down at step 0, the sensor is able to detect an object at 135" away which is the maximum distance. So as you can see the higher the steps, the shorter the distance an object can be detected by the sensor.The lower the steps the further the object can be detected by the sensor. The problem is that the relation is not linear, its exponential????

    Therefore I need to make a relation between the number of steps and inches. Please view attachment for an example of the curve set by the steps vs the distance!

    Here are some definite coordinates that I measured:

    (0, 120)

    My question is, how can I develop a mathematical model (formula) so that just by looking at a step value I would be able to calculate the respective distance without looking at the

    Thank you all for your help.

    Attached Files:

    Last edited: Dec 10, 2012
  2. jcsd
  3. Dec 10, 2012 #2


    User Avatar
    Science Advisor

    The graph that you have drawn looks like a re-scaled circle (i.e. an oval or ellipse) with vertical and horizontal tangents at (0,120) and (135,0) respectively.

    If one hypothesizes that the center is at (135,120) and that the distance metric in the x direction is scaled down by a factor of 120/135 then a possible equation is:

    (120/135 (x-135))^2 + (y-120)^2 = 120^2

    You are probably better served by starting with a physical rationale for a curve of a particular form, parameterizing that curve in terms of several numbers and then performing a regression to see what set of parameters makes the resulting curve best fit your measurements.
  4. Dec 10, 2012 #3
    hi jbriggs444,

    I am wondering how you picked this formula. I tested it and it works...

    okay, I just picked this curve at random. I simply wanted to see how one would create a mathematical model. But by what u are saying, every type of curve has its unique characteristics.

    I will come back with the actual curve the sensor actually produces.

    thanks so much for your help!
  5. Dec 11, 2012 #4


    User Avatar
    Science Advisor

    I picked the curve type by eyeballing it. It looked like a circle tangent to the x and y axes and centered at (135,120).

    Of course, that's impossible. But it could be a slightly flattened circle. The formula for a circle centered at (i,j) of radius r is

    (x-i)^2 + (y-i)^2 = r^2

    A circle centered of radius 120 centered at (120,120) is then

    (x-120)^2 + (y-120)^2 = 120^2

    Scale up the x axis by a factor of 135/120 and this becomes

    (120/135 (x-135))^2 + (y-120)^2 = 120^2

    Now, by my count you are fitting a curve to seven data points:

    (0,120), (10,75), (35, 40), (70,15), (135,0), an assumption that the slope is infinite at (0,120) and an assumption that the slope is zero at (135,0).

    There are infinitely many curves that fit those seven data points. If you can pick a particular family of curves there will be a family member that best fits the data. The trick is picking the right family.

    If you pick the wrong family of curves you can wind up with something like "epicycles". That was an attempt to model planetary motion as circles within circles within circles. Add enough layers and enough parameters and you can always fit the observed data. But switch to using ellipses as the model and you can fit the data with only a couple of parameters.

    One measure of a good model is one that can fit the observed data with a minimum number of adjustable parameters.
  6. Dec 11, 2012 #5
    Hello jbriggs444,

    Okay, I have not had the time to really look at your last post yet... But I will do so as soon as I can. In the meantime I have re-measured the values from the sensor and you may view the actual values in the new attachment below. Now my question is, in which category of curves does something like this fall in!!!

    I would have to modify your equation a little I suppose... Please take a look at it and let me know if I can still use your equation!!! Tonight, when I get home, I will re-read everything and try to figure it out... But I still need your help, because I am sure I will have some relative questions!

    Thank you so much

    Attached Files:

  7. Dec 11, 2012 #6
    a little confused about the math. in the following link what is x and y values???

    (x-9)^ + (y-6)^ = 100 ???


    by visual analyses I know x should be 8 and y should be 0. but if h and k are the x/y coordinates of the center of the circle what does x and y values mean???
    Last edited: Dec 11, 2012
  8. Dec 11, 2012 #7


    User Avatar
    Homework Helper

    You have a classic curve fitting situation. You have a number of data points and want to know the 'best' equation that represents the data points. The best way to do this is to already know the type/family of equation, ideally based on the physics of the problem. Otherwise, there is very little basis to choose the equation/model except by looking at the data and making intelligent guesses based on the shape. That's exactly what jbriggs444 did. The example data you provided looked like a circle. In the second case, it's not clear that a circle is an appropriate model (my guess is no). Choosing a model isn't trivial. There are curve fitting programs out there (google searches would find them) that will check a variety of equation types and determine the best fit among the equations it tries, but that may or may not provide a satisfactory result.

    The second most important thing is to understand why you want a model of the data points. Is it for integration, interpolation, extrapolation, or something else? I'm guessing it is either for interpolation (i.e. reading between existing points) or extrapolation (i.e. predicting values outside the range of data you have). If you want to extrapolate, you need to be careful because extrapolation is h-i-g-h-l-y dependent on the model you use. Interpolation is much safer and is far less dependent on the model used.

    If you really have no idea what kind of model to use based on the physics, the easiest is to use a polynomial, based on the data you show. You can either fit a polynomial to exactly go through each point (could give strange results if the data doesn't fit very well), or a least squares fit of some sort with a low order polynomial. You could also fit cubic splines through all of the points. As jbriggs444 already stated, there are actually infinitely many functions that could be used to fit the data.

    If all you want to do is interpolate, it's probably safe to find a curve fitting program on the web and try low order polynomial (2nd or 3rd order) least squares fitting. If you want to extrapolate, I'd try very hard to find a relation from the physics of the problem. Otherwise you'll likely be disappointed in the result.

    P.S. the last plot you posted is missing 150 on the vertical axis.
  9. Dec 12, 2012 #8
    Okay I seem to have put some thought into it ... and I get it now!
  10. Dec 12, 2012 #9
    But this shape, isn't it from the parabola family?? for example:

    x^ + 2ax + a^

    Please view better curve attachment. After all the vertex seems to be (38, 130)!

    I have never used any such tool... I didn't even know it existed. But for me I prefer doing these things from scratch as it serves me well in learning math!!!

    In school I remember doing soooo many of these completing the square, polynomials, quadratics and so forth... But like many students we were always given an equation and asked to solve for 'x'. Now, in my case here, I have to work backwards in providing that equation!!! or mathematical model... and this is what confuses me!!!!

    Exactly. Interpolation!! From a step value, I need an equation (mathematical model) that solves for inches.

    Sorry for the ignorant questions, but what do you mean by extrapolation...??

    I don't know if this is what I need to do, it seems to be a lot of work as there are many possible points on that curve!!!... Isn't there a way that from knowing a few points we can develop an equation for any point?? I think this would be the best way.... I know how to solve for equations but I don't know how to work backwards to come up with an equation from knowing a few coordinate points??

    I would rather try to do it myself by someone showing me on how to come up with my own polynomial of some sort! Can you show me how?... or is this kind of stuff too complex? I don't deal with math very often... so I am a little slow... but willing to learn! Thanks so much! However still a little confused though!

    Yes thank you for pointing that out!!! I have corrected it!

    Thank you for all help!

    Attached Files:

    • C5.jpg
      File size:
      72.6 KB
    Last edited: Dec 12, 2012
  11. Dec 14, 2012 #10


    User Avatar
    Homework Helper

    You really need a basic understanding of linear algebra (matrix, transpose, inverse, solving a set of linear equations) in order to do this yourself. Basic calculus would help also (differentiation, function minimization). You also need a tool to carry out the calculations. For what you are trying to do, I'd think Excel would work if you have access to it. If you don't have any linear algebra or calculus background at all, it's really tough to understand the concepts. You're better off using a black box tool. I have Excel 2010 and it has curve fitting functions that are straightforward to use.
  12. Dec 14, 2012 #11
    I have Excel 2010 and it has curve fitting functions that are straightforward to use:

    I have excel... under which menu???

    I don't know if learning matrix, transpose, inverse, solving a set of linear equations would be easier to do then have excel do it for me....

    Telling someone to use excel to do this is still quite complicated...
    Excel asks to select a function out of a hundred or so functions... still not easy to do!!! :biggrin:
    Last edited: Dec 14, 2012
  13. Dec 16, 2012 #12
    simpComp, these are the instructions of fitting a line in Excel 2010:
    First fill two columns with both your observation values.
    Then, select both columns and go to Insert-Scatter and click the first type.
    Now you need to fit a line on those points:
    Click the graph and go to Chart Layout and select the type that has a "fx" symbol.
    You got a linear fitting by default. To change it, you need to click the line, then right click and go to Format Trendline...
    There you can choose the line that fits best to your data.
  14. Dec 16, 2012 #13


    User Avatar
    Homework Helper
    Education Advisor
    Gold Member

    EDIT: See the next posting, that no use of any matrix nor linear algebra were necessary.

    My thoughts are that the shape is part of either an ellipse or a circle, and you could form your system of equations from whichever points you wish and use a graphing Calculator to solve the system (as a matrix) for the unknown constants or coefficients.
    EDIT AGAIN: Part of those thoughts are not needed.
    Last edited: Dec 16, 2012
  15. Dec 16, 2012 #14


    User Avatar
    Homework Helper
    Education Advisor
    Gold Member


    Your original graph really looks like an ellipse portion. You can use simple information about a repositioned ellipse to find all the values you need for the standard ellipse equation. Refer to almost any Intermediate Algebra book. You have a point (0, 120) and you expect a point (135, 0). You see how they may be tangent to the x and y axes. Your long ellipse axis is the horizontal one, so a=135, and b=120. If you look where the tangency points are directed from, the tangency lines perpendicular to these tangency points should meet at the center of the ellipse, at (135, 120), your (h, k).

    Standard Ellipse, moved to center (h, k):
    ((x-h)/a)^2 + ((y-k)/b)^2 =1

    Fitting to your graph:
    ((x-135)/135)^2 + ((y-120)/120)^2 = 1

    I tried testing some of your points against this model, and the results are good.
    (10, 75): ~0.998
    (35,40): ~0.993
    (75, 15): ~1.04

    Notice that Linear Algebra was not needed for this elliptical fit.
  16. Dec 16, 2012 #15
    Wow, I never thought excel can do all of this.... and it can do all other sorts of curves... unbelievable !!!! Ardit, you really thought something new here :redface:

    So, I followed your instructions and I got the following graph as shown in the attachment showing the Excel spreadsheet. So it seems that the million dollar equation that I have been searching for is:

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

    I was off with the middle sign trying to do it as:

    y = ax^2 - bx + c ????

    How is one supposed to know that the middle sign would be a "+" instead of a "-"??

    Any how, based on my other attachment, the calculated values from Excel's equation seems to be a little off. I did it for two coordinates and in each one the answer is off by approximately 1.5??

    Is this normal??? Is it because of truncated precision in the decimal numbers... If so is there a way to increase this precision?

    Also, in the graph generated by Excel, what is R2?

    Thanks for your help!!!!

    Also, thank you all for your help, it is much appreciated!

    Attached Files:

    Last edited: Dec 16, 2012
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook