Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A Plot a curve through some arbitrary points

  1. Apr 3, 2017 #1
    Hi how can i plot a curve (red curve at this example) like this:

    nonlinear.png
     
  2. jcsd
  3. Apr 3, 2017 #2

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    You could make a table of moving average y values (say 5 before and 5 after) versus x and put a spline curve through those points.
     
  4. Apr 3, 2017 #3
    Hi Auteng:

    I am not sure i understand what you are asking. There are two possibilities that come to mind.
    1. How to use a tool, like a spreadsheet, to plot sample points and a curve through the points.
    2. How to do the math to calculate the curve to be plotted.
    For this post I am assuming #2. Generally this means you want a curve of a certain type with the best fit.

    There are two things you need to specify.
    1. The criterion you want to use for "best fit". The most commonly used one is: least mean squared (LMS). From you use of the term "non-linear regression", I think this is the one you want.
    2. The type of curve. This may depend on the "best fit" criterion. Examples assuming LMS: quadratic, cubic, sinusoidal, exponential, and many more.

    Each kind of curve is usually based on a type of physical model for the source of the data points. Sometimes there are many reasonable models, so you fit the points with many curves, and then decide which is the one you want to use. For example, it you are using polynomials, the higher the maximum exponent the smaller the error. There are criteria you can use to tell you when to stop. The criteria are based on how much relative reduction you get from adding one more term to the polynomial.

    Hope this helps.

    Regards,
    Buzz
     
  5. Apr 3, 2017 #4
    How can i do it with MATLAB or EXCEL?
     
  6. Apr 3, 2017 #5
    Hi Auteng:

    I don't know MATLAB, but I am quite familiar with EXCEL. I don't have time now to give a long explanation, but you need to decide on what you want to do. Do you want to use polynomials? Do you have in mind a specific number of terms?

    I will look for your responding post in a few hours.

    Regards,
    Buzz
     
  7. Apr 3, 2017 #6
    I want a sin diagram that decay with time
     
  8. Apr 3, 2017 #7

    jedishrfu

    Staff: Mentor

  9. Apr 3, 2017 #8
    Hi Autang:

    I have a few minutes before I have to leave for a few hours.

    Are you saying the x-axis represents time? The picture shows a general increase of y-axis values as x increases. Why do you think the pattern should be a decaying sine function? You might have a linear function plus a sine with a decay, but if there is any decay it seems to be towards x = 0. From physical processes I can think of, I would expect a sine function to decay as time increases.

    Regards,
    Buzz
     
  10. Apr 3, 2017 #9
    I don't think the figure in the first post is the OP's actual data, it is just a figure showing what he wants to do: find the red curve for "his" data.

    To the OP: in excel what you want to do is called a "Trendline." Use excel help to explain how to make a trendline for your data. I don't think you are going to fine a decaying sine curve as a built in choice in Excel though. You're going to need to get trickier in Excel.
     
  11. Apr 3, 2017 #10
  12. Apr 3, 2017 #11
    Hi Autung:

    Sorry, I was unable to download your data. If you can take a screen shot of the graph of the actual data points, you can upload a PNG file attached to your next post with the image.

    If you are confident that the curve you want is a decaying sine function, there are many ways to proceed. The way I am going to suggest is not the best way, but I think it is the easiest to understand what is going on.

    First, recognize that the function you want to fit has four parameters, A, B, C, and D in the equation below.
    y = A × sin ( B × (x + C)) × e-(D × x)
    You can assume A, B, C, and D are all positive, and assuming that the sin function is with respect to radians, C is limited by
    0 ≤ C ≤ 2π.​

    If you post back that you understand this, I will post you some more about this later.

    Regards,
    Buzz
     
  13. Apr 3, 2017 #12

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    If your data is a time series and you want a statistical approach, you should consider time series analysis. A powerful approach is the Box-Jenkins technique of Auto-Regressive Integrated Moving Average (ARIMA). The free software package R has tools for ARIMA (see http://www.statmethods.net/advstats/timeseries.html ).
     
  14. Apr 3, 2017 #13
    Hi @FactChecker:

    Is ARIMA suitable for very noisy decaying sinusoidal functions?

    Regards,
    Buzz
     
  15. Apr 3, 2017 #14

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    I think it should be able to handle it. It is designed for noise. If the sinusoidal component at one frame is a multiple of that component at a fixed number of frames earlier, then it should be ok. It can be applied to seasonal data. (see https://people.duke.edu/~rnau/411sdif.htm )
     
  16. Apr 3, 2017 #15
    Hi @FactChecker:

    Thank you for your post. It has been a very long time since I worked with ARIMA calculations. I have forgotten how ARIMA produces a curve with a least mean squared fit error.

    Regards,
    Buzz
     
  17. Apr 4, 2017 #16

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    Excel is quite limited in the available shapes of trend lines, but sometimes you can transform your data. If you want a polynomial of an exponential, for example, don't plot the data itself, plot the logarithm, and then find a polynomial trendline there. That has an influence on the weights the individual data points get, but if you want to take uncertainties into account properly then Excel is not the right tool anyway.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Plot a curve through some arbitrary points
Loading...