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

6 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2019 年 12 月 26 日
回答済み: MathWorks Support Team 2019 年 12 月 26 日
如何使用 cftool 去拟合复数数据?

採用された回答

MathWorks Support Team
MathWorks Support Team 2019 年 12 月 26 日
可以使用 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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!