Initial conditions in a fitting

조회 수: 3 (최근 30일)
Roderick
Roderick 2023년 2월 26일
답변: Walter Roberson 2023년 2월 26일
Hello everyone
I'm trying to figure out the impact of boundary conditions on a fitting. The file where my fitting is defined looks like:
function [fitresult,gof]=Fitting(space,magnetization,initial_magnetization,initial_conditions)
if round(initial_magnetization(1),1)==0.7 && round(initial_magnetization(end),1)==0.7
fitting_function='(1/sqrt(2))*(sin(atan(exp(Q*(x-x0)/Delta)))+cos(atan(exp(Q*(x-x0)/Delta))))';
elseif round(initial_magnetization(1),1)==-0.7 && round(initial_magnetization(end),1)==-0.7
fitting_function='-(1/sqrt(2))*(sin(atan(exp(Q*(x-x0)/Delta)))+cos(atan(exp(Q*(x-x0)/Delta))))';
elseif round(initial_magnetization(1),1)==-0.7 && round(initial_magnetization(end),1)==0.7
fitting_function='(1/sqrt(2))*(sin(atan(exp(Q*(x-x0)/Delta)))-cos(atan(exp(Q*(x-x0)/Delta))))';
elseif round(initial_magnetization(1),1)==0.7 && round(initial_magnetization(end),1)==-0.7
fitting_function='-(1/sqrt(2))*(sin(atan(exp(Q*(x-x0)/Delta)))-cos(atan(exp(Q*(x-x0)/Delta))))';
end
ft=fittype(fitting_function,'independent','x','dependent','y');
opts=fitoptions('Method','NonlinearLeastSquares');
opts.Display='Off';
opts.StartPoint=initial_conditions;
[fitresult,gof]=fit(space,magnetization,ft,opts);
On the other hand, in the file where I process the data I have the following:
% Initial conditions
Initial_Conditions=[Delta0 x0_Q Topological_Charge(1)];
% Let's apply the fitting to the mx component
for j=1:length(Time)
[fitresult,gof]=Fitting(Spatial_Grid,mx(:,j),mx(:,1),Initial_Conditions);
Delta_Q(j)=fitresult.Delta; % m
x0_Q(j)=fitresult.x0; % m
Initial_Conditions=[Delta_Q(j) x0_Q(j) Topological_Charge(j)];
end
I was wondering on which order I have to write the initial conditions (Delta0, x0_Q, Topological_Charge), to match what it is defined in the function Fitting. It is important to note that Delta0/Delta_Q corresponds to Delta, x0_Q to x0, and Topological_Charge to Q in the fitting function environment. That is, as, for example:
Initial_Conditions=[Delta_Q(j) x0_Q(j) Topological_Charge(j)];
Initial_Conditions=[x0_Q(j) Delta_Q(j) Topological_Charge(j)];
...

채택된 답변

Walter Roberson
Walter Roberson 2023년 2월 26일
coeffnames(ft)
will tell you the names of the model coefficients. The order they are displayed in is the same order as you should use for the initial values.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by