zoukankan      html  css  js  c++  java
  • Java拟合算法

    
    

      其中引用到了apache的common-math的jar包,主要用于矩阵运算,下载地址:

    
    

      http://commons.apache.org/proper/commons-math/userguide/fitting.html


    1
    import org.apache.commons.math3.fitting.PolynomialCurveFitter; 2 import org.apache.commons.math3.fitting.WeightedObservedPoints; 3 import org.apache.commons.math3.linear.ArrayRealVector; 4 import org.apache.commons.math3.linear.DecompositionSolver; 5 import org.apache.commons.math3.linear.LUDecomposition; 6 import org.apache.commons.math3.linear.MatrixUtils; 7 import org.apache.commons.math3.linear.RealMatrix; 8 import org.apache.commons.math3.linear.RealVector; 9 10 public class MathUtil { 11 /** 12 * 一元线性拟合 y = a + b*x 13 * 14 * @param x 15 * @param y 16 * reuslt[0] = a result[1] = b result[2] 相关系数 result[3] 决定系数 17 * result[4] 点数量(长度) result[5] 自由度 18 */ 19 public static double[] lineFitting(double x[], double y[]) { 20 int size = x.length; 21 double xmean = 0.0; 22 double ymean = 0.0; 23 double xNum = 0.0; 24 double yNum = 0.0; 25 double xyNum = 0; 26 double xNum2 = 0; 27 double yNum2 = 0; 28 double rss = 0; 29 double tss = 0; 30 double result[] = new double[6]; 31 32 for (int i = 0; i < size; i++) { 33 xmean += x[i]; 34 ymean += y[i]; 35 xNum2 += x[i] * x[i]; 36 yNum2 += y[i] * y[i]; 37 xyNum += x[i] * y[i]; 38 } 39 xNum = xmean; 40 yNum = ymean; 41 xmean /= size; 42 ymean /= size; 43 44 double sumx2 = 0.0f; 45 double sumxy = 0.0f; 46 for (int i = 0; i < size; i++) { 47 sumx2 += (x[i] - xmean) * (x[i] - xmean); 48 sumxy += (y[i] - ymean) * (x[i] - xmean); 49 } 50 51 double b = sumxy / sumx2; 52 double a = ymean - b * xmean; 53 54 result[0] = a; 55 result[1] = b; 56 System.out.println("a = " + a + ", b=" + b); 57 58 double correlation = (xyNum - xNum * yNum / size) 59 / Math.sqrt((xNum2 - xNum * xNum / size) * (yNum2 - yNum * yNum / size)); 60 61 System.out.println("相关系数:" + correlation); 62 result[2] = correlation; 63 64 for (int i = 0; i < size; i++) { 65 rss += (y[i] - (a + b * x[i])) * (y[i] - (a + b * x[i])); 66 tss += (y[i] - ymean) * (y[i] - ymean); 67 } 68 69 double r2 = 1 - (rss / (size - 1 - 1)) / (tss / (size - 1)); 70 71 result[3] = r2; 72 System.out.println("决定系数" + r2); 73 74 result[4] = x.length; 75 result[5] = x.length - 1 - 1; 76 77 return result; 78 } 79 80 /** 81 * 多元线性拟合 y = a + b*x1 + c*x2 82 * 83 * @param x 84 * @param y 85 * result[0] = a result[b] = b . . . result[len - 4] 点数 result[len - 86 * 3] 自由度 result[len - 2] 残差平方和 result[len - 1] 确定系数 87 */ 88 public static double[] lineFitting2(double x[][], double y[]) { 89 double[] a = new double[x.length + 1]; 90 double[] v = new double[2]; // 这里的2为m 91 double[] dt = new double[4]; 92 93 line2sqt(x, y, 2, 11, a, dt, v); 94 95 int i; 96 97 System.out.println("残差平方和:" + dt[0]); 98 99 double temp = a[a.length - 1]; 100 // 更换输出位置,把常数放到第一位 101 for (i = a.length - 1; i > 0; i--) { 102 a[i] = a[i - 1]; 103 } 104 105 a[0] = temp; 106 107 double[] result = new double[x.length + 5]; 108 109 for (i = 0; i <= x.length; i++) { 110 result[i] = a[i]; 111 } 112 113 result[x.length + 1] = y.length; 114 result[x.length + 2] = y.length - x.length; 115 result[x.length + 3] = dt[0]; 116 result[x.length + 4] = getLine2R(x, y, a, x.length); 117 118 System.out.println("校正确定系数:" + result[x.length + 4]); 119 120 return result; 121 } 122 123 /** 124 * 多项式拟合 y = a + b*x1 + c*x1^2…… result[0] = a result[1] = b . . . result[n + 1] 125 * 点数 result[n + 2] 自由度 result[n + 3] 确定系数 126 * 127 * @param n 128 * 几级 129 * @return 130 */ 131 public static double[] dxsFitting(double x[], double y[], int n) { 132 double result[] = new double[n + 4]; 133 134 WeightedObservedPoints obs = new WeightedObservedPoints(); 135 136 for (int i = 0; i < x.length; i++) { 137 obs.add(x[i], y[i]); 138 } 139 140 // Instantiate a third-degree polynomial fitterm. 141 final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(n); 142 143 // Retrieve fitted parameters (coefficients of the polynomial function). 144 final double[] coeff = fitter.fit(obs.toList()); 145 146 for (int i = 0; i < coeff.length; i++) { 147 result[i] = coeff[i]; 148 } 149 150 double s = getDxsR(x, y, coeff, 5); 151 152 System.out.println("确定系数:" + s); 153 154 result[n + 1] = x.length; 155 result[n + 2] = x.length - n - 1; 156 result[n + 3] = s; 157 158 return result; 159 } 160 161 /** 162 * 指数拟合 y = b*exp(ax) result[0] = a result[1] = b result[2] 数据点数 result[3] 自由度 163 * result[4] 确定系数 164 * 165 * @param x 166 * @param y 167 * @return 168 */ 169 public static double[] expFitting(double x[], double y[]) { 170 int size = x.length; 171 double xmean = 0.0; 172 double ymean = 0.0; 173 double rss = 0; 174 double tss = 0; 175 double result[] = new double[5]; 176 177 for (int i = 0; i < size; i++) { 178 xmean += x[i]; 179 y[i] = Math.log(y[i]); 180 ymean += y[i]; 181 } 182 xmean /= size; 183 ymean /= size; 184 185 double sumx2 = 0.0f; 186 double sumxy = 0.0f; 187 for (int i = 0; i < size; i++) { 188 sumx2 += (x[i] - xmean) * (x[i] - xmean); 189 sumxy += (y[i] - ymean) * (x[i] - xmean); 190 } 191 192 double b = sumxy / sumx2; 193 double a = ymean - b * xmean; 194 195 for (int i = 0; i < size; i++) { 196 rss += (y[i] - (a + b * x[i])) * (y[i] - (a + b * x[i])); 197 tss += (y[i] - ymean) * (y[i] - ymean); 198 } 199 200 double r2 = 1 - (rss / (size - 1 - 1)) / (tss / (size - 1)); 201 202 System.out.println("决定系数" + r2); 203 204 a = Math.exp(a); 205 206 System.out.println("a = " + a + ";b= " + b); 207 208 result[0] = a; 209 result[1] = b; 210 result[2] = x.length; 211 result[3] = x.length - 2; 212 result[4] = r2; 213 214 return result; 215 } 216 217 /** 218 * 对数拟合 y = ln(a * x + b) result[0] = a result[1] = b result[2] 数据点数 result[3] 219 * 自由度 result[4] 确定系数 220 * 221 * @param x 222 * @param y 223 */ 224 public static double[] logFitting(double x[], double y[]) { 225 int size = x.length; 226 double xmean = 0.0; 227 double ymean = 0.0; 228 double rss = 0; 229 double tss = 0; 230 double result[] = new double[5]; 231 232 for (int i = 0; i < size; i++) { 233 xmean += x[i]; 234 y[i] = Math.exp(y[i]); 235 ymean += y[i]; 236 } 237 xmean /= size; 238 ymean /= size; 239 240 double sumx2 = 0.0f; 241 double sumxy = 0.0f; 242 for (int i = 0; i < size; i++) { 243 sumx2 += (x[i] - xmean) * (x[i] - xmean); 244 sumxy += (y[i] - ymean) * (x[i] - xmean); 245 } 246 247 double b = sumxy / sumx2; 248 double a = ymean - b * xmean; 249 250 for (int i = 0; i < size; i++) { 251 rss += (y[i] - (b + a * x[i])) * (y[i] - (b + a * x[i])); 252 tss += (y[i] - ymean) * (y[i] - ymean); 253 } 254 255 double r2 = 1 - (rss / (size - 1 - 1)) / (tss / (size - 1)); 256 257 System.out.println("决定系数" + r2); 258 259 System.out.println("a = " + a + ";b= " + b); 260 261 result[0] = a; 262 result[1] = b; 263 result[2] = x.length; 264 result[3] = x.length - 2; 265 result[4] = r2; 266 267 return result; 268 269 } 270 271 /** 272 * 参考网址:http://wenku.baidu.com/link?url=T-xy9CUR_hVlCpA5o6xjqWb-Z1o5jraGEg-OHEtDgFLEynf6HedV68wMwC5u7RTs7PN5kiYq3qjyiddMveDFywLiuXai11MisNrNvv4KjAW&qq-pf-to=pcqq.c2c 273 * 峰拟合 y = y(max) * exp[-(x - x(max))^2/S] 274 * 275 * @param x 276 * @param y 277 * result[0] = x(max) result[1] = y(max) result[2] = S result[3] 点数 278 * result[4] 自由度 result[5] 确定系数 279 */ 280 public static double[] peakFitting(double x[], double y[]) { 281 int size = x.length; 282 double maxX = 0; 283 double maxY = 0; 284 double minY = Integer.MAX_VALUE; 285 double result[] = new double[6]; 286 double[][] left = new double[x.length][3]; 287 double[][] right = new double[x.length][1]; 288 289 for (int i = 0; i < size; i++) { 290 if (y[i] > maxY) { 291 maxX = x[i]; 292 maxY = y[i]; 293 } 294 295 if (y[i] < minY) { 296 minY = y[i]; 297 } 298 299 for (int j = 0; j < 3; j++) { 300 left[i][j] = getPeakValue(j, x[i]); 301 } 302 303 right[i][0] = Math.log(y[i]); 304 } 305 306 RealMatrix leftMatrix = MatrixUtils.createRealMatrix(left); 307 RealMatrix rightMatrix = MatrixUtils.createRealMatrix(right); 308 RealMatrix leftMatrix1 = leftMatrix.transpose(); 309 RealMatrix m = leftMatrix1.multiply(leftMatrix); 310 311 RealMatrix tMatrix = new LUDecomposition(m).getSolver().getInverse().multiply(leftMatrix1) 312 .multiply(rightMatrix); 313 314 result[0] = maxX; 315 result[1] = maxY; 316 result[2] = -1.0 / tMatrix.getEntry(2, 0); 317 318 System.out.println(result[0] + " " + result[1] + " " + result[2]); 319 double aaaa = getPearR(x, y, result, 2); 320 System.out.println("确定系数:" + aaaa); 321 322 result[3] = x.length; 323 result[4] = x.length - 1 - 2; 324 result[5] = aaaa; 325 326 return result; 327 } 328 329 /** 330 * 用户自定义拟合 331 * 332 * @param x 333 * @param y 334 * @param sf 335 * 算法 <input type="checkbox" value="0" />常数 336 * <input type="checkbox" value="1" />x 337 * <input type="checkbox" value="2" />x^2 338 * <input type="checkbox" value="3" />x^3 339 * <input type="checkbox" value="4" />exp(x) 340 * <input type="checkbox" value="5" />ln(x) 341 * <input type="checkbox" value="6" />sin(x) 342 * <input type="checkbox" value="7" />cos(x) 343 * 344 * result[0] = 第一项系数 result[1] = 第二项系数 . . . result[n] = 第N项系数 345 * result[sf.length] 点数 result[sf.length+1] 自由度 result[sf.length+2] 346 * 确定系数 347 * @return 348 */ 349 public static double[] userDefineFitting(double x[], double y[], int sf[]) { 350 double[][] left = new double[sf.length][sf.length]; 351 double[] right = new double[sf.length]; 352 double[] result = new double[sf.length + 3]; 353 354 result[sf.length] = x.length; 355 boolean containZero = false; 356 357 for (int i = 0; i < sf.length; i++) { 358 double yValue = 0; 359 360 // 数值中包括0 361 if (sf[i] == 0) { 362 containZero = true; 363 } 364 365 for (int j = 0; j < sf.length; j++) { 366 double xValue = 0; 367 368 // 计算X的的司格马 369 for (int k = 0; k < x.length; k++) { 370 xValue += getUserDefineValue(sf[i], x[k]) * getUserDefineValue(sf[j], x[k]); 371 } 372 373 left[i][j] = xValue; 374 } 375 376 // 计算Y的的司格马 377 for (int k = 0; k < x.length; k++) { 378 yValue += y[k] * getUserDefineValue(sf[i], x[k]); 379 } 380 381 right[i] = yValue; 382 } 383 384 // 计算自由度 385 result[sf.length + 1] = x.length - sf.length - 1; 386 387 // 计算自由度 388 if (containZero) { 389 result[sf.length + 1] = x.length - sf.length; 390 } 391 392 // 矩阵求解 393 RealMatrix leftMatrix = MatrixUtils.createRealMatrix(left); 394 DecompositionSolver solver = new LUDecomposition(leftMatrix).getSolver(); 395 RealVector constants = new ArrayRealVector(right, false); 396 397 RealVector solution = solver.solve(constants); 398 399 System.out.println(solution); 400 401 // 获得系数值 402 for (int i = 0; i < solution.getDimension(); i++) { 403 result[i] = solution.getEntry(i); 404 } 405 406 double rss = 0, tss = 0, ymean = 0; 407 408 for (int i = 0; i < x.length; i++) { 409 ymean += y[i]; 410 } 411 412 ymean /= x.length; 413 414 for (int i = 0; i < x.length; i++) { 415 rss += (y[i] - getUserDefineValueByX(sf, x[i], solution)) 416 * (y[i] - getUserDefineValueByX(sf, x[i], solution)); 417 tss += (y[i] - ymean) * (y[i] - ymean); 418 } 419 420 double r2 = 1 - (rss / result[sf.length + 1]) / (tss / (x.length - 1)); 421 422 System.out.println("决定系数" + r2); 423 424 result[sf.length + 2] = r2; 425 426 return result; 427 } 428 429 /** 430 * 用户自定义函数,传入X值获得Y值 431 * 432 * @param n 433 * @param x 434 * @param solution 435 * @return 436 */ 437 private static double getUserDefineValueByX(int[] n, double x, RealVector solution) { 438 double value = 0; 439 440 for (int i = 0; i < n.length; i++) { 441 value += getUserDefineValue(n[i], x) * solution.getEntry(i); 442 } 443 444 return value; 445 } 446 447 /** 448 * 获得用户自定义的值, <input type="checkbox" value="0" />常数 449 * <input type="checkbox" value="1" />x <input type="checkbox" value="2" />x^2 450 * <input type="checkbox" value="3" />x^3 451 * <input type="checkbox" value="4" />exp(x) 452 * <input type="checkbox" value="5" />ln(x) 453 * <input type="checkbox" value="6" />sin(x) 454 * <input type="checkbox" value="7" />cos(x) 455 * 456 * @param i 457 * @param x 458 * @return 459 */ 460 private static double getUserDefineValue(int i, double x) { 461 // 常数 462 if (i == 0) { 463 return 1; 464 } else if (i == 1) { 465 // x 466 return x; 467 } else if (i == 2) { 468 // x^2 469 return x * x; 470 } else if (i == 3) { 471 // x^3 472 return x * x * x; 473 } else if (i == 4) { 474 // exp(x) 475 return Math.pow(Math.E, x); 476 } else if (i == 5) { 477 // ln(x) 478 return Math.log(x); 479 } else if (i == 6) { 480 // sin(x) 481 return Math.sin(x); 482 } else if (i == 7) { 483 // cos(x) 484 return Math.cos(x); 485 } 486 487 return 0; 488 } 489 490 /** 491 * 获得决定系数 492 * 493 * @param coeff 494 * @return 495 */ 496 private static double getPearR(double x[], double y[], double coeff[], int n) { 497 int size = x.length; 498 double ymean = 0.0; 499 double rss = 0; 500 double tss = 0; 501 502 for (int i = 0; i < size; i++) { 503 ymean += y[i]; 504 } 505 506 ymean /= size; 507 508 for (int i = 0; i < size; i++) { 509 rss += (y[i] - getPeakValueByX(x[i], coeff)) * (y[i] - getPeakValueByX(x[i], coeff)); 510 tss += (y[i] - ymean) * (y[i] - ymean); 511 } 512 513 double r2 = 1 - (rss / (size - n - 1)) / (tss / (size - 1)); 514 515 return r2; 516 } 517 518 /** 519 * 通过X获得Y的值 y = y(max) * exp[-(x - x(max))^2/S] 520 * 521 * @param x 522 * @param y 523 * result[0] = x(max) result[1] = y(max) result[2] = S 524 * @return 525 */ 526 private static double getPeakValueByX(double x, double result[]) { 527 double b = Math.exp(-Math.pow((x - result[0]), 2) / result[2]) * result[1]; 528 529 return b; 530 } 531 532 private static double getPeakValue(int i, double x) { 533 // 常数 534 if (i == 0) { 535 return 1; 536 } else if (i == 1) { 537 return x; 538 } else if (i == 2) { 539 // x^2 540 return x * x; 541 } 542 543 return 0; 544 } 545 546 /** 547 * 获得决定系数 548 * 549 * @param coeff 550 * @return 551 */ 552 private static double getDxsR(double x[], double y[], double coeff[], int n) { 553 int size = x.length; 554 double ymean = 0.0; 555 double rss = 0; 556 double tss = 0; 557 558 for (int i = 0; i < size; i++) { 559 ymean += y[i]; 560 } 561 562 ymean /= size; 563 564 for (int i = 0; i < size; i++) { 565 rss += (y[i] - getDxsValueByX(x[i], coeff)) * (y[i] - getDxsValueByX(x[i], coeff)); 566 tss += (y[i] - ymean) * (y[i] - ymean); 567 } 568 569 double r2 = 1 - (rss / (size - n - 1)) / (tss / (size - 1)); 570 571 return r2; 572 } 573 574 /** 575 * 通过X获得Y的值 576 * 577 * @param x 578 * @param coeff 579 * @return 580 */ 581 private static double getDxsValueByX(double x, double coeff[]) { 582 int size = coeff.length; 583 double result = coeff[0]; 584 585 for (int i = 1; i < size; i++) { 586 result += coeff[i] * Math.pow(x, i); 587 } 588 589 return result; 590 } 591 592 /** 593 * 多元线性回归分析 594 * 595 * @param x[m][n] 596 * 每一列存放m个自变量的观察值 597 * @param y[n] 598 * 存放随即变量y的n个观察值 599 * @param m 600 * 自变量的个数 601 * @param n 602 * 观察数据的组数 603 * @param a 604 * 返回回归系数a0,...,am 605 * @param dt[4] 606 * dt[0]偏差平方和q,dt[1] 平均标准偏差s dt[2]返回复相关系数r dt[3]返回回归平方和u 607 * @param v[m] 608 * 返回m个自变量的偏相关系数 609 */ 610 private static void line2sqt(double[][] x, double[] y, int m, int n, double[] a, double[] dt, double[] v) { 611 int i, j, k, mm; 612 double q, e, u, p, yy, s, r, pp; 613 double[] b = new double[(m + 1) * (m + 1)]; 614 mm = m + 1; 615 b[mm * mm - 1] = n; 616 for (j = 0; j <= m - 1; j++) { 617 p = 0.0; 618 for (i = 0; i <= n - 1; i++) 619 p = p + x[j][i]; 620 b[m * mm + j] = p; 621 b[j * mm + m] = p; 622 } 623 for (i = 0; i <= m - 1; i++) 624 for (j = i; j <= m - 1; j++) { 625 p = 0.0; 626 for (k = 0; k <= n - 1; k++) 627 p = p + x[i][k] * x[j][k]; 628 b[j * mm + i] = p; 629 b[i * mm + j] = p; 630 } 631 a[m] = 0.0; 632 for (i = 0; i <= n - 1; i++) 633 a[m] = a[m] + y[i]; 634 for (i = 0; i <= m - 1; i++) { 635 a[i] = 0.0; 636 for (j = 0; j <= n - 1; j++) 637 a[i] = a[i] + x[i][j] * y[j]; 638 } 639 640 chlk(b, mm, 1, a); 641 642 yy = 0.0; 643 for (i = 0; i <= n - 1; i++) 644 yy = yy + y[i] / n; 645 q = 0.0; 646 e = 0.0; 647 u = 0.0; 648 for (i = 0; i <= n - 1; i++) { 649 p = a[m]; 650 for (j = 0; j <= m - 1; j++) 651 p = p + a[j] * x[j][i]; 652 q = q + (y[i] - p) * (y[i] - p); 653 e = e + (y[i] - yy) * (y[i] - yy); 654 u = u + (yy - p) * (yy - p); 655 } 656 s = Math.sqrt(q / n); 657 r = Math.sqrt(1.0 - q / e); 658 for (j = 0; j <= m - 1; j++) { 659 p = 0.0; 660 for (i = 0; i <= n - 1; i++) { 661 pp = a[m]; 662 for (k = 0; k <= m - 1; k++) 663 if (k != j) 664 pp = pp + a[k] * x[k][i]; 665 p = p + (y[i] - pp) * (y[i] - pp); 666 } 667 v[j] = Math.sqrt(1.0 - q / p); 668 } 669 dt[0] = q; 670 dt[1] = s; 671 dt[2] = r; 672 dt[3] = u; 673 } 674 675 private static int chlk(double[] a, int n, int m, double[] d) { 676 int i, j, k, u, v; 677 if ((a[0] + 1.0 == 1.0) || (a[0] < 0.0)) { 678 System.out.println("fail "); 679 return (-2); 680 } 681 a[0] = Math.sqrt(a[0]); 682 for (j = 1; j <= n - 1; j++) 683 a[j] = a[j] / a[0]; 684 for (i = 1; i <= n - 1; i++) { 685 u = i * n + i; 686 for (j = 1; j <= i; j++) { 687 v = (j - 1) * n + i; 688 a[u] = a[u] - a[v] * a[v]; 689 } 690 if ((a[u] + 1.0 == 1.0) || (a[u] < 0.0)) { 691 System.out.println("fail "); 692 return (-2); 693 } 694 a[u] = Math.sqrt(a[u]); 695 if (i != (n - 1)) { 696 for (j = i + 1; j <= n - 1; j++) { 697 v = i * n + j; 698 for (k = 1; k <= i; k++) 699 a[v] = a[v] - a[(k - 1) * n + i] * a[(k - 1) * n + j]; 700 a[v] = a[v] / a[u]; 701 } 702 } 703 } 704 for (j = 0; j <= m - 1; j++) { 705 d[j] = d[j] / a[0]; 706 for (i = 1; i <= n - 1; i++) { 707 u = i * n + i; 708 v = i * m + j; 709 for (k = 1; k <= i; k++) 710 d[v] = d[v] - a[(k - 1) * n + i] * d[(k - 1) * m + j]; 711 d[v] = d[v] / a[u]; 712 } 713 } 714 for (j = 0; j <= m - 1; j++) { 715 u = (n - 1) * m + j; 716 d[u] = d[u] / a[n * n - 1]; 717 for (k = n - 1; k >= 1; k--) { 718 u = (k - 1) * m + j; 719 for (i = k; i <= n - 1; i++) { 720 v = (k - 1) * n + i; 721 d[u] = d[u] - a[v] * d[i * m + j]; 722 } 723 v = (k - 1) * n + k - 1; 724 d[u] = d[u] / a[v]; 725 } 726 } 727 return (2); 728 } 729 730 /** 731 * 获得相关系数 732 * 733 * @param coeff 734 * @return 735 */ 736 private static double getLine2R(double x[][], double y[], double a[], int n) { 737 int size = x[0].length; 738 double ymean = 0.0; 739 double rss = 0; 740 double tss = 0; 741 742 for (int i = 0; i < size; i++) { 743 ymean += y[i]; 744 } 745 746 ymean /= size; 747 748 for (int i = 0; i < size; i++) { 749 rss += (y[i] - getLine2ValueByX(x, a, i)) * (y[i] - getLine2ValueByX(x, a, i)); 750 tss += (y[i] - ymean) * (y[i] - ymean); 751 } 752 753 double r2 = 1 - (rss / (size - n - 1)) / (tss / (size - 1)); 754 755 return r2; 756 } 757 758 /** 759 * 通过X获得Y的值 760 * 761 * @param x 762 * @return 763 */ 764 private static double getLine2ValueByX(double x[][], double a[], int n) { 765 int size = a.length; 766 double result = a[0]; 767 768 for (int i = 1; i < size; i++) { 769 result += x[i - 1][n] * a[i]; 770 } 771 772 return result; 773 } 774 }
  • 相关阅读:
    springcloud 微服务 分布式 Activiti6 工作流 vue.js html 跨域 前后分离
    java 整合redis缓存 SSM 后台框架 rest接口 shiro druid maven bootstrap html5
    继承
    封装
    对象的生命周期
    类与对象
    如何理解类?
    面向过程
    jdk1.8新特性
    git使用指南
  • 原文地址:https://www.cnblogs.com/Jason-MLiu/p/9243138.html
Copyright © 2011-2022 走看看