Question

In: Advanced Math

MatLab code for Bisection and Newton Method to find root for f(k) = p(k)^3+2*(p(k)^2)-10 on interval...

MatLab code for Bisection and Newton Method to find root for f(k) = p(k)^3+2*(p(k)^2)-10 on interval [-1,2]. P(o)=1.5, P(1)=2.

Answer=
1.654249

Solutions

Expert Solution


%%Matlab code for finding root using Newton, Secant and Bisection method
clear all
close all


%Function for which root have to find
fun=@(x) x.^3+2.*x.^2-10;

%plotting of the function
xx=linspace(-1,2,1001);
yy=fun(xx);
plot(xx,yy)
xlabel('x')
ylabel('y')
title('f(x) vs x plot')

%displaying the function
fprintf('For the function\n')
disp(fun)

%Root using Newton method
x0=2; %Initial guess
maxit=1000; %maximum iteration
[root]=newton_method(fun,x0,maxit);
fprintf('Root using Newton method for initial guess %f is %2.15f.\n',x0,root);


%Root using Bisection method
x0=-1; x1=2; %Initial guess
maxit=1000; %maximum iteration
[root]=bisection_method(fun,x0,x1,maxit);
fprintf('Root using Bisection method for initial guess[%f,%f] is %2.15f.\n',x0,x1,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
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
while k>eps
    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
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]
%Loop for all intial guesses
    n=eps; %error limit for close itteration
    for i=1:maxit
        x2=double(xx-(fun(xx)./g1(xx))); %Newton Raphson Formula
        cc=abs(fun(x2));                 %Error
        err(i)=cc;
        xx=x2;
        if cc<=n
            break
        end
      
    end
    root=xx;
end

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


Related Solutions

In Sciland code, use the Newton Method to find the root of f(x)=10-x^2 and tol =10^-5
In Sciland code, use the Newton Method to find the root of f(x)=10-x^2 and tol =10^-5
To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
Using Newton-Raphson method, find the complex root of the function f(z) = z 2 + z...
Using Newton-Raphson method, find the complex root of the function f(z) = z 2 + z + 1 with with an accuracy of 10–6. Let z0 = 1 − i. write program c++ or matlab
USING BISECTION METHOD, FIND THE ROOT OF 0.5e^x - 5x + 2 = 0 ON THE...
USING BISECTION METHOD, FIND THE ROOT OF 0.5e^x - 5x + 2 = 0 ON THE INTERVAL [ 0 , 1 ] UP TO 3 DECIMAL PLACES. USE NEWTON'S METHOD TO APPROXIMATE THE ROOT OF f(x)=x^2-5    IN THE INTERVAL  [ 2 , 3 ] UP TO 4 DECIMAL PLACES.
f(x)=x^3-3x-1=0 x=[0,2] epsilon=5*10^-2 1. perform the bisection method for the root in [0,2] until your root...
f(x)=x^3-3x-1=0 x=[0,2] epsilon=5*10^-2 1. perform the bisection method for the root in [0,2] until your root is closer to the real root within epsilon. Let x_0=1.0, x_1=1.2 2. perform the secant method until your root is closer to the real root within epsilon. 3. do as in 2. with the Newton's method, with x_0=1.1
Implement in MATLAB the Newton-Raphson method to find the roots of the following functions. (a) f(x)...
Implement in MATLAB the Newton-Raphson method to find the roots of the following functions. (a) f(x) = x 3 + 3x 2 – 5x + 2 (b) f(x) = x2 – exp(0.5x) Define these functions and their derivatives using the @ symbol. For example, the function of part (a) should be f=@(x)x^3 + 3*x.^2 - 5*x + 2, and its derivative should be f_prime=@(x)3*x.^2 + 6*x - 5. For each function, use three initial values for x (choose between -10...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of scalar nonlinear equa-tions. Use these programs to compute approximations to real roots of the following equations: exp(x)−3x^2=0, (1) x^3=x^2+x+1, (2) exp(x) =1/(0.1 +x^2), (3) and x= 1 + 0.3 cos(x). (4) Use an error tolerance tol=10^(−12). Display the obtained approximations to the roots of these equations, and compare the number of iterations, starting with the same initial values x0 for bisection and Newton methods,...
Use matlab code for bisection method and regula falsi. Thank you!
Use matlab code for bisection method and regula falsi. Thank you!
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
Using Matlab, create a code that determines the highest real root of f(x)=x3-6x2+11x-6.1 using the Newton-Raphson...
Using Matlab, create a code that determines the highest real root of f(x)=x3-6x2+11x-6.1 using the Newton-Raphson method with x0=3.5 for three iterations. Verify that the process is quadratically convergent. I found the code to get the highest real root (root for three iterations = 3.0473), however, I do not know how to verify that it is quadratically convergent.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT