Matlab 2008b VC++ ODE45

1 view (last 30 days)
Paul Huter
Paul Huter on 12 Jul 2012
I am trying to utilize the ODE45 functionality of Matlab in Visual C++ 2010. Searching the Internet, I see that there used to be a file "matlab.hpp" that could be included in a C++ project, but that in R2008b (the version of Matlab I am using), this is not an option. I did try searching Matlab Central for "Matlab 2008 C++ ODE45" and got no hits, so either that was too specific or there really is no solution already posted. If anyone knows how to do this (use ODE45 in C++), I would appreciate the help.
Thanks in advance.
  1 Comment
Paul Huter
Paul Huter on 13 Jul 2012
Further looking into things...still think utilizing the Matlab code in C++ will be the simplest solution. I have a numerical coding book that shows me how to implement RK4, and like I said, I've found multiple "answers" online. But the book I'm using as a guide walks me through the steps using ODE45 in Matlab for solving a system of equations. I kind of looked at the ODE45.m file, just not sure how to use it with C++ (is this even possible?).
Thanks.

Sign in to comment.

Accepted Answer

Jan
Jan on 12 Jul 2012
Matlab's ODE45 is a stable and well tested implementation of explicit Runge-Kutta method of Dormand-Prince. It is a 4th order method using an embedded 5th order method for the stepsize control.
This method has been implemented in C directly very often. Look for the terms "RK45" and "Dormand-Prince" in the net, e.g. at www.netlib.org. The C-implementation can be 10 times faster than ODE45.m and I do not see advantages of using the Matlab integrator.
  1 Comment
Paul Huter
Paul Huter on 12 Jul 2012
Thanks Jan. I am currently using an implementation of RK4, and I know ODE45 uses RK4. I'm not 100% certain I'm doing things correctly though - I found multiple sites that provided different solutions for the same problem, which is similar to a problem I solved in a class (using Matlab for RK4), and all based on a book I am using to solve some things (the problem is integrating acceleration to find velocity and position). Moving further through this same book, it talks about using Matlab/Simulink and ODE45 to solve the integration, which was why I was hoping to implement in C++, since I thought it would be easier to follow an example in the book (which was written for solving the overall general problem I am working), rather than trying to figure out the best way to implement an RK4 based on the numerous possible implementations on the Internet.
However, if you know of a good solution for integrating acceleration (which is partially a function of velocity) to solve for velocity, and also to integrate velocity (which will have been converted to a different coordinate system) to solve for velocity, I would appreciate the help. Like I said, I know I've implemented RK4 before, and I can follow the examples on (the many) websites, but they don't exactly match up to my particular problem, so I'm looking for a more general solution. If you don't have anything, that's fine, I'll keep searching.
Thanks again for the quick response.
Paul.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!