MATLAB Answers

How to create a best fit line for data with an aymptote?

9 ビュー (過去 30 日間)
Evan Shimoun
Evan Shimoun 2020 年 1 月 19 日
コメント済み: Image Analyst 2020 年 1 月 20 日
I am currently trying to find the point at which the data reaches its max, the asymptote. However, te data fluctuates, so I need to create a best fit line, since finding the derivative of the data as it is now would not work. How would I programatically go about creating a best fit line for this? I need to be able to acess the equation from the code. The data takes the form of the attached images.

  0 件のコメント

サインイン to comment.

回答 (2 件)

Image Analyst
Image Analyst 2020 年 1 月 19 日
How about if you just fit a line to the last N points? Like N=20 or N = 10% of the total width or whatever. Or you can figure out how many final points to fit to the line by using diff() and seeing when the difference starts getting small.
N = 20; % Whatever.
coefficients = polyfit(x(end N : end), y(end - N : end), 1)
slope = coefficients(1)
offset = coefficients(2)
% Show the assymptote line over the original graph.
hold on;
xa = x(end N : end);
ya = slope * xa + offset;
plot(xa, ya, 'r-', 'LineWidth', 2);
grid on;

  0 件のコメント

サインイン to comment.

John D'Errico
John D'Errico 2020 年 1 月 20 日
It partly depends on your goal. Do you just want to best estimate the constant asymptote? Or, are you looking for some function that will approximate the entire curve? The latter is of course far more difficult, since there is no reasonable model that will fit any possible such relationship, especially when it appears that your curve increases smoothly, then suddenly flattens out, with a virtual break in the slope at one point in one of the examples you show. Worse, at the bottom end, it looks like there is some garbage, SOME of the time.
If your goal is to just find the best possible constant asymptote estimate, then it is simple enough. Pick the set of points at the upper end where it appears to be essentially constant, then take the mean of y over that interval. The mean would be a good estimate of a constant function over an interval, the best estimate, in fact. You could be more sophisticated of course, in lots of ways, but that is simplest, and should be entirely adequate.
If your goal is really to get the entire curve fit smoothly, then I might recommend a smoothing spline, as most general. But a smoothing spline will not understand that the upper end of the curve approaches an asymptote. You could build that information into the spline model, but again, that will take more effort. And of course, splines have real problems with transitions from a high slope region into a constant slope region. You will always find ringing there near the transition, unless you use a spline model that includes a monotonicity constraint. Again - that will be more difficult to deal with.
Anyway, your question seems to be how to find a best estimate of the asymptote, which as I said, is not that difficult.

  4 件のコメント

表示 1 件の古いコメント
Image Analyst
Image Analyst 2020 年 1 月 20 日
What do you mean by threshold? I did not threshold the values. You simply take a certain number of points on the end of the data that approaches an assymptote and fit a line through them. What do you know about your data? Anything? Like do all data sets have the same number of points? Do they all have assymptotes parallel with an axis? Or a line at about the same slope? Is the "flat" potion of all curves about the same, or does it vary? Surely you must know something about your different data sets and how they might be similar.
Evan Shimoun
Evan Shimoun 2020 年 1 月 20 日
The amount of data points varies depending on the set. The datasets are of the time taken for a motor to reach its maximum speed and what I am trying to figure out is the time taken to reach that speed. Generally the maximum speed, where the dataset flattens off, is at a y-value of around 740, though there is variation among the datasets, with some being closer to 730 or 725. The slope of the curve to reach the asymptote is different in each dataset, as it takes a different amount of time to reach the max. By threshold I meant a hardcoded value for what the max speed, the asymptote, would be. For example, right now, to get the function to work in the meantime, I have a threshold of around 736 set, so I take the first point which is greater than or equal to that number in each dataset and declare that to be the point where the max speed, the asymptote, is reached. My goal in figuring out the actual asymptote for each dataset is to create a more accurate analysis if possible.
Image Analyst
Image Analyst 2020 年 1 月 20 日
OK, so I think my strategy should work. Didn't it?
You might be interested in my piecewise linear fit demo. It fits lines to the left part and the right part of a signal and determines where the "kink" is in the curve by identifying the location where the slopes between the two linear fit pieces is most different.

サインイン to comment.

サインイン してこの質問に回答します。




Translated by