Professional Documents
Culture Documents
CANARIA
CANARIA
1
Newton-Raphson and Secant Method
Name: CANARIA, LIZ ANNE L. Section: EE22S1
Date Performed: 1/31/2023 Date Submitted:
Instructor:
1. Objective(s):
3. Discussion:
Newton’s method also known as the Newton-Raphson Method is named after Isaac Newton and
Joseph Raphson, is a root-finding algorithm which produces successively better approximations to the
roots (or zeroes) of a real-valued function. Newton-Raphson method is often the most efficient root-
finding algorithm available. The iterative formula for NRM is given by
The secant method is very similar to the bisection method except instead of dividing each interval by
choosing the midpoint the secant method divides each interval by the secant line connecting the
endpoints. The iterative formula for SM is given by
4. Procedure:
NEWTON-RAPHSON METHOD
EXAMPLE 1: Find the root of the function using NRM having initial approximation of 1
Input the following codes to your MATLAB edit window and name as “newton.m”
% Newton-Raphson Algorithm
syms x
%Input section
y = input('Enter the given function: ');
yd = input('Enter the derivative of the given function:
');
p0 = input('Enter initial approximation: ');
n = input('Enter no. of iterations, n: ');
tol = input('Enter tolerance, tol: ');
i = 1;
while i <= n
d=(eval(subs(y,x,p0)))/eval(subs(yd,x,p0));
p0 = p0 - d;
if abs(d) < tol
if i == 3
fprintf('\nApproximate solution of %s is xn=
%11.9f on %drd iterations \n\n',y, p0, i);
elseif i == 1
fprintf('\nApproximate solution of %s is xn=
%11.9f on %dst iterations \n\n',y, p0, i);
elseif i == 2
fprintf('\nApproximate solution of %s is xn=
%11.9f on %dnd iterations \n\n',y, p0, i);
else
fprintf('\nApproximate solution of %s is xn=
%11.9f on %dth iterations \n\n',y, p0, i);
end
break;
else
i = i+1;
end
end
Run the program and enter the following
% Secant Algorithm
syms x
%Input section
y = input('Enter the given function: ');
p0 = input('Enter 1st approximation, p0: ');
p1 = input('Enter 2nd approximation, p1: ');
n = input('Enter no. of iterations, n: ');
tol = input('Enter tolerance, tol: ');
i = 2;
f0 = eval(subs(y,x,p0));
f1 = eval(subs(y,x,p1));
while i <= n
p = p1-(f1*(p1-p0))/(f1-f0);
fp = eval(subs(y,x,p));
if abs(p-p1) < tol
if i == 3
fprintf('\nApproximate solution of %s is xn=
%11.9f on %drd iterations \n\n',y, p, i);
elseif i == 1
fprintf('\nApproximate solution of %s is xn=
%11.9f on %dst iterations \n\n',y, p, i);
elseif i == 2
fprintf('\nApproximate solution of %s is xn=
%11.9f on %dnd iterations \n\n',y, p, i);
else
fprintf('\nApproximate solution of %s is xn=
%11.9f on %dth iterations \n\n',y, p, i);
end
break;
else
i = i+1;
p0 = p1;
f0 = f1;
p1 = p;
f1 = fp;
end
end
Run the program and enter the following
EXERCISES
Approximate the positive root of the functions below using both NRM and SM.(Write the output for both
methods)
1. 2.
>> Canaria_SM NRM:
Enter the given function: 3*x-cos(x)-1
Enter 1st approximation, p0: 0
Enter 2nd approximation, p1: pi
Enter no. of iterations, n: 20
Enter tolerance, tol: 0.0001
NRM:
Approximate solution of 3*x - cos(x) - 1 is
xn= 0.607101643 on 3rd iterations
SM:
Approximate solution of 3*x - cos(x) - 1 is
xn= 0.607101643 on 5th iterations
3. 4.
5. 6.
Applications
1. The volume of a liquid in a hollow horizontal cylinder of radius and length is related to the depth of
the liquid by
2. In structural engineering, the secant formula defines the force per unit area, P/A, that causes a
maximum stress in a column of given slenderness ratio :
where the eccentricity ratio and modulus elasticity. If for a steel beam, , and , compute for .
5. Conclusion:
Rating =
(Total Score / 21)