cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Translate the entire conversation x

Vectorization works only for simple functions, not e.g. a Gaussian?

bbobbs
3-Newcomer

Vectorization works only for simple functions, not e.g. a Gaussian?

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

5 REPLIES 5
StuartBruff
23-Emerald IV
(To:bbobbs)

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

 

2025 13 09 E.png

 

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

Werner_E
25-Diamond I
(To:bbobbs)

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

Werner_E_0-1760392841716.png

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.

Werner_E_1-1760393092320.png

 

 

 

bbobbs
3-Newcomer
(To:Werner_E)

Thank you!

Announcements

Top Tags