From 98a3e9760177fc86324e12b39597f8d5bab20bf7 Mon Sep 17 00:00:00 2001 From: Andrii Solianyk Date: Wed, 13 Nov 2024 23:14:28 +0100 Subject: [PATCH] Done --- .idea/editor.xml | 103 ++++++++++++++++++++++++ horner/CMakeLists.txt => CMakeLists.txt | 2 +- horner/horner_class.cpp | 4 + interpolacja/Interpolacja.cpp | 41 +++++----- 4 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 .idea/editor.xml rename horner/CMakeLists.txt => CMakeLists.txt (81%) diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..855412d --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,103 @@ + + + + + \ No newline at end of file diff --git a/horner/CMakeLists.txt b/CMakeLists.txt similarity index 81% rename from horner/CMakeLists.txt rename to CMakeLists.txt index d5af0e5..79727d0 100644 --- a/horner/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,4 +4,4 @@ project(MO_pracadomowa) set(CMAKE_CXX_STANDARD 14) add_executable(MO_pracadomowa - horner_simple.cpp) + main.cpp) diff --git a/horner/horner_class.cpp b/horner/horner_class.cpp index dfcb0fe..929db59 100644 --- a/horner/horner_class.cpp +++ b/horner/horner_class.cpp @@ -1,3 +1,7 @@ +#if WIN32 +#include +#endif + #include #include #include diff --git a/interpolacja/Interpolacja.cpp b/interpolacja/Interpolacja.cpp index f2d8999..12a8301 100644 --- a/interpolacja/Interpolacja.cpp +++ b/interpolacja/Interpolacja.cpp @@ -43,7 +43,7 @@ public: void oblicz() { - bool rowne_odstepy = true; + rowne_odstepy = true; float pierwszy_odstep = x[1] - x[0]; // Sprawdzenie czy odstępy x są takie same @@ -87,39 +87,41 @@ public: else { // Lagrange - suma = 0.0; + suma = 0; for (int i = 0; i < liczba_wezlow; i++) { - double iloczyn = tablica_roznic[i][0]; + float L = 1; for (int j = 0; j < liczba_wezlow; j++) { if (i != j) { - iloczyn *= (x[j] - x[0]) / (x[i] - x[j]); + L *= (x[j] - x[0]) / (x[j] - x[i]); } } - suma += iloczyn; + suma += L * y[i]; } } } void wyswietl_tabela() { - // nagłowki - cout << setw(5) << "i" << setw(10) << "x" << setw(10) << "y"; - for (int j = 1; j < liczba_wezlow; ++j) - cout << setw(10) << "Δ^" + to_string(j); - cout << endl; - - // wartości - for (int i = 0; i < liczba_wezlow; i++) - { - cout << setw(5) << i << setw(10) << x[i]; - for (int j = 0; j < liczba_wezlow - i; j++) - { - cout << setw(10) << tablica_roznic[i][j]; - } + if(rowne_odstepy) { + // nagłowki + cout << setw(5) << "i" << setw(10) << "x" << setw(10) << "y"; + for (int j = 1; j < liczba_wezlow; ++j) + cout << setw(10) << "Δ^" + to_string(j); cout << endl; + + // wartości + for (int i = 0; i < liczba_wezlow; i++) + { + cout << setw(5) << i << setw(10) << x[i]; + for (int j = 0; j < liczba_wezlow - i; j++) + { + cout << setw(10) << tablica_roznic[i][j]; + } + cout << endl; + } } cout << "Interpolowany wynik: " << suma << endl; @@ -128,6 +130,7 @@ public: private: float a, b, h, suma, czynnik; int liczba_wezlow; + bool rowne_odstepy; vector x, y; vector > tablica_roznic; };