MATLAB: ??? Output argument “bg” (and maybe others) not assigned during call to

assiging problem

Step 2 find the largest and smallest
[p1,s1]=eig(A);
[P,D]=sortem(p1,s1);
lmin = D(n,n)
lmax = D(1,1)
Step 3 Initialization
l=2; % Number of lanczos iteration that we want
l=l+2; % change because of the algorithm
%b = A*ones(n,1);
b = P(:,1)
tol = 10e-8
x0 = zeros(n,1)
[x,r,bg,bgrl,bgru,bgl] = CGQL(A,b,x0,n,lmin,lmax,tol,l);
When I run this program(above code is just the part of the program) I'm getting this error when b=P(:,1)
Error in ==> CGQL at 24 x(:,1) = x0;
??? Output argument "bg" (and maybe others) not assigned during call to "/home/meerkat/Desktop/Work/Golub/CG/CGQL.m>CGQL".
But when i change b=A*ones(n,1) (commented in the above code) it will run I'm not getting what error is this as the dimension of the matrix A and P are same.

Best Answer

When you call CGQL(), somehow the CGQL() function goes all the way through and exits without ever assigning a value for bg. Make sure that "bg" gets assigned internally to CGQL(). Common mistakes are not initializing bg right at the start of your function and then assigning bg inside an "if" block that never gets executed. Also, make sure that you are accepting the same number of output arguments (6) as CGQL() sends back.