Aaditya Goverdhan asked . 2022-03-11

How do I estimate or optimize the parameters of my ODE system in MATLAB 8.1 (R2013a)?

I have a system of ordinary differential equations (ODE) with some unknown parameters (coefficients). I want to simultaneously solve the system of differential equations as well as optimize for the unknown parameters by minimizing an objective function that depends on the solution of the ODE system.
 
What is the best way to do this in MATLAB?

parameter , estimation , in , ode , optimize , parameters , simultaneouso , ptimization , and , solv

Expert Answer

Prashant Kumar answered . 2024-04-19 20:09:42

There are two approaches that can be taken:
 
1) The optimization toolbox in MATLAB provides function such as FMINSEARCH, LSQNONLIN, FMINCON etc., which can be used for optimizing parameters while minimizing an objective function. In this case, the objective function will have to call another sub-routine which solves the differential equations using ODE solvers such as ODE23, ODE45, ODE23s, ODE113, or ODE15s. The ODE solver in turn will call the function where the differential equations are implemented.
 
Attached is a simple example that optimizes a single parameter for a 1 state simulation (that is a first order ODE). Note that the ‘optimization toolbox’ is needed to execute the example.
 
The workflow can be described as follows:
 
a) Choose an ODE solver (i.e. ode45 or ode15s), then write the update function for the differential equations.
 
b) Write an objective function that takes in the values of the parameters, solves the ODE for those particular values, and then calculates the cost function (such as the difference between the experimental and simulated data) that needs to be minimized.
 
c) Use an optimization function like LSQNONLIN or FMINCON to minimize the objective function.
 
d) Use this section of the documentation to address potential issues that go along with a numerical optimization routine wrapped around a numerical simulation.
 
For example, some potential problems can occur due to the variable time-stepping used by many ODE solvers. This causes the gradient of the objective function to be ‘non-smooth’. Many optimization routines depend on computing the gradient, the change of the function value when it is perturbed. When the function value is determined by the NUMERICAL solution of an ODE, the function value may not depend smoothly on the perturbation. If you move the perturbation up a little bit, the function moves one way; if you move it up a little bit more, the function may move the opposite way. This non-smoothness is because of the variable step size used by the ODE solvers.
 
A good reference for this problem is Hairer, Norsett, and Wanner, Solving Ordinary Differential Equations I, Springer-Verlag, 1991, pg. 200.
 
One solution for the above problem is to eliminate the error checking done by an explicit ODE Solver (e.g. ode45) by forcing the solver to take fixed steps. This eliminates the need for error checking to choose a step size, but may cause accuracy problems. To do "fixed-step" simulation with the ODE Suite, you can use ODESET to turn up both the ‘RelTol’ and the ‘AbsTol’ to large values (e.g. 1), and set the ‘MaxStep’ and the ‘InitialStep’ to some fixed-step value (visit the documentation page for more information on ODESET). Note that this technique will not work with the implicit solvers such as ode15s.
 
To get output at specific times, you can pass in the vector of times ‘[t1 t2 ... tn]’ as the ‘tspan’ vector:
 
 
[t, y] = ode23(myfun, [t1 t2 ... tn], y0, options);
By combining these two techniques, you can avoid some of the difficulties described in Hairer, Norsett, and Wanner, but there is always the problem of not knowing the accuracy when doing fixed step simulation.
 
Another solution is to use PATTERNSEARCH for the optimization. It is a derivative-free solver. Note that this function belongs to the ‘Global Optimization toolbox’.
 
 
2) A second way of estimating the parameters in an ODE is to use the "Nonlinear Grey Box" models of System Identification Toolbox. This feature has been available since R2007a.
 
The workflow is as follows:
 
a) Prepare a data object containing the signal that you want to optimize your ODE coefficients for.
 
b) Write an M- or a MEX-file for your ODE that represents the ODE as a set of first order differential equations. This file returns the state derivatives and signal values as a function of time, forcing function (if any), coefficient values and initial conditions.
 
c) Then create an IDNLGREY object that encapsulates the ODE in a model form. It uses the ODE file from previous step as its main component. It also defines the initial values of coefficients, dimension of signal (in case of multi variable ODEs), names/units of signals, type of optimizer to use etc.
 
d) Use the estimation command PEM to optimize the ODE's coefficients to maximize the fit between the ODE's simulation results and the provided external signal. For this, a variety of optimization routines are available (line-search schemes such as Gauss-Newton, Levenburg-Marquardt, Steepest Descent and trust region approach (lsqnonlin)).
 
These techniques work for both linear and nonlinear ODEs. However, for linear ODEs, a special object called IDGREY is also available which facilitates a more efficient approach and provide additional functionality such as prescribing stability constraints, modeling disturbance and plotting time/frequency domain response of the model ("model" is a state-space representation of the ODE). See the demos in system Identification Toolbox for some examples.
 
 
If you're doing this type of work within a Simulink simulation, Simulink Design Optimization allows you to optimize system parameters while using a variable step size solver. It is designed to handle the numerical difficulties which arise in these situations such as the aforementioned issues when using the optimization toolbox and ode solvers directly. 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.