# first number in array incorrect...

• 06-09-2008
first number in array incorrect...
Can anyone tell me if there is anything wrong with this notation?
I have array[200];
then this

Code:

```for(i=0; i<100; i++){ delta_x[i]=array[i]; } for(i=100; i<200; i++){ delta_y[i-100]=array[i]; }```
In my program everything is okay except that delta_y[0] is not right - it's not in array[200] at all, so it messes everything up by that amount.
This seems right to me, but I thought maybe there was a problem, or does anyone know why this could happen?
• 06-09-2008
tabstop
That assignment statement sets delta_y[0] to array[100], so everything is okay there. Are you sure that the error is here and not some later statement?
• 06-09-2008
I'm not sure of anything, actually, this is really puzzling me. I have the same notation for delta_x[100] as I do for delta_y[100] and delta_x is fine all the way.
I printed out array[200] to make sure the mistake's not there, and it's not. I also printed out delta_y[100] by itself, and the first number is wrong.
I don't think there's anything going on between array and delta_y besides the loop I already posted...
• 06-09-2008
QuantumPete
Rather than having two loops, that essentially do the same thing, try this:

Code:

```for(i=0; i<100; i++){ delta_x[i] = array[i]; delta_y[i] = array[i+100]; }```
QuantumPete
• 06-09-2008
lol good call. My whole program's kinda like that. I did it in pieces when I was tired... :P But I just condensed my other loops, too. Unfortunately, it didn't change anything. Still same problem...
• 06-09-2008
QuantumPete
How did you declare delta_x and delta_y?
Can you post the smallest program that reproduces this problem?
QuantumPete
• 06-09-2008
They're declared as double delta_x[100], delta_y[100].
I'm messing with the first part of the program now. Once I get it simplified I'll post some more.
• 06-09-2008
All right, I think the problem might actually be here

Code:

```    for (i=0; i<100; i++){         x[i+1]=x[i]+delta_x[i];         y[i+1]=y[i]+delta_y[i];         A[i]=bluemoon(x[i], y[i]);         }```
When I comment this out and print delta_y[100] by itself, the first number is correct.
But how does this change delta_y?
bluemoon is my function. :P
• 06-09-2008
laserlight
I think you are still better off showing the smallest and simplest compilable program that demonstrates the problem.
• 06-09-2008
All right:

Code:

```#include <stdio.h> double bluemoon (double x, double y) {       double function;       double expfunction;             function=-1*x*x;-(1/2)*y*y;       expfunction=exp(function);             return expfunction; }     main () {     double array[200];         int i;     double asta;           for (i = 0; i < 200; i++){         asta=i;         array[i]=asta;         }             double delta_x[100], delta_y[100];     double x[100], y[100], A[100];                   for(i=0; i<100; i++){               delta_x[i] = array[i];               delta_y[i] = array[i+100];               }         for (i=0; i<100; i++){         x[i+1]=x[i]+delta_x[i];         y[i+1]=y[i]+delta_y[i];         A[i]=bluemoon(x[i], y[i]);         }             for(i=0; i<100; i++){       printf("&#37;e\n", delta_y[i]);       }            getchar();     return 0; }```
Same problem.
But if I take out the
Code:

```    for (i=0; i<100; i++){         x[i+1]=x[i]+delta_x[i];         y[i+1]=y[i]+delta_y[i];         A[i]=bluemoon(x[i], y[i]);         }```
section it's fine.

EDIT: It also doesn't matter what bluemoon is defined as, still happens. Unfortunately I need that section... lol
• 06-09-2008
laserlight
According to your code, delta_y[100] does not exist, since delta_y has 100 elements. Consequently, printing delta_y[100] by itself is accessing the array out of bounds.
• 06-09-2008