0% found this document useful (0 votes)
10 views9 pages

Msit - PNG : Applied Mathematic S - Iv

any

Uploaded by

SMALL Towner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Msit - PNG : Applied Mathematic S - Iv

any

Uploaded by

SMALL Towner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 9

msit.

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.

The bisection is simple but convergence is very


slow. The interval within which the root lies is
bisected each time until we get the root with
desired accuracy.
page3image416.jpg ¬

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 :

WhatsApp Image 2021-04-11 at 4.09.05 PM.jpeg ¬

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.

Suppose you need to find the root of a


continuous, differentiable function f(x), and you
know the root you are looking for is near the
point x=x_0 . Then Newton's method tells us that
a better approximation for the root is
Screen Shot 2021-04-13 at 12.22.23 PM.png ¬
This process may be repeated as many times as
necessary to get the desired accuracy. In
general, for any x value x_n , the next value is
given by
Screen Shot 2021-04-13 at 12.22.45 PM.png ¬

Here is a picture to demonstrate what Newton's


method actually does:

Screen Shot 2021-04-13 at 10.50.15 AM.png ¬

We draw a tangent line to the graph of f(x) at the


point x=x_n . This line has slope f’(x_n) and goes
through the point (x_n , f(x_n) ) . Therefore it
has the equation y=f’(x_n)(x-x_n) + f(x_n) . Now ,
we find the root of this tangent line by setting y
= 0 and x=x_{n+1} for our new approximation .
Solving this equation gives us our new
approximation , which is x_{n+1} = x_n

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 :

Screen Shot 2021-04-13 at 12.57.09 PM.png ¬

Screen Shot 2021-04-13 at 1.06.15 PM.png ¬

You might also like