Skip to content

Commit 2847f60

Browse files
committed
Débbut exercice 3
1 parent 320d9c7 commit 2847f60

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

GCST.m

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
function [x,Jx,GJx,nit] = GCST(J,GJ,x0,pas,epsil,nitmax,findic)
1+
function [x,Jx,GJx,nit] = GCST(J,GJ,x0,pas,epsil,nitmax)
22
error = 10000;
33
nit = 0;
4+
disp('In GCST')
45
while (error > epsil) && (nit < nitmax)
5-
error = abs(norm(GJ(x0,findic)));
6-
x = x0 - pas .* GJ(x0,findic);
6+
error = abs(norm(GJ(x0)));
7+
x = x0 - pas .* GJ(x0);
78
nit = nit +1;
89
x0=x;
9-
Jx = J(x,findic);
10-
GJx = GJ(x,findic);
10+
Jx = J(x);
11+
GJx = GJ(x);
1112
end
1213

GJ.m

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
% Detailed explanation goes here
44
U=direct(F);
55
G=adjoint(U);
6-
76
end
87

J.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function [Y] = J(F)
22
%UNTITLED5 Summary of this function goes here
33
% Detailed explanation goes here
4+
global Uobs
45
n=length(F)+1;
56
h=1/n;
6-
J=h/2*sum(direct(F)-Uobs); % A faire
7-
7+
Y=h/2*sum( (direct(F)-Uobs).^2 );
88
end
99

TP2.m

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%% Tests de convergence du problème direct
77

88
%Test dans un cas simple
9-
n = 150
9+
n = 150;
1010
h = 1/n;
1111
x=linspace(h,1-h,n-1);
1212
F = pi^2*sin(pi.*x)';
@@ -69,6 +69,14 @@
6969
ylabel('log10 de l erreur')
7070
title(['Convergence du probleme adjoint : ' num2str(coeff(1))])
7171

72-
%% Exercice 3
73-
72+
%% Exercice 3 Gradient et Gradient conjugué à pas constant
73+
n = 150;
74+
h = 1/n;
75+
x=linspace(h,1-h,n-1);
76+
Uobs = sin(pi.*x)';
77+
F = zeros(length(x),1);
78+
pas = 0.5;
79+
epsil = 1e-2;
80+
nitmax = 1000;
81+
[xmin,Jxmin,GJxmin,nit] = GCST(@J,@GJ,F,pas,epsil,nitmax);
7482

0 commit comments

Comments
 (0)