Register or Login to View the Solution or Ask a Question
Introduction : In this article, we will solve sin(x)+e^(-x)=x numerically using Newtons method. Solution of the given equation are points where function intersects x-axis also called roots.
Question: Write a Matlab program to find the root of \(\sin\left(x\right)+e^{-x}=x\) to the 10th decimal places using Newton’s Method.\[\]
Solution:
Given equation
\[\sin\left(x\right)+e^{-x}=x\]
can be written as
\[\sin\left(x\right)+e^{-x}-x = 0\]
Let \(f\left(x\right) =\sin\left(x\right)+e^{-x}-x\)
Newton’s Method of finding root of an equation \(f\left(x\right)=0\) is
\[x_{n+1}=x_n-\frac{f\left(x_n\right)}{f^\prime\left(x_n\right)} , n\geq 0\hspace{5cm}(1)\]
for given initial guess \(x_0\) to the root.
% Matlab Program to find root of an equation using Newton's Method
f=@(x) sin(x)+exp(-x)-x; % function
df=@(x) cos(x)-exp(-x)-1; % derivative of f
x(1) = 1; %initialGuess
Error_tolerance = 0.0000000001; % tolerance 1e^-10
N = 100; % steps
for i=1:N;
functionValue(i)=feval(f,x(i));% function value evaluation at x
derivativeValue(i)=feval(df,x(i)); % derivative evaluation at x
x(i+1)=x(i)-functionValue(i)/derivativeValue(i); % Newton Mthod
if abs(x(i+1)-x(i))<Error_tolerance
break;
end
iteration = i+1
Root = x(i+1)
end
Output Results
iteration | Root |
1 | 1.0000 |
2 | 1.2530 |
3 | 1.2351 |
4 | 1.2350 |
5 | 1.2350 |
6 | 1.2350 |
Therefore \(x = 1.2350\) is the required root of the given equation.
Register or Login to View the Solution or Ask a Question