有人可以解释的功能mkpp和ppval的行为? [英] Can someone explain the behavior of the functions mkpp and ppval?

查看:453
本文介绍了有人可以解释的功能mkpp和ppval的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做在MATLAB:

If I do the following in MATLAB:

ppval(mkpp(1:2, [1 0 0 0]),1.5)
ans =  0.12500

这应该构建一个多项式 F(X)= X ^ 3 ,并在评估它 X = 1.5 。那么,为什么它给我结果 1.5 ^ 3 = .125 ?现在,如果我改变的第一个参数定义的域 mkpp ,我得到这样的:

This should construct a polynomial f(x) = x^3 and evaluate it at x = 1.5. So why does it give me the result 1.5^3 = .125? Now, if I change the domain defined in the first argument to mkpp, I get this:

> ppval(mkpp([1 1.5 2], [[1 0 0 0]; [1 0 0 0]]), 1.5)
ans = 0

因此​​,没有改变的功能,我改变了答案。真棒。

So without changing the function, I change the answer. Awesome.

任何人能解释这是怎么回事呢?如何改变的第一个参数 mkpp 更改结果我得到什么?

Can anyone explain what's going on here? How does changing the first argument to mkpp change the result I get?

推荐答案

函数 MKPP 会的的多项式让 X = 0 将开始在你给它相应范围的开始。在你的第一个例子中,多项式 X ^ 3 转移到范围 [1〜2] ,所以如果你想在评价一个多项式的未移位的范围 [01] ,你就必须做到以下几点:

The function MKPP will shift the polynomial so that x = 0 will start at the beginning of the corresponding range you give it. In your first example, the polynomial x^3 is shifted to the range [1 2], so if you want to evaluate the polynomial at an unshifted range of [0 1], you would have to do the following:

>> pp = mkpp(1:2,[1 0 0 0]);   %# Your polynomial
>> ppval(pp,1.5+pp.breaks(1))  %# Shift evaluation point by the range start

ans =

    3.3750                     %# The answer you expect

在你的第二个例子,你有一个多项式 X ^ 3 转向范围 [1 1.5] 和另一个多项式 X ^ 3 转移到的范围为[1.5 2] 。在 X = 1.5 为您提供了一个零值,在第二多项式的开始发生。

In your second example, you have one polynomial x^3 shifted to the range [1 1.5] and another polynomial x^3 shifted to the range of [1.5 2]. Evaluating the piecewise polynomial at x = 1.5 gives you a value of zero, occurring at the start of the second polynomial.

它可以帮助您可视化都使得多项式如下:

It may help to visualize the polynomials you are making as follows:

x = linspace(0,3,100);                     %# A vector of x values
pp1 = mkpp([1 2],[1 0 0 0]);               %# Your first piecewise polynomial
pp2 = mkpp([1 1.5 2],[1 0 0 0; 1 0 0 0]);  %# Your second piecewise polynomial
subplot(1,2,1);                            %# Make a subplot
plot(x,ppval(pp1,x));                      %# Evaluate and plot pp1 at all x
title('First Example');                    %# Add a title
subplot(1,2,2);                            %# Make another subplot
plot(x,ppval(pp2,x));                      %# Evaluate and plot pp2 at all x
axis([0 3 -1 8])                           %# Adjust the axes ranges
title('Second Example');                   %# Add a title

这篇关于有人可以解释的功能mkpp和ppval的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