summaryrefslogtreecommitdiff
path: root/845/CH3/EX3.1
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.1
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.1')
-rwxr-xr-x845/CH3/EX3.1/Ex3_1.sce27
1 files changed, 27 insertions, 0 deletions
diff --git a/845/CH3/EX3.1/Ex3_1.sce b/845/CH3/EX3.1/Ex3_1.sce
new file mode 100755
index 000000000..cc74f2226
--- /dev/null
+++ b/845/CH3/EX3.1/Ex3_1.sce
@@ -0,0 +1,27 @@
+//Example 3.1
+clc
+clear
+
+A = [2 3 -1; 4 4 -3; -2 3 -1]; //Coefficient Matrix
+B = [5; 3; 1]; //Constant Matrix
+
+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 Substitution
+x = zeros(n,1);
+x(n) = Aug(n,n+1) / Aug(n,n);
+for i = n-1:-1:1
+ x(i) = (Aug(i,n+1)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);
+end
+disp(strcat(["x = ",string(x(1))]))
+disp(strcat(["y = ",string(x(2))]))
+disp(strcat(["z = ",string(x(3))]))
+