Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Conor Joseph Mccoid
UNIGE
Commits
8805a59c
Commit
8805a59c
authored
Oct 27, 2021
by
conmccoid
Browse files
Extrap: added GMRES comparison to linear FPI example
parent
bbfba5a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Research/Extrapolation methods/Code/ALGO_extrap_MPE_v1_20211022.m
View file @
8805a59c
function
x_out
=
ALGO_extrap_MPE_v1_20211022
(
F
,
X
)
function
[
x_out
,
r_out
]
=
ALGO_extrap_MPE_v1_20211022
(
F
,
X
)
% MPE performs minimal polynomial extrapolation using Arnoldi iteration
[
d
,
k
]
=
size
(
F
);
q0
=
F
(:,
1
);
Hinv
=
1
/
norm
(
q0
);
q0
=
Hinv
*
q0
;
Q
=
zeros
(
d
,
k
);
Q
(:,
1
)
=
q0
;
x_out
=
zeros
(
d
,
k
);
x_out
(:,
1
)
=
X
(:,
1
);
r_out
=
zeros
(
1
,
k
);
r_out
(
1
)
=
norm
(
F
(:,
1
));
for
j
=
2
:
k
Q
(:,
j
)
=
F
(:,
j
);
h
=
zeros
(
j
-
1
,
1
);
...
...
@@ -14,6 +15,7 @@ for j=2:k
hj
=
norm
(
Q
(:,
j
));
Q
(:,
j
)
=
Q
(:,
j
)/
hj
;
Hinv
=
[
Hinv
,
-
Hinv
*
h
/
hj
;
zeros
(
1
,
j
-
1
),
1
/
hj
];
u
=
Hinv
(:,
end
);
u
=
u
/
sum
(
u
);
x_out
(:,
j
)
=
X
(:,
1
:
j
)
*
u
;
r_out
(
j
)
=
norm
(
F
(:,
1
:
j
)
*
u
);
end
% if nargin==1
% x_out=x_out(:,end);
...
...
Research/Extrapolation methods/Code/EX_extrap_linearFPI_v1_20211022.m
View file @
8805a59c
...
...
@@ -9,15 +9,28 @@ for i=1:n
end
F
=
X
(:,
2
:
end
)
-
X
(:,
1
:
n
);
x_out
=
ALGO_extrap_MPE_v1_20211022
(
F
,
X
(:,
1
:
n
));
[
x_out
,
r_out
]
=
ALGO_extrap_MPE_v1_20211022
(
F
,
X
(:,
1
:
n
));
x
=
x_out
(:,
end
);
Error_abs
=
norm
(
x
-
x_true
)
Error_rel
=
Error_abs
/
norm
(
x_true
)
Residual
=
norm
(
A
*
x
+
b
-
x
)
Error_list
=
zeros
(
1
,
n
);
Error_list
=
zeros
(
1
,
n
);
res_MPE
=
zeros
(
1
,
n
);
for
i
=
1
:
n
Error_list
(
i
)
=
norm
(
x_out
(:,
i
)
-
x_true
);
res_MPE
(
i
)
=
norm
(
A
*
x_out
(:,
i
)
+
b
-
x_out
(:,
i
));
end
semilogy
(
1
:
n
,
Error_list
,
'b*--'
)
\ No newline at end of file
[
x_GMRES
,
~
,
~
,
~
,
res_GMRES
]
=
gmres
(
A
-
eye
(
d
),
-
b
);
figure
(
1
)
semilogy
(
1
:
n
,
Error_list
,
'b*--'
)
xlabel
(
'Iteration'
)
ylabel
(
'Error in solution'
)
title
(
'Error vs iteration'
)
figure
(
2
)
semilogy
(
1
:
n
,
res_MPE
,
'b*--'
,
1
:
length
(
res_GMRES
),
res_GMRES
,
'ro'
)
xlabel
(
'Iteration'
)
ylabel
(
'Residual'
)
title
(
'Residual vs iteration'
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment