Question: function [val] = f(x) val = ( x .^ 6 ) - 5 * ( x .^ 2 ) + 3; end f_0 = f

function [val] = f(x)

val = ( x .^ 6 ) - 5 * ( x .^ 2 ) + 3;

end

f_0 = f(0); f_1 = f(1);

fprintf('f(0) : %f f(2) : %f ' , f_0 , f_1);

if f_0 * f_1 0

a = 0;

b = 2;

error = 0.5 * ( 10^-5 );

pre = 0.0;

x = ( a + b ) / 2;

while true

if abs( x - pre ) error

break;

end

f_x = f(x);

if f(a) >= 0 && f(b) 0

if f_x > 0

a = x;

else

b = x;

end

else

if f_x > 0

b = x

else

a = x;

end

end

pre = x

x = ( a + b ) / 2;

end

fprintf('Root lies at x = %f ' , x);

else

fprintf('As the sign of f(0) and f(1) is same. SO, no root exists between [0 , 1] ');

end

function [val] = f(x) val = ( x .^ 6 ) -

Question2 8 pts Write no more than two lines of MATLAB find the root of the function fx)-xA6-5xA2+3 that is between 0 and 1. Your code should have a call to your bisection code which you wrote for this lab but you do not need to include the bisection code. code (including 1 for an anonymous function) that will approximately HTML Editor Paragraph

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!