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/CH3/EX3.1/Ex3_1.sce | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 845/CH3/EX3.1/Ex3_1.sce (limited to '845/CH3/EX3.1') 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))])) + -- cgit