curve fitting of a complex data
이전 댓글 표시
I'm currently working on fitting some experimental data to a complex-valued function using MATLAB's lsqcurvefit function. However, I seem to encounter issues, and I'm not getting the desired solution. I'm hoping to get some guidance on what might be going wrong with my approach. I have tried changing the values of initial guesses
VALUE OF P1=102; P3=326;
w1=8000;
xdata = [0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 10500 11000 11500 12000 12500 13000 13500 14000 14500 15000];
ydata = [0 23.23166979 43.89101766 61.37336819 76.13374067 88.63427978 99.17236163 107.96827 115.2289659 121.1585778 125.9542122 129.7976768 132.8504967 135.2544369 137.1234954 138.5545735 139.6310041 140.4137722 140.960863 141.3115956 141.5020398 141.5603911 141.5098635 141.3688178 141.150192 140.8714973 140.5392011 140.1625248 139.7464364 139.3025573 138.8344027];
function= -1j .* ((params(1) .* (xdata ./ 60) ./ (1 + (xdata ./ w1).^2)) + (params(2) .* (xdata ./ 60) ./ (1 + (xdata ./ params(3)).^2))) .* 0.001;
i want to fit the ydata to the function given, i have tried least square methods. But i am not getting the solution.
댓글 수: 9
Cris LaPierre
2023년 7월 25일
Please share your code for performing the fit as well. If you know what the solution should be, share that, too.
The argument list for ‘complex_func’ is reversed from the MATLAB convention. The parameter argument must be the first argument, the independent variable data the second argument.
% Given data
xdata = [0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 10500 11000 11500 12000 12500 13000 13500 14000 14500 15000];
ydata = [0 23.23166979 43.89101766 61.37336819 76.13374067 88.63427978 99.17236163 107.96827 115.2289659 121.1585778 125.9542122 129.7976768 132.8504967 135.2544369 137.1234954 138.5545735 139.6310041 140.4137722 140.960863 141.3115956 141.5020398 141.5603911 141.5098635 141.3688178 141.150192 140.8714973 140.5392011 140.1625248 139.7464364 139.3025573 138.8344027];
w1 = 8000;
% Define the complex function
% complex_func = @(xdata, params) -1j .* ((params(1) .* (xdata) ./ (1 + (xdata ./ w1).^2)) + (params(2) .* (xdata) ./ (1 + (xdata ./ params(3)).^2))) .* 0.001;
complex_func = @(params, xdata) -1j .* ((params(1) .* (xdata) ./ (1 + (xdata ./ w1).^2)) + (params(2) .* (xdata) ./ (1 + (xdata ./ params(3)).^2))) .* 0.001;
% Define the cost function for lsqcurvefit
cost_func = @(params) abs(abs(complex_func(xdata, params)) - ydata);
% Initial guess for the parameters
p0 = [1, 2, 16000];
% Use lsqcurvefit to find the best-fitting parameters
best_params = lsqcurvefit(complex_func, p0, xdata, ydata)
% Evaluate the fitted complex function at the data points using the optimized parameters
yfit = abs(complex_func(best_params,xdata)); % <— CHANGED (Argument Order Reversed)
% Plot the data and the fitted function
figure;
plot(xdata, ydata, 'o', xdata, yfit, '-')
legend('Data', 'Fit');
xlabel('xdata');
ylabel('ydata');
title('Complex Curve Fitting Example');
grid on;
% Display the optimized parameters
disp('Optimized Parameters:');
disp(['k1: ', num2str(best_params(1))]);
disp(['k2: ', num2str(best_params(2))]);
disp(['w2: ', num2str(best_params(3))]);
With that change, it works, and the fit seems to be reasonably good!
.
Supreeth D K
2023년 7월 25일
Star Strider
2023년 7월 25일
The lsqcurvefit function allows bounding the parameters. That is likely preferable to fixing the values of ‘K1’ and ‘K2’ and solving only for the ‘W2’, although that is certainly an option.
Supreeth D K
2023년 7월 25일
Cris LaPierre
2023년 7월 25일
Star Strider
2023년 7월 25일
Supreeth D K
2023년 7월 27일
답변 (0개)
카테고리
도움말 센터 및 File 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!
