日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

matlab 信号的原子产生,MATLAB随机产生原子结构代码

發布時間:2023/11/27 生活经验 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab 信号的原子产生,MATLAB随机产生原子结构代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在計算材料學中極少的情況下,我們可能會需要隨機產生一個模擬盒子內的原子結構,一般用于測試。

這樣說,其實只要rand一個數組就可以了,但是我們又希望這個結構又能夠大致滿足一些物理上的限制,而不是純粹數學上的隨機,比如原子間距要比較合適。

這里提供的程序就是考慮了原子間距,而產生隨機結構的。

function randStructure(numAtom,boxlength,dmin,dmax)

% Geanerate a structure randomly with the distance in specified range

%

% randStructure(numAtom,boxlength,dmin,dmax)

% numAtom: number of atoms in the structure.

% boxlength: length of the simulation box

% dmin: minimum of the distance between two atoms

% dmax: [optional] maximum of the distance between two atoms

%

% Recommendation:

%It's better to set dmax equaling to boxlength.

%

% Example:

% randStructure(10,4,2,5)

%

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% log:

% 2012-12-10: Complete

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin == 3

dmax = boxlength;

end

%function randStructure()

%numAtom = input('Number of atoms:');

%boxlength = input('Scale factor:');

%dmin = input('minimum of the distance between two atoms:');

%dmax = input('maximum of the distance between two atoms:');

coord = rand(1,3)*boxlength; % the 1st atoms

n = 1; % number of atoms

while n < numAtom

tcoord = rand(1,3)*boxlength;

nlen = size(coord,1);

counter = 0;

for i=1:nlen

tdist = norm(coord(i,:)-tcoord);

if tdist >= dmin && tdist <= dmax

counter = counter + 1;

end

end

if counter == nlen

coord(end+1,:) = tcoord;

n = n + 1;

end

end

coord/boxlength

關于以上程序,有幾點是需要特別說明的:

這里模擬的盒子為正交,并且各軸長度相等的。

如果第四個參數,即dmax不輸入,默認賦boxlength。

最后一行將坐標轉換成了分數坐標。如果需要絕對坐標,不除以boxlength就可以了。

在有些情況下,程序似乎不能結束。這是因為第一個原子的位置產生的不太好,使得在一個有限的盒子內,無法產生距離滿足要求的其他原子。這時可以把程序終止掉,重新運行。如果這樣做幾次仍然不行,就要考慮是不是參數設置有問題,比如盒子太小,或者原子間距離太大。

總結

以上是生活随笔為你收集整理的matlab 信号的原子产生,MATLAB随机产生原子结构代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。