topic Re: Evaluating entries of a matrix using a scalar function in PTC Mathcad
https://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737507#M196508
<P>The problem (not that it's really a problem, it actually is a feature!) is that the <EM>square</EM> operator notes that Input is a matrix and, therefore expects it to be square. Using Mathcad's <EM>vectorize</EM> 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).</P>
<P> </P>
<P>Stuart</P>
<P> </P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.jpg" style="width: 350px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/43721i9A24838160376FC1/image-size/large?v=v2&px=999" role="button" title="Untitled.jpg" alt="Untitled.jpg" /></span></P>Fri, 09 Jul 2021 14:41:04 GMTStuartBruff2021-07-09T14:41:04ZEvaluating entries of a matrix using a scalar function
https://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737501#M196507
<P>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:</P>
<P> </P>
<P>Output(i,j) := function( Input(i,j) )</P>
<P> </P>
<P>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).</P>
<P> </P>
<P>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?</P>Fri, 09 Jul 2021 13:58:47 GMThttps://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737501#M196507KA_99741172021-07-09T13:58:47ZRe: Evaluating entries of a matrix using a scalar function
https://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737507#M196508
<P>The problem (not that it's really a problem, it actually is a feature!) is that the <EM>square</EM> operator notes that Input is a matrix and, therefore expects it to be square. Using Mathcad's <EM>vectorize</EM> 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).</P>
<P> </P>
<P>Stuart</P>
<P> </P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.jpg" style="width: 350px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/43721i9A24838160376FC1/image-size/large?v=v2&px=999" role="button" title="Untitled.jpg" alt="Untitled.jpg" /></span></P>Fri, 09 Jul 2021 14:41:04 GMThttps://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737507#M196508StuartBruff2021-07-09T14:41:04ZRe: Evaluating entries of a matrix using a scalar function
https://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737567#M196517
<P>Yep! See attached.</P>Fri, 09 Jul 2021 20:10:20 GMThttps://community.ptc.com/t5/PTC-Mathcad/Evaluating-entries-of-a-matrix-using-a-scalar-function/m-p/737567#M196517Fred_Kohlhepp2021-07-09T20:10:20Z