Answer to Question #330687 in MatLAB for aaa

Question #330687

Make an octave code to find the root of cos(x) – x * e x = 0 by using bisection method. The answer should be corrected up to four decimal places.


1
Expert's answer
2022-04-19T03:08:23-0400
f = @(x) cos(x)-x.*exp(x);
EPS = 1e-4;
a = 0;
b = 1;
fa = f(a);
fb = f(b);
while b-a > EPS
    c = (b + a) / 2;
    fc = f(c);
    if fc == 0
        break
    end
    if fc*fa < 0
        b = c;
        fb = fc;
    else
        a = c;
        fa = fc;
    end
end
fprintf("The root is %f\n", c)

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