Questions about ppval in piecewise polynomial
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a question about piecewise polynomial.
If I use t=pp.coefs to get the coefficients about the polynomial.
Then I use
[m n]=size(t);
for i=1:n-1
t(:,i)=i.*t(:,i);
end
to get the new coefficients after differentiate it. How can I use ppval again to evaluate the polynomial with this new coefficients?
댓글 수: 0
답변 (1개)
John D'Errico
2016년 4월 2일
편집: John D'Errico
2016년 4월 2일
You only think that this differentiates the polynomial. But it does not. In fact, look at the result. For example, consider the polynomial represented by coefficients:
t = [1 2 3 4]
so the polynomial is
x^3 + 2^x^2 + 3*x + 4
Remember in MATLAB, the polynomial is represented by the coefficients starting from the highest order first.
Now, try the code you wrote. What vector t results?
[m n]=size(t);
for i=1:n-1
t(:,i)=i.*t(:,i);
end
t
t =
1 4 9 4
so:
x^3 + 4*x + 9*x^2 + 4
Clearly that is the wrong derivative. Instead, try this:
M = diag([3 2 1],1);
t = [1 2 3 4];
t*M
ans =
0 3 4 3
That is the polynomial
0*x^3 + 3*x^2 + 4*x + 3
Which is the proper derivative polynomial. Just stuff it back into the proper field in pp.
pp.coefs = pp.coefs*M;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!