当前位置:网站首页>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边栏推荐
- Codeforces Round # 806 (Div. 4) | | precipitation) bloodbath wudaokou
- ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
- 智能工具管理系统
- CryoEM粒子(Particle)类型预测的数据集构建
- 【燃】是时候展现真正的实力了!一文看懂2022华为开发者大赛技术亮点
- 2.1、基于并行上下文注意网络的场景文本图像超分辨率
- 央企施工企业数字化转型的灵魂是什么
- Video chat source code - how to improve the quality of one-to-one live broadcast?
- IDEA启动缓慢原因(一)
- PGSQL backup tool, which is better?
猜你喜欢

如何让button中的内容分两行显示

PADS生成位号图

A50 - 基于51单片机的太阳能充电路灯设计

2022年8月9日:用C#生成.NET应用程序--使用 Visual Studio Code 调试器,以交互方式调试 .NET 应用(不会,失败)

NFT+IDO预售代币合约模式系统开发

Vim practical skills_2. Normal mode and insert mode

期货开户流程和手续费如何调整

B44 - Based on stm32 bluetooth intelligent voice recognition classification broadcast trash

August 9, 2022: Build .NET apps in C# -- use the Visual Studio Code debugger to interactively debug .NET apps (won't, fail)

日志定期压缩、清除
随机推荐
The Chinese Academy of Sciences slaps Google in the face: ordinary computers catch up with quantum superiority, and can solve calculations that would have taken 10,000 years in a few hours...
Optimization of a piece of JDBC code (Part 1)
称重模块的分类及特点
QuickSort(快速排序)&&MergeSort(归并排序)的效率比较[搭配LeetCode例题]
反转链表的多种写法(武器库了属于是)
生产者-消费者线程模型学习
Lagrange插值公式matlab实现
<IDEA using tricks & & combined operation of common keys>
使用SourceTree添加SSH公钥并克隆码云项目(笔记整理篇)
MySQL的索引你了解吗
2.1、基于并行上下文注意网络的场景文本图像超分辨率
B49 - 基于STM32单片机的心率血氧检测与远程定位报警装置
5G NR Paging
OpenCV 图像变换之 —— 拉伸、收缩、扭曲和旋转
2022-08-09日报:做学术OR去公司 ? 想通这点,治好 AI 打工人的精神内耗
A51 - 基于STM32的DHT11和LCD显示串口通信仿真
PHP completes missing dates in date ranges/returns missing dates
ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
期货开户流程和手续费如何调整
LeetCode 413.等差数列划分