Quick Mathematica Question

  • #1
366
11
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
 

Answers and Replies

  • #2
OldEngr63
Gold Member
732
51
Just a thought: Replace m1 by mm1 or some such, then replace mm1 by - m1. This may allow you to fool the computer.
 
  • #3
366
11
Yes, I ended up doing something just like that ##m_1=-m_{11}##.

Thanks,
Chris
 
  • #4
Dale
Mentor
Insights Author
2020 Award
31,320
8,105
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.
 
  • #5
366
11
Awesome, thank you.

Chris
 

Related Threads on Quick Mathematica Question

  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
5K
  • Last Post
Replies
8
Views
2K
  • Last Post
Replies
3
Views
9K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
10
Views
6K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
1K
Top