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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Interactive dynamic system: a simple interaction that does not work

anthonyQueen
8-Gravel

Interactive dynamic system: a simple interaction that does not work


Using Mathcad v11, I tried a simple interaction, to update variables according to the movement of time (t).

Two points that have drawn me crazy: I guess the second does not have easy solution.

    1. In the picture below, I cannot really understand why the code SA1 does not work, and stops with error at Ai-1. I shall notice that  if I set t=1, it works. So the conditional "if" in SA1 seems ok. Can someone kindly explain what is the problem with t>1, while no problem is found in SA2 code?
    2. I made the error in another sheet - not in the one below - of setting my initial variables with the literal subscript (e.g. A.0) , even when the sbuscript is a number. I would like now to  "Replace" A.0, with a proper numerical subscript. But MC does not accept a paste of Math text into the Replace Window, for such subscript. Is there another way to write it in the Replace Window? Thanks.

Interactive_System_problem_Mathcad.png

1 ACCEPTED SOLUTION

Accepted Solutions

anthony Queen wrote:


Using Mathcad v11, I tried a simple interaction, to update variables according to the movement of time (t).

Two points that have drawn me crazy: I guess the second does not have easy solution.

    1. In the picture below, I cannot really understand why the code SA1 does not work, and stops with error at Ai-1. I shall notice that  if I set t=1, it works. So the conditional "if" in SA1 seems ok. Can someone kindly explain what is the problem with t>1, while no problem is found in SA2 code?
    2. I made the error in another sheet - not in the one below - of setting my initial variables with the literal subscript (e.g. A.0) , even when the sbuscript is a number. I would like now to  "Replace" A.0, with a proper numerical subscript. But MC does not accept a paste of Math text into the Replace Window, for such subscript. Is there another way to write it in the Replace Window? Thanks.

Just to back up Luc's points ... I've changed gI to 1 to make the effects more obvious.  Your code doesn't seem to run into the same error in M15.  I don't know whether this is problem with my typing or M11.  There are several Mathcad constructs (such as the literal versus vector subscript problem you mention) that are difficult if not impossible to analyze without the offending worksheet.  I've attached an M11 version of my M15 worksheet  - do you still get the error?

Stuart

View solution in original post

16 REPLIES 16
LucMeekes
23-Emerald III
(To:anthonyQueen)

1.

Without the actual worksheet it's difficult to interpret your code exactly.

