Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package interpolacja_fs;
- import static java.lang.Math.pow;
- import java.util.Scanner;
- public class Interpolacja_FS {
- public static void main(String[] args) {
- Scanner od = new Scanner(System.in);
- System.out.println("Podaj wilekosc tabeli");
- int n = od.nextInt();
- System.out.println("Podaj jaki x ma byc wyliczony");
- double xx = od.nextDouble();
- double[] x = new double[n];
- double[] y = new double[n];
- for (int i = 0; i < n; i++) {
- System.out.println("Podaj x= ");
- x[i] = od.nextInt();
- System.out.println("Podaj y= ");
- y[i] = od.nextInt();
- }
- // double[] a = lsolve(A, b);
- }
- //--------------------------------------------
- public static double fun_skl(double[] a, double xx, double[] x) {
- double wynik = 0;
- double [] temp = new double [a.length-4];
- temp[0]=0;
- for(int i =0;i<temp.length;i++)
- {
- temp[i]= temp[i]+a[i+4]*(pow(xx-x[i+1],3));
- }
- if (xx < x[1]) {
- for (int i = 0; i < a.length - 3; i++) {
- wynik = wynik + a[i] * pow(xx, i);
- }
- }
- if (xx > x[1] && xx < x[2]) {
- for (int i = 0; i < a.length - 3; i++) {
- wynik = wynik + a[i] * pow(xx, i)+temp[i];
- }
- }
- if (xx > x[2] && xx < x[3]) {
- for (int i = 0; i < a.length - 3; i++) {
- wynik = wynik + a[i] * pow(xx, i)+temp[i+1];
- }
- }
- if (xx > x[3] && xx < x[4]) {
- for (int i = 0; i < a.length - 3; i++) {
- wynik = wynik + a[i] * pow(xx, i)+temp[i+2];
- }
- }
- return wynik;
- }
- public static double[] lsolve(double[][] A, double[] b) {
- int N = b.length;
- for (int p = 0; p < N; p++) {
- // find pivot row and swap
- int max = p;
- for (int i = p + 1; i < N; i++) {
- if (Math.abs(A[i][p]) > Math.abs(A[max][p])) {
- max = i;
- }
- }
- double[] temp = A[p];
- A[p] = A[max];
- A[max] = temp;
- double t = b[p];
- b[p] = b[max];
- b[max] = t;
- // singular or nearly singular
- if (Math.abs(A[p][p]) <= Math.E) {
- throw new RuntimeException("Matrix is singular or nearly singular");
- }
- // pivot within A and b
- for (int i = p + 1; i < N; i++) {
- double alpha = A[i][p] / A[p][p];
- b[i] -= alpha * b[p];
- for (int j = p; j < N; j++) {
- A[i][j] -= alpha * A[p][j];
- }
- }
- }
- // back substitution
- double[] x = new double[N];
- for (int i = N - 1; i >= 0; i--) {
- double sum = 0.0;
- for (int j = i + 1; j < N; j++) {
- sum += A[i][j] * x[j];
- }
- x[i] = (b[i] - sum) / A[i][i];
- }
- return x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement