-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexam.m
61 lines (47 loc) · 1.21 KB
/
exam.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%%% Devoir MTH1210 Antoine Busque
%% Question 1
% Donnees:
t0 = 0;
y0 = 1;
h = 0.1;
nbPas = (2 - 0) / h;
% Solution analytique, telle qu'indiquee sur le questionnaire
t=0:h:2;
solAnalytique = (1/2).*(exp(t) + exp(-t));
% a)
% Solution numerique par la methode d'Euler
[t, y1] = euler('examQ1eqndiff', t0, y0, h, nbPas);
solAnalytique(1)-y1(1)
solAnalytique(11) - y1(11)
solAnalytique(21) - y1(21)
% b) voir feuille
% c)
% Solution numerique par la methode de Runge-Kutta, ordre 4
h = 1/4;
nbPas = (2 - 0) / h;
[t, y2] = rk4('examQ1eqndiff', t0, y0, h, nbPas);
e4 = solAnalytique(21) - y2(2/h + 1)
h = 1/8;
nbPas = (2 - 0) / h;
[t, y2] = rk4('examQ1eqndiff', t0, y0, h, nbPas);
e8 = solAnalytique(21) - y2(2/h + 1)
h = 1/16;
nbPas = (2 - 0) / h;
[t, y2] = rk4('examQ1eqndiff', t0, y0, h, nbPas);
e16 = solAnalytique(21) - y2(2/h + 1)
h = 1/32;
nbPas = (2 - 0) / h;
[t, y2] = rk4('examQ1eqndiff', t0, y0, h, nbPas);
e32 = solAnalytique(21) - y2(2/h + 1)
h = 1/64;
nbPas = (2 - 0) / h;
[t, y2] = rk4('examQ1eqndiff', t0, y0, h, nbPas);
e64 = solAnalytique(21) - y2(2/h + 1)
h = 1/128;
nbPas = (2 - 0) / h;
[t, y2] = rk4('examQ1eqndiff', t0, y0, h, nbPas);
e128 = solAnalytique(21) - y2(2/h + 1)
e8/e16
e16/e32
e32/e64
e64/e128