23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

icgstab<br />

2-156<br />

M1 = diag([10:-1:1 1 1:10]);<br />

x = bicgstab(A,b,tol,maxit,M1,[],[]);<br />

bicgstab converged at iteration 12.5 to a solution with relative<br />

residual 1.2e-014<br />

Alternatively, use this matrix-vector product function<br />

function y = afun(x,n)<br />

y = [0;<br />

x(1:n-1)] + [((n-1)/2:-1:0)';<br />

(1:(n-1)/2)'] .*x + [x(2:n);<br />

0];<br />

and this preconditioner backsolve function<br />

function y = mfun(r,n)<br />

y = r ./ [((n-1)/2:-1:1)'; 1; (1:(n-1)/2)'];<br />

as inputs to bicgstab<br />

x1 = bicgstab(@afun,b,tol,maxit,@mfun,[],[],21);<br />

Note that both afun and mfun must accept bicgstab's extra input n=21.<br />

Example 2.<br />

load west0479;<br />

A = west0479;<br />

b = sum(A,2);<br />

[x,flag] = bicgstab(A,b)<br />

flag is 1 because bicgstab does not converge to the default tolerance 1e-6<br />

within the default 20 iterations.<br />

[L1,U1] = luinc(A,1e-5);<br />

[x1,flag1] = bicgstab(A,b,1e-6,20,L1,U1)<br />

flag1 is 2 because the upper triangular U1 has a zero on its diagonal. This<br />

causes bicgstab to fail in the first iteration when it tries to solve a system such<br />

as U1*y = r using backslash.<br />

[L2,U2] = luinc(A,1e-6);<br />

[x2,flag2,relres2,iter2,resvec2] = bicgstab(A,b,1e-15,10,L2,U2)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!