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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
//Eg-3.12
//pg-100
clear
clc
A=[6 15 55 ;15 55 225;55 225 979];
B=[74.5;262.3;1078.1];
n=3;
matsol=zeros(3,3);//initialising matrix matsol
Z=A;
Y=B;
I=[1 0 0;0 1 0;0 0 1];//creates an identity matrix of size n*n
X=zeros(3,1);
inverse=zeros(3,3);
ABI=zeros(3,7);
ABI(:,:)=[A(:,:) B(:,:) I(:,:)];//augumented matrix of A,B,I
for k=1:n//proceeds from 1st row to the last row
u=k;
big=abs(ABI(k,k));
for t=k+1:n //this loop is for selecting the elementhaving max absolute value in a column
dummy=abs(ABI(t,k));
if dummy>big then
big=dummy;
u=t;
end
end
if u~=k then
for j=1:2*n+1//interchanging rows to make max absolute element as pivot
dummy=ABI(u,j);
ABI(u,j)=ABI(k,j);
ABI(k,j)=dummy;
end
end
pivot=ABI(k,k);
ABI(k,:)=ABI(k,:)/pivot;
for i=1:n
if i~=k;
factor=ABI(i,k);
ABI(i,:)=ABI(i,:)-ABI(k,:)*factor;
end
end
X(:,:)=[ABI(:,n+1)];//determining X using augumented matrix
matsol=inv(Z)*Y;//using matlab inbuilt functions to get X
end
disp("Coefficients of parabola")
disp(X)
|