Hi,
I have a mathematical equation i was hoping to get some help with to get it working in C. I'ts a small part of a program and if i figured it out it , i think i could figure out the rest of it! The equation is a second order derivative
z[n] = x[n-1] - 2 x[n] + x[n+1]
so for an array of 8 numbers say {2,5,7,4,3,5,9,8}
it picks the number before the current no. - twice current no. + next number.
For 5 in the array it would be z[n] = (2 - 10 + 7) = -1
Here is my very poor attempt so far
I was hopingto store the ouput values into an array z. I know there is going to be a problem with the first value because n-1 = 0Code:#define MAX 8 int z[MAX]; int a[MAX] = {2,5,7,4,3,5,9,8}; int main(void) { for (int i=0; i<8; i++) z[i] = a[i-1] - (2(a[i]) + a[i+1]; }
Any help would be greatly appreciated



LinkBack URL
About LinkBacks



???
I've just one more small problem though if anyone could help. Would i be able to modify the it so it could read in an array of 8 numbers as a function, add the zeros at either end so the calculations is performed okay and the array doesnt go out of bounds, and return the values into the z array from z[0] to z[7] (at the moment the values are perfect but it goes from z[1] to z[8])