/
levg
/
numm
Обзор
Документация
Войти
/
levg
/
numm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
8/code/graph3.py
49 строк
2 KB
Лев Черняховский
s
29 окт 2024, 10:38
29 окт 2024, 10:38
d9048cd
Код
Авторство
О чём код?
import numpy as np import matplotlib.pyplot as plt def load_data(filename): data = np.loadtxt('C:/Users/Aser/source/repos/Chisl2sem1homework/' + filename) return data[:, 0], data[:, 1], data[:, 2], data[:, 3] def max_error_from_file(filename): _, _, _, error = load_data(filename) return np.max(np.abs(error)) def plot_max_error_vs_nodes(uniform_files, chebyshev_files, title): uniform_nodes = [] uniform_max_errors = [] chebyshev_nodes = [] chebyshev_max_errors = [] for interp_file in uniform_files: max_err = max_error_from_file(interp_file) nodes_count = int(interp_file.split('_')[-1].split('.')[0]) uniform_nodes.append(nodes_count) uniform_max_errors.append(max_err) print(f"Равномерная сетка - Файл {interp_file}: узлов = {nodes_count}, максимальная ошибка = {max_err}") for interp_file in chebyshev_files: max_err = max_error_from_file(interp_file) nodes_count = int(interp_file.split('_')[-1].split('.')[0]) chebyshev_nodes.append(nodes_count) chebyshev_max_errors.append(max_err) print(f"Чебышевская сетка - Файл {interp_file}: узлов = {nodes_count}, максимальная ошибка = {max_err}") plt.figure(figsize=(10, 6)) plt.plot(uniform_nodes, uniform_max_errors, marker='o', label='Равномерная сетка') plt.plot(chebyshev_nodes, chebyshev_max_errors, marker='x', label='Чебышевская сетка') plt.yscale('log') plt.xscale('log') plt.title(title) plt.xlabel('Количество узлов') plt.ylabel('Максимальная ошибка') plt.legend() plt.grid(True) plt.show() nfunc = 1 interp_files_uniform= [f'error_uniform_func{nfunc}_{i}.txt' for i in range(5,101)] interp_files_chebyshev = [f'error_chebyshev_func{nfunc}_{i}.txt' for i in range(5,101)] plot_max_error_vs_nodes(interp_files_uniform, interp_files_chebyshev, f"Максимальная ошибка интерполяции для функции {nfunc}")