-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.m
More file actions
42 lines (32 loc) · 1.15 KB
/
solution.m
File metadata and controls
42 lines (32 loc) · 1.15 KB
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
% Homework MATLAB template file
% Your main file should be named "solution.m" and it should be saved as UTF-8 file.
function [consoleout, A1, A2, A3, A4, A5] = solution()
[consoleout, A1, A2, A3, A4, A5] = evalc('student_solution(0)');
end
function [A1, A2, A3, A4, A5] = student_solution(dummy_argument)
n = 64;
L = 20;
DeltaX = L/n;
AA = zeros(9, n^2, 5); % To store all solutions.
xs = -L/2 : DeltaX: L/2 - DeltaX;
ys = -L/2 : DeltaX: L/2 - DeltaX;
Params = Parameters(n, DeltaX);
Params.l = 20; % For fft.
InitialDistribution = @(x, y) exp(-x.^2 - y.^2./20);
w_vec = VectorizeInitialDistribution(xs, ys, InitialDistribution);
for I = 1:5
Tspan = 0: 0.5: 4;
Params.SolveModes = I;
% Setting Options for solving and stuff.
% Solving
ODEFun = @(t, w) Rhs(w, Params);
[~, Ws] = ode45(ODEFun, Tspan, w_vec);
AA(:, :, I) = Ws;
end
A1 = AA(:, :, 1);
A2 = AA(:, :, 2);
A3 = AA(:, :, 3);
A4 = AA(:, :, 4);
A5 = AA(:, :, 5);
end
% your extra functions, if you need them, can be in other files (don't forget to upload them too!)