%%
%% 2.2 Lorentz transformation LT (Computational example)
% \left( {x\prime \atop ct\prime} \right)=LT\left( {x \atop ct} \right), \ LT=\left({a_{11}\ a_{12} \atop a_{21}\  a_{22}}\right)
%

clear all
syms a_11 a_12 a_21 a_22 real
syms x ct v xb c ctb real

%% 1 Basics
% Four-space in reference system S:\[\vec r = \left( {\begin{array}{*{20}{c}}
%   x \\
%   {ct}
% \end{array}} \right)\], in S\prime:\[\vec {r'} = \left( {\begin{array}{*{20}{c}}
%   {x'} \\
%   {ct'}
% \end{array}} \right)\]
% Metric: \[G=\left( {{g_{\mu \nu }}} \right) = \left( {\begin{array}{*{20}{c}}
%   1&0 \\
%   0&{ - 1}
% \end{array}} \right)\]
% Lorentz transformation: \[{T_L} = \left( {\begin{array}{*{20}{c}}
%   {{a_{11}}}&{{a_{12}}} \\
%   {{a_{21}}}&{{a_{22}}}
% \end{array}} \right)\]

r_v=[x;ct]

% Metric: \[G= \left( {\begin{array}{*{20}{c}}
%   1&0 \\
%   0&{ - 1}
% \end{array}} \right)\]

G=[1 0;0 -1]

% Approach for the Lorentz transformation \[{T_L} = \left( {\begin{array}{*{20}{c}}
%   {{a_{11}}}&{{a_{12}}} \\
%   {{a_{21}}}&{{a_{22}}}
% \end{array}} \right)\]

LT1=[a_11 a_12;a_21 a_22]

% so

r_vb=LT1*r_v

%
%% 2 Transformation into the rest frame
% Origin of S' in S: \[\left( {\begin{array}{*{20}{c}}
%   0 \\
%   {ct'}
% \end{array}} \right) = {T_L}\left( {\begin{array}{*{20}{c}}
%   x \\
%   {ct}
% \end{array}} \right){\text{ }}\quad {\text{und }}\quad x = vt\]
% so: \[\vec {r'} = \left( {\begin{array}{*{20}{c}}
%   0 \\
%   {ct'}
% \end{array}} \right),\quad v = \frac{x}{t} = \frac{{cx}}{{ct}}\quad  \to \quad {a_{12}}\left( {{a_{11}}} \right)\]
% Rest frame

RS=[xb==0 x==ct*v/c]

% substitution in \vec r \prime

sube(r_vb,RS)
a_12=solve(ans(1,1),a_12)

% The Lorentz transformation is therefore

LT2=subs(LT1)

% and \vec r \prime

r_vb=eval(r_vb)

%
%% 3 Lorentz transformation
% Equating the lengths of the four-vectors leads to the other three equations:
% Invariance:  \[{\left( {\vec r} \right)^2} = {\left( {\vec r'} \right)^2},\quad \left( {{{\left( {\vec r} \right)}^2} = {g_{\mu \nu }}{x^\mu }{x^\nu } = {{\vec r}^t}\left( {{g_{\mu \nu }}} \right)\vec r} \right)\]

r_vb'*G*r_vb==r_v'*G*r_v

% all to one side:

rhs(expand(ans-lhs(ans)))

% Coefficients of x^2,\ xct\ {\rm and\ } (ct)^2

Coeff=coeffs(ans,[x ct])

% all coefficients have to be 0  \to\ a_{ij}

assumeAlso(v>0 & v<c)
Sol=solve(Coeff,[a_11 a_21 a_22],'ReturnConditions',true);
SN=1;
ME=[a_11==Sol.a_11(SN),a_21==Sol.a_21(SN),a_22==Sol.a_22(SN)];
LT=simplify(sube(LT2,ME),'Steps',20)

% Save LT for further use in Chap 2.3

save Kap02 LT