3

I do not know enough about Mathematica to understand why the following statement won't save the variable for me for later use:

x_fake = Table[i, {i, 1, 100}]

It generates a list of fake x values from 1 to 100 with increments of 1. I want to use this list later to plot:

ListPlot[x_fake]

But it doesn't work and throws the errors

"Rule: Pattern x_fake appears on the right-hand side of rule..." and "ListPlot: x_fake is not a list of numbers or pairs of numbers"

Although the reason must be very simple, I can't seem to find a straightforward answer. The Wolfram docs indicate that in Mathematica there is a difference between immediate and delayed execution, so I tried the delayed execution syntax

x_fake := Table[i, {i, 1, 100}]

But it throws the same errors.

How can I save x_fake and reuse it like I can with R or any other normal programming language?

rhermans
  • 36,518
  • 4
  • 57
  • 149
brienna
  • 1,071
  • 5
  • 12

1 Answers1

6

The underscore is a reserved character. Effectively, you are writing

Pattern[x, Blank[fake]]

you can see this by looking at FullForm[x_fake]. You then get the message whenever you try to use it because x_fake, a Pattern, appears on the right hand side of a rule, like Set or SetDelayed. Variable names must start with a character, but otherwise can contain a mix of characters and numbers. Note, this includes the full character table, such as \[Alpha].

As an example found in ref/ImplicitRegion, this uses \[ScriptCapitalR]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
rcollyer
  • 33,976
  • 7
  • 92
  • 191