Advertisement
YauhenMardan

Untitled

May 4th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package com.company;
  2.  
  3. import org.knowm.xchart.SwingWrapper;
  4. import org.knowm.xchart.XYChart;
  5. import org.knowm.xchart.XYChartBuilder;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.Arrays;
  9.  
  10. public class Main {
  11.  
  12. public static void main(String[] args) {
  13. // WindowApp window=new WindowApp();
  14. // window.setVisible(true);
  15. //
  16. XYChart chart=new XYChartBuilder().width(800).height(600).title("My chart").xAxisTitle("k").yAxisTitle("Error").build();
  17. //chart preferenses
  18. chart.getStyler().setChartTitleVisible(true);
  19. chart.getStyler().setYAxisLogarithmic(true);
  20. chart.getStyler().setXAxisLabelRotation(45);
  21. //
  22. ArrayList<Double> errors2Y= new ArrayList<>();//(Arrays.asList(10.0,100.0,100.0,1000.0,10000.1,10000.0,1000000.0,1000000.0));
  23. solveWithNewton2(errors2Y);
  24. //show errors
  25. ArrayList<Integer> errors2X=new ArrayList<>();
  26. for(int i=0;i<errors2Y.size();i++){
  27. errors2X.add(i+1);
  28. }
  29. // for(int i=0;i<errors2Y.size();i++){
  30. // double error=errors2Y.get(i);
  31. // errors2Y.set(i,error/FuncUtils.EPSILON);
  32. // }
  33. chart.addSeries("Newton 2", errors2X,errors2Y);
  34. //show chart
  35. new SwingWrapper<XYChart>(chart).displayChart();
  36. }
  37.  
  38. public static void solveWithNewton2(ArrayList<Double> errors){
  39. double x0, x, error;
  40. int k=0;
  41. //init
  42. x0 = (2.0 + 2.5) / 2.0;
  43. x=x0;
  44. error=2+2.5;
  45. //
  46. while (error > FuncUtils.EPSILON) {
  47. k++;
  48. x0 = x;
  49. x = FuncUtils.NewtonPhi2(x0);
  50. x = FuncUtils.round(x,FuncUtils.PRECISION);
  51. error=FuncUtils.round(FuncUtils.getNorm(x,x0),FuncUtils.PRECISION);
  52. errors.add(error);
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement