Untitled

mail@pastecode.io avatar
unknown
java
23 days ago
622 B
1
Indexable
Never
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