Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

model.param.get does not return complex values

I set a parameter to a complex value by:

model.param.set('v1', 4.5+j*2)

However, when I try to access the parameter later by

model.param.get('v1')

All I get is

4.5

I am using comsol4.2a and matlab 2011a on a 64 bit linux machine.

Does the error occur when I am setting the parameter value or when I am accessing it.

In other words, is 'v1' correctly set to the complex value, and it is just the model.param.get that is not
working properly?

Or, is it model.param.set which is not setting 'v1' correctly?

I would appreciate any help.

Thank you,
Emi

3 Replies Last Post 28/11/2011, 01:15 GMT-05:00
Posted: 6 years ago 27/11/2011, 14:55 GMT-05:00
Hi

I'm not sure you can retrieve the comlex value in one call, have you tried to recall twice with a real() and imag()

--
Good luck
Ivar
Hi I'm not sure you can retrieve the comlex value in one call, have you tried to recall twice with a real() and imag() -- Good luck Ivar

Posted: 6 years ago 27/11/2011, 16:20 GMT-05:00

No, the model.param.set does not work if you set a parameter to a complex number.

Currently, I am getting around this by turning the complex value into a string and
setting the parameter to that string.

Example:
v1 = 4.5+j*2.5
v1String = num2str(v1);
model.param.set('v1', v1String);

Then when I call
model.param.get('v1')

I get the correct value:
4.5+j*2.5

So, I guess to pass complex values to model.param.set, you need to convert it to a string first.

Regards,
Emi
No, the model.param.set does not work if you set a parameter to a complex number. Currently, I am getting around this by turning the complex value into a string and setting the parameter to that string. Example: v1 = 4.5+j*2.5 v1String = num2str(v1); model.param.set('v1', v1String); Then when I call model.param.get('v1') I get the correct value: 4.5+j*2.5 So, I guess to pass complex values to model.param.set, you need to convert it to a string first. Regards, Emi

Posted: 6 years ago 28/11/2011, 01:15 GMT-05:00
Hi

Then I think it's worth to get that confirmed by "support". I find it somewhat astonishing, but OK, I hardly use matlab now with V4

--
Good luck
Ivar
Hi Then I think it's worth to get that confirmed by "support". I find it somewhat astonishing, but OK, I hardly use matlab now with V4 -- Good luck Ivar

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.