- Specifying the independent parameters in the function
- Proper use dot operator( .^, .*)
- Identifying any missing operators in x02. In case x02 is a variable, check if its defined in the code or MATLAB Workspace
How to fit data with an arbitrary lorentzian function
34 次查看(过去 30 天)
显示 更早的评论
I created a function:
x0=1960
y=10
x=linspace(x0-100,x0+100,200)
F=(1/pi*y)*(y^2./(x-x0).^2+y^2)
plot(x,F,'LineWidth',1)
PlotLorentzian = [x', F']; % compile into data format
writematrix(PlotLorentzian,'plotlorentzian.m','filetype','text')
Now I want to fit data from OneLorentzian.txt to this function. OneLorentzian.txt has x in the first column and the output is F; the values of x0 and y are different than the values in the above function but the equation is the same. I need to write a code to fit this spectrum to the function I made, and determine the x0 and y values. The data has a Lorentzian curve shape.
data=load('OneLorentzian.txt')
fitx=data(:,1)
L=data(:,2)
plot(fitx,L)
Lorentzian=fittype(@(fitx,fity)(1/pi*fity)*(fity^2./(fitx-x02).^2+fity^2))
The last line of code isn't working and I'm stuck. Any help is appreciated.
0 个评论
回答(1 个)
Keerthana Chiruvolu
2020-12-16
Hi,
The error in last line of code can be eliminated by,
Sample code:
Lorentzian=fittype(@(fitx,fity)(1/pi*fity).*(fity.^2./(fitx-x0*2).^2+fity.^2),'independent','fity')
0 个评论
另请参阅
类别
在 Help Center 和 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!