필터 지우기
필터 지우기

Save parameters at each ODE iteration

조회 수: 2 (최근 30일)
alesmaz
alesmaz 2019년 11월 1일
답변: Samatha Aleti 2019년 11월 5일
Hi, I would like to know how to save at each iteration of a parametric ODE the vector of my parameters 'p'.
function f=bernardode(p,t)
t=temposp;
options=odeset('AbsTol',1e-6,'RelTol',1e-6);
[T,Z]=ode45(@bernard2,t,z0,options);
function dz = bernard2(t,z)
dzdt=zeros(4,1);
dzdt(1)=-(p(3)*(1-qmin/z(1)))*(((Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2))))/(p(4)+(Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2)))))*z(1);
dzdt(2)=(p(3)*(1-qmin/z(1)))*(((Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2))))/(p(4)+(Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2)))))*z(2);
dzdt(3)=p(2)*z(4)+(p(3)*(1-qmin/z(1)))*(((Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2))))/(p(4)+(Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2)))))*(1-p(1)-z(3));
dzdt(4)=(p(1)-z(4))*(p(3)*(1-qmin/z(1)))*(((Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2))))/(p(4)+(Io/(sigma*L*z(2)))*(1-exp(-sigma*L*z(2)))))-p(2)*z(4);
dz=dzdt;
end
f=Z;
end
In particular the optimal parameters are found by simulated annealing algorithm.
I tried to add a string parameter=p before the second 'end' but the code overwrite p at each cycle.
I tried also to use 'save' command but it doesn't work.
Thank you in advance.
  댓글 수: 2
darova
darova 2019년 11월 1일
Where p parameter changes? How it is obtained?
alesmaz
alesmaz 2019년 11월 1일
Hi, I've solved a parametric (4 parameters) ODE using simulannealbnd in order to find the best parameters' set able to minize the residual sum of square error (I've attached the code below).
fitns = @(p) (norm(datisp-bernardode(p,t))^2);
P=4;
rng(0,'v4');
lb=zeros(P,1);
opts = optimoptions(@simulannealbnd, 'PlotFcns',{@saplotbestx,@saplotbestf,@saplotx,@saplotf},'FunctionTolerance',1e-20);
t0 = clock;
[theta,fval,exitflag,output] = simulannealbnd(fitns,p0,lb,[1;5;5;20],opts)
Since I would like to calculate the confidence intervals for the estimated parameters and with this optimization tool 'nlparci' or similar cannot be used, I've thought to do it manually extracting the iterative parameters from ODE loop. I've tried also to add 'save ('parameters.mat', 'p', -'append')' before the second 'end' but the code overwrites at each cycle the vector p.
I hope that I've been clear. Thank you.
P.S. If it were possible to calculate the confidence intervals in another way I would use that method instead of this.

댓글을 달려면 로그인하십시오.

답변 (1개)

Samatha Aleti
Samatha Aleti 2019년 11월 5일
As per my understanding, you want to save the vector "p" of each iteration. To do this, you can initialize a matrix, let “store” of size (number of iterations) x (length of vector p) as follows:
% numIterations : number of iteration
% len : length of vector p
store = zeros(numIterations, len); % Initialization
idx = 0; % Row index
Then save each ‘p’ in a separate row of “store” using “idx” as follows:
% Before end in your code
idx = idx+1;
store(idx,:) = p;

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by