Solving an ODE for the path of an electron
2 views (last 30 days)
Show older comments
Hello,
I am trying to plot an electron's trajectory through a magnetic field. However, I don't understand how to program the code to recognise that the magnetic field varies spatially.
Here is my go:
function xdot = electron(t,x);
xdot = zeros(2,1);
xdot(1) = x(2);
%my piecewise magnetic field
function Mag = B(X)
if (10 <= X) && (X <= 20)
Mag = 100*10^(-4);
else
Mag = 0;
end
end
xdot(2) = -(5.6933643*10^(-15)) * (x(2) * Mag(x(1)));
end
[t,x] = ode45('electron',[0, 300],[0, 1]);
Does it make sense to put Mag(x(1)) in my equation? I'm sure that's the problem, but I lack experience to know why and how to fix it.
Thank you!
0 Comments
Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!