-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem4.m
79 lines (76 loc) · 1.93 KB
/
problem4.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%% Problem 4.b)
clear
prob4a = make_prob("4a");
meth.N=1000;
meth.G= @(prob,meth) G_LF(prob,meth);
show.yes=1;
show.freq=100;
meth=shallow_water(prob4a, meth, show);
Qref=meth.Q;
%% suite of Problem 4.b)
clear
prob4a = make_prob("4a");
meth.G= @(prob,meth) G_LF(prob,meth);
show.yes=0;
show.freq=100;
NN=logspace(2,3.5,5); % (2,3.5,5)
figure()
ax1=subplot(2,1,1);
ax2=subplot(2,1,2);
legends=string([]);
for N=NN
meth.N=N;
meth=shallow_water(prob4a, meth, show);
subplot(2,1,1)
plot(meth.x,meth.Q(1,:))
legends= [legends, "$\Delta x = "+ num2str(meth.dx)+"$" ];
hold on
subplot(2,1,2)
plot(meth.x,meth.Q(2,:))
hold on
end
legend(ax1,legends,"interpreter","latex")
legend(ax2,legends,"interpreter","latex")
title(ax1,"Problem 4 b): h-solutions with the Lax-Friedrichs scheme" +...
" at time T = 0.5 with varying mesh size")
title(ax2,"Problem 4 b): m-solutions with the Lax-Friedrichs scheme" +...
" at time T = 0.5 with varying mesh size")
hold off
%% Problem 4.c)
clear
prob4a = make_prob("4a");
meth.N=1000;
meth.G= @(prob,meth) G_Roe(prob,meth);
show.yes=1;
show.freq=100;
meth=shallow_water(prob4a, meth, show);
Qref=meth.Q;
%% suite of Problem 4.c)
clear
prob4a = make_prob("4a");
meth.G= @(prob,meth) G_Roe(prob,meth);
show.yes=0;
show.freq=100;
NN=logspace(2,3,5); %
figure()
ax1=subplot(2,1,1);
ax2=subplot(2,1,2);
legends=string([]);
for N=NN
meth.N=N;
meth=shallow_water(prob4a, meth, show);
subplot(2,1,1)
plot(meth.x,meth.Q(1,:))
legends= [legends, "$\Delta x = "+ num2str(meth.dx)+"$" ];
hold on
subplot(2,1,2)
plot(meth.x,meth.Q(2,:))
hold on
end
legend(ax1,legends,"interpreter","latex")
legend(ax2,legends,"interpreter","latex")
title(ax1,"Problem 4 b): h-solutions with the Lax-Friedrichs scheme" +...
" at time T = 0.5 with varying mesh size")
title(ax2,"Problem 4 b): m-solutions with the Lax-Friedrichs scheme" +...
" at time T = 0.5 with varying mesh size")
hold off