Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <ic4j4j$oqf$1@fred.mathworks.com> <ic4l4d$1n9$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1290132784 27813 172.30.248.38 (19 Nov 2010 02:13:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 19 Nov 2010 02:13:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2599472
Xref: news.mathworks.com 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
            
            r=1;
            phi=rand(1)*pi;
            theta=rand(1)*2*pi;
            %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

            R=[Rx;Ry;Rz];
            %returns random unit vector for each of 100 steps
            
        end
        
    end
    end


     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.