I have generated an image processing code in Matlab. It has several subroutines and in one of them, I should solve a system of 7 nonlinear equations. I use "fsolve" in Matlab to solve this system, however, it gives me only one local optimum (answer) while using "Nsolve" in Mathematica, I can get all the possible answers. That's why I decided to solve my equations with Nsolve. Would you please let me know how should I import this equation from Matlab to Mathematica and export the results to Matlab after solving? (Belo is the code I used for Nsolve)

M = {{α1, β3, β2}, {β3, α2, β1}, {β2, β1, α3}};

 sol2 = NSolve[{
   β1 - (β2 β3 )/α1 == 2/3, 
   α2 - (β3 β3)/α1 == 2/3, 
   α3 - (β2 β2)/α1 == 8/3, 
   α1 - (β2 β2)/α3 == 8/3, 
   α2 - (β1 β1)/α3 == 2/3, 
   β3 - (β1 β2)/α3 == 2/3, 
   (4/3*Pi)^2 == 2.094^2*(CharacteristicPolynomial[M, x] /. x -> 0)}, {α1, α2, α3, β1, β2, β3}]

Right Hand Side (RHS) values in the above system (2/3, 2/3, 8/3,...) are being calculated in a subroutine in Matlab and are known here and matrix M should be calculated by NSolve. Therefore, my question is that which command should I use in Matlab to import RHS values to Mathematica (to use in the above code) AND after solving, how can I export "M" to Matlab? Thanks,

  • 2
    $\begingroup$ try matlink matlink.org $\endgroup$
    – Nasser
    Commented Oct 9, 2014 at 2:30
  • 1
    $\begingroup$ If you use MATLink, you will be able to control MATLAB from Mathematica, but not vice versa: you will not be able to control Mathematica from MATLAB. If your primary working environment is Mathematica and you need to call a few MATLAB functions then MATLink will be perfect. If your primary working environment is MATLAB, then it will be less convenient or not useful. $\endgroup$
    – Szabolcs
    Commented Oct 9, 2014 at 16:04
  • $\begingroup$ @Szabolcs Thank you for your comment. Yes, Matlab is actually my primary environment. So, what is your suggestion for how to import RHS values to Mathematica and send matrix "M" back to Matlab? $\endgroup$
    – vorujak
    Commented Oct 9, 2014 at 19:51
  • $\begingroup$ @Hossein Use files. Export to a file, then run a Mathematica script that reads the data from that file, processes it and writes the result to another. Then read the result from a file. $\endgroup$
    – Szabolcs
    Commented Oct 9, 2014 at 20:04

1 Answer 1


The magic words are MATlink, which can be found on matlink.org


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.