Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have this assignment for linear algebra and I am not sure how to do it. I was able to get the first 2 parts
I have this assignment for linear algebra and I am not sure how to do it.
I was able to get the first 2 parts of this assignment, but the last part I am not sure how to do. Here is the function that was to be made in project 1, thanks.
Exercise 4 (6 points) In this exercise, you will be solving a non-homogencous system Ax-b (b0) with a general mxn matrix A. The case when there are infinitely many solutions is included. Difficulty: Hard Note: the general solution of a consistent non-homogeneous system is the sum of the general solution of the corresponding homogencous system and a particular solution of the non- homogeneous system. The general solution of the homogeneous system, which has nontrivial solutions, is the Span of the columns of the matrix C, where C is an output of the function homobasis (see Projectl). The Span of the columns of C is also called the colurn space of C and denoted Col(C). Create a function in MATLAB, called nonhomogen, that begins with the lines: funet ion xenonhomogen (a,b) -.n-size(A) tprintf('Reduced echelon form of To create a function tc.p] -homobasis btA,b), you will need to add a few lines to that part of the code for homobasis that deals with the case when there are non-trivial solutions of [Ab] 8-> a homogencous system Specifically, you will need to generate the particular solution p of the non-homogeneous system in a similar way as you created matrix C. You can use the matrix R-zret(IA, bl) and obtain vector p modifying the last column of R. (Do not put semicolon after the line Rerre(A,b) to have R as an output the reduced echelon form of the augmented matrix A,b will allow you to verify your answers by hand.) Note please do not use fornat zat First, you need to determine whether the system is consistent and, if "yes", whether there is a unique solution or there are infinitely many solutions. You could use a conditional "if... elseif... else" statement. in the code for homobasis b to have the output matrices displayed in your diary file properly (I) If the equation Ax-b is not consistent, output the message The system inconsistent and the solution x has to be an empty vector (2) If the equation is consistent and the solution is unique output the message The syste has a unique solution and use the backslash operator, A b, to find the solution (see also Exercise 3 in this Project) (3) If the equation is consistent and there are infinitely many solutions- output a message Hint: You might find it helpful, first, write the solution on paper using the reduced echelon form of [A b] and, then, code it in your file. You may notice that the ordered entries of p corresponding to the free variables must be zero, and the other entries come from the last column of the matrix Rerref tA, bl The last line of the function homobasis b has to be a message that comments on the outputs C and p. This part of the code may be: disp(*The solution set of Axab is Span of the columns of C ranslated by vector P. where There are infinitely many solutions" To get the output x for this case, you, first, need to create another function in the file C.plhomobasis b(A, b which is a modification of the function c-homobasis (A) created in ProjectI. Here is a description of how to create the function hoobasis b - this message will comment on the outputs that follow: the matrix C and the vector p. Here is the final part of the function nonhomogen After you created the function homobasis b, you will insert the line into the code of the function nonhomogen for part (3) (when there are infinitely many solutions.) Note: do not put semicolon after (C.p- homobasis b(a,b) to have C and p displayed The last two lines in the code for nonhomogen have to be Sesond affcr you bave identitiod the froe variables and noe-pivot columes, you can proccod to constructing a spanning set of vectioes for the solution set, which are to form the columns of an nxq matrix C.Hint the matrix C has to be constructied using matrices nel A) and eyeg). Specifically, if amatrax E3s obtained him melIA) by emovag the prvot columns and pivot rows, then, the rows of C, whose indees are pivose match the rows of matrix (-B) and the rows of C whose indeses are from the set P Cor non pivet columns) match the rows of cyetq). Make sure that you will check your output matrix C on correctness by using mefA) Finally you would neod to dhock if you did find a basis for the solution sct of a homogenoous systom All the following condistions must hold: K1) the mumiber of noas of C is n(the number of entries in .2) the mumber of columns of C is q (the nurnber of free variables in the systom).(3) the columas of C are lincarly independons (equivalenly, rank(C) is oquals the number of columms of C), and (4) the columns odf C are solutions of As- (oquivaleatly A"Cis an mxqzcro matrix). Notc.There may be a peoblem with verifying the last condition due to a round eff enoe in calculating the matrix product, which may result in a very senall by absolute value entrics in places of zeros. There fore "you need to create another function in the file, named closetoze roroundott, that will replace the entries, which are smaller than 10-wits aceos The code is given below EXERCISE5 (6 points Difficulty: Hard Theory In this exercise, you will analyze the solution set of a homogeneous linear system Ax-0, where x R. and A is an mxn matrix. If the system has only the trivial solution (there are no free variables), the spanning set for the solution set consists of the zero vector only. If the system has non-trivial solutions (there is at least one free variable), the spanning set for the solutions obtained by solving the system by row reduction algorithm is also linearly independent and, therefore, forms a basis for the solution set. Later on, we will call the solution set of a homogeneous equation Ax = 0 the Null space of the matrix A: thus, in this exercise, we are creating a basis for the Null space of a matrix A Note: Before proceeding with programming, you are advised to solve a sample homogeneous system by hand using row reduction algorithm to see how the spanning set is formed and, then, program it in your file You will do the following: "Create a function in MATLAB starting with these lines: function c-homobasis(A) m-size (A,1) nesize (A,2) format rat red ech form rref (A EIA Note: The reduced echelon form of A has to be an output as well (do not place a semicolon at the end of the command red ech form zret (A)). This form will allow you to verify by the inspection whether the results you obtain are correct. First, your function has to check if the system has only the trivial solutionx-0. It happens if and only if all columns of A are pivot columns (no free variables). In this case, the outputs have to be: (1) the zero vector, C- zeros(n1), and the message: 'the homogeneous system has only the trivial solution Otherwise, there are free variables and non-pivot columns in A. This has to be stated with a message: the homogeneous system has non-trivial solutions Your code has to output the ordered indexes of the non-pivot columns. The command The product AC condition (4) will be seplaced with -caasataaroroundatt4AC); and 0 has to be n mxg aero malri If all 4 conditios hold, the output has to be a mossage C is a bis for the solution sst ofthe homogeneous system and the matris C has to be displayed, otherwise, the output message hem) r and honobaske in your diary file Run the functionchbais) on the llowing matricex a) At-3 4- 2-2 54 4 pivot cl-rref (A) gives the set of indexes of the pivot columns; the commands P-setdift (s.piot c) output the set of indexes of all columns (S) and the set of indexes of non-pivot columns (P) The set of commands below will help you to output the messages that list all free variables: q-length(P) () Aa(0 1 3a0 2 4 61 %Notice that the matrices in dg) and chidiffer only by ont entry Write a comment that would explain the differences in the spanning sets by fint analying the sets of the basis and ree fprintfA free varlable is P Exercise 4 (6 points) In this exercise, you will be solving a non-homogencous system Ax-b (b0) with a general mxn matrix A. The case when there are infinitely many solutions is included. Difficulty: Hard Note: the general solution of a consistent non-homogeneous system is the sum of the general solution of the corresponding homogencous system and a particular solution of the non- homogeneous system. The general solution of the homogeneous system, which has nontrivial solutions, is the Span of the columns of the matrix C, where C is an output of the function homobasis (see Projectl). The Span of the columns of C is also called the colurn space of C and denoted Col(C). Create a function in MATLAB, called nonhomogen, that begins with the lines: funet ion xenonhomogen (a,b) -.n-size(A) tprintf('Reduced echelon form of To create a function tc.p] -homobasis btA,b), you will need to add a few lines to that part of the code for homobasis that deals with the case when there are non-trivial solutions of [Ab] 8-> a homogencous system Specifically, you will need to generate the particular solution p of the non-homogeneous system in a similar way as you created matrix C. You can use the matrix R-zret(IA, bl) and obtain vector p modifying the last column of R. (Do not put semicolon after the line Rerre(A,b) to have R as an output the reduced echelon form of the augmented matrix A,b will allow you to verify your answers by hand.) Note please do not use fornat zat First, you need to determine whether the system is consistent and, if "yes", whether there is a unique solution or there are infinitely many solutions. You could use a conditional "if... elseif... else" statement. in the code for homobasis b to have the output matrices displayed in your diary file properly (I) If the equation Ax-b is not consistent, output the message The system inconsistent and the solution x has to be an empty vector (2) If the equation is consistent and the solution is unique output the message The syste has a unique solution and use the backslash operator, A b, to find the solution (see also Exercise 3 in this Project) (3) If the equation is consistent and there are infinitely many solutions- output a message Hint: You might find it helpful, first, write the solution on paper using the reduced echelon form of [A b] and, then, code it in your file. You may notice that the ordered entries of p corresponding to the free variables must be zero, and the other entries come from the last column of the matrix Rerref tA, bl The last line of the function homobasis b has to be a message that comments on the outputs C and p. This part of the code may be: disp(*The solution set of Axab is Span of the columns of C ranslated by vector P. where There are infinitely many solutions" To get the output x for this case, you, first, need to create another function in the file C.plhomobasis b(A, b which is a modification of the function c-homobasis (A) created in ProjectI. Here is a description of how to create the function hoobasis b - this message will comment on the outputs that follow: the matrix C and the vector p. Here is the final part of the function nonhomogen After you created the function homobasis b, you will insert the line into the code of the function nonhomogen for part (3) (when there are infinitely many solutions.) Note: do not put semicolon after (C.p- homobasis b(a,b) to have C and p displayed The last two lines in the code for nonhomogen have to be Sesond affcr you bave identitiod the froe variables and noe-pivot columes, you can proccod to constructing a spanning set of vectioes for the solution set, which are to form the columns of an nxq matrix C.Hint the matrix C has to be constructied using matrices nel A) and eyeg). Specifically, if amatrax E3s obtained him melIA) by emovag the prvot columns and pivot rows, then, the rows of C, whose indees are pivose match the rows of matrix (-B) and the rows of C whose indeses are from the set P Cor non pivet columns) match the rows of cyetq). Make sure that you will check your output matrix C on correctness by using mefA) Finally you would neod to dhock if you did find a basis for the solution sct of a homogenoous systom All the following condistions must hold: K1) the mumiber of noas of C is n(the number of entries in .2) the mumber of columns of C is q (the nurnber of free variables in the systom).(3) the columas of C are lincarly independons (equivalenly, rank(C) is oquals the number of columms of C), and (4) the columns odf C are solutions of As- (oquivaleatly A"Cis an mxqzcro matrix). Notc.There may be a peoblem with verifying the last condition due to a round eff enoe in calculating the matrix product, which may result in a very senall by absolute value entrics in places of zeros. There fore "you need to create another function in the file, named closetoze roroundott, that will replace the entries, which are smaller than 10-wits aceos The code is given below EXERCISE5 (6 points Difficulty: Hard Theory In this exercise, you will analyze the solution set of a homogeneous linear system Ax-0, where x R. and A is an mxn matrix. If the system has only the trivial solution (there are no free variables), the spanning set for the solution set consists of the zero vector only. If the system has non-trivial solutions (there is at least one free variable), the spanning set for the solutions obtained by solving the system by row reduction algorithm is also linearly independent and, therefore, forms a basis for the solution set. Later on, we will call the solution set of a homogeneous equation Ax = 0 the Null space of the matrix A: thus, in this exercise, we are creating a basis for the Null space of a matrix A Note: Before proceeding with programming, you are advised to solve a sample homogeneous system by hand using row reduction algorithm to see how the spanning set is formed and, then, program it in your file You will do the following: "Create a function in MATLAB starting with these lines: function c-homobasis(A) m-size (A,1) nesize (A,2) format rat red ech form rref (A EIA Note: The reduced echelon form of A has to be an output as well (do not place a semicolon at the end of the command red ech form zret (A)). This form will allow you to verify by the inspection whether the results you obtain are correct. First, your function has to check if the system has only the trivial solutionx-0. It happens if and only if all columns of A are pivot columns (no free variables). In this case, the outputs have to be: (1) the zero vector, C- zeros(n1), and the message: 'the homogeneous system has only the trivial solution Otherwise, there are free variables and non-pivot columns in A. This has to be stated with a message: the homogeneous system has non-trivial solutions Your code has to output the ordered indexes of the non-pivot columns. The command The product AC condition (4) will be seplaced with -caasataaroroundatt4AC); and 0 has to be n mxg aero malri If all 4 conditios hold, the output has to be a mossage C is a bis for the solution sst ofthe homogeneous system and the matris C has to be displayed, otherwise, the output message hem) r and honobaske in your diary file Run the functionchbais) on the llowing matricex a) At-3 4- 2-2 54 4 pivot cl-rref (A) gives the set of indexes of the pivot columns; the commands P-setdift (s.piot c) output the set of indexes of all columns (S) and the set of indexes of non-pivot columns (P) The set of commands below will help you to output the messages that list all free variables: q-length(P) () Aa(0 1 3a0 2 4 61 %Notice that the matrices in dg) and chidiffer only by ont entry Write a comment that would explain the differences in the spanning sets by fint analying the sets of the basis and ree fprintfA free varlable is PStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started