Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The given csolve.m is % This function finds the rank, pivot variables, and free

ID: 3281644 • Letter: T

Question

The given csolve.m is

% This function finds the rank, pivot variables, and free variables of a

% matrix.

% Input: m x n matrix A.

% Output: Text stating the rank, pivot, and free variables of the matrix A.

function csolve(A)

[m,n] = size(A);

pivot = []; % initialize "pivot"

free = 1:1:n; % initialize "free"

R = rref(A); % rref(A) returns reduced row echlon form of A

for i = 1:m % visit every row

    for j = 1:n % visit every column

        if R(i,j) == 1 % check for a leading 1

            pivot = [pivot,j]; % save the pivot column

            break; % terminate the inner for loop

        end

    end

end

free([pivot]) = '';

% Print the results.

fprintf('The rank of the coefficient matrix is %d. ', length(pivot));

fprintf('Pivot variables:');

for i = 1:length(pivot)

    fprintf(' %d', pivot(i));

end

fprintf(' ');

fprintf('Free variables:');

for i = 1:length(free)

    fprintf(' %d', free(i));

end

fprintf(' ');

end

Submit your m-file and a diary that shows how you tested the code. Modify csolve.m so that it outputs pivot and free. Then call upon this function in csolvefull.m. Submit the m-file for csolvefull.m, but not csolve.nm Create a function csolveful1.m with input matrix A and a column vector b and no output. The function should display the rank, the pivot and free variables of A, the particular solution to Ax - b, and the special solutions for A. Test it using the system below 11 5 826 4 0 2-2-5 15 -36-12 -8 -5 1 3-1 7 6 2 A= Your display should be precisely the following >>csolvefull(A,b) The rank of the coefficient matrix is 3 Pivot variables: 1 2 5 Free variables: 3 4 The particular solution is: -0.4413 -0.0829 0 0.3981 The special solutions are 0.5000 -0.5000 -1.5000 0.5000 1 1.0000 0 1.0000 0.0000 0.0000

Explanation / Answer

function csolve(A)

[rows, columns] = size(A)

pivot = [];

free = []; for i = 1:columns

free(i) = i;

end

R = rref(A);

disp(R); fprintf(' ');

for i = 1:rows

for j = 1:columns-1 %TODO : Make it to columns instead of columns-1, after verification

if R(i, j) == 1

pivot = [pivot j];

break;

end

end

end

free = setdiff(free, pivot);

fprintf("rank of coefficient of matrix is %d ",length(pivot));

fprintf("pivot variables : ");

disp(pivot); fprintf("free variables : ")

disp(free);

end

A = [1 -8 -7 5; 0 0 -3 2; 1 -8 -10 8];

disp(A);

csolve(A);

To find pivot columns, the algorithm says to consider all columns, in each row, which has a leading 1 , but in the given example the last column has leading 1 in reduced echleon form, but it is not considered. This usually happens in case of augmented matrix. Make the change in the second for loop specified as TODO, in the above code, based on your definition of pivot colum

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote