233 views (last 30 days)

Hi!I have no experience in Matlab, but I was given the assignment to find point of inflection in this graph. What I have is: x = [ 7.0 7.2 7.4 7.6 8.4 8.8 9.2 9.6 10.0]; y = [ 0.692 0.719 0.723 0.732 0.719 0.712 1.407 1.714 1.99];

I would REALLY appreciate if someone could help me because I don't know what to do and how to find it. Thank you all!

Star Strider
on 20 Feb 2018

Edited: Star Strider
on 8 Jun 2020

Inflection points are defined where the curve changes direction, and the derivative is equal to zero.

See if this does what you want:

x = [ 7.0 7.2 7.4 7.6 8.4 8.8 9.2 9.6 10.0];

y = [ 0.692 0.719 0.723 0.732 0.719 0.712 1.407 1.714 1.99];

dydx = gradient(y) ./ gradient(x); % Derivative Of Unevenly-Sampled Data

zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector

zxidx = zci(dydx); % Approximate Indices Where ‘dydx=0’

for k1 = 1:numel(zxidx) % Loop Finds ‘x’ & ‘y’ For ‘dydx=0’

inflptx(k1) = interp1(dydx(zxidx(k1):zxidx(k1)+1), x(zxidx(k1):zxidx(k1)+1), 0, 'linear');

inflpty(k1) = interp1(x(zxidx(k1):zxidx(k1)+1), y(zxidx(k1):zxidx(k1)+1), inflptx(k1), 'linear');

end

figure(1)

plot(x, y)

hold on

plot(x, dydx)

plot(inflptx, inflpty, 'pg', 'MarkerFaceColor','g')

hold off

grid

legend('Data', 'Derivative', 'Inflection Points')

inflpts = regexp(sprintf('(%5.3f,%5.3f)\n', [inflptx; inflpty]), '\n', 'split');

text(inflptx, inflpty, inflpts(1:end-1),'FontSize',8, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')

The ‘inflptx’ and ‘inflpty’ vectors (derived from a linear interpolation of the derivative) are the coordinates of the inflection points. They are approximate because your data are discrete. The code does not find an inflection point where what is apparently a spline interpolation might create one, because that is not in your original data.

EDIT — (8 Jun 2020 at 12:21)

While the original code works for the original data here, if the identified zero-crossings of the derivative are close to the ends of the vector, it will crash with indices that exceed the number of vector elements.

This version of the loop fixes that:

for k1 = 1:numel(zxidx) % Loop Finds ‘x’ & ‘y’ For ‘dydx=0’

ixrng = max(zxidx(k1)-2,1):min(zxidx(k1)+2,numel(x));

inflptx(k1) = interp1(dydx(ixrng), x(ixrng), 0, 'linear');

inflpty(k1) = interp1(x(ixrng), y(ixrng), inflptx(k1), 'linear');

end

The ‘inflpts’ assignment also needs to be modified:

inflpts = sprintfc('(%5.3f, %5.3f)', [inflptx; inflpty].');

text(inflptx, inflpty, inflpts,'FontSize',8, 'HorizontalAlignment','center', 'VerticalAlignment','bottom')

.

John D'Errico
on 17 Jun 2018

@Vishal - there are 4 points of inflection that a spline would "see" in your data.

spl = spline(x,y);

fnplt(spl)

hold on

plot(x,y,'ro')

Finding them is easy.

Differentiate the spline twice. Then search for where that second derivative curve crosses the x axis.

spl2 = fnder(spl,2);

fnplt(spl2)

refline(0,0)

I used fnder and fnplt there, which probably live in the curve fitting toolbox. But if you are working with curves like this, that is an excellent investment.

The simplest way to find those crossing points is to download my SLM toolbox, from the file exchange.

infp = slmsolve(spl2)

infp =

1.45210153974199 3.72373878056329 4.42012614139132 5.61348471267802

So the points of inflection lie at those locations.

fnplt(spl)

hold on

plot(x,y,'ro')

plot(repmat(infp,2,1),repmat([4;10],1,4),'b-')

Since that second derivative curve is piecewise linear, finding those zero crossings is a trivial task, no matter how you do it.

Adilah R
on 8 Sep 2019

then how do I find the y values for those identified inflection points on the spline?

John D'Errico
on 20 Feb 2018

Um, I think you need to look CAREFULLY at the data you have. Then think carefully about what you need.

An inflection point is a location where a curve has a sign change in the second derivative.

Here is your data.

The data seems a bit noisy, although it is hard to know if what I see is noise or true signal. It is also a bit sparse, in the sense that if you truly need to locate a point of inflection, then it is insufficient to do so well.

But, look to the left of the red line. The data there seems to have a fairly simple negative second derivative. To the right of the red line?It is also a region of negative curvature. So essentially everywhere, except at one point, that curve is negatively curved. At the location of the red line, (x==8.8) at best I would see a location where the curve goes through a slope discontinuity. To infer anything more than that from this poor dataset is asking for someone to have a good laugh at your expense.

So, COULD you use a numerical tool (perhaps a spline of some sort) to try to locate an inflection point? Well, yes, in theory, you could try. But the result would be laughably, woefully, poor.

At best, the point of inflection is at x=8.8. See? You did not even need a computer to do that. Just a pair of eyes.

Opportunities for recent engineering grads.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/383721-how-to-find-inflection-point-please-help#comment_537408

⋮## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/383721-how-to-find-inflection-point-please-help#comment_537408

Sign in to comment.