Posts

Showing posts from 2017

C PROGRAM FOR GAUSS JORDAN METHOD

// gauss jordan method #include<stdio.h> int main() { int i,j,k,n; float a[20][20],c,x[10],sum=0.0; printf("\nEnter the order of matrix: "); scanf("%d",&n); printf("\nEnter the elements of augmented matrix row-wise:\n\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]); } } for(j=1; j<=n; j++) { for(i=1; i<=n; i++) { if(i!=j) { c=a[i][j]/a[j][j]; for(k=1; k<=n+1; k++) { a[i][k]=a[i][k]-c*a[j][k]; } } } } x[n]=a[n][n+1]/a[n][n]; printf("Augmented matrix AB :\n"); for(i=1;i<=n;i++) { for(j=1;j<=(n+1);j++) { printf("%f\t",a[i][j]); } printf("\n"); } for(i=n-1; ...

TAYLOR'S SERIES FOR e^x sin(X) cos(X)

//Taylors series to find e^x,sin nx,cos x #include<stdio.h> #include<math.h> #define PI 3.1415 float expx(int ,int); double sinnx(int , int); double cosnx(int , int); int fact (int ); int main() { int x,n,i; do{ printf("Enter option\n1.e^x\n2.sin nx\n3.cos nx\n4.exit\n"); scanf("%d",&i); switch(i) { case 1 :printf("Enter x and number of terms\n"); scanf("%d%d",&x,&n); printf("e^%d in (%d) number of terms in taylor's series = %4.4f\n",x,n,expx(x,n)); break; case 2 :printf("Enter degree and number of terms\n"); scanf("%d%d",&x,&n); printf("sin(%d) in (%d) number of terms in taylor's series = %f\n",x,n,sinnx(x,n)); break; case 3 :printf("Enter degree and number of terms\n"); scanf("%d%d",&x,&n); printf("cos(%d) in (%d) number of terms in taylor...

C PROGRAM FOR GAUSS SEIDEL METHOD.

//Program to implement Gauss Seidel #include<stdio.h> #include<math.h> int main() { float a[20][20],x[20],e,big,temp,relerror,sum=0;//e=relative error int n,i,j,maxit,itr; printf("Enter the size of the equation\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the co-efficent of equation of %d and RHS\n",i); for(j=0;j<=n;j++) scanf("%f",&a[i][j]); } printf("Enter relative error and number of itereation:\n"); scanf("%f%d",&e,&maxit); for(i=0;i<n;i++) { printf("Enter initial approx value of x[%d]=\n",i); scanf("%f",&x[i]); x[i]=0; } for(itr=1;itr<=maxit;itr++) { printf("\n Iteration [%d]",itr); big=0; for(i=0;i<n;i++) { sum=0; for(j=0;j<n;j++) { if(i!=j) sum=sum+a[i][j]*x[j]; } temp=(a[i][n]-sum)/a[i][i]; printf("   x[%d]=%f",i,temp);...

GAUSS JACOBI'S METHOD.

//Program to implement Gauss Jacobi #include<stdio.h> #include<math.h> int main() { float a[20][20],xold[20],xnew[20],e,big,temp,relerror,sum=0;           // e = error   maxit=max no. of iterations int n,i,j,maxit,itr; printf("Enter the size of the equation\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the co-efficent of equation of %d and RHS\n",i); for(j=0;j<=n;j++) scanf("%f",&a[i][j]); } printf("Enter relative error and number of itereation:\n"); scanf("%f%d",&e,&maxit); for(i=0;i<n;i++) { printf("Enter initial approx value of x[%d]=\n",i); scanf("%f",&xold[i]); xnew[i]=0; } for(itr=1;itr<=maxit;itr++) { printf("\n Iteration [%d]",itr); big=0; for(i=0;i<n;i++) { sum=0; for(j=0;j<n;j++) { if(i!=j) sum=sum+a[i][j]*xold[j]; } temp=(a[i][n]-sum)...

EULER'S MODIFIED METHOD.

