parametric vector form - matrix

39 次查看(过去 30 天)
Seungryul Lee
Seungryul Lee 2022-10-1
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