Docsity

MCEN 3030: Homework 2 - Linear Equations and Curve Fitting, Assignments of Mechanical Engineering

Toggle sidebar
bg1
1
MCEN 3030: Homework 2: 70pts
Due date: Monday, February 13th, 2006 at the beginning of the lecture.
LU (50pts):
Develop, debug, and test a program (MATLAB m-file) that solves a system of
linear equations Ax =busing Doolittle LU decomposition with partial pivoting
(on columns). (Important: do not perform Crout LU decomposition, you will
be given no credits for it.) The code should be able to solve for an arbitrary
square mƗmmatrix A.
You should provide 2 different functions:
[P,L,U,flag] = LUDecompose(A);
and
[x] = LUBacksub(P,L,U,b);
The first function would compute the LU decomposition while the second one
would take care of solving the problem LUx =bgiven L,U,band the per-
mutation vector P. The flag is an error variable to use before entering the
substitution code.
Consider the possibility that matrix A is not invertible. This will happen dur-
ing the LU decomposition process: you will encounter a zero diagonal element.
This can only happen if the rows or columns are linearly dependent. If this
happens, your program should display an error message before stopping like:
ā€error: matrix is rank deficientā€.
If possible, solve the following systems of linear equations with your own pro-
gram:
A)


0 1 āˆ’1
132
āˆ’1 2 1



x1
x2
x3

=

4
4
8


B)


110
132
022



x1
x2
x3

=

1
0
1


C)




2 2 1 3
2āˆ’1āˆ’1 3
1āˆ’1āˆ’1 4
3 3 4 1








x1
x2
x3
x4




=



1
3
0
9




Check you results by substituting xinto Ax and compare it with b. If
your code is correct, Ax should be identical to b. If your code can not solve
pf3

Partial preview of the text

Download MCEN 3030: Homework 2 - Linear Equations and Curve Fitting and more Assignments Mechanical Engineering in PDF only on Docsity!

MCEN 3030: Homework 2: 70pts

Due date: Monday, February 13th, 2006 at the beginning of the lecture.

LU (50pts):

Develop, debug, and test a program (MATLAB m-file) that solves a system of linear equations Ax = b using Doolittle LU decomposition with partial pivoting (on columns). (Important: do not perform Crout LU decomposition, you will be given no credits for it.) The code should be able to solve for an arbitrary square m Ɨ m matrix A.

You should provide 2 different functions:

[P,L,U,flag] = LUDecompose(A);

and

[x] = LUBacksub(P,L,U,b);

The first function would compute the LU decomposition while the second one would take care of solving the problem LU x = b given L,U , b and the per- mutation vector P. The f lag is an error variable to use before entering the substitution code. Consider the possibility that matrix A is not invertible. This will happen dur- ing the LU decomposition process: you will encounter a zero diagonal element. This can only happen if the rows or columns are linearly dependent. If this happens, your program should display an error message before stopping like: ā€error: matrix is rank deficientā€.

If possible, solve the following systems of linear equations with your own pro- gram: A) (^) 



x 1 x 2 x 3

B) 

x 1 x 2 x 3

C) 

x 1 x 2 x 3 x 4

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 a solution and something is wrong with your code. Email your code (m-file). 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 out.

Rectangular systems (20pts)

Given a set of points (xi, yi) ∈ R^2 , j = 1, ..., N that comes from some experiment and that we believe would either lie on some curve if it were not from experi- mental error, what would be the curve that best approximate these points? Suppose that the data behaves like a line yi = bxi + c and that we seek b, c that works for all xi and yi. The resulting system describing the problem would be :

    

x 1 1 x 2 1 .. .

xN 1

[

b c

]

y 1 y 2 .. . yN

If the curve sought was a parabola then the system

   

x^21 x 1 1 x^22 x 2 1 .. .

x^2 N xN 1

a b c

y 1 y 2 .. . yN

would describe the (over-determined) problem. These problems written as Ax = b have no unique solutions. This unsolvable problem can be replaced by the solvable one Axˆ = ˆb where ˆb is as close as possible to b and yet does lie in the column space of A. Thus, the best ˆb will be the one orthogonal to the column space of A namely

AT^ (ˆb āˆ’ b) = AT^ (Aˆx āˆ’ b) = 0

or equivalently (AT^ A)ˆx = AT^ b.

Download from the MCEN3030 website

http://scales.colorado.edu/classes/MCEN3030_S2006/assignments.html

the file xyexperiment.mat is under the link Data for this homework. Place the file where matlab can read it (ie check your path settings). Load the data in matlab using the load command. Now if you type xy you will see that it contains an array of data with two columns: one for xi the other for yi.