Answer to Question #323599 in C for Mominul

Question #323599

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.


1
Expert's answer
2022-04-04T19:55:35-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS