[MatLab] Motion of Particle in a spatially varying electromagnetic field

In summary, the problem is that MatLab cannot solve second order differential equation, thus I have tried to use the code:%%Initial driftrhsE1=@(z,x)[x(2); 0];[zaE1, xaE1] = ode45(rhsE1, [0 69], [0 0]);%%inside E field E=1; rhsE =@(z,x)[x(2); (q/m)*(E/v^2)]; [zaE, xaE] = ode45(rhsE, [70 130], [0 0]);For the drift
  • #1
1Keenan
101
4
I have to simulate the motion of particle in an electromagnetic device which deflects particle using electric and magnetic field.
Those field are arranged in such a way that the electric field is inside the magnetic one. Moreover the electrodes begin at the center of the magnetic field ad their end is a bit outside the coils.
The motion equations are:
1) d^2x(z)/dz^2 = qE/mv^2
2) d^2y(z)/dz^2 = qB/mv

The problem is that MatLab cannot solve second order differential equation, thus I have tried to use the code:

Code:
%%Initial drift
rhsE1=@(z,x)[x(2); 0];
[zaE1, xaE1] = ode45(rhsE1, [0 69], [0 0]);
%%inside E field
  E=1;
  rhsE =@(z,x)[x(2); (q/m)*(E/v^2)];
  [zaE, xaE] = ode45(rhsE, [70 130], [0 0]);

For the drift after the field I have calculated the derivative of the trajectory and used it as initial condition for solving the eqaution of motion in the drift sector.
I have also write a similar code for the magnetic field.
The problem is that solving the equation separately doesn't seem to me correct because one solution could be longer than the other...

I have also tryed to solve the lorentz force using the code:
Code:
%%%%
f = @(t,y) [y(4:6); (q_over_m).*cross(y(4:6),B)+(q_over_m).*E];
[t,y] = ode23t(f,tspan,y0);
%%%

and some "while" loop like:

Code:
%%%
while (z>= length at which B begins ||  z<= length atwhich the electric field begins)
     B=[1 0 0]';
     E = [0 0 0]';
   solve the equation
  z=y(end,3);
end
%%%%%

and so on...

The problem is that the code is incredibly slow and sometimes, I think, it cannot get out of a loop.

I think I have used bad approaches to solve the problem, someone can give me a clue?
 
Physics news on Phys.org
  • #2
more than 100 people have red this thread but I still get no answer.
Am I doing something wrong?
I really need some help because I am stuck with this simulation.
 
  • #3
Matlab CAN however solve a system of first order diff eqns... if only there was a way to take a system of 2nd order diff eqns to a system of 1st order eqns...
 
  • #4
AIR&SPACE said:
Matlab CAN however solve a system of first order diff eqns... if only there was a way to take a system of 2nd order diff eqns to a system of 1st order eqns...

Yes, that's what I did with the code:
Code:
%%%%
f = @(t,y) [y(4:6); (q_over_m).*cross(y(4:6),B)+(q_over_m).*E];
[t,y] = ode23t(f,tspan,y0);
%%%

It is supposed to solve the system
dx/dt=vx
dy/dt=vy
dz/dt=vz
dvx/dt= (Lorentz Force)x
...

I have found what was wrong in my code, it is able to track a particle all the way long from the source to the detector and inside the field... I hope...
The trajectory seems to be reasonable, I would need someone to double check it for confirmation.
Is there someone available to test the code for me?
I can post it here or send in private, doesn't matter.
 
  • #5
Ok, I have done with the code.
If the moderators want to close this thread for me it is ok.
 

1. What is MatLab and how is it used in studying the motion of particles in a spatially varying electromagnetic field?

MatLab is a programming language and software environment commonly used in scientific and engineering fields. It allows for the manipulation and analysis of large sets of data, making it a useful tool in studying the motion of particles in a spatially varying electromagnetic field. MatLab can be used to simulate and visualize the behavior of particles in different electromagnetic fields, allowing for a better understanding of their motion and interactions.

2. How does a spatially varying electromagnetic field affect the motion of particles?

A spatially varying electromagnetic field causes a force to act on charged particles, which can alter their motion. This force is dependent on the strength and direction of the electric and magnetic fields in the given space. In a spatially varying field, the strength and direction of the fields change at different points in space, resulting in a non-uniform force on the particles.

3. Can MatLab be used to model the behavior of particles in any type of electromagnetic field?

Yes, MatLab can be used to model the behavior of particles in any type of electromagnetic field, as long as the equations governing the field are known. MatLab has built-in functions for solving differential equations, making it well-suited for simulating the motion of particles in various fields.

4. How does the motion of particles in a spatially varying electromagnetic field compare to their motion in a uniform field?

In a uniform electromagnetic field, particles experience a constant force in a single direction, resulting in a uniform motion. In a spatially varying field, the force acting on the particles changes at different points in space, causing the particles to accelerate and change direction. This results in a more complex and non-uniform motion compared to a uniform field.

5. Can MatLab be used to analyze the data collected from experiments involving the motion of particles in a spatially varying electromagnetic field?

Yes, MatLab can be used to analyze the data collected from experiments involving the motion of particles in a spatially varying electromagnetic field. The software allows for the import and manipulation of data, making it useful for analyzing experimental results and comparing them to theoretical predictions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
712
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Classical Physics
Replies
8
Views
970
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • Electromagnetism
Replies
14
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top