Clear Filters
Clear Filters

calling a c file to use ode45

31 views (last 30 days)
kim
kim on 31 Jul 2024 at 17:40
Commented: James Tursa on 2 Aug 2024 at 17:44
I am trying to call a c file that hold a derivative function. I want to call it with ode45, or something similar.
  1 Comment
James Tursa
James Tursa on 2 Aug 2024 at 17:44
Have you ever written a mex function before? What does the derivative function C signature look like?

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 31 Jul 2024 at 18:24
You can pass a function handle to a MEX-file that you've created from a C or C++ file into ode45 as long as the signature of that MEX-file matches the signature ode45 requires its ODE function (the first input) to have. See the description of the odefun input argument on the ode45 documentation page.
"The function dydt = odefun(t,y), for a scalar t and a column vector y, must return a column vector dydt of data type single or double that corresponds to f(t,y). odefun must accept both input arguments t and y, even if one of the arguments is not used in the function."

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!