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