Question

I need help creating program for the Test_Bisection pseudocode. I need to find a root for each function f and g and get the output below.

Pseudocode Now lets construct pseudocode to carry out this procedure. We shall not try to create a piece of high-quality sofBisection Pseudocode end if error + b - a for n = 0 to nmax error + error/2 c a + error fc + f(c) output n, c, fc, error if ſNumerical Examples Now we want to illustrate how the bisection pseudocode can be used. Suppose that we have two functions, anprogram Test Bisection integer n, nmax + 20 real a, b, € + 110-6 external function f, g a + 0.0 b 1.0 call Bisection (f, a, bHere are the computer results with the iterative steps of the bisection method for f (x): nen f(en) error 0 0.5 0.25 0.375 0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

1)

clc%clears screen
clear all%clears history
close all%closes all files
format long
f = @(x) x^3-3*x+1;
e=1e-6;
a=0;
b=1;
iter = 0;
  
if f(a)*f(b)>=0

disp('No Root')

else

prev = (a+b)/2;
p=a;
while (abs(f(p))>e)
prev=p;

iter =iter+ 1;

p = (a+b)/2;

if f(p) == 0

break;

end

if f(a)*f(p)<0

b = p;

else

a = p;

end
fprintf('Iteration %d, root=%2.8f\n',iter,p);
if(iter==100)
disp('the required accuracy is not reached in 50 iterations');
end
end

end

- O X Pradeep do E C . Search Documentation EDITOR PUBLISH VIEW Insert E fx EH - D Comment % 92% & Breakpoints Run Indent 1 -

2)

clc%clears screen
clear all%clears history
close all%closes all files
format long
f = @(x) x^3-2*sin(x);
e=1e-6;
a=0.5;
b=2;
iter = 0;
  
if f(a)*f(b)>=0

disp('No Root')

else

prev = (a+b)/2;
p=a;
while (abs(f(p))>e)
prev=p;

iter =iter+ 1;

p = (a+b)/2;

if f(p) == 0

break;

end

if f(a)*f(p)<0

b = p;

else

a = p;

end
fprintf('Iteration %d, root=%2.8f\n',iter,p);
if(iter==100)
disp('the required accuracy is not reached in 50 iterations');
end
end

end

- O X Pradeep do E C . Search Documentation EDITOR PUBLISH VIEW Insert E fx EH - D Comment % 92% & Breakpoints Run Indent 1 -

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I need help creating program for the Test_Bisection pseudocode. I need to find a root for...
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
  • % Bisection.m Lines of code 17-26 and 43-47 are bold % This code finds the root...

    % Bisection.m Lines of code 17-26 and 43-47 are bold % This code finds the root of a function f(x) in the interval [a, b] using the Bisection method % % It uses f.m to define f(x), and assumes f(x) is continuous % It requires specification of a, b and the maximum error % It defines error using |f(xnew)| % Define inputs for problem a=0; %Defines lower limit of initial bracketing interval b=1; %Defines upper limit of initial bracketing interval...

  • The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at...

    The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at least one root between a = 0 and b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows: a. It finds the midpoint r = (a + b)/2. b. If f(r) = 0, then r is the root. If |b ‐ a| is very small less than ∈ then also we can take r as the root....

  • Need solution for question 5.6 using python? tation to within e, 5.11 Determine the real root...

    Need solution for question 5.6 using python? tation to within e, 5.11 Determine the real root of x 80: (a) analytically and (b) with the false-position method to within e, = 2.5%. Use initial guesses of 2.0 and 5.0. Compute the estimated error Ea and the true error after each 1.0% teration 5.2 Determine the real root of (x) 5r - 5x2 + 6r -2 (a) Graphically (b) Using bisection to locate the root. Employ initial guesses of 5.12 Given...

  • Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2...

    Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2 +3x−7 Calculate the accuracy of the solution to 1 × 10−10. Find the number of iterations required to achieve this accuracy. Compute the root of the equation with the bisection method. Your program should output the following lines: • Bisection Method: Method converged to root X after Y iterations with a relative error of Z.

  • Submission Items: (1) A Word document in which you: a. Describe in brief the problem you...

    Submission Items: (1) A Word document in which you: a. Describe in brief the problem you are solving and the numerical method used. b. Snapshot of the output, when you run the program for the conditions mentioned in the questions. c. Discuss your results. (2) MATLAB code (m) file() Question 1: [10 points) Write a MATLAB function that calculates the approximate value of arctan(x) using the Maclaurin series approximation: arctan(x) = x- + +... The function should accept 3 parameters:...

  • R$ ( pseudocode only, I just need the English written pseudocode) Write pseudocode for a program...

    R$ ( pseudocode only, I just need the English written pseudocode) Write pseudocode for a program that prints a calendar such as the following: Su M T W Th F Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

  • 13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable,...

    13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable, function f e C2la,b]. on the given interval to find out where it Your program should first probe the function f(x) changes sign. (Thus, the program has, in addition to f itself, four other input arguments: a, b, the number nprobe of equidistant values between a and b at which f is probed, and a tolerance tol.) For each subinterval [a,b;] over which the...

  • Questions: 1. Write a MATLAB program to find all the roots of a given, twice continuously differe...

    Questions: 1. Write a MATLAB program to find all the roots of a given, twice continuously differentiable, function f E C2[a, b]. Your program should first probe the function f(x) on the given interval to find out where it changes sign. (Thus, the program has, in addition to f itself, four other input arguments: a, b, the number nprobe of equidistant values between a and b at which f is probed, and a tolerance tol.) For each subinterval [ai,b] over...

  • I'm working on the newton's method on matlab, could someone help me and show what two...

    I'm working on the newton's method on matlab, could someone help me and show what two lines are needed to be added in the codes in order to make this function work? function sample_newton(f, xc, tol, max_iter) % sample_newton(f, xc, tol, max_iter) % finds a root of the given function f over the interval [a, b] using Newton-Raphson method % IN: % f - the target function to find a root of % function handle with two outputs, f(x), f'(x)...

  • Hi, we recently had an assignment and I ended up skipping this question because I didn't understand the question nor...

    Hi, we recently had an assignment and I ended up skipping this question because I didn't understand the question nor how to even start it. Obviously for Matlab! Coding is not my strong point so this was a stitch up. The data we were meant to use is below! For (a) function [n,alpha]=bisect(a,b,eps) alpha=(a+b)/2 n=1; fval=f(alpha); while (b-alpha> eps) & (fval ~= 0) fa=f(a); if fa*fval< 0 b=alpha; else a=alpha; end alpha=(a+b)/2 n=n+1; fval=f(alpha); end end Sample f.m function y=f(w)...

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