Skip to main content
4-Participant
January 18, 2023
Solved

program in function definition corrupts vector?

  • January 18, 2023
  • 1 reply
  • 1650 views

"This value must be a scalar"
Why does the standard lognormal (Pr_lnorm) work
but when I introduce a program into the function definition (Pr_tlnorm), I get the above error?

Best answer by JKT

... or

JKT_0-1674053189767.png

if you expect only vectors are arrays as input for id..

1 reply

25-Diamond I
January 18, 2023

If you want to call a function which, like yours, expects a scalar argument "id" using a vector instead and expect this vector to be fed element by element as argument of the function and the various results to be collected in a result vector, you have to use vectorization!

Werner_E_0-1674052627518.png

 

JKT13-AquamarineAnswer
13-Aquamarine
January 18, 2023

... or

JKT_0-1674053189767.png

if you expect only vectors are arrays as input for id..

4-Participant
January 18, 2023

Thanks @Werner_E and @JKT 

I'm not familiar enough with Mathcad (or perhaps maths) to be sure what the difference is between the two solutions, but the latter solution by @JKT does appear to offer the benefit of baking in the vectorization at the function definition stage.