问题
I have tried to reproduce the script of the following link: Parameters estimation on Lotka Volterra model with Scilab
And I get similar errors in the results to those described in it.. You could guide me to run the script without errors. Gracias Hermes
回答1:
Solution for Scilab 5.5.1 or smaller
The problem is that the solver somehow reach a point where it cannot solve the ode on every t
and stops at a certain point. Thus your y_calc
is smaller than y_exp
in size.
If this is not a problem for you, change diffmat
on line 6 of the Differences
function to
diffmat = y_calc' - y_exp(1:size(y_calc',1),:)
Solution for Scilab 6.0.0 or greater
The ode
function now raise an error when it fails to compute in Scilab 6.X.X.
Using the try ... catch ... end
statements, we can let the program deal with it.
So a wrong (and i will explain why after) solution is changing line 5 of Differences
function to
try // test if ode works normally
[y_calc,odew,odeiw]=ode(y0',t0,t,list(LotkaVolterra,c,n,m,e))
catch // if an error is raised
y_calc = y_exp' // Put a value when the computations fails
end
diffmat = y_calc' - y_exp(1:size(y_calc',1),:)
You would still get warning from ode.
Why it is bad
Since you asked for a running program, i've used the try catch
statement to toss away the error and let the program continue. You should not. It means that your problem is ill defined: the parameters are poorly chosen or it's not numerically solvable. I recommend to work on the mathematics behind the program and find why some parameters may break the ode
algorithm.
And there's another reason you should not follow my answer. As you see, when I catch an error, I give to y_calc
some value. But that's mathematically absurd because an optimization problem rely on the fact that the solution approximate at best the initial problem. I'm 99% sure that the y_calc = y_exp'
statement will gives you unusable results.
来源:https://stackoverflow.com/questions/45861364/scilab-parameters-estimation-on-lotka-volterra-model-scilab