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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Isolate a block area from the rest of the Mathcad sheet

anthonyQueen
8-Gravel

Isolate a block area from the rest of the Mathcad sheet

I am still using MC 11.2

 

Sometimes I solve a set of math exercises, let say three of them, in the same MC document since they belong to the same exam.

I was looking for a way to separate completely one exercise from the others, not only in terms of  layout (using "Insert Area"), but also in terms of variable definitions. In this way a variable defined in the first exercise would not be seen (and used) in the second and third exercise. This to avoid overlappings of data.

 

Is there a way to do this, like a command "clear variables", or isolation blocks,  that are in use in other math software? If not, is there a workaround to achieve the same result?

 

Thank you.

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

Hi Anthony,

 

Mathcad does not have a 'clear variables' command. (Prime has,  but there are other things it doesn't have...).

Separate sheets gives the best isolation.

The second best is to undefine your variables at/after the end of every exrcise, using

var := var

to undefine the variable 'var', that is, it removes any definition (numeric or only the symbolic ones) attached to var.

The third best is to use unique variable names in each of your exercises. Attach the exercise number to each of your variables e.g...

 

Success!
Luc

Just reset the symbolic variables and give new values to the constants.

Hi,

Luc has the answer but has not gone far enough.  He said

"The second best is to undefine your variables at/after the end of every exercise, using

var := var

to undefine the variable 'var', that is, it removes any definition (numeric or symbolic) attached to var."

 

What he didn't add was you could put all these var:=var statements into a region which could be collapsed and leave just a line between each exercise.

 

Cheers

Terry

Thanks Luc,  MFranc and Terry,

I knew the "trick" of redefining the variable. But when there are many of them, there is the risk of leaving something behind.

Luc and Terry: the trick of clearing the variable with var := var seems not working in MC 11.2 (at least, with numeric values).

I agree, that apart of putting a single exercise in a single sheet, the other workaround is to add numbering to variables, according to the exercise that is referring to.

 

A.

LucMeekes
23-Emerald III
(To:anthonyQueen)

Anthony,

 

you are right.

var := var     only clears the symbolic definition of var. It leaves the numeric definition intact. For that you need to use MFranc's suggestion: Redefine var numerically. But then it's defined symbolically as well, but with a numeric value; that will impact subsequent symbolic manipulations using var.

Seems the third-best option might be the best option when you want all exercises in one sheet.

Or you solve all exercises the way I advise to do generally:

1. First solve your problem (as much as possible) purely symbolically; using undefined or cleared symbols.

2. Then fill in the numbers (if needed), which involves defining numerical values to variables as applicable.

 

Either way, you have to keep track of any variables you use.

 

Success!
Luc

To reset a variable symbolically AND numerically you may use the two step procedure shown in the picture.

But it sure is cumbersome and failure-prone to do so with all variables one by one.

B.png

The variable name "_-y-_" simply was chosen to ensure(?) its a name still undefined and unused.

Numerical clearing could be done using a vector, but symbolical clearing must be done singly one by one:

B2.png

 

LucMeekes
23-Emerald III
(To:Werner_E)

And the order in which you 'undefine' does matter.

First do the numeric, then the symbolic.

If you reverse that, your variable will be symbolically defined to whatever you chose as undefined symbol.

 

Success!
Luc

Thanks Werner_E you too.

 

I don't know if the following is too naive. But I notice that it is enough to use (at least for numeric definitions) the following to clear variables' content.

 

var :=.  (i.e. dot).

or also var :=""  (enough to type once the double inverted comma).

 

The first works also by putting in a vector all variables, and then equalizing the vector to this:=.

 

LucMeekes
23-Emerald III
(To:anthonyQueen)

Hmm, nice find, but it's not quite the same I fear.

LM_20190905_Undefine.png

(I wonder if Mathcad 15 is the same.)

 

Luc

Here is a pdf-print of your sheet from Mathcad 15.

As you can see MC15 acts differently than your MC11 in some cases.

 

What you suggest does not clear a single variable (makes it unknown) but just redefines it to a different value.

 

x:="" defines x a a an empty string

x:=. is equivalent to write x:=0

 

BUT ... if you do it with a vector (even if it contains just 1 element), things differ because a vector can't neither be assigned a simple scalar like 0 nor a string like "" and so is an invalid assignment  (similar to my suggestion of assigning an non-existent variable) and that way the vector elements get cleared.

Your method of assigning . or 0 to a vector has a big advantage over my suggestion above because it clears the variable for numeric AND symbolic in one single step. Nice find indeed!

B.png

 

Another interesting detail I just noticed (and was not aware of) is that numerics and symbolics react differently to x:=.

 

B2.png

So it looks like x:=. is equivalent to x:=x (with the difference of changing the numeric value to 0)

LucMeekes
23-Emerald III
(To:Werner_E)

I doubt the usefulness. Note that an undefined variable x should symbolically evaluate as:

 x -> x

And (In mathcad 11) there's a difference between assinging 0 or a . to a vector:

LM_20190906_Undefine.png

So when you assign a 0 or a . to a vector of variables it will set them undefined numerically, but you still need the

x := x

for each variable individually, to undefine them symbolically, such that they can be used.

From your pictures of Mathcad 15 I think it's the same there.

 

Luc


@LucMeekes wrote:

I doubt the usefulness.


You are quite right about that. The method does not help when it comes to clear variables for symbolic use.
The variables become useless for symbolic calculations unless you assign them a numeric value and then clear them one by one in the usual way.

Too bad, would have been a nice trick

B.png

Thanks again to all, Luc and Werner_E in particular.

 

Still naive here:

Let say I have x :=3, by using:

x:=x.   (the final dot comes hidden, since it is captured in MC11 as a way to put a text subscript, if I am correct)  gives

 

x =     (in red, i.e. empty), and symbolically it gives correctly

x --> x     and  solves dx^2/dx --> 2x

 The hidden dot is still there in the symbolic calculations, but can be put completely invisible just by typing a space after it x:=x.[space]. It works also in  case there is already  a text subscript, like xy - just add "." after y.

 

PS: @Werner_E  in MC 11 after using x :=.  I don't have x=0 as you are showing in MC15,  but x= (in red, i.e. undefined).

 

It does not matter if you assign x:=x. or if you use x:=x.new or any other variable name which was not used in the sheet.

As already written above this clear effectively the variable for numeric use, but when it comes to symbolics it does not the very same as x:=x is doing. Nevertheless it might suffice for some needs.

 


symbolically it gives correctly

x --> x     and  solves dx^2/dx --> 2x

Thats not correct! You get x --> x. and dx^2/dx --> 2x.

Note the dot after x. It looks like x, but it isn't. I can image that this is OK in a lot of occasions, but maybe not in all.

B.PNG


Thats not correct! You get x --> x. and dx^2/dx --> 2x.

Note the dot after x. It looks like x, but it isn't. I can image that this is OK in a lot of occasions, but maybe not in all.

 



I noticed that, thanks, and I was editing my last post, while you were posting yours.

You are correct: not exactly a pure "x"! But for most practical purposes it could work.


It works also in  case there is already  a text subscript, like xy - just add "." after y.

 


At least in MC15 in this case the dot remain visible but if you really like this method you could add a space at the end instead of the dot using the Ctrl-Shift.k method.

 

For my part, I do not particularly like the idea that the variable names displayed do not correspond to the real ones and I would rather take the trouble and add the additional region to clear the necessary variables symbolically the usual way.

B1.png

 

Another possible single solution that in MC11 seems to work for both numeric and symbolic calculations is to use a global definition like that.

previous definition:  x :=3

now: x ≡ x

result: x = (undefined) and with symbolics  x --> x  and  dx^2/dx --> 2x

So it looks like MC11 and MC15 behave differently here.

In MC15 this global assignment makes the variable unusable for symbolic calculations:

B.png

Unfortunately, it seems so. Probably this is due to the fact that from v.11 to v.15 the math engine has changed.

Top Tags