Untitled

 avatar
unknown
java
a year ago
622 B
2
Indexable
import static java.lang.Math.log;
import static java.lang.Math.pow;

public class rule_of_doubling {

	public static void main(String[] args) {
		double temp_min = error_sum(1), optim = 10; //temporary optima
		for (double k = 10; k<=100; k+=0.5) {
			double sum_error = error_sum(k);
			if (sum_error < temp_min) { //updating the optimal figures
				temp_min = sum_error; 
				optim = k;
			}
		}
		System.out.println(optim);
	}
	
	public static double error_sum(double k) {
		double sum_error = 0;
		for (double r = 0.01; r<=0.2; r+=0.005) {
			sum_error += pow((log(2)/log(1+r)) - (k/r),2);
		}
		return sum_error;
	}
}
Leave a Comment