NAS Lab Record
NAS Lab Record
CERTIFICATE
A
PRACTICAL RECORD
This is to certify that Sri._________________________
Date : EXAMINER’S : 1.
2.
02. Program to solve the given equation x*x+5*x-6=0 by using Regula Falsi
method.
03. Program to solve the given equation x*x*x-12=0 by using Newton Raphson
method.
04. Program to solve the given equation dy/dx=1+y*y where x1=0, y1=1, h=0.3,
xf=1.4 using Eulers method.
05. Program to solve the given equation dy/dx=x*y where X1=1, y1=2 , h=0.3,
XF=1.4 by using Rungekutta’s II order method.
06. Program to solve the given equation dy/dx=x*y where X1=1, y1=2 , h=0.3,
XF=1.4 by using Rungekutta’s II order method.
07. Program to solve the given equation ∫ dx/(1+x) where, a=0,b=1,n=10 by using
Trapezoidal method.
08. Program to solve the given equation ∫ Sin (x)dx where a=0,b=π/2, n=6 by
using Simpson’s 1/3 rule.
09. Program to solve the given equation ∫ Sin (x)dx where a=0,b=π/2, n=6 by
using Simpson’s 1/3 rule.
PART B
10. Program to solve the following set of simultaneous equation x+y+4z=12, 8x-
3y+2z=20,4x+11y-z=33 using the Guass Elimination method.
11. Program to solve the following set of simultaneous equation 2x1+6x2-x3 = -
14,5x 1-x2 +2x3 =29,-3x1 -4x2 +x3 =4 using Guass Jordon method.
12. Program to solve the following set of simultaneous equation 2x1 –x2 +x 3 =5,
x1 +3x2-2x3=7,x1+2x2+3x3=10 using Guass Seidal method.
13. Program to compute mean, median and standard deviation of n elements
using linear array for ungrouped data.
14.
Program to calculate correlation co-efficient for ungrouped data.
15.
Program to generate frequency distribution table.
OUTPUT
BISECTION METHOD
F(x) = (x*x) - 14
Enter the initial guess
First guess x0 :3
Second guess x1 :5
ERROR :0.001
I x0 x1 x2 Y0 Y1 Y2
0 3.000 5.000 4.000 -5.000 11.000 2.000
1 3.000 4.000 3.500 -5.000 2.000 -1.750
2 3.500 4.000 3.750 -1.750 2.000 0.062
3 3.500 3.750 3.625 -1.750 0.062 -0.859
4 3.625 3.750 3.688 -0.859 0.062 -0.402
5 3.688 3.750 3.719 -0.402 0.062 -0.171
6 3.719 3.750 3.734 -0.171 0.062 -0.054
7 3.734 3.750 3.742 -0.054 0.062 0.004
8 3.734 3.742 3.738 -0.054 0.004 -0.025
9 3.738 3.742 3.740 -0.025 0.004 -0.011
F(x) = (x*x+5*x-6=0
Enter the initial guess
First guess x0 :0
Second guess x1 :2
Number of iteration :8
ERROR :0.001
I x0 x1 x2 Y0 Y1 Y2
}
else
{
x1=x0-(y0/y1);
printf("%3.1f\t %6.4f \t %6.4f",i,x0,x1);
printf("\t\t %6.4f \t %6.4f\n ",y0,y1);
if (fabs((x1-x0)/x1)>e)
x0=x1;
}
}
printf("\n\t Covergent solution");
printf("\n\t Required root = %.4f",x1);
getch();
}
float f(float y)
{
return(y*y*y-12);
}
float df(float y)
{
return(3*y*y);
}
OUTPUT
NEWTON RAPHSON METHOD
F(x) = x*x*x - 12
Enter the Initial guess x0 :2
Enter the number of iteration :4
I x0 x1 Y0 Y1
1.0 2.0000 2.3333 -4.0000 12.0000
2.0 2.3333 2.2902 0.7037 16.3333
3.0 2.2902 2.2894 0.0129 15.7357
4.0 2.2902 2.2894 0.0129 15.7357
Covergent solution
Required root = 2.2894
4. /* TO FIND THE ROOTS OF THE EQN F(x) USING EULER'S
METHOD */
F(X) = 1+y*Y. Y(0)=1, h=0.1,
find y(1.4)
float f(float y);
#include<stdio.h>
#include<conio.h>
void main()
{
float x1,x2,y1,y2,h,xf,s;
clrscr();
printf("\n\t Enter the initial value of X : ");
scanf ("%f",&x1);
printf("\t Enter the initial value of Y : ");
scanf ("%f",&y1);
printf("\t Enter the value of Xf : ");
scanf ("%f",&xf);
printf("\t Enter the initial value of H : ");
scanf ("%f",&h);
printf("\n\tTO FIND THE SOLUTION OF THE EQUATION F(x) USING ");
printf(" EULER'S METHOD .");
printf("\n\n\t F(X) = 1+Y*Y \n");
printf("\nThe intial values x1 = %3.3f and Y1 = %3.3f\n", x1,y1);
printf("The final value of X = %3.3f\n",xf);
printf("The step width H = %3.3f\n", h);
printf("\n\t\tX \t\t Y \t\t\n");
while(x1<xf)
{
printf("\n\t\t%2.4f\t\t\%2.4f\t\t\n",x1,y1);
s=f(y1);
y2= y1+h*s;
x2=x1+h;
y1=y2;
x1=x2;
}
printf("\n");
printf(" The required value of y at x = %.3f is %.4f\n",xf,y1);
getch();
return;
}
float f(float y)
{
return (1+y*y);
}
OUTPUT
Enter the initial value of X : 0
Enter the initial value of Y : 1
Enter the value of Xf : .4
Enter the initial value of H : .1
TO FIND THE SOLUTION OF THE EQUATION F(x) USING EULER'S METHOD .
F(X) = 1+Y*Y
The initial values x1 = 0.000 and Y1 = 1.000
The final value of X = 0.400
The step width H = 0.100
X Y
0.0000 1.0000
0.1000 1.2000
0.2000 1.4440
0.3000 1.7525
The required value of y at x = 0.400 is 2.1596
5. /* TO FIND THE ROOTS OF THE EQUATION USING RK II ORDER METHOD
F(X) =X*Y y(1)=2, h=.3 and find y(1.4) i.e x1=1, y1=2, xf=1.4 */
X Y
1.0000 2.0000
1.3000 2.8070
OUTPUT
RUNGE KUTTA IV ORDER
Enter the intial value of X : 1
Enter the initial value of Y : 2
Enter the value of Xf : 1.4
Enter the initial value of H : .3
The intial values x1 = 1.000 and Y1 = 2.000
The final value of X = 1.400
The step width H = 0.300
X Y
1.0000 2.0000
1.3000 2.8239
/* OUTPUT */
SIMPSON 1/3 RULE
F(X)=sin(x) with x1=0, xn = (22/7)/2 for n=6
The lower limit = 0.0000
The upper limit = 1.5714
The no of iterations = 6
The value of step width = 0.2619
The value of X1=0.0000 and Xn=1.5714
Iterations X F(X)
1 0.2619 0.2589
2 0.5238 0.5002
3 0.7857 0.7073
4 1.0476 0.8662
5 1.3095 0.9661
OUTPUT
SIMPSON 3/8 RULE
The lower limit = 0.0000
The upper limit = 1.5714
The no of iterations = 6
The value of step width = 0.2619
Iterations X F(X)
1 0.2619 0.2589
2 0.5238 0.5002
3 0.7857 0.7073
4 1.0476 0.8662
5 1.3095 0.9661
TRIANGULARIZED MATRIX
1.00 1.00 4.00 12.00
0.00 -11.00 -30.00 -76.00
0.00 0.00 -36.09 -63.36
x[1] = 2.86
x[2] = 2.12
x[3] = 1.76
OUTPUT
GAUSS JORDAN METHOD.
*************************
Enter the order of the matrix : 3
x[1] = 3.86
x[2] = -3.07
x[3] = 3.31
12. /* PROGRAM TO IMPLEMENT GAUSS SEIDAL METHOD
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,n,itr, maxit;
float e,big,sum,temp,reerr,x[100],a[10][10];
clrscr();
printf("\n\t Enter the order of the matrix :");
scanf("%d",&n);
printf("\n Enter the augumented matrix \n");
for(i=1;i<=n;i++)
for(j=1;j<=n+1;j++)
{
printf(" A[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
clrscr();
printf("Enter the allowed relative error \n");
scanf("%f",&e);
printf("Enter the maximum no. of iterations\n");
scanf("%d", &maxit);
printf("\n\t GAUSS SEIDAL METHOD.");
printf("\n\t **************************");
printf("\n\n Entered matrix is .....\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf("%6.2f",a[i][j]);
printf("\n");
}
/* INITIALISEING THE SOLUTION VECTOR TO ZERO */
for (i=1; i<=n; i++)
x[i]=0.0;
printf("\nIT. NO\t\tX1\t\tX2\t\tX3\n");
/* TO FIND THE ROOTS */
for(itr=1; itr<=maxit; itr++)
{
big=0.0;
printf("\n%d",itr);
for(i=1; i<=n; i++)
{
sum=0.0;
for(j=1;j<=n;j++)
if(j!=i)
sum=sum + (a[i][j]*x[j]);
temp=(a[i][n+1]-sum)/a[i][i];
reerr=fabs((temp-x[i])/temp);
if(reerr>big)
big=reerr;
x[i]=temp;
printf("\t\t%2.3f", x[i]);
}
}
printf("\n");
if (big<=e)
{
printf("Solution vector is \n");
for(i=1;i<=n;i++)
printf("\tx[%d] = %2.3f\n",i,x[i]);
exit();
}
}
OUTPUT
GAUSS SEIDAL METHOD.
Enter the order of the matrix : 3
Enter the allowed relative error : 0.001
Enter the maximum no. of iterations : 10
Entered matrix is .....
2.00 -1.00 1.00 5.00
1.00 3.00 -1.00 7.00
1.00 2.00 3.00 10.00
IT. NO X1 X2 X3
1 2.500 1.500 1.500
2 2.500 2.000 1.167
3 2.917 1.750 1.194
4 2.778 1.806 1.204
5 2.801 1.801 1.199
6 2.801 1.799 1.200
7 2.800 1.800 1.200
8 2.800 1.800 1.200
9 2.800 1.800 1.200
10 2.800 1.800 1.200
Solution vector is
x[1] = 2.800
x[2] = 1.800
x[3] = 1.200
Output
Enter the Size of the Array : 5
Enter the Elements for Array
1 2 2 3 4
The Elements of the Array After Sorting....
1.00 2.00 2.00 3.00 4.00
Mean is = 2.40000
Mode = 2.00000
Median = 2.0000
Standard Deviation = 1.0198
#include<stdio.h>
#include<conio.h>
main( )
{
int a[20],i,n1=0,n2=0,n3=0,n4=0,n5=0;
clrscr();
printf("enter the any 10 no of range(1- 25)");
for(i=1;i<=15;i++)
scanf("%d",&a[i]);
for(i=1;i<=10;i++)
if((a[i]>=1)&&(a[i]<6))
n1++;
else if((a[i]>5)&&(a[i]<11))
n2++;
else if((a[i]>10)&&(a[i]<16))
n3++;
else if((a[i]>15)&&(a[i]<21))
n4++;
else if((a[i]>20)&&(a[i]<26))
n5++;
printf("class interval frequency");
printf("\n 01-05 \t%d",n1);
printf("\n 06-10 \t%d",n2);
printf("\n 11-15 \t%d",n3);
printf("\n 16-20 \t%d",n4);
printf("\n 21-25 \t%d",n5);
getch();
}
/* OUTPUT */
enter the any 15 no of range(1- 25)
12 7 8 9 1 4
1 9 1 2 43 2
24 23 23
class interval frequency
1-5 6
6-10 4
11-15 1
16-20 0
21-25 3