Hello I am looking for help writing the MATLAB function p p

Hello, I am looking for help writing the MATLAB function p = proj(A,b)

which computes the projection of b onto the Column Space of an m x n matrix A. The program should allow a possibility that the columns of A are not linearly independent. For the algorithm to work, there is a need to create a basis for Col A.

**A basis can be produced with the function shrink that you should create in MATLAB. Here is the code:

function B = shrink(A)

format compact,

[~, pivot] = rref(A);

B = A(: , pivot);

Also, to save a space in the file, all input vectors must be row vectors and you can use a MATLAB command transpose to make the adjustments for the outputs to be row vectors as well. Note: the MATLAB command transpose(X) is the same as X \' .

Hint: A vector p is the orthogonal projection of a vector b onto Col A, when the columns of A are linearly independent, if and only if p x = Aˆ , where xˆ is the solution of the normal equations:

(AT)(Ax) = (AT)(b)

Also, if p is the orthogonal projection of a vector b onto Col A, then the vector b can be written as bpz = + , where z is the unique vector orthogonal to Col A.

The function proj(A,b) should begin with:

format compact,

A=shrink(A);

b=transpose(b);

(Remember, the input vector b must be a row vector, therefore, we convert it into a column vector by transposing in order to solve the normal equations).

Then, the program has to check if the input vector b has exactly m entries, where m is the number of columns in AT . If it doesn’t, the program breaks with a message: “No solution: dimensions of A and b disagree” and returns “p=empty_vector”. I could type the following lines in your code:

disp(‘No solution: dimensions of A and b disagree’)

p=sym(‘empty_vector’);

return

I have some ideas, but really need some help on how to figure this out and find the code, thank you.

Solution

MATLAB
should look. A page similar to the one below has to be created in MATLAB for each exercise
and called exercise# (please put the corresponding number). The file will be created by using
the command diary exercise#. After the file diary exercise# is initiated, the next command
will be diary on – the beginning of recording. Everything that you put in the Command
Window will be recorded in the created file. The command diary off will end up the
recording. Within the diary file: the command type function name types the function that has
to be previously created using the text editor and saved in MATLAB with the extension .m.
Then you should assign values to the arguments in the function and call the function. Please
refer to MATLAB help page on the subject of creating functions in files:
http://www.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html
After you got the required outputs, execute the last command diary off and your file is ready
for printing. The printed “diary” file for each exercise has to be turned in as a part of the
Project.
Example of the function “add” placed into a “diary file” and executed:
diary on
type add
function c=add(a,b)
% c=add(a,b). This is the function which adds
% the matrices a and b. It duplicates the MATLAB
% function a+b.*
[m,n]=size(a);
[k,l]=size(b);
if m~=k | n~=l,
disp(\'ERROR using add: matrices are not the same size\')

Hello, I am looking for help writing the MATLAB function p = proj(A,b) which computes the projection of b onto the Column Space of an m x n matrix A. The progra
Hello, I am looking for help writing the MATLAB function p = proj(A,b) which computes the projection of b onto the Column Space of an m x n matrix A. The progra

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site