Hi, I have the following query using spline interpolation for angular data. The code attached below is from matlab documentation:
x = pi*[0:.5:2];
y = [0 1 0 -1 0 1 0;
1 0 1 0 -1 0 1];
pp = spline(x,y);
yy = ppval(pp, linspace(0,2*pi,101));
plot(yy(1,:),yy(2,:),'-b',y(1,2:5),y(2,2:5),'or')
axis equal
This code gives the closed piecewise polynomial for circle of radius 1unit. Now if I calculate the value of plynomial for a given query point, it doesnt give me the correct answer. why??
For ex: xq = 0; yq = ppval(pp,xq);
It gives yq = [1;0] but it should be yq = [1,-1];

댓글 수: 1

Julius Muschaweck
Julius Muschaweck 2021년 8월 23일
If you think my answer is correct, please make it the "accepted answer".Thanks

댓글을 달려면 로그인하십시오.

 채택된 답변

Julius Muschaweck
Julius Muschaweck 2021년 8월 22일

0 개 추천

Your x has five values, your y has seven values. This is a mismatch.
I think you should use
y = [0 1 0 -1 0;
1 0 -1 0 1];
and when you do that,
xq = 0; yq = ppval(pp,xq);
gives you [0;1] as it should. Your "circle" looks more triangular, but that's ok since the sine is badly approximated by the spline with only 5 support points.

댓글 수: 6

mukesh bisht
mukesh bisht 2021년 8월 22일
Here also it gives yq = [0;1] for xq = 0;
But in actual at x= 0, the y values are [-1,1]. This is the problem, it is not giving correct answers
Julius Muschaweck
Julius Muschaweck 2021년 8월 22일
편집: Julius Muschaweck 2021년 8월 22일
Why do you think it should be [1, -1] (a row vector) and not [0;1] == [sin(0); cos(0)] (a column vector)?
mukesh bisht
mukesh bisht 2021년 8월 22일
Because, the piecewise polynomial is representing the circle of radius 1 with centre (0,0).
Hence, when my x = 0; y = radius i.e. y = -1,1. See, the attached figure, red dots corresponds to the query points at x = 0. Clearly, the point x= 0 & y = 0 doesn'nt lie on circle.
Here, my aim is to back calculate the y values using the piecewise polynomial obtained using spline interpolation
Julius Muschaweck
Julius Muschaweck 2021년 8월 22일
Isn't a radius a scalar number -- how can it be -1,1?
Your code, with
x = pi*[0:.5:2];
y = [0 1 0 -1 0;
1 0 -1 0 1];
uses x as the angle, and the first and second row of y are the first and second coordinate of unit circle points in a plane, i.e.
y = [sin(x);
cos(x)];
Then, at xq = 0, you get yq = [0; 1], which is the first column of y, and a point on the unit circle.
Your expected value [-1, 1] is not a point on the unit circle.
mukesh bisht
mukesh bisht 2021년 8월 22일
ok. Thanks. I got it
darova
darova 2021년 8월 23일

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

질문:

2021년 8월 22일

댓글:

2021년 8월 23일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by