I'm taking a different approach to my program after getting some input from some of the forum members.
My first question is if I want to display a result that can either be negative or positive, do I declare it as a float?
My next question is a problem with my code I believe...I'm getting a 0.00000 as a result. Could someone please take a look at my code and tell me why this is my result.
To explain my code n is the number of elements in the array, arrayx is the x values and arrayy is the y values in the array. Here is what the formula should do:
arrayy[i] * (x – arrayx[i])*(x – arrayx[i+1])*(x – arrayx[i+2]) and so on...
+ arrayy[i+1] * (x – arrayx[i])*(x – arrayx[i+1])*(x – arrayx[i+2]) and so on...
I want to set (x - arrayx[i]) = 1 in the first product and (x - arrayx[i+1] ) = 1 in the second product and so on...
I hope that I didn't confuse anyone in my explanation. Anyways, here's the code that I have so far and am wondering why it doesn't work??
Code:
int n=0;
int i=0;
double arrayx[12];
float arrayy[12];
float arraytop[12];
int x;
int j;
printf("Enter the x value you wish to interpolate: ");
scanf("%i", &x);
//Determine formula
for (i=0; i<=n-1; i++)
{
for (j=0; j<=n-1; j++)
{
if (arrayx[j] == arrayx[i])
{
arraytop[j] = 1;
}
arraytop[j] = x - arrayx[j];
//printf(" * (x - %i)", arrayx[j]);
}
arraytop[i] = arrayy[i] * arraytop[j];
}
//Display of top value of formula
printf("%f", arraytop[i]);