//progran to implement euler's modified method #include<stdio.h> #include<math.h> #define F(x,y) exp(x)+y //here change to desired function int main () { double x0,x1,y0,y1,y2,n,h; int i,j,k; printf("Enter x0,y0,h,xn values \n"); scanf("%lf%lf%lf%lf",&x0,&y0,&h,&n); x1=x0+h; for(j=1;x1<=n;j++) { i=0;k=0; y2=y0+(h*F(x1-h,y0)); printf("   y%d-0 = %.6lf \n ",j,y2); do{ k++; y1=y0+h/2*(F(x1-h,y0)+F(x1,y2)); printf("\nx=%.3lf => y%d-%d =%.6lf\n",x1,j,k,y1); if(fabs(y1-y2)<0.000001) { printf("\ny%d =%.5lf \n\n",j,y1); i=1; } else y2=y1; }while(i!=1); y0=y1; x1=x1+h; } return 0; }

EULER'S METHOD .

//program to implement euler's method to solve a differential equation #include<stdio.h> float fun (float x, float y) { return x+y; } int main () { float x,y,h,xn,k; printf("Enter x0,y0,h,xn \n"); scanf("%f%f%f%f",&x,&y,&h,&xn); printf("\nx\ty\n"); while(x<xn) { k=h*fun(x,y); y+=k; x+=h; printf("%.3f\t%.3f\n",x,y); } }

RUNGE-KUTTA 2nd ORDER METHOD.

//program to implement runge kutta method of 4th order #include<stdio.h> #include<math.h> double F (double x,double y) {   return (x+y)/x; } int main () { double x0,y0,y1,n,h,f,k1,k2,k3,k4; printf("Enter x0,y0,h,xn values \n"); scanf("%lf%lf%lf%lf",&x0,&y0,&h,&n); for(;x0<n;x0+=h) { f=F(x0,y0); k1=h*f; f=F(x0+h,y0+k1); k2=h*f; y1=y0+(k1+k2)/2; printf("\nk1=%.5lf\nk2=%.5lf\n",k1,k2); printf("y(%.5lf) = %.3lf",x0+h,y1); y0=y1; } }

RUNGE-KUTTA 4th ORDER METHOD.

//program to implement runge kutta method of 4th order #include<stdio.h> #include<math.h> double F (double x,double y) {   return x+y*y;//change this function to given question } int main () { double x0,y0,y1,n,h,f,k1,k2,k3,k4; printf("Enter x0,y0,h,xn values \n"); scanf("%lf%lf%lf%lf",&x0,&y0,&h,&n); for(;x0<n;x0+=h) { f=F(x0,y0); k1=h*f; f=F(x0+h/2,y0+k1/2); k2=h*f; f=F(x0+h/2,y0+k2/2); k3=h*f; f=F(x0+h,y0+k3); k4=h*f; y1=y0+(k1+k2*2+2*k3+k4)/6; printf("\nk1=%.5lf\nk2=%.5lf\nk3=%.5lf\nk4=%.5lf\n",k1,k2,k3,k4); printf("y(%.5lf) = %.3lf",x0+h,y1); y0=y1; } }

C PROGRAM TO IMPLEMENT GAUSS SEIDEL METHOD

//Program to implement Gauss Seidel method #include<stdio.h> #include<math.h> #include<conio.h> #include<stdlib.h> int main() { float a[20][20],x[20],e,big,temp,relerror,sum=0; //e=relative error int n,i,j,maxit,itr; printf("Enter the size of the equation\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the coefficent of equation of %d and RHS\n",i); for(j=0;j<=n;j++) scanf("%f",&a[i][j]); } printf("Enter relative error and number of iteration:\n"); scanf("%f%d",&e,&maxit); // GIVE e =0.001 or 0.0001 for more accuracy for(i=0;i<n;i++) { printf("Enter initial approx value of x[%d]=\n",i); scanf("%f",&x[i]); x[i]=0; } for(itr=1;itr<=maxit;itr++) { printf("\n Iteration [%d]",itr); big=0; for(i=0;i<n;i++) { sum=0; for(j=0;j<n;j++) { if(i!=j) sum=sum+a[i][j]*x[j]; } tem...

