NAST Practical File
NAST Practical File
ETCS-211
Group: 4C-1
wopD56A.tmpoleObject0.bin
Applied Maths - IV
Practical Record
PRACTICAL DETAILS
Experiment – 1a
//matrixaddition
m=input('Enter The Number Of Rows:')
n=input('Enter The Number Of Columns:')
A=zeros(m,n)
B=zeros(m,n)
C=zeros(m,n)
disp('Enter the elements of first matrix row wise:')
for i=1:m
for j=1:n
A(i,j)=input('')
end
end
disp('Enter the elements of second matrix row wise')
for i=1:m
for j=1:n
B(i,j)=input('')
end
end
for i=1:m
for j=1:n
C(i,j)=A(i,j)+B(i,j)
end
end
disp('First Matrix==>')
disp(A)
disp('Second Matrix==>')
disp(B)
disp('Sum Of Above Two Matrices==>')
disp(C)
OUTPUT:
Experiment – 1b
//matrix multiplication
m=input('Enter The Number Of Rows:')
n=input('Enter The Number Of Columns:')
A=zeros(m,n)
B=zeros(m,n)
C=zeros(m,n)
disp('Enter the elements of first matrix row wise:')
for i=1:m
for j=1:n
A(i,j)=input('')
end
end
disp('Enter the elements of second matrix row wise')
for i=1:m
for j=1:n
B(i,j)=input('')
end
end
C=A*B
disp('First Matrix==>')
disp(A)
disp('Second Matrix==>')
disp(B)
disp('Product Of Above Two Matrices==>')
disp(C)
OUTPUT:
Experiment – 1c
//matrix transpose
m=input('Enter The Number Of Rows:')
n=input('Enter The Number Of Columns:')
A=zeros(m,n)
B=zeros(m,n)
disp('Enter the elements of first matrix row wise:')
for i=1:m
for j=1:n
A(i,j)=input('')
end
end
B=A'
disp('Matrix==>')
disp(A)
disp('Transpose Of The Matrix==>')
disp(B)
OUTPUT:
Experiment – 2
Aim – Write a program to find inverse of a matrix using Gauss Jordan Method
OUTPUT:
Experiment – 3
Aim – Write a program to find Eigen Values and Eigen Vectors of a given 2*2 matrix
OUTPUT:
Experiment – 4
Aim – Write a program to find mean, standard deviation and first r moments about mean of
given grouped data.
//Program to find mean, standard deviation and first r moments about mean of
//given grouped data
clc;
n=input('Enter the number of observations:');
disp('Enter the values of xi==>');
for i=1:n
x(i)=input('\');
end;
disp('Enter thecorresponding frequencies fi==>');
sum3=0;
for i=1:n
f(i)=input('\');
sum3=sum3+f(i);
end;
r=input('Enter the number of moments to be caculated:');
sum1=0;
for i=1:n
sum1=sum1+f(i)*x(i);
end;
A=sum1/sum3; //calculation of mean
printf('Mean=%f\n',A);
for j=1:r
sum2=0;
for i=1:n
y(i)=f(i)*(x(i)-A)^j;
sum2=sum2+y(i);
end;
M(j)=(sum2/sum3); //calculation of moments
printf('Moment about mean M(%d)=%f\n',j,M(j));
end;
sd=sqrt(M(2)); //calculation of standard deviation
printf('Standard deviation:%f\n',sd);
OUTPUT:
Experiment – 5a
OUTPUT:
Experiment – 6a
OUTPUT:
Experiment – 6b
Experiment – 7a
Aim – Write a program to find solution of a non-linear equation using Bisection method
//Bisection Method
clc;
clear;
close;
deff('y=f(x)','y=x^3-4*x-9')
x1=2;
x2=3;
e=0.001;
i=0;
printf('f(x)=x^3-4*x-9\n')
printf('Iteration\tx1\t\tx2\t\tz\t\tf(z)\n')
while abs(x1-x2)>2*e
z=(x1+x2)/2
printf(' %i\t\t%f\t%f\t%f\t%f\n',i,x1,x2,z,f(z))
if f(z)*f(x1)>0
x1=z
else
x2=z
end
i=i+1
end
printf('\n\nThe solution of f(x) is %g after %i iterations',z,i-1)
OUTPUT:
Experiment – 7b
Aim – Write a program to find solution of an non-linear equation using Newton - Raphson
method
//Newton-Raphson Method
clc;
clear;
close;
deff('x=f(x)','x=cos(x)-x*exp(x)')
deff('x=f1(x)','x=-sin(x)-(x+1)*exp(x)')
x0=0.5;
e=0.00001;
printf('\nf(x)=cos(x)-x*exp(x)')
printf('\nf1(x)=-sin(x)-(x+1)*exp(x)\n')
printf(' n\t xn\t\t f(xn)\t\t f1(xn)\t\t xn+1\t\t Error\n\n')
for i=1:4
x1=x0-f(x0)/f1(x0)
e1=abs(x0-x1)
printf(' %i\t%f\t%f\t%f\t%f\t%f\n',i-1,x0,f(x0),f1(x0),x1,e1)
x0=x1;
if(e1<e)
break;
end
end
printf( '\nThe solution of f(x) after %i iterations is %f',i,x1)
OUTPUT:
Experiment – 8a
Experiment – 8b
Aim – Write a program to evaluate a definite integral using Simpson’s one third rule
OUTPUT:
Experiment – 8c
Aim – Write a program to evaluate a definite integral using Simpson’s three eighth rule
OUTPUT:
Experiment – 9
Aim – Write a program to find the initial value problem using Euler’s method
//Program to solve the equation y'=f(x,y); y(x0)=0 for y(xn) using Euler's
//method
clc;
clear;
close;
deff('z=f(x,y)','z=(y-x)/(y+x)')
x0=0;
y0=1;
xn=0.1;
h=0.02;
x=x0;
y=y0;
while x~=xn
y=y+h*f(x,y);
x=x+h;
printf('\nWhen x=%g,y=%g\n',x,y);
end
OUTPUT:
Experiment – 10
Aim – Write a program to find the solution of initial value using Runge-Kutta method of fourth
order
OUTPUT: