MAT343_LAB02_v3.pdf - MATLAB sessions Laboratory 2 MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming In this laboratory session we

MAT343_LAB02_v3.pdf - MATLAB sessions Laboratory 2 MAT 343...

This preview shows page 1 - 3 out of 9 pages.

MATLAB sessions: Laboratory 2 MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming In this laboratory session we will learn how to 1. Solve linear systems with MATLAB 2. Create M-files with simple MATLAB codes Backslash or Matrix Left Division If A is an n × n matrix and b represents a vector in R n , the solution of the system A x = b can be computed using MATLAB’s backslash operator by setting x = A \ b The “ \ ” operator command invokes an algorithm which depends upon the structure of the matrix A . Depending on the structure of the matrix, the algorithm employs different matrix factorization tech- niques to solve the system, some of which you will learn in later chapters (e.g., the LU decomposition and the QR factorization). For example, if we set A = [1,1,1,1;1,2,3,4;3,4,6,2;2,7,10,5] and b = [3;5;5;8] , then the command x = A \ b will yield x = 1.0000 3.0000 -2.0000 1.0000 In the case that the coefficient matrix is singular (or “close” to singular), the backslash operator will still compute a solution, but MATLAB will issue a warning. For example, the 4 × 4 matrix A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (L2.1) is singular and the command x = A \ b (with the same vector b as above) yields Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.755481e-18. x = 1.0e+15 * 2.2153 -5.6648 4.6837 -1.2342 The 1.0e+15 indicates the exponent for each of the entries of x . Thus, each of the four entries listed is multiplied by 10 15 . The value of RCOND is an estimate of the reciprocal of the condition number of the coefficient matrix. The condition number is a way to measure how sensitive the matrix is to round off error. Even if the matrix were nonsingular, with a condition number of the order of 10 18 , one could expect to lose as much as 18 digits of accuracy in the decimal representation of the computed solution. Since the computer keeps track of only 16 decimal digits, this means that the computed solution may THIS CONTENT IS PROTECTED AND MAY NOT BE SHARED, UPLOADED, SOLD, OR DISTRIBUTED - c 2018 Stefania Tracogna, SoMSS, ASU 1
Image of page 1

Subscribe to view the full document.

MATLAB sessions: Laboratory 2 not have any digit of accuracy. Remark: You can verify that the system A x = b , with A given by (L2.1), is inconsistent by com- puting the RREF of the augmented matrix: rref([A, b]) . If the coefficient matrix for a linear system has more rows than columns, then MATLAB assumes that a least squares solution of the system is desired (you will learn about least squares in Chapter 5). If we set C = A(:,1:2) then C is a 4 × 2 matrix and the command x = C \ b will compute the least squares solution x = -2.2500 2.6250 EXERCISES Instructions: For the following three problems, follow the instructions in LAB 1 to create a diary text file. 1. (a) Set n = 1000. The commands below generate an n × n random matrix with integer entries between 0 and 9, an n × 1 vector z with all entries equal to 1, and an n × 1 vector b given by the product A z .
Image of page 2
Image of page 3

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes