Professional Documents
Culture Documents
JMIT
List of Experiments
2.
Simpson rule.
Solution to a non linear equation in single variable
4.
5.
6.
Eulers method.
Solution to a non linear equation in single variable
8.
9.
10.
3.
7.
11.
Issued By:
Work Instructions
Approved By:
Date of Issue:
02.02.09
Aim of Experiment: - Numerical solution to an differential equation using the RangeKutta method.
#include<stdio.h>
float f(float x,float y);
{
return x+y*y;
}
main()
{
float x0,y0,h,xn,x,y,k1,k2,k3,k4,k;
printf("Enter the value of x0,y0,h,xn\n");
scanf("%f%f%f%f",&x0,&y0,&h,&xn);
x=x0;
y=y0;
while(1)
{
if (x==xn)
break;
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);
k=(k1+(k2+k3)*2+k4)/6;
x+=h;
y+=k;
printf("when x= %8.4f""y=%8.4f\n",x,y);
}
}
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Aim of Experiment: - Numerical solution to the integral equation using Simpson rule.
#include<stdio.h>
float y(float x)
{
return 1/(1+x*x);
}
float x0,h,s,xn;
int i,n;
printf("Enter the x0,xn,,no. of subintervals");
scanf("%f%f%d",&x0,&xn,&n);
h=(xn-x0)/n;
s=y(x0)+y(xn)+4*y(x0+h);
for(i=3; i<=n-2; i+=2)
s+=4*y(x0+i*h)+2+y(x0+(i-1)*h);
printf("value of integral is %6.4f\n"(h/3)*s);
}
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Aim of Experiment: - Solution to a non linear equation in single variable using the method of
Regular Falsi.
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(x*x*x - (4*x)-9);
}
void false (float *x,float a, float b, int *itr)
{
*x =((b-a)*f(a)/(f(a)-f(b)))+a ;
++(*itr);
printf("\n iteration number = %3d, value of x = %7.5f",*itr,*x);
}
main()
{
int itr = 0,mitr;
float a,b,x,y,merr;
printf("enter the value of a,b""allowed error,maximum iterations \n");
scanf("%f%f%f%d",&a,&b,&merr,&mitr);
if (f(a)*f(b)>0)
{
printf("root doesnot lie in a and b");
return(0);
}
false (&x,a,b,&itr);
do{
if(f(x)*f(a)<0)
b=x;
else
a=x;
false(&y,a,b,&itr);
if (fabs(y-x)<merr)
{
printf("\nafter %d iterations,root=%f \n",itr,y);
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
return(0);
}
x=y;
}
while(itr<mitr);
printf("solution does not converge\n");
printf("iterations not sufficient");
return (1);
}
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Aim of Experiment: - Solution to a non linear equation in single variable using the method of
successive Bisection.
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(x*x*x - (4*x)-9);
}
void bisect (float *x,float a, float b, int *itr)
{
*x = (a+b)/2;
++(*itr);
printf("\n iteration number = %3d, value of x = %7.5f",*itr,*x);
}
main()
{
int itr = 0,mitr;
float a,b,x,y,merr;
printf("enter the value of a,b""allowed error,maximum iterations \n");
scanf("%f%f%f%d",&a,&b,&merr,&mitr);
if (f(a)*f(b)>0)
{
printf("root doesnot lie in a and b");
return(0);
}
bisect (&x,a,b,&itr);
do
{
if(f(x)*f(a)<0)
b=x;
else
a=x;
bisect(&y,a,b,&itr);
if (fabs(y-x)<merr)
{
printf("\nafter %d iterations,root=%f \n",itr,y);
return(0);
}
x=y;
}while(itr<mitr);
printf("solution does not converge\n");
printf("iterations not sufficient");
return (1);
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Aim of Experiment: - Solution to a non linear equation in single variable using the method of
Newton raphons...
#include<stdio.h>
#include<math.h>
float f(float x)
{ return ((3*x)-cos(x)-1); }
float f1(float x)
{ return (3+sin(x));
}
main ()
{
float a,b,merr,h,x,y;
int itr,mitr;
clrscr();
printf("Enter the values of a,b,merr,x,mitr");
scanf("%f%f%f%f%d",&a,&b,&merr,&x,&mitr);
if(f(a)*f(b)>0)
{
printf("Root do not lie");
}
for(itr = 1;itr<=mitr;++itr)
{
h = f(x)/f1(x);
y=x-h;
printf("iteration = %3d,x= %7.5f",itr,x)l;
if(fabs (h) < merr)
{
printf("Root = %f",x); return(0);
}
x=y
}
printf("Root do not converge");
return(0);
}
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Approved By:
Date of Issue:
02.02.09
Work Instructions
t0=f(x[4],t);
if(fabs(t-y[4])<merr)
{
printf("value of y at%f,at x%f",t,x[4]);
break;
}
y[4]=t;
v[4]=t0;
}
}
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Aim of Experiment: - Solution to a non linear equation in single variable using the method of
Newton Raphons.
#include<stdio.h>
#include<math.h>
float f(float x)
{ return ((3*x)-cos(x)-1); }
float f1(float x)
{ return (3+sin(x));
}
main ()
{
float a,b,merr,h,x,y;
int itr,mitr;
clrscr();
printf("Enter the values of a,b,merr,x,mitr");
scanf("%f%f%f%f%d",&a,&b,&merr,&x,&mitr);
if(f(a)*f(b)>0)
{
printf("Root do not lie");
}
for(itr = 1;itr<=mitr;++itr)
{
h = f(x)/f1(x);
y=x-h;
printf("iteration = %3d,x= %7.5f",itr,x)l;
if(fabs (h) < merr)
{
printf("Root = %f",x); return(0);
}
x=y
}
printf("Root do not converge");
return(0);
}
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Issued By:
Approved By:
Date of Issue:
02.02.09
Work Instructions
Aim of Experiment: - Solution to a non linear equation in single variable using the Secant .
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(3*x-cos(x)-1);
}
main()
{
int itr, mitr;
float x0,x1, merr, err, h, t;
printf("enter the values of x0, x1, merr, mitr");
scanf("%f%f%f%d", &x0, &x1, &merr, &mitr);
for(itr=1; itr<mitr; ++itr)
{
h=f(x0)*((x1-x0)/(f(x1)-f(x0)));
err=fabs(h);
t=x0-h;
printf("\n value of x is %7.5f in %d iterations", t,itr);
if(err<=merr)
{
printf("\n %f is the root ",t);
return(0);
}
x0=x1;
x1=t;
}
printf("the solution is not convergent in given iterations");
return(1);
}
Issued By:
Approved By:
Date of Issue:
02.02.09