Does set_param have a numerical accuracy limit? If so, what can I do to solve the problem?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ottmar Beucher
el 19 de Ag. de 2015
Comentada: Titus Edelhofer
el 17 de Sept. de 2015
Hello,
I recently conceived a MATLAB/Simulink programming problem for my students. The problem was to adapt the coefficients of a 2nd order linear dynamical system such that the step response best fits a given function.
The structure shoud be as follows (see attaced files OptDynSysTest1.m, simuSys.m and DynSystem.slx, sprawsoll.m in setparamproblem.zip):
When the main file (OptDynSysTest1.m) is launched with a handle to the desired step response (@sprawsoll), the sampling points (for example (0:0.1:10)) and an ititial guess for the three system coefficients (for example [1,1,1]), the program opens DynSystem.slx and tries to optinize those coefficients to best fit the step response of the system to the given function. For this purpose the procedure lsqcurvefit is used. The objective function is represented by simuSys.m. This function simulates the system by setting the actual parameters to DynSystem.slx using set_param and the calling sim.
In a second version of this problem, I do not use Simulink to simulate the system but I'm using lsim instead (see attaced files OptDynSysTest3.m, simuSys3.m and DynSystem.slx, sprawsoll.m in setparamproblem.zip).
The problem is that this program works fine and finds the optimal step resonse approximation whereas the version using Simulink sticks in the first iteration saying that the initial guess is the optimum. Regardedless what the initial guess is!
After a couple of hours of analysis I found out what the reason is.
The problem is set_param!!!
This function passes parameters in a numerically inexact way. For example the parameter 2.001 is passed exactly whereas the parameter 2.0000001 will be simply 2 for Simulink. This is the reason why the optimizaton procedure doesn't work, because in the beginning the changements in the parameter values are very small. Since those small changements "disappear" when passed to Simulink by set_param, the optimization algorithm immediately finds a zero gradient and stops saying that this is an optimum.
My questions: Is this a set_param bug? How can I overcome this set_param problem?
Sincerily Ottmar Beucher
2 comentarios
Sainath Varikuti
el 21 de Ag. de 2015
Hi Ottmar,
You can use get_param(gcb,'ParameterName') to get the value of the parameter. Do you see the truncation in the value returned by get_param?
Regards,
Sainath
Respuesta aceptada
Titus Edelhofer
el 16 de Sept. de 2015
Dear Prof. Beucher,
it's not a bug in set_param but the way it's used, e.g.
set_param('DynSystem/TF1','Numerator',num2str(Coeffs(1)));
num2str converts with 6 digits. Therefore everything else is lost. Call num2str with a precision to overcome the problem:
set_param('DynSystem/TF1','Numerator',num2str(Coeffs(1), 20));
Then it should work as expected.
Titus
4 comentarios
Titus Edelhofer
el 17 de Sept. de 2015
Happy to help :). I think it's o.k. to mark the question as answered then ...
Más respuestas (0)
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!