一维线性插值java实现_使用线性插值来预测matlab中的值

Simple Interpolation

你可以用另一种方式插值......

% Your code

x = [1 2 3 4 5 6 7 8 9];

y = [1 2 3 4 5 4 2 6 8];

xq = [1:0.25:9];

yq = interp1(x, y, xq);

% Interpolate your newly interpolated xq and yq to find x = x1 when y = 3.5

x1 = interp1(yq, xq, 3.5)

Finding Zeros

这种方法更复杂,但根据您的数据,可能更适用 .

您可以使用fzero使用某种根查找方法,并使用如下定义的函数

% Initialise

x = [1 2 3 4 5 6 7 8 9]; y = [1 2 3 4 5 4 2 6 8];

% Define function, like your interpolation, which will have a zero at x=x0

% when y = y0.

y0 = 3.5;

yq = @(xq) interp1(x, y, xq) - y0

% find the zero, intial guess must be good enough

y0 = fzero(yq, 1)

正如评论中所指出的那样,初始猜测必须是"good enough" - 这不仅仅适用于 fzero 内的收敛,而且如果在评估期间测试的x值超出了插值范围,那么它将会中断 .

例:

y0 = fzero(yq, 1)

% >> Exiting fzero: aborting search for an interval containing a sign change

% because NaN or Inf function value encountered during search.

% (Function value at 0.971716 is NaN.)

y0 = fzero(yq, 5)

% >> y0 = 3.5, as expected from the input data.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值