当前位置:网站首页>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边栏推荐
- Arrow parquet 之 String Reader
- [1413. Stepwise summation to get the minimum value of positive numbers]
- Sigrity PowerSI Characteristic Impedance and Coupling Simulation
- Reasons for slow startup of IDEA (1)
- 称重模块的分类及特点
- Print the star chart "Recommended Collection"
- B48 - 基于51单片机的学生管理门禁系统设计
- 3 Feature Binning Methods!
- 智慧灯杆网关智慧交通应用
- 元宇宙虚拟场景互动获得生活、工作、学习新鲜体验
猜你喜欢
随机推荐
知识点滴 - 如何写项目总结
B024 – STM32温湿度控制体温检测烟雾报警系统
B48 - 基于51单片机的学生管理门禁系统设计
QuickSort(快速排序)&&MergeSort(归并排序)的效率比较[搭配LeetCode例题]
【开源教程4】疯壳·开源编队无人机-OPENMV 脚本烧写
A42 - 基于51单片机的洗衣机设计
融云 x N 世界:构建无限用户实时交互的「元宇宙会场」
硬件开发的发展前景
领先实践|全球最大红酒App如何用设计冲刺创新vivino模式
vr虚拟仿真样板间极大节省出样成本-深圳华锐视点
测试/开发程序员喜欢跳槽?跳了就能涨工资吗?
电子产品硬件开发中存在的问题
Became CTO, was killed by my boss in 6 months, I lost 10 million
Leading practice | How the world's largest wine app uses design sprint to innovate the vivino model
OpenCV 图像变换之 —— 直方图均衡化
Codeforces Round #808 (Div. 2)||Precipitation
IDEA启动缓慢原因(一)
对象模型-虚指针虚表
A49 - ESP8266建立AP传输XPT2046AD数据WIFI模块
B40 - 基于STM32单片机的电热蚊香蓝牙控制系统









![[ Kitex 源码解读 ] 请求重试](/img/d9/c1871c15cc9124e919d22c9adcc75b.png)