Msit - PNG : Applied Mathematic S - Iv
Msit - PNG : Applied Mathematic S - Iv
png ¬
APPLIED
MATHEMATIC
S -IV
NAME : Ria Mittal
ENROLLMENT NO : 20315003119
SEMESTER : 4th sem
BRANCH : IT -1
SERIAL NO. : 57
EXPERIMENT-1
AIM :
To find the roots of non-linear
equation using Bisection Method
THEORY:
Bisection method is an
iterative implementation of the ‘Intermediate
Value Theorem‘ to find the real roots of a
nonlinear function. According to the theorem “If a
function f(x)=0 is continuous in an interval (a,b),
such that f(a) and f(b) are of opposite nature or
opposite signs, then there exists at least one or
an odd number of roots between a and b.”
Assuming that f(a)>0 and f(b)<0 , then by
bisection method , let first approximation root is
x1= (a=b)/2. If f(x1)=0 , then x1 is a root of f(x)
= 0 . If f(x) =/ 0, then the root lies between a and
x1 or x1 and b depending on whether f(x1) > 0 or
f(x1) < 0 . Further bisect the interval in which the
root lies and continue the process until the root is
found to be of desired accuracy.
PROGRAM :
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define f(x) pow(x,3)-4*x-9
void
int main ()
{
float x0, x1, x2, f0, f1, f2, e;
int step = 1;
clrscr ();
up;
printf ("\nENTER TWO INITIAL GUESSES:\n");
scanf ("%f%f", &x0, &x1);
printf ("Enter tolerable error:\n");
scanf ("%f", &e);
f0 = f(x0);
f1 = f(x1);
if (f0 * f1 > 0.0)
{
printf ("Incorrect initial guesses.\n");
goto up;
}
printf ("\nStep\t\tx0\t\tx1\t\tx2\t\tf(x2)\n");
do
{
x2 = (x0 + x1) / 2;
f2 = f(x2);
printf (“%d\t\t%f\t%f\t%f\t%f\n”,step,x0,x1,x2,f2);
if (f0 * f2 < 0)
{
x1 = x2;
f1 = f2;
}
else
{
x0 = x2;
f0 = f2;
}
step = step + 1;
}
while (fabs (f2) > e);
printf ("\nROOT IS:%f", x2);
getch ();
return 0;
}
OUTPUT :
EXPERIMENT-2
AIM :
To find the roots of non-linear
equation using Newton Raphson Method
THEORY :
The Newton-Raphson
method is a way to quickly find a good
approximation for the root of a real-valued
function f(x) = 0. It uses the idea that a
continuous and differentiable function can be
approximated by a straight line tangent to it.
PROGRAM :
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define f(x) pow(x,3)-4*x-9
#define g(x) pow(x,2)-4
int main()
{
float x0,x1,f0,f1,g0,e;
int step=1,N;
printf("\nEnter the intial guess :\n");
scanf("%f",&x0);
printf("\nEnter tolerable error :\n");
scanf("%f",&e);
printf("\nEnter maximum iteration :\n");
scanf("%d",&N);
printf("\nStep\t\tx0\t\tf(x0)\t\tx1\t\tf(x1)\n");
do
{
g0=g(x0);
f0=f(f0);
if(g0==0.0)
{
printf("Mathematical Error.");
exit(0);
}
x1=x0-f0/g0;
printf("%d\t\t%f\t%f\t%f\t%f\n",step,x0,f0,x1,f1);
x0=x1;
step=step+1;
}
while(fabs(f1)>e);
printf("\nRoot is : %f",x1);
getch();
}
OUTPUT :