parametric vector form - matrix

조회 수: 39 (최근 30일)
Seungryul Lee
Seungryul Lee 2022년 10월 1일
댓글: Dyuman Joshi 2022년 10월 2일
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
Dyuman Joshi
Dyuman Joshi 2022년 10월 2일
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?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by