Clear [ s 1 , s 2 , … ]

clears values and definitions for the symbols s i .

Clear [ patt 1 , patt 2 , … ]

clears values and definitions for all symbols whose names textually match any of the arbitrary string patterns patt i .

Clear [ { spec 1 , spec 2 , … } ]

clears values and definitions for any symbols that are equal to or whose names match any of the spec i .

variable assignment mathematica

  • Clear does not clear attributes, defaults, options or messages associated with symbols. »
  • The pattern patt can be given as a string with metacharacters, as StringExpression [ … ] or as RegularExpression [ " regex " ] . »
  • Clear allows abbreviated string patterns containing the following metacharacters:
  • Clear [ " context `*" ] clears all symbols in a particular context. »
  • Clear [ "`*" ] clears all symbols in the current context. »
  • Clear does not affect symbols with the attribute Protected . »
  • Clear has attribute HoldAll . »

Basic Examples     (2)

Clear a variable:

The variable no longer has a value:

Define values for a symbol:

Clear values:

Scope     (12)

Symbol inputs     (7).

Clear values of variables (ownvalues):

Clear functions (downvalues):

Clear upvalues:

Clear subvalues:

Clear formatting:

Clear several symbols:

Use a combination of symbols and symbol names:

Only x3 remains defined:

Using Patterns     (5)

Specify symbols to clear as string patterns:

Clear all symbols in the current context:

Clear all symbols in a given context:

Clear all 2-character symbols in the current context using StringExpression :

The symbols x1 and x2 were cleared, but y remains unaffected:

Clear all 3-character symbols in the current context using RegularExpression :

Applications     (2)

Clear any old definitions before making new ones:

Unprotect and clear all symbols in a package, to allow it to be read twice:

Properties & Relations     (6)

Clear [ pattern ] clears the same symbols as Clear/@ Names [ pattern ] :

Use Unset ( =. ) to clear definitions with a particular left-hand side:

Clear all definitions:

Clear does not remove attributes, defaults or options:

Use ClearAll to clear everything:

Clear does not remove messages:

Use ClearAll to clear messages:

Clear removes all definitions but leaves the symbol intact:

Remove removes the symbol completely:

Clear has the attribute HoldAll :

This clears symbol itself:

This clears its value:

Possible Issues     (2)

Protected symbols cannot be cleared:

Use Unprotect to clear definitions of protected symbols:

When using a pattern without a context mark, all matching symbols on $ContextPath are cleared:

The symbol xy was cleared, along with attempts to clear several system symbols:

Use a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:

ClearAll   Unset   TagUnset   ClearAttributes   Remove   Unprotect   Names   Definition   OwnValues   DownValues   Attributes   MakeBoxes   Format   WithCleanup

  • Defining Variables
  • Defining Functions
  • Making Definitions
  • Manipulating Symbols and Contexts by Name
  • Memory Management

Related Guides

  • Tuning & Debugging
  • Memory Measurement & Optimization
  • Assignments
  • Defining Variables and Functions
  • Symbol Handling

Related Workflows

  • Clear Definitions for Symbols and Functions

Related Links

  • Fast Introduction for Programmers: Function Definitions
  • An Elementary Introduction to the Wolfram Language : Assigning Names to Things
  • An Elementary Introduction to the Wolfram Language : Defining Your Own Functions

Introduced in 1988 (1.0) | Updated in 2022 (13.2)

Wolfram Research (1988), Clear, Wolfram Language function, https://reference.wolfram.com/language/ref/Clear.html (updated 2022).

Wolfram Language. 1988. "Clear." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Clear.html.

Wolfram Language. (1988). Clear. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Clear.html

@misc{reference.wolfram_2023_clear, author="Wolfram Research", title="{Clear}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Clear.html}", note=[Accessed: 17-April-2024 ]}

