Skip to main content
1-Visitor
October 21, 2021
Solved

Basic If Functions Applied to Arrays Derived from Spreadsheet Data

  • October 21, 2021
  • 2 replies
  • 2030 views

I'm fairly new to the use of arrays and matrices in general. I'm in the crane design industry and modern codes require multiple load combinations to be analysed in structural calculations simultaneously. Codes then often pose choices based on things like stress ratios. For example, in it's simplest form, a different set of rules are required if a stress is in compression rather than in tension. I need the ability to automatically differentiate between these stresses, and the correct rules are applied for each load combination. Sometimes these problems may use array sizes in the hundreds. I've attached a very basic programme. My desired outcome is a single n x 1 array. What I tend to get is an array of nested arrays. I've played around and found that if I were to transpose this and turn the nested array into a single clean matrix, use the diagonal function, then this would give me what I need. I have no idea how to do this though. Help would be greatly appreciated.

Best answer by ttokoro

image.pngimage.png

 

image.pngimage.png

2 replies

ttokoro
21-Topaz I
ttokoro21-Topaz IAnswer
21-Topaz I
October 21, 2021

image.pngimage.png

 

image.pngimage.png

t.t.
1-Visitor
January 28, 2022

Thank you!

23-Emerald V
January 29, 2022

For those with only Mathcad Prime Express, here's an Express 7 solution:

 

StuartBruff_0-1643444224318.png

 

StuartBruff_1-1643444260975.png

 

Stuart

 

Note: this would have been a lot easier if "if" was a true function that could be vectorized over. That way, the vectorized operator could be contained within prog1 and prog2 instead of needing to be defined as first scalar functions (_prog1 and _prog2) and then as (vectorized) array functions.

 

Help says the same thing that it has done since Mathcad first crawled out of the sea: "if is a (PTC) Mathcad control operator, not a function, and it does not work with operators that modify functions, such as the vectorize operator.".  Which explains everything and nothing.