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 06.03.2023, 04:28 GMT-5
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 06.03.2023, 04:28 GMT-5
Updated: 2 years ago 07.03.2023, 05:22 GMT-5

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.