0% found this document useful (0 votes)
4 views

NAS Lab Record

Uploaded by

Jeevan Kp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

NAS Lab Record

Uploaded by

Jeevan Kp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 31

HASSAN.

CERTIFICATE
A

PRACTICAL RECORD
This is to certify that Sri._________________________

has satisfactorily completedBOOK


the course of experiments in

Numerical analysis and statistics, IV SEMESTER B.C.A.


OF
course in the Laboratory of this college during 2017-2018.
NUMERICAL ANALYSIS AND STATISTICS

Signature of the In charge Lecturer


IV SEMESTER B.C.A

Signature of the HODSubmitted by:

Date : EXAMINER’S : 1.

2.

Govt. HOME SCIENCE COLLEGE


HASSAN- 573201
SL. PAGE
NO
PROGRAM LIST NO
PART A
01.
Program to solve the given equation x*x-14=0 by using Bisection method.

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.

1. Program to solve the given equation x*x-14=0 by using Bisection method.

1. /* PROGRAM TO FIND THE ROOT BY BISECTION METHOD */


#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float y);
void main()
{
float x0,x1,x2,y0,y1,y2,e=0.001,i;
clrscr();
printf("\n\t\t F(x) = (x*x) - 14 \n");
printf("\tEnter the initial guess ");
printf("\n\t First guess x0 :");
scanf ("%f",&x0);
printf("\t Second guess x1 :");
scanf ("%f",&x1);
printf("\t ERROR :%5.3f\n",e);
y0=f(x0);
y1=f(x1);
i=0;
if (y0*y1>0)
printf("\n\t Initial GUESSES are not valid .....");
else
{
printf("\n \tBISECTION METHOD\n");
printf("\nI\t x0\t x1\t x2\t Y0\t Y1\t Y2\n");
do
{
if (i<10)
x2=(x0+x1)/2.0;
y0=f(x0);
y1=f(x1);
y2=f(x2);
printf("\n%3.0f\t%6.3f\t%6.3f\t%6.3f",i,x0,x1,x2);
printf("\t%6.3f\t%6.3f\t%6.3f",y0,y1,y2);
if (y1*y2 > 0)
x1=x2;
else
x0=x2;
i=i+1;
}
while (fabs((x1-x0)/x1)>e);
}
printf("\n");
printf ("\n\n The required root = %6.3f",x2);
getch();
}
float f(float y)
{
float d;
d=(y*y)-14;
return d;
}

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

The required root = 3.740

2. TO FIND ROOT OF THE EQUATION USING REGULA FALSI METHOD


F(x)=X*X+5*X-6
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float y);
void main()
{
float x0,x1,x2,y0,y1,y2,e=0.001,i,n;
clrscr();
printf("\n\t\t\t REGULA FALSI METHOD \n");
printf("\n\t F(x) = (x*x+5*x-6=0 \n");
printf("\t Enter the initial guess ");
printf("\n\t First guess x0 :");
scanf ("%f",&x0);
printf("\t Second guess x1 :");
scanf ("%f",&x1);
printf("\t Number of iteration :");
scanf ("%f",&n);
printf("\t ERROR :%5.3f\n",e);
y0=f(x0);
y1=f(x1);
if (y0*y1>0)
printf("\n\t Initial GUESSES are not valid .....");
else
{
printf("\n I\t x0\t x1\t x2\t Y0 \t Y1\t Y2\n");
for (i=1;i<=n;i++)
{
x2=(x0*y1-x1*y0)/(y1-y0);
y2=f(x2);
if ( fabs(y2) <= e)
{
printf("\n\n Convergent solution\n");
printf("\n\t X2 %6.3f\n\t Y2 %6.3f\n",x2,y2);
break;
}
else
{
y0=f(x0);
y1=f(x1);
printf("\n%3.0f \t%6.3f \t%6.3f \t%6.3f",i,x0,x1,x2);
printf("\t%6.3f\t%6.3f \t%6.3f",y0,y1,y2);
}
if (y1*y2 > 0)
x1=x2;
else
x0=x2;
}
}
printf("\n");
printf ("\n The required root = %6.3f\n",x2);
getch();
}
float f(float y)
{
return(y*y+5*y-6);
}
OUTPUT
REGULA FALSI METHOD

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

