Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Program:
A =[2 4 6; 3 8 5;-1 1 2];
B=[22;27;2];
Ab=[A B];
[m n]=size(Ab);
%% Agumented matrix is converting into upper triangle matrix%%
for i=1:m-1
for j=i+1:m
alpha= Ab(j,i)/Ab(i,i);
Ab(j,:)=Ab(j,:)-(alpha*Ab(i,:));
end
end
disp(Ab);
%%Backward substitution%%
x=zeros(m,1);
for k=m:-1:1
x(k,1)= (Ab(k,end)-Ab(k,k+1:m)*x(k+1:m,1))/Ab(k,k);
end
disp('The co-efficient values are');
x
Result:
2 4 6 22
0 2 -4 -6
0 0 11 22
x =
2
Experiment No: 4
Program:
n= input('Enter the size of matrix: \n');
l(1:n,1)=4;
u(1:n-1,1)=-1;
d(1:n-1,1)= 3;
x=diag(l,0);
y= diag(u,-1);
z= diag(d,1);
%% co-efficient matrix%%
A=x+y+z;
%% Resource Matrix%%
b(1:n,1)=5;
%% Agumented Matrix%%
Ab=[A b];
[m p]= size(Ab);
%% converting into upper triangular matrix%%
for i=1:m-1
for j=i+1:m
alpha= Ab(j,i)/Ab(i,i);
Ab(j,:)= Ab(j,:)- (alpha*Ab(i,:));
end
end
disp(Ab)
%%Backward substitution%%
r = zeros(m,1);
for k=m:-1:1
r(k,1)=(Ab(k,end)- Ab(k,k+1:m)*r(k+1:m,1))/Ab(k,k);
end
r
Result:
Enter the size of matrix:
4
0.4890
1.0147
0.4768
1.3692
Experiment No: 5
Aim: To develop code for 1-D Dirchlet Boundary (Constant temperature) condition for 1-D
steady state heat conduction equation
Program:
l= input('Enter the length of slab: \n');
n=input('Enter the number of divisions: \n');
dx=l/n;
%% Defining Diagonals Elements %%
a(1:n-1,1)= 1;
a(n,1)=0;
c(2:n,1)=1;
c(1,1)=0;
b(2:n,1)=-2;
b(1,1) = 1;
b(n+1,1) =1;
x=diag(b,0);
y=diag(a,-1);
z = diag(c,1);
%% Co-efficient Matrix of Temperature %%
A = x+y+z
%% Resource Matrix %%
B(1,1)=350;
B(n+1,1)=50;
B(2:n,1)=0
%% Temperature distribution %%
Y = A\B
X= 1:n+1;
plot(X,Y)
Result:
Enter the length of slab: 10
1 0 0 0 0 0
1 -2 1 0 0 0
0 1 -2 1 0 0
0 0 1 -2 1 0
0 0 0 1 -2 1
0 0 0 0 0 1
B =
350
0
0
0
0
50
Y =
350.0000
290.0000
230.0000
170.0000
110.0000
50.0000