Speeding Up the ODE solver algorithm for a given time dependent input
Show older comments
Hi,
I am currently looking for a way to modify my code such that it will require shorter computation time, for solving a system of differential equations. The part of my code which is causing the most computation time in brief is the following ODE solver:
the ODE solver is called in my main program as
options=odeset('AbsTol',10e-6,'RelTol',10e-5,'Stats','on');
[T_, Y_]=ode45(@yourFcn, tspan,Y0, options, freq, b, amp);
where Y0 is a vector with initial conditions, freq, b, amp are constants passed to my function. tspan is a vector of X elements where in my case I like it to be approximately 50000 elements. and I have evaluated that I need the corresponding Absolute and relative error tolerances for my system.
function dy = yourFcn(t, y, b, freq, amp);
J=(amp/2)*(sin(2*pi*freq*t);
J=J+b;
dy = zeros(3,1);
dy(1) = (A*(y(3))/(B*y(1)))*y(1)+ C*y(3)^2;
dy(2) = (B*(y(3))/(A*y(1))-1);
dy(3) = J/C*y(3) - D*(y(3))/(A*y(1))*y(1);
where A,B,C,D are all constants, and J is my time dependent variable in my system of differential equations which will also have a length of approximately 50000 elements as same as tspan.
Looking at the profile function, as expected most of time has been taking by calling the function yourFcn and the algorithem used for ODE45.
I have so far tried to evaluate the vector J in my main program, evaluating each element of J over a short tspan of a:b, and capturing the steady state solution of my differential equation as my final result for that particular element of J and moving to next point......
I have also tried the following method by defining J in my main program again and calling my ODE solver as follow
[T_, Y_]=ode45(@(tspan, y) yourFcn(tspan, y, tspan, J) ,tspan, Y_0, options);
where in my Function i made the following changes
function dy = yourFcn(t, y, t1, J1);
dy = zeros(3,1);
J=interp1(t1, J1, t);
.
.
.
but in all case the first method showed the best performance but still extremely slow for me.
My computer specs are: Intel Quad Core i7 @ 3.7Ghz 4Gb Ram
Many Thanks, Arsalan
2 Comments
Arsalan
on 18 Nov 2012
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!