Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Pass a 1D array (vector) to a MATLAB function in COMSOL with MATLAB

Abir Bangladesh University of Engineering and Technology

Please login with a confirmed email address before reporting spam

I am trying to define the material properties (permittivity and conductivity) with MATLAB functions. The functions have six input arguments. Of the six, first two are usual COMSOL coordinate variables x and y. The next three are vectors (1D array) and the sixth one is a scalar.

My approach: I tried to define the last four variables using the model.param.set() method like following:

model.param.set('x1', x1); % x1 is a vector
model.param.set('y1', y1); % y1 is a vector
model.param.set('epsr1', epsr1); % epsr is a vector
model.param.set('del', del); % del is a scalar

Then I would define the material property as following:

model.component('comp1').material('mat2').propertyGroup('def').set('relpermittivity', {'mat_epsr(x,y,x1,y1,epsr_array,del_c)'}); % mat_epsr is the function

Unfortunately, this throws an error for trying to set an array as a parameter in COMSOL. The error message is as follows:

No method 'set' with matching signature found for class 'com.comsol.clientapi.impl.ModelParamClient'.

Error in (line 36) model.param.set('x1', x1);

How may I solve this error? I appreciate your help a lot.

-------------------
Md. Al-Imran Abir

1 Reply Last Post Mar 6, 2023, 4:28 a.m. EST
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 year ago Mar 6, 2023, 4:28 a.m. EST
Updated: 1 year ago Mar 7, 2023, 5:22 a.m. EST

Dear Abir,

In your case you need to define x1 and y1 in COMSOL with a scalar value as parameters cannot be defined as vector types. An alternative is to enter the vector definiton directly in the MATLAB function so you would call it in COMSOL as : mat_epsr(x,y,del) x1, y1, and epsr1 being defined inside the MATLAB function. If you need to update the values, edit the function and clear the function in COMSOL with the command:

model.func('extm1').refresh;

where 'extm1' is the tag of the external MATLAB function node in COMSOL.

Be aware that x and y are evaluated in the MATLAB function as a vector and the ouput of the function has to have the same size as x and y. Usually it is sufficient to use pointwise operation to get proper ouput size format.

Best regards,

Dear Abir, In your case you need to define x1 and y1 in COMSOL with a scalar value as parameters cannot be defined as vector types. An alternative is to enter the vector definiton directly in the MATLAB function so you would call it in COMSOL as : mat_epsr(x,y,del) x1, y1, and epsr1 being defined inside the MATLAB function. If you need to update the values, edit the function and clear the function in COMSOL with the command: model.func('extm1').refresh; where 'extm1' is the tag of the external MATLAB function node in COMSOL. Be aware that x and y are evaluated in the MATLAB function as a vector and the ouput of the function has to have the same size as x and y. Usually it is sufficient to use pointwise operation to get proper ouput size format. Best regards,

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.