how can i find convex and concave points

how do I find the convex and concave points of the discrete data as in the photoWhatsApp Image 2019-05-15 at 5.41.47 PM.jpeg

 Accepted Answer

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
dfdx = gradient(f(x),h); % Derivative
[~,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:
how can i find convex and concave points - 2019 05 15.png
Your data may be different, so experiment with different values for the slope to get the result you want.

9 Comments

my data does not have a function, all of my data in the matrix and manually entered values. I need to derive from here or do I need a different code? i actually don't understand. mybe this picture tells you betterWhatsApp Image 2019-05-16 at 1.21.44 AM.jpeg
The function in my code simply creates a vector of data, and is not used otherwise.
My code should work with your data vectors.
@Cem SARIKAYA, this is the line of Star Strider's code you should apply your data to:
dfdx = gradient(f(x),h);
Read about the gradient() function to understand what it's doing.
Do you understand conceptually why Star Strider is suggesting you look for a slope of -0.5?
If you say 'x' to the vertical section and 'y' to the horizontal section, what changes should I make in your code? I'm so sorry I still don't understand
Adam Danz
Adam Danz on 15 May 2019
Edited: Adam Danz on 15 May 2019
I think it's important to take a moment to grasp these concepts before you worry about implementing them in your code.
I chose this image quickly from the internet. You can see a curve and a tangent line. The slope of the tangent line is roughtly -0.5. Now imagine a tangent line traveling down your curve at each point along your curve. There will be two places along the curve where the slope is exactly -0.5 and those places align with the areas you inidicate with arrows. So, if you're going to use this method, you'll need to compute the slope at each point along your curve and then find where those slope values pass through -0.5.
Read the documentation for the gradient function or the ischange function (I provided you links).
I understand the code now, I want to find slopes which constantly changes, can give a range?
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.
Thank you very much for your time.
As always, my pleasure.

Sign in to comment.

More Answers (1)

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])

2 Comments

my data does not have a function, all of my data in the matrix and manually entered values. I need to derive from here or do I need a different code? i actually don't understand. mybe this picture tells you betterWhatsApp Image 2019-05-16 at 1.21.44 AM.jpeg
@Cem SARIKAYA, Steven Lord's proposal is similar to Star Strider's. In the function ischange(), when the method is set to 'linear', the slope of the line is considered and it searches for abrupt changes in the slope.
Again, take a moment to grasp these concepts conceptually before you worry about implementing the code.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!