how to find the inflection point from data contained in an array?

88 ビュー (過去 30 日間)
Angelavtc
Angelavtc 2020 年 4 月 10 日
回答済み: darova 2020 年 4 月 11 日
Dear all,
I have an array of size (360*1 cell) where in each cell I have a set of variables an data as the one that I attach here (data.xlsx). If I plot the variables (Volume, Price) I obtain the following scatter plot:
As you can see, the set of points shown an 'inverse S-Shape'.
My question is, how can I find the two 'inflection points' that I marked in red? I want to find the two points using just numerical data instead of using some analytical equation, because so far all my analytical fits have gone wrong (so far, I tried poly 3 and smoothing spline).
but is not working with my data. Any help would be really welcome :)
Also, how can I automatize this process so it works for all my cells contained in my array?
If this is really complicated and its better to use an analytical equation. Then, how do I fit 360 curves without doing one by one? and how do I find the inflection points?
Thanks in advance!
  8 件のコメント
Angelavtc
Angelavtc 2020 年 4 月 11 日
yep :), @darova I dont know why I cant accept your answer, as you reply really soon to my bad question

サインインしてコメントする。

採用された回答

darova
darova 2020 年 4 月 11 日
Please accept my answer
A = xlsread('data.xlsx');
x = A(:,1);
y = A(:,2);
%%
ii = [1:4 5:10:length(x)];
x1 = x(ii);
y1 = y(ii);
t1 = [0; cumsum(hypot(diff(x1),diff(y1)))]; % arc-length (parameter for interpolation)
t2 = linspace(0,t1(end),100); % new arc-length
x2 = spline(t1,x1,t2);
y2 = spline(t1,y1,t2);
dy = diff(y2)./diff(x2); % first derivative
d2y = diff(y2,2)./diff(x2(2:end)).^2; % second derivative
kk = d2y./(1+dy(2:end).^2).^(3/2); % curvature (1/r)
plot(x,y,'.b')
hold on
plot(x2,y2,'.-r')
plot(x2(2:end-1),kk*1e6,'.-g')
hold off
legend('original data','spline','curvature','location','northwest')

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 4 月 10 日
編集済み: John D'Errico 2020 年 4 月 10 日
YOU ESSENTIALLY JUST ASKED THIS QUESTION. How many times will you ask it?
However, there are two important points I need to explain in what you are doing.
First: replicates. If you have replicated x values, then no, you cannot use spline (OR pchip) directly. Those are interpolating tools. You have what, 16 data points at a volume of 15670? What prediction do you expect an INTERPOLATING spline to produce at that Volume?
plot(Vol,Price,'o')
The simplest way to deal with replicates is to average the values of y, for each replicated x. You can download my consolidator tool from the File exchange. It is designed to do exactly that.
[Vave,Pave] = consolidator(Vol,Price);
plot(Vave,Pave,'o')
xlabel 'Average reduced Volume'
ylabel 'Average reduced Price'
grid on
Still, are you serious? I can count, what roughly at least 5 different inflection points. I see various points where the relationship is possibly discontinuous. Exactly what do you realistically expect to find here? Do you seriously expect to be able to identify second derivative changes, to see where that second derivative changes sign, and to have even the slightest amount of confidence in the result?
What happens when you try to fit this data with a spline?
spl = spline(Vave,Pave);
fnplt(spl)
hold on
plot(Vave,Pave,'ro')
xlabel 'Average reduced Volume'
ylabel 'Average reduced Price'
grid on
There is an old saying about computers, and the use thereof. Garbage in, garbage out. As you can see, the spline has produced just what I would have expected - garbage as a result.
You can do better in terms of a plot, with the use of pchip.
spl = pchip(Vave,Pave);
fnplt(spl)
hold on
plot(Vave,Pave,'ro')
xlabel 'Average reduced Volume'
ylabel 'Average reduced Price'
grid on
While this seems to be more realistic, using a pchip interpolant to find second derivative changes on crappy data is literally insane, because pchip is less able to estimate those second derivatives. It is not as highly differentiable as would be a spline.
Here is the second derivative of the pchip interpolant.
spl = pchip(Vave,Pave);
spl2 = fnder(spl,2);
fnplt(spl2)
Sorry, but the result is exactly what I would expect on this data. Useless.
Hoping to use any method to accurately find an inflection point on that data is almost a laughable idea. I'm sorry, but it is. At the very least, there would be multiple inflection points. I'm sorry, but you are kidding yourself in this task.
  1 件のコメント
Angelavtc
Angelavtc 2020 年 4 月 11 日
yes, @JohnD´errico you are right, I have been kidding myself with all this problem. In any case, thank you!

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by