Adobe Scan 20-Feb-2024
Adobe Scan 20-Feb-2024
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define FUN(X) 3*x-cos(x)-1 /" Given equation "/
#define DFUN(x) 3+sin(x) /* First derivative of the given equation *1
void main()
int i,n;
float x0,x1,x2;
double e;
clrscr():
printf("\n ***
Newton-Raphson Method ****);
printf("nGive the starting value for iteration (x0):");
scanf("%f", &x0);
printf("n Value of the root to how many significant decimal places? i.e. n=");
scanf("%d", &n);
i=0;
e= 1/(pow(10,n));
printf("ne value = %If", e);
begin:
x1=x0-(FUN(X0))/(DFUN(X0));:
printf("n Iteration No. i=%d:The value of approximate root (x0)=%f", i,x0);
if (fabs((x1-x0)/x1) >= e)
x0 = x1;
i=i+1;
gotobegin;
printf("n The real positive root of the given equation = %f", x1):
x2=x0-(FUN(X0)W(DFUN(X0);
if (x2-x1 ==0.0)
printf("n The root Converged.");
else
printf("n The root does not converge. Try with different e value."):
getch():
*Cprogram: Trapezoidal rule */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(X) 1/(1+pow(X,2))
void main()
int n,i;
float a,b,SUM,trap,h,X;
clrscr();
printf(" ****TRAPEZOIDAL RULE*****\n");
printf("\n Enter the values of a, b, n:");
scanf("%f %f %d", &a, &b, &n);
h=(b-a)/n;
SUM=0.0;
for(i=1;i<=n-1;i++)
X=(a+ih):
SUM=SUM+F(X);:
trap=h/(2.0)"(F(a)+ F(b)+2.0 * SUM);
printf("n Value of the given integral= %f", trap);
getch():
Cprogram: Simpson's (1/3) rule *I
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define F(x) 1/(1+ pow(x, 2))
float a, b, h, sum, os, es, val, x;
void main()
int n, i:
clrscr():
printf("Simpson's (1/3) Rule"):
printf("n Give lower limit of the integral (a)=");
scanf("%f",&a);
printf("\n Give upper limit of the integral(b)=");
scanf("%f",&b);
printf("n Give number of intervals (n) [should be even number]=");
scanf("%d", &n);
h=(b-a)/n;
Sum=es=os=0.0;
Sum=F(a)+F(b);
for(i=1;i<=n-1;i=i+2)
Os=os+F(a+i*h);
for(i=2;i<=n-2;i=i+2)
es=es+F(a+i*h);
val=(h/3.0) (sum+(4*os) +(2*es)):
printf("n The value of the integral between linmits %f and %f \n", a, b);
printf("n with class interval (h)=%f is equal to %fn", h, val);
getch():
}
* C-Program for Linear Curve Fitting LEAST SQUARES METHOD */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
int n,i;
float a,b,x[20],y[20],sumx=0,sumy=0,sumxy=0,sumx2=0;
clrscr();
printf("\n CprOgram for Linear Curve Fitting of the form Y = a + bX \n ");
printf("\n Enter the value of number of data terms n:");
Scanf("%d",&n):
printf("\n Enter the values of x:"):
for(i=0;i<=n-1;i++)
scanf(" %f",8x[i]);
printf("\n Enter the values of y:");
for(i=0;i<=n-1;i++)
Scanf("%f",&y[i));
}
for(i=0;i<=n-1;i++)
Sumx=Sumx +x[0;
Sumx2=sumx2 +X[[]*x[];
Sumy=sumy +y[0;
sumxy=sumxy +x[i]*y[i];
}
a=((sumx2*sumy -sumx*sumxy)*1.0/(n*sumx2-sumx*sumx)*1.0):
b=((n"sumxy-sumx*sumy)* 1.0/(n*sumX2-sumx*sumx)*1.0);
printf("\n\nThe line is Y=%3.3f +%3.3f X",a,b);
getch ();
* Runge Kutta Method - Fourth order formula
*|
#include<stdio.h>
#include<math.h>
float dydx(float x, float y);
void main()
kl = h*dydx(x, y);
k2 = h*dydx((x + 0.5*h), (y +
k3 = h*dydx((x + 0.5*h), (y + 0.5*k1));
k4 = h*dydx((x + h), (y + k3)); 0.5*k2)
);
k=((k1+2*k2+2*k3+k4)*1.0/6.0);
y=y+k;
X=X+h;
1/printf("kl=%f\tk2=%f\tk3=%f\tk4=%f\n",k1, k2, k3, k4);
printf("%of\t%f\n",x, y);
getch();
}
float dydx(float x, float y)
float k:
k=(x+y); /* input the R.H.S. of the differential equation */
return k;
*C-Program to interpolate the value of afunction from a set of values using
LAGRANGE'S INTERPOLATION METHOD */
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h
void main()
t=t+s*ylil:
printf("\n\nFor x=%f the interpolated value of y=%f"a,t);
getch):