Small mathematica operator question

  • Context: Mathematica 
  • Thread starter Thread starter FocusedWolf
  • Start date Start date
  • Tags Tags
    Mathematica Operator
Click For Summary
SUMMARY

The discussion focuses on the use of replacement operators in Mathematica, specifically how to substitute values into expressions. Users demonstrate the syntax for replacing variables, such as using the replacement rule syntax (/.), exemplified by the expression yy = E^T*C[1]+C[2] /. {C[1] -> 1/6}. Additionally, the Block function is introduced for temporary variable assignment, allowing for localized substitutions within expressions. The conversation clarifies that both methods are valid for achieving similar outcomes in Mathematica.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of variable substitution and replacement rules
  • Basic knowledge of mathematical expressions in programming
  • Experience with temporary variable assignment using Block
NEXT STEPS
  • Explore advanced variable substitution techniques in Mathematica
  • Learn about the use of the ReplaceAll function in Mathematica
  • Investigate the implications of using Block for variable scoping
  • Study the differences between local and global variable assignments in Mathematica
USEFUL FOR

Mathematica users, mathematicians, and programmers looking to enhance their skills in variable manipulation and expression evaluation within the Mathematica environment.

FocusedWolf
Messages
81
Reaction score
0
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:
Physics news on Phys.org
Code:
yy = E^T*C[1]+C[2] /. { C[1] -> 1/6 }
 x + y /. {x -> 2, y -> 1}
or just
Code:
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:
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)
 
Thx that'll do :cool:
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K