Parameters estimation on Lotka Volterra model with Scilab -
i'm trying make parameters estimation on lotka-volterra model scilab (i total neophyte). when try run script, scilab warns incoherent subtraction. guess problem same in this topic, solution there uses matlab function.
here script:
// 1. create lotka volterra function function [dy]=lotkavolterra(t,x,c,n,m,e) ingestc = c * x(1) * x(2) growthp = n * x(1) mortc = m * x(2) dy(1) = growthp - ingestc dy(2) = ingestc * e - mortc endfunction // 2. define nonlinear least squares functions function f = differences ( x ) // returns difference between simulated differential // equation , experimental data. c = x(1) ;n = x(2);m = x(3);e = x(4);y0 = y_exp(1,:);t0 = 0 y_calc=ode(y0',t0,t,list(lotkavolterra,c,n,m,e)) diffmat = y_calc' - y_exp f = diffmat(:) endfunction function val = l_squares ( x ) // computes sum of squares of differences. f = differences ( x ) val = sum(f.^2) endfunction // experimental data t = [0:19]'; h=[20,20,20,12,28,58,75,75,88,61,75,88,69,32,13,21,30,2,153,148]; l=[30,45,49,40,21,8,6,5,10,20,33,34,30,21,14,8,4,4,14,38]; y_exp=[h',l']; // compute model cost function function [f, g, ind] = modelcost (x, ind) f = l_squares ( x ) g = derivative ( l_squares , x ) endfunction // use of optim function loops avoid local minimum tic i=0 fitminx=zeros(4,100); fitminy=zeros(1,100); c=[0:0.1:1] n=[0:0.1:1] m=[0:0.1:1] e=[0:0.1:1] i=i+1 x0 = [c;n;m;e] [ fopt , xopt , gopt ] = optim ( modelcost , x0 ) fitminx(:,i)=xopt; fitminy(:,i)=fopt; end end end end [a,b]=min(fitminy) fitminx(:,a) toc
the error message :
lsoda-- @ t (=r1), mxstep (=i1) steps needed before reaching tout i1 : 500 r1 : 0.4145715729197d+01 attention : le résultat est peut être inexact. !--error 9 soustraction incohérente. @ line 4 of function differences called : @ line 2 of function l_squares called : @ line 16 of function %r_ called : @ line 15 of function %deriv1_ called : @ line 58 of function derivative called : @ line 3 of function modelcost called : [ fopt , xopt , gopt ] = optim ( modelcost , x0 )
thanks interest , time give problem (and sorry english)
duplicate of answer here
the problem solver somehow reach point cannot solve ode on every t
, stops @ point. y_calc
smaller y_exp
in size.
if not problem you, solved changing diffmat
on line 6 of differences
function
diffmat = y_calc' - y_exp(1:size(y_calc',1),:)
Comments
Post a Comment