Compare commits
2
Commits
ce1a12056d
...
e90d5ebc49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e90d5ebc49 | ||
|
|
57b01edebd |
No files matched your search
@@ -97,4 +97,3 @@ add_mmps_plugin(
|
||||
# ПРИМЕР ЗАПУСКА ИЗ КАТАЛОГА build
|
||||
# bin/Release/mmps_host.exe (Visual Studio)
|
||||
# bin/mmps_host (Linux/Makefiles)
|
||||
# Каталог плагинов и значения k1, k2, h программа запросит через std::cin.
|
||||
+6
-12
@@ -5,7 +5,6 @@ from scipy.optimize import least_squares
|
||||
K1_REFERENCE = 0.577
|
||||
K2_REFERENCE = 0.422
|
||||
|
||||
# Диапазоны из задания
|
||||
K1_BOUNDS = (1e-5, 1e2)
|
||||
K2_BOUNDS = (1e-2, 1.0)
|
||||
|
||||
@@ -79,15 +78,11 @@ def rk4_solution(t, k1, k2):
|
||||
|
||||
return solution
|
||||
|
||||
|
||||
# Моменты времени из задания:
|
||||
# tj = 0.1j, j = 0, ..., 100
|
||||
time = np.linspace(T_BEGIN, T_END, 101)
|
||||
|
||||
# Эталонные данные
|
||||
reference_solution = analytical_solution(time, K1_REFERENCE, K2_REFERENCE)
|
||||
|
||||
|
||||
def residuals(parameters):
|
||||
"""
|
||||
Вектор невязок между моделью и эталонными данными.
|
||||
@@ -120,17 +115,16 @@ absolute_error_k2 = abs(found_k2 - K2_REFERENCE)
|
||||
|
||||
relative_error_k1 = absolute_error_k1 / K1_REFERENCE * 100.0
|
||||
relative_error_k2 = absolute_error_k2 / K2_REFERENCE * 100.0
|
||||
criterion_value = np.sum(result.fun ** 2)
|
||||
|
||||
print("Results")
|
||||
print(f"Found k1:{found_k1:.4f}")
|
||||
print(f"Theoretical k1:{K1_REFERENCE:.4f}")
|
||||
print(f"Absolute error of k1:{absolute_error_k1:.4e}")
|
||||
print(f"Relative error of k1:{relative_error_k1:.4e} %")
|
||||
print(f"Absolute error of k1:{absolute_error_k1:.5e}")
|
||||
print(f"Relative error of k1:{relative_error_k1:.5e} %")
|
||||
print()
|
||||
|
||||
print(f"Found k2:{found_k2:.4f}")
|
||||
print(f"Theoretical k2:{K2_REFERENCE:.4f}")
|
||||
print(f"Absolute error of k2:{absolute_error_k2:.4e}")
|
||||
print(f"Relative error of k2:{relative_error_k2:.4e} %")
|
||||
print(f"Found k2:{found_k2:.5f}")
|
||||
print(f"Theoretical k2:{K2_REFERENCE:.5f}")
|
||||
print(f"Absolute error of k2:{absolute_error_k2:.5e}")
|
||||
print(f"Relative error of k2:{relative_error_k2:.5e} %")
|
||||
print()
|
||||
@@ -0,0 +1,50 @@
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def export_component_comparison(
|
||||
rk4_path: str,
|
||||
ab2_path: str,
|
||||
component: str,
|
||||
ylabel: str,
|
||||
out_name: str,
|
||||
):
|
||||
"""
|
||||
Строит график зависимости одной компоненты x_i(t) от времени,
|
||||
на котором результаты метода Рунге--Кутты и метода Адамса--Башфорта
|
||||
представлены на общей координатной плоскости (п.4 базовой части задания).
|
||||
"""
|
||||
df_rk4 = pd.read_csv(rk4_path)
|
||||
df_ab2 = pd.read_csv(ab2_path)
|
||||
|
||||
t_rk4, y_rk4 = df_rk4["t"].values, df_rk4[component].values
|
||||
t_ab2, y_ab2 = df_ab2["t"].values, df_ab2[component].values
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
|
||||
plt.plot(t_rk4, y_rk4, label="Рунге--Кутты 4-го порядка",
|
||||
linewidth=2.2, color="#1f77b4")
|
||||
plt.plot(t_ab2, y_ab2, label="Адамса--Башфорта 2-го порядка",
|
||||
linewidth=1.8, color="#ff7f0e", linestyle="--")
|
||||
|
||||
plt.xlabel("t", fontsize=12)
|
||||
plt.ylabel(ylabel, fontsize=12)
|
||||
plt.grid(True, which="both", linestyle="--", alpha=0.6)
|
||||
plt.legend(fontsize=11, loc="best", framealpha=0.9)
|
||||
|
||||
t_min = min(t_rk4.min(), t_ab2.min())
|
||||
t_max = max(t_rk4.max(), t_ab2.max())
|
||||
plt.xlim(t_min - 0.1, t_max + 0.1)
|
||||
plt.ylim(-0.02, 1.05)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"figures/{out_name}.png", dpi=300)
|
||||
plt.close()
|
||||
|
||||
|
||||
RK4_CSV = "../build/bin/results/runge_kutta_plugin.csv"
|
||||
AB2_CSV = "../build/bin/results/adams_bashforth_plugin.csv"
|
||||
|
||||
export_component_comparison(RK4_CSV, AB2_CSV, "x1", r"$x_1(t)$", "x1_comparison")
|
||||
export_component_comparison(RK4_CSV, AB2_CSV, "x2", r"$x_2(t)$", "x2_comparison")
|
||||
export_component_comparison(RK4_CSV, AB2_CSV, "x3", r"$x_3(t)$", "x3_comparison")
|
||||
Reference in new issue
Block a user