Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package logic;
- /**
- * Created by Alexey on 07.05.2016.
- */
- public class GSM {
- private double a, b, epsilon;
- public double getA() {
- return a;
- }
- public void setA(double a) {
- this.a = a;
- }
- public double getB() {
- return b;
- }
- public void setB(double b) {
- this.b = b;
- }
- public double getEpsilon() {
- return epsilon;
- }
- public void setEpsilon(double epsilon) {
- this.epsilon = epsilon;
- }
- private double f(double x){
- return 3.0*x - 2.;
- }
- public double algorithm(){
- double y = a + ((3. - Math.sqrt(5.))/(2.))*(b - a);
- double z = a + b - y;
- while (Math.abs(b - a) > epsilon){
- System.out.print(a + " a " + b + " b ");
- System.out.print(epsilon + " epsilon ");
- System.out.println(Math.abs(b-a) + " module");
- if (f(y) <= f(z)){
- b = z;
- y = a + b - y;
- z = y;
- } else {
- a = y;
- y = z;
- z = a + b - y;
- }
- }
- return ((a + b) / 2.);
- }
- }
- package logic;
- /**
- * Created by Alexey on 07.05.2016.
- */
- public class Main {
- public static void main(String[] args) {
- GSM gsm = new GSM();
- gsm.setA(1.004);
- gsm.setB(3.);
- gsm.setEpsilon(0.000000001);
- System.out.println(gsm.algorithm());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment