Results 1 to 11 of 11

Math Help - Using ODE45

  1. #1
    Senior Member Twig's Avatar
    Joined
    Mar 2008
    From
    Gothenburg
    Posts
    396

    Using ODE45

    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:

    m\frac{d\vec{v}}{dt}=Q(E(r)-B(r) \, \times \, v)

    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.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Twig View Post
    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:

    m\frac{d\vec{v}}{dt}=Q(E(r)-B(r) \, \times \, v)

    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.
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Senior Member Twig's Avatar
    Joined
    Mar 2008
    From
    Gothenburg
    Posts
    396

    Hi

    Hi

    thanks, I looked at the link, but didnt really understand much though

    But I can wait, thanks again!
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Twig View Post
    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:

    m\frac{d\vec{v}}{dt}=Q(E(r)-B(r) \, \times \, v)

    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:

    {\bf{X}}=\left[ \begin{array}{c}x \\ y \\ z \\ x' \\ y' \\ z'\end{array}\right]

    The the first order vector ODE is:

    {\bf{X}}'=\left[ \begin{array}{c}x' \\ y' \\ z' \\ x'' \\ y'' \\ z''\end{array}\right]

    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
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Senior Member Twig's Avatar
    Joined
    Mar 2008
    From
    Gothenburg
    Posts
    396

    Hi

    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!
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Twig View Post
    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!
    They are derivatives with respect to time.

    If you dont know what either E(r) of B(r) are you cannot proceed further.

    CB
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Senior Member Twig's Avatar
    Joined
    Mar 2008
    From
    Gothenburg
    Posts
    396
    hi

    Ok, so the first derivative will be, if we let  C(r) = B(r) \times V(r)

     \frac{Q}{m}(E'_{x}(r) - C'_{x}(r)) ?

    Or don't I need to differentiate at all? And just put for example in
    dYdt(4)=  \frac{Q}{m}(E(r)-C(r)) , 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
    Last edited by CaptainBlack; March 29th 2009 at 09:12 AM.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Twig View Post
    hi

    Ok, so the first derivative will be, if we let  C(r) = B(r) \times V(r)

     \frac{Q}{m}(E'_{x}(r) - C'_{x}(r)) ?

    Or don't I need to differentiate at all? And just put for example in
    dYdt(4)=  \frac{Q}{m}(E(r)-C(r)) , 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

    I guess they mean that the electric and magnetic fields are constant and in the (1,0,0) and (0,0,1) directions respectivly. That should greatly simplify everything.

    CB
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Senior Member Twig's Avatar
    Joined
    Mar 2008
    From
    Gothenburg
    Posts
    396

    hi

    Hi CB

    I tried this:

    E = (e,0,0) and B=(0,0,b).

     \frac{d \vec{v}}{dt} = \frac{Q}{m}((e,0,0)-(-bv,bu,0))

    This was after doing a cross product, just letting B=(0,0,b) and v(t) = (u,v,w).

    After simplifying:  \frac{d \vec{v}}{dt} = \frac{Q}{m}((e+bv,-bu,0))

    Is this what they mean?

    thanks!
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Twig View Post
    Hi CB

    I tried this:

    E = (e,0,0) and B=(0,0,b).

     \frac{d \vec{v}}{dt} = \frac{Q}{m}((e,0,0)-(-bv,bu,0))

    This was after doing a cross product, just letting B=(0,0,b) and v(t) = (u,v,w).

    After simplifying:  \frac{d \vec{v}}{dt} = \frac{Q}{m}((e+bv,-bu,0))

    Is this what they mean?

    thanks!
    more or less (though I don't recall what u and v denote, components of the velocity?)

    CB
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Senior Member Twig's Avatar
    Joined
    Mar 2008
    From
    Gothenburg
    Posts
    396
    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?
    Last edited by Twig; March 29th 2009 at 03:07 PM. Reason: update
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. ode45 help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 12th 2010, 11:53 PM
  2. Ode45
    Posted in the Math Software Forum
    Replies: 5
    Last Post: October 28th 2009, 06:40 PM
  3. Matlab ode45
    Posted in the Math Software Forum
    Replies: 8
    Last Post: October 24th 2009, 12:22 PM
  4. ode45
    Posted in the Differential Equations Forum
    Replies: 3
    Last Post: March 19th 2009, 05:58 AM
  5. ode45 MATLAB
    Posted in the Math Software Forum
    Replies: 2
    Last Post: September 24th 2008, 05:02 AM

Search Tags


/mathhelpforum @mathhelpforum