/
aytsan_ns
/
Num_meth
Обзор
Документация
Войти
/
aytsan_ns
/
Num_meth
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Lab8/Lab_1.m
188 строк
5 KB
aytsan-ns
Оформлена часть отчета 10 лабы, сделаны графики зависимостей ошибки и числа итераций от точности.
28 авг 2024, 20:14
28 авг 2024, 20:14
baf4b0a
Код
Авторство
О чём код?
function1 = @(x) log(x+2) + x; function2 = @(x) x.^3 - 0.1*x.^2 + 0.4*abs(x) + 2; %{ �������� �� �������� ����� fid = fopen('points1.txt', 'r'); if fid == -1 error('�� ������� ������� ����.'); else data = fread(fid); fclose(fid); disp(char(data')); % ����� ����������� ����� ��� ������ end %} %{ ����������� ������ ������ ������������ ��������� points1 = dlmread('points1.txt'); values1 = dlmread('values1.txt'); points_Cheb1 = dlmread('points_cheb1.txt'); values_Cheb1 = dlmread('values_cheb1.txt'); points2 = dlmread('points2.txt'); values2 = dlmread('values2.txt'); points_Cheb2 = dlmread('points_cheb2.txt'); values_Cheb2 = dlmread('values_cheb2.txt'); Newton1 = dlmread('Newton1.txt'); Newton2 = dlmread('Newton2.txt'); Newton_Cheb1 = dlmread('Newton_cheb1.txt'); Newton_Cheb2 = dlmread('Newton_cheb2.txt'); X1 = -1.5 : 0.01 : 1.99; X2 = -1 : 0.01 : 0.99; figure; hold on; fplot(function1, [-1.5 2]); plot(X1, Newton1, 'g'); plot(X1, Newton_Cheb1, 'r'); plot(points1, values1, 'og'); plot(points_Cheb1, values_Cheb1, 'or'); grid on legend('�������', '����', '���', '����������� �����', '����� ��������', 'Location','northwest'); title('$\bf y = ln(x + 2) + x, \; n = 5$', 'Interpreter','latex'); figure; hold on; fplot(function2, [-1 1]); plot(X2, Newton2, 'g'); plot(X2, Newton_Cheb2, 'r'); plot(points2, values2, 'og'); plot(points_Cheb2, values_Cheb2, 'or'); grid on legend('�������', '����', '���', '����������� �����', '����� ��������', 'Location','northwest'); title('$\bf y = x^3 - 0.1x^2 + 0.4|x| + 2, \; n = 5$', 'Interpreter','latex'); error_Newton1 = dlmread('error_Newton1.txt'); error_Newton2 = dlmread('error_Newton2.txt'); error_Newton_Cheb1 = dlmread('error_Newton_cheb1.txt'); error_Newton_Cheb2 = dlmread('error_Newton_cheb2.txt'); teor_error_Newton1 = dlmread('teor_error_Newton1.txt'); teor_error_Newton2 = dlmread('teor_error_Newton2.txt'); teor_error_Newton_Cheb1 = dlmread('teor_error_Newton_cheb1.txt'); teor_error_Newton_Cheb2 = dlmread('teor_error_Newton_cheb2.txt'); figure; hold on; plot(X1, error_Newton1, 'g'); plot(X1, error_Newton_Cheb1, 'r'); plot(X1, teor_error_Newton1, 'b'); plot(X1, teor_error_Newton_Cheb1, 'y'); grid on legend('����', '���', '����. ������ ����', '����. ������ ���', 'Location','northwest'); title('$\bf y = ln(x + 2) + x, \; n = 5$', 'Interpreter','latex'); figure; hold on; plot(X2, error_Newton2, 'g'); plot(X2, error_Newton_Cheb2, 'r'); plot(X2, teor_error_Newton2, 'b'); plot(X2, teor_error_Newton_Cheb2, 'y'); grid on legend('����', '���', '����. ������ ����', '����. ������ ���', 'Location','northwest'); title('$\bf y = x^3 - 0.1x^2 + 0.4|x| + 2, \; n = 5$', 'Interpreter','latex'); %} %{ ����������� ������������ ������ �� ����� ����� X = 5 : 1 : 100; max_error_Newton1 = dlmread('errorN_Newton1.txt'); max_error_Newton2 = dlmread('errorN_Newton2.txt'); max_error_Newton_Cheb1 = dlmread('errorN_Newton_cheb1.txt'); max_error_Newton_Cheb2 = dlmread('errorN_Newton_cheb2.txt'); figure; hold on; plot(X, max_error_Newton1, 'b'); plot(X, max_error_Newton_Cheb1, 'y'); grid on; set(gca, 'YScale', 'log'); xlabel('����� �����', 'Interpreter', 'latex'); ylabel('����. ������', 'Interpreter', 'latex'); legend('����', '���', 'Location','northwest'); title('$\bf y = lg(x + 2) + x$', 'Interpreter','latex'); figure; hold on; plot(X, max_error_Newton2, 'b'); plot(X, max_error_Newton_Cheb2, 'y'); grid on; set(gca, 'YScale', 'log'); xlabel('����� �����', 'Interpreter', 'latex'); ylabel('����. ������', 'Interpreter', 'latex'); legend('����', '���', 'Location','northwest'); title('$\bf y = x^3 - 0.1x^2 + 0.4|x| + 2$', 'Interpreter','latex'); %} X = 5 : 1 : 100; error_point1_Newton1 = dlmread('error_point1_Newton1.txt'); error_point1_Newton2 = dlmread('error_point1_Newton2.txt'); error_point1_Newton_Cheb1 = dlmread('error_point1_Newton_cheb1.txt'); error_point1_Newton_Cheb2 = dlmread('error_point1_Newton_cheb2.txt'); error_point2_Newton1 = dlmread('error_point2_Newton1.txt'); error_point2_Newton2 = dlmread('error_point2_Newton2.txt'); error_point2_Newton_Cheb1 = dlmread('error_point2_Newton_cheb1.txt'); error_point2_Newton_Cheb2 = dlmread('error_point2_Newton_cheb2.txt'); figure; hold on; plot(X, error_point1_Newton1, 'b'); plot(X, error_point1_Newton_Cheb1, 'y'); grid on; set(gca, 'YScale', 'log'); xlabel('����� �����', 'Interpreter', 'latex'); ylabel('������', 'Interpreter', 'latex'); legend('����', '���', 'Location','northwest'); title('$\bf y = lg(x + 2) + x, \; x = -0.73$', 'Interpreter','latex'); figure; hold on; plot(X, error_point1_Newton2, 'b'); plot(X, error_point1_Newton_Cheb2, 'y'); grid on; set(gca, 'YScale', 'log'); xlabel('����� �����', 'Interpreter', 'latex'); ylabel('������', 'Interpreter', 'latex'); legend('����', '���', 'Location','northwest'); title('$\bf y = x^3 - 0.1x^2 + 0.4|x| + 2, \; x = -0.73$', 'Interpreter','latex'); figure; hold on; plot(X, error_point2_Newton1, 'b'); plot(X, error_point2_Newton_Cheb1, 'y'); grid on; set(gca, 'YScale', 'log'); xlabel('����� �����', 'Interpreter', 'latex'); ylabel('������', 'Interpreter', 'latex'); legend('����', '���', 'Location','northwest'); title('$\bf y = lg(x + 2) + x, \; x = 0.48$', 'Interpreter','latex'); figure; hold on; plot(X, error_point2_Newton2, 'b'); plot(X, error_point2_Newton_Cheb2, 'y'); grid on; set(gca, 'YScale', 'log'); xlabel('����� �����', 'Interpreter', 'latex'); ylabel('������', 'Interpreter', 'latex'); legend('����', '���', 'Location','northwest'); title('$\bf y = x^3 - 0.1x^2 + 0.4|x| + 2, \; x = 0.48$', 'Interpreter','latex');