'polyfit' for parametrized curves.
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
%
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?
Risposta accettata
John D'Errico
il 8 Dic 2022
Modificato: John D'Errico
il 8 Dic 2022
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)
Più risposte (1)
Walter Roberson
il 8 Dic 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!