RIZAL TECHNOLOGICAL UNIVERSITY
COLLEGE OF ENGINEERING AND ARCHITECTURE
DEPARTMENT OF ELECTRICAL ENGINEERING
NUMERICAL METHODS AND ANALYSIS
CATAMORA, RECOLITO
GABINETE, EARL LAWRENCE
MILALLOS, IVAN
SAPITIN, LANCE IVAN
DATE:
SEPTEMBER 27, 2024
MACHINE PROBLEM 2
ROOT FINDING BY BRACKETING METHODS
Create a program in Scilab that will approximate a root of an nth-order polynomial equation
using: (a) the Bisection method, and (b) the False position method. The program should be able to
choose which method to use and plot the function's graph. The laboratory report shall include a
narrative report, flow chart, source code of the working program, and sample output.
OBJECTIVE
The activity aims to provide a thorough understanding of the Bisection and False Position
methods for approximating the roots of nth-order polynomial equations. You will develop a Scilab
program that implements both algorithms, allowing users to select their preferred method and
visualize the polynomial function and its roots. The program should accept user input for
polynomial coefficients and the interval for root approximation, outputting the approximated root
and the number of iterations required for convergence. Additionally, you will produce a
comprehensive laboratory report that includes a narrative on the methods, a flow chart outlining
the program logic, the source code, and sample outputs demonstrating the program's functionality.
Testing with various polynomial equations will ensure the program's accuracy and efficiency.
NARRATIVE REPORT
Day 1
On Friday, September 13, 2024 Engr. Romulo Cruz posted Machine Problem 2, asking every
group to work on brainstorming about the topic given to us. Our group decided to discuss the given
problem to ensure that everyone understood what needed to be done for the activity. We realized that
even though Engr. Cruz has not yet discussed the False Position method, so it would be good for us to
learn about it in advance. This way, we can stay on track with the project and not fall behind. Each
member would research the topic independently over the weekend, specifically from Saturday to Sunday.
It will allow us to gather various perspectives and information before our group discussion on Monday
through Gmeet. By doing our research ahead of time, we can better understand the requirements of the
activity and have more time to complete our tasks thoroughly.
As the days passed, each group member took the initiative to search for information online, looking
for resources that explain both the Bisection and False Position methods. We shared our knowledge
during our Monday discussion, which helped us clarify any doubts and questions regarding our project.
Seeing how cooperative and passionate every member was in making this activity go very well was
inspiring.
Day 2
On Tuesday, September 17, 2024, our group decided to use the time to learn and focus more on
the False Position Method and how it works. Each member researched the topic, Mr. Millalos explained
that the False Position method is “described as the trial and error approach of using 'false' or 'test' values
for the variable and then altering the test value based on the results.” Mr. Sapitin added that this method
is “quite similar to the Bisection method algorithm and is one of the oldest approaches used in root-
finding.”
As we discussed our findings and exchanged information, we were all glad to learn from each
other. This collaboration helped us gather new ideas on how to work on our activity and make it more
easy for us to complete. Through the cooperation of every group member, we made steady progress and
deepened our understanding of the topic. It was encouraging to see how our collective efforts helped us
advance in the project, and we felt more confident moving forward.
Day 3
On Friday, September 18, 2024, Mr. Gabinete began working on the code in Scilab, while other
group members also tried creating their versions of the code for the activity. This led to a lot of trial and
error as we all worked to understand what was needed to run the code successfully. Everyone put in a
lot of effort, facing challenges along the way. Mr. Gabinete managed to make some progress, but he
didn’t complete the entire source code. To enhance our understanding, we continued researching online,
looking for more information about Scilab, its parts, and its functions. We even explored YouTube for
tutorials, which helped us learn more and improve our coding skills as a group.
Day 4
Monday, September 20, 2024, we can work on the bisection method source code for the activity
and still figuring out how to execute with the false position method, At the same time we are also working
on the flowchart for both the bisection method and false position method, we are helping each other and
give us our ideas and perspectives on how to work on this thing, this activity challenges us to be more
productive day by day for us to be able to understand what's more about to learn and to know more about
this activity.
Day 5
September 23, 2024, Gabinete has begun working on the source code for the false position
method, while Mr.Sapitin is troubleshooting the previous code for any errors and improvements. While
completing the code the other members, Mr. Catamora and Mr. Milallos, are researching a function for
the code to show the iterations and the limit where the root is already shown. Many hours were dedicated
to researching the right code, Mr. Gabinete has been done in working out the code for the false position
method with both methods having an abundant line of if-else statements Mr. Milallos suggested a loop
function and we all agreed upon using the while function.
Day 6
September 25, 2024, We are now complete with the source and are only using the remaining time
to troubleshoot using varied examples to notice any errors and improve the source code to be more
efficient and clean. We are also reviewing and educating ourselves to cover the blindspots for the
upcoming defense.
DAY 7
September 26, 2024. During the troubleshooting, we notice some errors and we change some
codes which helps us to find much more reliable codes and formulas as well as shortcuts for us to
elaborate the functions and roots of the problem using bisection and false position methods in sci lab. As
a group, we decided to use the for-loop method instead of using the if-else loop due to the ranges of
iteration we need to limit as well as the contentment of the value and results. As we continue to review
the codes we are preparing for the upcoming defense tomorrow September 27, 2024.
Day 8
Last day, September 27, 2024. We can double-check and replenish all the gaps, and problems
and review finishing and finalizing the narrative report and machine problem report for the upcoming
deadline. We can finalize all the codes as well as the narrative report and other documentation. Mr.
Sapitin double-checked the soft copy of the paper and revised some words and grammar they were using
in the narrative report.
FLOWCHART
SOURCE CODE
mprintf("PLEASE FOLLOW THE FORMAT:[-1 -1 2 1] SHOULD DISPLAY -1-x+2x^2+x^3");
coefficient = input("PLEASE PUT THE COEFFICIENT IN ASCENDING ORDER: ");
fx=poly((coefficient),'x','coeff');
printf(" THE POLYNOMIAL EQUATION IS");
disp(fx);
printf("\n");
a = input ('a INTERVAL:')
b = input ('b INTERVAL:')
function y=polyFunc(x)
y = horner(fx,x)
endfunction
funcA = polyFunc(a)
funcB = polyFunc(b)
disp(funcA)
printf("\n")
disp(funcB)
for i = 1:100
if funcA*funcB >= 0
printf("\n")
disp("ERROR! DOES NOT SATISFY f(a)*f(b)<0!PLEASE RE-ENTER INTERVALS! ")
printf("\n")
a = input ('a INTERVAL:')
b = input ('b INTERVAL:')
funcA = polyFunc(a)
funcB = polyFunc(b)
disp(funcA)
printf("\n")
disp(funcB)
else break
end
end
nonbracketingmethod = input ('PLEASE CHOOSE DESIRED NON BRACKETING METHOD TO BE APPLIED (1
FOR BISECTION METHOD; 2 FOR FALSE POSITION): ')
//BISECTION
if nonbracketingmethod == 1
then
i = 100
tolerance = 0.0001
mprintf("\t\t\t%s\t\t%s\n",'ITERATIONS','ROOTS');
for iter = 1:i;
c = (a+b)/2;
funcC = polyFunc(c);
mprintf("\t\t\t%d\t\t\t%.3f\n",iter,c);
if funcA *funcC < 0;
a = a, b=c
else
a = c, b = b
end
if (abs(funcC)< tolerance)
then break
end
end
end
//FALSE POSITION
if nonbracketingmethod == 2
then
i = 100
tolerance = 0.001
mprintf("\t\t\t%s\t\t\t%s\n",'ITERATIONS','ROOTS');
for iter = 1:i;
c = ((a*funcB)-(b*funcA))/((funcB-funcA));
funcC = polyFunc(c);
mprintf("\t\t\t%d\t\t\t%.3f\n",iter,c);
if funcA * funcC < 0;
a = a, b = c
funcA = funcA, funcB = funcC
else
a = c, b = b
funcA = funcC, funcB = funcB
end
if (abs(funcC)<tolerance)
then break
end
end
end
mprintf("\nTHE ROOT IS APPROXIMATELY AT %.3f AND TOOK %d ITERATIONS\n",c, iter)
//GRAPHING THE FUNCTION
x = linspace(-5,5);
y = x.^2
title ('GRAPH OF THE POLYNOMIAL FUNCTION');
xlabel ('x');
ylabel ('f(x)');
plot (x,fx,'r');
plot (c,0,'o')
legend(['Polynomial Equation','Approximate Root'])
xgrid(5)
funcprot(0)
clc
SAMPLE OUTPUT
DOCUMENTATION