Search This Blog

Showing posts with label ODE. Show all posts
Showing posts with label ODE. Show all posts

Friday, October 19, 2012

Variable Function Name in MATLAB

Suppose we want to call four different type of ODE solver, we can define a cell containing the 4 function handler as below:

functionName = {@ode45 @ode23 @ode113 @ode15s};

 and we can call in a cycle the desired function:
 for iFunction = 1 : size(functionName,2)  
   f = functionName{iFunction};  
   tol = 1e-4;  
   options = odeset ('RelTol',tol,'AbsTol',tol);  
   [t,y] = f('function_rhs', xspan, ic, options); % SOLVE ODEs 
 
   figure  
   plot(t,y)  
   title(func2str(f))  
 end 

Where function_rhs is the right side of the ODE we want to solve.
In this way we'll obtain 4 figures with the ODE solver name in the title.