Results 1 to 2 of 2

Math Help - Inline function

  1. #1
    Junior Member
    Joined
    Feb 2009
    Posts
    28

    Inline function

    Hi,
    I am a newbie to mathlab. I try follow what in the example in the notes. But error occurs. I do not know why it is like that.
    Can anyone please help me see this code got any problem?


    x'' − 3x' + 2x = te^t, x(0) = 0, x'(0) = −2.

    function xdot = myfunction(t,x)
    xdot = zeros (2,1);
    xdot(1) = x(2);
    xdot(2) = 3*x(2) - 2*x(1)+t.*exp(t); %only need to change this line

    This is exactly the same from the notes. when i try run it at mathlab window, error occurs. it can't recognised xdot(1) = x(2)

    Can anyone explain to me? I have never try create function before.
    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 elliotyang View Post
    Hi,
    I am a newbie to mathlab. I try follow what in the example in the notes. But error occurs. I do not know why it is like that.
    Can anyone please help me see this code got any problem?


    x'' − 3x' + 2x = te^t, x(0) = 0, x'(0) = −2.

    function xdot = myfunction(t,x)
    xdot = zeros (2,1);
    xdot(1) = x(2);
    xdot(2) = 3*x(2) - 2*x(1)+t.*exp(t); %only need to change this line

    This is exactly the same from the notes. when i try run it at mathlab window, error occurs. it can't recognised xdot(1) = x(2)

    Can anyone explain to me? I have never try create function before.
    Please show the calling code for your function. It should be something like:

    t=0;
    x=[0;-2];
    xd=myfunction(t,x)

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 20
    Last Post: November 27th 2012, 06:28 AM
  2. Replies: 0
    Last Post: October 19th 2011, 05:49 AM
  3. Replies: 4
    Last Post: October 27th 2010, 06:41 AM
  4. Replies: 3
    Last Post: September 14th 2010, 03:46 PM
  5. Replies: 0
    Last Post: August 31st 2009, 03:02 AM

Search Tags


/mathhelpforum @mathhelpforum