Error using integral; First input argument must be a function handle.
Afficher commentaires plus anciens
I am trying to fit my equation using the modelE which is the sum of two functions exciton and continum. Continum is the integral of function cont. I am having error while using matlab inbuilt integral function. Can someone guide me where I am messing up on this code?
A=xlsread('Data');
xdata=1240./A(:,1);
ydata=A(:,2);
plot(xdata,ydata,'r.','markersize',30)
box on
energy=xdata;
Absorption=ydata;
options =optimoptions(@lsqcurvefit,'Algorithm','trust-region-reflective',...
'StepTolerance',1e-19,'MaxFunctionEvaluations',1e10, ...
'MaxIterations',1e3)
var=[0.0529 2.3926 0.0307 1.002];
MI=lsqcurvefit(@modelE,var,energy,Absorption,[],[],options);
fitdata=modelE(MI,energy);
hold on
plot(energy,modelE(var,energy),'co')
plot(energy,exciton(var,energy),'m.','markersize',30)
plot(energy, continum(var,energy),'k.')
function alpha = modelE(var,energy)
alpha = cont(var,energy) +var(2).* exciton(var,energy);
end
function x= exciton(var,energy)
x= 2.*var(1).*sech((energy-var(2)+var(1))./var(3))+...
0.125.*var(1).*sech((energy-var(2)+(var(1)./8))./var(3))+...
(2/27).*var(1).*sech((energy-var(2)+(var(1)./27))./var(3));
end
function y= cont(var,energy)
y=(sech((energy-var(2))./var(3))).*(1./(1-exp(-2.*pi.*sqrt(var(1)./(energy-var(2)))))).*(1./(1-(var(4).*energy-var(2))));
end
function z= continum(var,energy)
z = integral(cont(var,energy),2.39,inf);
end
2 commentaires
Bibek Dhami
le 30 Juin 2022
Torsten
le 30 Juin 2022
During the integration in "continuum", the expression
var(1)./(x-var(2))
becomes or is negative and thus
sqrt(var(1)./(x-var(2)))
becomes complex-valued.
This makes MATLAB's "lsqcurvefit" throw an error and stop.
Réponses (1)
Torsten
le 28 Juin 2022
function z= continum(var,energy)
z = integral(@(x)cont(var,x),2.39,inf);
end
2 commentaires
Bibek Dhami
le 28 Juin 2022
Modifié(e) : Bibek Dhami
le 28 Juin 2022
Torsten
le 28 Juin 2022
An integral gives a single scalar value, not a curve.
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

