diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-08 23:01:22 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-08 23:01:22 +0000 |
commit | dba3bb1c68b4f11435c979998569367c854cbeaf (patch) | |
tree | 120a104c2d4184c317f0bf3f3e9a31d4f355dced | |
parent | 9c795066ea17feded11d8de9af704e72e87a807d (diff) | |
download | NumericalAnalysis-dba3bb1c68b4f11435c979998569367c854cbeaf.tar.gz NumericalAnalysis-dba3bb1c68b4f11435c979998569367c854cbeaf.zip |
Finished part 3 completely
-rw-r--r-- | Part 3/figures/abs_sin_24_100.png | bin | 0 -> 122172 bytes | |||
-rw-r--r-- | Part 3/figures/sin_24_100.png | bin | 0 -> 101189 bytes | |||
-rw-r--r-- | Part 3/figures/triang_24_100.png | bin | 0 -> 84887 bytes | |||
-rw-r--r-- | Part 3/scripts/finite_script.m | 23 |
4 files changed, 15 insertions, 8 deletions
diff --git a/Part 3/figures/abs_sin_24_100.png b/Part 3/figures/abs_sin_24_100.png Binary files differnew file mode 100644 index 0000000..b768040 --- /dev/null +++ b/Part 3/figures/abs_sin_24_100.png diff --git a/Part 3/figures/sin_24_100.png b/Part 3/figures/sin_24_100.png Binary files differnew file mode 100644 index 0000000..6acd7d6 --- /dev/null +++ b/Part 3/figures/sin_24_100.png diff --git a/Part 3/figures/triang_24_100.png b/Part 3/figures/triang_24_100.png Binary files differnew file mode 100644 index 0000000..749f9f3 --- /dev/null +++ b/Part 3/figures/triang_24_100.png diff --git a/Part 3/scripts/finite_script.m b/Part 3/scripts/finite_script.m index dd2ce15..6d8177c 100644 --- a/Part 3/scripts/finite_script.m +++ b/Part 3/scripts/finite_script.m @@ -1,13 +1,13 @@ % This script implements the finite difference method to solve the heat % equation -format long; +clear; % Set the number of samples to take -N = 14; +N = 24; % Set the total time to run -m = 50; +m = 100; % Declare final size of matrix for speed res = zeros(N+1, m+1); @@ -20,23 +20,29 @@ h = 1/N; k = h^2 * v; % Set initial condition to triangle function -umj = 0:h:1; count = 1; for i = 0:h:1 if i < 0.5 - umj(count) = 2*i; + res(count, 1) = 2*i; else - umj(count) = 2-2*i; + res(count, 1) = 2-2*i; end count = count + 1; end +% Set inital condition to sin function +% res(:, 1) = sin(2*pi*(0:h:1)); + +% Set initial condition to abs of sin +% res(:, 1) = abs(sin(2*pi*(0:h:1))); + + + % Set boundary conditions res(1, :) = zeros(1, m+1); res(N+1, :) = zeros(1, m+1); % Calculate M+1 and plot it continuously -res(:, 1) = umj; 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); @@ -46,4 +52,5 @@ end plot(0:h:1, res); xlabel('x'); ylabel('y'); -title('Plot of result from t = 1:m and u = 1:N');
\ No newline at end of file +title('Plots of 1D Heat equation over time'); +legend('m = 0', 'm = 1', '...', 'm = 99');
\ No newline at end of file |