当前位置:网站首页>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;
end
3.绘图
代码:
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
边栏推荐
- 【燃】是时候展现真正的实力了!一文看懂2022华为开发者大赛技术亮点
- 2019强网杯高明的黑客
- pgsql备份工具,哪个比较好?
- ECCV 2022 | BMD: 面向无源领域自适应的类平衡多中心动态原型策略
- MySQL 5.5系列安装步骤教程(图解版)
- 安装MySQL的最后一步第四个红叉怎么解决
- Functions and Features of Smart Home Control System
- CocosCreator accesses WeChat mini-games
- 融云 x N 世界:构建无限用户实时交互的「元宇宙会场」
- Leading practice | How the world's largest wine app uses design sprint to innovate the vivino model
猜你喜欢
QuickSort(快速排序)&&MergeSort(归并排序)的效率比较[搭配LeetCode例题]
B43 - 基于STM32单片机的自动视力检测仪
聊聊基于docker部署的mysql如何进行数据恢复
Using Prometheus skillfully to extend the kubernetes scheduler
领先实践|全球最大红酒App如何用设计冲刺创新vivino模式
2.1、基于并行上下文注意网络的场景文本图像超分辨率
HR to get the entry date RP_GET_HIRE_DATE
智慧灯杆网关智慧交通应用
shopee引流方式有哪些,商家如何为自己店铺做引流?
MySQL 5.5 series installation steps tutorial (graphical version)
随机推荐
Print the star chart "Recommended Collection"
August 9, 2022: Build .NET apps in C# -- use the Visual Studio Code debugger to interactively debug .NET apps (won't, fail)
No need to pay for the 688 Apple developer account, xcode13 packaged and exported ipa, and provided others for internal testing
qiucode.cn网站之文章详情实现代码块可点击按钮进行复制
MySQL索引的B+树到底有多高?
中科院打脸谷歌:普通电脑追上量子优越性,几小时搞定原本要一万年的计算...
B44 - 基于stm32蓝牙智能语音识别分类播报垃圾桶
消防安全培训|暑期“消防课堂”,开讲!
【服务器数据恢复】SAN LUN映射出错导致文件系统数据丢失的数据恢复案例
A42 - 基于51单片机的洗衣机设计
B50 - 基于51单片机的儿童成长管理系统
知识点滴 - 如何写项目总结
PADS generates bitmap
Sigrity PowerSI Characteristic Impedance and Coupling Simulation
OpenCV 图像变换之 —— 直方图均衡化
IDEA中Lombok插件的安装与使用
B43 - 基于STM32单片机的自动视力检测仪
After the WeChat developer tool program is developed, no error is reported, but the black screen "recommended collection"
Knowledge Bits - How to Write a Project Summary
Lagrange插值公式matlab实现