Math 2680 Differential Equations, Spring 2014

You must be logged in to reply to this topic.

  • Author
  • #13658

    Suman Ganguli

    Here is the code I put up today for creating the direction field in Matlab for v’ = 9.8 – (v/5)

    (as shown shown in Sec 1.1, Fig 1.1.2 in Boyce/DiPrima):

    >>dv = 9.8 – (v/5)
    >>dt = ones(size(dv))

    So to create other direction fields you’ll just need to change the line for the differential equation, and also change the bounds of graph in the meshgrid command.

    Here’s an explanation of the various commands, adapted from pp7-9 (which I highly recommend you read):

    create a meshgrid:

    >>[x,y]=meshgrid(a:k:b, c:j:d)

    creates a set of points (x; y), where x lies between a and b, incremented by k, and y lies between c and d, incremented by j (so this is where you set the bounds of the section of the coordinate plane for which you will draw the direction field)


    creates the set of nine points: (1; 0), (1; 1),(1; 2), (1:5; 0), (1:5; 1), (1:5; 2), (2; 0), (2; 1), (2; 2)



    plots an arrow at (a; b) in the direction of the vector v = (x; y)

    Example: quiver(0,0,1,1) begins at the point (0; 0) and draws an arrow inclined 45 degrees from the horizontal

    Recall: vector v = (x; y) has slope y/x

    So quiver(x, y, dx, dy) begins at the point (x; y) and draws a vector with slope dy/dx

    size(A) returns the dimensions of the matrix A

    ones(m,n) creates a matrix with m rows and n columns with a 1 in each entry

    direction field for y'(x) = x + sin(y) :

    >>dy = x + sin(y);

    The expression dx=ones(size(dy)) may become more clear if you think of our ODE as

    dy/dx = f(x,y)/1

    Optional–normalize length of vectors:

    >>dy = x + sin(y);
    >>dyu = dy./sqrt(dx.^2+dy.^2);
    >>dxu = dx./sqrt(dx.^2+dy.^2);

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.