Message Boards Message Boards

0
|
6087 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Increment of a Decimal?

Posted 10 years ago

Hey guys,

Just wondering if there is a way to use an increment in a loop (i.e. r++), but instead of increasing by 1 each time, will increase by 0.1.

For example, in the code used below:

For[r = 1, r <= 32, r++,

For[j = 1, j <= Length[XandY], j++,

If[Sqrt[(y[j] - 4.8)^2 + (x[j] - 2.6)^2] <= r,

plotCount[[r]] = plotCount[[r]] + 1]]]

Thanks,

Lewis Millar

POSTED BY: Lewis Millar
2 Replies

Try

For[r = 1, r <= 32, r++, 
 For[j = 1, j <= Length[XandY], j = j + 0.1, 
  If[Sqrt[(y[j] - 4.8)^2 + (x[j] - 2.6)^2] <= r, 
   plotCount[[r]] = plotCount[[r]] + 1]]]
POSTED BY: Marvin Ray Burns
Posted 10 years ago

Thanks, I just had a brainwave though! Basically just used <= r/10

Cheers for the response!

POSTED BY: Lewis Millar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract