· Download
and read the example codes Particle1d.java Particle1dTester.java
· Compile
them by typing javac Particle1d.java Particle1dTester.java
· Run
them by typing java Particle1dTester
· Graph
the output by running xmgrace Particle1.dat
· We
shall now reuse your previously
debugged Vector3d to do more advanced codes
Make readFromTokens set the Tokenizer
to ignore '(' ')' '{' '}' and ',' characters
Make readFromTokens set the Tokenizer to skip C++ comments
See StreamTokenizer.slashSlashComments() (http://java.sun.com/j2se/1.4.2/docs/api/java/io/StreamTokenizer.html)
In what follows you can now write your input file in a more readable format
like
0.01 // dt
10000 // numsteps
// Particle 1 starts off as follows
( 0, 0, 0 ) // initial position
( -1, 1, 0 ) // inital velocity
1 // mass
1// charge
Write a data file for the trajectory
(x-position vs y-position) a single particle in an electric field E=(-x,-4y,0),
This program should read the initial status from an input file. This should contain anything you are likely to
change later to avoid having to modify and recompile your code all the time. Think through what these should be.
Produce a plot for mass=1, charge=1 starting with velocity (-1,1,0) at position
(0,0,0).
Note the field depends on the coordinate, and recall that the force on the
particle of charge q is F = q E(x) .
Verify your code by calculating the final trajectory analytically for this situation.
· Advanced
o Increase the timestep to 0.1 - why does it no longer repeat in a stable fashion.
o Design a numerical experiment to measure the error your computer program makes
§ Hint: your analytic solution tells you the exact period
o Plot the error at fixed time t as a function of dt.
Add a resistive force -b v and replot for b=0.01.
2.
Central electric field with two test particles
On a graph of distance against
time, plot the separation of two particles of mass 1, with charges 1 and 4,
started at rest at position (1,0,0) .
This program should read its initial conditions from an input file.
Use the same field as above, and ignore the interaction between the particles.
3. Magnetic field
Plot the x-y trajectories for a magnetic field
(0,0,1) with the particles of charge 1,-1 having a initial velocities (1, 0, 0)
and position (0, 0, 0).
Your program should open and write two files at the same time.
(You will need to use your Vector.cross cross
product method now that the force is qv x B).
You will have to use an "old" velocity to compute the force
Why do you think the timestep errors seem bigger?