Filter löschen
Filter löschen

Build a function by combining a variable number of sub-functions

3 Ansichten (letzte 30 Tage)
Ferdi
Ferdi am 30 Mär. 2022
Bearbeitet: Geoff Hayes am 31 Mär. 2022
Hi,
I’m building an app to fit some data.
The fitting function can vary, and I’d like to have the possibility to use different combinations of basic functions, like Lorentzian, gaussian, damped harmonic oscillator…. In the example below, there are two of these functions (Lrz and DHO) and a multiplying factor (be) :
properties (Access = public)
nLrz, nLrzw, nDHO, T % Lorz
end
methods (Access = private)
function nw=be(app,x,Temp)
kT=8.6173303e-2*Temp;
nw = 1/kT*x./(1-exp(-x/kT));
nw(isnan(nw))=1;
end
function fLrz = Lrz(app,P,x)
fLrz=(P(1)/pi*P(2)./(x.^2 + P(2)^2));
end
function fDHO = DHO(app,P,x)
fDHO=P(1)/pi * 2*P(2) * P(3)^2 ./ ( (x.^2-P(3)^2).^2 + 4*(P(2) * x).^2 ) ;
end
end
The number of the Lrz and DHO is also a variable (they typically range from 1 to 4). For example: Ftot = Lrz1 + Lrz2 + be*DHO (that is nLrz=2 and nDHO=1), that means that I’d like to have something like :
Ftot = @(pL1,pL2,pL1,x) Lrz(app,pL1,x) + Lrz(app,pL2,x) + be.*DHO(app,pD1,x)
As far I understood, loops are not suggested.
Based on the number of parameters, the app will produce a table where to enter the guess values of the (variable number of) parameters pL1,pL2,pD1, T,and so on
I am wondering which is the best way to enter the parameters in Ftot.
A possible choice is to have something like:
pL(1).I=10; % 1st Lrz
pL(1).G=2;
pL(2).I=1; % 2nd Lrz
pL(2).G=6;
pD(1).I=1; % 1st DHO
pD(1).G=1;
pD(1).E=8;
I am looking for some hints on the more efficient way to go on.
Thanks for your help!

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by