繁体   English   中英

如何从点集中找到大于最大值的值? (Matlab求三次样条插值的函数)

[英]How to find a value which is bigger than the maximum point from point set? (Function to find Cubic Spline Interpolation by Matlab)

我已经编写了一个 Matlab 代码来构造一个 Cubic Runout Spline,并用一个图形来显示我的数据。 但是我如何在我的图中显示不在我的数据组 ex.f(2010) 中的数据。 我有个主意。 我可以证明 t 在 2000 年之后有效,即 t=2010,但我不知道如何启动它。 我的身影

clear; clc;

t= [1850, 1875, 1900, 1925, 1950, 1975, 2000];
y= [285.2, 288.6, 295.7, 305.3, 311.3, 331.36, 369.64];

N= length(t); %number of points I want 
n=N-1 ; % number of subintervals

h=(t(N)-t(1))/n; %step size

A=[1,1,1,0],B=[2,0,0,0,2],C=[0,1,1,1];

Trid=diag(4*ones(1,n-1))+diag(A,-1)+diag(B)+diag(C,1);

for i=1:n-1
    f(i)= 6/h^2*(y(i+2)-2*y(i+1)+y(i));
end

f=f';
w=inv(Trid)*f;%since sigma 1 and sigma n+1 are both 0, we need to add 0 in the beginning and also in the end of then matrix
sigma=[0;w;0];%it is a nx1 matrix, be careful.

for i=1:n
    d(i)=y(i);
    b(i)=sigma(i)/2;
    a(i)=(sigma(i+1)-sigma(i))/(6*h);
    c(i)=(y(i+1)-y(i))/h-h/6*(2*sigma(i)+sigma(i+1));
end

r= 25; %subsubintervals for t ex. between 1850 and 1875, here i seperate it into 1 years per slot
hh=h/r; %step size of subsubintervals

x=t(1):hh:t(N);

for i=1:n
    for j=r*(i-1)+1:r*i
        s(j)=a(i)*(x(j)-t(i))^3+b(i)*(x(j)-t(i))^2+c(i)*(x(j)-t(i))+d(i);
    end
end

s(r*n+1)=y(N);

plot(t,y,'o')
hold on
plot(x,s,'-x')
hold off

你问的是extrapolation 你做了插值,这很好。 对于外推,只需继续最后一段的三次方程即可。

s(r*n+1)=y(N); 

s_orig_len = length(s);  %%  new

plot(t,y,'o')
hold on
plot(x,s,'-x')
% hold off     %%% there is more to plot!

% %%   All new lines below
i_last = 6;
i_next = 7;
t = [t 2026];
x_extrapolation = x(end):t(end);
x = [x x_extrapolation];

for j = r*(i_next-1)+1:r*i_next + 3
    s(j)=a(i_last)*(x(j)-t(i_last))^3+b(i_last)*(x(j)-t(i_last))^2+c(i_last)*(x(j)-t(i_last))+d(i_last);
end

plot(x_extrapolation, s(s_orig_len+1:end), '-b', 'LineWidth',2)
hold off;

外推法

我希望这有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM