2018年12月26日 星期三

Newton's Forward and Backward Interpolation Using c/c++

Newton's Forward and Backward Interpolation Using c/c++

Differential Table Generator
Newton's Forward Interpolation Table and Newton's Backward Interpolation Table can be generated using c and c++ programming language.
Source Code For  Newton's Forward Interpolation Table and Newton's Backward Interpolation Table 

輸出畫面
輸入畫面



#include<stdio.h>
#include<math.h>
int main()

{
    float x[10],y[15][15];
    int n,i,j;
//no. of items
    printf("Enter n : ");
    scanf("%d",&n);
    printf("X\tY\n");
    for(i = 0;i<n;i++){
            scanf("%f %f",&x[i],&y[i][0]);
    }
    //forward difference table
    for(j=1;j<n;j++)
        for(i=0;i<(n-j);i++)
            y[i][j] = y[i+1][j-1] - y[i][j-1];
    printf("\n***********Forward Difference Table ***********\n");
//display Forward Difference Table
    for(i=0;i<n;i++)
    {
        printf("\t%.2f",x[i]);
        for(j=0;j<(n-i);j++)
            printf("\t%.2f",y[i][j]);
        printf("\n");
    }
    //backward difference table
    for(j=1;j<n;j++)
//for j = 0 initially input is taken so we start from j=1
        for(i=n-1;i>(j-1);i--)
            y[i][j] = y[i][j-1] - y[i-1][j-1];
    printf("\n***********Backward Difference Table ***********\n");
//display Backward Difference Table
    for(i=0;i<n;i++)
    {
        printf("\t%.2f",x[i]);
        for(j=0;j<=i;j++)
            printf("\t%.2f",y[i][j]);
        printf("\n");
    }
return 0;
}

輸入TEXT資料
4
10      1.1
20      2.0
30      4.4
40      7.9


輸出畫面

Enter n : X Y

***********Forward Difference Table ***********
10.00 1.10 0.90 1.50 -0.40
20.00 2.00 2.40 1.10
30.00 4.40 3.50
40.00 7.90

***********Backward Difference Table ***********
10.00 1.10
20.00 2.00 0.90
30.00 4.40 2.40 1.50
40.00 7.90 3.50 1.10 -0.40



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...