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

조회 수: 4 (최근 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 CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!