I need help with a matlab exercise.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

I need help with a matlab exercise.

Post by answerhappygod »

I need help with a matlab exercise.
I Need Help With A Matlab Exercise 1
I Need Help With A Matlab Exercise 1 (68.83 KiB) Viewed 13 times
Part II. Isomorphism & Change of Basis Exercise 3 (5 points) Difficulty: Hard In this exercise, you will be given a set B of n polynomials. The polynomials in B are from the subspace P₁-1 of the polynomials whose degrees do not exceed (n − 1). The standard basis for Pn-1 is E = {x-1, x-2, ...,x, 1}, where x is in R. You will determine whether the given set B forms a basis for Pn-1- That could be done by employing isomorphism from P₁-1 onto R" in the following way: first, we create a matrix P of the E-coordinate vectors of the polynomials in B and, then, we check if the set of the columns of P forms a basis for R". According to the isomorphism, the set of n polynomials in B forms a basis for the subspace P₁-1 if and only if the set of the n columns of P forms a basis for R". If the set B is not a basis for P-1, you will construct a new basis B by replacing some polynomials in the original set B with the polynomials from the standard basis E. Then, you will work with the basis B (original or constructed) and perform two more tasks: (1) You will find the B-coordinate vector, q, of a polynomial Q that is given in symbolic form through the standard basis E; (2) you will output the polynomial R in symbolic form through the standard basis E, given its B-coordinate vector r. For help with this exercise, you may find it useful to review the second Example in the Lecture Notes for Module 19. We will be using the function closetozeroroundoff () with p = 7 within our code. This function was created in Project 0 and you should have it in your Current Folder in MATLAB. **Create a function in a file that begins with function P-polyspace (B, Q, I) format n=numel (B); The input B = [B(1), B(2), ...,B(n)] is a vector whose n components are polynomials from the vector space P-1, the input Q is a single polynomial from the same space Pn-1: and r is a numerical column vector with n entries. The output P is a matrix whose columns are either the E-coordinate vectors of the polynomials in B if the polynomials form a basis for Pn-1 or a new matrix constructed using the E-coordinate vectors of the polynomials in B and some other polynomials such that its columns form a basis for R". Note: The number n introduced above is also the dimension of the vector space Pn-1; thus, Pn-1 is isomorphic to the Euclidean space R".
Note on the format of the input polynomials: The input polynomials will be written through the standard basis E in the descending order according to the degree. For the purpose of this program, it is required that the coefficient of the leading term x-1 of a polynomial must not be zero. However, the zero leading coefficient is accepted by the definition of the subspace P₁-1, and some of the input polynomials do not have term x-1, that is, the coefficient of x-1 is a zero. To be able to work with such polynomials, we insert the coefficient 10^(-8) of x-¹, and, then, we will convert it to a 0 by running the function closetozeroroundoff with p = 7 on the matrix P. **Continue your function polyspace with outputting the matrix P: First, pre-allocate a matrix P=zeros (n); and, then, re-assign to the ith column of P, P (:,1), the vector of coefficients of the polynomial B (1) using the command sym2poly (B (i)) (i=1:n). Note: in general, the command sym2poly () when applied to a polynomial written through the basis E outputs the row vector of the coefficients of the polynomial. Your output for this part will be the matrix P (do not display it here). **Then, convert to a 0 all entries of the matrix P that are in the range of 10^(-7) from a 0 by running the function: P=closetozeroroundoff (P, 7); and display the matrix P with a message: fprintf('matrix of E-coordinate vectors of the polynomials in B is\n') P Next, continue your code with a conditional statement that will check if the columns of P form a basis for R" - use here the command rank (). Note: do not employ command det () since the determinant of a matrix may be calculated in MATLAB with a round off error. **If the columns of P form a basis for R", output a message: fprintf('the polynomials in B form a basis for P%d\n', n-1) **Otherwise, if the columns of P do not form a basis for R", then, due to the isomorphism, the polynomials in B do not form a basis for Pn-1. In this case, output a message: fprintf('the polynomials in B do not form a basis for P%d\n', n-1) and continue your code for this case with constructing a basis for Pn-1 by removing some polynomials from B and adding to B some polynomials from the standard basis E. **To perform this task, run the function shrink as below: [~, P]=shrink ( [P eye (n)]); Notice that the columns of the new matrix P form a basis for R". This matrix P will be the matrix of the E-coordinates of the new set B of the polynomials in P-1, which, due to the isomorphism, forms a basis for Pn-1- Display the matrix P as below: disp('the new matrix P is') P
**Proceed with constructing the new set B in the following way: Use a "for" loop (i=1:n) and the function poly2sym that you will run on an ith column of P to output the polynomial B (i). The whole set of these polynomials will form a new basis B. Output and display the constructed basis B as below: disp('the constructed basis is') B This is the end of the conditional statement. After completing the conditional statement above, you will have as an output the matrix P of the E-coordinate vectors of the polynomials in the basis B, where B is either the original set or the constructed basis. The columns of P form a basis for R". **You will use the matrix P to proceed with two more tasks: (1) Given a polynomial Q written in symbolic form through the standard basis E, output the B-coordinate vector, q, of Q. Hint: First, use the MATLAB command sym2poly () that outputs the E-coordinate (row) vector of the polynomial Q. Then, transpose it to a column vector and run the function closetozeroroundoff with p = 7 on that vector to convert the leading entry to a 0 if needed. After that, you can proceed with outputting the B-coordinate vector q of Q using the Change- of-Coordinates (matrix) equation. Your displayed outputs for this part will be a message and the vector q as below: fprintf('the B-coordinate vector of Q is\n') q (2) Given the B-coordinate vector, r, of a polynomial R, output the polynomial R in symbolic form through the standard basis E. Hint: first, output the E-coordinate vector of the polynomial R by using the Change-of- Coordinates equation; next, run the function closetozeroroundoff with p = 7 on the output vector to convert to zero the entries that are within the given margin from a 0; and, finally, use the obtained vector and the command poly2sym () to output the required polynomial R. The displayed outputs for this part is a message and the polynomial R as below: fprintf('the polynomial whose B-coordinates form the vector r is\n') R This is the end of the function polyspace. **Print the functions closetozeroroundoff, shrink, and polyspace in the Live Script. **Then, type in the Live Script syms x This command introduces a symbolic variable x. It will allow you to input the polynomials in the variable x by typing (or copying and pasting) the inputs B and Q as they are given below.
** Run the function P-polyspace (B, Q, rB); on the choices (a)-(f) as indicated below: % (a) B=[x^3+3*x^2,10^(-8)*x^3+x,10^(-8)*x^3+4*x^2+x,x^3+x] Q-10^(-8)*x^3+x^2+6*x+3 r=[2; -1;3; -2] P-polyspace (B,Q,r); %(b) B=[x^3-1,10^(-8)*x^3+2*x^2,10^(-8)*x^3+x,x^3+x] P-polyspace (B,Q,r); % (c) B=[x^3+1,10^(-8)*x^3+x^2+1,10^(-8)*x^3+x+1,10^(-8)*x^3+1] Q-10^(-8)*x^3+3*x^2+x+6 r=[1; -4;2;3] P-polyspace (B,Q,r); % (d) B=[x^4+x^3+x^2+1,10^(-8)*x^4+x^3+x^2+x+1,10^(-8)*x^4+x^2+x+1,10^(- 8)*x^4+x+1,10^(-8)*x^4+1] Q-10^(-8)*x^4+3*x^3-1 r-diag(pascal (5)) P-polyspace (B,Q,r); %(e) B=[x^3+3*x^2,10^(-8)*x^3+x,x^3+3*x^2,2*x^3+6*x^2+x] Q-10^(-8)*x^3+x^2+6*x+3 r=[-1;3;2;4] P-polyspace (B,Q,r); % (f) B=[x^3+2*x^2+3*x+1,2*x^3+4*x^2+6*x+2,3*x^3+6*x^2+9*x+3,10^(-8)*x^3-2*x^2+1] Q-10^(-8)*x^3+x^2+6*x+3 r=[-2;1; -3;5] P-polyspace (B,Q,r); Note: Q and r in choice (b) are the same as in choice (a).
function B-closetozeroroundoff (A, p) A(abs (A) <10^-p)=0; B=A; end
function [pivot, B]=shrink (A) [~,pivot]=rref (A); B=A (:,pivot); end
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply