⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lagrange.m

📁 拉哥朗日插值算法的实现,MATLAB编写,仅供参考.
💻 M
字号:
function FF=lagrange(X,F,XX)
%% This is a function to realize lagrange interpolation %%
%% the vector X is a collection of interpolation points %%
%% the vector F is a collection of interpolated function values%%
%% Obviously,the vector X should be the same size as F  %%
%% **************the author:程剑光**********************%%
%% ************chengjianguang@163.com*******************%%
%% this programme copyrighted by the physics and %%
%% tele-communication school in scnu,  2006.4.17 %%
%% if you have some ways to improve this arithmetic, %%
%% please make contact with me, thank you very much! %%


FF=0;
m=size(X,2);
n=size(F,2);
if((m>n)|(m<n))
    error('the input X and F should be the same size');
end
l=ones(1,m);
for i=1:m
    for k=1:m
        if(k==i)
            l(i)=l(i)*1;
        else
            l(i)=l(i)*(XX-X(k));
        end
    end
end
for i=1:m
    for k=1:m
        if(k==i)
            l(i)=l(i)*1;
        else
            l(i)=l(i)/(X(i)-X(k));
        end
    end
end
for i=1:m
    FF=FF+l(i)*F(i);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -