NAST LAB EXPERIMENTS, (PRANAY), (ME), (3rd SEM), (MVSIT), (00255111119)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

MAHAVIR SWAMI INSTITUTE OF

TECHNOLOGY

Numerical analysis and statistical techniques


Lab

ETME - 253

SUBMITTED TO :

MS . TARUNA MAM SUBMITTED BY:

ANAND, (3rd Sem), (ME)

B tech , (MVSIT)

ROLL No : - 00155111119

Experiment – 1
Aim – To find the addition of two matrices.

Output –

Experiment – 2
Aim – To find the multiplication of two matrices
clc
clear all
format compact
A=input('Enter the matrix A');
[m1,n1]=size(A);
B=input('Enter the matrix B');
[m2,n2]=size(B);
fprintf('\n Multiplication of matrix\n');
if(n1==m2)
D = A*B
else
disp('for these matrices multiplication is not possible')
end

Output –
Experiment – 3

Aim – To find the transpose of matrix

Output –
Experiment – 4

Aim – To find the solution of algebraic and transcendental equation by


using by bisection method.
clc
clear all
syms x;
f=input('Enter the function');
I=input('Enter the value of an interval');
a=I(1);
b=I(2);
fa=subs(f,x,a);
if fa==0
disp(['Root of the function is=',num2str(a)]);
break;
end
fb=subs(f,x,b);
if fb==0
disp(['Root of the function is=',num2str(b)]);
break;
end
if fa*fb>0
disp('Root does not lie in the interval');
else
%while (abs(fm)<.001)
m=(a+b)/2
fm=subs(f,x,m);
if fm==0
disp(['Root of the function is=',num2str(m)]);
break;
else
while(abs(fm)>.001)
if fa*fm<0
b=m
else
a=m;
end
fa=subs(f,x,a);
fb=subs(f,x,b);
m=(a+b)/2;
fm=subs(f,x,m);
end
end
disp(['Root of the function is=',num2str(m)]);
end
Output –
EXPERIMENT – 5

Aim – To find the solution of linear equations by using gauss Jordan


method.

clc
clear all
n=input('enter the number of variables');
a=input('enter the augumented matrix A/b-');
for j=1:n
for i=1:n
if(i~=j)
t=a(i,j)/a(j,j);
for k=1:n+1
a(i,k)=a(i,k)-a(j,k).*t;
end
end
end
end
fprintf('\nThe diagonal matrix is:-\n')
disp(a)
fprintf('\nThe solution is:-\n')
for i=1:n
fprintf('x[%d]=%f\n',i,a(i,n+1)./a(i,i));
end
Output –
Experiment – 6

Aim – to find the eigen values and eigen vectors of a matrix.


clc
clear all
format rat
A=input('Enter the matrix');
[V,D]=eig(A);
fprintf('The eigen values of A are')
D(1,1),D(2,2),D(3,3)
fprintf('The eigen vector matrix of A is\n')
disp(V);

Output –
Experiment – 7

Aim – To find the numerical integration using trapezoidal rule.


clc
clear all
format compact
syms x
y = input('Enter the function to be integrated');
xO= input('Enter xO:');
xn= input('Enter xn:\');
n=input('Enter the number of subintervals:');
h=(xn-xO)/n
s= subs(y,xn0= subs(y,xO)+y*subs(y,xO+h0;
for i=3:2:n-1
s=s+4*subs(y,xO+i*h0)+2* subs(y,xO+(i-1)*h);
end
t=vpa((h/3)*s,7);
fprintf('The value of the integral is=%f \n');
disp(t);

Output


Experiment-8

Aim:Finding the integral using Simpson’s 1/3 rd Rule.

clc
clear all
format compact
syms x
y = input('Enter the function to be integrated');
xO= input('Enter xO:');
xn= input('Enter xn:\');
n=input('Enter the number of subintervals:');
h=(xn-xO)/n
s= subs(y,xn0= subs(y,xO)+y*subs(y,xO+h0;
for i=3:2:n-1
s=s+4*subs(y,xO+i*h0)+2* subs(y,xO+(i-1)*h);
end
t=vpa((h/3)*s,7);
fprintf('The value of the integral is=%f \n');
disp(t);
Experiment-9

Aim: To find the solution of ordinary differential equation using


Euler’s method.

clc
clear all
format compact
format short g
syms x y
f = input('Enter the function :');
x0 = input('Enter x0:');
y0 = input('Enter y0:');
h = input('Enter the value of h:');
r = input('Enter the value of x:');
while (r>x0)
y0 = y0+h*subs(f,{x,y},{x0,y0});
x0 = x0+h
disp(x0);
disp(y0);
end
Experiment-10

Aim: To find the solution of ordinary differential equation using runge Kutta
method.

clc
clear all
format compact
format rat
format short g
syms x y
f=input('Enter the function :');
x0=input('Enter x0:');
y0=input('Enter y0:');
h=input('Enter the value of h:');
xn=input('Enter the value of xn:');
while(x0~=xn)
if(x0==xn)
break
end
k1=vpa(h*subs(f,{x,y},{x0,y0}),5)
k2=vpa(h*subs(f,{x,y},{x0+h/2,y0+k1/2}),5)
k3=vpa(h*subs(f,{x,y},{x0+h/2,y0+k2/2}),5)
k4=vpa(h*subs(f,{x,y},{x0+h,y0+k3}),5)
k=vpa((k1+(k2+k3)*2+k4)/6,5)
x0=x0+h;
y0=vpa(y0+k,6);
fprintf('when x=%g\n');
disp(x0);
fprintf('the value of f=%3.3f');
disp(y0);
end
Experiment – 11

Aim – To plot a unit step function.

clc
clear all
fprintf('\n unit step function\n')
a=input('enter the value of a:')
t=(a-5):0.00001:(a+5);
n=size(t);
for(i=1:n(2))
if t(i)<a
r(i)=0;
else
r(i)=1;
end
i=i+1;
end
plot(t,r)
axis([a-5,a+5,0,5])
title('unit step function');
xlabel('X axis');
ylabel('Y axis');
Output –

Graph –

You might also like