Electric field and a misbehaving particle
Show older comments
What I wish to do is to model the trajectory of a point particle of small negative charge in the field of a point charge of large positive mass, so the latter is stationary.
What I have done so far always gives the solution where the small particle is totally unaffected by the field it's in -- so it just travels on in a straight line, which is obviously rubbish. (It should be going in a circle centered at the origin!)
Could anyone please help me? Note that the code is in its rough/draft stage so signs and constants are not guaranteed, but that should not affect the general physics behind it!
We shall consider motion in a plane. The coordinates of the particle with small charge is (a(t),b(t)) and that with large charge is at (0,0).
function EField
clear
trange = (0:.005:5);
%Starting conditions
a0 = ... ;
b0 = ... ;
adot0 = ... ;
bdot0 = ... ;
addot0 = -a0/((a0^2+b0^2)^(3/2));
bddot0 = -b0/((a0^2+b0^2)^(3/2));
vec0 = [a0, b0, adot0, bdot0, addot0, bddot0];
options = odeset('RelTol', 1e-8 ,'AbsTol', 1e-10);
[t,vec] = ode45(@EF, trange, vec0, options);
%Plot trajectory
plot(vec(:,1), vec(:,2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is the function EF in a separate m-file.
function sth = EF(t,vec)
a = vec(1);
b = vec(2);
adot = vec(3);
bdot = vec(4);
addot = vec(5);
bddot = vec(6);
sth = zeros(size(vec));
sth(1) = a;
sth(2) = b;
sth(3) = adot;
sth(4) = bdot;
sth(5) = -a/((a^2+b^2)^(3/2));
sth(6) = -b/(2*a^2+b^2)^(3/2));
Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!