Curve fitting to a non-linear created equation

5 visualizaciones (últimos 30 días)
Richard Wood
Richard Wood el 10 de Abr. de 2020
Comentada: darova el 10 de Abr. de 2020
Hello everyone
I have a doubt concerning a fitting that I am trying to obtain. Suppose my independent variable is called "spatial_grid", while my dependent variable is called "mx_elastic". I want to fit, for each column of the "mx_elastic" array, this matrix to the "fitting_DWs_profile_elastic" function. Previously, I have stimated some initial values for the fitting, that it is, Delta1_elastic(1), A1_elastic(1), q1_elastic(1), Delta2_elastic(1), A2_elastic(1), and q2_elastic(1). The relevant part of my code is the following:
fitting_DWs_profile_elastic=@(A1_elastic,q1_elastic,Delta1_elastic,A2_elastic,...
q2_elastic,Delta2_elastic)(A1_elastic.*sech((spatial_grid-q1_elastic)./Delta1_elastic)+...
abs(A2_elastic).*sech((spatial_grid-q2_elastic)./Delta2_elastic));
for i=2:length(physical_time_elastic)
fitted_DW_elastic=fit(spatial_grid,mx_elastic(:,i),fitting_DWs_profile_elastic,...
'StartPoint',[A1_elastic(i-1),A2_elastic(i-1),q1_elastic(i-1),q2_elastic(i-1),Delta1_elastic(i-1),...
Delta2_elastic(i-1)]);
A1_elastic(i)=fitted_DW_elastic.A1_elastic;
A2_elastic(i)=fitted_DW_elastic.A2_elastic;
q1_elastic(i)=fitted_DW_elastic.q1_elastic;
q2_elastic(i)=fitted_DW_elastic.q2_elastic;
Delta1_elastic(i)=fitted_DW_elastic.Delta1_elastic;
Delta2_elastic(i)=fitted_DW_elastic.Delta2_elastic;
% if q1_elastic(i)=q2_elastic(i)
% break
% else continue
% end
end
After stimate the parameters, I want to save them in the corresponding element of the array "A,q,Delta1,2_elastic". Moreover, I want to include a condition in my for loop. If q1_elastic(i)=q2_elastic(i), then do not take into account the i-th fitting, and stop the process. If that condition is not fulfilled, continue.
For some reason, without taking into account the if condition, I get the following error:
Error using fittype>iDeduceCoefficients (line 621)
The independent variable x does not appear in the equation expression.
Use x in the expression or indicate another variable as the independent variable.
Error in fittype>iCreateFromAnonymousFunction (line 516)
obj = iDeduceCoefficients(obj);
Error in fittype>iCreateFittype (line 357)
obj = iCreateFromAnonymousFunction( obj, varargin{:} );
Error in fittype (line 330)
obj = iCreateFittype( obj, varargin{:} );
Error in fit>iFit (line 165)
model = fittype( fittypeobj, 'numindep', size( xdatain, 2 ) );
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in Post_Spin_Peltier_Treatment (line 219)
fitted_DW_elastic=fit(spatial_grid,mx_elastic(:,i),fitting_DWs_profile_elastic,...
Probably a problem in the syntax of creating the function or fitting. Any ideas? Also, is the if condition well postulated?
  1 comentario
darova
darova el 10 de Abr. de 2020
I think your question is too complicated. You should simplify it

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by