# Avoid issues with "ToMatlab" Package?

Posted 1 year ago
1620 Views
|
6 Replies
|
1 Total Likes
|
 Hello All,I am having issues converting some of my Mathematica Code to Matlab. I am using mathematica to symbolically solve for the frequency response of a MEMS cantilever beam. I am using the Homotopy Analysis Method. I have generated expressions that I need to import into Matlab to run numerical simulations using Matlab's FSOLVE. I downloaded and have been using ToMatlab package in the wolfram library. This has worked in part but when i copy the converted Matlab syntax statement and paste it into Matlab it is not in the correct format. The codes below illustrate my problem. I have to delete the "\" symbols and eliminate the empty space and reformat the ellipsis because i want them to follow the + signs. Not only do I want them to follow the + signs but I need them to make the next entries following the ellipsis go down a line. In other words i need it to be "...ENTER" Where enter is where i have to manually press the enter key. For the line of code i have attached below it is no problem however i have larger statements consisting of thousands of terms when i go to higher orders for the Homotopy method, therefore it is not reasonable to do this manually every time. Please help. ToMatlab[-(1/16) x[ 2] (8 g2 Omega Sin[beta] SuperStar[b] + Cos[beta] (6 b delta g2 - 8 g2 omega^2 + 8 g2 Omega^2 + 4 d delta g4 x[2]^2 + d delta g4 Cos[2 beta] x[2]^2))] 
6 Replies
Sort By:
Posted 1 year ago
 Christopher,I have never used the ToMatlab package you described but I wrote my own and do the same task as you are doing. You need to right-click and do "Copy as-> Plain Text" (or Edit menu Copy as plain text). Matlab does not like the default copy format and inserts special characters (which messes up your syntax in MATLAB). I do this once in a while (and periodically forget to do the right type of copy and get the same types of errors you are seeing!)Regards,Neil
Posted 1 year ago
 Christopher,I would also be careful running that ToMatlab package -- Out of curiosity I took a quick look at it and it has at least one bug that I noticed. I use the ArcTan[] function and Mathematica uses the convention of ArcTan[x,y] while MATLAB uses atan2(y,x). I do not see where the ToMatlab function reverses the arguments of the function. There may be other similar cases of incompatibilities that need to be handled. Make sure you check things if you use any non-simple functions. This is why I wrote my own so that I can be certain of the processing of the functions that I use.RegardsNeil
Posted 1 year ago
 Neil,Thank You for your response. By "your own" do you mean that you have created your own code for converting Mathematica code to MATLAB Syntax?-Chris
Posted 1 year ago
 Chris,Yes. I made my own Mathematica to Matlab converter. I think the one in the Wolfram Library Archive is overly complicated (not meant as a criticism -- it was written nearly 20 years ago and the wolfram language has changed since then). -Neil