parametric vector form - matrix
    26 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi, I have a function pvss that takes as input the coefficient matrix and right hand side of a linear system and returns the parametric vector form of the solution.
And these are the formats:

And here is my code:
function [sscount, p, V] = pvss(A,b)
% For the linear system Ax=b finds the parametric vector form of the solution.
% If no solutions sscount=-1; otherwise, sscount is number of free variables
% p is the particular solution with the free variables equal to zero (empty if sscount== -1)
% ith column of V is the homogeneous solution corresponding to the ith free variable (empty if sscount <= 0)
    Augmented = [A b];
    [m, n] = size(Augmented);
    [R, pclist] = rref(Augmented);         % rreduced row echelon form and pivot column list
    r = size(pclist,2);                    % number of pivot columns (rank(A))
    %   CASE OF AN INCONSISTENT SYSTEM
    if r>0 && pclist(r)==n
        sscount = -1;
        p = zeros(n-1,0);
        V = zeros(n-1,0);
    else
        sscount=n-r;
    %   OBTAIN THE PARTICULAR SOLUTION
        p = zeros(n-1,1);     
        p(pclist) = R(1:r,n);    
    %   OBTAIN THE HOMOGENEOUS SOLUTIONS CORRESPONDING TO EACH FREE VARIABLE (IF ANY)
        V(pclist,:) = -R(1:r,n);        %  UPDATE: copy appropriately pivot rows of V from R
        V(n,:) = eye(sscount);
    end
    %  UPDATE: set free rows of V appropriately
end
And this is the code to call the function:
A=[1 2 3; 4 5 6; 7 8 9]
b=[1; 1; 1]
[sscount, p, V] = pvss(A,b)
I've tested with some cases, and I passed a few tests, but I'm keep getting an error for this example

How should I fix my code to get a correct output for all sizes of matrix?
1 comentario
  Dyuman Joshi
      
      
 el 2 de Oct. de 2022
				You are assigning a matrix to a row (as stated in the error as well), which is not possible.
V(n,:) = eye(sscount)
What exactly do you want to perform with respect to this line of code?
In case of a particular solution, what is the expected size of V?
Respuestas (0)
Ver también
Categorías
				Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

