# finding slope of a curve at some specific points

150 views (last 30 days)

Show older comments

cagatay yilmaz
on 10 Apr 2015

Commented: Caden Armentrout
on 8 Sep 2021

Hi

I have a a column data set which is the transverse strain of a composite material. I want to calculate slope of it at some specific points

##### 0 Comments

### Accepted Answer

Star Strider
on 10 Apr 2015

##### 6 Comments

### More Answers (6)

Image Analyst
on 10 Apr 2015

How about if you just pass points around the point in question to polyfit and fit a line to them:

coefficients = polyfit(x(index1:index2), y(index1:index2), 1);

slope = coefficients(1);

Or fit a quadratic and get the slope at the middle of the stretch of points you fitted:

coefficients = polyfit(x(index1:index2), y(index1:index2), 2);

slope = 2 * coefficients(1) * x(middleIndex) + coefficients(2);

##### 3 Comments

Image Analyst
on 28 Feb 2016

Chris McComb
on 10 Apr 2015

You might want to start by looking at MATLAB's gradient function. You could also use simple finite difference formulas, like:

slope(i) = (y(i+1) - y(i-1))/(x(i+1) - x(i-1))

##### 0 Comments

Eirini Gk
on 25 Mar 2016

##### 0 Comments

cagatay yilmaz
on 25 Mar 2016

Edited: cagatay yilmaz
on 25 Mar 2016

##### 1 Comment

Eirini Gk
on 25 Mar 2016

ali moshkriz
on 7 Dec 2016

hey Guys! how can i find the slope of this curve in 3 point that have different slope! please help...

>> A=[0,198.6026,397.2053,993.01346,2376.65783,3968.16977,4566.799,5161.454,6956.4044,9930.1346]; >> B=[0.29835,0.3978,0.467415,0.546975,0.745875,0.975375,1.09395,1.3923,2.56275,4.5288]; >> loglog(A,B);

##### 0 Comments

Image Analyst
on 7 Dec 2016

The slope is deltaB/deltaA. For each point, you will have a slope to the right of the point and a slope to the left of the point. You can take whichever one you want, or even average the slopes on each side if you want. For example, the slopes around element #2:

leftSlope = (B(2)-B(1)) / (A(2)-A(1))

rightSlope = (B(3)-B(2)) / (A(3)-A(2))

averageSlope = (leftSlope + rightSlope) / 2;

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!