From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 845/CH10/EX10.1/Ex10_1.sce | 38 +++++++++++++++++++++++++++++ 845/CH10/EX10.2/Ex10_2.sce | 2 ++ 845/CH10/EX10.3/Ex10_3.sce | 49 +++++++++++++++++++++++++++++++++++++ 845/CH10/EX10.4/Ex10_4.sce | 29 ++++++++++++++++++++++ 845/CH10/EX10.5/Ex10_5.sce | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100755 845/CH10/EX10.1/Ex10_1.sce create mode 100755 845/CH10/EX10.2/Ex10_2.sce create mode 100755 845/CH10/EX10.3/Ex10_3.sce create mode 100755 845/CH10/EX10.4/Ex10_4.sce create mode 100755 845/CH10/EX10.5/Ex10_5.sce (limited to '845/CH10') diff --git a/845/CH10/EX10.1/Ex10_1.sce b/845/CH10/EX10.1/Ex10_1.sce new file mode 100755 index 000000000..efddc3c9f --- /dev/null +++ b/845/CH10/EX10.1/Ex10_1.sce @@ -0,0 +1,38 @@ +//Example 10.1 + +clc +clear + +h = 1/4; +xf = 1; +yf = 1; +x = 0:h:xf; +y = 0:h:yf; +m = length(y); +n = length(x); + +u = zeros(m,n); +u(m,:) = 100*x; +u(:,n) = 100*y'; +u0 = u; + +I = ceil(m/2); +J = ceil(n/2); + +u(J,I) = (u0(J-2,I-2) + u0(J-2,I+2) + u0(J+2,I-2) + u0(J+2,I+2)) / 4; + +for j = [J-1 J+1] + for i = [I-1 I+1] + u(j,i) = (u(j-1,i-1) + u(j-1,i+1) + u(j+1,i-1) + u(j+1,i+1)) / 4; + end +end + +j1 = [J-1 J J J+1]; +i1 = [I I-1 I+1 I]; +for k = 1:4 + i = i1(k); + j = j1(k); + u(j,i) = (u(j,i-1) + u(j,i+1) + u(j-1,i) + u(j+1,i)) / 4; +end + +disp(u,"u:") diff --git a/845/CH10/EX10.2/Ex10_2.sce b/845/CH10/EX10.2/Ex10_2.sce new file mode 100755 index 000000000..7e137e627 --- /dev/null +++ b/845/CH10/EX10.2/Ex10_2.sce @@ -0,0 +1,2 @@ +// Example 10.2 +// This is an analytical problem and need not be coded. diff --git a/845/CH10/EX10.3/Ex10_3.sce b/845/CH10/EX10.3/Ex10_3.sce new file mode 100755 index 000000000..1e54186ab --- /dev/null +++ b/845/CH10/EX10.3/Ex10_3.sce @@ -0,0 +1,49 @@ +//Example 10.3 + +clc +clear + +m = 5; +n = 5; +u = zeros(m,n); +u(m,:) = [50 100 100 100 50]; +u0 = u; +I = ceil(m/2); +J = ceil(n/2); + +u(J,I) = (u0(J-2,I-2) + u0(J-2,I+2) + u0(J+2,I-2) + u0(J+2,I+2)) / 4; + +for j = [J-1 J+1] + for i = [I-1 I+1] + u(j,i) = (u(j-1,i-1) + u(j-1,i+1) + u(j+1,i-1) + u(j+1,i+1)) / 4; + end +end + +j1 = [J-1 J J J+1]; +i1 = [I I-1 I+1 I]; +for k = 1:4 + i = i1(k); + j = j1(k); + u(j,i) = (u(j,i-1) + u(j,i+1) + u(j-1,i) + u(j+1,i)) / 4; +end + +kf = 2; +tab = zeros(kf+1,(m-2)*(n-2)); +row = []; +for j = 2:n-1 + row = [row u(j,2:m-1)]; +end +tab(1,:) = row; +for k = 1:kf + row = []; + for j = 2:n-1 + for i = 2:m-1 + u(j,i) = (u(j,i-1) + u(j,i+1) + u(j-1,i) + u(j+1,i)) / 4; + end + row = [row u(j,2:m-1)]; + end + row = round(row*10^4)/10^4; + tab(k+1,:) = row; +end +mprintf("%4s %9s %9s %9s %9s %10s %10s %10s %10s %10s",'r','u11','u21','u31','u12','u22','u32','u13','u23','u33') +disp([(1:k+1)' tab]) diff --git a/845/CH10/EX10.4/Ex10_4.sce b/845/CH10/EX10.4/Ex10_4.sce new file mode 100755 index 000000000..4840d8c21 --- /dev/null +++ b/845/CH10/EX10.4/Ex10_4.sce @@ -0,0 +1,29 @@ +//Example 10.4 + +clc +clear + +h = 1/3; +x = 0:h:1; +y = 0:h:1; +m = length(y); +n = length(x); +u = zeros(m,n); +u(m,2:n-1) = 1; + +kf = 5; +tab = zeros(kf,(m-2)*(n-2)); +for k = 1:kf + row = []; + for j = 2:n-1 + for i = 2:m-1 + constant = 10/9* (5 + 1/9*(i-1)^2 + 1/9*(j-1)^2); + u(j,i) = (u(j,i-1) + u(j,i+1) + u(j-1,i) + u(j+1,i) + constant) / 4; + end + row = [row u(j,2:m-1)]; + end + row = round(row*10^4)/10^4; + tab(k,:) = row; +end +mprintf("%4s %9s %9s %9s %9s",'r','u11','u21','u12','u22') +disp([(1:k)' tab]) diff --git a/845/CH10/EX10.5/Ex10_5.sce b/845/CH10/EX10.5/Ex10_5.sce new file mode 100755 index 000000000..889edee01 --- /dev/null +++ b/845/CH10/EX10.5/Ex10_5.sce @@ -0,0 +1,60 @@ +//Example 10.5 + +clc +clear + +x = 0:4; +y = 0:4; +m = length(y); +n = length(x); +u = zeros(m,n); +u(m,:) = x.^3; +u(:,n) = 16*y'; +u0 = u; + +I = ceil(m/2); +J = ceil(n/2); + +u(J,I) = (u0(J-2,I-2) + u0(J-2,I+2) + u0(J+2,I-2) + u0(J+2,I+2)) / 4; + +for j = [J-1 J+1] + for i = [I-1 I+1] + u(j,i) = (u(j-1,i-1) + u(j-1,i+1) + u(j+1,i-1) + u(j+1,i+1)) / 4; + end +end + +j1 = [J-1 J J J+1]; +i1 = [I I-1 I+1 I]; +for k = 1:4 + i = i1(k); + j = j1(k); + u(j,i) = (u(j,i-1) + u(j,i+1) + u(j-1,i) + u(j+1,i)) / 4; +end +disp(u,"u:") + +p = m-1; +q = n-1; +c = cos(%pi/p) + cos(%pi/q); +w = 4/(2+sqrt(4-c^2)); +w = round(w*10^3)/10^3; + +kf = 10; +tab = zeros(kf+1,(m-2)*(n-2)); +row = []; +for j = 2:n-1 + row = [row u(j,2:m-1)]; +end +tab(1,:) = row; +for k = 1:kf + row = []; + for j = 2:n-1 + for i = 2:m-1 + u(j,i) = (u(j,i-1) + u(j,i+1) + u(j-1,i) + u(j+1,i)) *w/4 + (1-w)*u(j,i); + end + row = [row u(j,2:m-1)]; + end + row = round(row*10^4)/10^4; + tab(k+1,:) = row; +end +mprintf("\n\n%8s %9s %10s %10s %9s %10s %10s %9s %9s",'u11','u21','u31','u12','u22','u32','u13','u23','u33') +disp(tab) -- cgit