Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

? Input argument y is undefined.

  1. Apr 23, 2007 #1
    ??? Input argument "y" is undefined.

    HII Friends
    Iam little bit new to matlab and iam trying to use ode45 and wrote code as

    function dy = sampleode(t,y)

    dy=zeros(2,1);

    dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);

    dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));

    [t,y]=ode45('sampleode', [0:5:40],[1;1]);


    BUt iam getting the below error:

    ??? Input argument "y" is undefined.

    Error in ==> sampleode at 3
    dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);
    I saved my mfile as sampleode.m .please suggest me any suggestions. Thanks in advance
     
  2. jcsd
  3. Apr 24, 2007 #2
    Hi,

    I'm also a newbie in MATLAB, but two things strike me as odd here
    1) In the following line you multiply by 0. Did you really mean to do that?
    dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));
    2) I was under the impression ode45 required a function handle not a string containing the name of the function (though I may be wrong there)
    Moreover, what are you inputing as your y as you didn't give the command you use to run the function.
    Regardless, sorry I can't be much help.
     
  4. Apr 24, 2007 #3
    Matlab is strange when working with functions.

    One solution is to define the function (and save it in an .m file) and then running ode45 in console. The other (wich i prefer) is to work with nested functions.

    In the first one, you should do a sampleode.m file with the following code

    Code (Text):
    function dy = sampleode(t,y)
      dy=zeros(2,1);
      dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);
      dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));
    end
    and then in console type

    Code (Text):
    [t,y]=ode45(@sampleode, [0:5:40],[1;1]);
    (nothe the @).

    The second solution works better when you are using a more sophisticated code and would be using nested functions. Create a file named ord.m with the following code:

    Code (Text):
    function ord

    [t,y]=ode45(@sampleode, [0:5:40],[1;1]);

      function dy = sampleode(t,y)
        dy=zeros(2,1);
        dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);
        dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));
      end

    end
    That way, when you type
    Code (Text):
    ord
    in console, Matlab will perform ode45 on the function sampleode. If you add the line
    Code (Text):
    plot(y,U);
    after ode45 but before defining sampleode, then Matlab will perform ode45 and plot the solution every time you type
    Code (Text):
    ord
    in console.

    You should check the diference between local and global variables, it could provide another way of solving your problem.
     
    Last edited: Apr 24, 2007
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: ? Input argument y is undefined.
  1. Undefined Points (Replies: 6)

  2. Is this undefined? (Replies: 4)

  3. Undefinable numbers (Replies: 31)

Loading...