MATLAB: Fitting of a data set with interpolation condition

conditioncurve fittingCurve Fitting ToolboxinterpolationMATLAB

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

Best Answer

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).