Bismillahirrahmanirrahim
Alhamdulillah, washalatu wasalamu 'ala rasulillah, waba'du
Berikut ini saya berikan contoh program untuk menghitung interpolasi dengan bahasa c.
======================================================================================================================
#include <stdio.h>
struct Data
{
double x,y;
};
double interpolate(struct Data f[], int xi, int n)
{
double result = 0;
for ( int i = 0; i < n; i++)
{
double term = f[i].y;
for (int j = 0; j < n; j++)
{
if (j!=i)
term = term * (xi - f[j].x)/(f[i].x - f[j].x);
}
result += term;
}
return result;
}
int main ()
{
struct Data f[] = {{1,0.54},{10, -0.84},{20, 0.41},{30, 0.15},{45, 0.53}};
printf ("value of f(15) is = %lf\n", interpolate (f,15,5));
return 0;
}
======================================================================================================================
Selamat mencoba!
Tidak ada komentar:
Posting Komentar