Fit coefficients are equal (to starting points) in 3000 different fits
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gil
el 5 de Ag. de 2022
Comentada: Cris LaPierre
el 7 de Ag. de 2022
Hey all,
I'm trying to get the fit coefficients data, for about 3000 fits with added data, starting with 10 points and adding another and another until I get to 2999 points.
My goal is to see how the fit coefficients, and eventually the gooddness of fit as well, changes over the change in the data. When I run my script the coefficients end up fixed as their start points. What did I do wrong?
Another question is do you maybe know how do I extract the R-square value out of the fit in a similar way? and the coefficients errors?
One last less urgent question - right now I need to fill manually the data array (x,y as follows) and cannot extract it from the workspace. Is there a way to use the workspace here?
I'm adding my script for clearer understanding.
Thanks in advance!
function[x,y,f] = GraphFittingAnalysisFrom0 (x,y,f) % x,y are columns and f the fitting function.
prompt_x = ['x='];
prompt_y = ['y='];
prompt_f = ['fit type f='];
x = input(prompt_x);
y = input(prompt_y);
f=input(prompt_f);
Fit = fit(x,y,f);
A = coeffnames(Fit);
Num_of_coeff = size(A,1);
disp(['the number of coefficients is ', num2str(Num_of_coeff)]) % check by output
Start_point = zeros([Num_of_coeff 1]); % asking user to enter coefficients' start point
for i = 1: Num_of_coeff
Start_point(i) = input(['start point of ',A{i},' ']);
end
Coefficients = zeros([Num_of_coeff 2999]); % where values of coefficients will be saved
for n = 10:2999 % the problem is in the fits here -it does not change the coefficients and give them as their start points
x_n = x(1:n);
y_n = y(1:n);
options = fitoptions(f);
options.Robust = 'LAR';
options.StartPoint = Start_point;
options.MaxIter = 25000;
options.TolFun = 25000;
Fit_n = fit(x_n,y_n,f,options);
Val = coeffvalues(Fit_n);
Coefficients(:,n) = Val.'; % saving the coefficients values of the nth fit in the nth column of Coefficeints
end
disp (Coefficients)
tiledlayout(1,Num_of_coeff) % plotting the coefficients graphs
X=[1:2999];
for i = 1 : Num_of_coeff
Y=Coefficients(i,:);
nexttile
plot(X,Y)
title(A{i})
end
end
8 comentarios
Cris LaPierre
el 7 de Ag. de 2022
My apologies. It looks like I was accidentally loading the wrong mat file on my computer (XYData instead of xyvectors)
Respuesta aceptada
Bruno Luong
el 7 de Ag. de 2022
Editada: Bruno Luong
el 7 de Ag. de 2022
Can you do check whereas they are identical with this command after the loop
isequal(Coefficients(:,10),Coefficients(:,2999))
fprintf('%e ', Coefficients(:,10)-Coefficients(:,2999))
fprintf('\n')
3 comentarios
Bruno Luong
el 7 de Ag. de 2022
Editada: Bruno Luong
el 7 de Ag. de 2022
Are you sure is this huge value?
options.TolFun = 25000
The starting point probably satisties such lostly tolerance so the fit give you back what you feed in.
(PS also; Highly recommended you check correctness of output.exitflag with
[Fit_n, ~, output] = fit(x_n,y_n,f,options);
)
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!