Differential Equation
Ivan Sutoris
ivan.sutoris at gmail.com
Fri Nov 14 18:14:56 CST 2008
On Sat, Nov 15, 2008 at 12:36 AM, William Christopher Carleton
<williamcarlet at trentu.ca> wrote:
> I'm new to Octave and have tried to set up a simple differential equation that demonstrates variable behaviour as a result of a constant 'r'.
>
> octave:1>function osc=f(x,t);
>> osc = -1.01*x;
>> endfunction
>
> octave:2> x0=1000
> octave:3> t=linspace(0,100,100)
> octave:4> x=lsode("f",x0,t)
> octave:5> plot(t,x)
>
> The above equation should demonstrate an increasing oscillation, but instead plots as an exponential decay. What have I done incorrectly? Thanks,
>
> Chris
In fact, the result is correct - your ODE dx / dt = -1.01*x has an
exact solution x(t) = a*exp(-1.01*t) for some constant a (in this
case, a=1000). Perhaps you mean to plot difference equation x(t) =
-1.01*x(t-1):
t = 0:100;
x = zeros(size(t));
x(1) = 1000;
for i=2:length(t)
x(i) = -1.01 * x(i-1);
end
plot(t,x)
Regards
Ivan Sutoris
More information about the Help-octave
mailing list