User defined function for curve fitting, but the defined function is complicated
显示 更早的评论
Hi all,
I am working on this project whihc requires me to fit my experimental data using a complicated function (function is attached in the picture below). May I ask how can I create this fitting function using matlab codes?
Information about function:
function (2):
dependent: A_CC
independent: \hbar*\omega
parameters: A_1, E_b, E_g, \Gamma
function (3):
dependent: A_EC
independent: \hbar*\omega
parameters: A_2, E_b, E_g, \Gamma
Please note that any over lapping terms in both functions should have the same value. For instance, \Gamma exist in both (2) and (3), and hence they need to have the same value.

thank you!
2 个评论
Star Strider
2024-5-28
Shouldn’t the actual ‘independent variable’ be ω rather than
? As I am sure you are aware, ℏ is the Planck constant. Is there some specific reason that you want to scale ω by it?
采纳的回答
更多回答(1 个)
SAI SRUJAN
2024-5-28
Hi Jack,
I understand that you are facing an issue with fitting a function in MATLAB.
To fit experimental data using custom functions in MATLAB, we can use the 'fittype' and 'fit' functions from MATLAB's Curve Fitting Toolbox.
Please follow the below code sample to proceed further,
% Define the fitting functions with shared parameters
fitFuncCC = fittype('(A1 * exp(-((x - Eg)^2) / (2*Gamma^2))) + Eb', 'independent', 'x', 'coefficients', {'A1', 'Eg', 'Gamma', 'Eb'});
fitFuncEC = fittype('(A2 * exp(-((x - Eg)^2) / (2*Gamma^2))) + Eb', 'independent', 'x', 'coefficients', {'A2', 'Eg', 'Gamma', 'Eb'});
% load or compute required data/variables
% Fit the first dataset
[fitresultCC, gofCC] = fit(hbarOmega, ACCData, fitFuncCC);
% Fit the second dataset
[fitresultEC, gofEC] = fit(hbarOmega, AECData, fitFuncEC);
For a comprehensive understanding of the 'fittype' and 'fit' functions in MATLAB, please refer to the following documentation.
I hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