@online{reference.wolfram_2023_clear, organization={Wolfram Research}, title={Clear}, year={2022}, url={https://reference.wolfram.com/language/ref/Clear.html}, note=[Accessed: 17-April-2024 ]}

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how

IMAGES

  1. Systems of Equations

    variable assignment mathematica

  2. Solve Equations Multiple Variables Mathematica

    variable assignment mathematica

  3. Using variable names as strings in Mathematica

    variable assignment mathematica

  4. Solve Equations Multiple Variables Mathematica

    variable assignment mathematica

  5. wolfram language

    variable assignment mathematica

  6. How To Solve An Equation For A Variable In Mathematica

    variable assignment mathematica

VIDEO

  1. [Algorithm Session 01]

  2. 6 storing values in variable, assignment statement

  3. Declare Variable in Mathematica

  4. Swapping Variants Using Variables

  5. HTML Class-13, Title and meta tag importanceđź”´Live

  6. Initial value problem || Variable separable form

COMMENTS

  1. Assignments—Wolfram Language Documentation

    The Wolfram Language's symbolic architecture supports a highly generalized notion of assignment, in which you can specify a transformation for any class of expressions defined by a Wolfram Language pattern. Simple cases correspond to assignments for "variables", "indexed variables", or "structure elements". Other cases define functions or general transformations.

  2. Assign the results from a Solve to variable(s)

    $\begingroup$ I agree that often you just want to use rules, but in my case I'm trying to set a global variable before going on to solve for other things (where Solve will work better if it has this global value instead of trying to remain general for all possible values). I tried the equivalent of Set[sols[[1]]], and when that didn't work.Of course the "help" file is no help because it ...

  3. Assigning Names to Things: Elementary Introduction to the ...

    If you expect to refer to a result later, you can assign it a name. For example, you can say thing= Range [10] to assign thing as a name for the result of Range [10]. You can assign a name to the result of a computation even if you never display the result. End your input with ; (semicolon) to avoid seeing the result.

  4. assignment

    The idea here is to assign automatically the variables a, b, c and x to a function so it becomes something like that: fn[x_,a_,b_,c_] := a*x^2 + b*x + c. In order to do this I've tried to extract the varibles from fn using Variables: Sort@Variables@fn. {a, b, c, x} Then in order to apply it to the function fn I do the following:

  5. Variable assignment/replacement issues

    3. I have three questions about variable assignment. When I run the above code, it outputs 0. 1) If I run the same code outside the Module, it gives me 1. Why isn't the local z treated like the global case (which I can understand)? 2) If I remove the call to Evaluate (and run without the module), it again gives me 0.

  6. Assign variable in mathematica

    Here's some unasked for help: PD.= does not have a syntactically-correct form, nor does P./; don't expect the variable pi to be interpreted to have the value 3.14159...; finally, it's unusual in Mathematica to make an assignment in a function to a variable with the same name as the function, a Module will return a value or values if you write it properly.

  7. Mathematica Module 1: Variables, Commenting Code, and ...

    Mathematica is utilized a tool to analyze data. Here we demonstrate how to assign values to variables, comment code, and perform numerical operations.

  8. Multiple variable assignment from a list

    Closed 3 years ago. Improve this question. For example in Python, if we have a list of 3 elements, say ls = [1,2,3] and we want to assign a variable to each value (from left to right), one can do as follows: x,y,z = ls where then, x will take the value 1 and so on. Now if we have a list in Mathematica ls = {1,2,3}, is there an analogous way of ...

  9. See currently assigned variables in Mathematica

    1. Mathematica associates with each symbol a set of values. OwnValues is the one that stores value assignments to the symbol. This code returns the list of symbol names (as strings) for those symbols whose OwnValues is non-empty, i.e. the symbol has been assigned a value: Select[Names["Global`*"], ToExpression[#, InputForm, OwnValues ...

  10. assignment

    1. @tchronis You should not need the injector pattern here; a straightforward assignment will work: SetAttributes[assign, HoldFirst]; assign[association_, key_, val_] := association[key] = val. Much of the time I would just write out (asc[#] = #2) & however if I needed to apply that across a set of keys and values.

  11. Common due-date assignment problems with fixed-plus-linear earliness

    Abstract. We study single machine scheduling and common due-date assignment problems. The cost considered is fixed plus linear, i.e., jobs are penalized by two cost components: (i) a variable cost which is proportional to their earliness/tardiness values, (ii) a fixed cost which is independent of their actual earliness/tardiness values.

  12. scoping

    Here is an example code: a = 1; b = 1; c = a + b; f[x_, y_] := Module[{a = 3, b = 2, c}, c = (x + y)*(a + b)]; a,b,c are used outside of the function f and also inside f. How can I ensure that all used variables in a function are local WITHOUT specifing all of them in Module[{local variables},...]. This can be extremely annoying when I use many ...

  13. Clear: Remove values and definitions from symbols—Wolfram Documentation

    removes all definitions but leaves the symbol intact: removes the symbol completely: has the attribute : This clears itself: This clears its value: Possible Issues (2) Protected symbols cannot be cleared: Use to clear definitions of protected symbols: When using a pattern without a context mark, all matching symbols on are cleared:

  14. list manipulation

    Thanks for contributing an answer to Mathematica Stack Exchange! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. Use MathJax to format equations.