/
levg
/
numm
Обзор
Документация
Войти
/
levg
/
numm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
8/code/graph1.py
65 строк
2 KB
Лев Черняховский
8new
31 окт 2024, 16:19
31 окт 2024, 16:19
8adb061
Код
Авторство
О чём код?
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 plot_functions_and_interpolations(interp_files, labels, title, node_files=None): plt.figure(figsize=(10, 6)) for i, interp_file in enumerate(interp_files): x, f_value, p_value, error = load_data(interp_file) if i == 0: plt.plot(x, f_value, label='Функция', color='black', linewidth=2) #plt.plot(x, p_value, label=labels[i]) if node_files: x_nodes, f_nodes, p_nodes, _ = load_data(node_files[i]) plt.scatter(x, p_value, label=labels[i], marker='o') plt.title(title) plt.xlabel('x') plt.ylabel('y') plt.legend() plt.grid(True) plt.show() def plot_errors(interp_files, labels, title): plt.figure(figsize=(10, 6)) for i, interp_file in enumerate(interp_files): x, f_value, p_value, error = load_data(interp_file) plt.plot(x, error, label=f'Ошибка: {labels[i]}') plt.title(title) plt.xlabel('x') plt.ylabel('Ошибка') plt.legend() plt.grid(True) plt.show() nfunc=2 func_file1_uniform = f'error_uniform_func{nfunc}_5.txt' interp_files1_uniform = [f'error_uniform_func{nfunc}_5.txt', f'error_uniform_func{nfunc}_6.txt', f'error_uniform_func{nfunc}_7.txt'] interp_files1_chebyshev = [f'error_chebyshev_func{nfunc}_5.txt', f'error_chebyshev_func{nfunc}_6.txt', f'error_chebyshev_func{nfunc}_7.txt'] labels_uniform = [ 'Полином 5 узлов', 'Полином 6 узлов', 'Полином 7 узлов' ] labels_chebyshev = [ 'Полином 5 узлов', 'Полином 6 узлов', 'Полином 7 узлов' ] plot_functions_and_interpolations(interp_files1_uniform, labels_uniform, f"Функция и полиномы для функции {nfunc} (Равномерная сетка)") plot_functions_and_interpolations(interp_files1_chebyshev, labels_chebyshev, f"Функция и полиномы для функции {nfunc} (Чебышевская сетка)")