Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Laboratory Activity No.

1
Newton-Raphson and Secant Method
Name: CANARIA, LIZ ANNE L. Section: EE22S1
Date Performed: 1/31/2023 Date Submitted:
Instructor:
1. Objective(s):

1.1 To solve simultaneous equations by Newton-Raphson Method using MATLAB


1.2 To solve simultaneous equations by Secant Method using MATLAB
1.3 To solve some applications using Newton-Raphson and Secant Method

2. Intended Learning Outcomes (ILOs):

The students shall be able to:


2.1 Demonstrate scientific thinking and the ability to approach scientific resources intelligently.
2.2 Utilize MATLAB software in solving simultaneous equations using NRM and SM.
2.3 Utilize MATLAB software in solving some applications using NRM and SM.
2.4 Infer appropriate conclusions based upon the results of activity.
2.5 Reflect on personal transformation along the TIP graduate attributes, specifically, professional
competence and critical thinking skills.

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

Enter the given function: cos(x)


Enter the derivative of the given function: -sin(x)
Enter initial approximation: 1
Enter no. of iterations, n: 30
Enter tolerance, tol: 0.0001

Write the output below


SECANT METHOD

EXAMPLE 2: Find the root of the function using SM


Input the following codes to your MATLAB edit window

% 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

Enter the given function: cos(x)


Enter 1st approximation, p0: 0
Enter 2nd approximation, p1: pi
Enter no. of iterations, n: 20
Enter tolerance, tol: 0.0001

Write the output below

1. Which of the following methods converges faster? Why?

The Newton-Raphson Method, because it is shorter than the other method.

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

Determine given and . Using newton Raphson method

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:

6. Assessment (Rubric for Activity Performance):

BEGINNER ACCEPTABLE PROFICIENT


CRITERIA SCORE
1 2 3
I. Activity Skills
Work that usually needs to have quality of work and Provides work of the
Quality of work be checked/redone by some small errors on the highest quality and answers
others to ensure quality answer are correct
Group is rarely focused on Group is focused on the Group is consistently stays
Focus on the
the task and what to be task and what needs to be focused on the task and
task
done done most of the time what needs to be done
Members do not Members occasionally Members always
Process Skills demonstrate targeted demonstrate targeted demonstrate targeted
process skills. process skills. process skills.
II. Work Habits
Time
Members finish ahead of
Management / Members do not finish on Members finish on time with
time with complete data
Conduct of time with incomplete data. incomplete data.
and time to revise data.
Experiment
Cooperative and Members do not know their Members have defined Members are on tasks and
have defined
tasks and have no defined responsibilities most of the
responsibilities at all times.
responsibilities. Group time. Group conflicts are
Teamwork Group conflicts are
conflicts have to be settled
cooperatively managed
cooperatively managed at
by the teacher. most of the time.
all times.
Clean and orderly Clean and orderly
Neatness and Messy workplace during and workplace with occasional workplace at all times
Orderliness after the experiment. mess during and after the during and after the
experiment. experiment.
Ability to do
Members require Members require occasional Members do not need to be
independent
supervision by the teacher. supervision by the teacher. supervised by the teacher.
work
Other Comments / Observations:
TOTAL SCORE

Rating =
(Total Score / 21)

You might also like