Sei sulla pagina 1di 6

1.

Basic operations in MATLAB:


Symbol Operation
+ Addition
- Subtraction
* Multiplication
/ Division
^ exponent
sqrt Square root
exp e power
Power (base value,
Ex : power ( 2, 3) = 8
exponent value)
pi 𝜋 = 3.14 in radian
clc Clear screen
sin
cos Sin function. Ex: sin(pi/6) =0.5
tan
asin
Inverse of trigonometry, answer will come in radians that has to be
acos
convert in radians
atan
sinh, cosh, tanh Hyperbolic functions
asinh,acosh,atanh Inverse of hyperbolic function
summation of group of elements
sum Ex: x = [1 2 3 4 5 6 7 8 9 10];
sum(x) = 55
linspace ( , , ) Linear space values
log Logarithemic function with base ‘e’.
log10 Logarithemic function with base 10.
.* Term by term multiplication.
./ Term by term division.
.^ Term by term exponentiation.
dot(A,B) Dot products of vectors A & B
cross(A,B) Cross product of vectors A &B
roots (x) Where x is the vector form of a quadratic equation
Exercise;
1.1 Arithmetic operations:
25
1)
25 −1
√5−1
2) 3 -1
(√5+1)2

1.2 Exponential and logarithms


1) e3
2) log(e3), log 10(e3 ), log 10(105 )
3) 𝑒 𝜋√163
4) 3x = 27

1.3 Transcendental Equations


1) ex +2 = 0
2) log(x) = 0
245
3) 49t + 𝑡⁄ - 545 = 0
2
4) 2x2 -5x +6
5) Find the value of x, when y=5, from the given equation x3+5y2x-xy-x2y = 0 ?
Experiment No: 3

Aim: To develop code for Gauss Elimination Method

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

The co-efficient values are

x =

2
Experiment No: 4

Aim: To develop code for formation Tri-Diagonal Matrix Algorithm (TDMA)

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

4.0000 3.0000 0 0 5.0000


0 4.7500 3.0000 0 6.2500
0 0 4.6316 3.0000 6.3158
0 0 0 4.6477 6.3636
r =

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

Enter the number of divisions: 5


A =

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

Potrebbero piacerti anche