Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- private static final double epsilon = 0.000001;
- private static double from;
- private static double to;
- private static double aprior;
- public static void main(String[] args) {
- double xcur;
- double xnext = calculateApproximateX();
- int iterations = 0;
- System.out.println("Выполнение условий теоремы: " + checkTheoremConditions(xnext));
- System.out.println("Начальное приближение: " + xnext);
- do {
- xcur = xnext;
- xnext = calculateFi(xcur);
- iterations++;
- } while (Math.abs(xnext - xcur) >= epsilon);
- System.out.println("Решение: " + xnext);
- System.out.println("Невязка: " + Math.abs(calculateF(xnext)));
- System.out.println("Количество итераций: " + iterations);
- System.out.println("Априорное количество итераций: " + aprior);
- }
- private static double calculateApproximateX() {
- double left = -0.5;
- double right = 0.5;
- double tmp;
- while (Math.abs(left - right) >= 10) {
- tmp = (left + right) / 2;
- if (calculateF(left) * calculateF(tmp) < 0) {
- right = tmp;
- } else {
- left = tmp;
- }
- }
- from = left;
- to = right;
- return (left + right) / 2;
- }
- private static double calculateF(double x) {
- return Math.pow(x, 2) - Math.pow(Math.cos(Math.PI * x),2);
- }
- private static double calculateFi(double x) {
- return Math.acos(Math.pow(Math.pow(x, 2), 0.5)) / Math.PI;
- }
- private static double calculateFiDeriv(double x) {
- return - x / (Math.PI * Math.pow(Math.pow(x, 2) - Math.pow(x, 4), 0.5));
- }
- private static boolean checkTheoremConditions(double xApprox) {
- double delta = (to - from) / 2;
- double m = Math.abs(xApprox - calculateFi(xApprox));
- double q = Math.max(calculateFiDeriv(to), calculateFiDeriv(from));
- aprior = Math.log(epsilon * (1 - q) / m) / Math.log(q);
- return (m / (1 - q)) <= delta;
- }
- }
- Выполнение условий теоремы: true
- Начальное приближение: 0.0
- Решение: 0.3769668917546923
- Невязка: 3.4676940013911306E-7
- Количество итераций: 14
- Априорное количество итераций: 14
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement