Borrar filtros
Borrar filtros

Fitting of a data set with interpolation condition

3 visualizaciones (últimos 30 días)
Simone Guadagni
Simone Guadagni el 15 de Mzo. de 2020
Editada: Simone Guadagni el 17 de Jul. de 2020
Hi everyone, I'm trying to fit a data set on the plane whose trend is concave.
Doing that with "Curve Fitting Toolbox" is quite easy, but I have to add another condition: I need that a assigned point A belong to the fitting curve.
Someone can help me?
Thank you very much
  3 comentarios
Simone Guadagni
Simone Guadagni el 15 de Mzo. de 2020
I am attaching below a first plot of the fitting curve made with the toolbox. I want to impose the passage through the circled point. Do you know if it is possible adding this condition in the toolbox with no other calculations?
dpb
dpb el 15 de Mzo. de 2020
Not an implemented constraint. You could try a weighted fit and give the specific point a very high weight and see what happens...otherwise, would have to solve a specific model.

Iniciar sesión para comentar.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 15 de Mzo. de 2020
Editada: Ameer Hamza el 17 de Mzo. de 2020
As pointed out by dpb, you can specify the weights of each data point to the fit() function. Following code shows an example
rng(0);
x = linspace(-1, 1, 20);
y = 2 - x.^2 + 0.25*rand(size(x));
w = ones(size(x));
w(11) = 200;
fitCurve1 = fit(x', y', 'poly2');
y_fit1 = fitCurve1(x');
fitCurve2 = fit(x', y', 'poly2', 'Weights', w);
y_fit2 = fitCurve2(x');
plot(x, y_fit1, 'b', x, y_fit2, 'k', x, y, 'r+', 'LineWidth', 2)
hold on
plot(x(11), y(11), 'r+', 'LineWidth', 4, 'MarkerSize', 15);
legend({'Equal Weights', 'Unequal Weights'})
This code gives high weight to the 11th data point (indicated with a big marker below) in the input. The following figure shows both responses (with and without high weight).

Más respuestas (1)

Simone Guadagni
Simone Guadagni el 21 de Mayo de 2020
I have an additional question: is it also possible to impose a condition on the derivative in the marked point? (in particular i need a maximum in this point).
thanks a lot
  8 comentarios
John D'Errico
John D'Errico el 26 de Mayo de 2020
Editada: John D'Errico el 26 de Mayo de 2020
You need to consider if forcing the curve to have a zero slope at exactly x==1 makes sense in terms of that data. For example, if we zoom into your data
I see you have one point at x==1, perhaps it was even artificially inserted. That is, your data has the exact point (x,y) = (1,0), whereas most of the other data has many decimals in it.
However, if we look at the shape of the curve near there, it seem there is a natural maximum around x==1.05, a location that lies between that point and the next. The shape is fairly complex, but if you force the curve to have a zero slope exactly at x==1, this forces what is essentially a second derivative discontinuity into the curve at x==0.
In this plot, the vertical line in black is where the maximum wants to live, in order to be consistent with the data we see. In fact, this is relative nice, smooth data. In fact, the model fits very well, even though there is some interesting behavior around x=1.5 where the curve dips down, and there is one strange point at x=0.4, that seems to be almost another derivative discontinuity. (I wonder how the data was generated.) In the model as created, the data naturally wants the maximum to be around x=1.05. I get 1.0517 from the curve, where that peak lies.
But, now consider the fit when I artifically force the maximum to live exactly at x=1.
Do you see what happens? This is inconsistent with the data itself. In turn, that introduces oscillations into the curve away from that point. I had to force the fit to do something inconsistent with the data.
In order to get the result you want I might as well break the problem into two separate problems, where I model the left and right halves of the curve separately. If I do that, splitting the curve into two halves, but forcing each half to pass through the point at (x,y) = (1,0), then things do fit reasonably well. This implicitly creates a point at x=1 where the curve is continuous but not differentiable.
Simone Guadagni
Simone Guadagni el 29 de Mayo de 2020
Editada: Simone Guadagni el 17 de Jul. de 2020
thank you very much John you have been very kind.
I will do some tests these days and if I have problems I will contact you.
Thanks a lot

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by