Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Modeling and Array Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58744] Re: Modeling and Array Problem
  • From: Ken Levasseur <kenneth_levasseur at uml.edu>
  • Date: Sun, 17 Jul 2005 03:03:57 -0400 (EDT)
  • References: <200507160503.BAA14933@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Peter:
I noticed that you constructed the list {{0,0},{1,1},{2,4},{3,9},..., 
{100,10000}}  using a Do loop.  It's much more efficient to use Map:

In[53]:=
Map[{#1, #1^2} & , Range[0, 100]]

Out[53]=
{{0,0},{1,1},{2,4},{3,9},{
   4,16},{5,25},{6,36},{7,49},{8,64},{9,81},{10,100},{11,121}, 
{12,144},{13,
     169},{14,196},{15,225},{16,256},{17,289},{18,324},{19,361}, 
{20,400},{21,
   441},{22,484},{23,529},{24,576},{25,625},{26,676},{27,729}, 
{28,784},{29,
   841},{30,900},{31,961},{32,1024},{33,1089},{34,1156},{
   35,1225},{36,1296},{37,1369},{38,1444},{39,
     1521},{40,1600},{41,1681},{42,1764},{43,1849},{
   44,1936},{45,2025},{46,2116},{47,2209},{48,
     2304},{49,2401},{50,2500},{51,2601},{52,2704},{
   53,2809},{54,2916},{55,3025},{56,3136},{57,
     3249},{58,3364},{59,3481},{60,3600},{61,3721},{62,3844}, 
{63,3969},{64,\
4096},{65,4225},{66,4356},{67,4489},{68,4624},{69,4761},{70,4900}, 
{71,5041},{\
72,5184},{73,5329},{74,5476},{75,5625},{76,5776},{77,5929},{78,6084}, 
{79,6241}\
,{80,6400},{81,6561},{82,6724},{83,6889},{84,7056},{85,7225}, 
{86,7396},{87,\
7569},{88,7744},{89,7921},{90,8100},{91,8281},{92,8464},{93,8649}, 
{94,8836},{\
95,9025},{96,9216},{97,9409},{98,9604},{99,9801},{100,10000}}

The pure function {#1, #1^2} & produces one such pair and you just  
map that over the integers from 0 to 100.



On Jul 16, 2005, at 1:03 AM, Sycamor at gmail.com wrote:

> Hello,
>
> I am a high school student and am interning/volunteering at a
> university over the summer.  My ultimate goal is to model the movement
> of charge in a Nickel Metal Hydride Sphere using Mathematica.  This
> goal is beyond my ability as it requires calculus and differential
> equations and so forth.  But I am to progress as best I can, using
> iterative processes to replace calculus where possible.  The professor
> I am working with has started me with the simpler task of finding the
> curvature of a set of data points (in this first easy case, the 'data'
> is the values of 101 points of the x^2 function).
>
> While programming, I have found it necessary to change the value of
> certain elements of an array of ordered pairs, but have been unable to
> do so.
>
> In[1]:= array = {{1,1},{2,2},{3,3},{4,4},{5,5}};
> In[2]:= array[[1]][[1]]
> Out[2]= 1
> In[2]:= array[[1]][[1]] = 42
> Out[2]= Set::setps: test in assignment of part is not a symbol.
>
> I suppose the error arises when I attempt to set the numerical  
> contents
> of the array equal to a certain value.  Is there anyway to simply
> overwrite the element at a certain address?  Why does the syntax used
> above seem to work for lists?
>
> In[3]:= list = {1,2,3,4,5};
> In[4}:= list[[1]]
> Out[4]= 1
> In[5]:= list[[1]] = 42;
> In[6]:= list
> Out[6]= {42,2,3,4,5}
>
> I have included what I have written so far at the end of this message
> to put my problem in context.  As I am new to Mathematica, I do not
> know hoe to write elegant, concise programs using the array of  
> powerful
> built in functions, so I appologize for my clunky code.  There is
> probably a much easier way to accomplish my task.
>
> I would appreciate any help on this matter.
>
>
> Thank you,
>
> Peter Hedman
>
>
>
>
>
>
> Bellow is what I have written so far.  The comments are mostly meant
> for myself, and probably do not make much sense.
>
> g = 1;
>     (*sets value of liberated proton constant*)
>
> d=0.1;
>     (*sets value of diffusion constant*)
>
> v= 0.1;
>     (*sets value of boundry velocity*)
>
> a = 0.1;
>     (*sets the value of constant \[Alpha]*)
>
> j = 0;
>
>     (*sets the initial value of j.  This step shouldn't be necessary*)
>
> rprevb=rprev = Table[0z, {z,0,100}];
>
> r = 0; s = 0;
>
> (Do[rprev[([q])] = {r, s^2}; (r++); (s++), {q, 1, 101}];)
>
>     (*These three lines create the initial list of ordered pairs*)
>
> Do[rprevb[[q]]={0,0}, {q,1,101}]
>
> jmax = 100;
>     (*initially sets the maximum horizontal range*)
>
> iter[n_]:= If[
>       n==jmax , (rprev[[n+1]][[2]] + v*(g+rprev[[n+1]][[2]]) -
>           d*(rprev[[n+2]][[2]]-rprev[[n+1]][[2]])), (rprev[[n+1]] 
> [[2]]+
>           a*(rprev[[n]][[2]]-2rprev[[n+1]][[2]]+rprev[[n+2]][[2]]))] ;
>
> (*defines transformation function*)
>
> dim =Dimensions[rprev];
>
> dimb = Dimensions[rprevb];
>
> Print["Dimensions of initial list = ",dim]
>
> Print["Dimensions of initial list = ",dimb]
>
> initialplot = ListPlot[rprev]
>
> Do[Do[rprevb[[(j+1)]][[2]]=iter[j]; Print[rprevb]; {j,0,jmax,1}];
>   rprev=rprevb; Print["time = ",t]; Print["jmax = ",jmax ];
> ListPlot[rprev];
>   jmax--,{t,1,10}]
>
> (*With every iteration of the outside loop,
>   jmax is decremented by one.  As iterations progress to flatten the
> curve,
>   the boundry moves.  Should these two processes take place in this
> way?
>       It appears this is not the ideal model, but it will work for
> now.*)
>
>



***********************************
Ken Levasseur
Mathematical Sciences
UML
http://faculty.uml.edu/klevasseur

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


  • Prev by Date: Re: Modeling and Array Problem
  • Next by Date: Re: Modeling and Array Problem
  • Previous by thread: Re: Modeling and Array Problem
  • Next by thread: Re: Modeling and Array Problem