how to solve A*x=b, if A is a singular matrix;
Show older comments
hello, everyone! I am using hte following code to build the matrix New_P and New_Pg, in order to solve New_P*h=New_Pg; Because, the matrix New_P has a possibility of singular, so I use the pinv function. However, it turns out this make the computation very solw, escepically when the size of the matrix growing largely. I wonder if there exist any way to replace the pinv function or to optimize the code. Thank you very much!
S=size(P,1);
if n<=10
New_P=P(sub2ind(size(P),repmat((1:size(P,1))',1, size(P,2)), repmat(1:size(P,2), size(P,1), 1), repmat(U0, 1,size(P,2))));
else
New_P=zeros(S,S);
for s=1:S
New_P(s,:)=P(s,:,U0(s));
end;
end;
New_Pg=g(:,1);
New_P=cat(2,ones(S,1),eye(S)-New_P);
New_P(S+1,t+1)=1; % set state 1 as the reference state;
New_Pg=[New_Pg;0];
if rcond(New_P)>=eps('double')
h0=New_P\New_Pg;
else
h0=pinv(New_P)*New_Pg; % pinv is very unefficient, but it is mostly used in sigular matrix.
end;
h0=h0(2:end);
Accepted Answer
More Answers (0)
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!