0% found this document useful (0 votes)
30 views14 pages

Lecture 2 Computational Methods For Engineers

Here are the solutions to problems 6.1 to 6.6 from Applied Numerical Methods with Matlab, 2nd Ed., by S.C. Chapra: Problem 6.1: Use the bisection method to find the root of f(x) = x^3 - x - 1 between x = 0 and x = 2 with a tolerance of 0.0001. [MATLAB CODE AND OUTPUT OMITTED FOR BREVITY] The root is located between 1.414 and 1.415. Problem 6.2: Use the secant method to find the root of f(x) = x^3 - x - 1 starting from x1 = 0, x2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views14 pages

Lecture 2 Computational Methods For Engineers

Here are the solutions to problems 6.1 to 6.6 from Applied Numerical Methods with Matlab, 2nd Ed., by S.C. Chapra: Problem 6.1: Use the bisection method to find the root of f(x) = x^3 - x - 1 between x = 0 and x = 2 with a tolerance of 0.0001. [MATLAB CODE AND OUTPUT OMITTED FOR BREVITY] The root is located between 1.414 and 1.415. Problem 6.2: Use the secant method to find the root of f(x) = x^3 - x - 1 starting from x1 = 0, x2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Computational Methods for

Engineers

Lecture 2

Reuel C. Pallugna
instructor
Topics
• Roots of equations
• Open Methods
• Fixed point iteration Method
• Newton Raphson Method
• Secant Method
• Polynomials using Matlab
• Solutions to Linear Algebraic Equations
• Curve Fitting
• Numerical Differentiation and Integration
• Numerical Solutions to Ordinary Differential Equations
• Numerical Solution to Partial Differential Equations
Fixed Point Iteration Method
• This is called a method of Example:
successive substitution Solve for the roots of
• A function f(x) is rearranged
such that the x is on the left
side of the equation Solution:

• The auxiliary equation is then


cast into its iterative form
A given function

Rearrange into an auxiliary equation

Cast into its iterative form

Iterated until its tolerance value


Newton-Raphson Method
• One of the most widely used root location
method
• Needs only one “good” initial guess
• Needs exact derivative of the function
• Fast method, easily converge
• May not converge quickly for multiple roots and
extremely nonlinear or polynomial curves
Basic Concept of Newton-Raphson Method

The equation of the tangent line is

The Basic Concept of NR:


1. Assume an initial estimate of the root x1
2. Take the derivative of the curve at that initial point This is now the
3. The derivative is the slope of a line tangent to the curve NR formula
4. Locate the point where the tangent line crosses the x-axis , x2
5. Use x2 as the second estimate of the root
6. Repeat the process until desired accuracy is reached
Newton-Raphson Method: example

Solution:
Newton-Raphson Method Algorithm and Matlab Code

NR Algorithm NR Code in Matlab Matlab Graph

• % This is a Newton Raphson Code to solve


% the equation
% f(x) =e^x -x, evaluated between 0<x<1
% df(x) = -e^x-1
xr = 0;
tol =1e-6;
dx = inf;
while abs(dx) > tol
dx = (exp(1).^-xr-xr)/((-exp(1).^-xr) -1);
xr = xr-dx
end

Matlab Output Result from Textbook


NewtonRaphsonCode

xr = 0.5000

xr = 0.5663

xr = 0.5671

xr = 0.5671
Secant Method
Basic Concept of the Secant Method
• Is an open method ( no need to bracket the root)
• Similar to the Newton Raphson method but
requires two initial guesses to determine the slope
of the secant line
• Whereas the NR uses the derivative to determine
the slope of the tangent line, the secant method
uses the two initial guesses to determine the
slope of the secant line
• The point in the secant line that crosses the x-axis
is used to estimate of the root of the curve Substituting the value of
• A numerical equivalent to the NR

Derivation of the Secant Method Formula Equation of a line connecting


Points 2 and 3 is: The general equation for the
Initial guesses Slope of line that passes Secant Method
Point 1 and point 2 is:
Points y-coordinates
on curve at initial guesses
but:
Secant Method (alternate derivation)
The Basic Concept of the Secant Method Initial guesses
can be derived from the Newton-Raphson
method
Points y-coordinates
on curve at initial guesses

The general equation for the


Secant Method
Secant Method sample problem

Solution:
Initial guesses

Solving for y-coordinates

Solving for the next guess


Secant Method Algorithm and Matlab Code
Secant Method Algorithm Secant Method Code in Matlab Result from Matlab Code
% Matlab Code sample for the secant method
% this is taken from CEM Computational Methods for Electrical
x2 = 0.6127
% Engineers and written by Dr. Ramf
% this is put into the slides as an illustration of Secant Code
% This is a more complete code
x2 = 0.5638
% INITIALIZE MATLAB
close all; % Closes all figure window
clc; % Clears command window
x2 = 0.5672
clear all; % Clears workspace
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%DASHBOAARD
x2 = 0.5671
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEFINE THE FUNCTION
func =@(x) exp(1)^-x - x; % a handle to the function
x2 = 0.5671 ( in red dot )
% INITIAL GUESS
x1 = 0;
x2 = 1;
%TOLERANCE
tol = 1e-6;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%IMPLEMENT SECANT METHOD
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% EVALUAT FUNCTION AT X1
f1 = func(x1);
%MAIN LOOP
dx =inf;
iter = 0;
while abs(dx)>tol
% count iterations
iter = iter + 1;
f2 = func(x2);
Note: dx = (x2-x1)*f2/(f2-f1);
% the second point now becomes new first point
Videos of this topic can be viewed x1 = x2;
f1 = f2;
On youtube at CEM Lectures, Topic 4b, %update position of the second point
x2 = x2-dx
Numerical Methods for Electrical Engineers end
By Dr. Ramf
Roots of Polynomials
A polynomial of the form
Introduction
• Can be expressed in matrix form. The coefficient
Matrix , c , of which is as shown highlighted

The eigenvalue algorithm can then be used to


solve
for the roots of the equation
The Matlab function to solve the given equation is

>> x = roots(c) Where c is the coefficient of f(x)


Roots of Polynomials solution using Matlab roots
function
Solve for the roots of the equation using Matlab roots function

Solution:
Matlab m-file using roots function Matlab Output
% this m-file is an illustration of using
the Matlab roots function
% to solve for the roots of the equation x=
% f(x) = x^5 - 3.5x^4 + 2.75x^3 + 2.125x^2
-3.875x +1.25 2.0000 + 0.0000i
c = [1 -3.5 2.75 2.125 -3.875 1.25]; -1.0000 + 0.0000i
x = roots(c) 1.0000 + 0.5000i
1.0000 - 0.5000i
0.5000 + 0.0000i
Activity 2
• Solve problems 6.1 to 6.6 of Applied Numerical Methods with Matlab,
2nd Ed., by S.C. Chapra

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy