在Matlab中进行样条插值以预测值 [英] Spline interpolation in matlab in order to predict value
问题描述
我的情况如下图所示:
此图是两个向量的结果:
This plot is the result of two vectors:
fi = [41.309180589278, 41.8087915220215, 42.8081880760916, ...
43.8078181874395, 44.8076823745539, 45.8077808710707, 46.3079179803177]
m = [1.00047608139868, 1.00013712198767, 0.999680989440986, ...
0.999524195487826, 0.999671686649694, 1.00012913666266, 1.00047608139868]
我需要获取fi
的值,其中m
等于1.所以大约是42.2和42.5.
I need to get the values of fi
where m
is equal to 1. So approximately that will be 42.2 and 42.5.
我试图进行样条插值:
xq = [fi(1):0.25:fi(7)];
vq1 = interp1(fi,m,xq);
[fi1, fi2] = interp1(m, xq, 1)
但这不起作用.有人可以帮我吗?
But that is not working. Can someone help me with this?
推荐答案
查找过零的一种方法是使图形侧向翻转",使fi
是m
的函数,然后进行插值以找到m=0
.但是interp1
要求m
输入必须是单调的,但不是.实际上,对于每个m
,此函数都有两个不同的值.
One way to find a zero crossing is to "turn the graph sideways", having fi
be a function of m
, and interpolate to find m=0
. But interp1
requires the m
input to be monotonic, which this is not. In fact, this function has two different values for each m
.
MATLAB知道 fzeros
函数,该函数可以找到一个函数的数字过零.它需要一个函数作为输入.我们可以使用interp1
定义匿名函数,该函数为x
的任何值返回m-1
.在这里,x
由fi
定义,而f(x)
由m
定义:
MATLAB knows the fzeros
function, which finds a zero crossing of a function numerically. It requires a function as input. We can define an anonymous function using interp1
, which returns m-1
for any value of x
. Here, x
is defined by fi
and f(x)
by m
:
fi = [41.309180589278, 41.8087915220215, 42.8081880760916, ...
43.8078181874395, 44.8076823745539, 45.8077808710707, 46.3079179803177];
m = [1.00047608139868, 1.00013712198767, 0.999680989440986, ...
0.999524195487826, 0.999671686649694, 1.00012913666266, 1.00047608139868];
fun = @(x)interp1(fi,m,x)-1;
x1 = fzero(fun,42)
x2 = fzero(fun,46)
这给了我
x1 = 42.109
x2 = 45.525
请注意,我们需要知道这两个零的大概位置.据我所知,没有简单的方法可以解决此问题.如果知道两个零交叉以及函数的一般形状,则可以找到局部最小值:
Note that we needed to know the approximate locations for these two zeros. There is no easy way around this that I know of. If one knows that there are two zero crossings, and the general shape of the function, one can find the local minimum:
[~,fimin] = min(m);
fimin = fi(fimin);
,然后找到每个端点和局部最小值之间的零交叉点:
and then find the zero crossings between each of the end points and the local minimum:
x1 = fzero(fun,[fi(1),fimin])
x2 = fzero(fun,[fimin,fi(end)])
这篇关于在Matlab中进行样条插值以预测值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!