In: Advanced Math
The Ostrowski method for finding a single root of ?(?)=0 is
given by
Initial guess ?0 ??=??−?(??)?′(??), ??+1=??−?(??)?′(??)
?(??)?(??)−2?(??).
a) Write MATLAB or OCTAVE coding to implement the Ostrowski
method.
(Hint: You may use the coding of Newton Method given in Moodle
pages)
b) Use your coding to find a root of the equation
(?−2)2−ln(?)=0
With initial guess ?0=1.0 and ?0 = 3.0.
Write or print the results in your Homework sheet.
%%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-2).^2-log(x);
fprintf('For the function f(x)=')
disp(fun)
xx=linspace(0,4);
yy=fun(xx);
plot(xx,yy)
xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')
box on; grid on;
[root1]=newton_method(fun,1,1000);
[root2]=newton_method(fun,3,1000);
hold on
plot(root1,fun(root1),'r*')
plot(root2,fun(root2),'r*')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%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 for initial guess
%f\n',x0)
%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=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
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%