Repository navigation
Expand file tree
/
Copy pathExample1D.m
More file actions
67 lines (61 loc) · 2.03 KB
/
Copy pathExample1D.m
File metadata and controls
67 lines (61 loc) · 2.03 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
clear; close all; clc;
%%
x = 0:0.1:300; % Space
L = 10; % Correlation Length
mu = 10; % Mean
s2 = 25; % Variance
Nmc = 1; % Single realization for spatial plot
Nmc_hist = 5000; % Many realizations for PDF validation
laws = {'gauss', 'lognormal', 'uniform', 'gamma', 'weibull'};
colors = {[0 0.447 0.741], [0.85 0.325 0.098], [0.929 0.694 0.125], ...
[0.494 0.184 0.556], [0.466 0.674 0.188]};
figure('Color', 'w', 'Name', 'Random Field Law Comparison');
for i = 1:length(laws)
fprintf('Processing law: %s...\n', laws{i});
field_1d = randomField(laws{i}, 'gauss', L, mu, s2, Nmc, x);
xx = x(1:2:end);
field_pdf = randomField(laws{i}, 'gauss', L, mu, s2, Nmc_hist, xx);
[R(i,:),xo(i,:),Lc(i)] = corrFromField(field_pdf, xx, 1);
subplot(2, 1, 1);
plot(x, field_1d, 'Color', colors{i}, 'LineWidth', 1.5, 'DisplayName', laws{i});
hold on;
box on
grid on
subplot(2, length(laws), length(laws) + i);
histogram(field_pdf(:), 100, 'Normalization', 'pdf', 'FaceColor', colors{i}, 'EdgeColor', 'none');
xline(mu, 'k--', 'Mean', 'LineWidth', 1.5);
xline(mu+sqrt(s2), 'k--', 'std+1', 'LineWidth', 0.5);
xline(mu-sqrt(s2), 'k--', 'std-1', 'LineWidth', 0.5);
box on
grid on
title(upper(laws{i}));
grid on;
if i == 1
ylabel('Probability Density');
end
xlabel('Value');
end
subplot(2, 1, 1);
yline(mu, 'k-', 'Mean', 'LineWidth', 2);
yline(mu+sqrt(s2), 'k-', 'std+1', 'LineWidth', 0.5);
yline(mu-sqrt(s2), 'k-', 'std-1', 'LineWidth', 0.5);
title(sprintf('1D Spatial Realizations (L = %g, \\mu = %g, \\sigma^2 = %g)', L, mu, s2));
ll = legend;
ll.String = ll.String(1:5);
xlabel('Distance (x)');
ylabel('Field Value');
grid on;
%%
figure('Color', 'w', 'Name', 'Correlation Random Field');
hold on
for i = 1:length(laws)
plot(xo(i,:),R(i,:),'LineWidth', 1.5, 'DisplayName', laws{i})
ind = R(i,:)>0.00;
LLc(i) = trapz(xo(i,ind),R(i,ind));
end
LLc
legend;
xlabel('Lag-Distance (x)');
ylabel('Auto-Correlation');
box on
grid on