0

When I input to Mathematica as follows,

G = {
  {-1, 0, 0, 0},
  {0, 1, 0, 0},
  {0, 0, 1, 0},
  {0, 0, 0, 1}};
h = {
  {-h00/2, h01, h02, h03},
  {0, 0, 0, 0},
  {0, 0, 0, 0},
  {0, 0, 0, 0}};
L = G + h;
Lt = Transpose[L];
G2raw = Lt . G. L;
G2 = Expand[ G2raw ]

The value of G2 will be as follows.

{ {-1 - h00 - h00^2/4, h01 + (h00 h01)/2, h02 + (h00 h02)/2, h03 + (h00 h03)/2}, {h01 + (h00 h01)/2, 1 - h01^2, -h01 h02, -h01 h03},
{h02 + (h00 h02)/2, -h01 h02, 1 - h02^2, -h02 h03}, {h03 + (h00 h03)/2, -h01 h03, -h02 h03, 1 - h03^2} }

If [h00,h01,h02,h03] are very small values, I cut off secondary approximate parts and leave first approximate parts, and I'd like to obtain the following output.

{ {-1 - h00, h01, h02, h03}, {h01, 1, 0, 0}, {h02, 0, 1, 0},
{h03, 0, 0, 1} }

What kind of input should be added to Mathematica to obtain the above expected output ?

Thank you.

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • Hello ! Please, visit the help centre and read more about proper code formatting guidelines and format your post accordingly. Thank you ! – Sektor Jan 16 '15 at 12:42

4 Answers4

1

This is your input:

 G = {{-1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
h = {{-h00/2, h01, h02, h03}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 
    0}};
L = G + h;
Lt = Transpose[L];
G2raw = Lt.G.L;
G2 = Expand[G2raw]

yielding the following:

(*
{{-1 - h00 - h00^2/4, h01 + (h00 h01)/2, h02 + (h00 h02)/2, 
  h03 + (h00 h03)/2}, {h01 + (h00 h01)/2, 
  1 - h01^2, -h01 h02, -h01 h03}, {h02 + (h00 h02)/2, -h01 h02, 
  1 - h02^2, -h02 h03}, {h03 + (h00 h03)/2, -h01 h03, -h02 h03, 
  1 - h03^2}}
*)

you may use the rule:

   G2 /. {h00^_Integer -> 0, h01^_Integer -> 0, h02^_Integer -> 0, 
  h03^_Integer -> 0, h00*(h01 | h02 | h03) -> 0, h01*(h02 | h03) -> 0,
   h02*h03 -> 0}

(*  {{-1 - h00, h01, h02, h03}, {h01, 1, 0, 0}, {h02, 0, 1, 0}, {h03, 0, 
  0, 1}}  *)

Have fun!

Later edit: You may do the same another way around. Let us prepare the list

     M=3;
    lst = (Table[
    ToExpression["h0" <> ToString[n]]*
     ToExpression["h0" <> ToString[m]], {n, 0, M}, {m, 0, M}] // 
   Flatten)

(* {h00^2, h00 h01, h00 h02, h00 h03, h00 h01, h01^2, h01 h02, h01 h03, 
 h00 h02, h01 h02, h02^2, h02 h03, h00 h03, h01 h03, h02 h03, h03^2}   *)

If you have more terms, play with M. Now I would like to replace in this list each term h0N by the rule h0N->0. This may be done using the function:

f[x_] := x -> 0;

as follows:

    f /@ lst2

(* {h00^2 -> 0, h00 h01 -> 0, h00 h02 -> 0, h00 h03 -> 0, h00 h01 -> 0, 
 h01^2 -> 0, h01 h02 -> 0, h01 h03 -> 0, h00 h02 -> 0, h01 h02 -> 0, 
 h02^2 -> 0, h02 h03 -> 0, h00 h03 -> 0, h01 h03 -> 0, h02 h03 -> 0, 
 h03^2 -> 0}  *)

Now we have all rules we need (provided, of course, you will not tell that you have also higher orders). We can operate G2:

    G2 /. f /@ lst2

(*  {{-1 - h00, h01, h02, h03}, {h01, 1, 0, 0}, {h02, 0, 1, 0}, {h03, 0, 
  0, 1}}  *)

Have fun!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
0
G = {{-1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}} ;

h = {{-h00/2, h01, h02, h03}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 
    0}};

L = G + h ;

Lt = Transpose[L];

G2raw = Lt.G.L ;

G2 = Expand[G2raw] /.
  Thread[
   Times @@@
     Tuples[
      Variables[Level[G2raw, -1]],
      2] -> 0]

{{-1 - h00, h01, h02, h03}, {h01, 1, 0, 0}, {h02, 0, 1, 0}, {h03, 0,
0, 1}}

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
0
h0 = {h00, h01, h02, h03};
r = DeleteDuplicates@Flatten@Outer[Times, h0, h0] -> 0 // Thread

(* {h00^2 -> 0, h00 h01 -> 0, h00 h02 -> 0, h00 h03 -> 0, 
h01^2 -> 0, h01 h02 -> 0, h01 h03 -> 0, h02^2 -> 0, h02 h03 -> 0, 
h03^2 -> 0} *)

then apply list of rules r to your resoulting matrix

k_v
  • 579
  • 5
  • 6
0

Easiest I think is to expand as a power series in a new variable t, after first changing the expression so that each variable of interest is multiplied by t. Expand to first order to remove all terms quadratic and higher. Then use Normal and substitute t->1.

smallvars = {h00, h01, h02, h03}; Normal[Series[G2 /. Thread[smallvars -> t*smallvars], {t, 0, 1}]] /. t -> 1

(* Out[21]= {{-1 - h00, h01, h02, h03}, {h01, 1, 0, 0}, {h02, 0, 1, 0}, {h03, 0, 0, 1}} *)

Related from MSE:

Best way to power series expand in multiple variables?

nested series expansion

Multivariable Taylor expansion does not work as expected

nested series expansion

Daniel Lichtblau
  • 58,970
  • 2
  • 101
  • 199