-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptsTP1.m
29 lines (28 loc) · 769 Bytes
/
scriptsTP1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
n=1000;m=15;In=eye(n);Im=eye(m);
A=3*In-diag(ones(n-1,1),-1)-diag(ones(n-1,1),1);
b=A*ones(n,1);
x0=zeros(n,1);
for i=1:50
x=FOM(A,b,i,x0);
err(i)=norm(ones(n,1)-x);
y=GMRES(A,b,i,x0);
err2(i)=norm(b-A*y,2);
[T,V,z]=LanczosSym(A,b,i,x0);
err3(i)=norm(b-A*z);
end
figure, subplot(131), plot(err), title("FOM");
subplot(132), plot(err2),title("GMRES");
subplot(133), plot(err3),title("Lanczos");
B=2*In-diag(ones(n-1,1),-1)-diag(ones(n-1,1),1);
b=B*ones(n,1);
for i=1:50
x=FOM(B,b,i,x0);
err(i)=norm(ones(n,1)-x);
y=GMRES(B,b,i,x0);
err2(i)=norm(b-A*y,2);
[T,V,z]=LanczosSym(B,b,i,x0);
err3(i)=norm(b-A*z);
end
figure, subplot(131), plot(err), title("FOM");
subplot(132), plot(err2),title("GMRES");
subplot(133), plot(err3),title("Lanczos");