Tangent at a given point to a nonlinear curve

조회 수: 6 (최근 30일)
Jan Adamkiewicz
Jan Adamkiewicz 2019년 1월 20일
댓글: John D'Errico 2019년 1월 20일
Hello,
I have a problem with caltulating and plotting a tangent to a specified point from data given by two arrays. I know i'm supposed to use spline function to estimate the function of the data points I have and then calculate the derivative and slope to plot a tangent, but unfortunately i'm not very experienced with MATLAB. I would greatly appreciate any help of how to get from teoretical idea to matlab code. So far, i have created a script that uses movmean function to filter any noise i got from the source of the data and got a plot like shown below:
load trzy.csv
A=zeros(1906,2);
A=trzy;
x=A(:,2)*1000;
B=zeros(1906,1);
C=zeros(1906,1);
B(:,1)=movmean(A(:,1),7);
A(:,1)=B(:,1);
C(:,1)=movmean(x,7);
for k = 2:20
B(:,k)=movmean(B(:,k-1),7) ;
end
for y = 2:20
C(:,y)=movmean(C(:,y-1),7);
end
plot(B(:,20),C(:,20))

채택된 답변

Sargondjani
Sargondjani 2019년 1월 20일
편집: Sargondjani 2019년 1월 20일
I think you need to be a bit more precise in what you want: you have data with errors in them, and you want to fit a curve that approximates those points, and then get the slope of the curve?
If you want to fit a spline that goes through all data points (of 1D function), and get the slope one simply way to do it is to use interp1:
POL = interp1(xx,yy,'spline','pp');
dPOL = fnder(POL);
dydx = ppval(dPOL,xi);
where xi are your query points. Something like that.
  댓글 수: 1
Jan Adamkiewicz
Jan Adamkiewicz 2019년 1월 20일
Hi !
The situation is as follows:
I have a curve plotted using two arrays of data ( one is voltage, the other is time) and i have to draw a tangent to a particular point on this curve. I just don't know how to do it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2019년 1월 20일
Why not try using a spline? Actually, given that slope discontinuity at the beginning of your curve, you would use pchip. That is as simple as
spl = pchip(B(:,20),C(:,20));
You can differentiate the spline usingfnder (if you have the curve fitting toolbox.) And then evaluate
splder = fnder(spl);
Now you can evaluate the function in spl or the derivative function in splder using fnval or ppval.
So try these tools.
  댓글 수: 2
Jan Adamkiewicz
Jan Adamkiewicz 2019년 1월 20일
Thank you very much ! I get the idea and it seems to be working :) Have a lovely day
John D'Errico
John D'Errico 2019년 1월 20일
fnplt(spl)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by