C PROGRAM TO IMPLEMENT GAUSS JACOBI METHOD

//Program to implement Gauss Jacobi #include<stdio.h> #include<math.h> #include<conio.h> #include<stdlib.h> int main() { float a[20][20],xold[20],xnew[20],e,big,temp,relerror,sum=0; // e for precision int n,i,j,maxit,itr; char ch; printf("Enter the size of the equation\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the co-efficent of equation of %d and RHS\n",i); for(j=0;j<=n;j++) scanf("%f",&a[i][j]); } printf("Enter relative error and number of itereation:\n"); scanf("%f%d",&e,&maxit); // GIVE e =0.001 or 0.0001 for more accuracy for(i=0;i<n;i++) { printf("Enter initial approx value of x[%d]=\n",i); scanf("%f",&xold[i]); xnew[i]=0; } for(itr=1;itr<=maxit;itr++) { printf("\n Iteration [%d]",itr); big=0; for(i=0;i<n;i++) { sum=0; for(j=0;j<n;j++) { if(i!...

TRIANGLE EFFECT MUSIC .

Image
If u want this track comment down ill provide you within a day or 2.

TRAPEZOIDAL RULE IN C

//program to evaluate definite integral using trapizoidal rule #include<stdio.h> #include<math.h> float fx (float x); int main() {  int i,n;  float x[10],y[10],h,sum=0.0,l,u;//l=lower limit u=upperlimt  printf("Enter the number of sub-intervals :\n");  scanf("%d",&n);  printf("Enter the lower limit amd upper limit :\n");  scanf("%f%f",&l,&u); h=(u-l)/n;  for(i=0;i<=n;i++)  {     x[i]=i*h;     printf("x[%d]=%f\t",i,x[i]);      y[i]=fx(x[i]);    printf("y[%d]=%f\n",i,y[i]);  } sum=y[0]+y[n];  for(i=1;i<n;i++)        sum+=2*y[i]; sum=(h/2)*sum; printf("Intergral value is : %f \n",sum); return 0; }  float fx (float x) {  float f;  f=exp(x);           //by changing this statement we can change the function as we require return f; }        

NEWTONS BACKWARD DIFFERENCE INTERPOLATION IN C

//PROGRAM TO FIND NEWTONS BACKWARD DIFFERENCE INTERPOLATION #include<stdio.h> #include<stdlib.h> #define MAX 15 int factorial (int value); int main () { int n,i,j,m; float x[MAX],y[MAX],differ[MAX][MAX],p,xvalue,yvalue,hvalue,product,sum; puts("Number of entries of x :\n"); scanf("%d",&n); for (i=0;i<n;i++) { puts("Enter the value of x and corresponding value of y :\n"); scanf("%f%f",&x[i],&y[i]); } puts("Enter the value of x you want to find :\n"); scanf("%f",&xvalue); if (xvalue<x[0]||xvalue>x[n-1]) { puts("Value lies outside the given values of x ."); return 0; } else { printf("\n\nNEWTON'S BACKWARD DIFFERENCE INTERPOLATION"); for(j=0;j<n-1;j++) { for(i=j+1;i<n;i++) { if(j==0) differ[i][j]=y[i]-y[i-1]; else differ[i][j]=differ[i][j-1]-di...

NEWTONS FORWARD DIFFERENCE INTERPOLATION IN C

//PROGRAM TO FIND NEWTONS FORWARD DIFFERENCE INTERPOLATION #include<stdio.h> #include<stdlib.h> #define MAX 15 int factorial (int temp); int main () { int n,i,j,k=0; float x[MAX],y[MAX],differ[MAX][MAX],p,xvalue,yvalue,m,h,product,sum; //m= factorial from function puts("Number of entries of x :\n"); scanf("%d",&n); for (i=0;i<n;i++) { puts("Enter the value of x and corresponding value of y :\n"); scanf("%f%f",&x[i],&y[i]); } puts("Enter the value of x you want to find :\n"); scanf("%f",&xvalue); if (xvalue<x[0]||xvalue>x[n-1]) { puts("Value lies outside the given values of x ."); return 0; } else { printf("\n\nNEWTON'S FORWARD DIFFERENCE INTERPOLATION"); for(j=0;j<n-1;j++) { for(i=0;i<n-(j+1);i++) { if(j==0) differ[i][j]=y[i+1]-y[i]; else differ[i][j]...

