Technocrat

  • Home
Showing posts with label Numerical Methods. Show all posts
Showing posts with label Numerical Methods. Show all posts

Monday, September 8, 2014

Gauss-Jacobi Method using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Gauss-Jacobi Method


Equation:8x+2y-2z=0,x-8y+3y=-4,2x+y+9z=12
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float ax,ay,az,x,y,z;
int i,n;
float f1(float,float);
float f2(float,float);
float f3(float,float);
clrscr();
printf("\nEnter the number of equations:: ");
scanf("%d",&n);
x=y=z=0;
for(i=0;i<=n;i++)
{
ax=f1(y,z);
ay=f2(z,x);
az=f3(x,y);
x=ax;
y=ay;
z=az;
}
printf("\nx= %f, y= %f, z= %f",x,y,z);
getch();
}
float f1(float y,float z)
{
return (8-2*y+2*z)/8;
}
float f2(float z,float x)
{
return (4+x+3*z)/8;
}
float f3(float x,float y)
{
return (12-2*x-y)/9;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Gauss-Seidal Method using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Gauss-Seidal Method


Equation:8x+2y-2z=0,x-8y+3y=-4,2x+y+9z=12
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float ax,ay,az,x,y,z;
int i,n;
float f1(float,float);
float f2(float,float);
float f3(float,float);
clrscr();
printf("\nEnter the number of equations:: ");
scanf("%d",&n);
x=y=z=0;
for(i=0;i<=n;i++)
{
ax=f1(y,z);
ay=f2(z,ax);
az=f3(ax,ay);
x=ax;
y=ay;
z=az;
}
printf("\nx= %f, y= %f, z= %f",x,y,z);
getch();
}
float f1(float y,float z)
{
return (8-2*y+2*z)/8;
}
float f2(float z,float x)
{
return (4+x+3*z)/8;
}
float f3(float x,float y)
{
return (12-2*x-y)/9;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Newtons forward formula Using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Newtons forward formula


x: 1 1.10 1.20 1.30
y: .4158 .8912 .9320 .9636
Compute::f(1.02)=?
*/
#include<conio.h>
#include<stdio.h>
#define n 4
void main()
{
float x[n],y[n][n],xf,fx,u,h;
int j,i,index,f=1;
for(i=0;i<n;i++)
{
printf("\nEnter x[%d] & y[%d][0]",i+1,i+1);
scanf("%f%f",&x[i],&y[i][0]);
}
for(j=1;j<n;j++)
{
for(i=0;i<n;i++)
y[i][j]=y[i+1][j-1]-y[i][j-1];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
printf("%f\t",y[i][j]);
printf("\n");
}
printf("\nEnter x");
scanf("%f",&xf);
for(i=0;i<n-1;i++)
{
if(xf>=x[i]&&xf<=x[i+1])
{
index=i;
break;
}
}
h=x[1]-x[0];
u=(xf-x[index])/h;
fx=y[index][0];
for(i=1;i<n;i++)
{
if(i!=1)
u=u*(u+1-i);
f=f*i;
fx=fx+(u*y[index][i])/f;
}

printf("\nResult %f",fx);
getch();
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Newtons backward formula using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Newtons backward formula


x: 1 1.10 1.20 1.30
y: .4158 .8912 .9320 .9636
Compute::f(1.40)=?
*/
#include<conio.h>
#include<stdio.h>
#define n 4
void main()
{
float x[n],y[n][n],xf,fx,u,h;
int j,i,index,f=1;
for(i=0;i<n;i++)
{
printf("\nEnter x[%d] & y[%d][0]",i+1,i+1);
scanf("%f%f",&x[i],&y[i][0]);
}
for(j=1;j<n;j++)
{
for(i=0;i<n;i++)
y[i][j]=y[i+1][j-1]-y[i][j-1];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
printf("%f\t",y[i][j]);
printf("\n");
}
printf("\nEnter x");
scanf("%f",&xf);
index=n-1;
h=x[1]-x[0];
u=(xf-x[index])/h;
fx=y[index][0];
for(i=1;i<n;i++)
{
if(i!=1)
u=u*(u+i-1);
f=f*i;
fx=fx+(u*y[index][i])/f;
}

printf("\nResult %f",fx);
getch();
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Lagranges formula using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Lagranges formula


x: 30 35 45 55
y: 148 196 68 34
Compute::f(40)=?
*/
#include<conio.h>
#include<stdio.h>
#define n 4
void main()
{
float f,x[n],y[n],xf,fx;
int j,i;
for(i=0;i<n;i++)
{
printf("\nEnter x[%d] & y[%d]",i+1,i+1);
scanf("%f%f",&x[i],&y[i]);
}
printf("\nEnter x");
scanf("%f",&xf);
fx=0;
for(i=0;i<n;i++)
{
f=1;
for(j=0;j<n;j++)
{
if(i!=j)
f=f*((xf-x[j])/(x[i]-x[j]));
}
fx=fx+(f*y[i]);
}
printf("\nResult %f",fx);
getch();
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Runga-Kutta Method using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Runga-Kutta Method


COmpute:: f(0.2)=?
When f(x,y)=x+y^2; y(0)=1 h=0.1
*/
#include<conio.h>
#include<stdio.h>

void main()
{
float x,y,h,xf,k1,k2,k3,k4,n;
int i;
float f(float,float);
printf("\nEnter x0 & y0");
scanf("%f%f",&x,&y);
printf("\nEnter x & h");
scanf("%f%f",&xf,&h);
n=(xf-x)/h;
for(i=0;i<=(int)n;i++)
{
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,y+k2/2);
k4=h*f(x+h,y+k3);
y=y+(k1+2*(k2+k3)+k4)/6;
x=x+h;
}
printf("\nResult %f",y);
getch();
}
float f(float x,float y)
{
return x+y*y;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

C Program to solve using Euler Rule

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak





/*
Euler Rule
Compute:: f(0.1)=?
When f(x,y)=1+xy, y(0)=2,h=0.01
*/
#include<conio.h>
#include<stdio.h>

void main()
{
float x0,y0,h,xf,fx,x;
float f(float,float);
printf("\nEnter x0 & y0");
scanf("%f%f",&x0,&y0);
printf("\nEnter x & h");
scanf("%f%f",&x,&h);
xf=x0;fx=y0;
while(xf<=x)
{
fx=fx+h*f(xf,fx);
xf=xf+h;
}
printf("\nResult %f",fx);
getch();
}

float f(float x,float y)
{
return 1+x*y;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

C Program to implement Simpson's 1/3 rd Rule

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   








Sumit Kar, Numerical Methods, C, Timus Rak




/*


Simpson's 1/3 Rule


Equation: x/(1+x) dx
lower limit=0 upper limit=1 number of interval=6
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,h,x,y,so=0;
float x0,y0,yn,xn,r,se=0;;
int i,n;
float f(float);
clrscr();
printf("\nEnter lower limit value:: ");
scanf("%f",&a);
printf("\nEnter upper limit value:: ");
scanf("%f",&b);
printf("\nEnter the number of intervals:: ");
scanf("%d",&n);
h=(b-a)/n;
x0=a;
y0=f(x0);
yn=f(b);
x=x0+h;
for(i=1;i<=n-1;i=i+2)
{
y=f(x);
so=so+y;
x=x+2*h;
}
x=x0+2*h;
for(i=2;i<=n-2;i=i+2)
{
y=f(x);
se=se+y;
x=x+2*h;
}
r=(h/3)*(y0+yn+4*so+2*se);
printf("\nResult is:: %f",r);
getch();
}
float f(float x)
{
return x/(1+x);
}



Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

C Program to implement Trapezoidal Rule

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*
Trapezoidal Rule
Equation: x/(1+x) dx
lower limit=0 upper limit=1 number of interval=6
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,h,x,y,s=0;
float x0,y0,xn,yn,r;
int i,n;
float f(float);
clrscr();
printf("\nEnter lower limit value:: ");
scanf("%f",&a);
printf("\nEnter upper limit value:: ");
scanf("%f",&b);
printf("\nEnter the number of intervals:: ");
scanf("%d",&n);
h=(b-a)/n;
x0=a;
y0=f(a);
yn=f(b);
x=x0+h;
for(i=1;i<=n-1;i++)
{
y=f(x);
s=s+y;
x=x+h;
}
r=(h/2)*(y0+yn+2*s);
printf("\nResult is:: %f",r);
getch();
}
float f(float x)
{
return x/(1+x);
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Implement Secant Method using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Sumit Kar, Numerical Methods, C, Timus Rak



/*


Secant Method



Equation: x^3-4x-9=0


*/
#include<conio.h>
#include<stdio.h>
void main()
{
float a,b,k,c;
int i;
float f(float);
clrscr();
printf("\nEnter first initial value:: ");
scanf("%f",&a);
printf("\nEnter second initial value:: ");
scanf("%f",&b);
for(i=1;i<=5;i++)
{
c=b-((b-a)*(f(b)/(f(b)-f(a))));
a=b;
b=c;
}
printf("\nRoot is:: %f",c);
getch();
}
float f(float x)
{
return (x*x*x)-(4*x)-9;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Method of Regula-Falsi using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   








Sumit Kar, Numerical Methods, C, Timus Rak


/*


Method of Regula-Falsi



Equation: x^3-4x-9=0


*/
#include<conio.h>
#include<stdio.h>

void main()
{
float a,b,k,c;
int i;
float f(float);
clrscr();
printf("\nEnter first initial value:: ");
scanf("%f",&a);
printf("\nEnter second initial value:: ");
scanf("%f",&b);
for(i=1;i<=5;i++)
{
c=b-((b-a)*(f(b)/(f(b)-f(a))));
k=f(c);
if(k>0)
b=c;
if(k<=0)
a=c;
}
printf("\nRoot is:: %f",c);
getch();
}
float f(float x)
{
return (x*x*x)-(4*x)-9;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Implement Newton-Raphson Method using C

 Sumit Kar     September 08, 2014     C - Programming, Numerical Methods     No comments   



Implement Newton-Raphson Method using C,Sumit Kar, Numerical Methods, C, Timus Rak




/*


Method of Newton-Raphson



Equation: x^3-4x-9=0


*/

#include<stdio.h>

void main()
{
float a,h;
int i;
float f(float);
float f1(float);
printf("\nEnter initial value:: ");
scanf("%f",&a);
for(i=1;i<=5;i++)
{
h=-f(a)/f1(a);
a=a+h;
}
printf("\nRoot is:: %f",a);
}
float f(float x)
{
return (x*x*x)-(4*x)-9;
}
float f1(float x)
{
return (3*x*x)-4;
}


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp
Older Posts Home

Pages

  • Home

Trending Now

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Blog Archive

  • ▼  2020 (1)
    • ▼  May (1)
      • Automating your deployments using Ansible
  • ►  2015 (92)
    • ►  October (4)
    • ►  September (3)
    • ►  August (3)
    • ►  July (9)
    • ►  June (9)
    • ►  May (20)
    • ►  April (7)
    • ►  March (22)
    • ►  February (7)
    • ►  January (8)
  • ►  2014 (158)
    • ►  November (70)
    • ►  October (6)
    • ►  September (82)
Powered by Blogger.

Categories

C - Programming Java Programming Basic Technology 8085 Assembly Programming For Loop Numerical Methods WhatsApp Algorithm Shell Programming Programming Networking Windows Android C++ Programming CPP If Else Tricky Internet Microsoft Pattern Photography Socket Program News While Loop Array DBMS DS Macro Recursion User Defined Function Conditional Operator Data Structure Durga Puja Earthquake Google Mela Nokia SQL Share Yahoo Airtel Bio Command Prompt Confused Facebook Finance Firefox Ganges Graph HokKolorob Input Kolkata MCQ Math Matrix NetNeutrality Oracle Religion Search Sumit Kar Survey Switch Case Viral Virus Visual Studio do-while featured featured_slider

Popular Programs

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Daily Hits

Copyright © Sumit Kar