/*
*作者:KDF5000
*功能:利用拉格朗日插值法求解近似值
*时间:2013.4.15
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//存放插值节点
struct Data{
double x;
double y;
struct Data *next;
};
/****************************************************
*LagrangeInsert()
*功能:拉格朗日插值法
*****************************************************/
double LagrangeInsert(struct Data *header,double x)
{
Data *pi,*pj,*p;
pi=pj=header->next;
double temp1,temp2;
temp1=0; //记录内循环的积
temp2=1; //记录外循环的和
while(pi!=NULL)
{
while(pj!=NULL)
{
if(pi!=pj)
temp2 *=(x-pj->x)/(pi->x-pj->x);
pj = pj->next;
}
temp1 +=temp2*pi->y;
temp2=1;
pj = header->next;
pi = pi->next;
}
return temp1; //返回计算结果
}
void main()
{
Data *header = (Data *)malloc(sizeof(Data));
char str[20];
Data *p,*newData;
char strx[20],stry[20];
double x;
拉格朗日插值法 C语言实现
最新推荐文章于 2025-03-02 19:58:31 发布