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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Translate the entire conversation x

"Resetting" variabes

AA_10775414
2-Explorer

"Resetting" variabes

Hi,

 

Is it possible to reset variables? For example, if I want to have one file with multiple different calculations inclduing a variable for diameter, is it possible to have a line break or something, so that any variables above it are not used? Therefore variable for diameter needs to be redefined again. 

 

I know that just re-using the same variable redefines it, and that I could use D, D_1, D_2 and so on, but I do not find these acceptable solutions as it increases potential for calculating errors.

 

And sorry for asking this, I know this must be a common question, but I don't seem to be finding the old ones.

 

AA_10775414_0-1768204411103.png

 

ACCEPTED SOLUTION

Accepted Solutions

There are several potential ways to solve this problem.

 

The most direct method is to use the build-in Clear for functions, clear and clear.sym.

 

https://support.ptc.com/help/mathcad/r11.0/en/#page/PTC_Mathcad_Help/variable_clearing_functions.html%23wwID0EAI5EB

 

Is there a reason why simply assigning new values won't work?

 

Alternatively, you could write a function to encapsulate your equations. Your main variables could, for example, be passed to the function as its arguments, whilst any other variables could be defined locally within the function.

 

https://support.ptc.com/help/mathcad/r11.0/en/#page/PTC_Mathcad_Help/about_user-defined_functions.html%23wwID0EAYDQ

 

Unfortunately, I’m not near a PC at the moment, so can’t give examples. 

Stuart

View solution in original post

4 REPLIES 4

There are several potential ways to solve this problem.

 

The most direct method is to use the build-in Clear for functions, clear and clear.sym.

 

https://support.ptc.com/help/mathcad/r11.0/en/#page/PTC_Mathcad_Help/variable_clearing_functions.html%23wwID0EAI5EB

 

Is there a reason why simply assigning new values won't work?

 

Alternatively, you could write a function to encapsulate your equations. Your main variables could, for example, be passed to the function as its arguments, whilst any other variables could be defined locally within the function.

 

https://support.ptc.com/help/mathcad/r11.0/en/#page/PTC_Mathcad_Help/about_user-defined_functions.html%23wwID0EAYDQ

 

Unfortunately, I’m not near a PC at the moment, so can’t give examples. 

Stuart

Thank you!

 

That's exactly what I needed. Would be slightly more convinient if it would clear everything without needing to type every variable, but it's easy enough to copy-paste.

 

Simply assigning new values works, but it introduces a very high risk for miscalculations. If you forgot to redefine something, it would not be immediately obvious that an incorrect value is being used. but if all variables are clered, it is obviously not possible to end up with wrong results.

LucMeekes
23-Emerald IV
(To:AA_10775414)

Unfortunately any form of ALL, or * doesn't work to clear all variables.

Note that you can clear ORIGIN, but you cannot clear NaN:

LucMeekes_0-1768210937025.png

Success!

Luc

Werner_E
25-Diamond I
(To:LucMeekes)


Note that you can clear ORIGIN, but you cannot clear NaN:

Interesting!

I did not expect to be able to 'clear' NaN  as NaN is used wherever a number is valid and you can't clear a number either..

But I would call it a bug that we can clear system variables like ORIGIN, TOL and CTOL!

And, yes, I also miss some kind of clearAll() and clearAll.sym().

 

BTW, trying to do this

Werner_E_0-1768219460112.png

seems to force Prime's calculation into and endless loop. So it's clearly a bug. Who's willing to officially report it to PTC?

Note that ORIGIN must be manually labelled as "System" for this to 'work' and that we use a vector index "3".

Trying to 'clear' a system variable should either throw an error or it should reset it to its default value (I'm not quite sure yet which of these I should consider more sensible).

Announcements

Top Tags