forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_Feb_5.m
84 lines (68 loc) · 1.65 KB
/
class_Feb_5.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
80
81
82
83
84
t_0 = 0;
t_f = 1;
M = 100;
N = 100;
[u,u_true,x,t] = explicit_upwind(@f,t_0,t_f,M,N);
for j=0:20
plot(x,u_true(:,1+5*j),'r','LineWidth',2);
hold on
plot(x,u(:,1+5*j),'LineWidth',2);
axis([0,2*pi,-.3,1.3]);
title('Explicit Upwind','FontSize',16)
xlabel('true solution is in red','FontSize',16)
hold off
figure(1)
pause(1)
end
pause
[u,u_true,x,t] = centered_difference(@f,t_0,t_f,M,N);
for j=0:20
plot(x,u_true(:,1+5*j),'r','LineWidth',2);
hold on
plot(x,u(:,1+5*j),'LineWidth',2);
axis([0,2*pi,-.3,1.3]);
title('Centered Difference','FontSize',16)
xlabel('true solution is in red','FontSize',16)
hold off
figure(1)
pause(1)
end
pause
[u,u_true,x,t] = lax_friedrichs(@f,t_0,t_f,M,N);
for j=0:20
plot(x,u_true(:,1+5*j),'r','LineWidth',2);
hold on
plot(x,u(:,1+5*j),'LineWidth',2);
axis([0,2*pi,-.3,1.3]);
title('Lax-Friedrichs','FontSize',16)
xlabel('true solution is in red','FontSize',16)
hold off
figure(1)
pause(1)
end
pause
[u,u_true,x,t] = lax_wendroff(@f,t_0,t_f,M,N);
for j=0:20
plot(x,u_true(:,1+5*j),'r','LineWidth',2);
hold on
plot(x,u(:,1+5*j),'LineWidth',2);
axis([0,2*pi,-.3,1.3]);
title('Lax-Wendroff','FontSize',16)
xlabel('true solution is in red','FontSize',16)
hold off
figure(1)
pause(1)
end
pause
[u,u_true,x,t] = beam_warming(@f,t_0,t_f,M,N);
for j=1:21
plot(x,u_true(:,j),'r','LineWidth',2);
hold on
plot(x,u(:,j),'LineWidth',2);
axis([0,2*pi,-.3,1.3]);
title('Beam-Warming','FontSize',16)
xlabel('true solution is in red','FontSize',16)
hold off
figure(1)
pause(1)
end