yy(1) = y(1)
yy(2)=(y(1) + y(2) + y(3))/3 yy(3) = (y(1) 十y(2) 十y(3) + y(4)十y(5))/5 yy(4) = (y(2) + y(3)十y(4) + y(5) + y(6))/5 yy(5) = (y(3) + y(4)十y(5)十y(6) +y(7))/5...
java实现
/**
* <p> * Title: smooth * </p> * <p> * Description: 数组平滑处理 * </p> * * @param d * @return */ public static double[] smooth(double[] d) {int length = d.length;
double[] dbRt = new double[length];if (length == 1) {
/** 前置与后置无元素 index=0与index=length-1 */ dbRt[0] = d[0]; dbRt[length - 1] = d[length - 1];}
if (length == 2) { /** 前置与后置无元素 index=0与index=length-1 */ dbRt[0] = d[0]; dbRt[length - 1] = d[length - 1]; } if (length == 3) { /** 前置与后置无元素 index=0与index=length-1 */ dbRt[0] = d[0]; dbRt[length - 1] = d[length - 1]; /** 前置与后置只有一个元素 index=1 与index=length-2 */ dbRt[1] = (d[0] + d[1] + d[2]) / 3;}
if (length == 4) { /** 前置与后置无元素 index=0与index=length-1 */ dbRt[0] = d[0]; dbRt[length - 1] = d[length - 1]; /** 前置与后置只有一个元素 index=1 与index=length-2 */ dbRt[1] = (d[0] + d[1] + d[2]) / 3; dbRt[2] = (d[1] + d[2] + d[3]) / 3; } if (length >= 5) {/** 前置与后置无元素 index=0与index=length-1 */
dbRt[0] = d[0]; /** 前置与后置只有一个元素 index=1 与index=length-2 */ dbRt[1] = (d[0] + d[1] + d[2]) / 3; for (int x = 2; x < length - 2; x++) { /** 前置与后置均由两个元素情况 d[n] n-2>=0且n+2<=length-1 */ dbRt[x] = (d[x - 2] + d[x - 1] + d[x] + d[x + 1] + d[x + 2]) / 5; } dbRt[length - 2] = (d[length - 3] + d[length - 2] + d[length - 1]) / 3; dbRt[length - 1] = d[length - 1];}
return dbRt;
}
public static void main(String[] args) {
double[] dbPara = { 1, 2, 100, 10, 50, 20 }; double[] dbRt = smooth(dbPara); for (double dbIndex : dbRt) { System.out.println(dbIndex); }}