automatic differentiation with ode45()
이전 댓글 표시
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
Star Strider
2017년 12월 8일
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.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!