'polyfit' for parametrized curves.
조회 수: 5 (최근 30일)
이전 댓글 표시
%
Hello! My question is about the 'polyfit' routine, i have a collection of (x,y) points that are similar to a star, and i want to make a function out of thoose points in order to calculate a line integral. However, it's not a biyecitve function, so. It is possible for polyfit to fit a parametrized curve (x(t), y(t))? If not, there is another routine that makes that possible?
채택된 답변
John D'Errico
2022년 12월 8일
편집: John D'Errico
2022년 12월 8일
Can polyfit be made to solve this in a parameetric form? NO. Why not? Because even if it COULD be used for that purpose, the result you want to make is a piecewise linear function. Polyfit cannot solve that problem!
Can you solve it in a different way? Of course. But you will need to use a pair of splines, of a very specific type. If the curve really is represented as piecewise linear star segments, then you need linear spline segments. For example...
t = linspace(0,2*pi,11)';
rad = [1 3];
r = mod((1:11)',2)*diff(rad) + rad(1);
xy = r.*[cos(t),sin(t)]
plot(xy(:,1),xy(:,2),'-o')
axis equal
So a 5 pointed star. Nobody can ever say all of my answers are pointless. ;-) Without merit, maybe.
We can create a simple function that can evaluate x(t) and y(t) separately as piecewise linear functions using griddedInterpolant.
x_t = griddedInterpolant(t,xy(:,1))
y_t = griddedInterpolant(t,xy(:,2));
Now, you should be able to perform a line integral along that path. since there are two parametric functions. For example, you can now plot x)t as functino of t, or evaluate it at any point.
tint = linspace(0,2*pi);
plot(tint,x_t(tint),'r',tint,y_t(tint),'g')
legend('x(t)','y(t)')
And integral will have no problems.
fxy = @(x,y) x.^2 + y.^2;
f_t = @(t) fxy(x_t(t),y_t(t));
integral(f_t,0,2*pi)
추가 답변 (1개)
Walter Roberson
2022년 12월 8일
It is possible for polyfit to fit a parametrized curve (x(t), y(t))?
No, polyfit is strictly restricted to polynomials of the form (t, y(t)), never to (t, x(t), y(t)) .
In the Curve Fitting Toolbox, fit can be used to fit (t, x(t), y(t)) to a variety of different functions, such as 'poly23' (degree 2 in one of the independents, degree 3 in the other independent)
You can also use fit() to fit custom functions.
However, fit() expects the functions to be continuous with continuous first derivatives, and so would not be suitable for functions with sharp corners.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!