# How to Solve Engineering Problems with Numerical Methods and MATLAB

## Numerical Methods with MATLAB: Implementation and Application by Gerald W. Recktenwald

Numerical methods are techniques for solving mathematical problems that cannot be solved analytically or exactly. They involve approximating the solution using numerical algorithms that are implemented on computers. Numerical methods are widely used in engineering, science, and mathematics to model complex phenomena, analyze data, and design systems.

## numerical methods with matlab recktenwald pdf 11

MATLAB is a powerful software tool for numerical computing that combines a high-level programming language with built-in functions and libraries for various numerical methods. MATLAB also provides an interactive environment for exploring data, visualizing results, and debugging code. MATLAB can be used to solve a wide range of problems using numerical methods, such as linear algebra, optimization, differential equations, and more.

## Overview of the book

Numerical Methods with MATLAB: Implementation and Application is a book written by Gerald W. Recktenwald, an Associate Professor of Mechanical Engineering at Portland State University. The book is an introduction to MATLAB and numerical methods for undergraduate students of engineering, applied mathematics, and science. The book was published by Prentice Hall in 2000.

### Structure and content of the book

The book consists of 15 chapters that cover the following topics:

Introduction to MATLAB and numerical methods

Interactive computing with MATLAB

Programming with MATLAB

Plotting with MATLAB

File input and output with MATLAB

Solving linear systems of equations

Interpolation and curve fitting

Numerical differentiation and integration

Root finding and optimization

Ordinary differential equations

Partial differential equations

Eigenvalues and eigenvectors

Fast Fourier transform

Random numbers and Monte Carlo methods

Numerical methods for boundary value problems

The book is a modern exposition of classic numerical methods using MATLAB. The fundamental theory of each method is briefly developed. Rather than providing a detailed numerical analysis, the behavior of the methods is exposed by carefully designed numerical experiments. The methods are then exercised on several nontrivial example problems from engineering practice.

### Features and benefits of the book

The book has several features that make it a valuable resource for learning numerical methods using MATLAB:

The book contains an extensive reference to using MATLAB, including interactive (command line) use of MATLAB, MATLAB programming, plotting, file input and output.

The book contains a large number of examples of two basic types: one type demonstrates a principle or numerical method in the simplest possible terms; another type demonstrates how a particular method can be used to solve a more complex practical problem.

The book provides exercises at the end of each chapter that test the understanding of the concepts and methods presented in the chapter. The exercises range from simple calculations to challenging projects that require programming and creativity.

The book includes a CD-ROM that contains the MATLAB code for all the examples and exercises in the book, as well as additional material such as data files, supplementary functions, and solutions to selected exercises.

## Examples of numerical methods using MATLAB

In this section, we will present some examples of numerical methods using MATLAB that are discussed in the book. We will briefly describe the problem, the method, and the MATLAB code and output. For more details and explanations, please refer to the book.

### Solving linear systems of equations

A linear system of equations is a set of equations of the form:

$$Ax=b$$

where $A$ is a matrix of coefficients, $x$ is a vector of unknowns, and $b$ is a vector of constants. Solving a linear system means finding the value of $x$ that satisfies the equations.

One of the most common methods for solving linear systems is Gaussian elimination, which consists of transforming the system into an equivalent upper triangular system using elementary row operations, and then solving the system by back substitution.

The following MATLAB code implements Gaussian elimination with partial pivoting, which means swapping rows to ensure that the largest element in each column is on the diagonal. The code also checks for singularity (when the system has no unique solution) and reports the number of floating-point operations (flops) required by the algorithm.

```matlab function x = gauss(A,b) % GAUSS Solves a linear system by Gaussian elimination with partial pivoting % Input: A - coefficient matrix % b - constant vector % Output: x - solution vector [m,n] = size(A); % get the size of A if m = n % check if A is square error('A must be square') end if n = length(b) % check if b has compatible size error('b must have compatible size') end flops(0); % reset flop counter for k = 1:n-1 % loop over columns % find pivot element [pivot,p] = max(abs(A(k:n,k))); % find largest element in column k below diagonal p = p + k - 1; % adjust index to account for offset if pivot == 0 % check for singularity error('A is singular') end if p = k % check if pivot row needs to be swapped % swap rows k and p in A and b A([k p],:) = A([p k],:); b([k p]) = b([p k]); end % perform elimination on rows below pivot for i = k+1:n % loop over rows below pivot m = A(i,k)/A(k,k); % compute multiplier A(i,k+1:n) = A(i,k+1:n) - m*A(k,k+1:n); % update row i of A b(i) = b(i) - m*b(k); % update entry i of b end end if A(n,n) == 0 % check for singularity again error('A is singular') end % perform back substitution to solve for x x = zeros(n,1); % initialize x as a column vector of zeros x(n) = b(n)/A(n,n); % solve for last entry of x for i = n-1:-1:1 % loop over remaining entries of x in reverse order x(i) = (b(i) - A(i,i+1:n)*x(i+1:n))/A(i,i); % solve for entry i of x end fprintf('Number of flops: %d\n',flops); % print number of flops end ``` The following example shows how to use the function gauss to solve a linear system:

### ```matlab >> A = [2 -1 0; -1 2 -1; 0 -1 2]; % define coefficient matrix A >> b = [1; 0; 0]; % define constant vector b >> x = gauss(A,b) % call gauss function to solve Ax=b Number of flops: 23 x = 0.7500 0.5000 0.2500 ``` Interpolation and curve fitting

Interpolation is a method for estimating the value of a function at a given point based on known values of the function at other points. Curve fitting is a method for finding a function that best fits a set of data points. 71b2f0854b