I have several expressions like the two followings:
X11 = I omega rho0 phi HankelH1[m, k0 ra];
X12 = -b1 kp1^2 BesselJ[m, kp1 ra];
I want to covert these expressions to Matlab. To this end, I use the package ToMatlab (by the way is there somewhere available a more recent version of it?)
X11 // ToMatlab
X12 // ToMatlab
(* "sqrt(-1).*omega.*phi.*rho0.*HankelH1(m,k0.*ra);
" *)
(* "(-1).*b1.*kp1.^2.*BesselJ(m,kp1.*ra);
" *)
However, this is not the syntax that Matlab uses of the Bessel and Hankel functions. For instance BesselJ[m,x]
(Mathematica) => besselj(m,x)
(Matlab).
Any ideas how to overcome the problem and avoid modifying on my own the latter expressions?
Answer
You could modify the ToMatlab package.
Find the section starting with
(*** Symbols *****************************************************************)
then add
ToMatlabaux[BesselJ] = "besselj"
ToMatlabaux[HankelH1] = "besselh"
In these cases the translation was trivial. Only the function name needed to be changed. When the argument order needs changing too, modify the section starting with
(*** Special cases of functions **********************************************)
For example, for the two-argument form of ArcTan
, add
ToMatlabaux[ArcTan[x_, y_]] := "atan2(" <> ToMatlabaux[y] <> ", " <> ToMatlabaux[x] <> ")"
This will set up a new rule for ArcTan
, in addition to the existing one that handles the single-argument form.
Comments
Post a Comment