Do you realize that the assignment inside the if statement of SA1 only can assign the values 1 or 0 to SAi, while Ai always gets assigned the value of A0 (which you preset at 2? The 'and' operator is not there to allow to put more assignments (or other statements) on a single line, but it is a logical operator, with a logic result (either True or False, 1 or 0 respectively).

What actually happens is that the value of A0 is assigned to Ai (and that seems to be what you want, as shown by SA2), but SAi gets the result of the logical question whether both SA0 and Ai are TRUE (unequal to zero) and looking at the implementation of SA2, that is NOT what you want.

2.

I've run in that problem a couple of times also. It's hand work.

Success!

Luc


Thanks LucMeekes,

I fear for 2, so no surprise that even the MC experts did not have  - unfortunately - workarounds.

You may be correct for  question 1. But then I do not have quite clear why then the "AND" operator works in connecting columns in SA2 (line before the last).

Initially I wrote SA1 avoiding the IF operator, and setting  i  € 1...t not from 0...t as above. Yet, the program gave me  the same kind error when t>1 (to be correct  it does not recognize SAi-1), with the same error message :  "Value of subscript is too big (or too small) for this array".  It did work instead also in that case if t=1. This is a puzzle for me, since values for i=1 (i.e when t=2) are calculated correctly within the script, in the  previous loop of the "for" operator (I say this since for t=1 it works).

If necessary I can upload the sheet, but really there is no much else  that the shown picture, and I try to avoid uploading files that may appear trivial.

LucMeekes
23-Emerald III
(To:anthonyQueen)

anthony Queen wrote:

You may be correct for  question 1. But then I do not have quite clear why then the "AND" operator works in connecting columns in SA2 (line before the last).

I checked the result of the SA1 <- SA0 ^ Ai <- A0 assignment in the if statement by adding a line between the if and the otherwise statements with 'return SA1 if i=1' and it gave me 1 (instead of the 3 you probably expected). See also Stuarts analysis.

Likewise the last line in SA2 'works' in that it does not throw an error, but I doubt if you get the result in the matrix M that you were looking for.

As to the reason for the error message occurring with Ai-1 in the otherwise line, I'm still puzzling. Here the actual worksheet may be required because it DOES make a difference compared to a picture...

Success!

Luc

StuartBruff
23-Emerald II
(To:LucMeekes)

LucMeekes wrote:

As to the reason for the error message occurring with Ai-1 in the otherwise line, I'm still puzzling. Here the actual worksheet may be required because it DOES make a difference compared to a picture...

Does my worksheet work OK in your M11, Luc?

Stuart

LucMeekes
23-Emerald III
(To:StuartBruff)

Stuart,

No joy for (the top-left) SA1, the others are OK.

But SA2 gives a different result.

Luc

StuartBruff
23-Emerald II
(To:LucMeekes)

LucMeekes wrote:

Stuart,

No joy for (the top-left) SA1, the others are OK.

But SA2 gives a different result.Intr

Luc

Interesting, Luc.  It almost looks as though it's skipped the assignments for Mi,1 and Mi,2 during the first pass.

Stuart

anthony Queen wrote:


Using Mathcad v11, I tried a simple interaction, to update variables according to the movement of time (t).

Two points that have drawn me crazy: I guess the second does not have easy solution.

    1. In the picture below, I cannot really understand why the code SA1 does not work, and stops with error at Ai-1. I shall notice that  if I set t=1, it works. So the conditional "if" in SA1 seems ok. Can someone kindly explain what is the problem with t>1, while no problem is found in SA2 code?
    2. I made the error in another sheet - not in the one below - of setting my initial variables with the literal subscript (e.g. A.0) , even when the sbuscript is a number. I would like now to  "Replace" A.0, with a proper numerical subscript. But MC does not accept a paste of Math text into the Replace Window, for such subscript. Is there another way to write it in the Replace Window? Thanks.

Just to back up Luc's points ... I've changed gI to 1 to make the effects more obvious.  Your code doesn't seem to run into the same error in M15.  I don't know whether this is problem with my typing or M11.  There are several Mathcad constructs (such as the literal versus vector subscript problem you mention) that are difficult if not impossible to analyze without the offending worksheet.  I've attached an M11 version of my M15 worksheet  - do you still get the error?

Stuart

The first assignment yields the correct result, too, if typed in the correct way 😉

Probably its better to type parentheses

The Boolean AND between the two assignments has no effect and you could as well replace it by a comma

What you (I am referring to Stuarts sheet)  had typed was

StuartBruff
23-Emerald II
(To:Werner_E)

Werner Exinger wrote:

The first assignment yields the correct result, too, if typed in the correct way 😉

Probably its better to type parentheses

Indeed - or at least until we get an RPN or LISP version of Mathcad

But I didn't "Like" your post for that, Werner.   I did, however, like it for this.   

The Boolean AND between the two assignments has no effect and you could as well replace it by a comma

I didn't realize you could do this outside of a function call or for-loop sequence.   That's why I use the vector method for multiple assignment (which I think is necessary, regardless, for worksheet := multiple assignments).

Everyday's a learning experience

Stuart

Stuart, Werner many thanks for your precious feedback, and work!

Stuart: I have commuted since my last post, and now I am with my portable. With this other Mathacad (still v.11), the file you uploaded throws the same error (and message: "Value of subscript, etc.") I pointed out in my original post. All the other three cases instead work ok. Thanks for that!

So there is something in v.11 (at least in my versions) that fortunately is no longer present in v.15.

Werner: Using again the Stuart's file (in addition to mine), I can also say that if I substitute the "AND" operator with a "COMMA", even if I add parenthesis I got a "Illegal function value", and the two assignments SAi<-- SA_0 e Ai<--A_0 are in red.

Werner: Using again the Stuart's file (in addition to mine), I can also say that if I substitute the "AND" operator with a "COMMA", even if I add parenthesis I got a "Illegal function value", and the two assignments SAi<-- SA_0 e Ai<--A_0 are in red.

So there seem to be a bit more differences between MC11 and newer releases than we are aware of.

But using single assignments line by line or multiple assignment using a vector is the method which should be used, anyway.

Werner

RichardJ
19-Tanzanite
(To:Werner_E)

I've poked around at that in MC11 for over an hour, and I can't figure out why it fails. If I replace the otherwise statement with

SA[i<--i otherwise

then i takes the values 1, 1, 2, which is correct. So it makes no sense to me that A[i-1 should throw an error about the subscript being out of range, but it does.

Whatever. I'm not going to spend any more time trying to figure out why a dubious piece of syntax causes an error in a very old version of Mathcad

   I didn't realize you could do this outside of a function call or for-loop sequence.

Nor did I.

That's why I use the vector method for multiple assignment

Which is exactly what I would use, too, and what should be used anyway, I guess.

Werner

StuartBruff
23-Emerald II
(To:Werner_E)

Werner Exinger wrote:

   I didn't realize you could do this outside of a function call or for-loop sequence.

Nor did I.

That's why I use the vector method for multiple assignment

Which is exactly what I would use, too, and what should be used anyway, I guess.

Sadly, this idea has been killed off in its Prime ... it's Prime 3.1 to be exact.  It doesn't translate and I can't enter it. Curses.  Just when I was getting enthusiastic about this new shortcut.

Still, the Prime method of entering arrays makes the "conventional" approach a bit easier.   I find myself entering vectors explicitly in Prime rather than using stack, which I find easier in M15.  ... and I suppose, if one were feeling that way inclined, one could subvert a built-in arbitrary argument count function?

Stuart

Other unexpected result.

  1. Take with MC11 the code of SA1, (initial picture or Stuart's file).
  2. Remove "AND" operator and substitute it with "XOR" operator.
  3. That works.
  4. This may help to explain (by extension) why recent MC versions work also with "AND". If we let  work with "XOR", why not with "AND", programmers probably thought.

anthony Queen wrote:

Other unexpected result.

  1. Take with MC11 the code of SA1, (initial picture or Stuart's file).
  2. Remove "AND" operator and substitute it with "XOR" operator.
  3. That works.
  4. This may help to explain (by extension) why recent MC versions work also with "AND". If we let  work with "XOR", why not with "AND", programmers probably thought.

Possibly, but I doubt it.  It's more likely that whatever caused the problem disappeared as a side-effect of the major re-write that happened going from M11 to M12.  I'm afraid I can't see a programmer (project manager, system engineer, test engineer, software engineer, whatever) deciding to allow something; it's far more likely, IMO, they would have stopped it happening for any boolean.

Stuart

Top Tags