I need to make a Gaussian fit, problem is i dont know how to type the parameters using lsqcurvefit
조회 수: 15 (최근 30일)
이전 댓글 표시
Equation of Gaussian distribution
if it's not gonna work with lsqcurvefit then please suggest another Function
[name,path]=uigetfile({'*.xlsx'});
filename = [path name];
opts = detectImportOptions(filename);
preview(filename,opts);
newtable = readtable(filename,'Range','A1:D15');
newtable(:,1)=[]; % Discard A Column
newtable(:,2)=[]; % Discard C Column
figure;
x = newtable{:,1};
y = newtable{:,2};
plot(x,y)
title('Energy in Relation of Beam Insulation');
xlabel('Movement on y Axis [mm]');
ylabel('Energy [mW]');
dydx = gradient(y(:))./gradient(x(:));
mitt=mean(dydx); % Average
sig = std(dydx); % Standard Deviation
fun = @(z,x)z(1)*exp(; % Here is the Problem !!!!
x0 = [1 1];
z = lsqcurvefit(fun,x0,x,dydx)
times = linspace(x(1),x(end));
plot(x,dydx,'ko',times,fun(z,times),'b-')
set(gca, 'YDir','reverse')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
댓글 수: 0
채택된 답변
Torsten
2022년 9월 2일
편집: Torsten
2022년 9월 2일
M = [
24.6 1.518572825
24.7 1.5083088954
24.8 1.5210166178
24.9 1.4203323558
24.95 1.1490713587
24.97 0.9853372434
24.99 0.811827957
25.01 0.6217008798
25.03 0.4384164223
25.05 0.2776148583
25.07 0.1495601173
25.09 0.0654936461
25.11 0.0151515152
25.16 0
25.26 0 ];
x = M(:,1);
y = M(:,2);
dydx = -gradient(y(:))./gradient(x(:));
mitt=mean(dydx); % Average
sig = std(dydx); % Standard Deviation
fun1 = @(z)1/(z(2)*sqrt(2*pi))*exp(-(x-z(1)).^2/(2*z(2)^2));
fun= @(z)fun1(z)-dydx;
z0 = [mitt sig];
z = lsqnonlin(fun,z0)
plot(x,dydx)
hold on
plot(x,fun1(z))
댓글 수: 2
Torsten
2022년 9월 2일
lsqnonlin tries to determine parameters such that res_i(p1,p2,...,pn) = 0.
So in contrast to lsqcurvefit where you define
f_i = 1/(z(2)*sqrt(2*pi))*exp(-(x_i-z(1)).^2/(2*z(2)^2))
and the solver subtracts dydx(i) internally from f_i, you must provide the residual
res_i = f_i - dydx(i)
for lsqnonlin directly.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!