You are on page 1of 17

Numerical Methods for

Engineers
EE0903301
Lecture 1: Introduction
Dr. Yanal Faouri
Textbook
Textbook
Course Topics:

• 1. Introduction to Numerical Analysis: Area of study in numerical analysis, benefits of studying the
numerical analysis, computer and numerical analysis, mathematical subjects' area, Approximation and
Numerical Error.
• 2. Roots of Equations: Bracketing Methods, Open Methods, System of Nonlinear Equations.
• 3. System of Linear Equations: Gauss Elimination Method, Gauss Jordan Method, Decomposition
Method, Matrix Inverse, Iteration Method.
• 4. Curve Fitting: Introduction, Least Square Regression, Nonlinear Regression Models, Multiple Linear
Regression, Multi-Dimensional Regression, Interpolation, Splines.
• 5. Numerical Differential and Integration: Numerical Differentiation, Numerical Integration, The
Trapezoidal Rule, the Simpson’s rule, Integration with unequal segments, Integration of function.
• 6. Ordinary Differential Equations (ODE): Introduction, Euler’s Method, Runge-Kutta Method, Adams
Multi-step Methods, Boundary Value Problem, Eigenvalues Problem.
• 7. MATLAB Programming
Why you should study numerical methods:

1. Numerical methods greatly expand the types of problems you can address. They are capable of handling
large systems of equations, nonlinearities, and complicated geometries that are not uncommon in engineering
and science and that are often impossible to solve analytically with standard calculus.
2. Numerical methods allow you to use software with insight. During your career, you will invariably have
occasion to use commercially available prepackaged computer programs that involve numerical methods. The
intelligent use of these programs is greatly enhanced by an understanding of the basic theory underlying the
methods. In the absence of such understanding, you will be left to treat such packages as “black boxes” with
little critical insight into their inner workings or the validity of the results they produce.
3. Many problems cannot be approached using canned programs. If you are conversant with numerical
methods, and are adept at computer programming, you can design your own programs to solve problems
without having to buy or commission expensive software.
4. Numerical methods are an efficient vehicle for learning to use computers.
5. Numerical methods provide a vehicle for you to reinforce your understanding of mathematics.
Numerical Methods Covered in this Course (1)

• Part Two deals with two related topics: root finding and optimization. As depicted in
(Fig. a) below, root location involves searching for the zeros of a function. In
contrast, optimization involves determining a value or values of an independent
variable that correspond to a “best” or optimal value of a function. Thus,
optimization involves identifying maxima and minima. Although somewhat different
approaches are used, root location and optimization both typically arise in design
contexts.
Numerical Methods Covered in this Course (2)

• Part Three is devoted to solving systems of simultaneous linear algebraic equations (Fig. b).
Such systems are similar in spirit to roots of equations in the sense that they are concerned
with values that satisfy equations. However, in contrast to satisfying a single equation, a set
of values is sought that simultaneously satisfies a set of linear algebraic equations. Such
equations arise in a variety of problem contexts and in all disciplines of engineering and
science. They originate in the mathematical modeling of large systems of interconnected
elements such as structures, electric circuits, and fluid networks. However, they are also
encountered in other areas of numerical methods such as curve fitting and differential
equations.
Numerical Methods Covered in this Course (3)

• As an engineer or scientist, you will often have occasion to fit curves to data points. The techniques
developed for this purpose can be divided into two general categories: regression and interpolation.
As described in Part Four (Fig. c), regression is employed where there is a significant degree of error
associated with the data. Experimental results are often of this kind. For these situations, the strategy
is to derive a single curve that represents the general trend of the data without necessarily matching
any individual points.
• In contrast, interpolation is used where the objective is to determine intermediate values between
relatively error-free data points. Such is usually the case for tabulated information. The strategy in
such cases is to fit a curve directly through the data points and use the curve to predict the
intermediate values.
Numerical Methods Covered in this Course (4)

• As depicted in Fig. d, Part Five is devoted to integration and differentiation. A physical interpretation of
numerical integration is the determination of the area under a curve. Integration has many applications in
engineering and science, ranging from the determination of the centroids of oddly shaped objects to the
calculation of total quantities based on sets of discrete measurements. In addition, numerical integration
formulas play an important role in the solution of differential equations.
• Part Five also covers methods for numerical differentiation. As you know from your study of calculus, this
involves the determination of a function’s slope or its rate of change.
Numerical Methods Covered in this Course (5)

• Finally, Part Six focuses on the solution of ordinary differential equations (Fig. e).
Such equations are of great significance in all areas of engineering and science. This
is because many physical laws are understood in terms of the rate of change of a
quantity rather than the magnitude of the quantity itself. Examples range from
population-forecasting models (rate of change of population) to the acceleration of a
falling body (rate of change of velocity).
• Two types of problems are addressed: initial-value and boundary-value problems.
Introduction to MATLAB: Entering Vectors
• In MATLAB, the basic objects are matrices, i.e., arrays of numbers. Vectors can be thought of as special matrices.
A row vector is recorded as a 1 × 𝑛 matrix and a column vector is recorded as a 𝑚 × 1 matrix.
• To enter a row vector in MATLAB, type the following in the command window:
>> v = [0 1 2 3], and press enter. MATLAB will print out the row vector.
• To enter a column vector type
>> u = [9; 10; 11; 12; 13]. You can access an entry in a vector with u(2) and change the value of that entry with
>> u(2) = 47
• You can extract a slice out of a vector with
>> u (2:4)
• You can change a row vector into a column vector, and vice versa, easily in MATLAB using
>> w = v’, This is called transposing the vector and we call ' the transpose operator.
• There are also useful shortcuts to make vectors such as
>> x = -1:.1:1
>> y = linspace (0 ,1 ,11), it will give 11 numbers between 0 and 1
Introduction to MATLAB: Basic Formatting

