summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-03-05 20:25:30 +0000
committerVasil Zlatanov <v@skozl.com>2017-03-05 20:25:30 +0000
commit86466678b35deb496f6fd5ad08e527412290b3d3 (patch)
treed5af05844557a4e5b4e2db69d876c9ff46ff7858
parent0c4597af1ff1c30f4f7df8735fb8e38e1e6e6b86 (diff)
downloade2-matlab-86466678b35deb496f6fd5ad08e527412290b3d3.tar.gz
e2-matlab-86466678b35deb496f6fd5ad08e527412290b3d3.tar.bz2
e2-matlab-86466678b35deb496f6fd5ad08e527412290b3d3.zip
add more initial conditions
-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)));