Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import org.knowm.xchart.SwingWrapper;
- import org.knowm.xchart.XYChart;
- import org.knowm.xchart.XYChartBuilder;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- // WindowApp window=new WindowApp();
- // window.setVisible(true);
- //
- XYChart chart=new XYChartBuilder().width(800).height(600).title("My chart").xAxisTitle("k").yAxisTitle("Error").build();
- //chart preferenses
- chart.getStyler().setChartTitleVisible(true);
- chart.getStyler().setYAxisLogarithmic(true);
- chart.getStyler().setXAxisLabelRotation(45);
- //
- ArrayList<Double> errors2Y= new ArrayList<>();//(Arrays.asList(10.0,100.0,100.0,1000.0,10000.1,10000.0,1000000.0,1000000.0));
- solveWithNewton2(errors2Y);
- //show errors
- ArrayList<Integer> errors2X=new ArrayList<>();
- for(int i=0;i<errors2Y.size();i++){
- errors2X.add(i+1);
- }
- // for(int i=0;i<errors2Y.size();i++){
- // double error=errors2Y.get(i);
- // errors2Y.set(i,error/FuncUtils.EPSILON);
- // }
- chart.addSeries("Newton 2", errors2X,errors2Y);
- //show chart
- new SwingWrapper<XYChart>(chart).displayChart();
- }
- public static void solveWithNewton2(ArrayList<Double> errors){
- double x0, x, error;
- int k=0;
- //init
- x0 = (2.0 + 2.5) / 2.0;
- x=x0;
- error=2+2.5;
- //
- while (error > FuncUtils.EPSILON) {
- k++;
- x0 = x;
- x = FuncUtils.NewtonPhi2(x0);
- x = FuncUtils.round(x,FuncUtils.PRECISION);
- error=FuncUtils.round(FuncUtils.getNorm(x,x0),FuncUtils.PRECISION);
- errors.add(error);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement