File mttroot/mtt/bin/trans/ode2odes_m artifact 0f0069f5e3 part of check-in e87199e5d9


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: ode2odes_m

# Transforms descriptor matrix rep to step response

# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.9  1997/01/06 21:36:44  peterg
## Fixed bug mtt_error --> mtt_error.txt
## Replaced lsode by Euler integration.
##
## Revision 1.8  1996/09/13 17:54:08  peter
## Now writes default $PARAMS to $1_args.m - $1_ode may use it.
##
## Revision 1.7  1996/09/12 18:41:48  peter
## Standard error handling added.
##
## Revision 1.6  1996/08/24 14:11:04  peter
## Global parameter passing.
##
## Revision 1.5  1996/08/18 12:01:26  peter
## Unified format of time responses.
##
## Revision 1.4  1996/08/16 13:04:46  peter
## Fixed problem with more than one output (y vector).
##
## Revision 1.3  1996/08/16 06:36:03  peter
## Removed u from default arg list.
##
## Revision 1.2  1996/08/15 16:24:43  peter
## Uses T in place of t to avoid name clash within function.
##
## Revision 1.1  1996/08/15 11:56:38  peter
## Initial revision
##
###############################################################

echo Creating $1_odes.m
rm -f ode2odes_m.log

if [ "$2" = "" ]; 
then
  PARAMS='T=[0:0.1:10]; x0=zeros(nx,1);'
  echo Using default parameter $PARAMS
  echo $PARAMS>$1_args.m
else
  PARAMS=$2;
fi

PARAMS="$PARAMS ;"


$MATRIX << EOF > ode2odes_m.log 2>mtt_error.txt

  step_factor = 1; %Set up default step factor
  %Read in parameters
  $1_numpar;

  [nx,ny,nu,nz,nyz] = $1_def;
  t=0;	%Just in case it appears in the parameter list.

  $PARAMS

  %Defaults
  if exist('T')==0
    T=[0:0.1:10]
  end;

  if exist('x0')==0
    x0 = zeros(nx,1);
  end;

  [n,m]=size(T);
  if m>n
    T=T';
  end;

if nx>0
%  x = lsode('$1_ode', x0, T);

%Euler integration
  x = x0;
  X=[];
  dt = (T(2)-T(1))/step_factor;

  for t=T'
    X = [X x];
    ts = t;
    for i=1:step_factor
      dx = $1_ode(x,ts);
      ts = ts + dt;
      x = x + dx*dt;
    end;
  end;

  X = X';
  write_matrix([T,X], '$1_odes');
else
  X = zeros(size(T));
end;

if ny>0
  i=0;
  for tt=T'
    i=i+1;
    y(i,:) = $1_odeo(X(i,:),tt)';
  end;
  write_matrix([T,y], '$1_odeso');
end;

EOF

# Now invoke the standard error handling.
mtt_error mtt_error.txt









MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]