28.12.2012 Views

Figure Properties - SERC

Figure Properties - SERC

Figure Properties - SERC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Examples Example 1.<br />

A = gallery('wilk',21);<br />

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

tol = 1e-12;<br />

maxit = 15;<br />

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

gmres<br />

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

gmres(10) converged at iteration 2(10) to a solution with relative<br />

residual 1.9e-013<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 gmres<br />

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

Note that both afun and mfun must accept the gmres extra input n=21.<br />

Example 2.<br />

load west0479<br />

A = west0479<br />

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

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

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

the default 10 outer iterations.<br />

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

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

2-983

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

Saved successfully!

Ooh no, something went wrong!