User defined function for curve fitting, but the defined function is complicated
Show older comments
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 Comments
Star Strider
on 28 May 2024
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?
Accepted Answer
More Answers (1)
SAI SRUJAN
on 28 May 2024
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!
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
