# Math Help - Quick MATLAB ode45 question

1. ## 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!

2. Originally Posted by duma
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))

3. 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?

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