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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Different result of the same formula in different worksheets

tthys
1-Newbie

Different result of the same formula in different worksheets

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:

2016-07-25 09_57_18-Mathcad - [Torsiestijfheid.xmcd].png                         2016-07-25 09_58_05-Mathcad - [Torsiestijfheid [formularium].xmcd].png

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:tthys)

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

View solution in original post

16 REPLIES 16
tthys
1-Newbie
(To:tthys)

BTW, I'm using Mathcad 15, the original worksheet is written in Mathcad 12 or 13

Fred_Kohlhepp
23-Emerald I
(To:tthys)

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

Werner_E
24-Ruby V
(To:tthys)

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

tthys
1-Newbie
(To:Werner_E)

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.

Werner_E
24-Ruby V
(To:tthys)

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

MJG
18-Opal
18-Opal
(To:Werner_E)

Here's another assignment of nul that I assume will work regardless of your compatibility settings:

tthys
1-Newbie
(To:Werner_E)

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

-MFra-
21-Topaz II
(To:tthys)

The for loop is to be used in a program with more program lines and not in an assignment statement.

for loop for Thys.jpg

Werner_E
24-Ruby V
(To:-MFra-)

> 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

-MFra-
21-Topaz II
(To:Werner_E)

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

Werner_E
24-Ruby V
(To:-MFra-)

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

tthys
1-Newbie
(To:Werner_E)

I went for solution number 2, although I like your first solution a lot too

-MFra-
21-Topaz II
(To:Werner_E)

Very interesting.

Thank you very much.

FM

tthys
1-Newbie
(To:-MFra-)

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.

tthys
1-Newbie
(To:tthys)

Thank you all for your valuable input. Changing the compatibility settings solved the issue!

Top Tags