isection(f,[1 1.5], %3D

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Not a graded question 

For example: For finding the cube root of 2, the equation to be solved is x^3 = 2
>> f=e (x) x.^3-2; % root finding function
>>
>> bisection (f, [1 1.5], 0.05)
ans =
1.2603
>> bisection (f, [0 1], 0.05)
Error using bisection (line 13)
Use a bracketing interval
Use the above examples as two sample cases and publish & upload the pdf on Blackboard.
(b) Determine the two roots of f(x) = 2x cos(2x) – (x – 2)² accurate to 4 sig figs.
Write a script that will use your bisection.m written in subpart (a). Use fprintf to print the results to
screen and plot these solution points on the graph with red star markers. Publish to generate pdf and submit on
Blackboard.
Transcribed Image Text:For example: For finding the cube root of 2, the equation to be solved is x^3 = 2 >> f=e (x) x.^3-2; % root finding function >> >> bisection (f, [1 1.5], 0.05) ans = 1.2603 >> bisection (f, [0 1], 0.05) Error using bisection (line 13) Use a bracketing interval Use the above examples as two sample cases and publish & upload the pdf on Blackboard. (b) Determine the two roots of f(x) = 2x cos(2x) – (x – 2)² accurate to 4 sig figs. Write a script that will use your bisection.m written in subpart (a). Use fprintf to print the results to screen and plot these solution points on the graph with red star markers. Publish to generate pdf and submit on Blackboard.
Expert Solution
Step 1

The required function is given below.

function c= bisection(f,interval,es)
    a = interval(1);
    b = interval(2);
    if f(a)*f(b) >= 0
        error('Use a bracketing interval')
    end
        c = mean([a,b]);
    err = 1;
        while err > es
                if f(a)*f(c) < 0
                    b = c;
            else
                    a = c;
            end
                c = mean([a,b]);
        err = abs(c-b);
    end
end
Output

>> f = @(x) x.^3-2;
>> bisection(f,[1,1.5],0.05)

ans =

    1.2812

>> bisection(f,[0,1],0.05)
Error using bisection (line 5)
Use a bracketing interval
 
clear; clc; close all;

% Description: Calculates the root of a given function using bisection
% method

f = @(x) 2*x.*cos(2*x) - (x-2).^2;
fplot(f);
set(gca,'XAxisLocation','origin')
set(gca,'YAxisLocation','origin')
xlim([0 4])
ylim([-5 5])
xlabel('x')
ylabel('f(x)')
grid on

c = bisection(f,[2,3],1e-6);
hold on
plot(c,f(c),'rx')
fprintf('Root: %.4f\n',c)

c = bisection(f,[3,4],1e-6);
plot(c,f(c),'rx')
fprintf('Root: %.4f\n',c)
Output

Root: 2.3707
Root: 3.7221

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY