MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Matrix Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15267] RE: [mg15247] Matrix Problem
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 30 Dec 1998 01:50:29 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Pedro wrote:
>
>
> t=
>  N[GramSchmidt[{ve[1],ve[2],ve[3],ve[4]},
>    InnerProduct ->
>     (skproduct[#1, #2]&)]]
>
> {{{1.1547},{0},{0},{0}},{{0},{0.755929},{0},{0}},
>  {{-0.258199},{0},{0.774597},{0}},{{0.},{-0.169031},{0.},{1.18322}}}
>
> But I would like to have t in the following form:
>
> {{1.1547,0,0,0},{0,0.755929,0,0},
>  {-0.258199,0,0.774597,0},{0.,-0.169031,0.,1.18322}}
>
> so t should be a real matrix. How can I make the innerst brackets
> disapear ?
>
>

Pedro,

In[5]:=
t={
 {{1.1547},{0},{0},{0}},
 {{0},{0.755929},{0},{0}},
 {{-0.258199},{0},{0.774597},{0}},
 {{0.},{-0.169031},{0.},{1.18322}}
};


In[6]:=
Apply[Identity, t, {-2}]

Out[6]=
{
  {1.1547, 0, 0, 0},
  {0, 0.7559289, 0, 0}, 
  {-0.258199, 0, 0.774597, 0}, 
  {0., -0.169031, 0., 1.18322}
}


So how does this work?
Check the information on Apply.

In[7]:=
?Apply

Apply[f, expr] or f @@ expr replaces the head of expr by
   f. Apply[f, expr, levelspec] replaces heads in parts of
   expr specified by levelspec.


I applied the function Identity to (level -2). Note: 
Identity[expr]->expr

Now what is (level -2)?
Level -2 is all subexpressions with a depth of 2. Anything like {0.2581}
has a depth of 2.

In[8]:=
Depth[ {0.2581} ]

Out[8]=
2

You can read more about levels of expressions in section 2.1.7 of the
Mathematica book.

________________________________

Here is another way to do what you want.

In[9]:=
t/.{num_}:>num

Out[9]=
{{1.1547, 0, 0, 0},
 {0, 0.7559299, 0, 0}, 
 {-0.258199, 0, 0.774597, 0}, 
 {0., -0.169031, 0., 1.18322}
}


Cheers,
Ted Ersek


  • Prev by Date: List handling
  • Next by Date: Contour Plotting on a sphere
  • Previous by thread: Re: Matrix Problem
  • Next by thread: List of Matrices