Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double limitFromLeft(double right, double startPoint){
- double tmp = 0;
- double further = startPoint;
- double closer = right + (further - right) / 2;
- double valCloser = Math.exp(closer);
- double valFurther = Math.exp(further);
- if (Math.abs(valFurther - valCloser) < 1e-50) return valCloser;
- else{
- do{
- tmp = closer;
- closer = closer - (further - closer) / 2;
- further = tmp;
- valCloser = Math.log(closer);
- valFurther = Math.log(further);
- i++;
- }while(Math.abs(valFurther - valCloser) > 1e-50);
- return valCloser;
- }
- } // w obu funkcjach analogicznie przekazywać zamiast Math.exp() funcExec(command, *)
- public static double [] generateOutput (double left, double right, double h, int ilosc_wezlow){
- double [] output = new double[ilosc_wezlow];
- double arg = 0;
- for (int i = 0; i < ilosc_wezlow; i++)
- {
- arg = left + h * i;
- output[i] = arg;
- }
- return output;
- }
- public static double newtonCotes (double eps, double left, double right){
- int ilosc_wezlow = 3;
- double h = (right - left)/2;
- double[] output = generateOutput (left, right, h, ilosc_wezlow);
- double wynik = (h/3) * (output[0] + 4 * output[1] + output[2]);
- double wynik_poprzedni = wynik;
- for(int i = 1; i < 30; i++) // maks. ilosc iteracji - 30
- {
- ilosc_wezlow += 2 * i;
- h = (right - left) / (ilosc_wezlow - 1);
- output = generateOutput (left, right, h, ilosc_wezlow);
- wynik = left + right;
- for(int j = 1; j <= (ilosc_wezlow - 1)/2; j++)
- {
- wynik += 4 * output[2*j - 1];
- }
- for(int j = 1; j < (ilosc_wezlow - 1)/2; j++)
- {
- wynik += 2 * output[2*j];
- }
- wynik = wynik * (h/3);
- if (Math.abs(wynik - wynik_poprzedni) < eps) return wynik;
- }
- return wynik;
- }
- public static double gaussLegendre(int iter, double left, double right){
- double wynik = 0;
- double arg = 0;
- double[][] nodes = new double[][] {
- new double[] { -0.577350269189626, 0.577350269189626 },
- new double[] { -0.774596669241483, 0.0, 0.774596669241483 },
- new double[] { -0.861136311594053, -0.339981043584856,
- 0.339981043584856, 0.861136311594053 },
- new double[] { -0.906179845938664, -0.538469310105683, 0.0,
- 0.538469310105683, 0.906179845938664 }
- };
- double[][] weights = new double[][] {
- new double[] { 1.0, 1.0 },
- new double[] { 0.555555555555556, 0.888888888888889,
- 0.555555555555556 },
- new double[] { 0.347854845137454, 0.652145154862544,
- 0.652145154862544, 0.347854845137454 },
- new double[] { 0.236926885056189, 0.478628670499366,
- 0.568888888888889, 0.478628670499366, 0.236926885056189 } };
- for (int i = 0; i < iter; ++i) {
- arg = (right - left) / 2 * nodes[iter - 2][i] + (right + left) / 2;
- wynik += weights[iter - 2][i] * Math.exp(arg) * (right - left) / 2;
- }
- return wynik;
- } // w miejsce Math.exp(arg) wstawić funcExec(command, arg) i przekazać Command command jako argument
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement