# How to perform a coordinate transformation in a function?

26 views (last 30 days)
Kovács on 23 Dec 2023
Edited: Kovács on 24 Dec 2023
I want to perform a coordinate transformation on a ds square. I have never used MatLab before. I have entered the original expression, I will enter how the new coordinates depend on the original ones. Here I get stuck: how should I tell it to substitute into the ds square function?
##### 3 CommentsShow 1 older commentHide 1 older comment
John D'Errico on 24 Dec 2023
This is not a question about knowing MATLAB, but a question of understanding what a coordinate transform means, and how you would "apply" such a thing.
For example, suppose you have coordinates, (x,y). Then you might wish to convert to polar coordinates. That is a coordinate transform. You can do so by a simple set of equations, or you can use the cart2pol function in MATLAB.
Even more simply, given coordinates (x,y), then the pair (x+1,y+2) is a coordinate transform, a simple translational one.
The problem is, we have no idea what you are doing, what transformation you would employ, or how you would use it in code. I could see cases where you might use the coordinate transform in a purely mathematical way, so before you write any code at all. Or it might become an essential part of your code.
You need to be far more clear if you want a useful answer.
Kovács on 24 Dec 2023
Edited: Kovács on 24 Dec 2023
I understand, thank you for your response. To be more precise: there is a square of ds , used in relativity theory, which is a function with four variables (t, x, y, z), on the picture is (2). From this, I want to transform two variables in the following way, containing sine and cosine. So there will be two new coordinates, instead of x and t. The result should be the Rindler metric shown in (3). But as I tried it on paper, it didn't come out exactly that, on the other hand I would like to learn how to do this on a computer, since it is very often a similar calculation necessary in spacetime analysis. John D'Errico, Torsten

David Goodmanson on 24 Dec 2023
Hi Kovacs
Here is one way. Clearly
x^2 + t^2 = xi^2
by inspection, so that factor, which is common to both terms, can be saved till the end.
syms x t xi lam dxi dlam
x = xi*cos(lam)
t = xi*sin(lam)
dx = diff(x,lam)*dlam + diff(x,xi)*dxi
dt = diff(t,lam)*dlam + diff(t,xi)*dxi
ds2 = simplify((1/xi^2)*((-dt^2+dx^2)*(x^2-t^2) +4*x*t*(dx*dt)))
ds2 = - dlam^2*xi^2 + dxi^2
Kovács on 24 Dec 2023
Edited: Kovács on 24 Dec 2023
Thank you very much, David Goodmanson , excellent solution. I did it with the full expression according to this. The key is to use the "simplify" and "diff" commands. I learned a lot from it. Ideteszem az eredeti cikk forrását, ha érdekelne: TARDIS spacetime

### Categories

Find more on Assumptions in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!