1 0.000 2.000 0.857 -6.000 8.000 -0.980


2 0.857 2.000 1.347 -0.980 8.000 2.549
3 0.857 1.347 0.911 -0.980 2.549 -0.618
4 0.911 1.347 1.032 -0.618 2.549 0.223
5 0.911 1.032 0.934 -0.618 0.223 -0.456
6 0.934 1.032 1.006 -0.456 0.223 0.041
7 0.934 1.006 0.982 -0.456 0.041 -0.123
8 0.982 1.006 1.004 -0.123 0.041 0.027

The required root = 1.004

3. /* TO FIND SQUARE ROOT OF 25 USING NEWTON-RAPHSON


METOHD */
F(x) = (x*x*X) - 12 and DF(x) = 3*x*x
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float y);
float df(float y);
void main()
{
float x0,x1,y0,y1,e=0.001,n,d=0,i;
clrscr();
printf("\n \t NEWTON RAPHSON METHOD \n ");
printf("\n\n\t F(x) = x*x*x - 12 \n");
printf("\t Enter the Initial guess x0 :");
scanf ("%f",&x0);
printf("\t Enter the number of iteration :");
scanf ("%f",&n);
printf("\n I \t x0 \t x1 \t Y0 \t\t Y1 \n");
for (i=1;i<=n;i++)
{
y0=f(x0);
y1=df(x0);
if(fabs(y1)<=d)
{
printf("\n\t Slope too small \n");
printf("\tx0 = %6.4f \n\t x1 = %6.4f",x0,x1);
printf("\n\tY0 = %6.4f \n\t Y1 = %3.1f ",y0,y1);

}
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 */

float f(float x,float y);


#include<stdio.h>
#include<conio.h>
void main()
{
float x1,x2,y1,y2,xf,h,s1,s2;
clrscr();
printf("\n\tEnter the initial value of X: ");
scanf("%f",&x1);
printf("\t Enter the intial value of Y:");
scanf("%f",&y1);
printf("\t Enter the value of Xf:");
scanf("%f",&xf);
printf("\t Enter the value of H :");
scanf("%f",&h);
clrscr();
printf("\nFIND THE SOLUTION OF THE EQUATION F(X) USING");
printf(" RANGE KUTTA II ORDER METHOD");
printf("\n\n\t F(X)=X*Y\n");
printf("\nThe initial 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\t X\t\t Y\t\t\n");
while(x1<=xf)
{
printf("\n\t\t%2.4f\t\t\%2.4f\t\t\n",x1,y1);
s1=f(x1,y1);
s2=f(x1+h,y1+s1*h);
y2=y1+h*(s1+s2)/2;
x2=x1+h;
y1=y2;
x1=x2;
}
printf("\n");
printf("The requried value of y at x =%.3f is %.4f\n",xf,y1);
getch();
return;
}

float f(float x,float y)


{
return(x*y);
}

FIND THE SOLUTION OF THE EQUATION F(X)=x*y USING RK II ORDER METHOD


The initial 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.8070

The requried value of y at x =1.400 is 4.2908


6. /* TO FIND THE ROOTS OF THE EQUATION USING rk IV ORDER
F(X)=X*Y at x1=1, y1=2, h=0.3, xf=1.4
float f(float x, float y);
#include<stdio.h>
#include<conio.h>
void main()
{
float x1,x2,y1,y2,h,xf,s1,s2,s3,s4;
clrscr();
printf("\n\t Enter the intial 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(" \t\tRUNGE KUTTA IV ORDER METHOD .");
printf("\n\n\t F(X) = X*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);
s1=f(x1,y1);
s2=f(x1+h/2, y1+s1*h/2);
s3=f(x1+h/2, y1+s2*h/2);
s4=f(x1+h, y1+s3*h);
y2=y1+h/6*(s1+2*s2+2*s3+s4);
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 x,float y)
{
return (x*y);
}

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

The required value of y at x = 1.400 is 4.3623


7. /* TO FIND THE INTEGRATED VALUE OF F(X) USING TRAPEZOIDAL
RULE */
F(x) = ∫(1/(1 + X) )dx limits 0 to 1 for n=10
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float x1,xn,sum,area,x,h;
int i,n;
float f(float);
clrscr();
printf("\n\t TRAPEZOIDAL Rule");
printf("\n\t F(x) = 1 / (1+x) \n");
printf("\n\t Enter lower and upper limit :");
scanf("%f%f",&x1,&xn);
printf("\t Enter the number of iteration :");
scanf("%d",&n);
h=(xn-x1)/n;
sum=(f(x1)+f(xn))/2;
printf("Lower limit= %6.4f\n",x1);
printf("upper limit= %6.4f\n",xn);
printf("Step width = %6.4f\n", h);
printf("f(0)=%6.4f\nf(1)=%6.4f\n", f(x1),f(xn));
printf("ITERATION\t X\t F(X)\t AREA\n");
for(i=1;i<n;i++)
{
x=x1+i*h;
sum=sum+f(x);
area=h * sum;
printf("\n\t %2d\t%6.4f\t%6.4f\t%6.4f",i,x,f(x),area);
}
getch();
}
float f(float x)
{
return(1/(1+x));
}

/**************** output **************************/


TRAPEZOIDAL Rule
F(x) = 1 / (1+x)
Enter lower and upper limit :0 1
Enter the number of iteration :10
Lower limit= 0.0000
upper limit= 1.0000
Step width = 0.1000
f(0)=1.0000 f(1)=0.5000

ITERATION X F(X) AREA


1 0.1000 0.9091 0.1659
2 0.2000 0.8333 0.2492
3 0.3000 0.7692 0.3262
4 0.4000 0.7143 0.3976
5 0.5000 0.6667 0.4643
6 0.6000 0.6250 0.5268
7 0.7000 0.5882 0.5856
8 0.8000 0.5556 0.6411
9 0.9000 0.5263 0.6938
8. /* TO FIND THE INTEGRATED VALUE OF F(X) USING SIMPSON'S 1/3
RULE F(x) = ∫ sin(x)dx limits 0 to π/2 for n=6
*/
#include<stdio.h>
#include<math.h>
float f(float y);
main()
{
float x1,xn,h,area,sum,x;
int n,i;
clrscr();
printf("\nEnter the lower & upper limits\n");
scanf("%f%f",&x1,&xn);
printf("Enter the max no of iteration\n");
scanf("%d",&n);
h=(xn-x1)/n;
sum = f(x1) + f(xn);
clrscr();
printf("\n \t\t SIMPSON 1/3 RULE\n");
printf("F(X)=sin(x) with x1=0, xn = (22/7)/2 for n=6\n");
printf("\n\t The lower limit = %3.4f\n",x1);
printf("\t The upper limit = %3.4f\n",xn);
printf("\t The no of iterations = %d\n",n);
printf("\t The value of step width = %6.4f\n",h);
printf("The value of X1=%6.4f and Xn=%6.4f\n", x1,xn);
printf("\nIterations\t X\t\t F(X)\n");
for(i=1;i<=n-1;i++)
{
x=x1+i*h;
if (i%2 == 1)
sum=sum+(4.0*f(x));
else
sum= sum+(2.0*f(x));
printf("\n %d\t\t %3.4f\t\t %3.4f",i,x,f(x));
}
printf("\n");
area=(h/3.0) * sum;
printf("\n\t The area = %4.4f\n",area);
getch();
}
float f(float y)
{
return(sin(y));
}

/* 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

The area = 1.0006


9. /* TO FIND THE INTEGRATED VALUE USING simpson's 3/8 rule
F(x) = ∫ sin(x)dx limits 0 to π/2 for n=6 */
#include<stdio.h>
#include<math.h>
float f(float y);
main()
{
float x1,xn,h,area,sum,x,f1,fn1;
int n,i;
clrscr();
printf("\nEnter the lower & upper limits\n");
scanf("%f %f",&x1,&xn);
printf("Enter the max no of iteration\n");
scanf("%d",&n);
h=(xn-x1)/n;
clrscr();
sum = f(x1) + f(xn);
printf("\n \t\t SIMPSON 3/8 RULE\n");
printf("\n\t The lower limit = %3.4f\n",x1);
printf("\t The upper limit = %3.4f\n",xn);
printf("\t The no of iterations = %d\n",n);
printf("\t The value of step width = %6.4f\n",h);
printf("\nIterations\t X\t\tF(X)\n");
for(i=1;i<n;i++)
{
x=x1+i*h;
if(i%3==0)
sum=sum+(2.0*f(x));
else
sum=sum+(3.0*f(x));
printf("\n%d \t\t %3.4f \t\t %3.4f",i,x,f(x));
}
printf("\n");
area=(3.0 * h * sum)/8;
printf("\n\t The area = %4.4f\n",area);
getch();
}
float f(float y)
{
return(sin(y));
}

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

The area = 1.0007


10. /* Program to solve the equations x1+x2+4x3=12, 8x1-
3x2+2x3=20, 4x1+11x2-x3=33 using GAUSS ELIMINATION
METHOD. */
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n,k;
float u,xn,sum,x[100],a[10][10];
clrscr();
printf("\n\t Enter the order of the matrix :");
scanf("%d",&n);
printf("\n Enter the elements \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("\n\t GAUSS ELIMINATION METHOD.");
printf("\n\t **************************");
printf("\n\n\n Entered matrix is .....\n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf("%6.2f",a[i][j]);
printf("\n");
}
for(i=2;i<=n;i++)
{
u=a[i][1]/a[1][1];
for(j=1;j<=n+1;j++)
{
a[i][j]=a[i][j]-u*a[1][j];
}
}
/* ELIMINATION OF X(n-1) EXTENDED TO N UNKNOWNS*/
i=3;
u=a[i][2]/a[2][2];
for(j=2;j<=n+1;j++)
a[i][j]=a[i][j]-u*a[2][j];
printf("\n\n TRIANGULARIZED MATRIX \n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf(" %6.2f",a[i][j]);
printf("\n");
}
/* BACK SUBSTITUTION */
printf("\n\n The required values of .........\n");
x[n]=a[n][n+1]/a[n][n];
for(i=n-1;i>=1;i--)
{
sum=0.0;
for(j=i+1;j<=n;j++)
{
sum=sum+a[i][j]*x[j];
}
x[i]=(a[i][n+1] - sum)/a[i][i];
}
for(i=1;i<=n;i++)
printf("\n\t x[%d] = %.2f",i,x[i]);
getch();
return;
}
OUTPUT

GAUSS ELIMINATION METHOD.


**************************
Enter the order of the matrix : 3
Entered matrix is .....
1.00 1.00 4.00 12.00
8.00 -3.00 2.00 20.00
4.00 11.00 -1.00 33.00

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

The required values of .........

x[1] = 2.86
x[2] = 2.12
x[3] = 1.76

11 /* PROGRAM TO IMPLEMENT GAUSS JORDON METHOD


*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k;
float u,xn,sum,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("\n\t GAUSS JORDAN METHOD.");
printf("\n\t **************************");
printf("\n\n\n Entered matrix is .....\n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf("%6.2f",a[i][j]);
printf("\n");
}
for (k=1; k<=n; k++)
for(i=1;i<=n;i++)
if(i!=k)
{
u=a[i][k]/a[k][k];
for(j=k;j<=n+1;j++)
{
a[i][j]=a[i][j]-u*a[k][j];
}
}
printf("\n\n THE GIVEN MATRIX AFTER DIAGONALISE \n\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
printf(" %6.2f",a[i][j]);
printf("\n");
}
/* FORWARD SUBSTITUTION */
for (i=1; i<=n; i++)
x[i]= a[i][n+1] / a[i][i];
printf("\n\n The required values of .........\n");
for(i=1;i<=n;i++)
printf("\n\t x[%d] = %.2f",i,x[i]);
getch();
return;
}

