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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Evaluating entries of a matrix using a scalar function

KA_9974117
3-Visitor

Evaluating entries of a matrix using a scalar function

I am a new Mathcad user. I have a function defined for a scalar input. I have an input 4x6 matrix of scalars. I want an output of another 4x6 matrix of scalars, evaluating the function at each entry of the input matrix. That is:

 

Output(i,j) := function( Input(i,j) )

 

I quickly found that just entering the 4x6 input matrix into the function as an argument did not work. I ended up using two for loops to generate the matrix (i.e. evaluating the above equation at each i & j value).

 

My question is this - is there a single line command to input a non-symmetric matrix into a function for a scalar & get the output I want? Any other ideas or resources for how to do this?

2 REPLIES 2

The problem (not that it's really a problem, it actually is a feature!) is that the square operator notes that Input is a matrix and, therefore expects it to be square.   Using Mathcad's vectorize operator.  This forces the processor to act on each element.  You can either vectorize over the function applied to Input, or modify the function to autovectorize (like many of Mathcad's built-in functions, such as cos).

 

Stuart

 

Untitled.jpg

Yep!  See attached.

Top Tags