Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

C program Mini

The document contains various numerical methods implemented in C programming, including Euler's modified method, Gauss-Jacobi, Gauss-Seidel, Newton forward interpolation, Lagrange interpolation, and methods for root-finding such as the bisection method and Newton-Raphson. Each method is accompanied by code snippets demonstrating how to perform calculations related to these numerical techniques. The document serves as a reference for implementing these algorithms in programming.

Uploaded by

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

C program Mini

The document contains various numerical methods implemented in C programming, including Euler's modified method, Gauss-Jacobi, Gauss-Seidel, Newton forward interpolation, Lagrange interpolation, and methods for root-finding such as the bisection method and Newton-Raphson. Each method is accompanied by code snippets demonstrating how to perform calculations related to these numerical techniques. The document serves as a reference for implementing these algorithms in programming.

Uploaded by

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

Euler’s modified method Gauss-Jacobi

#include<stdio.h> #include <stdio.h> Gauss Quadrature Gauss-elimination #include<stdio.h>


#include<stdio.h> #include<math.h>
#include<math.h>
#include <math.h> int main() #define X1(x2,x3) ((20+3*x2-2*x3)/8)
float f(float x, float y) float f(float x) { #define X2(x1,x3) ((33-4*x1+x3)/11)
{ { int i,j,k,n; #define X3(x1,x3) ((9-x1-x2)/4)
return (x*x+y); return (x*x*x); float A[20][20],c,x[10],sum=0.0; #define ESP 0.00001
} } printf("\nEnter the order of matrix: "); void main()
int main() int main() scanf("%d",&n); {
{ { printf("\nEnter the elements of augmented matrix double x1=0,x2=0,x3=0,y1,y2,y3;
int i; row-wise:\n\n"); int i=0;
float x,y,x0,y0,h,k1,k2;
float x[20],w[20],a,b,p,q, result= 0; for(i=1; i<=n; i++) printf("\n x1 \t x2 \t x3");
int i,n; printf("Enter the values of a and b:\n"); { printf("\n %f\t%f\t%f",x1,x2,x3);
printf("\n Enetr the value of x,x0,y0,h="); scanf("%f%f",&a,&b); for(j=1; j<=(n+1); j++) do
scanf("%f%f%f%f",& x,& x0,& y0,& h); p=(a+b)/2; { {
n=(x-x0)/h; q=(b-a)/2; printf("A[%d][%d] : ", i,j); y1=X1(x2,x3);
x=x0; x[1]=0.23861919; scanf("%f",&A[i][j]); y2=X2(x1,x3);
x[2]=-x[1]; } y3=X3(x1,x2);
y=y0;
x[3]=0.661209899; } if(fabs(y1-x1)<ESP&&
for(i=1;i<=n;i++)
x[4]=-x[3]; for(j=1; j<=n; j++) /* loop for the generation of fabs(y2-x2)<ESP&&
{ x[5]=0.93246951; upper triangular matrix*/ fabs(y3-x3)<ESP)
k1=h*f(x,y); x[6]=-x[5]; { for(i=1; i<=n; i++) {
k2=h*f(x+h,y+k1); w[1]=0.46791393; { if(i>j) printf("\n x1=%0.4f",y1);
y=y+(k1+k2)/2; w[2]=w[1]; { printf("\n x2=%0.4f",y2);
x=x+h; w[3]=0.36076157; c=A[i][j]/A[j][j]; printf("\n x3=%0.4f",y3);
w[4]=w[3]; for(k=1; k<=n+1; k++) i=1;
}
w[5]=0.17132449; { }
printf("\n The required value is: %f",y); w[6]=w[5]; A[i][k]=A[i][k]-c*A[j][k]; } else
return 0; for (i=1;i<=6;i++) {
} { } x1=y1;
result = result + w[i] * f(p + q * x[i]); x2=y2;
} } x3=y3;
result= result * q; printf("\n %f\t%f\t%f",x1,x2,x3);
}
Gauss-Seidel printf("The value of the integral:%5.3f", result); }
x[n]=A[n][n+1]/A[n][n];
#include<stdio.h> return 0; /* this loop is for backward substitution*/ }
#include<math.h> } for(i=n-1; i>=1; i--) while(i!=1);
#define X1(x2,x3) ((20+3*x2-2*x3)/8) { }
#define X2(x1,x3) ((33-4*x1+x3)/11) sum=0;
#define X3(x1,x3) ((9-x1-x2)/4) for(j=i+1; j<=n; j++)
Newton forward interpolation
#define ESP 0.00001 {
#include<stdio.h>
void main() sum=sum+A[i][j]*x[j]; Power method
int main()
{ } #include<stdio.h>
{
double x1=0,x2=0,x3=0,y1,y2,y3; x[i]=(A[i][n+1]-sum)/A[i][i]; #include<math.h>
float x[20], y[20][20],sum,p,h,a,u;
int i=0; } void main()
int i,j, n;
printf("x1\t\tx2\t\tx3"); printf("\nThe solution is: \n"); {
printf("Enter number of data?\n");
printf("\n"); for(i=1; i<=n; i++) int i,j,n;
scanf("%d", &n);
do { float
printf("Enter data:\n");
{ printf("\nx%d=%f\t",i,x[i]); /* x1, x2, x3 are the A[30][30],x[30],z[30],e[30],zmax,emax;
for(i = 0; i < n ; i++)
y1=X1(x2,x3); required solutions*/ printf("\nEnter the order of matrix:");
{
y2=X2(y1,x3); } scanf("%d",&n);
printf("x[%d]=", i);
y3=X3(y1,y2); return(0); printf("\nEnter matrix elements row-
scanf("%f", &x[i]);
if(fabs(y1-x1)<ESP&& fabs(y2-x2)<ESP&& fabs(y3- } wise\n");
printf("y[%d]=", i);
x3)<ESP) for(i=1; i<=n; i++)
scanf("%f", &y[i][0]);
{ {
}
printf("\n x1=%0.4f",y1); for(j=1; j<=n; j++)
printf("entre the value of x : ");
printf("\n x2=%0.4f",y2); standard deviation {
scanf("%f",&a);
printf("\n x3=%0.4f",y3); #include<stdio.h> printf("A[%d][%d]=", i,j);
i=1; #include<math.h> scanf("%f",&A[i][j]);
for(i = 1; i < n; i++)
} int main() }
{
else { }
for(j = 0; j < n-i; j++)
{ float xxf[6],dr1=0,dr=0,xf[6]; printf("\nEnter the initial column
{
x1=y1; float x[6]= {1,2,3,4,5,6}, f[6]={4,3,2,5,6,5}, vector\n");
y[j][i] = y[j+1][i-1] - y[j][i-1];
x2=y2; sumf=0; for(i=1; i<=n; i++)
}
x3=y3; float sumx2f=0, sumxf=0; {
printf("\n %f\t%f\t%f",x1,x2,x3); } int i,n=6; printf("X[%d]=",i);
} printf("\n The forward difference table is \n\n"); for(i=0;i<n;i++) scanf("%f",&x[i]);
} for(i = 0; i < n; i++) { }
while(i!=1); { xxf[i]=x[i]*x[i]*f[i]; do
} printf("%0.2f", x[i]); xf[i]=x[i]*f[i]; {
for(j = 0; j < n-i ; j++) } for(i=1; i<=n; i++)
{ for(i=0;i<n;i++) {
printf("\t%0.2f", y[i][j]); { z[i]=0;
} sumxf+=xf[i]; for(j=1; j<=n; j++)
Lagrange Interpolation printf("\n"); sumf+=f[i]; {
#include<stdio.h> } } z[i]=z[i]+A[i][j]*x[j];
#include<math.h> p=1.0; for(i=0;i<n;i++) }
void main() sum=y[0][0]; { }
{ h=x[1]-x[0]; zmax=fabs(z[1]);
float x[50], y[50], x0, p ,y0=0.0; u=(a-x[0])/h; sumx2f+=xxf[i]; for(i=2; i<=n; i++)
int i,n,j; for(j=1;j<n;j++) } {
printf("Enter the value of number of data:"); { float sumx2=sumxf*sumxf; if((fabs(z[i]))>zmax)
scanf("%d",&n); p=p*(u-j+1)/j; printf("\n x\tf\t x*f\t x*x*f\n"); zmax=fabs(z[i]);
}
for(i=1;i<=n;i++) }
sum=sum+p*y[0][j]; for(i=0;i<n;i++)
{ for(i=1; i<=n; i++)
{ {
printf("The value of y at %f is %f",a,sum); printf("%f\t%f\t%f\t%f",x[i],f[i],xf[i],xxf[i]);
printf("Enter the value of x%d:",i); } z[i]=z[i]/zmax;
printf("\n");
scanf("%f",&x[i]); }
}
printf("Enter the value of y%d:",i); for(i=1; i<=n; i++)
printf("sumxf=%f",sumxf);
scanf("%f",&y[i]); {
printf("\nsumx2f=%f",sumx2f);
} e[i]=0;
printf("\n sumx2=%f",sumx2);
printf("Enter the interpolation value:"); e[i]=fabs((fabs(z[i]))-(fabs(x[i])));
printf("\n sumf=%f",sumf);
scanf("%f",&x0); }
dr1= sumx2f/sumf - sumx2/(sumf*sumf);
for(i=1;i<=n;i++) emax=e[1];
printf("\n dr1=%f",dr1);
{ for(i=2; i<=n; i++)
dr=sqrt(dr1);
p=1;
for(j=1;j<=n;j++)
printf("\n Standard Deviation=%f",dr);
return 0;
{
{ if(e[i]>emax)
}
if(i!=j) emax=e[i];
{ }
for(i=1; i<=n; i++)
p=p*(x0-x[j])/(x[i]-x[j]); {
} x[i]=z[i];
} }
y0=y0+p*y[i]; }
} while(emax>0.001);
printf("\n The required largest eigen
printf("The value of y[%f] is %f",x0,y0);
value is %f",zmax);
}
printf("\n\nThe required corresponding
eigen vector is \n");
for(i=1; i<=n; i++)
{
printf("%f\t",z[i]); } }
}
bisection method. 1. Newton-Raphson Regula Falsi method.
fixed point iteration
#include <stdio.h> method.
#include <math.h> #include<math.h> #include<stdio.h> method.
float f(float x) #define f(x) (x*x-sin(x)) #include<math.h> #include<stdio.h>
{ #define g(x) (2*x-cos(x)) #define f(x) (x-sin(x)-1) #include<math.h>
return (3*x+sin(x)-exp(x)); void main() #define g(x) sqrt(sin(x))
void main()
} { void main()
{ {
int main() float x0, x1, f0, g0, f1, e;
float x0, x1, x2, y0, y1, y2, e; float x0, g0, e, k;
{ int i,n;
int i; printf("The initial value x0:"); int i, n; int i, n;
float a,b,e,f2,c; scanf("%f",&x0); printf("Enter the value of x0,x1:"); printf("Enter the initial
printf("Enter the value of a:"); printf("Maximum number of scanf("%f%f",& x0, & x1); value of x0:");
scanf("%f",&a); iteration n:"); scanf("%f",&x0);
printf("Enter the maximum iteration:");
printf("Enter the value of b:"); printf("\n Enter the
scanf("#include<stdio.h> scanf("%d", & n);
number of iterations:");
scanf("%f",&b);
printf("Error:"); scanf("%d",&n);
printf("Error:"); #include<math.h> scanf("%f",& e);
scanf("%f",&e); printf("Enter the error:");
printf("\n No of itteration \t a \t\t b \t\t c \t\t float f(float x, float y) y0=f(x0); scanf("%f",&e);
f(c)" ); y1=f(x1); printf("\n Iteration No.\t
printf("\n............................................................. { if((y0*y1)>0.0) x0\t g(x)");
.................."); printf("\n______________
return (x*x+y); {
_________________");
if(f(a)*f(b)<0) printf("Change the initial
{ } approximation");
for(i=1;i<=n;i++)
do {
{ int main() } g0=g(x0);
c=(a+b)/2; else k=fabs(g0-x0);
f2=f(c);
{ { printf("\n %d \t %f \t
%f",i,x0,g0);
printf("\n %d\t\t\t %f\t %f\t %f\t float x,y,x0,y0,h,k1,k2; for(i=1;i<=n;i++)
if(k<e)
%f",i,a,b,c,f(c)); {
if(f(a)*f(c)<0) int i,n; x2=(x0*y1-x1*y0)/(y1-y0);
{
{ printf("\n The root is
a=a; printf("\n Enetr the y2=f(x2); %f",x0);
b=c; if(fabs(y2)<e) i=n;
value of x,x0,y0,h="); { }
}
else scanf("%f%f%f%f",& printf("The root is %f", x2); x0=g0;
{ }
n=i;
a=c; x,& x0,& y0,& h); }
if(k>e)
b=b; {
}
n=(x-x0)/h; else if((y2*y0)<0) printf("\n Error is not
{ satisfied, increase iteration
i++; x=x0; x1=x2; number");
}
while(fabs(a-b)>e); y=y0; y1=f(x2); }
printf("\n The root is %f",c); } }
} for(i=1;i<=n;i++) else
else
{
{ {
x0=x2;
printf("Change the value of a & b"); k1=h*f(x,y); y0=f(x2);
}
return 0; k2=h*f(x+h,y+k1); } }}}
}
y=y+(k1+k2)/2;
x=x+h; Euler’s method
simpson’s 1/3
trapezoidal rule
#include<stdio.h>
}
#include<stdio.h> #include<stdio.h>
#include<math.h> #include<math.h>
#define f(x)printf("\n The required
#include<math.h>
(x/(1+x))
float f(float x)
int main()
#define f(x,y) ((y-x)/(y+x))
{
{
value is: %f",y); void main()
return (x/(1+2*x+x*x));
} return 0; h,k;
float a, b, integration=0, {
int i,n; float x0,y0,x,y,h;
void main()
printf("Limit} of the intrigation are:");
{
scanf("%f%f", &a, &b);
int i,n;
float a,b,h,s=0,tr; printf("Enter the value of
printf("Enter the number of subintervals
int i,n;
printf("Limit of the intrigation
n:"); %d",&n); x0,y0,h,x: ");
scanf("%d",printf("error
&n); e:"); scanf("%f%f%f%f", &x0, &y0, &h,
are:\n");
h=(b-a)/n; scanf("%f",&e);
scanf("%f%f", &a, &b);
integration=printf("\n
f(a)+f(b);No. of iteration \t x1 \t &x);
printf("Number of intervals is:\n"); printf("%f\t%f\t%f\t%f",x0,y0,h,x
f(x1)");
for(i=1;i<=n-1;i++)
scanf("%d", &n);
h=(b-a)/n;
{ printf("\n_____________________ );
k=a+i*h; ____________\n"); n=(x-x0)/h;
for(i=1;i<=n-1;i++)
if(i%2==0) do
s= s+ f(a+ i*h);
{ { x=x0;
tr= h*(f(a)+f(b)+2*s)/2; y=y0;
f0=f(x0);
integration=integration+2*f(k);
printf("The value of the integral is=
%0.6f",tr);
} g0=g(x0); for(i=1;i<=n;i++)
else if(g0==0) {
}
{ {
printf("mathematical error");
integration=integration+4*f(k);
y=y+h*f(x,y);
} exit(0); x=x+h;
} }
integration=x1=x0-(f0/g0);
h/3*integration; }
x0=x1; value of integration
printf("\n Required
i++;
is: %0.6f",integration);
printf(" \n The required value is:
least square the inverse of matrix Determinant
coefficient of correlation #include<stdio.h> #include<stdio.h> #include<stdio.h>
#include<stdio.h> int main() #include<math.h> #include<math.h>
#include<math.h> { void main() void main()
int main() float { {
{ x[40],y[40],sumx=0,sumx2=0,sumy=0 int a[3][3],i,j; int a[3][3],i,j;
float xx[9], xy[9], yy[9], ,sumyx=0,a,b; float determinant=0; float determinant=0;
nr=0,dr1=0,dr=0,dr2=0,dr3=0,r=0; int i,n; printf("Enter the element of the matrix:"); printf("Enter the element of the
float x[9]={1,2,3,4,5,6,7,8,9}, printf("Enter the number of data,n: for(i=0;i<3;i++) matrix:");
y[9]={9,8,7,6,5,4,3,2,1}; "); { for(i=0;i<3;i++)
float sumx=0,sumy=0, sumyy=0,sumxx=0,sumxy=0; scanf("%d",&n); for(j=0;j<3;j++) {
int i,n=9; printf("Enter the values :\n"); scanf("%d",&a[i][j]); for(j=0;j<3;j++)
for(i=0;i<n;i++) for(i=0;i<n;i++) } scanf("%d",&a[i][j]);
{ { printf("The given matrix is:\n"); }
xx[i]=x[i]*x[i]; printf("Enter value of x%d and y%d: for(i=0;i<3;i++) printf("The given matrix is:\n");
xy[i]=x[i]*y[i]; ",i,i); { for(i=0;i<3;i++)
yy[i]=y[i]*y[i]; scanf("%f%f",&x[i],&y[i]); for(j=0;j<3;j++) {
} } { for(j=0;j<3;j++)
for(i=0;i<n;i++) for(i=0;i<n;i++) printf("%d\t",a[i][j]); {
{ }
sumx+=x[i]; { printf("\n");
printf("%d\t",a[i][j]);
}
sumxx+=xx[i]; sumx=sumx+x[i]; } printf("\n");
sumy+=y[i]; sumx2=sumx2+x[i]*x[i]; /*Foundimg Determinat*/ }
sumyy+=yy[i]; sumy=sumy+y[i]; for(i=0;i<3;i++) /*Foundimg Determinat*/
sumxy+=xy[i]; sumyx=sumyx+y[i]*x[i]; determinant=determinant+(a[0][i]*(a[1][(i+1)%3] for(i=0;i<3;i++)
} } *a[2][(i+2)%3]-a[1][(i+2)%3]*a[2][(i+1)%3])); determinant=determinant+(a[0][i]*(a[
nr=(n*sumxy)-(sumx*sumy); b=(sumx2*sumy-
float sumx2=sumx*sumx; sumyx*sumx)/(n*sumx2- printf("\n 1][(i+1)%3]*a[2][(i+2)%3]-
a[1][(i+2)%3]*a[2][(i+1)%3]));
float sumy2=sumy*sumy; sumx*sumx); Determinant:%f\n",determinant); printf("\n
dr1= (n*sumxx)-sumx2; a=(n*sumyx-sumx*sumy)/(n*sumx2- /*Found Inverse*/ Determinant:%f\n",determinant);
dr2= (n*sumyy)-sumy2; sumx*sumx); printf("\n Inverse of matrix is:\n"); }
dr3= dr1*dr2; printf("\n The required equation of for(i=0;i<3;i++)
dr=sqrt(dr3); the straight line is y = %fx + %f",a,b); {
r= (nr/dr); return 0; for(j=0;j<3;j++)
printf("\nTotal number of data:%d",n); } printf("%f\t",(a[(j+1)%3][(i+1)%3]*a[(j+2)%3][(i+2)
printf("\n sumx=%f",sumx); %3]-
printf("\n sumxx=%f",sumxx); (a[(j+1)%3][(i+2)%3]*a[(j+2)%3][(i+1)%3]))/deter
minant);
printf("\n sumy=%f ",sumy); printf("\n");
printf("\n sumyy=%f",sumyy); Multiply the matrices
}
printf("\n nr=%f",nr); #include<stdio.h>
}
printf("\n dr=%f",dr); #include<math.h>
printf("\n The correlation coefficient:%0.4f",r); void main()
return 0; {
Newton backward interpolation: int a[10][10],b[10][10],c[10][10];
} transpose of matrix
#include<stdio.h> int i,j,k,r1,r2,c1,c2;
int main() #include<stdio.h>
printf("enter the row and column of
{ #include<math.h>
matrix A:");
float x[20], y[20][20],sum,p,h,a,u; void main()
scanf("%d%d",&r1,&c1);
int i,j, n; {
printf("Enter the element of A: ");
standard deviation printf("Enter number of data?\n"); int a[10][10],b[10][10];
for(i=0;i<r1;i++)
#include<stdio.h> scanf("%d", &n); int i,j,r,c;
{
#include<math.h> printf("Enter data:\n"); printf("Enter the number of row and
for(j=0;j<c1;j++)
int main() for(i = 0; i < n ; i++) column:");
scanf("%d",&a[i][j]);
{ { scanf("%d%d",&r,&c);
}
float xxf[6],dr1=0,dr=0,xf[6]; printf("x[%d]=", i); printf("Enter the element of matrix A:");
printf("enter row and column of matrix
float x[6]= {1,2,3,4,5,6}, f[6]={4,3,2,5,6,5}, sumf=0; scanf("%f", &x[i]); for(i=0;i<r;i++)
B:");
float sumx2f=0, sumxf=0; printf("y[%d]=", i); {
scanf("%d%d",&r2,&c2);
int i,n=6; scanf("%f", &y[i][0]); for(j=0;j<c;j++)
printf("Enter the element of B:");
for(i=0;i<n;i++) } scanf("%d",&a[i][j]);
for(i=0;i<r2;i++)
{ printf("entre the value of x : "); {
xxf[i]=x[i]*x[i]*f[i]; scanf("%f",&a); }
for(j=0;j<c2;j++)
xf[i]=x[i]*f[i]; for(i = 1; i < n; i++) printf("The matrix is A=\n");
scanf("%d",&b[i][j]);
} { for(i=0;i<r;i++)
}
for(i=0;i<n;i++) for(j = n-1; j > i-1; j--) {
if(c1==r2)
{ { for(j=0;j<c;j++)
{
sumxf+=xf[i]; y[j][i] = y[j][i-1] - y[j-1][i-1]; printf("\t%d",a[i][j]);
for(i=0;i<r1;i++)
sumf+=f[i]; } printf("\n");
{
} } }
for(j=0;j<c2;j++)
for(i=0;i<n;i++) printf("\n The backward difference table is \n\n"); for(i=0;i<r;i++)
{
{ for(i = 0; i < n; i++) {
c[i][j]=0;
{ for(j=0;j<c;j++)
for(k=0;k<c1;k++)
sumx2f+=xxf[i]; printf("%0.2f", x[i]); b[j][i]=a[i][j];
c[i][j]+=a[i][k]*b[k][j];
} {
for(j = 0; j <= i ; j++)
} }
float sumx2=sumxf*sumxf; }
printf("\t%0.2f", y[i][j]); printf("The product of two metrices
printf("\n x\tf\t x*f\t x*x*f\n"); } printf("The tranpose of A=\n");
for(i=0;i<n;i++) for(i=0;i<c;i++) is:\n");
printf("\n"); for(i=0;i<r1;i++)
{ } {
printf("%f\t%f\t%f\t%f",x[i],f[i],xf[i],xxf[i]); for(j=0;j<r;j++) {
p=1.0; for(j=0;j<c2;j++)
printf("\n"); sum=y[n-1][0]; printf("\t%d",b[i][j]);
} printf("\n"); printf("\t%d",c[i][j]);
h=x[1]-x[0]; printf("\n");
printf("sumxf=%f",sumxf); u=(a-x[n-1])/h; }
printf("\nsumx2f=%f",sumx2f); } }
for(j=1;j<n;j++) }
printf("\n sumx2=%f",sumx2); {
printf("\n sumf=%f",sumf); else
p=p*(u+j-1)/j; {
dr1= sumx2f/sumf - sumx2/(sumf*sumf); sum=sum+p*y[n-1][j];
printf("\n dr1=%f",dr1); printf("Product does not exist");
} }
dr=sqrt(dr1); printf("The value of y at %f is %f",a,sum);
printf("\n Standard Deviation=%f",dr); }
}
return 0;
}
Wedlle’s rule.
#include<stdio.h>
the subtract of matrix find Mean , median , mode
#include<math.h>
#include<stdio.h> #include<stdio.h>
float f(float x)
#include<math.h> int main()
{
void main() {
return ((x*x)*(1-x));
{ int invalue[]={2,4,5,9,6,8};
}
float a[10][10],b[10][10],c[10][10]; int num_value=6;
void main()
int i,j,m,n; float tot=0;
the subtract
printf("Enter the number of row and coloumn:");
{
float a,b,h,s1=0,s2=0,s=0;
float mean=0;
scanf("%d%d",&m,&n); for(int i=0;i<num_value;i++)
int i,n,m;
printf("enter the element the of matrix A:"); {
printf("Enter the value of lower limit= ");
for(i=0;i<m;i++) tot=tot+invalue[i];
scanf("%f",&a);
{ }
printf("Enter the value of upper limit= ");
for(j=0;j<n;j++) mean=tot/num_value;
scanf("%f",&b);
scanf("%f",&a[i][j]); printf("The value of the mean is:%.2f", mean);
printf("Enter the value of n=");
} //Median Calculation
scanf("%d",&n);
printf("Enter the element of matrix B:"); float median=0;
h=(b-a)/n;
for(i=0;i<m;i++) float mid=0;
printf("h= %f",h);
{ if(num_value%2==0)
m=n/6;
for(j=0;j<n;j++) {
s=0;
int temp=(num_value/2)-1;
if(n%6==0)
scanf("%f",&b[i][j]); for(int i=0;i<num_value;i++)
{
{
for(i=1;i<=m;i++)
} if(temp==i|| (temp+1)==i)
{
for(i=0;i<m;i++) {
s=s+((3*h/10)*(f(a)+f(a+2*h)+5*f(a+h)+6*f(a+3*h)+f(a+4*h)+5*f(a+5
mid=mid+invalue[i];
*h)+f(a+6*h)));
for(i=0;i<m;i++) }
a=a+6*h;
{ }
}
for(j=0;j<n;j++) mid=mid/2;
printf("\nResult is : %0.9f",s);
c[i][j]=a[i][j]-b[i][j]; printf("\n");
}
} printf("Median value is:%.1f", mid);
else
printf("The sum of matrix A and B is:\n" ); }
{
for(i=0;i<m;i++) else
printf(" Weddle’s rule is not applicable");
{ {
}
for(j=0;j<n;j++) int temp=(num_value/2);
}
for(int i=0;i<num_value;i++)
printf("\t%f",c[i][j]);
{
printf("\n"); if(temp==i)
} {
} int mid=invalue[i];
printf("Median value is:%d", mid);
} } }
// Mode calculation
int i,j,z, tmp,maxCount, modeValue;
int tally[num_value];
Runge Kutta 4th order for(i=0;i<num_value;i++)
the rank of 2*2 matrix #include<stdio.h> {
#include <stdio.h> #include<math.h> for(j=0;j<num_value-i;j++)
int main() float f(float x,float y) {
{ { if (invalue[j]>invalue [j+1])
int a[2][2], i, j, det; return((x*x)+(y*y)); {
printf("Enter the elements of the 2*2 matrix:\n"); } tmp=invalue[j];
for (i=0;i<2;i++) int main() invalue[j]=invalue [j+1];
{ { invalue [j+1]=tmp;
for (j=0;j<2;j++) float x0,y0,h,x,y,k1,k2,k3,k4; }}}
scanf("%d",&a[i][j]); int i,n; for(i=0;i<num_value;i++)
} printf("\n Enter the value of x0,y0,h,x"); {
det= (a[0][0]* a[1][1] − a [1][0]* a[0][1]) ; scanf("%f%f%f%f",&x0,&y0,&h,&x); for(z=i+1;z<num_value;z++)
if (det!=0) n=(x-x0)/h; {
{ x=x0; if(invalue[i]=invalue[z])
printf("Rank of the input matrix is 2"); y=y0; {
} for(i=1;i<=n;i++) tally[i]++;
else { }}}
{ k1=h*f(x,y); maxCount=0;
printf("Rank of the input matrix is 1"); k2=h*f(x+h/2,y+k1/2); modeValue=0;
} k3=h*f(x+h/2,y+k2/2); for(i=1;i<=num_value;i++)
return 0; k4=h*f(x+h/2,y+k3);
} y=y+(k1+2*k2+2*k3+k4)/6; {
x=x+h; if(tally[i]>maxCount)
} {
printf("\n the required value is=%f",y); maxCount=tally[i];
return 0; modeValue=invalue[i];
} }
printf("\n Mode valu is: %d", modeValue);
return 0;
}

You might also like