Dear all,
i’m wondering whether it exists somewhere help resource or specific examples about the calibration of model developed in Xcos (modelica) environment ?
As first step in naïve approach I’m considering to write a cost function that includes a call to Xcos simulation where parameters are read from the Context
and simulation outputs in matrix updated in the context
as well. Then call fminsearch with such cost function. Does it make sense or another more Xcos-integrated approach available ?
Thank you for any comment and tip !
David
Hello David,
Reading your question, I realize that we completely miss this kind of example in Scilab. Data fitting when the parameters are those of a system of odes is quite common and we have such examples in pure Scilab. But when the system is an Xcos simulation, I think we don’t have any. Anyway, I don’t see any other method than using the Context and ToWorkspace blocks (but I have a limited experience of Xcos).
S.
thank you Stephane for your comment, hopefully I may contribute with some example in a few days !
In fact here is a simple example, where the a coefficient of an exponential
y=\exp(at) is fitted:
function [c,Y]=costf(a)
Context.a=a;
scicos_simulate(scs_m,Context);
c=sum((Y.values-Yobs').^2);
endfunction
loadXcosLibs(); loadScicos();
importXcosDiagram("exp.zcos")
tobs=0:29;
Yobs=exp(-tobs/15)+rand(tobs,"normal")/50;
options = optimset ("Display","iter");
a_opt = fminsearch(costf,0,options);
t=linspace(0,29,100);
clf
plot(tobs,Yobs,'o',t,exp(a_opt*t));
legend("data","y=exp("+string(a_opt)+"*t)")
Iteration Func-count min f(x) Procedure
0 2 11.077356
1 2 11.077356 initial simplex
2 4 4.6579769 expand
3 6 0.4460295 expand
4 8 0.0476999 reflect
5 10 0.0399707 contract inside
6 12 0.0091233 contract inside
7 14 0.0091233 contract inside
8 16 0.0091233 contract inside
9 18 0.0086472 contract inside
10 20 0.0086472 contract inside
11 22 0.0086472 contract inside
12 24 0.0086463 contract inside
13 26 0.0086445 contract inside
Optimization terminated:
the current x satisfies the termination criteria using OPTIONS.TolX of 0.0001
and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 0.0001

exp.zcos (2.9 KB)
Thank you Stephane, it clarifies the structure and key steps to drive the calibration process with underlying Xcos simulation.
David