0% found this document useful (0 votes)
16 views10 pages

Graphical Method Description: 'B' On 'MP' 'FP' 'Graphical Method To Find Root of FP' On

The document outlines various numerical methods for finding roots of functions, including the Graphical Method, Bisection Method, Regula Falsi Method, Newton-Raphson Method, Secant Method, and Modified Secant Method. Each method is described with its advantages, disadvantages, use cases, and limitations, providing guidance on when to apply each technique. Additionally, it summarizes the appropriate scenarios for using these methods and highlights their respective constraints.

Uploaded by

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

Graphical Method Description: 'B' On 'MP' 'FP' 'Graphical Method To Find Root of FP' On

The document outlines various numerical methods for finding roots of functions, including the Graphical Method, Bisection Method, Regula Falsi Method, Newton-Raphson Method, Secant Method, and Modified Secant Method. Each method is described with its advantages, disadvantages, use cases, and limitations, providing guidance on when to apply each technique. Additionally, it summarizes the appropriate scenarios for using these methods and highlights their respective constraints.

Uploaded by

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

1.

Graphical Method
• Description: In the graphical method, the function f(x)f(x)f(x) is plotted over
a range to visually identify where it crosses the x-axis.
• Types of Functions: This method is suitable for functions that are
continuous and simple enough to interpret visually.
• Advantages: Provides a quick and intuitive understanding of the behavior of
the function and the approximate location of roots.
• Disadvantages: Lacks precision and is impractical for complex functions or
when high accuracy is required.
• % Constants
• cd = 0.25;
• g = 9.81;
• v = 36;
• t = 4;

• % Define the range of mp and calculate fp
• mp = linspace(50, 200, 1000); % Increase the number of points for a
smoother plot
• fp = sqrt(g * mp / cd) .* tanh(sqrt(g * cd ./ mp) * t) - v;

• % Plot the function fp
• plot(mp, fp, 'b');
• grid on;
• xlabel('mp');
• ylabel('fp');
• title('Graphical Method to Find Root of fp');
• hold on;

• % Add a horizontal line at fp = 0 (the x-axis)
• yline(0, 'r--'); % Red dashed line at y = 0

• % Use polyxpoly to find the intersection point
• [x_int, y_int] = polyxpoly(mp, fp, mp, zeros(size(mp)));

• % Plot the intersection points
• plot(x_int, y_int, 'go'); % Green circles for the intersection points

• hold off;

• % Display the intersection points (roots)
• disp('Intersection points (roots):');
• disp(x_int);
% Define the range of mp
mp = linspace(3, 6, 1000); % Increase the number of points for a smoother plot

% Define the function fp as a function of x


fp = @(x) sin(10*x) + cos(3*x);

% Evaluate fp at each point in mp


fp_values = fp(mp);

% Plot
plot(mp, fp_values, 'b'); % Plot fp with a blue line
hold on; % Hold on to add more elements to the plot

% Add a horizontal line at fp = 0 to help locate the roots


yline(0, 'r--'); % Red dashed line at y = 0

% Plot formatting
grid on;
xlabel('mp');
ylabel('fp');
title('Graphical Method to Find Root of fp');

hold off; % Release the hold so further plots don’t add to this figure
% Define the range of mp and calculate c
mp = 1:25; % Increase the number of points for a smoother plot
c = mp; % Assuming c is equal to mp for calculation

% Calculate x1, x2, x3, and fp based on mp


x1 = exp(-0.1468 .* c);
x2 = 1 - x1;
x3 = 667.38 ./ c;
fp = x3 .* x2 - 40;

% Plot the function fp


figure;
plot(mp, fp, 'b', 'LineWidth', 1.5);
grid on;
xlabel('mp');
ylabel('fp');
title('Graphical Method to Find Root of fp');
hold on;

% Add a horizontal line at fp = 0 (the x-axis)


yline(0, 'r--', 'LineWidth', 1); % Red dashed line at y = 0

% Define a horizontal line at y = 0 over the same range as mp


horizontal_fp = zeros(size(mp));
% Use polyxpoly to find the intersection point(s)
[x_int, y_int] = polyxpoly(mp, fp, mp, horizontal_fp);

% Plot the intersection points


plot(x_int, y_int, 'go', 'MarkerSize', 8); % Green circles for the intersection points

hold off;
2. Bisection Method
• Description: The bisection method is a bracketing method that requires a
continuous function f(x)f(x)f(x) over an interval [a,b][a, b][a,b] where
f(a)f(a)f(a) and f(b)f(b)f(b) have opposite signs. The interval is iteratively
halved until it converges to a root.
• Types of Functions: Works well for continuous functions with one root in
the interval.
• Advantages: Simple, guaranteed convergence for functions meeting the
criteria, and relatively robust.
• Disadvantages: Slow convergence and unsuitable for functions with
multiple roots in a single interval or discontinuities within the interval.

cd = 0.25;
g = 9.81;
v = 36;
t = 4;

% Define the function fp as a function of mp


fp = @(x) sqrt(g * x / cd) .* tanh(sqrt(g * cd / x) * t) - v;

% Bisection method parameters


xl = 50; % Lower bound of mp
xu = 200; % Upper bound of mp
xr_prev=0;
error = 100; % Error tolerance

% Bisection method loop


while error>0.05
xr = (xl + xu) / 2;
error=abs((xr-xr_prev)/xr)*100;
if fp(xl)*fp(xr) < 0
xu = xr;
else
xl = xr;
end
xr_prev=xr;

