# how can i find convex and concave points

66 views (last 30 days)
Cem SARIKAYA on 15 May 2019
Commented: Star Strider on 16 May 2019
how do I find the convex and concave points of the discrete data as in the photo

Star Strider on 15 May 2019
It depends on how you want to define them.
Here, I define them as points where the slope is -0.5:
f = @(x) 1-(x./sqrt(1+x.^2)); % Create Function
x = linspace(-10, 10);
h = x(2)-x(1); % Step Interval
[~,infpt] = min(dfdx);
xpoint(1) = interp1(dfdx(1:infpt-1),x(1:infpt-1),-0.5); % Slope = -0.5
xpoint(2) = interp1(dfdx(infpt+1:end),x(infpt+1:end),-0.5); % Slope = -0.5
figure
plot(x, f(x))
hold on
plot(xpoint, f(xpoint), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
grid
axis('equal')
xlim([-2.5 2.5])
To illustrate:
Your data may be different, so experiment with different values for the slope to get the result you want.

Star Strider on 16 May 2019
If you say 'x' to the vertical section and 'y' to the horizontal section ...’
In my code, ‘x’ is the independent variable and ‘y’ is the dependent variable.
I want to find slopes which constantly changes
You can set the slope value (I chose -0.5 here) to be whatever you like, within limits. (The slope has to have that value somewhere in the region of interest.) My code (specifically the ‘xpoint’ interpolations) should be reasonably robust to your choices.
can give a range?
I am not certain what you intend. See the documentation for the interp1 (link) function (that I use to calculate the ‘xpoint’ values) to understand what the function can do, and how to use it.
Cem SARIKAYA on 16 May 2019
Thank you very much for your time.
Star Strider on 16 May 2019
As always, my pleasure.

Steven Lord on 15 May 2019
Depending on what you want to do with this information (which is not clear from the question) you may find the ischange function useful.
f = @(x) 1-(x./sqrt(1+x.^2)); % Create Function
x = linspace(-10, 10);
y = f(x);
changes = ischange(y, 'linear', 'SamplePoints', x);
plot(x, y, '-', x(changes), y(changes), 'gp')
grid on
axis('equal')
xlim([-2.5 2.5])