Docsity

uSED FOR SUMMARIES IN ENGINEERING, Summaries of Electrical Engineering

Toggle sidebar
bg1
1 | CDM – CE DEPT. – APIC – BSCE2 – CIEN 2221 – LAB3
: __________________________
__________________________
:
: _______________
_______________
BSCE 02
Year
LAB No.
1. To write a clear and well-documented M-file on finding roots of functions and polynomials using
the following: Bisection Method, Regula-Falsi Method, Newton-Raphson Method and Secant
Method.
Although they arise in other problem contexts, roots of equations frequently occur in the area of
design. Roots of equations may be either real or complex. Although there are cases where complex
roots of nonpolynomials are of interest, such situations are less common than for polynomials. As a
consequence, the standard methods for locating roots typically fall into two somewhat related but
primarily distinct problem areas: (1) the determination of the real roots of algebraic and transcendental
functions; (2) the determination of all real and complex roots of polynomials. Roots of functions are
categorized into two: bracketing methods and open methods.
For bracketing methods, the root is located within an interval prescribed by a lower and an upper
bound. Such methods are said to be convergent because they move closer to the truth as the
computation progresses. Two common bracketing methods are used: the Bisection Method and the
False-Position Method.
For open methods, it only requires single starting value of x or two starting values that do not necessary
bracket the root. As such, they sometimes diverge or move away from the true root as the computation
progresses. However, when the open methods converge, they usually do so much more quickly than
the bracketing methods. Two typical open methods are used: the Newton- Raphson Method and the
Secant Method.
Casabuena, Jhonel D.
Ignacio, Robbie S.
Lazona, Princess Emee E.
Navarra, Casey S.
Vicente, Marielle Joi G.
Year and Section: _________________________
CE2Y
I. INTRODUCTION
II. OBJECTIVE
CIEN 2221 Numerical
Subject
Date
Topic
Name
Subject Code /
: __________________________
: Introduction to MATLAB Program
Solutions to CE Problems
: _______________
:
Laboratory 03
Student No.
Colegio de
Muntinlupa
Department of
Civil Engineering
Republic of the Philippines
Colegio de Muntinlupa
Mayor J. Posadas Ave., Brgy. Sucat, Muntinlupa City, Philippines
College of Engineering
Civil Engineering Department
CIEN 2221 (Lab)
Numerical Solutions to Civil Engineering Problems
Coding Exercise No. 03
MATHLAB Coding Fundamentals
Coders and Programmers (Names)
pf3
pf4
pf5
pf8

Partial preview of the text

Download uSED FOR SUMMARIES IN ENGINEERING and more Summaries Electrical Engineering in PDF only on Docsity!

: __________________________

: __________________________

: _______________

______________^ BSCE 02 _

Year LAB No.

  1. To write a clear and well-documented M-file on finding roots of functions and polynomials using the following: Bisection Method, Regula-Falsi Method, Newton-Raphson Method and Secant Method. Although they arise in other problem contexts, roots of equations frequently occur in the area of design. Roots of equations may be either real or complex. Although there are cases where complex roots of nonpolynomials are of interest, such situations are less common than for polynomials. As a consequence, the standard methods for locating roots typically fall into two somewhat related but primarily distinct problem areas: (1) the determination of the real roots of algebraic and transcendental functions; (2) the determination of all real and complex roots of polynomials. Roots of functions are categorized into two: bracketing methods and open methods. For bracketing methods, the root is located within an interval prescribed by a lower and an upper bound. Such methods are said to be convergent because they move closer to the truth as the computation progresses. Two common bracketing methods are used: the Bisection Method and the False-Position Method. For open methods, it only requires single starting value of x or two starting values that do not necessary bracket the root. As such, they sometimes diverge or move away from the true root as the computation progresses. However, when the open methods converge, they usually do so much more quickly than the bracketing methods. Two typical open methods are used: the Newton- Raphson Method and the Secant Method.

(1) ____________________________________________________________

(2) ____________________________________________________________

(4) ____________________________________________________________

(3) ____________________________________________________________

(5) ____________________________________________________________

Casabuena, Jhonel D. Ignacio, Robbie S. Lazona, Princess Emee E. Navarra, Casey S. Vicente, Marielle Joi G.

Year and Section: _________________________CE2Y

I. INTRODUCTION

II. OBJECTIVE

CIEN 2221 Numerical Subject Date Topic Name Subject Code /

: __________________________

: Introduction to MATLAB Program Solutions to CE Problems : _______________

Laboratory 0 3 Student No. Colegio de Muntinlupa Department of Civil Engineering

Republic of the Philippines

Colegio de Muntinlupa

Mayor J. Posadas Ave., Brgy. Sucat, Muntinlupa City, Philippines

College of Engineering

Civil Engineering Department

CIEN 2221 (Lab)

Numerical Solutions to Civil Engineering Problems

Coding Exercise No. 03

MATHLAB Coding Fundamentals

Coders and Programmers (Names)

III. MATERIALS / TOOLS / EQUIPMENT

1 unit – Computer or Laptop with installed MATLAB software for each student

IV. PROCEDURES

BISECTION METHOD:

