In: Advanced Math
solve for x:
[x * sqrt(1+x2)] + ln[x + sqrt(1+x2)] = 25
%%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.*sqrt(1+x.^2)+log(x+sqrt(1+x.^2))-25;
fprintf('For the function f(x)=')
disp(fun)
[root]=newton_method(fun,10,1000);
fprintf('\tValue of x using Newton method is %f.\n',root)
xx=linspace(0,5);
yy=fun(xx);
plot(xx,yy)
xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')
hold on
plot(root,fun(root),'r*')
box on; grid on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%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=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
fprintf('\tAfter %d
iteration root using Newton method is %f\n',i,xx)
end
root=xx;
end
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%