Change variables and expand around new variable (Mathematica)

In summary, the speaker is trying to expand a differential expression to a certain order around infinity in order to calculate weak-field limits in GR. They are encountering errors in Mathematica and are seeking guidance on how to properly change variables and have Mathematica perform the chain rule. They have also tried using Maple, which has a dchange function that can accomplish this task. They are seeking help in achieving the same functionality in Mathematica.
  • #1
ramparts
45
0
I have a differential expression that I want to expand to some order around infinity (it's for calculating weak-field limits in GR). I have two functions, B(r) and n(r), and some expression involving them along the lines of

n[r] (3 r B'[r]^2 - 4 B[r] (2 B'[r] + r B''[r]))

Basically I want to change variables to x=1/r and expand this expression around x=0 to, say, 5th order. This seems like it would be fairly simple, but I must be doing something wrong because Mathematica keeps giving me errors like

General::ivar: "1/r is not a valid variable."

I've tried several ways of doing this, but I'm still learning Mathematica so I'd appreciate having the right way pointed out! Thanks.

(I've also tried expanding around {r,Infinity,5} and just gotten a symbolic result which wasn't useful.)
 
Mathematics news on Phys.org
  • #2
I don't have Mathematica, but I suggest that you create a simplified example of this situation and see if error happens. If it does, you can post the example. If it doesn't, it might lead to some other aspect of the problem that you failed to capture in the example.
 
  • #3
I think the problem boils down to this: given a differential expression (like the one I posted) I don't know how, in Mathematica, to change variables and have Mathematica do all the chain rule through. I've since learned that Maple can do this (and indeed I've been using Maple for what I need to do) with its dchange function in the PDETools. I wonder how one can get the same functionality within Mathematica.
 
  • #4
I can't help with that. I suggest you ask in the forum section Physics Forums > Other Sciences > Computing & Technology. > Math & Science Software
 
  • #5


Thank you for your question. In order to expand your expression to a certain order around infinity using Mathematica, you can use the following steps:

1. Define your functions B[r] and n[r] using the "Set" command, for example:

B[r_]:= 1/r

n[r_]:= r^2

2. Use the "Series" command to expand your expression to the desired order, using the variable x=1/r and specifying the order as 5:

Series[n[r] (3 r B'[r]^2 - 4 B[r] (2 B'[r] + r B''[r])), {x, 0, 5}]

This will give you the expanded expression in terms of the variable x.

3. You can then substitute back in the original variable r by using the "ReplaceAll" command, for example:

%/.x->1/r

This will give you the expanded expression in terms of the original variable r.

Hope this helps! If you have any further questions, please feel free to ask.
 

FAQ: Change variables and expand around new variable (Mathematica)

What is the purpose of changing variables in Mathematica?

Changing variables in Mathematica allows you to manipulate and simplify mathematical expressions by substituting new variables for existing ones. This can make complex calculations and equations more manageable and easier to work with.

How do I change variables in Mathematica?

To change variables in Mathematica, you can use the ReplaceAll function, denoted by /.. This function takes two arguments, the first being the expression you want to manipulate and the second being the replacement rule. For example, expr /. x -> y will replace all instances of x in expr with y.

Can I expand an expression around a new variable in Mathematica?

Yes, you can expand an expression around a new variable in Mathematica using the Series function. This function takes three arguments, the expression to expand, the variable to expand around, and the order of the expansion. For example, Series[expr, {x, x0, n}] will expand expr around x0 to nth order.

What are the benefits of expanding an expression around a new variable?

Expanding an expression around a new variable can help simplify and approximate complex equations, making them easier to understand and work with. It also allows you to analyze the behavior of an expression as the variable approaches different values.

Can I change variables and expand an expression at the same time in Mathematica?

Yes, you can use the Series function to both change variables and expand an expression around a new variable. For example, Series[expr /. x -> y, {y, y0, n}] will first replace all instances of x with y in expr and then expand it around y0 to nth order.

Similar threads

Replies
6
Views
2K
Replies
5
Views
1K
Replies
2
Views
605
Replies
3
Views
1K
Replies
4
Views
1K
Back
Top