summaryrefslogtreecommitdiff
path: root/845/CH3/EX3.4
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /845/CH3/EX3.4
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '845/CH3/EX3.4')
-rwxr-xr-x845/CH3/EX3.4/Ex3_4.sce29
1 files changed, 29 insertions, 0 deletions
diff --git a/845/CH3/EX3.4/Ex3_4.sce b/845/CH3/EX3.4/Ex3_4.sce
new file mode 100755
index 000000000..82acb17b9
--- /dev/null
+++ b/845/CH3/EX3.4/Ex3_4.sce
@@ -0,0 +1,29 @@
+//Example 3.4
+clc
+clear
+
+A = [1 2 1; 2 3 4; 4 3 2];
+B = [8; 20; 16];
+n = length (B);
+Aug = [A,B];
+
+// Forward Elimination
+for j = 1:n-1
+ for i = j+1:n
+ Aug(i,j:n+1) = Aug(i,j:n+1) - Aug(i,j) / Aug(j,j) * Aug(j,j:n+1);
+ end
+end
+
+// Backward Elimination
+for j = n:-1:2
+ Aug(1:j-1,:) = Aug(1:j-1,:) - Aug(1:j-1,j) / Aug(j,j) * Aug(j,:);
+end
+
+// Diagonal Normalization
+for j=1:n
+ Aug(j,:) = Aug(j,:) / Aug(j,j);
+end
+x = Aug(:,n+1);
+disp(strcat(["x = ",string(x(1))]))
+disp(strcat(["y = ",string(x(2))]))
+disp(strcat(["z = ",string(x(3))]))