Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Small mathematica operator question

  1. Oct 15, 2007 #1
    Hi,

    Quick question. In the ti89 i can do this:

    x+1|x=2
    Answer = 3

    It works like x + 1 given x = 2...do 2+1 = 3. I'm not sure what the '|' operator would be called in this case...

    Anyway, is this shorthand possible in mathematica?

    like if i had: yy = E^T*C[1]+C[2], and i wanted to specify C[1]=1/6... what would do it?
     
    Last edited: Oct 15, 2007
  2. jcsd
  3. Oct 15, 2007 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Code (Text):
    yy = E^T*C[1]+C[2] /. { C[1] -> 1/6 }
     x + y /. {x -> 2, y -> 1}
     
    or just
    Code (Text):
    yy = E^T*C[1]+C[2] /. C[1]->1/6
    x+1 /. x -> 2
     
    if you have only one replacement.

    You can also do
    Code (Text):
    Block[ {C[1]=1/6},
       E^T*C[1]+C[2]
     ];
     
    if you need the expression more often, but since you assign it anyway that's not necessary here (thought I generally prefer not assign variables)
     
  4. Oct 15, 2007 #3
    Thx that'll do :cool:
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook