如何使用 cftool 去拟合复数数据?

5 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 26 Déc 2019
如何使用 cftool 去拟合复数数据?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 26 Déc 2019
可以使用 lsqcurvefit 函数,请参考:
这里也给出一个例子:
%%Create target data
tmpData = 100*rand(10, 4);
targetData = tmpData(:, 1) + 3i*tmpData(:, 2) + 0.5*tmpData(:, 3) - 2*tmpData(:, 4);
% goal is to approximate x + yi + w + zi
%%Split target data into real and imaginary parts
uData = [real(targetData) imag(targetData)];
%%Input data
inputData = ones(10, 4);
% these are all ones because the function to approximate can be written as:
% x * 1 + y * 1 * 1i + z * 1 + w * 1 * 1i
% we want to find x, y, z, w
% so the input data are all ones
%%Starting assumption for x, y, z, w values
coeff0 = zeros(size(inputData));
%%Create options for the function call
opts = optimoptions(@lsqcurvefit, 'Algorithm', 'levenberg-marquardt');
%%Call the optimization function
coeffVals = lsqcurvefit(@curveFunc, coeff0, inputData, uData, [], [], opts);
%%Get the predicted data based on output of the optimization routine
predictedData = curveFunc(coeffVals, inputData);
%%Plot the original data and predicted data
figure; hold on;
plot(uData(:, 1), uData(:, 2), 'g*');
plot(predictedData(:, 1), predictedData(:, 2), 'bo');
function uout = curveFunc(v, xdata)
% this part is broken down to show how the "curveFunc" relates to the function that we are trying to approximate
tmpUout = v(:, 1) .* xdata(:, 1); % a values
tmpUout = tmpUout + 1i * v(:, 2) .* xdata(:, 2); % b values
tmpUout = tmpUout + v(:, 3) .* xdata(:, 3); % c values
tmpUout = tmpUout + 1i * v(:, 4) .* xdata(:, 4); % d values
uout = [real(tmpUout) imag(tmpUout)];
end

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!