       Re: Questions on evaluate matrix operations

• To: mathgroup at smc.vnet.net
• Subject: [mg92939] Re: [mg92913] Questions on evaluate matrix operations
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Mon, 20 Oct 2008 07:35:15 -0400 (EDT)

```n = 1;
m = 10;
f[x_] := Sin[x*Pi];

l = 0;
t = 0;
a = 1;
h = 1/10;
k = 1/100;
LAMDA = a*a*k/(h*h);

Although you did not provide a value for T, your desired output implies that it is zero.

T = 0;

w = {T};
count = 1;
Do[w = Append[w, f[count*h]]; count++, {m - 1}];

This could be written more efficiently as this RHS

w == Prepend[f[#*h] & /@ Range[m - 1], T]

True

A1 = {0};
count = 0;
Do[A1 = Append[A1, 1 + 2*LAMDA]; count++, {m}];
count;
A1 = Drop[A1, 1]

{3,3,3,3,3,3,3,3,3,3}

This could be written more efficiently as this RHS

A1 == Table[1 + 2*LAMDA, {m}]

True

A2 = {0};
Do[A2 = Append[A2, -LAMDA], {m - 1}];
A2 = Drop[A2, 1]

{-1,-1,-1,-1,-1,-1,-1,-1,-1}

This can be written more efficiently as this RHS

A2 == Table[-LAMDA, {m - 1}]

True

MatrixForm is only used for printing (mostly prior to Mathematica v6) and you do not want it included inside the definition of A

A = DiagonalMatrix[A2, -1] + DiagonalMatrix[A1] + DiagonalMatrix[A2, 1];

Ainv = Inverse[A];

The dot product is then (N is used since I have used exact numbers up to this point)

A.w // N

{-0.309017,0.339266,0.645322,0.888209,1.04415,1.09789,1.04415,0.888209,0.\
645322,0.339266}

Verifying

w - A.w.Ainv // Simplify

{0,0,0,0,0,0,0,0,0,0}

If using machine numbers throughout, Chop would be used rather than Simplify

Bob Hanlon

---- rac00n <rac00nza at gmail.com> wrote:

=============
Hi all,

I've given up on another system and I have a Mathematica question for you.
Please bare with me as this is the first time I'm using Mathematica
for anything else besides plotting.

Here is my program so far:

n = 1;
m = 10;
f[x_] := Sin[x*Pi];

l = 0;
t = 0;
a = 1;
h = 0.1;
k = 0.01;
LAMDA = a*a*k/(h*h);

w = {T};
count = 1;
Do[w = Append[w, f[count*h]]; count++, {m - 1}];
w

A1 = {0};
count = 0;
Do[A1 = Append[A1, 1 + 2*LAMDA]; count++, {m}];
count;
A1 = Drop[A1, 1];

A2 = {0};
Do[A2 = Append[A2, -LAMDA], {m - 1}];
A2 = Drop[A2, 1];

A = MatrixForm[
DiagonalMatrix[A2, -1] + DiagonalMatrix[A1] +
DiagonalMatrix[A2, 1]];
Ainv = Inverse[A];

count = 0;
Do[wN = Evaluate[A.w]; Print["W[", count, "]: ", wN]; w = wN;
count++, {n}];

This gives the following output:

the Matrix "A" dot the vector "w"

If I Select the output and choose "Evaluate in Place/Cell" the
following output is shown:

{-0.30901699437494734`, 0.3392657308323691`, 0.6453217681275247`, \
0.8882092145372158`, 1.0441525545105133`, 1.0978869674096932`, \
1.0441525545105133`, 0.8882092145372158`, 0.6453217681275247`, \
0.33926573083236944`}

How can I force: wN = Evaluate[A.w] to always be fully evaluated? Even
though I have Evaluate[%] it still shows the full explicit answer. I
want to flatten/reduce the the result. Everything I've tried so far
does not work. Any ideas?

Kind Regards,
Miguel

--

Bob Hanlon

```

• Prev by Date: Re: notation using # with exponents and &
• Next by Date: Re: Questions on evaluate matrix operations
• Previous by thread: Re: Questions on evaluate matrix operations
• Next by thread: Re: Questions on evaluate matrix operations