Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5935 > unrolled thread

Re: Using values from inside a matrix for a new row

Started byJacopo Bertolotti <jacopo.bertolotti@gmail.com>
First post2011-10-27 10:43 +0000
Last post2011-10-27 10:43 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Using values from inside a matrix for a new row Jacopo Bertolotti <jacopo.bertolotti@gmail.com> - 2011-10-27 10:43 +0000

#5935 — Re: Using values from inside a matrix for a new row

FromJacopo Bertolotti <jacopo.bertolotti@gmail.com>
Date2011-10-27 10:43 +0000
SubjectRe: Using values from inside a matrix for a new row
Message-ID<j8bcjs$8tc$1@smc.vnet.net>
A conceptually simple (but ugly) way to do that is to first define a 
array filled with zeroes via the command Table and then use a For loop 
to fill it with the desired values.
a = Table[0, {i, 10}];
For[i = 1, i <= 10, i++,  If[i == 1, a[[i]] = {1, 2, 3}, a[[i]] = a[[i - 
1]] + 1] ];
MatrixForm[a]

A more compact/elegant/efficient (but also less intuitive) way is to 
re-think it in the form of functional programming and use something like 
the FoldList command to do the job:
MatrixForm@FoldList[Plus, Range[3], Table[1, {9}]]

Regards

Jacopo

On 10/26/2011 11:40 PM, Michelle A wrote:
> Hello,
> I am new to Mathematica and I am trying to create an array of values
> that uses info from the line above.  I'm thinking of it like how Excel
> would do it but I'm not sure how to go about it in Mathematica.  I've
> been getting the RecursionLimit error when I try to call an earlier
> element of the array.
>
> Here is what I'm thinking in a simplified form:
>
> Say I simply want to add a constant (1 here) to each element above. So
> I want my answer to be like this:
>
> 1 2 3
> 2 3 4
> 3 4 5
>
> f = {{1, 2, 3}, {f[[1, 1]] + 1, f[[1, 2]] + 1, f[[1, 2]] + 1}} and
> continue to have it grow to be a 10x3 matrix.  I know I'll need some
> i's and j's but I can't get it to work.  Do I need to initialize an
> array or make a loop to just add one row at a time in a separate
> step?
>
> Any help is greatly appreciated.  Thank you
>
>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web