Closed contour with least square differences to dataset

23 次查看(过去 30 天)
Trying to reproduce a data model where both X and Y values in a dataset are summarised using the fourier parameters of a closed loop (FPCC) - but the fit function only works with one value of Y for one value of X (whereas a closed loop would have multiple values of Y for one value of X). Does anyone have ideas on how to approach this?
  2 个评论
Sean
Sean 2025-9-19,13:13
编辑:Sean 2025-9-19,13:13
Right, I realise I haven't been very clear - was feeling a bit stressed and under the weather.
The original data is in essence a point cloud - a series of co-ordinates on an arbitary plane chosen by participants in response to a series of stimuli, so the points themselves don't make any particular shape.
The method of analysis is to summarise this point cloud through the fourier closed contour that can be generated by the least squares method, then use the resultant paramaters to describe and analyse the data as a whole.
So in this case eventually getting the parameters Vc1/2, Vs1/2 and V0. (And the same parameters for the Y-axis as well)
John D'Errico
John D'Errico about 3 hours 前
编辑:John D'Errico about 3 hours 前
So what then is the problem? Do exactly as I suggested.
  1. Convert to polar coordinates, by subtracting off the mean, and then using cart2pol.
  2. Model the result using a series of sin and cosine terms (plus a constant), getting a model in the form r(theta).
  3. Once you have a model r(theta), convert back to the original cartesian form, that is:
x = xmean + r(theta)*cos(theta)
y = ymean + r(theta)*sin(theta)
The model you will then generate is exactly what you seem to be asking to get, and I showed you exactly how to do that. Again, what is the problem?

请先登录,再进行评论。

回答(2 个)

Matt J
Matt J 2025-9-18,16:05
编辑:Matt J 2025-9-18,16:21
A closed curve, e.g. a circle, would usually satisfy an implicit equation
F(x,y)=0
The way to approach that is with implicit equation solvers like fsolve or lsqnonlin.
  1 个评论
Matt J
Matt J 2025-9-18,16:21
but the fit function only works with one value of Y for one value of X
Not true, strictly speaking. For example, below every x has two corresponding values y1 and y2. Appropriately, the fit() function finds an intermediate curve.
x=linspace(0,1)';
y1=sin(x);
y2=y1+1;
X=[x;x]; Y=[y1;y2];
f=fit(X,Y,'sin1');
plot(f,X,Y); axis padded

请先登录,再进行评论。


John D'Errico
John D'Errico 2025-9-19,11:38
编辑:John D'Errico 2025-9-19,11:39
This can be quite difficult if you have some completely arbitrary form. But you tell us this is a simple closed form. And as long as that form is not too nasty looking, you can do it easily.
The solution approach I would take is to start with a transformation. You have a problem that is mappable to a circle. SO DO THAT FIRST! That is, convert to polar coordinates. Since you show no data at all, I need to make some up.
t = (0:100)'*2*pi/101;
xy = randn(1,2)*10 + [cos(t),sin(t)]*randn(2,2)*10 + randn(1,2)*20 + randn(numel(t),2)/5;
x = xy(:,1);
y = xy(:,2);
plot(x,y,'.')
The result is in fact, just a random ellipse. I could have been more interesting about what I did, maybe something oval, or made it less obvious, but I've not yet had breakfast. Please don't ask me to think. Anyway, pretend we don't know the true shape, as then we could have used a tool out there that can fit ellipses to data. So, how can we fit a curve to this? First, go polar. (It is getting cold.)
mux = mean(x);muy = mean(y);
[theta,rad] = cart2pol(x-mux,y-muy);
Now, plot it. But don't use a polar plot. We need to think of this as just a cartesian thing now. So plot will suffice.
plot(theta,rad,'.')
You can use the same transformation on the model form you have, and do a fit to your closed contour. In this case, I'm just going to use a fourier series approximation for a fit.
mdl = fit(theta,rad,'fourier4');
hold on
xhat = linspace(min(theta),max(theta),500);
plot(xhat,mdl(xhat),'r-')
Reconstructing the original curve is now simple. Just convert back from polar coordinates. Then add the means back in, and plot.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by