Group Abstract Group Abstract

Message Boards Message Boards

MatlabForm and ComsolForm

POSTED BY: Thales Fernandes
10 Replies
Posted 5 years ago

Would you consider submitting it to the Function Repository?

POSTED BY: Baker Ren

I extensively use Comsol for my work and I use Mathematica to modify or create some expressions that I utilize in COMSOL.

For 'modify' part, don't you also need an inverse definitions to import an existing COMSOL expression into Mathematica for simplification?

POSTED BY: Kapio Letto

For 'modify' part, don't you also need an inverse definitions to import an existing COMSOL expression into Mathematica for simplification?

I don't get your meaning of inverse definition, but you can access Comsol expressions by expanding the "equations" tag, where you can use Mathematica latter to parse the data by, for example, converting ewfd.Ez to a string "ewfd.Ez" or just stripping the ewfd tag. You can use Matlab to import all such equations, parse it into Mathematica, create a rule-based substitution and end-up with a simplified version of an equation.

POSTED BY: Thales Fernandes

Have you seen the ToMatlab package? It seems like a natural foundation to build on top of.

POSTED BY: Szabolcs Horvát
POSTED BY: Thales Fernandes
POSTED BY: Szabolcs Horvát
POSTED BY: Thales Fernandes

A 1x1 matrix is what we usually call scalars and 1xn or nx1 matrix is what we call vectors...

That depends on who "we" is. Physicist usually call a two-index tensor a matrix, even if it is a 1 by 1 tensor. I know that many engineering books just fall back to "row matrices" and "column matrices" for vectors.

What I meant is that the data structure that MATLAB uses is always a two (or higher) dimensional array. You can see this if you work with the MEX interface, because it exposes the data representation.

But it also has practical consequences in how one does calculations. Since MATLAB does not have true vectors, you cannot write vector*matrix*vector, as you can do vector.matrix.vector in Mathematica. You must keep in mind whether you have a "column vector" (column matrix really) or "row vector" and you must transpose when needed.

Another consequence of this representation is that MATLAB supports both 0 by n and n by 0 matrices (and distinguishes them). Only the latter can be represented in Mathematica as {{}}, but not the former.

Finally, * is an element-wise product in Mathematica. Thus converting a*b to a*b may be correct for Comsol, but it is only correct for "scalars" in MATLAB. The translation a.*b is correct for both "scalars" and larger matrices.

POSTED BY: Szabolcs Horvát

That depends on who "we" is. Physicist usually call a two-index tensor a matrix, even if it is a 1 by 1 tensor. I know that many engineering books just fall back to "row matrices" and "column matrices" for vectors.

As a physicist myself, I'm not part of this "norm"... Tensors in physics have a physical meaning, matrices don't. Matrices are far too general, they don't need to transform covariantly. But call all you want, a rank 17 tensor in 1 dimension is still a scalar, no matter how pretty and more sophisticated it would be to be to call it a tensor. An equally valid point would be to call all real numbers Octonions with zero imaginary part, and argue that there are no "true" real numbers... But I don't think such pedantic matters on semantics has much to add to the discussion. One should use the lingo which one is used to...

Matlab indeed treats everything as a matrix (I never argued to oppose it), but not all definitions need to be "vectorized". You can be equally happy by making a function that only accepts scalars. As in Mathematica, not all functions have attribute Listable.

Matlab own error handling call 1x1 matrices scalars, so, why can't we all? Just because internally they are two-dimensional arrays? Should we still can a matrix a matrix if it has rank different then 2? Or call it an array? Tensor?

In Comsol, you can only modify vectors, tensors, component-wisely, so, there is no need to have a high-level representation in terms of dot products, matrix multiplication etc.

POSTED BY: Thales Fernandes
Posted 8 years ago

I am also a COMSOL user. Thanks very much for this!

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard