Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: plz help-me/advise-me on my algorithm!
Date: Fri, 2 Jan 2009 18:08:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 48
Message-ID: <gjll62$qgt$1@fred.mathworks.com>
References: <gjlech$v6$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1230919682 27165 172.30.248.37 (2 Jan 2009 18:08:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 2 Jan 2009 18:08:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:509537

"Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gjlech$v6$1@fred.mathworks.com>...
> Hi
> 
> Im having problems implementing my algorithm. All i want to implement is the formula:
> 
> % q_zero is just a scalar number, assume scalars q(i)'s all equal to one.
> % c=constant scalar.
> % R is a vector. i.e, the random charges on a rod, where the force is to be computed % between the cahrges.
> 
> F=q_zero*E
> 
> where E= sum(for i=1:N) q(i)*(R-R(i))/c*(abs(R-R(i)).^3)
> 
> Can someone please help me, or advise me on a better way to implement this?
> 
> Warm Regards
> Sid
> 
> p.s. my previous algorithm was:
> my algorithm is:
> clear all;
> % User to enter number of charges (N) to be placed on rod.
>     N=input('Enter number of charges: '); 
> 
> % Position N charges on the rod randomly.
>     intN=int32(N);
>     % Get the random numbers, and sort them.
>     R = sort(2 * rand(intN, 1) - 1);
>     
>     R(1)=-1;  % Assign boundary charges.
>     R(intN)=1;
>    
> % Calculate the charges of N forces using Coulomb's Total Force.
>     q_zero = input('Enter charge amount: ');
>     constant=1;
>     En=zeros(N,N);
>     q=0.0;
>     for i = 1:N
>         En = sum((q(i)*(R-R(i)))/(constant*(abs(R-R(i)).^3)));
>     end
>     Fx=q_zero*En;

  In addition to Matt's remarks I will add this.  Your stuff only makes sense if you are calculating the field E at some arbitrary point P = (x,y) or (x,y,z), in space.  This had better not be one of the locations of your N charges because the field there would be infinite.  You are using 'R' to designate this vector P but matlab would be confused by that because you are also using R to denote the positions of the charges.  Use some other letter.  Also for all of this to make sense, the positions of the charges along the rod should each be three-dimensional vectors (in the spatial sense, not matlab's three-dimensonal sense,) not scalars, to allow vector subtraction from P.  For that you need to decide what is the orientation and location of the rod in space.

  By the way I don't see the need of sorting your charges in order along the rod.  Coulomb's law holds independent of their ordering in R.

Roger Stafford