Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

problem with integrating a function containing one fitting parameter

1 vue (au cours des 30 derniers jours)
Amin
Amin le 29 Oct 2011
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello all,
I am trying to fit one integral function:
Y(x) = integral ( x ./ (x.^4 + (omega + p(1)).^2) dx)
which has one fitting parameter p(1) inside.
Below is my code. But before reviewing the code, I should mention these points:
x data are "omega"
y data are the measures values "Y"
so in the code, matlab first makes a cell array of functions (one function for every Omega value). Now function contains only 'x' and p(1).
Here is the problem: G(j) = @(p)quad(f_string(p),0,3);
I try to do the integral(for example between 0 and 3), taking 'p' as independant, then do the fitting on p(1).
x=[... some example data ...];
y=[... some example data ...];
%estimate of error in the measurement 2%
dy = y*0.02;
pat = 'omega';
K_diff = 1.0 / (6.0e-9);
f = ' x ./ (x.^4 + (omega + p(1)).^2) ';
%Number of parameters
Npar = 1;
%initial parameter guess
p = [1];
Nrepeat=10;
sd = 0.08;
%========================================================
pList=zeros(Nrepeat,Npar);
for rep =1:Nrepeat
rep
%form the new randomized start vector
for np = 1:Npar
p(np) = [p(np)*(1+sd*randn)];
end
%do the fit
w = [1 5 10 15 20];
% makes a cell array of functions (one function for every Omega value)
f_str ='';
for i = 1:5
replace = int2str(w(i));
r = regexprep(f,pat,replace);
r = cellstr(r);
f_str = [f_str; r];
end
f_cell = cellstr(f_str);
% integrating and fitting
for j = 1:5
f_string = char(f_cell(j));
G(j) = @(p)quad(f_string(p),0,3);
[p,r,j] = nlinfit(x,y,G(j),p);
end
??? Index exceeds matrix dimensions.
Error in ==> quad at 75 if ~isfinite(y(1))
Error in ==> @(p)quad(f_string(p),0,3)
Error in ==> nonlinear_fit_integral at 178 [p,r,j] = nlinfit(x,y,G(j),p);

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by