       Re: Modeling and Array Problem

• To: mathgroup at smc.vnet.net
• Subject: [mg58750] Re: Modeling and Array Problem
• From: Pratik Desai <pdesai1 at umbc.edu>
• Date: Sun, 17 Jul 2005 03:04:02 -0400 (EDT)
• References: <200507160503.BAA14933@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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).
>
>
I think you will need some kind of calculus for this. Try looking up the
osculating plane or Frenet's formulas

>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:= array = {{1,1},{2,2},{3,3},{4,4},{5,5}};
>In:= array[][]
>Out= 1
>In:= array[][] = 42
>Out= 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:= list = {1,2,3,4,5};
>In[4}:= list[]
>Out= 1
>In:= list[] = 42;
>In:= list
>Out= {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]][] + v*(g+rprev[[n+1]][]) -
>          d*(rprev[[n+2]][]-rprev[[n+1]][])), (rprev[[n+1]][]+
>          a*(rprev[[n]][]-2rprev[[n+1]][]+rprev[[n+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)]][]=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.*)
>
>
>
Here is my understanding of your code, Although I cannot claim to  know
exactly what it means or does.Note that to identify( or extract) an
element in any array can be accomplished by Table. In fact Table is a
much easier form of the Do loop. So anyway, here is my attempt and good

Clear[rprev, rprevb, jmax, iter, n]
<< Graphics`Graphics`
jmax = 100;
n = 150
rprev = Table[{s, s^2}, {s, 1, jmax + 1}];
iter[n_] := If[n == jmax, Table[(rprev[[s + 1]][] +
v*(g + rprev[[s + 1]][]) - d*(rprev[[s + 2]][] - rprev[[s + 1]][[
2]])), {s, 1, jmax -
2}], Table[(rprev[[s + 1]][[
2]] + a*(rprev[[s]][] - 2rprev[[s + 1]][] + rprev[[s +
2]][])), {s, 1, jmax - 2}]];
initialplot = ListPlot[rprev]
rprevb = Table[{s, iter[n][[s]]}, {s, 1, jmax - 2}]
DisplayTogether[ListPlot[rprev, PlotJoined -> True],
ListPlot[rprevb, PlotJoined -> True]]
best regards
Pratik

--
Pratik Desai