How to use exp() and powers ^ in uncertain matrixes?

4 Ansichten (letzte 30 Tage)
Dylan Bartlett
Dylan Bartlett am 29 Jun. 2023
Kommentiert: Steven Lord am 29 Jun. 2023
I am trying to represent a thermistor using the Robust Control Toolbox.
I've created ureal objects to represent the thermistors base tolerance and beta and now want to create a matrix that represents the resistance.
ntcBase = ureal('ntcBase',2200,'Percentage',5)
ntcBeta = ureal('ntcBeta',3500,'Percentage',1)
ntcR = exp(ntcBeta)
I'm having issues getting exponentials and powers working in umats where the power is a ureal object and get the following error.
untitled
ntcBase =
Uncertain real parameter "ntcBase" with nominal value 2.2e+03 and variability [-5,5]%.
ntcBeta =
Uncertain real parameter "ntcBeta" with nominal value 3.5e+03 and variability [-1,1]%.
Check for incorrect argument data type or missing argument in call to function 'exp'.
Error in untitled (line 4)
ntcR = exp(ntcBeta)
Are these operators supported with these objects, or am I missing something else?
Thanks for the help

Akzeptierte Antwort

Steven Lord
Steven Lord am 29 Jun. 2023
ntcBase = ureal('ntcBase',2200,'Percentage',5)
Uncertain real parameter "ntcBase" with nominal value 2.2e+03 and variability [-5,5]%.
Let's see what operations are defined for this class.
methods(ntcBase)
Methods for class ureal: actual2normalized end getBlockValue inv issiso mrdivide pid series squeeze usample append feedback getLimits iosize issparse mtimes pid2 set ss uscale blkdiag fliplr getNominal ipermute isstatic nblocks pidstd setBlockValue stack uss cat flipud getTunedValue isGeneralized length ndims pidstd2 setTunedValue tf usubs conj frd getValue isLinear lft nmodels plus setValue transpose vertcat connect gainsurfdata gridureal isParametric lftdata normalize replaceBlock showBlockValue ufrd voidModel ctranspose genfrd hasInternalDelay isUncertain makeStateSpace normalized2actual repmat showTunable umat wcnorm display genmat hasdelay isempty minus numel reshape simplify uminus double genss horzcat isfinite mldivide parallel rsampleBlock size uplus dss get imp2exp isreal mpower permute sampleBlock sminreal ureal Static methods: empty matchChannelNames
The list of methods for this type of object does not include exp so it is not defined for this class. To double-check, let's see what would be called if you ran the command you tried:
which -all exp(ntcBase)
'exp(ntcBase)' not found.
Compare with the following, which correctly identifies the exp function for double arrays:
which -all exp(1)
built-in (/MATLAB/toolbox/matlab/elfun/@double/exp) % double method
The power function (the .^ operator) is not listed in the methods list, but the mpower function (the ^ operator) is. Since ntcBase is a scalar, the two would perform equivalent operations.
y1 = ntcBase^2
Uncertain matrix with 1 rows and 1 columns. The uncertainty consists of the following blocks: ntcBase: Uncertain real, nominal = 2.2e+03, variability = [-5,5]%, 2 occurrences Type "y1.NominalValue" to see the nominal value and "y1.Uncertainty" to interact with the uncertain elements.
y1.NominalValue
ans = 4840000
2200^2
ans = 4840000
y2 = ntcBase.^2
Operator '.^' is not supported for operands of type 'ureal'.
I'm not sure why the class doesn't define power. [Robust Control Toolbox is not my area of expertise.] This seems like a reasonable enhancement request to file with Technical Support. I could see exp being a little bit trickier to implement, though.
  2 Kommentare
Dylan Bartlett
Dylan Bartlett am 29 Jun. 2023
Thanks for this well explained answer Steven. The reason why I was asking about powers was to try and get around exp() not working in the first instance.
I tried the following and got another, much different error.
>> y = exp(1)^ntcBase
Check for incorrect argument data type or missing argument in call to function 'iosize'.
Error in ^ (line 26)
[ny,nu] = iosize(M);
I think all these issues are linked though, with some missing functionality holding me back. I'll raise a request and see what comes of it.
Steven Lord
Steven Lord am 29 Jun. 2023
From a little experimentation it looks like the mpower operator for ureal objects expects the base to be a ureal and the exponent to be an integer valued scalar number. The mpower function is asking questions (with the iosize utility function) about the first input that make sense for a ureal but not for a double value like exp(1).
ntcBase = ureal('ntcBase',2200,'Percentage',5);
ntcBase ^ 0.5
Error using ^
In the expression "M^K", the exponent K must be a scalar integer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by