Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Re: Matrix Output from For Loop

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

07-23-2021
05:30 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-23-2021
05:30 PM

Matrix Output from For Loop

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.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

07-23-2021
05:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-23-2021
05:43 PM

@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

6 REPLIES 6

07-23-2021
05:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-23-2021
05:43 PM

@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

07-23-2021
06:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-23-2021
06:01 PM

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.

07-23-2021
08:39 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-23-2021
08:39 PM

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

07-24-2021
03:28 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-24-2021
03:28 AM

Yes, it was MC12

And the reason that the Mathcad sheet of the OP also gives a vector result in Mathcad 15 is the setting under "Tools"-"WorkSheet Options"-"Compatibility"-"Local assignment result" which is set to "MC12" in this sheet:

07-24-2021
05:28 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-24-2021
05:28 AM

Aha. Mystery explained. IIRC, I used to leave multiple assignment on but change local assignment.

07-26-2021
02:09 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2021
02:09 PM

@StuartBruff wrote:

Aha. Mystery explained. IIRC, I used to leave multiple assignment on but change local assignment.

Same here. I think that's the factory default (in Normal.xmct) anyway.