Hello.
Working on simulations for mechanical systems, I found really usefull
to generate ODE equations on Maxima and then translate to octave to
make simulations. I am using a simple function
"generateOctaveFunction" at end of the mail to generate the octave
functions as follow:
load ("generateOctaveFunction.mac");
f(x,y) := sin(x) + cos(y) + t $
eq1 : -y + f(x,y);
eq2 : x - f(x,y);
testFunc : "generated";
generateOctaveFunction(testFunc,".",dq,[eq1,eq2],[x,y]);
This generates file generated.maxgen with content:
function dq =generated(q,t)
dq(1,1) = t+cos(q(2))+sin(q(1))-q(2)
dq(1,2) = -t-cos(q(2))-sin(q(1))+q(1)
endfunction
My question is: how to generate dq(i) in stand of dq(1,i)?? I am
using f90mx inside generateOctaveFunction.
Is there any more sofisticated way to pass Maxima equations to Octave??
Regards,
Pawe? Cesar Sanjuan Szklarz.
PD. generateOctaveFunction.mac
/*
Generate ODE function definition for octave
Parameters
functionName : Octave function name
directoryName : target directory
dq : matrix to save ODE equations
EquationsList : equations [eq_1,eq_2,...]
listVariables : state variables [x_1,x_2,...]
Generated ODE function has form
d(x_1)/dt = eq1;
d(x_2)/dt = eq2;
Variables [x_1,x_2,...] are replaced by [q[1],q[2],...] and
generated is pseudo octave file
"function dq =$funcName$(q,t)
dq(1,i) = f90(eq_i)
endfunction"
Final equations should be repared to by
q(1,i) = f90(eq_i)
It can be done with command:
sed -i -e 's/^d\(.\)(.\+,\(.\+\)) =\(.*\)$/d\1(\2)=\3;/g'
TODO: fix to generate directly q(i).
*/
load (f90)$
generateOctaveFunction(functionName,directoryName,dq,EquationsList,listVariables)
:= block(
/* x,y -> q_1,q_2 */
[q_eq : matrix( subst(
map("=",listVariables,makelist(q[i],i,1,length(listVariables))),
EquationsList )) ],
FunHeader(funcName) := concat("function dq =",funcName,"(q,t)"),
FunFileName(funcName,dir) := concat(dir,"/",funcName,".maxgen"),
FunFooter : "endfunction",
print (FunHeader(functionName)),
f90mx(dq,q_eq),
print (FunFooter),
with_stdout (FunFileName(functionName,directoryName) , print
(FunHeader(functionName)),f90mx(dq,q_eq),print (FunFooter)),
dq:matrixEquation
)$