# Re: math modelling

Hi,

On Sun, 4 Apr 2004, David Fokkema wrote:

> On Sun, Apr 04, 2004 at 03:16:38PM +0200, Sebastiaan wrote:
> > Hi,
> >
> > On Sun, 4 Apr 2004, David Fokkema wrote:
> > > You snipped the part away which said I'm using octave at the moment, ;-)
> > >
> > haha, ok. Just popped on the list today. In what way does octave limit
> > you? Currently I am working daily with equations like you posted in
> > another message, but in Matlab though.
>
> Octave doesn't limit me in any way. The only 'problem' is that if you
> want to calculate such a simple model, you have to write a for-loop and
> store the calculated values in a vector for subsequent plotting. In
> Coach, you have two windows: one for the model and one for the initial
> values of the parameters. In the model window, you type things really as
> simple as
>
> v = v + a*dt
> x = x + v*dt
> t = t + dt
>
> without having to worry about losing previous values of x which you had
> to store in x(i) for example. You don't have to specify loops or
> whatever. The program runs your simulation while it is tabulating and
> plotting the values automatically. If you want to use more points,
> specify that somewhere. The idea is that students should only worry
> about their model, not about programming. Seems that something like this
> is not (yet) available as free software.
>
ok, now I see what you mean. No, as far as I know there is no trivial way
to implement this without for loops in either Octave or Matlab. I am not
surprised either since those models seldomly occur in these simpel forms
(and if they do, setting up a for loop is nothing compared to setting up
the matrices and stuff).

An alternative is to write your own procedure to perform the model steps,
which can be very simple indeed.

For example, make a file runmodel.m like:

maxsteps=100;
v_mem=zeros(1,maxsteps);
x_mem=zeros(1,maxsteps);
t=0;
x=0;
v=0;

for k=1:maxsteps
modelfile;
x_mem(k)=x;
v_mem(k)=v;
end

plot(x_mem,v_mem)

Then allow the students to edit modelfile.m:
v = v + a*dt;
x = x + v*dt;
t = t + dt;

After saving modelfile.m and choosing a suitable value for a and dt, they
can run runmodel (which can be a black-box for them) and see the output.

Of course there are some limitations with respect to the names of the used
variables. This you can overcome by either selecting some predefined names
for the variables allowed to use, or find the function that displays all
used variables (can't think how it's called atm) and do some 1337
programming work by assigning _mem for every variable listed then (gives a
lot of overhead of course, but I don't think this will be a problem with
this type of equations).

Cheers,
Sebastiaan

--

English written by Dutch people is easily recognized by the improper use of 'In principle ...'

The software box said 'Requires Windows 95 or better', so I installed Linux.

Als Pacman in de jaren '80 de kinderen zo had be?nvloed zouden nu veel jongeren rondrennen
in donkere zalen terwijl ze pillen eten en luisteren naar monotone electronische muziek.
(Kristian Wilson, Nintendo, 1989)