end
xr
3. Regula Falsi Method (False Position)
• Description: This is a modification of the bisection method where instead of
taking the midpoint, it uses a secant line to estimate the root more
accurately. It requires f(a)f(a)f(a) and f(b)f(b)f(b) to have opposite signs.
• Types of Functions: Suitable for functions with one root in a bracketed
interval; it’s faster than the bisection method for well-behaved functions.
• Advantages: Faster convergence than bisection for some functions, while
still maintaining reliability in the bracketing interval.
• Disadvantages: May get "stuck" near a point if one side of the interval
doesn’t change significantly, slowing down convergence. Not suitable for
functions without sign changes.
• % Define the function fp as an anonymous function of x
• fp = @(x) x^10-1

• % Regula Falsi method parameters
• xl = 0; % Lower bound
• xu = 1.3; % Upper bound
• xr_prev = 0; % Initial previous root
• error = 100; % Initial error set to a high value

• % Regula Falsi method loop
• while error > 0.05 % Error tolerance threshold
• % Calculate xr using the Regula Falsi formula
• xr = xu - (fp(xu) * (xl - xu)) / (fp(xl) - fp(xu));

• % Calculate relative error
• if xr ~= 0
• error = abs((xr - xr_prev) / xr) * 100;
• else
• error = 100; % Avoid division by zero
• end

• % Check for sign change to update bounds
• if fp(xl) * fp(xr) < 0
• xu = xr; % Update upper bound
• else
• xl = xr; % Update lower bound
• end

• % Update previous xr for the next iteration
• xr_prev = xr;
• end
Newton-Raphson Method
• Description: An iterative approach that uses the function’s derivative
f′(x)f'(x)f′(x) to update guesses. Given an initial guess x0x_0x0, the next
guess is xn+1=xn−f(xn)f′(xn)x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}xn+1=xn
−f′(xn)f(xn).
• Use: Highly effective for smooth functions with easily computable
derivatives.
• Limitations: Ineffective if the function has discontinuities, is non-
differentiable at certain points, or has flat tangents near the root.
• Advantages: Fast convergence for well-behaved functions; often quadratic
convergence.
• Disadvantages: Requires derivative calculation; can fail to converge if
starting guess is poor, or if the function’s behavior is highly non-linear.
• syms x
• func = (x^10-1); % Define the function for the 10th root of 1
• g = diff(func); % Derivative of the function
• f = matlabFunction(func); % Convert symbolic function to numeric
• g_prime = matlabFunction(g); % Convert derivative to numeric

• a = 0.5; % Initial guess
• n = 100; % Maximum number of iterations

• for i = 1:n
• x_new = a - f(a) / g_prime(a); % Newton-Raphson formula
• error = abs((x_new - a) / x_new) * 100; % Calculate error percentage

• if error < 0.0001
• break
• end

• a = x_new; % Update the value of 'a'
• end

• root = x_new; % Resulting 10th root of 1
• disp(root)


• a = double(a) % Final root approximation

4. Secant MethodSecant Method
• Description: A method that approximates the root by drawing secant lines
between two initial points and iteratively updating them.
• Use: Suitable for differentiable functions where derivatives are difficult to
compute.
• Limitations: Requires good initial guesses and can fail if guesses are poor
or if f(x)f(x)f(x) is not well-behaved.
• Advantages: Faster than bisection and regula falsi; does not require
derivatives.
• Disadvantages: Convergence is not guaranteed; sensitive to initial guesses.
• clc
• clear all
• close all
• % Prompt the user to give the function
• f = inline(input('Enter function: ', 's'));
• % Ask for the initial guesses
• a = input('Enter first guess: ');
• b = input('Enter second guess: ');
• % Ask for the tolerance
• maxerr = input('Enter max err in %: ');

• % Run the algorithm until the result is below the value of tolerance
• while abs(a - b) > maxerr
• c = b - ((f(b) * (a - b)) / (f(a) - f(b)));
• a = b;
• b = c;
• end

• disp(['Root approximation is: ', num2str(c)])

Modified Secant Method


• Description: A variation of the secant method that uses a small
perturbation δ\deltaδ on xxx to approximate derivatives, eliminating the
need for a second point.
• Use: Effective when evaluating f(x)f(x)f(x) at two points is difficult.
• Limitations: Sensitive to the choice of δ\deltaδ.
• Advantages: More flexible than the secant method; only requires one
point.
• Disadvantages: May diverge if δ\deltaδ is poorly chosen; less reliable for
steep or flat functions.
• clc
• clear all
• close all

• % Prompt the user to give the function
• f = inline(input('Enter function: ', 's'));
• % Ask for the initial guess
• x0 = input('Enter initial guess: ');
• % Ask for the tolerance
• maxerr = input('Enter max err in %: ');
• % Ask for the perturbation factor delta
• delta = input('Enter a small perturbation (e.g., 0.01): ');

• % Run the modified secant method algorithm
• while true
• % Calculate the modified secant approximation
• x1 = x0 - (f(x0) * delta * x0) / (f(x0 + delta * x0) - f(x0));

• % Check if the approximation is within the tolerance
• if abs(x1 - x0) < maxerr
• break
• end

• % Update x0 for the next iteration
• x0 = x1;
• end

• disp(['Root approximation is: ', num2str(x1)])

Summary of Use Cases and Limitations


• When to Use Each:
o Bisection and Regula Falsi are suitable for any continuous function
with a sign change.
o Secant and Modified Secant work well when derivatives are hard to
calculate.
o Newton-Raphson is ideal for functions with available derivatives
and close initial guesses.
o Graphical Method is more of a preliminary analysis tool.
• When Not to Use:
o Bisection and Regula Falsi aren’t ideal for functions without a sign
change in the interval.
o Secant and Modified Secant may struggle with poor initial guesses
or irregular functions.
o Newton-Raphson fails with discontinuous or non-differentiable
functions and roots with horizontal tangents.

You might also like