if your ids last digit is 0 then implement Bisection numerical method to find the root of the given equation.
if your ids last digit is 1/2/3 or even then implement False position numerical method to find the given equation.
if your ids last digit is 4/5/6 or even then implement secant numerical method to find the given equation.
if your ids last digit is 7/8/9 or even then implement newton raphson numerical method to find the given equation.
given equation:x^3-(last digit of your id)x+(ASCIIvalue of your names first letter)
an example :if my id is 110104154 then the last digit is 4
my name: Sanjida first letter S . ASCII of S=83 (cap letter only)
so equation for me is:x^3-(4)x+(83)
as last digit is 4 i have to choose secant method.
now find your and you need to describe your equationand method choosein your report as i shown here.
#include <stdio.h>
#include <math.h>
#define EPS 1e-12
#define MAX_ITER 100
double fun(double x) {
return x*x*x - 4*x + 83;
}
double Secand(double fun(double), double x0, double x1) {
double x;
int iter = 0;
while (fabs(x1 - x0) >= EPS) {
x = x1 - fun(x1) *(x1 - x0) / (fun(x1) - fun(x0));
x0 = x1;
x1 = x;
iter++;
if (iter > MAX_ITER) {
printf("No convergence after %d iterations\n", MAX_ITER);
break;
}
}
return x1;
}
int main() {
double x0=83, x1=-10;
double x = Secand(fun, x0, x1);
double y = fun(x);
printf("Root found %lf, f(x) = %lf", x, y);
return 0;
}
Comments
Leave a comment