0% found this document useful (0 votes)
44 views8 pages

Lab 6 - Regular Falsi Method

This document provides instructions for a lab on implementing the Regula Falsi method for finding roots of equations numerically. It describes the objectives, tools, and steps to take which include defining an input function, getting initial guesses, applying the Regula Falsi formula in a loop until the error threshold is met, and outputting the root.

Uploaded by

Maheen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views8 pages

Lab 6 - Regular Falsi Method

This document provides instructions for a lab on implementing the Regula Falsi method for finding roots of equations numerically. It describes the objectives, tools, and steps to take which include defining an input function, getting initial guesses, applying the Regula Falsi formula in a loop until the error threshold is met, and outputting the root.

Uploaded by

Maheen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of Computing

MATH 352: Numerical Methods

Class: BESE-13AB

Lab 6: Regula Falsi Method

Date: March 11 & 13, 2024


Time: 2:00 pm-5:00 pm

Instructor: Hina Munir Dutt


Lab Engineer: Junaid Sajid

MATH333: Numerical Analysis Page 1


Lab 5: Regula Falsi Method
Introduction
False position ( regula falsi ) method which is defined as a closed numerical method used for
find the roots of equations and polynomials.

Objectives
The purpose of this lab is to get familiar with Regular Falsi Method

Tools/Software Requirement
Matlab R2016a

Description
First of all, we need to predict a value for the roots (lower and upper guess)
 xl (xlower); lower guess
 xu (xupper); upper guess
For these two values of function f we will find;
 For xl f(xl)
 For xu f(xu)
Implement the following equation called as a false position formula:

Pseudocode

1. Start
2. Define function f(x)

3. Input
a. Lower and Upper guesses a and b
b. tolerable error e

4. If f(a)*f(b) > 0
print "Incorrect initial guesses"
goto 3
End If

5. Do
Code the above mentioned equation to find the root and store it in variable c.

MATH333: Numerical Analysis Page 2


If f(a)*f(c) < 0
b=c
Else
a=c
End If

while (fabs(f(c)) > e) // fabs -> returns absolute value

6. Print root as c

7. Stop

(By using loop and understanding the algorithm, write the code and display the root. You can use
a simple while loop instead of a do while loop as well)

Lab Task
Implement Regular Falsi method as function. Take function, initial guess, tolerance and other
required parameter as input from user. find its roots.

Code:

function regulafalsi()

while true
% Setting x as symbolic variable
syms x;

% Input Section
inputFunction = input('Enter non-linear equations: ');
error = input('Tolerable error: ');

% Keep looping until valid guesses are provided


while true
firstGuess = input('Enter first guess: ');
secondGuess = input('Enter second guess: ');

% Finding Functional Value


fa = eval(subs(inputFunction, x, firstGuess));
fb = eval(subs(inputFunction, x, secondGuess));

if fa * fb > 0
disp('Given initial values do not bracket the root. Please enter new guesses.');

MATH333: Numerical Analysis Page 3


else
break; % Break the loop if valid guesses are provided
end
end

% Implementing Regula Falsi Method


c = firstGuess - (firstGuess - secondGuess) * fa / (fa - fb);
fc = eval(subs(inputFunction, x, c));
fprintf('\n\na\t\t\tb\t\t\tc\t\t\tf(c)\n');

while abs(fc) > error


fprintf('%f\t%f\t%f\t%f\n', firstGuess, secondGuess, c, fc);
if fa * fc < 0
secondGuess = c;
fb = eval(subs(inputFunction, x, secondGuess));
else
firstGuess = c;
fa = eval(subs(inputFunction, x, firstGuess));
end
c = firstGuess - (firstGuess - secondGuess) * fa / (fa - fb);
fc = eval(subs(inputFunction, x, c));
end

fprintf('\nRoot is: %f\n', c);

% Exit the loop after finding the roots


break;
end

MATH333: Numerical Analysis Page 4


Screenshots:

MATH333: Numerical Analysis Page 5


MATH333: Numerical Analysis Page 6
Output:

MATH333: Numerical Analysis Page 7


Deliverables
Submit single word file with MATLAB code and screen shot of Output.

MATH333: Numerical Analysis Page 8

You might also like