Question

3. Write a code to find 3 roots of the function f(x) 2r3-4x2 -22x +24 for the interval I-5, 5] considering the following meth3. Write a code to find 3 roots of the function f(x) 2x3-4x2 -22x +24 for the interval [-5, 5] considering the following meth

3. Write a code to find 3 roots of the function f(x) 2r3-4x2 -22x +24 for the interval I-5, 5] considering the following methods a) Bisection Method b) Newton's Method Hint: Plot a graph of f(x) and determine proper intervals and initial guesses for a) and b), respectively.
3. Write a code to find 3 roots of the function f(x) 2x3-4x2 -22x +24 for the interval [-5, 5] considering the following methods a) Bisection Method b) Newton's Method Hint: Plot a graph of f(x) and determine proper intervals and initial guesses for a) and b), respectively.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Web Browser - Blsection Nr 3roots Blsection Nr 3roots ← → 台 Location file ///C:/Users/sona /Documents MATLAB/html Bisection N

media%2F17b%2F17b8dcfb-4559-42f5-aed6-5a

100 50 -50 -100 -150 200 -250 -5 4 -321 02345

Script TXT:

f =  @(x) 2*x.^3 - 4*x.^2 - 22*x + 24;
df = @(x) 6*x.^2 - 8*x - 22;
x = linspace(-5,5);

% Plotting Function and zero line to see 3 roots
plot(x,f(x))
xlabel("x"); ylabel("f(x)");
grid on
yline(0);       % plotting zero line to identify roots

%%%%%%%%% Bisection Method %%%%%%%%%%%
% For interval (-4,-2)
    x1_bis = Bisection(f,-4,-2);
% For Interval (0,2)
    x2_bis = Bisection(f,0,2);
% For Interval (3,5)
    x3_bis = Bisection(f,3,5);

%%%%%%%%% Newton's Method %%%%%%%%%%%
% For starting value (-4)
    x1_NR = NR(f,df,-4);
% For starting value (0)
    x2_NR = NR(f,df,0);
% For starting value (3)
    x3_NR = NR(f,df,3);

fprintf("\n 3 roots by Bisection Method : %.3f \t %.3f \t %.3f",x1_bis,x2_bis,x3_bis);
fprintf("\n 3 roots by Newton's Method  : %.3f \t %.3f \t %.3f",x1_NR,x2_NR,x3_NR);


%Function for bisection method
function xr = Bisection(f,xl,xu)
    % f is function
    % xl ,xu are initial Guesses
    error = 1;                  % Initializing Error
    tol = 10^-6;
    while(error>=tol)
        xr = (xl+xu)/2;            % New Guess Calculation
        if f(xl)*f(xr) < 0         % Checking Condition for guess replacement
             xu = xr;
        else
             xl = xr;
        end
        error = abs(f(xr));             % Defining error
    end
end

% Function For NR
function x2 = NR(f,df,x1)
% f is function
% df is derivative function
% x1: Initial Guess
    error = 1;                          % Initializing Error
    tol = 1e-6;                         % Setting Tolerance
    while (error >= tol)
        x2 = x1 - (f(x1)/df(x1));       % Calculation of next guess
        error = abs(f(x2));             % Defining Error
        x1 = x2;                        % Replacing Guesses
    end
end
Add a comment
Know the answer?
Add Answer to:
3. Write a code to find 3 roots of the function f(x) 2r3-4x2 -22x +24 for the interval I-5, 5] co...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT