fork download
  1. package laba3;
  2.  
  3. public class Laba3
  4. {
  5. public static void main(String[] args) {
  6. {
  7. double a = Math.PI/5;
  8. double b = 9*Math.PI/5;
  9. int k = 10;
  10. int n = 40;
  11. double delta = (b - a)/k;
  12. double e = 0.0001;
  13. for (double i = a; i <= b; i += delta)
  14. {
  15. double y_an, y_n, y_e, err_e, err_n;
  16.  
  17. y_an = f(i);
  18. y_n = S(i, n);
  19. y_e = S(i, e);
  20. 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);
  21.  
  22. }
  23. }
  24. }
  25. public static double f(double x) //Аналитическая формула
  26. {
  27. double y = (-Math.log(2)*Math.abs((2)*Math.sin(x/2)));
  28.  
  29. return y;
  30. }
  31.  
  32. public static double S(double x, int n) {
  33. double y = 0.;
  34. for (int i = 1; i <= n; i++) {
  35. y += Math.cos(i * x) / (double) i;
  36. }
  37. return y;
  38. }
  39.  
  40. public static double S(double x, double e) //Конечная сумма с погрешностью e
  41. {
  42. double y = 0;
  43. double y_an = f(x);
  44.  
  45. for (int i = 1; Math.abs(y - y_an) > e; i++)
  46. {
  47. y += (Math.acos((2*i - 1)*x))/Math.pow((2*i - 1), 2);
  48. }
  49. return y;
  50. }
  51. }
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class Laba3 is public, should be declared in a file named Laba3.java
public class Laba3
       ^
1 error
stdout
Standard output is empty