Index: mttroot/mtt/bin/trans/ode2odes_m ================================================================== --- mttroot/mtt/bin/trans/ode2odes_m +++ mttroot/mtt/bin/trans/ode2odes_m @@ -13,10 +13,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.14 1998/05/19 19:48:02 peterg +## Read the simpar file now. +## ## Revision 1.13 1998/05/14 08:05:10 peterg ## Put back under RCS ## ## Revision 1.12 1998/02/25 18:02:39 peterg ## Removed the argument passing stuff . @@ -110,10 +113,13 @@ if exist('x')==0 x = zeros(nx,1); end; + % xx is the composite vector containing x and the internal inputs. + xx = [x; zeros(nyz,1)]; + [n,m]=size(T); if m>n T=T'; end; @@ -125,16 +131,19 @@ elseif strcmp(method,'euler') %Euler integration X=[]; dt = (T(2)-T(1))/STEPFACTOR; for t=T' - X = [X; x']; + X = [X; xx']; ts = t; for i=1:STEPFACTOR - dx = $1_ode(x,ts); + x = xx(1:nx); + xx = $1_ode(xx,ts); ts = ts + dt; + dx = xx(1:nx); x = x + dx*dt; + xx(1:nx) = x; end; end; else error('Method %s not available here', METHOD); return; @@ -145,11 +154,11 @@ end; if ny>0 % compute y and print it i = 0; Y=[]; for t=T' - i = i+1; + i = i+1, X(i,:) y = $1_odeo(X(i,:),t); Y = [Y; y']; end; write_matrix([T,Y], '$1_odeso'); end; Index: mttroot/mtt/bin/trans/ode_r2m ================================================================== --- mttroot/mtt/bin/trans/ode_r2m +++ mttroot/mtt/bin/trans/ode_r2m @@ -12,10 +12,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.12 1998/05/21 12:55:48 peterg +## Put in algebraic equation stuff +## ## Revision 1.11 1998/05/21 08:05:23 peterg ## Back under RCS ## ## Revision 1.10 1998/04/14 07:25:02 peterg ## _input now has arguments (x,t) @@ -63,10 +66,11 @@ rm -f $1_ode.m1 rm -f $1_ode.m2 rm -f $1_ode.m3 rm -f $1_ode.m4 rm -f $1_odea.m1; +rm -f $1_odeo.m1; # Use reduce to accomplish the transformation reduce >ode_r2m.log << EOF %Read the reduce definitions file @@ -181,32 +185,21 @@ %Write algebraic equations if any ... zero := MTTYz; SHUT "$1_odea.m"; -OFF fort; % Now do the y = g(x,t) function. -OUT "$1_odeo.m"; - -write "function mtty = $1_odeo(x,t);"; -write "% mtty = $1_odeo(x,t);"; -write "%ODE in Simulab form for system $1;;"; -write "%File $1_odeo.m;;"; -write "%Generated by MTT;;"; - -common(); - -%Fortran switches - one line expressions -OFF echo; -ON fort$ -cardno!* := 1$ -fortwidth!* := 500$ -OFF period$ - -MTTy := MTTy; - -SHUT "$1_odeo.m"; +% The body of the odeo function + GENTRANOUT "$1_odeo.m1"; + mtt_matrix := MTTy$ + mtt_matrix_n := MTTNy$ + mtt_matrix_m := 1$ + mtt_matrix_name := MTTy$ + matlab_matrix(); + GENTRAN MTTy := mtt_matrix; + GENTRANSHUT "$1_odeo.m1"; + EOF # Create the ode.m function cat < $1_ode.m @@ -227,14 +220,16 @@ cat $1_ode.m4 >> $1_ode.m cat <> $1_ode.m % Solve the algebraic equations (if any) if nyz>0 - global xx; - xx = x; + global xx tt; + xx = x; tt=t; mttui = fsolve('$1_odea',mttui); -end; +else + mttui = []; +end EOF cat $1_ode.m3 >> $1_ode.m cat <> $1_ode.m @@ -262,12 +257,12 @@ # Create the globals sympar2global_txt2m $1 >> $1_odea.m cat <> $1_odea.m -global xx t; -x = xx; +global xx tt; +x = xx; t=tt; EOF #Common bit cat $1_ode.mc >> $1_odea.m @@ -277,11 +272,40 @@ cat <> $1_odea.m % The algebraic equations EOF cat $1_odea.m1 >> $1_odea.m + +# Create the odeo.m function +cat < $1_odeo.m +function mtty = $1_odeo(x,t); +% mtty = $1_odeo(x,t); +%Algebraic equations in Octave form for system $1; +%File $1_odeo.m; +%Generated by MTT on `date`; +EOF + +# Create the globals +sympar2global_txt2m $1 >> $1_odeo.m + + +#Common bit +cat $1_ode.mc >> $1_odeo.m + +#Extract internal input from state vector +cat $1_ode.m4 >> $1_odeo.m + +# Internal inputs +cat $1_ode.m3 >> $1_odeo.m + +cat <> $1_odeo.m + +% The output equations +EOF +cat $1_odeo.m1 >> $1_odeo.m +