专栏
标签
Syslab 中如何对散点数据进行插值操作?
技术分享
发布于 2025-08-06 16:30:36
查看 2过去300天

针对上述问题,可以使用scatteredInterpolant函数或者scatteredInterpolant1函数。

其中scatteredInterpolant函数支持线性插值计算,不支持最邻近点插值计算,在计算最邻近点插值时,可以采用scatteredInterpolant1函数替代.

方法一:使用scatteredInterpolant1函放计算最邻近点插值

1.运行下面代码,创建插值的样本值:

using TyMath

using TyPlot

t =LinRange((3 4)pi,2pi,50)

x=[3cos.(t);2cos.(t);0.7cos.(t)]

y =[3sin.(t);2sin.(t);0.7sin.(t)]

v =repeat([-0.5;1.5;2],inner =length(t))

2.得到以下结果,可以看到已经创建了样本值:
image.png

3.运行以下代码,创建最邻近点插值结构,并查询位置(xq,yq)处的插值:

itp =scatteredInterpolant1(x,y,v,"nearest")

tg=LinRange(3/4*pi+0.2,2*pi-0.2,40)

xq =[2.8 *cos.(tq);1.7* cos.(tq);cos.(tq)]

yq= [2.8 *sin.(tq);1.7* sin.(tq);sin.(tq)]

vq =itp(xq,yq)

4.得到以下结果,已经完成最邻近点插值结构和查询:
image.png

5.运行以下代码,绘图观察最邻近点插值的结果:

p1ot3(x,y,v,".",xq,yq,vq,".")

grid("on")

title("Nearest Interpolation")

xlabel("x")

ylabel("y")

zlabel("Values")

legend(["Sample data","Interpolated query data"])

6.得到以下结果,可以看到已经完成了散点最邻近点插值:
image.png

7.scatteredInterpolant1函数计算最邻近点插值的用法,目前scatteredInterpolant1皙时没有相应的帮助文档:

函数库:TyMath

语法:

F=scatteredInterpolant1(vec(x),vec(y),vec(v),"nearest")

方法二:使用scatteredInterpolant函数计算线性插值

1.运行以下代码,创建插值的样本点:

2.得到以下结果,可以看到已经创建了样本值:
image.png

3.运行以下代码,创建线性插值结构,并查询位置(xq,yq)处的插值:

itp= scatteredInterpolant(Multiquadratic(),[x y]',v)

tq =LinRange(3 /4 *pi +0.2,2 *pi- 0.2,40)

xq=[2.8*cos.(tq);1.7*cos.(tq);cos.(tq)]

yg=[2.8*sin.(tq);1.7*sin.(tq);sin.(tq)]

vq =evaluate(itp,[xq yq]')

4.得到以下结果,已经完成线性插值结构和查询:
image.png

5.运行以下代码,绘图观索线性插值结果:

p1ot3(x,y,v,".",xq,yq,vq,".")

grid("on")

title("Linear Interpolation")

xlabel("x")

ylabel("y")

zlabel("Values")

legend(["Sample data","Interpolated query data"])

6.得到以下结果,可以看到已经完成了散点的线性插值:
image.png

7.scatteredInterpolant通数的用法:

函数库:TyMath

语法:

itp =scatteredInterpolant(method,points,samples;metric Euclidean(),

说明:scatteredInterpolant函数对自变量points与因变量samples采用插值方法method进行插值

示例:

using TyMath

using TyPlot

t =LinRange((3 /4)pi,2pi,50)

x=[3cos.(t);2cos.(t);0.7cos.(t)]

y =[3sin.(t);2sin.(t);0.7sin.(t)]

v =repeat([-0.5;1.5;2],inner= length(t))

itp =scatteredInterpolant(Multiquadratic(),[x y]',v)

tq =LinRange(3 /4 *pi+ 0.2,2 *pi- 0.2,40)

xq=[2.8*cos.(tq);1.7*cos.(tq);cos.(tq)]

yq =[2.8* sin.(tq);1.7 *sin.(tq);sin.(tq)]

vq= evaluate(itp,[xq yq]')

plot3(x,y,v,".",xq,yq,vq,".")

grid("on")

title("Linear Interpolation")

xlabel("x")

ylabel("y")

zlabel("Values")

legend(["Sample data","Interpolated query data"])

image.png

scatteredInterpolant函数的详细用法可以查看帮助文档:
image.png

所属专栏:Syslab基础平台
产品信息:Syslab科学计算环境
科学计算

全部回答

暂无数据
暂无数据
用户
和原帖交流更多问题细节吧,去
我要发帖 我要发帖
资料中心 资料中心
查看更多>
热门帖子 热门帖子
主要贡献者 主要贡献者
过去7天