Permalink
Browse files

Lab7 has been passed

  • Loading branch information...
1 parent 6b61547 commit 4d1bb0773f2d335992be53404ff31dc7b7110f3d @Paulche committed Apr 20, 2013
View
No changes.
View
@@ -0,0 +1,12 @@
+function [] = linput()
+ c = 4;
+ a = 2;
+ T = 4;
+ nx = 50;
+ nt = 50;
+ t = T/nt;
+ h = a/nx;
+
+ u(1) = @(x) sin(pi * x) + 3*sin(2.5*pi*x);
+ u(2) = u(3) = u(4) = @(x) 0;
+end
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
0 lab4/README.md 100644 → 100755
No changes.
View
0 lab4/action.m 100644 → 100755
No changes.
View
0 lab4/d_solve.m 100644 → 100755
No changes.
View
0 lab4/df.m 100644 → 100755
No changes.
View
0 lab4/f.m 100644 → 100755
No changes.
View
0 lab4/linput.m 100644 → 100755
No changes.
View
0 lab4/n_solve.m 100644 → 100755
No changes.
View
0 lab4/лр 4.doc 100644 → 100755
No changes.
View
Binary file not shown.
View
0 lab5/README.md 100644 → 100755
No changes.
View
0 lab5/action.m 100644 → 100755
No changes.
View
0 lab5/check_convergency.m 100644 → 100755
No changes.
View
0 lab5/compute_bc.m 100644 → 100755
No changes.
View
0 lab5/generate_equation.m 100644 → 100755
No changes.
View
0 lab5/iter_method.m 100644 → 100755
No changes.
View
0 lab5/seidel_method.m 100644 → 100755
No changes.
View
0 lab5/лр 5.doc 100644 → 100755
No changes.
View
Binary file not shown.
View
0 lab6/action.m 100644 → 100755
No changes.
View
0 lab6/cheb.m 100644 → 100755
No changes.
View
0 lab6/ipol_lagr.m 100644 → 100755
No changes.
View
0 lab6/runge.m 100644 → 100755
No changes.
View
0 lab6/лр 6.doc 100644 → 100755
No changes.
View
@@ -1,11 +1,21 @@
function action()
+ [x y] = linput();
+
+ delete(findall(0,'Type','Figure'));
% First part
- [simple_y simple_x] = simple_square();
-
- subplot(3,1,1);
- plot(plot_x,plot_y);
-
+ [simple_y simple_x simple_rev_y simple_rev_x] = simple_square();
+
+ subplot(3,2,1);
+ plot(x(1:10),y(1:10),'b.');
+ hold on;
+
+ plot(simple_x,simple_y,'r');
+ plot(simple_rev_y,simple_rev_x,'g');
+
+ legend('Exact','Direct','Reverse');
+ hold off;
+
simple_mean = mean(simple_y)
simple_median = median(simple_y)
@@ -15,31 +25,21 @@ function action()
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');
+ draw_poly(3,1)
+ draw_poly(5,2)
+ draw_poly(7,3)
+ % Third part
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);
+ m_reverse_x = mapprox(y,reverse_p);
+
+ plot_x = [x; x; m_reverse_x]';
+ plot_y = [y; m_straight_y; y]';
+
+ subplot(3,2,5);
plot(plot_x,plot_y);
- legend('Variable', 'Straight', 'Reverse');
+ legend('Variable', 'Straight');
end
View
16 lab7/action.m 100644 → 100755
@@ -1,4 +1,4 @@
-function action()
+function [R m_straight_y] = action()
[x y] = linput();
delete(findall(0,'Type','Figure'));
@@ -7,7 +7,7 @@ function action()
[simple_y simple_x simple_rev_y simple_rev_x] = simple_square();
subplot(3,2,1);
- plot(x(1:10),y(1:10),'b');
+ plot(x(1:10),y(1:10),'b.');
hold on;
plot(simple_x,simple_y,'r');
@@ -27,19 +27,15 @@ function action()
% Second part
draw_poly(3,1)
draw_poly(5,2)
- draw_poly(7,3)
+ R = draw_poly(7,3)
% Third part
straight_p = polyfit(x,y,7);
reverse_p = polyfit(y,x,7);
- m_straight_y = mapprox(x,straight_p);
- m_reverse_x = mapprox(y,reverse_p);
-
- plot_x = [x; x; m_reverse_x]';
- plot_y = [y; m_straight_y; y]';
+ m_straight_y = mapprox(x,straight_p)
subplot(3,2,5);
- plot(plot_x,plot_y);
- legend('Variable', 'Straight', 'Reverse');
+ plot(x,y,'r.',x,m_straight_y,'b');
+ legend('Variable', 'Straight');
end
View
15 lab7/draw_poly.m 100644 → 100755
@@ -1,16 +1,11 @@
-function draw_poly(n,pos)
+function straight_y = draw_poly(n,pos)
[x y] = linput();
- straight_x = x;
- straight_y = poly(x,y,n);
-
- reverse_x = poly(y,x,n);
- reverse_y = y
+ straight_x = x
+ straight_y = poly(x,y,n)
% Draw plots
subplot(3,2,2*pos);
- plot_x = [x; straight_x; reverse_x]';
- plot_y = [y; straight_y; reverse_y]';
- plot(plot_x,plot_y);
- legend(sprintf('Variable %d',n), 'Straight', 'Reverse');
+ plot(x,y,'r.',straight_x,straight_y,'b');
+ legend(sprintf('Variable %d',n), 'Straight');
end
View
0 lab7/linput.m 100644 → 100755
No changes.
View
0 lab7/mapprox.m 100644 → 100755
No changes.
View
0 lab7/min_square.m 100644 → 100755
No changes.
View
@@ -0,0 +1,23 @@
+function r = poly(x,y,n)
+ A = [];
+
+ for i = 1:length(x)
+ A(i,1) = 1;
+
+ for j = 2:n
+ A(i,j) = x(i)^(j-1);
+ end
+ end
+
+ b = ((A'*A)^-1*A')*y';
+
+ for i = 1:length(x)
+ t = b(1);
+
+ for j = 2:n
+ t = t + b(j)*x(i)^j;
+ end
+
+ r(i) = t;
+ end
+end
View
4 lab7/poly.m 100644 → 100755
@@ -5,7 +5,7 @@
A(i,1) = 1;
for j = 2:n
- A(i,j) = x(i)^j;
+ A(i,j) = x(i)^(j-1);
end
end
@@ -15,7 +15,7 @@
t = b(1);
for j = 2:n
- t = t + b(j)*x(i)^j;
+ t = t + b(j)*x(i)^(j-1);
end
r(i) = t;
View
0 lab7/simple_square.m 100644 → 100755
No changes.
View
@@ -0,0 +1,31 @@
+function action
+ %
+ % Here is the task:
+ % 1. Numeric solve diff equation by Euler
+ % 2. Numeric solve diff equation by Runge-Kutta
+ % 3. Numeric solve diff equation by Matlab build-in function
+ % 4. Draw three plot and compare them
+ %
+ [f cond h domain] = linput();
+
+ x = domain(1):h:domain(2)+h;
+
+ % 1.
+ euler_y = euler();
+
+ % 2.
+ runge_y = runge();
+
+ % 3.
+ [mat_x mat_y] = ode45(f,domain,cond(2))
+
+ % 4.
+ plot_y = [euler_y; runge_y];
+
+ subplot(2,1,1);
+ plot(x,plot_y);
+ legend('Euler','Runge');
+
+ subplot(2,1,2);
+ plot(mat_x, mat_y);
+end
View
@@ -0,0 +1,13 @@
+function y = euler()
+ [f cond h domain] = linput();
+
+ prev = cond(2);
+
+ y = [prev];
+
+ for i = domain(1):h:domain(2)
+ prev = prev + h * f(i,prev);
+ y = [y prev];
+ end
+
+end
View
@@ -0,0 +1,6 @@
+function [f cond h domain] = linput()
+ f = @(t,u) (u + (u^2 + t^2)^0.5)/t;
+ cond = [0 1];
+ h = 0.02;
+ domain = [1 1.5];
+end
View
@@ -0,0 +1,17 @@
+function y = runge()
+ [f cond h domain] = linput();
+
+ prev = cond(2);
+
+ y = [prev];
+
+ for i = domain(1):h:domain(2)
+ k1 = f(i,prev);
+ k2 = f(i + h/2,prev + k1/2);
+ k3 = f(i + h/2,prev + k2/2);
+ k4 = f(i + h, prev + k3);
+
+ prev = prev + (h * (k1 + 2*k2 + 2*k3 + k4))/6;
+ y = [y prev];
+ end
+end
View
0 lab9/action.m 100644 → 100755
No changes.
View
0 lab9/compute_matrix.m 100644 → 100755
No changes.
View
0 lab9/linput.m 100644 → 100755
No changes.
View
0 lab9/solve_system.m 100644 → 100755
No changes.
View
0 lab9/try_a.m 100644 → 100755
No changes.

0 comments on commit 4d1bb07

Please sign in to comment.