How can I do a spline interpolation with tangent continuity

조회 수: 11(최근 30일)
Michael Schletterer
Michael Schletterer 2021년 4월 22일
답변: darova 2021년 8월 8일
Hi every one this is my first post on this forum so please don't hate me for formating etc.
I'm trying to derive data from a spline interpolation (twice). The problem I run into here is that there are always kinks in the interpolated data which leads to problems with the derivation.
My question is: Is there a way to do a spline (or other) interpolation of my data where the slope at every interpolated point stays the same (there are no kinks in the interpolated data, tangent continuity at every spline point) ?
This is so i can do a derivation twice to find linear portions of my data.
Thanks for your help in advance.
load('test.mat');
HV4502=table2array(HV450102);
x452=linspace(0,HV4502(end,2),200);
HV4502S=spline(HV4502(1:end,2),HV4502(1:end,1),x452);
plot(x452,HV4502S,'g');
hold on;
plot(HV4502(1:end,2),HV4502(1:end,1),'r--');
hold on;
G4502=gradient(HV4502S)./gradient(x452);
GG452=gradient(G4502)./gradient(x452);
plot(x452,GG452,'b');
  댓글 수: 3
Boris Blagojevic
Boris Blagojevic 2021년 8월 6일
In case it is still relevant: Maybe derivest might be suited to your problem?

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

답변(1개)

darova
darova 2021년 8월 8일
What about this? I calculated tangent at each point and added points
dx = 0.1; % adding points distance
x = 0:5;
y = sin(x); % origial data
x1 = 0:.1:5;
y1 = spline(x,y,x1); % refine the data
dy = atan(diff(y)./diff(x)); % find tangent
a = diff(dy)/2 + dy(1:end-1); % find tangent
k = tan(a); % find tangent
x2 = zeros(1,2*numel(x)-2);
x2([1 end]) = x([1 end]); % first and last points
tmp = [x(2:end-1)-dx;x(2:end-1)+dx];% adding points
x2(2:end-1) = tmp(:); % one row
y2 = x2*0;
y2([1 end]) = y([1 end]); % first and last points
for i = 1:length(k)
y2(2*i) = y(i+1) - k(i)*dx; % left point
y2(2*i+1) = y(i+1) + k(i)*dx; % right point
end
x3 = x1;
y3 = spline(x2,y2,x3); % create new spline
plot(x,y,'r')
hold on
plot(x1,y1,'r')
plot(x2,y2,'.b')
plot(x3,y3,'b')
hold off
legend('original data','original spline','added points','spline through added points')

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by