automatic differentiation with ode45()
Afficher commentaires plus anciens
Hi,
I wanted to understand how the package Automatic Differentiation for Matlab worked. So I create a small example. I wish to use the add-in to find for example myFunc(t=3) and grad(myFunc)(t=3). My func is a function that is solution to the differential equation x''(t) = 1. So I created a function
function ds = doubleIntegrator(t,s)
ds = zeros(2,1);
ds(1) = s(2);
ds(2) = 1;
end
and also the function
function [t,s] = integrateme(f,st,tspan)
[t,s] = ode45(f,tspan,st);
end
then I define the function myFunc as :
K>> myFunc=@(t) integrateme(@doubleIntegrator,[0,0],[0,t])
K>>tAD = myAD(3) % because I want to compute de AD in t=3
K>>myFunc(tAD)
but it returns the error
Error using length Too many input arguments.
Error in myAD/length (line 6) mylength = length(x.values);
Error in odearguments (line 20) if length(tspan) < 2
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in integrateme (line 2) [t,s] = ode45(f,tspan,st);
Error in myAD/length>@(t)integrateme(@doubleIntegrator,[0,0],[0,t])
1 commentaire
Star Strider
le 8 Déc 2017
The File Exchange function appears to do numerical differentiation of a vector (similar to MATLAB gradient), and will not produce the derivative used in the ODE solvers.
The Symbolic Math Toolbox is probably your best option if you want to calculate a symbolic derivative.
Réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!