Computational Methods - MATLAB Project 2 | MCEN 3030, Study Guides, Projects, Research of Mechanical Engineering

Material Type: Project; Professor: Vasilyev; Class: COMPUTATIONAL METHODS; Subject: Mechanical Engineering; University: University of Colorado - Boulder; Term: Unknown 1989;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 02/10/2009

koofers-user-wd1-1
koofers-user-wd1-1 🇺🇸

5

(1)

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computational Project # 2
Due September 25
Develop, debug, and test a program (MATLAB m-file) that solves a system of linear equations
=
Ax b
using Gauss-Jordan elimination with complete pivoting. Organize you code in such way that the
following two procedures are called from the loop:
1. complete pivoting operation – given an arbitrary matrix, the procedure identifies the
element of the matrix that has the largest absolute value and swaps corresponding row
and column with the first row and first column of the matrix.
2. Gauss-Jordan elimination step – given an arbitrary matrix A, use Aii element to eliminate
all the other elements in i-th column of the matrix.
The code should be able to solve for arbitrary rectangular nn
×
matrix A and right hand-side b.
Organize your code such a way that both matrix A and vector b are the input parameters and
vector x and pivoting vectors Prow and Pcolumn are your output arguments.
Consider the possibility that matrix A is rank-deficient and the system does not have the solution.
This will happen when in the process of pivoting you will encounter zero (or very small)
diagonal element. This can only happen if the rows or columns are linear dependent. If this
happen, make your program should display the error message like “error: matrix is rank
deficient” and stop.
If possible, solve the following systems of linear equations with your own program:
a) b)
1
2
3
01 1 1
11 2 1
04 2 2
x
x
x
⎡⎤
⎡⎤
⎢⎥
⎢⎥
=−
⎢⎥
⎢⎥
⎢⎥
⎢⎥
⎣⎦
⎣⎦
1
2
3
01 1 1
11 2 0
24 2 1
x
x
x
⎡⎤
⎤⎡
⎢⎥
⎥⎢
=
⎢⎥
⎥⎢
⎢⎥
⎥⎢
⎦⎣
⎣⎦
c)
1
2
3
4
01 14 5
112 1 2
01 20 2
13 0 1 0
x
x
x
x
⎡⎤
⎡⎤
⎢⎥
⎢⎥
−−
⎢⎥
⎢⎥
=
⎢⎥
⎢⎥
⎢⎥
⎢⎥
⎣⎦
⎣⎦
Check you results by substituting x into Ax and compare it with b. If your code is correct, Ax
should be identical to b. If your code can not solve the problem, see whether you can invert the
matrix using MATLAB internal procedure, inv(A). If you can, then the problem definitely has
the solution and something is wrong with your code.
P.S. Email your code to [email protected]. The program that you send should be a
working program. All the codes will be checked whether they run or not. If they are erroneous,
but run, points will be taken for the errors. If the code is not running (it has some syntax
errors), an additional 25% will be taken off. The goal of this class is for you to be comfortable
solving engineering problems. Please take your time and learn how to trust the computer.

Partial preview of the text

Download Computational Methods - MATLAB Project 2 | MCEN 3030 and more Study Guides, Projects, Research Mechanical Engineering in PDF only on Docsity!

Computational Project # 2

Due September 25

Develop, debug, and test a program (MATLAB m-file) that solves a system of linear equations Ax = b

using Gauss-Jordan elimination with complete pivoting. Organize you code in such way that the following two procedures are called from the loop:

  1. complete pivoting operation – given an arbitrary matrix, the procedure identifies the element of the matrix that has the largest absolute value and swaps corresponding row and column with the first row and first column of the matrix.
  2. Gauss-Jordan elimination step – given an arbitrary matrix A , use A ii element to eliminate all the other elements in i -th column of the matrix. The code should be able to solve for arbitrary rectangular n × n matrix A and right hand-side b. Organize your code such a way that both matrix A and vector b are the input parameters and vector x and pivoting vectors P row and P column are your output arguments.

Consider the possibility that matrix A is rank-deficient and the system does not have the solution. This will happen when in the process of pivoting you will encounter zero (or very small) diagonal element. This can only happen if the rows or columns are linear dependent. If this happen, make your program should display the error message like “error: matrix is rank deficient” and stop.

If possible, solve the following systems of linear equations with your own program:

a) b)

1 2 3

x x x

⎡ − ⎤ ⎡^ ⎤ ⎡

⎢ ⎥ ⎢^ ⎥ ⎢

⎢ ⎥ ⎢^ ⎥=^ ⎢−

⎢⎣ − ⎥⎦ ⎢⎣^ ⎥⎦ ⎢⎣

1 2 3

x x x

⎡ −⎤ ⎡^ ⎤ ⎡

c)

1 2 3 4

x x x x

⎡ −^ ⎤ ⎡^ ⎤

⎢ ⎥ ⎢^ ⎥=

⎢ − ⎥⎢^ ⎥

⎢ ⎥⎢^ ⎥

Check you results by substituting x into Ax and compare it with b. If your code is correct, Ax should be identical to b. If your code can not solve the problem, see whether you can invert the matrix using MATLAB internal procedure, inv(A). If you can, then the problem definitely has the solution and something is wrong with your code.

P.S. Email your code to [email protected]. The program that you send should be a working program. All the codes will be checked whether they run or not. If they are erroneous, but run, points will be taken for the errors. If the code is not running (it has some syntax errors), an additional 25% will be taken off. The goal of this class is for you to be comfortable solving engineering problems. Please take your time and learn how to trust the computer.