Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add lab7. It is ready for cheching

  • Loading branch information...
commit 7166cb99a5f907f8677608000007bd37a69c4ca8 1 parent 3d13943
Paul Chechetin authored
45 lab7/action.asv
View
@@ -0,0 +1,45 @@
+function action()
+
+ % First part
+ [simple_y simple_x] = simple_square();
+
+ subplot(3,1,1);
+ plot(plot_x,plot_y);
+
+ simple_mean = mean(simple_y)
+ simple_median = median(simple_y)
+
+ simple_std = std(simple_y)
+ simple_std_s = std(simple_y, 1)
+
+ corr = corrcoef(simple_y)
+
+ % Second part
+ [x y] = linput();
+
+ straight_x = x;
+ straight_y = poly(x,y);
+
+ reverse_x = y;
+ reverse_y = poly(y,x);
+
+ % Draw plots
+ subplot(3,1,2);
+ plot_x = [x; straight_x; reverse_x]';
+ plot_y = [y; straight_y; reverse_y]';
+ plot(plot_x,plot_y);
+ legend('Variable', 'Straight', 'Reverse');
+
+ straight_p = polyfit(x,y,7);
+ reverse_p = polyfit(y,x,7);
+
+ m_straight_y = mapprox(x,straight_p);
+ m_reverse_y = mapprox(y,reverse_p);
+
+ plot_x = [x; x; y]';
+ plot_y = [y; m_straight_y; m_reverse_y]';
+
+ subplot(3,1,3);
+ plot(plot_x,plot_y);
+ legend('Variable', 'Straight', 'Reverse');
+end
52 lab7/action.m
View
@@ -0,0 +1,52 @@
+function action()
+ [x y] = linput();
+
+ delete(findall(0,'Type','Figure'));
+
+ % First part
+ [simple_y simple_x] = simple_square();
+
+ subplot(3,1,1);
+ plot_x = [x(1:10); simple_x]';
+ plot_y = [y(1:10); simple_y]';
+
+ plot(plot_x,plot_y);
+ legend('Exact','Approx');
+
+ simple_mean = mean(simple_y)
+ simple_median = median(simple_y)
+
+ simple_std = std(simple_y)
+ simple_std_s = std(simple_y, 1)
+
+ corr = corrcoef(simple_y)
+
+ % Second part
+ [x y] = linput();
+
+ straight_x = x;
+ straight_y = poly(x,y);
+
+ reverse_x = y;
+ reverse_y = poly(y,x);
+
+ % Draw plots
+ subplot(3,1,2);
+ plot_x = [x; straight_x; reverse_x]';
+ plot_y = [y; straight_y; reverse_y]';
+ plot(plot_x,plot_y);
+ legend('Variable', 'Straight', 'Reverse');
+
+ straight_p = polyfit(x,y,7);
+ reverse_p = polyfit(y,x,7);
+
+ m_straight_y = mapprox(x,straight_p);
+ m_reverse_y = mapprox(y,reverse_p);
+
+ plot_x = [x; x; y]';
+ plot_y = [y; m_straight_y; m_reverse_y]';
+
+ subplot(3,1,3);
+ plot(plot_x,plot_y);
+ legend('Variable', 'Straight', 'Reverse');
+end
5 lab7/linput.m
View
@@ -0,0 +1,5 @@
+function [x y] = linput()
+ x = 0.1:0.1:5.1;
+ y = x;
+ % y = [-2.3660 -1.7701 -1.3201 -1.2720 -0.5055 -0.3275 -0.4319 -0.4051 -0.1362 0.0405 -0.2024 0.3066 0.1005 -0.0493 0.3263 0.6423 0.0442 0.7559 0.5858 0.5291 0.4964 0.8012 0.7039 1.2297 0.9044 1.1075 1.3314 0.8089 0.7722 1.0514 1.3509 0.6801 1.2743 1.0409 1.2800 1.0181 1.2439 1.4303 1.3457 1.4073 1.1276 1.2935 1.3850 1.6022 1.6745 1.3950 1.2535 1.7307 1.8445 1.2650 1.6089];
+end
15 lab7/mapprox.asv
View
@@ -0,0 +1,15 @@
+function y = mapprox(x,p)
+ y = [];
+
+ for i = 1:size(x)
+ vector = [];
+ for j =
+ vector = [vector;x(i)^ ]
+ vector = x(i).^(size-1):-x(i):x(i)
+
+ r = p(1:(size-1)).*vector;
+ y = [y r];
+ end
+
+ y = y + p(size);
+end
12 lab7/mapprox.m
View
@@ -0,0 +1,12 @@
+function y = mapprox(x,p)
+ y = [];
+ p_size = length(p);
+
+ for i = 1:length(x)
+ r = 0;
+ for j = 1:length(p)
+ r = r + p(j) * x(i)^(p_size-j);
+ end
+ y = [y r];
+ end
+end
10 lab7/poly.m
View
@@ -0,0 +1,10 @@
+function r = poly(x,y)
+ A = [];
+
+ for i = 1:length(x)
+ A(i,:) = [1 x(i)^3 x(i)^5 x(i)^7];
+ end
+
+ b = ((A'*A)^-1*A')*y';
+ r = b(1) + b(2)*x.^3 + b(3)*x.^5 + b(4)*x.^7;
+end
15 lab7/simple_square.m
View
@@ -0,0 +1,15 @@
+function [r_y x_ten] = simple_square()
+ [x y] = linput;
+
+ x_ten = x(1:10);
+ y_ten = y(1:10);
+
+ x_mean = mean(x_ten);
+ y_mean = mean(y_ten);
+
+ b_one = sum((x_ten - x_mean).*(y_ten- y_mean)) / std(x_ten);
+
+ b_zero = y_mean - b_one * x_mean;
+
+ r_y = b_zero + b_one * x_ten;
+end
Please sign in to comment.
Something went wrong with that request. Please try again.