summaryrefslogtreecommitdiff
path: root/coursework17
diff options
context:
space:
mode:
Diffstat (limited to 'coursework17')
-rw-r--r--coursework17/ex4.m45
1 files changed, 35 insertions, 10 deletions
diff --git a/coursework17/ex4.m b/coursework17/ex4.m
index b82b60b..6f44271 100644
--- a/coursework17/ex4.m
+++ b/coursework17/ex4.m
@@ -23,20 +23,45 @@ u = zeros(length(t),length(x));
u(1,:) = 0;
u(1,length(x)) = 0;
-% Initial condition
-for i = 1:length(x)
- if x(i) <= 0.5
- u(1,i) = 2*x(i);;
- else
- u(1,i) = 2*(1-x(i));
- end
+% % Initial condition 1
+% for i = 1:length(x)
+% if x(i) <= 0.5
+% u(1,i) = 2*x(i);;
+% else
+% u(1,i) = 2*(1-x(i));
+% end
+% end
+
+% % Initial condition 2
+% for i = 1:length(x)
+% u(1,i) = abs(sin(2*pi*x(i)));
+% % u(1,i) = sin(2*pi*x(i));
+% end
+
+% % Initial Condition 3
+% for i = 0.25/dx:0.75/dx
+% u(1,i) = 1;
+% end
+
+
+% Initial Condition 4
+for i = 1:0.5/dx
+ u(1,i) = -1;
end
-
+for i = 0.5/dx+1:length(x)
+ u(1,i) = 1;
+end
+
+
+
+
for m = 1:length(t)
% Set boundaries
- u(m+1,1) = 0.5 * m /length(t);
- u(m+1,length(x)) = 0.5 * m /length(t);
+% u(m+1,1) = 0.5 * m /length(t);
+% u(m+1,length(x)) = 0.5 * m /length(t);
+ u(m+1,1) = 0;
+ u(m+1,length(x)) = 0;
for j = 2:(length(x)-1)
% multiply out (1-2v) and factorise out v
u(m+1,j) = u(m,j) + ((dt/(dx^2))*(u(m,j+1) - 2*u(m,j) + u(m,j-1)));