Menu

[Solved]Could Really Use Help Supposed Use Bisection Method Find Roots Equation Done Matlab Reall Q37219814

Algorithm 1: Bisection Method ı find middle point c-(a +b)/2; 2 if f(c)0 thern sthen c is the root of the solution: 4 else 5i

I could really use some help on this. I am supposed to use thebisection method to find roots of the equation. I have done it inmatlab but am really struggling to convert it to c++. I will attachthe matlab code below. In matlab I needed to add a table in matlabbut forgot to do so. Thanks for all the help!

syms x; %Assigning x as a symboly = @(x) (2*(x)^4+3*(x)^3-11*(x)^2-9*(x)+15); %Establishing the functiona = input(‘Please enter the value of a: ‘); %Asking the user for the intervalb = input(‘Please enter the value of b: ‘);%If the outputs are greater than zero then there are no roots if y(a) * y(b) > 0 fprintf(‘There are no roots on the given intervaln’) returnend%If a number is entered and equals zero then it is a rootif y(a) == 0 fprintf(‘a is one of the rootsn’) returnelseif y(b) == 0 fprintf(‘ b is one of the rootsn’) returnend%The loop is now initiated to find our root value%Also compiling error data value to plotiter = 1;ErrorData = [];for i = 1:100 c = (a+b)/2; if y(a)*y(c) < 0 b = c; else a = c; end if abs(y(a)) < 1.0E-10 break end ErrorData(iter) = c; iter = iter + 1;end %Showing that the root value was found. fprintf(‘The root: %fn’,a)%Plotting the absolute value of the error that was foundplot(abs(ErrorData),’r–*’)xlim([-10 10])ylim([-10 10])title(‘Error Plot’)grid onAlgorithm 1: Bisection Method ı find middle point c-(a +b)/2; 2 if f(c)0 thern sthen c is the root of the solution: 4 else 5if (f(a) * f(c)) 0 then 6then the root between a and c 7else if (f (b) f(c)) S0 then | then the root between b and c; end Is this possible?; 10 12 end 13 end 2 Methodology Write a C++ code to implement the bisection method for f(x). Your code should accept the interval [a, b] as user input. However, you may hard-code f(z) into your program. As output, you should provide the approximation c to a root of f(x) at each step of the algorithm. For this particular function f(x) 2r4 +3r – 11r2 -9 15 you should be able to determine 4 different roots (-2.5, -1.7321, 1.7321, and 1.0), depending on your choice of Io. Note that, in writing your code, you will need to implement appropriate stopping criteria. Ensure that your program: 1. outputs the root to good accuracy, 2. terminates if it is unable to find the root suitably quickly (define tolerance example le – 10) , and 3. (10 points bonus) plot the error f(c) 2.1 Sample output Table 1: Sample Program output Iteration 0.0000000000 1.5000000000 0.7500000000 0.7500000000 3.9609375000 0.7500000000 1.5000000000 1.1250000000 0.3750000000 1.5717773438 0.7500000000 1.1250000000 0.9375000000 0.1875000000 0.9114074707 72 Show transcribed image text Algorithm 1: Bisection Method ı find middle point c-(a +b)/2; 2 if f(c)0 thern sthen c is the root of the solution: 4 else 5if (f(a) * f(c)) 0 then 6then the root between a and c 7else if (f (b) f(c)) S0 then | then the root between b and c; end Is this possible?; 10 12 end 13 end 2 Methodology Write a C++ code to implement the bisection method for f(x). Your code should accept the interval [a, b] as user input. However, you may hard-code f(z) into your program. As output, you should provide the approximation c to a root of f(x) at each step of the algorithm. For this particular function f(x) 2r4 +3r – 11r2 -9 15 you should be able to determine 4 different roots (-2.5, -1.7321, 1.7321, and 1.0), depending on your choice of Io. Note that, in writing your code, you will need to implement appropriate stopping criteria. Ensure that your program: 1. outputs the root to good accuracy, 2. terminates if it is unable to find the root suitably quickly (define tolerance example le – 10) , and 3. (10 points bonus) plot the error f(c) 2.1 Sample output Table 1: Sample Program output Iteration 0.0000000000 1.5000000000 0.7500000000 0.7500000000 3.9609375000 0.7500000000 1.5000000000 1.1250000000 0.3750000000 1.5717773438 0.7500000000 1.1250000000 0.9375000000 0.1875000000 0.9114074707 72

Expert Answer


Answer to I could really use some help on this. I am supposed to use the bisection method to find roots of the equation. I have do… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *