I don't have the time to answer this in detail at present, and will get back to it. But in the mean time look at this thread.
CB
Hi
I have a problem that I dont really understand.
An electron with mass m and charge Q moves in an electric and magnetic forcefield with strengths E(x,y,z) and B(x,y,z). If the electrons position is described in cartesian coordinates r(t)=(x(t),y(t),z(t)) and velocity vector
dr/dt = v(t)=(u(t),v(t),w(t)) then:
The X is the cross product. I am supposed to write these equations as a first order system, that is, write out the equations for all the six components x,y,z,u,v,w.
I dont get what I am supposed to do.
I do realize to be able to use MATLAB to solve differential equations of second order, I need to re-write to first order, but this I have done for very simple diff. equations.
Thanks!
PS: If anyone has a good link or something about using ODE45, feel free to post it.
The state vector is:
The the first order vector ODE is:
where the first three components of the derivative are the last three components of the state vector, and the second three components are obtained from the equation for the derivative of velocity writen out in terms of position and velocity.
CB
Hi CB
Ok, let me see if I get this right.
I am just going to ramble out my thoughts here, correct me where I am wrong.
[t,Y]=ode45(@function,[0 tfinal],[ state vector?]) ?
then
function dYdt=function(t,Y)
m=9.11e-31; %Electron mass
Q=1.609e-18; %Charge
dYdt=zeros(6,1); %Create empty column vector
dYdt(1)=Y(4);
dYdt(2)=Y(5);
dYdt(3)=Y(6);
dYdt(4)=derivative of equation
dydt(5)=derivative of equation
dYdt(6)=derivative of equation
Now, how do I differentiate that function?
Will the
dYdt(4)=derivative of equation
dydt(5)=derivative of equation
dYdt(6)=derivative of equation
be partial derivatives?
Do I even know how E(r) looks like?
Thanks again!
hi
Ok, so the first derivative will be, if we let
?
Or don't I need to differentiate at all? And just put for example in
dYdt(4)= , where I just you the x-components of the vector fields?
Btw, it says a bit down: "Let the fields be homogenous, that is E=(e,0,0) and B=(0,0,b). What do they mean by "e" and "b" ?
thanks
hi
Yes, u,v,w are compontents of velocity.
function dYdt=labtest(t,Y)
dYdt=zeros(4,1);
if(Y(1).^2 + Y(3).^2 <= 1)
dYdt(1)=Y(2);
dYdt(2)=1+Y(4);
dYdt(3)=Y(4);
dYdt(4)=-Y(2);
else
dYdt(1)=Y(2);
dYdt(2)=0;
dYdt(3)=Y(4);
dYdt(4)=0;
end
function testalabtest()
clc
x0 = 1;
vx0=-1.8; %Uppgiften säger börja med -2, är detta typ hastigheten som skall has
%för att elektronen lämnar vid (0,1) ? Se plot nedan. -1.8
y0=0;
vy0=0;
[t,Y]=ode45(@labtest,[0 3],[x0 vx0 y0 vy0])
x = Y(:,1); y=Y(:,3);
ezplot('sin(t)','cos(t)',[0,2*pi]);grid,hold on
plot(x,y,'-r');axis([-2 2 -2 2])
Forgive my swedish comments here and there, but does this seem reasonable?