Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package ohlaba3again;
  8.  
  9. /**
  10. *
  11. * @author Гость
  12. */
  13. public class Ohlaba3again {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. // TODO code application logic here
  20. double a = 0.1;
  21. double b = 0.8;
  22. int k = 10;
  23. int n = 35;
  24. double delta = (b - a)/k;
  25. double e = 0.0001;
  26.  
  27. for (double i = a; i <= b; i += delta)
  28. {
  29. double y_an, y_n, y_e, err_e, err_n;
  30.  
  31. y_an = f(i);
  32. y_n = S(i, n);
  33. y_e = S(i, e);
  34. /*err_e = err(y_an, y_e);
  35. err_n = err(y_an, y_n);*/
  36.  
  37. //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);
  38. System.out.printf("X=% 8.8f Y=% 8.8f SN=% 8.8f SE=% 8.8f \n", i, y_an,y_n,y_e);
  39.  
  40. }
  41. }
  42. public static double f(double x) //Аналитическая формула
  43. {
  44. // System.out.println("TEST X: "+ x);
  45. //double y = ((Math.pow(Math.PI, 2)/8) - (Math.PI/4)*Math.abs(x));
  46. double y = -0.5*Math.log(1-2*x*Math.cos(Math.PI/3)+Math.pow(x, 2));
  47. return y;
  48. }
  49.  
  50. public static double S(double x, int n) //Конечная сумма n членов ряда
  51. {
  52. double y = 0;
  53. for (int i = 1; i <= n; i++)
  54. {
  55. //y += (Math.cos((2*i - 1)*x))/Math.pow((2*i - 1), 2);
  56. y+= Math.pow(x, i)*Math.cos(i*(Math.PI/3));
  57. }
  58. return y;
  59. }
  60.  
  61. public static double S(double x, double e) //Конечная сумма с погрешностью e
  62. {
  63. double y = 0;
  64. double y_an = f(x);
  65. System.out.println("TEST Y_an:" + y_an);
  66. for (int i = 1; Math.abs(y - y_an) > e; i++)
  67. {
  68. //y += (Math.cos((2*i - 1)*x))/Math.pow((2*i - 1), 2);
  69. y+= Math.pow(x, i)*Math.cos(i*(Math.PI/3));
  70. }
  71. return y;
  72. }
  73.  
  74. public static double err(double y_an, double y) //Относительная погрешность
  75. {
  76. return Math.abs((y_an - y)/y_an);
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement