finding slope of a curve at some specific points

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

 Respuesta aceptada

Star Strider
Star Strider el 10 de Abr. de 2015

2 votos

Your data appear to be smooth enough that you could fit them with a low-order (about 3 or 4) polynomial with polyfit, dividing ‘Index’ by 1E+5 first. Then use polyder to take the derivative of the polyfit coefficients, and use polyval to evaluate the derivative at the values of ‘Index’ you want.

6 comentarios

cagatay yilmaz
cagatay yilmaz el 10 de Abr. de 2015
Editada: cagatay yilmaz el 10 de Abr. de 2015
Hi guys thank you very much for your answer. when i use polyfit command get the following error:
Error using polyfit (line 48)
X and Y vectors must be the same size.;
this is the code that i use:
window_size=40;
exp = tsmovavg(trs2,'e',window_size,1);
x=length(exp);
y = exp;
p = polyfit(x,y,7);
I see the problem: you’re defining x as:
x = length(exp);
This will be a single value. Either use x as (preferably):
x = Index/1E+5;
or define x as:
x = 0:length(exp)-1;
cagatay yilmaz
cagatay yilmaz el 10 de Abr. de 2015
i got you thank you very much:) best
Star Strider
Star Strider el 10 de Abr. de 2015
My pleasure!
If my Answer solved your problem, please Accept it.
Ahmed Desoky
Ahmed Desoky el 27 de Mzo. de 2019
Thank you Star Strider
Star Strider
Star Strider el 27 de Mzo. de 2019
My pleasure.

Iniciar sesión para comentar.

Más respuestas (6)

Image Analyst
Image Analyst el 10 de Abr. de 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 comentarios

Chris Loizou
Chris Loizou el 28 de Feb. de 2016
Dear Image Analyst,
could you please write a more complete code for me that im looking to find the gradient of a randomly spaced data
Thanks in advance
Image Analyst
Image Analyst el 28 de Feb. de 2016
Chris, post your own question and show your code about how you tried to use interp1() to get uniformly spaced data and then used gradient() and show why that wasn't working. Then someone will probably answer there.
@Image Analyst Ay yo you da MVP

Iniciar sesión para comentar.

Chris McComb
Chris McComb el 10 de Abr. de 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))
Eirini Gk
Eirini Gk el 25 de Mzo. de 2016

0 votos

Hello, I need also to find some things like that but im new in matlab and i cant understand every statement. i want to make a function that gives the slope in a point in every curve (close curve). I dont have the toolbox to use 'sym' statement because i need to do it just numerically. I think that diff or gradient function would help but i havent understand excaclty how to use it. I have to input F(x,y) (for example x^2+y^2-1 - the circle with radius 1) and a point of it (x0,y0). I saw that with these statement i get a row of numbers. But can somebody explain me excactly input and ouputs in these statement? Thank you.
cagatay yilmaz
cagatay yilmaz el 25 de Mzo. de 2016
Editada: cagatay yilmaz el 25 de Mzo. de 2016
let say x your independent variable and y dependent variable
index=(x>=2)&(x<=5) % takes the points where you want to calculate your slope (regression)
[slope,intercept]=polyfit(x(index),y(index),1) % create a tangent line on the your selected data points
I hope this will solve your problem.

1 comentario

Eirini Gk
Eirini Gk el 25 de Mzo. de 2016
i dont understand why i have to input an interval. I mean its because of the numerical methods? So when i want a point , lets say (x0,y0)=(2,3) i have to take an area of x=1.5:0.001:2.5 or not?

Iniciar sesión para comentar.

ali moshkriz
ali moshkriz el 7 de Dic. de 2016

0 votos

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);
Image Analyst
Image Analyst el 7 de Dic. de 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;

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 10 de Abr. de 2015

Comentada:

el 8 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by