Question

In: Advanced Math

why can't we use bisection methods or newton's method for nonconvex functions? x^4+x^3-2x^2-2x especially for this...

why can't we use bisection methods or newton's method for nonconvex functions? x^4+x^3-2x^2-2x especially for this function?

Solutions

Expert Solution


%%Matlab code for finding root using newton secant bisection and false
clear all
close all

%function for which root have to find
fun=@(x) x.^4+x.^3-2.*x.^2-2.*x;
fprintf('For the function f(x)=')
disp(fun)

a=1;b=2;
xx=linspace(1,2);
yy=fun(xx);

plot(xx,yy)
xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')

[root]=bisection_method(fun,a,b,1000);
fprintf('\tRoot using Bisection method is %f.\n',root)

[root]=newton_method(fun,a,1000);
fprintf('\tRoot using Newton method is %f.\n',root)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Matlab function for Bisection Method
function [root]=bisection_method(fun,x0,x1,maxit)
if fun(x0)<=0
    t=x0;
    x0=x1;
    x1=t;
end
fprintf('\nRoot using Bisection method\n')
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
while k>5*10^-10
    count=count+1;
    xx(count)=(x0+x1)/2;
    mm=double(fun(xx(count)));
    if mm>=0
        x0=xx(count);
    else
        x1=xx(count);
    end
    err(count)=abs(fun(x1));
    k=abs(fun(x1));
    if count>=maxit
        break
      
    end
    %
end
fprintf('\tAfter %d iteration root using Bisection method is %f\n',count,xx(count))
root=xx(end);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Matlab function for Newton Method
function [root]=newton_method(fun,x0,maxit)
syms x
g1(x) =diff(fun,x);   %1st Derivative of this function
xx=x0;            %initial guess]
fprintf('\nRoot using Newton method\n')
%Loop for all intial guesses
    n=5*10^-15; %error limit for close itteration
    for i=1:maxit
        x2=double(xx-(fun(xx)./g1(xx))); %Newton Raphson Formula
        cc=abs(double(fun(x2)));                 %Error
        err(i)=cc;
        xx=x2;
        if cc<=n
            break
        end
      
    end
    fprintf('\tAfter %d iteration root using Newton method is %f\n',i,xx)
    root=xx;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Related Solutions

Using the bisection method, find the root of the following function: f(x)=cos(2x) - x Use the...
Using the bisection method, find the root of the following function: f(x)=cos(2x) - x Use the following initial values: xl=0 and xu=2 NOTE: Perform only 3 iterations.
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2...
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2 + 10x -20, with x_0 = 2, and x_1 = 1.
Solve for x x^4 + 2x^3 + 2x^2 + 3x + 1 = 0
Solve for x x^4 + 2x^3 + 2x^2 + 3x + 1 = 0
F(x) = 0 + 2x + (4* x^2)/2! + (3*x^3)/3! + ..... This is a taylors...
F(x) = 0 + 2x + (4* x^2)/2! + (3*x^3)/3! + ..... This is a taylors series for a function and I'm assuming there is an inverse function with an inverse taylors series, I am trying to find as much of the taylors series of the inverse function (f^-1) as I can
Matlab Consider f(x) = x^3 - x. Plot it. (a) Use Newton's method with p_0 =1.5...
Matlab Consider f(x) = x^3 - x. Plot it. (a) Use Newton's method with p_0 =1.5 to find an approximation to a root with tolerance TOL = 0.01. (b) Use secant method with p_0 = 0.5 , p_1 =1.5, to answer same question as (a). (c) Use Method of False position with initial approximate roots as in (b).
Use Bisection and Newton Raphson methods to find roof for the following equation manually. F(x)=x^2 –...
Use Bisection and Newton Raphson methods to find roof for the following equation manually. F(x)=x^2 – 5 = 0 ε = 0.01
p(x)=x^4-2x^3+x^2+2x-2 zero: 1-i use the given zero to find all the zeros of the polynomial function
p(x)=x^4-2x^3+x^2+2x-2 zero: 1-i use the given zero to find all the zeros of the polynomial function
Create a flowchart using the bisection method when a=2 and b=5 and y=(x-3)3-1
Create a flowchart using the bisection method when a=2 and b=5 and y=(x-3)3-1
excel problem Find the roots of the functions given using the bisection method. Use the graph...
excel problem Find the roots of the functions given using the bisection method. Use the graph of each function to choose points that bracket the root of interest. a. f(x) x-x^1/3-2 b.f(x)=xtanx-1 c.f(x)=x^4-e^x+1 d.f(x)x^2e^x-1
Q.3 Consider the function f(x) = x^2– 2x + 4 on the interval [-2, 2] with...
Q.3 Consider the function f(x) = x^2– 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT