簡體   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