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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

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

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

在計(jì)算材料學(xué)中極少的情況下,我們可能會(huì)需要隨機(jī)產(chǎn)生一個(gè)模擬盒子內(nèi)的原子結(jié)構(gòu),一般用于測(cè)試。

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

這里提供的程序就是考慮了原子間距,而產(chǎn)生隨機(jī)結(jié)構(gòu)的。

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

關(guān)于以上程序,有幾點(diǎn)是需要特別說明的:

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

如果第四個(gè)參數(shù),即dmax不輸入,默認(rèn)賦boxlength。

最后一行將坐標(biāo)轉(zhuǎn)換成了分?jǐn)?shù)坐標(biāo)。如果需要絕對(duì)坐標(biāo),不除以boxlength就可以了。

在有些情況下,程序似乎不能結(jié)束。這是因?yàn)榈谝粋€(gè)原子的位置產(chǎn)生的不太好,使得在一個(gè)有限的盒子內(nèi),無法產(chǎn)生距離滿足要求的其他原子。這時(shí)可以把程序終止掉,重新運(yùn)行。如果這樣做幾次仍然不行,就要考慮是不是參數(shù)設(shè)置有問題,比如盒子太小,或者原子間距離太大。

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。