From: John Ertle Jr. on
I want to subtract array A by 1/2 array B and put it in array C. I need something like this except more complicated later. This is what I have thus far:

C:=C=Simplify[Table[A[i]-1/2*B[i],{i,1,9}]]

From: David Park on
Define A and B as same sized lists or arrays and then just write:

C = A + 1/2 B

But symbols that begin with capitals could conflict with Mathematica symbols
so I woul use names like:

cVector = aVector + 1/2 bVector

cMatrix = aMatrix + 1/2 bMatrix

Of course, you have to fill aVector and bVector with values to begin with.
Look up CORE LANGUAGE, Lists and DATA MANIPULATION, Arrays in the
Documentation Center.


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/



From: John Ertle Jr. [mailto:ertlejack(a)sbcglobal.net]

I want to subtract array A by 1/2 array B and put it in array C. I need
something like this except more complicated later. This is what I have thus
far:

C:=C=Simplify[Table[A[i]-1/2*B[i],{i,1,9}]]



From: Bill Rowe on
On 4/10/10 at 6:52 AM, ertlejack(a)sbcglobal.net (John Ertle Jr.)
wrote:

>I want to subtract array A by 1/2 array B and put it in array C. I
>need something like this except more complicated later. This is
>what I have thus far:

>C:=C=Simplify[Table[A[i]-1/2*B[i],{i,1,9}]]

The first thing to note is in Mathematica the syntax A[i] does
not refer to the element i of array A. It is a function named A
evaluated at i, much different than an array even though this
notation can sometimes be usefully treated as being element i of
array A.

So, I will first create two arrays

In[3]:= a = RandomInteger[100, {3, 3}];
b = RandomInteger[10, {3, 3}];

then the third array c is computed simply as:

In[5]:= c = a - 1/2 b

Out[5]= {{99/2, 11/2, -2}, {121/2, 65, 78}, {84, 9/2, 60}}

No need to use Table or Simplify. And note:

In[6]:= ArrayQ[a]

Out[6]= True

But assigning values to d as if it were a 2D array by

In[7]:= Table[d[i, j] = RandomInteger[100], {i, 3}, {j, 3}];
ArrayQ[d]

gives

Out[8]= False


From: Murray Eisenberg on
Use the "array processing" inherent in functions such as Plus and Times
that have the attribute of being Listable , namely:

C = A - (1/2)B

That's it! (You can do Simplify later. And even there, you don't need
to do any explicit indexing, but -- at least for a one-dimensional list
-- just use Map: Simplify/@C

On 4/10/2010 6:52 AM, John Ertle Jr. wrote:
> I want to subtract array A by 1/2 array B and put it in array C. I need something like this except more complicated later. This is what I have thus far:
>
> C:=C=Simplify[Table[A[i]-1/2*B[i],{i,1,9}]]


--
Murray Eisenberg murray(a)math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

From: Bob Hanlon on
C is a reserved word. To avoid conflict with built-in names, always start your names with a lower case letter.

n = 3;

mA = Array[a, {n, n}];
mB = Array[b, {n, n}];

mC = mA + mB/2

{{a[1, 1] + (1/2)*b[1, 1], a[1, 2] + (1/2)*b[1, 2],
a[1, 3] + (1/2)*b[1, 3]}, {a[2, 1] + (1/2)*b[2, 1],
a[2, 2] + (1/2)*b[2, 2], a[2, 3] + (1/2)*b[2, 3]},
{a[3, 1] + (1/2)*b[3, 1], a[3, 2] + (1/2)*b[3, 2],
a[3, 3] + (1/2)*b[3, 3]}}


Bob Hanlon

---- "John Ertle Jr." <ertlejack(a)sbcglobal.net> wrote:

=============
I want to subtract array A by 1/2 array B and put it in array C. I need something like this except more complicated later. This is what I have thus far:

C:=C=Simplify[Table[A[i]-1/2*B[i],{i,1,9}]]