从一排点

时间:2015-12-07 17:35:19

标签: matlab matrix matrix-multiplication

我正试图从一组初始点创建一个"平面",可以说是MATLAB中的点。到目前为止,我只能创建一行点,算法如下所示:

    % Generate molecular orientation and position
a = 4.309; % lattice constant in angstroms
l = 10; % number of lattices desired

placeHolder = [0 0 0 ; a/2 a/2 0; a/2 0 a/2; 0 a/2 a/2];    % centers of molecules

numMol = 4; %input('how many molecules are in the unit cell? \n # molecules = ');
numAtoms = 2; %input('how many atoms per molecule? \n # atoms per molecule = ');
atomPerUC = numMol*numAtoms; % number of atoms per unit cell
dir = zeros(numMol,3);      % array for orientations
atomPosition = zeros(numAtoms*l^3,3,numMol);        % array for positions of atoms
theta = zeros(numMol,1);        % array for theta values
phi = zeros(numMol,1);      % array for phi values
b = 1.54;      % bond length in angstroms

for kk = 1:numMol % generate unit cell
%     disp(['What is the molecular orientation for molecule ',num2str(kk),' ?']);
%     dir(kk,1) = input('u = '); % ask for user input for molecular orientations
%     dir(kk,2) = input('v = ');
%     dir(kk,3) = input('w = ');
    dir = [1,1,1;-1,1,1;-1,-1,1;1,-1,1];
    u = dir(kk,1);       % set variables for theta, phi computation
    v = dir(kk,2);
    w = dir(kk,3);

    theta(kk) = w/sqrt(u^2+v^2+w^2); % theta value for molecule k

    if v<0   % phi value for molecule k
        phi(kk) = 2*pi - acos(abs(v)/sqrt(u^2+v^2+w^2));
    else if v>0
           phi(kk) = acos(u/sqrt(u^2+v^2+w^2)); 
        end
    end

    theta = theta(kk); phi = phi(kk);     % set variables for theta, phi for x,y,z computation

    xp = placeHolder(kk,1);      % cooridnates of center of molecule k
    yp = placeHolder(kk,2);
    zp = placeHolder(kk,3);

    x1 = (b/2)*sin(theta)*cos(phi) + xp;        % cooridnates for atoms in molecule
    x2 = -(b/2)*sin(theta)*cos(phi) + xp;
    y1 = (b/2)*sin(theta)*sin(phi) + yp;
    y2 = -(b/2)*sin(theta)*sin(phi) + yp;
    z1 = (b/2)*cos(theta) + zp;
    z2 = -(b/2)*cos(theta) + zp;

    atomPosition(1,:,kk) = [x1 y1 z1];
    atomPosition(2,:,kk) = [x2 y2 z2];
end

for k = 1:numMol

    x01 = atomPosition(1,1,k); y01 = atomPosition(1,2,k); z01 = atomPosition(1,3,k);
    x02 = atomPosition(2,1,k); y02 = atomPosition(2,2,k); z02 = atomPosition(2,3,k);

    for ii = 1:l-1
        atomPosition(2*ii+1,:,k) = [(atomPosition(2*ii-1,1,k) + a) y01 z01];
        atomPosition(2*ii+2,:,k) = [(atomPosition(2*ii,1,k) + a) y02 z02];
    end

end

我的问题是我不知道如何从这里转过来#34; row&#34;分成一个&#34;飞机&#34;分数。这可以被认为是采用x轴上已知的点,并创建在y方向上向上移动的类似行,以创建点的x-y平面。

任何帮助/建议都将不胜感激!

1 个答案:

答案 0 :(得分:0)

虽然我不明白你想要做什么。在一个简单的例子中,您可以通过添加额外的维度从一行点移动到一个平面。

即。

x=[1,2,3,4,5]
y=x^2

更改为

x=[1,2,3,4,5]
y=[1,2,3,4,5]
[x,y] = meshgrid(x,y)
z=x^2+y^2