Mathematica Replacing Mass in Equations of Motion: Quick Mathematica Question

  • Thread starter Thread starter kq6up
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
To replace one or both masses with a negative mass in Mathematica, using a direct substitution like m1 = -m1 leads to infinite recursion. A recommended approach is to use replacement rules, such as eq /. {m1 -> -m1}, which effectively changes every occurrence of m1 to -m1 without causing recursion. Another suggestion is to introduce a temporary variable, like mm1, to facilitate the substitution. This method allows for handling complex equations of motion more easily. Learning and applying replacement rules in Mathematica can greatly streamline the process.
kq6up
Messages
366
Reaction score
13
I have equation of motion that our instructor wants to replace one or both of the masses with a negative mass in Mathematica. I tried m1=-m1, but I get an infinite recursion. What is the best way to do this? The equations of motion is a monster, so I don't really want to do this by hand.

Thanks,
Chris
 
Physics news on Phys.org
Just a thought: Replace m1 by mm1 or some such, then replace mm1 by - m1. This may allow you to fool the computer.
 
Yes, I ended up doing something just like that ##m_1=-m_{11}##.

Thanks,
Chris
 
kq6up said:
I have equation of motion that our instructor wants to replace one or both of the masses with a negative mass in Mathematica. I tried m1=-m1, but I get an infinite recursion. What is the best way to do this? The equations of motion is a monster, so I don't really want to do this by hand.
The easiest way is:
eq /.{m1 -> -m1}

This goes through the expression eq and replaces every occurrence of m1 with -m1. It is very worthwhile learning this technique of using replacement rules.
 
Awesome, thank you.

Chris
 

Similar threads

Replies
1
Views
2K
Replies
4
Views
2K
Replies
9
Views
3K
Replies
3
Views
2K
Replies
12
Views
2K
Replies
3
Views
2K
Replies
4
Views
3K
Replies
4
Views
4K
Replies
19
Views
4K
Replies
1
Views
2K
Back
Top