腦腦腦,這東西讓我有成就感!
昨晚在鄭仲廷那邊,邊聊旅行邊偵錯出來的!
這是可以執行的執行碼唷!
成就感!哇哈哈!
鄭仲廷跟我數值分析 ( 數值分析是一堂課 )
他也去過很多地方旅行耶!也是個旅行好咖!
#include
#include
#define TURE 1
main()
{
int i, j, kk;
float xa, yans, z;
static n = 3;
static float x[11]={1. , 2. , 3. , 4. , };
static const double f[11]={.671, .620, .567, .512};
printf( "\nCSL/C2-1 Lagrange Interpolation\n\n" );
printf( "Funtion table used:\n" );
printf( "i x(i) f(i \n)" );
for ( i = 0; i <= n ; i++)
printf( "%d %g %g \n", i, x[i], f[i] );
while (TURE)
{
printf( "\nInput x ? " ); scanf( "%f" , &xa );
if ( !(x[0] <= xa && xa <= x[n]) )
printf( "(WARNING: x is in the extrapolation rarge.)\n" );
yans = 0;
for( i = 0; i <= n; i++)
{
z = 1.0;
for( j = 0; j<= n; j++)
{
if(i != j) z = z*(xa - x[j])/(x[i] - x[j]);
}
yans = yans + z*f[i];
}
printf( "Answer: g( %g ) = %g \n", xa, yans );
printf( "\nType 1 to continue, 0 to stop:" ); scanf("%d",&kk);
if( kk != 1 )
return 0 ;
}
}
昨晚在鄭仲廷那邊,邊聊旅行邊偵錯出來的!
這是可以執行的執行碼唷!
成就感!哇哈哈!
鄭仲廷跟我數值分析 ( 數值分析是一堂課 )
他也去過很多地方旅行耶!也是個旅行好咖!
#include
#include
#define TURE 1
main()
{
int i, j, kk;
float xa, yans, z;
static n = 3;
static float x[11]={1. , 2. , 3. , 4. , };
static const double f[11]={.671, .620, .567, .512};
printf( "\nCSL/C2-1 Lagrange Interpolation\n\n" );
printf( "Funtion table used:\n" );
printf( "i x(i) f(i \n)" );
for ( i = 0; i <= n ; i++)
printf( "%d %g %g \n", i, x[i], f[i] );
while (TURE)
{
printf( "\nInput x ? " ); scanf( "%f" , &xa );
if ( !(x[0] <= xa && xa <= x[n]) )
printf( "(WARNING: x is in the extrapolation rarge.)\n" );
yans = 0;
for( i = 0; i <= n; i++)
{
z = 1.0;
for( j = 0; j<= n; j++)
{
if(i != j) z = z*(xa - x[j])/(x[i] - x[j]);
}
yans = yans + z*f[i];
}
printf( "Answer: g( %g ) = %g \n", xa, yans );
printf( "\nType 1 to continue, 0 to stop:" ); scanf("%d",&kk);
if( kk != 1 )
return 0 ;
}
}
全站熱搜