non linear fitting with subroutine
Show older comments
Hi everybody,
I am trying to make a fit with a non linear recursive function but it appears that my code does not work.
The code is as follow
close all
clear
load 'teffe_10jumps_from_393_tann100sec_withtau.txt'
teffe_10jumps_from_393_tann100sec_withtau;
t=teffe_10jumps_from_393_tann100sec_withtau(:,1);
T=teffe_10jumps_from_393_tann100sec_withtau(:,2);
teffe=teffe_10jumps_from_393_tann100sec_withtau(:,5);
tau=teffe_10jumps_from_393_tann100sec_withtau(:,4);
A=exp(-274);
x=0.35;
C=1e5;
beta=0.25;
t_ann=t(1:211);
T_ann=T(1:211);
teffe_ann=teffe(1:211);
tau_ann=tau(1:211);
b0=[exp(-274),0.25,1e5,0.35];
lb=[0,0,1e3,0];
ub=[1e-100,1,1e8,1];
f=@(b) teffefit_rout(t_ann,T_ann,b);
z=@(b) norm(teffe_ann(11:end)-f(b));
problem = createOptimProblem('fmincon', 'x0',b0, 'objective',z,'lb',lb,'ub',ub);
gs = GlobalSearch('PlotFcns',@gsplotbestf);
[b,fval] = run(gs,problem)
The subroutine teffefit_rout is reported below
function [Tf]=teffefit(t,T,b)
Dt0=diff(t);
Dtin=0;
Dt=[0 Dt0'];
DT0=diff(T);
DTin=0;
DT=[DTin DT0'];
teffe=zeros(length(t),1);
tau0=zeros(length(t),1);
teffe(1)=T(1);
tau0(1)= b(1)*exp(b(2)*b(3)/T(1)+(1-b(2))*b(3)/teffe(1));
for i=2:length(t);
tau0(i)=@(T) b(1)*exp(b(2)*b(3)/T+(1-b(2))*b(3)/teffe(i-1));
s2=0;
for j=2:i;
s1=0;
for h=j:i;
s1=s1+Dt(h)/tau0(h);
end;
s2= s2+DT(j)*(1-exp(-(s1^b(4))));
end;
teffe(i)=teffe(1)+s2;
end;
Tf=teffe(11:end);
How can I fix the problem in my code. Attached there is the file that I load to make the test.
Thank you!
5 Comments
Adam Danz
on 6 Aug 2022
> How can I fix the problem in my code
@Daniele Sonaglioni, the problem was never described. Are you getting an error (if so, please include the copy-pasted error message)? Are you getting an unexpected result (if so, describe what you're getting and what you expect to get)?
Torsten
on 6 Aug 2022
"teffefit" is "teffefit_rout"
Daniele Sonaglioni
on 8 Aug 2022
Edited: Daniele Sonaglioni
on 8 Aug 2022
Accepted Answer
More Answers (0)
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!