SIMPSON'S 3/8 RULE IN C

//PROGRAM TO USE SIMPSON'S 3/8 RULE TO FIND F(X)=e^x^2 #include<stdio.h> #include<math.h> float fun(float); int main() {   int i,n;   float x[10],y[10],h,sum,l,u;//l = lower limit,u=upperlimit   printf("Enter number of intervals :\n");   scanf("%d",&n);   if(i%3==0)   {      printf("Enter the lower limit and upper limit :\n");      scanf("%f%f",&l,&u);       h=(u-l)/n;      for(i=0;i<=n;i++)       {            x[i]=(i*h)+l;           printf("x[%d]=%f\t",i,x[i]);             y[i]=fun(x[i]);           printf("y[%d]=%f\t",i,y[i]);        }     sum=y[0]+y[n];    for(i=1;i<n;i++)    {       if(i%3==0)         sum+=2*y[i];   ...

SIMPSON'S 1/3 RULE IN C

//PROGRAM TO USE SIMPSON'S 1/3 RULE TO FIND F(X)=e^x^2 #include<stdio.h> #include<math.h> float fun(float); int main() {   int i,n;   float x[10],y[10],h,sum,s1,s2,l,u;//l = lower limit,u=upperlimit   printf("Enter number of intervals :\n");   scanf("%d",&n);   if(i%2==0)   {      printf("Enter the lower limit and upper limit :\n");      scanf("%f%f",&l,&u);       h=(u-l)/n;      for(i=0;i<=n;i++)       {            x[i]=(i*h)+l;           printf("x[%d]=%f\t",i,x[i]);             y[i]=fun(x[i]);           printf("y[%d]=%f\t",i,y[i]);        }     sum=y[0]+y[n];    for(i=1;i<n;i++)    {       if(i%2==0)         s1+=y[i]; ...

LAGRANGE'S INTERPOLATION IN C

//program to implement lagranges interpolation. #include<stdio.h> int main() {  int i,j,n; printf("\n Enter the number of entries :\n); scanf("%d",&n); float x[n],y[n],nr,dr,xv,yv=0.0; printf("\n Enter the values of x and y :\n \n);   for(i=0;i<n;i++)     scanf("%f%f",&x[i],&y[i]); printf("\n Enter the the value of x to find y :\n); scanf("%f",&xv);   for(i=0;i<n;i++)  {    nr=1;    dr=1;     for(j=0;j<n;j++)     {        if(j!=i)        {  nr=nr*(xv-x[j]);           dr=dr*(x[i]-x[j]);         }     }     yv=yv+((nr/dr)*y[i]);  } printf("The value of y for x= %f is y= %f \n ",xv,yv); return 0; }

GAUSS'S INTERPOLATION

//program to implement  GAUSS'S INTERPOLATION #include<stdio.h> #define max 10 int main() {  float table[max][max],x, n, h, y, p;  int n, mid, i, j;   printf("\n How many values are to be entered? \n");  scanf("%d",&n);  printf("\n Enter the values of x and y in tabular format: \n\n");  for(i=0; i<=2*n-2; i+=2)    for(j=0; j<=1; j++)        scanf("%f",&table[i][j]) ;  printf("\n Find the value of y at x = ? \n");  scanf("%f",&x);   for(i=2; i<=n; i++)       for(j=i-1, n=1; n<=n+1-i; j+=2, n++)      {        table[j][i]=table[j+1][i-1] - table[j-1][i-1];      } /* Finding the middle of the x column of the table */  if(n%2==1)             mid=n-1;  else mid=n;  h=table[mid+2][0] - table[mid][0] ;  n=p=(x-table[mid][0])/h; ...