From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab 3-d Walk problem
Date: Fri, 19 Nov 2010 02:13:04 +0000 (UTC)
Organization: University of Arizona
Lines: 35
Message-ID: <ic4mfg$r55$>
References: <ic4j4j$oqf$> <ic4l4d$1n9$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1290132784 27813 (19 Nov 2010 02:13:04 GMT)
NNTP-Posting-Date: Fri, 19 Nov 2010 02:13:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2599472
Xref: comp.soft-sys.matlab:688223

Okay, so I understand conceptually what you mean, but I get lost in the code.  Right now, here is what I have:

%This program creates a random unit vector in 3D. It then sums over many of
%these unit vetors in order to create a total displacement, R. Once it has
%found R, it then creates many more displacement vectors and finds the average displacement, R.
clear all

    for n = 1:1000
    %this repeats for 1000 random walks
        for N=1:100
           %accounts for 100 steps
            %creates one 3d unit vector randomly oriented
            Rx= r*sin(phi)*cos(theta);
            Ry= r*sin(phi)*sin(theta);
            Rz= r*cos(phi);
            %breaks down vector into x,y,z components

            %returns random unit vector for each of 100 steps

     I'm not sure exactly how to incorporate what you said.  My attempt to try and incorporate a Rxnew=Rxlast+Rx, but I couldn't get the labelling right (I think this is similar to what you said about keeping track of present position.  Then, my next thought was that maybe I could somehow return the result vectors from the loop to create a matrix and then sum over all x's, y's and z's to find net displacement, but I can't figure out a way to do that w/the loop present.  Either way, if you could help enlighten/walk me through this a little, it would be greatly appreciated.  Thank you.