# Thread: Issue With MATLAB Homework Problem

1. ## Issue With MATLAB Homework Problem

Hey guys,

Long story short, my DiffEq class has to use MATLAB, but they're not really teaching it to us. I'm trying my best to do some problems given to us, but it's difficult to do this stuff if you don't have much experience.

So here's the problem:

Apparently we're supposed to use 'inline' and 'ode45' to solve this, and then plot it.

So I started with this:

>> f=inline('[-.1*x(1)*x(2);-1*x(1)]','x','t')

f =

Inline function:
f(x,t) = [-.1*x(1)*x(2);-1*x(1)]

...and then I tried this and got a bunch of errors:

[t y]=ode45(f,[0,15],[10,15])

Not quite sure what the problem is here. If anyone could help me out a little bit, I'd greatly appreciate it.

2. Originally Posted by EddieB
Hey guys,

Long story short, my DiffEq class has to use MATLAB, but they're not really teaching it to us. I'm trying my best to do some problems given to us, but it's difficult to do this stuff if you don't have much experience.

So here's the problem:

Apparently we're supposed to use 'inline' and 'ode45' to solve this, and then plot it.

So I started with this:

>> f=inline('[-.1*x(1)*x(2);-1*x(1)]','x','t')

f =

Inline function:
f(x,t) = [-.1*x(1)*x(2);-1*x(1)]

...and then I tried this and got a bunch of errors:

[t y]=ode45(f,[0,15],[10,15])

Not quite sure what the problem is here. If anyone could help me out a little bit, I'd greatly appreciate it.
These are the Lanchester equations appropriate to guerilla warfare, where the rate of casulties inflicted by the regular forces is proportional to their number and the number of targets, and the rate of casulties inflicted by the irregular forces is just proportional to their number.

try:

Code:
>f=inline('[-.1*x(1)*x(2);-1*x(1)]','t','x')
>[t, y]=ode45(f,[0,15],[10;15])
The order of the arguments in the derivative is f(t,x) you had them the other way around.

Also the initial value vector in ode45 is a column vector, you had a row vector.

CB

3. Ah, thanks so much for the help!