Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
I am trying to fill a 1D array/vector with calculated scalar values. This works fine for a simple calculation; but for a more complicated calculation, it fills the vector with nested [1x1] arrays instead of scalars. I have tried to use Vectorize to fix this, but unsuccessfully.
As an example, I define an array index i = -mf::mf. A simple function f_sub_i = f0 + df*i works fine to set up a vector of frequencies f with uniform step size df. But now I try a Gaussian function S_sub_i = e^{-[(f_sub_i -f0)/sigma]^2} , and I get a vector of nested [1x1] arrays instead of scalars. How can I get a vector of scalar values calculated by the formula for S_sub_i?
I'm using MathCAD Prime 9.0.0.0
Your exponent is a 1x1 matrix (or vector, depending upon your outlook). Consequently, the result is a matrix. Get rid of the bracket, and all is well.
Alternatively, I find the function unbox, and its counterpart box, to be helpful on several occasions
Stuart
(I've got Mathcad Express 11, not Mathcad Prime 9, I'm afraid, so a worksheet wouldn't be much help to you).
OMG, I’m so used to thinking that [brackets] are the same as (parentheses), just at a “higher level” of nesting. But of course you are right – brackets in MathCAD indicate an array, NOT like parentheses. Thank you so much!
Hi @bbobbs,
I wanted to see if you got the help you needed.
If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Of course, if you have more to share on your issue, please pursue the conversation.
Thanks,
Anurag
Stuart already explained the main problem: Don't type a square bracket unless you really want to create a matrix/vector.
Here is your fixed Prime 9 file attached
I would also suggest not to set the ORIGIN to an unusual value like -10 just to make it a little bit easier to create just one vector (f).
I also would suggest to use the vector f itself when creating the vector S. Vectorization may be done automatically in case of the expression you are using but may not with other expressions. So its a good idea to always explicitly apply vectorization whenever a vector is used as argument in a scalar function - just to be on the safe side.
Thank you!
