Closed Flune closed 1 year ago
Hi @Flune!
The large discrepancy is indeed surprising. I suspect it's the numerical solution that is the problem.
Is this using the RK4 method? Keep in mind that there are a lot of factors of 0.5 involved in that algorithm, so perhaps you are missing such a factor somewhere? I'm just guessing based on the fact that from your plot it looks like the numerical solution is progressing about twice as fast as the analytical one.
Feel free to provide a link to the your code on GitHub -- then either me or one of the other teachers might have time to take a quick look sometime tomorrow. (No guarantees, though!)
Another possible source of error that could give a time evolution that is about twice too fast: In the RK4 algorithm, if you have updated the positions/velocities of the particles in your trap in order to compute the various k's you need, make sure that the final update expressions for position/velocity still uses the old positions/velocities from the previous time step.
One more thing, since you are computing the analytical solution in Python, while the numerical solution presumably comes from your C++ code: make sure that all numbers match across the two codes (e.g. the magnetic field strength), and make sure that the timesteps match.
It has been solved. Your first hunch was correct, a factor was missing. Thank you :)
Great, happy to hear that! :)
I have a big difference in the analytical and simulated solution. The image above shows the analytical and simulated particle in the x/y plane. I'm not sure which of these two are actually wrong, or if we are supposed to have this large of a difference. Is it the analytical or the simulated solution? The analytical solution of the particle seems to be moving a lot faster.
This is the function I use for the analytical solution, in case it is of interest.