1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//Book - Power System: Analysis & Design 5th Edition
//Authors - J. Duncan Glover, Mulukutla S. Sarma, and Thomas J. Overbye
//Chapter - 6 ; Example 6.1
//Scilab Version - 6.0.0 ; OS - Windows
clc;
clear;
A=[10 5;2 9];
y=[6;3];
N=length(y); //Number of variables
st=N-1; //Number of Gauss elimination steps
//Gauss Elimination step:
B=A;
for i=1:st
for j=i+1:N
m=(B(j,i)/B(i,i));
A(j,i+1:N)=A(j,i+1:N)-m*(A(i,i+1:N));
A(i+1:N,i)=0;
y(j)=y(j)-m*y(i);
end
B=A;
end
//Back Substitution step
x2=y(2)/A(2,2)
x1=(y(1)-A(1,2)*x2)/A(1,1);
disp(A,'The triangularized matrix using gauss elemination is:')
disp(y,'and the corresponding y matrix is:')
printf('The solution using back substitution is x1=%.4f and x2=%.4f',x1,x2)
|