Matlab协方差矩阵分解法生成随机场

发布于:2024-07-07 ⋅ 阅读:(49) ⋅ 点赞:(0)

Matlab协方差矩阵分解法生成随机场

相关系数矩阵

在这里插入图片描述

% function out=cohesion(x,y,mu,theta)
% end
% xy=load('F:\Research-OUC\基于机器许学习模型的海底斜坡可靠度研究\基于comsol的斜坡稳定性分析\comsol网格操作\grid_operate-matlab.mphtxt');
% x=xy(:,1);
% y=xy(:,2);
X=linspace(0,10,20);
Y=linspace(0,5,10)
[xxx,yyy]=meshgrid(X,Y);

x=reshape(xxx,200,1);
y=reshape(yyy,200,1);

% 自相关距离
Lh = 10; % 根据需要设置
Lv = 5; % 根据需要设置
% 计算自相关函数矩阵
n = length(x);
autocorr_matrix = zeros(n, n);
for i = 1:n
    for j = 1:n
        autocorr_matrix(i, j) = exp(-((x(i) - x(j))^2 / Lh) - ((y(i) - y(j))^2 / Lv));
    end
end
% 对相关函数进行chelosky分解
R=chol(autocorr_matrix,'upper');
random_m=randn(length(R));
G=dot(random_m,R);
mu=1e7;
theta=3e6;
thetaln=sqrt(log(1+(theta/mu)^2));
muln=log(mu)-thetaln^2/2;

Rf=exp(thetaln*G+muln);
%组合成多列
E_modulus=[x,y,reshape(Rf,200,1)];
% save('E_field.txt', 'E_modulus', '-ascii');



% contour(x,y,Rf)
% 创建网格
xlin = linspace(min(x), max(x), 100); % 创建 x 轴的网格点
ylin = linspace(min(y), max(y), 100); % 创建 y 轴的网格点
[X, Y] = meshgrid(xlin, ylin); % 创建网格

% 插值
Z = griddata(x, y, Rf, X, Y, 'natural'); % 使用 natural 插值方法适用于不规则数据

% 绘制等值线图
figure;
pcolor(X, Y, Z); % 绘制等值线,20 表示等值线的数量
colorbar; % 显示颜色条
title('不规则数据的等值线图');
xlabel('X 轴');
ylabel('Y 轴');


%对自相关函数求解特征值和特征函数

% % Nkl = 50;
% % [eigenVec,eigenVal]=eigs(autocorr_matrix,Nkl);
% [eigenVec,eigenVal]=eigs(autocorr_matrix);



% % % 保存自相关函数矩阵到文件
% % save('autocorr_matrix.txt', 'autocorr_matrix', '-ascii');
% 
% % 绘制自相关函数矩阵图
% figure;
% imagesc(autocorr_matrix);
% colorbar;
% title('自相关函数矩阵');
% xlabel('Index');
% ylabel('Index');

网站公告

今日签到

点亮在社区的每一天
去签到