Results 1 to 4 of 4

Math Help - Quick MATLAB ode45 question

  1. #1
    Newbie
    Joined
    Nov 2009
    Posts
    2

    Quick MATLAB ode45 question

    I am using matlab for a Differential Equations course and keep getting this error when i try to plot this ode45 function:

    ??? Input argument "x" is undefined.

    Error in ==> F at 3
    xp(1)=x(2)

    here is the code:
    function xp=F(t,x)
    xp=zeros(2,1);
    xp(1)=x(2)
    xp(2)=-4*x(2)-5*x(1)+10*cos(0*t)

    [t,x]=ode45('F',[30,80],[0,0])
    [t,x(:,1)]
    plot(t,x(:,1))


    I really dont know why matlab keeps telling me 'x' is undefined. Any help would be appreciated!
    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 duma View Post
    I am using matlab for a Differential Equations course and keep getting this error when i try to plot this ode45 function:

    ??? Input argument "x" is undefined.

    Error in ==> F at 3
    xp(1)=x(2)

    here is the code:
    function xp=F(t,x)
    xp=zeros(2,1);
    xp(1)=x(2)
    xp(2)=-4*x(2)-5*x(1)+10*cos(0*t)

    [t,x]=ode45('F',[30,80],[0,0])
    [t,x(:,1)]
    plot(t,x(:,1))


    I really dont know why matlab keeps telling me 'x' is undefined. Any help would be appreciated!
    (Matlab is funny about case sensitivity in the case of functions in .m files)

    Code:
    function xp=ff(t,x)
      xp=zeros(2,1);
      xp(1)=x(2)
      xp(2)=-4*x(2)-5*x(1)+10*cos(0*t)
    Code:
    [t,x]=ode45('f',[30,80],[0,0])
    [t',x(:,1)]
    plot(t',x(:,1))
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Nov 2009
    Posts
    2
    I tried, using the lowercase f didnt work. The same "undefined x" error occured. I saw someone w/ a similar prob on another forum and a seperate m file (an instruction file?) containing a 'for' statement was suggested to define x. Im a novice, I have no clue how to do that for this prob. this is the for statement they posted:

    for i=1:3

    T(i)=1000*i;
    lmax(i)=fminbnd(-f,1*10^(-8),1*10^(-6));
    c(i)=lmax(i)*T(i)
    end

    so, do i need a seperate m file defining x?
    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 duma View Post
    I tried, using the lowercase f didnt work. The same "undefined x" error occured. I saw someone w/ a similar prob on another forum and a seperate m file (an instruction file?) containing a 'for' statement was suggested to define x. Im a novice, I have no clue how to do that for this prob. this is the for statement they posted:

    for i=1:3

    T(i)=1000*i;
    lmax(i)=fminbnd(-f,1*10^(-8),1*10^(-6));
    c(i)=lmax(i)*T(i)
    end

    so, do i need a seperate m file defining x?
    Change both the file name to lower case and the function name in the file, it works for me on FreeMat.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab ode45
    Posted in the Math Software Forum
    Replies: 8
    Last Post: October 24th 2009, 12:22 PM
  2. Matlab ode45
    Posted in the Differential Equations Forum
    Replies: 0
    Last Post: October 24th 2009, 06:23 AM
  3. Solving IVP in Matlab (ode45)
    Posted in the Math Software Forum
    Replies: 2
    Last Post: December 15th 2008, 10:01 PM
  4. ode45 Matlab
    Posted in the Math Software Forum
    Replies: 6
    Last Post: November 29th 2008, 09:21 PM
  5. ode45 MATLAB
    Posted in the Math Software Forum
    Replies: 2
    Last Post: September 24th 2008, 05:02 AM

Search Tags


/mathhelpforum @mathhelpforum