Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ohlaba3again;
- /**
- *
- * @author Гость
- */
- public class Ohlaba3again {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- double a = 0.1;
- double b = 0.8;
- int k = 10;
- int n = 35;
- double delta = (b - a)/k;
- double e = 0.0001;
- for (double i = a; i <= b; i += delta)
- {
- double y_an, y_n, y_e, err_e, err_n;
- y_an = f(i);
- y_n = S(i, n);
- y_e = S(i, e);
- /*err_e = err(y_an, y_e);
- err_n = err(y_an, y_n);*/
- //System.out.printf("X=% 8.8f Y=% 8.8f SN=% 8.8f SE=% 8.8f о_погрSN=% 8.8f о_погрSE=% 8.8f\n", i, y_an, y_n, y_e, err_e, err_n);
- System.out.printf("X=% 8.8f Y=% 8.8f SN=% 8.8f SE=% 8.8f \n", i, y_an,y_n,y_e);
- }
- }
- public static double f(double x) //Аналитическая формула
- {
- // System.out.println("TEST X: "+ x);
- //double y = ((Math.pow(Math.PI, 2)/8) - (Math.PI/4)*Math.abs(x));
- double y = -0.5*Math.log(1-2*x*Math.cos(Math.PI/3)+Math.pow(x, 2));
- return y;
- }
- public static double S(double x, int n) //Конечная сумма n членов ряда
- {
- double y = 0;
- for (int i = 1; i <= n; i++)
- {
- //y += (Math.cos((2*i - 1)*x))/Math.pow((2*i - 1), 2);
- y+= Math.pow(x, i)*Math.cos(i*(Math.PI/3));
- }
- return y;
- }
- public static double S(double x, double e) //Конечная сумма с погрешностью e
- {
- double y = 0;
- double y_an = f(x);
- System.out.println("TEST Y_an:" + y_an);
- for (int i = 1; Math.abs(y - y_an) > e; i++)
- {
- //y += (Math.cos((2*i - 1)*x))/Math.pow((2*i - 1), 2);
- y+= Math.pow(x, i)*Math.cos(i*(Math.PI/3));
- }
- return y;
- }
- public static double err(double y_an, double y) //Относительная погрешность
- {
- return Math.abs((y_an - y)/y_an);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement