Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Array problem

0 views
Skip to first unread message

Ben Peachey

unread,
Apr 7, 2002, 6:31:36 PM4/7/02
to
i am having trouble with this bit of script,

for Count:= 0 to 199 do
begin
for Count1:= 1 to 50 do
Position [Count * 50 + Count1] := Count1;
end;

what i have is an array of 10,000 particals and i want to sprear them evenly
over a distance of 200 available positions, but nothing seems to happen when
i try to plot them on to a canvas.

Again thanks for your help on my previous problem.

Ben


Jason Playne

unread,
Apr 8, 2002, 6:13:50 AM4/8/02
to
umm... as far as i can tell - there is nothing wrong with the code...

here is the code i used - the array is being populated... and i simply plot
the x coord to the array data - and the y coord to one of 50 lines

procedure TForm1.FormCreate(Sender: TObject);
var
i,j : Integer;
begin
for i := 1 to 199 do
for j := 1 to 50 do
p[i*50+j] := j;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
i : Integer;
begin
for i := 1 to 10000 do
canvas.Pixels[p[i], i div 199] := clBlack;
end;

it might be a problem with your plotting code... if you post it - then we
can check it out!

Jason

"Ben Peachey" <Talb...@btopenworld.com> wrote in message
news:a8qhc7$505$1...@knossos.btinternet.com...

David Wilkinson

unread,
Apr 8, 2002, 3:56:45 AM4/8/02
to
In article <a8qhc7$505$1...@knossos.btinternet.com>, Ben Peachey
<Talb...@btopenworld.com> writes
If you evaluate it by hand the index of Position goes from 1 (Count = 0,
Count1 = 1) to 10000 (Count = 199, Count1 = 50) so presumably you have
declared it somewhere above as Array[1..10000] of integer.

The array variables Position[i], (1 = 1,,10000) are given the values
Count1 only, which goes from 1 to 50.

This means Position[i], (i = 1..50) = 1..50.
Position[i], (i = 51..100) = 1..50.
Position[i], (i = 101..150) = 1..50.
....................
Position[i], (i = 9951..10000) = 1..50.

Is this what you want? You have 10000 particles but they only occupy 50
positions so there are 200 particles at each position.

--
David Wilkinson

Ben Peachey

unread,
Apr 10, 2002, 12:08:04 AM4/10/02
to
hello again

i dont know why the array will not fill as you sugested it only works when i
do this

begin
for i := 1 to 199 do
for j := 1 to 50 do

p[i*50+j] := i;
end;

strange....

i am using a second array to count the positions of the particals

for Count:=1 to 10000 do {Counts the Final values for the FP array}
case Position[Count] of
for count1:=1 to 200 do
1 : Inc(FP[ 1 ]);
2 : Inc(FP[ 2 ]);
3 : Inc(FP[ 3 ]);
4 : Inc(FP[ 4 ]);
5 : Inc(FP[ 5 ]);
6 : Inc(FP[ 6 ]);
and so on,

This is odd it will not let me use another loop for the inc comands and is
asking fo a simple local variable?

to draw the line....

procedure PlotFP; {Plots the Final Positions of the 10,000 Particals}
var
Count:Integer;
begin
Disp.Canvas.Moveto (10, Disp.Height - 20);
Disp.Canvas.Pen.Color := clBlue;
for Count:= 0 to 200 do {Plots the Displacement of the particals}
Disp.Canvas.Lineto ( Count * 2 + 10 , Disp.height - 20 - (3 *
FP[Count]) );
Disp.Canvas.Moveto (10, Disp.Height - 20);
end;


is supposed to be simple... oh well.

Ben


"Jason Playne" <da...@iinet.net.au> wrote in message
news:3cb2...@quokka.wn.com.au...

Jason Playne

unread,
Apr 10, 2002, 6:37:19 AM4/10/02
to
Sounds like you are doing the hard way...

>for Count:=1 to 10000 do {Counts the Final values for the FP array}
> case Position[Count] of
> for count1:=1 to 200 do
>1 : Inc(FP[ 1 ]);
>2 : Inc(FP[ 2 ]);
>3 : Inc(FP[ 3 ]);
>4 : Inc(FP[ 4 ]);
>5 : Inc(FP[ 5 ]);
>6 : Inc(FP[ 6 ]);
>and so on,

you do not need to use a case statement here instead use

var
FP : array[0..199] of integer;
i : integer;

For i := 1 to 10000 do
inc(FP[Position[i]]);

as the number in the array Position coresponds to a number in the array you
are counting then just put it straight there... MUCH easier...

And as for the simple local variable...
way back in the dayd of Turbo Pascal - you could declare a global var and
use it as a loop control var... bu then if you called a routine out side of
your loop - you could use it again... and therefore stuff things up
immensly...

this basically stops you from treading on your own feet. you must declare
all loop variables locally eg

Procedure Test;
Var
MyLocalVar : Integer;
Begin
end;

instead of

type
TForm1 = Class(TForm);
end;

var
Form1 : TForm1;
MyGlobalVar : Integer;


i am curious... as to what you are doing here, as the array FP holds 50
repititions of the values 1..199. giving you a constant set of data...
nothing random about it... is this a project of class or something?

"Ben Peachey" <Talb...@btopenworld.com> wrote in message

news:a90dr4$hjh$1...@helle.btinternet.com...

Ben Peachey

unread,
Apr 10, 2002, 10:32:57 AM4/10/02
to
am doing a quantum model for my final year project.


It's hopefully going to work like this:-

10,000 particles will be evenly distributed in a range 1 to 200, they will
have a random step (like a random walk model) but the step size is
proportional to a probability density Mod R^2

Mod R^2 = A Tan^-1 (A(P[i]))

A = Pi/200

its not supposed to be difficult but I cant program I just did a module in
my first year on Delphi so here I am.

Thanks

Ben

"Jason Playne" <da...@iinet.net.au> wrote in message

news:3cb4...@quokka.wn.com.au...

Maarten Wiltink

unread,
Apr 10, 2002, 11:08:14 AM4/10/02
to
Ben Peachey wrote in message ...
>[I] am doing a quantum model for my final year project.

>It's hopefully going to work like this:-


<mathematics elided>


>its not supposed to be difficult but I cant program I just did a module in
>my first year on Delphi so here I am.


Ah. I see.

Forget all about Delphi (but don't break the CD yet).
Ignore the database interfacing. Look away when you
see visual components. When people mention objects,
cut them short.

Focus on that simple statement: "I can't program."
It's true. There is no shame in that; I can't weld
and that does not bother me. Now acknowledge that
learning everything about Delphi to program a simple
mathematical model in it is like learning Aluminium,
MIG/MAG, and below-water electric welding in order to
make basic repairs to your computer's on/off-switch.
Total and complete overkill.

Get a book about elementary Pascal programming. If
it talks about punched cards, so much the better - it
won't waste your time trying to explain the finer
points of list views and tray components for accessing
databases through COM-ports. Just a simple book about
if-statements, for-loops, and arrays. Unfortunately,
I don't know the title of a book to recommend. All I
can say is that there _is_ a book on Pascal that talks
about punched cards, only IIRC it wasn't even very well
written; I didn't yet learn Pascal that time.

Next, get Numerical Recipes in Pascal. This is a book
that contains source code of the type you are looking
to write. Borrow from it. Extensively. (I believe this
is called "science".)

Finally, write your code in straight Pascal, as Delphi
console applications. Read input from files or using
ReadLn, write output to files or using WriteLn.

When you're graduated, come back to us and we'll tell
you all about the unending joy and boundless fun to be
had in creating beautiful, elegant, object-oriented,
slick-as-hell, full-featured, intellectually satisfying,
Visual-Basic-bashing programs in Delphi that use all the
features that mathematical modelling _does_not_need_.

Groetjes,
Maarten Wiltink

Ben Peachey

unread,
Apr 10, 2002, 6:18:00 PM4/10/02
to
i have a new problem i really am that bad!

: )

var
i, Step : Integer;
begin
Step:= Trunc(100 * ((Cos(Pi*P[i]/200))/(Sin(Pi*P[i]/200))));
P[i]:= P[i] + Step;
end;

i get invalid floating point opreator error and somehting to do with
incompatable types interger and real P[] is (Real), but so is cos and sin.

? anybody ?

Thanks
Ben


"Jason Playne" <da...@iinet.net.au> wrote in message

news:3cb4...@quokka.wn.com.au...

Surfer

unread,
Apr 20, 2002, 7:15:28 AM4/20/02
to
Ben Peachey wrote:
> i have a new problem i really am that bad!
>
> : )
>
> var
> i, Step : Integer;
> begin
> Step:= Trunc(100 * ((Cos(Pi*P[i]/200))/(Sin(Pi*P[i]/200))));
> P[i]:= P[i] + Step;
> end;
>
> i get invalid floating point opreator error and somehting to do with
> incompatable types interger and real P[] is (Real), but so is cos and sin.


var i has not been initialised.

if you put a breakpoint (press F5 - or click in the gutter) on the line
'Step:=..'
hover the mouse over i at it should show the value in i during runtime

also press Ctrl-F7 and copy and paste the code after := in 'Step := ..'
to evalualate the result.

hope it helps :)

siegfried niedinger

0 new messages