/
levg
/
numm
Обзор
Документация
Войти
/
levg
/
numm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
8/code/graph4.py
44 строки
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 error_at_point(filename, point): x, _, _, error = load_data(filename) idx = (np.abs(x - point)).argmin() return error[idx] def plot_error_at_points_vs_nodes(files, points, title): nodes = [] errors_at_points = {point: [] for point in points} for file in files: nodes_count = int(file.split('_')[-1].split('.')[0]) nodes.append(nodes_count) for point in points: error = error_at_point(file, point) errors_at_points[point].append(error) print(f"Файл {file}: узлов = {nodes_count}, ошибка в точке {point} = {error}") plt.figure(figsize=(10, 6)) for point, errors in errors_at_points.items(): plt.plot(nodes, errors, marker='o', label=f'Ошибка в точке {point}') 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)] points = [1.5, 4.5] plot_error_at_points_vs_nodes(interp_files_chebyshev, points, f"Зависимость ошибки в выбранных точках от количества узлов")