first of all compliments for the ADiGator software !
I would like to ask you, if possible, an information regarding the use of Matlab ode function inside a function to pass to ADiGator for a following automatic differentiation.
First of all, is it possible for ADiGator to manipulate ode functions (i.e. are ode functions overloaded) ?
Actually I'm working on a Matlab code that has to be differentiated through automatic differentiation; so I modified this code in order to be treated by ADiGator.
The problem I'm getting now appears when ADiGator starts to write the derivatives: Matlab gives me the error "impossible to convert to logical from cada" when the ode45 is called in my function.
Is there any way to sort out this problem ?
Thank you in advance for your reply and your time.
Nicola.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your interest in the code. In short, no, ode functions are not overloaded and there is not an easy way to do so that I see. The only solution I would see is to write your own ode solver such that ADiGator can differentiate it. The big issues here would be replacing while loops with for/if/break sequences, removing anonymous function calls, etc.
Out of curiosity, what are you differentiating with respect to? The initial state or time? If the initial condition is fixed and time varies, I would suggest solving the ode on a dense mesh and fitting a spline prior to problem solution, then calling ppval within the function you are differentiating. I would think that if your initial mesh is dense enough this should be fine.
If you are differentiating with respect to initial condition, that is a bit tougher. You could look into doing a collocation scheme and solving the square system via a Newton loop - assuming the system is well behaved this would be some fairly simple code.
-Matt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Matthew,
first of all compliments for the ADiGator software !
I would like to ask you, if possible, an information regarding the use of Matlab ode function inside a function to pass to ADiGator for a following automatic differentiation.
First of all, is it possible for ADiGator to manipulate ode functions (i.e. are ode functions overloaded) ?
Actually I'm working on a Matlab code that has to be differentiated through automatic differentiation; so I modified this code in order to be treated by ADiGator.
The problem I'm getting now appears when ADiGator starts to write the derivatives: Matlab gives me the error "impossible to convert to logical from cada" when the ode45 is called in my function.
Is there any way to sort out this problem ?
Thank you in advance for your reply and your time.
Nicola.
Hello Nicola,
Thank you for your interest in the code. In short, no, ode functions are not overloaded and there is not an easy way to do so that I see. The only solution I would see is to write your own ode solver such that ADiGator can differentiate it. The big issues here would be replacing while loops with for/if/break sequences, removing anonymous function calls, etc.
Out of curiosity, what are you differentiating with respect to? The initial state or time? If the initial condition is fixed and time varies, I would suggest solving the ode on a dense mesh and fitting a spline prior to problem solution, then calling ppval within the function you are differentiating. I would think that if your initial mesh is dense enough this should be fine.
If you are differentiating with respect to initial condition, that is a bit tougher. You could look into doing a collocation scheme and solving the square system via a Newton loop - assuming the system is well behaved this would be some fairly simple code.
-Matt