Output argument <Variable> (and maybe others) not assigned during call to <Function>.
Show older comments
I have a function that currently works perfectly:
function [x,cv] = mybasic(A,b,M,x,TOL,nmax)
% Basic iteration x <- x+M\(b-A*x)
x = x(:); % make sure initial guess is column vector
r = b-A*x;
e = M\r;
err0 = norm(e); % euclidean magnitude
rerr = 1; % relative error
n = 0;
if nargout==2
cv = zeros(nmax+1,2+length(x)); % preallocate space for cv
cv(1,:) = [n,x.',rerr]; % iter. #, iterate (row vector), rel. error
end
while (rerr>TOL && n<nmax)
x = x+e;
r = r-A*e;
e = M\r;
rerr = norm(e)/err0;
n = n+1;
if nargout==2
cv(n+1,:) = [n,x.',rerr];
end
end
n
if nargout==2
cv(n+2:end,:) = []; % delete unused space in cv
end
if rerr>TOL && n==nmax
warning('MYBASIC:noCV','no cv within %i iterations',n)
end
end
However, if all I do is change the function output to [n,x,cv] instead and try and run the function with a script file, I end up getting the error Output argument "cv" (and maybe others) not assigned during call to "mybasic". Here is the script I am trying to use:
A = [1,.375,.375;.375,1,.375;.375,.375,1];
b = [1;1;1];
M = diag(diag(A));
TOL = 1e-5;
nmax = 100;
x0 = zeros(3,1);
[n,x,cv] = mybasic(A,b,M,x0,TOL,nmax);
Please help. Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Signal Processing Toolbox 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!