Q4: Using Newton Bisection method, Compute the real root of
f ( x )=xlogx−1. R
In C-language, Where ‘R’ is the last digit of your University Roll
number.
Solution:
Code:
#include<stdio.h>
#include<math.h>
#define f(x) ((x) * log(x) – 1.3)
Int main()
Float x0, x1, x2, f0, f1, f2, e;
Int step = 1;
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);
While (f0 * f1 > 0.0) {
Printf(“Incorrect Initial Guesses. Please enter again:\n”);
Scanf(“%f%f”, &x0, &x1);
F0 = f(x0);
F1 = f(x1);
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\n”, x2);
Return 0;
OUTPUT: