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

Evaluating entries of a matrix using a scalar function

KA_9974117
2-Guest

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.

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."