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

Is it an error in Mathcad?

ValeryOchkov
24-Ruby IV

Is it an error in Mathcad?

Err.png

1 ACCEPTED SOLUTION

Accepted Solutions


@ValeryOchkov wrote:

Is it an error in Mathcad?


Not at all. Its the behaviour as it should be.

Note that the global b and the local b have nothing to do with each other! The local b is a new variable created by the program and as you don't provide a value for the element with index 0, this element is initialized with 0 as usual.

If you want a global variable to be used in a program you have to either provide it as an argument of your function or you must use it on the right hand side of a local assignment as you did with variable a.

In your program "a" is local only for a sort moment. after the fist assignment which introduces the global "a" on the right hand side it turns into the global variable. As ttokoro showed, just "mentioning" b (his first program line) does the job as well. I am not sure if this behaviour is OK from a purists point of view. The "normal" way to do it used to be the dummy assignment  b <-- b.

Werner_E_0-1593822062169.png

P.S.: It looks like you are using a 4K monitor like me (in combination with a large windows zoom factor). Thats the reason your screenshots are far too large when you embed them here. To make your post better readable I would advice that you either scale down the pics with an appropriate program or at least resize them after you embed them in your post.

View solution in original post

2 REPLIES 2
ttokoro
20-Turquoise
(To:ValeryOchkov)

Prime.6

image.png


@ValeryOchkov wrote:

Is it an error in Mathcad?


Not at all. Its the behaviour as it should be.

Note that the global b and the local b have nothing to do with each other! The local b is a new variable created by the program and as you don't provide a value for the element with index 0, this element is initialized with 0 as usual.

If you want a global variable to be used in a program you have to either provide it as an argument of your function or you must use it on the right hand side of a local assignment as you did with variable a.

In your program "a" is local only for a sort moment. after the fist assignment which introduces the global "a" on the right hand side it turns into the global variable. As ttokoro showed, just "mentioning" b (his first program line) does the job as well. I am not sure if this behaviour is OK from a purists point of view. The "normal" way to do it used to be the dummy assignment  b <-- b.

Werner_E_0-1593822062169.png

P.S.: It looks like you are using a 4K monitor like me (in combination with a large windows zoom factor). Thats the reason your screenshots are far too large when you embed them here. To make your post better readable I would advice that you either scale down the pics with an appropriate program or at least resize them after you embed them in your post.

Top Tags