function [root, fx, Re, Cd, ea, iter] = bisect(func, xl, xu, es, maxit, varargin) %% Find the root of function using Bisection Method % Input: % func = given function to determine the root % xl = lower initial guess % xu = upper initial guess % es = stopping criterion (%) % maxit = maximum number of iterations % Output: % root = approximate value of the root of function % fx = corresponding function value of the root % Re = Reynolds number % Cd = Drag Coefficient % ea = approximate relative error (%) % iter = number of iterations %% Constants: rho = 1000; % fluid density (kg/m^3) mu = 0.001; % dynamic viscosity (N*s/m^2) D = 0.001; % particle diameter (m) %% Initializations: if nargin < 3, error('At least 3 input required'), end if nargin < 4 || isempty(es), es = 0.05; end if nargin < 5 || isempty(maxit), maxit = 100; end fl = func(xl, varargin{:}); fu = func(xu, varargin{:}); sign = fl * fu; if sign <= 0, error('No Sign Change'), end iter = 1; ea = 100; xr = xl; fprintf('\n'); fprintf('root function value reynolds number Drag Coefficient approx. rel. error iteration\n'); %% Bisection Method Iteration: while (1) xrold = xr; xr = (xl + xu)/2; iter = iter + 1; if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end test = func(xl, varargin{:}) * func(xr, varargin{:}); if test < 0 xu = xr; elseif test > 0 xl = xr; else ea = 0;

if xr ~= 0 ea = abs((xr - xrold)/xr) * 100; end if func(xl, varargin{:}) * func(xr, varargin{:}) < 0 xu = xr; elseif func(xl, varargin{:}) * func(xr, varargin{:}) > 0 xl = xr; else ea = 0; end if ea <= es || iter >= maxit; break, end end %% Resulting Calculation: root = xr; fx = func(xr, varargin{:}); Re = (rho * D * root) / mu; Cd = 24/Re + 3/sqrt(Re) + 0.34; fprintf('%14.10f %14.10f %14.10f %14.10f %12.8f %2d\n',root, fx, Re, Cd, ea, iter); fprintf('\n');

NEWTON RAPHSON METHOD:

function [vr, fv, Re, cd, ea, iter] = newtraph(vr, es, maxit, varargin) %% uses Newton-Raphson method to find the root of func % Input: % func = name of function % dfunc = name of derivative of function % vr = initial guess % es = stopping criterion (%) % maxit = maximum allowable iterations (default = 100) % g = gravity % D = the particle's diameter % mu = the fluid's dynamic viscosity % rho = the fluid's density % rhos = the particle's density % Output: % v = real root % ea = approximate relative error (%) % iter = number of iterations (%) % fv = settling velocity of particle % Re = Reynolds number % cd = drag coefficient %% Constants for the function g = 9.81; % gravity (m/s^2) D = 0.001; % particle's diameter (m) mu = 0.001; % fluid's dynamic viscosity (N*s/m^2) rho = 1000; % fluid's density (kg/m^3) rhos = 2650; % particle's density (kg/m^3) %% Initialization: if nargin < 3, error('at least 3 input arguments reguired'), end if nargin < 4 || isempty(es), es = 0.05; end if nargin < 5 || isempty(maxit), maxit = 100; end iter = 0;

fprintf('\n'); fprintf('root function value Reynolds number Drag coefficient approximate relative error iterations\n'); %% Applying Newton-Raphson method: v = vr; while (1) Re = (rho * D * v)/mu; if Re <= 0, error('invalid Reynolds number'); end func = (sqrt((4gRemu(rhos - rho) / ((72/Re + 9/sqrt(Re) + 1.02) ... Dv))) - v); dfunc = func(4gRe(rhos - rho)(72/Re + 9/sqrt(Re) + 1.02) ... D) / ((72/Re + 9/sqrt(Re) + 1.02)Dv)^2; vrold = vr; fval = func; dfval = dfunc; vr= vrold - (fval / dfval); iter = iter + 1; if vr ~= 0, ea = abs((vr - vrold)/vr) * 100; end if ea <= es || iter >= maxit, break, end end %% Resulting Calculation fv = func; Re = (rho * D * v)/mu; cd = 24/Re + 4/sqrt(Re) + 0.34; fprintf('%4.2f %5.2f %5.2f %5.2f %3.2f %2d\n', vr, fv, Re, cd, ea, iter); fprintf('\n');

SECANT METHOD:

function [root, fx, Re, Cd, ea, iter] = secant( xl, xu, es, maxit, varargin) % secant: root location zeroes using Secant Method % [root, fx, Re, Cd, ea, iter] = secant(func, xl, xu, es, maxit, ...): % uses secant method to find the root of func and computes Re and Cd % Input: % func = name of function % xl = lower initial guess % xu = upper initial guess % es = desired relative error % maxit = maximum allowable iterations % rho = fluid density (kg/m^3) % rhos = particle density (kg/m^3) % mu = dynamic viscosity (N·s/m^2) % D = particle diameter (m) % Output: % root = root estimate (velocity) % fx = function value at root % ea = approximate relative error (%)

FALSE POSITION METHOD:

NEWTON RAPHSON METHOD:

SECANT METHOD:

Root Locating

Method

Flow Parameters of the Spherical Quartz Sand Setting in Water

Velocity, v

(m/s) (root)

Reynolds

Number, Re

Drag

Coefficient, Cd

ԑa (%) Iterations

Bisection 0.50 499.76 0.52 0.05 12

False-Position 249.72 249715.4 0 0.35 0.00 10

Newton-Raphson 0.50 500.00 0.57 0.00 1

Secant 249.7 2 249715.41 0.35 0.00 9