How to use pcg with a function in MATLAB -


i going solve inverse problem, ax=b, using conjugate gradient method in matlab. want use pcg function in matlab , know instead of matrix a can use function.

i have function example afun has entries. in documents, have seen afun function entered in pcg function without entries, however, when same, error not enough input arguments appears. use code this:

b = afun(ent1,ent2); x = pcg(@afun,b,tol,max_iter); 

how should use function in pcg?

according documentation, function handle should have signature afun(x) , return a*x.

your function apparently takes 2 inputs... need use anonymous function wrap call, this:

% dont know these ent1/ent2 represent exactly, % must complete ".." part first fcn = @(x) afun(x, ..)  % can call pcg x = pcg(fcn, b, tol, maxiter); 

there doc page explaining how parameterize functions pass args using function handles.


Comments