OUTPUT
GAUSS JORDAN METHOD.
*************************
Enter the order of the matrix : 3

Entered matrix is .....

2.00 6.00 -1.00 -14.00


5.00 -1.00 2.00 29.00
-3.00 -4.00 1.00 4.00

THE GIVEN MATRIX AFTER DIAGONALISE

2.00 0.00 0.00 7.72


0.00 -16.00 0.00 49.10
0.00 0.00 0.91 3.00

The required values of .........

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

13. /* TO FIND MEAN, mode, MEDIAN, and standard


deviation of n-elements using arrays for ungrouped data*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i,temp,j,count, pre;
float a[' '],sum=0,sumsq,avg,mean,median,s,std,c,mod,bi;
clrscr();
printf("Enter the Size of the Array : ");
scanf("%d",&n);
printf("Enter the Elements for Array\n");
for(i=1;i<=n;i++)
{
scanf("%f",&a[i]);
sum=sum+a[i];
}
mean=sum/n;
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-i;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
printf("\nThe Elements of the Array After Sorting....\n");
for(i=1;i<=n;i++)
{
printf("%4.2f\t",a[i]);
}
if(n%2==1)
median=a[(n/2)+1];
else
median=(a[n/2]+a[n/2+1])/2;
sumsq=0;
for(i=1;i<=n;i++)
{
sumsq=sumsq+a[i]*a[i];
}
s=sumsq/n-(mean*mean);
std=sqrt(s);
count=pre=1;
for(i=0; i<n; i++)
{
c=a[i];
count=1;
for(j=0; j<n; j++)
{
if(c==a[j])
count++;
if(count>pre)
{
pre=count;
mod=c;
}
}
}
if(pre==1)
printf("There is no mode\n");
else
printf("\nMean is = %4.5f", mean);
printf("\nMode = %4.5f", mod);
printf("\nMedian = %6.4f",median);
printf("\nStandard Deviation = %6.4f\n",std);
getch();
}

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

14. /*PROGRAM TO CALCULATE CORRELATION CO-EFFICIENT*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int u[20],v[20],u2[20],a,b,x[20],y[20],n,sumv=0,
sumu=0,sumu2=0,sumv2=0,v2[20],uv[20],sumuv=0;
float nr,dr,corr;
int mid,i;
clrscr();
printf("enter the value of n \n");
scanf("%d",&n);
printf("enter the value of x and y\n");
for(i=1;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
mid=n/2;
a=x[mid];
b=y[mid];
for(i=1;i<=n;i++)
{
u[i]=x[i]-a;
u2[i]=u[i]*u[i];
v[i]=y[i]-b;
v2[i]=v[i]*v[i];
uv[i]=u[i]*u[i];
sumv=sumv+v[i];
sumu=sumu+u[i];
sumv2=sumv2+v2[i];
sumu2=sumu2+u2[i];
sumuv=sumuv+uv[i];
}
nr=((n*sumuv)-(sumu*sumv));
dr=((sqrt(n*sumu2-sumu*sumu))*(sqrt(n*sumv2-sumv*sumv)));
corr=nr/dr;
printf("correlation=%4.2f",corr);
getch();
}
/* OUTPUT */
enter the value of n 5
enter the value of x and y
2 5
4 8
3 7
5 9
2 4
correlation=0.41
15. Program to generate frequency distribution table

#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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy