您是否只是为了计算该日期的“最佳”二阶导数值而执行步骤 (1) 到 (3)?如果是这样,有一个更简单的方法来做到这一点。在伪代码中,它看起来像:
%assume that all_dates is a Matlab datenum that encodes both
%the date and the time as a floating point value
%find just those values for your day that you care about
I = find(todays_date == floor(all_dates));
todays_data = all_data(I);
todays_datenums = all_dates(I);
%find the best-fit parabola to today's data
N_fit = 2; %2nd order is a parabola
p = polyfit(todays_datenums, todays_data,N_fit);
%compute the 2nd derivative
p_1st = polyder(p); %first derivative, form is y = p(1)*todays_datenum+p(2)
p_2nd = polyder(p_1st); %second derivative
因为您只适合抛物线,所以 p_2nd 将是一个值。这是您对当天数据的二阶导数的最佳估计。单位为每天美元 (?)。