aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-02-09 10:46:51 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-02-09 10:46:51 +0000
commitdfb39419fcc36003395c807ea01db40650a7de4b (patch)
treece08342dc5b0fdb2b0cc18b98b12e19bc7b6b94d
parent95b00f8755c5b5260b850438ffd47b17a3b0c807 (diff)
downloadNumericalAnalysis-dfb39419fcc36003395c807ea01db40650a7de4b.tar.gz
NumericalAnalysis-dfb39419fcc36003395c807ea01db40650a7de4b.zip
Finished making most plots
-rw-r--r--Part 3/figures/abs_sin3D_150_5000.pngbin0 -> 147325 bytes
-rw-r--r--Part 3/figures/abs_sin3D_150_5000_tvbcsin.pngbin0 -> 162074 bytes
-rw-r--r--Part 3/figures/abs_sin_150_5000.pngbin0 -> 93786 bytes
-rw-r--r--Part 3/figures/abs_sin_150_5000_tvbcsin.pngbin0 -> 152399 bytes
-rw-r--r--Part 3/figures/sin3D_150_5000.pngbin0 -> 108988 bytes
-rw-r--r--Part 3/figures/sin3D_150_5000_tvbcsin.pngbin0 -> 138469 bytes
-rw-r--r--Part 3/figures/sin_150_5000.pngbin0 -> 78704 bytes
-rw-r--r--Part 3/figures/sin_150_5000_tvbcsin.pngbin0 -> 150619 bytes
-rw-r--r--Part 3/figures/triang3D_150_5000.pngbin0 -> 104938 bytes
-rw-r--r--Part 3/figures/triang3D_150_5000_tvbcsin.pngbin0 -> 151454 bytes
-rw-r--r--Part 3/figures/triang_150_5000.pngbin0 -> 75086 bytes
-rw-r--r--Part 3/figures/triang_150_5000_tvbcsin.pngbin0 -> 167005 bytes
-rw-r--r--Part 3/scripts/finite_script.m37
-rw-r--r--Part 3/scripts/finite_script.m~67
-rw-r--r--Part 3/scripts/get_function.m4
15 files changed, 98 insertions, 10 deletions
diff --git a/Part 3/figures/abs_sin3D_150_5000.png b/Part 3/figures/abs_sin3D_150_5000.png
new file mode 100644
index 0000000..f8af342
--- /dev/null
+++ b/Part 3/figures/abs_sin3D_150_5000.png
Binary files differ
diff --git a/Part 3/figures/abs_sin3D_150_5000_tvbcsin.png b/Part 3/figures/abs_sin3D_150_5000_tvbcsin.png
new file mode 100644
index 0000000..e9089cc
--- /dev/null
+++ b/Part 3/figures/abs_sin3D_150_5000_tvbcsin.png
Binary files differ
diff --git a/Part 3/figures/abs_sin_150_5000.png b/Part 3/figures/abs_sin_150_5000.png
new file mode 100644
index 0000000..6e867bd
--- /dev/null
+++ b/Part 3/figures/abs_sin_150_5000.png
Binary files differ
diff --git a/Part 3/figures/abs_sin_150_5000_tvbcsin.png b/Part 3/figures/abs_sin_150_5000_tvbcsin.png
new file mode 100644
index 0000000..4b09a9a
--- /dev/null
+++ b/Part 3/figures/abs_sin_150_5000_tvbcsin.png
Binary files differ
diff --git a/Part 3/figures/sin3D_150_5000.png b/Part 3/figures/sin3D_150_5000.png
new file mode 100644
index 0000000..92a47eb
--- /dev/null
+++ b/Part 3/figures/sin3D_150_5000.png
Binary files differ
diff --git a/Part 3/figures/sin3D_150_5000_tvbcsin.png b/Part 3/figures/sin3D_150_5000_tvbcsin.png
new file mode 100644
index 0000000..773dfce
--- /dev/null
+++ b/Part 3/figures/sin3D_150_5000_tvbcsin.png
Binary files differ
diff --git a/Part 3/figures/sin_150_5000.png b/Part 3/figures/sin_150_5000.png
new file mode 100644
index 0000000..c81ccd4
--- /dev/null
+++ b/Part 3/figures/sin_150_5000.png
Binary files differ
diff --git a/Part 3/figures/sin_150_5000_tvbcsin.png b/Part 3/figures/sin_150_5000_tvbcsin.png
new file mode 100644
index 0000000..a083f6d
--- /dev/null
+++ b/Part 3/figures/sin_150_5000_tvbcsin.png
Binary files differ
diff --git a/Part 3/figures/triang3D_150_5000.png b/Part 3/figures/triang3D_150_5000.png
new file mode 100644
index 0000000..97b3274
--- /dev/null
+++ b/Part 3/figures/triang3D_150_5000.png
Binary files differ
diff --git a/Part 3/figures/triang3D_150_5000_tvbcsin.png b/Part 3/figures/triang3D_150_5000_tvbcsin.png
new file mode 100644
index 0000000..a4814db
--- /dev/null
+++ b/Part 3/figures/triang3D_150_5000_tvbcsin.png
Binary files differ
diff --git a/Part 3/figures/triang_150_5000.png b/Part 3/figures/triang_150_5000.png
new file mode 100644
index 0000000..7fc1cbf
--- /dev/null
+++ b/Part 3/figures/triang_150_5000.png
Binary files differ
diff --git a/Part 3/figures/triang_150_5000_tvbcsin.png b/Part 3/figures/triang_150_5000_tvbcsin.png
new file mode 100644
index 0000000..831cd51
--- /dev/null
+++ b/Part 3/figures/triang_150_5000_tvbcsin.png
Binary files differ
diff --git a/Part 3/scripts/finite_script.m b/Part 3/scripts/finite_script.m
index 76c682c..e10f509 100644
--- a/Part 3/scripts/finite_script.m
+++ b/Part 3/scripts/finite_script.m
@@ -4,10 +4,10 @@
clear;
% Set the number of samples to take
-N = 60;
+N = 150;
% Set the total time to run
-m = 300;
+m = 5000;
% Declare final size of matrix for speed
res = zeros(N+1, m+1);
@@ -20,11 +20,11 @@ h = 1/N;
k = h^2 * v;
% Set Initial condition
-res(:, 1) = get_function(N, h, 3);
+res(:, 1) = get_function(N, h, 1)';
% Set boundary conditions
-res(1, :) = zeros(1, m+1);
-res(N+1, :) = zeros(1, m+1);
+res(1, :) = sin(2*pi*(0:m)/m)/2+0.5;
+res(N+1, :) = sin(2*pi*(0:m)/m)/2+0.5;
% Calculate M+1 and plot it continuously
for c = 1:m
@@ -33,14 +33,35 @@ for c = 1:m
end
end
+% Plot 2D
+figure;
+Z = zeros(N+1, m/50+1);
+count = 1;
for i = 1:m+1
- if rem(i, 10) == 0
+ if rem(i, 50) == 1
plot(0:h:1, res(:, i));
+ Z(:, count) = res(:, i);
hold on;
+ count = count + 1;
end
end
hold off;
+
xlabel('x');
ylabel('y');
-title('Plots of 1D Heat equation over time, bc = abs(sin(2*pi*x))');
-legend('m = 0', 'm = 1', '...', 'm = 99'); \ No newline at end of file
+title('Plots of 1D Heat equation over time, bc = 0');
+legend('m = 0', 'm = 100', 'm = 200', 'm = ...', 'm = 5000');
+
+% Plot 3D
+figure;
+x = (0:m/50) / (m/50);
+y = (0:N) / N;
+[X,Y] = meshgrid(x, y);
+surf(X, Y, Z);
+
+xlabel('time / t');
+ylabel('x');
+zlabel('y');
+title('3D plot of 1D Heat equation over time, bc = 0');
+
+
diff --git a/Part 3/scripts/finite_script.m~ b/Part 3/scripts/finite_script.m~
new file mode 100644
index 0000000..7d91875
--- /dev/null
+++ b/Part 3/scripts/finite_script.m~
@@ -0,0 +1,67 @@
+% This script implements the finite difference method to solve the heat
+% equation
+
+clear;
+
+% Set the number of samples to take
+N = 150;
+
+% Set the total time to run
+m = 5000;
+
+% Declare final size of matrix for speed
+res = zeros(N+1, m+1);
+
+% Set v
+v = 0.25;
+
+% Get h and k
+h = 1/N;
+k = h^2 * v;
+
+% Set Initial condition
+res(:, 1) = get_function(N, h, 3)';
+
+% Set boundary conditions
+res(1, :) = sin(2*pi*(0:k:1))/2+1;
+res(N+1, :) = zeros(1, m+1);
+
+% Calculate M+1 and plot it continuously
+for c = 1:m
+ for i = 2:N
+ res(i, c+1) = v * res(i-1, c) + (1-2*v) * res(i, c) + v * res(i+1, c);
+ end
+end
+
+% Plot 2D
+figure;
+Z = zeros(N+1, m/50+1);
+count = 1;
+for i = 1:m+1
+ if rem(i, 50) == 1
+ plot(0:h:1, res(:, i));
+ Z(:, count) = res(:, i);
+ hold on;
+ count = count + 1;
+ end
+end
+hold off;
+
+xlabel('x');
+ylabel('y');
+title('Plots of 1D Heat equation over time, bc = 0');
+legend('m = 0', 'm = 100', 'm = 200', 'm = ...', 'm = 5000');
+
+% Plot 3D
+figure;
+x = (0:m/50) / (m/50);
+y = (0:N) / N;
+[X,Y] = meshgrid(x, y);
+surf(X, Y, Z);
+
+xlabel('time / t');
+ylabel('x');
+zlabel('y');
+title('3D plot of 1D Heat equation over time, bc = 0');
+
+
diff --git a/Part 3/scripts/get_function.m b/Part 3/scripts/get_function.m
index 1e1fb8f..b34ee30 100644
--- a/Part 3/scripts/get_function.m
+++ b/Part 3/scripts/get_function.m
@@ -6,9 +6,9 @@ if f == 1
count = 1;
for i = 0:h:1
if i < 0.5
- y(count, 1) = 2*i;
+ y(count) = 2*i;
else
- y(count, 1) = 2-2*i;
+ y(count) = 2-2*i;
end
count = count + 1;
end