Skip to main content
1-Visitor
July 23, 2021
Solved

Matrix Output from For Loop

  • July 23, 2021
  • 1 reply
  • 3494 views

Hi, I am very new to mathcad, and am wondering if anyone could help me solve why when using Prime 7's inbuilt xmcd converter, the output of my for loop is no longer a matrix for all values of k, but the output for the final number of k only. I have tried re-writing the for-loop from scratch but that still gives me the same result.

 

Thanks in advance.

Best answer by StuartBruff

@FrankM22 wrote:

Hi, I am very new to mathcad, and am wondering if anyone could help me solve why when using Prime 7's inbuilt xmcd converter, the output of my for loop is no longer a matrix for all values of k, but the output for the final number of k only. I have tried re-writing the for-loop from scratch but that still gives me the same result.


Just add out as the last line in your program.  Mathcad returns the last thing it evaluated.  In your case, it was the last element of Mz.

 

Cheers,

 

Stuart

1 reply

23-Emerald V
July 23, 2021

@FrankM22 wrote:

Hi, I am very new to mathcad, and am wondering if anyone could help me solve why when using Prime 7's inbuilt xmcd converter, the output of my for loop is no longer a matrix for all values of k, but the output for the final number of k only. I have tried re-writing the for-loop from scratch but that still gives me the same result.


Just add out as the last line in your program.  Mathcad returns the last thing it evaluated.  In your case, it was the last element of Mz.

 

Cheers,

 

Stuart

FrankM221-VisitorAuthor
1-Visitor
July 23, 2021

Ah ok, thanks so much. I'd tried something similar and having the last line as return out[k but I suppose for the same reasons you said it would only output the value of out at the final value of k. Cheers again.

23-Emerald V
July 24, 2021

No worries.  IIRC, one of the versions of Mathcad (possibly 12?) did return the matrix rather than the element, but this didn't really fit with the way that Mathcad was supposed to work (ie,  return last calculation by default).

 

Cheers,

 

Stuart