1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Help

  1. Jan 31, 2008 #1
    Dear all. I am trying to solve an ODE in MATLAB using ODE45 solver. But the programe keep saying

    ??? Input argument "y" is undefined.

    Error in ==> lvv at 4
    yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];

    Can anybody be of help? Please.

    The complete code is this:
    function yprime=lvv(t,y)
    %LV: Contains Lotka-Volterra equations
    a=.5471;b=.0281;c=.0266;r=.8439;
    yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];
    [t,y]=ode45(@lvv,[0 20],[30;4])
    plot(t,y(:,1))
    Thanks
     
  2. jcsd
  3. Jan 31, 2008 #2
    make on m-file called whatever you want an place:

    [t,y]=ode45(@lvv,[0 20],[30;4])
    plot(t,y(:,1))

    this in that. Then make another m-file called lvv and place

    function yprime=lvv(t,y)
    %LV: Contains Lotka-Volterra equations
    a=.5471;b=.0281;c=.0266;r=.8439;
    yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];

    this in that, then it works, have tested it. You should always place functions in their own m-file, there are ways to put them in the same, but if you place it in another, then you never get problems.
     
  4. Feb 2, 2008 #3
    a way I sometimes use, is to trick matlab to think of the lvv function as a nested function by making your m-file into a function that doesn't do anything then it works, that is writing

    function idontdoanything=LaLaLa

    [t,y]=ode45(@lvv,[0 20],[30;4])
    plot(t,y(:,1))


    function yprime=lvv(t,y)
    %LV: Contains Lotka-Volterra equations
    a=.5471;b=.0281;c=.0266;r=.8439;
    yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];


    that is start you m-file with a dummy function.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Matlab Help
  1. MATLAB help (Replies: 9)

  2. MATLAB help (Replies: 2)

  3. MATLAB help (Replies: 0)

  4. MATLAB help (Replies: 7)

  5. Matlab help (Replies: 6)

Loading...