# Inline function

• Feb 8th 2009, 01:36 AM
elliotyang
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.

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.
• Feb 9th 2009, 01:21 AM
CaptainBlack
Quote:

Originally Posted by elliotyang
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.

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