Nonlinear curve fitting with summation function
이전 댓글 표시
I have the following data (Rt vs Sm) that I would like to fit with the following equation:

where ri=r0+i*(Ss+Sm), r0=30. In the fitting, Rs, Rm and LT are fitting parameters with initial guesses [100, 0.2, 0.2].
Please excuse the poor coding as I am new to MATLAB and have been using ChatGPT to help. I have the following code but it returned multiple errors and a few fixes doesn't seem to help. I am attaching the data file. Thank you in advance!
% Load data from Excel file
data = readtable('results.xlsx');
% Designate first column as Sm and second column as Rt
Sm = data(:,1).Variables;
Rt = data(:,2).Variables;
% Define fitting function
ri = 30+(0:9).*(10+Sm);
rj = (1:9).*(10+Sm);
fun = @(x,Sm) ((x(1))/(2*pi))*sum((log((ri+Sm)./ri))+((x(2))*((1./ri)+(1./(ri+Sm)))))+(x(3))/(2*pi)*(sum(log((rj-(x(2)))./(ri-10+(x(2))))));
% Set initial guess for fitting parameters
x0 = [100, 0.2, 0.2];
% Perform nonlinear curve fitting
x = lsqcurvefit(fun,x0,Sm,Rt);
% Calculate fitted values
Rt_fit = fun(x,Sm);
% Calculate R-square value
Rsq = 1 - sum((Rt - Rt_fit).^2)/sum((Rt - mean(Rt)).^2);
% Plot data and fitted curve
figure;
plot(Sm,Rt,'o',Sm,Rt_fit);
legend('Data','Fitted Curve');
xlabel('Sm');
ylabel('Rt');
채택된 답변
추가 답변 (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!
