Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package lab1;
  2.  
  3. import org.jfree.chart.ChartFactory;
  4. import org.jfree.chart.ChartPanel;
  5. import org.jfree.chart.JFreeChart;
  6. import org.jfree.chart.plot.PlotOrientation;
  7. import org.jfree.data.xy.XYDataset;
  8. import org.jfree.data.xy.XYSeries;
  9. import org.jfree.data.xy.XYSeriesCollection;
  10.  
  11. import javax.swing.*;
  12. import java.awt.*;
  13.  
  14. public class Main {
  15.  
  16. public static void main(String[] args) {
  17.  
  18. double t0=Math.PI/2;
  19. double tmax = t0+3;
  20. double u=1.0;
  21.  
  22. double h= 0.05;
  23.  
  24.  
  25. // Явный Эйлер
  26. for (double t=t0; t< tmax; t+=h) {
  27.  
  28. u=u+h*((u/t) + t*Math.sin(t));
  29. System.out.println("E = " + Math.abs((((2*t)/Math.PI) - t*Math.cos(t)) - u));
  30. //System.out.println("(" + t + ";" + u + ")");
  31. //System.out.println("(" + t + ";" + (((2*t)/Math.PI) - t*Math.cos(t)) + ")");
  32.  
  33. }
  34. u=1.0; // Коши-Эйлер
  35.  
  36. for (double t=t0; t< tmax; t+=0.1) {
  37. double uNew =u+0.1*((u/t) + t*Math.sin(t));
  38.  
  39. for (int i =0; i<3; i++) {
  40.  
  41. uNew=u+(0.1*(((u/t) + t*Math.sin(t))+((uNew/(t+0.1))+((t+0.1) * Math.sin((t+0.1))))))/2;
  42. }
  43. u = uNew;
  44. System.out.println("E = " + Math.abs((((2*t)/Math.PI) - t*Math.cos(t)) - u));
  45. // System.out.println("(" + t + ";" + uNew + ")");
  46. //System.out.println("(" + t + ";" + (((2*t)/Math.PI) - t*Math.cos(t)) + ")");
  47. }
  48.  
  49. u=1/9.0;
  50. double z =-2/9.0;
  51. for (double t=0; t<=1; t+=0.2) {
  52. u=u+0.2*(u-z+1);
  53. z=z+0.2*(z-4*u+t);
  54. System.out.println("E(u) = " + Math.abs(funcU(t)-u));
  55. System.out.println("E(z) = " + Math.abs(funcZ(t)-z));
  56. // System.out.println("("+ t +";" + u +")");
  57. //System.out.println("("+ t +";" + z +")");
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. System.out.println("End");
  65. }
  66.  
  67. public static double funcU(double x) {
  68. return (-0.25*Math.pow(Math.E,-x))+0.25*Math.pow(Math.E,3*x)+(1/9)+(x/3);
  69. }
  70.  
  71. public static double funcZ(double x) {
  72. return ((-1/2)*Math.pow(Math.E,-x)) - (0.5*Math.pow(Math.E,3*x)) +(7/9) + (x/3);
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement