I am trying to use a predefined conjugate gradient in matlab to speed up the process. I use this iterative method because the backslash operator is too long. However, I am having some problems. E.g. I want to solve this system of linear equations given
Ax=B
where A is a sparse positive definite matrix, and B is also a matrix. In matlab, I can do it simply
x= A\B
However, if I use the pcg function, then I will have to iterate over all columns of B and solve individual
x(:,i)=pcg(A,B(:,i))
This cycle will take longer than x = A \ B. If I consider only one column as b instead of matrix B, then pcg is faster than the backslash operator. However, if I look at the whole matrix B, then pcg is slower than the backslash operator. Thus, it makes no sense to use pcg.
Any suggestions guys?
When using the method suggested by Mattj, it shows the following error:
Error using iterapp (line 60)
user supplied function ==>
@(x)reshape(repmat(A*x,1,nb),[],1)
failed with the following error:
Inner matrix dimensions must agree.
Error in pcg (line 161)
r = b -
iterapp('mtimes',afun,atype,afcnstr,x,varargin{:});
source
share