• To make MATLAB put fewer blank lines in its output, enter


>> format compact
>> pi
➔ 3.1416
• To make MATLAB display more digits, enter
>> format long
>> pi
➔ 3.141592653589793
• Note that this does not change the number of digits MATLAB is using in its calculations; it only
changes what is displayed.
Introduction to MATLAB: Plotting Data
• Enter the data into MATLAB with the following commands in the command window:
>> x = [ 5 20 30 50 55 ]
>> y = [ 0.08 0.015 0.009 0.006 0.0055]
• Entering the name of the variable retrieves its current values. For instance
>> x

• We can plot data in the form of vectors using the plot command:
>> plot (x,y), this will produce a graph with the data points connected by lines.
• If you would prefer that the data points be represented by symbols you can do so. For instance;
>> plot (x,y,'*’)
>> plot (x,y,'o’)
>> plot (x,y,'.')
Data as a Representation of a Function

• A major theme in this course is that often we are interested in a certain function y =
f(x), but the only information we have about this function is a discrete set of data
{(xi; yi)}. Plotting the data can be thought of envisioning the function using just the
data.

• We will find later that we can also do other things with the function, like
differentiating and integrating, just using the available data.

• Numerical methods, the topic of this course, means doing mathematics by computer.
Since a computer can only store a finite amount of information, we will almost
always be working with a finite, discrete set of values of the function (data), rather
than a formula for the function.
Introduction to MATLAB: Built-in Functions

• If we wish to deal with formulas for functions, MATLAB contains several built-in functions, including all the usual
functions, such as sin( ), exp( ), etc.. The meaning of most of these is clear. The dependent variable (input) always goes
in parentheses in MATLAB. For instance
>> sin (pi), should return the value of sin π, which is of course 0 and
>> exp (0), will return e0 which is 1.
• More importantly, the built-in functions can operate not only on single numbers but on vectors. For example
>> x = linspace (0 ,2*pi, 41)
>> y = sin(x)
>> plot (x,y), will return a plot of sin x on the interval [0, 2π]
• Some of the built-in functions in MATLAB include cos( ), tan( ), sinh( ), cosh( ), log( ) (natural logarithm), log10( ) (log
base 10), asin( ) (inverse sine), acos( ), atan( ).
• To find out more about a function, use the help command; try
>> help plot
Introduction to MATLAB: User-Defined
Anonymous Functions
• If we wish to deal with a function that is a combination of the built-in functions, MATLAB has a couple of ways for the user to dene
functions. One that we will use a lot is the anonymous function, which is a way to define a function in the command window. The
following is a typical anonymous function:
>> f = @(x) 2*x.^2 - 3*x + 1. This produces the function f(x) = 2x2 - 3x + 1. To obtain a single value of this function enter
>> y = f (2.23572)
➔ 4.2897
• Just as for built-in functions, the function f as we defined it can operate not only on single numbers but on vectors. Try the following:
>> x = -2:0.2:2
>> y = f(x)
• This is an example of vectorization, i.e., putting several numbers into a vector and treating the vector all at once, rather than one
component at a time, and is one of the strengths of MATLAB. The reason f(x) works when x is a vector is because we represented x2 by
x.^2. The . turns the exponent operator ^ into entry-wise exponentiation, so that [-2 -1.8 -1.6].^2 means [(-2)2; (-1.8)2; (-1.6)2] and
yields [4 3.24 2.56]. In contrast, [-2 -1.8 -1.6]^2 means the matrix product [-2;-1.8;-1.6][-2;-1.8;-1.6] and yields only an error.
• The . is needed in .^, .*, and ./. It is not needed when you * or / by a scalar or for + and -.
• The results can be plotted using the plot command, just as for data:
• plot (x,y)
• Notice that before plotting the function, we in effect converted it into data. Plotting on any machine always requires this step.
Exercises

• 1.1) Recall that .*, ./, .^ are component-wise operations. Make row vectors a = 0 : 1 : 3 and b =[-1 0 1 2]. Try the
following commands and report the answer (or error) they produce. Are any of the results surprising?
(a) a.*b, (b) a*b, (c) a*b', (d) a+3*b, (e) a./b, (f) 2*b./a, (g) a.^3, (h) a.^b

• 1.2) Input the data of the below table as vectors and plot it, using symbols at the data points. Use the insert icon to label
the axes and add a title to your graph. Turn in the graph. Indicate what the data is and properly reference where it came
from.

• 1.3) Find a non-linear function formula in an engineering or science textbook or website. Make an anonymous function
that produces that function. Plot it with a smooth curve on a physically relevant domain.
Label the axes and add a title to your graph. Turn in the graph and include the MATLAB command for the anonymous
function.

You might also like