声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1447|回复: 0

[综合讨论] 自写程序,拉格朗日插值且给出插值多项式的系数

[复制链接]
发表于 2014-11-5 14:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
有时候只是想知道 拉格朗日插值 后的多项式系数具体是多少,这个程序就能实现!

function coef=LagrangeInterpolation(xx,yy)
%get the ploynimial coefficients of Lagrange interpolation.
%input is a set of sample points
%output is the coefficients of Lagrange interpolation.
syms x
y=0;
%start to implement the Lagrange interpolation
for i=1:length(xx)
    p=1;
    for j=1:length(xx)
        if(j~=i)
            p=p*(xx(j)-x)/(xx(j)-xx(i));
        end
    end
    y=y+p*yy(i);
end
%get the coefficients of polynimial
coef=sym2poly(y);
return

回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-7-3 09:08 , Processed in 0.053876 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表