Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Dear all,
I have this very simple code that gives a different result with the same input but in a different worksheet. I can't imagine what goes wrong here. Below you can find two snippets of the code:
Thanks for your help
Solved! Go to Solution.
I got it!
Its the "good" old MC12 compatibility!
Local assignment were handled differently in MC12 than in MC11 and before. This stopped a lot of programs to work properly.
So in later version a compatibility switch was introduced.
Go to menu "Tools", "Worksheet Options" and chose the tab "Compatibility". Her you can change the behavior of "Local assignment result" to MC12 and this will get you the vector as result.
Nevertheless I would advice to leave the setting at MC11 and change the routine instead so its not version dependent:
Regards
Werner
BTW, I'm using Mathcad 15, the original worksheet is written in Mathcad 12 or 13
I suspect that the subscript k in the picture on the left is a literal subscript (type the decimal point) while the one on the right is an index (type "[" character)
Good idea, but I guess thats not the case.
You would get a simple 0 in both cases, no vector, like shown.
And then a literal sub is a bit higher than a matrix sub. In the picture both look the same.
WE
You should always post the worksheets themselves, not just pics.
Whats the purpose of that routine? The vector as result in the right hand picture seems wrong to me (even if its the result you probably expect) as the return value should be just the last value assigned in the loop, like in the left hand pic.
But without seeing both worksheets its hard to say more.
WE
I'm sorry I didn't post the whole worksheets, they are rather long and with a lot of external references. On top of that they are rather confidential. If you still prefer it, I can try to make a condensed version of them that could recreate the problem.
I got it!
Its the "good" old MC12 compatibility!
Local assignment were handled differently in MC12 than in MC11 and before. This stopped a lot of programs to work properly.
So in later version a compatibility switch was introduced.
Go to menu "Tools", "Worksheet Options" and chose the tab "Compatibility". Her you can change the behavior of "Local assignment result" to MC12 and this will get you the vector as result.
Nevertheless I would advice to leave the setting at MC11 and change the routine instead so its not version dependent:
Regards
Werner
Here's another assignment of nul that I assume will work regardless of your compatibility settings:
I'll certainly try it. I had a suspicion that it could have something to do with older versions of MC; hence my initial comment
The for loop is to be used in a program with more program lines and not in an assignment statement.
> The for loop is to be used in a program with more program lines and not in an assignment statement.
Guess this does not answer the question about the different results in different sheet.
The answer is the MC12 compatibility. See my reply above.
In MC12 the program was perfectly OK the way it was written, no need to return A in an extra step.
Nevertheless I prefer the way MC11 and below handled that kind of thing (as I wrote in my first reply, the last value used is the "result" of a loop) and its sure good program style to return the vector and not the loop.
WE
But who, or what experienced programmer, regardless of the version of mathcad, would create a vector of n terms, with a for loop in an assignment statement? I believe it does not exist!
FM
The question was not for the elegance of this solution (as I wrote i would also vote against it) or if it is usual or good programming style (its sure not).
The question simply was why two different sheets yield different results for the very same content and the answer seems to be that the compatibility setting in the two sheets is different.
BTW, here are some easy and short ways to create a vector nul corresponding to the size of xgear (assuming ORIGIN=0).
For the second and third variant the prepended dummy assignment is just here for safety reasons - nul could already be a larger vector and so the result of the assignment won't change its size.
And, no, I won't recommend the last one 😉
But the first one has some charm, though it won't work correct if any element in the first column is not a number (like a string, NaN, or a matrix)
Werner
I went for solution number 2, although I like your first solution a lot too
Very interesting.
Thank you very much.
FM
I'm not the original programmer of the sheet, I only have to do the maintenance... The original programmer left the company long time ago. To be honest, I wouldn't think of programming it like that. I already changed it, but was still curious why it would work in one sheet and not in an almost identical other sheet.
Thank you all for your valuable input. Changing the compatibility settings solved the issue!