- Curve Fitting Toolbox Documentation (mathworks.com)
- Optimization Toolbox Documentation (mathworks.com)
fittype, multiplication with constant
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I have a data needs a curcefit. Someone else used the follwing custom fit equation in a different code and obtained a very well curve fit. I am trying to repeat using MATLAB. The equation has a multiplication with C=1E8, but when I do that there is very bad fitting with the real data. Neither the shape nor the data fits. The fit is way out of the experimental data (y) plot.
fittype('1E8*(a + (b/(x^2)))*exp(-x/34)', 'dependent',{'y'}, 'independent',{'x_cm'},'coefficients',{ 'a','b'})
f = fit(x_cm,y,ft,'StartPoint', [9.17E-11 0.75])
However, if I don't have a constant mutiplication (C) and I divide the real data y by C then I get a perfect fit.
fittype('(a + (b/(x^2)))*exp(-x/34)', 'dependent',{'y'}, 'independent',{'x_cm'},'coefficients',{ 'a','b'})
I tried use C as constant inside the fittype but it gave errr.
fittype('C*(a + (b/(x^2)))*exp(-x/34)', 'dependent',{'y'}, 'independent',{'x_cm'},'coefficients',{ 'a','b'})
Any recommendation, Thank you
birsen
댓글 수: 0
답변 (1개)
Karan Singh
2023년 9월 29일
Hi Birsen,
From what I understand, your doubt is about fitting a curve to a set of experimental data using a custom equation. The equation includes a multiplication constant C, and initially, when C is set to 1E8, the curve fit does not match the experimental data. However, when the real data (y) is divided by C, a perfect fit is obtained.
It seems that the multiplication constant C in the fit equation is causing issues with the curve fitting. One possible reason for this discrepancy could be the scale of the data. The constant C = 1E8 might be too large for the data you are working with, causing numerical instability or overflow issues during the fitting process. Dividing the data by C effectively scales it down, making it more suitable for the fitting algorithm.
To address this issue, you can try rescaling your data before fitting the curve. Instead of using C = 1E8, you can divide the dependent variable y by a smaller constant or choose a scaling factor that is more appropriate for your data. For example:
C = 1E4; % Choose a smaller constant
y_scaled = y / C; % Rescale the dependent variable
% Fit the curve using the rescaled data
ft = fittype('(a + (b/(x^2)))*exp(-x/34)', 'dependent',{'y_scaled'}, 'independent',{'x_cm'}, 'coefficients', {'a','b'});
f = fit(x_cm, y_scaled, ft, 'StartPoint', [9.17E-11 0.75]);
% Retrieve the fitted coefficients
a_fit = f.a;
b_fit = f.b;
% Rescale the fitted coefficients back to the original scale
a = a_fit * C;
b = b_fit * C;
By rescaling the data and fitting the curve using the rescaled data, you can obtain the fitted coefficients (a_fit and b_fit) on the scaled-down version of the data. Then, you can rescale these coefficients back to the original scale by multiplying them with the scaling constant C.
Attached below are some documentation links that you may find helpful:
Hope this helps!
Karan Singh Khat
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!