To evaluate a MATLAB function from in the COMSOL Multiphysics model you need to add a MATLAB node in the model object where the function name, the list of the arguments, and, if required, the function derivatives, are defined.
Under Functions, you define the function name and the list of the function arguments.
In the table columns and rows, enter the Function name and the associated function
Arguments. The table supports multiple function definitions. You can define several functions in the same table or add several
MATLAB nodes, as you prefer.
Any function that you want to call using a MATLAB node must fulfill the following requirements:
For example, functions such as + and
- (plus and minus) work well on vector inputs, but matrix multiplication (
*,
mtimes) and matrix power (
^,
mpower) do not. Instead, use the elementwise array operators
.* and
.^. See also
Function Input/Output Considerations.
As another example, test the corrcoef function for computing correlation coefficients:
There are no errors when calling corrcoef using vector inputs, but the result does not have the same size as the input and hence a call to
corrcoef in this way will not work.
Click the Plot button (

) to display a plot of the function.
Click the Create Plot button (

) to create a plot group under the
Results node.
To plot the function you first need to define limits for the arguments. Expand the Plot Parameters section and enter the desired value in the
Lower limit and
Upper limit columns. In the
Plot Parameters table the number of rows correspond to the number of input arguments of the function. The first input argument corresponds to the top row.
In case there are several functions declared in the Functions table, only the function that has the same number of input arguments as the number of filled in rows in the
Plot Parameters table is plotted.
To plot the function you need first to define the lower and upper limits for both nu and
x. In the
Plot Parameters table set the first row (which corresponds to the first argument
nu) of the
Lower limit column to 0 and the
Upper limit column to 5 and set the second row (corresponding of
x) of the
Lower limit column to 0 and the
Upper limit column to 10:
