diff options
author | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
---|---|---|
committer | prashantsinalkar | 2017-10-10 12:27:19 +0530 |
commit | 7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch) | |
tree | dbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /260/CH3/EX3.7/3_7.sce | |
parent | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff) | |
download | Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2 Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip |
initial commit / add all books
Diffstat (limited to '260/CH3/EX3.7/3_7.sce')
-rw-r--r-- | 260/CH3/EX3.7/3_7.sce | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/260/CH3/EX3.7/3_7.sce b/260/CH3/EX3.7/3_7.sce new file mode 100644 index 000000000..2691b2075 --- /dev/null +++ b/260/CH3/EX3.7/3_7.sce @@ -0,0 +1,93 @@ +//Eg-3.7
+//pg-86
+
+clear
+clc
+
+ //Matrices A and B
+ A=[-0.41 0.58 1 0 0;0.41 0.58 0 1 0;-.82 -.58 0 0 1;.82 .58 0 0 0;-.82 .58 0 0 0];;
+ B=[0;3;0;6.25;0];
+[n,n]=size(A);
+
+//Permutation,Lower triangular matrix initialisation
+P=eye(n);
+L=zeros(n,n);
+
+//Algorithm of LU decomposition to find L,U,P and X
+//Partial Pivoting
+ for k=1:n-1
+ u=k;
+ big=abs(A(k,k));
+ for t=k+1:n
+ dummy=abs(A(t,k));
+ if dummy>big//Finidng max absolute element
+ big=dummy;
+ u=t;//Index of max ansolute element
+ end
+ end
+ if u~=k
+ for j=1:n
+ dummy=A(u,j);//Interchanging rows of A
+ A(u,j)=A(k,j);
+ A(k,j)=dummy;
+
+ dummy=L(u,j);//interchanging rows of lowertriangular matrix according to A
+ L(u,j)=L(k,j);
+ L(k,j)=dummy;
+ end
+ dummy=B(u);//interchanging rows of B matrix
+ B(u)=B(k);
+ B(k)=dummy;
+ end
+
+ //forward elimination to get U and sending corresponding factors to L
+ for i=(k+1):n
+ facotr=A(i,k)/A(k,k);
+ for j=1:n
+ A(i,j)=A(i,j)-facotr*A(k,j);
+ U=A;//upper triangular matrix
+ end
+ for j=k
+ L(i,j)=facotr;//factors are transformed to lower triangular matrix
+ end
+
+ end
+ end
+
+ //Lower triangular matrix
+ for s=1:n
+ L(s,s)=1;
+ end
+
+ //Initialisation of D,X
+ D=zeros(n,1);
+ X=zeros(n,1);
+
+ //Forward Substitution Ld=B..we get d here
+ D(1)=B(1)/L(1,1);
+ for i=2:n
+ summ=B(i);
+ for j=1:i-1
+ summ=summ-L(i,j)*D(j);
+ end
+ D(i)=summ/L(i,i);
+ end
+
+ //Backward substitution Ux=B gives X
+ X(n)=D(n)/U(n,n);
+ for i=(n-1):-1:1
+ summ=D(i);
+ for j=(i+1):n
+ summ=summ-U(i,j)*X(j);
+ end
+ X(i)=summ/U(i,i);
+ end
+
+//Displaying results
+disp(X(1),"F0=")
+disp(X(2),"F1=")
+disp(X(3),"F2=")
+disp(X(4),"F3=")
+disp(X(5),"F4=")
+
+
\ No newline at end of file |