a Use builtin Matlab function fzero to find the root of fx

a) Use built-in Matlab function fzero to find the root of f(x) = x2|sinx|-4=0, initial guess x0=0.5.

            b) Use false-position method to find the root of f(x)= x2|sinx|-4=0, initial guess [a, b]=[0, 4].

                 Accept your result when |f(xi)|<5*10-7. Print out all iterations of xi and f(xi).

Solution

Code for file \"f.m\"


function y = f( x )
   y=(x.^2).*(abs(sin(x)))-4;
end

save the above file by the name f.m

a)

code for the file \"fzro.m\"

fun=@f;
x0=0.5;
z=fzero(fun,x0);
fprintf(\'zero of the given function is at %f\ \',z);

save the file by the name fzro.m in the same folder where \"f.m\" is saved.

b)

code for the file falsepost.m

xp=0;
x1=4;

xf=x1-((xp-x1)/(f(xp)-f(x1)))*f(x1);
fprintf(\'at 1 iteration xi is %f and f(xi) is %f\ \',xf,f(xf));
i=2;
while(abs(f(xf))>=5*10^-7)
   xp=xf;
   xf=x1-((xp-x1)/(f(xp)-f(x1)))*f(x1);
   fprintf(\'at %d iteration xi is %f and f(xi) is %f\ \',i,xf,f(xf));
   i=i+1;
end

save the file by the name falsepost.m in the same folder where \"f.m\" is saved

then run the file falsepost.m for getting the answer for (b) part and run the file fzro.m for getting the answer for part (a).

The answer for both the parts is 3.4785

a) Use built-in Matlab function fzero to find the root of f(x) = x2|sinx|-4=0, initial guess x0=0.5. b) Use false-position method to find the root of f(x)= x2|s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site