Skip to content

exp2 #3

Description

@legend17-dot

clc; clear; format long;
f = @(x) x^3 - x - 2;
a = 1; b = 2; tol = 1e-6;
for i = 1:100
c = (a+b)/2;
if abs(f(c)) < tol, break; end
if f(a)*f(c) < 0, b = c; else a = c; end
end
fprintf('Root = %.8f after %d iterations\n', c, i);

clc; clear; format long;
f = @(x) cos(x) - x;
a = 0; b = 1; tol = 1e-6;
for i = 1:100
c = (af(b) - bf(a))/(f(b)-f(a));
if abs(f(c)) < tol, break; end
if f(a)*f(c) < 0, b = c; else a = c; end
end
fprintf('Root = %.8f after %d iterations\n', c, i);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions