[Date Index] [Thread Index] [Author Index]
Re: Looking for a program that transforms Mathematica to Matlab expressions!!!
On Thursday, June 27, 2002, at 06:49 PM, KonNNos Oikonomou wrote: > First of all I would like to thank you for your message! > > What I actually want to do is find the rank of a 6nx37 numerical > matrix > which is generated by a 6x37 symbolic matrix (n is the number of time > instants). The 6x37 symbolic matrix describes the dynamics of a robot > manipulator and so the numerical matrix (6nx37) is produced for certain > trajectories of the angular positions, velocities and accelerations > (for each > time instant we substitute in the 6x37 matrix all parameters-variables > and > then we place all n matrices one below the other). > The reason I decided to use Matlab instead of Mathematica (despite > the fact > that until now I have done all my work in Mathematica) is that I have > found > the tools provided by the latter not so convenient. I understand that > Mathematica hasn't got any function computing the rank directly (such as > funtion rank() of Matlab), isn't it so? Another more indirect way to > find the > rank of the 6nx37 matrix of interest is via RowReduce. Nevertheless it > turns out that RowReduce is a very memory and time consuming funtion. In > other words it doesn't suit my problem I think. There are other ways of solving for the rank of a matrix using NullSpace, SingularValues, or QRDecomposition with Pivoting -> True. If you work with the symbolic values directly then you can only use NullSpace but the computation will be slow. If the expressions for the elements of the matrix are not numerically unstable ie. division of very small values by division of very large values, I would simply solve for all 6nx37 matrix entries then use SingularValues. The length of the second list returned from this routine is approximately the numerical rank of your matrix. Alternatively, 37-Length(NullSpace(m)) where m is your matrix is also an approximation of the column rank of your matrix. You can set the Tolerance option of SingularValues to determine the minimum ratio of a singular value to the maximum singular value to consider nonzero. I would guess that NullSpace calls RowReduce internally so I don't think that using it would be much of an improvement. > To be honest I have thought of using Mathlink and working with both > Mathematica and Matlab but I am afraid that when Mathematica substitutes > numerical values into my symbolic matrix errors do appear due to bad > numerical capabilities (comparing to Matlab). What I am saying is that > when I > realised that RowReduce is memory and CPU-time consuming I transferred > my > numerical data to Matlab (using package ToMatlab.m) and computed the > rank > there. Unfortunately the results I took were quite weird. So I decided > to > tranlate my symbolic matrix to Matlab and perform the whole trajectory- > simulation there, in order to take advantage of the better numerical > capabilities of Matlab from start. As I've said, I am not an expert in using Matlab, but in my limited experience Mathematica has proven to be a more stable platform for numerical analysis than Matlab. I am basing that statement purely on comparison of Mathematica's NIntegrate function and quadl from Matlab. Whenever I have noticed disagreement between the two programs the error is usually on the part of Matlab. Intuitively that makes sense since Mathematica has access to the original symbolic expression allowing it to perform simplifications which aid in stable computation. In Matlab it is up to the user to make sure that the expressions are robust with respect to floating point error. I have no desire to debate this point though, if in your experience Matlab has proven to be more robust I can accept that. > What do you think of all these? Is there any other way to compute > rank in > Mathematica (other than RowReduce)? Do you think that I should trust the > numerical capabilities of Mathematica? Or maybe I should try to pass my > symbolic matrix or my numerical data to Matlab by some other way (i.e. > text > file etc.)? Do you think that I should try MathLink? > In short, I think you are underestimating the numerical capabilities of Mathematica. Try substituting values into your symbolic expression (ideally the expressions should be simplified) and using SingularValues. This would be the quickest solution to implement. If you don't trust the results, pass the numeric values to Matlab, you can do this simply by writing the matrix to a text file since both programs can read and write data in that format. If you develop a larger program in Matlab though and still need to use Mathematica for symbolic computations then I suggest using Mathlink for communication since it can be done programmatically without requiring assistance from the user. Regards, Sseziwa Mukasa > Sseziwa Mukasa <mukasa at jeol.com> said: > >> I'm not quite sure what you want to use this expression for in MATLAB. >> Are you going to be substituting values for the symbols of the >> expression for a numeric calculation in MATLAB? If so and your >> expressions are not too large, FortranForm is pretty close to MATLAB >> syntax so you can output the elements of your matrix in FortranForm >> then >> cut and paste. It's tedious but only needs to be done once. I'm not a >> very experienced MATLAB user but I know that as of version 6 there is a >> C interface to MATLAB, if you write a C program using that interface >> and >> Mathlink you can communicate between MATLAB and Mathematica through >> it. I would only recommend this if your calculation is a combination >> of >> MATLAB and Mathematica programs. Also I understand that MATLAB has an >> interface for Maple which is similar to Mathematica, so maybe porting >> your symbolic calculations to Maple would be a better idea. Finally, >> if >> you don't want to use the C interface to MATLAB, I wrote an >> optimization >> program in which MATLAB writes an expression to a text file, then >> executes a UNIX script which calls a Mathlink program to run a >> Mathematica program. The C program then writes the result into another >> text file which MATLAB reads. Admittedly not the most elegant >> solution, >> but it works, I can provide details if you wish. However without >> further information about what you are trying to do it's hard to >> recommend a specific course of action. >> >> Regards, >> >> Ssezi >> >> >