当前位置:网站首页>Lagrange interpolation formula matlab implementation
Lagrange interpolation formula matlab implementation
2022-08-09 19:02:00 【Bubble diet】
一、The principle of formula derivation
NSubinterpolation basis functions:

Satisfy the interpolation polynomial

An interpolating polynomial of the form this formula is calledLagrang插值多项式.
由
的定义可知
If a count is introduced
,再求导
因此

二 、符号说明
输入:
xi:The abscissa of the known data point
k:函数lk(x)的下标k
xx:The abscissa of the point to be interpolated
输出:lk_x,即函数lk(x)在xxThe ordinate of the coordinate point
代码如下:
function li_x = LagrangeFactor( xi, i, xx )
w = 1;
n = length( xi );
syms x;
for j = 1 : n
w = w * ( x - xi(j) );
end
dw = diff( w );
dwf = matlabFunction( dw );
dwi = dwf( xi(i) );
lx = ( w / ( x - xi(i) ) ) / dwi;
f = matlabFunction( lx );
lk_x = f( xx );
end三、一次插值
1. Preparation of the argument function:
(xi,yi):are the known data point coordinates
代码:xi = [ 0, 1 ];
yi = sin( xi );
n = length( xi );
y = 0;
x = [ xi(1) - 1 : 0.1 : xi(2) + 1 ];2.根据lagrangeInterpolating polynomial calculationsxThe function value at the coordinate point(纵坐标)
代码:
for k = 1 : n
lkx = LagrangeFactor( xi, k, x );
y = y + yi(k) * lkx;
end3.绘图
代码:
figure;
plot( xi, yi, 'b.', 'markersize', 30 )
hold on
plot( x, sin(x), 'k--', 'LineWidth', 1.5 )
plot( x, y, 'r-', 'LineWidth', 2 )
legend( '插值点', '原曲线', 'Interpolate polynomial curves' );
axis( [ -1, 2, -1, 3 ] )结果如图:

四、抛物插值
1.Preparation of the argument function:
xi = [ 0, pi/2, pi ];
yi = [ 0, 1, 0 ];
n = length( xi );
y = 0;
x = [ xi(1) - 1 : 0.1 : xi(n) + 1 ];
2.根据lagrangeInterpolating polynomial calculationsxThe function value at the coordinate point
for k = 1 : n
lkx = LagrangeFactor( xi, k, x );
y = y + yi(i) * lkx;
end
3.绘图
plot( xi, yi, 'b.', 'markersize', 30 )
hold on
plot( x, sin(x), 'k--', 'LineWidth', 1.5 )
plot( x, y, 'r-', 'LineWidth', 2 )
legend( '插值点', '原曲线', 'Interpolate polynomial curves' );
axis( [ xi(1) - 1, xi(n) + 1, -1, 2 ] )

汇总代码:
clear all
clc
%% 一次插值
%(xi,yi):
xi = [ 0, 1 ];
yi = sin( xi );
n = length( xi );
y = 0;
x = [ xi(1) - 1 : 0.1 : xi(2) + 1 ];
for k = 1 : n
lkx = LagrangeFactor( xi, k, x );
y = y + yi(k) * lkx;
end
%y
figure;
plot( xi, yi, 'b.', 'markersize', 30 )
hold on
plot( x, sin(x), 'k--', 'LineWidth', 1.5 )
plot( x, y, 'r-', 'LineWidth', 2 )
legend( '插值点', '原曲线', 'Interpolate polynomial curves' );
axis( [ -1, 2, -1, 3 ] )
%% 抛物插值
clear all
clc
xi = [ 0, pi/2, pi ];
yi = [ 0, 1, 0 ];
n = length( xi );
y = 0;
x = [ xi(1) - 1 : 0.1 : xi(n) + 1 ];
for k = 1 : n
lkx = LagrangeFactor( xi, k, x );
y = y + yi(k) * lkx;
end
%y
figure;
plot( xi, yi, 'b.', 'markersize', 30 )
hold on
plot( x, sin(x), 'k--', 'LineWidth', 1.5 )
plot( x, y, 'r-', 'LineWidth', 2 )
legend( '插值点', '原曲线', 'Interpolate polynomial curves' );
axis( [ xi(1) - 1, xi(n) + 1, -1, 2 ] )
function lk_x = LagrangeFactor( xi, k, xx )
w = 1;
n = length( xi );
syms x;
for j = 1 : n
w = w * ( x - xi(j) );
end
dw = diff( w );
dwf = matlabFunction( dw );
dwi = dwf( xi(k) );
lx = ( w / ( x - xi(k) ) ) / dwi;
f = matlabFunction( lx );
lk_x = f( xx );
end边栏推荐
- 智慧灯杆网关智慧交通应用
- Became CTO, was killed by my boss in 6 months, I lost 10 million
- 2022国赛Ezpop
- 无需支付688苹果开发者账号,xcode13打包导出ipa,提供他人进行内测
- A40 - 基于51单片机的GSM模块优化设计
- Sigrity PowerSI Characteristic Impedance and Coupling Simulation
- Using Prometheus skillfully to extend the kubernetes scheduler
- ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
- Knowledge Bits - How to Write a Project Summary
- Collection of DP Optimization Methods
猜你喜欢
随机推荐
.NET 6学习笔记(4)——解决VS2022中Nullable警告
uni-app覆盖组件样式h5生效,微信小程序不生效的问题
LeetCode 131.分割回文串
【燃】是时候展现真正的实力了!一文看懂2022华为开发者大赛技术亮点
OpenCV 图像变换之 —— 直方图均衡化
Codeforces Round # 806 (Div. 4) | | precipitation) bloodbath wudaokou
领先实践|全球最大红酒App如何用设计冲刺创新vivino模式
ceph2
Insert a number and sort "Suggested Favorites"
什么是硬件集成开发?硬件集成开发的核心有哪些?
Volatile:JVM 我警告你,我的人你别乱动
After the WeChat developer tool program is developed, no error is reported, but the black screen "recommended collection"
元宇宙虚拟场景互动获得生活、工作、学习新鲜体验
2019强网杯高明的黑客
B49 - 基于STM32单片机的心率血氧检测与远程定位报警装置
【教程3】疯壳·ARM功能手机-整板资源介绍
PADS generates bitmap
CocosCreator接入微信小游戏
无需支付688苹果开发者账号,xcode13打包导出ipa,提供他人进行内测
什么是控制板定制开发?








