# Motion of a charged particle in a static magnetic field in matlab

by gursimran
Tags: charged particle, magnetic field, matlab
 P: 36 I want to simulate this type of situation but for simplicity I'm implementing it in 2d at first.. by setting the initial velocity 0 in parallel to B. 1. The problem statement, all variables and given/known data mass of particle is given assume anything charge magnitude of B initial velocity 2. Relevant equations 3. The attempt at a solution % script that simulates a moving particle with some initial velocity in a % magnetic field B v0 = [5 0 0]; %initial velocity B = [0 0 -5]; %magnitude of B m = 5; % mass q = 1; % charge on particle r0 = [0 0 0]; % initial position of particle t = 0; % Now we want to find the next velocity as the particle enters the magnetic % field and hence its new position r = r0; v = v0; dt = 0.00000000000000000001; figure xlim([-25 25]) ylim([-25 25]) hold on for n = 1:100 %plot it plot(r(1),r(2),'*'); %pause % update time t = t+dt; % new position r dr = v*dt; r = r + dr; %find new velocity dv = (q/m) * cross(v,B); v = v + dv; end I know the most probable reason is the quantissation error but I'm not able to figure out that how can I avoid this error and simulate the situation in matlab ..

 Related Discussions Introductory Physics Homework 2 Introductory Physics Homework 5 Introductory Physics Homework 0 Advanced Physics Homework 1 Introductory Physics Homework 1