Use the bisection method to find the roots of a polynomial o

Use the bisection method to find the roots of a polynomial of maximum degree 3 (.i.e. x^3). Prompt the user to input the function coefficients one at a time. Plot the function. Label the axes. Output the function, then list the function and the roots. The roots should be accurate to 2 decimal places. Validate your model with the following functions for -5

Solution

Paste the below code in file name bisect.m file and run the program from command window.

function bisect()

syms a b c d x; % coefficients of polynomial ax^3+bx^2+cx+d

prompt = \'Enter a \';

a = input(prompt);

prompt = \'Enter b \';

b = input(prompt);

prompt = \'Enter c \';

c = input(prompt);

prompt = \'Enter d \';

d = input(prompt);

p = [a b c d];

y = poly2sym(p,x) % Generating polynomial from coefficients

x = -5:0.5:5; %x range -5<=x<=5

grid on;

ezplot(y,x);

title(\'Plot y = f(x)\')

xlabel(\'x values-->\')

ylabel(\'y values-->\')

%Implementation of Bisection method

k = input(\'Enter the first approximation xl(lower) \');

l = input(\'Enter the second approximation xu(upper) \');

acc = input(\'Enter the value of accuracy\');

fk = polyval(p,k);

fl = polyval(p,l);

%always enter lower root as negative and upper as positive

while((polyval(p,k) * polyval(p,l))>0)

k = input(\'Enter the first approximation xl(lower) \');

l = input(\'Enter the second approximation xu(upper) \');

end

while(abs(l-k)>acc)

m = (l+k)/2;

fk = polyval(p,k);

fm = polyval(p,m);

if(fk * fm < 0)

l = m;

else

k = m;

end

end

fprintf(\'The root of the equation is %f\',m);

end

 Use the bisection method to find the roots of a polynomial of maximum degree 3 (.i.e. x^3). Prompt the user to input the function coefficients one at a time. P
 Use the bisection method to find the roots of a polynomial of maximum degree 3 (.i.e. x^3). Prompt the user to input the function coefficients one at a time. P

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site