└── REGRESSION /REGRESSION: -------------------------------------------------------------------------------- 1 | package simpleregression; 2 | 3 | public class Simpleregression { 4 | 5 | private static final double[] CN_A = {0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}; 6 | private static final double[] CN_B = {0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.92}; 7 | private static final double[] CN_C = {0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45}; 8 | 9 | 10 | public static double calculateRunoff(double precipitation, double runoffCoefficient) { 11 | double cn = lookupCNValue(runoffCoefficient); 12 | double runoff = (precipitation - (0.2 * Math.pow(cn - 10, 2.0) / (cn + 0.8))); 13 | return Math.max(runoff, 0); 14 | } 15 | 16 | private static double lookupCNValue(double runoffCoefficient) { 17 | for (int i = 0; i < CN_B.length; i++) { 18 | if (runoffCoefficient <= CN_B[i]) { 19 | return CN_A[i] * Math.exp(CN_C[i] * runoffCoefficient); 20 | } 21 | } 22 | return 100; 23 | } 24 | 25 | public static double estimateSoilMoisture(double precipitation, double evapotranspiration, double initialSoilMoisture) { 26 | 27 | return initialSoilMoisture + precipitation - evapotranspiration; 28 | } 29 | 30 | public static void main(String[] args) { 31 | double precipitation = 50; 32 | double runoffCoefficient = 0.3; 33 | double evapotranspiration = 20; 34 | double initialSoilMoisture = 100; 35 | 36 | double runoff = calculateRunoff(precipitation, runoffCoefficient); 37 | double finalSoilMoisture = estimateSoilMoisture(precipitation, evapotranspiration, initialSoilMoisture); 38 | 39 | System.out.println("Estimated Runoff: " + runoff + " mm"); 40 | System.out.println("Final Soil Moisture: " + finalSoilMoisture + " mm"); 41 | } 42 | } 43 | --------------------------------------------------------------------------------