-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoneD_adveq_with_dissipation_dispersion.m
43 lines (39 loc) · 1.14 KB
/
oneD_adveq_with_dissipation_dispersion.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
n = 100;
x = [0:n-1]/n * 2 * pi;
u0 = sin(x/2).^16;
close all
plot(x,u0,'b')
[t,u] = ode45(@oneD_adveq_upwind_func, [0, 2*pi], u0);
hold on;
plot(x, u(end,:),'r')
% illustration of dissipation or diffusion
n = 2*n;
x = [0:n-1]/n * 2 * pi;
u0 = sin(x/2).^16;
plot(x,u0,'b')
hold on
[t,u] = ode45(@oneD_adveq_upwind_func, [0, 2*pi], u0);
hold on;
plot(x, u(end,:),'g')
[t,u] = ode45(@oneD_adveq_upwind_func, [0, 2*2*pi], u0); % the dissipation is linearly related with dx
hold on;
plot(x, u(end,:),'k')
[t,u] = ode45(@oneD_adveq_central_func, [0, 2*2*pi], u0); % here we use central deriative to avoid dissipation
hold on;
plot(x, u(end,:),'y')
% illustration of dispersion
u0 = sin(x/2).^16;
figure()
plot(x,u0,'b')
[t,u] = ode45(@oneD_adveq_central_func, [0, 20*2*pi], u0); % here we show the affect of the dispersion
hold on
plot(x, u(end,:),'g')
u0 = sin(x/2).^16>0.8;
figure()
plot(x,u0,'b')
[t,u] = ode45(@oneD_adveq_central_func, [0, 2*pi], u0); % here we show the affect of the dispersion
hold on
plot(x, u(end,:),'g')
[t,u] = ode45(@oneD_adveq_upwind_func, [0, 2*pi], u0); % here we show the affect of the dissipation
hold on
plot(x, u(end,:),'k')