Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Some functions such as Plot (and FindRoot) can use the option Evaluated -> True -- for these this is superior to other methods because the range variable is still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described herethe methods I described here.

Example using the pure function method:

W1 = {p, -2, 2, 0.5};
P = W1;

ContourPlot[#, {x, -5, 5}, {y, -5, 5}] &[
  Union[Table[y^2 == 2 p*x, #], Table[x^2 == 2 p*y, #]] & @ P
]

Mathematica graphics

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Some functions such as Plot (and FindRoot) can use the option Evaluated -> True -- for these this is superior to other methods because the range variable is still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described here.

Example using the pure function method:

W1 = {p, -2, 2, 0.5};
P = W1;

ContourPlot[#, {x, -5, 5}, {y, -5, 5}] &[
  Union[Table[y^2 == 2 p*x, #], Table[x^2 == 2 p*y, #]] & @ P
]

Mathematica graphics

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Some functions such as Plot (and FindRoot) can use the option Evaluated -> True -- for these this is superior to other methods because the range variable is still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described here.

Example using the pure function method:

W1 = {p, -2, 2, 0.5};
P = W1;

ContourPlot[#, {x, -5, 5}, {y, -5, 5}] &[
  Union[Table[y^2 == 2 p*x, #], Table[x^2 == 2 p*y, #]] & @ P
]

Mathematica graphics

added 276 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Specific to plottingSome functions such as Plot (and FindRoot) you shouldcan use the option Evaluated -> True -- for these this is superior to other methods in thatbecause the range variable areis still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described here.

Example using the pure function method:

W1 = {p, -2, 2, 0.5};
P = W1;

ContourPlot[#, {x, -5, 5}, {y, -5, 5}] &[
  Union[Table[y^2 == 2 p*x, #], Table[x^2 == 2 p*y, #]] & @ P
]

Mathematica graphics

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Specific to plotting functions (and FindRoot) you should use the option Evaluated -> True -- this is superior to other methods in that the range variable are still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described here.

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Some functions such as Plot (and FindRoot) can use the option Evaluated -> True -- for these this is superior to other methods because the range variable is still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described here.

Example using the pure function method:

W1 = {p, -2, 2, 0.5};
P = W1;

ContourPlot[#, {x, -5, 5}, {y, -5, 5}] &[
  Union[Table[y^2 == 2 p*x, #], Table[x^2 == 2 p*y, #]] & @ P
]

Mathematica graphics

Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

You needed Evaluate because you want evaluation of an argument that is normally held, both in the case of ContourPlot and Table. There are several ways to force this evaluation.

  1. Evaluate causes evaluation of an argument before the function reads it, or even "sees" it for pattern matching. It only works at the first level of the function, meaning it must wrap (be the head of) an argument, and not a sub-expression. Compare: Hold[Evaluate[2 + 2], 3 + 3] and Hold[5 + Evaluate[2 + 2]]. (Hold is used as a representative of an arbitrary function with the HoldAll attribute.)

  2. Specific to plotting functions (and FindRoot) you should use the option Evaluated -> True -- this is superior to other methods in that the range variable are still correctly localized.

  3. You can use a function which does not have a Hold attribute to cause intermediate evaluation. The most direct way is a "pure function" using &:
    Hold[1 + 2 + #] &[2 + 2]
    This works because the & function evaluates its argument before Hold ever sees it, and # (Slot) can appear anywhere in the body of the function, not merely the first level.

  4. As Rojo stated you can use With to do a lexical replacement of specific variables: With[{x = 2 + 2}, Hold[x, 3 + 3]]

  5. More complicated evaluations and insertion may be achieved using the methods I described here.